Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/jabber.c @ 28902:08a52bdd9619
merged with im.pidgin.pidgin
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sun, 08 Nov 2009 02:21:28 +0900 |
parents | 3e5a37c743df 96ba7fd24177 |
children | 0399f8ef665a |
comparison
equal
deleted
inserted
replaced
28887:4b3ef6752037 | 28902:08a52bdd9619 |
---|---|
66 #include "adhoccommands.h" | 66 #include "adhoccommands.h" |
67 | 67 |
68 #include "jingle/jingle.h" | 68 #include "jingle/jingle.h" |
69 #include "jingle/rtp.h" | 69 #include "jingle/rtp.h" |
70 | 70 |
71 PurplePlugin *jabber_plugin = NULL; | |
72 GList *jabber_features = NULL; | 71 GList *jabber_features = NULL; |
73 GList *jabber_identities = NULL; | 72 GList *jabber_identities = NULL; |
74 GSList *jabber_cmds = NULL; | 73 static GSList *jabber_cmds = NULL; |
75 | 74 |
76 static void jabber_unregister_account_cb(JabberStream *js); | 75 static void jabber_unregister_account_cb(JabberStream *js); |
77 static void try_srv_connect(JabberStream *js); | 76 static void try_srv_connect(JabberStream *js); |
78 | 77 |
79 static void jabber_stream_init(JabberStream *js) | 78 static void jabber_stream_init(JabberStream *js) |
198 if(xmlnode_get_child(packet, "starttls")) { | 197 if(xmlnode_get_child(packet, "starttls")) { |
199 if(jabber_process_starttls(js, packet)) { | 198 if(jabber_process_starttls(js, packet)) { |
200 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING_ENCRYPTION); | 199 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING_ENCRYPTION); |
201 return; | 200 return; |
202 } | 201 } |
203 } else if(purple_account_get_bool(js->gc->account, "require_tls", FALSE) && !jabber_stream_is_ssl(js)) { | 202 } else if(purple_account_get_bool(js->gc->account, "require_tls", JABBER_DEFAULT_REQUIRE_TLS) && !jabber_stream_is_ssl(js)) { |
204 purple_connection_error_reason(js->gc, | 203 purple_connection_error_reason(js->gc, |
205 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, | 204 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, |
206 _("You require encryption, but it is not available on this server.")); | 205 _("You require encryption, but it is not available on this server.")); |
207 return; | 206 return; |
208 } | 207 } |
253 | 252 |
254 void jabber_process_packet(JabberStream *js, xmlnode **packet) | 253 void jabber_process_packet(JabberStream *js, xmlnode **packet) |
255 { | 254 { |
256 const char *xmlns; | 255 const char *xmlns; |
257 | 256 |
258 purple_signal_emit(jabber_plugin, "jabber-receiving-xmlnode", js->gc, packet); | 257 purple_signal_emit(purple_connection_get_prpl(js->gc), "jabber-receiving-xmlnode", js->gc, packet); |
259 | 258 |
260 /* if the signal leaves us with a null packet, we're done */ | 259 /* if the signal leaves us with a null packet, we're done */ |
261 if(NULL == *packet) | 260 if(NULL == *packet) |
262 return; | 261 return; |
263 | 262 |
292 if (js->state == JABBER_STREAM_INITIALIZING_ENCRYPTION && !js->gsc) | 291 if (js->state == JABBER_STREAM_INITIALIZING_ENCRYPTION && !js->gsc) |
293 tls_init(js); | 292 tls_init(js); |
294 else | 293 else |
295 purple_debug_warning("jabber", "Ignoring spurious <proceed/>\n"); | 294 purple_debug_warning("jabber", "Ignoring spurious <proceed/>\n"); |
296 } else { | 295 } else { |
297 purple_debug(PURPLE_DEBUG_WARNING, "jabber", "Unknown packet: %s\n", | 296 purple_debug_warning("jabber", "Unknown packet: %s\n", (*packet)->name); |
298 (*packet)->name); | |
299 } | 297 } |
300 } | 298 } |
301 | 299 |
302 static int jabber_do_send(JabberStream *js, const char *data, int len) | 300 static int jabber_do_send(JabberStream *js, const char *data, int len) |
303 { | 301 { |
375 return success; | 373 return success; |
376 } | 374 } |
377 | 375 |
378 void jabber_send_raw(JabberStream *js, const char *data, int len) | 376 void jabber_send_raw(JabberStream *js, const char *data, int len) |
379 { | 377 { |
380 | |
381 /* because printing a tab to debug every minute gets old */ | 378 /* because printing a tab to debug every minute gets old */ |
382 if(strcmp(data, "\t")) { | 379 if(strcmp(data, "\t")) { |
380 const char *username; | |
383 char *text = NULL, *last_part = NULL, *tag_start = NULL; | 381 char *text = NULL, *last_part = NULL, *tag_start = NULL; |
384 | 382 |
385 /* Because debug logs with plaintext passwords make me sad */ | 383 /* Because debug logs with plaintext passwords make me sad */ |
386 if(js->state != JABBER_STREAM_CONNECTED && | 384 if(js->state != JABBER_STREAM_CONNECTED && |
387 /* Either <auth> or <query><password>... */ | 385 /* Either <auth> or <query><password>... */ |
402 | 400 |
403 last_part = strchr(data_start, '<'); | 401 last_part = strchr(data_start, '<'); |
404 *data_start = '\0'; | 402 *data_start = '\0'; |
405 } | 403 } |
406 | 404 |
407 purple_debug(PURPLE_DEBUG_MISC, "jabber", "Sending%s: %s%s%s\n", | 405 username = purple_connection_get_display_name(js->gc); |
408 jabber_stream_is_ssl(js) ? " (ssl)" : "", text ? text : data, | 406 if (!username) |
407 username = purple_account_get_username(purple_connection_get_account(js->gc)); | |
408 | |
409 purple_debug_misc("jabber", "Sending%s (%s): %s%s%s\n", | |
410 jabber_stream_is_ssl(js) ? " (ssl)" : "", username, | |
411 text ? text : data, | |
409 last_part ? "password removed" : "", | 412 last_part ? "password removed" : "", |
410 last_part ? last_part : ""); | 413 last_part ? last_part : ""); |
411 | 414 |
412 g_free(text); | 415 g_free(text); |
413 } | 416 } |
414 | 417 |
415 /* If we've got a security layer, we need to encode the data, | 418 /* If we've got a security layer, we need to encode the data, |
416 * splitting it on the maximum buffer length negotiated */ | 419 * splitting it on the maximum buffer length negotiated */ |
417 | 420 |
418 purple_signal_emit(jabber_plugin, "jabber-sending-text", js->gc, &data); | 421 purple_signal_emit(purple_connection_get_prpl(js->gc), "jabber-sending-text", js->gc, &data); |
419 if (data == NULL) | 422 if (data == NULL) |
420 return; | 423 return; |
421 | 424 |
422 #ifdef HAVE_CYRUS_SASL | 425 #ifdef HAVE_CYRUS_SASL |
423 if (js->sasl_maxbuf>0) { | 426 if (js->sasl_maxbuf>0) { |
485 g_free(txt); g_free(utf); | 488 g_free(txt); g_free(utf); |
486 } | 489 } |
487 | 490 |
488 void jabber_send(JabberStream *js, xmlnode *packet) | 491 void jabber_send(JabberStream *js, xmlnode *packet) |
489 { | 492 { |
490 purple_signal_emit(jabber_plugin, "jabber-sending-xmlnode", js->gc, &packet); | 493 purple_signal_emit(purple_connection_get_prpl(js->gc), "jabber-sending-xmlnode", js->gc, &packet); |
491 } | 494 } |
492 | 495 |
493 static gboolean jabber_keepalive_timeout(PurpleConnection *gc) | 496 static gboolean jabber_keepalive_timeout(PurpleConnection *gc) |
494 { | 497 { |
495 JabberStream *js = gc->proto_data; | 498 JabberStream *js = gc->proto_data; |
526 } | 529 } |
527 | 530 |
528 while((len = purple_ssl_read(gsc, buf, sizeof(buf) - 1)) > 0) { | 531 while((len = purple_ssl_read(gsc, buf, sizeof(buf) - 1)) > 0) { |
529 gc->last_received = time(NULL); | 532 gc->last_received = time(NULL); |
530 buf[len] = '\0'; | 533 buf[len] = '\0'; |
531 purple_debug(PURPLE_DEBUG_INFO, "jabber", "Recv (ssl)(%d): %s\n", len, buf); | 534 purple_debug_info("jabber", "Recv (ssl)(%d): %s\n", len, buf); |
532 jabber_parser_process(js, buf, len); | 535 jabber_parser_process(js, buf, len); |
533 if(js->reinit) | 536 if(js->reinit) |
534 jabber_stream_init(js); | 537 jabber_stream_init(js); |
535 } | 538 } |
536 | 539 |
566 if (js->sasl_maxbuf>0) { | 569 if (js->sasl_maxbuf>0) { |
567 const char *out; | 570 const char *out; |
568 unsigned int olen; | 571 unsigned int olen; |
569 sasl_decode(js->sasl, buf, len, &out, &olen); | 572 sasl_decode(js->sasl, buf, len, &out, &olen); |
570 if (olen>0) { | 573 if (olen>0) { |
571 purple_debug(PURPLE_DEBUG_INFO, "jabber", "RecvSASL (%u): %s\n", olen, out); | 574 purple_debug_info("jabber", "RecvSASL (%u): %s\n", olen, out); |
572 jabber_parser_process(js,out,olen); | 575 jabber_parser_process(js,out,olen); |
573 if(js->reinit) | 576 if(js->reinit) |
574 jabber_stream_init(js); | 577 jabber_stream_init(js); |
575 } | 578 } |
576 return; | 579 return; |
577 } | 580 } |
578 #endif | 581 #endif |
579 buf[len] = '\0'; | 582 buf[len] = '\0'; |
580 purple_debug(PURPLE_DEBUG_INFO, "jabber", "Recv (%d): %s\n", len, buf); | 583 purple_debug_info("jabber", "Recv (%d): %s\n", len, buf); |
581 jabber_parser_process(js, buf, len); | 584 jabber_parser_process(js, buf, len); |
582 if(js->reinit) | 585 if(js->reinit) |
583 jabber_stream_init(js); | 586 jabber_stream_init(js); |
584 } else if(len < 0 && errno == EAGAIN) { | 587 } else if(len < 0 && errno == EAGAIN) { |
585 return; | 588 return; |
3402 const gchar *ui_type; | 3405 const gchar *ui_type; |
3403 const gchar *type = "pc"; /* default client type, if unknown or | 3406 const gchar *type = "pc"; /* default client type, if unknown or |
3404 unspecified */ | 3407 unspecified */ |
3405 const gchar *ui_name = NULL; | 3408 const gchar *ui_name = NULL; |
3406 | 3409 |
3407 jabber_plugin = plugin; | |
3408 | |
3409 ui_type = ui_info ? g_hash_table_lookup(ui_info, "client_type") : NULL; | 3410 ui_type = ui_info ? g_hash_table_lookup(ui_info, "client_type") : NULL; |
3410 if (ui_type) { | 3411 if (ui_type) { |
3411 if (strcmp(ui_type, "pc") == 0 || | 3412 if (strcmp(ui_type, "pc") == 0 || |
3412 strcmp(ui_type, "console") == 0 || | 3413 strcmp(ui_type, "console") == 0 || |
3413 strcmp(ui_type, "phone") == 0 || | 3414 strcmp(ui_type, "phone") == 0 || |
3493 purple_value_new(PURPLE_TYPE_STRING), /* node */ | 3494 purple_value_new(PURPLE_TYPE_STRING), /* node */ |
3494 purple_value_new(PURPLE_TYPE_STRING)); /* namespace */ | 3495 purple_value_new(PURPLE_TYPE_STRING)); /* namespace */ |
3495 } | 3496 } |
3496 | 3497 |
3497 void | 3498 void |
3498 jabber_uninit_plugin(void) | 3499 jabber_uninit_plugin(PurplePlugin *plugin) |
3499 { | 3500 { |
3500 purple_plugin_ipc_unregister_all(jabber_plugin); | 3501 purple_plugin_ipc_unregister_all(plugin); |
3501 | 3502 |
3502 jabber_features_destroy(); | 3503 jabber_features_destroy(); |
3503 jabber_identities_destroy(); | 3504 jabber_identities_destroy(); |
3504 } | 3505 } |