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);
|
114
|
267 jb_reset_keepalive();
|
35
|
268 }
|
|
269
|
31
|
270 void postlogin()
|
|
271 {
|
|
272 //int i;
|
|
273
|
|
274 //flogged = TRUE;
|
|
275 //ourstatus = available;
|
|
276
|
|
277 //setautostatus(jhook.manualstatus);
|
|
278
|
35
|
279 setjabberstatus(1, "I'm here!");
|
81
|
280 buddylist_build();
|
31
|
281 /*
|
|
282 for (i = 0; i < clist.count; i++) {
|
|
283 c = (icqcontact *) clist.at(i);
|
|
284
|
|
285 if (c->getdesc().pname == proto)
|
|
286 if (ischannel(c))
|
|
287 if (c->getbasicinfo().requiresauth)
|
|
288 c->setstatus(available);
|
|
289 }
|
|
290 */
|
|
291
|
|
292 /*
|
|
293 agents.insert(agents.begin(), agent("vcard", "Jabber VCard", "", agent::atStandard));
|
|
294 agents.begin()->params[agent::ptRegister].enabled = TRUE;
|
|
295
|
|
296 string buf;
|
|
297 ifstream f(conf.getconfigfname("jabber-infoset").c_str());
|
|
298
|
|
299 if (f.is_open()) {
|
|
300 icqcontact *c = clist.get(contactroot);
|
|
301
|
|
302 c->clear();
|
|
303 icqcontact::basicinfo bi = c->getbasicinfo();
|
|
304 icqcontact::reginfo ri = c->getreginfo();
|
|
305
|
|
306 ri.service = agents.begin()->name;
|
|
307 getstring(f, buf); c->setnick(buf);
|
|
308 getstring(f, buf); bi.email = buf;
|
|
309 getstring(f, buf); bi.fname = buf;
|
|
310 getstring(f, buf); bi.lname = buf;
|
|
311 f.close();
|
|
312
|
|
313 c->setbasicinfo(bi);
|
|
314 c->setreginfo(ri);
|
|
315
|
|
316 sendupdateuserinfo(*c);
|
|
317 unlink(conf.getconfigfname("jabber-infoset").c_str());
|
|
318 }
|
|
319 */
|
|
320 }
|
|
321
|
29
|
322 void gotloggedin(void)
|
|
323 {
|
|
324 xmlnode x;
|
|
325
|
|
326 x = jutil_iqnew(JPACKET__GET, NS_AGENTS);
|
|
327 xmlnode_put_attrib(x, "id", "Agent List");
|
|
328 jab_send(jc, x);
|
|
329 xmlnode_free(x);
|
|
330
|
|
331 x = jutil_iqnew(JPACKET__GET, NS_ROSTER);
|
|
332 xmlnode_put_attrib(x, "id", "Roster");
|
|
333 jab_send(jc, x);
|
|
334 xmlnode_free(x);
|
|
335 }
|
|
336
|
|
337 void gotroster(xmlnode x)
|
|
338 {
|
33
|
339 xmlnode y, z;
|
29
|
340
|
|
341 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) {
|
|
342 const char *alias = xmlnode_get_attrib(y, "jid");
|
51
|
343 //const char *sub = xmlnode_get_attrib(y, "subscription"); // TODO Not used
|
29
|
344 const char *name = xmlnode_get_attrib(y, "name");
|
81
|
345 const char *group = NULL;
|
29
|
346
|
33
|
347 z = xmlnode_get_tag(y, "group");
|
|
348 if (z) group = xmlnode_get_data(z);
|
29
|
349
|
|
350 if (alias) {
|
35
|
351 char *buddyname;
|
|
352 if (name)
|
51
|
353 buddyname = (char*)name;
|
35
|
354 else
|
|
355 buddyname = jidtodisp(alias);
|
|
356
|
81
|
357 roster_add_user(alias, buddyname, group, ROSTER_TYPE_USER);
|
35
|
358 if (!name)
|
29
|
359 free(buddyname);
|
|
360 }
|
|
361 }
|
|
362
|
|
363 postlogin();
|
|
364 }
|
|
365
|
|
366 void gotmessage(char *type, const char *from, const char *body,
|
|
367 const char *enc)
|
|
368 {
|
113
|
369 char *jid;
|
29
|
370
|
35
|
371 /*
|
113
|
372 //char *u, *h, *r;
|
|
373 //jidsplit(from, &u, &h, &r);
|
35
|
374 // Maybe we should remember the resource?
|
|
375 if (r)
|
|
376 scr_LogPrint("There is an extra part in message (resource?): %s", r);
|
113
|
377 //scr_LogPrint("Msg from <%s>, type=%s", jidtodisp(from), type);
|
35
|
378 */
|
|
379
|
113
|
380 jid = jidtodisp(from);
|
|
381 hk_message_in(jid, 0, body);
|
|
382 free(jid);
|
29
|
383 }
|
|
384
|
31
|
385 void statehandler(jconn conn, int state)
|
|
386 {
|
|
387 static int previous_state = -1;
|
|
388
|
35
|
389 ut_WriteLog("StateHandler called (state=%d).\n", state);
|
31
|
390
|
|
391 switch(state) {
|
|
392 case JCONN_STATE_OFF:
|
37
|
393
|
112
|
394 online = FALSE;
|
31
|
395
|
37
|
396 if (previous_state != JCONN_STATE_OFF) {
|
|
397 scr_LogPrint("+ JCONN_STATE_OFF");
|
|
398 /*
|
31
|
399 jhook.roster.clear();
|
|
400 jhook.agents.clear();
|
37
|
401 */
|
|
402 }
|
31
|
403 break;
|
|
404
|
|
405 case JCONN_STATE_CONNECTED:
|
35
|
406 scr_LogPrint("+ JCONN_STATE_CONNECTED");
|
31
|
407 break;
|
|
408
|
|
409 case JCONN_STATE_AUTH:
|
35
|
410 scr_LogPrint("+ JCONN_STATE_AUTH");
|
31
|
411 break;
|
|
412
|
|
413 case JCONN_STATE_ON:
|
35
|
414 scr_LogPrint("+ JCONN_STATE_ON");
|
112
|
415 online = TRUE;
|
31
|
416 break;
|
|
417
|
35
|
418 case JCONN_STATE_CONNECTING:
|
|
419 scr_LogPrint("+ JCONN_STATE_CONNECTING");
|
|
420 break;
|
|
421
|
31
|
422 default:
|
|
423 break;
|
|
424 }
|
|
425 previous_state = state;
|
|
426 }
|
|
427
|
|
428 void packethandler(jconn conn, jpacket packet)
|
|
429 {
|
91
|
430 char *p, *r;
|
37
|
431 xmlnode x, y;
|
31
|
432 // string from, type, body, enc, ns, id, u, h, s;
|
|
433 char *from=NULL, *type=NULL, *body=NULL, *enc=NULL;
|
|
434 char *ns=NULL;
|
|
435 char *id=NULL;
|
35
|
436 enum imstatus ust;
|
31
|
437 // int npos;
|
|
438
|
112
|
439 jb_reset_keepalive(); // reset keepalive delay
|
31
|
440 jpacket_reset(packet);
|
|
441
|
|
442 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p;
|
|
443 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p;
|
|
444
|
|
445 switch (packet->type) {
|
|
446 case JPACKET_MESSAGE:
|
52
|
447 {
|
|
448 char *tmp = NULL;
|
|
449 x = xmlnode_get_tag(packet->x, "body");
|
|
450 p = xmlnode_get_data(x); if (p) body = p;
|
31
|
451
|
52
|
452 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL)
|
|
453 if ((p = xmlnode_get_data(x)) != NULL) {
|
|
454 tmp = malloc(strlen(body)+strlen(p)+3);
|
|
455 *tmp = '[';
|
|
456 strcpy(tmp+1, p);
|
|
457 strcat(tmp, "]\n");
|
|
458 strcat(tmp, body);
|
|
459 body = tmp;
|
|
460 }
|
|
461
|
|
462 /* there can be multiple <x> tags. we're looking for one with
|
|
463 xmlns = jabber:x:encrypted */
|
|
464
|
|
465 for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) {
|
|
466 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x"))
|
|
467 if ((p = xmlnode_get_attrib(x, "xmlns")) &&
|
|
468 !strcasecmp(p, "jabber:x:encrypted"))
|
|
469 if ((p = xmlnode_get_data(x)) != NULL) {
|
|
470 enc = p;
|
|
471 break;
|
|
472 }
|
31
|
473 }
|
|
474
|
52
|
475 if (body)
|
|
476 gotmessage(type, from, body, enc);
|
|
477 if (tmp)
|
|
478 free(tmp);
|
31
|
479 }
|
|
480 break;
|
|
481
|
|
482 case JPACKET_IQ:
|
|
483 if (!strcmp(type, "result")) {
|
|
484
|
51
|
485 if ((p = xmlnode_get_attrib(packet->x, "id")) != NULL) {
|
31
|
486 int iid = atoi(p);
|
|
487
|
|
488 ut_WriteLog("iid = %d\n", iid);
|
|
489 if (iid == s_id) {
|
|
490 if (!regmode) {
|
|
491 if (jstate == STATE_GETAUTH) {
|
51
|
492 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL)
|
31
|
493 if (!xmlnode_get_tag(x, "digest")) {
|
|
494 jc->sid = 0;
|
|
495 }
|
|
496
|
|
497 s_id = atoi(jab_auth(jc));
|
|
498 jstate = STATE_SENDAUTH;
|
|
499 } else {
|
|
500 gotloggedin();
|
|
501 jstate = STATE_LOGGED;
|
|
502 }
|
|
503 } else {
|
|
504 regdone = TRUE;
|
|
505 }
|
|
506 return;
|
|
507 }
|
|
508
|
|
509 if (!strcmp(p, "VCARDreq")) {
|
|
510 x = xmlnode_get_firstchild(packet->x);
|
|
511 if (!x) x = packet->x;
|
|
512
|
|
513 //jhook.gotvcard(ic, x); TODO
|
|
514 scr_LogPrint("Got VCARD");
|
|
515 return;
|
|
516 } else if (!strcmp(p, "versionreq")) {
|
|
517 // jhook.gotversion(ic, packet->x); TODO
|
|
518 scr_LogPrint("Got version");
|
|
519 return;
|
|
520 }
|
|
521 }
|
|
522
|
51
|
523 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) {
|
31
|
524 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p;
|
|
525
|
|
526 if (!strcmp(ns, NS_ROSTER)) {
|
|
527 gotroster(x);
|
|
528 } else if (!strcmp(ns, NS_AGENTS)) {
|
|
529 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) {
|
|
530 const char *alias = xmlnode_get_attrib(y, "jid");
|
|
531
|
|
532 if (alias) {
|
|
533 const char *name = xmlnode_get_tag_data(y, "name");
|
|
534 const char *desc = xmlnode_get_tag_data(y, "description");
|
51
|
535 // const char *service = xmlnode_get_tag_data(y, "service"); TODO
|
37
|
536 enum agtype atype = unknown;
|
31
|
537
|
37
|
538 if (xmlnode_get_tag(y, "groupchat")) atype = groupchat; else
|
|
539 if (xmlnode_get_tag(y, "transport")) atype = transport; else
|
|
540 if (xmlnode_get_tag(y, "search")) atype = search;
|
31
|
541
|
|
542 if (alias && name && desc) {
|
37
|
543 scr_LogPrint("Agent: %s / %s / %s / type=%d",
|
|
544 alias, name, desc, atype);
|
31
|
545
|
37
|
546 if (atype == search) {
|
31
|
547 x = jutil_iqnew (JPACKET__GET, NS_SEARCH);
|
|
548 xmlnode_put_attrib(x, "to", alias);
|
|
549 xmlnode_put_attrib(x, "id", "Agent info");
|
|
550 jab_send(conn, x);
|
|
551 xmlnode_free(x);
|
|
552 }
|
|
553
|
|
554 if (xmlnode_get_tag(y, "register")) {
|
|
555 x = jutil_iqnew (JPACKET__GET, NS_REGISTER);
|
|
556 xmlnode_put_attrib(x, "to", alias);
|
|
557 xmlnode_put_attrib(x, "id", "Agent info");
|
|
558 jab_send(conn, x);
|
|
559 xmlnode_free(x);
|
|
560 }
|
|
561 }
|
|
562 }
|
|
563 }
|
|
564
|
37
|
565 /*
|
31
|
566 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end())
|
|
567 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV,
|
|
568 _("Default Jabber conference server"), agent::atGroupchat));
|
|
569
|
|
570 */
|
|
571 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) {
|
|
572 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)"";
|
|
573
|
|
574 if (!strcmp(id, "Agent info")) {
|
|
575 // jhook.gotagentinfo(packet->x); TODO
|
|
576 scr_LogPrint("Got agent info");
|
|
577 } else if (!strcmp(id, "Lookup")) {
|
|
578 // jhook.gotsearchresults(packet->x); TODO
|
|
579 scr_LogPrint("Got search results");
|
|
580 } else if (!strcmp(id, "Register")) {
|
|
581 x = jutil_iqnew(JPACKET__GET, NS_REGISTER);
|
|
582 xmlnode_put_attrib(x, "to", from);
|
|
583 xmlnode_put_attrib(x, "id", "Agent info");
|
|
584 jab_send(conn, x);
|
|
585 xmlnode_free(x);
|
|
586 }
|
|
587
|
|
588 }
|
|
589 }
|
|
590 } else if (!strcmp(type, "set")) {
|
|
591 } else if (!strcmp(type, "error")) {
|
|
592 char *name=NULL, *desc=NULL;
|
52
|
593 int code = 0;
|
31
|
594
|
|
595 x = xmlnode_get_tag(packet->x, "error");
|
|
596 p = xmlnode_get_attrib(x, "code"); if (p) code = atoi(p);
|
|
597 p = xmlnode_get_attrib(x, "id"); if (p) name = p;
|
|
598 p = xmlnode_get_tag_data(packet->x, "error"); if (p) desc = p;
|
|
599
|
|
600 switch(code) {
|
|
601 case 401: /* Unauthorized */
|
|
602 case 302: /* Redirect */
|
|
603 case 400: /* Bad request */
|
|
604 case 402: /* Payment Required */
|
|
605 case 403: /* Forbidden */
|
|
606 case 404: /* Not Found */
|
|
607 case 405: /* Not Allowed */
|
|
608 case 406: /* Not Acceptable */
|
|
609 case 407: /* Registration Required */
|
|
610 case 408: /* Request Timeout */
|
|
611 case 409: /* Conflict */
|
|
612 case 500: /* Internal Server Error */
|
|
613 case 501: /* Not Implemented */
|
|
614 case 502: /* Remote Server Error */
|
|
615 case 503: /* Service Unavailable */
|
|
616 case 504: /* Remote Server Timeout */
|
|
617 default:
|
|
618 /*
|
|
619 if (!regmode) {
|
|
620 face.log(desc.empty() ?
|
|
621 _("+ [jab] error %d") :
|
|
622 _("+ [jab] error %d: %s"),
|
|
623 code, desc.c_str());
|
|
624
|
|
625 if (!jhook.flogged && code != 501) {
|
|
626 close(jc->fd);
|
|
627 jc->fd = -1;
|
|
628 }
|
|
629
|
|
630 } else {
|
|
631 jhook.regerr = desc;
|
|
632
|
|
633 }
|
|
634 */
|
|
635 }
|
|
636 scr_LogPrint("Error code from server (%d)", code);
|
|
637
|
|
638 }
|
|
639 break;
|
|
640
|
|
641 case JPACKET_PRESENCE:
|
|
642 x = xmlnode_get_tag(packet->x, "show");
|
35
|
643 ust = available;
|
31
|
644
|
|
645 if (x) {
|
|
646 p = xmlnode_get_data(x); if (p) ns = p;
|
|
647
|
|
648 if (ns) {
|
35
|
649 if (!strcmp(ns, "away")) ust = away;
|
|
650 else if (!strcmp(ns, "dnd")) ust = dontdisturb;
|
|
651 else if (!strcmp(ns, "xa")) ust = notavail;
|
|
652 else if (!strcmp(ns, "chat")) ust = freeforchat;
|
31
|
653 }
|
|
654 }
|
|
655
|
35
|
656 if (type && !strcmp(type, "unavailable")) {
|
|
657 ust = offline;
|
31
|
658 }
|
|
659
|
91
|
660 r = jidtodisp(from);
|
113
|
661 /*
|
91
|
662 if (ust != roster_getstatus(r))
|
|
663 scr_LogPrint("Buddy status has changed: [%c>%c] <%s>",
|
|
664 imstatus2char[roster_getstatus(r)], imstatus2char[ust], r);
|
|
665 roster_setstatus(r, ust);
|
113
|
666 */
|
|
667 if (ust != roster_getstatus(r))
|
|
668 hk_statuschange(r, 0, ust);
|
91
|
669 free(r);
|
81
|
670 buddylist_build();
|
|
671 scr_DrawRoster();
|
31
|
672 /*
|
35
|
673 if (x = xmlnode_get_tag(packet->x, "status"))
|
|
674 if (p = xmlnode_get_data(x))
|
|
675 scr_LogPrint("Away msg: %s", p);
|
31
|
676 */
|
|
677 break;
|
|
678
|
|
679 case JPACKET_S10N:
|
|
680 scr_LogPrint("Received subscription packet");
|
43
|
681 if (type) scr_LogPrint("Type=%s", type);
|
31
|
682
|
43
|
683 if (!strcmp(type, "subscribe")) {
|
91
|
684 int isagent;
|
|
685 r = jidtodisp(from);
|
|
686 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0;
|
|
687 free(r);
|
|
688 scr_LogPrint("isagent=%d", isagent); // XXX DBG
|
|
689 if (!isagent) {
|
43
|
690 scr_LogPrint("<%s> wants to subscribe "
|
|
691 "to your network presence updates", from);
|
91
|
692 } else {
|
|
693 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0);
|
31
|
694 jab_send(jc, x);
|
|
695 xmlnode_free(x);
|
91
|
696 }
|
43
|
697 } else if (!strcmp(type, "unsubscribe")) {
|
|
698 x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0);
|
31
|
699 jab_send(jc, x);
|
|
700 xmlnode_free(x);
|
43
|
701 scr_LogPrint("<%s> has unsubscribed to your presence updates", from);
|
31
|
702 }
|
|
703 break;
|
|
704
|
|
705 default:
|
|
706 break;
|
|
707 }
|
|
708 }
|
|
709
|