comparison libpurple/protocols/simple/simple.c @ 32330:a5b556ac1de5

Rename purple_connection_error_reason to purple_connection_error
author Mark Doliner <mark@kingant.net>
date Sun, 21 Aug 2011 08:00:53 +0000
parents f71b6a715cc7
children dfe284205c32
comparison
equal deleted inserted replaced
32329:5105d0306b2a 32330:a5b556ac1de5
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"), 433 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"),
434 g_strerror(errno)); 434 g_strerror(errno));
435 purple_connection_error_reason(gc, 435 purple_connection_error(gc,
436 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); 436 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
437 g_free(tmp); 437 g_free(tmp);
438 return; 438 return;
439 } 439 }
440 440
449 struct sip_connection *conn; 449 struct sip_connection *conn;
450 450
451 if(source < 0) { 451 if(source < 0) {
452 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"), 452 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"),
453 error_message); 453 error_message);
454 purple_connection_error_reason(gc, 454 purple_connection_error(gc,
455 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); 455 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
456 g_free(tmp); 456 g_free(tmp);
457 return; 457 return;
458 } 458 }
459 459
477 struct simple_account_data *sip = gc->proto_data; 477 struct simple_account_data *sip = gc->proto_data;
478 478
479 if(!sip->connecting) { 479 if(!sip->connecting) {
480 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);
481 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) {
482 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Unable to connect")); 482 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Unable to connect"));
483 } 483 }
484 sip->connecting = TRUE; 484 sip->connecting = TRUE;
485 } 485 }
486 486
487 if(purple_circ_buffer_get_max_read(sip->txbuf) > 0) 487 if(purple_circ_buffer_get_max_read(sip->txbuf) > 0)
1120 if(sip->registerstatus != SIMPLE_REGISTER_RETRY) { 1120 if(sip->registerstatus != SIMPLE_REGISTER_RETRY) {
1121 purple_debug_info("simple", "REGISTER retries %d\n", sip->registrar.retries); 1121 purple_debug_info("simple", "REGISTER retries %d\n", sip->registrar.retries);
1122 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { 1122 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) {
1123 if (!purple_account_get_remember_password(sip->gc->account)) 1123 if (!purple_account_get_remember_password(sip->gc->account))
1124 purple_account_set_password(sip->gc->account, NULL); 1124 purple_account_set_password(sip->gc->account, NULL);
1125 purple_connection_error_reason(sip->gc, 1125 purple_connection_error(sip->gc,
1126 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, 1126 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
1127 _("Incorrect password")); 1127 _("Incorrect password"));
1128 return TRUE; 1128 return TRUE;
1129 } 1129 }
1130 tmp = sipmsg_find_header(msg, "WWW-Authenticate"); 1130 tmp = sipmsg_find_header(msg, "WWW-Authenticate");
1135 break; 1135 break;
1136 default: 1136 default:
1137 if (sip->registerstatus != SIMPLE_REGISTER_RETRY) { 1137 if (sip->registerstatus != SIMPLE_REGISTER_RETRY) {
1138 purple_debug_info("simple", "Unrecognized return code for REGISTER.\n"); 1138 purple_debug_info("simple", "Unrecognized return code for REGISTER.\n");
1139 if (sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { 1139 if (sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) {
1140 purple_connection_error_reason(sip->gc, 1140 purple_connection_error(sip->gc,
1141 PURPLE_CONNECTION_ERROR_OTHER_ERROR, 1141 PURPLE_CONNECTION_ERROR_OTHER_ERROR,
1142 _("Unknown server response")); 1142 _("Unknown server response"));
1143 return TRUE; 1143 return TRUE;
1144 } 1144 }
1145 sip->registerstatus = SIMPLE_REGISTER_RETRY; 1145 sip->registerstatus = SIMPLE_REGISTER_RETRY;
1737 struct sip_connection *conn; 1737 struct sip_connection *conn;
1738 1738
1739 if(source < 0) { 1739 if(source < 0) {
1740 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"), 1740 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"),
1741 error_message); 1741 error_message);
1742 purple_connection_error_reason(gc, 1742 purple_connection_error(gc,
1743 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); 1743 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
1744 g_free(tmp); 1744 g_free(tmp);
1745 return; 1745 return;
1746 } 1746 }
1747 1747
1773 struct simple_account_data *sip = (struct simple_account_data*) data; 1773 struct simple_account_data *sip = (struct simple_account_data*) data;
1774 1774
1775 sip->listen_data = NULL; 1775 sip->listen_data = NULL;
1776 1776
1777 if(listenfd == -1) { 1777 if(listenfd == -1) {
1778 purple_connection_error_reason(sip->gc, 1778 purple_connection_error(sip->gc,
1779 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1779 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1780 _("Unable to create listen socket")); 1780 _("Unable to create listen socket"));
1781 return; 1781 return;
1782 } 1782 }
1783 1783
1802 int addr_size; 1802 int addr_size;
1803 1803
1804 sip->query_data = NULL; 1804 sip->query_data = NULL;
1805 1805
1806 if (!hosts || !hosts->data) { 1806 if (!hosts || !hosts->data) {
1807 purple_connection_error_reason(sip->gc, 1807 purple_connection_error(sip->gc,
1808 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1808 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1809 _("Unable to resolve hostname")); 1809 _("Unable to resolve hostname"));
1810 return; 1810 return;
1811 } 1811 }
1812 1812
1823 1823
1824 /* create socket for incoming connections */ 1824 /* create socket for incoming connections */
1825 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_DGRAM, 1825 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_DGRAM,
1826 simple_udp_host_resolved_listen_cb, sip); 1826 simple_udp_host_resolved_listen_cb, sip);
1827 if (sip->listen_data == NULL) { 1827 if (sip->listen_data == NULL) {
1828 purple_connection_error_reason(sip->gc, 1828 purple_connection_error(sip->gc,
1829 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1829 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1830 _("Unable to create listen socket")); 1830 _("Unable to create listen socket"));
1831 return; 1831 return;
1832 } 1832 }
1833 } 1833 }
1838 1838
1839 sip->listen_data = NULL; 1839 sip->listen_data = NULL;
1840 1840
1841 sip->listenfd = listenfd; 1841 sip->listenfd = listenfd;
1842 if(sip->listenfd == -1) { 1842 if(sip->listenfd == -1) {
1843 purple_connection_error_reason(sip->gc, 1843 purple_connection_error(sip->gc,
1844 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1844 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1845 _("Unable to create listen socket")); 1845 _("Unable to create listen socket"));
1846 return; 1846 return;
1847 } 1847 }
1848 1848
1853 purple_debug_info("simple", "connecting to %s port %d\n", 1853 purple_debug_info("simple", "connecting to %s port %d\n",
1854 sip->realhostname, sip->realport); 1854 sip->realhostname, sip->realport);
1855 /* open tcp connection to the server */ 1855 /* open tcp connection to the server */
1856 if (purple_proxy_connect(sip->gc, sip->account, sip->realhostname, 1856 if (purple_proxy_connect(sip->gc, sip->account, sip->realhostname,
1857 sip->realport, login_cb, sip->gc) == NULL) { 1857 sip->realport, login_cb, sip->gc) == NULL) {
1858 purple_connection_error_reason(sip->gc, 1858 purple_connection_error(sip->gc,
1859 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1859 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1860 _("Unable to connect")); 1860 _("Unable to connect"));
1861 } 1861 }
1862 } 1862 }
1863 1863
1893 if(!sip->udp) { 1893 if(!sip->udp) {
1894 /* create socket for incoming connections */ 1894 /* create socket for incoming connections */
1895 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_STREAM, 1895 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_STREAM,
1896 simple_tcp_connect_listen_cb, sip); 1896 simple_tcp_connect_listen_cb, sip);
1897 if (sip->listen_data == NULL) { 1897 if (sip->listen_data == NULL) {
1898 purple_connection_error_reason(sip->gc, 1898 purple_connection_error(sip->gc,
1899 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1899 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1900 _("Unable to create listen socket")); 1900 _("Unable to create listen socket"));
1901 return; 1901 return;
1902 } 1902 }
1903 } else { /* UDP */ 1903 } else { /* UDP */
1904 purple_debug_info("simple", "using udp with server %s and port %d\n", hostname, port); 1904 purple_debug_info("simple", "using udp with server %s and port %d\n", hostname, port);
1905 1905
1906 sip->query_data = purple_dnsquery_a_account(sip->account, hostname, 1906 sip->query_data = purple_dnsquery_a_account(sip->account, hostname,
1907 port, simple_udp_host_resolved, sip); 1907 port, simple_udp_host_resolved, sip);
1908 if (sip->query_data == NULL) { 1908 if (sip->query_data == NULL) {
1909 purple_connection_error_reason(sip->gc, 1909 purple_connection_error(sip->gc,
1910 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1910 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1911 _("Unable to resolve hostname")); 1911 _("Unable to resolve hostname"));
1912 } 1912 }
1913 } 1913 }
1914 } 1914 }
1922 1922
1923 const char *username = purple_account_get_username(account); 1923 const char *username = purple_account_get_username(account);
1924 gc = purple_account_get_connection(account); 1924 gc = purple_account_get_connection(account);
1925 1925
1926 if (strpbrk(username, " \t\v\r\n") != NULL) { 1926 if (strpbrk(username, " \t\v\r\n") != NULL) {
1927 purple_connection_error_reason(gc, 1927 purple_connection_error(gc,
1928 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, 1928 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
1929 _("SIP usernames may not contain whitespaces or @ symbols")); 1929 _("SIP usernames may not contain whitespaces or @ symbols"));
1930 return; 1930 return;
1931 } 1931 }
1932 1932
1941 if(!sip->udp) 1941 if(!sip->udp)
1942 sip->txbuf = purple_circ_buffer_new(0); 1942 sip->txbuf = purple_circ_buffer_new(0);
1943 1943
1944 userserver = g_strsplit(username, "@", 2); 1944 userserver = g_strsplit(username, "@", 2);
1945 if (userserver[1] == NULL || userserver[1][0] == '\0') { 1945 if (userserver[1] == NULL || userserver[1][0] == '\0') {
1946 purple_connection_error_reason(gc, 1946 purple_connection_error(gc,
1947 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, 1947 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
1948 _("SIP connect server not specified")); 1948 _("SIP connect server not specified"));
1949 return; 1949 return;
1950 } 1950 }
1951 1951