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