Changes in protocols/jabber/iq.c [4358b10:74349eb]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/iq.c
r4358b10 r74349eb 51 51 { 52 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/> ????? */53 ( c = xt_find_node( node->children, "ping" ) ) ) || 54 54 !( s = xt_find_attr( c, "xmlns" ) ) ) 55 55 { 56 imcb_log( ic, "Warning: Received incomplete IQ-%s packet", type ); 56 /* Sigh. Who decided to suddenly invent new elements 57 instead of just sticking with <query/>? */ 57 58 return XT_HANDLED; 58 59 } … … 90 91 pack = 0; 91 92 } 92 else if( strcmp( s, XMLNS_DISCO _INFO) == 0 )93 { 94 const char *features[] = { XMLNS_DISCO _INFO,93 else if( strcmp( s, XMLNS_DISCOVER ) == 0 ) 94 { 95 const char *features[] = { XMLNS_DISCOVER, 95 96 XMLNS_VERSION, 96 97 XMLNS_TIME, … … 98 99 XMLNS_MUC, 99 100 XMLNS_PING, 100 XMLNS_SI,101 XMLNS_BYTESTREAMS,102 XMLNS_FILETRANSFER,103 101 NULL }; 104 102 const char **f; … … 120 118 { 121 119 xt_free_node( reply ); 122 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" , NULL);120 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" ); 123 121 pack = 0; 124 122 } … … 126 124 else if( strcmp( type, "set" ) == 0 ) 127 125 { 128 if( ( c = xt_find_node( node->children, "si" ) ) && 129 ( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_SI ) == 0 ) ) 130 { 131 return jabber_si_handle_request( ic, node, c ); 132 } else if( !( c = xt_find_node( node->children, "query" ) ) || 126 if( !( c = xt_find_node( node->children, "query" ) ) || 133 127 !( s = xt_find_attr( c, "xmlns" ) ) ) 134 128 { 135 129 imcb_log( ic, "Warning: Received incomplete IQ-%s packet", type ); 136 130 return XT_HANDLED; 137 } else if( strcmp( s, XMLNS_ROSTER ) == 0 )138 {131 } 132 139 133 /* This is a roster push. XMPP servers send this when someone 140 134 was added to (or removed from) the buddy list. AFAIK they're 141 135 sent even if we added this buddy in our own session. */ 136 if( strcmp( s, XMLNS_ROSTER ) == 0 ) 137 { 142 138 int bare_len = strlen( ic->acc->user ); 143 139 … … 156 152 157 153 xt_free_node( reply ); 158 reply = jabber_make_error_packet( node, "not-allowed", "cancel" , NULL);154 reply = jabber_make_error_packet( node, "not-allowed", "cancel" ); 159 155 pack = 0; 160 156 } 161 } else if( strcmp( s, XMLNS_BYTESTREAMS ) == 0 ) 162 { 163 /* Bytestream Request (stage 2 of file transfer) */ 164 return jabber_bs_recv_request( ic, node, c ); 165 } else 157 } 158 else 166 159 { 167 160 xt_free_node( reply ); 168 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" , NULL);161 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" ); 169 162 pack = 0; 170 163 } … … 601 594 return st; 602 595 } 603 604 xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );605 606 xt_status jabber_iq_query_features( struct im_connection *ic, char *bare_jid )607 {608 struct xt_node *node, *query;609 struct jabber_buddy *bud;610 611 if( ( bud = jabber_buddy_by_jid( ic, bare_jid , 0 ) ) == NULL )612 {613 /* Who cares about the unknown... */614 imcb_log( ic, "Couldn't find buddy: %s", bare_jid);615 return 0;616 }617 618 if( bud->features ) /* been here already */619 return XT_HANDLED;620 621 node = xt_new_node( "query", NULL, NULL );622 xt_add_attr( node, "xmlns", XMLNS_DISCO_INFO );623 624 if( !( query = jabber_make_packet( "iq", "get", bare_jid, node ) ) )625 {626 imcb_log( ic, "WARNING: Couldn't generate feature query" );627 xt_free_node( node );628 return 0;629 }630 631 jabber_cache_add( ic, query, jabber_iq_parse_features );632 633 return jabber_write_packet( ic, query );634 }635 636 xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig )637 {638 struct xt_node *c;639 struct jabber_buddy *bud;640 char *feature;641 642 if( !( c = xt_find_node( node->children, "query" ) ) ||643 !( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_INFO ) == 0 ) )644 {645 imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" );646 return XT_HANDLED;647 }648 if( ( bud = jabber_buddy_by_jid( ic, xt_find_attr( node, "from") , 0 ) ) == NULL )649 {650 /* Who cares about the unknown... */651 imcb_log( ic, "Couldn't find buddy: %s", xt_find_attr( node, "from"));652 return 0;653 }654 655 c = c->children;656 while( ( c = xt_find_node( c, "feature" ) ) ) {657 feature = xt_find_attr( c, "var" );658 bud->features = g_slist_append(bud->features, g_strdup(feature) );659 c = c->next;660 }661 662 return XT_HANDLED;663 }664 665 xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );666 667 xt_status jabber_iq_query_server( struct im_connection *ic, char *jid, char *xmlns )668 {669 struct xt_node *node, *query;670 struct jabber_data *jd = ic->proto_data;671 672 node = xt_new_node( "query", NULL, NULL );673 xt_add_attr( node, "xmlns", xmlns );674 675 if( !( query = jabber_make_packet( "iq", "get", jid, node ) ) )676 {677 imcb_log( ic, "WARNING: Couldn't generate server query" );678 xt_free_node( node );679 }680 681 jd->have_streamhosts--;682 jabber_cache_add( ic, query, jabber_iq_parse_server_features );683 684 return jabber_write_packet( ic, query );685 }686 687 /*688 * Query the server for "items", query each "item" for identities, query each "item" that's a proxy for it's bytestream info689 */690 xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig )691 {692 struct xt_node *c;693 struct jabber_data *jd = ic->proto_data;694 695 if( !( c = xt_find_node( node->children, "query" ) ) ||696 !xt_find_attr( node, "from" ) )697 {698 imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" );699 return XT_HANDLED;700 }701 702 jd->have_streamhosts++;703 704 if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_ITEMS ) == 0 )705 {706 char *item, *itemjid;707 708 /* answer from server */709 710 c = c->children;711 while( ( c = xt_find_node( c, "item" ) ) )712 {713 item = xt_find_attr( c, "name" );714 itemjid = xt_find_attr( c, "jid" );715 716 jabber_iq_query_server( ic, itemjid, XMLNS_DISCO_INFO );717 718 c = c->next;719 }720 } else if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_INFO ) == 0 )721 {722 char *category, *type;723 724 /* answer from potential proxy */725 726 c = c->children;727 while( ( c = xt_find_node( c, "identity" ) ) )728 {729 category = xt_find_attr( c, "category" );730 type = xt_find_attr( c, "type" );731 732 if( type && ( strcmp( type, "bytestreams" ) == 0 ) &&733 category && ( strcmp( category, "proxy" ) == 0 ) )734 jabber_iq_query_server( ic, xt_find_attr( node, "from" ), XMLNS_BYTESTREAMS );735 736 c = c->next;737 }738 } else if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_BYTESTREAMS ) == 0 )739 {740 char *host, *jid;741 int port;742 743 /* answer from proxy */744 745 if( ( c = xt_find_node( c->children, "streamhost" ) ) &&746 ( host = xt_find_attr( c, "host" ) ) &&747 ( port = atoi( xt_find_attr( c, "port" ) ) ) &&748 ( jid = xt_find_attr( c, "jid" ) ) )749 {750 jabber_streamhost_t *sh = g_new0( jabber_streamhost_t, 1 );751 sh->jid = g_strdup( jid );752 sh->host = g_strdup( host );753 sprintf( sh->port, "%u", port );754 755 imcb_log( ic, "Proxy found: jid %s host %s port %u", jid, host, port );756 jd->streamhosts = g_slist_append( jd->streamhosts, sh );757 }758 }759 760 if( jd->have_streamhosts == 0 )761 jd->have_streamhosts++;762 return XT_HANDLED;763 }
Note: See TracChangeset
for help on using the changeset viewer.