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