comparison libpurple/protocols/simple/simple.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 b1847ec1ba5f
children 2cb6ea4420a0
comparison
equal deleted inserted replaced
27462:1bbed9fd046b 27463:f541583e31bd
426 426
427 written = write(sip->fd, sip->txbuf->outptr, max_write); 427 written = write(sip->fd, sip->txbuf->outptr, max_write);
428 428
429 if(written < 0 && errno == EAGAIN) 429 if(written < 0 && errno == EAGAIN)
430 written = 0; 430 written = 0;
431 else if(written <= 0) { 431 else if (written <= 0) {
432 /*TODO: do we really want to disconnect on a failure to write?*/ 432 /*TODO: do we really want to disconnect on a failure to write?*/
433 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"),
434 g_strerror(errno));
433 purple_connection_error_reason(gc, 435 purple_connection_error_reason(gc,
434 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 436 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
435 _("Could not write")); 437 g_free(tmp);
436 return; 438 return;
437 } 439 }
438 440
439 purple_circ_buffer_mark_read(sip->txbuf, written); 441 purple_circ_buffer_mark_read(sip->txbuf, written);
440 } 442 }
441 443
442 static void simple_input_cb(gpointer data, gint source, PurpleInputCondition cond); 444 static void simple_input_cb(gpointer data, gint source, PurpleInputCondition cond);
443 445
444 static void send_later_cb(gpointer data, gint source, const gchar *error) { 446 static void send_later_cb(gpointer data, gint source, const gchar *error_message) {
445 PurpleConnection *gc = data; 447 PurpleConnection *gc = data;
446 struct simple_account_data *sip; 448 struct simple_account_data *sip;
447 struct sip_connection *conn; 449 struct sip_connection *conn;
448 450
449 if(source < 0) { 451 if(source < 0) {
452 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"),
453 error_message);
450 purple_connection_error_reason(gc, 454 purple_connection_error_reason(gc,
451 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 455 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
452 _("Could not connect")); 456 g_free(tmp);
453 return; 457 return;
454 } 458 }
455 459
456 sip = gc->proto_data; 460 sip = gc->proto_data;
457 sip->fd = source; 461 sip->fd = source;
473 struct simple_account_data *sip = gc->proto_data; 477 struct simple_account_data *sip = gc->proto_data;
474 478
475 if(!sip->connecting) { 479 if(!sip->connecting) {
476 purple_debug_info("simple", "connecting to %s port %d\n", sip->realhostname ? sip->realhostname : "{NULL}", sip->realport); 480 purple_debug_info("simple", "connecting to %s port %d\n", sip->realhostname ? sip->realhostname : "{NULL}", sip->realport);
477 if (purple_proxy_connect(gc, sip->account, sip->realhostname, sip->realport, send_later_cb, gc) == NULL) { 481 if (purple_proxy_connect(gc, sip->account, sip->realhostname, sip->realport, send_later_cb, gc) == NULL) {
478 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Couldn't create socket")); 482 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Unable to connect"));
479 } 483 }
480 sip->connecting = TRUE; 484 sip->connecting = TRUE;
481 } 485 }
482 486
483 if(purple_circ_buffer_get_max_read(sip->txbuf) > 0) 487 if(purple_circ_buffer_get_max_read(sip->txbuf) > 0)
1118 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { 1122 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) {
1119 if (!purple_account_get_remember_password(sip->gc->account)) 1123 if (!purple_account_get_remember_password(sip->gc->account))
1120 purple_account_set_password(sip->gc->account, NULL); 1124 purple_account_set_password(sip->gc->account, NULL);
1121 purple_connection_error_reason(sip->gc, 1125 purple_connection_error_reason(sip->gc,
1122 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, 1126 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
1123 _("Incorrect password.")); 1127 _("Incorrect password"));
1124 return TRUE; 1128 return TRUE;
1125 } 1129 }
1126 tmp = sipmsg_find_header(msg, "WWW-Authenticate"); 1130 tmp = sipmsg_find_header(msg, "WWW-Authenticate");
1127 fill_auth(sip, tmp, &sip->registrar); 1131 fill_auth(sip, tmp, &sip->registrar);
1128 sip->registerstatus = SIMPLE_REGISTER_RETRY; 1132 sip->registerstatus = SIMPLE_REGISTER_RETRY;
1133 if (sip->registerstatus != SIMPLE_REGISTER_RETRY) { 1137 if (sip->registerstatus != SIMPLE_REGISTER_RETRY) {
1134 purple_debug_info("simple", "Unrecognized return code for REGISTER.\n"); 1138 purple_debug_info("simple", "Unrecognized return code for REGISTER.\n");
1135 if (sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { 1139 if (sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) {
1136 purple_connection_error_reason(sip->gc, 1140 purple_connection_error_reason(sip->gc,
1137 PURPLE_CONNECTION_ERROR_OTHER_ERROR, 1141 PURPLE_CONNECTION_ERROR_OTHER_ERROR,
1138 _("Unknown server response.")); 1142 _("Unknown server response"));
1139 return TRUE; 1143 return TRUE;
1140 } 1144 }
1141 sip->registerstatus = SIMPLE_REGISTER_RETRY; 1145 sip->registerstatus = SIMPLE_REGISTER_RETRY;
1142 do_register(sip); 1146 do_register(sip);
1143 } 1147 }
1727 PurpleConnection *gc = data; 1731 PurpleConnection *gc = data;
1728 struct simple_account_data *sip; 1732 struct simple_account_data *sip;
1729 struct sip_connection *conn; 1733 struct sip_connection *conn;
1730 1734
1731 if(source < 0) { 1735 if(source < 0) {
1736 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"),
1737 error_message);
1732 purple_connection_error_reason(gc, 1738 purple_connection_error_reason(gc,
1733 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1739 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
1734 _("Could not connect")); 1740 g_free(tmp);
1735 return; 1741 return;
1736 } 1742 }
1737 1743
1738 sip = gc->proto_data; 1744 sip = gc->proto_data;
1739 sip->fd = source; 1745 sip->fd = source;
1765 sip->listen_data = NULL; 1771 sip->listen_data = NULL;
1766 1772
1767 if(listenfd == -1) { 1773 if(listenfd == -1) {
1768 purple_connection_error_reason(sip->gc, 1774 purple_connection_error_reason(sip->gc,
1769 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1775 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1770 _("Could not create listen socket")); 1776 _("Unable to create listen socket"));
1771 return; 1777 return;
1772 } 1778 }
1773 1779
1774 sip->fd = listenfd; 1780 sip->fd = listenfd;
1775 1781
1790 sip->query_data = NULL; 1796 sip->query_data = NULL;
1791 1797
1792 if (!hosts || !hosts->data) { 1798 if (!hosts || !hosts->data) {
1793 purple_connection_error_reason(sip->gc, 1799 purple_connection_error_reason(sip->gc,
1794 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1800 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1795 _("Couldn't resolve host")); 1801 _("Unable to resolve hostname"));
1796 return; 1802 return;
1797 } 1803 }
1798 1804
1799 addr_size = GPOINTER_TO_INT(hosts->data); 1805 addr_size = GPOINTER_TO_INT(hosts->data);
1800 hosts = g_slist_remove(hosts, hosts->data); 1806 hosts = g_slist_remove(hosts, hosts->data);
1811 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_DGRAM, 1817 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_DGRAM,
1812 simple_udp_host_resolved_listen_cb, sip); 1818 simple_udp_host_resolved_listen_cb, sip);
1813 if (sip->listen_data == NULL) { 1819 if (sip->listen_data == NULL) {
1814 purple_connection_error_reason(sip->gc, 1820 purple_connection_error_reason(sip->gc,
1815 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1821 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1816 _("Could not create listen socket")); 1822 _("Unable to create listen socket"));
1817 return; 1823 return;
1818 } 1824 }
1819 } 1825 }
1820 1826
1821 static void 1827 static void
1826 1832
1827 sip->listenfd = listenfd; 1833 sip->listenfd = listenfd;
1828 if(sip->listenfd == -1) { 1834 if(sip->listenfd == -1) {
1829 purple_connection_error_reason(sip->gc, 1835 purple_connection_error_reason(sip->gc,
1830 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1836 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1831 _("Could not create listen socket")); 1837 _("Unable to create listen socket"));
1832 return; 1838 return;
1833 } 1839 }
1834 1840
1835 purple_debug_info("simple", "listenfd: %d\n", sip->listenfd); 1841 purple_debug_info("simple", "listenfd: %d\n", sip->listenfd);
1836 sip->listenport = purple_network_get_port_from_fd(sip->listenfd); 1842 sip->listenport = purple_network_get_port_from_fd(sip->listenfd);
1841 /* open tcp connection to the server */ 1847 /* open tcp connection to the server */
1842 if (purple_proxy_connect(sip->gc, sip->account, sip->realhostname, 1848 if (purple_proxy_connect(sip->gc, sip->account, sip->realhostname,
1843 sip->realport, login_cb, sip->gc) == NULL) { 1849 sip->realport, login_cb, sip->gc) == NULL) {
1844 purple_connection_error_reason(sip->gc, 1850 purple_connection_error_reason(sip->gc,
1845 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1851 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1846 _("Couldn't create socket")); 1852 _("Unable to connect"));
1847 } 1853 }
1848 } 1854 }
1849 1855
1850 static void srvresolved(PurpleSrvResponse *resp, int results, gpointer data) { 1856 static void srvresolved(PurpleSrvResponse *resp, int results, gpointer data) {
1851 struct simple_account_data *sip; 1857 struct simple_account_data *sip;
1881 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_STREAM, 1887 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_STREAM,
1882 simple_tcp_connect_listen_cb, sip); 1888 simple_tcp_connect_listen_cb, sip);
1883 if (sip->listen_data == NULL) { 1889 if (sip->listen_data == NULL) {
1884 purple_connection_error_reason(sip->gc, 1890 purple_connection_error_reason(sip->gc,
1885 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1891 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1886 _("Could not create listen socket")); 1892 _("Unable to create listen socket"));
1887 return; 1893 return;
1888 } 1894 }
1889 } else { /* UDP */ 1895 } else { /* UDP */
1890 purple_debug_info("simple", "using udp with server %s and port %d\n", hostname, port); 1896 purple_debug_info("simple", "using udp with server %s and port %d\n", hostname, port);
1891 1897
1892 sip->query_data = purple_dnsquery_a(hostname, port, simple_udp_host_resolved, sip); 1898 sip->query_data = purple_dnsquery_a(hostname, port, simple_udp_host_resolved, sip);
1893 if (sip->query_data == NULL) { 1899 if (sip->query_data == NULL) {
1894 purple_connection_error_reason(sip->gc, 1900 purple_connection_error_reason(sip->gc,
1895 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1901 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1896 _("Could not resolve hostname")); 1902 _("Unable to resolve hostname"));
1897 } 1903 }
1898 } 1904 }
1899 } 1905 }
1900 1906
1901 static void simple_login(PurpleAccount *account) 1907 static void simple_login(PurpleAccount *account)