comparison libpurple/protocols/zephyr/zephyr.c @ 32767:2ec94166be43

On the way to hiding the PurpleConnection struct. * Added purple_connection_get_flags() and purple_connection_set_flags() * Use purple_connection_ accessor functions.
author andrew.victor@mxit.com
date Tue, 18 Oct 2011 18:47:48 +0000
parents 10e5000326a5
children 3e7a7e14af62
comparison
equal deleted inserted replaced
32766:ea2b621fd3ba 32767:2ec94166be43
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 {
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)) {
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)) {
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 zephyr = g_new0(zephyr_account, 1); 1575 zephyr = g_new0(zephyr_account, 1);
1576 purple_connection_set_protocol_data(gc, zephyr); 1576 purple_connection_set_protocol_data(gc, zephyr);
1577 1577
1578 zephyr->account = account; 1578 zephyr->account = account;
1579 1579
1580 /* 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 */
1581 zephyr->exposure=g_strdup(normalize_zephyr_exposure(exposure)); 1581 zephyr->exposure=g_strdup(normalize_zephyr_exposure(exposure));
1582 1582
1583 if (purple_account_get_bool(gc->account,"use_tzc",0)) { 1583 if (purple_account_get_bool(purple_connection_get_account(gc),"use_tzc",0)) {
1584 zephyr->connection_type = PURPLE_ZEPHYR_TZC; 1584 zephyr->connection_type = PURPLE_ZEPHYR_TZC;
1585 } else { 1585 } else {
1586 zephyr->connection_type = PURPLE_ZEPHYR_KRB4; 1586 zephyr->connection_type = PURPLE_ZEPHYR_KRB4;
1587 } 1587 }
1588 1588
1589 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);
1590 purple_connection_update_progress(gc, _("Connecting"), 0, 8); 1590 purple_connection_update_progress(gc, _("Connecting"), 0, 8);
1591 1591
1592 /* 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 */
1593 if (use_tzc(zephyr)) { 1593 if (use_tzc(zephyr)) {
1594 pid_t pid; 1594 pid_t pid;
1605 exit(-1); 1605 exit(-1);
1606 } 1606 }
1607 if (pid == 0) { 1607 if (pid == 0) {
1608 unsigned int i=0; 1608 unsigned int i=0;
1609 gboolean found_ps = FALSE; 1609 gboolean found_ps = FALSE;
1610 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);
1611 if (close(1) == -1) { 1611 if (close(1) == -1) {
1612 exit(-1); 1612 exit(-1);
1613 } 1613 }
1614 if (dup2(zephyr->fromtzc[1], 1) == -1) { 1614 if (dup2(zephyr->fromtzc[1], 1) == -1) {
1615 exit(-1); 1615 exit(-1);
1777 1777
1778 zephyr->username = g_strdup_printf("%s",username); 1778 zephyr->username = g_strdup_printf("%s",username);
1779 if ((realm = strchr(username,'@'))) 1779 if ((realm = strchr(username,'@')))
1780 zephyr->realm = g_strdup_printf("%s",realm+1); 1780 zephyr->realm = g_strdup_printf("%s",realm+1);
1781 else { 1781 else {
1782 realm = (gchar *)purple_account_get_string(gc->account,"realm",""); 1782 realm = (gchar *)purple_account_get_string(purple_connection_get_account(gc),"realm","");
1783 if (!*realm) { 1783 if (!*realm) {
1784 realm = "local-realm"; 1784 realm = "local-realm";
1785 } 1785 }
1786 zephyr->realm = g_strdup(realm); 1786 zephyr->realm = g_strdup(realm);
1787 g_strlcpy(__Zephyr_realm, (const char*)zephyr->realm, REALM_SZ-1); 1787 g_strlcpy(__Zephyr_realm, (const char*)zephyr->realm, REALM_SZ-1);
1814 gchar* realm; 1814 gchar* realm;
1815 z_call_s(ZInitialize(), "Couldn't initialize zephyr"); 1815 z_call_s(ZInitialize(), "Couldn't initialize zephyr");
1816 z_call_s(ZOpenPort(&(zephyr->port)), "Couldn't open port"); 1816 z_call_s(ZOpenPort(&(zephyr->port)), "Couldn't open port");
1817 z_call_s(ZSetLocation((char *)zephyr->exposure), "Couldn't set location"); 1817 z_call_s(ZSetLocation((char *)zephyr->exposure), "Couldn't set location");
1818 1818
1819 realm = (gchar *)purple_account_get_string(gc->account,"realm",""); 1819 realm = (gchar *)purple_account_get_string(purple_connection_get_account(gc),"realm","");
1820 if (!*realm) { 1820 if (!*realm) {
1821 realm = ZGetRealm(); 1821 realm = ZGetRealm();
1822 } 1822 }
1823 zephyr->realm = g_strdup(realm); 1823 zephyr->realm = g_strdup(realm);
1824 g_strlcpy(__Zephyr_realm, (const char*)zephyr->realm, REALM_SZ-1); 1824 g_strlcpy(__Zephyr_realm, (const char*)zephyr->realm, REALM_SZ-1);
1970 g_free((char *)l->data); 1970 g_free((char *)l->data);
1971 l = l->next; 1971 l = l->next;
1972 } 1972 }
1973 g_list_free(zephyr->pending_zloc_names); 1973 g_list_free(zephyr->pending_zloc_names);
1974 1974
1975 if (purple_account_get_bool(gc->account, "write_anyone", FALSE)) 1975 if (purple_account_get_bool(purple_connection_get_account(gc), "write_anyone", FALSE))
1976 write_anyone(zephyr); 1976 write_anyone(zephyr);
1977 1977
1978 if (purple_account_get_bool(gc->account, "write_zsubs", FALSE)) 1978 if (purple_account_get_bool(purple_connection_get_account(gc), "write_zsubs", FALSE))
1979 write_zsubs(zephyr); 1979 write_zsubs(zephyr);
1980 1980
1981 s = zephyr->subscrips; 1981 s = zephyr->subscrips;
1982 while (s) { 1982 while (s) {
1983 free_triple((zephyr_triple *) s->data); 1983 free_triple((zephyr_triple *) s->data);
2045 return -EINVAL; 2045 return -EINVAL;
2046 2046
2047 sig = zephyr_get_signature(); 2047 sig = zephyr_get_signature();
2048 2048
2049 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,
2050 gc->account); 2050 purple_connection_get_account(gc));
2051 gcc = purple_conversation_get_chat_data(gconv1); 2051 gcc = purple_conversation_get_chat_data(gconv1);
2052 2052
2053 if (!(inst = (char *)purple_conv_chat_get_topic(gcc))) 2053 if (!(inst = (char *)purple_conv_chat_get_topic(gcc)))
2054 inst = g_strdup("PERSONAL"); 2054 inst = g_strdup("PERSONAL");
2055 2055
2574 zt = find_sub_by_id(zephyr,id); 2574 zt = find_sub_by_id(zephyr,id);
2575 /* find_sub_by_id can return NULL */ 2575 /* find_sub_by_id can return NULL */
2576 if (!zt) 2576 if (!zt)
2577 return; 2577 return;
2578 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,
2579 gc->account); 2579 purple_connection_get_account(gc));
2580 gcc = purple_conversation_get_chat_data(gconv); 2580 gcc = purple_conversation_get_chat_data(gconv);
2581 2581
2582 topic_utf8 = zephyr_recv_convert(gc,(gchar *)topic); 2582 topic_utf8 = zephyr_recv_convert(gc,(gchar *)topic);
2583 purple_conv_chat_set_topic(gcc,sender,topic_utf8); 2583 purple_conv_chat_set_topic(gcc,sender,topic_utf8);
2584 g_free(topic_utf8); 2584 g_free(topic_utf8);