29
|
1 /* |
|
2 * jabglue.c -- Jabber protocol handling |
|
3 * |
|
4 * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net> |
|
5 * Parts come from the centericq project: |
|
6 * Copyright (C) 2002-2005 by Konstantin Klyagin <konst@konst.org.ua> |
|
7 * |
|
8 * This program is free software; you can redistribute it and/or modify |
|
9 * it under the terms of the GNU General Public License as published by |
|
10 * the Free Software Foundation; either version 2 of the License, or (at |
|
11 * your option) any later version. |
|
12 * |
|
13 * This program is distributed in the hope that it will be useful, but |
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 * General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with this program; if not, write to the Free Software |
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
21 * USA |
|
22 */ |
|
23 |
|
24 #include "../libjabber/jabber.h" |
|
25 #include "jabglue.h" |
81
|
26 #include "roster.h" |
29
|
27 #include "screen.h" |
|
28 #include "utils.h" |
|
29 |
|
30 #define JABBERPORT 5222 |
|
31 #define JABBERSSLPORT 5223 |
|
32 |
|
33 jconn jc; |
31
|
34 static int s_id = 1; // FIXME which use?? |
|
35 static int regmode, regdone; |
29
|
36 |
46
|
37 char imstatus2char[imstatus_size] = { |
|
38 '_', 'o', 'i', 'f', 'd', 'c', 'n', 'a' |
|
39 }; |
|
40 |
31
|
41 static enum { |
29
|
42 STATE_CONNECTING, |
|
43 STATE_GETAUTH, |
|
44 STATE_SENDAUTH, |
|
45 STATE_LOGGED |
|
46 } jstate; |
|
47 |
|
48 |
31
|
49 void statehandler(jconn, int); |
|
50 void packethandler(jconn, jpacket); |
|
51 |
|
52 void screen_logger(jconn j, int io, const char *buf) |
|
53 { |
36
|
54 scr_LogPrint("%03s: %s", ((io == 0) ? "OUT" : "IN"), buf); |
31
|
55 } |
|
56 |
|
57 void file_logger(jconn j, int io, const char *buf) |
|
58 { |
36
|
59 ut_WriteLog("%03s: %s\n", ((io == 0) ? "OUT" : "IN"), buf); |
31
|
60 } |
|
61 |
|
62 void big_logger(jconn j, int io, const char *buf) |
|
63 { |
|
64 screen_logger(j, io, buf); |
|
65 file_logger(j, io, buf); |
|
66 } |
|
67 |
29
|
68 static void jidsplit(const char *jid, char **user, char **host, |
|
69 char **res) |
|
70 { |
|
71 char *tmp, *ptr; |
|
72 tmp = strdup(jid); |
|
73 |
|
74 if ((ptr = strchr(tmp, '/')) != NULL) { |
|
75 *res = strdup(ptr+1); |
|
76 *ptr = 0; |
|
77 } else |
|
78 *res = NULL; |
|
79 |
|
80 if ((ptr = strchr(tmp, '@')) != NULL) { |
|
81 *host = strdup(ptr+1); |
|
82 *ptr = 0; |
|
83 } else |
|
84 *host = NULL; |
|
85 |
|
86 *user = strdup(tmp); |
|
87 free(tmp); |
|
88 } |
|
89 |
|
90 char *jidtodisp(const char *jid) |
|
91 { |
|
92 char *ptr; |
|
93 char *alias = strdup(jid); |
|
94 if ((ptr = strchr(alias, '/')) != NULL) { |
|
95 *ptr = 0; |
|
96 } |
|
97 return alias; |
|
98 } |
|
99 |
35
|
100 jconn jb_connect(const char *jid, unsigned int port, int ssl, const char *pass) |
29
|
101 { |
|
102 if (!port) { |
|
103 if (ssl) |
|
104 port = JABBERSSLPORT; |
|
105 else |
|
106 port = JABBERPORT; |
|
107 } |
|
108 |
|
109 if (jc) |
|
110 free(jc); |
|
111 |
51
|
112 jc = jab_new((char*)jid, (char*)pass, port, ssl); |
29
|
113 |
35
|
114 jab_logger(jc, file_logger); |
29
|
115 jab_packet_handler(jc, &packethandler); |
|
116 jab_state_handler(jc, &statehandler); |
|
117 |
|
118 if (jc->user) { |
31
|
119 //fonline = TRUE; |
29
|
120 jstate = STATE_CONNECTING; |
|
121 statehandler(0, -1); |
|
122 jab_start(jc); |
|
123 } |
|
124 |
|
125 return jc; |
|
126 } |
|
127 |
|
128 void jb_disconnect(void) |
|
129 { |
|
130 statehandler(jc, JCONN_STATE_OFF); |
|
131 } |
|
132 |
|
133 void jb_keepalive() |
|
134 { |
|
135 if (jc) { |
|
136 // XXX Only if connected... |
|
137 jab_send_raw(jc, " "); |
|
138 } |
|
139 } |
|
140 |
|
141 void jb_main() |
|
142 { |
|
143 xmlnode x, z; |
|
144 char *cid; |
|
145 |
|
146 if (jc && jc->state == JCONN_STATE_CONNECTING) { |
|
147 jab_start(jc); |
|
148 return; |
|
149 } |
|
150 |
31
|
151 jab_poll(jc, 50); |
29
|
152 |
|
153 if (jstate == STATE_CONNECTING) { |
|
154 if (jc) { |
|
155 x = jutil_iqnew(JPACKET__GET, NS_AUTH); |
|
156 cid = jab_getid(jc); |
|
157 xmlnode_put_attrib(x, "id", cid); |
|
158 // id = atoi(cid); |
|
159 |
|
160 z = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "username"); |
|
161 xmlnode_insert_cdata(z, jc->user->user, (unsigned) -1); |
|
162 jab_send(jc, x); |
|
163 xmlnode_free(x); |
|
164 |
|
165 jstate = STATE_GETAUTH; |
|
166 } |
|
167 |
|
168 if (!jc || jc->state == JCONN_STATE_OFF) { |
|
169 scr_LogPrint("Unable to connect to the server"); |
31
|
170 // fonline = FALSE; |
29
|
171 } |
|
172 } |
|
173 |
|
174 if (!jc) { |
|
175 statehandler(jc, JCONN_STATE_OFF); |
|
176 } else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) { |
|
177 statehandler(jc, JCONN_STATE_OFF); |
|
178 } |
|
179 } |
|
180 |
|
181 void setjabberstatus(enum imstatus st, char *msg) |
|
182 { |
|
183 xmlnode x = jutil_presnew(JPACKET__UNKNOWN, 0, 0); |
|
184 |
|
185 switch(st) { |
|
186 case away: |
|
187 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "away", |
|
188 (unsigned) -1); |
|
189 break; |
|
190 |
|
191 case occupied: |
|
192 case dontdisturb: |
|
193 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "dnd", |
|
194 (unsigned) -1); |
|
195 break; |
|
196 |
|
197 case freeforchat: |
|
198 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "chat", |
|
199 (unsigned) -1); |
|
200 break; |
|
201 |
|
202 case notavail: |
|
203 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "xa", |
|
204 (unsigned) -1); |
|
205 break; |
|
206 |
|
207 case invisible: |
|
208 xmlnode_put_attrib(x, "type", "invisible"); |
|
209 break; |
51
|
210 |
|
211 default: |
|
212 break; |
29
|
213 } |
|
214 |
31
|
215 /* TODO |
|
216 if (!add["prio"].empty()) |
29
|
217 xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"), |
|
218 add["prio"].c_str(), (unsigned) -1); |
|
219 */ |
|
220 |
|
221 if (!msg || !*msg) { |
51
|
222 msg = ""; // FIXME |
29
|
223 //msg = imstatus2str(st); |
|
224 } |
|
225 |
|
226 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), msg, |
|
227 (unsigned) -1); |
|
228 |
|
229 jab_send(jc, x); |
|
230 xmlnode_free(x); |
|
231 |
|
232 //sendvisibility(); |
|
233 |
|
234 // XXX logger.putourstatus(proto, getstatus(), ourstatus = st); |
|
235 } |
|
236 |
35
|
237 void jb_send_msg(const char *jid, const char *text) |
|
238 { |
51
|
239 xmlnode x = jutil_msgnew(TMSG_CHAT, (char*)jid, 0, (char*)text); |
35
|
240 jab_send(jc, x); |
|
241 xmlnode_free(x); |
|
242 } |
|
243 |
31
|
244 void postlogin() |
|
245 { |
|
246 //int i; |
|
247 |
|
248 //flogged = TRUE; |
|
249 //ourstatus = available; |
|
250 |
|
251 //setautostatus(jhook.manualstatus); |
|
252 |
35
|
253 setjabberstatus(1, "I'm here!"); |
81
|
254 buddylist_build(); |
31
|
255 /* |
|
256 for (i = 0; i < clist.count; i++) { |
|
257 c = (icqcontact *) clist.at(i); |
|
258 |
|
259 if (c->getdesc().pname == proto) |
|
260 if (ischannel(c)) |
|
261 if (c->getbasicinfo().requiresauth) |
|
262 c->setstatus(available); |
|
263 } |
|
264 */ |
|
265 |
|
266 /* |
|
267 agents.insert(agents.begin(), agent("vcard", "Jabber VCard", "", agent::atStandard)); |
|
268 agents.begin()->params[agent::ptRegister].enabled = TRUE; |
|
269 |
|
270 string buf; |
|
271 ifstream f(conf.getconfigfname("jabber-infoset").c_str()); |
|
272 |
|
273 if (f.is_open()) { |
|
274 icqcontact *c = clist.get(contactroot); |
|
275 |
|
276 c->clear(); |
|
277 icqcontact::basicinfo bi = c->getbasicinfo(); |
|
278 icqcontact::reginfo ri = c->getreginfo(); |
|
279 |
|
280 ri.service = agents.begin()->name; |
|
281 getstring(f, buf); c->setnick(buf); |
|
282 getstring(f, buf); bi.email = buf; |
|
283 getstring(f, buf); bi.fname = buf; |
|
284 getstring(f, buf); bi.lname = buf; |
|
285 f.close(); |
|
286 |
|
287 c->setbasicinfo(bi); |
|
288 c->setreginfo(ri); |
|
289 |
|
290 sendupdateuserinfo(*c); |
|
291 unlink(conf.getconfigfname("jabber-infoset").c_str()); |
|
292 } |
|
293 */ |
|
294 } |
|
295 |
29
|
296 void gotloggedin(void) |
|
297 { |
|
298 xmlnode x; |
|
299 |
|
300 x = jutil_iqnew(JPACKET__GET, NS_AGENTS); |
|
301 xmlnode_put_attrib(x, "id", "Agent List"); |
|
302 jab_send(jc, x); |
|
303 xmlnode_free(x); |
|
304 |
|
305 x = jutil_iqnew(JPACKET__GET, NS_ROSTER); |
|
306 xmlnode_put_attrib(x, "id", "Roster"); |
|
307 jab_send(jc, x); |
|
308 xmlnode_free(x); |
|
309 } |
|
310 |
|
311 void gotroster(xmlnode x) |
|
312 { |
33
|
313 xmlnode y, z; |
29
|
314 |
|
315 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) { |
|
316 const char *alias = xmlnode_get_attrib(y, "jid"); |
51
|
317 //const char *sub = xmlnode_get_attrib(y, "subscription"); // TODO Not used |
29
|
318 const char *name = xmlnode_get_attrib(y, "name"); |
81
|
319 const char *group = NULL; |
29
|
320 |
33
|
321 z = xmlnode_get_tag(y, "group"); |
|
322 if (z) group = xmlnode_get_data(z); |
29
|
323 |
|
324 if (alias) { |
35
|
325 char *buddyname; |
|
326 if (name) |
51
|
327 buddyname = (char*)name; |
35
|
328 else |
|
329 buddyname = jidtodisp(alias); |
|
330 |
81
|
331 roster_add_user(alias, buddyname, group, ROSTER_TYPE_USER); |
35
|
332 if (!name) |
29
|
333 free(buddyname); |
|
334 } |
|
335 } |
|
336 |
|
337 postlogin(); |
|
338 } |
|
339 |
|
340 void gotmessage(char *type, const char *from, const char *body, |
|
341 const char *enc) |
|
342 { |
|
343 char *u, *h, *r; |
|
344 |
|
345 jidsplit(from, &u, &h, &r); |
35
|
346 /* |
|
347 // Maybe we should remember the resource? |
|
348 if (r) |
|
349 scr_LogPrint("There is an extra part in message (resource?): %s", r); |
|
350 */ |
|
351 |
43
|
352 //scr_LogPrint("Msg from <%s>, type=%s", jidtodisp(from), type); |
35
|
353 scr_WriteIncomingMessage(jidtodisp(from), body); |
29
|
354 } |
|
355 |
31
|
356 void statehandler(jconn conn, int state) |
|
357 { |
|
358 static int previous_state = -1; |
|
359 |
35
|
360 ut_WriteLog("StateHandler called (state=%d).\n", state); |
31
|
361 |
|
362 switch(state) { |
|
363 case JCONN_STATE_OFF: |
37
|
364 |
|
365 /* jhook.flogged = jhook.fonline = FALSE; */ |
31
|
366 |
37
|
367 if (previous_state != JCONN_STATE_OFF) { |
|
368 scr_LogPrint("+ JCONN_STATE_OFF"); |
|
369 /* |
31
|
370 jhook.roster.clear(); |
|
371 jhook.agents.clear(); |
37
|
372 */ |
|
373 } |
31
|
374 break; |
|
375 |
|
376 case JCONN_STATE_CONNECTED: |
35
|
377 scr_LogPrint("+ JCONN_STATE_CONNECTED"); |
31
|
378 break; |
|
379 |
|
380 case JCONN_STATE_AUTH: |
35
|
381 scr_LogPrint("+ JCONN_STATE_AUTH"); |
31
|
382 break; |
|
383 |
|
384 case JCONN_STATE_ON: |
35
|
385 scr_LogPrint("+ JCONN_STATE_ON"); |
31
|
386 // if (regmode) jhook.fonline = TRUE; |
|
387 break; |
|
388 |
35
|
389 case JCONN_STATE_CONNECTING: |
|
390 scr_LogPrint("+ JCONN_STATE_CONNECTING"); |
|
391 break; |
|
392 |
31
|
393 default: |
|
394 break; |
|
395 } |
|
396 previous_state = state; |
|
397 } |
|
398 |
|
399 void packethandler(jconn conn, jpacket packet) |
|
400 { |
91
|
401 char *p, *r; |
37
|
402 xmlnode x, y; |
31
|
403 // string from, type, body, enc, ns, id, u, h, s; |
|
404 char *from=NULL, *type=NULL, *body=NULL, *enc=NULL; |
|
405 char *ns=NULL; |
|
406 char *id=NULL; |
35
|
407 enum imstatus ust; |
31
|
408 // int npos; |
|
409 |
|
410 jpacket_reset(packet); |
|
411 |
|
412 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p; |
|
413 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p; |
|
414 |
|
415 switch (packet->type) { |
|
416 case JPACKET_MESSAGE: |
52
|
417 { |
|
418 char *tmp = NULL; |
|
419 x = xmlnode_get_tag(packet->x, "body"); |
|
420 p = xmlnode_get_data(x); if (p) body = p; |
31
|
421 |
52
|
422 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL) |
|
423 if ((p = xmlnode_get_data(x)) != NULL) { |
|
424 tmp = malloc(strlen(body)+strlen(p)+3); |
|
425 *tmp = '['; |
|
426 strcpy(tmp+1, p); |
|
427 strcat(tmp, "]\n"); |
|
428 strcat(tmp, body); |
|
429 body = tmp; |
|
430 } |
|
431 |
|
432 /* there can be multiple <x> tags. we're looking for one with |
|
433 xmlns = jabber:x:encrypted */ |
|
434 |
|
435 for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) { |
|
436 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) |
|
437 if ((p = xmlnode_get_attrib(x, "xmlns")) && |
|
438 !strcasecmp(p, "jabber:x:encrypted")) |
|
439 if ((p = xmlnode_get_data(x)) != NULL) { |
|
440 enc = p; |
|
441 break; |
|
442 } |
31
|
443 } |
|
444 |
52
|
445 if (body) |
|
446 gotmessage(type, from, body, enc); |
|
447 if (tmp) |
|
448 free(tmp); |
31
|
449 } |
|
450 break; |
|
451 |
|
452 case JPACKET_IQ: |
|
453 if (!strcmp(type, "result")) { |
|
454 |
51
|
455 if ((p = xmlnode_get_attrib(packet->x, "id")) != NULL) { |
31
|
456 int iid = atoi(p); |
|
457 |
|
458 ut_WriteLog("iid = %d\n", iid); |
|
459 if (iid == s_id) { |
|
460 if (!regmode) { |
|
461 if (jstate == STATE_GETAUTH) { |
51
|
462 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) |
31
|
463 if (!xmlnode_get_tag(x, "digest")) { |
|
464 jc->sid = 0; |
|
465 } |
|
466 |
|
467 s_id = atoi(jab_auth(jc)); |
|
468 jstate = STATE_SENDAUTH; |
|
469 } else { |
|
470 gotloggedin(); |
|
471 jstate = STATE_LOGGED; |
|
472 } |
|
473 } else { |
|
474 regdone = TRUE; |
|
475 } |
|
476 return; |
|
477 } |
|
478 |
|
479 if (!strcmp(p, "VCARDreq")) { |
|
480 x = xmlnode_get_firstchild(packet->x); |
|
481 if (!x) x = packet->x; |
|
482 |
|
483 //jhook.gotvcard(ic, x); TODO |
|
484 scr_LogPrint("Got VCARD"); |
|
485 return; |
|
486 } else if (!strcmp(p, "versionreq")) { |
|
487 // jhook.gotversion(ic, packet->x); TODO |
|
488 scr_LogPrint("Got version"); |
|
489 return; |
|
490 } |
|
491 } |
|
492 |
51
|
493 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) { |
31
|
494 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p; |
|
495 |
|
496 if (!strcmp(ns, NS_ROSTER)) { |
|
497 gotroster(x); |
|
498 } else if (!strcmp(ns, NS_AGENTS)) { |
|
499 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) { |
|
500 const char *alias = xmlnode_get_attrib(y, "jid"); |
|
501 |
|
502 if (alias) { |
|
503 const char *name = xmlnode_get_tag_data(y, "name"); |
|
504 const char *desc = xmlnode_get_tag_data(y, "description"); |
51
|
505 // const char *service = xmlnode_get_tag_data(y, "service"); TODO |
37
|
506 enum agtype atype = unknown; |
31
|
507 |
37
|
508 if (xmlnode_get_tag(y, "groupchat")) atype = groupchat; else |
|
509 if (xmlnode_get_tag(y, "transport")) atype = transport; else |
|
510 if (xmlnode_get_tag(y, "search")) atype = search; |
31
|
511 |
|
512 if (alias && name && desc) { |
37
|
513 scr_LogPrint("Agent: %s / %s / %s / type=%d", |
|
514 alias, name, desc, atype); |
31
|
515 |
37
|
516 if (atype == search) { |
31
|
517 x = jutil_iqnew (JPACKET__GET, NS_SEARCH); |
|
518 xmlnode_put_attrib(x, "to", alias); |
|
519 xmlnode_put_attrib(x, "id", "Agent info"); |
|
520 jab_send(conn, x); |
|
521 xmlnode_free(x); |
|
522 } |
|
523 |
|
524 if (xmlnode_get_tag(y, "register")) { |
|
525 x = jutil_iqnew (JPACKET__GET, NS_REGISTER); |
|
526 xmlnode_put_attrib(x, "to", alias); |
|
527 xmlnode_put_attrib(x, "id", "Agent info"); |
|
528 jab_send(conn, x); |
|
529 xmlnode_free(x); |
|
530 } |
|
531 } |
|
532 } |
|
533 } |
|
534 |
37
|
535 /* |
31
|
536 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end()) |
|
537 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV, |
|
538 _("Default Jabber conference server"), agent::atGroupchat)); |
|
539 |
|
540 */ |
|
541 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) { |
|
542 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)""; |
|
543 |
|
544 if (!strcmp(id, "Agent info")) { |
|
545 // jhook.gotagentinfo(packet->x); TODO |
|
546 scr_LogPrint("Got agent info"); |
|
547 } else if (!strcmp(id, "Lookup")) { |
|
548 // jhook.gotsearchresults(packet->x); TODO |
|
549 scr_LogPrint("Got search results"); |
|
550 } else if (!strcmp(id, "Register")) { |
|
551 x = jutil_iqnew(JPACKET__GET, NS_REGISTER); |
|
552 xmlnode_put_attrib(x, "to", from); |
|
553 xmlnode_put_attrib(x, "id", "Agent info"); |
|
554 jab_send(conn, x); |
|
555 xmlnode_free(x); |
|
556 } |
|
557 |
|
558 } |
|
559 } |
|
560 } else if (!strcmp(type, "set")) { |
|
561 } else if (!strcmp(type, "error")) { |
|
562 char *name=NULL, *desc=NULL; |
52
|
563 int code = 0; |
31
|
564 |
|
565 x = xmlnode_get_tag(packet->x, "error"); |
|
566 p = xmlnode_get_attrib(x, "code"); if (p) code = atoi(p); |
|
567 p = xmlnode_get_attrib(x, "id"); if (p) name = p; |
|
568 p = xmlnode_get_tag_data(packet->x, "error"); if (p) desc = p; |
|
569 |
|
570 switch(code) { |
|
571 case 401: /* Unauthorized */ |
|
572 case 302: /* Redirect */ |
|
573 case 400: /* Bad request */ |
|
574 case 402: /* Payment Required */ |
|
575 case 403: /* Forbidden */ |
|
576 case 404: /* Not Found */ |
|
577 case 405: /* Not Allowed */ |
|
578 case 406: /* Not Acceptable */ |
|
579 case 407: /* Registration Required */ |
|
580 case 408: /* Request Timeout */ |
|
581 case 409: /* Conflict */ |
|
582 case 500: /* Internal Server Error */ |
|
583 case 501: /* Not Implemented */ |
|
584 case 502: /* Remote Server Error */ |
|
585 case 503: /* Service Unavailable */ |
|
586 case 504: /* Remote Server Timeout */ |
|
587 default: |
|
588 /* |
|
589 if (!regmode) { |
|
590 face.log(desc.empty() ? |
|
591 _("+ [jab] error %d") : |
|
592 _("+ [jab] error %d: %s"), |
|
593 code, desc.c_str()); |
|
594 |
|
595 if (!jhook.flogged && code != 501) { |
|
596 close(jc->fd); |
|
597 jc->fd = -1; |
|
598 } |
|
599 |
|
600 } else { |
|
601 jhook.regerr = desc; |
|
602 |
|
603 } |
|
604 */ |
|
605 } |
|
606 scr_LogPrint("Error code from server (%d)", code); |
|
607 |
|
608 } |
|
609 break; |
|
610 |
|
611 case JPACKET_PRESENCE: |
|
612 x = xmlnode_get_tag(packet->x, "show"); |
35
|
613 ust = available; |
31
|
614 |
|
615 if (x) { |
|
616 p = xmlnode_get_data(x); if (p) ns = p; |
|
617 |
|
618 if (ns) { |
35
|
619 if (!strcmp(ns, "away")) ust = away; |
|
620 else if (!strcmp(ns, "dnd")) ust = dontdisturb; |
|
621 else if (!strcmp(ns, "xa")) ust = notavail; |
|
622 else if (!strcmp(ns, "chat")) ust = freeforchat; |
31
|
623 } |
|
624 } |
|
625 |
35
|
626 if (type && !strcmp(type, "unavailable")) { |
|
627 ust = offline; |
31
|
628 } |
|
629 |
91
|
630 r = jidtodisp(from); |
|
631 if (ust != roster_getstatus(r)) |
|
632 scr_LogPrint("Buddy status has changed: [%c>%c] <%s>", |
|
633 imstatus2char[roster_getstatus(r)], imstatus2char[ust], r); |
|
634 roster_setstatus(r, ust); |
|
635 free(r); |
81
|
636 buddylist_build(); |
|
637 scr_DrawRoster(); |
31
|
638 /* |
35
|
639 if (x = xmlnode_get_tag(packet->x, "status")) |
|
640 if (p = xmlnode_get_data(x)) |
|
641 scr_LogPrint("Away msg: %s", p); |
31
|
642 */ |
|
643 break; |
|
644 |
|
645 case JPACKET_S10N: |
|
646 scr_LogPrint("Received subscription packet"); |
43
|
647 if (type) scr_LogPrint("Type=%s", type); |
31
|
648 |
43
|
649 if (!strcmp(type, "subscribe")) { |
91
|
650 int isagent; |
|
651 r = jidtodisp(from); |
|
652 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0; |
|
653 free(r); |
|
654 scr_LogPrint("isagent=%d", isagent); // XXX DBG |
|
655 if (!isagent) { |
43
|
656 scr_LogPrint("<%s> wants to subscribe " |
|
657 "to your network presence updates", from); |
91
|
658 } else { |
|
659 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); |
31
|
660 jab_send(jc, x); |
|
661 xmlnode_free(x); |
91
|
662 } |
43
|
663 } else if (!strcmp(type, "unsubscribe")) { |
|
664 x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0); |
31
|
665 jab_send(jc, x); |
|
666 xmlnode_free(x); |
43
|
667 scr_LogPrint("<%s> has unsubscribed to your presence updates", from); |
31
|
668 } |
|
669 break; |
|
670 |
|
671 default: |
|
672 break; |
|
673 } |
|
674 } |
|
675 |