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" |
|
26 #include "screen.h" |
|
27 #include "utils.h" |
51
|
28 #include "buddies.h" |
29
|
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!"); |
31
|
254 /* |
|
255 for (i = 0; i < clist.count; i++) { |
|
256 c = (icqcontact *) clist.at(i); |
|
257 |
|
258 if (c->getdesc().pname == proto) |
|
259 if (ischannel(c)) |
|
260 if (c->getbasicinfo().requiresauth) |
|
261 c->setstatus(available); |
|
262 } |
|
263 */ |
|
264 |
|
265 /* |
|
266 agents.insert(agents.begin(), agent("vcard", "Jabber VCard", "", agent::atStandard)); |
|
267 agents.begin()->params[agent::ptRegister].enabled = TRUE; |
|
268 |
|
269 string buf; |
|
270 ifstream f(conf.getconfigfname("jabber-infoset").c_str()); |
|
271 |
|
272 if (f.is_open()) { |
|
273 icqcontact *c = clist.get(contactroot); |
|
274 |
|
275 c->clear(); |
|
276 icqcontact::basicinfo bi = c->getbasicinfo(); |
|
277 icqcontact::reginfo ri = c->getreginfo(); |
|
278 |
|
279 ri.service = agents.begin()->name; |
|
280 getstring(f, buf); c->setnick(buf); |
|
281 getstring(f, buf); bi.email = buf; |
|
282 getstring(f, buf); bi.fname = buf; |
|
283 getstring(f, buf); bi.lname = buf; |
|
284 f.close(); |
|
285 |
|
286 c->setbasicinfo(bi); |
|
287 c->setreginfo(ri); |
|
288 |
|
289 sendupdateuserinfo(*c); |
|
290 unlink(conf.getconfigfname("jabber-infoset").c_str()); |
|
291 } |
|
292 */ |
|
293 } |
|
294 |
29
|
295 void gotloggedin(void) |
|
296 { |
|
297 xmlnode x; |
|
298 |
|
299 x = jutil_iqnew(JPACKET__GET, NS_AGENTS); |
|
300 xmlnode_put_attrib(x, "id", "Agent List"); |
|
301 jab_send(jc, x); |
|
302 xmlnode_free(x); |
|
303 |
|
304 x = jutil_iqnew(JPACKET__GET, NS_ROSTER); |
|
305 xmlnode_put_attrib(x, "id", "Roster"); |
|
306 jab_send(jc, x); |
|
307 xmlnode_free(x); |
|
308 } |
|
309 |
|
310 void gotroster(xmlnode x) |
|
311 { |
33
|
312 xmlnode y, z; |
29
|
313 |
|
314 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) { |
|
315 const char *alias = xmlnode_get_attrib(y, "jid"); |
51
|
316 //const char *sub = xmlnode_get_attrib(y, "subscription"); // TODO Not used |
29
|
317 const char *name = xmlnode_get_attrib(y, "name"); |
33
|
318 const char *group = 0; |
29
|
319 |
33
|
320 z = xmlnode_get_tag(y, "group"); |
|
321 if (z) group = xmlnode_get_data(z); |
29
|
322 |
|
323 if (alias) { |
35
|
324 char *buddyname; |
|
325 if (name) |
51
|
326 buddyname = (char*)name; |
35
|
327 else |
|
328 buddyname = jidtodisp(alias); |
|
329 |
|
330 bud_AddBuddy(alias, buddyname); |
|
331 if (!name) |
29
|
332 free(buddyname); |
|
333 } |
|
334 } |
|
335 |
35
|
336 bud_SortRoster(); |
29
|
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 { |
|
401 char *p; |
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 // bool isagent; |
|
410 |
|
411 jpacket_reset(packet); |
|
412 |
|
413 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p; |
|
414 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p; |
|
415 |
|
416 switch (packet->type) { |
|
417 case JPACKET_MESSAGE: |
|
418 x = xmlnode_get_tag(packet->x, "body"); |
|
419 p = xmlnode_get_data(x); if (p) body = p; |
51
|
420 char *tmp = NULL; |
31
|
421 |
|
422 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL) |
|
423 if ((p = xmlnode_get_data(x)) != NULL) { |
51
|
424 tmp = malloc(strlen(body)+strlen(p)+3); |
43
|
425 *tmp = '['; |
|
426 strcpy(tmp+1, p); |
|
427 strcat(tmp, "]\n"); |
31
|
428 strcat(tmp, body); |
51
|
429 body = tmp; |
31
|
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")) |
37
|
437 if ((p = xmlnode_get_attrib(x, "xmlns")) && |
|
438 !strcasecmp(p, "jabber:x:encrypted")) |
31
|
439 if ((p = xmlnode_get_data(x)) != NULL) { |
|
440 enc = p; |
|
441 break; |
|
442 } |
|
443 } |
|
444 |
51
|
445 if (body) |
31
|
446 gotmessage(type, from, body, enc); |
51
|
447 if (tmp) |
|
448 free(tmp); |
31
|
449 break; |
|
450 |
|
451 case JPACKET_IQ: |
|
452 if (!strcmp(type, "result")) { |
|
453 |
51
|
454 if ((p = xmlnode_get_attrib(packet->x, "id")) != NULL) { |
31
|
455 int iid = atoi(p); |
|
456 |
|
457 ut_WriteLog("iid = %d\n", iid); |
|
458 if (iid == s_id) { |
|
459 if (!regmode) { |
|
460 if (jstate == STATE_GETAUTH) { |
51
|
461 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) |
31
|
462 if (!xmlnode_get_tag(x, "digest")) { |
|
463 jc->sid = 0; |
|
464 } |
|
465 |
|
466 s_id = atoi(jab_auth(jc)); |
|
467 jstate = STATE_SENDAUTH; |
|
468 } else { |
|
469 gotloggedin(); |
|
470 jstate = STATE_LOGGED; |
|
471 } |
|
472 } else { |
|
473 regdone = TRUE; |
|
474 } |
|
475 return; |
|
476 } |
|
477 |
|
478 if (!strcmp(p, "VCARDreq")) { |
|
479 x = xmlnode_get_firstchild(packet->x); |
|
480 if (!x) x = packet->x; |
|
481 |
|
482 //jhook.gotvcard(ic, x); TODO |
|
483 scr_LogPrint("Got VCARD"); |
|
484 return; |
|
485 } else if (!strcmp(p, "versionreq")) { |
|
486 // jhook.gotversion(ic, packet->x); TODO |
|
487 scr_LogPrint("Got version"); |
|
488 return; |
|
489 } |
|
490 } |
|
491 |
51
|
492 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) { |
31
|
493 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p; |
|
494 |
|
495 if (!strcmp(ns, NS_ROSTER)) { |
|
496 gotroster(x); |
|
497 } else if (!strcmp(ns, NS_AGENTS)) { |
|
498 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) { |
|
499 const char *alias = xmlnode_get_attrib(y, "jid"); |
|
500 |
|
501 if (alias) { |
|
502 const char *name = xmlnode_get_tag_data(y, "name"); |
|
503 const char *desc = xmlnode_get_tag_data(y, "description"); |
51
|
504 // const char *service = xmlnode_get_tag_data(y, "service"); TODO |
37
|
505 enum agtype atype = unknown; |
31
|
506 |
37
|
507 if (xmlnode_get_tag(y, "groupchat")) atype = groupchat; else |
|
508 if (xmlnode_get_tag(y, "transport")) atype = transport; else |
|
509 if (xmlnode_get_tag(y, "search")) atype = search; |
31
|
510 |
|
511 if (alias && name && desc) { |
37
|
512 scr_LogPrint("Agent: %s / %s / %s / type=%d", |
|
513 alias, name, desc, atype); |
31
|
514 |
37
|
515 if (atype == search) { |
31
|
516 x = jutil_iqnew (JPACKET__GET, NS_SEARCH); |
|
517 xmlnode_put_attrib(x, "to", alias); |
|
518 xmlnode_put_attrib(x, "id", "Agent info"); |
|
519 jab_send(conn, x); |
|
520 xmlnode_free(x); |
|
521 } |
|
522 |
|
523 if (xmlnode_get_tag(y, "register")) { |
|
524 x = jutil_iqnew (JPACKET__GET, NS_REGISTER); |
|
525 xmlnode_put_attrib(x, "to", alias); |
|
526 xmlnode_put_attrib(x, "id", "Agent info"); |
|
527 jab_send(conn, x); |
|
528 xmlnode_free(x); |
|
529 } |
|
530 } |
|
531 } |
|
532 } |
|
533 |
37
|
534 /* |
31
|
535 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end()) |
|
536 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV, |
|
537 _("Default Jabber conference server"), agent::atGroupchat)); |
|
538 |
|
539 */ |
|
540 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) { |
|
541 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)""; |
|
542 |
|
543 if (!strcmp(id, "Agent info")) { |
|
544 // jhook.gotagentinfo(packet->x); TODO |
|
545 scr_LogPrint("Got agent info"); |
|
546 } else if (!strcmp(id, "Lookup")) { |
|
547 // jhook.gotsearchresults(packet->x); TODO |
|
548 scr_LogPrint("Got search results"); |
|
549 } else if (!strcmp(id, "Register")) { |
|
550 x = jutil_iqnew(JPACKET__GET, NS_REGISTER); |
|
551 xmlnode_put_attrib(x, "to", from); |
|
552 xmlnode_put_attrib(x, "id", "Agent info"); |
|
553 jab_send(conn, x); |
|
554 xmlnode_free(x); |
|
555 } |
|
556 |
|
557 } |
|
558 } |
|
559 } else if (!strcmp(type, "set")) { |
|
560 } else if (!strcmp(type, "error")) { |
|
561 char *name=NULL, *desc=NULL; |
|
562 int code; |
|
563 |
|
564 x = xmlnode_get_tag(packet->x, "error"); |
|
565 p = xmlnode_get_attrib(x, "code"); if (p) code = atoi(p); |
|
566 p = xmlnode_get_attrib(x, "id"); if (p) name = p; |
|
567 p = xmlnode_get_tag_data(packet->x, "error"); if (p) desc = p; |
|
568 |
|
569 switch(code) { |
|
570 case 401: /* Unauthorized */ |
|
571 case 302: /* Redirect */ |
|
572 case 400: /* Bad request */ |
|
573 case 402: /* Payment Required */ |
|
574 case 403: /* Forbidden */ |
|
575 case 404: /* Not Found */ |
|
576 case 405: /* Not Allowed */ |
|
577 case 406: /* Not Acceptable */ |
|
578 case 407: /* Registration Required */ |
|
579 case 408: /* Request Timeout */ |
|
580 case 409: /* Conflict */ |
|
581 case 500: /* Internal Server Error */ |
|
582 case 501: /* Not Implemented */ |
|
583 case 502: /* Remote Server Error */ |
|
584 case 503: /* Service Unavailable */ |
|
585 case 504: /* Remote Server Timeout */ |
|
586 default: |
|
587 /* |
|
588 if (!regmode) { |
|
589 face.log(desc.empty() ? |
|
590 _("+ [jab] error %d") : |
|
591 _("+ [jab] error %d: %s"), |
|
592 code, desc.c_str()); |
|
593 |
|
594 if (!jhook.flogged && code != 501) { |
|
595 close(jc->fd); |
|
596 jc->fd = -1; |
|
597 } |
|
598 |
|
599 } else { |
|
600 jhook.regerr = desc; |
|
601 |
|
602 } |
|
603 */ |
|
604 } |
|
605 scr_LogPrint("Error code from server (%d)", code); |
|
606 |
|
607 } |
|
608 break; |
|
609 |
|
610 case JPACKET_PRESENCE: |
|
611 x = xmlnode_get_tag(packet->x, "show"); |
35
|
612 ust = available; |
31
|
613 |
|
614 if (x) { |
|
615 p = xmlnode_get_data(x); if (p) ns = p; |
|
616 |
|
617 if (ns) { |
35
|
618 if (!strcmp(ns, "away")) ust = away; |
|
619 else if (!strcmp(ns, "dnd")) ust = dontdisturb; |
|
620 else if (!strcmp(ns, "xa")) ust = notavail; |
|
621 else if (!strcmp(ns, "chat")) ust = freeforchat; |
31
|
622 } |
|
623 } |
|
624 |
35
|
625 if (type && !strcmp(type, "unavailable")) { |
|
626 ust = offline; |
31
|
627 } |
41
|
628 //scr_LogPrint("New status: ust=%d (%s)", ust, from); |
31
|
629 |
35
|
630 bud_SetBuddyStatus(jidtodisp(from), ust); |
31
|
631 /* |
35
|
632 if (x = xmlnode_get_tag(packet->x, "status")) |
|
633 if (p = xmlnode_get_data(x)) |
|
634 scr_LogPrint("Away msg: %s", p); |
31
|
635 */ |
|
636 break; |
|
637 |
|
638 case JPACKET_S10N: |
|
639 scr_LogPrint("Received subscription packet"); |
43
|
640 if (type) scr_LogPrint("Type=%s", type); |
31
|
641 |
43
|
642 if (!strcmp(type, "subscribe")) { |
|
643 // if (!isagent) { |
|
644 scr_LogPrint("<%s> wants to subscribe " |
|
645 "to your network presence updates", from); |
|
646 /*} else { |
31
|
647 auto_ptr<char> cfrom(strdup(from.c_str())); |
|
648 x = jutil_presnew(JPACKET__SUBSCRIBED, cfrom.get(), 0); |
|
649 jab_send(jc, x); |
|
650 xmlnode_free(x); |
43
|
651 }*/ |
|
652 } else if (!strcmp(type, "unsubscribe")) { |
|
653 x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0); |
31
|
654 jab_send(jc, x); |
|
655 xmlnode_free(x); |
43
|
656 scr_LogPrint("<%s> has unsubscribed to your presence updates", from); |
31
|
657 } |
|
658 break; |
|
659 |
|
660 default: |
|
661 break; |
|
662 } |
|
663 } |
|
664 |