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