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 |
{ |
36
|
49 |
scr_LogPrint("%03s: %s", ((io == 0) ? "OUT" : "IN"), buf); |
31
|
50 |
} |
|
51 |
|
|
52 |
void file_logger(jconn j, int io, const char *buf) |
|
53 |
{ |
36
|
54 |
ut_WriteLog("%03s: %s\n", ((io == 0) ? "OUT" : "IN"), buf); |
31
|
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 |
bud_AddBuddy(alias, buddyname); |
|
323 |
if (!name) |
29
|
324 |
free(buddyname); |
|
325 |
} |
|
326 |
} |
|
327 |
|
35
|
328 |
bud_SortRoster(); |
29
|
329 |
postlogin(); |
|
330 |
} |
|
331 |
|
|
332 |
void gotmessage(char *type, const char *from, const char *body, |
|
333 |
const char *enc) |
|
334 |
{ |
|
335 |
char *u, *h, *r; |
|
336 |
|
|
337 |
jidsplit(from, &u, &h, &r); |
35
|
338 |
/* |
|
339 |
// Maybe we should remember the resource? |
|
340 |
if (r) |
|
341 |
scr_LogPrint("There is an extra part in message (resource?): %s", r); |
|
342 |
*/ |
|
343 |
|
43
|
344 |
//scr_LogPrint("Msg from <%s>, type=%s", jidtodisp(from), type); |
35
|
345 |
scr_WriteIncomingMessage(jidtodisp(from), body); |
29
|
346 |
} |
|
347 |
|
31
|
348 |
void statehandler(jconn conn, int state) |
|
349 |
{ |
|
350 |
static int previous_state = -1; |
|
351 |
|
35
|
352 |
ut_WriteLog("StateHandler called (state=%d).\n", state); |
31
|
353 |
|
|
354 |
switch(state) { |
|
355 |
case JCONN_STATE_OFF: |
37
|
356 |
|
|
357 |
/* jhook.flogged = jhook.fonline = FALSE; */ |
31
|
358 |
|
37
|
359 |
if (previous_state != JCONN_STATE_OFF) { |
|
360 |
scr_LogPrint("+ JCONN_STATE_OFF"); |
|
361 |
/* |
31
|
362 |
jhook.roster.clear(); |
|
363 |
jhook.agents.clear(); |
37
|
364 |
*/ |
|
365 |
} |
31
|
366 |
break; |
|
367 |
|
|
368 |
case JCONN_STATE_CONNECTED: |
35
|
369 |
scr_LogPrint("+ JCONN_STATE_CONNECTED"); |
31
|
370 |
break; |
|
371 |
|
|
372 |
case JCONN_STATE_AUTH: |
35
|
373 |
scr_LogPrint("+ JCONN_STATE_AUTH"); |
31
|
374 |
break; |
|
375 |
|
|
376 |
case JCONN_STATE_ON: |
35
|
377 |
scr_LogPrint("+ JCONN_STATE_ON"); |
31
|
378 |
// if (regmode) jhook.fonline = TRUE; |
|
379 |
break; |
|
380 |
|
35
|
381 |
case JCONN_STATE_CONNECTING: |
|
382 |
scr_LogPrint("+ JCONN_STATE_CONNECTING"); |
|
383 |
break; |
|
384 |
|
31
|
385 |
default: |
|
386 |
break; |
|
387 |
} |
|
388 |
previous_state = state; |
|
389 |
} |
|
390 |
|
|
391 |
void packethandler(jconn conn, jpacket packet) |
|
392 |
{ |
|
393 |
char *p; |
37
|
394 |
xmlnode x, y; |
31
|
395 |
// string from, type, body, enc, ns, id, u, h, s; |
|
396 |
char *from=NULL, *type=NULL, *body=NULL, *enc=NULL; |
|
397 |
char *ns=NULL; |
|
398 |
char *id=NULL; |
35
|
399 |
enum imstatus ust; |
31
|
400 |
// int npos; |
|
401 |
// bool isagent; |
|
402 |
|
|
403 |
jpacket_reset(packet); |
|
404 |
|
|
405 |
p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p; |
|
406 |
p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p; |
|
407 |
|
|
408 |
switch (packet->type) { |
|
409 |
case JPACKET_MESSAGE: |
|
410 |
x = xmlnode_get_tag(packet->x, "body"); |
|
411 |
p = xmlnode_get_data(x); if (p) body = p; |
|
412 |
|
|
413 |
if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL) |
|
414 |
if ((p = xmlnode_get_data(x)) != NULL) { |
|
415 |
char *tmp = malloc(strlen(body)+strlen(p)+3); |
43
|
416 |
*tmp = '['; |
|
417 |
strcpy(tmp+1, p); |
|
418 |
strcat(tmp, "]\n"); |
31
|
419 |
strcat(tmp, body); |
37
|
420 |
body = tmp; // XXX we should free it later... |
31
|
421 |
} |
|
422 |
|
|
423 |
/* there can be multiple <x> tags. we're looking for one with |
|
424 |
xmlns = jabber:x:encrypted */ |
|
425 |
|
|
426 |
for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) { |
|
427 |
if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) |
37
|
428 |
if ((p = xmlnode_get_attrib(x, "xmlns")) && |
|
429 |
!strcasecmp(p, "jabber:x:encrypted")) |
31
|
430 |
if ((p = xmlnode_get_data(x)) != NULL) { |
|
431 |
enc = p; |
|
432 |
break; |
|
433 |
} |
|
434 |
} |
|
435 |
|
|
436 |
if (body) { |
|
437 |
gotmessage(type, from, body, enc); |
|
438 |
} |
|
439 |
break; |
|
440 |
|
|
441 |
case JPACKET_IQ: |
|
442 |
if (!strcmp(type, "result")) { |
|
443 |
|
|
444 |
if (p = xmlnode_get_attrib(packet->x, "id")) { |
|
445 |
int iid = atoi(p); |
|
446 |
|
|
447 |
ut_WriteLog("iid = %d\n", iid); |
|
448 |
if (iid == s_id) { |
|
449 |
if (!regmode) { |
|
450 |
if (jstate == STATE_GETAUTH) { |
|
451 |
if (x = xmlnode_get_tag(packet->x, "query")) |
|
452 |
if (!xmlnode_get_tag(x, "digest")) { |
|
453 |
jc->sid = 0; |
|
454 |
} |
|
455 |
|
|
456 |
s_id = atoi(jab_auth(jc)); |
|
457 |
jstate = STATE_SENDAUTH; |
|
458 |
} else { |
|
459 |
gotloggedin(); |
|
460 |
jstate = STATE_LOGGED; |
|
461 |
} |
|
462 |
} else { |
|
463 |
regdone = TRUE; |
|
464 |
} |
|
465 |
return; |
|
466 |
} |
|
467 |
|
|
468 |
if (!strcmp(p, "VCARDreq")) { |
|
469 |
x = xmlnode_get_firstchild(packet->x); |
|
470 |
if (!x) x = packet->x; |
|
471 |
|
|
472 |
//jhook.gotvcard(ic, x); TODO |
|
473 |
scr_LogPrint("Got VCARD"); |
|
474 |
return; |
|
475 |
} else if (!strcmp(p, "versionreq")) { |
|
476 |
// jhook.gotversion(ic, packet->x); TODO |
|
477 |
scr_LogPrint("Got version"); |
|
478 |
return; |
|
479 |
} |
|
480 |
} |
|
481 |
|
|
482 |
if (x = xmlnode_get_tag(packet->x, "query")) { |
|
483 |
p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p; |
|
484 |
|
|
485 |
if (!strcmp(ns, NS_ROSTER)) { |
|
486 |
gotroster(x); |
|
487 |
} else if (!strcmp(ns, NS_AGENTS)) { |
|
488 |
for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) { |
|
489 |
const char *alias = xmlnode_get_attrib(y, "jid"); |
|
490 |
|
|
491 |
if (alias) { |
|
492 |
const char *name = xmlnode_get_tag_data(y, "name"); |
|
493 |
const char *desc = xmlnode_get_tag_data(y, "description"); |
|
494 |
const char *service = xmlnode_get_tag_data(y, "service"); |
37
|
495 |
enum agtype atype = unknown; |
31
|
496 |
|
37
|
497 |
if (xmlnode_get_tag(y, "groupchat")) atype = groupchat; else |
|
498 |
if (xmlnode_get_tag(y, "transport")) atype = transport; else |
|
499 |
if (xmlnode_get_tag(y, "search")) atype = search; |
31
|
500 |
|
|
501 |
if (alias && name && desc) { |
37
|
502 |
scr_LogPrint("Agent: %s / %s / %s / type=%d", |
|
503 |
alias, name, desc, atype); |
31
|
504 |
|
37
|
505 |
if (atype == search) { |
31
|
506 |
x = jutil_iqnew (JPACKET__GET, NS_SEARCH); |
|
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 |
if (xmlnode_get_tag(y, "register")) { |
|
514 |
x = jutil_iqnew (JPACKET__GET, NS_REGISTER); |
|
515 |
xmlnode_put_attrib(x, "to", alias); |
|
516 |
xmlnode_put_attrib(x, "id", "Agent info"); |
|
517 |
jab_send(conn, x); |
|
518 |
xmlnode_free(x); |
|
519 |
} |
|
520 |
} |
|
521 |
} |
|
522 |
} |
|
523 |
|
37
|
524 |
/* |
31
|
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 |
if (!strcmp(ns, "away")) ust = away; |
|
609 |
else if (!strcmp(ns, "dnd")) ust = dontdisturb; |
|
610 |
else if (!strcmp(ns, "xa")) ust = notavail; |
|
611 |
else if (!strcmp(ns, "chat")) ust = freeforchat; |
31
|
612 |
} |
|
613 |
} |
|
614 |
|
35
|
615 |
if (type && !strcmp(type, "unavailable")) { |
|
616 |
ust = offline; |
31
|
617 |
} |
41
|
618 |
//scr_LogPrint("New status: ust=%d (%s)", ust, from); |
31
|
619 |
|
35
|
620 |
bud_SetBuddyStatus(jidtodisp(from), ust); |
31
|
621 |
/* |
35
|
622 |
if (x = xmlnode_get_tag(packet->x, "status")) |
|
623 |
if (p = xmlnode_get_data(x)) |
|
624 |
scr_LogPrint("Away msg: %s", p); |
31
|
625 |
*/ |
|
626 |
break; |
|
627 |
|
|
628 |
case JPACKET_S10N: |
|
629 |
scr_LogPrint("Received subscription packet"); |
43
|
630 |
if (type) scr_LogPrint("Type=%s", type); |
31
|
631 |
|
43
|
632 |
if (!strcmp(type, "subscribe")) { |
|
633 |
// if (!isagent) { |
|
634 |
scr_LogPrint("<%s> wants to subscribe " |
|
635 |
"to your network presence updates", from); |
|
636 |
/*} else { |
31
|
637 |
auto_ptr<char> cfrom(strdup(from.c_str())); |
|
638 |
x = jutil_presnew(JPACKET__SUBSCRIBED, cfrom.get(), 0); |
|
639 |
jab_send(jc, x); |
|
640 |
xmlnode_free(x); |
43
|
641 |
}*/ |
|
642 |
} else if (!strcmp(type, "unsubscribe")) { |
|
643 |
x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0); |
31
|
644 |
jab_send(jc, x); |
|
645 |
xmlnode_free(x); |
43
|
646 |
scr_LogPrint("<%s> has unsubscribed to your presence updates", from); |
31
|
647 |
} |
|
648 |
break; |
|
649 |
|
|
650 |
default: |
|
651 |
break; |
|
652 |
} |
|
653 |
} |
|
654 |
|