Mercurial > pidgin
comparison libpurple/protocols/jabber/jabber.c @ 28650:9ae3e70a327b
jabber: More namespaces! This is a good stopping point for now.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Fri, 27 Nov 2009 17:07:19 +0000 |
parents | 1a4b6f47258c |
children | d9c70a78fad5 3bf5dbff753b c4f836780e1c cb8b53a6f238 |
comparison
equal
deleted
inserted
replaced
28649:8d8a1afc4268 | 28650:9ae3e70a327b |
---|---|
79 static void jabber_stream_init(JabberStream *js) | 79 static void jabber_stream_init(JabberStream *js) |
80 { | 80 { |
81 char *open_stream; | 81 char *open_stream; |
82 | 82 |
83 open_stream = g_strdup_printf("<stream:stream to='%s' " | 83 open_stream = g_strdup_printf("<stream:stream to='%s' " |
84 "xmlns='jabber:client' " | 84 "xmlns='" NS_XMPP_CLIENT "' " |
85 "xmlns:stream='http://etherx.jabber.org/streams' " | 85 "xmlns:stream='" NS_XMPP_STREAMS "' " |
86 "version='1.0'>", | 86 "version='1.0'>", |
87 js->user->domain); | 87 js->user->domain); |
88 /* setup the parser fresh for each stream */ | 88 /* setup the parser fresh for each stream */ |
89 jabber_parser_setup(js); | 89 jabber_parser_setup(js); |
90 jabber_send_raw(js, open_stream, -1); | 90 jabber_send_raw(js, open_stream, -1); |
114 xmlnode *session; | 114 xmlnode *session; |
115 | 115 |
116 jabber_iq_set_callback(iq, jabber_session_initialized_cb, NULL); | 116 jabber_iq_set_callback(iq, jabber_session_initialized_cb, NULL); |
117 | 117 |
118 session = xmlnode_new_child(iq->node, "session"); | 118 session = xmlnode_new_child(iq->node, "session"); |
119 xmlnode_set_namespace(session, "urn:ietf:params:xml:ns:xmpp-session"); | 119 xmlnode_set_namespace(session, NS_XMPP_SESSION); |
120 | 120 |
121 jabber_iq_send(iq); | 121 jabber_iq_send(iq); |
122 } | 122 } |
123 | 123 |
124 static void jabber_bind_result_cb(JabberStream *js, const char *from, | 124 static void jabber_bind_result_cb(JabberStream *js, const char *from, |
126 xmlnode *packet, gpointer data) | 126 xmlnode *packet, gpointer data) |
127 { | 127 { |
128 xmlnode *bind; | 128 xmlnode *bind; |
129 | 129 |
130 if (type == JABBER_IQ_RESULT && | 130 if (type == JABBER_IQ_RESULT && |
131 (bind = xmlnode_get_child_with_namespace(packet, "bind", "urn:ietf:params:xml:ns:xmpp-bind"))) { | 131 (bind = xmlnode_get_child_with_namespace(packet, "bind", NS_XMPP_BIND))) { |
132 xmlnode *jid; | 132 xmlnode *jid; |
133 char *full_jid; | 133 char *full_jid; |
134 if((jid = xmlnode_get_child(bind, "jid")) && (full_jid = xmlnode_get_data(jid))) { | 134 if((jid = xmlnode_get_child(bind, "jid")) && (full_jid = xmlnode_get_data(jid))) { |
135 jabber_id_free(js->user); | 135 jabber_id_free(js->user); |
136 | 136 |
215 } else if(xmlnode_get_child(packet, "bind")) { | 215 } else if(xmlnode_get_child(packet, "bind")) { |
216 xmlnode *bind, *resource; | 216 xmlnode *bind, *resource; |
217 char *requested_resource; | 217 char *requested_resource; |
218 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); | 218 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); |
219 bind = xmlnode_new_child(iq->node, "bind"); | 219 bind = xmlnode_new_child(iq->node, "bind"); |
220 xmlnode_set_namespace(bind, "urn:ietf:params:xml:ns:xmpp-bind"); | 220 xmlnode_set_namespace(bind, NS_XMPP_BIND); |
221 requested_resource = jabber_prep_resource(js->user->resource); | 221 requested_resource = jabber_prep_resource(js->user->resource); |
222 | 222 |
223 if (requested_resource != NULL) { | 223 if (requested_resource != NULL) { |
224 resource = xmlnode_new_child(bind, "resource"); | 224 resource = xmlnode_new_child(bind, "resource"); |
225 xmlnode_insert_data(resource, requested_resource, -1); | 225 xmlnode_insert_data(resource, requested_resource, -1); |
270 } else if(!strcmp((*packet)->name, "message")) { | 270 } else if(!strcmp((*packet)->name, "message")) { |
271 jabber_message_parse(js, *packet); | 271 jabber_message_parse(js, *packet); |
272 } else if(!strcmp((*packet)->name, "stream:features")) { | 272 } else if(!strcmp((*packet)->name, "stream:features")) { |
273 jabber_stream_features_parse(js, *packet); | 273 jabber_stream_features_parse(js, *packet); |
274 } else if (!strcmp((*packet)->name, "features") && xmlns && | 274 } else if (!strcmp((*packet)->name, "features") && xmlns && |
275 !strcmp(xmlns, "http://etherx.jabber.org/streams")) { | 275 !strcmp(xmlns, NS_XMPP_STREAMS)) { |
276 jabber_stream_features_parse(js, *packet); | 276 jabber_stream_features_parse(js, *packet); |
277 } else if(!strcmp((*packet)->name, "stream:error") || | 277 } else if(!strcmp((*packet)->name, "stream:error") || |
278 (!strcmp((*packet)->name, "error") && xmlns && | 278 (!strcmp((*packet)->name, "error") && xmlns && |
279 !strcmp(xmlns, "http://etherx.jabber.org/streams"))) | 279 !strcmp(xmlns, NS_XMPP_STREAMS))) |
280 { | 280 { |
281 jabber_stream_handle_error(js, *packet); | 281 jabber_stream_handle_error(js, *packet); |
282 } else if(!strcmp((*packet)->name, "challenge")) { | 282 } else if(!strcmp((*packet)->name, "challenge")) { |
283 if(js->state == JABBER_STREAM_AUTHENTICATING) | 283 if(js->state == JABBER_STREAM_AUTHENTICATING) |
284 jabber_auth_handle_challenge(js, *packet); | 284 jabber_auth_handle_challenge(js, *packet); |
383 | 383 |
384 /* Because debug logs with plaintext passwords make me sad */ | 384 /* Because debug logs with plaintext passwords make me sad */ |
385 if(js->state != JABBER_STREAM_CONNECTED && | 385 if(js->state != JABBER_STREAM_CONNECTED && |
386 /* Either <auth> or <query><password>... */ | 386 /* Either <auth> or <query><password>... */ |
387 (((tag_start = strstr(data, "<auth ")) && | 387 (((tag_start = strstr(data, "<auth ")) && |
388 strstr(data, "xmlns='urn:ietf:params:xml:ns:xmpp-sasl'")) || | 388 strstr(data, "xmlns='" NS_XMPP_SASL "'")) || |
389 ((tag_start = strstr(data, "<query ")) && | 389 ((tag_start = strstr(data, "<query ")) && |
390 strstr(data, "xmlns='jabber:iq:auth'>") && | 390 strstr(data, "xmlns='jabber:iq:auth'>") && |
391 (tag_start = strstr(tag_start, "<password>"))))) { | 391 (tag_start = strstr(tag_start, "<password>"))))) { |
392 char *data_start, *tag_end = strchr(tag_start, '>'); | 392 char *data_start, *tag_end = strchr(tag_start, '>'); |
393 text = g_strdup(data); | 393 text = g_strdup(data); |
486 | 486 |
487 if (js->bosh) | 487 if (js->bosh) |
488 if (g_str_equal((*packet)->name, "message") || | 488 if (g_str_equal((*packet)->name, "message") || |
489 g_str_equal((*packet)->name, "iq") || | 489 g_str_equal((*packet)->name, "iq") || |
490 g_str_equal((*packet)->name, "presence")) | 490 g_str_equal((*packet)->name, "presence")) |
491 xmlnode_set_namespace(*packet, "jabber:client"); | 491 xmlnode_set_namespace(*packet, NS_XMPP_CLIENT); |
492 txt = xmlnode_to_str(*packet, &len); | 492 txt = xmlnode_to_str(*packet, &len); |
493 jabber_send_raw(js, txt, len); | 493 jabber_send_raw(js, txt, len); |
494 g_free(txt); | 494 g_free(txt); |
495 } | 495 } |
496 | 496 |
1211 | 1211 |
1212 if((x = xmlnode_get_child_with_namespace(query, "x", "jabber:x:data"))) { | 1212 if((x = xmlnode_get_child_with_namespace(query, "x", "jabber:x:data"))) { |
1213 jabber_x_data_request(js, x, jabber_register_x_data_cb, g_strdup(from)); | 1213 jabber_x_data_request(js, x, jabber_register_x_data_cb, g_strdup(from)); |
1214 return; | 1214 return; |
1215 | 1215 |
1216 } else if((x = xmlnode_get_child_with_namespace(query, "x", "jabber:x:oob"))) { | 1216 } else if((x = xmlnode_get_child_with_namespace(query, "x", NS_OOB_X_DATA))) { |
1217 xmlnode *url; | 1217 xmlnode *url; |
1218 | 1218 |
1219 if((url = xmlnode_get_child(x, "url"))) { | 1219 if((url = xmlnode_get_child(x, "url"))) { |
1220 char *href; | 1220 char *href; |
1221 if((href = xmlnode_get_data(url))) { | 1221 if((href = xmlnode_get_data(url))) { |
1640 xmlnode_set_attrib(result->node, "to", from); | 1640 xmlnode_set_attrib(result->node, "to", from); |
1641 | 1641 |
1642 error = xmlnode_new_child(result->node, "error"); | 1642 error = xmlnode_new_child(result->node, "error"); |
1643 xmlnode_set_attrib(error, "type", "cancel"); | 1643 xmlnode_set_attrib(error, "type", "cancel"); |
1644 x = xmlnode_new_child(error, "not-allowed"); | 1644 x = xmlnode_new_child(error, "not-allowed"); |
1645 xmlnode_set_namespace(x, "urn:ietf:params:xml:ns:xmpp-stanzas"); | 1645 xmlnode_set_namespace(x, NS_XMPP_STANZAS); |
1646 | 1646 |
1647 jabber_iq_send(result); | 1647 jabber_iq_send(result); |
1648 return; | 1648 return; |
1649 } | 1649 } |
1650 | 1650 |
1666 xmlnode_set_attrib(result->node, "id", id); | 1666 xmlnode_set_attrib(result->node, "id", id); |
1667 | 1667 |
1668 error = xmlnode_new_child(result->node, "error"); | 1668 error = xmlnode_new_child(result->node, "error"); |
1669 xmlnode_set_attrib(error, "type", "modify"); | 1669 xmlnode_set_attrib(error, "type", "modify"); |
1670 x = xmlnode_new_child(error, "bad-request"); | 1670 x = xmlnode_new_child(error, "bad-request"); |
1671 xmlnode_set_namespace(x, "urn:ietf:params:xml:ns:xmpp-stanzas"); | 1671 xmlnode_set_namespace(x, NS_XMPP_STANZAS); |
1672 | 1672 |
1673 jabber_iq_send(result); | 1673 jabber_iq_send(result); |
1674 return; | 1674 return; |
1675 } else { | 1675 } else { |
1676 for ( ; item; item = xmlnode_get_next_twin(item)) { | 1676 for ( ; item; item = xmlnode_get_next_twin(item)) { |
1696 { | 1696 { |
1697 xmlnode *blocklist, *item; | 1697 xmlnode *blocklist, *item; |
1698 PurpleAccount *account; | 1698 PurpleAccount *account; |
1699 | 1699 |
1700 blocklist = xmlnode_get_child_with_namespace(packet, | 1700 blocklist = xmlnode_get_child_with_namespace(packet, |
1701 "blocklist", "urn:xmpp:blocking"); | 1701 "blocklist", NS_SIMPLE_BLOCKING); |
1702 account = purple_connection_get_account(js->gc); | 1702 account = purple_connection_get_account(js->gc); |
1703 | 1703 |
1704 if (type == JABBER_IQ_ERROR || blocklist == NULL) | 1704 if (type == JABBER_IQ_ERROR || blocklist == NULL) |
1705 return; | 1705 return; |
1706 | 1706 |
1729 xmlnode *blocklist; | 1729 xmlnode *blocklist; |
1730 | 1730 |
1731 iq = jabber_iq_new(js, JABBER_IQ_GET); | 1731 iq = jabber_iq_new(js, JABBER_IQ_GET); |
1732 | 1732 |
1733 blocklist = xmlnode_new_child(iq->node, "blocklist"); | 1733 blocklist = xmlnode_new_child(iq->node, "blocklist"); |
1734 xmlnode_set_namespace(blocklist, "urn:xmpp:blocking"); | 1734 xmlnode_set_namespace(blocklist, NS_SIMPLE_BLOCKING); |
1735 | 1735 |
1736 jabber_iq_set_callback(iq, jabber_blocklist_parse, NULL); | 1736 jabber_iq_set_callback(iq, jabber_blocklist_parse, NULL); |
1737 | 1737 |
1738 jabber_iq_send(iq); | 1738 jabber_iq_send(iq); |
1739 } | 1739 } |
1762 } | 1762 } |
1763 | 1763 |
1764 iq = jabber_iq_new(js, JABBER_IQ_SET); | 1764 iq = jabber_iq_new(js, JABBER_IQ_SET); |
1765 | 1765 |
1766 block = xmlnode_new_child(iq->node, "block"); | 1766 block = xmlnode_new_child(iq->node, "block"); |
1767 xmlnode_set_namespace(block, "urn:xmpp:blocking"); | 1767 xmlnode_set_namespace(block, NS_SIMPLE_BLOCKING); |
1768 | 1768 |
1769 item = xmlnode_new_child(block, "item"); | 1769 item = xmlnode_new_child(block, "item"); |
1770 xmlnode_set_attrib(item, "jid", who); | 1770 xmlnode_set_attrib(item, "jid", who); |
1771 | 1771 |
1772 jabber_iq_send(iq); | 1772 jabber_iq_send(iq); |
1792 return; | 1792 return; |
1793 | 1793 |
1794 iq = jabber_iq_new(js, JABBER_IQ_SET); | 1794 iq = jabber_iq_new(js, JABBER_IQ_SET); |
1795 | 1795 |
1796 unblock = xmlnode_new_child(iq->node, "unblock"); | 1796 unblock = xmlnode_new_child(iq->node, "unblock"); |
1797 xmlnode_set_namespace(unblock, "urn:xmpp:blocking"); | 1797 xmlnode_set_namespace(unblock, NS_SIMPLE_BLOCKING); |
1798 | 1798 |
1799 item = xmlnode_new_child(unblock, "item"); | 1799 item = xmlnode_new_child(unblock, "item"); |
1800 xmlnode_set_attrib(item, "jid", who); | 1800 xmlnode_set_attrib(item, "jid", who); |
1801 | 1801 |
1802 jabber_iq_send(iq); | 1802 jabber_iq_send(iq); |
2456 } else if(xmlnode_get_child(error, "unexpected-request")) { | 2456 } else if(xmlnode_get_child(error, "unexpected-request")) { |
2457 text = _("Unexpected Request"); | 2457 text = _("Unexpected Request"); |
2458 } else if(xmlnode_get_child(error, "undefined-condition")) { | 2458 } else if(xmlnode_get_child(error, "undefined-condition")) { |
2459 text = _("Unknown Error"); | 2459 text = _("Unknown Error"); |
2460 } | 2460 } |
2461 } else if(xmlns && !strcmp(xmlns, "urn:ietf:params:xml:ns:xmpp-sasl")) { | 2461 } else if(xmlns && !strcmp(xmlns, NS_XMPP_SASL)) { |
2462 /* Most common reason can be the default */ | 2462 /* Most common reason can be the default */ |
2463 SET_REASON(PURPLE_CONNECTION_ERROR_NETWORK_ERROR); | 2463 SET_REASON(PURPLE_CONNECTION_ERROR_NETWORK_ERROR); |
2464 if(xmlnode_get_child(packet, "aborted")) { | 2464 if(xmlnode_get_child(packet, "aborted")) { |
2465 text = _("Authorization Aborted"); | 2465 text = _("Authorization Aborted"); |
2466 } else if(xmlnode_get_child(packet, "incorrect-encoding")) { | 2466 } else if(xmlnode_get_child(packet, "incorrect-encoding")) { |
2484 SET_REASON(PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED); | 2484 SET_REASON(PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED); |
2485 text = _("Authentication Failure"); | 2485 text = _("Authentication Failure"); |
2486 } | 2486 } |
2487 } else if(!strcmp(packet->name, "stream:error") || | 2487 } else if(!strcmp(packet->name, "stream:error") || |
2488 (!strcmp(packet->name, "error") && xmlns && | 2488 (!strcmp(packet->name, "error") && xmlns && |
2489 !strcmp(xmlns, "http://etherx.jabber.org/streams"))) { | 2489 !strcmp(xmlns, NS_XMPP_STREAMS))) { |
2490 /* Most common reason as default: */ | 2490 /* Most common reason as default: */ |
2491 SET_REASON(PURPLE_CONNECTION_ERROR_NETWORK_ERROR); | 2491 SET_REASON(PURPLE_CONNECTION_ERROR_NETWORK_ERROR); |
2492 if(xmlnode_get_child(packet, "bad-format")) { | 2492 if(xmlnode_get_child(packet, "bad-format")) { |
2493 text = _("Bad Format"); | 2493 text = _("Bad Format"); |
2494 } else if(xmlnode_get_child(packet, "bad-namespace-prefix")) { | 2494 } else if(xmlnode_get_child(packet, "bad-namespace-prefix")) { |
3265 JabberBuddyResource *jbr = (JabberBuddyResource *) iter->data; | 3265 JabberBuddyResource *jbr = (JabberBuddyResource *) iter->data; |
3266 | 3266 |
3267 if (jabber_resource_has_capability(jbr, | 3267 if (jabber_resource_has_capability(jbr, |
3268 "http://jabber.org/protocol/si/profile/file-transfer") | 3268 "http://jabber.org/protocol/si/profile/file-transfer") |
3269 && (jabber_resource_has_capability(jbr, | 3269 && (jabber_resource_has_capability(jbr, |
3270 "http://jabber.org/protocol/bytestreams") | 3270 NS_BYTESTREAMS) |
3271 || jabber_resource_has_capability(jbr, NS_IBB))) { | 3271 || jabber_resource_has_capability(jbr, NS_IBB))) { |
3272 return TRUE; | 3272 return TRUE; |
3273 } | 3273 } |
3274 } | 3274 } |
3275 return FALSE; | 3275 return FALSE; |
3477 ui_name = PACKAGE; | 3477 ui_name = PACKAGE; |
3478 | 3478 |
3479 jabber_add_identity("client", type, NULL, ui_name); | 3479 jabber_add_identity("client", type, NULL, ui_name); |
3480 | 3480 |
3481 /* initialize jabber_features list */ | 3481 /* initialize jabber_features list */ |
3482 jabber_add_feature("jabber:iq:last", 0); | 3482 jabber_add_feature(NS_LAST_ACTIVITY, 0); |
3483 jabber_add_feature("jabber:iq:oob", 0); | 3483 jabber_add_feature(NS_OOB_IQ_DATA, 0); |
3484 jabber_add_feature("urn:xmpp:time", 0); | 3484 jabber_add_feature(NS_ENTITY_TIME, 0); |
3485 jabber_add_feature("jabber:iq:version", 0); | 3485 jabber_add_feature("jabber:iq:version", 0); |
3486 jabber_add_feature("jabber:x:conference", 0); | 3486 jabber_add_feature("jabber:x:conference", 0); |
3487 jabber_add_feature("http://jabber.org/protocol/bytestreams", 0); | 3487 jabber_add_feature(NS_BYTESTREAMS, 0); |
3488 jabber_add_feature("http://jabber.org/protocol/caps", 0); | 3488 jabber_add_feature("http://jabber.org/protocol/caps", 0); |
3489 jabber_add_feature("http://jabber.org/protocol/chatstates", 0); | 3489 jabber_add_feature("http://jabber.org/protocol/chatstates", 0); |
3490 jabber_add_feature("http://jabber.org/protocol/disco#info", 0); | 3490 jabber_add_feature(NS_DISCO_INFO, 0); |
3491 jabber_add_feature("http://jabber.org/protocol/disco#items", 0); | 3491 jabber_add_feature(NS_DISCO_ITEMS, 0); |
3492 jabber_add_feature(NS_IBB, 0); | 3492 jabber_add_feature(NS_IBB, 0); |
3493 jabber_add_feature("http://jabber.org/protocol/muc", 0); | 3493 jabber_add_feature("http://jabber.org/protocol/muc", 0); |
3494 jabber_add_feature("http://jabber.org/protocol/muc#user", 0); | 3494 jabber_add_feature("http://jabber.org/protocol/muc#user", 0); |
3495 jabber_add_feature("http://jabber.org/protocol/si", 0); | 3495 jabber_add_feature("http://jabber.org/protocol/si", 0); |
3496 jabber_add_feature("http://jabber.org/protocol/si/profile/file-transfer", 0); | 3496 jabber_add_feature("http://jabber.org/protocol/si/profile/file-transfer", 0); |
3497 jabber_add_feature("http://jabber.org/protocol/xhtml-im", 0); | 3497 jabber_add_feature(NS_XHTML_IM, 0); |
3498 jabber_add_feature(NS_PING, 0); | 3498 jabber_add_feature(NS_PING, 0); |
3499 | 3499 |
3500 /* Buzz/Attention */ | 3500 /* Buzz/Attention */ |
3501 jabber_add_feature(NS_ATTENTION, jabber_buzz_isenabled); | 3501 jabber_add_feature(NS_ATTENTION, jabber_buzz_isenabled); |
3502 | 3502 |