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; |
112
|
34 time_t LastPingTime; |
|
35 unsigned int KeepaliveDelay; |
31
|
36 static int s_id = 1; // FIXME which use?? |
|
37 static int regmode, regdone; |
112
|
38 unsigned char online; |
29
|
39 |
46
|
40 char imstatus2char[imstatus_size] = { |
|
41 '_', 'o', 'i', 'f', 'd', 'c', 'n', 'a' |
|
42 }; |
|
43 |
31
|
44 static enum { |
29
|
45 STATE_CONNECTING, |
|
46 STATE_GETAUTH, |
|
47 STATE_SENDAUTH, |
|
48 STATE_LOGGED |
|
49 } jstate; |
|
50 |
|
51 |
31
|
52 void statehandler(jconn, int); |
|
53 void packethandler(jconn, jpacket); |
|
54 |
|
55 void screen_logger(jconn j, int io, const char *buf) |
|
56 { |
36
|
57 scr_LogPrint("%03s: %s", ((io == 0) ? "OUT" : "IN"), buf); |
31
|
58 } |
|
59 |
|
60 void file_logger(jconn j, int io, const char *buf) |
|
61 { |
36
|
62 ut_WriteLog("%03s: %s\n", ((io == 0) ? "OUT" : "IN"), buf); |
31
|
63 } |
|
64 |
|
65 void big_logger(jconn j, int io, const char *buf) |
|
66 { |
|
67 screen_logger(j, io, buf); |
|
68 file_logger(j, io, buf); |
|
69 } |
|
70 |
29
|
71 static void jidsplit(const char *jid, char **user, char **host, |
|
72 char **res) |
|
73 { |
|
74 char *tmp, *ptr; |
|
75 tmp = strdup(jid); |
|
76 |
|
77 if ((ptr = strchr(tmp, '/')) != NULL) { |
|
78 *res = strdup(ptr+1); |
|
79 *ptr = 0; |
|
80 } else |
|
81 *res = NULL; |
|
82 |
|
83 if ((ptr = strchr(tmp, '@')) != NULL) { |
|
84 *host = strdup(ptr+1); |
|
85 *ptr = 0; |
|
86 } else |
|
87 *host = NULL; |
|
88 |
|
89 *user = strdup(tmp); |
|
90 free(tmp); |
|
91 } |
|
92 |
|
93 char *jidtodisp(const char *jid) |
|
94 { |
|
95 char *ptr; |
|
96 char *alias = strdup(jid); |
|
97 if ((ptr = strchr(alias, '/')) != NULL) { |
|
98 *ptr = 0; |
|
99 } |
|
100 return alias; |
|
101 } |
|
102 |
35
|
103 jconn jb_connect(const char *jid, unsigned int port, int ssl, const char *pass) |
29
|
104 { |
|
105 if (!port) { |
|
106 if (ssl) |
|
107 port = JABBERSSLPORT; |
|
108 else |
|
109 port = JABBERPORT; |
|
110 } |
|
111 |
|
112 if (jc) |
|
113 free(jc); |
|
114 |
51
|
115 jc = jab_new((char*)jid, (char*)pass, port, ssl); |
29
|
116 |
35
|
117 jab_logger(jc, file_logger); |
29
|
118 jab_packet_handler(jc, &packethandler); |
|
119 jab_state_handler(jc, &statehandler); |
|
120 |
|
121 if (jc->user) { |
112
|
122 online = TRUE; |
29
|
123 jstate = STATE_CONNECTING; |
|
124 statehandler(0, -1); |
|
125 jab_start(jc); |
|
126 } |
|
127 |
|
128 return jc; |
|
129 } |
|
130 |
|
131 void jb_disconnect(void) |
|
132 { |
|
133 statehandler(jc, JCONN_STATE_OFF); |
|
134 } |
|
135 |
112
|
136 inline void jb_reset_keepalive() |
|
137 { |
|
138 time(&LastPingTime); |
|
139 } |
|
140 |
29
|
141 void jb_keepalive() |
|
142 { |
|
143 if (jc) { |
|
144 // XXX Only if connected... |
112
|
145 jab_send_raw(jc, " \t "); |
|
146 scr_LogPrint("Sent keepalive"); |
29
|
147 } |
112
|
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 { |
|
368 char *u, *h, *r; |
|
369 |
|
370 jidsplit(from, &u, &h, &r); |
35
|
371 /* |
|
372 // Maybe we should remember the resource? |
|
373 if (r) |
|
374 scr_LogPrint("There is an extra part in message (resource?): %s", r); |
|
375 */ |
|
376 |
43
|
377 //scr_LogPrint("Msg from <%s>, type=%s", jidtodisp(from), type); |
35
|
378 scr_WriteIncomingMessage(jidtodisp(from), body); |
29
|
379 } |
|
380 |
31
|
381 void statehandler(jconn conn, int state) |
|
382 { |
|
383 static int previous_state = -1; |
|
384 |
35
|
385 ut_WriteLog("StateHandler called (state=%d).\n", state); |
31
|
386 |
|
387 switch(state) { |
|
388 case JCONN_STATE_OFF: |
37
|
389 |
112
|
390 online = FALSE; |
31
|
391 |
37
|
392 if (previous_state != JCONN_STATE_OFF) { |
|
393 scr_LogPrint("+ JCONN_STATE_OFF"); |
|
394 /* |
31
|
395 jhook.roster.clear(); |
|
396 jhook.agents.clear(); |
37
|
397 */ |
|
398 } |
31
|
399 break; |
|
400 |
|
401 case JCONN_STATE_CONNECTED: |
35
|
402 scr_LogPrint("+ JCONN_STATE_CONNECTED"); |
31
|
403 break; |
|
404 |
|
405 case JCONN_STATE_AUTH: |
35
|
406 scr_LogPrint("+ JCONN_STATE_AUTH"); |
31
|
407 break; |
|
408 |
|
409 case JCONN_STATE_ON: |
35
|
410 scr_LogPrint("+ JCONN_STATE_ON"); |
112
|
411 online = TRUE; |
31
|
412 break; |
|
413 |
35
|
414 case JCONN_STATE_CONNECTING: |
|
415 scr_LogPrint("+ JCONN_STATE_CONNECTING"); |
|
416 break; |
|
417 |
31
|
418 default: |
|
419 break; |
|
420 } |
|
421 previous_state = state; |
|
422 } |
|
423 |
|
424 void packethandler(jconn conn, jpacket packet) |
|
425 { |
91
|
426 char *p, *r; |
37
|
427 xmlnode x, y; |
31
|
428 // string from, type, body, enc, ns, id, u, h, s; |
|
429 char *from=NULL, *type=NULL, *body=NULL, *enc=NULL; |
|
430 char *ns=NULL; |
|
431 char *id=NULL; |
35
|
432 enum imstatus ust; |
31
|
433 // int npos; |
|
434 |
112
|
435 jb_reset_keepalive(); // reset keepalive delay |
31
|
436 jpacket_reset(packet); |
|
437 |
|
438 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p; |
|
439 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p; |
|
440 |
|
441 switch (packet->type) { |
|
442 case JPACKET_MESSAGE: |
52
|
443 { |
|
444 char *tmp = NULL; |
|
445 x = xmlnode_get_tag(packet->x, "body"); |
|
446 p = xmlnode_get_data(x); if (p) body = p; |
31
|
447 |
52
|
448 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL) |
|
449 if ((p = xmlnode_get_data(x)) != NULL) { |
|
450 tmp = malloc(strlen(body)+strlen(p)+3); |
|
451 *tmp = '['; |
|
452 strcpy(tmp+1, p); |
|
453 strcat(tmp, "]\n"); |
|
454 strcat(tmp, body); |
|
455 body = tmp; |
|
456 } |
|
457 |
|
458 /* there can be multiple <x> tags. we're looking for one with |
|
459 xmlns = jabber:x:encrypted */ |
|
460 |
|
461 for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) { |
|
462 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) |
|
463 if ((p = xmlnode_get_attrib(x, "xmlns")) && |
|
464 !strcasecmp(p, "jabber:x:encrypted")) |
|
465 if ((p = xmlnode_get_data(x)) != NULL) { |
|
466 enc = p; |
|
467 break; |
|
468 } |
31
|
469 } |
|
470 |
52
|
471 if (body) |
|
472 gotmessage(type, from, body, enc); |
|
473 if (tmp) |
|
474 free(tmp); |
31
|
475 } |
|
476 break; |
|
477 |
|
478 case JPACKET_IQ: |
|
479 if (!strcmp(type, "result")) { |
|
480 |
51
|
481 if ((p = xmlnode_get_attrib(packet->x, "id")) != NULL) { |
31
|
482 int iid = atoi(p); |
|
483 |
|
484 ut_WriteLog("iid = %d\n", iid); |
|
485 if (iid == s_id) { |
|
486 if (!regmode) { |
|
487 if (jstate == STATE_GETAUTH) { |
51
|
488 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) |
31
|
489 if (!xmlnode_get_tag(x, "digest")) { |
|
490 jc->sid = 0; |
|
491 } |
|
492 |
|
493 s_id = atoi(jab_auth(jc)); |
|
494 jstate = STATE_SENDAUTH; |
|
495 } else { |
|
496 gotloggedin(); |
|
497 jstate = STATE_LOGGED; |
|
498 } |
|
499 } else { |
|
500 regdone = TRUE; |
|
501 } |
|
502 return; |
|
503 } |
|
504 |
|
505 if (!strcmp(p, "VCARDreq")) { |
|
506 x = xmlnode_get_firstchild(packet->x); |
|
507 if (!x) x = packet->x; |
|
508 |
|
509 //jhook.gotvcard(ic, x); TODO |
|
510 scr_LogPrint("Got VCARD"); |
|
511 return; |
|
512 } else if (!strcmp(p, "versionreq")) { |
|
513 // jhook.gotversion(ic, packet->x); TODO |
|
514 scr_LogPrint("Got version"); |
|
515 return; |
|
516 } |
|
517 } |
|
518 |
51
|
519 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) { |
31
|
520 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p; |
|
521 |
|
522 if (!strcmp(ns, NS_ROSTER)) { |
|
523 gotroster(x); |
|
524 } else if (!strcmp(ns, NS_AGENTS)) { |
|
525 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) { |
|
526 const char *alias = xmlnode_get_attrib(y, "jid"); |
|
527 |
|
528 if (alias) { |
|
529 const char *name = xmlnode_get_tag_data(y, "name"); |
|
530 const char *desc = xmlnode_get_tag_data(y, "description"); |
51
|
531 // const char *service = xmlnode_get_tag_data(y, "service"); TODO |
37
|
532 enum agtype atype = unknown; |
31
|
533 |
37
|
534 if (xmlnode_get_tag(y, "groupchat")) atype = groupchat; else |
|
535 if (xmlnode_get_tag(y, "transport")) atype = transport; else |
|
536 if (xmlnode_get_tag(y, "search")) atype = search; |
31
|
537 |
|
538 if (alias && name && desc) { |
37
|
539 scr_LogPrint("Agent: %s / %s / %s / type=%d", |
|
540 alias, name, desc, atype); |
31
|
541 |
37
|
542 if (atype == search) { |
31
|
543 x = jutil_iqnew (JPACKET__GET, NS_SEARCH); |
|
544 xmlnode_put_attrib(x, "to", alias); |
|
545 xmlnode_put_attrib(x, "id", "Agent info"); |
|
546 jab_send(conn, x); |
|
547 xmlnode_free(x); |
|
548 } |
|
549 |
|
550 if (xmlnode_get_tag(y, "register")) { |
|
551 x = jutil_iqnew (JPACKET__GET, NS_REGISTER); |
|
552 xmlnode_put_attrib(x, "to", alias); |
|
553 xmlnode_put_attrib(x, "id", "Agent info"); |
|
554 jab_send(conn, x); |
|
555 xmlnode_free(x); |
|
556 } |
|
557 } |
|
558 } |
|
559 } |
|
560 |
37
|
561 /* |
31
|
562 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end()) |
|
563 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV, |
|
564 _("Default Jabber conference server"), agent::atGroupchat)); |
|
565 |
|
566 */ |
|
567 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) { |
|
568 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)""; |
|
569 |
|
570 if (!strcmp(id, "Agent info")) { |
|
571 // jhook.gotagentinfo(packet->x); TODO |
|
572 scr_LogPrint("Got agent info"); |
|
573 } else if (!strcmp(id, "Lookup")) { |
|
574 // jhook.gotsearchresults(packet->x); TODO |
|
575 scr_LogPrint("Got search results"); |
|
576 } else if (!strcmp(id, "Register")) { |
|
577 x = jutil_iqnew(JPACKET__GET, NS_REGISTER); |
|
578 xmlnode_put_attrib(x, "to", from); |
|
579 xmlnode_put_attrib(x, "id", "Agent info"); |
|
580 jab_send(conn, x); |
|
581 xmlnode_free(x); |
|
582 } |
|
583 |
|
584 } |
|
585 } |
|
586 } else if (!strcmp(type, "set")) { |
|
587 } else if (!strcmp(type, "error")) { |
|
588 char *name=NULL, *desc=NULL; |
52
|
589 int code = 0; |
31
|
590 |
|
591 x = xmlnode_get_tag(packet->x, "error"); |
|
592 p = xmlnode_get_attrib(x, "code"); if (p) code = atoi(p); |
|
593 p = xmlnode_get_attrib(x, "id"); if (p) name = p; |
|
594 p = xmlnode_get_tag_data(packet->x, "error"); if (p) desc = p; |
|
595 |
|
596 switch(code) { |
|
597 case 401: /* Unauthorized */ |
|
598 case 302: /* Redirect */ |
|
599 case 400: /* Bad request */ |
|
600 case 402: /* Payment Required */ |
|
601 case 403: /* Forbidden */ |
|
602 case 404: /* Not Found */ |
|
603 case 405: /* Not Allowed */ |
|
604 case 406: /* Not Acceptable */ |
|
605 case 407: /* Registration Required */ |
|
606 case 408: /* Request Timeout */ |
|
607 case 409: /* Conflict */ |
|
608 case 500: /* Internal Server Error */ |
|
609 case 501: /* Not Implemented */ |
|
610 case 502: /* Remote Server Error */ |
|
611 case 503: /* Service Unavailable */ |
|
612 case 504: /* Remote Server Timeout */ |
|
613 default: |
|
614 /* |
|
615 if (!regmode) { |
|
616 face.log(desc.empty() ? |
|
617 _("+ [jab] error %d") : |
|
618 _("+ [jab] error %d: %s"), |
|
619 code, desc.c_str()); |
|
620 |
|
621 if (!jhook.flogged && code != 501) { |
|
622 close(jc->fd); |
|
623 jc->fd = -1; |
|
624 } |
|
625 |
|
626 } else { |
|
627 jhook.regerr = desc; |
|
628 |
|
629 } |
|
630 */ |
|
631 } |
|
632 scr_LogPrint("Error code from server (%d)", code); |
|
633 |
|
634 } |
|
635 break; |
|
636 |
|
637 case JPACKET_PRESENCE: |
|
638 x = xmlnode_get_tag(packet->x, "show"); |
35
|
639 ust = available; |
31
|
640 |
|
641 if (x) { |
|
642 p = xmlnode_get_data(x); if (p) ns = p; |
|
643 |
|
644 if (ns) { |
35
|
645 if (!strcmp(ns, "away")) ust = away; |
|
646 else if (!strcmp(ns, "dnd")) ust = dontdisturb; |
|
647 else if (!strcmp(ns, "xa")) ust = notavail; |
|
648 else if (!strcmp(ns, "chat")) ust = freeforchat; |
31
|
649 } |
|
650 } |
|
651 |
35
|
652 if (type && !strcmp(type, "unavailable")) { |
|
653 ust = offline; |
31
|
654 } |
|
655 |
91
|
656 r = jidtodisp(from); |
|
657 if (ust != roster_getstatus(r)) |
|
658 scr_LogPrint("Buddy status has changed: [%c>%c] <%s>", |
|
659 imstatus2char[roster_getstatus(r)], imstatus2char[ust], r); |
|
660 roster_setstatus(r, ust); |
|
661 free(r); |
81
|
662 buddylist_build(); |
|
663 scr_DrawRoster(); |
31
|
664 /* |
35
|
665 if (x = xmlnode_get_tag(packet->x, "status")) |
|
666 if (p = xmlnode_get_data(x)) |
|
667 scr_LogPrint("Away msg: %s", p); |
31
|
668 */ |
|
669 break; |
|
670 |
|
671 case JPACKET_S10N: |
|
672 scr_LogPrint("Received subscription packet"); |
43
|
673 if (type) scr_LogPrint("Type=%s", type); |
31
|
674 |
43
|
675 if (!strcmp(type, "subscribe")) { |
91
|
676 int isagent; |
|
677 r = jidtodisp(from); |
|
678 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0; |
|
679 free(r); |
|
680 scr_LogPrint("isagent=%d", isagent); // XXX DBG |
|
681 if (!isagent) { |
43
|
682 scr_LogPrint("<%s> wants to subscribe " |
|
683 "to your network presence updates", from); |
91
|
684 } else { |
|
685 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); |
31
|
686 jab_send(jc, x); |
|
687 xmlnode_free(x); |
91
|
688 } |
43
|
689 } else if (!strcmp(type, "unsubscribe")) { |
|
690 x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0); |
31
|
691 jab_send(jc, x); |
|
692 xmlnode_free(x); |
43
|
693 scr_LogPrint("<%s> has unsubscribed to your presence updates", from); |
31
|
694 } |
|
695 break; |
|
696 |
|
697 default: |
|
698 break; |
|
699 } |
|
700 } |
|
701 |