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