Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jab_iq.c @ 606:0b4ed231ebc2
Code cleanup + remove deprecated Agents list IQ request
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Thu, 15 Dec 2005 15:40:21 +0100 |
parents | 2a4fefb98511 |
children | cf722bff6579 |
comparison
equal
deleted
inserted
replaced
605:2a4fefb98511 | 606:0b4ed231ebc2 |
---|---|
29 #include "utils.h" | 29 #include "utils.h" |
30 #include "screen.h" | 30 #include "screen.h" |
31 | 31 |
32 int s_id; // XXX | 32 int s_id; // XXX |
33 | 33 |
34 static void gotloggedin(void) | 34 static void request_roster(void) |
35 { | 35 { |
36 xmlnode x; | 36 xmlnode x = jutil_iqnew(JPACKET__GET, NS_ROSTER); |
37 | 37 xmlnode_put_attrib(x, "id", "Roster1"); // XXX |
38 x = jutil_iqnew(JPACKET__GET, NS_AGENTS); | |
39 xmlnode_put_attrib(x, "id", "Agent List"); | |
40 jab_send(jc, x); | 38 jab_send(jc, x); |
41 xmlnode_free(x); | 39 xmlnode_free(x); |
42 | 40 } |
43 x = jutil_iqnew(JPACKET__GET, NS_ROSTER); | 41 |
44 xmlnode_put_attrib(x, "id", "Roster"); | 42 static void handle_iq_roster(xmlnode x) |
45 jab_send(jc, x); | |
46 xmlnode_free(x); | |
47 } | |
48 | |
49 static void gotroster(xmlnode x) | |
50 { | 43 { |
51 xmlnode y; | 44 xmlnode y; |
52 const char *jid, *name, *group, *sub, *ask; | 45 const char *jid, *name, *group, *sub, *ask; |
53 char *buddyname; | 46 char *buddyname; |
54 char *cleanalias; | 47 char *cleanalias; |
119 update_roster = TRUE; | 112 update_roster = TRUE; |
120 if (need_refresh) | 113 if (need_refresh) |
121 scr_ShowBuddyWindow(); | 114 scr_ShowBuddyWindow(); |
122 } | 115 } |
123 | 116 |
124 static void gotagents(jconn conn, xmlnode x) | |
125 { | |
126 xmlnode y; | |
127 const char *alias; | |
128 const char *name, *desc; | |
129 | |
130 y = xmlnode_get_tag(x, "agent"); | |
131 | |
132 for (; y; y = xmlnode_get_nextsibling(y)) { | |
133 enum agtype atype = unknown; | |
134 | |
135 alias = xmlnode_get_attrib(y, "jid"); | |
136 if (!alias) | |
137 continue; | |
138 | |
139 name = xmlnode_get_tag_data(y, "name"); | |
140 desc = xmlnode_get_tag_data(y, "description"); | |
141 // TODO | |
142 // service = xmlnode_get_tag_data(y, "service"); | |
143 | |
144 if (xmlnode_get_tag(y, TMSG_GROUPCHAT)) atype = groupchat; | |
145 else if (xmlnode_get_tag(y, "transport")) atype = transport; | |
146 else if (xmlnode_get_tag(y, "search")) atype = search; | |
147 | |
148 if (atype == transport) { | |
149 char *cleanjid = jidtodisp(alias); | |
150 roster_add_user(cleanjid, NULL, JABBER_AGENT_GROUP, | |
151 ROSTER_TYPE_AGENT, sub_none); | |
152 g_free(cleanjid); | |
153 } | |
154 if (alias && name && desc) { | |
155 scr_LogPrint(LPRINT_LOGNORM, "Agent: %s / %s / %s / type=%d", | |
156 alias, name, desc, atype); | |
157 | |
158 if (atype == search) { | |
159 x = jutil_iqnew (JPACKET__GET, NS_SEARCH); | |
160 xmlnode_put_attrib(x, "to", alias); | |
161 xmlnode_put_attrib(x, "id", "Agent info"); | |
162 jab_send(conn, x); | |
163 xmlnode_free(x); | |
164 } | |
165 | |
166 if (xmlnode_get_tag(y, "register")) { | |
167 x = jutil_iqnew (JPACKET__GET, NS_REGISTER); | |
168 xmlnode_put_attrib(x, "to", alias); | |
169 xmlnode_put_attrib(x, "id", "Agent info"); | |
170 jab_send(conn, x); | |
171 xmlnode_free(x); | |
172 } | |
173 } | |
174 } | |
175 } | |
176 | |
177 static void handle_iq_result(jconn conn, char *from, xmlnode xmldata) | 117 static void handle_iq_result(jconn conn, char *from, xmlnode xmldata) |
178 { | 118 { |
179 xmlnode x; | 119 xmlnode x; |
180 char *p; | 120 char *p; |
181 char *ns; | 121 char *ns; |
194 } | 134 } |
195 | 135 |
196 s_id = atoi(jab_auth(jc)); | 136 s_id = atoi(jab_auth(jc)); |
197 jstate = STATE_SENDAUTH; | 137 jstate = STATE_SENDAUTH; |
198 } else if (jstate == STATE_SENDAUTH) { | 138 } else if (jstate == STATE_SENDAUTH) { |
199 gotloggedin(); | 139 request_roster(); |
200 jstate = STATE_LOGGED; | 140 jstate = STATE_LOGGED; |
201 } | 141 } |
202 return; | 142 return; |
203 } | 143 } |
204 | 144 |
145 /* | |
205 if (!strcmp(p, "VCARDreq")) { | 146 if (!strcmp(p, "VCARDreq")) { |
206 x = xmlnode_get_firstchild(xmldata); | 147 x = xmlnode_get_firstchild(xmldata); |
207 if (!x) x = xmldata; | 148 if (!x) x = xmldata; |
208 | 149 |
209 scr_LogPrint(LPRINT_LOGNORM, "Got VCARD"); // TODO | 150 scr_LogPrint(LPRINT_LOGNORM, "Got VCARD"); // TODO |
210 return; | 151 return; |
211 } else if (!strcmp(p, "versionreq")) { | 152 } else if (!strcmp(p, "versionreq")) { |
212 scr_LogPrint(LPRINT_LOGNORM, "Got version"); // TODO | 153 scr_LogPrint(LPRINT_LOGNORM, "Got version"); // TODO |
213 return; | 154 return; |
214 } | 155 } |
156 */ | |
215 | 157 |
216 x = xmlnode_get_tag(xmldata, "query"); | 158 x = xmlnode_get_tag(xmldata, "query"); |
217 if (!x) return; | 159 if (!x) return; |
218 | 160 |
219 ns = xmlnode_get_attrib(x, "xmlns"); | 161 ns = xmlnode_get_attrib(x, "xmlns"); |
220 if (!ns) return; | 162 if (!ns) return; |
221 | 163 |
222 if (!strcmp(ns, NS_ROSTER)) { | 164 if (!strcmp(ns, NS_ROSTER)) { |
223 gotroster(x); | 165 handle_iq_roster(x); |
224 | 166 |
225 // Post-login stuff FIXME shouldn't be there | 167 // Post-login stuff FIXME shouldn't be there |
226 jb_setstatus(available, NULL, NULL); | 168 jb_setstatus(available, NULL, NULL); |
227 } else if (!strcmp(ns, NS_AGENTS)) { | |
228 gotagents(conn, x); | |
229 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) { | |
230 char *id = xmlnode_get_attrib(xmldata, "id"); | |
231 if (!id) id = ""; | |
232 | |
233 if (!strcmp(id, "Agent info")) { | |
234 scr_LogPrint(LPRINT_LOGNORM, "Got agent info"); // TODO | |
235 } else if (!strcmp(id, "Lookup")) { | |
236 scr_LogPrint(LPRINT_LOGNORM, "Got search results"); // TODO | |
237 } else if (!strcmp(id, "Register")) { | |
238 if (!from) | |
239 return; | |
240 x = jutil_iqnew(JPACKET__GET, NS_REGISTER); | |
241 xmlnode_put_attrib(x, "to", from); | |
242 xmlnode_put_attrib(x, "id", "Agent info"); | |
243 jab_send(conn, x); | |
244 xmlnode_free(x); | |
245 } | |
246 } | 169 } |
247 } | 170 } |
248 | 171 |
249 static void handle_iq_get(jconn conn, char *from, xmlnode xmldata) | 172 static void handle_iq_get(jconn conn, char *from, xmlnode xmldata) |
250 { | 173 { |