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