Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/jabber.c @ 27463:f541583e31bd
More uniformity among disconnect error messages
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 06 Jul 2009 09:07:42 +0000 |
parents | a71cc338f0fd |
children | 889bf9af9706 85fa979b08c2 42360009f2e5 |
comparison
equal
deleted
inserted
replaced
27462:1bbed9fd046b | 27463:f541583e31bd |
---|---|
100 if (type == JABBER_IQ_RESULT) { | 100 if (type == JABBER_IQ_RESULT) { |
101 jabber_disco_items_server(js); | 101 jabber_disco_items_server(js); |
102 if(js->unregistration) | 102 if(js->unregistration) |
103 jabber_unregister_account_cb(js); | 103 jabber_unregister_account_cb(js); |
104 } else { | 104 } else { |
105 purple_connection_error_reason (js->gc, | 105 purple_connection_error_reason(js->gc, |
106 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 106 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
107 ("Error initializing session")); | 107 ("Error initializing session")); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
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 JabberBuddy *my_jb = NULL; | 135 JabberBuddy *my_jb = NULL; |
136 jabber_id_free(js->user); | 136 jabber_id_free(js->user); |
137 if(!(js->user = jabber_id_new(full_jid))) { | 137 if(!(js->user = jabber_id_new(full_jid))) { |
138 purple_connection_error_reason (js->gc, | 138 purple_connection_error_reason(js->gc, |
139 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 139 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
140 _("Invalid response from server.")); | 140 _("Invalid response from server")); |
141 } | 141 } |
142 if((my_jb = jabber_buddy_find(js, full_jid, TRUE))) | 142 if((my_jb = jabber_buddy_find(js, full_jid, TRUE))) |
143 my_jb->subscription |= JABBER_SUB_BOTH; | 143 my_jb->subscription |= JABBER_SUB_BOTH; |
144 | 144 |
145 purple_connection_set_display_name(js->gc, full_jid); | 145 purple_connection_set_display_name(js->gc, full_jid); |
147 g_free(full_jid); | 147 g_free(full_jid); |
148 } | 148 } |
149 } else { | 149 } else { |
150 PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; | 150 PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; |
151 char *msg = jabber_parse_error(js, packet, &reason); | 151 char *msg = jabber_parse_error(js, packet, &reason); |
152 purple_connection_error_reason (js->gc, reason, msg); | 152 purple_connection_error_reason(js->gc, reason, msg); |
153 g_free(msg); | 153 g_free(msg); |
154 } | 154 } |
155 | 155 |
156 jabber_session_init(js); | 156 jabber_session_init(js); |
157 } | 157 } |
194 if(xmlnode_get_child(packet, "starttls")) { | 194 if(xmlnode_get_child(packet, "starttls")) { |
195 if(jabber_process_starttls(js, packet)) | 195 if(jabber_process_starttls(js, packet)) |
196 | 196 |
197 return; | 197 return; |
198 } else if(purple_account_get_bool(js->gc->account, "require_tls", FALSE) && !jabber_stream_is_ssl(js)) { | 198 } else if(purple_account_get_bool(js->gc->account, "require_tls", FALSE) && !jabber_stream_is_ssl(js)) { |
199 purple_connection_error_reason (js->gc, | 199 purple_connection_error_reason(js->gc, |
200 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, | 200 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, |
201 _("You require encryption, but it is not available on this server.")); | 201 _("You require encryption, but it is not available on this server.")); |
202 return; | 202 return; |
203 } | 203 } |
204 | 204 |
236 static void jabber_stream_handle_error(JabberStream *js, xmlnode *packet) | 236 static void jabber_stream_handle_error(JabberStream *js, xmlnode *packet) |
237 { | 237 { |
238 PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; | 238 PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; |
239 char *msg = jabber_parse_error(js, packet, &reason); | 239 char *msg = jabber_parse_error(js, packet, &reason); |
240 | 240 |
241 purple_connection_error_reason (js->gc, reason, msg); | 241 purple_connection_error_reason(js->gc, reason, msg); |
242 | 242 |
243 g_free(msg); | 243 g_free(msg); |
244 } | 244 } |
245 | 245 |
246 static void tls_init(JabberStream *js); | 246 static void tls_init(JabberStream *js); |
318 ret = jabber_do_send(js, js->write_buffer->outptr, writelen); | 318 ret = jabber_do_send(js, js->write_buffer->outptr, writelen); |
319 | 319 |
320 if (ret < 0 && errno == EAGAIN) | 320 if (ret < 0 && errno == EAGAIN) |
321 return; | 321 return; |
322 else if (ret <= 0) { | 322 else if (ret <= 0) { |
323 purple_connection_error_reason (js->gc, | 323 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), |
324 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 324 g_strerror(errno)); |
325 _("Write error")); | 325 purple_connection_error_reason(js->gc, |
326 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); | |
327 g_free(tmp); | |
326 return; | 328 return; |
327 } | 329 } |
328 | 330 |
329 purple_circ_buffer_mark_read(js->write_buffer, ret); | 331 purple_circ_buffer_mark_read(js->write_buffer, ret); |
330 } | 332 } |
343 ret = -1; | 345 ret = -1; |
344 errno = EAGAIN; | 346 errno = EAGAIN; |
345 } | 347 } |
346 | 348 |
347 if (ret < 0 && errno != EAGAIN) { | 349 if (ret < 0 && errno != EAGAIN) { |
348 purple_connection_error_reason (js->gc, | 350 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), |
349 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 351 g_strerror(errno)); |
350 _("Write error")); | 352 purple_connection_error_reason(js->gc, |
353 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); | |
354 g_free(tmp); | |
351 success = FALSE; | 355 success = FALSE; |
352 } else if (ret < len) { | 356 } else if (ret < len) { |
353 if (ret < 0) | 357 if (ret < 0) |
354 ret = 0; | 358 ret = 0; |
355 if (js->writeh == 0) | 359 if (js->writeh == 0) |
471 | 475 |
472 static gboolean jabber_keepalive_timeout(PurpleConnection *gc) | 476 static gboolean jabber_keepalive_timeout(PurpleConnection *gc) |
473 { | 477 { |
474 JabberStream *js = gc->proto_data; | 478 JabberStream *js = gc->proto_data; |
475 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 479 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
476 _("Ping timeout")); | 480 _("Ping timed out")); |
477 js->keepalive_timeout = 0; | 481 js->keepalive_timeout = 0; |
478 return FALSE; | 482 return FALSE; |
479 } | 483 } |
480 | 484 |
481 void jabber_keepalive(PurpleConnection *gc) | 485 void jabber_keepalive(PurpleConnection *gc) |
514 } | 518 } |
515 | 519 |
516 if(len < 0 && errno == EAGAIN) | 520 if(len < 0 && errno == EAGAIN) |
517 return; | 521 return; |
518 else { | 522 else { |
523 gchar *tmp; | |
519 if (len == 0) | 524 if (len == 0) |
520 purple_debug_info("jabber", "Server closed the connection.\n"); | 525 tmp = g_strdup_printf(_("Server closed the connection")); |
521 else | 526 else |
522 purple_debug_info("jabber", "Disconnected: %s\n", g_strerror(errno)); | 527 tmp = g_strdup_printf(_("Lost connection with server: %s"), |
523 purple_connection_error_reason (js->gc, | 528 g_strerror(errno)); |
524 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 529 purple_connection_error_reason(js->gc, |
525 _("Read Error")); | 530 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); |
531 g_free(tmp); | |
526 } | 532 } |
527 } | 533 } |
528 | 534 |
529 static void | 535 static void |
530 jabber_recv_cb(gpointer data, gint source, PurpleInputCondition condition) | 536 jabber_recv_cb(gpointer data, gint source, PurpleInputCondition condition) |
559 if(js->reinit) | 565 if(js->reinit) |
560 jabber_stream_init(js); | 566 jabber_stream_init(js); |
561 } else if(len < 0 && errno == EAGAIN) { | 567 } else if(len < 0 && errno == EAGAIN) { |
562 return; | 568 return; |
563 } else { | 569 } else { |
570 gchar *tmp; | |
564 if (len == 0) | 571 if (len == 0) |
565 purple_debug_info("jabber", "Server closed the connection.\n"); | 572 tmp = g_strdup_printf(_("Server closed the connection")); |
566 else | 573 else |
567 purple_debug_info("jabber", "Disconnected: %s\n", g_strerror(errno)); | 574 tmp = g_strdup_printf(_("Lost connection with server: %s"), |
568 purple_connection_error_reason (js->gc, | 575 g_strerror(errno)); |
569 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 576 purple_connection_error_reason(js->gc, |
570 _("Read Error")); | 577 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); |
578 g_free(tmp); | |
571 } | 579 } |
572 } | 580 } |
573 | 581 |
574 static void | 582 static void |
575 jabber_login_callback_ssl(gpointer data, PurpleSslConnection *gsc, | 583 jabber_login_callback_ssl(gpointer data, PurpleSslConnection *gsc, |
601 JabberStream *js = data; | 609 JabberStream *js = data; |
602 | 610 |
603 js->srv_query_data = NULL; | 611 js->srv_query_data = NULL; |
604 | 612 |
605 if (responses == NULL) { | 613 if (responses == NULL) { |
606 gchar *tmp; | 614 purple_connection_error_reason(js->gc, |
607 tmp = g_strdup_printf(_("Could not find alternative XMPP connection methods after failing to connect directly.\n")); | 615 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
608 purple_connection_error_reason (js->gc, | 616 _("Unable to find alternative XMPP connection " |
609 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); | 617 "methods after failing to connect directly.")); |
610 g_free(tmp); | |
611 return; | 618 return; |
612 } | 619 } |
613 | 620 |
614 while (responses) { | 621 while (responses) { |
615 PurpleTxtResponse *resp = responses->data; | 622 PurpleTxtResponse *resp = responses->data; |
707 js->serverFQDN = g_strdup(host); | 714 js->serverFQDN = g_strdup(host); |
708 | 715 |
709 if (purple_proxy_connect(js->gc, js->gc->account, host, | 716 if (purple_proxy_connect(js->gc, js->gc->account, host, |
710 port, jabber_login_callback, js->gc) == NULL) { | 717 port, jabber_login_callback, js->gc) == NULL) { |
711 if (fatal_failure) { | 718 if (fatal_failure) { |
712 purple_connection_error_reason (js->gc, | 719 purple_connection_error_reason(js->gc, |
713 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 720 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
714 _("Unable to create socket")); | 721 _("Unable to connect")); |
715 } | 722 } |
716 | 723 |
717 return FALSE; | 724 return FALSE; |
718 } | 725 } |
719 | 726 |
794 presence = purple_account_get_presence(account); | 801 presence = purple_account_get_presence(account); |
795 if (purple_presence_is_idle(presence)) | 802 if (purple_presence_is_idle(presence)) |
796 js->idle = purple_presence_get_idle_time(presence); | 803 js->idle = purple_presence_get_idle_time(presence); |
797 | 804 |
798 if(!js->user) { | 805 if(!js->user) { |
799 purple_connection_error_reason (gc, | 806 purple_connection_error_reason(gc, |
800 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, | 807 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, |
801 _("Invalid XMPP ID")); | 808 _("Invalid XMPP ID")); |
802 return; | 809 return; |
803 } | 810 } |
804 | 811 |
805 if (!js->user->domain || *(js->user->domain) == '\0') { | 812 if (!js->user->domain || *(js->user->domain) == '\0') { |
806 purple_connection_error_reason (gc, | 813 purple_connection_error_reason(gc, |
807 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, | 814 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, |
808 _("Invalid XMPP ID. Domain must be set.")); | 815 _("Invalid XMPP ID. Domain must be set.")); |
809 return; | 816 return; |
810 } | 817 } |
811 | 818 |
833 js->use_bosh = TRUE; | 840 js->use_bosh = TRUE; |
834 js->bosh = jabber_bosh_connection_init(js, bosh_url); | 841 js->bosh = jabber_bosh_connection_init(js, bosh_url); |
835 if (js->bosh) | 842 if (js->bosh) |
836 jabber_bosh_connection_connect(js->bosh); | 843 jabber_bosh_connection_connect(js->bosh); |
837 else { | 844 else { |
838 purple_connection_error_reason (js->gc, | 845 purple_connection_error_reason(js->gc, |
839 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, | 846 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, |
840 _("Malformed BOSH URL")); | 847 _("Malformed BOSH URL")); |
841 } | 848 } |
842 | 849 |
843 return; | 850 return; |
851 js->gsc = purple_ssl_connect(js->gc->account, | 858 js->gsc = purple_ssl_connect(js->gc->account, |
852 js->certificate_CN, | 859 js->certificate_CN, |
853 purple_account_get_int(account, "port", 5223), jabber_login_callback_ssl, | 860 purple_account_get_int(account, "port", 5223), jabber_login_callback_ssl, |
854 jabber_ssl_connect_failure, js->gc); | 861 jabber_ssl_connect_failure, js->gc); |
855 if (!js->gsc) { | 862 if (!js->gsc) { |
856 purple_connection_error_reason (js->gc, | 863 purple_connection_error_reason(js->gc, |
857 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, | 864 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, |
858 _("Unable to establish SSL connection")); | 865 _("Unable to establish SSL connection")); |
859 } | 866 } |
860 } else { | 867 } else { |
861 purple_connection_error_reason (js->gc, | 868 purple_connection_error_reason(js->gc, |
862 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, | 869 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, |
863 _("SSL support unavailable")); | 870 _("SSL support unavailable")); |
864 } | 871 } |
865 | 872 |
866 return; | 873 return; |
1302 js->next_id = g_random_int(); | 1309 js->next_id = g_random_int(); |
1303 js->old_length = 0; | 1310 js->old_length = 0; |
1304 js->keepalive_timeout = 0; | 1311 js->keepalive_timeout = 0; |
1305 | 1312 |
1306 if(!js->user) { | 1313 if(!js->user) { |
1307 purple_connection_error_reason (gc, | 1314 purple_connection_error_reason(gc, |
1308 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, | 1315 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, |
1309 _("Invalid XMPP ID")); | 1316 _("Invalid XMPP ID")); |
1310 return; | 1317 return; |
1311 } | 1318 } |
1312 | 1319 |
1327 /* TODO: Just use purple_url_parse? */ | 1334 /* TODO: Just use purple_url_parse? */ |
1328 if (!g_ascii_strncasecmp(connect_server, "http://", 7) || !g_ascii_strncasecmp(connect_server, "https://", 8)) { | 1335 if (!g_ascii_strncasecmp(connect_server, "http://", 7) || !g_ascii_strncasecmp(connect_server, "https://", 8)) { |
1329 js->use_bosh = TRUE; | 1336 js->use_bosh = TRUE; |
1330 js->bosh = jabber_bosh_connection_init(js, connect_server); | 1337 js->bosh = jabber_bosh_connection_init(js, connect_server); |
1331 if (!js->bosh) { | 1338 if (!js->bosh) { |
1332 purple_connection_error_reason (js->gc, | 1339 purple_connection_error_reason(js->gc, |
1333 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, | 1340 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, |
1334 _("Malformed BOSH Connect Server")); | 1341 _("Malformed BOSH Connect Server")); |
1335 return; | 1342 return; |
1336 } | 1343 } |
1337 jabber_bosh_connection_connect(js->bosh); | 1344 jabber_bosh_connection_connect(js->bosh); |
1344 if(purple_ssl_is_supported()) { | 1351 if(purple_ssl_is_supported()) { |
1345 js->gsc = purple_ssl_connect(account, server, | 1352 js->gsc = purple_ssl_connect(account, server, |
1346 purple_account_get_int(account, "port", 5222), | 1353 purple_account_get_int(account, "port", 5222), |
1347 jabber_login_callback_ssl, jabber_ssl_connect_failure, gc); | 1354 jabber_login_callback_ssl, jabber_ssl_connect_failure, gc); |
1348 if (!js->gsc) { | 1355 if (!js->gsc) { |
1349 purple_connection_error_reason (js->gc, | 1356 purple_connection_error_reason(js->gc, |
1350 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, | 1357 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, |
1351 _("Unable to establish SSL connection")); | 1358 _("Unable to establish SSL connection")); |
1352 } | 1359 } |
1353 } else { | 1360 } else { |
1354 purple_connection_error_reason (gc, | 1361 purple_connection_error_reason(gc, |
1355 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, | 1362 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, |
1356 _("SSL support unavailable")); | 1363 _("SSL support unavailable")); |
1357 } | 1364 } |
1358 | 1365 |
1359 return; | 1366 return; |