comparison libpurple/protocols/jabber/jabber.c @ 29268:9ea6842536ba

propagate from branch 'im.pidgin.pidgin' (head dd9cb9ed28311438c0cc3c2962f1c030fb282df3) to branch 'im.pidgin.cpw.attention_ui' (head a37bbe96365f1b9bea6638cd3a2a9d41310109b0)
author Marcus Lundblad <ml@update.uu.se>
date Thu, 01 Jan 2009 21:19:11 +0000
parents a0fd6a41d127 3a4070656d61
children 4561aa5b368c
comparison
equal deleted inserted replaced
29267:58e1e1463b6e 29268:9ea6842536ba
29 #include "debug.h" 29 #include "debug.h"
30 #include "dnssrv.h" 30 #include "dnssrv.h"
31 #include "message.h" 31 #include "message.h"
32 #include "notify.h" 32 #include "notify.h"
33 #include "pluginpref.h" 33 #include "pluginpref.h"
34 #include "privacy.h"
34 #include "proxy.h" 35 #include "proxy.h"
35 #include "prpl.h" 36 #include "prpl.h"
36 #include "request.h" 37 #include "request.h"
37 #include "server.h" 38 #include "server.h"
38 #include "util.h" 39 #include "util.h"
148 149
149 static char *jabber_prep_resource(char *input) { 150 static char *jabber_prep_resource(char *input) {
150 char hostname[256]; /* current hostname */ 151 char hostname[256]; /* current hostname */
151 152
152 /* Empty resource == don't send any */ 153 /* Empty resource == don't send any */
153 if (*input == '\0') 154 if (input == NULL || *input == '\0')
154 return NULL; 155 return NULL;
155 156
156 if (strstr(input, "__HOSTNAME__") == NULL) 157 if (strstr(input, "__HOSTNAME__") == NULL)
157 return g_strdup(input); 158 return g_strdup(input);
158 159
198 requested_resource = jabber_prep_resource(js->user->resource); 199 requested_resource = jabber_prep_resource(js->user->resource);
199 200
200 if (requested_resource != NULL) { 201 if (requested_resource != NULL) {
201 resource = xmlnode_new_child(bind, "resource"); 202 resource = xmlnode_new_child(bind, "resource");
202 xmlnode_insert_data(resource, requested_resource, -1); 203 xmlnode_insert_data(resource, requested_resource, -1);
203 free(requested_resource); 204 g_free(requested_resource);
204 } 205 }
205 206
206 jabber_iq_set_callback(iq, jabber_bind_result_cb, NULL); 207 jabber_iq_set_callback(iq, jabber_bind_result_cb, NULL);
207 208
208 jabber_iq_send(iq); 209 jabber_iq_send(iq);
348 349
349 void jabber_send_raw(JabberStream *js, const char *data, int len) 350 void jabber_send_raw(JabberStream *js, const char *data, int len)
350 { 351 {
351 352
352 /* because printing a tab to debug every minute gets old */ 353 /* because printing a tab to debug every minute gets old */
353 if(strcmp(data, "\t")) 354 if(strcmp(data, "\t")) {
354 purple_debug(PURPLE_DEBUG_MISC, "jabber", "Sending%s: %s\n", 355 char *text = NULL, *last_part = NULL, *tag_start = NULL;
355 js->gsc ? " (ssl)" : "", data); 356
357 /* Because debug logs with plaintext passwords make me sad */
358 if(js->state != JABBER_STREAM_CONNECTED &&
359 /* Either <auth> or <query><password>... */
360 (((tag_start = strstr(data, "<auth ")) &&
361 strstr(data, "xmlns='urn:ietf:params:xml:ns:xmpp-sasl'")) ||
362 ((tag_start = strstr(data, "<query ")) &&
363 strstr(data, "xmlns='jabber:iq:auth'>") &&
364 (tag_start = strstr(tag_start, "<password>"))))) {
365 char *data_start, *tag_end = strchr(tag_start, '>');
366 text = g_strdup(data);
367
368 data_start = text + (tag_end - data) + 1;
369
370 last_part = strchr(data_start, '<');
371 *data_start = '\0';
372 }
373
374 purple_debug(PURPLE_DEBUG_MISC, "jabber", "Sending%s: %s%s%s\n",
375 js->gsc ? " (ssl)" : "", text ? text : data,
376 last_part ? "password removed" : "",
377 last_part ? last_part : "");
378
379 g_free(text);
380 }
356 381
357 /* If we've got a security layer, we need to encode the data, 382 /* If we've got a security layer, we need to encode the data,
358 * splitting it on the maximum buffer length negotiated */ 383 * splitting it on the maximum buffer length negotiated */
359 384
360 purple_signal_emit(my_protocol, "jabber-sending-text", js->gc, &data); 385 purple_signal_emit(my_protocol, "jabber-sending-text", js->gc, &data);
1411 purple_connection_update_progress(js->gc, _("Authenticating"), 1436 purple_connection_update_progress(js->gc, _("Authenticating"),
1412 js->gsc ? 7 : 3, JABBER_CONNECT_STEPS); 1437 js->gsc ? 7 : 3, JABBER_CONNECT_STEPS);
1413 if(js->protocol_version == JABBER_PROTO_0_9 && js->registration) { 1438 if(js->protocol_version == JABBER_PROTO_0_9 && js->registration) {
1414 jabber_register_start(js); 1439 jabber_register_start(js);
1415 } else if(js->auth_type == JABBER_AUTH_IQ_AUTH) { 1440 } else if(js->auth_type == JABBER_AUTH_IQ_AUTH) {
1441 /* with dreamhost's xmpp server at least, you have to
1442 specify a resource or you will get a "406: Not
1443 Acceptable"
1444 */
1445 if(!js->user->resource || *js->user->resource == '\0') {
1446 g_free(js->user->resource);
1447 js->user->resource = g_strdup("Home");
1448 }
1449
1416 jabber_auth_start_old(js); 1450 jabber_auth_start_old(js);
1417 } 1451 }
1418 break; 1452 break;
1419 case JABBER_STREAM_REINITIALIZING: 1453 case JABBER_STREAM_REINITIALIZING:
1420 purple_connection_update_progress(js->gc, _("Re-initializing Stream"), 1454 purple_connection_update_progress(js->gc, _("Re-initializing Stream"),
1441 void jabber_idle_set(PurpleConnection *gc, int idle) 1475 void jabber_idle_set(PurpleConnection *gc, int idle)
1442 { 1476 {
1443 JabberStream *js = gc->proto_data; 1477 JabberStream *js = gc->proto_data;
1444 1478
1445 js->idle = idle ? time(NULL) - idle : idle; 1479 js->idle = idle ? time(NULL) - idle : idle;
1480 }
1481
1482 static void jabber_blocklist_parse(JabberStream *js, xmlnode *packet, gpointer data)
1483 {
1484 xmlnode *blocklist, *item;
1485 PurpleAccount *account;
1486
1487 blocklist = xmlnode_get_child_with_namespace(packet,
1488 "blocklist", "urn:xmpp:blocking");
1489 account = purple_connection_get_account(js->gc);
1490
1491 if (blocklist == NULL)
1492 return;
1493
1494 item = xmlnode_get_child(blocklist, "item");
1495 while (item != NULL) {
1496 const char *jid = xmlnode_get_attrib(item, "jid");
1497
1498 purple_privacy_deny_add(account, jid, TRUE);
1499 item = xmlnode_get_next_twin(item);
1500 }
1501 }
1502
1503 void jabber_request_block_list(JabberStream *js)
1504 {
1505 JabberIq *iq;
1506 xmlnode *blocklist;
1507
1508 iq = jabber_iq_new(js, JABBER_IQ_GET);
1509
1510 blocklist = xmlnode_new_child(iq->node, "blocklist");
1511 xmlnode_set_namespace(blocklist, "urn:xmpp:blocking");
1512
1513 jabber_iq_set_callback(iq, jabber_blocklist_parse, NULL);
1514
1515 jabber_iq_send(iq);
1516 }
1517
1518 void jabber_add_deny(PurpleConnection *gc, const char *who)
1519 {
1520 JabberStream *js;
1521 JabberIq *iq;
1522 xmlnode *block, *item;
1523
1524 js = gc->proto_data;
1525 if (js == NULL)
1526 return;
1527
1528 if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER)
1529 {
1530 jabber_google_roster_add_deny(gc, who);
1531 return;
1532 }
1533
1534 if (!(js->server_caps & JABBER_CAP_BLOCKING))
1535 {
1536 purple_notify_error(NULL, _("Server doesn't support blocking"),
1537 _("Server doesn't support blocking"), NULL);
1538 return;
1539 }
1540
1541 iq = jabber_iq_new(js, JABBER_IQ_SET);
1542
1543 block = xmlnode_new_child(iq->node, "block");
1544 xmlnode_set_namespace(block, "urn:xmpp:blocking");
1545
1546 item = xmlnode_new_child(block, "item");
1547 xmlnode_set_attrib(item, "jid", who);
1548
1549 jabber_iq_send(iq);
1550 }
1551
1552 void jabber_rem_deny(PurpleConnection *gc, const char *who)
1553 {
1554 JabberStream *js;
1555 JabberIq *iq;
1556 xmlnode *unblock, *item;
1557
1558 js = gc->proto_data;
1559 if (js == NULL)
1560 return;
1561
1562 if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER)
1563 {
1564 jabber_google_roster_rem_deny(gc, who);
1565 return;
1566 }
1567
1568 if (!(js->server_caps & JABBER_CAP_BLOCKING))
1569 return;
1570
1571 iq = jabber_iq_new(js, JABBER_IQ_SET);
1572
1573 unblock = xmlnode_new_child(iq->node, "unblock");
1574 xmlnode_set_namespace(unblock, "urn:xmpp:blocking");
1575
1576 item = xmlnode_new_child(unblock, "item");
1577 xmlnode_set_attrib(item, "jid", who);
1578
1579 jabber_iq_send(iq);
1446 } 1580 }
1447 1581
1448 void jabber_add_feature(const char *shortname, const char *namespace, JabberFeatureEnabled cb) { 1582 void jabber_add_feature(const char *shortname, const char *namespace, JabberFeatureEnabled cb) {
1449 JabberFeature *feat; 1583 JabberFeature *feat;
1450 1584