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:
|
52
|
418 {
|
|
419 char *tmp = NULL;
|
|
420 x = xmlnode_get_tag(packet->x, "body");
|
|
421 p = xmlnode_get_data(x); if (p) body = p;
|
31
|
422
|
52
|
423 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL)
|
|
424 if ((p = xmlnode_get_data(x)) != NULL) {
|
|
425 tmp = malloc(strlen(body)+strlen(p)+3);
|
|
426 *tmp = '[';
|
|
427 strcpy(tmp+1, p);
|
|
428 strcat(tmp, "]\n");
|
|
429 strcat(tmp, body);
|
|
430 body = tmp;
|
|
431 }
|
|
432
|
|
433 /* there can be multiple <x> tags. we're looking for one with
|
|
434 xmlns = jabber:x:encrypted */
|
|
435
|
|
436 for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) {
|
|
437 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x"))
|
|
438 if ((p = xmlnode_get_attrib(x, "xmlns")) &&
|
|
439 !strcasecmp(p, "jabber:x:encrypted"))
|
|
440 if ((p = xmlnode_get_data(x)) != NULL) {
|
|
441 enc = p;
|
|
442 break;
|
|
443 }
|
31
|
444 }
|
|
445
|
52
|
446 if (body)
|
|
447 gotmessage(type, from, body, enc);
|
|
448 if (tmp)
|
|
449 free(tmp);
|
31
|
450 }
|
|
451 break;
|
|
452
|
|
453 case JPACKET_IQ:
|
|
454 if (!strcmp(type, "result")) {
|
|
455
|
51
|
456 if ((p = xmlnode_get_attrib(packet->x, "id")) != NULL) {
|
31
|
457 int iid = atoi(p);
|
|
458
|
|
459 ut_WriteLog("iid = %d\n", iid);
|
|
460 if (iid == s_id) {
|
|
461 if (!regmode) {
|
|
462 if (jstate == STATE_GETAUTH) {
|
51
|
463 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL)
|
31
|
464 if (!xmlnode_get_tag(x, "digest")) {
|
|
465 jc->sid = 0;
|
|
466 }
|
|
467
|
|
468 s_id = atoi(jab_auth(jc));
|
|
469 jstate = STATE_SENDAUTH;
|
|
470 } else {
|
|
471 gotloggedin();
|
|
472 jstate = STATE_LOGGED;
|
|
473 }
|
|
474 } else {
|
|
475 regdone = TRUE;
|
|
476 }
|
|
477 return;
|
|
478 }
|
|
479
|
|
480 if (!strcmp(p, "VCARDreq")) {
|
|
481 x = xmlnode_get_firstchild(packet->x);
|
|
482 if (!x) x = packet->x;
|
|
483
|
|
484 //jhook.gotvcard(ic, x); TODO
|
|
485 scr_LogPrint("Got VCARD");
|
|
486 return;
|
|
487 } else if (!strcmp(p, "versionreq")) {
|
|
488 // jhook.gotversion(ic, packet->x); TODO
|
|
489 scr_LogPrint("Got version");
|
|
490 return;
|
|
491 }
|
|
492 }
|
|
493
|
51
|
494 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) {
|
31
|
495 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p;
|
|
496
|
|
497 if (!strcmp(ns, NS_ROSTER)) {
|
|
498 gotroster(x);
|
|
499 } else if (!strcmp(ns, NS_AGENTS)) {
|
|
500 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) {
|
|
501 const char *alias = xmlnode_get_attrib(y, "jid");
|
|
502
|
|
503 if (alias) {
|
|
504 const char *name = xmlnode_get_tag_data(y, "name");
|
|
505 const char *desc = xmlnode_get_tag_data(y, "description");
|
51
|
506 // const char *service = xmlnode_get_tag_data(y, "service"); TODO
|
37
|
507 enum agtype atype = unknown;
|
31
|
508
|
37
|
509 if (xmlnode_get_tag(y, "groupchat")) atype = groupchat; else
|
|
510 if (xmlnode_get_tag(y, "transport")) atype = transport; else
|
|
511 if (xmlnode_get_tag(y, "search")) atype = search;
|
31
|
512
|
|
513 if (alias && name && desc) {
|
37
|
514 scr_LogPrint("Agent: %s / %s / %s / type=%d",
|
|
515 alias, name, desc, atype);
|
31
|
516
|
37
|
517 if (atype == search) {
|
31
|
518 x = jutil_iqnew (JPACKET__GET, NS_SEARCH);
|
|
519 xmlnode_put_attrib(x, "to", alias);
|
|
520 xmlnode_put_attrib(x, "id", "Agent info");
|
|
521 jab_send(conn, x);
|
|
522 xmlnode_free(x);
|
|
523 }
|
|
524
|
|
525 if (xmlnode_get_tag(y, "register")) {
|
|
526 x = jutil_iqnew (JPACKET__GET, NS_REGISTER);
|
|
527 xmlnode_put_attrib(x, "to", alias);
|
|
528 xmlnode_put_attrib(x, "id", "Agent info");
|
|
529 jab_send(conn, x);
|
|
530 xmlnode_free(x);
|
|
531 }
|
|
532 }
|
|
533 }
|
|
534 }
|
|
535
|
37
|
536 /*
|
31
|
537 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end())
|
|
538 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV,
|
|
539 _("Default Jabber conference server"), agent::atGroupchat));
|
|
540
|
|
541 */
|
|
542 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) {
|
|
543 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)"";
|
|
544
|
|
545 if (!strcmp(id, "Agent info")) {
|
|
546 // jhook.gotagentinfo(packet->x); TODO
|
|
547 scr_LogPrint("Got agent info");
|
|
548 } else if (!strcmp(id, "Lookup")) {
|
|
549 // jhook.gotsearchresults(packet->x); TODO
|
|
550 scr_LogPrint("Got search results");
|
|
551 } else if (!strcmp(id, "Register")) {
|
|
552 x = jutil_iqnew(JPACKET__GET, NS_REGISTER);
|
|
553 xmlnode_put_attrib(x, "to", from);
|
|
554 xmlnode_put_attrib(x, "id", "Agent info");
|
|
555 jab_send(conn, x);
|
|
556 xmlnode_free(x);
|
|
557 }
|
|
558
|
|
559 }
|
|
560 }
|
|
561 } else if (!strcmp(type, "set")) {
|
|
562 } else if (!strcmp(type, "error")) {
|
|
563 char *name=NULL, *desc=NULL;
|
52
|
564 int code = 0;
|
31
|
565
|
|
566 x = xmlnode_get_tag(packet->x, "error");
|
|
567 p = xmlnode_get_attrib(x, "code"); if (p) code = atoi(p);
|
|
568 p = xmlnode_get_attrib(x, "id"); if (p) name = p;
|
|
569 p = xmlnode_get_tag_data(packet->x, "error"); if (p) desc = p;
|
|
570
|
|
571 switch(code) {
|
|
572 case 401: /* Unauthorized */
|
|
573 case 302: /* Redirect */
|
|
574 case 400: /* Bad request */
|
|
575 case 402: /* Payment Required */
|
|
576 case 403: /* Forbidden */
|
|
577 case 404: /* Not Found */
|
|
578 case 405: /* Not Allowed */
|
|
579 case 406: /* Not Acceptable */
|
|
580 case 407: /* Registration Required */
|
|
581 case 408: /* Request Timeout */
|
|
582 case 409: /* Conflict */
|
|
583 case 500: /* Internal Server Error */
|
|
584 case 501: /* Not Implemented */
|
|
585 case 502: /* Remote Server Error */
|
|
586 case 503: /* Service Unavailable */
|
|
587 case 504: /* Remote Server Timeout */
|
|
588 default:
|
|
589 /*
|
|
590 if (!regmode) {
|
|
591 face.log(desc.empty() ?
|
|
592 _("+ [jab] error %d") :
|
|
593 _("+ [jab] error %d: %s"),
|
|
594 code, desc.c_str());
|
|
595
|
|
596 if (!jhook.flogged && code != 501) {
|
|
597 close(jc->fd);
|
|
598 jc->fd = -1;
|
|
599 }
|
|
600
|
|
601 } else {
|
|
602 jhook.regerr = desc;
|
|
603
|
|
604 }
|
|
605 */
|
|
606 }
|
|
607 scr_LogPrint("Error code from server (%d)", code);
|
|
608
|
|
609 }
|
|
610 break;
|
|
611
|
|
612 case JPACKET_PRESENCE:
|
|
613 x = xmlnode_get_tag(packet->x, "show");
|
35
|
614 ust = available;
|
31
|
615
|
|
616 if (x) {
|
|
617 p = xmlnode_get_data(x); if (p) ns = p;
|
|
618
|
|
619 if (ns) {
|
35
|
620 if (!strcmp(ns, "away")) ust = away;
|
|
621 else if (!strcmp(ns, "dnd")) ust = dontdisturb;
|
|
622 else if (!strcmp(ns, "xa")) ust = notavail;
|
|
623 else if (!strcmp(ns, "chat")) ust = freeforchat;
|
31
|
624 }
|
|
625 }
|
|
626
|
35
|
627 if (type && !strcmp(type, "unavailable")) {
|
|
628 ust = offline;
|
31
|
629 }
|
41
|
630 //scr_LogPrint("New status: ust=%d (%s)", ust, from);
|
31
|
631
|
35
|
632 bud_SetBuddyStatus(jidtodisp(from), ust);
|
31
|
633 /*
|
35
|
634 if (x = xmlnode_get_tag(packet->x, "status"))
|
|
635 if (p = xmlnode_get_data(x))
|
|
636 scr_LogPrint("Away msg: %s", p);
|
31
|
637 */
|
|
638 break;
|
|
639
|
|
640 case JPACKET_S10N:
|
|
641 scr_LogPrint("Received subscription packet");
|
43
|
642 if (type) scr_LogPrint("Type=%s", type);
|
31
|
643
|
43
|
644 if (!strcmp(type, "subscribe")) {
|
|
645 // if (!isagent) {
|
|
646 scr_LogPrint("<%s> wants to subscribe "
|
|
647 "to your network presence updates", from);
|
|
648 /*} else {
|
31
|
649 auto_ptr<char> cfrom(strdup(from.c_str()));
|
|
650 x = jutil_presnew(JPACKET__SUBSCRIBED, cfrom.get(), 0);
|
|
651 jab_send(jc, x);
|
|
652 xmlnode_free(x);
|
43
|
653 }*/
|
|
654 } else if (!strcmp(type, "unsubscribe")) {
|
|
655 x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0);
|
31
|
656 jab_send(jc, x);
|
|
657 xmlnode_free(x);
|
43
|
658 scr_LogPrint("<%s> has unsubscribed to your presence updates", from);
|
31
|
659 }
|
|
660 break;
|
|
661
|
|
662 default:
|
|
663 break;
|
|
664 }
|
|
665 }
|
|
666
|