Changes in protocols/jabber/iq.c [eded1f7:2ff2076]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/iq.c
reded1f7 r2ff2076 31 31 { 32 32 struct im_connection *ic = data; 33 struct jabber_data *jd = ic->proto_data; 33 34 struct xt_node *c, *reply = NULL; 34 35 char *type, *s; … … 46 47 if( strcmp( type, "result" ) == 0 || strcmp( type, "error" ) == 0 ) 47 48 { 48 return jabber_cache_handle_packet( ic, node ); 49 struct jabber_cache_entry *entry; 50 51 if( ( s = xt_find_attr( node, "id" ) ) == NULL || 52 strncmp( s, jd->cached_id_prefix, strlen( jd->cached_id_prefix ) ) != 0 ) 53 { 54 /* Silently ignore it, without an ID (or a non-cache 55 ID) we don't know how to handle the packet and we 56 probably don't have to. */ 57 return XT_HANDLED; 58 } 59 60 entry = g_hash_table_lookup( jd->node_cache, s ); 61 62 if( entry == NULL ) 63 imcb_log( ic, "WARNING: Received IQ-%s packet with unknown/expired ID %s!", type, s ); 64 else if( entry->func ) 65 return entry->func( ic, node, entry->node ); 49 66 } 50 67 else if( strcmp( type, "get" ) == 0 ) 51 68 { 52 if( !( ( c = xt_find_node( node->children, "query" ) ) || 53 ( c = xt_find_node( node->children, "ping" ) ) ) || /* O_o WHAT is wrong with just <query/> ????? */ 69 if( !( c = xt_find_node( node->children, "query" ) ) || 54 70 !( s = xt_find_attr( c, "xmlns" ) ) ) 55 71 { … … 82 98 xt_add_child( reply, xt_new_node( "tz", buf, NULL ) ); 83 99 } 84 else if( strcmp( s, XMLNS_PING ) == 0 ) 85 { 86 xt_free_node( reply ); 87 reply = jabber_make_packet( "iq", "result", xt_find_attr( node, "from" ), NULL ); 88 if( ( s = xt_find_attr( node, "id" ) ) ) 89 xt_add_attr( reply, "id", s ); 90 pack = 0; 91 } 92 else if( strcmp( s, XMLNS_DISCO_INFO ) == 0 ) 100 else if( strcmp( s, XMLNS_DISCOVER ) == 0 ) 93 101 { 94 102 const char *features[] = { XMLNS_VERSION, … … 96 104 XMLNS_CHATSTATES, 97 105 XMLNS_MUC, 98 XMLNS_PING,99 106 XMLNS_SI, 100 107 XMLNS_BYTESTREAMS, … … 575 582 return st; 576 583 } 577 578 xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );579 580 xt_status jabber_iq_query_features( struct im_connection *ic, char *bare_jid )581 {582 struct xt_node *node, *query;583 struct jabber_buddy *bud;584 585 if( ( bud = jabber_buddy_by_jid( ic, bare_jid , 0 ) ) == NULL )586 {587 /* Who cares about the unknown... */588 imcb_log( ic, "Couldnt find the man: %s", bare_jid);589 return 0;590 }591 592 if( bud->features ) /* been here already */593 return XT_HANDLED;594 595 node = xt_new_node( "query", NULL, NULL );596 xt_add_attr( node, "xmlns", XMLNS_DISCO_INFO );597 598 if( !( query = jabber_make_packet( "iq", "get", bare_jid, node ) ) )599 {600 imcb_log( ic, "WARNING: Couldn't generate feature query" );601 xt_free_node( node );602 }603 604 jabber_cache_add( ic, query, jabber_iq_parse_features );605 606 return jabber_write_packet( ic, query );607 }608 609 xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig )610 {611 struct xt_node *c;612 struct jabber_buddy *bud;613 char *feature;614 615 if( !( c = xt_find_node( node->children, "query" ) ) ||616 !( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_INFO ) == 0 ) )617 {618 imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" );619 return XT_HANDLED;620 }621 if( ( bud = jabber_buddy_by_jid( ic, xt_find_attr( node, "from") , 0 ) ) == NULL )622 {623 /* Who cares about the unknown... */624 imcb_log( ic, "Couldnt find the man: %s", xt_find_attr( node, "from"));625 return 0;626 }627 628 c = c->children;629 while( ( c = xt_find_node( c, "feature" ) ) ) {630 feature = xt_find_attr( c, "var" );631 bud->features = g_slist_append(bud->features, g_strdup(feature) );632 c = c->next;633 }634 635 return XT_HANDLED;636 }637 638 xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );639 640 xt_status jabber_iq_query_server( struct im_connection *ic, char *jid, char *xmlns )641 {642 struct xt_node *node, *query;643 struct jabber_data *jd = ic->proto_data;644 645 node = xt_new_node( "query", NULL, NULL );646 xt_add_attr( node, "xmlns", xmlns );647 648 if( !( query = jabber_make_packet( "iq", "get", jid, node ) ) )649 {650 imcb_log( ic, "WARNING: Couldn't generate server query" );651 xt_free_node( node );652 }653 654 jd->have_streamhosts--;655 jabber_cache_add( ic, query, jabber_iq_parse_server_features );656 657 return jabber_write_packet( ic, query );658 }659 660 /*661 * Query the server for "items", query each "item" for identities, query each "item" that's a proxy for it's bytestream info662 */663 xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig )664 {665 struct xt_node *c;666 struct jabber_data *jd = ic->proto_data;667 668 if( !( c = xt_find_node( node->children, "query" ) ) ||669 !xt_find_attr( node, "from" ) )670 {671 imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" );672 return XT_HANDLED;673 }674 675 jd->have_streamhosts++;676 677 if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_ITEMS ) == 0 )678 {679 char *item, *itemjid;680 681 /* answer from server */682 683 c = c->children;684 while( ( c = xt_find_node( c, "item" ) ) )685 {686 item = xt_find_attr( c, "name" );687 itemjid = xt_find_attr( c, "jid" );688 689 jabber_iq_query_server( ic, itemjid, XMLNS_DISCO_INFO );690 691 c = c->next;692 }693 } else if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_INFO ) == 0 )694 {695 char *category, *type;696 697 /* answer from potential proxy */698 699 c = c->children;700 while( ( c = xt_find_node( c, "identity" ) ) )701 {702 category = xt_find_attr( c, "category" );703 type = xt_find_attr( c, "type" );704 705 if( type && ( strcmp( type, "bytestreams" ) == 0 ) &&706 category && ( strcmp( category, "proxy" ) == 0 ) )707 jabber_iq_query_server( ic, xt_find_attr( node, "from" ), XMLNS_BYTESTREAMS );708 709 c = c->next;710 }711 } else if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_BYTESTREAMS ) == 0 )712 {713 char *host, *jid;714 int port;715 716 /* answer from proxy */717 718 if( ( c = xt_find_node( c->children, "streamhost" ) ) &&719 ( host = xt_find_attr( c, "host" ) ) &&720 ( port = atoi( xt_find_attr( c, "port" ) ) ) &&721 ( jid = xt_find_attr( c, "jid" ) ) )722 {723 jabber_streamhost_t *sh = g_new0( jabber_streamhost_t, 1 );724 sh->jid = g_strdup( jid );725 sh->host = g_strdup( host );726 sprintf( sh->port, "%u", port );727 728 imcb_log( ic, "Proxy found: jid %s host %s port %u", jid, host, port );729 jd->streamhosts = g_slist_append( jd->streamhosts, sh );730 }731 }732 733 if( jd->have_streamhosts == 0 )734 jd->have_streamhosts++;735 return XT_HANDLED;736 }
Note: See TracChangeset
for help on using the changeset viewer.