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
|
31
|
36 static enum {
|
29
|
37 STATE_CONNECTING,
|
|
38 STATE_GETAUTH,
|
|
39 STATE_SENDAUTH,
|
|
40 STATE_LOGGED
|
|
41 } jstate;
|
|
42
|
|
43
|
31
|
44 void statehandler(jconn, int);
|
|
45 void packethandler(jconn, jpacket);
|
|
46
|
|
47 void screen_logger(jconn j, int io, const char *buf)
|
|
48 {
|
|
49 scr_LogPrint("%.03s: %s", ((io == 0) ? "OUT" : "IN"), buf);
|
|
50 }
|
|
51
|
|
52 void file_logger(jconn j, int io, const char *buf)
|
|
53 {
|
|
54 ut_WriteLog("%.03s: %s\n", ((io == 0) ? "OUT" : "IN"), buf);
|
|
55 }
|
|
56
|
|
57 void big_logger(jconn j, int io, const char *buf)
|
|
58 {
|
|
59 screen_logger(j, io, buf);
|
|
60 file_logger(j, io, buf);
|
|
61 }
|
|
62
|
29
|
63 static void jidsplit(const char *jid, char **user, char **host,
|
|
64 char **res)
|
|
65 {
|
|
66 char *tmp, *ptr;
|
|
67 tmp = strdup(jid);
|
|
68
|
|
69 if ((ptr = strchr(tmp, '/')) != NULL) {
|
|
70 *res = strdup(ptr+1);
|
|
71 *ptr = 0;
|
|
72 } else
|
|
73 *res = NULL;
|
|
74
|
|
75 if ((ptr = strchr(tmp, '@')) != NULL) {
|
|
76 *host = strdup(ptr+1);
|
|
77 *ptr = 0;
|
|
78 } else
|
|
79 *host = NULL;
|
|
80
|
|
81 *user = strdup(tmp);
|
|
82 free(tmp);
|
|
83 }
|
|
84
|
|
85 char *jidtodisp(const char *jid)
|
|
86 {
|
|
87 char *ptr;
|
|
88 char *alias = strdup(jid);
|
|
89 if ((ptr = strchr(alias, '/')) != NULL) {
|
|
90 *ptr = 0;
|
|
91 }
|
|
92 return alias;
|
|
93 }
|
|
94
|
|
95 jconn jb_connect(const char *servername, unsigned int port, int ssl,
|
|
96 const char *jid, const char *pass,
|
|
97 const char *resource)
|
|
98 {
|
|
99 if (!port) {
|
|
100 if (ssl)
|
|
101 port = JABBERSSLPORT;
|
|
102 else
|
|
103 port = JABBERPORT;
|
|
104 }
|
|
105
|
|
106 if (jc)
|
|
107 free(jc);
|
|
108
|
|
109 //jc = jab_new(jid, pass, port, ssl);
|
|
110 jc = jab_new("mctest@lilotux.net/mcabber", (char*)pass, (int)port, ssl);
|
|
111
|
31
|
112 jab_logger(jc, big_logger);
|
29
|
113 jab_packet_handler(jc, &packethandler);
|
|
114 jab_state_handler(jc, &statehandler);
|
|
115
|
|
116 if (jc->user) {
|
31
|
117 //fonline = TRUE;
|
29
|
118 scr_LogPrint("+ State_Connecting");
|
|
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) {
|
|
218 msg = "unknownStatus";
|
|
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
|
31
|
233 void postlogin()
|
|
234 {
|
|
235 //int i;
|
|
236
|
|
237 //flogged = TRUE;
|
|
238 //ourstatus = available;
|
|
239
|
|
240 //setautostatus(jhook.manualstatus);
|
|
241
|
|
242 /*
|
|
243 for (i = 0; i < clist.count; i++) {
|
|
244 c = (icqcontact *) clist.at(i);
|
|
245
|
|
246 if (c->getdesc().pname == proto)
|
|
247 if (ischannel(c))
|
|
248 if (c->getbasicinfo().requiresauth)
|
|
249 c->setstatus(available);
|
|
250 }
|
|
251 */
|
|
252
|
|
253 /*
|
|
254 agents.insert(agents.begin(), agent("vcard", "Jabber VCard", "", agent::atStandard));
|
|
255 agents.begin()->params[agent::ptRegister].enabled = TRUE;
|
|
256
|
|
257 string buf;
|
|
258 ifstream f(conf.getconfigfname("jabber-infoset").c_str());
|
|
259
|
|
260 if (f.is_open()) {
|
|
261 icqcontact *c = clist.get(contactroot);
|
|
262
|
|
263 c->clear();
|
|
264 icqcontact::basicinfo bi = c->getbasicinfo();
|
|
265 icqcontact::reginfo ri = c->getreginfo();
|
|
266
|
|
267 ri.service = agents.begin()->name;
|
|
268 getstring(f, buf); c->setnick(buf);
|
|
269 getstring(f, buf); bi.email = buf;
|
|
270 getstring(f, buf); bi.fname = buf;
|
|
271 getstring(f, buf); bi.lname = buf;
|
|
272 f.close();
|
|
273
|
|
274 c->setbasicinfo(bi);
|
|
275 c->setreginfo(ri);
|
|
276
|
|
277 sendupdateuserinfo(*c);
|
|
278 unlink(conf.getconfigfname("jabber-infoset").c_str());
|
|
279 }
|
|
280 */
|
|
281 }
|
|
282
|
29
|
283 void gotloggedin(void)
|
|
284 {
|
|
285 xmlnode x;
|
|
286
|
|
287 /*
|
|
288 x = jutil_iqnew(JPACKET__GET, NS_AGENTS);
|
|
289 xmlnode_put_attrib(x, "id", "Agent List");
|
|
290 jab_send(jc, x);
|
|
291 xmlnode_free(x);
|
|
292 */
|
|
293
|
|
294 x = jutil_iqnew(JPACKET__GET, NS_ROSTER);
|
|
295 xmlnode_put_attrib(x, "id", "Roster");
|
|
296 jab_send(jc, x);
|
|
297 xmlnode_free(x);
|
|
298 }
|
|
299
|
|
300 void gotroster(xmlnode x)
|
|
301 {
|
|
302 xmlnode y; // z;
|
|
303
|
|
304 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) {
|
|
305 const char *alias = xmlnode_get_attrib(y, "jid");
|
|
306 const char *sub = xmlnode_get_attrib(y, "subscription");
|
|
307 const char *name = xmlnode_get_attrib(y, "name");
|
|
308 //const char *group = 0;
|
|
309
|
|
310 //z = xmlnode_get_tag(y, "group");
|
31
|
311 //if (z) group = xmlnode_get_data(z);
|
29
|
312
|
|
313 if (alias) {
|
|
314 char *buddyname = jidtodisp(alias);
|
|
315 if (buddyname) {
|
|
316 scr_LogPrint("New buddy: %s", buddyname);
|
|
317 free(buddyname);
|
|
318 }
|
|
319 }
|
|
320 }
|
|
321
|
|
322 postlogin();
|
|
323 }
|
|
324
|
|
325 void gotmessage(char *type, const char *from, const char *body,
|
|
326 const char *enc)
|
|
327 {
|
|
328 char *u, *h, *r;
|
|
329
|
|
330 jidsplit(from, &u, &h, &r);
|
|
331 if (*r)
|
|
332 scr_LogPrint("There is an extra part in message: %s", *r);
|
|
333 scr_WriteIncomingMessage(from, body);
|
|
334 }
|
|
335
|
31
|
336 void statehandler(jconn conn, int state)
|
|
337 {
|
|
338 static int previous_state = -1;
|
|
339
|
|
340 scr_LogPrint("StateHandler called (%d).\n", state);
|
|
341 ut_WriteLog("StateHandler called (%d).\n", state);
|
|
342
|
|
343 switch(state) {
|
|
344 case JCONN_STATE_OFF:
|
|
345 /*
|
|
346 jhook.flogged = jhook.fonline = FALSE;
|
|
347
|
|
348 if (previous_state != JCONN_STATE_OFF) {
|
|
349 logger.putourstatus(jhook.proto, jhook.getstatus(), jhook.ourstatus = offline);
|
|
350 jhook.log(logDisconnected);
|
|
351 jhook.roster.clear();
|
|
352 jhook.agents.clear();
|
|
353 clist.setoffline(jhook.proto);
|
|
354 face.update();
|
|
355 }
|
|
356 */
|
|
357 break;
|
|
358
|
|
359 case JCONN_STATE_CONNECTED:
|
|
360 break;
|
|
361
|
|
362 case JCONN_STATE_AUTH:
|
|
363 break;
|
|
364
|
|
365 case JCONN_STATE_ON:
|
|
366 // if (regmode) jhook.fonline = TRUE;
|
|
367 break;
|
|
368
|
|
369 default:
|
|
370 break;
|
|
371 }
|
|
372 previous_state = state;
|
|
373 }
|
|
374
|
|
375 void packethandler(jconn conn, jpacket packet)
|
|
376 {
|
|
377 char *p;
|
|
378 xmlnode x; // , y;
|
|
379 // string from, type, body, enc, ns, id, u, h, s;
|
|
380 char *from=NULL, *type=NULL, *body=NULL, *enc=NULL;
|
|
381 char *ns=NULL;
|
|
382 char *id=NULL;
|
|
383 // imstatus ust;
|
|
384 // int npos;
|
|
385 // bool isagent;
|
|
386
|
|
387 scr_LogPrint("Received a packet");
|
|
388 ut_WriteLog("Received a packet\n");
|
|
389
|
|
390 jpacket_reset(packet);
|
|
391
|
|
392 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p;
|
|
393 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p;
|
|
394 //imcontact ic(jidtodisp(from), jhook.proto);
|
|
395
|
|
396 switch (packet->type) {
|
|
397 case JPACKET_MESSAGE:
|
|
398 x = xmlnode_get_tag(packet->x, "body");
|
|
399 p = xmlnode_get_data(x); if (p) body = p;
|
|
400
|
|
401 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL)
|
|
402 if ((p = xmlnode_get_data(x)) != NULL) {
|
|
403 char *tmp = malloc(strlen(body)+strlen(p)+3);
|
|
404 strcpy(tmp, p);
|
|
405 strcat(tmp, ": ");
|
|
406 strcat(tmp, body);
|
|
407 body = tmp; // XXX check it is free'd later...
|
|
408 }
|
|
409
|
|
410 /* there can be multiple <x> tags. we're looking for one with
|
|
411 xmlns = jabber:x:encrypted */
|
|
412
|
|
413 for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) {
|
|
414 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x"))
|
|
415 if ((p = xmlnode_get_attrib(x, "xmlns")) && !strcasecmp(p, "jabber:x:encrypted"))
|
|
416 if ((p = xmlnode_get_data(x)) != NULL) {
|
|
417 enc = p;
|
|
418 break;
|
|
419 }
|
|
420 }
|
|
421
|
|
422 // FIXME:
|
|
423 if (body) {
|
|
424 scr_LogPrint("Message received");
|
|
425 scr_LogPrint("Type: %s", type);
|
|
426 gotmessage(type, from, body, enc);
|
|
427 }
|
|
428
|
|
429 break;
|
|
430
|
|
431 case JPACKET_IQ:
|
|
432 if (!strcmp(type, "result")) {
|
|
433 scr_LogPrint("Received a result packet");
|
|
434 ut_WriteLog("Received a result packet\n");
|
|
435
|
|
436 if (p = xmlnode_get_attrib(packet->x, "id")) {
|
|
437 int iid = atoi(p);
|
|
438
|
|
439 ut_WriteLog("iid = %d\n", iid);
|
|
440 if (iid == s_id) {
|
|
441 if (!regmode) {
|
|
442 if (jstate == STATE_GETAUTH) {
|
|
443 if (x = xmlnode_get_tag(packet->x, "query"))
|
|
444 if (!xmlnode_get_tag(x, "digest")) {
|
|
445 jc->sid = 0;
|
|
446 }
|
|
447
|
|
448 s_id = atoi(jab_auth(jc));
|
|
449 jstate = STATE_SENDAUTH;
|
|
450 } else {
|
|
451 gotloggedin();
|
|
452 jstate = STATE_LOGGED;
|
|
453 }
|
|
454 } else {
|
|
455 regdone = TRUE;
|
|
456 }
|
|
457 return;
|
|
458 }
|
|
459
|
|
460 if (!strcmp(p, "VCARDreq")) {
|
|
461 x = xmlnode_get_firstchild(packet->x);
|
|
462 if (!x) x = packet->x;
|
|
463
|
|
464 //jhook.gotvcard(ic, x); TODO
|
|
465 scr_LogPrint("Got VCARD");
|
|
466 return;
|
|
467 } else if (!strcmp(p, "versionreq")) {
|
|
468 // jhook.gotversion(ic, packet->x); TODO
|
|
469 scr_LogPrint("Got version");
|
|
470 return;
|
|
471 }
|
|
472 }
|
|
473
|
|
474 if (x = xmlnode_get_tag(packet->x, "query")) {
|
|
475 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p;
|
|
476
|
|
477 if (!strcmp(ns, NS_ROSTER)) {
|
|
478 gotroster(x);
|
|
479 } else if (!strcmp(ns, NS_AGENTS)) {
|
|
480 /* TODO...
|
|
481 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) {
|
|
482 const char *alias = xmlnode_get_attrib(y, "jid");
|
|
483
|
|
484 if (alias) {
|
|
485 const char *name = xmlnode_get_tag_data(y, "name");
|
|
486 const char *desc = xmlnode_get_tag_data(y, "description");
|
|
487 const char *service = xmlnode_get_tag_data(y, "service");
|
|
488 agent::agent_type atype = agent::atUnknown;
|
|
489
|
|
490 if (xmlnode_get_tag(y, "groupchat")) atype = agent::atGroupchat; else
|
|
491 if (xmlnode_get_tag(y, "transport")) atype = agent::atTransport; else
|
|
492 if (xmlnode_get_tag(y, "search")) atype = agent::atSearch;
|
|
493
|
|
494 if (alias && name && desc) {
|
|
495 jhook.agents.push_back(agent(alias, name, desc, atype));
|
|
496
|
|
497 if (atype == agent::atSearch) {
|
|
498 x = jutil_iqnew (JPACKET__GET, NS_SEARCH);
|
|
499 xmlnode_put_attrib(x, "to", alias);
|
|
500 xmlnode_put_attrib(x, "id", "Agent info");
|
|
501 jab_send(conn, x);
|
|
502 xmlnode_free(x);
|
|
503 }
|
|
504
|
|
505 if (xmlnode_get_tag(y, "register")) {
|
|
506 x = jutil_iqnew (JPACKET__GET, NS_REGISTER);
|
|
507 xmlnode_put_attrib(x, "to", alias);
|
|
508 xmlnode_put_attrib(x, "id", "Agent info");
|
|
509 jab_send(conn, x);
|
|
510 xmlnode_free(x);
|
|
511 }
|
|
512 }
|
|
513 }
|
|
514 }
|
|
515
|
|
516 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end())
|
|
517 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV,
|
|
518 _("Default Jabber conference server"), agent::atGroupchat));
|
|
519
|
|
520 */
|
|
521 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) {
|
|
522 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)"";
|
|
523
|
|
524 if (!strcmp(id, "Agent info")) {
|
|
525 // jhook.gotagentinfo(packet->x); TODO
|
|
526 scr_LogPrint("Got agent info");
|
|
527 } else if (!strcmp(id, "Lookup")) {
|
|
528 // jhook.gotsearchresults(packet->x); TODO
|
|
529 scr_LogPrint("Got search results");
|
|
530 } else if (!strcmp(id, "Register")) {
|
|
531 x = jutil_iqnew(JPACKET__GET, NS_REGISTER);
|
|
532 xmlnode_put_attrib(x, "to", from);
|
|
533 xmlnode_put_attrib(x, "id", "Agent info");
|
|
534 jab_send(conn, x);
|
|
535 xmlnode_free(x);
|
|
536 }
|
|
537
|
|
538 }
|
|
539 }
|
|
540 } else if (!strcmp(type, "set")) {
|
|
541 } else if (!strcmp(type, "error")) {
|
|
542 char *name=NULL, *desc=NULL;
|
|
543 int code;
|
|
544
|
|
545 x = xmlnode_get_tag(packet->x, "error");
|
|
546 p = xmlnode_get_attrib(x, "code"); if (p) code = atoi(p);
|
|
547 p = xmlnode_get_attrib(x, "id"); if (p) name = p;
|
|
548 p = xmlnode_get_tag_data(packet->x, "error"); if (p) desc = p;
|
|
549
|
|
550 switch(code) {
|
|
551 case 401: /* Unauthorized */
|
|
552 case 302: /* Redirect */
|
|
553 case 400: /* Bad request */
|
|
554 case 402: /* Payment Required */
|
|
555 case 403: /* Forbidden */
|
|
556 case 404: /* Not Found */
|
|
557 case 405: /* Not Allowed */
|
|
558 case 406: /* Not Acceptable */
|
|
559 case 407: /* Registration Required */
|
|
560 case 408: /* Request Timeout */
|
|
561 case 409: /* Conflict */
|
|
562 case 500: /* Internal Server Error */
|
|
563 case 501: /* Not Implemented */
|
|
564 case 502: /* Remote Server Error */
|
|
565 case 503: /* Service Unavailable */
|
|
566 case 504: /* Remote Server Timeout */
|
|
567 default:
|
|
568 /*
|
|
569 if (!regmode) {
|
|
570 face.log(desc.empty() ?
|
|
571 _("+ [jab] error %d") :
|
|
572 _("+ [jab] error %d: %s"),
|
|
573 code, desc.c_str());
|
|
574
|
|
575 if (!jhook.flogged && code != 501) {
|
|
576 close(jc->fd);
|
|
577 jc->fd = -1;
|
|
578 }
|
|
579
|
|
580 } else {
|
|
581 jhook.regerr = desc;
|
|
582
|
|
583 }
|
|
584 */
|
|
585 }
|
|
586 scr_LogPrint("Error code from server (%d)", code);
|
|
587
|
|
588 }
|
|
589 break;
|
|
590
|
|
591 case JPACKET_PRESENCE:
|
|
592 x = xmlnode_get_tag(packet->x, "show");
|
|
593 //ust = available;
|
|
594
|
|
595 if (x) {
|
|
596 p = xmlnode_get_data(x); if (p) ns = p;
|
|
597
|
|
598 if (ns) {
|
|
599 scr_LogPrint("New status: %s", ns);
|
|
600 /*
|
|
601 if (ns == "away") ust = away; else
|
|
602 if (ns == "dnd") ust = dontdisturb; else
|
|
603 if (ns == "xa") ust = notavail; else
|
|
604 if (ns == "chat") ust = freeforchat;
|
|
605 */
|
|
606 }
|
|
607 }
|
|
608
|
|
609 if (!strcmp(type, "unavailable")) {
|
|
610 scr_LogPrint("New status: unavailable/offline");
|
|
611 // XXX
|
|
612 // ust = offline;
|
|
613 }
|
|
614
|
|
615 /*
|
|
616 jidsplit(from, u, h, s);
|
|
617 id = u + "@" + h;
|
|
618
|
|
619 if (clist.get(imcontact((string) "#" + id, jhook.proto))) {
|
|
620 if (ust == offline) {
|
|
621 vector<string>::iterator im = find(jhook.chatmembers[id].begin(), jhook.chatmembers[id].end(), s);
|
|
622 if (im != jhook.chatmembers[id].end())
|
|
623 jhook.chatmembers[id].erase(im);
|
|
624
|
|
625 } else {
|
|
626 jhook.chatmembers[id].push_back(s);
|
|
627
|
|
628 }
|
|
629
|
|
630 } else {
|
|
631 icqcontact *c = clist.get(ic);
|
|
632
|
|
633 if (c)
|
|
634 if (c->getstatus() != ust) {
|
|
635 if (c->getstatus() == offline)
|
|
636 jhook.awaymsgs[ic.nickname] = "";
|
|
637
|
|
638 logger.putonline(c, c->getstatus(), ust);
|
|
639 c->setstatus(ust);
|
|
640
|
|
641 if (x = xmlnode_get_tag(packet->x, "status"))
|
|
642 if (p = xmlnode_get_data(x))
|
|
643 jhook.awaymsgs[ic.nickname] = p;
|
|
644
|
|
645 #ifdef HAVE_GPGME
|
|
646 if (x = xmlnode_get_tag(packet->x, "x"))
|
|
647 if (p = xmlnode_get_attrib(x, "xmlns"))
|
|
648 if ((string) p == "jabber:x:signed")
|
|
649 if (p = xmlnode_get_data(x))
|
|
650 c->setpgpkey(pgp.verify(p, jhook.awaymsgs[ic.nickname]));
|
|
651 #endif
|
|
652
|
|
653 }
|
|
654 }
|
|
655 */
|
|
656 break;
|
|
657
|
|
658 case JPACKET_S10N:
|
|
659 scr_LogPrint("Received subscription packet");
|
|
660 /*
|
|
661 isagent = find(jhook.agents.begin(), jhook.agents.end(), from) != jhook.agents.end();
|
|
662
|
|
663 if (type == "subscribe") {
|
|
664 if (!isagent) {
|
|
665 em.store(imauthorization(ic, imevent::incoming,
|
|
666 imauthorization::Request, _("The user wants to subscribe to your network presence updates")));
|
|
667
|
|
668 } else {
|
|
669 auto_ptr<char> cfrom(strdup(from.c_str()));
|
|
670 x = jutil_presnew(JPACKET__SUBSCRIBED, cfrom.get(), 0);
|
|
671 jab_send(jc, x);
|
|
672 xmlnode_free(x);
|
|
673 }
|
|
674
|
|
675 } else if (type == "unsubscribe") {
|
|
676 auto_ptr<char> cfrom(strdup(from.c_str()));
|
|
677 x = jutil_presnew(JPACKET__UNSUBSCRIBED, cfrom.get(), 0);
|
|
678 jab_send(jc, x);
|
|
679 xmlnode_free(x);
|
|
680 em.store(imnotification(ic, _("The user has removed you from his contact list (unsubscribed you, using the Jabber language)")));
|
|
681
|
|
682 }
|
|
683 */
|
|
684
|
|
685 break;
|
|
686
|
|
687 default:
|
|
688 break;
|
|
689 }
|
|
690 }
|
|
691
|