author | Mikael Berthe <mikael@lilotux.net> |
Sun, 25 Sep 2005 00:33:56 +0200 | |
changeset 444 | 5927c3bfba13 |
parent 441 | 51b8f10cfeb8 |
child 447 | 03bb57383cea |
permissions | -rw-r--r-- |
29 | 1 |
/* |
2 |
* jabglue.c -- Jabber protocol handling |
|
393 | 3 |
* |
29 | 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 |
||
237 | 24 |
#define _GNU_SOURCE /* We need glibc for strptime */ |
29 | 25 |
#include "../libjabber/jabber.h" |
26 |
#include "jabglue.h" |
|
81 | 27 |
#include "roster.h" |
29 | 28 |
#include "screen.h" |
113 | 29 |
#include "hooks.h" |
29 | 30 |
#include "utils.h" |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
31 |
#include "settings.h" |
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
32 |
#include "hbuf.h" |
29 | 33 |
|
34 |
#define JABBERPORT 5222 |
|
35 |
#define JABBERSSLPORT 5223 |
|
36 |
||
194 | 37 |
#define JABBER_AGENT_GROUP "Jabber Agents" |
38 |
||
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
39 |
#define to_utf8(s) ((s) ? g_locale_to_utf8((s), -1, NULL,NULL,NULL) : NULL) |
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
40 |
#define from_utf8(s) ((s) ? g_locale_from_utf8((s), -1, NULL,NULL,NULL) : NULL) |
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
41 |
|
29 | 42 |
jconn jc; |
311
1d6b16d9c577
Make some global variables static
Mikael Berthe <mikael@lilotux.net>
parents:
300
diff
changeset
|
43 |
static time_t LastPingTime; |
1d6b16d9c577
Make some global variables static
Mikael Berthe <mikael@lilotux.net>
parents:
300
diff
changeset
|
44 |
static unsigned int KeepaliveDelay; |
272 | 45 |
static unsigned int prio; |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
46 |
static int s_id; |
31 | 47 |
static int regmode, regdone; |
116 | 48 |
static enum imstatus mystatus = offline; |
112 | 49 |
unsigned char online; |
29 | 50 |
|
353
3fe43f6daa5a
Make imstatus2char a null-terminated string
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
51 |
char imstatus2char[imstatus_size+1] = { |
3fe43f6daa5a
Make imstatus2char a null-terminated string
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
52 |
'_', 'o', 'i', 'f', 'd', 'n', 'a', '\0' |
46 | 53 |
}; |
54 |
||
31 | 55 |
static enum { |
29 | 56 |
STATE_CONNECTING, |
57 |
STATE_GETAUTH, |
|
58 |
STATE_SENDAUTH, |
|
59 |
STATE_LOGGED |
|
60 |
} jstate; |
|
61 |
||
62 |
||
31 | 63 |
void statehandler(jconn, int); |
64 |
void packethandler(jconn, jpacket); |
|
65 |
||
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
66 |
static void logger(jconn j, int io, const char *buf) |
31 | 67 |
{ |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
68 |
scr_LogPrint(LPRINT_DEBUG, "%03s: %s", ((io == 0) ? "OUT" : "IN"), buf); |
31 | 69 |
} |
70 |
||
113 | 71 |
/* |
29 | 72 |
static void jidsplit(const char *jid, char **user, char **host, |
73 |
char **res) |
|
74 |
{ |
|
75 |
char *tmp, *ptr; |
|
76 |
tmp = strdup(jid); |
|
77 |
||
78 |
if ((ptr = strchr(tmp, '/')) != NULL) { |
|
79 |
*res = strdup(ptr+1); |
|
80 |
*ptr = 0; |
|
81 |
} else |
|
82 |
*res = NULL; |
|
83 |
||
84 |
if ((ptr = strchr(tmp, '@')) != NULL) { |
|
85 |
*host = strdup(ptr+1); |
|
86 |
*ptr = 0; |
|
87 |
} else |
|
88 |
*host = NULL; |
|
89 |
||
90 |
*user = strdup(tmp); |
|
91 |
free(tmp); |
|
92 |
} |
|
113 | 93 |
*/ |
29 | 94 |
|
192 | 95 |
// jidtodisp(jid) |
96 |
// Strips the resource part from the jid |
|
97 |
// The caller should g_free the result after use. |
|
29 | 98 |
char *jidtodisp(const char *jid) |
99 |
{ |
|
100 |
char *ptr; |
|
165 | 101 |
char *alias; |
102 |
||
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
103 |
alias = g_strdup(jid); |
165 | 104 |
|
29 | 105 |
if ((ptr = strchr(alias, '/')) != NULL) { |
106 |
*ptr = 0; |
|
107 |
} |
|
108 |
return alias; |
|
109 |
} |
|
110 |
||
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
111 |
char *compose_jid(const char *username, const char *servername, |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
112 |
const char *resource) |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
113 |
{ |
393 | 114 |
char *jid = g_new(char, 3 + |
115 |
strlen(username) + strlen(servername) + strlen(resource)); |
|
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
116 |
strcpy(jid, username); |
403
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
117 |
if (!strchr(jid, '@')) { |
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
118 |
strcat(jid, "@"); |
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
119 |
strcat(jid, servername); |
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
120 |
} |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
121 |
strcat(jid, "/"); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
122 |
strcat(jid, resource); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
123 |
return jid; |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
124 |
} |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
125 |
|
403
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
126 |
jconn jb_connect(const char *jid, const char *server, unsigned int port, |
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
127 |
int ssl, const char *pass) |
29 | 128 |
{ |
129 |
if (!port) { |
|
130 |
if (ssl) |
|
131 |
port = JABBERSSLPORT; |
|
132 |
else |
|
133 |
port = JABBERPORT; |
|
134 |
} |
|
135 |
||
357
e8adc3c96e68
Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents:
353
diff
changeset
|
136 |
jb_disconnect(); |
29 | 137 |
|
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
138 |
s_id = 1; |
403
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
139 |
jc = jab_new((char*)jid, (char*)pass, (char*)server, port, ssl); |
29 | 140 |
|
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
141 |
/* These 3 functions can deal with a NULL jc, no worry... */ |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
142 |
jab_logger(jc, logger); |
29 | 143 |
jab_packet_handler(jc, &packethandler); |
144 |
jab_state_handler(jc, &statehandler); |
|
145 |
||
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
146 |
if (jc && jc->user) { |
112 | 147 |
online = TRUE; |
29 | 148 |
jstate = STATE_CONNECTING; |
149 |
statehandler(0, -1); |
|
150 |
jab_start(jc); |
|
151 |
} |
|
152 |
||
153 |
return jc; |
|
154 |
} |
|
155 |
||
156 |
void jb_disconnect(void) |
|
157 |
{ |
|
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
158 |
if (!jc) return; |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
159 |
|
416
48e7808c4191
Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents:
411
diff
changeset
|
160 |
// announce it to everyone else |
444 | 161 |
jb_setstatus(offline, NULL, ""); |
416
48e7808c4191
Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents:
411
diff
changeset
|
162 |
|
48e7808c4191
Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents:
411
diff
changeset
|
163 |
// announce it to the user |
29 | 164 |
statehandler(jc, JCONN_STATE_OFF); |
416
48e7808c4191
Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents:
411
diff
changeset
|
165 |
|
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
166 |
jab_delete(jc); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
167 |
//free(jc); XXX |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
168 |
jc = NULL; |
29 | 169 |
} |
170 |
||
112 | 171 |
inline void jb_reset_keepalive() |
172 |
{ |
|
173 |
time(&LastPingTime); |
|
174 |
} |
|
175 |
||
436 | 176 |
void jb_send_raw(const char *str) |
177 |
{ |
|
178 |
if (jc && online) |
|
179 |
jab_send_raw(jc, str); |
|
180 |
} |
|
181 |
||
29 | 182 |
void jb_keepalive() |
183 |
{ |
|
113 | 184 |
if (jc && online) |
112 | 185 |
jab_send_raw(jc, " \t "); |
186 |
jb_reset_keepalive(); |
|
187 |
} |
|
188 |
||
189 |
void jb_set_keepalive_delay(unsigned int delay) |
|
190 |
{ |
|
191 |
KeepaliveDelay = delay; |
|
29 | 192 |
} |
193 |
||
272 | 194 |
inline void jb_set_priority(unsigned int priority) |
195 |
{ |
|
196 |
prio = priority; |
|
197 |
} |
|
198 |
||
29 | 199 |
void jb_main() |
200 |
{ |
|
201 |
xmlnode x, z; |
|
202 |
char *cid; |
|
203 |
||
406 | 204 |
if (!online) { |
419 | 205 |
safe_usleep(10000); |
406 | 206 |
return; |
207 |
} |
|
164 | 208 |
|
29 | 209 |
if (jc && jc->state == JCONN_STATE_CONNECTING) { |
419 | 210 |
safe_usleep(75000); |
29 | 211 |
jab_start(jc); |
212 |
return; |
|
213 |
} |
|
214 |
||
31 | 215 |
jab_poll(jc, 50); |
29 | 216 |
|
217 |
if (jstate == STATE_CONNECTING) { |
|
218 |
if (jc) { |
|
219 |
x = jutil_iqnew(JPACKET__GET, NS_AUTH); |
|
220 |
cid = jab_getid(jc); |
|
221 |
xmlnode_put_attrib(x, "id", cid); |
|
222 |
// id = atoi(cid); |
|
223 |
||
224 |
z = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "username"); |
|
225 |
xmlnode_insert_cdata(z, jc->user->user, (unsigned) -1); |
|
226 |
jab_send(jc, x); |
|
227 |
xmlnode_free(x); |
|
228 |
||
229 |
jstate = STATE_GETAUTH; |
|
230 |
} |
|
231 |
||
232 |
if (!jc || jc->state == JCONN_STATE_OFF) { |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
233 |
scr_LogPrint(LPRINT_LOGNORM, "Unable to connect to the server"); |
112 | 234 |
online = FALSE; |
29 | 235 |
} |
236 |
} |
|
237 |
||
238 |
if (!jc) { |
|
239 |
statehandler(jc, JCONN_STATE_OFF); |
|
240 |
} else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) { |
|
241 |
statehandler(jc, JCONN_STATE_OFF); |
|
242 |
} |
|
112 | 243 |
|
244 |
// Keepalive |
|
245 |
if (KeepaliveDelay) { |
|
246 |
time_t now; |
|
247 |
time(&now); |
|
248 |
if (now > LastPingTime + KeepaliveDelay) |
|
249 |
jb_keepalive(); |
|
250 |
} |
|
29 | 251 |
} |
252 |
||
116 | 253 |
inline enum imstatus jb_getstatus() |
254 |
{ |
|
255 |
return mystatus; |
|
256 |
} |
|
257 |
||
444 | 258 |
void jb_setstatus(enum imstatus st, const char *recipient, const char *msg) |
29 | 259 |
{ |
116 | 260 |
xmlnode x; |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
261 |
gchar *utf8_msg; |
116 | 262 |
|
164 | 263 |
if (!online) return; |
116 | 264 |
|
265 |
x = jutil_presnew(JPACKET__UNKNOWN, 0, 0); |
|
29 | 266 |
|
444 | 267 |
if (recipient) |
268 |
xmlnode_put_attrib(x, "to", recipient); |
|
269 |
||
29 | 270 |
switch(st) { |
271 |
case away: |
|
272 |
xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "away", |
|
273 |
(unsigned) -1); |
|
274 |
break; |
|
275 |
||
276 |
case dontdisturb: |
|
277 |
xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "dnd", |
|
278 |
(unsigned) -1); |
|
279 |
break; |
|
280 |
||
281 |
case freeforchat: |
|
282 |
xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "chat", |
|
283 |
(unsigned) -1); |
|
284 |
break; |
|
285 |
||
286 |
case notavail: |
|
287 |
xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "xa", |
|
288 |
(unsigned) -1); |
|
289 |
break; |
|
290 |
||
291 |
case invisible: |
|
292 |
xmlnode_put_attrib(x, "type", "invisible"); |
|
293 |
break; |
|
51 | 294 |
|
118 | 295 |
case offline: |
296 |
xmlnode_put_attrib(x, "type", "unavailable"); |
|
297 |
break; |
|
298 |
||
51 | 299 |
default: |
300 |
break; |
|
29 | 301 |
} |
302 |
||
272 | 303 |
if (prio) { |
304 |
char strprio[8]; |
|
305 |
snprintf(strprio, 8, "%u", prio); |
|
29 | 306 |
xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"), |
272 | 307 |
strprio, (unsigned) -1); |
308 |
} |
|
29 | 309 |
|
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
310 |
if (!msg) |
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
311 |
msg = settings_get_status_msg(st); |
29 | 312 |
|
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
313 |
utf8_msg = to_utf8(msg); |
321
59193965f2cb
Convert status messages to/from UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
319
diff
changeset
|
314 |
xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), utf8_msg, |
29 | 315 |
(unsigned) -1); |
316 |
||
317 |
jab_send(jc, x); |
|
318 |
xmlnode_free(x); |
|
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
319 |
g_free(utf8_msg); |
29 | 320 |
|
444 | 321 |
// If we didn't change our _global_ status, we are done |
322 |
if (recipient) return; |
|
323 |
||
324 |
// Buddy per buddy invisibility handling |
|
325 |
//sendvisibility(); |
|
29 | 326 |
|
164 | 327 |
// We'll need to update the roster if we switch to/from offline because |
328 |
// we don't know the presences of buddies when offline... |
|
329 |
if (mystatus == offline || st == offline) |
|
330 |
update_roster = TRUE; |
|
331 |
||
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
311
diff
changeset
|
332 |
hk_mystatuschange(0, mystatus, st, msg); |
116 | 333 |
mystatus = st; |
29 | 334 |
} |
335 |
||
35 | 336 |
void jb_send_msg(const char *jid, const char *text) |
337 |
{ |
|
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
338 |
gchar *buffer = to_utf8(text); |
213 | 339 |
xmlnode x = jutil_msgnew(TMSG_CHAT, (char*)jid, 0, (char*)buffer); |
35 | 340 |
jab_send(jc, x); |
341 |
xmlnode_free(x); |
|
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
342 |
g_free(buffer); |
114 | 343 |
jb_reset_keepalive(); |
35 | 344 |
} |
345 |
||
213 | 346 |
// Note: the caller should check the jid is correct |
244 | 347 |
void jb_addbuddy(const char *jid, const char *name, const char *group) |
124 | 348 |
{ |
349 |
xmlnode x, y, z; |
|
192 | 350 |
char *cleanjid; |
124 | 351 |
|
208 | 352 |
if (!online) return; |
124 | 353 |
|
354 |
// We don't check if the jabber user already exists in the roster, |
|
355 |
// because it allows to re-ask for notification. |
|
356 |
||
357 |
//x = jutil_presnew(JPACKET__SUBSCRIBE, jid, NULL); |
|
125 | 358 |
x = jutil_presnew(JPACKET__SUBSCRIBE, (char*)jid, "online"); |
124 | 359 |
jab_send(jc, x); |
360 |
xmlnode_free(x); |
|
361 |
||
362 |
x = jutil_iqnew(JPACKET__SET, NS_ROSTER); |
|
363 |
y = xmlnode_get_tag(x, "query"); |
|
364 |
z = xmlnode_insert_tag(y, "item"); |
|
365 |
xmlnode_put_attrib(z, "jid", jid); |
|
366 |
||
244 | 367 |
if (name) { |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
368 |
gchar *name_utf8 = to_utf8(name); |
244 | 369 |
z = xmlnode_insert_tag(z, "name"); |
370 |
xmlnode_insert_cdata(z, name_utf8, (unsigned) -1); |
|
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
371 |
g_free(name_utf8); |
244 | 372 |
} |
373 |
||
124 | 374 |
if (group) { |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
375 |
char *group_utf8 = to_utf8(group); |
124 | 376 |
z = xmlnode_insert_tag(z, "group"); |
213 | 377 |
xmlnode_insert_cdata(z, group_utf8, (unsigned) -1); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
378 |
g_free(group_utf8); |
124 | 379 |
} |
380 |
||
381 |
jab_send(jc, x); |
|
382 |
xmlnode_free(x); |
|
383 |
||
192 | 384 |
cleanjid = jidtodisp(jid); |
244 | 385 |
roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER); |
192 | 386 |
g_free(cleanjid); |
124 | 387 |
buddylist_build(); |
388 |
||
244 | 389 |
update_roster = TRUE; |
124 | 390 |
} |
391 |
||
205 | 392 |
void jb_delbuddy(const char *jid) |
393 |
{ |
|
394 |
xmlnode x, y, z; |
|
395 |
char *cleanjid; |
|
396 |
||
397 |
if (!online) return; |
|
398 |
||
399 |
cleanjid = jidtodisp(jid); |
|
400 |
||
401 |
// If the current buddy is an agent, unsubscribe from it |
|
402 |
if (roster_gettype(cleanjid) == ROSTER_TYPE_AGENT) { |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
403 |
scr_LogPrint(LPRINT_LOGNORM, "Unregistering from the %s agent", cleanjid); |
205 | 404 |
|
405 |
x = jutil_iqnew(JPACKET__SET, NS_REGISTER); |
|
406 |
xmlnode_put_attrib(x, "to", cleanjid); |
|
407 |
y = xmlnode_get_tag(x, "query"); |
|
408 |
xmlnode_insert_tag(y, "remove"); |
|
409 |
jab_send(jc, x); |
|
410 |
xmlnode_free(x); |
|
411 |
} |
|
412 |
||
413 |
// Unsubscribe this buddy from our presence notification |
|
414 |
x = jutil_presnew(JPACKET__UNSUBSCRIBE, cleanjid, 0); |
|
415 |
jab_send(jc, x); |
|
416 |
xmlnode_free(x); |
|
417 |
||
418 |
// Ask for removal from roster |
|
419 |
x = jutil_iqnew(JPACKET__SET, NS_ROSTER); |
|
420 |
y = xmlnode_get_tag(x, "query"); |
|
421 |
z = xmlnode_insert_tag(y, "item"); |
|
422 |
xmlnode_put_attrib(z, "jid", cleanjid); |
|
423 |
xmlnode_put_attrib(z, "subscription", "remove"); |
|
424 |
jab_send(jc, x); |
|
425 |
xmlnode_free(x); |
|
426 |
||
427 |
roster_del_user(cleanjid); |
|
428 |
g_free(cleanjid); |
|
429 |
buddylist_build(); |
|
430 |
||
431 |
update_roster = TRUE; |
|
432 |
} |
|
433 |
||
208 | 434 |
void jb_updatebuddy(const char *jid, const char *name, const char *group) |
435 |
{ |
|
436 |
xmlnode x, y; |
|
437 |
char *cleanjid; |
|
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
438 |
gchar *name_utf8; |
208 | 439 |
|
440 |
if (!online) return; |
|
441 |
||
442 |
// XXX We should check name's and group's correctness |
|
443 |
||
444 |
cleanjid = jidtodisp(jid); |
|
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
445 |
name_utf8 = to_utf8(name); |
208 | 446 |
|
447 |
x = jutil_iqnew(JPACKET__SET, NS_ROSTER); |
|
448 |
y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); |
|
449 |
xmlnode_put_attrib(y, "jid", cleanjid); |
|
213 | 450 |
xmlnode_put_attrib(y, "name", name_utf8); |
208 | 451 |
|
452 |
if (group) { |
|
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
453 |
gchar *group_utf8 = to_utf8(group); |
208 | 454 |
y = xmlnode_insert_tag(y, "group"); |
213 | 455 |
xmlnode_insert_cdata(y, group_utf8, (unsigned) -1); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
456 |
g_free(group_utf8); |
208 | 457 |
} |
458 |
||
459 |
jab_send(jc, x); |
|
460 |
xmlnode_free(x); |
|
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
461 |
g_free(name_utf8); |
208 | 462 |
g_free(cleanjid); |
463 |
} |
|
464 |
||
31 | 465 |
void postlogin() |
466 |
{ |
|
467 |
//int i; |
|
468 |
||
469 |
//flogged = TRUE; |
|
470 |
//ourstatus = available; |
|
471 |
||
472 |
//setautostatus(jhook.manualstatus); |
|
473 |
||
444 | 474 |
jb_setstatus(available, NULL, NULL); |
81 | 475 |
buddylist_build(); |
31 | 476 |
/* |
477 |
for (i = 0; i < clist.count; i++) { |
|
478 |
c = (icqcontact *) clist.at(i); |
|
479 |
||
480 |
if (c->getdesc().pname == proto) |
|
481 |
if (ischannel(c)) |
|
482 |
if (c->getbasicinfo().requiresauth) |
|
483 |
c->setstatus(available); |
|
484 |
} |
|
485 |
*/ |
|
486 |
||
487 |
/* |
|
488 |
agents.insert(agents.begin(), agent("vcard", "Jabber VCard", "", agent::atStandard)); |
|
489 |
agents.begin()->params[agent::ptRegister].enabled = TRUE; |
|
490 |
||
491 |
string buf; |
|
492 |
ifstream f(conf.getconfigfname("jabber-infoset").c_str()); |
|
493 |
||
494 |
if (f.is_open()) { |
|
495 |
icqcontact *c = clist.get(contactroot); |
|
496 |
||
497 |
c->clear(); |
|
498 |
icqcontact::basicinfo bi = c->getbasicinfo(); |
|
499 |
icqcontact::reginfo ri = c->getreginfo(); |
|
500 |
||
501 |
ri.service = agents.begin()->name; |
|
502 |
getstring(f, buf); c->setnick(buf); |
|
503 |
getstring(f, buf); bi.email = buf; |
|
504 |
getstring(f, buf); bi.fname = buf; |
|
505 |
getstring(f, buf); bi.lname = buf; |
|
506 |
f.close(); |
|
507 |
||
508 |
c->setbasicinfo(bi); |
|
509 |
c->setreginfo(ri); |
|
510 |
||
511 |
sendupdateuserinfo(*c); |
|
512 |
unlink(conf.getconfigfname("jabber-infoset").c_str()); |
|
513 |
} |
|
514 |
*/ |
|
515 |
} |
|
516 |
||
29 | 517 |
void gotloggedin(void) |
518 |
{ |
|
519 |
xmlnode x; |
|
520 |
||
521 |
x = jutil_iqnew(JPACKET__GET, NS_AGENTS); |
|
522 |
xmlnode_put_attrib(x, "id", "Agent List"); |
|
523 |
jab_send(jc, x); |
|
524 |
xmlnode_free(x); |
|
525 |
||
526 |
x = jutil_iqnew(JPACKET__GET, NS_ROSTER); |
|
527 |
xmlnode_put_attrib(x, "id", "Roster"); |
|
528 |
jab_send(jc, x); |
|
529 |
xmlnode_free(x); |
|
530 |
} |
|
531 |
||
532 |
void gotroster(xmlnode x) |
|
533 |
{ |
|
33 | 534 |
xmlnode y, z; |
29 | 535 |
|
536 |
for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) { |
|
537 |
const char *alias = xmlnode_get_attrib(y, "jid"); |
|
51 | 538 |
//const char *sub = xmlnode_get_attrib(y, "subscription"); // TODO Not used |
29 | 539 |
const char *name = xmlnode_get_attrib(y, "name"); |
213 | 540 |
char *group = NULL; |
29 | 541 |
|
33 | 542 |
z = xmlnode_get_tag(y, "group"); |
543 |
if (z) group = xmlnode_get_data(z); |
|
29 | 544 |
|
545 |
if (alias) { |
|
35 | 546 |
char *buddyname; |
192 | 547 |
char *cleanalias = jidtodisp(alias); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
548 |
gchar *name_noutf8 = NULL; |
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
549 |
gchar *group_noutf8 = NULL; |
213 | 550 |
|
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
551 |
buddyname = cleanalias; |
213 | 552 |
if (name) { |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
553 |
name_noutf8 = from_utf8(name); |
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
554 |
if (name_noutf8) buddyname = name_noutf8; |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
555 |
} |
35 | 556 |
|
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
557 |
if (group) |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
558 |
group_noutf8 = from_utf8(group); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
559 |
|
213 | 560 |
roster_add_user(cleanalias, buddyname, group_noutf8, ROSTER_TYPE_USER); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
561 |
if (name_noutf8) g_free(name_noutf8); |
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
562 |
if (group_noutf8) g_free(group_noutf8); |
192 | 563 |
g_free(cleanalias); |
29 | 564 |
} |
565 |
} |
|
566 |
||
567 |
postlogin(); |
|
568 |
} |
|
569 |
||
570 |
void gotmessage(char *type, const char *from, const char *body, |
|
223 | 571 |
const char *enc, time_t timestamp) |
29 | 572 |
{ |
113 | 573 |
char *jid; |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
574 |
gchar *buffer = from_utf8(body); |
29 | 575 |
|
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
576 |
jid = jidtodisp(from); |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
577 |
|
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
578 |
if (!buffer && body) { |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
579 |
scr_LogPrint(LPRINT_LOGNORM, "Decoding of message from <%s> has failed", |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
580 |
from); |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
581 |
scr_WriteIncomingMessage(jid, "Cannot display message: " |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
582 |
"UTF-8 conversion failure", |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
583 |
0, HBB_PREFIX_ERR | HBB_PREFIX_IN); |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
584 |
g_free(jid); |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
585 |
return; |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
586 |
} |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
587 |
|
35 | 588 |
/* |
113 | 589 |
//char *u, *h, *r; |
590 |
//jidsplit(from, &u, &h, &r); |
|
35 | 591 |
// Maybe we should remember the resource? |
592 |
if (r) |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
593 |
scr_LogPrint(LPRINT_NORMAL, |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
594 |
"There is an extra part in message (resource?): %s", r); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
595 |
//scr_LogPrint(LPRINT_NORMAL, "Msg from <%s>, type=%s", |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
596 |
// jidtodisp(from), type); |
35 | 597 |
*/ |
598 |
||
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
321
diff
changeset
|
599 |
hk_message_in(jid, timestamp, buffer, type); |
192 | 600 |
g_free(jid); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
601 |
g_free(buffer); |
29 | 602 |
} |
603 |
||
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
604 |
const char *defaulterrormsg(int code) |
420
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
605 |
{ |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
606 |
const char *desc; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
607 |
|
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
608 |
switch(code) { |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
609 |
case 401: desc = "Unauthorized"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
610 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
611 |
case 302: desc = "Redirect"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
612 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
613 |
case 400: desc = "Bad request"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
614 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
615 |
case 402: desc = "Payment Required"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
616 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
617 |
case 403: desc = "Forbidden"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
618 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
619 |
case 404: desc = "Not Found"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
620 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
621 |
case 405: desc = "Not Allowed"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
622 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
623 |
case 406: desc = "Not Acceptable"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
624 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
625 |
case 407: desc = "Registration Required"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
626 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
627 |
case 408: desc = "Request Timeout"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
628 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
629 |
case 409: desc = "Conflict"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
630 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
631 |
case 500: desc = "Internal Server Error"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
632 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
633 |
case 501: desc = "Not Implemented"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
634 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
635 |
case 502: desc = "Remote Server Error"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
636 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
637 |
case 503: desc = "Service Unavailable"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
638 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
639 |
case 504: desc = "Remote Server Timeout"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
640 |
break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
641 |
default: |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
642 |
desc = NULL; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
643 |
} |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
644 |
|
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
645 |
return desc; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
646 |
} |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
647 |
|
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
648 |
// display_server_error(x) |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
649 |
// Display the error to the user |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
650 |
// x: error tag xmlnode pointer |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
651 |
void display_server_error(xmlnode x) |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
652 |
{ |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
653 |
const char *desc = NULL; |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
654 |
int code = 0; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
655 |
char *s; |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
656 |
const char *p; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
657 |
|
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
658 |
/* RFC3920: |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
659 |
* The <error/> element: |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
660 |
* o MUST contain a child element corresponding to one of the defined |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
661 |
* stanza error conditions specified below; this element MUST be |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
662 |
* qualified by the 'urn:ietf:params:xml:ns:xmpp-stanzas' namespace. |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
663 |
*/ |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
664 |
p = xmlnode_get_name(xmlnode_get_firstchild(x)); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
665 |
if (p) |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
666 |
scr_LogPrint(LPRINT_LOGNORM, "Received error packet [%s]", p); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
667 |
|
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
668 |
// For backward compatibility |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
669 |
if ((s = xmlnode_get_attrib(x, "code")) != NULL) { |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
670 |
code = atoi(s); |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
671 |
// Default message |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
672 |
desc = defaulterrormsg(code); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
673 |
} |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
674 |
|
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
675 |
// Error tag data is better, if available |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
676 |
s = xmlnode_get_data(x); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
677 |
if (s && *s) desc = s; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
678 |
|
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
679 |
// And sometimes there is a text message |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
680 |
s = xmlnode_get_tag_data(x, "text"); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
681 |
if (s && *s) desc = s; // FIXME utf8?? |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
682 |
|
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
683 |
scr_LogPrint(LPRINT_LOGNORM, "Error code from server: %d %s", code, desc); |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
684 |
} |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
685 |
|
31 | 686 |
void statehandler(jconn conn, int state) |
687 |
{ |
|
688 |
static int previous_state = -1; |
|
689 |
||
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
690 |
scr_LogPrint(LPRINT_DEBUG, "StateHandler called (state=%d).", state); |
31 | 691 |
|
692 |
switch(state) { |
|
693 |
case JCONN_STATE_OFF: |
|
192 | 694 |
if (previous_state != JCONN_STATE_OFF) |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
695 |
scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Not connected to the server"); |
37 | 696 |
|
112 | 697 |
online = FALSE; |
159 | 698 |
mystatus = offline; |
164 | 699 |
roster_free(); |
700 |
update_roster = TRUE; |
|
31 | 701 |
break; |
702 |
||
703 |
case JCONN_STATE_CONNECTED: |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
704 |
scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connected to the server"); |
31 | 705 |
break; |
706 |
||
707 |
case JCONN_STATE_AUTH: |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
708 |
scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Authenticating to the server"); |
31 | 709 |
break; |
710 |
||
711 |
case JCONN_STATE_ON: |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
712 |
scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Communication with the server " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
713 |
"established"); |
112 | 714 |
online = TRUE; |
31 | 715 |
break; |
716 |
||
35 | 717 |
case JCONN_STATE_CONNECTING: |
357
e8adc3c96e68
Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents:
353
diff
changeset
|
718 |
if (previous_state != state) |
408
73433860665c
Tune previous usleep() change
Mikael Berthe <mikael@lilotux.net>
parents:
407
diff
changeset
|
719 |
scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connecting to the server"); |
35 | 720 |
break; |
721 |
||
31 | 722 |
default: |
723 |
break; |
|
724 |
} |
|
725 |
previous_state = state; |
|
726 |
} |
|
727 |
||
728 |
void packethandler(jconn conn, jpacket packet) |
|
729 |
{ |
|
91 | 730 |
char *p, *r; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
731 |
const char *m, *rname; |
37 | 732 |
xmlnode x, y; |
31 | 733 |
char *from=NULL, *type=NULL, *body=NULL, *enc=NULL; |
734 |
char *ns=NULL; |
|
735 |
char *id=NULL; |
|
35 | 736 |
enum imstatus ust; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
737 |
char bpprio; |
31 | 738 |
|
112 | 739 |
jb_reset_keepalive(); // reset keepalive delay |
31 | 740 |
jpacket_reset(packet); |
741 |
||
742 |
p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p; |
|
743 |
p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p; |
|
744 |
||
745 |
switch (packet->type) { |
|
746 |
case JPACKET_MESSAGE: |
|
52 | 747 |
{ |
748 |
char *tmp = NULL; |
|
223 | 749 |
time_t timestamp = 0; |
750 |
||
52 | 751 |
x = xmlnode_get_tag(packet->x, "body"); |
752 |
p = xmlnode_get_data(x); if (p) body = p; |
|
31 | 753 |
|
52 | 754 |
if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL) |
755 |
if ((p = xmlnode_get_data(x)) != NULL) { |
|
165 | 756 |
tmp = g_new(char, strlen(body)+strlen(p)+4); |
52 | 757 |
*tmp = '['; |
758 |
strcpy(tmp+1, p); |
|
759 |
strcat(tmp, "]\n"); |
|
760 |
strcat(tmp, body); |
|
761 |
body = tmp; |
|
762 |
} |
|
763 |
||
764 |
/* there can be multiple <x> tags. we're looking for one with |
|
765 |
xmlns = jabber:x:encrypted */ |
|
766 |
||
420
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
767 |
x = xmlnode_get_firstchild(packet->x); |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
768 |
for ( ; x; x = xmlnode_get_nextsibling(x)) { |
52 | 769 |
if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) |
770 |
if ((p = xmlnode_get_attrib(x, "xmlns")) && |
|
771 |
!strcasecmp(p, "jabber:x:encrypted")) |
|
772 |
if ((p = xmlnode_get_data(x)) != NULL) { |
|
773 |
enc = p; |
|
774 |
break; |
|
775 |
} |
|
31 | 776 |
} |
777 |
||
223 | 778 |
// Timestamp? |
779 |
if ((x = xmlnode_get_tag(packet->x, "x")) != NULL) { |
|
241 | 780 |
if ((p = xmlnode_get_attrib(x, "stamp")) != NULL) |
781 |
timestamp = from_iso8601(p, 1); |
|
223 | 782 |
} |
783 |
||
420
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
784 |
if (type && !strcmp(type, "error")) { |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
785 |
if ((x = xmlnode_get_tag(packet->x, "error")) != NULL) |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
786 |
display_server_error(x); |
420
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
787 |
} |
165 | 788 |
if (from && body) |
223 | 789 |
gotmessage(type, from, body, enc, timestamp); |
52 | 790 |
if (tmp) |
159 | 791 |
g_free(tmp); |
31 | 792 |
} |
793 |
break; |
|
794 |
||
795 |
case JPACKET_IQ: |
|
796 |
if (!strcmp(type, "result")) { |
|
797 |
||
51 | 798 |
if ((p = xmlnode_get_attrib(packet->x, "id")) != NULL) { |
31 | 799 |
int iid = atoi(p); |
800 |
||
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
801 |
scr_LogPrint(LPRINT_DEBUG, "iid = %d", iid); |
31 | 802 |
if (iid == s_id) { |
803 |
if (!regmode) { |
|
804 |
if (jstate == STATE_GETAUTH) { |
|
51 | 805 |
if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) |
31 | 806 |
if (!xmlnode_get_tag(x, "digest")) { |
807 |
jc->sid = 0; |
|
808 |
} |
|
809 |
||
810 |
s_id = atoi(jab_auth(jc)); |
|
811 |
jstate = STATE_SENDAUTH; |
|
812 |
} else { |
|
813 |
gotloggedin(); |
|
814 |
jstate = STATE_LOGGED; |
|
815 |
} |
|
816 |
} else { |
|
817 |
regdone = TRUE; |
|
818 |
} |
|
819 |
return; |
|
820 |
} |
|
821 |
||
822 |
if (!strcmp(p, "VCARDreq")) { |
|
823 |
x = xmlnode_get_firstchild(packet->x); |
|
824 |
if (!x) x = packet->x; |
|
825 |
||
826 |
//jhook.gotvcard(ic, x); TODO |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
827 |
scr_LogPrint(LPRINT_LOGNORM, "Got VCARD"); |
31 | 828 |
return; |
829 |
} else if (!strcmp(p, "versionreq")) { |
|
830 |
// jhook.gotversion(ic, packet->x); TODO |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
831 |
scr_LogPrint(LPRINT_LOGNORM, "Got version"); |
31 | 832 |
return; |
833 |
} |
|
834 |
} |
|
835 |
||
51 | 836 |
if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) { |
31 | 837 |
p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p; |
838 |
||
839 |
if (!strcmp(ns, NS_ROSTER)) { |
|
840 |
gotroster(x); |
|
841 |
} else if (!strcmp(ns, NS_AGENTS)) { |
|
842 |
for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) { |
|
843 |
const char *alias = xmlnode_get_attrib(y, "jid"); |
|
844 |
||
845 |
if (alias) { |
|
846 |
const char *name = xmlnode_get_tag_data(y, "name"); |
|
847 |
const char *desc = xmlnode_get_tag_data(y, "description"); |
|
51 | 848 |
// const char *service = xmlnode_get_tag_data(y, "service"); TODO |
37 | 849 |
enum agtype atype = unknown; |
31 | 850 |
|
37 | 851 |
if (xmlnode_get_tag(y, "groupchat")) atype = groupchat; else |
852 |
if (xmlnode_get_tag(y, "transport")) atype = transport; else |
|
853 |
if (xmlnode_get_tag(y, "search")) atype = search; |
|
31 | 854 |
|
192 | 855 |
if (atype == transport) { |
856 |
char *cleanjid = jidtodisp(alias); |
|
194 | 857 |
roster_add_user(cleanjid, NULL, JABBER_AGENT_GROUP, |
858 |
ROSTER_TYPE_AGENT); |
|
192 | 859 |
g_free(cleanjid); |
860 |
} |
|
31 | 861 |
if (alias && name && desc) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
862 |
scr_LogPrint(LPRINT_LOGNORM, "Agent: %s / %s / %s / type=%d", |
37 | 863 |
alias, name, desc, atype); |
31 | 864 |
|
37 | 865 |
if (atype == search) { |
31 | 866 |
x = jutil_iqnew (JPACKET__GET, NS_SEARCH); |
867 |
xmlnode_put_attrib(x, "to", alias); |
|
868 |
xmlnode_put_attrib(x, "id", "Agent info"); |
|
869 |
jab_send(conn, x); |
|
870 |
xmlnode_free(x); |
|
871 |
} |
|
872 |
||
873 |
if (xmlnode_get_tag(y, "register")) { |
|
874 |
x = jutil_iqnew (JPACKET__GET, NS_REGISTER); |
|
875 |
xmlnode_put_attrib(x, "to", alias); |
|
876 |
xmlnode_put_attrib(x, "id", "Agent info"); |
|
877 |
jab_send(conn, x); |
|
878 |
xmlnode_free(x); |
|
879 |
} |
|
880 |
} |
|
881 |
} |
|
882 |
} |
|
883 |
||
37 | 884 |
/* |
31 | 885 |
if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end()) |
886 |
jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV, |
|
887 |
_("Default Jabber conference server"), agent::atGroupchat)); |
|
888 |
||
889 |
*/ |
|
890 |
} else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) { |
|
891 |
p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)""; |
|
892 |
||
893 |
if (!strcmp(id, "Agent info")) { |
|
894 |
// jhook.gotagentinfo(packet->x); TODO |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
895 |
scr_LogPrint(LPRINT_LOGNORM, "Got agent info"); |
31 | 896 |
} else if (!strcmp(id, "Lookup")) { |
897 |
// jhook.gotsearchresults(packet->x); TODO |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
898 |
scr_LogPrint(LPRINT_LOGNORM, "Got search results"); |
31 | 899 |
} else if (!strcmp(id, "Register")) { |
900 |
x = jutil_iqnew(JPACKET__GET, NS_REGISTER); |
|
901 |
xmlnode_put_attrib(x, "to", from); |
|
902 |
xmlnode_put_attrib(x, "id", "Agent info"); |
|
903 |
jab_send(conn, x); |
|
904 |
xmlnode_free(x); |
|
905 |
} |
|
906 |
||
907 |
} |
|
908 |
} |
|
909 |
} else if (!strcmp(type, "set")) { |
|
910 |
} else if (!strcmp(type, "error")) { |
|
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
911 |
if ((x = xmlnode_get_tag(packet->x, "error")) != NULL) |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
912 |
display_server_error(x); |
31 | 913 |
} |
914 |
break; |
|
915 |
||
916 |
case JPACKET_PRESENCE: |
|
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
917 |
r = jidtodisp(from); |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
918 |
if (type && !strcmp(type, "error")) { |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
919 |
scr_LogPrint(LPRINT_LOGNORM, "Error presence packet from <%s>", r); |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
920 |
if ((x = xmlnode_get_tag(packet->x, "error")) != NULL) |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
921 |
display_server_error(x); |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
922 |
g_free(r); |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
923 |
break; |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
924 |
} |
31 | 925 |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
926 |
p = xmlnode_get_tag_data(packet->x, "priority"); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
927 |
if (p && *p) bpprio = (gchar)atoi(p); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
928 |
else bpprio = 0; |
31 | 929 |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
930 |
ust = available; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
931 |
p = xmlnode_get_tag_data(packet->x, "show"); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
932 |
if (p) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
933 |
if (!strcmp(p, "away")) ust = away; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
934 |
else if (!strcmp(p, "dnd")) ust = dontdisturb; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
935 |
else if (!strcmp(p, "xa")) ust = notavail; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
936 |
else if (!strcmp(p, "chat")) ust = freeforchat; |
31 | 937 |
} |
938 |
||
321
59193965f2cb
Convert status messages to/from UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
319
diff
changeset
|
939 |
if (type && !strcmp(type, "unavailable")) |
35 | 940 |
ust = offline; |
31 | 941 |
|
221 | 942 |
if ((x = xmlnode_get_tag(packet->x, "status")) != NULL) |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
943 |
p = from_utf8(xmlnode_get_data(x)); |
221 | 944 |
else |
945 |
p = NULL; |
|
946 |
||
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
311
diff
changeset
|
947 |
// Call hk_statuschange() if status has changed or if the |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
311
diff
changeset
|
948 |
// status message is different |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
949 |
rname = strchr(from, '/'); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
950 |
if (rname) rname++; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
951 |
m = roster_getstatusmsg(r, rname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
952 |
if ((ust != roster_getstatus(r, rname)) || (p && (!m || strcmp(p, m)))) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
953 |
hk_statuschange(r, rname, bpprio, 0, ust, p); |
159 | 954 |
g_free(r); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
955 |
if (p) g_free(p); |
31 | 956 |
break; |
957 |
||
958 |
case JPACKET_S10N: |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
959 |
scr_LogPrint(LPRINT_LOGNORM, "Received (un)subscription packet " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
960 |
"(type=%s)", ((type) ? type : "")); |
31 | 961 |
|
43 | 962 |
if (!strcmp(type, "subscribe")) { |
91 | 963 |
int isagent; |
964 |
r = jidtodisp(from); |
|
965 |
isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0; |
|
159 | 966 |
g_free(r); |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
967 |
scr_LogPrint(LPRINT_LOGNORM, "isagent=%d", isagent); // XXX DBG |
91 | 968 |
if (!isagent) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
969 |
scr_LogPrint(LPRINT_LOGNORM, "<%s> wants to subscribe " |
43 | 970 |
"to your network presence updates", from); |
125 | 971 |
// FIXME we accept everybody... |
972 |
x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); |
|
973 |
jab_send(jc, x); |
|
974 |
xmlnode_free(x); |
|
91 | 975 |
} else { |
976 |
x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); |
|
31 | 977 |
jab_send(jc, x); |
978 |
xmlnode_free(x); |
|
91 | 979 |
} |
43 | 980 |
} else if (!strcmp(type, "unsubscribe")) { |
981 |
x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0); |
|
31 | 982 |
jab_send(jc, x); |
983 |
xmlnode_free(x); |
|
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
984 |
scr_LogPrint(LPRINT_LOGNORM, "<%s> has unsubscribed to " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
985 |
"your presence updates", from); |
31 | 986 |
} |
987 |
break; |
|
988 |
||
989 |
default: |
|
990 |
break; |
|
991 |
} |
|
992 |
} |
|
993 |