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