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