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 x = jutil_iqnew(JPACKET__GET, NS_AGENTS); |
|
288 xmlnode_put_attrib(x, "id", "Agent List"); |
|
289 jab_send(jc, x); |
|
290 xmlnode_free(x); |
|
291 |
|
292 x = jutil_iqnew(JPACKET__GET, NS_ROSTER); |
|
293 xmlnode_put_attrib(x, "id", "Roster"); |
|
294 jab_send(jc, x); |
|
295 xmlnode_free(x); |
|
296 } |
|
297 |
|
298 void gotroster(xmlnode x) |
|
299 { |
|
300 xmlnode y; // z; |
|
301 |
|
302 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) { |
|
303 const char *alias = xmlnode_get_attrib(y, "jid"); |
|
304 const char *sub = xmlnode_get_attrib(y, "subscription"); |
|
305 const char *name = xmlnode_get_attrib(y, "name"); |
|
306 //const char *group = 0; |
|
307 |
|
308 //z = xmlnode_get_tag(y, "group"); |
31
|
309 //if (z) group = xmlnode_get_data(z); |
29
|
310 |
|
311 if (alias) { |
|
312 char *buddyname = jidtodisp(alias); |
|
313 if (buddyname) { |
|
314 scr_LogPrint("New buddy: %s", buddyname); |
|
315 free(buddyname); |
|
316 } |
|
317 } |
|
318 } |
|
319 |
|
320 postlogin(); |
|
321 } |
|
322 |
|
323 void gotmessage(char *type, const char *from, const char *body, |
|
324 const char *enc) |
|
325 { |
|
326 char *u, *h, *r; |
|
327 |
|
328 jidsplit(from, &u, &h, &r); |
|
329 if (*r) |
|
330 scr_LogPrint("There is an extra part in message: %s", *r); |
|
331 scr_WriteIncomingMessage(from, body); |
|
332 } |
|
333 |
31
|
334 void statehandler(jconn conn, int state) |
|
335 { |
|
336 static int previous_state = -1; |
|
337 |
|
338 scr_LogPrint("StateHandler called (%d).\n", state); |
|
339 ut_WriteLog("StateHandler called (%d).\n", state); |
|
340 |
|
341 switch(state) { |
|
342 case JCONN_STATE_OFF: |
|
343 /* |
|
344 jhook.flogged = jhook.fonline = FALSE; |
|
345 |
|
346 if (previous_state != JCONN_STATE_OFF) { |
|
347 logger.putourstatus(jhook.proto, jhook.getstatus(), jhook.ourstatus = offline); |
|
348 jhook.log(logDisconnected); |
|
349 jhook.roster.clear(); |
|
350 jhook.agents.clear(); |
|
351 clist.setoffline(jhook.proto); |
|
352 face.update(); |
|
353 } |
|
354 */ |
|
355 break; |
|
356 |
|
357 case JCONN_STATE_CONNECTED: |
|
358 break; |
|
359 |
|
360 case JCONN_STATE_AUTH: |
|
361 break; |
|
362 |
|
363 case JCONN_STATE_ON: |
|
364 // if (regmode) jhook.fonline = TRUE; |
|
365 break; |
|
366 |
|
367 default: |
|
368 break; |
|
369 } |
|
370 previous_state = state; |
|
371 } |
|
372 |
|
373 void packethandler(jconn conn, jpacket packet) |
|
374 { |
|
375 char *p; |
|
376 xmlnode x; // , y; |
|
377 // string from, type, body, enc, ns, id, u, h, s; |
|
378 char *from=NULL, *type=NULL, *body=NULL, *enc=NULL; |
|
379 char *ns=NULL; |
|
380 char *id=NULL; |
|
381 // imstatus ust; |
|
382 // int npos; |
|
383 // bool isagent; |
|
384 |
|
385 scr_LogPrint("Received a packet"); |
|
386 ut_WriteLog("Received a packet\n"); |
|
387 |
|
388 jpacket_reset(packet); |
|
389 |
|
390 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p; |
|
391 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p; |
|
392 //imcontact ic(jidtodisp(from), jhook.proto); |
|
393 |
|
394 switch (packet->type) { |
|
395 case JPACKET_MESSAGE: |
|
396 x = xmlnode_get_tag(packet->x, "body"); |
|
397 p = xmlnode_get_data(x); if (p) body = p; |
|
398 |
|
399 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL) |
|
400 if ((p = xmlnode_get_data(x)) != NULL) { |
|
401 char *tmp = malloc(strlen(body)+strlen(p)+3); |
|
402 strcpy(tmp, p); |
|
403 strcat(tmp, ": "); |
|
404 strcat(tmp, body); |
|
405 body = tmp; // XXX check it is free'd later... |
|
406 } |
|
407 |
|
408 /* there can be multiple <x> tags. we're looking for one with |
|
409 xmlns = jabber:x:encrypted */ |
|
410 |
|
411 for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) { |
|
412 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) |
|
413 if ((p = xmlnode_get_attrib(x, "xmlns")) && !strcasecmp(p, "jabber:x:encrypted")) |
|
414 if ((p = xmlnode_get_data(x)) != NULL) { |
|
415 enc = p; |
|
416 break; |
|
417 } |
|
418 } |
|
419 |
|
420 // FIXME: |
|
421 if (body) { |
|
422 scr_LogPrint("Message received"); |
|
423 scr_LogPrint("Type: %s", type); |
|
424 gotmessage(type, from, body, enc); |
|
425 } |
|
426 |
|
427 break; |
|
428 |
|
429 case JPACKET_IQ: |
|
430 if (!strcmp(type, "result")) { |
|
431 scr_LogPrint("Received a result packet"); |
|
432 ut_WriteLog("Received a result packet\n"); |
|
433 |
|
434 if (p = xmlnode_get_attrib(packet->x, "id")) { |
|
435 int iid = atoi(p); |
|
436 |
|
437 ut_WriteLog("iid = %d\n", iid); |
|
438 if (iid == s_id) { |
|
439 if (!regmode) { |
|
440 if (jstate == STATE_GETAUTH) { |
|
441 if (x = xmlnode_get_tag(packet->x, "query")) |
|
442 if (!xmlnode_get_tag(x, "digest")) { |
|
443 jc->sid = 0; |
|
444 } |
|
445 |
|
446 s_id = atoi(jab_auth(jc)); |
|
447 jstate = STATE_SENDAUTH; |
|
448 } else { |
|
449 gotloggedin(); |
|
450 jstate = STATE_LOGGED; |
|
451 } |
|
452 } else { |
|
453 regdone = TRUE; |
|
454 } |
|
455 return; |
|
456 } |
|
457 |
|
458 if (!strcmp(p, "VCARDreq")) { |
|
459 x = xmlnode_get_firstchild(packet->x); |
|
460 if (!x) x = packet->x; |
|
461 |
|
462 //jhook.gotvcard(ic, x); TODO |
|
463 scr_LogPrint("Got VCARD"); |
|
464 return; |
|
465 } else if (!strcmp(p, "versionreq")) { |
|
466 // jhook.gotversion(ic, packet->x); TODO |
|
467 scr_LogPrint("Got version"); |
|
468 return; |
|
469 } |
|
470 } |
|
471 |
|
472 if (x = xmlnode_get_tag(packet->x, "query")) { |
|
473 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p; |
|
474 |
|
475 if (!strcmp(ns, NS_ROSTER)) { |
|
476 gotroster(x); |
|
477 } else if (!strcmp(ns, NS_AGENTS)) { |
|
478 /* TODO... |
|
479 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) { |
|
480 const char *alias = xmlnode_get_attrib(y, "jid"); |
|
481 |
|
482 if (alias) { |
|
483 const char *name = xmlnode_get_tag_data(y, "name"); |
|
484 const char *desc = xmlnode_get_tag_data(y, "description"); |
|
485 const char *service = xmlnode_get_tag_data(y, "service"); |
|
486 agent::agent_type atype = agent::atUnknown; |
|
487 |
|
488 if (xmlnode_get_tag(y, "groupchat")) atype = agent::atGroupchat; else |
|
489 if (xmlnode_get_tag(y, "transport")) atype = agent::atTransport; else |
|
490 if (xmlnode_get_tag(y, "search")) atype = agent::atSearch; |
|
491 |
|
492 if (alias && name && desc) { |
|
493 jhook.agents.push_back(agent(alias, name, desc, atype)); |
|
494 |
|
495 if (atype == agent::atSearch) { |
|
496 x = jutil_iqnew (JPACKET__GET, NS_SEARCH); |
|
497 xmlnode_put_attrib(x, "to", alias); |
|
498 xmlnode_put_attrib(x, "id", "Agent info"); |
|
499 jab_send(conn, x); |
|
500 xmlnode_free(x); |
|
501 } |
|
502 |
|
503 if (xmlnode_get_tag(y, "register")) { |
|
504 x = jutil_iqnew (JPACKET__GET, NS_REGISTER); |
|
505 xmlnode_put_attrib(x, "to", alias); |
|
506 xmlnode_put_attrib(x, "id", "Agent info"); |
|
507 jab_send(conn, x); |
|
508 xmlnode_free(x); |
|
509 } |
|
510 } |
|
511 } |
|
512 } |
|
513 |
|
514 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end()) |
|
515 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV, |
|
516 _("Default Jabber conference server"), agent::atGroupchat)); |
|
517 |
|
518 */ |
|
519 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) { |
|
520 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)""; |
|
521 |
|
522 if (!strcmp(id, "Agent info")) { |
|
523 // jhook.gotagentinfo(packet->x); TODO |
|
524 scr_LogPrint("Got agent info"); |
|
525 } else if (!strcmp(id, "Lookup")) { |
|
526 // jhook.gotsearchresults(packet->x); TODO |
|
527 scr_LogPrint("Got search results"); |
|
528 } else if (!strcmp(id, "Register")) { |
|
529 x = jutil_iqnew(JPACKET__GET, NS_REGISTER); |
|
530 xmlnode_put_attrib(x, "to", from); |
|
531 xmlnode_put_attrib(x, "id", "Agent info"); |
|
532 jab_send(conn, x); |
|
533 xmlnode_free(x); |
|
534 } |
|
535 |
|
536 } |
|
537 } |
|
538 } else if (!strcmp(type, "set")) { |
|
539 } else if (!strcmp(type, "error")) { |
|
540 char *name=NULL, *desc=NULL; |
|
541 int code; |
|
542 |
|
543 x = xmlnode_get_tag(packet->x, "error"); |
|
544 p = xmlnode_get_attrib(x, "code"); if (p) code = atoi(p); |
|
545 p = xmlnode_get_attrib(x, "id"); if (p) name = p; |
|
546 p = xmlnode_get_tag_data(packet->x, "error"); if (p) desc = p; |
|
547 |
|
548 switch(code) { |
|
549 case 401: /* Unauthorized */ |
|
550 case 302: /* Redirect */ |
|
551 case 400: /* Bad request */ |
|
552 case 402: /* Payment Required */ |
|
553 case 403: /* Forbidden */ |
|
554 case 404: /* Not Found */ |
|
555 case 405: /* Not Allowed */ |
|
556 case 406: /* Not Acceptable */ |
|
557 case 407: /* Registration Required */ |
|
558 case 408: /* Request Timeout */ |
|
559 case 409: /* Conflict */ |
|
560 case 500: /* Internal Server Error */ |
|
561 case 501: /* Not Implemented */ |
|
562 case 502: /* Remote Server Error */ |
|
563 case 503: /* Service Unavailable */ |
|
564 case 504: /* Remote Server Timeout */ |
|
565 default: |
|
566 /* |
|
567 if (!regmode) { |
|
568 face.log(desc.empty() ? |
|
569 _("+ [jab] error %d") : |
|
570 _("+ [jab] error %d: %s"), |
|
571 code, desc.c_str()); |
|
572 |
|
573 if (!jhook.flogged && code != 501) { |
|
574 close(jc->fd); |
|
575 jc->fd = -1; |
|
576 } |
|
577 |
|
578 } else { |
|
579 jhook.regerr = desc; |
|
580 |
|
581 } |
|
582 */ |
|
583 } |
|
584 scr_LogPrint("Error code from server (%d)", code); |
|
585 |
|
586 } |
|
587 break; |
|
588 |
|
589 case JPACKET_PRESENCE: |
|
590 x = xmlnode_get_tag(packet->x, "show"); |
|
591 //ust = available; |
|
592 |
|
593 if (x) { |
|
594 p = xmlnode_get_data(x); if (p) ns = p; |
|
595 |
|
596 if (ns) { |
|
597 scr_LogPrint("New status: %s", ns); |
|
598 /* |
|
599 if (ns == "away") ust = away; else |
|
600 if (ns == "dnd") ust = dontdisturb; else |
|
601 if (ns == "xa") ust = notavail; else |
|
602 if (ns == "chat") ust = freeforchat; |
|
603 */ |
|
604 } |
|
605 } |
|
606 |
|
607 if (!strcmp(type, "unavailable")) { |
|
608 scr_LogPrint("New status: unavailable/offline"); |
|
609 // XXX |
|
610 // ust = offline; |
|
611 } |
|
612 |
|
613 /* |
|
614 jidsplit(from, u, h, s); |
|
615 id = u + "@" + h; |
|
616 |
|
617 if (clist.get(imcontact((string) "#" + id, jhook.proto))) { |
|
618 if (ust == offline) { |
|
619 vector<string>::iterator im = find(jhook.chatmembers[id].begin(), jhook.chatmembers[id].end(), s); |
|
620 if (im != jhook.chatmembers[id].end()) |
|
621 jhook.chatmembers[id].erase(im); |
|
622 |
|
623 } else { |
|
624 jhook.chatmembers[id].push_back(s); |
|
625 |
|
626 } |
|
627 |
|
628 } else { |
|
629 icqcontact *c = clist.get(ic); |
|
630 |
|
631 if (c) |
|
632 if (c->getstatus() != ust) { |
|
633 if (c->getstatus() == offline) |
|
634 jhook.awaymsgs[ic.nickname] = ""; |
|
635 |
|
636 logger.putonline(c, c->getstatus(), ust); |
|
637 c->setstatus(ust); |
|
638 |
|
639 if (x = xmlnode_get_tag(packet->x, "status")) |
|
640 if (p = xmlnode_get_data(x)) |
|
641 jhook.awaymsgs[ic.nickname] = p; |
|
642 |
|
643 #ifdef HAVE_GPGME |
|
644 if (x = xmlnode_get_tag(packet->x, "x")) |
|
645 if (p = xmlnode_get_attrib(x, "xmlns")) |
|
646 if ((string) p == "jabber:x:signed") |
|
647 if (p = xmlnode_get_data(x)) |
|
648 c->setpgpkey(pgp.verify(p, jhook.awaymsgs[ic.nickname])); |
|
649 #endif |
|
650 |
|
651 } |
|
652 } |
|
653 */ |
|
654 break; |
|
655 |
|
656 case JPACKET_S10N: |
|
657 scr_LogPrint("Received subscription packet"); |
|
658 /* |
|
659 isagent = find(jhook.agents.begin(), jhook.agents.end(), from) != jhook.agents.end(); |
|
660 |
|
661 if (type == "subscribe") { |
|
662 if (!isagent) { |
|
663 em.store(imauthorization(ic, imevent::incoming, |
|
664 imauthorization::Request, _("The user wants to subscribe to your network presence updates"))); |
|
665 |
|
666 } else { |
|
667 auto_ptr<char> cfrom(strdup(from.c_str())); |
|
668 x = jutil_presnew(JPACKET__SUBSCRIBED, cfrom.get(), 0); |
|
669 jab_send(jc, x); |
|
670 xmlnode_free(x); |
|
671 } |
|
672 |
|
673 } else if (type == "unsubscribe") { |
|
674 auto_ptr<char> cfrom(strdup(from.c_str())); |
|
675 x = jutil_presnew(JPACKET__UNSUBSCRIBED, cfrom.get(), 0); |
|
676 jab_send(jc, x); |
|
677 xmlnode_free(x); |
|
678 em.store(imnotification(ic, _("The user has removed you from his contact list (unsubscribed you, using the Jabber language)"))); |
|
679 |
|
680 } |
|
681 */ |
|
682 |
|
683 break; |
|
684 |
|
685 default: |
|
686 break; |
|
687 } |
|
688 } |
|
689 |