comparison libpurple/protocols/simple/simple.c @ 32819:2c6510167895 default tip

propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24) to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 02 Jun 2012 02:30:49 +0000
parents 50cd80d3554e
children
comparison
equal deleted inserted replaced
32818:01ff09d4a463 32819:2c6510167895
65 static const char *simple_list_icon(PurpleAccount *a, PurpleBuddy *b) { 65 static const char *simple_list_icon(PurpleAccount *a, PurpleBuddy *b) {
66 return "simple"; 66 return "simple";
67 } 67 }
68 68
69 static void simple_keep_alive(PurpleConnection *gc) { 69 static void simple_keep_alive(PurpleConnection *gc) {
70 struct simple_account_data *sip = gc->proto_data; 70 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
71 if(sip->udp) { /* in case of UDP send a packet only with a 0 byte to 71 if(sip->udp) { /* in case of UDP send a packet only with a 0 byte to
72 remain in the NAT table */ 72 remain in the NAT table */
73 gchar buf[2] = {0, 0}; 73 gchar buf[2] = {0, 0};
74 purple_debug_info("simple", "sending keep alive\n"); 74 purple_debug_info("simple", "sending keep alive\n");
75 sendto(sip->fd, buf, 1, 0, (struct sockaddr*)&sip->serveraddr, sizeof(struct sockaddr_in)); 75 sendto(sip->fd, buf, 1, 0, (struct sockaddr*)&sip->serveraddr, sizeof(struct sockaddr_in));
98 tmp = tmp->next; 98 tmp = tmp->next;
99 } 99 }
100 } 100 }
101 101
102 static void simple_set_status(PurpleAccount *account, PurpleStatus *status) { 102 static void simple_set_status(PurpleAccount *account, PurpleStatus *status) {
103 PurpleConnection *gc = purple_account_get_connection(account);
103 PurpleStatusPrimitive primitive = purple_status_type_get_primitive(purple_status_get_type(status)); 104 PurpleStatusPrimitive primitive = purple_status_type_get_primitive(purple_status_get_type(status));
104 struct simple_account_data *sip = NULL; 105 struct simple_account_data *sip = NULL;
105 106
106 if (!purple_status_is_active(status)) 107 if (!purple_status_is_active(status))
107 return; 108 return;
108 109
109 if (account->gc) 110 if (gc)
110 sip = account->gc->proto_data; 111 sip = purple_connection_get_protocol_data(gc);
111 112
112 if (sip) 113 if (sip)
113 { 114 {
114 g_free(sip->status); 115 g_free(sip->status);
115 if (primitive == PURPLE_STATUS_AVAILABLE) 116 if (primitive == PURPLE_STATUS_AVAILABLE)
190 connection_remove(sip, ret->fd); 191 connection_remove(sip, ret->fd);
191 entry = sip->openconns; 192 entry = sip->openconns;
192 } 193 }
193 } 194 }
194 195
195 static void simple_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) 196 static void simple_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group, const char *message)
196 { 197 {
197 struct simple_account_data *sip = (struct simple_account_data *)gc->proto_data; 198 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
198 struct simple_buddy *b; 199 struct simple_buddy *b;
199 const char *name = purple_buddy_get_name(buddy); 200 const char *name = purple_buddy_get_name(buddy);
200 if(strncmp(name, "sip:", 4)) { 201 if(strncmp(name, "sip:", 4)) {
201 gchar *buf = g_strdup_printf("sip:%s", name); 202 gchar *buf = g_strdup_printf("sip:%s", name);
202 purple_blist_rename_buddy(buddy, buf); 203 purple_blist_rename_buddy(buddy, buf);
220 221
221 account = purple_connection_get_account(gc); 222 account = purple_connection_get_account(gc);
222 buddies = purple_find_buddies(account, NULL); 223 buddies = purple_find_buddies(account, NULL);
223 while (buddies) { 224 while (buddies) {
224 PurpleBuddy *buddy = buddies->data; 225 PurpleBuddy *buddy = buddies->data;
225 simple_add_buddy(gc, buddy, purple_buddy_get_group(buddy)); 226 simple_add_buddy(gc, buddy, purple_buddy_get_group(buddy), NULL);
226 227
227 buddies = g_slist_delete_link(buddies, buddies); 228 buddies = g_slist_delete_link(buddies, buddies);
228 } 229 }
229 } 230 }
230 231
231 static void simple_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) 232 static void simple_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
232 { 233 {
233 const char *name = purple_buddy_get_name(buddy); 234 const char *name = purple_buddy_get_name(buddy);
234 struct simple_account_data *sip = (struct simple_account_data *)gc->proto_data; 235 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
235 struct simple_buddy *b = g_hash_table_lookup(sip->buddies, name); 236 struct simple_buddy *b = g_hash_table_lookup(sip->buddies, name);
236 g_hash_table_remove(sip->buddies, name); 237 g_hash_table_remove(sip->buddies, name);
237 g_free(b->name); 238 g_free(b->name);
238 g_free(b); 239 g_free(b);
239 } 240 }
410 411
411 } 412 }
412 413
413 static void simple_canwrite_cb(gpointer data, gint source, PurpleInputCondition cond) { 414 static void simple_canwrite_cb(gpointer data, gint source, PurpleInputCondition cond) {
414 PurpleConnection *gc = data; 415 PurpleConnection *gc = data;
415 struct simple_account_data *sip = gc->proto_data; 416 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
416 gsize max_write; 417 gsize max_write;
417 gssize written; 418 gssize written;
418 419
419 max_write = purple_circ_buffer_get_max_read(sip->txbuf); 420 max_write = purple_circ_buffer_get_max_read(sip->txbuf);
420 421
430 written = 0; 431 written = 0;
431 else if (written <= 0) { 432 else if (written <= 0) {
432 /*TODO: do we really want to disconnect on a failure to write?*/ 433 /*TODO: do we really want to disconnect on a failure to write?*/
433 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), 434 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"),
434 g_strerror(errno)); 435 g_strerror(errno));
435 purple_connection_error_reason(gc, 436 purple_connection_error(gc,
436 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); 437 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
437 g_free(tmp); 438 g_free(tmp);
438 return; 439 return;
439 } 440 }
440 441
449 struct sip_connection *conn; 450 struct sip_connection *conn;
450 451
451 if(source < 0) { 452 if(source < 0) {
452 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"), 453 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"),
453 error_message); 454 error_message);
454 purple_connection_error_reason(gc, 455 purple_connection_error(gc,
455 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); 456 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
456 g_free(tmp); 457 g_free(tmp);
457 return; 458 return;
458 } 459 }
459 460
460 sip = gc->proto_data; 461 sip = purple_connection_get_protocol_data(gc);
461 sip->fd = source; 462 sip->fd = source;
462 sip->connecting = FALSE; 463 sip->connecting = FALSE;
463 464
464 simple_canwrite_cb(gc, sip->fd, PURPLE_INPUT_WRITE); 465 simple_canwrite_cb(gc, sip->fd, PURPLE_INPUT_WRITE);
465 466
472 conn->inputhandler = purple_input_add(sip->fd, PURPLE_INPUT_READ, simple_input_cb, gc); 473 conn->inputhandler = purple_input_add(sip->fd, PURPLE_INPUT_READ, simple_input_cb, gc);
473 } 474 }
474 475
475 476
476 static void sendlater(PurpleConnection *gc, const char *buf) { 477 static void sendlater(PurpleConnection *gc, const char *buf) {
477 struct simple_account_data *sip = gc->proto_data; 478 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
478 479
479 if(!sip->connecting) { 480 if(!sip->connecting) {
480 purple_debug_info("simple", "connecting to %s port %d\n", sip->realhostname ? sip->realhostname : "{NULL}", sip->realport); 481 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) { 482 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")); 483 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Unable to connect"));
483 } 484 }
484 sip->connecting = TRUE; 485 sip->connecting = TRUE;
485 } 486 }
486 487
487 if(purple_circ_buffer_get_max_read(sip->txbuf) > 0) 488 if(purple_circ_buffer_get_max_read(sip->txbuf) > 0)
489 490
490 purple_circ_buffer_append(sip->txbuf, buf, strlen(buf)); 491 purple_circ_buffer_append(sip->txbuf, buf, strlen(buf));
491 } 492 }
492 493
493 static void sendout_pkt(PurpleConnection *gc, const char *buf) { 494 static void sendout_pkt(PurpleConnection *gc, const char *buf) {
494 struct simple_account_data *sip = gc->proto_data; 495 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
495 time_t currtime = time(NULL); 496 time_t currtime = time(NULL);
496 int writelen = strlen(buf); 497 int writelen = strlen(buf);
497 498
498 purple_debug(PURPLE_DEBUG_MISC, "simple", "\n\nsending - %s\n######\n%s\n######\n\n", ctime(&currtime), buf); 499 purple_debug(PURPLE_DEBUG_MISC, "simple", "\n\nsending - %s\n######\n%s\n######\n\n", ctime(&currtime), buf);
499 if(sip->udp) { 500 if(sip->udp) {
627 } 628 }
628 629
629 static void send_sip_request(PurpleConnection *gc, const gchar *method, 630 static void send_sip_request(PurpleConnection *gc, const gchar *method,
630 const gchar *url, const gchar *to, const gchar *addheaders, 631 const gchar *url, const gchar *to, const gchar *addheaders,
631 const gchar *body, struct sip_dialog *dialog, TransCallback tc) { 632 const gchar *body, struct sip_dialog *dialog, TransCallback tc) {
632 struct simple_account_data *sip = gc->proto_data; 633 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
633 char *callid = dialog ? g_strdup(dialog->callid) : gencallid(); 634 char *callid = dialog ? g_strdup(dialog->callid) : gencallid();
634 char *auth = NULL; 635 char *auth = NULL;
635 const char *addh = ""; 636 const char *addh = "";
636 gchar *branch = genbranch(); 637 gchar *branch = genbranch();
637 gchar *tag = NULL; 638 gchar *tag = NULL;
1024 g_free(hdr); 1025 g_free(hdr);
1025 g_free(fullto); 1026 g_free(fullto);
1026 } 1027 }
1027 1028
1028 static int simple_im_send(PurpleConnection *gc, const char *who, const char *what, PurpleMessageFlags flags) { 1029 static int simple_im_send(PurpleConnection *gc, const char *who, const char *what, PurpleMessageFlags flags) {
1029 struct simple_account_data *sip = gc->proto_data; 1030 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
1030 char *to = g_strdup(who); 1031 char *to = g_strdup(who);
1031 char *text = purple_unescape_html(what); 1032 char *text = purple_unescape_html(what);
1032 simple_send_message(sip, to, text, NULL); 1033 simple_send_message(sip, to, text, NULL);
1033 g_free(to); 1034 g_free(to);
1034 g_free(text); 1035 g_free(text);
1118 break; 1119 break;
1119 case 401: 1120 case 401:
1120 if(sip->registerstatus != SIMPLE_REGISTER_RETRY) { 1121 if(sip->registerstatus != SIMPLE_REGISTER_RETRY) {
1121 purple_debug_info("simple", "REGISTER retries %d\n", sip->registrar.retries); 1122 purple_debug_info("simple", "REGISTER retries %d\n", sip->registrar.retries);
1122 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { 1123 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) {
1123 if (!purple_account_get_remember_password(sip->gc->account)) 1124 if (!purple_account_get_remember_password(purple_connection_get_account(sip->gc)))
1124 purple_account_set_password(sip->gc->account, NULL); 1125 purple_account_set_password(purple_connection_get_account(sip->gc), NULL);
1125 purple_connection_error_reason(sip->gc, 1126 purple_connection_error(sip->gc,
1126 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, 1127 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
1127 _("Incorrect password")); 1128 _("Incorrect password"));
1128 return TRUE; 1129 return TRUE;
1129 } 1130 }
1130 tmp = sipmsg_find_header(msg, "WWW-Authenticate"); 1131 tmp = sipmsg_find_header(msg, "WWW-Authenticate");
1135 break; 1136 break;
1136 default: 1137 default:
1137 if (sip->registerstatus != SIMPLE_REGISTER_RETRY) { 1138 if (sip->registerstatus != SIMPLE_REGISTER_RETRY) {
1138 purple_debug_info("simple", "Unrecognized return code for REGISTER.\n"); 1139 purple_debug_info("simple", "Unrecognized return code for REGISTER.\n");
1139 if (sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { 1140 if (sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) {
1140 purple_connection_error_reason(sip->gc, 1141 purple_connection_error(sip->gc,
1141 PURPLE_CONNECTION_ERROR_OTHER_ERROR, 1142 PURPLE_CONNECTION_ERROR_OTHER_ERROR,
1142 _("Unknown server response")); 1143 _("Unknown server response"));
1143 return TRUE; 1144 return TRUE;
1144 } 1145 }
1145 sip->registerstatus = SIMPLE_REGISTER_RETRY; 1146 sip->registerstatus = SIMPLE_REGISTER_RETRY;
1283 1284
1284 send_sip_response(sip->gc, msg, 200, "OK", NULL); 1285 send_sip_response(sip->gc, msg, 200, "OK", NULL);
1285 } 1286 }
1286 1287
1287 static unsigned int simple_typing(PurpleConnection *gc, const char *name, PurpleTypingState state) { 1288 static unsigned int simple_typing(PurpleConnection *gc, const char *name, PurpleTypingState state) {
1288 struct simple_account_data *sip = gc->proto_data; 1289 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
1289 1290
1290 gchar *xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 1291 gchar *xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1291 "<isComposing xmlns=\"urn:ietf:params:xml:ns:im-iscomposing\"\n" 1292 "<isComposing xmlns=\"urn:ietf:params:xml:ns:im-iscomposing\"\n"
1292 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" 1293 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
1293 "xsi:schemaLocation=\"urn:ietf:params:xml:ns:im-composing iscomposing.xsd\">\n" 1294 "xsi:schemaLocation=\"urn:ietf:params:xml:ns:im-composing iscomposing.xsd\">\n"
1659 } 1660 }
1660 } 1661 }
1661 1662
1662 static void simple_udp_process(gpointer data, gint source, PurpleInputCondition con) { 1663 static void simple_udp_process(gpointer data, gint source, PurpleInputCondition con) {
1663 PurpleConnection *gc = data; 1664 PurpleConnection *gc = data;
1664 struct simple_account_data *sip = gc->proto_data; 1665 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
1665 struct sipmsg *msg; 1666 struct sipmsg *msg;
1666 int len; 1667 int len;
1667 time_t currtime = time(NULL); 1668 time_t currtime = time(NULL);
1668 1669
1669 static char buffer[65536]; 1670 static char buffer[65536];
1679 } 1680 }
1680 1681
1681 static void simple_input_cb(gpointer data, gint source, PurpleInputCondition cond) 1682 static void simple_input_cb(gpointer data, gint source, PurpleInputCondition cond)
1682 { 1683 {
1683 PurpleConnection *gc = data; 1684 PurpleConnection *gc = data;
1684 struct simple_account_data *sip = gc->proto_data; 1685 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
1685 int len; 1686 int len;
1686 struct sip_connection *conn = connection_find(sip, source); 1687 struct sip_connection *conn = connection_find(sip, source);
1687 if(!conn) { 1688 if(!conn) {
1688 purple_debug_error("simple", "Connection not found!\n"); 1689 purple_debug_error("simple", "Connection not found!\n");
1689 return; 1690 return;
1702 purple_debug_info("simple", "simple_input_cb: read error\n"); 1703 purple_debug_info("simple", "simple_input_cb: read error\n");
1703 connection_remove(sip, source); 1704 connection_remove(sip, source);
1704 if(sip->fd == source) sip->fd = -1; 1705 if(sip->fd == source) sip->fd = -1;
1705 return; 1706 return;
1706 } 1707 }
1707 gc->last_received = time(NULL); 1708 purple_connection_update_last_received(gc);
1708 conn->inbufused += len; 1709 conn->inbufused += len;
1709 conn->inbuf[conn->inbufused] = '\0'; 1710 conn->inbuf[conn->inbufused] = '\0';
1710 1711
1711 process_input(sip, conn); 1712 process_input(sip, conn);
1712 } 1713 }
1713 1714
1714 /* Callback for new connections on incoming TCP port */ 1715 /* Callback for new connections on incoming TCP port */
1715 static void simple_newconn_cb(gpointer data, gint source, PurpleInputCondition cond) { 1716 static void simple_newconn_cb(gpointer data, gint source, PurpleInputCondition cond) {
1716 PurpleConnection *gc = data; 1717 PurpleConnection *gc = data;
1717 struct simple_account_data *sip = gc->proto_data; 1718 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
1718 struct sip_connection *conn; 1719 struct sip_connection *conn;
1719 int newfd, flags; 1720 int newfd, flags;
1720 1721
1721 newfd = accept(source, NULL, NULL); 1722 newfd = accept(source, NULL, NULL);
1722 1723
1737 struct sip_connection *conn; 1738 struct sip_connection *conn;
1738 1739
1739 if(source < 0) { 1740 if(source < 0) {
1740 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"), 1741 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"),
1741 error_message); 1742 error_message);
1742 purple_connection_error_reason(gc, 1743 purple_connection_error(gc,
1743 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); 1744 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
1744 g_free(tmp); 1745 g_free(tmp);
1745 return; 1746 return;
1746 } 1747 }
1747 1748
1748 sip = gc->proto_data; 1749 sip = purple_connection_get_protocol_data(gc);
1749 sip->fd = source; 1750 sip->fd = source;
1750 1751
1751 conn = connection_create(sip, source); 1752 conn = connection_create(sip, source);
1752 1753
1753 sip->registertimeout = purple_timeout_add((rand()%100)+10*1000, (GSourceFunc)subscribe_timeout, sip); 1754 sip->registertimeout = purple_timeout_add((rand()%100)+10*1000, (GSourceFunc)subscribe_timeout, sip);
1773 struct simple_account_data *sip = (struct simple_account_data*) data; 1774 struct simple_account_data *sip = (struct simple_account_data*) data;
1774 1775
1775 sip->listen_data = NULL; 1776 sip->listen_data = NULL;
1776 1777
1777 if(listenfd == -1) { 1778 if(listenfd == -1) {
1778 purple_connection_error_reason(sip->gc, 1779 purple_connection_error(sip->gc,
1779 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1780 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1780 _("Unable to create listen socket")); 1781 _("Unable to create listen socket"));
1781 return; 1782 return;
1782 } 1783 }
1783 1784
1802 int addr_size; 1803 int addr_size;
1803 1804
1804 sip->query_data = NULL; 1805 sip->query_data = NULL;
1805 1806
1806 if (!hosts || !hosts->data) { 1807 if (!hosts || !hosts->data) {
1807 purple_connection_error_reason(sip->gc, 1808 purple_connection_error(sip->gc,
1808 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1809 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1809 _("Unable to resolve hostname")); 1810 _("Unable to resolve hostname"));
1810 return; 1811 return;
1811 } 1812 }
1812 1813
1820 g_free(hosts->data); 1821 g_free(hosts->data);
1821 hosts = g_slist_remove(hosts, hosts->data); 1822 hosts = g_slist_remove(hosts, hosts->data);
1822 } 1823 }
1823 1824
1824 /* create socket for incoming connections */ 1825 /* create socket for incoming connections */
1825 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_DGRAM, 1826 sip->listen_data = purple_network_listen_range(5060, 5160, AF_UNSPEC, SOCK_DGRAM, TRUE,
1826 simple_udp_host_resolved_listen_cb, sip); 1827 simple_udp_host_resolved_listen_cb, sip);
1827 if (sip->listen_data == NULL) { 1828 if (sip->listen_data == NULL) {
1828 purple_connection_error_reason(sip->gc, 1829 purple_connection_error(sip->gc,
1829 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1830 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1830 _("Unable to create listen socket")); 1831 _("Unable to create listen socket"));
1831 return; 1832 return;
1832 } 1833 }
1833 } 1834 }
1838 1839
1839 sip->listen_data = NULL; 1840 sip->listen_data = NULL;
1840 1841
1841 sip->listenfd = listenfd; 1842 sip->listenfd = listenfd;
1842 if(sip->listenfd == -1) { 1843 if(sip->listenfd == -1) {
1843 purple_connection_error_reason(sip->gc, 1844 purple_connection_error(sip->gc,
1844 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1845 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1845 _("Unable to create listen socket")); 1846 _("Unable to create listen socket"));
1846 return; 1847 return;
1847 } 1848 }
1848 1849
1853 purple_debug_info("simple", "connecting to %s port %d\n", 1854 purple_debug_info("simple", "connecting to %s port %d\n",
1854 sip->realhostname, sip->realport); 1855 sip->realhostname, sip->realport);
1855 /* open tcp connection to the server */ 1856 /* open tcp connection to the server */
1856 if (purple_proxy_connect(sip->gc, sip->account, sip->realhostname, 1857 if (purple_proxy_connect(sip->gc, sip->account, sip->realhostname,
1857 sip->realport, login_cb, sip->gc) == NULL) { 1858 sip->realport, login_cb, sip->gc) == NULL) {
1858 purple_connection_error_reason(sip->gc, 1859 purple_connection_error(sip->gc,
1859 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1860 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1860 _("Unable to connect")); 1861 _("Unable to connect"));
1861 } 1862 }
1862 } 1863 }
1863 1864
1890 if(!sip->realport) sip->realport = 5060; 1891 if(!sip->realport) sip->realport = 5060;
1891 1892
1892 /* TCP case */ 1893 /* TCP case */
1893 if(!sip->udp) { 1894 if(!sip->udp) {
1894 /* create socket for incoming connections */ 1895 /* create socket for incoming connections */
1895 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_STREAM, 1896 sip->listen_data = purple_network_listen_range(5060, 5160, AF_UNSPEC, SOCK_STREAM, TRUE,
1896 simple_tcp_connect_listen_cb, sip); 1897 simple_tcp_connect_listen_cb, sip);
1897 if (sip->listen_data == NULL) { 1898 if (sip->listen_data == NULL) {
1898 purple_connection_error_reason(sip->gc, 1899 purple_connection_error(sip->gc,
1899 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1900 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1900 _("Unable to create listen socket")); 1901 _("Unable to create listen socket"));
1901 return; 1902 return;
1902 } 1903 }
1903 } else { /* UDP */ 1904 } else { /* UDP */
1904 purple_debug_info("simple", "using udp with server %s and port %d\n", hostname, port); 1905 purple_debug_info("simple", "using udp with server %s and port %d\n", hostname, port);
1905 1906
1906 sip->query_data = purple_dnsquery_a_account(sip->account, hostname, 1907 sip->query_data = purple_dnsquery_a(sip->account, hostname,
1907 port, simple_udp_host_resolved, sip); 1908 port, simple_udp_host_resolved, sip);
1908 if (sip->query_data == NULL) { 1909 if (sip->query_data == NULL) {
1909 purple_connection_error_reason(sip->gc, 1910 purple_connection_error(sip->gc,
1910 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1911 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1911 _("Unable to resolve hostname")); 1912 _("Unable to resolve hostname"));
1912 } 1913 }
1913 } 1914 }
1914 } 1915 }
1922 1923
1923 const char *username = purple_account_get_username(account); 1924 const char *username = purple_account_get_username(account);
1924 gc = purple_account_get_connection(account); 1925 gc = purple_account_get_connection(account);
1925 1926
1926 if (strpbrk(username, " \t\v\r\n") != NULL) { 1927 if (strpbrk(username, " \t\v\r\n") != NULL) {
1927 purple_connection_error_reason(gc, 1928 purple_connection_error(gc,
1928 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, 1929 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
1929 _("SIP usernames may not contain whitespaces or @ symbols")); 1930 _("SIP usernames may not contain whitespaces or @ symbols"));
1930 return; 1931 return;
1931 } 1932 }
1932 1933
1933 gc->proto_data = sip = g_new0(struct simple_account_data, 1); 1934 sip = g_new0(struct simple_account_data, 1);
1935 purple_connection_set_protocol_data(gc, sip);
1934 sip->gc = gc; 1936 sip->gc = gc;
1935 sip->fd = -1; 1937 sip->fd = -1;
1936 sip->listenfd = -1; 1938 sip->listenfd = -1;
1937 sip->account = account; 1939 sip->account = account;
1938 sip->registerexpire = 900; 1940 sip->registerexpire = 900;
1941 if(!sip->udp) 1943 if(!sip->udp)
1942 sip->txbuf = purple_circ_buffer_new(0); 1944 sip->txbuf = purple_circ_buffer_new(0);
1943 1945
1944 userserver = g_strsplit(username, "@", 2); 1946 userserver = g_strsplit(username, "@", 2);
1945 if (userserver[1] == NULL || userserver[1][0] == '\0') { 1947 if (userserver[1] == NULL || userserver[1][0] == '\0') {
1946 purple_connection_error_reason(gc, 1948 purple_connection_error(gc,
1947 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, 1949 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
1948 _("SIP connect server not specified")); 1950 _("SIP connect server not specified"));
1949 return; 1951 return;
1950 } 1952 }
1951 1953
1966 hosttoconnect = sip->servername; 1968 hosttoconnect = sip->servername;
1967 } else { 1969 } else {
1968 hosttoconnect = purple_account_get_string(account, "proxy", sip->servername); 1970 hosttoconnect = purple_account_get_string(account, "proxy", sip->servername);
1969 } 1971 }
1970 1972
1971 sip->srv_query_data = purple_srv_resolve_account(account, "sip", 1973 sip->srv_query_data = purple_srv_resolve(account, "sip",
1972 sip->udp ? "udp" : "tcp", hosttoconnect, srvresolved, sip); 1974 sip->udp ? "udp" : "tcp", hosttoconnect, srvresolved, sip);
1973 } 1975 }
1974 1976
1975 static void simple_close(PurpleConnection *gc) 1977 static void simple_close(PurpleConnection *gc)
1976 { 1978 {
1977 struct simple_account_data *sip = gc->proto_data; 1979 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
1978 1980
1979 if (!sip) 1981 if (!sip)
1980 return; 1982 return;
1981 1983
1982 /* unregister */ 1984 /* unregister */
2003 purple_timeout_remove(sip->registertimeout); 2005 purple_timeout_remove(sip->registertimeout);
2004 if (sip->query_data != NULL) 2006 if (sip->query_data != NULL)
2005 purple_dnsquery_destroy(sip->query_data); 2007 purple_dnsquery_destroy(sip->query_data);
2006 2008
2007 if (sip->srv_query_data != NULL) 2009 if (sip->srv_query_data != NULL)
2008 purple_srv_cancel(sip->srv_query_data); 2010 purple_srv_txt_query_destroy(sip->srv_query_data);
2009 2011
2010 if (sip->listen_data != NULL) 2012 if (sip->listen_data != NULL)
2011 purple_network_listen_cancel(sip->listen_data); 2013 purple_network_listen_cancel(sip->listen_data);
2012 2014
2013 if (sip->fd >= 0) 2015 if (sip->fd >= 0)
2037 if (sip->txbuf) 2039 if (sip->txbuf)
2038 purple_circ_buffer_destroy(sip->txbuf); 2040 purple_circ_buffer_destroy(sip->txbuf);
2039 g_free(sip->realhostname); 2041 g_free(sip->realhostname);
2040 2042
2041 g_free(sip); 2043 g_free(sip);
2042 gc->proto_data = NULL; 2044 purple_connection_set_protocol_data(gc, NULL);
2043 } 2045 }
2044 2046
2045 static PurplePluginProtocolInfo prpl_info = 2047 static PurplePluginProtocolInfo prpl_info =
2046 { 2048 {
2049 sizeof(PurplePluginProtocolInfo), /* struct_size */
2047 0, 2050 0,
2048 NULL, /* user_splits */ 2051 NULL, /* user_splits */
2049 NULL, /* protocol_options */ 2052 NULL, /* protocol_options */
2050 NO_BUDDY_ICONS, /* icon_spec */ 2053 NO_BUDDY_ICONS, /* icon_spec */
2051 simple_list_icon, /* list_icon */ 2054 simple_list_icon, /* list_icon */
2082 NULL, /* chat_whisper */ 2085 NULL, /* chat_whisper */
2083 NULL, /* chat_send */ 2086 NULL, /* chat_send */
2084 simple_keep_alive, /* keepalive */ 2087 simple_keep_alive, /* keepalive */
2085 NULL, /* register_user */ 2088 NULL, /* register_user */
2086 NULL, /* get_cb_info */ 2089 NULL, /* get_cb_info */
2087 NULL, /* get_cb_away */
2088 NULL, /* alias_buddy */ 2090 NULL, /* alias_buddy */
2089 NULL, /* group_buddy */ 2091 NULL, /* group_buddy */
2090 NULL, /* rename_group */ 2092 NULL, /* rename_group */
2091 NULL, /* buddy_free */ 2093 NULL, /* buddy_free */
2092 NULL, /* convo_closed */ 2094 NULL, /* convo_closed */
2107 simple_send_raw, /* send_raw */ 2109 simple_send_raw, /* send_raw */
2108 NULL, /* roomlist_room_serialize */ 2110 NULL, /* roomlist_room_serialize */
2109 NULL, /* unregister_user */ 2111 NULL, /* unregister_user */
2110 NULL, /* send_attention */ 2112 NULL, /* send_attention */
2111 NULL, /* get_attention_types */ 2113 NULL, /* get_attention_types */
2112 sizeof(PurplePluginProtocolInfo), /* struct_size */
2113 NULL, /* get_account_text_table */ 2114 NULL, /* get_account_text_table */
2114 NULL, /* initiate_media */ 2115 NULL, /* initiate_media */
2115 NULL, /* get_media_caps */ 2116 NULL, /* get_media_caps */
2116 NULL, /* get_moods */ 2117 NULL, /* get_moods */
2117 NULL, /* set_public_alias */ 2118 NULL, /* set_public_alias */
2118 NULL, /* get_public_alias */ 2119 NULL /* get_public_alias */
2119 NULL, /* add_buddy_with_invite */
2120 NULL /* add_buddies_with_invite */
2121 }; 2120 };
2122 2121
2123 2122
2124 static PurplePluginInfo info = 2123 static PurplePluginInfo info =
2125 { 2124 {