comparison libpurple/protocols/zephyr/zephyr.c @ 32672:3828a61c44da

A boring and large patch so I can merge heads.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Fri, 23 Dec 2011 08:21:58 +0000
parents 99ca503ea087
children
comparison
equal deleted inserted replaced
32671:0e69949b3e61 32672:3828a61c44da
345 345
346 static gchar *zephyr_recv_convert(PurpleConnection *gc, gchar *string) 346 static gchar *zephyr_recv_convert(PurpleConnection *gc, gchar *string)
347 { 347 {
348 gchar *utf8; 348 gchar *utf8;
349 GError *err = NULL; 349 GError *err = NULL;
350 zephyr_account *zephyr = gc->proto_data; 350 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
351 if (g_utf8_validate(string, -1, NULL)) { 351 if (g_utf8_validate(string, -1, NULL)) {
352 return g_strdup(string); 352 return g_strdup(string);
353 } else { 353 } else {
354 utf8 = g_convert(string, -1, "UTF-8", zephyr->encoding, NULL, NULL, &err); 354 utf8 = g_convert(string, -1, "UTF-8", zephyr->encoding, NULL, NULL, &err);
355 if (err) { 355 if (err) {
760 } 760 }
761 } 761 }
762 762
763 static void handle_message(PurpleConnection *gc,ZNotice_t notice) 763 static void handle_message(PurpleConnection *gc,ZNotice_t notice)
764 { 764 {
765 zephyr_account* zephyr = gc->proto_data; 765 zephyr_account* zephyr = purple_connection_get_protocol_data(gc);
766 766
767 if (!g_ascii_strcasecmp(notice.z_class, LOGIN_CLASS)) { 767 if (!g_ascii_strcasecmp(notice.z_class, LOGIN_CLASS)) {
768 /* well, we'll be updating in 20 seconds anyway, might as well ignore this. */ 768 /* well, we'll be updating in 20 seconds anyway, might as well ignore this. */
769 } else if (!g_ascii_strcasecmp(notice.z_class, LOCATE_CLASS)) { 769 } else if (!g_ascii_strcasecmp(notice.z_class, LOCATE_CLASS)) {
770 if (!g_ascii_strcasecmp(notice.z_opcode, LOCATE_LOCATE)) { 770 if (!g_ascii_strcasecmp(notice.z_opcode, LOCATE_LOCATE)) {
775 775
776 /* XXX add real error reporting */ 776 /* XXX add real error reporting */
777 if (ZParseLocations(&notice, NULL, &nlocs, &user) != ZERR_NONE) 777 if (ZParseLocations(&notice, NULL, &nlocs, &user) != ZERR_NONE)
778 return; 778 return;
779 779
780 if ((b = purple_find_buddy(gc->account, user)) == NULL) { 780 if ((b = purple_find_buddy(purple_connection_get_account(gc), user)) == NULL) {
781 char* stripped_user = zephyr_strip_local_realm(zephyr,user); 781 char* stripped_user = zephyr_strip_local_realm(zephyr,user);
782 b = purple_find_buddy(gc->account,stripped_user); 782 b = purple_find_buddy(purple_connection_get_account(gc),stripped_user);
783 g_free(stripped_user); 783 g_free(stripped_user);
784 } 784 }
785 785
786 bname = b ? purple_buddy_get_name(b) : NULL; 786 bname = b ? purple_buddy_get_name(b) : NULL;
787 if ((b && pending_zloc(zephyr,bname)) || pending_zloc(zephyr,user)) { 787 if ((b && pending_zloc(zephyr,bname)) || pending_zloc(zephyr,user)) {
813 purple_notify_userinfo(gc, (b ? bname : user), 813 purple_notify_userinfo(gc, (b ? bname : user),
814 user_info, NULL, NULL); 814 user_info, NULL, NULL);
815 purple_notify_user_info_destroy(user_info); 815 purple_notify_user_info_destroy(user_info);
816 } else { 816 } else {
817 if (nlocs>0) 817 if (nlocs>0)
818 purple_prpl_got_user_status(gc->account, b ? bname : user, "available", NULL); 818 purple_prpl_got_user_status(purple_connection_get_account(gc), b ? bname : user, "available", NULL);
819 else 819 else
820 purple_prpl_got_user_status(gc->account, b ? bname : user, "offline", NULL); 820 purple_prpl_got_user_status(purple_connection_get_account(gc), b ? bname : user, "offline", NULL);
821 } 821 }
822 822
823 g_free(user); 823 g_free(user);
824 } 824 }
825 } else { 825 } else {
870 serv_got_im(gc, stripped_sender, buf3, flags, time(NULL)); 870 serv_got_im(gc, stripped_sender, buf3, flags, time(NULL));
871 871
872 } else { 872 } else {
873 zephyr_triple *zt1, *zt2; 873 zephyr_triple *zt1, *zt2;
874 gchar *send_inst_utf8; 874 gchar *send_inst_utf8;
875 zephyr_account *zephyr = gc->proto_data; 875 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
876 zt1 = new_triple(zephyr,notice.z_class, notice.z_class_inst, notice.z_recipient); 876 zt1 = new_triple(zephyr,notice.z_class, notice.z_class_inst, notice.z_recipient);
877 zt2 = find_sub_by_triple(zephyr,zt1); 877 zt2 = find_sub_by_triple(zephyr,zt1);
878 if (!zt2) { 878 if (!zt2) {
879 /* This is a server supplied subscription */ 879 /* This is a server supplied subscription */
880 zephyr->subscrips = g_slist_append(zephyr->subscrips, new_triple(zephyr,zt1->class,zt1->instance,zt1->recipient)); 880 zephyr->subscrips = g_slist_append(zephyr->subscrips, new_triple(zephyr,zt1->class,zt1->instance,zt1->recipient));
898 send_inst_utf8 = g_strdup(stripped_sender); 898 send_inst_utf8 = g_strdup(stripped_sender);
899 } 899 }
900 } 900 }
901 901
902 gconv1 = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, 902 gconv1 = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT,
903 zt2->name, gc->account); 903 zt2->name, purple_connection_get_account(gc));
904 gcc = purple_conversation_get_chat_data(gconv1); 904 gcc = purple_conversation_get_chat_data(gconv1);
905 #ifndef INET_ADDRSTRLEN 905 #ifndef INET_ADDRSTRLEN
906 #define INET_ADDRSTRLEN 16 906 #define INET_ADDRSTRLEN 16
907 #endif 907 #endif
908 if (!purple_conv_chat_find_user(gcc, stripped_sender)) { 908 if (!purple_conv_chat_find_user(gcc, stripped_sender)) {
1107 } 1107 }
1108 1108
1109 static gint check_notify_tzc(gpointer data) 1109 static gint check_notify_tzc(gpointer data)
1110 { 1110 {
1111 PurpleConnection *gc = (PurpleConnection *)data; 1111 PurpleConnection *gc = (PurpleConnection *)data;
1112 zephyr_account* zephyr = gc->proto_data; 1112 zephyr_account* zephyr = purple_connection_get_protocol_data(gc);
1113 parse_tree *newparsetree = read_from_tzc(zephyr); 1113 parse_tree *newparsetree = read_from_tzc(zephyr);
1114 if (newparsetree != NULL) { 1114 if (newparsetree != NULL) {
1115 gchar *spewtype; 1115 gchar *spewtype;
1116 if ( (spewtype = tree_child(find_node(newparsetree,"tzcspew"),2)->contents) ) { 1116 if ( (spewtype = tree_child(find_node(newparsetree,"tzcspew"),2)->contents) ) {
1117 if (!g_ascii_strncasecmp(spewtype,"message",7)) { 1117 if (!g_ascii_strncasecmp(spewtype,"message",7)) {
1154 int nlocs = 0; 1154 int nlocs = 0;
1155 parse_tree *locations; 1155 parse_tree *locations;
1156 gchar *locval; 1156 gchar *locval;
1157 user = tree_child(find_node(newparsetree,"user"),2)->contents; 1157 user = tree_child(find_node(newparsetree,"user"),2)->contents;
1158 1158
1159 if ((b = purple_find_buddy(gc->account, user)) == NULL) { 1159 if ((b = purple_find_buddy(purple_connection_get_account(gc), user)) == NULL) {
1160 gchar *stripped_user = zephyr_strip_local_realm(zephyr,user); 1160 gchar *stripped_user = zephyr_strip_local_realm(zephyr,user);
1161 b = purple_find_buddy(gc->account, stripped_user); 1161 b = purple_find_buddy(purple_connection_get_account(gc), stripped_user);
1162 g_free(stripped_user); 1162 g_free(stripped_user);
1163 } 1163 }
1164 locations = find_node(newparsetree,"locations"); 1164 locations = find_node(newparsetree,"locations");
1165 locval = tree_child(tree_child(tree_child(tree_child(locations,2),0),0),2)->contents; 1165 locval = tree_child(tree_child(tree_child(tree_child(locations,2),0),0),2)->contents;
1166 1166
1198 purple_notify_userinfo(gc, b ? bname : user, 1198 purple_notify_userinfo(gc, b ? bname : user,
1199 user_info, NULL, NULL); 1199 user_info, NULL, NULL);
1200 purple_notify_user_info_destroy(user_info); 1200 purple_notify_user_info_destroy(user_info);
1201 } else { 1201 } else {
1202 if (nlocs>0) 1202 if (nlocs>0)
1203 purple_prpl_got_user_status(gc->account, b ? bname : user, "available", NULL); 1203 purple_prpl_got_user_status(purple_connection_get_account(gc), b ? bname : user, "available", NULL);
1204 else 1204 else
1205 purple_prpl_got_user_status(gc->account, b ? bname : user, "offline", NULL); 1205 purple_prpl_got_user_status(purple_connection_get_account(gc), b ? bname : user, "offline", NULL);
1206 } 1206 }
1207 } 1207 }
1208 else if (!g_ascii_strncasecmp(spewtype,"subscribed",10)) { 1208 else if (!g_ascii_strncasecmp(spewtype,"subscribed",10)) {
1209 } 1209 }
1210 else if (!g_ascii_strncasecmp(spewtype,"start",5)) { 1210 else if (!g_ascii_strncasecmp(spewtype,"start",5)) {
1263 static gint check_loc(gpointer data) 1263 static gint check_loc(gpointer data)
1264 { 1264 {
1265 GSList *buddies; 1265 GSList *buddies;
1266 ZLocations_t locations; 1266 ZLocations_t locations;
1267 PurpleConnection *gc = data; 1267 PurpleConnection *gc = data;
1268 zephyr_account *zephyr = gc->proto_data; 1268 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
1269 PurpleAccount *account = purple_connection_get_account(gc); 1269 PurpleAccount *account = purple_connection_get_account(gc);
1270 int numlocs; 1270 int numlocs;
1271 int one = 1; 1271 int one = 1;
1272 1272
1273 for (buddies = purple_find_buddies(account, NULL); buddies; 1273 for (buddies = purple_find_buddies(account, NULL); buddies;
1294 static gint check_loc(gpointer data) 1294 static gint check_loc(gpointer data)
1295 { 1295 {
1296 GSList *buddies; 1296 GSList *buddies;
1297 ZAsyncLocateData_t ald; 1297 ZAsyncLocateData_t ald;
1298 PurpleConnection *gc = (PurpleConnection *)data; 1298 PurpleConnection *gc = (PurpleConnection *)data;
1299 zephyr_account *zephyr = gc->proto_data; 1299 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
1300 PurpleAccount *account = purple_connection_get_account(gc); 1300 PurpleAccount *account = purple_connection_get_account(gc);
1301 1301
1302 if (use_zeph02(zephyr)) { 1302 if (use_zeph02(zephyr)) {
1303 ald.user = NULL; 1303 ald.user = NULL;
1304 memset(&(ald.uid), 0, sizeof(ZUnique_Id_t)); 1304 memset(&(ald.uid), 0, sizeof(ZUnique_Id_t));
1519 filename = g_strconcat(purple_home_dir(), "/.anyone", NULL); 1519 filename = g_strconcat(purple_home_dir(), "/.anyone", NULL);
1520 if ((fd = g_fopen(filename, "r")) != NULL) { 1520 if ((fd = g_fopen(filename, "r")) != NULL) {
1521 while (fgets(buff, BUFSIZ, fd)) { 1521 while (fgets(buff, BUFSIZ, fd)) {
1522 strip_comments(buff); 1522 strip_comments(buff);
1523 if (buff[0]) { 1523 if (buff[0]) {
1524 if (!(b = purple_find_buddy(gc->account, buff))) { 1524 if (!(b = purple_find_buddy(purple_connection_get_account(gc), buff))) {
1525 char *stripped_user = zephyr_strip_local_realm(zephyr,buff); 1525 char *stripped_user = zephyr_strip_local_realm(zephyr,buff);
1526 purple_debug_info("zephyr","stripped_user %s\n",stripped_user); 1526 purple_debug_info("zephyr","stripped_user %s\n",stripped_user);
1527 if (!(b = purple_find_buddy(gc->account,stripped_user))){ 1527 if (!(b = purple_find_buddy(purple_connection_get_account(gc),stripped_user))){
1528 b = purple_buddy_new(gc->account, stripped_user, NULL); 1528 b = purple_buddy_new(purple_connection_get_account(gc), stripped_user, NULL);
1529 purple_blist_add_buddy(b, NULL, g, NULL); 1529 purple_blist_add_buddy(b, NULL, g, NULL);
1530 } 1530 }
1531 g_free(stripped_user); 1531 g_free(stripped_user);
1532 } 1532 }
1533 } 1533 }
1562 gboolean read_anyone; 1562 gboolean read_anyone;
1563 gboolean read_zsubs; 1563 gboolean read_zsubs;
1564 gchar *exposure; 1564 gchar *exposure;
1565 1565
1566 gc = purple_account_get_connection(account); 1566 gc = purple_account_get_connection(account);
1567 read_anyone = purple_account_get_bool(gc->account,"read_anyone",TRUE); 1567 read_anyone = purple_account_get_bool(purple_connection_get_account(gc),"read_anyone",TRUE);
1568 read_zsubs = purple_account_get_bool(gc->account,"read_zsubs",TRUE); 1568 read_zsubs = purple_account_get_bool(purple_connection_get_account(gc),"read_zsubs",TRUE);
1569 exposure = (gchar *)purple_account_get_string(gc->account, "exposure_level", EXPOSE_REALMVIS); 1569 exposure = (gchar *)purple_account_get_string(purple_connection_get_account(gc), "exposure_level", EXPOSE_REALMVIS);
1570 1570
1571 #ifdef WIN32 1571 #ifdef WIN32
1572 username = purple_account_get_username(account); 1572 username = purple_account_get_username(account);
1573 #endif 1573 #endif
1574 gc->flags |= PURPLE_CONNECTION_AUTO_RESP | PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_BGCOLOR | PURPLE_CONNECTION_NO_URLDESC; 1574 purple_connection_set_flags(gc, PURPLE_CONNECTION_AUTO_RESP | PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_BGCOLOR | PURPLE_CONNECTION_NO_URLDESC);
1575 gc->proto_data = zephyr=g_new0(zephyr_account,1); 1575 zephyr = g_new0(zephyr_account, 1);
1576 purple_connection_set_protocol_data(gc, zephyr);
1576 1577
1577 zephyr->account = account; 1578 zephyr->account = account;
1578 1579
1579 /* Make sure that the exposure (visibility) is set to a sane value */ 1580 /* Make sure that the exposure (visibility) is set to a sane value */
1580 zephyr->exposure=g_strdup(normalize_zephyr_exposure(exposure)); 1581 zephyr->exposure=g_strdup(normalize_zephyr_exposure(exposure));
1581 1582
1582 if (purple_account_get_bool(gc->account,"use_tzc",0)) { 1583 if (purple_account_get_bool(purple_connection_get_account(gc),"use_tzc",0)) {
1583 zephyr->connection_type = PURPLE_ZEPHYR_TZC; 1584 zephyr->connection_type = PURPLE_ZEPHYR_TZC;
1584 } else { 1585 } else {
1585 zephyr->connection_type = PURPLE_ZEPHYR_KRB4; 1586 zephyr->connection_type = PURPLE_ZEPHYR_KRB4;
1586 } 1587 }
1587 1588
1588 zephyr->encoding = (char *)purple_account_get_string(gc->account, "encoding", ZEPHYR_FALLBACK_CHARSET); 1589 zephyr->encoding = (char *)purple_account_get_string(purple_connection_get_account(gc), "encoding", ZEPHYR_FALLBACK_CHARSET);
1589 purple_connection_update_progress(gc, _("Connecting"), 0, 8); 1590 purple_connection_update_progress(gc, _("Connecting"), 0, 8);
1590 1591
1591 /* XXX z_call_s should actually try to report the com_err determined error */ 1592 /* XXX z_call_s should actually try to report the com_err determined error */
1592 if (use_tzc(zephyr)) { 1593 if (use_tzc(zephyr)) {
1593 pid_t pid; 1594 pid_t pid;
1604 exit(-1); 1605 exit(-1);
1605 } 1606 }
1606 if (pid == 0) { 1607 if (pid == 0) {
1607 unsigned int i=0; 1608 unsigned int i=0;
1608 gboolean found_ps = FALSE; 1609 gboolean found_ps = FALSE;
1609 gchar ** tzc_cmd_array = g_strsplit(purple_account_get_string(gc->account,"tzc_command","/usr/bin/tzc -e %s")," ",0); 1610 gchar ** tzc_cmd_array = g_strsplit(purple_account_get_string(purple_connection_get_account(gc),"tzc_command","/usr/bin/tzc -e %s")," ",0);
1610 if (close(1) == -1) { 1611 if (close(1) == -1) {
1611 exit(-1); 1612 exit(-1);
1612 } 1613 }
1613 if (dup2(zephyr->fromtzc[1], 1) == -1) { 1614 if (dup2(zephyr->fromtzc[1], 1) == -1) {
1614 exit(-1); 1615 exit(-1);
1776 1777
1777 zephyr->username = g_strdup_printf("%s",username); 1778 zephyr->username = g_strdup_printf("%s",username);
1778 if ((realm = strchr(username,'@'))) 1779 if ((realm = strchr(username,'@')))
1779 zephyr->realm = g_strdup_printf("%s",realm+1); 1780 zephyr->realm = g_strdup_printf("%s",realm+1);
1780 else { 1781 else {
1781 realm = (gchar *)purple_account_get_string(gc->account,"realm",""); 1782 realm = (gchar *)purple_account_get_string(purple_connection_get_account(gc),"realm","");
1782 if (!*realm) { 1783 if (!*realm) {
1783 realm = "local-realm"; 1784 realm = "local-realm";
1784 } 1785 }
1785 zephyr->realm = g_strdup(realm); 1786 zephyr->realm = g_strdup(realm);
1786 g_strlcpy(__Zephyr_realm, (const char*)zephyr->realm, REALM_SZ-1); 1787 g_strlcpy(__Zephyr_realm, (const char*)zephyr->realm, REALM_SZ-1);
1813 gchar* realm; 1814 gchar* realm;
1814 z_call_s(ZInitialize(), "Couldn't initialize zephyr"); 1815 z_call_s(ZInitialize(), "Couldn't initialize zephyr");
1815 z_call_s(ZOpenPort(&(zephyr->port)), "Couldn't open port"); 1816 z_call_s(ZOpenPort(&(zephyr->port)), "Couldn't open port");
1816 z_call_s(ZSetLocation((char *)zephyr->exposure), "Couldn't set location"); 1817 z_call_s(ZSetLocation((char *)zephyr->exposure), "Couldn't set location");
1817 1818
1818 realm = (gchar *)purple_account_get_string(gc->account,"realm",""); 1819 realm = (gchar *)purple_account_get_string(purple_connection_get_account(gc),"realm","");
1819 if (!*realm) { 1820 if (!*realm) {
1820 realm = ZGetRealm(); 1821 realm = ZGetRealm();
1821 } 1822 }
1822 zephyr->realm = g_strdup(realm); 1823 zephyr->realm = g_strdup(realm);
1823 g_strlcpy(__Zephyr_realm, (const char*)zephyr->realm, REALM_SZ-1); 1824 g_strlcpy(__Zephyr_realm, (const char*)zephyr->realm, REALM_SZ-1);
1839 zephyr_inithosts(zephyr); 1840 zephyr_inithosts(zephyr);
1840 1841
1841 if (zephyr_subscribe_to(zephyr,"MESSAGE","PERSONAL",zephyr->username,NULL) != ZERR_NONE) { 1842 if (zephyr_subscribe_to(zephyr,"MESSAGE","PERSONAL",zephyr->username,NULL) != ZERR_NONE) {
1842 /* XXX don't translate this yet. It could be written better */ 1843 /* XXX don't translate this yet. It could be written better */
1843 /* XXX error messages could be handled with more detail */ 1844 /* XXX error messages could be handled with more detail */
1844 purple_notify_error(account->gc, NULL, 1845 purple_notify_error(purple_account_get_connection(account), NULL,
1845 "Unable to subscribe to messages", "Unable to subscribe to initial messages"); 1846 "Unable to subscribe to messages", "Unable to subscribe to initial messages");
1846 return; 1847 return;
1847 } 1848 }
1848 1849
1849 purple_connection_set_state(gc, PURPLE_CONNECTED); 1850 purple_connection_set_state(gc, PURPLE_CONNECTED);
1959 1960
1960 static void zephyr_close(PurpleConnection * gc) 1961 static void zephyr_close(PurpleConnection * gc)
1961 { 1962 {
1962 GList *l; 1963 GList *l;
1963 GSList *s; 1964 GSList *s;
1964 zephyr_account *zephyr = gc->proto_data; 1965 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
1965 pid_t tzc_pid = zephyr->tzc_pid; 1966 pid_t tzc_pid = zephyr->tzc_pid;
1966 1967
1967 l = zephyr->pending_zloc_names; 1968 l = zephyr->pending_zloc_names;
1968 while (l) { 1969 while (l) {
1969 g_free((char *)l->data); 1970 g_free((char *)l->data);
1970 l = l->next; 1971 l = l->next;
1971 } 1972 }
1972 g_list_free(zephyr->pending_zloc_names); 1973 g_list_free(zephyr->pending_zloc_names);
1973 1974
1974 if (purple_account_get_bool(gc->account, "write_anyone", FALSE)) 1975 if (purple_account_get_bool(purple_connection_get_account(gc), "write_anyone", FALSE))
1975 write_anyone(zephyr); 1976 write_anyone(zephyr);
1976 1977
1977 if (purple_account_get_bool(gc->account, "write_zsubs", FALSE)) 1978 if (purple_account_get_bool(purple_connection_get_account(gc), "write_zsubs", FALSE))
1978 write_zsubs(zephyr); 1979 write_zsubs(zephyr);
1979 1980
1980 s = zephyr->subscrips; 1981 s = zephyr->subscrips;
1981 while (s) { 1982 while (s) {
1982 free_triple((zephyr_triple *) s->data); 1983 free_triple((zephyr_triple *) s->data);
2034 const char *sig; 2035 const char *sig;
2035 PurpleConversation *gconv1; 2036 PurpleConversation *gconv1;
2036 PurpleConvChat *gcc; 2037 PurpleConvChat *gcc;
2037 char *inst; 2038 char *inst;
2038 char *recipient; 2039 char *recipient;
2039 zephyr_account *zephyr = gc->proto_data; 2040 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
2040 2041
2041 zt = find_sub_by_id(zephyr,id); 2042 zt = find_sub_by_id(zephyr,id);
2042 if (!zt) 2043 if (!zt)
2043 /* this should never happen. */ 2044 /* this should never happen. */
2044 return -EINVAL; 2045 return -EINVAL;
2045 2046
2046 sig = zephyr_get_signature(); 2047 sig = zephyr_get_signature();
2047 2048
2048 gconv1 = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, zt->name, 2049 gconv1 = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, zt->name,
2049 gc->account); 2050 purple_connection_get_account(gc));
2050 gcc = purple_conversation_get_chat_data(gconv1); 2051 gcc = purple_conversation_get_chat_data(gconv1);
2051 2052
2052 if (!(inst = (char *)purple_conv_chat_get_topic(gcc))) 2053 if (!(inst = (char *)purple_conv_chat_get_topic(gcc)))
2053 inst = g_strdup("PERSONAL"); 2054 inst = g_strdup("PERSONAL");
2054 2055
2063 2064
2064 2065
2065 static int zephyr_send_im(PurpleConnection * gc, const char *who, const char *im, PurpleMessageFlags flags) 2066 static int zephyr_send_im(PurpleConnection * gc, const char *who, const char *im, PurpleMessageFlags flags)
2066 { 2067 {
2067 const char *sig; 2068 const char *sig;
2068 zephyr_account *zephyr = gc->proto_data; 2069 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
2069 if (flags & PURPLE_MESSAGE_AUTO_RESP) 2070 if (flags & PURPLE_MESSAGE_AUTO_RESP)
2070 sig = "Automated reply:"; 2071 sig = "Automated reply:";
2071 else { 2072 else {
2072 sig = zephyr_get_signature(); 2073 sig = zephyr_get_signature();
2073 } 2074 }
2232 2233
2233 gc = purple_account_get_connection(account); 2234 gc = purple_account_get_connection(account);
2234 if (gc == NULL) 2235 if (gc == NULL)
2235 return NULL; 2236 return NULL;
2236 2237
2237 tmp = local_zephyr_normalize(gc->proto_data, who); 2238 tmp = local_zephyr_normalize(purple_connection_get_protocol_data(gc), who);
2238 2239
2239 if (strlen(tmp) >= sizeof(buf)) { 2240 if (strlen(tmp) >= sizeof(buf)) {
2240 g_free(tmp); 2241 g_free(tmp);
2241 return NULL; 2242 return NULL;
2242 } 2243 }
2248 } 2249 }
2249 2250
2250 static void zephyr_zloc(PurpleConnection *gc, const char *who) 2251 static void zephyr_zloc(PurpleConnection *gc, const char *who)
2251 { 2252 {
2252 ZAsyncLocateData_t ald; 2253 ZAsyncLocateData_t ald;
2253 zephyr_account *zephyr = gc->proto_data; 2254 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
2254 gchar* normalized_who = local_zephyr_normalize(zephyr,who); 2255 gchar* normalized_who = local_zephyr_normalize(zephyr,who);
2255 2256
2256 if (use_zeph02(zephyr)) { 2257 if (use_zeph02(zephyr)) {
2257 if (ZRequestLocations(normalized_who, &ald, UNACKED, ZAUTH) == ZERR_NONE) { 2258 if (ZRequestLocations(normalized_who, &ald, UNACKED, ZAUTH) == ZERR_NONE) {
2258 zephyr->pending_zloc_names = g_list_append(zephyr->pending_zloc_names, 2259 zephyr->pending_zloc_names = g_list_append(zephyr->pending_zloc_names,
2275 } 2276 }
2276 2277
2277 static void zephyr_set_status(PurpleAccount *account, PurpleStatus *status) { 2278 static void zephyr_set_status(PurpleAccount *account, PurpleStatus *status) {
2278 size_t len; 2279 size_t len;
2279 size_t result; 2280 size_t result;
2280 zephyr_account *zephyr = purple_account_get_connection(account)->proto_data; 2281 PurpleConnection *gc = purple_account_get_connection(account);
2282 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
2281 PurpleStatusPrimitive primitive = purple_status_type_get_primitive(purple_status_get_type(status)); 2283 PurpleStatusPrimitive primitive = purple_status_type_get_primitive(purple_status_get_type(status));
2282 2284
2283 if (zephyr->away) { 2285 if (zephyr->away) {
2284 g_free(zephyr->away); 2286 g_free(zephyr->away);
2285 zephyr->away=NULL; 2287 zephyr->away=NULL;
2409 /* ZSubscription_t sub; */ 2411 /* ZSubscription_t sub; */
2410 zephyr_triple *zt1, *zt2; 2412 zephyr_triple *zt1, *zt2;
2411 const char *classname; 2413 const char *classname;
2412 const char *instname; 2414 const char *instname;
2413 const char *recip; 2415 const char *recip;
2414 zephyr_account *zephyr=gc->proto_data; 2416 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
2415 classname = g_hash_table_lookup(data, "class"); 2417 classname = g_hash_table_lookup(data, "class");
2416 instname = g_hash_table_lookup(data, "instance"); 2418 instname = g_hash_table_lookup(data, "instance");
2417 recip = g_hash_table_lookup(data, "recipient"); 2419 recip = g_hash_table_lookup(data, "recipient");
2418 2420
2419 2421
2472 } 2474 }
2473 2475
2474 static void zephyr_chat_leave(PurpleConnection * gc, int id) 2476 static void zephyr_chat_leave(PurpleConnection * gc, int id)
2475 { 2477 {
2476 zephyr_triple *zt; 2478 zephyr_triple *zt;
2477 zephyr_account *zephyr = gc->proto_data; 2479 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
2478 zt = find_sub_by_id(zephyr,id); 2480 zt = find_sub_by_id(zephyr,id);
2479 2481
2480 if (zt) { 2482 if (zt) {
2481 zt->open = FALSE; 2483 zt->open = FALSE;
2482 zt->id = ++(zephyr->last_id); 2484 zt->id = ++(zephyr->last_id);
2522 return "zephyr"; 2524 return "zephyr";
2523 } 2525 }
2524 2526
2525 static unsigned int zephyr_send_typing(PurpleConnection *gc, const char *who, PurpleTypingState state) { 2527 static unsigned int zephyr_send_typing(PurpleConnection *gc, const char *who, PurpleTypingState state) {
2526 gchar *recipient; 2528 gchar *recipient;
2527 zephyr_account *zephyr = gc->proto_data; 2529 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
2528 if (use_tzc(zephyr)) 2530 if (use_tzc(zephyr))
2529 return 0; 2531 return 0;
2530 2532
2531 if (state == PURPLE_NOT_TYPING) 2533 if (state == PURPLE_NOT_TYPING)
2532 return 0; 2534 return 0;
2564 { 2566 {
2565 zephyr_triple *zt; 2567 zephyr_triple *zt;
2566 PurpleConversation *gconv; 2568 PurpleConversation *gconv;
2567 PurpleConvChat *gcc; 2569 PurpleConvChat *gcc;
2568 gchar *topic_utf8; 2570 gchar *topic_utf8;
2569 zephyr_account* zephyr = gc->proto_data; 2571 zephyr_account* zephyr = purple_connection_get_protocol_data(gc);
2570 char *sender = (char *)zephyr->username; 2572 char *sender = (char *)zephyr->username;
2571 2573
2572 zt = find_sub_by_id(zephyr,id); 2574 zt = find_sub_by_id(zephyr,id);
2573 /* find_sub_by_id can return NULL */ 2575 /* find_sub_by_id can return NULL */
2574 if (!zt) 2576 if (!zt)
2575 return; 2577 return;
2576 gconv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, zt->name, 2578 gconv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, zt->name,
2577 gc->account); 2579 purple_connection_get_account(gc));
2578 gcc = purple_conversation_get_chat_data(gconv); 2580 gcc = purple_conversation_get_chat_data(gconv);
2579 2581
2580 topic_utf8 = zephyr_recv_convert(gc,(gchar *)topic); 2582 topic_utf8 = zephyr_recv_convert(gc,(gchar *)topic);
2581 purple_conv_chat_set_topic(gcc,sender,topic_utf8); 2583 purple_conv_chat_set_topic(gcc,sender,topic_utf8);
2582 g_free(topic_utf8); 2584 g_free(topic_utf8);
2587 2589
2588 static PurpleCmdRet zephyr_purple_cmd_msg(PurpleConversation *conv, 2590 static PurpleCmdRet zephyr_purple_cmd_msg(PurpleConversation *conv,
2589 const char *cmd, char **args, char **error, void *data) 2591 const char *cmd, char **args, char **error, void *data)
2590 { 2592 {
2591 char *recipient; 2593 char *recipient;
2592 zephyr_account *zephyr = purple_conversation_get_gc(conv)->proto_data; 2594 PurpleConnection *gc = purple_conversation_get_connection(conv);
2595 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);;
2593 if (!g_ascii_strcasecmp(args[0],"*")) 2596 if (!g_ascii_strcasecmp(args[0],"*"))
2594 return PURPLE_CMD_RET_FAILED; /* "*" is not a valid argument */ 2597 return PURPLE_CMD_RET_FAILED; /* "*" is not a valid argument */
2595 else 2598 else
2596 recipient = local_zephyr_normalize(zephyr,args[0]); 2599 recipient = local_zephyr_normalize(zephyr,args[0]);
2597 2600
2605 } 2608 }
2606 2609
2607 static PurpleCmdRet zephyr_purple_cmd_zlocate(PurpleConversation *conv, 2610 static PurpleCmdRet zephyr_purple_cmd_zlocate(PurpleConversation *conv,
2608 const char *cmd, char **args, char **error, void *data) 2611 const char *cmd, char **args, char **error, void *data)
2609 { 2612 {
2610 zephyr_zloc(purple_conversation_get_gc(conv),args[0]); 2613 zephyr_zloc(purple_conversation_get_connection(conv),args[0]);
2611 return PURPLE_CMD_RET_OK; 2614 return PURPLE_CMD_RET_OK;
2612 } 2615 }
2613 2616
2614 static PurpleCmdRet zephyr_purple_cmd_instance(PurpleConversation *conv, 2617 static PurpleCmdRet zephyr_purple_cmd_instance(PurpleConversation *conv,
2615 const char *cmd, char **args, char **error, void *data) 2618 const char *cmd, char **args, char **error, void *data)
2617 /* Currently it sets the instance with leading spaces and 2620 /* Currently it sets the instance with leading spaces and
2618 * all. This might not be the best thing to do, though having 2621 * all. This might not be the best thing to do, though having
2619 * one word isn't ideal either. */ 2622 * one word isn't ideal either. */
2620 2623
2621 PurpleConvChat *gcc = purple_conversation_get_chat_data(conv); 2624 PurpleConvChat *gcc = purple_conversation_get_chat_data(conv);
2622 int id = gcc->id;
2623 const char* instance = args[0]; 2625 const char* instance = args[0];
2624 zephyr_chat_set_topic(purple_conversation_get_gc(conv),id,instance); 2626 zephyr_chat_set_topic(purple_conversation_get_connection(conv),purple_conv_chat_get_id(gcc),instance);
2625 return PURPLE_CMD_RET_OK; 2627 return PURPLE_CMD_RET_OK;
2626 } 2628 }
2627 2629
2628 static PurpleCmdRet zephyr_purple_cmd_joinchat_cir(PurpleConversation *conv, 2630 static PurpleCmdRet zephyr_purple_cmd_joinchat_cir(PurpleConversation *conv,
2629 const char *cmd, char **args, char **error, void *data) 2631 const char *cmd, char **args, char **error, void *data)
2631 /* Join a new zephyr chat */ 2633 /* Join a new zephyr chat */
2632 GHashTable *triple = g_hash_table_new(NULL,NULL); 2634 GHashTable *triple = g_hash_table_new(NULL,NULL);
2633 g_hash_table_insert(triple,"class",args[0]); 2635 g_hash_table_insert(triple,"class",args[0]);
2634 g_hash_table_insert(triple,"instance",args[1]); 2636 g_hash_table_insert(triple,"instance",args[1]);
2635 g_hash_table_insert(triple,"recipient",args[2]); 2637 g_hash_table_insert(triple,"recipient",args[2]);
2636 zephyr_join_chat(purple_conversation_get_gc(conv),triple); 2638 zephyr_join_chat(purple_conversation_get_connection(conv),triple);
2637 return PURPLE_CMD_RET_OK; 2639 return PURPLE_CMD_RET_OK;
2638 } 2640 }
2639 2641
2640 static PurpleCmdRet zephyr_purple_cmd_zi(PurpleConversation *conv, 2642 static PurpleCmdRet zephyr_purple_cmd_zi(PurpleConversation *conv,
2641 const char *cmd, char **args, char **error, void *data) 2643 const char *cmd, char **args, char **error, void *data)
2642 { 2644 {
2643 /* args = instance, message */ 2645 /* args = instance, message */
2644 zephyr_account *zephyr = purple_conversation_get_gc(conv)->proto_data; 2646 PurpleConnection *gc = purple_conversation_get_connection(conv);
2647 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
2645 if ( zephyr_send_message(zephyr,"message",args[0],"",args[1],zephyr_get_signature(),"")) 2648 if ( zephyr_send_message(zephyr,"message",args[0],"",args[1],zephyr_get_signature(),""))
2646 return PURPLE_CMD_RET_OK; 2649 return PURPLE_CMD_RET_OK;
2647 else 2650 else
2648 return PURPLE_CMD_RET_FAILED; 2651 return PURPLE_CMD_RET_FAILED;
2649 } 2652 }
2650 2653
2651 static PurpleCmdRet zephyr_purple_cmd_zci(PurpleConversation *conv, 2654 static PurpleCmdRet zephyr_purple_cmd_zci(PurpleConversation *conv,
2652 const char *cmd, char **args, char **error, void *data) 2655 const char *cmd, char **args, char **error, void *data)
2653 { 2656 {
2654 /* args = class, instance, message */ 2657 /* args = class, instance, message */
2655 zephyr_account *zephyr = purple_conversation_get_gc(conv)->proto_data; 2658 PurpleConnection *gc = purple_conversation_get_connection(conv);
2659 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
2656 if ( zephyr_send_message(zephyr,args[0],args[1],"",args[2],zephyr_get_signature(),"")) 2660 if ( zephyr_send_message(zephyr,args[0],args[1],"",args[2],zephyr_get_signature(),""))
2657 return PURPLE_CMD_RET_OK; 2661 return PURPLE_CMD_RET_OK;
2658 else 2662 else
2659 return PURPLE_CMD_RET_FAILED; 2663 return PURPLE_CMD_RET_FAILED;
2660 } 2664 }
2661 2665
2662 static PurpleCmdRet zephyr_purple_cmd_zcir(PurpleConversation *conv, 2666 static PurpleCmdRet zephyr_purple_cmd_zcir(PurpleConversation *conv,
2663 const char *cmd, char **args, char **error, void *data) 2667 const char *cmd, char **args, char **error, void *data)
2664 { 2668 {
2665 /* args = class, instance, recipient, message */ 2669 /* args = class, instance, recipient, message */
2666 zephyr_account *zephyr = purple_conversation_get_gc(conv)->proto_data; 2670 PurpleConnection *gc = purple_conversation_get_connection(conv);
2671 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
2667 if ( zephyr_send_message(zephyr,args[0],args[1],args[2],args[3],zephyr_get_signature(),"")) 2672 if ( zephyr_send_message(zephyr,args[0],args[1],args[2],args[3],zephyr_get_signature(),""))
2668 return PURPLE_CMD_RET_OK; 2673 return PURPLE_CMD_RET_OK;
2669 else 2674 else
2670 return PURPLE_CMD_RET_FAILED; 2675 return PURPLE_CMD_RET_FAILED;
2671 } 2676 }
2672 2677
2673 static PurpleCmdRet zephyr_purple_cmd_zir(PurpleConversation *conv, 2678 static PurpleCmdRet zephyr_purple_cmd_zir(PurpleConversation *conv,
2674 const char *cmd, char **args, char **error, void *data) 2679 const char *cmd, char **args, char **error, void *data)
2675 { 2680 {
2676 /* args = instance, recipient, message */ 2681 /* args = instance, recipient, message */
2677 zephyr_account *zephyr = purple_conversation_get_gc(conv)->proto_data; 2682 PurpleConnection *gc = purple_conversation_get_connection(conv);
2683 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
2678 if ( zephyr_send_message(zephyr,"message",args[0],args[1],args[2],zephyr_get_signature(),"")) 2684 if ( zephyr_send_message(zephyr,"message",args[0],args[1],args[2],zephyr_get_signature(),""))
2679 return PURPLE_CMD_RET_OK; 2685 return PURPLE_CMD_RET_OK;
2680 else 2686 else
2681 return PURPLE_CMD_RET_FAILED; 2687 return PURPLE_CMD_RET_FAILED;
2682 } 2688 }
2683 2689
2684 static PurpleCmdRet zephyr_purple_cmd_zc(PurpleConversation *conv, 2690 static PurpleCmdRet zephyr_purple_cmd_zc(PurpleConversation *conv,
2685 const char *cmd, char **args, char **error, void *data) 2691 const char *cmd, char **args, char **error, void *data)
2686 { 2692 {
2687 /* args = class, message */ 2693 /* args = class, message */
2688 zephyr_account *zephyr = purple_conversation_get_gc(conv)->proto_data; 2694 PurpleConnection *gc = purple_conversation_get_connection(conv);
2695 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
2689 if ( zephyr_send_message(zephyr,args[0],"PERSONAL","",args[1],zephyr_get_signature(),"")) 2696 if ( zephyr_send_message(zephyr,args[0],"PERSONAL","",args[1],zephyr_get_signature(),""))
2690 return PURPLE_CMD_RET_OK; 2697 return PURPLE_CMD_RET_OK;
2691 else 2698 else
2692 return PURPLE_CMD_RET_FAILED; 2699 return PURPLE_CMD_RET_FAILED;
2693 } 2700 }
2764 2771
2765 static int zephyr_resubscribe(PurpleConnection *gc) 2772 static int zephyr_resubscribe(PurpleConnection *gc)
2766 { 2773 {
2767 /* Resubscribe to the in-memory list of subscriptions and also 2774 /* Resubscribe to the in-memory list of subscriptions and also
2768 unsubscriptions*/ 2775 unsubscriptions*/
2769 zephyr_account *zephyr = gc->proto_data; 2776 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
2770 GSList *s = zephyr->subscrips; 2777 GSList *s = zephyr->subscrips;
2771 zephyr_triple *zt; 2778 zephyr_triple *zt;
2772 while (s) { 2779 while (s) {
2773 zt = s->data; 2780 zt = s->data;
2774 /* XXX We really should care if this fails */ 2781 /* XXX We really should care if this fails */
2789 2796
2790 2797
2791 static void zephyr_action_get_subs_from_server(PurplePluginAction *action) 2798 static void zephyr_action_get_subs_from_server(PurplePluginAction *action)
2792 { 2799 {
2793 PurpleConnection *gc = (PurpleConnection *) action->context; 2800 PurpleConnection *gc = (PurpleConnection *) action->context;
2794 zephyr_account *zephyr = gc->proto_data; 2801 zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
2795 gchar *title; 2802 gchar *title;
2796 int retval, nsubs, one,i; 2803 int retval, nsubs, one,i;
2797 ZSubscription_t subs; 2804 ZSubscription_t subs;
2798 if (use_zeph02(zephyr)) { 2805 if (use_zeph02(zephyr)) {
2799 GString* subout = g_string_new("Subscription list<br>"); 2806 GString* subout = g_string_new("Subscription list<br>");
2843 } 2850 }
2844 2851
2845 static PurplePlugin *my_protocol = NULL; 2852 static PurplePlugin *my_protocol = NULL;
2846 2853
2847 static PurplePluginProtocolInfo prpl_info = { 2854 static PurplePluginProtocolInfo prpl_info = {
2855 sizeof(PurplePluginProtocolInfo), /* struct_size */
2848 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_NO_PASSWORD, 2856 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_NO_PASSWORD,
2849 NULL, /* ??? user_splits */ 2857 NULL, /* ??? user_splits */
2850 NULL, /* ??? protocol_options */ 2858 NULL, /* ??? protocol_options */
2851 NO_BUDDY_ICONS, 2859 NO_BUDDY_ICONS,
2852 zephyr_list_icon, 2860 zephyr_list_icon,
2883 NULL, /* chat_whisper -- No "whispering"*/ 2891 NULL, /* chat_whisper -- No "whispering"*/
2884 zephyr_chat_send, /* chat_send */ 2892 zephyr_chat_send, /* chat_send */
2885 NULL, /* keepalive -- Not necessary*/ 2893 NULL, /* keepalive -- Not necessary*/
2886 NULL, /* register_user -- Not supported*/ 2894 NULL, /* register_user -- Not supported*/
2887 NULL, /* XXX get_cb_info */ 2895 NULL, /* XXX get_cb_info */
2888 NULL, /* get_cb_away */
2889 NULL, /* alias_buddy */ 2896 NULL, /* alias_buddy */
2890 NULL, /* group_buddy */ 2897 NULL, /* group_buddy */
2891 NULL, /* rename_group */ 2898 NULL, /* rename_group */
2892 NULL, /* buddy_free */ 2899 NULL, /* buddy_free */
2893 NULL, /* convo_closed */ 2900 NULL, /* convo_closed */
2909 NULL, /* roomlist_room_serialize */ 2916 NULL, /* roomlist_room_serialize */
2910 2917
2911 NULL, 2918 NULL,
2912 NULL, 2919 NULL,
2913 NULL, 2920 NULL,
2914 sizeof(PurplePluginProtocolInfo), /* struct_size */
2915 NULL, /* get_account_text_table */ 2921 NULL, /* get_account_text_table */
2916 NULL, /* initate_media */ 2922 NULL, /* initate_media */
2917 NULL, /* get_media_caps */ 2923 NULL, /* get_media_caps */
2918 NULL, /* get_moods */ 2924 NULL, /* get_moods */
2919 NULL, /* set_public_alias */ 2925 NULL, /* set_public_alias */
2920 NULL, /* get_public_alias */ 2926 NULL /* get_public_alias */
2921 NULL, /* add_buddy_with_invite */
2922 NULL /* add_buddies_with_invite */
2923 }; 2927 };
2924 2928
2925 static PurplePluginInfo info = { 2929 static PurplePluginInfo info = {
2926 PURPLE_PLUGIN_MAGIC, 2930 PURPLE_PLUGIN_MAGIC,
2927 PURPLE_MAJOR_VERSION, 2931 PURPLE_MAJOR_VERSION,