Mercurial > pidgin.yaz
annotate src/protocols/jabber/jabber.c @ 3667:11ab2a5f6677
[gaim-migrate @ 3796]
win32 fix
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Sun, 13 Oct 2002 16:38:05 +0000 |
parents | 1a6d3f3bc682 |
children | da6e3c984985 |
rev | line source |
---|---|
2086 | 1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
2 /* | |
3 * gaim | |
4 * | |
5 * Some code copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
6 * libfaim code copyright 1998, 1999 Adam Fritzler <afritz@auk.cx> | |
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 | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU 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 USA | |
21 * | |
22 */ | |
23 #ifdef HAVE_CONFIG_H | |
3630 | 24 #include <config.h> |
2086 | 25 #endif |
26 | |
3664 | 27 #include <sys/types.h> |
28 /*this must happen before sys/socket.h or freebsd won't compile*/ | |
29 | |
3630 | 30 #ifndef _WIN32 |
2086 | 31 #include <netdb.h> |
32 #include <netinet/in.h> | |
33 #include <arpa/inet.h> | |
3630 | 34 #include <sys/socket.h> |
35 #include <sys/utsname.h> | |
36 #include <unistd.h> | |
37 #else | |
38 #include <winsock.h> | |
39 #include "utsname.h" | |
40 #endif | |
41 | |
42 #include <errno.h> | |
2086 | 43 #include <string.h> |
44 #include <stdlib.h> | |
45 #include <stdio.h> | |
46 #include <time.h> | |
47 #include <sys/stat.h> | |
48 #include "multi.h" | |
49 #include "prpl.h" | |
50 #include "gaim.h" | |
2232
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
51 #ifdef MAX |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
52 #undef MAX |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
53 #endif |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
54 #ifdef MIN |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
55 #undef MIN |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
56 #endif |
2086 | 57 #include "jabber.h" |
58 #include "proxy.h" | |
59 | |
3630 | 60 #ifdef _WIN32 |
61 #include "win32dep.h" | |
62 #endif | |
63 | |
3583 | 64 #include "pixmaps/protocols/jabber/available.xpm" |
65 #include "pixmaps/protocols/jabber/available-away.xpm" | |
66 #include "pixmaps/protocols/jabber/available-chat.xpm" | |
67 #include "pixmaps/protocols/jabber/available-xa.xpm" | |
68 #include "pixmaps/protocols/jabber/available-dnd.xpm" | |
69 #include "pixmaps/protocols/jabber/available-error.xpm" | |
2086 | 70 |
3630 | 71 /* for win32 compatability */ |
72 G_MODULE_IMPORT GSList *connections; | |
73 | |
2086 | 74 /* The priv member of gjconn's is a gaim_connection for now. */ |
75 #define GJ_GC(x) ((struct gaim_connection *)(x)->priv) | |
76 | |
77 #define IQID_AUTH "__AUTH__" | |
78 | |
79 #define IQ_NONE -1 | |
80 #define IQ_AUTH 0 | |
81 #define IQ_ROSTER 1 | |
82 | |
3259 | 83 #define UC_AWAY (0x02 | UC_UNAVAILABLE) |
84 #define UC_CHAT 0x04 | |
85 #define UC_XA (0x08 | UC_UNAVAILABLE) | |
86 #define UC_DND (0x10 | UC_UNAVAILABLE) | |
87 #define UC_ERROR (0x20 | UC_UNAVAILABLE) | |
2086 | 88 |
89 #define DEFAULT_SERVER "jabber.org" | |
90 #define DEFAULT_GROUPCHAT "conference.jabber.org" | |
91 #define DEFAULT_PORT 5222 | |
92 | |
93 #define USEROPT_PORT 0 | |
94 | |
3311 | 95 #define JABBER_TYPING_NOTIFY_INT 15 /* Delay (in seconds) between sending typing notifications */ |
96 | |
3074 | 97 /* |
98 * Note: "was_connected" may seem redundant, but it was needed and I | |
99 * didn't want to touch the Jabber state stuff not specific to Gaim. | |
100 */ | |
2086 | 101 typedef struct gjconn_struct { |
102 /* Core structure */ | |
103 pool p; /* Memory allocation pool */ | |
104 int state; /* Connection state flag */ | |
3074 | 105 int was_connected; /* We were once connected */ |
2086 | 106 int fd; /* Connection file descriptor */ |
107 jid user; /* User info */ | |
108 char *pass; /* User passwd */ | |
109 | |
110 /* Stream stuff */ | |
111 int id; /* id counter for jab_getid() function */ | |
112 char idbuf[9]; /* temporary storage for jab_getid() */ | |
113 char *sid; /* stream id from server, for digest auth */ | |
114 XML_Parser parser; /* Parser instance */ | |
115 xmlnode current; /* Current node in parsing instance.. */ | |
116 | |
117 /* Event callback ptrs */ | |
2956 | 118 void (*on_state)(struct gjconn_struct *gjc, int state); |
119 void (*on_packet)(struct gjconn_struct *gjc, jpacket p); | |
120 | |
121 GHashTable *queries; /* query tracker */ | |
2086 | 122 |
123 void *priv; | |
124 | |
125 } *gjconn, gjconn_struct; | |
126 | |
2956 | 127 typedef void (*gjconn_state_h)(gjconn gjc, int state); |
128 typedef void (*gjconn_packet_h)(gjconn gjc, jpacket p); | |
2086 | 129 |
130 static gjconn gjab_new(char *user, char *pass, void *priv); | |
2956 | 131 static void gjab_delete(gjconn gjc); |
132 static void gjab_state_handler(gjconn gjc, gjconn_state_h h); | |
133 static void gjab_packet_handler(gjconn gjc, gjconn_packet_h h); | |
134 static void gjab_start(gjconn gjc); | |
135 static void gjab_stop(gjconn gjc); | |
2086 | 136 /* |
2956 | 137 static int gjab_getfd(gjconn gjc); |
138 static jid gjab_getjid(gjconn gjc); | |
139 static char *gjab_getsid(gjconn gjc); | |
2086 | 140 */ |
2956 | 141 static char *gjab_getid(gjconn gjc); |
142 static void gjab_send(gjconn gjc, xmlnode x); | |
143 static void gjab_send_raw(gjconn gjc, const char *str); | |
144 static void gjab_recv(gjconn gjc); | |
145 static void gjab_auth(gjconn gjc); | |
146 | |
147 /* | |
148 * It is *this* to which we point the gaim_connection proto_data | |
149 */ | |
2086 | 150 struct jabber_data { |
2956 | 151 gjconn gjc; |
2086 | 152 gboolean did_import; |
2956 | 153 GSList *chats; |
2086 | 154 time_t idle; |
2800
0ad63a625eec
[gaim-migrate @ 2813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
155 gboolean die; |
3311 | 156 GHashTable *buddies; |
3630 | 157 GSList *file_transfers; |
2086 | 158 }; |
159 | |
2956 | 160 /* |
3340 | 161 * Used in jabber_buddy_data.invisible, below |
162 */ | |
163 #define JABBER_NOT_INVIS 0x00 | |
164 #define JABBER_SERV_INVIS 0x01 /* Invisible set on server */ | |
165 #define JABBER_BUD_INVIS 0x02 /* Invisible set on buddy */ | |
166 | |
167 /* | |
3311 | 168 * It is *this* to which we point the buddy proto_data |
169 */ | |
170 struct jabber_buddy_data { | |
171 GSList *resources; | |
172 char *error_msg; | |
3340 | 173 unsigned invisible; /* We've set presence type invisible for this buddy */ |
3311 | 174 }; |
175 | |
176 /* | |
177 * per-resource info | |
178 */ | |
179 typedef struct jabber_resource_info { | |
180 char *name; | |
181 int priority; | |
182 int state; | |
183 char *away_msg; | |
184 char *thread_id; | |
185 gboolean has_composing; | |
186 } *jab_res_info; | |
187 | |
188 /* | |
189 * For our own jid handling | |
190 * | |
191 * We do our own so we can cleanly parse buddy names | |
192 * (user@server/resource) and rid ourselves of the | |
193 * struct when we're done with it. The Jabber lib | |
194 * structs last the life of the pool--we frequently | |
195 * don't want that. | |
196 * | |
197 * We use the real jid structs so we can make use of | |
198 * jid_safe(), jid_cmp() and some others. | |
199 * | |
200 * BE CAREFUL using the Jabber lib routines. | |
201 * Many of them assume pool use and are not | |
202 * amenable to use with our own! | |
203 * | |
204 * We give them special names so we know, throughout | |
205 * the code, that they're not alloc'd out of pool | |
206 * memory and we can, and must, dispose of them when | |
207 * we're done with 'em. | |
208 */ | |
209 #define gaim_jid_struct jid_struct | |
210 typedef struct gaim_jid_struct *gaim_jid; | |
211 | |
212 /* | |
2956 | 213 * Jabber "chat group" info. Pointers to these go in jabber_data |
214 * pending and existing chats lists. | |
215 */ | |
2086 | 216 struct jabber_chat { |
3311 | 217 gaim_jid gjid; |
2086 | 218 struct gaim_connection *gc; |
219 struct conversation *b; | |
220 int id; | |
2956 | 221 int state; |
2086 | 222 }; |
223 | |
2956 | 224 /* |
225 * Jabber chat states... | |
226 * | |
227 * Note: due to a bug in one version of the Jabber server, subscriptions | |
228 * to chat groups aren't (always?) properly removed at the server. The | |
229 * result is clients receive Jabber "presence" notifications for JIDs | |
230 * they no longer care about. The problem with such vestigial notifies is | |
231 * that we really have no way of telling if it's vestigial or if it's a | |
232 * valid "buddy" presence notification. So we keep jabber_chat structs | |
233 * around after leaving a chat group and simply mark them "closed." That | |
234 * way we can test for such errant presence notifications. I.e.: if we | |
235 * get a presence notfication from a JID that matches a chat group JID, | |
236 * we disregard it. | |
237 */ | |
238 #define JCS_PENDING 1 /* pending */ | |
239 #define JCS_ACTIVE 2 /* active */ | |
240 #define JCS_CLOSED 3 /* closed */ | |
241 | |
242 | |
243 #define STATE_EVT(arg) if(gjc->on_state) { (gjc->on_state)(gjc, (arg) ); } | |
244 | |
245 static void jabber_handlevcard(gjconn, xmlnode, char *); | |
2086 | 246 |
3630 | 247 static char *jabber_normalize(const char *s); |
248 | |
2086 | 249 static char *create_valid_jid(const char *given, char *server, char *resource) |
250 { | |
251 char *valid; | |
252 | |
253 if (!strchr(given, '@')) | |
254 valid = g_strdup_printf("%s@%s/%s", given, server, resource); | |
255 else if (!strchr(strchr(given, '@'), '/')) | |
256 valid = g_strdup_printf("%s/%s", given, resource); | |
257 else | |
258 valid = g_strdup(given); | |
259 | |
260 return valid; | |
261 } | |
262 | |
3311 | 263 /* |
264 * Dispose of a gaim_jid_struct | |
265 */ | |
266 static void gaim_jid_free(gaim_jid gjid) | |
267 { | |
268 if(gjid) { | |
269 if(gjid->resource) | |
270 free(gjid->resource); | |
271 if(gjid->user) | |
272 free(gjid->user); | |
273 if(gjid->server) | |
274 free(gjid->server); | |
275 if(gjid->full) | |
276 free(gjid->full); | |
277 free(gjid); | |
278 } | |
279 } | |
280 | |
281 /* | |
282 * Create a new gjid struct | |
283 * | |
284 * Unlike jid_new(), also creates "full." | |
285 * | |
286 * Shamelessly copied, in part, from jid.c: jid_new() | |
287 * | |
288 * Caller is responsible for freeing the space allocated by this via | |
289 * gaim_jid_free(). | |
290 * | |
291 * JFIXME: Has a local declaration for jid.c:jid_safe(). I've put in a | |
292 * request to have that added to libjabber's lib.h file. (JSeymour) | |
293 */ | |
294 static gaim_jid gaim_jid_new(char *name) | |
295 { | |
296 extern jid jid_safe(jid); /* *retch* */ | |
297 | |
298 gaim_jid gjid = NULL; | |
299 | |
300 if(name && strlen(name)) { | |
301 char *server, *resource, *type, *str; | |
302 int full_len = 0; | |
303 | |
304 /* user@server/resource */ | |
305 | |
306 str = strdup(name); /* we mangle a copy */ | |
307 | |
308 gjid = calloc(1, sizeof(struct gaim_jid_struct)); | |
309 | |
310 if((resource = strstr(str, "/")) != NULL) { | |
311 *resource = '\0'; | |
312 ++resource; | |
313 if((full_len = strlen(resource)) > 0) { | |
314 gjid->resource = strdup(resource); | |
315 ++full_len; /* for later "/" addition */ | |
316 } | |
317 } else { | |
318 resource = str + strlen(str); /* point to end */ | |
319 } | |
320 | |
321 type = strstr(str, ":"); | |
322 if(type != NULL && type < resource) { | |
323 *type = '\0'; | |
324 ++type; | |
325 str = type; /* ignore the type: prefix */ | |
326 } | |
327 | |
328 server = strstr(str, "@"); | |
329 | |
330 /* | |
331 * if there's no @, it's just the server address | |
332 */ | |
333 if(server == NULL || server > resource) { | |
334 gjid->server = strdup(str); | |
335 full_len += strlen(str); | |
336 } else { | |
337 *server = '\0'; | |
338 ++server; | |
339 gjid->server = strdup(server); | |
340 full_len += strlen(server) + 1; /* account for later "@" */ | |
341 if(strlen(str) > 0) { | |
342 gjid->user = strdup(str); | |
343 full_len += strlen(str); | |
344 } | |
345 } | |
346 | |
347 free(str); | |
348 | |
349 if(!jid_safe(gjid)) { | |
350 gaim_jid_free(gjid); | |
351 gjid = NULL; | |
352 } else { | |
353 if(full_len) { | |
354 char *s = gjid->full = malloc(++full_len); | |
355 | |
356 if(gjid->user) { | |
357 strcpy(s, gjid->user); | |
358 s += strlen(gjid->user); | |
359 } | |
360 if(gjid->server) { | |
361 if(s > gjid->full) | |
362 *(s++) = '@'; | |
363 strcpy(s, gjid->server); | |
364 s += strlen(gjid->server); | |
365 } | |
366 if(gjid->resource) { | |
367 *(s++) = '/'; | |
368 strcpy(s, gjid->resource); | |
369 } | |
370 } | |
371 } | |
372 } | |
373 | |
374 return gjid; | |
375 } | |
376 | |
377 /* | |
378 * Get a "username@server" from unadorned "username" | |
379 * | |
380 * If there's no "@server" part and "who" doesn't match the | |
381 * gjconn server (which would indicate that "who" *is* the | |
382 * server in case of server messages), the gjconn server is | |
383 * appended. | |
384 * | |
385 * If incl_resource is TRUE (non-0), the returned string | |
386 * includes the "/resource" part (if it exists), otherwise not. | |
387 * | |
388 * Allocates space for returned string. Caller is | |
389 * responsible for freeing it with g_free(). | |
390 * | |
391 * If "gjid" is non-null, sets that as well. Caller is | |
392 * reponsible for freeing that via gaim_jid_free() when done | |
393 * with it. | |
394 */ | |
3466 | 395 static gchar *get_realwho(gjconn gjc, const char *who, int incl_resource, gaim_jid *gjid) |
3311 | 396 { |
397 gaim_jid my_gjid; | |
398 gchar *my_who; | |
399 gchar *realwho = NULL; | |
400 | |
401 if(!(who && who[0])) { | |
402 return NULL; | |
403 } | |
404 | |
405 /* | |
406 * Bare username and "username" not the server itself? | |
407 */ | |
408 if(!strchr(who, '@') && strcasecmp(who, gjc->user->server)) { | |
409 my_who = g_strdup_printf("%s@%s", who, gjc->user->server); | |
410 } else { | |
411 my_who = g_strdup(who); | |
412 } | |
413 | |
414 if((my_gjid = gaim_jid_new(my_who)) != NULL) { | |
415 /* | |
416 * If there's no "user" part, "who" was just the server or perhaps a transport (?) | |
417 */ | |
418 if(my_gjid->user) { | |
419 /* | |
420 * Include "/resource" bit? | |
421 */ | |
422 if(incl_resource) { | |
423 realwho = g_strdup(my_gjid->full); | |
424 } else { | |
425 realwho = g_strdup_printf("%s@%s", my_gjid->user, my_gjid->server); | |
426 } | |
427 } else { | |
428 realwho = g_strdup(my_gjid->server); | |
429 } | |
430 } | |
431 | |
432 g_free(my_who); | |
433 | |
434 if(gjid) { | |
435 *gjid = my_gjid; | |
436 } else { | |
437 gaim_jid_free(my_gjid); | |
438 } | |
439 | |
440 return realwho; | |
441 } | |
442 | |
2086 | 443 static gjconn gjab_new(char *user, char *pass, void *priv) |
444 { | |
445 pool p; | |
2956 | 446 gjconn gjc; |
2086 | 447 |
448 if (!user) | |
449 return (NULL); | |
450 | |
451 p = pool_new(); | |
452 if (!p) | |
453 return (NULL); | |
2956 | 454 gjc = pmalloc_x(p, sizeof(gjconn_struct), 0); |
455 if (!gjc) { | |
456 pool_free(p); /* no need for this anymore! */ | |
2086 | 457 return (NULL); |
2956 | 458 } |
459 gjc->p = p; | |
460 | |
3236 | 461 if((gjc->user = jid_new(p, user)) == NULL) { |
462 pool_free(p); /* no need for this anymore! */ | |
463 return (NULL); | |
464 } | |
3257 | 465 |
466 gjc->pass = strdup(pass); | |
2956 | 467 |
468 gjc->state = JCONN_STATE_OFF; | |
3074 | 469 gjc->was_connected = 0; |
2956 | 470 gjc->id = 1; |
471 gjc->fd = -1; | |
472 | |
473 gjc->priv = priv; | |
474 | |
475 return gjc; | |
2086 | 476 } |
477 | |
2956 | 478 static void gjab_delete(gjconn gjc) |
2086 | 479 { |
2956 | 480 if (!gjc) |
2086 | 481 return; |
482 | |
2956 | 483 gjab_stop(gjc); |
3257 | 484 free(gjc->pass); |
2956 | 485 pool_free(gjc->p); |
2086 | 486 } |
487 | |
2956 | 488 static void gjab_state_handler(gjconn gjc, gjconn_state_h h) |
2086 | 489 { |
2956 | 490 if (!gjc) |
2086 | 491 return; |
492 | |
2956 | 493 gjc->on_state = h; |
2086 | 494 } |
495 | |
2956 | 496 static void gjab_packet_handler(gjconn gjc, gjconn_packet_h h) |
2086 | 497 { |
2956 | 498 if (!gjc) |
2086 | 499 return; |
500 | |
2956 | 501 gjc->on_packet = h; |
2086 | 502 } |
503 | |
2956 | 504 static void gjab_stop(gjconn gjc) |
2086 | 505 { |
2956 | 506 if (!gjc || gjc->state == JCONN_STATE_OFF) |
2086 | 507 return; |
508 | |
2956 | 509 gjab_send_raw(gjc, "</stream:stream>"); |
510 gjc->state = JCONN_STATE_OFF; | |
3074 | 511 gjc->was_connected = 0; |
3630 | 512 #ifndef _WIN32 |
2956 | 513 close(gjc->fd); |
3630 | 514 #else |
515 closesocket(gjc->fd); | |
516 #endif | |
2956 | 517 gjc->fd = -1; |
518 XML_ParserFree(gjc->parser); | |
519 gjc->parser = NULL; | |
2086 | 520 } |
521 | |
522 /* | |
2956 | 523 static int gjab_getfd(gjconn gjc) |
2086 | 524 { |
2956 | 525 if (gjc) |
526 return gjc->fd; | |
2086 | 527 else |
528 return -1; | |
529 } | |
530 | |
2956 | 531 static jid gjab_getjid(gjconn gjc) |
2086 | 532 { |
2956 | 533 if (gjc) |
534 return (gjc->user); | |
2086 | 535 else |
536 return NULL; | |
537 } | |
538 | |
2956 | 539 static char *gjab_getsid(gjconn gjc) |
2086 | 540 { |
2956 | 541 if (gjc) |
542 return (gjc->sid); | |
2086 | 543 else |
544 return NULL; | |
545 } | |
546 */ | |
547 | |
2956 | 548 static char *gjab_getid(gjconn gjc) |
2086 | 549 { |
2956 | 550 snprintf(gjc->idbuf, 8, "%d", gjc->id++); |
551 return &gjc->idbuf[0]; | |
2086 | 552 } |
553 | |
2956 | 554 static void gjab_send(gjconn gjc, xmlnode x) |
2086 | 555 { |
2956 | 556 if (gjc && gjc->state != JCONN_STATE_OFF) { |
2086 | 557 char *buf = xmlnode2str(x); |
558 if (buf) | |
3630 | 559 #ifndef _WIN32 |
2956 | 560 write(gjc->fd, buf, strlen(buf)); |
3630 | 561 #else |
562 send(gjc->fd, buf, strlen(buf), 0); | |
563 #endif | |
2086 | 564 debug_printf("gjab_send: %s\n", buf); |
565 } | |
566 } | |
567 | |
2956 | 568 static void gjab_send_raw(gjconn gjc, const char *str) |
2086 | 569 { |
2956 | 570 if (gjc && gjc->state != JCONN_STATE_OFF) { |
571 /* | |
572 * JFIXME: No error detection?!?! | |
573 */ | |
3630 | 574 #ifndef _WIN32 |
2956 | 575 if(write(gjc->fd, str, strlen(str)) < 0) { |
3630 | 576 #else |
577 if(send(gjc->fd, str, strlen(str), 0) < 0) { | |
578 #endif | |
2956 | 579 fprintf(stderr, "DBG: Problem sending. Error: %d\n", errno); |
580 fflush(stderr); | |
581 } | |
2086 | 582 debug_printf("gjab_send_raw: %s\n", str); |
583 } | |
584 } | |
585 | |
2956 | 586 static void gjab_reqroster(gjconn gjc) |
2086 | 587 { |
588 xmlnode x; | |
589 | |
590 x = jutil_iqnew(JPACKET__GET, NS_ROSTER); | |
2956 | 591 xmlnode_put_attrib(x, "id", gjab_getid(gjc)); |
592 | |
593 gjab_send(gjc, x); | |
2086 | 594 xmlnode_free(x); |
595 } | |
596 | |
2956 | 597 static void gjab_reqauth(gjconn gjc) |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
598 { |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
599 xmlnode x, y, z; |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
600 char *user; |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
601 |
2956 | 602 if (!gjc) |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
603 return; |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
604 |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
605 x = jutil_iqnew(JPACKET__GET, NS_AUTH); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
606 xmlnode_put_attrib(x, "id", IQID_AUTH); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
607 y = xmlnode_get_tag(x, "query"); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
608 |
2956 | 609 user = gjc->user->user; |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
610 |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
611 if (user) { |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
612 z = xmlnode_insert_tag(y, "username"); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
613 xmlnode_insert_cdata(z, user, -1); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
614 } |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
615 |
2956 | 616 gjab_send(gjc, x); |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
617 xmlnode_free(x); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
618 } |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
619 |
2956 | 620 static void gjab_auth(gjconn gjc) |
2086 | 621 { |
622 xmlnode x, y, z; | |
623 char *hash, *user; | |
624 | |
2956 | 625 if (!gjc) |
2086 | 626 return; |
627 | |
628 x = jutil_iqnew(JPACKET__SET, NS_AUTH); | |
629 xmlnode_put_attrib(x, "id", IQID_AUTH); | |
630 y = xmlnode_get_tag(x, "query"); | |
631 | |
2956 | 632 user = gjc->user->user; |
2086 | 633 |
634 if (user) { | |
635 z = xmlnode_insert_tag(y, "username"); | |
636 xmlnode_insert_cdata(z, user, -1); | |
637 } | |
638 | |
639 z = xmlnode_insert_tag(y, "resource"); | |
2956 | 640 xmlnode_insert_cdata(z, gjc->user->resource, -1); |
641 | |
642 if (gjc->sid) { | |
643 debug_printf("digest authentication (sid %s)\n", gjc->sid); | |
2086 | 644 z = xmlnode_insert_tag(y, "digest"); |
2956 | 645 hash = pmalloc(x->p, strlen(gjc->sid) + strlen(gjc->pass) + 1); |
646 strcpy(hash, gjc->sid); | |
647 strcat(hash, gjc->pass); | |
2086 | 648 hash = shahash(hash); |
649 xmlnode_insert_cdata(z, hash, 40); | |
650 } else { | |
651 z = xmlnode_insert_tag(y, "password"); | |
2956 | 652 xmlnode_insert_cdata(z, gjc->pass, -1); |
2086 | 653 } |
654 | |
2956 | 655 gjab_send(gjc, x); |
2086 | 656 xmlnode_free(x); |
657 | |
658 return; | |
659 } | |
660 | |
2956 | 661 static void gjab_recv(gjconn gjc) |
2086 | 662 { |
663 static char buf[4096]; | |
664 int len; | |
665 | |
2956 | 666 if (!gjc || gjc->state == JCONN_STATE_OFF) |
2086 | 667 return; |
3630 | 668 #ifndef _WIN32 |
3234 | 669 if ((len = read(gjc->fd, buf, sizeof(buf) - 1)) > 0) { |
3630 | 670 #else |
671 if ((len = recv(gjc->fd, buf, sizeof(buf) - 1, 0)) > 0) { | |
672 #endif | |
2956 | 673 struct jabber_data *jd = GJ_GC(gjc)->proto_data; |
2086 | 674 buf[len] = '\0'; |
675 debug_printf("input (len %d): %s\n", len, buf); | |
2956 | 676 XML_Parse(gjc->parser, buf, len, 0); |
2800
0ad63a625eec
[gaim-migrate @ 2813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
677 if (jd->die) |
2956 | 678 signoff(GJ_GC(gjc)); |
3105 | 679 } else if (len < 0 || errno != EAGAIN) { |
2086 | 680 STATE_EVT(JCONN_STATE_OFF) |
681 } | |
682 } | |
683 | |
684 static void startElement(void *userdata, const char *name, const char **attribs) | |
685 { | |
686 xmlnode x; | |
2956 | 687 gjconn gjc = (gjconn) userdata; |
688 | |
689 if (gjc->current) { | |
2086 | 690 /* Append the node to the current one */ |
2956 | 691 x = xmlnode_insert_tag(gjc->current, name); |
2086 | 692 xmlnode_put_expat_attribs(x, attribs); |
693 | |
2956 | 694 gjc->current = x; |
2086 | 695 } else { |
696 x = xmlnode_new_tag(name); | |
697 xmlnode_put_expat_attribs(x, attribs); | |
698 if (strcmp(name, "stream:stream") == 0) { | |
699 /* special case: name == stream:stream */ | |
700 /* id attrib of stream is stored for digest auth */ | |
2956 | 701 gjc->sid = g_strdup(xmlnode_get_attrib(x, "id")); |
2086 | 702 /* STATE_EVT(JCONN_STATE_AUTH) */ |
2635
8c75e59e4bdf
[gaim-migrate @ 2648]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2607
diff
changeset
|
703 xmlnode_free(x); |
2086 | 704 } else { |
2956 | 705 gjc->current = x; |
2086 | 706 } |
707 } | |
708 } | |
709 | |
710 static void endElement(void *userdata, const char *name) | |
711 { | |
2956 | 712 gjconn gjc = (gjconn) userdata; |
2086 | 713 xmlnode x; |
714 jpacket p; | |
715 | |
2956 | 716 if (gjc->current == NULL) { |
2086 | 717 /* we got </stream:stream> */ |
718 STATE_EVT(JCONN_STATE_OFF) | |
719 return; | |
720 } | |
721 | |
2956 | 722 x = xmlnode_get_parent(gjc->current); |
2086 | 723 |
724 if (!x) { | |
725 /* it is time to fire the event */ | |
2956 | 726 p = jpacket_new(gjc->current); |
727 | |
728 if (gjc->on_packet) | |
729 (gjc->on_packet) (gjc, p); | |
2086 | 730 else |
2956 | 731 xmlnode_free(gjc->current); |
2086 | 732 } |
733 | |
2956 | 734 gjc->current = x; |
2086 | 735 } |
736 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
737 static void jabber_callback(gpointer data, gint source, GaimInputCondition condition) |
2086 | 738 { |
739 struct gaim_connection *gc = (struct gaim_connection *)data; | |
740 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; | |
741 | |
2956 | 742 gjab_recv(jd->gjc); |
2086 | 743 } |
744 | |
745 static void charData(void *userdata, const char *s, int slen) | |
746 { | |
2956 | 747 gjconn gjc = (gjconn) userdata; |
748 | |
749 if (gjc->current) | |
750 xmlnode_insert_cdata(gjc->current, s, slen); | |
2086 | 751 } |
752 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
753 static void gjab_connected(gpointer data, gint source, GaimInputCondition cond) |
2086 | 754 { |
755 xmlnode x; | |
756 char *t, *t2; | |
757 struct gaim_connection *gc = data; | |
758 struct jabber_data *jd; | |
2956 | 759 gjconn gjc; |
2086 | 760 |
761 if (!g_slist_find(connections, gc)) { | |
3630 | 762 #ifndef _WIN32 |
2086 | 763 close(source); |
3630 | 764 #else |
765 closesocket(source); | |
766 #endif | |
2086 | 767 return; |
768 } | |
769 | |
770 jd = gc->proto_data; | |
2956 | 771 gjc = jd->gjc; |
772 | |
773 if (gjc->fd != source) | |
774 gjc->fd = source; | |
2300
d2686f757d6e
[gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
775 |
2086 | 776 if (source == -1) { |
777 STATE_EVT(JCONN_STATE_OFF) | |
778 return; | |
779 } | |
780 | |
2956 | 781 gjc->state = JCONN_STATE_CONNECTED; |
2086 | 782 STATE_EVT(JCONN_STATE_CONNECTED) |
783 | |
784 /* start stream */ | |
2956 | 785 x = jutil_header(NS_CLIENT, gjc->user->server); |
2086 | 786 t = xmlnode2str(x); |
787 /* this is ugly, we can create the string here instead of jutil_header */ | |
788 /* what do you think about it? -madcat */ | |
789 t2 = strstr(t, "/>"); | |
790 *t2++ = '>'; | |
791 *t2 = '\0'; | |
2956 | 792 gjab_send_raw(gjc, "<?xml version='1.0'?>"); |
793 gjab_send_raw(gjc, t); | |
2086 | 794 xmlnode_free(x); |
795 | |
2956 | 796 gjc->state = JCONN_STATE_ON; |
2086 | 797 STATE_EVT(JCONN_STATE_ON); |
798 | |
2956 | 799 gc = GJ_GC(gjc); |
800 gc->inpa = gaim_input_add(gjc->fd, GAIM_INPUT_READ, jabber_callback, gc); | |
2086 | 801 } |
802 | |
2956 | 803 static void gjab_start(gjconn gjc) |
2086 | 804 { |
805 struct aim_user *user; | |
806 int port; | |
807 | |
2956 | 808 if (!gjc || gjc->state != JCONN_STATE_OFF) |
2086 | 809 return; |
810 | |
2956 | 811 user = GJ_GC(gjc)->user; |
2086 | 812 port = user->proto_opt[USEROPT_PORT][0] ? atoi(user->proto_opt[USEROPT_PORT]) : DEFAULT_PORT; |
813 | |
2956 | 814 gjc->parser = XML_ParserCreate(NULL); |
815 XML_SetUserData(gjc->parser, (void *)gjc); | |
816 XML_SetElementHandler(gjc->parser, startElement, endElement); | |
817 XML_SetCharacterDataHandler(gjc->parser, charData); | |
818 | |
819 gjc->fd = proxy_connect(gjc->user->server, port, gjab_connected, GJ_GC(gjc)); | |
820 if (!user->gc || (gjc->fd < 0)) { | |
2086 | 821 STATE_EVT(JCONN_STATE_OFF) |
822 return; | |
823 } | |
824 } | |
825 | |
2956 | 826 /* |
827 * Find chat by chat group name | |
828 */ | |
2086 | 829 static struct conversation *find_chat(struct gaim_connection *gc, char *name) |
830 { | |
831 GSList *bcs = gc->buddy_chats; | |
832 struct conversation *b = NULL; | |
833 char *chat = g_strdup(normalize(name)); | |
834 | |
835 while (bcs) { | |
836 b = bcs->data; | |
837 if (!strcasecmp(normalize(b->name), chat)) | |
838 break; | |
839 b = NULL; | |
840 bcs = bcs->next; | |
841 } | |
842 | |
843 g_free(chat); | |
844 return b; | |
845 } | |
846 | |
2956 | 847 /* |
848 * Find chat by "chat id" | |
849 * | |
850 * Returns: 0 on success and jabber_chat pointer set | |
851 * or -EINVAL on error and jabber_chat pointer is | |
852 * undefined. | |
853 * | |
854 * TBD: Slogging through the buddy_chats list seems | |
855 * redundant since the chat i.d. is mirrored in the | |
856 * jabber_chat struct list. But that's the way it | |
857 * was, so that's the way I'm leaving it--for now. | |
858 */ | |
859 static int jabber_find_chat_by_convo_id(struct gaim_connection *gc, int id, struct jabber_chat **jc) | |
2086 | 860 { |
2956 | 861 GSList *bcs = gc->buddy_chats; |
862 struct conversation *b = NULL; | |
863 struct jabber_data *jd = gc->proto_data; | |
864 | |
865 *jc = NULL; | |
866 | |
867 while(bcs != NULL) { | |
868 b = bcs->data; | |
869 if (id == b->id) | |
870 break; | |
871 bcs = bcs->next; | |
872 } | |
873 | |
874 if (bcs != NULL) { | |
875 bcs = jd->chats; | |
876 while (bcs != NULL) { | |
877 *jc = bcs->data; | |
878 if ((*jc)->state == JCS_ACTIVE && (*jc)->b == b) | |
879 break; | |
880 bcs = bcs->next; | |
881 } | |
882 } | |
883 | |
884 return(bcs == NULL? -EINVAL : 0); | |
885 } | |
886 | |
887 /* | |
888 * Find any chat | |
889 */ | |
890 static struct jabber_chat *find_any_chat(struct gaim_connection *gc, jid chat) | |
891 { | |
892 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats; | |
2086 | 893 struct jabber_chat *jc = NULL; |
894 | |
2956 | 895 while (jcs) { |
896 jc = jcs->data; | |
3311 | 897 if (!jid_cmpx(chat, jc->gjid, JID_USER | JID_SERVER)) |
2086 | 898 break; |
899 jc = NULL; | |
2956 | 900 jcs = jcs->next; |
2086 | 901 } |
902 | |
903 return jc; | |
904 } | |
905 | |
2956 | 906 |
907 /* | |
908 * Find existing/active Jabber chat | |
909 */ | |
910 static struct jabber_chat *find_existing_chat(struct gaim_connection *gc, jid chat) | |
911 { | |
912 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats; | |
913 struct jabber_chat *jc = NULL; | |
914 | |
915 while (jcs) { | |
916 jc = jcs->data; | |
3311 | 917 if (jc->state == JCS_ACTIVE && !jid_cmpx(chat, jc->gjid, JID_USER | JID_SERVER)) |
2956 | 918 break; |
919 jc = NULL; | |
920 jcs = jcs->next; | |
921 } | |
922 | |
923 return jc; | |
924 } | |
925 | |
926 /* | |
927 * Find pending chat | |
928 */ | |
2086 | 929 static struct jabber_chat *find_pending_chat(struct gaim_connection *gc, jid chat) |
930 { | |
2956 | 931 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats; |
2086 | 932 struct jabber_chat *jc = NULL; |
933 | |
2956 | 934 while (jcs) { |
935 jc = jcs->data; | |
3311 | 936 if (jc->state == JCS_PENDING && !jid_cmpx(chat, jc->gjid, JID_USER | JID_SERVER)) |
2086 | 937 break; |
938 jc = NULL; | |
2956 | 939 jcs = jcs->next; |
2086 | 940 } |
941 | |
942 return jc; | |
943 } | |
944 | |
945 static gboolean find_chat_buddy(struct conversation *b, char *name) | |
946 { | |
947 GList *m = b->in_room; | |
948 | |
949 while (m) { | |
950 if (!strcmp(m->data, name)) | |
951 return TRUE; | |
952 m = m->next; | |
953 } | |
954 | |
955 return FALSE; | |
956 } | |
957 | |
2956 | 958 /* |
3236 | 959 * Remove a buddy from the (gaim) buddylist (if he's on it) |
960 */ | |
3466 | 961 static void jabber_remove_gaim_buddy(struct gaim_connection *gc, const char *buddyname) |
3236 | 962 { |
963 struct buddy *b; | |
964 | |
965 if ((b = find_buddy(gc, buddyname)) != NULL) { | |
966 struct group *group; | |
967 | |
968 group = find_group_by_buddy(gc, buddyname); | |
969 debug_printf("removing buddy [1]: %s, from group: %s\n", buddyname, group->name); | |
970 remove_buddy(gc, group, b); | |
971 do_export(gc); | |
972 } | |
973 } | |
974 | |
3466 | 975 static void jabber_change_passwd(struct gaim_connection *gc, const char *old, const char *new) |
3257 | 976 { |
977 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; | |
978 | |
979 if(strcmp(old, gjc->pass)) | |
980 { | |
3427 | 981 do_error_dialog(_("Unable to change password."), |
982 _("The current password you entered is incorrect. Your password has " | |
983 "not been changed."), GAIM_ERROR); | |
3257 | 984 } |
985 else if(!strcmp(old, new)) | |
986 { | |
3427 | 987 do_error_dialog(_("Unable to change password"), |
988 _("The new password you entered is the same as your current passord. " | |
989 "Your password remains the same."), GAIM_ERROR); | |
3257 | 990 } |
991 else | |
992 { | |
993 xmlnode x, y, z; | |
994 char *id; | |
995 | |
996 x = jutil_iqnew(JPACKET__SET, NS_REGISTER); | |
997 xmlnode_put_attrib(x, "to", gjc->user->server); | |
998 y = xmlnode_get_tag(x, "query"); | |
999 z = xmlnode_insert_tag(y, "username"); | |
1000 xmlnode_insert_cdata(z, gjc->user->user, -1); | |
1001 z = xmlnode_insert_tag(y, "password"); | |
1002 xmlnode_insert_cdata(z, new, -1); | |
1003 | |
1004 id = gjab_getid(gjc); | |
1005 xmlnode_put_attrib(x, "id", id); | |
1006 | |
1007 free(gjc->pass); | |
1008 gjc->pass = strdup(new); | |
1009 | |
1010 g_hash_table_insert(gjc->queries, g_strdup(id), g_strdup("change_password")); | |
1011 | |
1012 gjab_send(gjc, x); | |
1013 xmlnode_free(x); | |
1014 } | |
1015 } | |
3311 | 1016 |
3340 | 1017 /* |
1018 * Return pointer to jabber_buddy_data if buddy found. Create if necessary. | |
1019 */ | |
3311 | 1020 static struct jabber_buddy_data* jabber_find_buddy(struct gaim_connection *gc, char *buddy) |
1021 { | |
1022 struct jabber_data *jd = gc->proto_data; | |
1023 gpointer val; | |
1024 char *realwho; | |
1025 | |
1026 if((realwho = get_realwho(jd->gjc, buddy, FALSE, NULL)) == NULL) | |
1027 return NULL; | |
1028 | |
1029 val = g_hash_table_lookup(jd->buddies, realwho); | |
1030 if(val) { | |
1031 g_free(realwho); | |
1032 return (struct jabber_buddy_data *)val; | |
1033 | |
1034 } else { | |
1035 struct jabber_buddy_data *jbd = g_new0(struct jabber_buddy_data, 1); | |
1036 jbd->error_msg = NULL; | |
1037 jbd->resources = NULL; | |
3340 | 1038 jbd->invisible = JABBER_NOT_INVIS; |
3311 | 1039 g_hash_table_insert(jd->buddies, g_strdup(realwho), jbd); |
1040 g_free(realwho); | |
1041 return jbd; | |
1042 } | |
1043 } | |
3257 | 1044 |
3236 | 1045 /* |
3311 | 1046 * find a resource by name, or if no name given, return the "default" resource |
1047 * default being the highest priority one. | |
1048 */ | |
1049 | |
1050 static jab_res_info jabber_find_resource(struct gaim_connection *gc, char *who) | |
1051 { | |
1052 GSList *resources; | |
1053 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, who); | |
1054 jab_res_info jri = NULL; | |
1055 char *res = strstr(who, "/"); | |
1056 | |
1057 if(res) | |
1058 res++; | |
1059 | |
1060 if(jbd) | |
1061 { | |
1062 resources = jbd->resources; | |
1063 while(resources) | |
1064 { | |
1065 if(!jri && !res) { | |
1066 jri = (jab_res_info) resources->data; | |
1067 } else if(!res) { /* we're looking for the default priority, so... */ | |
1068 if(((jab_res_info) resources->data)->priority >= jri->priority) | |
1069 jri = (jab_res_info) resources->data; | |
3337 | 1070 } else if(((jab_res_info)resources->data)->name) { |
3311 | 1071 if(!strcasecmp(((jab_res_info) resources->data)->name, res)) { |
1072 jri = (jab_res_info) resources->data; | |
1073 break; | |
1074 } | |
1075 } | |
1076 resources = resources->next; | |
1077 } | |
1078 } | |
1079 | |
1080 return jri; | |
1081 } | |
1082 | |
1083 /* | |
1084 * if the resource doesn't exist, create it. otherwise, just update the priority | |
2956 | 1085 */ |
3311 | 1086 static void jabber_track_resource(struct gaim_connection *gc, |
1087 char *buddy, | |
1088 char *res, | |
1089 int priority, | |
1090 int state) | |
1091 { | |
1092 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, buddy); | |
1093 | |
3337 | 1094 if(jbd) { |
1095 char *who; | |
1096 jab_res_info jri; | |
1097 if(res) | |
1098 who = g_strdup_printf("%s/%s", buddy, res); | |
1099 else | |
1100 who = g_strdup(buddy); | |
1101 jri = jabber_find_resource(gc, who); | |
3311 | 1102 g_free(who); |
1103 if(!jri) { | |
1104 jri = g_new0(struct jabber_resource_info, 1); | |
1105 jri->name = g_strdup(res); | |
1106 jri->away_msg = NULL; | |
1107 jbd->resources = g_slist_append(jbd->resources, jri); | |
1108 } | |
1109 jri->priority = priority; | |
1110 jri->state = state; | |
1111 } | |
1112 } | |
1113 | |
1114 /* | |
1115 * remove the resource, if it exists | |
1116 */ | |
1117 static void jabber_remove_resource(struct gaim_connection *gc, char *buddy, char *res) | |
2956 | 1118 { |
3311 | 1119 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, buddy); |
3337 | 1120 if(jbd) { |
1121 char *who; | |
1122 jab_res_info jri; | |
1123 if(res) | |
1124 who = g_strdup_printf("%s/%s", buddy, res); | |
1125 else | |
1126 who = g_strdup(buddy); | |
1127 jri = jabber_find_resource(gc, who); | |
3311 | 1128 g_free(who); |
1129 if(jri) { | |
3337 | 1130 if(jri->name) |
1131 g_free(jri->name); | |
3311 | 1132 if(jri->away_msg) |
1133 g_free(jri->away_msg); | |
1134 jbd->resources = g_slist_remove(jbd->resources, jri); | |
1135 g_free(jri); | |
1136 } | |
1137 } | |
1138 } | |
1139 | |
1140 /* | |
1141 * grab the away message for the default resource | |
1142 */ | |
1143 static char *jabber_lookup_away(gjconn gjc, char *name) | |
1144 { | |
1145 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), name); | |
1146 | |
1147 if(!jri || !jri->away_msg) | |
1148 return _("Unknown"); | |
1149 | |
1150 return jri->away_msg; | |
1151 } | |
1152 | |
1153 static void jabber_track_away(gjconn gjc, jpacket p, char *type) | |
1154 { | |
2956 | 1155 char *show; |
1156 char *vshow = NULL; | |
1157 char *status = NULL; | |
1158 char *msg = NULL; | |
3311 | 1159 jab_res_info jri = NULL; |
1160 | |
3337 | 1161 if(!p || !p->from || !p->from->user) |
3311 | 1162 return; |
1163 | |
1164 jri = jabber_find_resource(GJ_GC(gjc), jid_full(p->from)); | |
1165 | |
1166 if(!jri) | |
1167 return; | |
1168 | |
3105 | 1169 if (type && (strcasecmp(type, "unavailable") == 0)) { |
1170 vshow = _("Unavailable"); | |
1171 } else { | |
1172 if((show = xmlnode_get_tag_data(p->x, "show")) != NULL) { | |
1173 if (!strcasecmp(show, "away")) { | |
1174 vshow = _("Away"); | |
1175 } else if (!strcasecmp(show, "chat")) { | |
1176 vshow = _("Online"); | |
1177 } else if (!strcasecmp(show, "xa")) { | |
1178 vshow = _("Extended Away"); | |
1179 } else if (!strcasecmp(show, "dnd")) { | |
1180 vshow = _("Do Not Disturb"); | |
1181 } | |
2956 | 1182 } |
1183 } | |
1184 | |
3311 | 1185 status = g_strdup(xmlnode_get_tag_data(p->x, "status")); |
2956 | 1186 |
1187 if(vshow != NULL || status != NULL ) { | |
1188 /* kinda hokey, but it works :-) */ | |
1189 msg = g_strdup_printf("%s%s%s", | |
1190 (vshow == NULL? "" : vshow), | |
1191 (vshow == NULL || status == NULL? "" : ": "), | |
1192 (status == NULL? "" : status)); | |
3105 | 1193 } else { |
1194 msg = g_strdup(_("Online")); | |
2956 | 1195 } |
1196 | |
3259 | 1197 g_free(status); |
1198 | |
3311 | 1199 if(jri->away_msg) |
1200 g_free(jri->away_msg); | |
1201 | |
1202 jri->away_msg = msg; | |
1203 } | |
1204 | |
1205 static void jabber_convo_closed(struct gaim_connection *gc, char *name) | |
1206 { | |
1207 jab_res_info jri = jabber_find_resource(gc, name); | |
1208 | |
1209 if(jri) { | |
1210 if(jri->thread_id) | |
1211 g_free(jri->thread_id); | |
1212 | |
1213 jri->thread_id = NULL; | |
2956 | 1214 } |
1215 } | |
1216 | |
3311 | 1217 static void jabber_track_convo_thread(gjconn gjc, char *name, char *thread_id) |
1218 { | |
1219 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), name); | |
1220 | |
1221 if(jri) { | |
1222 if(jri->thread_id) | |
1223 g_free(jri->thread_id); | |
1224 | |
1225 jri->thread_id = g_strdup(thread_id); | |
1226 } | |
1227 } | |
1228 | |
1229 static char *jabber_get_convo_thread(gjconn gjc, char *name) | |
1230 { | |
1231 char *ct = NULL; | |
1232 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), name); | |
1233 | |
1234 if(jri) { | |
1235 if(jri->thread_id) | |
1236 ct = g_strdup(jri->thread_id); | |
1237 } | |
1238 | |
1239 return ct; | |
1240 } | |
1241 | |
1242 | |
3159 | 1243 static time_t iso8601_to_time(char *timestamp) |
1244 { | |
3229 | 1245 struct tm t; |
1246 time_t retval = 0; | |
1247 | |
3311 | 1248 if(sscanf(timestamp, "%04d%02d%02dT%02d:%02d:%02d", |
3229 | 1249 &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec)) |
1250 { | |
1251 t.tm_year -= 1900; | |
1252 t.tm_mon -= 1; | |
1253 t.tm_isdst = 0; | |
1254 retval = mktime(&t); | |
1255 # ifdef HAVE_TM_GMTOFF | |
1256 retval += t.tm_gmtoff; | |
1257 # else | |
1258 # ifdef HAVE_TIMEZONE | |
1259 tzset(); /* making sure */ | |
1260 retval -= timezone; | |
1261 # endif | |
1262 # endif | |
1263 } | |
1264 | |
1265 return retval; | |
3159 | 1266 } |
1267 | |
2956 | 1268 static void jabber_handlemessage(gjconn gjc, jpacket p) |
2086 | 1269 { |
3311 | 1270 xmlnode y, subj; |
3159 | 1271 time_t time_sent = time(NULL); |
3311 | 1272 gboolean typing = FALSE; |
2086 | 1273 |
1274 char *from = NULL, *msg = NULL, *type = NULL, *topic = NULL; | |
3311 | 1275 char *thread_id = NULL; |
1276 char *conference_room = NULL; | |
2086 | 1277 char m[BUF_LONG * 2]; |
1278 | |
1279 type = xmlnode_get_attrib(p->x, "type"); | |
3311 | 1280 |
1281 if ((y = xmlnode_get_tag(p->x, "thread"))) | |
1282 thread_id = xmlnode_get_data(y); | |
1283 | |
1284 y = xmlnode_get_firstchild(p->x); | |
1285 | |
1286 while(y) { | |
1287 if(NSCHECK(y, NS_DELAY)) { | |
1288 char *timestamp = xmlnode_get_attrib(y, "stamp"); | |
1289 time_sent = iso8601_to_time(timestamp); | |
1290 } else if(NSCHECK(y, "jabber:x:event")) { | |
1291 if(xmlnode_get_tag(y, "composing")) | |
1292 typing = TRUE; | |
1293 } else if(NSCHECK(y, "jabber:x:conference")) { | |
1294 conference_room = xmlnode_get_attrib(y, "jid"); | |
1295 } | |
1296 y = xmlnode_get_nextsibling(y); | |
3159 | 1297 } |
1298 | |
2086 | 1299 if (!type || !strcasecmp(type, "normal") || !strcasecmp(type, "chat")) { |
1300 | |
1301 from = jid_full(p->from); | |
1302 /* | |
1303 if ((y = xmlnode_get_tag(p->x, "html"))) { | |
1304 msg = xmlnode_get_data(y); | |
1305 } else | |
1306 */ | |
1307 if ((y = xmlnode_get_tag(p->x, "body"))) { | |
1308 msg = xmlnode_get_data(y); | |
1309 } | |
1310 | |
1311 if (!from) | |
1312 return; | |
1313 | |
3311 | 1314 if (conference_room) { |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1315 GList *m = NULL; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1316 char **data; |
2086 | 1317 |
3311 | 1318 data = g_strsplit(conference_room, "@", 2); |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1319 m = g_list_append(m, g_strdup(data[0])); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1320 m = g_list_append(m, g_strdup(data[1])); |
2956 | 1321 m = g_list_append(m, g_strdup(gjc->user->user)); |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1322 g_strfreev(data); |
2086 | 1323 |
3311 | 1324 serv_got_chat_invite(GJ_GC(gjc), conference_room, from, msg, m); |
2086 | 1325 } else if (msg) { /* whisper */ |
1326 struct jabber_chat *jc; | |
1327 g_snprintf(m, sizeof(m), "%s", msg); | |
2956 | 1328 if (((jc = find_existing_chat(GJ_GC(gjc), p->from)) != NULL) && jc->b) |
3311 | 1329 serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 1, m, |
1330 time_sent); | |
2086 | 1331 else { |
2278
00a8b7bcef6c
[gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2232
diff
changeset
|
1332 int flags = 0; |
3311 | 1333 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), jid_full(p->from)); |
1334 if(jri && typing) | |
1335 jri->has_composing = TRUE; | |
2278
00a8b7bcef6c
[gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2232
diff
changeset
|
1336 if (xmlnode_get_tag(p->x, "gaim")) |
00a8b7bcef6c
[gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2232
diff
changeset
|
1337 flags = IM_FLAG_GAIMUSER; |
3311 | 1338 if ((y = xmlnode_get_tag(p->x, "thread"))) |
1339 jabber_track_convo_thread(gjc, jid_full(p->from), | |
1340 xmlnode_get_data(y)); | |
2086 | 1341 if (find_conversation(jid_full(p->from))) |
3311 | 1342 serv_got_im(GJ_GC(gjc), jid_full(p->from), m, flags, |
1343 time_sent, -1); | |
2086 | 1344 else { |
2956 | 1345 if(p->from->user) { |
3311 | 1346 from = g_strdup_printf("%s@%s", p->from->user, |
1347 p->from->server); | |
2956 | 1348 } else { |
3311 | 1349 /* server message? */ |
1350 from = g_strdup(p->from->server); | |
2956 | 1351 } |
3159 | 1352 serv_got_im(GJ_GC(gjc), from, m, flags, time_sent, -1); |
2086 | 1353 g_free(from); |
1354 } | |
1355 } | |
3311 | 1356 } else { |
1357 /* a non-message message! */ | |
1358 from = g_strdup_printf("%s@%s", p->from->user, p->from->server); | |
1359 if(typing) | |
1360 serv_got_typing(GJ_GC(gjc), from, 0); | |
1361 else | |
1362 serv_got_typing_stopped(GJ_GC(gjc), from); | |
1363 g_free(from); | |
2086 | 1364 } |
1365 | |
1366 } else if (!strcasecmp(type, "error")) { | |
1367 if ((y = xmlnode_get_tag(p->x, "error"))) { | |
1368 type = xmlnode_get_attrib(y, "code"); | |
1369 msg = xmlnode_get_data(y); | |
1370 } | |
1371 | |
1372 if (msg) { | |
3427 | 1373 from = g_strdup_printf(_("Jabber Error %s"), type ? type : ""); |
1374 do_error_dialog(from, msg, GAIM_ERROR); | |
2086 | 1375 g_free(from); |
1376 } | |
1377 } else if (!strcasecmp(type, "groupchat")) { | |
1378 struct jabber_chat *jc; | |
1379 static int i = 0; | |
1380 | |
1381 /* | |
1382 if ((y = xmlnode_get_tag(p->x, "html"))) { | |
1383 msg = xmlnode_get_data(y); | |
1384 } else | |
1385 */ | |
1386 if ((y = xmlnode_get_tag(p->x, "body"))) { | |
1387 msg = xmlnode_get_data(y); | |
1388 } | |
1389 | |
1390 if ((subj = xmlnode_get_tag(p->x, "subject"))) { | |
1391 topic = xmlnode_get_data(subj); | |
1392 } | |
1393 | |
2956 | 1394 jc = find_existing_chat(GJ_GC(gjc), p->from); |
2086 | 1395 if (!jc) { |
1396 /* we're not in this chat. are we supposed to be? */ | |
2956 | 1397 if ((jc = find_pending_chat(GJ_GC(gjc), p->from)) != NULL) { |
2086 | 1398 /* yes, we're supposed to be. so now we are. */ |
2956 | 1399 jc->b = serv_got_joined_chat(GJ_GC(gjc), i++, p->from->user); |
2086 | 1400 jc->id = jc->b->id; |
2956 | 1401 jc->state = JCS_ACTIVE; |
2086 | 1402 } else { |
1403 /* no, we're not supposed to be. */ | |
1404 g_free(msg); | |
1405 return; | |
1406 } | |
1407 } | |
1408 if (p->from->resource) { | |
1409 if (!y) { | |
2956 | 1410 if (!find_chat_buddy(jc->b, p->from->resource)) { |
2086 | 1411 add_chat_buddy(jc->b, p->from->resource); |
2956 | 1412 } else if ((y = xmlnode_get_tag(p->x, "status"))) { |
3311 | 1413 jabber_track_away(gjc, p, NULL); |
2086 | 1414 } |
1415 } else if (jc->b && msg) { | |
1416 char buf[8192]; | |
1417 | |
1418 if (topic) { | |
1419 char tbuf[8192]; | |
1420 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); | |
1421 chat_set_topic(jc->b, p->from->resource, tbuf); | |
1422 } | |
1423 | |
1424 g_snprintf(buf, sizeof(buf), "%s", msg); | |
3311 | 1425 serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 0, buf, |
1426 time_sent); | |
2086 | 1427 } |
1428 } else { /* message from the server */ | |
1429 if(jc->b && topic) { | |
1430 char tbuf[8192]; | |
1431 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); | |
1432 chat_set_topic(jc->b, "", tbuf); | |
1433 } | |
1434 } | |
1435 | |
1436 } else { | |
1437 debug_printf("unhandled message %s\n", type); | |
1438 } | |
1439 } | |
3159 | 1440 |
2956 | 1441 static void jabber_handlepresence(gjconn gjc, jpacket p) |
2086 | 1442 { |
1443 char *to, *from, *type; | |
1444 struct buddy *b = NULL; | |
3311 | 1445 gaim_jid gjid; |
2086 | 1446 char *buddy; |
3194 | 1447 xmlnode y; |
2086 | 1448 char *show; |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
1449 int state = 0; |
2086 | 1450 struct conversation *cnv = NULL; |
1451 struct jabber_chat *jc = NULL; | |
3311 | 1452 int priority = 0; |
1453 struct jabber_buddy_data *jbd; | |
1454 | |
2086 | 1455 to = xmlnode_get_attrib(p->x, "to"); |
1456 from = xmlnode_get_attrib(p->x, "from"); | |
1457 type = xmlnode_get_attrib(p->x, "type"); | |
3150 | 1458 |
3311 | 1459 if((buddy = get_realwho(gjc, from, FALSE, &gjid)) == NULL) |
1460 return; | |
1461 | |
1462 if (gjid->user == NULL) { | |
1463 /* FIXME: transport */ | |
1464 g_free(buddy); | |
1465 gaim_jid_free(gjid); | |
1466 return; | |
1467 } | |
1468 | |
1469 jbd = jabber_find_buddy(GJ_GC(gjc), buddy); | |
1470 | |
1471 if(jbd->error_msg) { | |
1472 g_free(jbd->error_msg); | |
1473 jbd->error_msg = NULL; | |
1474 } | |
1475 | |
3259 | 1476 if(type && !strcasecmp(type, "error")) { |
1477 state = UC_ERROR; | |
3311 | 1478 if((y = xmlnode_get_tag(p->x, "error")) != NULL) { |
1479 jbd->error_msg = g_strdup_printf(_("Error %s: %s"), | |
1480 xmlnode_get_attrib(y, "code"), xmlnode_get_data(y)); | |
1481 } else { | |
1482 jbd->error_msg = g_strdup(_("Unknown Error in presence")); | |
1483 } | |
3259 | 1484 } else { |
1485 if ((y = xmlnode_get_tag(p->x, "show"))) { | |
1486 show = xmlnode_get_data(y); | |
1487 if (!show) { | |
1488 state = 0; | |
1489 } else if (!strcasecmp(show, "away")) { | |
1490 state = UC_AWAY; | |
1491 } else if (!strcasecmp(show, "chat")) { | |
1492 state = UC_CHAT; | |
1493 } else if (!strcasecmp(show, "xa")) { | |
1494 state = UC_XA; | |
1495 } else if (!strcasecmp(show, "dnd")) { | |
1496 state = UC_DND; | |
1497 } | |
1498 } else { | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
1499 state = 0; |
2086 | 1500 } |
1501 } | |
1502 | |
3311 | 1503 if ((y = xmlnode_get_tag(p->x, "priority"))) |
1504 priority = atoi(xmlnode_get_data(y)); | |
2086 | 1505 |
1506 /* um. we're going to check if it's a chat. if it isn't, and there are pending | |
2956 | 1507 * chats, create the chat. if there aren't pending chats and we don't have the |
1508 * buddy on our list, simply bail out. */ | |
3311 | 1509 if ((cnv = find_chat(GJ_GC(gjc), gjid->user)) == NULL) { |
2086 | 1510 static int i = 0x70; |
3311 | 1511 if ((jc = find_pending_chat(GJ_GC(gjc), gjid)) != NULL) { |
1512 jc->b = cnv = serv_got_joined_chat(GJ_GC(gjc), i++, gjid->user); | |
2086 | 1513 jc->id = jc->b->id; |
2956 | 1514 jc->state = JCS_ACTIVE; |
1515 } else if ((b = find_buddy(GJ_GC(gjc), buddy)) == NULL) { | |
1516 g_free(buddy); | |
3311 | 1517 gaim_jid_free(gjid); |
2956 | 1518 return; |
2086 | 1519 } |
1520 } | |
1521 | |
3311 | 1522 if (type && (strcasecmp(type, "unavailable") == 0)) |
1523 jabber_remove_resource(GJ_GC(gjc), buddy, gjid->resource); | |
1524 else { | |
1525 jabber_track_resource(GJ_GC(gjc), buddy, gjid->resource, priority, state); | |
1526 | |
1527 /* keep track of away msg somewhat the same as the yahoo plugin */ | |
1528 jabber_track_away(gjc, p, type); | |
1529 } | |
1530 | |
1531 | |
2086 | 1532 if (!cnv) { |
3311 | 1533 /* this is where we handle presence information for "regular" buddies */ |
1534 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), buddy); | |
1535 if(jri) { | |
1536 serv_got_update(GJ_GC(gjc), buddy, 1, 0, b->signon, b->idle, jri->state, 0); | |
1537 } else | |
1538 serv_got_update(GJ_GC(gjc), buddy, 0, 0, 0, 0, 0, 0); | |
1539 | |
2086 | 1540 } else { |
3311 | 1541 if (gjid->resource) { |
3259 | 1542 if (type && (!strcasecmp(type, "unavailable"))) { |
2086 | 1543 struct jabber_data *jd; |
3311 | 1544 if (!jc && !(jc = find_existing_chat(GJ_GC(gjc), gjid))) { |
2086 | 1545 g_free(buddy); |
3311 | 1546 gaim_jid_free(gjid); |
2086 | 1547 return; |
1548 } | |
1549 jd = jc->gc->proto_data; | |
2956 | 1550 /* if it's not ourselves...*/ |
3311 | 1551 if (strcmp(gjid->resource, jc->gjid->resource) && jc->b) { |
1552 remove_chat_buddy(jc->b, gjid->resource, NULL); | |
2086 | 1553 g_free(buddy); |
3311 | 1554 gaim_jid_free(gjid); |
2086 | 1555 return; |
1556 } | |
2956 | 1557 |
1558 jc->state = JCS_CLOSED; | |
1559 serv_got_chat_left(GJ_GC(gjc), jc->id); | |
1560 /* | |
1561 * TBD: put back some day? | |
1562 jd->chats = g_slist_remove(jd->chats, jc); | |
1563 g_free(jc); | |
1564 */ | |
1565 } else { | |
3311 | 1566 if ((!jc && !(jc = find_existing_chat(GJ_GC(gjc), gjid))) || !jc->b) { |
2956 | 1567 g_free(buddy); |
3311 | 1568 gaim_jid_free(gjid); |
2956 | 1569 return; |
1570 } | |
3311 | 1571 if (!find_chat_buddy(jc->b, gjid->resource)) { |
1572 add_chat_buddy(jc->b, gjid->resource); | |
2086 | 1573 } |
1574 } | |
1575 } | |
1576 } | |
1577 | |
1578 g_free(buddy); | |
3311 | 1579 gaim_jid_free(gjid); |
2086 | 1580 |
1581 return; | |
1582 } | |
1583 | |
3229 | 1584 /* |
1585 * Used only by Jabber accept/deny add stuff just below | |
1586 */ | |
1587 struct jabber_add_permit { | |
1588 gjconn gjc; | |
1589 gchar *user; | |
1590 }; | |
1591 | |
1592 /* | |
1593 * Common part for Jabber accept/deny adds | |
1594 * | |
1595 * "type" says whether we'll permit/deny the subscribe request | |
1596 */ | |
1597 static void jabber_accept_deny_add(struct jabber_add_permit *jap, const char *type) | |
1598 { | |
1599 xmlnode g = xmlnode_new_tag("presence"); | |
1600 | |
1601 xmlnode_put_attrib(g, "to", jap->user); | |
1602 xmlnode_put_attrib(g, "type", type); | |
1603 gjab_send(jap->gjc, g); | |
1604 | |
1605 xmlnode_free(g); | |
1606 } | |
1607 | |
1608 /* | |
1609 * Callback from "accept" in do_ask_dialog() invoked by jabber_handles10n() | |
1610 */ | |
1611 static void jabber_accept_add(gpointer w, struct jabber_add_permit *jap) | |
1612 { | |
1613 jabber_accept_deny_add(jap, "subscribed"); | |
1614 /* | |
1615 * If we don't already have the buddy on *our* buddylist, | |
1616 * ask if we want him or her added. | |
1617 */ | |
1618 if(find_buddy(GJ_GC(jap->gjc), jap->user) == NULL) { | |
1619 show_got_added(GJ_GC(jap->gjc), NULL, jap->user, NULL, NULL); | |
1620 } | |
1621 g_free(jap->user); | |
1622 g_free(jap); | |
1623 } | |
1624 | |
1625 /* | |
1626 * Callback from "deny/cancel" in do_ask_dialog() invoked by jabber_handles10n() | |
1627 */ | |
1628 static void jabber_deny_add(gpointer w, struct jabber_add_permit *jap) | |
1629 { | |
1630 jabber_accept_deny_add(jap, "unsubscribed"); | |
1631 g_free(jap->user); | |
1632 g_free(jap); | |
1633 } | |
1634 | |
1635 /* | |
1636 * Handle subscription requests | |
1637 */ | |
2956 | 1638 static void jabber_handles10n(gjconn gjc, jpacket p) |
2086 | 1639 { |
1640 xmlnode g; | |
1641 char *Jid = xmlnode_get_attrib(p->x, "from"); | |
3136 | 1642 char *type = xmlnode_get_attrib(p->x, "type"); |
2086 | 1643 |
1644 g = xmlnode_new_tag("presence"); | |
1645 xmlnode_put_attrib(g, "to", Jid); | |
3229 | 1646 |
1647 if (!strcmp(type, "subscribe")) { | |
1648 /* | |
1649 * A "subscribe to us" request was received - put up the approval dialog | |
1650 */ | |
1651 struct jabber_add_permit *jap = g_new0(struct jabber_add_permit, 1); | |
1652 gchar *msg = g_strdup_printf(_("The user %s wants to add you to their buddy list."), | |
1653 Jid); | |
1654 | |
1655 jap->gjc = gjc; | |
1656 jap->user = g_strdup(Jid); | |
1657 do_ask_dialog(msg, jap, jabber_accept_add, jabber_deny_add); | |
1658 | |
1659 g_free(msg); | |
1660 xmlnode_free(g); /* Never needed it here anyway */ | |
1661 return; | |
1662 | |
1663 } else if (!strcmp(type, "unsubscribe")) { | |
1664 /* | |
1665 * An "unsubscribe to us" was received - simply "approve" it | |
1666 */ | |
2086 | 1667 xmlnode_put_attrib(g, "type", "unsubscribed"); |
3229 | 1668 } else { |
1669 /* | |
1670 * Did we attempt to subscribe to somebody and they do not exist? | |
1671 */ | |
3136 | 1672 if (!strcmp(type, "unsubscribed")) { |
1673 xmlnode y; | |
1674 char *status; | |
1675 if((y = xmlnode_get_tag(p->x, "status")) && (status = xmlnode_get_data(y)) && | |
1676 !strcmp(status, "Not Found")) { | |
3427 | 1677 char *msg = g_strdup_printf(_("The Jabber user %s does not exist and was therefore " |
1678 "not added to your roster."), | |
1679 xmlnode_get_attrib(p->x, "from")); | |
1680 do_error_dialog(_("No such user."), msg, GAIM_ERROR ); | |
3136 | 1681 g_free(msg); |
1682 } | |
1683 } | |
1684 | |
2956 | 1685 xmlnode_free(g); |
2086 | 1686 return; |
2956 | 1687 } |
1688 | |
1689 gjab_send(gjc, g); | |
1690 xmlnode_free(g); | |
2086 | 1691 } |
1692 | |
2956 | 1693 /* |
1694 * Pending subscription to a buddy? | |
1695 */ | |
1696 #define BUD_SUB_TO_PEND(sub, ask) ((!strcasecmp((sub), "none") || !strcasecmp((sub), "from")) && \ | |
1697 (ask) != NULL && !strcasecmp((ask), "subscribe")) | |
1698 | |
1699 /* | |
1700 * Subscribed to a buddy? | |
1701 */ | |
1702 #define BUD_SUBD_TO(sub, ask) ((!strcasecmp((sub), "to") || !strcasecmp((sub), "both")) && \ | |
1703 ((ask) == NULL || !strcasecmp((ask), "subscribe"))) | |
1704 | |
1705 /* | |
1706 * Pending unsubscription to a buddy? | |
1707 */ | |
1708 #define BUD_USUB_TO_PEND(sub, ask) ((!strcasecmp((sub), "to") || !strcasecmp((sub), "both")) && \ | |
1709 (ask) != NULL && !strcasecmp((ask), "unsubscribe")) | |
1710 | |
1711 /* | |
1712 * Unsubscribed to a buddy? | |
1713 */ | |
1714 #define BUD_USUBD_TO(sub, ask) ((!strcasecmp((sub), "none") || !strcasecmp((sub), "from")) && \ | |
1715 ((ask) == NULL || !strcasecmp((ask), "unsubscribe"))) | |
1716 | |
1717 /* | |
1718 * If a buddy is added or removed from the roster on another resource | |
1719 * jabber_handlebuddy is called | |
1720 * | |
1721 * Called with roster item node. | |
1722 */ | |
1723 static void jabber_handlebuddy(gjconn gjc, xmlnode x) | |
1724 { | |
1725 xmlnode g; | |
3311 | 1726 char *who, *name, *sub, *ask; |
1727 gaim_jid gjid; | |
2956 | 1728 struct buddy *b = NULL; |
3136 | 1729 char *buddyname, *groupname = NULL; |
2956 | 1730 |
3311 | 1731 who = xmlnode_get_attrib(x, "jid"); |
2956 | 1732 name = xmlnode_get_attrib(x, "name"); |
1733 sub = xmlnode_get_attrib(x, "subscription"); | |
1734 ask = xmlnode_get_attrib(x, "ask"); | |
3311 | 1735 |
1736 if((buddyname = get_realwho(gjc, who, FALSE, &gjid)) == NULL) | |
1737 return; | |
2956 | 1738 |
1739 /* JFIXME: jabber_handleroster() had a "FIXME: transport" at this | |
1740 * equivilent point. So... | |
1741 * | |
3311 | 1742 * We haven't done anything interesting to this point, so we'll |
1743 * violate Good Coding Structure here by simply bailing out. | |
2956 | 1744 */ |
3311 | 1745 if(!gjid->user) { |
1746 g_free(buddyname); | |
1747 gaim_jid_free(gjid); | |
2956 | 1748 return; |
1749 } | |
3311 | 1750 gaim_jid_free(gjid); |
2956 | 1751 |
3236 | 1752 if((g = xmlnode_get_tag(x, "group")) != NULL) { |
3136 | 1753 groupname = xmlnode_get_data(g); |
2956 | 1754 } |
1755 | |
3059 | 1756 /* |
3136 | 1757 * Add or remove a buddy? Change buddy's alias or group? |
3059 | 1758 */ |
2956 | 1759 if (BUD_SUB_TO_PEND(sub, ask) || BUD_SUBD_TO(sub, ask)) { |
1760 if ((b = find_buddy(GJ_GC(gjc), buddyname)) == NULL) { | |
1761 debug_printf("adding buddy [4]: %s\n", buddyname); | |
3136 | 1762 b = add_buddy(GJ_GC(gjc), groupname ? groupname : _("Buddies"), buddyname, |
2956 | 1763 name ? name : buddyname); |
1764 do_export(GJ_GC(gjc)); | |
3136 | 1765 } else { |
1766 struct group *c_grp = find_group_by_buddy(GJ_GC(gjc), buddyname); | |
1767 | |
1768 /* | |
1769 * If the buddy's in a new group or his/her alias is changed... | |
1770 */ | |
1771 if(groupname && c_grp && strcmp(c_grp->name, groupname)) { | |
1772 int present = b->present; /* save presence state */ | |
1773 int uc = b->uc; /* and away state (?) */ | |
3150 | 1774 int idle = b->idle; |
1775 int signon = b->signon; | |
3136 | 1776 |
1777 /* | |
1778 * seems rude, but it seems to be the only way... | |
1779 */ | |
1780 remove_buddy(GJ_GC(gjc), c_grp, b); | |
1781 b = add_buddy(GJ_GC(gjc), groupname, buddyname, | |
1782 name ? name : buddyname); | |
1783 do_export(GJ_GC(gjc)); | |
1784 if(present) { | |
3311 | 1785 serv_got_update(GJ_GC(gjc), buddyname, 1, 0, signon, idle, |
1786 uc, 0); | |
3136 | 1787 } |
1788 } else if(name != NULL && strcmp(b->show, name)) { | |
1789 strncpy(b->show, name, BUDDY_ALIAS_MAXLEN); | |
1790 b->show[BUDDY_ALIAS_MAXLEN - 1] = '\0'; /* cheap safety feature */ | |
1791 handle_buddy_rename(b, buddyname); | |
1792 } | |
2956 | 1793 } |
1794 } else if (BUD_USUB_TO_PEND(sub, ask) || BUD_USUBD_TO(sub, ask) || !strcasecmp(sub, "remove")) { | |
3236 | 1795 jabber_remove_gaim_buddy(GJ_GC(gjc), buddyname); |
2956 | 1796 } |
3328 | 1797 |
2956 | 1798 g_free(buddyname); |
1799 | |
1800 } | |
1801 | |
1802 static void jabber_handleroster(gjconn gjc, xmlnode querynode) | |
2086 | 1803 { |
1804 xmlnode x; | |
1805 | |
1806 x = xmlnode_get_firstchild(querynode); | |
1807 while (x) { | |
2956 | 1808 jabber_handlebuddy(gjc, x); |
2086 | 1809 x = xmlnode_get_nextsibling(x); |
1810 } | |
1811 | |
1812 x = jutil_presnew(0, NULL, "Online"); | |
2956 | 1813 gjab_send(gjc, x); |
2086 | 1814 xmlnode_free(x); |
1815 } | |
1816 | |
2956 | 1817 static void jabber_handleauthresp(gjconn gjc, jpacket p) |
2086 | 1818 { |
1819 if (jpacket_subtype(p) == JPACKET__RESULT) { | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1820 if (xmlnode_has_children(p->x)) { |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1821 xmlnode query = xmlnode_get_tag(p->x, "query"); |
2975 | 1822 set_login_progress(GJ_GC(gjc), 4, _("Authenticating")); |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1823 if (!xmlnode_get_tag(query, "digest")) { |
2956 | 1824 g_free(gjc->sid); |
1825 gjc->sid = NULL; | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1826 } |
2956 | 1827 gjab_auth(gjc); |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1828 } else { |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1829 debug_printf("auth success\n"); |
2086 | 1830 |
2956 | 1831 account_online(GJ_GC(gjc)); |
1832 serv_finish_login(GJ_GC(gjc)); | |
1833 | |
1834 if (bud_list_cache_exists(GJ_GC(gjc))) | |
1835 do_import(GJ_GC(gjc), NULL); | |
1836 | |
1837 ((struct jabber_data *)GJ_GC(gjc)->proto_data)->did_import = TRUE; | |
1838 | |
1839 gjab_reqroster(gjc); | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1840 } |
2086 | 1841 } else { |
1842 xmlnode xerr; | |
1843 char *errmsg = NULL; | |
1844 int errcode = 0; | |
2956 | 1845 struct jabber_data *jd = GJ_GC(gjc)->proto_data; |
2086 | 1846 |
1847 debug_printf("auth failed\n"); | |
1848 xerr = xmlnode_get_tag(p->x, "error"); | |
1849 if (xerr) { | |
1850 char msg[BUF_LONG]; | |
1851 errmsg = xmlnode_get_data(xerr); | |
1852 if (xmlnode_get_attrib(xerr, "code")) { | |
1853 errcode = atoi(xmlnode_get_attrib(xerr, "code")); | |
1854 g_snprintf(msg, sizeof(msg), "Error %d: %s", errcode, errmsg); | |
1855 } else | |
1856 g_snprintf(msg, sizeof(msg), "%s", errmsg); | |
2956 | 1857 hide_login_progress(GJ_GC(gjc), msg); |
2086 | 1858 } else { |
2975 | 1859 hide_login_progress(GJ_GC(gjc), _("Unknown login error")); |
2086 | 1860 } |
1861 | |
2800
0ad63a625eec
[gaim-migrate @ 2813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1862 jd->die = TRUE; |
2086 | 1863 } |
1864 } | |
1865 | |
2956 | 1866 static void jabber_handleversion(gjconn gjc, xmlnode iqnode) { |
2086 | 1867 xmlnode querynode, x; |
1868 char *id, *from; | |
1869 char os[1024]; | |
1870 struct utsname osinfo; | |
1871 | |
1872 uname(&osinfo); | |
1873 g_snprintf(os, sizeof os, "%s %s %s", osinfo.sysname, osinfo.release, osinfo.machine); | |
1874 | |
1875 id = xmlnode_get_attrib(iqnode, "id"); | |
1876 from = xmlnode_get_attrib(iqnode, "from"); | |
1877 | |
1878 x = jutil_iqnew(JPACKET__RESULT, NS_VERSION); | |
1879 | |
1880 xmlnode_put_attrib(x, "to", from); | |
1881 xmlnode_put_attrib(x, "id", id); | |
1882 querynode = xmlnode_get_tag(x, "query"); | |
1883 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "name"), PACKAGE, -1); | |
1884 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "version"), VERSION, -1); | |
1885 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "os"), os, -1); | |
1886 | |
2956 | 1887 gjab_send(gjc, x); |
2086 | 1888 |
1889 xmlnode_free(x); | |
1890 } | |
1891 | |
2956 | 1892 static void jabber_handletime(gjconn gjc, xmlnode iqnode) { |
2086 | 1893 xmlnode querynode, x; |
1894 char *id, *from; | |
1895 time_t now_t; | |
1896 struct tm *now; | |
1897 char buf[1024]; | |
1898 | |
1899 time(&now_t); | |
1900 now = localtime(&now_t); | |
1901 | |
1902 id = xmlnode_get_attrib(iqnode, "id"); | |
1903 from = xmlnode_get_attrib(iqnode, "from"); | |
1904 | |
1905 x = jutil_iqnew(JPACKET__RESULT, NS_TIME); | |
1906 | |
1907 xmlnode_put_attrib(x, "to", from); | |
1908 xmlnode_put_attrib(x, "id", id); | |
1909 querynode = xmlnode_get_tag(x, "query"); | |
1910 | |
1911 strftime(buf, 1024, "%Y%m%dT%T", now); | |
1912 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "utc"), buf, -1); | |
1913 strftime(buf, 1024, "%Z", now); | |
1914 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "tz"), buf, -1); | |
1915 strftime(buf, 1024, "%d %b %Y %T", now); | |
1916 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "display"), buf, -1); | |
1917 | |
2956 | 1918 gjab_send(gjc, x); |
2086 | 1919 |
1920 xmlnode_free(x); | |
1921 } | |
1922 | |
3630 | 1923 struct jabber_file_transfer { |
1924 enum { JFT_SENDFILE_IN, JFT_SENDFILE_OUT } type; | |
1925 struct file_transfer *xfer; | |
1926 char *from; | |
1927 struct g_url *url; | |
1928 char *name; | |
1929 GString *headers; | |
1930 | |
1931 int len; | |
1932 int fd; | |
1933 int watcher; | |
1934 | |
1935 gboolean sentreq; | |
1936 gboolean newline; | |
1937 gboolean startsaving; | |
1938 | |
1939 struct gaim_connection *gc; | |
1940 }; | |
1941 | |
1942 static struct jabber_file_transfer *find_jft_by_xfer(struct gaim_connection *gc, | |
1943 struct file_transfer *xfer) { | |
1944 GSList *g = ((struct jabber_data *)gc->proto_data)->file_transfers; | |
1945 struct jabber_file_transfer *f = NULL; | |
1946 | |
1947 while(g) { | |
1948 f = (struct jabber_file_transfer *)g->data; | |
1949 if(f->xfer == xfer) | |
1950 break; | |
1951 g = g->next; | |
1952 f = NULL; | |
1953 } | |
1954 | |
1955 return f; | |
1956 } | |
1957 | |
1958 static void jabber_http_recv_callback(gpointer data, gint source, GaimInputCondition condition) { | |
1959 struct jabber_file_transfer *jft = data; | |
1960 char test; | |
1961 | |
1962 jft->fd = source; | |
1963 if(!jft->sentreq) { | |
1964 char buf[1024]; | |
1965 g_snprintf(buf, sizeof(buf), "GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n", jft->url->page, jft->url->address); | |
1966 write(source, buf, strlen(buf)); | |
3667
11ab2a5f6677
[gaim-migrate @ 3796]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3664
diff
changeset
|
1967 #ifndef _WIN32 |
3630 | 1968 fcntl(source, F_SETFL, O_NONBLOCK); |
3667
11ab2a5f6677
[gaim-migrate @ 3796]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3664
diff
changeset
|
1969 #else |
11ab2a5f6677
[gaim-migrate @ 3796]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3664
diff
changeset
|
1970 { |
11ab2a5f6677
[gaim-migrate @ 3796]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3664
diff
changeset
|
1971 u_long imode = 1; |
11ab2a5f6677
[gaim-migrate @ 3796]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3664
diff
changeset
|
1972 ioctlsocket(source, FIONBIO, (u_long*)&imode); |
11ab2a5f6677
[gaim-migrate @ 3796]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3664
diff
changeset
|
1973 } |
11ab2a5f6677
[gaim-migrate @ 3796]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3664
diff
changeset
|
1974 #endif |
3630 | 1975 jft->sentreq = TRUE; |
1976 jft->watcher = gaim_input_add(source, GAIM_INPUT_READ, jabber_http_recv_callback,data); | |
1977 return; | |
1978 } | |
1979 | |
1980 if(!jft->startsaving) { | |
3667
11ab2a5f6677
[gaim-migrate @ 3796]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3664
diff
changeset
|
1981 #ifndef _WIN32 |
3630 | 1982 if(read(source, &test, sizeof(test)) > 0 || errno == EWOULDBLOCK) { |
3667
11ab2a5f6677
[gaim-migrate @ 3796]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3664
diff
changeset
|
1983 if(errno == EWOULDBLOCK) |
11ab2a5f6677
[gaim-migrate @ 3796]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3664
diff
changeset
|
1984 #else |
11ab2a5f6677
[gaim-migrate @ 3796]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3664
diff
changeset
|
1985 if(recv(source, &test, sizeof(test), 0) > 0 || WSAGetLastError() == WSAEWOULDBLOCK) { |
11ab2a5f6677
[gaim-migrate @ 3796]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3664
diff
changeset
|
1986 if(WSAEWOULDBLOCK == WSAGetLastError()) |
11ab2a5f6677
[gaim-migrate @ 3796]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3664
diff
changeset
|
1987 #endif |
11ab2a5f6677
[gaim-migrate @ 3796]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3664
diff
changeset
|
1988 { |
3630 | 1989 errno = 0; |
1990 return; | |
1991 } | |
1992 | |
1993 jft->headers = g_string_append_c(jft->headers, test); | |
1994 if(test == '\r') | |
1995 return; | |
1996 if(test == '\n') { | |
1997 if(jft->newline) { | |
1998 gchar *lenstr = strstr(jft->headers->str, "Content-Length: "); | |
1999 if(lenstr) { | |
2000 sscanf(lenstr, "Content-Length: %d", &jft->len); | |
2001 } | |
2002 jft->startsaving = TRUE; | |
2003 } else | |
2004 jft->newline = TRUE; | |
2005 return; | |
2006 } | |
2007 jft->newline = FALSE; | |
2008 return; | |
2009 } else { | |
2010 gaim_input_remove(jft->watcher); | |
2011 close(source); | |
2012 //FIXME: ft_cancel(NULL, jft->xfer); | |
2013 } | |
2014 return; | |
2015 } | |
2016 | |
2017 /* we've parsed the headers, gotten the size, all is good. now we pass the reception of | |
2018 * the file off to the core, and leave it in it's capable...err...hands?? */ | |
2019 gaim_input_remove(jft->watcher); | |
2020 jft->watcher = 0; | |
2021 transfer_in_do(jft->xfer, jft->fd, jft->name, jft->len); | |
2022 } | |
2023 | |
2024 static void jabber_file_transfer_cancel(struct gaim_connection *gc, struct file_transfer *xfer) { | |
2025 struct jabber_data *jd = gc->proto_data; | |
2026 struct jabber_file_transfer *jft = find_jft_by_xfer(gc, xfer);\ | |
2027 xmlnode x,y; | |
2028 | |
2029 jd->file_transfers = g_slist_remove(jd->file_transfers, jft); | |
2030 | |
2031 gaim_input_remove(jft->watcher); | |
2032 close(jft->fd); | |
2033 | |
2034 x = xmlnode_new_tag("iq"); | |
2035 xmlnode_put_attrib(x, "type", "error"); | |
2036 xmlnode_put_attrib(x, "to", jft->from); | |
2037 y = xmlnode_insert_tag(x, "error"); | |
2038 /* FIXME: need to handle other kinds of errors here */ | |
2039 xmlnode_put_attrib(y, "code", "406"); | |
2040 xmlnode_insert_cdata(y, "File Transfer Refused", -1); | |
2041 | |
2042 gjab_send(jd->gjc, x); | |
2043 | |
2044 xmlnode_free(x); | |
2045 | |
2046 g_string_free(jft->headers, TRUE); | |
2047 g_free(jft->from); | |
2048 g_free(jft->url); | |
2049 g_free(jft->name); | |
2050 | |
2051 g_free(jft); | |
2052 } | |
2053 | |
2054 static void jabber_file_transfer_done(struct gaim_connection *gc, struct file_transfer *xfer) { | |
2055 struct jabber_data *jd = gc->proto_data; | |
2056 struct jabber_file_transfer *jft = find_jft_by_xfer(gc, xfer); | |
2057 xmlnode x; | |
2058 | |
2059 jd->file_transfers = g_slist_remove(jd->file_transfers, jft); | |
2060 | |
2061 gaim_input_remove(jft->watcher); | |
2062 close(jft->fd); | |
2063 | |
2064 x = xmlnode_new_tag("iq"); | |
2065 xmlnode_put_attrib(x, "type", "result"); | |
2066 xmlnode_put_attrib(x, "to", jft->from); | |
2067 | |
2068 gjab_send(jd->gjc, x); | |
2069 | |
2070 xmlnode_free(x); | |
2071 | |
2072 g_string_free(jft->headers, TRUE); | |
2073 g_free(jft->from); | |
2074 g_free(jft->url); | |
2075 g_free(jft->name); | |
2076 | |
2077 g_free(jft); | |
2078 } | |
2079 | |
2080 static void jabber_file_transfer_in(struct gaim_connection *gc, struct file_transfer *xfer, int offset) { | |
2081 struct jabber_file_transfer *jft = find_jft_by_xfer(gc, xfer); | |
2082 | |
2083 proxy_connect(jft->url->address, jft->url->port, jabber_http_recv_callback, jft); | |
2084 } | |
2085 | |
2086 static void jabber_handleoob(gjconn gjc, xmlnode iqnode) { | |
2087 struct jabber_file_transfer *jft; | |
2088 struct jabber_data *jd = GJ_GC(gjc)->proto_data; | |
2089 char *msg = NULL; | |
2090 xmlnode querynode = xmlnode_get_tag(iqnode, "query"); | |
2091 xmlnode urlnode,descnode; | |
2092 | |
2093 if(!querynode) | |
2094 return; | |
2095 urlnode = xmlnode_get_tag(querynode, "url"); | |
2096 if(!urlnode) | |
2097 return; | |
2098 descnode = xmlnode_get_tag(querynode, "desc"); | |
2099 if(descnode) | |
2100 msg = xmlnode_get_data(descnode); | |
2101 | |
2102 jft = g_new0(struct jabber_file_transfer, 1); | |
2103 jft->type = JFT_SENDFILE_IN; | |
2104 jft->gc = GJ_GC(gjc); | |
2105 jft->url = parse_url(xmlnode_get_data(urlnode)); | |
2106 jft->from = g_strdup(xmlnode_get_attrib(iqnode, "from")); | |
2107 jft->name = g_strdup(g_strrstr(jft->url->page,"/")); | |
2108 if (!jft->name) | |
2109 jft->name = g_strdup(jft->url->page); | |
2110 jft->headers = g_string_new(""); | |
2111 jft->len = -1; | |
2112 | |
2113 jd->file_transfers = g_slist_append(jd->file_transfers, jft); | |
2114 | |
2115 jft->xfer = transfer_in_add(GJ_GC(gjc), jft->from, jft->name, jft->len, 1, msg); | |
2116 } | |
2117 | |
2956 | 2118 static void jabber_handlelast(gjconn gjc, xmlnode iqnode) { |
3630 | 2119 xmlnode x, querytag; |
2086 | 2120 char *id, *from; |
2956 | 2121 struct jabber_data *jd = GJ_GC(gjc)->proto_data; |
2086 | 2122 char idle_time[32]; |
3630 | 2123 |
2086 | 2124 id = xmlnode_get_attrib(iqnode, "id"); |
2125 from = xmlnode_get_attrib(iqnode, "from"); | |
2126 | |
2127 x = jutil_iqnew(JPACKET__RESULT, "jabber:iq:last"); | |
2128 | |
2129 xmlnode_put_attrib(x, "to", from); | |
2130 xmlnode_put_attrib(x, "id", id); | |
2131 querytag = xmlnode_get_tag(x, "query"); | |
2132 g_snprintf(idle_time, sizeof idle_time, "%ld", jd->idle ? time(NULL) - jd->idle : 0); | |
2133 xmlnode_put_attrib(querytag, "seconds", idle_time); | |
2134 | |
2956 | 2135 gjab_send(gjc, x); |
2086 | 2136 xmlnode_free(x); |
2137 } | |
2138 | |
2956 | 2139 /* |
2140 * delete == TRUE: delete found entry | |
2141 * | |
2142 * returns pointer to (local) copy of value if found, NULL otherwise | |
2143 * | |
2144 * Note: non-reentrant! Local static storage re-used on subsequent calls. | |
2145 * If you're going to need to keep the returned value, make a copy! | |
2146 */ | |
2147 static gchar *jabber_track_queries(GHashTable *queries, gchar *key, gboolean delete) | |
2148 { | |
2149 gpointer my_key, my_val; | |
2150 static gchar *ret_val = NULL; | |
2151 | |
2152 if(ret_val != NULL) { | |
2153 g_free(ret_val); | |
2154 ret_val = NULL; | |
2155 } | |
2156 | |
2157 /* self-protection */ | |
2158 if(queries != NULL && key != NULL) { | |
2159 if(g_hash_table_lookup_extended(queries, key, &my_key, &my_val)) { | |
2160 ret_val = g_strdup((gchar *) my_val); | |
2161 if(delete) { | |
2162 g_hash_table_remove(queries, key); | |
2163 g_free(my_key); | |
2164 g_free(my_val); | |
2165 } | |
2166 } | |
2167 } | |
2168 | |
2169 return(ret_val); | |
2170 } | |
2171 | |
2172 static void jabber_handlepacket(gjconn gjc, jpacket p) | |
2086 | 2173 { |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
2174 char *id; |
2086 | 2175 switch (p->type) { |
2176 case JPACKET_MESSAGE: | |
2956 | 2177 jabber_handlemessage(gjc, p); |
2086 | 2178 break; |
2179 case JPACKET_PRESENCE: | |
2956 | 2180 jabber_handlepresence(gjc, p); |
2086 | 2181 break; |
2182 case JPACKET_IQ: | |
2183 debug_printf("jpacket_subtype: %d\n", jpacket_subtype(p)); | |
2184 | |
2956 | 2185 id = xmlnode_get_attrib(p->x, "id"); |
2186 if (id != NULL && !strcmp(id, IQID_AUTH)) { | |
2187 jabber_handleauthresp(gjc, p); | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
2188 break; |
2086 | 2189 } |
2190 | |
2191 if (jpacket_subtype(p) == JPACKET__SET) { | |
2956 | 2192 xmlnode querynode; |
2193 querynode = xmlnode_get_tag(p->x, "query"); | |
2194 if (NSCHECK(querynode, "jabber:iq:roster")) { | |
2195 jabber_handlebuddy(gjc, xmlnode_get_firstchild(querynode)); | |
3630 | 2196 } else if(NSCHECK(querynode, "jabber:iq:oob")) { |
2197 jabber_handleoob(gjc, p->x); | |
2956 | 2198 } |
2086 | 2199 } else if (jpacket_subtype(p) == JPACKET__GET) { |
2200 xmlnode querynode; | |
2201 querynode = xmlnode_get_tag(p->x, "query"); | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
2202 if (NSCHECK(querynode, NS_VERSION)) { |
2956 | 2203 jabber_handleversion(gjc, p->x); |
2086 | 2204 } else if (NSCHECK(querynode, NS_TIME)) { |
2956 | 2205 jabber_handletime(gjc, p->x); |
2086 | 2206 } else if (NSCHECK(querynode, "jabber:iq:last")) { |
2956 | 2207 jabber_handlelast(gjc, p->x); |
2086 | 2208 } |
2209 } else if (jpacket_subtype(p) == JPACKET__RESULT) { | |
2210 xmlnode querynode, vcard; | |
2211 char *xmlns, *from; | |
2212 | |
2956 | 2213 /* |
2214 * TBD: ISTM maybe this part could use a serious re-work? | |
2215 */ | |
2086 | 2216 from = xmlnode_get_attrib(p->x, "from"); |
2217 querynode = xmlnode_get_tag(p->x, "query"); | |
2218 vcard = xmlnode_get_tag(p->x, "vCard"); | |
2316
ebb5ecb2cd5b
[gaim-migrate @ 2326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
2219 if (!vcard) |
ebb5ecb2cd5b
[gaim-migrate @ 2326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
2220 vcard = xmlnode_get_tag(p->x, "VCARD"); |
2086 | 2221 |
2222 if (NSCHECK(querynode, NS_ROSTER)) { | |
2956 | 2223 jabber_handleroster(gjc, querynode); |
2086 | 2224 } else if (NSCHECK(querynode, NS_VCARD)) { |
2956 | 2225 jabber_track_queries(gjc->queries, id, TRUE); /* delete query track */ |
2226 jabber_handlevcard(gjc, querynode, from); | |
2316
ebb5ecb2cd5b
[gaim-migrate @ 2326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
2227 } else if (vcard) { |
2956 | 2228 jabber_track_queries(gjc->queries, id, TRUE); /* delete query track */ |
2229 jabber_handlevcard(gjc, vcard, from); | |
2230 } else if((xmlns = xmlnode_get_attrib(querynode, "xmlns")) != NULL) { | |
2231 debug_printf("jabber:iq:query: %s\n", xmlns); | |
2086 | 2232 } else { |
2956 | 2233 char *val; |
2234 | |
2235 debug_printf("jabber:iq: %s\n", xmlnode2str(p->x)); | |
2236 | |
2237 /* handle "null" query results */ | |
2238 if((val = jabber_track_queries(gjc->queries, id, TRUE)) != NULL) { | |
2239 if(strcmp((char *) val, "vCard") == 0) { | |
2240 /* | |
2241 * No actual vCard, but there's other stuff. This | |
2242 * way the user always gets some kind of response. | |
2243 */ | |
2244 jabber_handlevcard(gjc, NULL, from); | |
3257 | 2245 } else if(!strcmp((char *) val, "change_password")) { |
2246 char buf[BUF_LONG]; | |
3311 | 2247 sprintf(buf, _("Password successfully changed.")); |
3257 | 2248 |
3427 | 2249 do_error_dialog(buf, NULL, GAIM_INFO); |
2956 | 2250 } |
2251 } | |
2086 | 2252 } |
2253 | |
2254 } else if (jpacket_subtype(p) == JPACKET__ERROR) { | |
2255 xmlnode xerr; | |
2256 char *from, *errmsg = NULL; | |
2257 int errcode = 0; | |
2258 | |
2259 from = xmlnode_get_attrib(p->x, "from"); | |
2260 xerr = xmlnode_get_tag(p->x, "error"); | |
2261 if (xerr) { | |
2262 errmsg = xmlnode_get_data(xerr); | |
2263 if (xmlnode_get_attrib(xerr, "code")) | |
2264 errcode = atoi(xmlnode_get_attrib(xerr, "code")); | |
2265 } | |
2266 | |
3427 | 2267 from = g_strdup_printf("Jabber Error %d (%s)", errcode, from); |
2268 do_error_dialog(from, errmsg, GAIM_ERROR); | |
2086 | 2269 g_free(from); |
2270 | |
2271 } | |
2272 | |
2273 break; | |
2274 case JPACKET_S10N: | |
2956 | 2275 jabber_handles10n(gjc, p); |
2086 | 2276 break; |
2277 default: | |
2278 debug_printf("jabber: packet type %d (%s)\n", p->type, xmlnode2str(p->x)); | |
2279 } | |
2280 | |
2281 xmlnode_free(p->x); | |
2282 | |
2283 return; | |
2284 } | |
2285 | |
2956 | 2286 static void jabber_handlestate(gjconn gjc, int state) |
2086 | 2287 { |
2288 switch (state) { | |
2289 case JCONN_STATE_OFF: | |
3074 | 2290 if(gjc->was_connected) { |
2291 hide_login_progress_error(GJ_GC(gjc), _("Connection lost")); | |
2292 } else { | |
2293 hide_login_progress(GJ_GC(gjc), _("Unable to connect")); | |
2294 } | |
2956 | 2295 signoff(GJ_GC(gjc)); |
2086 | 2296 break; |
2297 case JCONN_STATE_CONNECTED: | |
3074 | 2298 gjc->was_connected = 1; |
2975 | 2299 set_login_progress(GJ_GC(gjc), 2, _("Connected")); |
2086 | 2300 break; |
2301 case JCONN_STATE_ON: | |
2975 | 2302 set_login_progress(GJ_GC(gjc), 3, _("Requesting Authentication Method")); |
2956 | 2303 gjab_reqauth(gjc); |
2086 | 2304 break; |
2305 default: | |
2306 debug_printf("state change: %d\n", state); | |
2307 } | |
2308 return; | |
2309 } | |
2310 | |
2311 static void jabber_login(struct aim_user *user) | |
2312 { | |
2313 struct gaim_connection *gc = new_gaim_conn(user); | |
2314 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); | |
2315 char *loginname = create_valid_jid(user->username, DEFAULT_SERVER, "GAIM"); | |
2316 | |
3311 | 2317 jd->buddies = g_hash_table_new(g_str_hash, g_str_equal); |
2956 | 2318 jd->chats = NULL; /* we have no chats yet */ |
2086 | 2319 |
2975 | 2320 set_login_progress(gc, 1, _("Connecting")); |
2086 | 2321 |
2956 | 2322 if (!(jd->gjc = gjab_new(loginname, user->password, gc))) { |
2086 | 2323 g_free(loginname); |
2324 debug_printf("jabber: unable to connect (jab_new failed)\n"); | |
2975 | 2325 hide_login_progress(gc, _("Unable to connect")); |
2086 | 2326 signoff(gc); |
2327 return; | |
2328 } | |
2329 | |
2330 g_free(loginname); | |
2956 | 2331 gjab_state_handler(jd->gjc, jabber_handlestate); |
2332 gjab_packet_handler(jd->gjc, jabber_handlepacket); | |
2333 jd->gjc->queries = g_hash_table_new(g_str_hash, g_str_equal); | |
2334 gjab_start(jd->gjc); | |
2086 | 2335 } |
2336 | |
2337 static gboolean jabber_destroy_hash(gpointer key, gpointer val, gpointer data) { | |
2338 g_free(key); | |
2339 g_free(val); | |
2340 return TRUE; | |
2341 } | |
2342 | |
3311 | 2343 static gboolean jabber_destroy_buddy_hash(gpointer key, gpointer val, gpointer data) { |
2344 struct jabber_buddy_data *jbd = val; | |
2345 while (jbd->resources) { | |
2346 g_free(((jab_res_info) ((GSList *)jbd->resources)->data)->name); | |
2347 if(((jab_res_info) ((GSList *)jbd->resources)->data)->away_msg) | |
2348 g_free(((jab_res_info) ((GSList *)jbd->resources)->data)->away_msg); | |
2349 g_free(((GSList *)jbd->resources)->data); | |
2350 jbd->resources = g_slist_remove(jbd->resources, ((GSList *)jbd->resources)->data); | |
2351 | |
2352 } | |
2353 if(jbd->error_msg) | |
2354 g_free(jbd->error_msg); | |
2355 g_free(key); | |
2356 g_free(jbd); | |
2357 return TRUE; | |
2358 } | |
2359 | |
2360 | |
2086 | 2361 static gboolean jabber_free(gpointer data) |
2362 { | |
2956 | 2363 struct jabber_data *jd = data; |
2364 | |
3236 | 2365 if(jd->gjc != NULL) { |
3486 | 2366 g_free(jd->gjc->sid); |
3236 | 2367 gjab_delete(jd->gjc); |
2368 jd->gjc = NULL; | |
2369 } | |
2956 | 2370 g_free(jd); |
2371 | |
2086 | 2372 return FALSE; |
2373 } | |
2374 | |
2375 static void jabber_close(struct gaim_connection *gc) | |
2376 { | |
2377 struct jabber_data *jd = gc->proto_data; | |
2956 | 2378 |
2379 if(jd) { | |
2380 GSList *jcs = jd->chats; | |
2381 | |
2382 /* Free-up the jabber_chat struct allocs and the list */ | |
2383 while (jcs) { | |
3311 | 2384 gaim_jid_free(((struct jabber_chat *)jcs->data)->gjid); |
2956 | 2385 g_free(jcs->data); |
2386 jcs = jcs->next; | |
2387 } | |
2388 g_slist_free(jd->chats); | |
2389 | |
3311 | 2390 /* Free-up the buddy data hash */ |
2391 if(jd->buddies != NULL) | |
2392 { | |
2393 g_hash_table_foreach_remove(jd->buddies, jabber_destroy_buddy_hash, NULL); | |
2394 g_hash_table_destroy(jd->buddies); | |
2395 jd->buddies = NULL; | |
2956 | 2396 } |
2397 | |
2398 /* Free-up the pending queries memories and the list */ | |
3236 | 2399 if(jd->gjc != NULL && jd->gjc->queries != NULL) { |
2956 | 2400 g_hash_table_foreach_remove(jd->gjc->queries, jabber_destroy_hash, NULL); |
2401 g_hash_table_destroy(jd->gjc->queries); | |
2402 jd->gjc->queries = NULL; | |
2403 } | |
2404 } | |
2300
d2686f757d6e
[gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
2405 if (gc->inpa) |
d2686f757d6e
[gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
2406 gaim_input_remove(gc->inpa); |
2956 | 2407 |
2408 if(jd) { | |
3613 | 2409 g_timeout_add(0, jabber_free, jd); |
3236 | 2410 if(jd->gjc != NULL) |
2411 xmlnode_free(jd->gjc->current); | |
2956 | 2412 } |
2086 | 2413 gc->proto_data = NULL; |
2414 } | |
2415 | |
3311 | 2416 static int jabber_send_typing(struct gaim_connection *gc, char *who, int typing) |
2417 { | |
2418 xmlnode x, y; | |
2419 char *realwho; | |
2420 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; | |
2421 jab_res_info jri = jabber_find_resource(gc, who); | |
2422 | |
2423 if(!jri || !jri->has_composing) | |
2424 return 0; | |
2425 | |
2426 if((realwho = get_realwho(gjc, who, FALSE, NULL)) == NULL) | |
2427 return 0; | |
3596 | 2428 |
3311 | 2429 x = xmlnode_new_tag("message"); |
2430 xmlnode_put_attrib(x, "to", realwho); | |
2431 xmlnode_insert_tag(x, "gaim"); | |
2432 | |
2433 y = xmlnode_insert_tag(x, "x"); | |
2434 xmlnode_put_attrib(y, "xmlns", "jabber:x:event"); | |
2435 | |
3596 | 2436 if(typing == TYPING) |
3311 | 2437 xmlnode_insert_tag(y, "composing"); |
3596 | 2438 |
3311 | 2439 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2440 xmlnode_free(x); | |
2441 g_free(realwho); | |
2442 return JABBER_TYPING_NOTIFY_INT; | |
2443 } | |
2444 | |
3033 | 2445 static int jabber_send_im(struct gaim_connection *gc, char *who, char *message, int len, int flags) |
2086 | 2446 { |
2447 xmlnode x, y; | |
2448 char *realwho; | |
3311 | 2449 char *thread_id = NULL; |
2956 | 2450 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
2086 | 2451 |
2452 if (!who || !message) | |
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2112
diff
changeset
|
2453 return 0; |
2086 | 2454 |
3311 | 2455 if((realwho = get_realwho(gjc, who, FALSE, NULL)) == NULL) |
2456 return 0; | |
2457 | |
2086 | 2458 x = xmlnode_new_tag("message"); |
2459 xmlnode_put_attrib(x, "to", realwho); | |
3311 | 2460 |
2461 thread_id = jabber_get_convo_thread(gjc, realwho); | |
2462 if(thread_id) | |
2463 { | |
2464 y = xmlnode_insert_tag(x, "thread"); | |
2465 xmlnode_insert_cdata(y, thread_id, -1); | |
2466 g_free(thread_id); | |
2467 } | |
2468 | |
2086 | 2469 g_free(realwho); |
2470 | |
2278
00a8b7bcef6c
[gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2232
diff
changeset
|
2471 xmlnode_insert_tag(x, "gaim"); |
2086 | 2472 xmlnode_put_attrib(x, "type", "chat"); |
2473 | |
3311 | 2474 /* let other clients know we support typing notification */ |
2475 y = xmlnode_insert_tag(x, "x"); | |
2476 xmlnode_put_attrib(y, "xmlns", "jabber:x:event"); | |
2477 xmlnode_insert_tag(y, "composing"); | |
2478 | |
2086 | 2479 if (message && strlen(message)) { |
2480 y = xmlnode_insert_tag(x, "body"); | |
3642 | 2481 xmlnode_insert_cdata(y, message, -1); |
2086 | 2482 } |
2483 | |
2956 | 2484 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2086 | 2485 xmlnode_free(x); |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2300
diff
changeset
|
2486 return 1; |
2086 | 2487 } |
2488 | |
3105 | 2489 /* |
2490 * Add/update buddy's roster entry on server | |
3349 | 2491 * |
2492 * If "alias" or "group" are NULL, gets them from Gaim's current buddylist values | |
2493 * for the buddy. | |
3105 | 2494 */ |
3349 | 2495 static void jabber_roster_update(struct gaim_connection *gc, char *name, char *alias, char *group) |
3105 | 2496 { |
2497 xmlnode x, y; | |
2498 char *realwho; | |
2499 gjconn gjc; | |
2500 struct buddy *buddy = NULL; | |
2501 struct group *buddy_group = NULL; | |
3349 | 2502 char *my_alias = NULL; |
2503 char *my_group = NULL; | |
3105 | 2504 |
2505 if(gc && gc->proto_data && ((struct jabber_data *)gc->proto_data)->gjc && name) { | |
3311 | 2506 gaim_jid gjid; |
3105 | 2507 gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
2508 | |
3311 | 2509 if((realwho = get_realwho(gjc, name, FALSE, &gjid)) == NULL) |
2510 return; | |
2511 | |
2512 /* FIXME: transport */ | |
2513 if(gjid->user == NULL) { | |
2514 g_free(realwho); | |
2515 gaim_jid_free(gjid); | |
2516 return; | |
3105 | 2517 } |
3311 | 2518 gaim_jid_free(gjid); |
3105 | 2519 |
2520 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); | |
2521 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); | |
2522 xmlnode_put_attrib(y, "jid", realwho); | |
2523 | |
3349 | 2524 /* |
2525 * See if there's an explict (new?) alias for the buddy or we can pull | |
2526 * one out of current Gaim buddylist data for him. | |
2527 */ | |
2528 if(alias && alias[0] != '\0') { | |
2529 my_alias = alias; | |
2530 } else if((buddy = find_buddy(gc, realwho)) != NULL) { | |
2531 my_alias = buddy->show; | |
2532 } | |
2533 | |
2534 /* If there's an alias for the buddy, it's not 0-length | |
3105 | 2535 * and it doesn't match his JID, add the "name" attribute. |
2536 */ | |
3349 | 2537 if(my_alias != NULL && my_alias[0] != '\0' && strcmp(realwho, my_alias)) |
3311 | 2538 { |
3642 | 2539 xmlnode_put_attrib(y, "name", my_alias); |
3105 | 2540 } |
2541 | |
2542 /* | |
3349 | 2543 * See if there's an explict (new?) group for the buddy or pull |
2544 * one out of current Gaim buddylist data for him. | |
3105 | 2545 */ |
3349 | 2546 if(group && group[0] != '\0') { |
2547 my_group = group; | |
2548 } else if((buddy_group = find_group_by_buddy(gc, realwho)) != NULL) { | |
2549 my_group = buddy_group->name; | |
2550 } | |
2551 | |
2552 /* | |
2553 * Send what group the buddy's in along with the roster item. | |
2554 */ | |
2555 if(my_group != NULL && my_group[0] != '\0') { | |
2556 xmlnode z = xmlnode_insert_tag(y, "group"); | |
2557 xmlnode_insert_cdata(z, my_group, -1); | |
3105 | 2558 } |
2559 | |
2560 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); | |
2561 | |
2562 xmlnode_free(x); | |
2563 g_free(realwho); | |
2564 } | |
2565 } | |
2566 | |
3136 | 2567 /* |
3349 | 2568 * Add/update buddy's alias on server |
2569 * | |
2570 * This is just a roster update using existing, local buddylist data | |
2571 */ | |
2572 static void jabber_alias_buddy(struct gaim_connection *gc, char *name) | |
2573 { | |
2574 jabber_roster_update(gc, name, NULL, NULL); | |
2575 } | |
2576 | |
2577 /* | |
3136 | 2578 * Change buddy's group on server roster |
2579 */ | |
2580 static void jabber_group_change(struct gaim_connection *gc, char *name, char *old_group, char *new_group) | |
2581 { | |
3349 | 2582 if(old_group && new_group && strcmp(old_group, new_group)) |
2583 jabber_roster_update(gc, name, NULL, new_group); | |
2584 } | |
2585 | |
2586 /* | |
2587 * Group rename | |
2588 * | |
2589 * Jabber doesn't have "groups," per se. "Group" is simply a JID attribute. | |
2590 * So we iterate through the list of buddies that are in the group and change | |
2591 * the group attribute for each of them. | |
2592 */ | |
2593 static void jabber_rename_group(struct gaim_connection *gc, | |
2594 char *old_group, | |
2595 char *new_group, | |
2596 GList *members) | |
2597 { | |
2598 if(old_group && new_group && strcmp(old_group, new_group)) | |
2599 while(members) { | |
2600 jabber_group_change(gc, (char *)(members->data), old_group, new_group); | |
2601 members = members->next; | |
2602 } | |
3136 | 2603 } |
2604 | |
3466 | 2605 static void jabber_add_buddy(struct gaim_connection *gc, const char *name) |
2086 | 2606 { |
3136 | 2607 xmlnode x; |
2086 | 2608 char *realwho; |
2956 | 2609 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
3311 | 2610 gaim_jid gjid; |
2086 | 2611 |
2612 if (!((struct jabber_data *)gc->proto_data)->did_import) | |
2613 return; | |
2614 | |
3311 | 2615 /* |
2616 * If there's no name or the name is ourself | |
2617 */ | |
2618 if(!name || !strcmp(gc->username, name)) | |
2086 | 2619 return; |
2620 | |
3311 | 2621 if((realwho = get_realwho(gjc, name, FALSE, &gjid)) == NULL) { |
3427 | 2622 char *msg = g_strdup_printf(_("The user %s is an invalid Jabber I.D. and was " |
2623 "therefore not added."), name); | |
2624 do_error_dialog("Unable to add buddy.", _("Jabber Error"), GAIM_ERROR); | |
3311 | 2625 g_free(msg); |
2626 jabber_remove_gaim_buddy(gc, name); | |
2627 return; | |
2086 | 2628 } |
2629 | |
3311 | 2630 /* FIXME: transport */ |
2631 if(gjid->user == NULL) { | |
2632 g_free(realwho); | |
2633 gaim_jid_free(gjid); | |
2634 return; | |
2635 } | |
2636 gaim_jid_free(gjid); | |
2637 | |
2086 | 2638 x = xmlnode_new_tag("presence"); |
2639 xmlnode_put_attrib(x, "to", realwho); | |
2640 xmlnode_put_attrib(x, "type", "subscribe"); | |
2956 | 2641 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2642 xmlnode_free(x); | |
2086 | 2643 |
3349 | 2644 jabber_roster_update(gc, realwho, NULL, NULL); |
3105 | 2645 |
2086 | 2646 g_free(realwho); |
2647 } | |
2648 | |
2681
37d80035e77f
[gaim-migrate @ 2694]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2635
diff
changeset
|
2649 static void jabber_remove_buddy(struct gaim_connection *gc, char *name, char *group) |
2086 | 2650 { |
3048 | 2651 xmlnode x; |
2086 | 2652 char *realwho; |
2956 | 2653 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
2086 | 2654 |
3311 | 2655 if(!name || (realwho = get_realwho(gjc, name, FALSE, NULL)) == NULL) |
2086 | 2656 return; |
2657 | |
2956 | 2658 x = xmlnode_new_tag("presence"); |
2659 xmlnode_put_attrib(x, "to", realwho); | |
2660 xmlnode_put_attrib(x, "type", "unsubscribe"); | |
2661 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); | |
2086 | 2662 g_free(realwho); |
2663 xmlnode_free(x); | |
2664 } | |
2665 | |
3314 | 2666 /* |
2667 * Remove a buddy item from the roster entirely | |
2668 */ | |
2669 static void jabber_remove_buddy_roster_item(struct gaim_connection *gc, char *name) | |
2670 { | |
3340 | 2671 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
3314 | 2672 char *realwho; |
3340 | 2673 |
2674 if((realwho = get_realwho(gjc, name, FALSE, NULL)) != NULL) { | |
2675 xmlnode x = jutil_iqnew(JPACKET__SET, NS_ROSTER); | |
2676 xmlnode y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); | |
2677 xmlnode_put_attrib(y, "jid", realwho); | |
2678 xmlnode_put_attrib(y, "subscription", "remove"); | |
2679 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); | |
2680 g_free(realwho); | |
2681 xmlnode_free(x); | |
2682 } | |
2683 } | |
2684 | |
2685 /* | |
2686 * Unsubscribe a buddy from our presence | |
2687 */ | |
2688 static void jabber_unsubscribe_buddy_from_us(struct gaim_connection *gc, char *name) | |
2689 { | |
2690 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; | |
2691 char *realwho; | |
2692 | |
2693 if((realwho = get_realwho(gjc, name, FALSE, NULL)) != NULL) { | |
2694 xmlnode g = xmlnode_new_tag("presence"); | |
2695 xmlnode_put_attrib(g, "to", realwho); | |
2696 xmlnode_put_attrib(g, "type", "unsubscribed"); | |
2697 gjab_send(gjc, g); | |
2698 xmlnode_free(g); | |
2699 } | |
2700 } | |
2701 | |
2702 /* | |
2703 * Common code for setting ourselves invisible/visible to buddy | |
2704 */ | |
2705 static void jabber_invisible_to_buddy_common(struct gaim_connection *gc, char *name, gboolean invisible) | |
2706 { | |
3314 | 2707 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
3340 | 2708 char *realwho; |
2709 | |
2710 if((realwho = get_realwho(gjc, name, FALSE, NULL)) != NULL) { | |
2711 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, realwho); | |
2712 xmlnode g = xmlnode_new_tag("presence"); | |
2713 | |
2714 xmlnode_put_attrib(g, "to", realwho); | |
2715 | |
2716 if(invisible) | |
2717 xmlnode_put_attrib(g, "type", "invisible"); | |
2718 | |
2719 gjab_send(gjc, g); | |
2720 | |
2721 g_free(realwho); | |
2722 xmlnode_free(g); | |
2723 | |
2724 if(jbd) { | |
2725 if(invisible) { | |
2726 jbd->invisible |= JABBER_BUD_INVIS; | |
2727 } else { | |
2728 jbd->invisible &= ~JABBER_BUD_INVIS; | |
2729 } | |
2730 } | |
2731 } | |
2732 } | |
2733 | |
2734 /* | |
2735 * Make ourselves temporarily invisible to a buddy | |
2736 */ | |
2737 static void jabber_invisible_to_buddy(struct gaim_connection *gc, char *name) | |
2738 { | |
2739 jabber_invisible_to_buddy_common(gc, name, TRUE); | |
2740 } | |
2741 | |
2742 /* | |
2743 * Make ourselves visible to a buddy | |
2744 */ | |
2745 static void jabber_visible_to_buddy(struct gaim_connection *gc, char *name) | |
2746 { | |
2747 jabber_invisible_to_buddy_common(gc, name, FALSE); | |
2748 } | |
2749 | |
2750 /* | |
2751 * Function used by the g_hash_table_foreach() in invisible_to_all_buddies() to | |
2752 * actually set the status. | |
2753 * | |
2754 * key is unused | |
2755 * value is the pointer to the jabber_buddy_data struct | |
2756 * data is gboolean: TRUE (invisible) or FALSE (not invisible) | |
2757 */ | |
2758 static void set_invisible_to_buddy_status(gpointer key, gpointer val, gpointer data) { | |
2759 struct jabber_buddy_data *jbd = val; | |
2760 gboolean invisible = (gboolean) data; | |
2761 | |
2762 if(jbd) { | |
2763 if(invisible) { | |
2764 jbd->invisible = JABBER_SERV_INVIS | JABBER_BUD_INVIS; | |
2765 } else { | |
2766 /* | |
2767 * If we've asserted server-level invisibility, cancelling | |
2768 * it removes explicit buddy invisibility settings too. | |
2769 */ | |
2770 if(jbd->invisible & JABBER_SERV_INVIS) | |
2771 jbd->invisible = JABBER_NOT_INVIS; | |
2772 } | |
2773 } | |
2774 } | |
2775 | |
2776 /* | |
2777 * Show we've set ourselves invisible/visible to all buddies on the server | |
2778 * | |
2779 * Used when we set server-wide invisibility so that individual buddy menu | |
2780 * entries show the proper option. | |
2781 */ | |
2782 static void invisible_to_all_buddies(struct gaim_connection *gc, gboolean invisible) | |
2783 { | |
2784 struct jabber_data *jd = gc->proto_data; | |
2785 | |
2786 if(jd->buddies != NULL) | |
2787 g_hash_table_foreach(jd->buddies, set_invisible_to_buddy_status, (gpointer) invisible); | |
3314 | 2788 } |
2789 | |
2086 | 2790 static char **jabber_list_icon(int uc) |
2791 { | |
2792 switch (uc) { | |
2793 case UC_AWAY: | |
2794 return available_away_xpm; | |
2795 case UC_CHAT: | |
2796 return available_chat_xpm; | |
2797 case UC_XA: | |
2798 return available_xa_xpm; | |
2799 case UC_DND: | |
2800 return available_dnd_xpm; | |
3259 | 2801 case UC_ERROR: |
2802 return available_error_xpm; | |
2086 | 2803 default: |
2804 return available_xpm; | |
2805 } | |
2806 } | |
2807 | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2808 static GList *jabber_chat_info(struct gaim_connection *gc) |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2809 { |
2956 | 2810 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
2811 | |
2812 static char *confserv = NULL; /* this pointer must be persistent */ | |
2813 gchar *server; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2814 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2815 GList *m = NULL; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2816 struct proto_chat_entry *pce; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2817 |
2956 | 2818 /* This is a scientific wild-ass guess... |
2819 * | |
2820 * If there are more than two "components" to the current server name, | |
2821 * lop-off the left-most component and replace with "conference." | |
2822 */ | |
2823 if(confserv != NULL) { | |
2824 g_free(confserv); /* dispose of the old value */ | |
2825 } | |
2826 | |
2827 if((server = g_strdup(gjc->user->server)) == NULL) { | |
2828 confserv = g_strdup(DEFAULT_GROUPCHAT); | |
2829 } else { | |
2830 gchar **splits, **index; | |
2831 gchar *tmp; | |
2832 int cnt = 0; | |
2833 | |
2834 | |
2835 index = splits = g_strsplit(server, ".", -1); /* split the connected server */ | |
2836 | |
2837 while(*(index++)) /* index to the end--counting the parts */ | |
2838 ++cnt; | |
2839 | |
2840 /* | |
2841 * If we've more than two parts, point to the second part. Else point | |
2842 * to the start. | |
2843 */ | |
2844 if(cnt > 2) { | |
2845 index -= cnt; | |
2846 } else { | |
2847 index = splits; | |
2848 } | |
2849 | |
2850 /* Put it together */ | |
2851 confserv = g_strjoin(".", "conference", (tmp = g_strjoinv(".", index)), NULL); | |
2852 | |
2853 g_free(server); /* we don't need this stuff no more */ | |
2854 g_free(tmp); | |
2855 g_strfreev(splits); | |
2856 } | |
2857 | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2858 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2859 pce->label = _("Room:"); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2860 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2861 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2862 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2863 pce->label = _("Server:"); |
2956 | 2864 pce->def = confserv; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2865 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2866 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2867 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2868 pce->label = _("Handle:"); |
2956 | 2869 pce->def = gjc->user->user; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2870 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2871 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2872 return m; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2873 } |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2874 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2875 static void jabber_join_chat(struct gaim_connection *gc, GList *data) |
2086 | 2876 { |
2877 xmlnode x; | |
2878 char *realwho; | |
2956 | 2879 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
2880 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats; | |
2086 | 2881 struct jabber_chat *jc; |
3311 | 2882 gaim_jid gjid; |
2086 | 2883 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2884 if (!data || !data->next || !data->next->next) |
2086 | 2885 return; |
2886 | |
3311 | 2887 realwho = create_valid_jid(data->data, data->next->data, data->next->next->data); |
2086 | 2888 debug_printf("%s\n", realwho); |
2889 | |
3311 | 2890 if((gjid = gaim_jid_new(realwho)) == NULL) { |
3427 | 2891 char *msg = g_strdup_printf("The Jabber I.D. %s is invalid.", realwho); |
2892 do_error_dialog(_("Unable to join chat"), msg, GAIM_ERROR); | |
3236 | 2893 g_free(msg); |
3311 | 2894 g_free(realwho); |
3236 | 2895 return; |
2896 } | |
2956 | 2897 |
3311 | 2898 if((jc = find_any_chat(gc, gjid)) != NULL) { |
2956 | 2899 switch(jc->state) { |
2900 case JCS_PENDING: | |
2901 debug_printf("attempt to re-join already pending Jabber chat! (ignoring)\n"); | |
2902 g_free(realwho); /* yuck! */ | |
3311 | 2903 gaim_jid_free(gjid); |
2956 | 2904 return; |
2905 case JCS_ACTIVE: | |
2906 debug_printf("attempt to re-join already active Jabber chat! (ignoring)\n"); | |
2907 g_free(realwho); /* yuck! */ | |
3311 | 2908 gaim_jid_free(gjid); |
2956 | 2909 return; |
2910 case JCS_CLOSED: | |
2911 debug_printf("rejoining previously closed Jabber chat\n"); | |
2912 break; | |
2913 default: | |
2914 debug_printf("found Jabber chat in unknown state! (ignoring)\n"); | |
2915 g_free(realwho); /* yuck! */ | |
3311 | 2916 gaim_jid_free(gjid); |
2956 | 2917 return; |
2918 } | |
2919 } else { | |
2920 debug_printf("joining completely new Jabber chat\n"); | |
2921 jc = g_new0(struct jabber_chat, 1); | |
3311 | 2922 jc->gjid = gjid; |
2956 | 2923 jc->gc = gc; |
2924 ((struct jabber_data *)gc->proto_data)->chats = g_slist_append(jcs, jc); | |
3311 | 2925 add_buddy(gc, _("Chats"), realwho, realwho); |
2956 | 2926 } |
2927 | |
2928 jc->state = JCS_PENDING; | |
2929 | |
2086 | 2930 x = jutil_presnew(0, realwho, NULL); |
2956 | 2931 gjab_send(gjc, x); |
2086 | 2932 xmlnode_free(x); |
2933 g_free(realwho); | |
2934 } | |
2935 | |
3466 | 2936 static void jabber_chat_invite(struct gaim_connection *gc, int id, const char *message, const char *name) |
2086 | 2937 { |
2938 xmlnode x, y; | |
2939 struct jabber_data *jd = gc->proto_data; | |
2956 | 2940 gjconn gjc = jd->gjc; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2941 struct jabber_chat *jc = NULL; |
2086 | 2942 char *realwho, *subject; |
2943 | |
3311 | 2944 if(!name || (realwho = get_realwho(gjc, name, FALSE, NULL)) == NULL) |
2086 | 2945 return; |
2946 | |
2947 /* find which chat we're inviting to */ | |
2956 | 2948 if(jabber_find_chat_by_convo_id(gc, id, &jc) != 0) |
2086 | 2949 return; |
2950 | |
2951 x = xmlnode_new_tag("message"); | |
2952 xmlnode_put_attrib(x, "to", realwho); | |
3311 | 2953 |
2086 | 2954 g_free(realwho); |
2955 | |
2956 y = xmlnode_insert_tag(x, "x"); | |
2957 xmlnode_put_attrib(y, "xmlns", "jabber:x:conference"); | |
3311 | 2958 subject = g_strdup_printf("%s@%s", jc->gjid->user, jc->gjid->server); |
2086 | 2959 xmlnode_put_attrib(y, "jid", subject); |
2960 g_free(subject); | |
2961 | |
2962 if (message && strlen(message)) { | |
2963 y = xmlnode_insert_tag(x, "body"); | |
3642 | 2964 xmlnode_insert_cdata(y, message, -1); |
2086 | 2965 } |
2966 | |
2956 | 2967 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2086 | 2968 xmlnode_free(x); |
2969 } | |
2970 | |
2971 static void jabber_chat_leave(struct gaim_connection *gc, int id) | |
2972 { | |
2973 struct jabber_data *jd = gc->proto_data; | |
2956 | 2974 gjconn gjc = jd->gjc; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2975 struct jabber_chat *jc = NULL; |
3311 | 2976 char *chatname; |
2086 | 2977 xmlnode x; |
2978 | |
2956 | 2979 /* Find out which chat we're leaving */ |
2980 if(jabber_find_chat_by_convo_id(gc, id, &jc) != 0) | |
2086 | 2981 return; |
2982 | |
3311 | 2983 chatname = g_strdup_printf("%s@%s", jc->gjid->user, jc->gjid->server); |
2984 x = jutil_presnew(0, chatname, NULL); | |
2985 g_free(chatname); | |
2086 | 2986 xmlnode_put_attrib(x, "type", "unavailable"); |
2956 | 2987 gjab_send(gjc, x); |
2086 | 2988 xmlnode_free(x); |
2989 jc->b = NULL; | |
2990 } | |
2991 | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
2992 static int jabber_chat_send(struct gaim_connection *gc, int id, char *message) |
2086 | 2993 { |
2994 xmlnode x, y; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2995 struct jabber_chat *jc = NULL; |
2086 | 2996 char *chatname; |
2956 | 2997 int retval = 0; |
2998 | |
2999 /* Find out which chat we're sending to */ | |
3000 if((retval = jabber_find_chat_by_convo_id(gc, id, &jc)) != 0) | |
3001 return(retval); | |
2086 | 3002 |
3003 x = xmlnode_new_tag("message"); | |
3311 | 3004 xmlnode_put_attrib(x, "from", jc->gjid->full); |
3005 chatname = g_strdup_printf("%s@%s", jc->gjid->user, jc->gjid->server); | |
2086 | 3006 xmlnode_put_attrib(x, "to", chatname); |
3007 g_free(chatname); | |
3008 xmlnode_put_attrib(x, "type", "groupchat"); | |
3009 | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
3010 if (message && strlen(message) > strlen("/topic ") && |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
3011 !g_strncasecmp(message, "/topic ", strlen("/topic "))) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
3012 char buf[8192]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
3013 y = xmlnode_insert_tag(x, "subject"); |
3642 | 3014 xmlnode_insert_cdata(y, message + strlen("/topic "), -1); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
3015 y = xmlnode_insert_tag(x, "body"); |
3642 | 3016 g_snprintf(buf, sizeof(buf), "/me has changed the subject to: %s", message + strlen("/topic")); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
3017 xmlnode_insert_cdata(y, buf, -1); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
3018 } else if (message && strlen(message)) { |
2086 | 3019 y = xmlnode_insert_tag(x, "body"); |
3642 | 3020 xmlnode_insert_cdata(y, message, -1); |
2086 | 3021 } |
3022 | |
2956 | 3023 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2086 | 3024 xmlnode_free(x); |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
3025 return 0; |
2086 | 3026 } |
3027 | |
3028 static void jabber_chat_whisper(struct gaim_connection *gc, int id, char *who, char *message) | |
3029 { | |
3030 xmlnode x, y; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
3031 struct jabber_chat *jc = NULL; |
2086 | 3032 char *chatname; |
3033 | |
2956 | 3034 /* Find out which chat we're whispering to */ |
3035 if(jabber_find_chat_by_convo_id(gc, id, &jc) != 0) | |
2086 | 3036 return; |
3037 | |
3038 x = xmlnode_new_tag("message"); | |
3311 | 3039 xmlnode_put_attrib(x, "from", jc->gjid->full); |
3040 chatname = g_strdup_printf("%s@%s/%s", jc->gjid->user, jc->gjid->server, who); | |
2086 | 3041 xmlnode_put_attrib(x, "to", chatname); |
3042 g_free(chatname); | |
3043 xmlnode_put_attrib(x, "type", "normal"); | |
3044 | |
3045 if (message && strlen(message)) { | |
3046 y = xmlnode_insert_tag(x, "body"); | |
3642 | 3047 xmlnode_insert_cdata(y, message, -1); |
2086 | 3048 } |
3049 | |
2956 | 3050 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2086 | 3051 xmlnode_free(x); |
3052 } | |
3053 | |
3054 static char *jabber_normalize(const char *s) | |
3055 { | |
3056 static char buf[BUF_LEN]; | |
3057 char *t, *u; | |
3058 int x = 0; | |
3059 | |
3060 g_return_val_if_fail((s != NULL), NULL); | |
3061 | |
2956 | 3062 /* Somebody called us with s == NULL once... */ |
3063 if(s == NULL) { | |
3064 return(NULL); | |
3065 } else { | |
3066 u = t = g_strdup(s); | |
3067 | |
3068 g_strdown(t); | |
3069 | |
3070 while (*t && (x < BUF_LEN - 1)) { | |
3071 if (*t != ' ') | |
3072 buf[x++] = *t; | |
3073 t++; | |
3074 } | |
3075 buf[x] = '\0'; | |
3076 g_free(u); | |
3077 | |
3078 if (!strchr(buf, '@')) { | |
3079 strcat(buf, "@jabber.org"); /* this isn't always right, but eh */ | |
3080 } else if ((u = strchr(strchr(buf, '@'), '/')) != NULL) { | |
3081 *u = '\0'; | |
3082 } | |
3083 | |
3084 return buf; | |
2086 | 3085 } |
3086 } | |
3087 | |
3088 static void jabber_get_info(struct gaim_connection *gc, char *who) { | |
3089 xmlnode x; | |
3090 char *id; | |
2956 | 3091 char *realwho; |
2086 | 3092 struct jabber_data *jd = gc->proto_data; |
2956 | 3093 gjconn gjc = jd->gjc; |
2086 | 3094 |
3311 | 3095 if((realwho = get_realwho(gjc, who, TRUE, NULL)) == NULL) |
3096 return; | |
3097 | |
2086 | 3098 x = jutil_iqnew(JPACKET__GET, NS_VCARD); |
2956 | 3099 xmlnode_put_attrib(x, "to", realwho); |
3311 | 3100 |
2956 | 3101 g_free(realwho); |
3102 | |
3103 id = gjab_getid(gjc); | |
2086 | 3104 xmlnode_put_attrib(x, "id", id); |
3105 | |
2956 | 3106 g_hash_table_insert(jd->gjc->queries, g_strdup(id), g_strdup("vCard")); |
3107 | |
3108 gjab_send(gjc, x); | |
2086 | 3109 |
3110 xmlnode_free(x); | |
3311 | 3111 } |
3112 | |
3113 static void jabber_get_error_msg(struct gaim_connection *gc, char *who) { | |
3114 struct jabber_data *jd = gc->proto_data; | |
3115 gjconn gjc = jd->gjc; | |
3116 gchar **str_arr = (gchar **) g_new(gpointer, 3); | |
3117 gchar **ap = str_arr; | |
3118 gchar *realwho, *final; | |
3119 struct jabber_buddy_data *jbd; | |
3120 | |
3121 if((realwho = get_realwho(gjc, who, FALSE, NULL)) == NULL) { | |
3122 g_strfreev(str_arr); | |
3123 return; | |
3124 } | |
3125 | |
3126 jbd = jabber_find_buddy(gc, realwho); | |
3127 | |
3128 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", realwho); | |
3129 *ap++ = g_strdup_printf("<B>Error:</B> %s<BR>\n", jbd->error_msg); | |
3130 *ap = NULL; | |
2086 | 3131 |
3311 | 3132 final= g_strjoinv(NULL, str_arr); |
3133 | |
3134 g_strfreev(str_arr); | |
3135 | |
3136 g_show_info_text(gc, realwho, 2, final, NULL); | |
3137 g_free(realwho); | |
3138 g_free(final); | |
2086 | 3139 } |
3140 | |
2956 | 3141 static void jabber_get_away_msg(struct gaim_connection *gc, char *who) { |
3142 struct jabber_data *jd = gc->proto_data; | |
3143 gjconn gjc = jd->gjc; | |
3311 | 3144 int num_resources; |
3145 gaim_jid gjid; | |
3146 char *buddy = get_realwho(gjc, who, FALSE, &gjid); | |
3147 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, buddy); | |
3148 gchar **str_arr; | |
3149 gchar **ap; | |
3150 gchar *realwho, *final; | |
3151 GSList *resources; | |
3152 int i; | |
3153 | |
3154 if(!buddy) | |
3155 return; | |
3156 | |
3157 if(!gjid->resource) { | |
3158 num_resources = g_slist_length(jbd->resources); | |
3159 resources = jbd->resources; | |
3160 } else { | |
3161 num_resources = 1; | |
3162 resources = jbd->resources; | |
3163 while(strcasecmp(((jab_res_info)resources->data)->name, gjid->resource)) | |
3164 resources = resources->next; | |
3165 } | |
3166 | |
3167 gaim_jid_free(gjid); | |
2956 | 3168 |
3169 /* space for all elements: Jabber I.D. + "status" + NULL (list terminator) */ | |
3311 | 3170 str_arr = (gchar **) g_new(gpointer, num_resources*2 + 1); |
3171 ap = str_arr; | |
3172 | |
3173 for(i=0; i<num_resources; i++) | |
3174 { | |
3175 jab_res_info jri = resources->data; | |
3176 realwho = g_strdup_printf("%s/%s", buddy, jri->name); | |
3177 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", realwho); | |
3178 *ap++ = g_strdup_printf("<B>Status:</B> %s<BR>\n", jabber_lookup_away(gjc, realwho)); | |
3179 g_free(realwho); | |
3180 resources = resources->next; | |
2956 | 3181 } |
3182 | |
3183 *ap = NULL; | |
3311 | 3184 |
3185 g_free(buddy); | |
2956 | 3186 |
3187 final= g_strjoinv(NULL, str_arr); | |
3188 g_strfreev(str_arr); | |
3189 | |
3311 | 3190 g_show_info_text(gc, who, 2, final, NULL); |
2956 | 3191 g_free(final); |
3192 | |
3193 } | |
3194 | |
3195 static void jabber_get_cb_info(struct gaim_connection *gc, int cid, char *who) { | |
3196 struct jabber_chat *jc = NULL; | |
3197 char *realwho; | |
3198 | |
3199 /* Find out which chat */ | |
3200 if(jabber_find_chat_by_convo_id(gc, cid, &jc) != 0) | |
3201 return; | |
3202 | |
3311 | 3203 realwho = g_strdup_printf("%s@%s/%s", jc->gjid->user, jc->gjid->server, who); |
2956 | 3204 |
3205 jabber_get_info(gc, realwho); | |
3206 g_free(realwho); | |
3207 } | |
3208 | |
3209 static void jabber_get_cb_away_msg(struct gaim_connection *gc, int cid, char *who) { | |
3210 struct jabber_chat *jc = NULL; | |
3211 char *realwho; | |
3212 | |
3213 /* Find out which chat */ | |
3214 if(jabber_find_chat_by_convo_id(gc, cid, &jc) != 0) | |
3215 return; | |
3216 | |
3311 | 3217 realwho = g_strdup_printf("%s@%s/%s", jc->gjid->user, jc->gjid->server, who); |
2956 | 3218 |
3219 jabber_get_away_msg(gc, realwho); | |
3220 g_free(realwho); | |
3221 | |
3222 } | |
3223 | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
3224 static GList *jabber_buddy_menu(struct gaim_connection *gc, char *who) { |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
3225 GList *m = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
3226 struct proto_buddy_menu *pbm; |
3311 | 3227 struct buddy *b = find_buddy(gc, who); |
3228 | |
3229 if(b->uc == UC_ERROR) | |
3230 { | |
3231 pbm = g_new0(struct proto_buddy_menu, 1); | |
3232 pbm->label = _("View Error Msg"); | |
3233 pbm->callback = jabber_get_error_msg; | |
3234 pbm->gc = gc; | |
3235 m = g_list_append(m, pbm); | |
3236 } else { | |
3340 | 3237 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
3238 char *realwho = get_realwho(gjc, who, FALSE, NULL); | |
3239 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, realwho); | |
3240 | |
3241 g_free(realwho); | |
3242 | |
3311 | 3243 pbm = g_new0(struct proto_buddy_menu, 1); |
3244 pbm->label = _("Get Info"); | |
3245 pbm->callback = jabber_get_info; | |
3246 pbm->gc = gc; | |
3247 m = g_list_append(m, pbm); | |
3248 pbm = g_new0(struct proto_buddy_menu, 1); | |
3249 pbm->label = _("Get Away Msg"); | |
3250 pbm->callback = jabber_get_away_msg; | |
3251 pbm->gc = gc; | |
3252 m = g_list_append(m, pbm); | |
3340 | 3253 |
3254 pbm = g_new0(struct proto_buddy_menu, 1); | |
3255 if(jbd && (jbd->invisible & JABBER_BUD_INVIS)) { | |
3256 pbm->label = _("Un-hide From"); | |
3257 pbm->callback = jabber_visible_to_buddy; | |
3258 } else { | |
3259 pbm->label = _("Temporarily Hide From"); | |
3260 pbm->callback = jabber_invisible_to_buddy; | |
3261 } | |
3262 pbm->gc = gc; | |
3263 m = g_list_append(m, pbm); | |
3311 | 3264 } |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
3265 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
3266 return m; |
2086 | 3267 } |
3268 | |
3314 | 3269 /* |
3270 * Jabber protocol-specific "edit buddy menu" item(s) | |
3271 */ | |
3272 static GList *jabber_edit_buddy_menu(struct gaim_connection *gc, char *who) { | |
3273 GList *m = NULL; | |
3274 struct proto_buddy_menu *pbm; | |
3275 | |
3276 pbm = g_new0(struct proto_buddy_menu, 1); | |
3456 | 3277 pbm->label = _("Get Info"); |
3278 pbm->callback = jabber_get_info; | |
3279 pbm->gc = gc; | |
3280 m = g_list_append(m, pbm); | |
3281 pbm = g_new0(struct proto_buddy_menu, 1); | |
3314 | 3282 pbm->label = _("Remove From Roster"); |
3283 pbm->callback = jabber_remove_buddy_roster_item; | |
3284 pbm->gc = gc; | |
3285 m = g_list_append(m, pbm); | |
3340 | 3286 pbm = g_new0(struct proto_buddy_menu, 1); |
3287 pbm->label = _("Cancel Presence Notification"); | |
3288 pbm->callback = jabber_unsubscribe_buddy_from_us; | |
3289 pbm->gc = gc; | |
3290 m = g_list_append(m, pbm); | |
3314 | 3291 |
3292 return m; | |
3293 } | |
3294 | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
3295 static GList *jabber_away_states(struct gaim_connection *gc) { |
2086 | 3296 GList *m = NULL; |
3297 | |
3298 m = g_list_append(m, "Online"); | |
3299 m = g_list_append(m, "Chatty"); | |
3300 m = g_list_append(m, "Away"); | |
3301 m = g_list_append(m, "Extended Away"); | |
3302 m = g_list_append(m, "Do Not Disturb"); | |
3340 | 3303 m = g_list_append(m, "Invisible"); |
2086 | 3304 |
3305 return m; | |
3306 } | |
3307 | |
3308 static void jabber_set_away(struct gaim_connection *gc, char *state, char *message) | |
3309 { | |
3310 xmlnode x, y; | |
3311 struct jabber_data *jd = gc->proto_data; | |
2956 | 3312 gjconn gjc = jd->gjc; |
3311 | 3313 GSList *jcs; |
3314 struct jabber_chat *jc; | |
3315 char *chatname; | |
3340 | 3316 gboolean invisible = FALSE; |
2086 | 3317 |
3318 gc->away = NULL; /* never send an auto-response */ | |
3319 | |
3320 x = xmlnode_new_tag("presence"); | |
3321 | |
3322 if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
3323 /* oh goody. Gaim is telling us what to do. */ | |
3324 if (message) { | |
3325 /* Gaim wants us to be away */ | |
3326 y = xmlnode_insert_tag(x, "show"); | |
3327 xmlnode_insert_cdata(y, "away", -1); | |
3328 y = xmlnode_insert_tag(x, "status"); | |
3329 xmlnode_insert_cdata(y, message, -1); | |
3330 gc->away = ""; | |
3331 } else { | |
3332 /* Gaim wants us to not be away */ | |
3333 /* but for Jabber, we can just send presence with no other information. */ | |
3334 } | |
3335 } else { | |
3336 /* state is one of our own strings. it won't be NULL. */ | |
3337 if (!strcmp(state, "Online")) { | |
3338 /* once again, we don't have to put anything here */ | |
3339 } else if (!strcmp(state, "Chatty")) { | |
3340 y = xmlnode_insert_tag(x, "show"); | |
3341 xmlnode_insert_cdata(y, "chat", -1); | |
3342 } else if (!strcmp(state, "Away")) { | |
3343 y = xmlnode_insert_tag(x, "show"); | |
3344 xmlnode_insert_cdata(y, "away", -1); | |
3345 gc->away = ""; | |
3346 } else if (!strcmp(state, "Extended Away")) { | |
3347 y = xmlnode_insert_tag(x, "show"); | |
3348 xmlnode_insert_cdata(y, "xa", -1); | |
3349 gc->away = ""; | |
3350 } else if (!strcmp(state, "Do Not Disturb")) { | |
3351 y = xmlnode_insert_tag(x, "show"); | |
3352 xmlnode_insert_cdata(y, "dnd", -1); | |
3353 gc->away = ""; | |
3340 | 3354 } else if (!strcmp(state, "Invisible")) { |
3355 xmlnode_put_attrib(x, "type", "invisible"); | |
3356 gc->away = ""; | |
3357 invisible = TRUE; | |
2086 | 3358 } |
3359 } | |
3360 | |
3311 | 3361 gjab_send(gjc, x); /* Notify "individuals" */ |
3362 | |
3363 /* | |
3364 * As of jabberd-1.4.2: simply sending presence to the server doesn't result in | |
3365 * it being propagated to conference rooms. So we wade thru the list of chats, | |
3366 * sending our new presence status to each and every one. | |
3367 */ | |
3368 for(jcs = jd->chats; jcs; jcs = jcs->next) { | |
3369 jc = jcs->data; | |
3370 if(jc->state == JCS_ACTIVE) { | |
3371 xmlnode_put_attrib(x, "from", jc->gjid->full); | |
3372 chatname = g_strdup_printf("%s@%s", jc->gjid->user, jc->gjid->server); | |
3373 xmlnode_put_attrib(x, "to", chatname); | |
3374 gjab_send(gjc, x); | |
3375 g_free(chatname); | |
3376 } | |
3377 } | |
3378 | |
2086 | 3379 xmlnode_free(x); |
3340 | 3380 |
3381 invisible_to_all_buddies(gc, invisible); | |
2086 | 3382 } |
3383 | |
3384 static void jabber_set_idle(struct gaim_connection *gc, int idle) { | |
3385 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; | |
3386 debug_printf("jabber_set_idle: setting idle %i\n", idle); | |
3387 jd->idle = idle ? time(NULL) - idle : idle; | |
3388 } | |
3389 | |
3390 static void jabber_keepalive(struct gaim_connection *gc) { | |
3391 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; | |
2956 | 3392 gjab_send_raw(jd->gjc, " \t "); |
2086 | 3393 } |
3394 | |
2956 | 3395 /*---------------------------------------*/ |
3396 /* Jabber "set info" (vCard) support */ | |
3397 /*---------------------------------------*/ | |
3398 | |
3399 /* | |
3400 * V-Card format: | |
3401 * | |
3402 * <vCard prodid='' version='' xmlns=''> | |
3403 * <FN></FN> | |
3404 * <N> | |
3405 * <FAMILY/> | |
3406 * <GIVEN/> | |
3407 * </N> | |
3408 * <NICKNAME/> | |
3409 * <URL/> | |
3410 * <ADR> | |
3411 * <STREET/> | |
3412 * <EXTADD/> | |
3413 * <LOCALITY/> | |
3414 * <REGION/> | |
3415 * <PCODE/> | |
3416 * <COUNTRY/> | |
3417 * </ADR> | |
3418 * <TEL/> | |
3419 * <EMAIL/> | |
3420 * <ORG> | |
3421 * <ORGNAME/> | |
3422 * <ORGUNIT/> | |
3423 * </ORG> | |
3424 * <TITLE/> | |
3425 * <ROLE/> | |
3426 * <DESC/> | |
3427 * <BDAY/> | |
3428 * </vCard> | |
3429 * | |
3430 * See also: | |
3431 * | |
3432 * http://docs.jabber.org/proto/html/vcard-temp.html | |
3433 * http://www.vcard-xml.org/dtd/vCard-XML-v2-20010520.dtd | |
3434 */ | |
3435 | |
3436 /* | |
3437 * Cross-reference user-friendly V-Card entry labels to vCard XML tags | |
3438 * and attributes. | |
3439 * | |
3440 * Order is (or should be) unimportant. For example: we have no way of | |
3441 * knowing in what order real data will arrive. | |
3442 * | |
3443 * Format: Label, Pre-set text, "visible" flag, "editable" flag, XML tag | |
3444 * name, XML tag's parent tag "path" (relative to vCard node). | |
3445 * | |
3446 * List is terminated by a NULL label pointer. | |
3447 * | |
3448 * Entries with no label text, but with XML tag and parent tag | |
3449 * entries, are used by V-Card XML construction routines to | |
3450 * "automagically" construct the appropriate XML node tree. | |
3451 * | |
3452 * Thoughts on future direction/expansion | |
3453 * | |
3454 * This is a "simple" vCard. | |
3455 * | |
3456 * It is possible for nodes other than the "vCard" node to have | |
3457 * attributes. Should that prove necessary/desirable, add an | |
3458 * "attributes" pointer to the vcard_template struct, create the | |
3459 * necessary tag_attr structs, and add 'em to the vcard_dflt_data | |
3460 * array. | |
3461 * | |
3462 * The above changes will (obviously) require changes to the vCard | |
3463 * construction routines. | |
3464 */ | |
3465 | |
3466 struct vcard_template { | |
3467 char *label; /* label text pointer */ | |
3468 char *text; /* entry text pointer */ | |
3469 int visible; /* should entry field be "visible?" */ | |
3470 int editable; /* should entry field be editable? */ | |
3471 char *tag; /* tag text */ | |
3472 char *ptag; /* parent tag "path" text */ | |
3473 char *url; /* vCard display format if URL */ | |
3474 } vcard_template_data[] = { | |
2975 | 3475 {N_("Full Name"), NULL, TRUE, TRUE, "FN", NULL, NULL}, |
3476 {N_("Family Name"), NULL, TRUE, TRUE, "FAMILY", "N", NULL}, | |
3477 {N_("Given Name"), NULL, TRUE, TRUE, "GIVEN", "N", NULL}, | |
3478 {N_("Nickname"), NULL, TRUE, TRUE, "NICKNAME", NULL, NULL}, | |
3479 {N_("URL"), NULL, TRUE, TRUE, "URL", NULL, "<A HREF=\"%s\">%s</A>"}, | |
3480 {N_("Street Address"), NULL, TRUE, TRUE, "STREET", "ADR", NULL}, | |
3481 {N_("Extended Address"), NULL, TRUE, TRUE, "EXTADD", "ADR", NULL}, | |
3482 {N_("Locality"), NULL, TRUE, TRUE, "LOCALITY", "ADR", NULL}, | |
3483 {N_("Region"), NULL, TRUE, TRUE, "REGION", "ADR", NULL}, | |
3484 {N_("Postal Code"), NULL, TRUE, TRUE, "PCODE", "ADR", NULL}, | |
3485 {N_("Country"), NULL, TRUE, TRUE, "COUNTRY", "ADR", NULL}, | |
3486 {N_("Telephone"), NULL, TRUE, TRUE, "TELEPHONE", NULL, NULL}, | |
3487 {N_("Email"), NULL, TRUE, TRUE, "EMAIL", NULL, "<A HREF=\"mailto:%s\">%s</A>"}, | |
3488 {N_("Organization Name"), NULL, TRUE, TRUE, "ORGNAME", "ORG", NULL}, | |
3489 {N_("Organization Unit"), NULL, TRUE, TRUE, "ORGUNIT", "ORG", NULL}, | |
3490 {N_("Title"), NULL, TRUE, TRUE, "TITLE", NULL, NULL}, | |
3491 {N_("Role"), NULL, TRUE, TRUE, "ROLE", NULL, NULL}, | |
3492 {N_("Birthday"), NULL, TRUE, TRUE, "BDAY", NULL, NULL}, | |
3493 {N_("Description"), NULL, TRUE, TRUE, "DESC", NULL, NULL}, | |
2956 | 3494 {"", NULL, TRUE, TRUE, "N", NULL, NULL}, |
3495 {"", NULL, TRUE, TRUE, "ADR", NULL, NULL}, | |
3496 {"", NULL, TRUE, TRUE, "ORG", NULL, NULL}, | |
3497 {NULL, NULL, 0, 0, NULL, NULL, NULL} | |
3498 }; | |
3499 | |
3500 /* | |
3501 * The "vCard" tag's attibute list... | |
3502 */ | |
3503 struct tag_attr { | |
3504 char *attr; | |
3505 char *value; | |
3506 } vcard_tag_attr_list[] = { | |
3507 {"prodid", "-//HandGen//NONSGML vGen v1.0//EN"}, | |
3508 {"version", "2.0", }, | |
3509 {"xmlns", "vcard-temp", }, | |
3510 {NULL, NULL}, | |
3511 }; | |
3512 | |
3513 | |
3514 /* | |
3515 * V-Card user instructions | |
3516 */ | |
3517 static char *multi_entry_instructions = | |
2975 | 3518 N_("All items below are optional. Enter only the information with which you feel comfortable"); |
3519 static char *entries_title = N_("User Identity"); | |
2956 | 3520 |
3521 /* | |
3522 * Used by routines to parse an XML-encoded string into an xmlnode tree | |
3523 */ | |
3524 typedef struct { | |
3525 XML_Parser parser; | |
3526 xmlnode current; | |
3527 } *xmlstr2xmlnode_parser, xmlstr2xmlnode_parser_struct; | |
3528 | |
3529 | |
3530 /* | |
3531 * Display a Jabber vCard | |
3532 */ | |
3533 static void jabber_handlevcard(gjconn gjc, xmlnode querynode, char *from) | |
3534 { | |
3535 struct gaim_connection *gc = GJ_GC(gjc); | |
3536 char *cdata, *status; | |
3537 struct vcard_template *vc_tp = vcard_template_data; | |
3538 | |
3539 /* space for all vCard elements + Jabber I.D. + "status" + NULL (list terminator) */ | |
3540 gchar **str_arr = (gchar **) g_new(gpointer, | |
3541 (sizeof(vcard_template_data)/sizeof(struct vcard_template)) + 3); | |
3542 gchar **ap = str_arr; | |
3543 gchar *buddy, *final; | |
3544 | |
3311 | 3545 if((buddy = get_realwho(gjc, from, TRUE, NULL)) == NULL) { |
3546 g_strfreev(str_arr); | |
3547 return; | |
2956 | 3548 } |
3311 | 3549 |
2956 | 3550 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", buddy); |
3551 | |
3552 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
3553 if(strcmp(vc_tp->tag, "DESC") == 0) | |
3554 continue; /* special handling later */ | |
3555 if(vc_tp->ptag == NULL) { | |
3556 cdata = xmlnode_get_tag_data(querynode, vc_tp->tag); | |
3557 } else { | |
3558 gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag); | |
3559 cdata = xmlnode_get_tag_data(querynode, tag); | |
3560 g_free(tag); | |
3561 } | |
3562 if(cdata != NULL) { | |
3563 if(vc_tp->url == NULL) { | |
3564 *ap++ = g_strdup_printf("<B>%s:</B> %s<BR>\n", vc_tp->label, cdata); | |
3565 } else { | |
3566 gchar *fmt = g_strdup_printf("<B>%%s:</B> %s<BR>\n", vc_tp->url); | |
3567 *ap++ = g_strdup_printf(fmt, vc_tp->label, cdata, cdata); | |
3568 g_free(fmt); | |
3569 } | |
3570 } | |
3571 } | |
3572 | |
3311 | 3573 status = jabber_lookup_away(gjc, buddy); |
3574 | |
2956 | 3575 *ap++ = g_strdup_printf("<B>Status:</B> %s<BR>\n", status); |
3576 | |
3577 /* | |
3578 * "Description" handled as a special case: get a copy of the | |
3579 * string and HTML-ize. | |
3580 */ | |
3581 if((cdata = xmlnode_get_tag_data(querynode, "DESC")) != NULL) { | |
3582 gchar *tmp = g_strdup_printf("<HR>%s<BR>", cdata); | |
3583 *ap++ = strdup_withhtml(tmp); | |
3584 g_free(tmp); | |
3585 } | |
3586 | |
3587 *ap = NULL; | |
3588 | |
3589 final= g_strjoinv(NULL, str_arr); | |
3590 g_strfreev(str_arr); | |
3591 | |
3592 g_show_info_text(gc, buddy, 2, final, NULL); | |
3593 g_free(buddy); | |
3594 g_free(final); | |
3595 } | |
3596 | |
3597 /* | |
3598 * Used by XML_Parse on parsing CDATA | |
3599 */ | |
3600 static void xmlstr2xmlnode_charData(void *userdata, const char *s, int slen) | |
3601 { | |
3602 xmlstr2xmlnode_parser xmlp = (xmlstr2xmlnode_parser) userdata; | |
3603 | |
3604 if (xmlp->current) | |
3605 xmlnode_insert_cdata(xmlp->current, s, slen); | |
3606 } | |
3607 | |
3608 /* | |
3609 * Used by XML_Parse to start or append to an xmlnode | |
3610 */ | |
3611 static void xmlstr2xmlnode_startElement(void *userdata, const char *name, const char **attribs) | |
3612 { | |
3613 xmlnode x; | |
3614 xmlstr2xmlnode_parser xmlp = (xmlstr2xmlnode_parser) userdata; | |
3615 | |
3616 if (xmlp->current) { | |
3617 /* Append the node to the current one */ | |
3618 x = xmlnode_insert_tag(xmlp->current, name); | |
3619 xmlnode_put_expat_attribs(x, attribs); | |
3620 | |
3621 xmlp->current = x; | |
3622 } else { | |
3623 x = xmlnode_new_tag(name); | |
3624 xmlnode_put_expat_attribs(x, attribs); | |
3625 xmlp->current = x; | |
3626 } | |
3627 } | |
3628 | |
3629 /* | |
3630 * Used by XML_Parse to end an xmlnode | |
3631 */ | |
3632 static void xmlstr2xmlnode_endElement(void *userdata, const char *name) | |
3633 { | |
3634 xmlstr2xmlnode_parser xmlp = (xmlstr2xmlnode_parser) userdata; | |
3635 xmlnode x; | |
3636 | |
3637 if (xmlp->current != NULL && (x = xmlnode_get_parent(xmlp->current)) != NULL) { | |
3638 xmlp->current = x; | |
3639 } | |
3640 } | |
3641 | |
3642 /* | |
3643 * Parse an XML-encoded string into an xmlnode tree | |
3644 * | |
3645 * Caller is responsible for freeing the returned xmlnode | |
3646 */ | |
3647 static xmlnode xmlstr2xmlnode(char *xmlstring) | |
3648 { | |
3649 xmlstr2xmlnode_parser my_parser = g_new(xmlstr2xmlnode_parser_struct, 1); | |
3650 xmlnode x = NULL; | |
3651 | |
3652 my_parser->parser = XML_ParserCreate(NULL); | |
3653 my_parser->current = NULL; | |
3654 | |
3655 XML_SetUserData(my_parser->parser, (void *)my_parser); | |
3656 XML_SetElementHandler(my_parser->parser, xmlstr2xmlnode_startElement, xmlstr2xmlnode_endElement); | |
3657 XML_SetCharacterDataHandler(my_parser->parser, xmlstr2xmlnode_charData); | |
3658 XML_Parse(my_parser->parser, xmlstring, strlen(xmlstring), 0); | |
3659 | |
3660 x = my_parser->current; | |
3661 | |
3662 XML_ParserFree(my_parser->parser); | |
3663 g_free(my_parser); | |
3664 | |
3665 return(x); | |
3666 } | |
3667 | |
3668 /* | |
3669 * Insert a tag node into an xmlnode tree, recursively inserting parent tag | |
3670 * nodes as necessary | |
3671 * | |
3672 * Returns pointer to inserted node | |
3673 * | |
3674 * Note to hackers: this code is designed to be re-entrant (it's recursive--it | |
3675 * calls itself), so don't put any "static"s in here! | |
3676 */ | |
3677 static xmlnode insert_tag_to_parent_tag(xmlnode start, const char *parent_tag, const char *new_tag) | |
3678 { | |
3679 xmlnode x = NULL; | |
3680 | |
3681 /* | |
3682 * If the parent tag wasn't specified, see if we can get it | |
3683 * from the vCard template struct. | |
3684 */ | |
3685 if(parent_tag == NULL) { | |
3686 struct vcard_template *vc_tp = vcard_template_data; | |
3687 | |
3688 while(vc_tp->label != NULL) { | |
3689 if(strcmp(vc_tp->tag, new_tag) == 0) { | |
3690 parent_tag = vc_tp->ptag; | |
3691 break; | |
3692 } | |
3693 ++vc_tp; | |
3694 } | |
3695 } | |
3696 | |
3697 /* | |
3698 * If we have a parent tag... | |
3699 */ | |
3700 if(parent_tag != NULL ) { | |
3701 /* | |
3702 * Try to get the parent node for a tag | |
3703 */ | |
3704 if((x = xmlnode_get_tag(start, parent_tag)) == NULL) { | |
3705 /* | |
3706 * Descend? | |
3707 */ | |
3708 char *grand_parent = strcpy(g_malloc(strlen(parent_tag) + 1), parent_tag); | |
3709 char *parent; | |
3710 | |
3711 if((parent = strrchr(grand_parent, '/')) != NULL) { | |
3712 *(parent++) = '\0'; | |
3713 x = insert_tag_to_parent_tag(start, grand_parent, parent); | |
3714 } else { | |
3715 x = xmlnode_insert_tag(start, grand_parent); | |
3716 } | |
3717 g_free(grand_parent); | |
3718 } else { | |
3719 /* | |
3720 * We found *something* to be the parent node. | |
3721 * Note: may be the "root" node! | |
3722 */ | |
3723 xmlnode y; | |
3724 if((y = xmlnode_get_tag(x, new_tag)) != NULL) { | |
3725 return(y); | |
3726 } | |
3727 } | |
3728 } | |
3729 | |
3730 /* | |
3731 * insert the new tag into its parent node | |
3732 */ | |
3733 return(xmlnode_insert_tag((x == NULL? start : x), new_tag)); | |
3734 } | |
3735 | |
3736 /* | |
3737 * Find the tag name for a label | |
3738 * | |
3739 * Returns NULL on not found | |
3740 */ | |
3741 static char *tag_for_label(const char *label) | |
3742 { | |
3743 struct vcard_template *vc_tp = vcard_template_data; | |
3744 char *p = NULL; | |
3745 | |
3746 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
3747 if(strcmp(label, vc_tp->label) == 0) { | |
3748 p = vc_tp->tag; | |
3749 break; | |
3750 } | |
3751 } | |
3752 | |
3753 return(p); | |
3754 } | |
3755 | |
3756 /* | |
3757 * Send vCard info to Jabber server | |
3758 */ | |
3759 static void jabber_set_info(struct gaim_connection *gc, char *info) | |
3760 { | |
3761 xmlnode x, vc_node; | |
3762 char *id; | |
3763 struct jabber_data *jd = gc->proto_data; | |
3764 gjconn gjc = jd->gjc; | |
3765 | |
3766 x = xmlnode_new_tag("iq"); | |
3311 | 3767 xmlnode_put_attrib(x, "type", "set"); |
2956 | 3768 |
3769 id = gjab_getid(gjc); | |
3770 | |
3771 xmlnode_put_attrib(x, "id", id); | |
3772 | |
3773 /* | |
3774 * Send only if there's actually any *information* to send | |
3775 */ | |
3776 if((vc_node = xmlstr2xmlnode(info)) != NULL && xmlnode_get_name(vc_node) != NULL && | |
3777 g_strncasecmp(xmlnode_get_name(vc_node), "vcard", 5) == 0) { | |
3778 xmlnode_insert_tag_node(x, vc_node); | |
3779 debug_printf("jabber: vCard packet: %s\n", xmlnode2str(x)); | |
3780 gjab_send(gjc, x); | |
3781 } | |
3782 | |
3783 xmlnode_free(x); | |
3784 } | |
3785 | |
3786 /* | |
3787 * This is the callback from the "ok clicked" for "set vCard" | |
3788 * | |
3789 * Formats GSList data into XML-encoded string and returns a pointer | |
3790 * to said string. | |
3791 * | |
3792 * g_free()'ing the returned string space is the responsibility of | |
3793 * the caller. | |
3794 */ | |
3795 static gchar *jabber_format_info(MultiEntryDlg *b) | |
3796 { | |
3797 xmlnode vc_node; | |
3798 GSList *list; | |
3799 MultiEntryData *med; | |
3800 MultiTextData *mtd; | |
3801 char *p; | |
3802 | |
3803 struct tag_attr *tag_attr; | |
3804 | |
3805 vc_node = xmlnode_new_tag("vCard"); | |
3806 | |
3807 for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr) | |
3808 xmlnode_put_attrib(vc_node, tag_attr->attr, tag_attr->value); | |
3809 | |
3810 for(list = b->multi_entry_items; list != NULL; list = list->next) { | |
3811 med = (MultiEntryData *) list->data; | |
3812 if(med->label != NULL && med->text != NULL && (med->text)[0] != '\0') { | |
3813 if((p = tag_for_label(med->label)) != NULL) { | |
3814 xmlnode xp; | |
3815 if((xp = insert_tag_to_parent_tag(vc_node, NULL, p)) != NULL) { | |
3816 xmlnode_insert_cdata(xp, med->text, -1); | |
3817 } | |
3818 } | |
3819 } | |
3820 } | |
3821 | |
3822 for(list = b->multi_text_items; list != NULL; list = list->next) { | |
3823 mtd = (MultiTextData *) list->data; | |
3824 if(mtd->label != NULL && mtd->text != NULL && (mtd->text)[0] != '\0') { | |
3825 if((p = tag_for_label(mtd->label)) != NULL) { | |
3826 xmlnode xp; | |
3827 if((xp = insert_tag_to_parent_tag(vc_node, NULL, p)) != NULL) { | |
3828 xmlnode_insert_cdata(xp, mtd->text, -1); | |
3829 } | |
3830 } | |
3831 } | |
3832 } | |
3833 | |
3834 | |
3835 p = g_strdup(xmlnode2str(vc_node)); | |
3836 xmlnode_free(vc_node); | |
3837 | |
3838 return(p); | |
3839 } | |
3840 | |
3841 /* | |
3842 * This gets executed by the proto action | |
3843 * | |
3844 * Creates a new MultiEntryDlg struct, gets the XML-formatted user_info | |
3845 * string (if any) into GSLists for the (multi-entry) edit dialog and | |
3846 * calls the set_vcard dialog. | |
3847 */ | |
3848 static void jabber_setup_set_info(struct gaim_connection *gc) | |
3849 { | |
3850 MultiEntryData *data; | |
3851 const struct vcard_template *vc_tp; | |
3852 char *user_info; | |
3853 MultiEntryDlg *b = multi_entry_dialog_new(); | |
3854 char *cdata; | |
3855 xmlnode x_vc_data = NULL; | |
3856 struct aim_user *tmp = gc->user; | |
3857 b->user = tmp; | |
3858 | |
3859 | |
3860 /* | |
3861 * Get existing, XML-formatted, user info | |
3862 */ | |
3863 if((user_info = g_malloc(strlen(tmp->user_info) + 1)) != NULL) { | |
3864 strcpy(user_info, tmp->user_info); | |
3865 x_vc_data = xmlstr2xmlnode(user_info); | |
3866 } | |
3867 | |
3868 /* | |
3869 * Set up GSLists for edit with labels from "template," data from user info | |
3870 */ | |
3871 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
3872 if((vc_tp->label)[0] == '\0') | |
3873 continue; | |
3874 if(vc_tp->ptag == NULL) { | |
3875 cdata = xmlnode_get_tag_data(x_vc_data, vc_tp->tag); | |
3876 } else { | |
3877 gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag); | |
3878 cdata = xmlnode_get_tag_data(x_vc_data, tag); | |
3879 g_free(tag); | |
3880 } | |
3881 if(strcmp(vc_tp->tag, "DESC") == 0) { | |
3882 multi_text_list_update(&(b->multi_text_items), | |
3883 vc_tp->label, cdata, TRUE); | |
3884 } else { | |
3885 data = multi_entry_list_update(&(b->multi_entry_items), | |
3886 vc_tp->label, cdata, TRUE); | |
3887 data->visible = vc_tp->visible; | |
3888 data->editable = vc_tp->editable; | |
3889 } | |
3890 } | |
3891 | |
3892 | |
3893 if(x_vc_data != NULL) { | |
3894 xmlnode_free(x_vc_data); | |
3895 } else { | |
3896 /* | |
3897 * Early Beta versions had a different user_info storage format--let's | |
3898 * see if that works. | |
3899 * | |
3900 * This goes away RSN. | |
3901 */ | |
3902 const char *record_separator = "<BR>"; | |
3903 const char *field_separator = ": "; | |
3904 gchar **str_list, **str_list_ptr, **str_list2; | |
3905 | |
3906 if((str_list = g_strsplit(user_info, record_separator, 0)) != NULL) { | |
3907 for(str_list_ptr = str_list; *str_list_ptr != NULL; ++str_list_ptr) { | |
3908 str_list2 = g_strsplit(*str_list_ptr, field_separator, 2); | |
3909 if(str_list2[0] != NULL && str_list2[1] != NULL) { | |
3910 g_strstrip(str_list2[0]); | |
3911 g_strstrip(str_list2[1]); | |
3912 /* this is ugly--so far */ | |
3913 if(strcmp(str_list2[0], "Description") == 0) { | |
3914 multi_text_list_update(&(b->multi_text_items), | |
3915 str_list2[0], str_list2[1], FALSE); | |
3916 } else { | |
3917 multi_entry_list_update(&(b->multi_entry_items), | |
3918 str_list2[0], str_list2[1], FALSE); | |
3919 } | |
3920 } | |
3921 g_strfreev(str_list2); | |
3922 } | |
3923 g_strfreev(str_list); | |
3924 } | |
3925 } | |
3926 | |
3927 if(user_info != NULL) { | |
3928 g_free(user_info); | |
3929 } | |
3930 | |
2975 | 3931 b->title = _("Gaim - Edit Jabber vCard"); |
2956 | 3932 b->wmclass_name = "set_info"; |
3933 b->wmclass_class = "Gaim"; | |
3934 b->instructions->text = g_strdup(multi_entry_instructions); | |
2975 | 3935 b->entries_title = g_strdup(entries_title); |
2956 | 3936 |
3937 b->custom = (void *) jabber_format_info; | |
3938 | |
3939 show_set_vcard(b); | |
3940 } | |
3941 | |
3942 /*---------------------------------------*/ | |
3943 /* End Jabber "set info" (vCard) support */ | |
3944 /*---------------------------------------*/ | |
3945 | |
3946 /*----------------------------------------*/ | |
3947 /* Jabber "user registration" support */ | |
3948 /*----------------------------------------*/ | |
3949 | |
3950 /* | |
3951 * Three of the following four functions duplicate much of what | |
3952 * exists elsewhere: | |
3953 * | |
3954 * jabber_handleregresp() | |
3955 * gjab_reqreg() | |
3956 * jabber_handle_registration_state() | |
3957 * | |
3958 * It may be that an additional flag could be added to one of | |
3959 * the "local" structs and the duplicated code modified to | |
3960 * account for it--thus eliminating the duplication. Then again: | |
3961 * doing it the way it is may be much cleaner. | |
3962 * | |
3963 * TBD: Code to support requesting additional information server | |
3964 * wants at registration--incl. dialog. | |
3965 */ | |
3966 | |
3967 /* | |
3968 * Like jabber_handlepacket(), only different | |
3969 */ | |
3970 static void jabber_handleregresp(gjconn gjc, jpacket p) | |
3971 { | |
3972 if (jpacket_subtype(p) == JPACKET__RESULT) { | |
3973 xmlnode querynode; | |
3974 | |
3975 if((querynode = xmlnode_get_tag(p->x, "query")) != NULL) { | |
3976 char *xmlns; | |
3977 | |
3978 /* we damn well *better* have this! */ | |
3979 if((xmlns = xmlnode_get_attrib(querynode, "xmlns")) != NULL && | |
3980 strcmp(xmlns, NS_REGISTER) == 0) { | |
3981 | |
3982 char *tag; | |
3983 xmlnode child = xmlnode_get_firstchild(querynode); | |
3984 | |
3985 debug_printf("got registration requirments response!\n"); | |
3986 | |
3987 while(child != NULL) { | |
3988 if((tag = xmlnode_get_name(child)) != NULL) { | |
3989 char *data; | |
3990 | |
3991 fprintf(stderr, "DBG: got node: \"%s\"\n", tag); | |
3992 fflush(stderr); | |
3993 | |
3994 if((data = xmlnode_get_data(child)) != NULL) { | |
3995 fprintf(stderr, "DBG: got data: \"%s\"\n", data); | |
3996 fflush(stderr); | |
3997 } | |
3998 } | |
3999 child = xmlnode_get_nextsibling(child); | |
4000 } | |
4001 } | |
4002 } else { | |
4003 debug_printf("registration successful!\n"); | |
4004 | |
2975 | 4005 hide_login_progress_notice(GJ_GC(gjc), _("Server Registration successful!")); |
2956 | 4006 /* |
4007 * TBD: is this the correct way to do away with a | |
4008 * gaim_connection and all its associated memory | |
4009 * allocs, etc.? | |
4010 */ | |
4011 signoff(GJ_GC(gjc)); | |
4012 } | |
4013 | |
4014 } else { | |
4015 xmlnode xerr; | |
4016 char *errmsg = NULL; | |
4017 int errcode = 0; | |
4018 struct jabber_data *jd = GJ_GC(gjc)->proto_data; | |
4019 | |
4020 debug_printf("registration failed\n"); | |
4021 xerr = xmlnode_get_tag(p->x, "error"); | |
4022 if (xerr) { | |
4023 char msg[BUF_LONG]; | |
4024 errmsg = xmlnode_get_data(xerr); | |
4025 if (xmlnode_get_attrib(xerr, "code")) { | |
4026 errcode = atoi(xmlnode_get_attrib(xerr, "code")); | |
4027 g_snprintf(msg, sizeof(msg), "Error %d: %s", errcode, errmsg); | |
4028 } else | |
4029 g_snprintf(msg, sizeof(msg), "%s", errmsg); | |
4030 hide_login_progress(GJ_GC(gjc), msg); | |
4031 } else { | |
2975 | 4032 hide_login_progress(GJ_GC(gjc), _("Unknown registration error")); |
2956 | 4033 } |
4034 | |
4035 jd->die = TRUE; | |
4036 } | |
4037 } | |
4038 | |
4039 /* | |
4040 * Like gjab_reqauth(), only different | |
4041 */ | |
4042 static void gjab_reqreg(gjconn gjc) | |
4043 { | |
4044 xmlnode x, y, z; | |
4045 char *user; | |
4046 | |
4047 if (!gjc) | |
4048 return; | |
4049 | |
4050 x = jutil_iqnew(JPACKET__SET, NS_REGISTER); | |
4051 y = xmlnode_get_tag(x, "query"); | |
4052 | |
4053 user = gjc->user->user; | |
4054 | |
4055 if (user) { | |
4056 z = xmlnode_insert_tag(y, "username"); | |
4057 xmlnode_insert_cdata(z, user, -1); | |
4058 } | |
4059 z = xmlnode_insert_tag(y, "password"); | |
4060 xmlnode_insert_cdata(z, gjc->pass, -1); | |
4061 | |
4062 debug_printf("jabber: registration packet: %s\n", xmlnode2str(x)); | |
4063 gjab_send(gjc, x); | |
4064 xmlnode_free(x); | |
4065 } | |
4066 | |
4067 /* | |
4068 * Like jabber_handlestate(), only different | |
4069 */ | |
4070 static void jabber_handle_registration_state(gjconn gjc, int state) | |
4071 { | |
4072 switch (state) { | |
4073 case JCONN_STATE_OFF: | |
3074 | 4074 if(gjc->was_connected) { |
4075 hide_login_progress_error(GJ_GC(gjc), _("Connection lost")); | |
4076 } else { | |
4077 hide_login_progress(GJ_GC(gjc), _("Unable to connect")); | |
4078 } | |
2956 | 4079 signoff(GJ_GC(gjc)); |
4080 break; | |
4081 case JCONN_STATE_CONNECTED: | |
3074 | 4082 gjc->was_connected = 1; |
2956 | 4083 /* |
4084 * TBD? | |
2975 | 4085 set_login_progress(GJ_GC(gjc), 2, _("Connected")); |
2956 | 4086 */ |
4087 break; | |
4088 case JCONN_STATE_ON: | |
4089 /* | |
4090 * TBD? | |
2975 | 4091 set_login_progress(GJ_GC(gjc), 3, _("Requesting Authentication Method")); |
2956 | 4092 */ |
4093 gjab_reqreg(gjc); | |
4094 /* | |
4095 * TBD: A work-in-progress | |
4096 gjab_reqregreqs(gjc); | |
4097 */ | |
4098 break; | |
4099 default: | |
4100 debug_printf("state change: %d\n", state); | |
4101 } | |
4102 return; | |
4103 } | |
4104 | |
4105 /* | |
4106 * Like jabber_login(), only different | |
4107 */ | |
4108 void jabber_register_user(struct aim_user *au) | |
4109 { | |
4110 struct gaim_connection *gc = new_gaim_conn(au); | |
4111 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); | |
4112 char *loginname = create_valid_jid(au->username, DEFAULT_SERVER, "GAIM"); | |
4113 | |
4114 /* | |
4115 * These do nothing during registration | |
4116 */ | |
3311 | 4117 jd->buddies = NULL; |
2956 | 4118 jd->chats = NULL; |
4119 | |
4120 if ((jd->gjc = gjab_new(loginname, au->password, gc)) == NULL) { | |
4121 g_free(loginname); | |
4122 debug_printf("jabber: unable to connect (jab_new failed)\n"); | |
2975 | 4123 hide_login_progress(gc, _("Unable to connect")); |
2956 | 4124 signoff(gc); |
4125 } else { | |
4126 gjab_state_handler(jd->gjc, jabber_handle_registration_state); | |
4127 gjab_packet_handler(jd->gjc, jabber_handleregresp); | |
4128 jd->gjc->queries = NULL; | |
4129 gjab_start(jd->gjc); | |
4130 } | |
4131 | |
4132 g_free(loginname); | |
4133 } | |
4134 | |
4135 /*----------------------------------------*/ | |
4136 /* End Jabber "user registration" support */ | |
4137 /*----------------------------------------*/ | |
4138 | |
4139 static void jabber_do_action(struct gaim_connection *gc, char *act) | |
4140 { | |
2975 | 4141 if (!strcmp(act, _("Set User Info"))) { |
2956 | 4142 jabber_setup_set_info(gc); |
4143 /* | |
2975 | 4144 } else if (!strcmp(act, _("Set Dir Info"))) { |
2956 | 4145 show_set_dir(gc); |
3257 | 4146 */ |
2975 | 4147 } else if (!strcmp(act, _("Change Password"))) { |
2956 | 4148 show_change_passwd(gc); |
4149 } | |
4150 } | |
4151 | |
4152 static GList *jabber_actions() | |
4153 { | |
4154 GList *m = NULL; | |
4155 | |
2975 | 4156 m = g_list_append(m, _("Set User Info")); |
2956 | 4157 /* |
2975 | 4158 m = g_list_append(m, _("Set Dir Info")); |
3257 | 4159 */ |
2975 | 4160 m = g_list_append(m, _("Change Password")); |
2956 | 4161 |
4162 return m; | |
4163 } | |
4164 | |
2086 | 4165 static struct prpl *my_protocol = NULL; |
4166 | |
3630 | 4167 G_MODULE_EXPORT void jabber_init(struct prpl *ret) |
2086 | 4168 { |
4169 /* the NULL's aren't required but they're nice to have */ | |
3572 | 4170 struct proto_user_opt *puo; |
2086 | 4171 ret->protocol = PROTO_JABBER; |
4172 ret->options = OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_CHAT_TOPIC; | |
3572 | 4173 ret->name = g_strdup("Jabber"); |
2086 | 4174 ret->list_icon = jabber_list_icon; |
4175 ret->away_states = jabber_away_states; | |
2956 | 4176 ret->actions = jabber_actions; |
4177 ret->do_action = jabber_do_action; | |
2086 | 4178 ret->buddy_menu = jabber_buddy_menu; |
3314 | 4179 ret->edit_buddy_menu = jabber_edit_buddy_menu; |
2086 | 4180 ret->login = jabber_login; |
4181 ret->close = jabber_close; | |
4182 ret->send_im = jabber_send_im; | |
2956 | 4183 ret->set_info = jabber_set_info; |
2086 | 4184 ret->get_info = jabber_get_info; |
2956 | 4185 ret->get_cb_info = jabber_get_cb_info; |
4186 ret->get_cb_away = jabber_get_cb_away_msg; | |
2086 | 4187 ret->set_away = jabber_set_away; |
4188 ret->set_dir = NULL; | |
4189 ret->get_dir = NULL; | |
4190 ret->dir_search = NULL; | |
4191 ret->set_idle = jabber_set_idle; | |
3257 | 4192 ret->change_passwd = jabber_change_passwd; |
2086 | 4193 ret->add_buddy = jabber_add_buddy; |
4194 ret->add_buddies = NULL; | |
4195 ret->remove_buddy = jabber_remove_buddy; | |
4196 ret->add_permit = NULL; | |
4197 ret->add_deny = NULL; | |
4198 ret->rem_permit = NULL; | |
4199 ret->rem_deny = NULL; | |
4200 ret->set_permit_deny = NULL; | |
4201 ret->warn = NULL; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
4202 ret->chat_info = jabber_chat_info; |
2086 | 4203 ret->join_chat = jabber_join_chat; |
4204 ret->chat_invite = jabber_chat_invite; | |
4205 ret->chat_leave = jabber_chat_leave; | |
4206 ret->chat_whisper = jabber_chat_whisper; | |
4207 ret->chat_send = jabber_chat_send; | |
4208 ret->keepalive = jabber_keepalive; | |
4209 ret->normalize = jabber_normalize; | |
2956 | 4210 ret->register_user = jabber_register_user; |
3349 | 4211 ret->alias_buddy = jabber_alias_buddy; |
3136 | 4212 ret->group_buddy = jabber_group_change; |
3311 | 4213 ret->send_typing = jabber_send_typing; |
4214 ret->convo_closed = jabber_convo_closed; | |
3349 | 4215 ret->rename_group = jabber_rename_group; |
3630 | 4216 ret->file_transfer_out = NULL; /* TODO */ |
4217 ret->file_transfer_in = jabber_file_transfer_in; | |
4218 ret->file_transfer_data_chunk = NULL; /* TODO */ | |
4219 ret->file_transfer_done = jabber_file_transfer_done; | |
4220 ret->file_transfer_cancel = jabber_file_transfer_cancel; | |
4221 | |
3572 | 4222 puo = g_new0(struct proto_user_opt, 1); |
4223 puo->label = g_strdup("Port:"); | |
4224 puo->def = g_strdup("5222"); | |
4225 puo->pos = USEROPT_PORT; | |
4226 ret->user_opts = g_list_append(ret->user_opts, puo); | |
2086 | 4227 |
4228 my_protocol = ret; | |
4229 } | |
4230 | |
4231 #ifndef STATIC | |
4232 | |
3630 | 4233 G_MODULE_EXPORT void gaim_prpl_init(struct prpl *prpl) |
2086 | 4234 { |
3572 | 4235 jabber_init(prpl); |
4236 prpl->plug->desc.api_version = PLUGIN_API_VERSION; | |
2086 | 4237 } |
4238 | |
4239 #endif | |
3311 | 4240 |
4241 /* | |
4242 * Local variables: | |
4243 * c-indentation-style: k&r | |
4244 * c-basic-offset: 8 | |
4245 * indent-tabs-mode: notnil | |
4246 * End: | |
4247 * | |
4248 * vim: shiftwidth=8: | |
4249 */ |