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