Changes in protocols/jabber/iq.c [eded1f7:4306d8b]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/iq.c
reded1f7 r4306d8b 50 50 else if( strcmp( type, "get" ) == 0 ) 51 51 { 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/> ????? */ 52 if( !( c = xt_find_node( node->children, "query" ) ) || 54 53 !( s = xt_find_attr( c, "xmlns" ) ) ) 55 54 { … … 82 81 xt_add_child( reply, xt_new_node( "tz", buf, NULL ) ); 83 82 } 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 ) 83 else if( strcmp( s, XMLNS_DISCOVER ) == 0 ) 93 84 { 94 85 const char *features[] = { XMLNS_VERSION, … … 96 87 XMLNS_CHATSTATES, 97 88 XMLNS_MUC, 98 XMLNS_PING,99 XMLNS_SI,100 XMLNS_BYTESTREAMS,101 XMLNS_FILETRANSFER,102 89 NULL }; 103 90 const char **f; … … 119 106 { 120 107 xt_free_node( reply ); 121 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" , NULL);108 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" ); 122 109 pack = 0; 123 110 } … … 125 112 else if( strcmp( type, "set" ) == 0 ) 126 113 { 127 if( ( c = xt_find_node( node->children, "si" ) ) && 128 ( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_SI ) == 0 ) ) 129 { 130 return jabber_si_handle_request( ic, node, c ); 131 } else if( !( c = xt_find_node( node->children, "query" ) ) || 114 if( !( c = xt_find_node( node->children, "query" ) ) || 132 115 !( s = xt_find_attr( c, "xmlns" ) ) ) 133 116 { 134 117 imcb_log( ic, "WARNING: Received incomplete IQ-%s packet", type ); 135 118 return XT_HANDLED; 136 } else if( strcmp( s, XMLNS_ROSTER ) == 0 )137 {119 } 120 138 121 /* This is a roster push. XMPP servers send this when someone 139 122 was added to (or removed from) the buddy list. AFAIK they're 140 123 sent even if we added this buddy in our own session. */ 124 if( strcmp( s, XMLNS_ROSTER ) == 0 ) 125 { 141 126 int bare_len = strlen( ic->acc->user ); 142 127 … … 155 140 156 141 xt_free_node( reply ); 157 reply = jabber_make_error_packet( node, "not-allowed", "cancel" , NULL);142 reply = jabber_make_error_packet( node, "not-allowed", "cancel" ); 158 143 pack = 0; 159 144 } 160 } else if( strcmp( s, XMLNS_BYTESTREAMS ) == 0 ) 161 { 162 /* Bytestream Request (stage 2 of file transfer) */ 163 return jabber_bs_recv_request( ic, node, c ); 164 } else 145 } 146 else 165 147 { 166 148 xt_free_node( reply ); 167 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" , NULL);149 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" ); 168 150 pack = 0; 169 151 } … … 575 557 return st; 576 558 } 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.