comparison mcabber/src/jab_iq.c @ 603:9516db839e08

Store subscription data
author Mikael Berthe <mikael@lilotux.net>
date Thu, 15 Dec 2005 12:52:37 +0100
parents 96831b222903
children 2a4fefb98511
comparison
equal deleted inserted replaced
602:7b20c27cae48 603:9516db839e08
19 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 * USA 21 * USA
22 */ 22 */
23 23
24 #include <glib.h>
25
24 #include "jabglue.h" 26 #include "jabglue.h"
25 #include "jab_priv.h" 27 #include "jab_priv.h"
26 #include "roster.h" 28 #include "roster.h"
27 #include "utils.h" 29 #include "utils.h"
28 #include "logprint.h" 30 #include "screen.h"
29 31
30 int s_id; // XXX 32 int s_id; // XXX
31 33
32 static void gotloggedin(void) 34 static void gotloggedin(void)
33 { 35 {
45 } 47 }
46 48
47 static void gotroster(xmlnode x) 49 static void gotroster(xmlnode x)
48 { 50 {
49 xmlnode y; 51 xmlnode y;
50 const char *jid, *name, *group; 52 const char *jid, *name, *group, *sub;
51 char *buddyname; 53 char *buddyname;
52 char *cleanalias; 54 char *cleanalias;
55 enum subscr esub;
56 int need_refresh = FALSE;
53 57
54 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) { 58 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) {
55 gchar *name_noutf8 = NULL; 59 gchar *name_noutf8 = NULL;
56 gchar *group_noutf8 = NULL; 60 gchar *group_noutf8 = NULL;
57 61
58 jid = xmlnode_get_attrib(y, "jid"); 62 jid = xmlnode_get_attrib(y, "jid");
59 name = xmlnode_get_attrib(y, "name"); 63 name = xmlnode_get_attrib(y, "name");
60 //sub = xmlnode_get_attrib(y, "subscription"); // TODO Not used 64 sub = xmlnode_get_attrib(y, "subscription");
61 65
62 group = xmlnode_get_tag_data(y, "group"); 66 group = xmlnode_get_tag_data(y, "group");
63 67
64 if (!jid) 68 if (!jid)
65 continue; 69 continue;
66 70
67 buddyname = cleanalias = jidtodisp(jid); 71 buddyname = cleanalias = jidtodisp(jid);
72
73 esub = sub_none;
74 if (sub) {
75 if (!strcmp(sub, "to")) esub = sub_to;
76 else if (!strcmp(sub, "from")) esub = sub_from;
77 else if (!strcmp(sub, "both")) esub = sub_both;
78 else if (!strcmp(sub, "remove")) esub = sub_remove;
79 }
80
81 if (esub == sub_remove) {
82 roster_del_user(cleanalias);
83 scr_LogPrint(LPRINT_LOGNORM, "Buddy <%s> has been removed "
84 "from the roster", cleanalias);
85 g_free(cleanalias);
86 need_refresh = TRUE;
87 continue;
88 }
68 89
69 if (name) { 90 if (name) {
70 name_noutf8 = from_utf8(name); 91 name_noutf8 = from_utf8(name);
71 if (name_noutf8) 92 if (name_noutf8)
72 buddyname = name_noutf8; 93 buddyname = name_noutf8;
80 if (!group_noutf8) 101 if (!group_noutf8)
81 scr_LogPrint(LPRINT_LOG, "Decoding of buddy group has failed: %s", 102 scr_LogPrint(LPRINT_LOG, "Decoding of buddy group has failed: %s",
82 group); 103 group);
83 } 104 }
84 105
85 roster_add_user(cleanalias, buddyname, group_noutf8, ROSTER_TYPE_USER); 106 roster_add_user(cleanalias, buddyname, group_noutf8, ROSTER_TYPE_USER,
107 esub);
108
86 if (name_noutf8) g_free(name_noutf8); 109 if (name_noutf8) g_free(name_noutf8);
87 if (group_noutf8) g_free(group_noutf8); 110 if (group_noutf8) g_free(group_noutf8);
88 g_free(cleanalias); 111 g_free(cleanalias);
89 } 112 }
90 113
91 // Post-login stuff
92 jb_setstatus(available, NULL, NULL);
93 buddylist_build(); 114 buddylist_build();
115 update_roster = TRUE;
116 if (need_refresh)
117 scr_ShowBuddyWindow();
94 } 118 }
95 119
96 static void gotagents(jconn conn, xmlnode x) 120 static void gotagents(jconn conn, xmlnode x)
97 { 121 {
98 xmlnode y; 122 xmlnode y;
118 else if (xmlnode_get_tag(y, "search")) atype = search; 142 else if (xmlnode_get_tag(y, "search")) atype = search;
119 143
120 if (atype == transport) { 144 if (atype == transport) {
121 char *cleanjid = jidtodisp(alias); 145 char *cleanjid = jidtodisp(alias);
122 roster_add_user(cleanjid, NULL, JABBER_AGENT_GROUP, 146 roster_add_user(cleanjid, NULL, JABBER_AGENT_GROUP,
123 ROSTER_TYPE_AGENT); 147 ROSTER_TYPE_AGENT, sub_none);
124 g_free(cleanjid); 148 g_free(cleanjid);
125 } 149 }
126 if (alias && name && desc) { 150 if (alias && name && desc) {
127 scr_LogPrint(LPRINT_LOGNORM, "Agent: %s / %s / %s / type=%d", 151 scr_LogPrint(LPRINT_LOGNORM, "Agent: %s / %s / %s / type=%d",
128 alias, name, desc, atype); 152 alias, name, desc, atype);
191 ns = xmlnode_get_attrib(x, "xmlns"); 215 ns = xmlnode_get_attrib(x, "xmlns");
192 if (!ns) return; 216 if (!ns) return;
193 217
194 if (!strcmp(ns, NS_ROSTER)) { 218 if (!strcmp(ns, NS_ROSTER)) {
195 gotroster(x); 219 gotroster(x);
220
221 // Post-login stuff FIXME shouldn't be there
222 jb_setstatus(available, NULL, NULL);
196 } else if (!strcmp(ns, NS_AGENTS)) { 223 } else if (!strcmp(ns, NS_AGENTS)) {
197 gotagents(conn, x); 224 gotagents(conn, x);
198 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) { 225 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) {
199 char *id = xmlnode_get_attrib(xmldata, "id"); 226 char *id = xmlnode_get_attrib(xmldata, "id");
200 if (!id) id = ""; 227 if (!id) id = "";