Mercurial > pidgin.yaz
annotate src/protocols/jabber/jabber.c @ 2956:b68c648618a3
[gaim-migrate @ 2969]
I Love Rock & Roll....
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Sun, 17 Feb 2002 18:08:12 +0000 |
parents | b1e300a85678 |
children | 626729653436 |
rev | line source |
---|---|
2086 | 1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
2 /* | |
3 * gaim | |
4 * | |
5 * Some code copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
6 * libfaim code copyright 1998, 1999 Adam Fritzler <afritz@auk.cx> | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include "config.h" | |
26 #endif | |
27 | |
28 | |
29 #include <netdb.h> | |
30 #include <unistd.h> | |
31 #include <errno.h> | |
32 #include <netinet/in.h> | |
33 #include <arpa/inet.h> | |
34 #include <string.h> | |
35 #include <stdlib.h> | |
36 #include <stdio.h> | |
37 #include <time.h> | |
38 #include <sys/socket.h> | |
39 #include <sys/utsname.h> | |
40 #include <sys/stat.h> | |
41 #include "multi.h" | |
42 #include "prpl.h" | |
43 #include "gaim.h" | |
2232
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
44 #ifdef MAX |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
45 #undef MAX |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
46 #endif |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
47 #ifdef MIN |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
48 #undef MIN |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
49 #endif |
2086 | 50 #include "jabber.h" |
51 #include "proxy.h" | |
52 | |
53 #include "pixmaps/available.xpm" | |
54 #include "pixmaps/available-away.xpm" | |
55 #include "pixmaps/available-chat.xpm" | |
56 #include "pixmaps/available-xa.xpm" | |
57 #include "pixmaps/available-dnd.xpm" | |
58 | |
59 /* The priv member of gjconn's is a gaim_connection for now. */ | |
60 #define GJ_GC(x) ((struct gaim_connection *)(x)->priv) | |
61 | |
62 #define IQID_AUTH "__AUTH__" | |
63 | |
64 #define IQ_NONE -1 | |
65 #define IQ_AUTH 0 | |
66 #define IQ_ROSTER 1 | |
67 | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
68 #define UC_AWAY (0x02 | UC_UNAVAILABLE) |
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
69 #define UC_CHAT 0x04 |
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
70 #define UC_XA (0x08 | UC_UNAVAILABLE) |
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
71 #define UC_DND (0x10 | UC_UNAVAILABLE) |
2086 | 72 |
73 #define DEFAULT_SERVER "jabber.org" | |
74 #define DEFAULT_GROUPCHAT "conference.jabber.org" | |
75 #define DEFAULT_PORT 5222 | |
76 | |
77 #define USEROPT_PORT 0 | |
78 | |
79 typedef struct gjconn_struct { | |
80 /* Core structure */ | |
81 pool p; /* Memory allocation pool */ | |
82 int state; /* Connection state flag */ | |
83 int fd; /* Connection file descriptor */ | |
84 jid user; /* User info */ | |
85 char *pass; /* User passwd */ | |
86 | |
87 /* Stream stuff */ | |
88 int id; /* id counter for jab_getid() function */ | |
89 char idbuf[9]; /* temporary storage for jab_getid() */ | |
90 char *sid; /* stream id from server, for digest auth */ | |
91 XML_Parser parser; /* Parser instance */ | |
92 xmlnode current; /* Current node in parsing instance.. */ | |
93 | |
94 /* Event callback ptrs */ | |
2956 | 95 void (*on_state)(struct gjconn_struct *gjc, int state); |
96 void (*on_packet)(struct gjconn_struct *gjc, jpacket p); | |
97 | |
98 GHashTable *queries; /* query tracker */ | |
2086 | 99 |
100 void *priv; | |
101 | |
102 } *gjconn, gjconn_struct; | |
103 | |
2956 | 104 typedef void (*gjconn_state_h)(gjconn gjc, int state); |
105 typedef void (*gjconn_packet_h)(gjconn gjc, jpacket p); | |
2086 | 106 |
107 static gjconn gjab_new(char *user, char *pass, void *priv); | |
2956 | 108 static void gjab_delete(gjconn gjc); |
109 static void gjab_state_handler(gjconn gjc, gjconn_state_h h); | |
110 static void gjab_packet_handler(gjconn gjc, gjconn_packet_h h); | |
111 static void gjab_start(gjconn gjc); | |
112 static void gjab_stop(gjconn gjc); | |
2086 | 113 /* |
2956 | 114 static int gjab_getfd(gjconn gjc); |
115 static jid gjab_getjid(gjconn gjc); | |
116 static char *gjab_getsid(gjconn gjc); | |
2086 | 117 */ |
2956 | 118 static char *gjab_getid(gjconn gjc); |
119 static void gjab_send(gjconn gjc, xmlnode x); | |
120 static void gjab_send_raw(gjconn gjc, const char *str); | |
121 static void gjab_recv(gjconn gjc); | |
122 static void gjab_auth(gjconn gjc); | |
123 | |
124 /* | |
125 * It is *this* to which we point the gaim_connection proto_data | |
126 */ | |
2086 | 127 struct jabber_data { |
2956 | 128 gjconn gjc; |
2086 | 129 gboolean did_import; |
2956 | 130 GSList *chats; |
2086 | 131 GHashTable *hash; |
132 time_t idle; | |
2800
0ad63a625eec
[gaim-migrate @ 2813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
133 gboolean die; |
2086 | 134 }; |
135 | |
2956 | 136 /* |
137 * Jabber "chat group" info. Pointers to these go in jabber_data | |
138 * pending and existing chats lists. | |
139 */ | |
2086 | 140 struct jabber_chat { |
141 jid Jid; | |
142 struct gaim_connection *gc; | |
143 struct conversation *b; | |
144 int id; | |
2956 | 145 int state; |
2086 | 146 }; |
147 | |
2956 | 148 /* |
149 * Jabber chat states... | |
150 * | |
151 * Note: due to a bug in one version of the Jabber server, subscriptions | |
152 * to chat groups aren't (always?) properly removed at the server. The | |
153 * result is clients receive Jabber "presence" notifications for JIDs | |
154 * they no longer care about. The problem with such vestigial notifies is | |
155 * that we really have no way of telling if it's vestigial or if it's a | |
156 * valid "buddy" presence notification. So we keep jabber_chat structs | |
157 * around after leaving a chat group and simply mark them "closed." That | |
158 * way we can test for such errant presence notifications. I.e.: if we | |
159 * get a presence notfication from a JID that matches a chat group JID, | |
160 * we disregard it. | |
161 */ | |
162 #define JCS_PENDING 1 /* pending */ | |
163 #define JCS_ACTIVE 2 /* active */ | |
164 #define JCS_CLOSED 3 /* closed */ | |
165 | |
166 | |
2086 | 167 static char *jabber_name() |
168 { | |
169 return "Jabber"; | |
170 } | |
171 | |
2956 | 172 #define STATE_EVT(arg) if(gjc->on_state) { (gjc->on_state)(gjc, (arg) ); } |
173 | |
174 static void jabber_handlevcard(gjconn, xmlnode, char *); | |
2086 | 175 |
176 static char *create_valid_jid(const char *given, char *server, char *resource) | |
177 { | |
178 char *valid; | |
179 | |
180 if (!strchr(given, '@')) | |
181 valid = g_strdup_printf("%s@%s/%s", given, server, resource); | |
182 else if (!strchr(strchr(given, '@'), '/')) | |
183 valid = g_strdup_printf("%s/%s", given, resource); | |
184 else | |
185 valid = g_strdup(given); | |
186 | |
187 return valid; | |
188 } | |
189 | |
190 static gjconn gjab_new(char *user, char *pass, void *priv) | |
191 { | |
192 pool p; | |
2956 | 193 gjconn gjc; |
2086 | 194 |
195 if (!user) | |
196 return (NULL); | |
197 | |
198 p = pool_new(); | |
199 if (!p) | |
200 return (NULL); | |
2956 | 201 gjc = pmalloc_x(p, sizeof(gjconn_struct), 0); |
202 if (!gjc) { | |
203 pool_free(p); /* no need for this anymore! */ | |
2086 | 204 return (NULL); |
2956 | 205 } |
206 gjc->p = p; | |
207 | |
208 gjc->user = jid_new(p, user); | |
209 gjc->pass = pstrdup(p, pass); | |
210 | |
211 gjc->state = JCONN_STATE_OFF; | |
212 gjc->id = 1; | |
213 gjc->fd = -1; | |
214 | |
215 gjc->priv = priv; | |
216 | |
217 return gjc; | |
2086 | 218 } |
219 | |
2956 | 220 static void gjab_delete(gjconn gjc) |
2086 | 221 { |
2956 | 222 if (!gjc) |
2086 | 223 return; |
224 | |
2956 | 225 gjab_stop(gjc); |
226 pool_free(gjc->p); | |
2086 | 227 } |
228 | |
2956 | 229 static void gjab_state_handler(gjconn gjc, gjconn_state_h h) |
2086 | 230 { |
2956 | 231 if (!gjc) |
2086 | 232 return; |
233 | |
2956 | 234 gjc->on_state = h; |
2086 | 235 } |
236 | |
2956 | 237 static void gjab_packet_handler(gjconn gjc, gjconn_packet_h h) |
2086 | 238 { |
2956 | 239 if (!gjc) |
2086 | 240 return; |
241 | |
2956 | 242 gjc->on_packet = h; |
2086 | 243 } |
244 | |
2956 | 245 static void gjab_stop(gjconn gjc) |
2086 | 246 { |
2956 | 247 if (!gjc || gjc->state == JCONN_STATE_OFF) |
2086 | 248 return; |
249 | |
2956 | 250 gjab_send_raw(gjc, "</stream:stream>"); |
251 gjc->state = JCONN_STATE_OFF; | |
252 close(gjc->fd); | |
253 gjc->fd = -1; | |
254 XML_ParserFree(gjc->parser); | |
255 gjc->parser = NULL; | |
2086 | 256 } |
257 | |
258 /* | |
2956 | 259 static int gjab_getfd(gjconn gjc) |
2086 | 260 { |
2956 | 261 if (gjc) |
262 return gjc->fd; | |
2086 | 263 else |
264 return -1; | |
265 } | |
266 | |
2956 | 267 static jid gjab_getjid(gjconn gjc) |
2086 | 268 { |
2956 | 269 if (gjc) |
270 return (gjc->user); | |
2086 | 271 else |
272 return NULL; | |
273 } | |
274 | |
2956 | 275 static char *gjab_getsid(gjconn gjc) |
2086 | 276 { |
2956 | 277 if (gjc) |
278 return (gjc->sid); | |
2086 | 279 else |
280 return NULL; | |
281 } | |
282 */ | |
283 | |
2956 | 284 static char *gjab_getid(gjconn gjc) |
2086 | 285 { |
2956 | 286 snprintf(gjc->idbuf, 8, "%d", gjc->id++); |
287 return &gjc->idbuf[0]; | |
2086 | 288 } |
289 | |
2956 | 290 static void gjab_send(gjconn gjc, xmlnode x) |
2086 | 291 { |
2956 | 292 if (gjc && gjc->state != JCONN_STATE_OFF) { |
2086 | 293 char *buf = xmlnode2str(x); |
294 if (buf) | |
2956 | 295 write(gjc->fd, buf, strlen(buf)); |
2086 | 296 debug_printf("gjab_send: %s\n", buf); |
297 } | |
298 } | |
299 | |
2956 | 300 static void gjab_send_raw(gjconn gjc, const char *str) |
2086 | 301 { |
2956 | 302 if (gjc && gjc->state != JCONN_STATE_OFF) { |
303 /* | |
304 * JFIXME: No error detection?!?! | |
305 */ | |
306 if(write(gjc->fd, str, strlen(str)) < 0) { | |
307 fprintf(stderr, "DBG: Problem sending. Error: %d\n", errno); | |
308 fflush(stderr); | |
309 } | |
2086 | 310 debug_printf("gjab_send_raw: %s\n", str); |
311 } | |
312 } | |
313 | |
2956 | 314 static void gjab_reqroster(gjconn gjc) |
2086 | 315 { |
316 xmlnode x; | |
317 | |
318 x = jutil_iqnew(JPACKET__GET, NS_ROSTER); | |
2956 | 319 xmlnode_put_attrib(x, "id", gjab_getid(gjc)); |
320 | |
321 gjab_send(gjc, x); | |
2086 | 322 xmlnode_free(x); |
323 } | |
324 | |
2956 | 325 static void gjab_reqauth(gjconn gjc) |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
326 { |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
327 xmlnode x, y, z; |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
328 char *user; |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
329 |
2956 | 330 if (!gjc) |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
331 return; |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
332 |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
333 x = jutil_iqnew(JPACKET__GET, NS_AUTH); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
334 xmlnode_put_attrib(x, "id", IQID_AUTH); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
335 y = xmlnode_get_tag(x, "query"); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
336 |
2956 | 337 user = gjc->user->user; |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
338 |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
339 if (user) { |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
340 z = xmlnode_insert_tag(y, "username"); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
341 xmlnode_insert_cdata(z, user, -1); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
342 } |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
343 |
2956 | 344 gjab_send(gjc, x); |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
345 xmlnode_free(x); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
346 } |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
347 |
2956 | 348 static void gjab_auth(gjconn gjc) |
2086 | 349 { |
350 xmlnode x, y, z; | |
351 char *hash, *user; | |
352 | |
2956 | 353 if (!gjc) |
2086 | 354 return; |
355 | |
356 x = jutil_iqnew(JPACKET__SET, NS_AUTH); | |
357 xmlnode_put_attrib(x, "id", IQID_AUTH); | |
358 y = xmlnode_get_tag(x, "query"); | |
359 | |
2956 | 360 user = gjc->user->user; |
2086 | 361 |
362 if (user) { | |
363 z = xmlnode_insert_tag(y, "username"); | |
364 xmlnode_insert_cdata(z, user, -1); | |
365 } | |
366 | |
367 z = xmlnode_insert_tag(y, "resource"); | |
2956 | 368 xmlnode_insert_cdata(z, gjc->user->resource, -1); |
369 | |
370 if (gjc->sid) { | |
371 debug_printf("digest authentication (sid %s)\n", gjc->sid); | |
2086 | 372 z = xmlnode_insert_tag(y, "digest"); |
2956 | 373 hash = pmalloc(x->p, strlen(gjc->sid) + strlen(gjc->pass) + 1); |
374 strcpy(hash, gjc->sid); | |
375 strcat(hash, gjc->pass); | |
2086 | 376 hash = shahash(hash); |
377 xmlnode_insert_cdata(z, hash, 40); | |
378 } else { | |
379 z = xmlnode_insert_tag(y, "password"); | |
2956 | 380 xmlnode_insert_cdata(z, gjc->pass, -1); |
2086 | 381 } |
382 | |
2956 | 383 gjab_send(gjc, x); |
2086 | 384 xmlnode_free(x); |
385 | |
386 return; | |
387 } | |
388 | |
2956 | 389 static void gjab_recv(gjconn gjc) |
2086 | 390 { |
391 static char buf[4096]; | |
392 int len; | |
393 | |
2956 | 394 if (!gjc || gjc->state == JCONN_STATE_OFF) |
2086 | 395 return; |
396 | |
2956 | 397 if ((len = read(gjc->fd, buf, sizeof(buf) - 1))) { |
398 struct jabber_data *jd = GJ_GC(gjc)->proto_data; | |
2086 | 399 buf[len] = '\0'; |
400 debug_printf("input (len %d): %s\n", len, buf); | |
2956 | 401 XML_Parse(gjc->parser, buf, len, 0); |
2800
0ad63a625eec
[gaim-migrate @ 2813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
402 if (jd->die) |
2956 | 403 signoff(GJ_GC(gjc)); |
2086 | 404 } else if (len <= 0) { |
405 STATE_EVT(JCONN_STATE_OFF) | |
406 } | |
407 } | |
408 | |
409 static void startElement(void *userdata, const char *name, const char **attribs) | |
410 { | |
411 xmlnode x; | |
2956 | 412 gjconn gjc = (gjconn) userdata; |
413 | |
414 if (gjc->current) { | |
2086 | 415 /* Append the node to the current one */ |
2956 | 416 x = xmlnode_insert_tag(gjc->current, name); |
2086 | 417 xmlnode_put_expat_attribs(x, attribs); |
418 | |
2956 | 419 gjc->current = x; |
2086 | 420 } else { |
421 x = xmlnode_new_tag(name); | |
422 xmlnode_put_expat_attribs(x, attribs); | |
423 if (strcmp(name, "stream:stream") == 0) { | |
424 /* special case: name == stream:stream */ | |
425 /* id attrib of stream is stored for digest auth */ | |
2956 | 426 gjc->sid = g_strdup(xmlnode_get_attrib(x, "id")); |
2086 | 427 /* STATE_EVT(JCONN_STATE_AUTH) */ |
2635
8c75e59e4bdf
[gaim-migrate @ 2648]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2607
diff
changeset
|
428 xmlnode_free(x); |
2086 | 429 } else { |
2956 | 430 gjc->current = x; |
2086 | 431 } |
432 } | |
433 } | |
434 | |
435 static void endElement(void *userdata, const char *name) | |
436 { | |
2956 | 437 gjconn gjc = (gjconn) userdata; |
2086 | 438 xmlnode x; |
439 jpacket p; | |
440 | |
2956 | 441 if (gjc->current == NULL) { |
2086 | 442 /* we got </stream:stream> */ |
443 STATE_EVT(JCONN_STATE_OFF) | |
444 return; | |
445 } | |
446 | |
2956 | 447 x = xmlnode_get_parent(gjc->current); |
2086 | 448 |
449 if (!x) { | |
450 /* it is time to fire the event */ | |
2956 | 451 p = jpacket_new(gjc->current); |
452 | |
453 if (gjc->on_packet) | |
454 (gjc->on_packet) (gjc, p); | |
2086 | 455 else |
2956 | 456 xmlnode_free(gjc->current); |
2086 | 457 } |
458 | |
2956 | 459 gjc->current = x; |
2086 | 460 } |
461 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
462 static void jabber_callback(gpointer data, gint source, GaimInputCondition condition) |
2086 | 463 { |
464 struct gaim_connection *gc = (struct gaim_connection *)data; | |
465 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; | |
466 | |
2956 | 467 gjab_recv(jd->gjc); |
2086 | 468 } |
469 | |
470 static void charData(void *userdata, const char *s, int slen) | |
471 { | |
2956 | 472 gjconn gjc = (gjconn) userdata; |
473 | |
474 if (gjc->current) | |
475 xmlnode_insert_cdata(gjc->current, s, slen); | |
2086 | 476 } |
477 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
478 static void gjab_connected(gpointer data, gint source, GaimInputCondition cond) |
2086 | 479 { |
480 xmlnode x; | |
481 char *t, *t2; | |
482 struct gaim_connection *gc = data; | |
483 struct jabber_data *jd; | |
2956 | 484 gjconn gjc; |
2086 | 485 |
486 if (!g_slist_find(connections, gc)) { | |
487 close(source); | |
488 return; | |
489 } | |
490 | |
491 jd = gc->proto_data; | |
2956 | 492 gjc = jd->gjc; |
493 | |
494 if (gjc->fd != source) | |
495 gjc->fd = source; | |
2300
d2686f757d6e
[gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
496 |
2086 | 497 if (source == -1) { |
498 STATE_EVT(JCONN_STATE_OFF) | |
499 return; | |
500 } | |
501 | |
2956 | 502 gjc->state = JCONN_STATE_CONNECTED; |
2086 | 503 STATE_EVT(JCONN_STATE_CONNECTED) |
504 | |
505 /* start stream */ | |
2956 | 506 x = jutil_header(NS_CLIENT, gjc->user->server); |
2086 | 507 t = xmlnode2str(x); |
508 /* this is ugly, we can create the string here instead of jutil_header */ | |
509 /* what do you think about it? -madcat */ | |
510 t2 = strstr(t, "/>"); | |
511 *t2++ = '>'; | |
512 *t2 = '\0'; | |
2956 | 513 gjab_send_raw(gjc, "<?xml version='1.0'?>"); |
514 gjab_send_raw(gjc, t); | |
2086 | 515 xmlnode_free(x); |
516 | |
2956 | 517 gjc->state = JCONN_STATE_ON; |
2086 | 518 STATE_EVT(JCONN_STATE_ON); |
519 | |
2956 | 520 gc = GJ_GC(gjc); |
521 gc->inpa = gaim_input_add(gjc->fd, GAIM_INPUT_READ, jabber_callback, gc); | |
2086 | 522 } |
523 | |
2956 | 524 static void gjab_start(gjconn gjc) |
2086 | 525 { |
526 struct aim_user *user; | |
527 int port; | |
528 | |
2956 | 529 if (!gjc || gjc->state != JCONN_STATE_OFF) |
2086 | 530 return; |
531 | |
2956 | 532 user = GJ_GC(gjc)->user; |
2086 | 533 port = user->proto_opt[USEROPT_PORT][0] ? atoi(user->proto_opt[USEROPT_PORT]) : DEFAULT_PORT; |
534 | |
2956 | 535 gjc->parser = XML_ParserCreate(NULL); |
536 XML_SetUserData(gjc->parser, (void *)gjc); | |
537 XML_SetElementHandler(gjc->parser, startElement, endElement); | |
538 XML_SetCharacterDataHandler(gjc->parser, charData); | |
539 | |
540 gjc->fd = proxy_connect(gjc->user->server, port, gjab_connected, GJ_GC(gjc)); | |
541 if (!user->gc || (gjc->fd < 0)) { | |
2086 | 542 STATE_EVT(JCONN_STATE_OFF) |
543 return; | |
544 } | |
545 } | |
546 | |
2956 | 547 /* |
548 * Find chat by chat group name | |
549 */ | |
2086 | 550 static struct conversation *find_chat(struct gaim_connection *gc, char *name) |
551 { | |
552 GSList *bcs = gc->buddy_chats; | |
553 struct conversation *b = NULL; | |
554 char *chat = g_strdup(normalize(name)); | |
555 | |
556 while (bcs) { | |
557 b = bcs->data; | |
558 if (!strcasecmp(normalize(b->name), chat)) | |
559 break; | |
560 b = NULL; | |
561 bcs = bcs->next; | |
562 } | |
563 | |
564 g_free(chat); | |
565 return b; | |
566 } | |
567 | |
2956 | 568 /* |
569 * Find chat by "chat id" | |
570 * | |
571 * Returns: 0 on success and jabber_chat pointer set | |
572 * or -EINVAL on error and jabber_chat pointer is | |
573 * undefined. | |
574 * | |
575 * TBD: Slogging through the buddy_chats list seems | |
576 * redundant since the chat i.d. is mirrored in the | |
577 * jabber_chat struct list. But that's the way it | |
578 * was, so that's the way I'm leaving it--for now. | |
579 */ | |
580 static int jabber_find_chat_by_convo_id(struct gaim_connection *gc, int id, struct jabber_chat **jc) | |
2086 | 581 { |
2956 | 582 GSList *bcs = gc->buddy_chats; |
583 struct conversation *b = NULL; | |
584 struct jabber_data *jd = gc->proto_data; | |
585 | |
586 *jc = NULL; | |
587 | |
588 while(bcs != NULL) { | |
589 b = bcs->data; | |
590 if (id == b->id) | |
591 break; | |
592 bcs = bcs->next; | |
593 } | |
594 | |
595 if (bcs != NULL) { | |
596 bcs = jd->chats; | |
597 while (bcs != NULL) { | |
598 *jc = bcs->data; | |
599 if ((*jc)->state == JCS_ACTIVE && (*jc)->b == b) | |
600 break; | |
601 bcs = bcs->next; | |
602 } | |
603 } | |
604 | |
605 return(bcs == NULL? -EINVAL : 0); | |
606 } | |
607 | |
608 /* | |
609 * Find any chat | |
610 */ | |
611 static struct jabber_chat *find_any_chat(struct gaim_connection *gc, jid chat) | |
612 { | |
613 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats; | |
2086 | 614 struct jabber_chat *jc = NULL; |
615 | |
2956 | 616 while (jcs) { |
617 jc = jcs->data; | |
2086 | 618 if (!jid_cmpx(chat, jc->Jid, JID_USER | JID_SERVER)) |
619 break; | |
620 jc = NULL; | |
2956 | 621 jcs = jcs->next; |
2086 | 622 } |
623 | |
624 return jc; | |
625 } | |
626 | |
2956 | 627 |
628 /* | |
629 * Find existing/active Jabber chat | |
630 */ | |
631 static struct jabber_chat *find_existing_chat(struct gaim_connection *gc, jid chat) | |
632 { | |
633 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats; | |
634 struct jabber_chat *jc = NULL; | |
635 | |
636 while (jcs) { | |
637 jc = jcs->data; | |
638 if (jc->state == JCS_ACTIVE && !jid_cmpx(chat, jc->Jid, JID_USER | JID_SERVER)) | |
639 break; | |
640 jc = NULL; | |
641 jcs = jcs->next; | |
642 } | |
643 | |
644 return jc; | |
645 } | |
646 | |
647 /* | |
648 * Find pending chat | |
649 */ | |
2086 | 650 static struct jabber_chat *find_pending_chat(struct gaim_connection *gc, jid chat) |
651 { | |
2956 | 652 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats; |
2086 | 653 struct jabber_chat *jc = NULL; |
654 | |
2956 | 655 while (jcs) { |
656 jc = jcs->data; | |
657 if (jc->state == JCS_PENDING && !jid_cmpx(chat, jc->Jid, JID_USER | JID_SERVER)) | |
2086 | 658 break; |
659 jc = NULL; | |
2956 | 660 jcs = jcs->next; |
2086 | 661 } |
662 | |
663 return jc; | |
664 } | |
665 | |
666 static gboolean find_chat_buddy(struct conversation *b, char *name) | |
667 { | |
668 GList *m = b->in_room; | |
669 | |
670 while (m) { | |
671 if (!strcmp(m->data, name)) | |
672 return TRUE; | |
673 m = m->next; | |
674 } | |
675 | |
676 return FALSE; | |
677 } | |
678 | |
2956 | 679 /* |
680 * keep track of away msg same as yahoo plugin | |
681 */ | |
682 static void jabber_track_away(gjconn gjc, jpacket p, char *name) | |
683 { | |
684 struct jabber_data *jd = GJ_GC(gjc)->proto_data; | |
685 gpointer val = g_hash_table_lookup(jd->hash, name); | |
686 char *show; | |
687 char *vshow = NULL; | |
688 char *status = NULL; | |
689 char *msg = NULL; | |
690 | |
691 if((show = xmlnode_get_tag_data(p->x, "show")) != NULL) { | |
692 if (!strcasecmp(show, "away")) { | |
693 vshow = "Away"; | |
694 } else if (!strcasecmp(show, "chat")) { | |
695 vshow = "Online"; | |
696 } else if (!strcasecmp(show, "xa")) { | |
697 vshow = "Extended Away"; | |
698 } else if (!strcasecmp(show, "dnd")) { | |
699 vshow = "Do Not Disturb"; | |
700 } | |
701 } | |
702 | |
703 status = xmlnode_get_tag_data(p->x, "status"); | |
704 | |
705 if(vshow != NULL || status != NULL ) { | |
706 /* kinda hokey, but it works :-) */ | |
707 msg = g_strdup_printf("%s%s%s", | |
708 (vshow == NULL? "" : vshow), | |
709 (vshow == NULL || status == NULL? "" : ": "), | |
710 (status == NULL? "" : status)); | |
711 } | |
712 | |
713 if (val) { | |
714 g_free(val); | |
715 g_hash_table_insert(jd->hash, name, msg); | |
716 } else { | |
717 g_hash_table_insert(jd->hash, g_strdup(name), msg); | |
718 } | |
719 } | |
720 | |
721 static void jabber_handlemessage(gjconn gjc, jpacket p) | |
2086 | 722 { |
723 xmlnode y, xmlns, subj; | |
724 | |
725 char *from = NULL, *msg = NULL, *type = NULL, *topic = NULL; | |
726 char m[BUF_LONG * 2]; | |
727 | |
728 type = xmlnode_get_attrib(p->x, "type"); | |
729 | |
730 if (!type || !strcasecmp(type, "normal") || !strcasecmp(type, "chat")) { | |
731 | |
732 /* XXX namespaces could be handled better. (mid) */ | |
733 if ((xmlns = xmlnode_get_tag(p->x, "x"))) | |
734 type = xmlnode_get_attrib(xmlns, "xmlns"); | |
735 | |
736 from = jid_full(p->from); | |
737 /* | |
738 if ((y = xmlnode_get_tag(p->x, "html"))) { | |
739 msg = xmlnode_get_data(y); | |
740 } else | |
741 */ | |
742 if ((y = xmlnode_get_tag(p->x, "body"))) { | |
743 msg = xmlnode_get_data(y); | |
744 } | |
745 | |
746 msg = utf8_to_str(msg); | |
747 | |
748 if (!from) | |
749 return; | |
750 | |
751 if (type && !strcasecmp(type, "jabber:x:conference")) { | |
752 char *room; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
753 GList *m = NULL; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
754 char **data; |
2086 | 755 |
756 room = xmlnode_get_attrib(xmlns, "jid"); | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
757 data = g_strsplit(room, "@", 2); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
758 m = g_list_append(m, g_strdup(data[0])); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
759 m = g_list_append(m, g_strdup(data[1])); |
2956 | 760 m = g_list_append(m, g_strdup(gjc->user->user)); |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
761 g_strfreev(data); |
2086 | 762 |
2956 | 763 serv_got_chat_invite(GJ_GC(gjc), room, from, msg, m); |
2086 | 764 } else if (msg) { /* whisper */ |
765 struct jabber_chat *jc; | |
766 g_snprintf(m, sizeof(m), "%s", msg); | |
2956 | 767 if (((jc = find_existing_chat(GJ_GC(gjc), p->from)) != NULL) && jc->b) |
768 serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 1, m, time(NULL)); | |
2086 | 769 else { |
2278
00a8b7bcef6c
[gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2232
diff
changeset
|
770 int flags = 0; |
00a8b7bcef6c
[gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2232
diff
changeset
|
771 if (xmlnode_get_tag(p->x, "gaim")) |
00a8b7bcef6c
[gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2232
diff
changeset
|
772 flags = IM_FLAG_GAIMUSER; |
2086 | 773 if (find_conversation(jid_full(p->from))) |
2956 | 774 serv_got_im(GJ_GC(gjc), jid_full(p->from), m, flags, time(NULL), -1); |
2086 | 775 else { |
2956 | 776 if(p->from->user) { |
777 from = g_strdup_printf("%s@%s", p->from->user, p->from->server); | |
778 } else { | |
779 /* server message? */ | |
780 from = g_strdup(p->from->server); | |
781 } | |
782 serv_got_im(GJ_GC(gjc), from, m, flags, time(NULL), -1); | |
2086 | 783 g_free(from); |
784 } | |
785 } | |
786 } | |
787 | |
788 if (msg) | |
789 g_free(msg); | |
790 | |
791 } else if (!strcasecmp(type, "error")) { | |
792 if ((y = xmlnode_get_tag(p->x, "error"))) { | |
793 type = xmlnode_get_attrib(y, "code"); | |
794 msg = xmlnode_get_data(y); | |
795 } | |
796 | |
797 if (msg) { | |
798 from = g_strdup_printf("Error %s", type ? type : ""); | |
799 do_error_dialog(msg, from); | |
800 g_free(from); | |
801 } | |
802 } else if (!strcasecmp(type, "groupchat")) { | |
803 struct jabber_chat *jc; | |
804 static int i = 0; | |
805 | |
806 /* | |
807 if ((y = xmlnode_get_tag(p->x, "html"))) { | |
808 msg = xmlnode_get_data(y); | |
809 } else | |
810 */ | |
811 if ((y = xmlnode_get_tag(p->x, "body"))) { | |
812 msg = xmlnode_get_data(y); | |
813 } | |
814 | |
815 msg = utf8_to_str(msg); | |
816 | |
817 if ((subj = xmlnode_get_tag(p->x, "subject"))) { | |
818 topic = xmlnode_get_data(subj); | |
819 } | |
820 topic = utf8_to_str(topic); | |
821 | |
2956 | 822 jc = find_existing_chat(GJ_GC(gjc), p->from); |
2086 | 823 if (!jc) { |
824 /* we're not in this chat. are we supposed to be? */ | |
2956 | 825 if ((jc = find_pending_chat(GJ_GC(gjc), p->from)) != NULL) { |
2086 | 826 /* yes, we're supposed to be. so now we are. */ |
2956 | 827 jc->b = serv_got_joined_chat(GJ_GC(gjc), i++, p->from->user); |
2086 | 828 jc->id = jc->b->id; |
2956 | 829 jc->state = JCS_ACTIVE; |
2086 | 830 } else { |
831 /* no, we're not supposed to be. */ | |
832 g_free(msg); | |
833 return; | |
834 } | |
835 } | |
836 if (p->from->resource) { | |
837 if (!y) { | |
2956 | 838 if (!find_chat_buddy(jc->b, p->from->resource)) { |
2086 | 839 add_chat_buddy(jc->b, p->from->resource); |
2956 | 840 } else if ((y = xmlnode_get_tag(p->x, "status"))) { |
2086 | 841 char buf[8192]; |
2956 | 842 |
843 g_snprintf(buf, sizeof(buf), "%s@%s/%s", | |
844 p->from->user, p->from->server, p->from->resource); | |
845 jabber_track_away(gjc, p, buf); | |
846 | |
2086 | 847 } |
848 } else if (jc->b && msg) { | |
849 char buf[8192]; | |
850 | |
851 if (topic) { | |
852 char tbuf[8192]; | |
853 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); | |
854 chat_set_topic(jc->b, p->from->resource, tbuf); | |
855 } | |
856 | |
857 | |
858 g_snprintf(buf, sizeof(buf), "%s", msg); | |
2956 | 859 serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 0, buf, time(NULL)); |
2086 | 860 } |
861 } else { /* message from the server */ | |
862 if(jc->b && topic) { | |
863 char tbuf[8192]; | |
864 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); | |
865 chat_set_topic(jc->b, "", tbuf); | |
866 } | |
867 } | |
868 | |
869 g_free(msg); | |
870 g_free(topic); | |
871 | |
872 } else { | |
873 debug_printf("unhandled message %s\n", type); | |
874 } | |
875 } | |
876 | |
2956 | 877 static void jabber_handlepresence(gjconn gjc, jpacket p) |
2086 | 878 { |
879 char *to, *from, *type; | |
880 struct buddy *b = NULL; | |
881 jid who; | |
882 char *buddy; | |
883 xmlnode y; | |
884 char *show; | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
885 int state = 0; |
2086 | 886 GSList *resources; |
887 char *res; | |
888 struct conversation *cnv = NULL; | |
889 struct jabber_chat *jc = NULL; | |
890 | |
891 to = xmlnode_get_attrib(p->x, "to"); | |
892 from = xmlnode_get_attrib(p->x, "from"); | |
893 type = xmlnode_get_attrib(p->x, "type"); | |
894 | |
895 if ((y = xmlnode_get_tag(p->x, "show"))) { | |
896 show = xmlnode_get_data(y); | |
897 if (!show) { | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
898 state = 0; |
2086 | 899 } else if (!strcasecmp(show, "away")) { |
900 state = UC_AWAY; | |
901 } else if (!strcasecmp(show, "chat")) { | |
902 state = UC_CHAT; | |
903 } else if (!strcasecmp(show, "xa")) { | |
904 state = UC_XA; | |
905 } else if (!strcasecmp(show, "dnd")) { | |
906 state = UC_DND; | |
907 } | |
908 } else { | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
909 state = 0; |
2086 | 910 } |
911 | |
2956 | 912 who = jid_new(gjc->p, from); |
2086 | 913 if (who->user == NULL) { |
914 /* FIXME: transport */ | |
915 return; | |
916 } | |
917 | |
918 buddy = g_strdup_printf("%s@%s", who->user, who->server); | |
919 | |
920 /* um. we're going to check if it's a chat. if it isn't, and there are pending | |
2956 | 921 * chats, create the chat. if there aren't pending chats and we don't have the |
922 * buddy on our list, simply bail out. */ | |
923 if ((cnv = find_chat(GJ_GC(gjc), who->user)) == NULL) { | |
2086 | 924 static int i = 0x70; |
2956 | 925 if ((jc = find_pending_chat(GJ_GC(gjc), who)) != NULL) { |
926 jc->b = cnv = serv_got_joined_chat(GJ_GC(gjc), i++, who->user); | |
2086 | 927 jc->id = jc->b->id; |
2956 | 928 jc->state = JCS_ACTIVE; |
929 } else if ((b = find_buddy(GJ_GC(gjc), buddy)) == NULL) { | |
930 g_free(buddy); | |
931 return; | |
2086 | 932 } |
933 } | |
934 | |
935 if (!cnv) { | |
936 resources = b->proto_data; | |
937 res = who->resource; | |
938 if (res) | |
939 while (resources) { | |
940 if (!strcmp(res, resources->data)) | |
941 break; | |
942 resources = resources->next; | |
943 } | |
944 | |
945 if (type && (strcasecmp(type, "unavailable") == 0)) { | |
946 if (resources) { | |
947 g_free(resources->data); | |
948 b->proto_data = g_slist_remove(b->proto_data, resources->data); | |
949 } | |
950 if (!b->proto_data) { | |
2956 | 951 serv_got_update(GJ_GC(gjc), buddy, 0, 0, 0, 0, 0, 0); |
2086 | 952 } |
953 } else { | |
954 /* keep track of away msg same as yahoo plugin */ | |
2956 | 955 jabber_track_away(gjc, p, normalize(b->name)); |
2086 | 956 |
957 if (!resources) { | |
958 b->proto_data = g_slist_append(b->proto_data, g_strdup(res)); | |
959 } | |
960 | |
2956 | 961 serv_got_update(GJ_GC(gjc), buddy, 1, 0, 0, 0, state, 0); |
2086 | 962 |
963 } | |
964 } else { | |
965 if (who->resource) { | |
966 if (type && !strcasecmp(type, "unavailable")) { | |
967 struct jabber_data *jd; | |
2956 | 968 if (!jc && !(jc = find_existing_chat(GJ_GC(gjc), who))) { |
2086 | 969 g_free(buddy); |
970 return; | |
971 } | |
972 jd = jc->gc->proto_data; | |
2956 | 973 /* if it's not ourselves...*/ |
2086 | 974 if (strcmp(who->resource, jc->Jid->resource) && jc->b) { |
2820
b917845dad3c
[gaim-migrate @ 2833]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2814
diff
changeset
|
975 remove_chat_buddy(jc->b, who->resource, NULL); |
2086 | 976 g_free(buddy); |
977 return; | |
978 } | |
2956 | 979 |
980 jc->state = JCS_CLOSED; | |
981 serv_got_chat_left(GJ_GC(gjc), jc->id); | |
982 /* | |
983 * TBD: put back some day? | |
984 jd->chats = g_slist_remove(jd->chats, jc); | |
985 g_free(jc); | |
986 */ | |
987 } else { | |
988 if ((!jc && !(jc = find_existing_chat(GJ_GC(gjc), who))) || !jc->b) { | |
989 g_free(buddy); | |
990 return; | |
991 } | |
992 if (!find_chat_buddy(jc->b, who->resource)) { | |
2086 | 993 add_chat_buddy(jc->b, who->resource); |
2956 | 994 } else { |
2086 | 995 char buf[8192]; |
2956 | 996 g_snprintf(buf, sizeof(buf), "%s@%s/%s", |
997 who->user, who->server, who->resource); | |
998 jabber_track_away(gjc, p, buf); | |
2086 | 999 } |
1000 } | |
1001 } | |
1002 } | |
1003 | |
1004 g_free(buddy); | |
1005 | |
1006 return; | |
1007 } | |
1008 | |
2956 | 1009 static void jabber_handles10n(gjconn gjc, jpacket p) |
2086 | 1010 { |
1011 xmlnode g; | |
1012 char *Jid = xmlnode_get_attrib(p->x, "from"); | |
1013 char *ask = xmlnode_get_attrib(p->x, "type"); | |
1014 | |
1015 g = xmlnode_new_tag("presence"); | |
1016 xmlnode_put_attrib(g, "to", Jid); | |
1017 if (!strcmp(ask, "subscribe")) | |
1018 xmlnode_put_attrib(g, "type", "subscribed"); | |
1019 else if (!strcmp(ask, "unsubscribe")) | |
1020 xmlnode_put_attrib(g, "type", "unsubscribed"); | |
2956 | 1021 else { |
1022 xmlnode_free(g); | |
2086 | 1023 return; |
2956 | 1024 } |
1025 | |
1026 gjab_send(gjc, g); | |
1027 xmlnode_free(g); | |
2086 | 1028 } |
1029 | |
2956 | 1030 /* |
1031 * Pending subscription to a buddy? | |
1032 */ | |
1033 #define BUD_SUB_TO_PEND(sub, ask) ((!strcasecmp((sub), "none") || !strcasecmp((sub), "from")) && \ | |
1034 (ask) != NULL && !strcasecmp((ask), "subscribe")) | |
1035 | |
1036 /* | |
1037 * Subscribed to a buddy? | |
1038 */ | |
1039 #define BUD_SUBD_TO(sub, ask) ((!strcasecmp((sub), "to") || !strcasecmp((sub), "both")) && \ | |
1040 ((ask) == NULL || !strcasecmp((ask), "subscribe"))) | |
1041 | |
1042 /* | |
1043 * Pending unsubscription to a buddy? | |
1044 */ | |
1045 #define BUD_USUB_TO_PEND(sub, ask) ((!strcasecmp((sub), "to") || !strcasecmp((sub), "both")) && \ | |
1046 (ask) != NULL && !strcasecmp((ask), "unsubscribe")) | |
1047 | |
1048 /* | |
1049 * Unsubscribed to a buddy? | |
1050 */ | |
1051 #define BUD_USUBD_TO(sub, ask) ((!strcasecmp((sub), "none") || !strcasecmp((sub), "from")) && \ | |
1052 ((ask) == NULL || !strcasecmp((ask), "unsubscribe"))) | |
1053 | |
1054 /* | |
1055 * If a buddy is added or removed from the roster on another resource | |
1056 * jabber_handlebuddy is called | |
1057 * | |
1058 * Called with roster item node. | |
1059 */ | |
1060 static void jabber_handlebuddy(gjconn gjc, xmlnode x) | |
1061 { | |
1062 xmlnode g; | |
1063 char *Jid, *name, *sub, *ask; | |
1064 jid who; | |
1065 struct buddy *b = NULL; | |
1066 char *buddyname, *groupname; | |
1067 | |
1068 Jid = xmlnode_get_attrib(x, "jid"); | |
1069 name = xmlnode_get_attrib(x, "name"); | |
1070 sub = xmlnode_get_attrib(x, "subscription"); | |
1071 ask = xmlnode_get_attrib(x, "ask"); | |
1072 who = jid_new(gjc->p, Jid); | |
1073 | |
1074 /* JFIXME: jabber_handleroster() had a "FIXME: transport" at this | |
1075 * equivilent point. So... | |
1076 * | |
1077 * We haven't allocated any memory or done anything interesting to | |
1078 * this point, so we'll violate Good Coding Structure here by | |
1079 * simply bailing out. | |
1080 */ | |
1081 if (!who || !who->user) { | |
1082 return; | |
1083 } | |
1084 | |
1085 buddyname = g_strdup_printf("%s@%s", who->user, who->server); | |
1086 | |
1087 if((g = xmlnode_get_tag(x, "group")) == NULL || (groupname = xmlnode_get_data(g)) == NULL) { | |
1088 groupname = "Buddies"; | |
1089 } | |
1090 | |
1091 | |
1092 if (BUD_SUB_TO_PEND(sub, ask) || BUD_SUBD_TO(sub, ask)) { | |
1093 if ((b = find_buddy(GJ_GC(gjc), buddyname)) == NULL) { | |
1094 debug_printf("adding buddy [4]: %s\n", buddyname); | |
1095 b = add_buddy(GJ_GC(gjc), groupname, buddyname, | |
1096 name ? name : buddyname); | |
1097 do_export(GJ_GC(gjc)); | |
1098 } | |
1099 /* | |
1100 * TBD: this is what we *would* do if we could. But the | |
1101 * remove_buddy() code doesn't update the UI. And if the | |
1102 * user selects and tries to remove a buddy already removed | |
1103 * via here: *ka-boom*! | |
1104 * | |
1105 } else if (BUD_USUB_TO_PEND(sub, ask) || BUD_USUBD_TO(sub, ask) || !strcasecmp(sub, "remove")) { | |
1106 if ((b = find_buddy(GJ_GC(gjc), buddyname)) != NULL) { | |
1107 struct group *group; | |
1108 | |
1109 group = find_group_by_buddy(GJ_GC(gjc), buddyname); | |
1110 debug_printf("removing buddy [1]: %s, from group: %s\n", | |
1111 buddyname, group->name); | |
1112 remove_buddy(GJ_GC(gjc), group, b); | |
1113 do_export(GJ_GC(gjc)); | |
1114 } | |
1115 */ | |
1116 } | |
1117 g_free(buddyname); | |
1118 | |
1119 } | |
1120 | |
1121 static void jabber_handleroster(gjconn gjc, xmlnode querynode) | |
2086 | 1122 { |
1123 xmlnode x; | |
1124 | |
1125 x = xmlnode_get_firstchild(querynode); | |
1126 while (x) { | |
2956 | 1127 jabber_handlebuddy(gjc, x); |
2086 | 1128 x = xmlnode_get_nextsibling(x); |
1129 } | |
1130 | |
1131 x = jutil_presnew(0, NULL, "Online"); | |
2956 | 1132 gjab_send(gjc, x); |
2086 | 1133 xmlnode_free(x); |
1134 } | |
1135 | |
2956 | 1136 static void jabber_handleauthresp(gjconn gjc, jpacket p) |
2086 | 1137 { |
1138 if (jpacket_subtype(p) == JPACKET__RESULT) { | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1139 if (xmlnode_has_children(p->x)) { |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1140 xmlnode query = xmlnode_get_tag(p->x, "query"); |
2956 | 1141 set_login_progress(GJ_GC(gjc), 4, "Authenticating"); |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1142 if (!xmlnode_get_tag(query, "digest")) { |
2956 | 1143 g_free(gjc->sid); |
1144 gjc->sid = NULL; | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1145 } |
2956 | 1146 gjab_auth(gjc); |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1147 } else { |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1148 debug_printf("auth success\n"); |
2086 | 1149 |
2956 | 1150 account_online(GJ_GC(gjc)); |
1151 serv_finish_login(GJ_GC(gjc)); | |
1152 | |
1153 if (bud_list_cache_exists(GJ_GC(gjc))) | |
1154 do_import(GJ_GC(gjc), NULL); | |
1155 | |
1156 ((struct jabber_data *)GJ_GC(gjc)->proto_data)->did_import = TRUE; | |
1157 | |
1158 gjab_reqroster(gjc); | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1159 } |
2086 | 1160 } else { |
1161 xmlnode xerr; | |
1162 char *errmsg = NULL; | |
1163 int errcode = 0; | |
2956 | 1164 struct jabber_data *jd = GJ_GC(gjc)->proto_data; |
2086 | 1165 |
1166 debug_printf("auth failed\n"); | |
1167 xerr = xmlnode_get_tag(p->x, "error"); | |
1168 if (xerr) { | |
1169 char msg[BUF_LONG]; | |
1170 errmsg = xmlnode_get_data(xerr); | |
1171 if (xmlnode_get_attrib(xerr, "code")) { | |
1172 errcode = atoi(xmlnode_get_attrib(xerr, "code")); | |
1173 g_snprintf(msg, sizeof(msg), "Error %d: %s", errcode, errmsg); | |
1174 } else | |
1175 g_snprintf(msg, sizeof(msg), "%s", errmsg); | |
2956 | 1176 hide_login_progress(GJ_GC(gjc), msg); |
2086 | 1177 } else { |
2956 | 1178 hide_login_progress(GJ_GC(gjc), "Unknown login error"); |
2086 | 1179 } |
1180 | |
2800
0ad63a625eec
[gaim-migrate @ 2813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1181 jd->die = TRUE; |
2086 | 1182 } |
1183 } | |
1184 | |
2956 | 1185 static void jabber_handleversion(gjconn gjc, xmlnode iqnode) { |
2086 | 1186 xmlnode querynode, x; |
1187 char *id, *from; | |
1188 char os[1024]; | |
1189 struct utsname osinfo; | |
1190 | |
1191 uname(&osinfo); | |
1192 g_snprintf(os, sizeof os, "%s %s %s", osinfo.sysname, osinfo.release, osinfo.machine); | |
1193 | |
1194 id = xmlnode_get_attrib(iqnode, "id"); | |
1195 from = xmlnode_get_attrib(iqnode, "from"); | |
1196 | |
1197 x = jutil_iqnew(JPACKET__RESULT, NS_VERSION); | |
1198 | |
1199 xmlnode_put_attrib(x, "to", from); | |
1200 xmlnode_put_attrib(x, "id", id); | |
1201 querynode = xmlnode_get_tag(x, "query"); | |
1202 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "name"), PACKAGE, -1); | |
1203 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "version"), VERSION, -1); | |
1204 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "os"), os, -1); | |
1205 | |
2956 | 1206 gjab_send(gjc, x); |
2086 | 1207 |
1208 xmlnode_free(x); | |
1209 } | |
1210 | |
2956 | 1211 static void jabber_handletime(gjconn gjc, xmlnode iqnode) { |
2086 | 1212 xmlnode querynode, x; |
1213 char *id, *from; | |
1214 time_t now_t; | |
1215 struct tm *now; | |
1216 char buf[1024]; | |
1217 | |
1218 time(&now_t); | |
1219 now = localtime(&now_t); | |
1220 | |
1221 id = xmlnode_get_attrib(iqnode, "id"); | |
1222 from = xmlnode_get_attrib(iqnode, "from"); | |
1223 | |
1224 x = jutil_iqnew(JPACKET__RESULT, NS_TIME); | |
1225 | |
1226 xmlnode_put_attrib(x, "to", from); | |
1227 xmlnode_put_attrib(x, "id", id); | |
1228 querynode = xmlnode_get_tag(x, "query"); | |
1229 | |
1230 strftime(buf, 1024, "%Y%m%dT%T", now); | |
1231 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "utc"), buf, -1); | |
1232 strftime(buf, 1024, "%Z", now); | |
1233 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "tz"), buf, -1); | |
1234 strftime(buf, 1024, "%d %b %Y %T", now); | |
1235 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "display"), buf, -1); | |
1236 | |
2956 | 1237 gjab_send(gjc, x); |
2086 | 1238 |
1239 xmlnode_free(x); | |
1240 } | |
1241 | |
2956 | 1242 static void jabber_handlelast(gjconn gjc, xmlnode iqnode) { |
2086 | 1243 xmlnode x, querytag; |
1244 char *id, *from; | |
2956 | 1245 struct jabber_data *jd = GJ_GC(gjc)->proto_data; |
2086 | 1246 char idle_time[32]; |
1247 | |
1248 id = xmlnode_get_attrib(iqnode, "id"); | |
1249 from = xmlnode_get_attrib(iqnode, "from"); | |
1250 | |
1251 x = jutil_iqnew(JPACKET__RESULT, "jabber:iq:last"); | |
1252 | |
1253 xmlnode_put_attrib(x, "to", from); | |
1254 xmlnode_put_attrib(x, "id", id); | |
1255 querytag = xmlnode_get_tag(x, "query"); | |
1256 g_snprintf(idle_time, sizeof idle_time, "%ld", jd->idle ? time(NULL) - jd->idle : 0); | |
1257 xmlnode_put_attrib(querytag, "seconds", idle_time); | |
1258 | |
2956 | 1259 gjab_send(gjc, x); |
2086 | 1260 xmlnode_free(x); |
1261 } | |
1262 | |
2956 | 1263 /* |
1264 * delete == TRUE: delete found entry | |
1265 * | |
1266 * returns pointer to (local) copy of value if found, NULL otherwise | |
1267 * | |
1268 * Note: non-reentrant! Local static storage re-used on subsequent calls. | |
1269 * If you're going to need to keep the returned value, make a copy! | |
1270 */ | |
1271 static gchar *jabber_track_queries(GHashTable *queries, gchar *key, gboolean delete) | |
1272 { | |
1273 gpointer my_key, my_val; | |
1274 static gchar *ret_val = NULL; | |
1275 | |
1276 if(ret_val != NULL) { | |
1277 g_free(ret_val); | |
1278 ret_val = NULL; | |
1279 } | |
1280 | |
1281 /* self-protection */ | |
1282 if(queries != NULL && key != NULL) { | |
1283 if(g_hash_table_lookup_extended(queries, key, &my_key, &my_val)) { | |
1284 ret_val = g_strdup((gchar *) my_val); | |
1285 if(delete) { | |
1286 g_hash_table_remove(queries, key); | |
1287 g_free(my_key); | |
1288 g_free(my_val); | |
1289 } | |
1290 } | |
1291 } | |
1292 | |
1293 return(ret_val); | |
1294 } | |
1295 | |
1296 static void jabber_handlepacket(gjconn gjc, jpacket p) | |
2086 | 1297 { |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1298 char *id; |
2086 | 1299 switch (p->type) { |
1300 case JPACKET_MESSAGE: | |
2956 | 1301 jabber_handlemessage(gjc, p); |
2086 | 1302 break; |
1303 case JPACKET_PRESENCE: | |
2956 | 1304 jabber_handlepresence(gjc, p); |
2086 | 1305 break; |
1306 case JPACKET_IQ: | |
1307 debug_printf("jpacket_subtype: %d\n", jpacket_subtype(p)); | |
1308 | |
2956 | 1309 id = xmlnode_get_attrib(p->x, "id"); |
1310 if (id != NULL && !strcmp(id, IQID_AUTH)) { | |
1311 jabber_handleauthresp(gjc, p); | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1312 break; |
2086 | 1313 } |
1314 | |
1315 if (jpacket_subtype(p) == JPACKET__SET) { | |
2956 | 1316 xmlnode querynode; |
1317 querynode = xmlnode_get_tag(p->x, "query"); | |
1318 if (NSCHECK(querynode, "jabber:iq:roster")) { | |
1319 jabber_handlebuddy(gjc, xmlnode_get_firstchild(querynode)); | |
1320 } | |
2086 | 1321 } else if (jpacket_subtype(p) == JPACKET__GET) { |
1322 xmlnode querynode; | |
1323 querynode = xmlnode_get_tag(p->x, "query"); | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1324 if (NSCHECK(querynode, NS_VERSION)) { |
2956 | 1325 jabber_handleversion(gjc, p->x); |
2086 | 1326 } else if (NSCHECK(querynode, NS_TIME)) { |
2956 | 1327 jabber_handletime(gjc, p->x); |
2086 | 1328 } else if (NSCHECK(querynode, "jabber:iq:last")) { |
2956 | 1329 jabber_handlelast(gjc, p->x); |
2086 | 1330 } |
1331 } else if (jpacket_subtype(p) == JPACKET__RESULT) { | |
1332 xmlnode querynode, vcard; | |
1333 char *xmlns, *from; | |
1334 | |
2956 | 1335 /* |
1336 * TBD: ISTM maybe this part could use a serious re-work? | |
1337 */ | |
2086 | 1338 from = xmlnode_get_attrib(p->x, "from"); |
1339 querynode = xmlnode_get_tag(p->x, "query"); | |
1340 vcard = xmlnode_get_tag(p->x, "vCard"); | |
2316
ebb5ecb2cd5b
[gaim-migrate @ 2326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1341 if (!vcard) |
ebb5ecb2cd5b
[gaim-migrate @ 2326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1342 vcard = xmlnode_get_tag(p->x, "VCARD"); |
2086 | 1343 |
1344 if (NSCHECK(querynode, NS_ROSTER)) { | |
2956 | 1345 jabber_handleroster(gjc, querynode); |
2086 | 1346 } else if (NSCHECK(querynode, NS_VCARD)) { |
2956 | 1347 jabber_track_queries(gjc->queries, id, TRUE); /* delete query track */ |
1348 jabber_handlevcard(gjc, querynode, from); | |
2316
ebb5ecb2cd5b
[gaim-migrate @ 2326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1349 } else if (vcard) { |
2956 | 1350 jabber_track_queries(gjc->queries, id, TRUE); /* delete query track */ |
1351 jabber_handlevcard(gjc, vcard, from); | |
1352 } else if((xmlns = xmlnode_get_attrib(querynode, "xmlns")) != NULL) { | |
1353 debug_printf("jabber:iq:query: %s\n", xmlns); | |
2086 | 1354 } else { |
2956 | 1355 char *val; |
1356 | |
1357 debug_printf("jabber:iq: %s\n", xmlnode2str(p->x)); | |
1358 | |
1359 /* handle "null" query results */ | |
1360 if((val = jabber_track_queries(gjc->queries, id, TRUE)) != NULL) { | |
1361 if(strcmp((char *) val, "vCard") == 0) { | |
1362 /* | |
1363 * No actual vCard, but there's other stuff. This | |
1364 * way the user always gets some kind of response. | |
1365 */ | |
1366 jabber_handlevcard(gjc, NULL, from); | |
1367 } | |
1368 } | |
2086 | 1369 } |
1370 | |
1371 } else if (jpacket_subtype(p) == JPACKET__ERROR) { | |
1372 xmlnode xerr; | |
1373 char *from, *errmsg = NULL; | |
1374 int errcode = 0; | |
1375 | |
1376 from = xmlnode_get_attrib(p->x, "from"); | |
1377 xerr = xmlnode_get_tag(p->x, "error"); | |
1378 if (xerr) { | |
1379 errmsg = xmlnode_get_data(xerr); | |
1380 if (xmlnode_get_attrib(xerr, "code")) | |
1381 errcode = atoi(xmlnode_get_attrib(xerr, "code")); | |
1382 } | |
1383 | |
1384 from = g_strdup_printf("Error %d (%s)", errcode, from); | |
1385 do_error_dialog(errmsg, from); | |
1386 g_free(from); | |
1387 | |
1388 } | |
1389 | |
1390 break; | |
1391 | |
1392 case JPACKET_S10N: | |
2956 | 1393 jabber_handles10n(gjc, p); |
2086 | 1394 break; |
1395 default: | |
1396 debug_printf("jabber: packet type %d (%s)\n", p->type, xmlnode2str(p->x)); | |
1397 } | |
1398 | |
1399 xmlnode_free(p->x); | |
1400 | |
1401 return; | |
1402 } | |
1403 | |
2956 | 1404 static void jabber_handlestate(gjconn gjc, int state) |
2086 | 1405 { |
1406 switch (state) { | |
1407 case JCONN_STATE_OFF: | |
2956 | 1408 hide_login_progress(GJ_GC(gjc), "Unable to connect"); |
1409 signoff(GJ_GC(gjc)); | |
2086 | 1410 break; |
1411 case JCONN_STATE_CONNECTED: | |
2956 | 1412 set_login_progress(GJ_GC(gjc), 2, "Connected"); |
2086 | 1413 break; |
1414 case JCONN_STATE_ON: | |
2956 | 1415 set_login_progress(GJ_GC(gjc), 3, "Requesting Authentication Method"); |
1416 gjab_reqauth(gjc); | |
2086 | 1417 break; |
1418 default: | |
1419 debug_printf("state change: %d\n", state); | |
1420 } | |
1421 return; | |
1422 } | |
1423 | |
1424 static void jabber_login(struct aim_user *user) | |
1425 { | |
1426 struct gaim_connection *gc = new_gaim_conn(user); | |
1427 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); | |
1428 char *loginname = create_valid_jid(user->username, DEFAULT_SERVER, "GAIM"); | |
1429 | |
1430 jd->hash = g_hash_table_new(g_str_hash, g_str_equal); | |
2956 | 1431 jd->chats = NULL; /* we have no chats yet */ |
2086 | 1432 |
1433 set_login_progress(gc, 1, "Connecting"); | |
1434 | |
2956 | 1435 if (!(jd->gjc = gjab_new(loginname, user->password, gc))) { |
2086 | 1436 g_free(loginname); |
1437 debug_printf("jabber: unable to connect (jab_new failed)\n"); | |
1438 hide_login_progress(gc, "Unable to connect"); | |
1439 signoff(gc); | |
1440 return; | |
1441 } | |
1442 | |
1443 g_free(loginname); | |
2956 | 1444 gjab_state_handler(jd->gjc, jabber_handlestate); |
1445 gjab_packet_handler(jd->gjc, jabber_handlepacket); | |
1446 jd->gjc->queries = g_hash_table_new(g_str_hash, g_str_equal); | |
1447 gjab_start(jd->gjc); | |
2086 | 1448 } |
1449 | |
1450 static gboolean jabber_destroy_hash(gpointer key, gpointer val, gpointer data) { | |
1451 g_free(key); | |
1452 g_free(val); | |
1453 return TRUE; | |
1454 } | |
1455 | |
1456 static gboolean jabber_free(gpointer data) | |
1457 { | |
2956 | 1458 struct jabber_data *jd = data; |
1459 | |
1460 gjab_delete(jd->gjc); | |
1461 g_free(jd->gjc->sid); | |
1462 jd->gjc = NULL; | |
1463 g_free(jd); | |
1464 | |
2086 | 1465 return FALSE; |
1466 } | |
1467 | |
1468 static void jabber_close(struct gaim_connection *gc) | |
1469 { | |
1470 struct jabber_data *jd = gc->proto_data; | |
2956 | 1471 |
1472 if(jd) { | |
1473 GSList *jcs = jd->chats; | |
1474 | |
1475 /* Free-up the jabber_chat struct allocs and the list */ | |
1476 while (jcs) { | |
1477 g_free(jcs->data); | |
1478 jcs = jcs->next; | |
1479 } | |
1480 g_slist_free(jd->chats); | |
1481 | |
1482 /* Free-up the away status memories and the list */ | |
1483 if(jd->hash != NULL) { | |
1484 g_hash_table_foreach_remove(jd->hash, jabber_destroy_hash, NULL); | |
1485 g_hash_table_destroy(jd->hash); | |
1486 jd->hash = NULL; | |
1487 } | |
1488 | |
1489 /* Free-up the pending queries memories and the list */ | |
1490 if(jd->gjc->queries != NULL) { | |
1491 g_hash_table_foreach_remove(jd->gjc->queries, jabber_destroy_hash, NULL); | |
1492 g_hash_table_destroy(jd->gjc->queries); | |
1493 jd->gjc->queries = NULL; | |
1494 } | |
1495 } | |
2300
d2686f757d6e
[gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
1496 if (gc->inpa) |
d2686f757d6e
[gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
1497 gaim_input_remove(gc->inpa); |
2956 | 1498 |
1499 if(jd) { | |
1500 g_timeout_add(50, jabber_free, jd); | |
1501 xmlnode_free(jd->gjc->current); | |
1502 } | |
2086 | 1503 gc->proto_data = NULL; |
1504 } | |
1505 | |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
1506 static int jabber_send_im(struct gaim_connection *gc, char *who, char *message, int flags) |
2086 | 1507 { |
1508 xmlnode x, y; | |
1509 char *realwho; | |
2956 | 1510 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
2086 | 1511 |
1512 if (!who || !message) | |
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2112
diff
changeset
|
1513 return 0; |
2086 | 1514 |
1515 x = xmlnode_new_tag("message"); | |
2956 | 1516 /* Bare username and "username" not the server itself? */ |
1517 if (!strchr(who, '@') && strcmp(who, gjc->user->server) != 0) | |
1518 realwho = g_strdup_printf("%s@%s", who, gjc->user->server); | |
2086 | 1519 else |
1520 realwho = g_strdup(who); | |
1521 xmlnode_put_attrib(x, "to", realwho); | |
1522 g_free(realwho); | |
1523 | |
2278
00a8b7bcef6c
[gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2232
diff
changeset
|
1524 xmlnode_insert_tag(x, "gaim"); |
2086 | 1525 xmlnode_put_attrib(x, "type", "chat"); |
1526 | |
1527 if (message && strlen(message)) { | |
1528 char *utf8 = str_to_utf8(message); | |
1529 y = xmlnode_insert_tag(x, "body"); | |
1530 xmlnode_insert_cdata(y, utf8, -1); | |
1531 g_free(utf8); | |
1532 } | |
1533 | |
2956 | 1534 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2086 | 1535 xmlnode_free(x); |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2300
diff
changeset
|
1536 return 1; |
2086 | 1537 } |
1538 | |
1539 static void jabber_add_buddy(struct gaim_connection *gc, char *name) | |
1540 { | |
1541 xmlnode x, y; | |
1542 char *realwho; | |
2956 | 1543 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
1544 struct buddy *buddy = NULL; | |
1545 struct group *buddy_group = NULL; | |
2086 | 1546 |
1547 if (!((struct jabber_data *)gc->proto_data)->did_import) | |
1548 return; | |
1549 | |
1550 if (!name) | |
1551 return; | |
1552 | |
1553 if (!strcmp(gc->username, name)) | |
1554 return; | |
1555 | |
1556 if (!strchr(name, '@')) | |
2956 | 1557 realwho = g_strdup_printf("%s@%s", name, gjc->user->server); |
2086 | 1558 else { |
2956 | 1559 jid who = jid_new(gjc->p, name); |
2086 | 1560 if (who->user == NULL) { |
1561 /* FIXME: transport */ | |
1562 return; | |
1563 } | |
1564 realwho = g_strdup_printf("%s@%s", who->user, who->server); | |
1565 } | |
1566 | |
2956 | 1567 |
2086 | 1568 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); |
1569 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); | |
1570 xmlnode_put_attrib(y, "jid", realwho); | |
2956 | 1571 |
1572 /* If we can find the buddy, there's an alias for him and | |
1573 * it's not 0-length, add the "name" attribute. | |
1574 */ | |
1575 if((buddy = find_buddy(gc, realwho)) != NULL && | |
1576 buddy->show != NULL && (buddy->show)[0] != '\0') { | |
1577 | |
1578 xmlnode_put_attrib(y, "name", buddy->show); | |
1579 } | |
1580 | |
1581 /* | |
1582 * Find out what group the buddy's in and send that along | |
1583 * with the roster item. | |
1584 */ | |
1585 if((buddy_group = find_group_by_buddy(gc, realwho)) != NULL) { | |
1586 xmlnode z; | |
1587 z = xmlnode_insert_tag(y, "group"); | |
1588 xmlnode_insert_cdata(z, buddy_group->name, -1); | |
1589 } | |
1590 | |
1591 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); | |
2086 | 1592 xmlnode_free(x); |
1593 | |
1594 x = xmlnode_new_tag("presence"); | |
1595 xmlnode_put_attrib(x, "to", realwho); | |
1596 xmlnode_put_attrib(x, "type", "subscribe"); | |
2956 | 1597 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
1598 xmlnode_free(x); | |
2086 | 1599 |
1600 g_free(realwho); | |
1601 } | |
1602 | |
2681
37d80035e77f
[gaim-migrate @ 2694]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2635
diff
changeset
|
1603 static void jabber_remove_buddy(struct gaim_connection *gc, char *name, char *group) |
2086 | 1604 { |
1605 xmlnode x, y; | |
1606 char *realwho; | |
2956 | 1607 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
2086 | 1608 |
1609 if (!name) | |
1610 return; | |
1611 | |
1612 if (!strchr(name, '@')) | |
2956 | 1613 realwho = g_strdup_printf("%s@%s", name, gjc->user->server); |
2086 | 1614 else |
1615 realwho = g_strdup(name); | |
1616 | |
2956 | 1617 x = xmlnode_new_tag("presence"); |
1618 xmlnode_put_attrib(x, "to", realwho); | |
1619 xmlnode_put_attrib(x, "type", "unsubscribe"); | |
1620 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); | |
2086 | 1621 g_free(realwho); |
1622 xmlnode_free(x); | |
1623 } | |
1624 | |
1625 static char **jabber_list_icon(int uc) | |
1626 { | |
1627 switch (uc) { | |
1628 case UC_AWAY: | |
1629 return available_away_xpm; | |
1630 case UC_CHAT: | |
1631 return available_chat_xpm; | |
1632 case UC_XA: | |
1633 return available_xa_xpm; | |
1634 case UC_DND: | |
1635 return available_dnd_xpm; | |
1636 default: | |
1637 return available_xpm; | |
1638 } | |
1639 } | |
1640 | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1641 static GList *jabber_chat_info(struct gaim_connection *gc) |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1642 { |
2956 | 1643 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
1644 | |
1645 static char *confserv = NULL; /* this pointer must be persistent */ | |
1646 gchar *server; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1647 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1648 GList *m = NULL; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1649 struct proto_chat_entry *pce; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1650 |
2956 | 1651 /* This is a scientific wild-ass guess... |
1652 * | |
1653 * If there are more than two "components" to the current server name, | |
1654 * lop-off the left-most component and replace with "conference." | |
1655 */ | |
1656 if(confserv != NULL) { | |
1657 g_free(confserv); /* dispose of the old value */ | |
1658 } | |
1659 | |
1660 if((server = g_strdup(gjc->user->server)) == NULL) { | |
1661 confserv = g_strdup(DEFAULT_GROUPCHAT); | |
1662 } else { | |
1663 gchar **splits, **index; | |
1664 gchar *tmp; | |
1665 int cnt = 0; | |
1666 | |
1667 | |
1668 index = splits = g_strsplit(server, ".", -1); /* split the connected server */ | |
1669 | |
1670 while(*(index++)) /* index to the end--counting the parts */ | |
1671 ++cnt; | |
1672 | |
1673 /* | |
1674 * If we've more than two parts, point to the second part. Else point | |
1675 * to the start. | |
1676 */ | |
1677 if(cnt > 2) { | |
1678 index -= cnt; | |
1679 } else { | |
1680 index = splits; | |
1681 } | |
1682 | |
1683 /* Put it together */ | |
1684 confserv = g_strjoin(".", "conference", (tmp = g_strjoinv(".", index)), NULL); | |
1685 | |
1686 g_free(server); /* we don't need this stuff no more */ | |
1687 g_free(tmp); | |
1688 g_strfreev(splits); | |
1689 } | |
1690 | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1691 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1692 pce->label = _("Room:"); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1693 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1694 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1695 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1696 pce->label = _("Server:"); |
2956 | 1697 pce->def = confserv; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1698 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1699 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1700 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1701 pce->label = _("Handle:"); |
2956 | 1702 pce->def = gjc->user->user; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1703 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1704 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1705 return m; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1706 } |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1707 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1708 static void jabber_join_chat(struct gaim_connection *gc, GList *data) |
2086 | 1709 { |
1710 xmlnode x; | |
1711 char *realwho; | |
2956 | 1712 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
1713 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats; | |
2086 | 1714 struct jabber_chat *jc; |
2956 | 1715 jid Jid; |
2086 | 1716 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1717 if (!data || !data->next || !data->next->next) |
2086 | 1718 return; |
1719 | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1720 realwho = create_valid_jid(data->data, data->next->data, |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1721 data->next->next->data); |
2086 | 1722 debug_printf("%s\n", realwho); |
1723 | |
2956 | 1724 Jid = jid_new(gjc->p, realwho); |
1725 | |
1726 if((jc = find_any_chat(gc, Jid)) != NULL) { | |
1727 free(Jid); /* don't need it, after all */ | |
1728 switch(jc->state) { | |
1729 case JCS_PENDING: | |
1730 debug_printf("attempt to re-join already pending Jabber chat! (ignoring)\n"); | |
1731 g_free(realwho); /* yuck! */ | |
1732 return; | |
1733 case JCS_ACTIVE: | |
1734 debug_printf("attempt to re-join already active Jabber chat! (ignoring)\n"); | |
1735 g_free(realwho); /* yuck! */ | |
1736 return; | |
1737 case JCS_CLOSED: | |
1738 debug_printf("rejoining previously closed Jabber chat\n"); | |
1739 break; | |
1740 default: | |
1741 debug_printf("found Jabber chat in unknown state! (ignoring)\n"); | |
1742 g_free(realwho); /* yuck! */ | |
1743 return; | |
1744 } | |
1745 } else { | |
1746 debug_printf("joining completely new Jabber chat\n"); | |
1747 jc = g_new0(struct jabber_chat, 1); | |
1748 jc->Jid = Jid; | |
1749 jc->gc = gc; | |
1750 ((struct jabber_data *)gc->proto_data)->chats = g_slist_append(jcs, jc); | |
1751 } | |
1752 | |
1753 jc->state = JCS_PENDING; | |
1754 | |
2086 | 1755 x = jutil_presnew(0, realwho, NULL); |
2956 | 1756 gjab_send(gjc, x); |
2086 | 1757 xmlnode_free(x); |
1758 g_free(realwho); | |
1759 } | |
1760 | |
1761 static void jabber_chat_invite(struct gaim_connection *gc, int id, char *message, char *name) | |
1762 { | |
1763 xmlnode x, y; | |
1764 struct jabber_data *jd = gc->proto_data; | |
2956 | 1765 gjconn gjc = jd->gjc; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1766 struct jabber_chat *jc = NULL; |
2086 | 1767 char *realwho, *subject; |
1768 | |
1769 if (!name) | |
1770 return; | |
1771 | |
1772 /* find which chat we're inviting to */ | |
2956 | 1773 if(jabber_find_chat_by_convo_id(gc, id, &jc) != 0) |
2086 | 1774 return; |
1775 | |
1776 x = xmlnode_new_tag("message"); | |
1777 if (!strchr(name, '@')) | |
2956 | 1778 realwho = g_strdup_printf("%s@%s", name, gjc->user->server); |
2086 | 1779 else |
1780 realwho = g_strdup(name); | |
1781 xmlnode_put_attrib(x, "to", realwho); | |
1782 g_free(realwho); | |
1783 | |
1784 y = xmlnode_insert_tag(x, "x"); | |
1785 xmlnode_put_attrib(y, "xmlns", "jabber:x:conference"); | |
1786 subject = g_strdup_printf("%s@%s", jc->Jid->user, jc->Jid->server); | |
1787 xmlnode_put_attrib(y, "jid", subject); | |
1788 g_free(subject); | |
1789 | |
1790 if (message && strlen(message)) { | |
1791 char *utf8 = str_to_utf8(message); | |
1792 y = xmlnode_insert_tag(x, "body"); | |
1793 xmlnode_insert_cdata(y, utf8, -1); | |
1794 g_free(utf8); | |
1795 } | |
1796 | |
2956 | 1797 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2086 | 1798 xmlnode_free(x); |
1799 } | |
1800 | |
1801 static void jabber_chat_leave(struct gaim_connection *gc, int id) | |
1802 { | |
1803 struct jabber_data *jd = gc->proto_data; | |
2956 | 1804 gjconn gjc = jd->gjc; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1805 struct jabber_chat *jc = NULL; |
2086 | 1806 char *realwho; |
1807 xmlnode x; | |
1808 | |
2956 | 1809 /* Find out which chat we're leaving */ |
1810 if(jabber_find_chat_by_convo_id(gc, id, &jc) != 0) | |
2086 | 1811 return; |
1812 | |
1813 realwho = g_strdup_printf("%s@%s", jc->Jid->user, jc->Jid->server); | |
1814 x = jutil_presnew(0, realwho, NULL); | |
1815 g_free(realwho); | |
1816 xmlnode_put_attrib(x, "type", "unavailable"); | |
2956 | 1817 gjab_send(gjc, x); |
2086 | 1818 xmlnode_free(x); |
1819 jc->b = NULL; | |
1820 } | |
1821 | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1822 static int jabber_chat_send(struct gaim_connection *gc, int id, char *message) |
2086 | 1823 { |
1824 xmlnode x, y; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1825 struct jabber_chat *jc = NULL; |
2086 | 1826 char *chatname; |
2956 | 1827 int retval = 0; |
1828 | |
1829 /* Find out which chat we're sending to */ | |
1830 if((retval = jabber_find_chat_by_convo_id(gc, id, &jc)) != 0) | |
1831 return(retval); | |
2086 | 1832 |
1833 x = xmlnode_new_tag("message"); | |
1834 xmlnode_put_attrib(x, "from", jid_full(jc->Jid)); | |
1835 chatname = g_strdup_printf("%s@%s", jc->Jid->user, jc->Jid->server); | |
1836 xmlnode_put_attrib(x, "to", chatname); | |
1837 g_free(chatname); | |
1838 xmlnode_put_attrib(x, "type", "groupchat"); | |
1839 | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
1840 if (message && strlen(message) > strlen("/topic ") && |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
1841 !g_strncasecmp(message, "/topic ", strlen("/topic "))) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
1842 char buf[8192]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
1843 char *utf8 = str_to_utf8(message + strlen("/topic ")); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
1844 y = xmlnode_insert_tag(x, "subject"); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
1845 xmlnode_insert_cdata(y, utf8, -1); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
1846 y = xmlnode_insert_tag(x, "body"); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
1847 g_snprintf(buf, sizeof(buf), "/me has changed the subject to: %s", utf8); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
1848 xmlnode_insert_cdata(y, buf, -1); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
1849 g_free(utf8); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
1850 } else if (message && strlen(message)) { |
2086 | 1851 char *utf8 = str_to_utf8(message); |
1852 y = xmlnode_insert_tag(x, "body"); | |
1853 xmlnode_insert_cdata(y, utf8, -1); | |
1854 g_free(utf8); | |
1855 } | |
1856 | |
2956 | 1857 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2086 | 1858 xmlnode_free(x); |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1859 return 0; |
2086 | 1860 } |
1861 | |
1862 static void jabber_chat_whisper(struct gaim_connection *gc, int id, char *who, char *message) | |
1863 { | |
1864 xmlnode x, y; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1865 struct jabber_chat *jc = NULL; |
2086 | 1866 char *chatname; |
1867 | |
2956 | 1868 /* Find out which chat we're whispering to */ |
1869 if(jabber_find_chat_by_convo_id(gc, id, &jc) != 0) | |
2086 | 1870 return; |
1871 | |
1872 x = xmlnode_new_tag("message"); | |
1873 xmlnode_put_attrib(x, "from", jid_full(jc->Jid)); | |
1874 chatname = g_strdup_printf("%s@%s/%s", jc->Jid->user, jc->Jid->server, who); | |
1875 xmlnode_put_attrib(x, "to", chatname); | |
1876 g_free(chatname); | |
1877 xmlnode_put_attrib(x, "type", "normal"); | |
1878 | |
1879 if (message && strlen(message)) { | |
1880 char *utf8 = str_to_utf8(message); | |
1881 y = xmlnode_insert_tag(x, "body"); | |
1882 xmlnode_insert_cdata(y, utf8, -1); | |
1883 g_free(utf8); | |
1884 } | |
1885 | |
2956 | 1886 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2086 | 1887 xmlnode_free(x); |
1888 } | |
1889 | |
1890 static char *jabber_normalize(const char *s) | |
1891 { | |
1892 static char buf[BUF_LEN]; | |
1893 char *t, *u; | |
1894 int x = 0; | |
1895 | |
1896 g_return_val_if_fail((s != NULL), NULL); | |
1897 | |
2956 | 1898 /* Somebody called us with s == NULL once... */ |
1899 if(s == NULL) { | |
1900 return(NULL); | |
1901 } else { | |
1902 u = t = g_strdup(s); | |
1903 | |
1904 g_strdown(t); | |
1905 | |
1906 while (*t && (x < BUF_LEN - 1)) { | |
1907 if (*t != ' ') | |
1908 buf[x++] = *t; | |
1909 t++; | |
1910 } | |
1911 buf[x] = '\0'; | |
1912 g_free(u); | |
1913 | |
1914 if (!strchr(buf, '@')) { | |
1915 strcat(buf, "@jabber.org"); /* this isn't always right, but eh */ | |
1916 } else if ((u = strchr(strchr(buf, '@'), '/')) != NULL) { | |
1917 *u = '\0'; | |
1918 } | |
1919 | |
1920 return buf; | |
2086 | 1921 } |
1922 } | |
1923 | |
1924 static void jabber_get_info(struct gaim_connection *gc, char *who) { | |
1925 xmlnode x; | |
1926 char *id; | |
2956 | 1927 char *realwho; |
2086 | 1928 struct jabber_data *jd = gc->proto_data; |
2956 | 1929 gjconn gjc = jd->gjc; |
2086 | 1930 |
1931 x = jutil_iqnew(JPACKET__GET, NS_VCARD); | |
2956 | 1932 /* Bare username? */ |
1933 if (!strchr(who, '@')) { | |
1934 realwho = g_strdup_printf("%s@%s", who, gjc->user->server); | |
1935 } else { | |
1936 realwho = g_strdup(who); | |
1937 } | |
1938 xmlnode_put_attrib(x, "to", realwho); | |
1939 g_free(realwho); | |
1940 | |
1941 id = gjab_getid(gjc); | |
2086 | 1942 xmlnode_put_attrib(x, "id", id); |
1943 | |
2956 | 1944 g_hash_table_insert(jd->gjc->queries, g_strdup(id), g_strdup("vCard")); |
1945 | |
1946 gjab_send(gjc, x); | |
2086 | 1947 |
1948 xmlnode_free(x); | |
1949 | |
1950 } | |
1951 | |
2956 | 1952 static void jabber_get_away_msg(struct gaim_connection *gc, char *who) { |
1953 struct jabber_data *jd = gc->proto_data; | |
1954 gjconn gjc = jd->gjc; | |
1955 char *status; | |
1956 | |
1957 /* space for all elements: Jabber I.D. + "status" + NULL (list terminator) */ | |
1958 gchar **str_arr = (gchar **) g_new(gpointer, 3); | |
1959 gchar **ap = str_arr; | |
1960 gchar *realwho, *final; | |
1961 | |
1962 /* Bare username? */ | |
1963 if (!strchr(who, '@')) { | |
1964 realwho = g_strdup_printf("%s@%s", who, gjc->user->server); | |
1965 } else { | |
1966 realwho = g_strdup(who); | |
1967 } | |
1968 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", realwho); | |
1969 | |
1970 if((status = g_hash_table_lookup(jd->hash, realwho)) == NULL) { | |
1971 status = "Online"; | |
1972 } | |
1973 *ap++ = g_strdup_printf("<B>Status:</B> %s<BR>\n", status); | |
1974 | |
1975 *ap = NULL; | |
1976 | |
1977 final= g_strjoinv(NULL, str_arr); | |
1978 g_strfreev(str_arr); | |
1979 | |
1980 g_show_info_text(gc, realwho, 2, final, NULL); | |
1981 g_free(realwho); | |
1982 g_free(final); | |
1983 | |
1984 } | |
1985 | |
1986 static void jabber_get_cb_info(struct gaim_connection *gc, int cid, char *who) { | |
1987 struct jabber_chat *jc = NULL; | |
1988 char *realwho; | |
1989 | |
1990 /* Find out which chat */ | |
1991 if(jabber_find_chat_by_convo_id(gc, cid, &jc) != 0) | |
1992 return; | |
1993 | |
1994 realwho = g_strdup_printf("%s@%s/%s", jc->Jid->user, jc->Jid->server, who); | |
1995 | |
1996 jabber_get_info(gc, realwho); | |
1997 g_free(realwho); | |
1998 } | |
1999 | |
2000 static void jabber_get_cb_away_msg(struct gaim_connection *gc, int cid, char *who) { | |
2001 struct jabber_chat *jc = NULL; | |
2002 char *realwho; | |
2003 | |
2004 /* Find out which chat */ | |
2005 if(jabber_find_chat_by_convo_id(gc, cid, &jc) != 0) | |
2006 return; | |
2007 | |
2008 realwho = g_strdup_printf("%s@%s/%s", jc->Jid->user, jc->Jid->server, who); | |
2009 | |
2010 jabber_get_away_msg(gc, realwho); | |
2011 | |
2012 g_free(realwho); | |
2013 | |
2014 } | |
2015 | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2016 static GList *jabber_buddy_menu(struct gaim_connection *gc, char *who) { |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2017 GList *m = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2018 struct proto_buddy_menu *pbm; |
2086 | 2019 |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2020 pbm = g_new0(struct proto_buddy_menu, 1); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2021 pbm->label = _("Get Info"); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2022 pbm->callback = jabber_get_info; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2023 pbm->gc = gc; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2024 m = g_list_append(m, pbm); |
2956 | 2025 pbm = g_new0(struct proto_buddy_menu, 1); |
2026 pbm->label = _("Get Away Msg"); | |
2027 pbm->callback = jabber_get_away_msg; | |
2028 pbm->gc = gc; | |
2029 m = g_list_append(m, pbm); | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2030 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2031 return m; |
2086 | 2032 } |
2033 | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
2034 static GList *jabber_away_states(struct gaim_connection *gc) { |
2086 | 2035 GList *m = NULL; |
2036 | |
2037 m = g_list_append(m, "Online"); | |
2038 m = g_list_append(m, "Chatty"); | |
2039 m = g_list_append(m, "Away"); | |
2040 m = g_list_append(m, "Extended Away"); | |
2041 m = g_list_append(m, "Do Not Disturb"); | |
2042 | |
2043 return m; | |
2044 } | |
2045 | |
2046 static void jabber_set_away(struct gaim_connection *gc, char *state, char *message) | |
2047 { | |
2048 xmlnode x, y; | |
2049 struct jabber_data *jd = gc->proto_data; | |
2956 | 2050 gjconn gjc = jd->gjc; |
2086 | 2051 |
2052 gc->away = NULL; /* never send an auto-response */ | |
2053 | |
2054 x = xmlnode_new_tag("presence"); | |
2055 | |
2056 if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
2057 /* oh goody. Gaim is telling us what to do. */ | |
2058 if (message) { | |
2059 /* Gaim wants us to be away */ | |
2060 y = xmlnode_insert_tag(x, "show"); | |
2061 xmlnode_insert_cdata(y, "away", -1); | |
2062 y = xmlnode_insert_tag(x, "status"); | |
2063 xmlnode_insert_cdata(y, message, -1); | |
2064 gc->away = ""; | |
2065 } else { | |
2066 /* Gaim wants us to not be away */ | |
2067 /* but for Jabber, we can just send presence with no other information. */ | |
2068 } | |
2069 } else { | |
2070 /* state is one of our own strings. it won't be NULL. */ | |
2071 if (!strcmp(state, "Online")) { | |
2072 /* once again, we don't have to put anything here */ | |
2073 } else if (!strcmp(state, "Chatty")) { | |
2074 y = xmlnode_insert_tag(x, "show"); | |
2075 xmlnode_insert_cdata(y, "chat", -1); | |
2076 } else if (!strcmp(state, "Away")) { | |
2077 y = xmlnode_insert_tag(x, "show"); | |
2078 xmlnode_insert_cdata(y, "away", -1); | |
2079 gc->away = ""; | |
2080 } else if (!strcmp(state, "Extended Away")) { | |
2081 y = xmlnode_insert_tag(x, "show"); | |
2082 xmlnode_insert_cdata(y, "xa", -1); | |
2083 gc->away = ""; | |
2084 } else if (!strcmp(state, "Do Not Disturb")) { | |
2085 y = xmlnode_insert_tag(x, "show"); | |
2086 xmlnode_insert_cdata(y, "dnd", -1); | |
2087 gc->away = ""; | |
2088 } | |
2089 } | |
2090 | |
2956 | 2091 gjab_send(gjc, x); |
2086 | 2092 xmlnode_free(x); |
2093 } | |
2094 | |
2095 static void jabber_set_idle(struct gaim_connection *gc, int idle) { | |
2096 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; | |
2097 debug_printf("jabber_set_idle: setting idle %i\n", idle); | |
2098 jd->idle = idle ? time(NULL) - idle : idle; | |
2099 } | |
2100 | |
2101 static void jabber_keepalive(struct gaim_connection *gc) { | |
2102 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; | |
2956 | 2103 gjab_send_raw(jd->gjc, " \t "); |
2086 | 2104 } |
2105 | |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
2106 static GList *jabber_user_opts() |
2086 | 2107 { |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
2108 GList *m = NULL; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
2109 struct proto_user_opt *puo; |
2086 | 2110 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
2111 puo = g_new0(struct proto_user_opt, 1); |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
2112 puo->label = "Port:"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
2113 puo->def = "5222"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
2114 puo->pos = USEROPT_PORT; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
2115 m = g_list_append(m, puo); |
2086 | 2116 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
2117 return m; |
2086 | 2118 } |
2119 | |
2607
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
2120 static void jabber_buddy_free(struct buddy *b) |
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
2121 { |
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
2122 while (b->proto_data) { |
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
2123 g_free(((GSList *)b->proto_data)->data); |
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
2124 b->proto_data = g_slist_remove(b->proto_data, ((GSList *)b->proto_data)->data); |
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
2125 } |
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
2126 } |
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
2127 |
2956 | 2128 /*---------------------------------------*/ |
2129 /* Jabber "set info" (vCard) support */ | |
2130 /*---------------------------------------*/ | |
2131 | |
2132 /* | |
2133 * V-Card format: | |
2134 * | |
2135 * <vCard prodid='' version='' xmlns=''> | |
2136 * <FN></FN> | |
2137 * <N> | |
2138 * <FAMILY/> | |
2139 * <GIVEN/> | |
2140 * </N> | |
2141 * <NICKNAME/> | |
2142 * <URL/> | |
2143 * <ADR> | |
2144 * <STREET/> | |
2145 * <EXTADD/> | |
2146 * <LOCALITY/> | |
2147 * <REGION/> | |
2148 * <PCODE/> | |
2149 * <COUNTRY/> | |
2150 * </ADR> | |
2151 * <TEL/> | |
2152 * <EMAIL/> | |
2153 * <ORG> | |
2154 * <ORGNAME/> | |
2155 * <ORGUNIT/> | |
2156 * </ORG> | |
2157 * <TITLE/> | |
2158 * <ROLE/> | |
2159 * <DESC/> | |
2160 * <BDAY/> | |
2161 * </vCard> | |
2162 * | |
2163 * See also: | |
2164 * | |
2165 * http://docs.jabber.org/proto/html/vcard-temp.html | |
2166 * http://www.vcard-xml.org/dtd/vCard-XML-v2-20010520.dtd | |
2167 */ | |
2168 | |
2169 /* | |
2170 * Cross-reference user-friendly V-Card entry labels to vCard XML tags | |
2171 * and attributes. | |
2172 * | |
2173 * Order is (or should be) unimportant. For example: we have no way of | |
2174 * knowing in what order real data will arrive. | |
2175 * | |
2176 * Format: Label, Pre-set text, "visible" flag, "editable" flag, XML tag | |
2177 * name, XML tag's parent tag "path" (relative to vCard node). | |
2178 * | |
2179 * List is terminated by a NULL label pointer. | |
2180 * | |
2181 * Entries with no label text, but with XML tag and parent tag | |
2182 * entries, are used by V-Card XML construction routines to | |
2183 * "automagically" construct the appropriate XML node tree. | |
2184 * | |
2185 * Thoughts on future direction/expansion | |
2186 * | |
2187 * This is a "simple" vCard. | |
2188 * | |
2189 * It is possible for nodes other than the "vCard" node to have | |
2190 * attributes. Should that prove necessary/desirable, add an | |
2191 * "attributes" pointer to the vcard_template struct, create the | |
2192 * necessary tag_attr structs, and add 'em to the vcard_dflt_data | |
2193 * array. | |
2194 * | |
2195 * The above changes will (obviously) require changes to the vCard | |
2196 * construction routines. | |
2197 */ | |
2198 | |
2199 struct vcard_template { | |
2200 char *label; /* label text pointer */ | |
2201 char *text; /* entry text pointer */ | |
2202 int visible; /* should entry field be "visible?" */ | |
2203 int editable; /* should entry field be editable? */ | |
2204 char *tag; /* tag text */ | |
2205 char *ptag; /* parent tag "path" text */ | |
2206 char *url; /* vCard display format if URL */ | |
2207 } vcard_template_data[] = { | |
2208 {"Full Name", NULL, TRUE, TRUE, "FN", NULL, NULL}, | |
2209 {"Family Name", NULL, TRUE, TRUE, "FAMILY", "N", NULL}, | |
2210 {"Given Name", NULL, TRUE, TRUE, "GIVEN", "N", NULL}, | |
2211 {"Nickname", NULL, TRUE, TRUE, "NICKNAME", NULL, NULL}, | |
2212 {"URL", NULL, TRUE, TRUE, "URL", NULL, "<A HREF=\"%s\">%s</A>"}, | |
2213 {"Street Address", NULL, TRUE, TRUE, "STREET", "ADR", NULL}, | |
2214 {"Extended Address", NULL, TRUE, TRUE, "EXTADD", "ADR", NULL}, | |
2215 {"Locality", NULL, TRUE, TRUE, "LOCALITY", "ADR", NULL}, | |
2216 {"Region", NULL, TRUE, TRUE, "REGION", "ADR", NULL}, | |
2217 {"Postal Code", NULL, TRUE, TRUE, "PCODE", "ADR", NULL}, | |
2218 {"Country", NULL, TRUE, TRUE, "COUNTRY", "ADR", NULL}, | |
2219 {"Telephone", NULL, TRUE, TRUE, "TELEPHONE", NULL, NULL}, | |
2220 {"Email", NULL, TRUE, TRUE, "EMAIL", NULL, "<A HREF=\"mailto:%s\">%s</A>"}, | |
2221 {"Organization Name", NULL, TRUE, TRUE, "ORGNAME", "ORG", NULL}, | |
2222 {"Organization Unit", NULL, TRUE, TRUE, "ORGUNIT", "ORG", NULL}, | |
2223 {"Title", NULL, TRUE, TRUE, "TITLE", NULL, NULL}, | |
2224 {"Role", NULL, TRUE, TRUE, "ROLE", NULL, NULL}, | |
2225 {"Birthday", NULL, TRUE, TRUE, "BDAY", NULL, NULL}, | |
2226 {"Description", NULL, TRUE, TRUE, "DESC", NULL, NULL}, | |
2227 {"", NULL, TRUE, TRUE, "N", NULL, NULL}, | |
2228 {"", NULL, TRUE, TRUE, "ADR", NULL, NULL}, | |
2229 {"", NULL, TRUE, TRUE, "ORG", NULL, NULL}, | |
2230 {NULL, NULL, 0, 0, NULL, NULL, NULL} | |
2231 }; | |
2232 | |
2233 /* | |
2234 * The "vCard" tag's attibute list... | |
2235 */ | |
2236 struct tag_attr { | |
2237 char *attr; | |
2238 char *value; | |
2239 } vcard_tag_attr_list[] = { | |
2240 {"prodid", "-//HandGen//NONSGML vGen v1.0//EN"}, | |
2241 {"version", "2.0", }, | |
2242 {"xmlns", "vcard-temp", }, | |
2243 {NULL, NULL}, | |
2244 }; | |
2245 | |
2246 | |
2247 /* | |
2248 * V-Card user instructions | |
2249 */ | |
2250 static char *multi_entry_instructions = | |
2251 "Enter the stuff you feel comfortable with. Leave the rest blank."; | |
2252 | |
2253 /* | |
2254 * Used by routines to parse an XML-encoded string into an xmlnode tree | |
2255 */ | |
2256 typedef struct { | |
2257 XML_Parser parser; | |
2258 xmlnode current; | |
2259 } *xmlstr2xmlnode_parser, xmlstr2xmlnode_parser_struct; | |
2260 | |
2261 | |
2262 /* | |
2263 * Display a Jabber vCard | |
2264 */ | |
2265 static void jabber_handlevcard(gjconn gjc, xmlnode querynode, char *from) | |
2266 { | |
2267 struct gaim_connection *gc = GJ_GC(gjc); | |
2268 struct jabber_data *jd = GJ_GC(gjc)->proto_data; | |
2269 jid who = jid_new(gjc->p, from); | |
2270 char *cdata, *status; | |
2271 | |
2272 struct vcard_template *vc_tp = vcard_template_data; | |
2273 | |
2274 /* space for all vCard elements + Jabber I.D. + "status" + NULL (list terminator) */ | |
2275 gchar **str_arr = (gchar **) g_new(gpointer, | |
2276 (sizeof(vcard_template_data)/sizeof(struct vcard_template)) + 3); | |
2277 gchar **ap = str_arr; | |
2278 gchar *buddy, *final; | |
2279 | |
2280 if(who->resource != NULL && (who->resource)[0] != '\0') { | |
2281 buddy = g_strdup_printf("%s@%s/%s", who->user, who->server, who->resource); | |
2282 } else { | |
2283 buddy = g_strdup_printf("%s@%s", who->user, who->server); | |
2284 } | |
2285 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", buddy); | |
2286 | |
2287 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
2288 if(strcmp(vc_tp->tag, "DESC") == 0) | |
2289 continue; /* special handling later */ | |
2290 if(vc_tp->ptag == NULL) { | |
2291 cdata = xmlnode_get_tag_data(querynode, vc_tp->tag); | |
2292 } else { | |
2293 gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag); | |
2294 cdata = xmlnode_get_tag_data(querynode, tag); | |
2295 g_free(tag); | |
2296 } | |
2297 if(cdata != NULL) { | |
2298 if(vc_tp->url == NULL) { | |
2299 *ap++ = g_strdup_printf("<B>%s:</B> %s<BR>\n", vc_tp->label, cdata); | |
2300 } else { | |
2301 gchar *fmt = g_strdup_printf("<B>%%s:</B> %s<BR>\n", vc_tp->url); | |
2302 *ap++ = g_strdup_printf(fmt, vc_tp->label, cdata, cdata); | |
2303 g_free(fmt); | |
2304 } | |
2305 } | |
2306 } | |
2307 | |
2308 if((status = g_hash_table_lookup(jd->hash, buddy)) == NULL) { | |
2309 status = "Online"; | |
2310 } | |
2311 *ap++ = g_strdup_printf("<B>Status:</B> %s<BR>\n", status); | |
2312 | |
2313 /* | |
2314 * "Description" handled as a special case: get a copy of the | |
2315 * string and HTML-ize. | |
2316 */ | |
2317 if((cdata = xmlnode_get_tag_data(querynode, "DESC")) != NULL) { | |
2318 gchar *tmp = g_strdup_printf("<HR>%s<BR>", cdata); | |
2319 *ap++ = strdup_withhtml(tmp); | |
2320 g_free(tmp); | |
2321 } | |
2322 | |
2323 *ap = NULL; | |
2324 | |
2325 final= g_strjoinv(NULL, str_arr); | |
2326 g_strfreev(str_arr); | |
2327 | |
2328 g_show_info_text(gc, buddy, 2, final, NULL); | |
2329 g_free(buddy); | |
2330 g_free(final); | |
2331 } | |
2332 | |
2333 /* | |
2334 * Used by XML_Parse on parsing CDATA | |
2335 */ | |
2336 static void xmlstr2xmlnode_charData(void *userdata, const char *s, int slen) | |
2337 { | |
2338 xmlstr2xmlnode_parser xmlp = (xmlstr2xmlnode_parser) userdata; | |
2339 | |
2340 if (xmlp->current) | |
2341 xmlnode_insert_cdata(xmlp->current, s, slen); | |
2342 } | |
2343 | |
2344 /* | |
2345 * Used by XML_Parse to start or append to an xmlnode | |
2346 */ | |
2347 static void xmlstr2xmlnode_startElement(void *userdata, const char *name, const char **attribs) | |
2348 { | |
2349 xmlnode x; | |
2350 xmlstr2xmlnode_parser xmlp = (xmlstr2xmlnode_parser) userdata; | |
2351 | |
2352 if (xmlp->current) { | |
2353 /* Append the node to the current one */ | |
2354 x = xmlnode_insert_tag(xmlp->current, name); | |
2355 xmlnode_put_expat_attribs(x, attribs); | |
2356 | |
2357 xmlp->current = x; | |
2358 } else { | |
2359 x = xmlnode_new_tag(name); | |
2360 xmlnode_put_expat_attribs(x, attribs); | |
2361 xmlp->current = x; | |
2362 } | |
2363 } | |
2364 | |
2365 /* | |
2366 * Used by XML_Parse to end an xmlnode | |
2367 */ | |
2368 static void xmlstr2xmlnode_endElement(void *userdata, const char *name) | |
2369 { | |
2370 xmlstr2xmlnode_parser xmlp = (xmlstr2xmlnode_parser) userdata; | |
2371 xmlnode x; | |
2372 | |
2373 if (xmlp->current != NULL && (x = xmlnode_get_parent(xmlp->current)) != NULL) { | |
2374 xmlp->current = x; | |
2375 } | |
2376 } | |
2377 | |
2378 /* | |
2379 * Parse an XML-encoded string into an xmlnode tree | |
2380 * | |
2381 * Caller is responsible for freeing the returned xmlnode | |
2382 */ | |
2383 static xmlnode xmlstr2xmlnode(char *xmlstring) | |
2384 { | |
2385 xmlstr2xmlnode_parser my_parser = g_new(xmlstr2xmlnode_parser_struct, 1); | |
2386 xmlnode x = NULL; | |
2387 | |
2388 my_parser->parser = XML_ParserCreate(NULL); | |
2389 my_parser->current = NULL; | |
2390 | |
2391 XML_SetUserData(my_parser->parser, (void *)my_parser); | |
2392 XML_SetElementHandler(my_parser->parser, xmlstr2xmlnode_startElement, xmlstr2xmlnode_endElement); | |
2393 XML_SetCharacterDataHandler(my_parser->parser, xmlstr2xmlnode_charData); | |
2394 XML_Parse(my_parser->parser, xmlstring, strlen(xmlstring), 0); | |
2395 | |
2396 x = my_parser->current; | |
2397 | |
2398 XML_ParserFree(my_parser->parser); | |
2399 g_free(my_parser); | |
2400 | |
2401 return(x); | |
2402 } | |
2403 | |
2404 /* | |
2405 * Insert a tag node into an xmlnode tree, recursively inserting parent tag | |
2406 * nodes as necessary | |
2407 * | |
2408 * Returns pointer to inserted node | |
2409 * | |
2410 * Note to hackers: this code is designed to be re-entrant (it's recursive--it | |
2411 * calls itself), so don't put any "static"s in here! | |
2412 */ | |
2413 static xmlnode insert_tag_to_parent_tag(xmlnode start, const char *parent_tag, const char *new_tag) | |
2414 { | |
2415 xmlnode x = NULL; | |
2416 | |
2417 /* | |
2418 * If the parent tag wasn't specified, see if we can get it | |
2419 * from the vCard template struct. | |
2420 */ | |
2421 if(parent_tag == NULL) { | |
2422 struct vcard_template *vc_tp = vcard_template_data; | |
2423 | |
2424 while(vc_tp->label != NULL) { | |
2425 if(strcmp(vc_tp->tag, new_tag) == 0) { | |
2426 parent_tag = vc_tp->ptag; | |
2427 break; | |
2428 } | |
2429 ++vc_tp; | |
2430 } | |
2431 } | |
2432 | |
2433 /* | |
2434 * If we have a parent tag... | |
2435 */ | |
2436 if(parent_tag != NULL ) { | |
2437 /* | |
2438 * Try to get the parent node for a tag | |
2439 */ | |
2440 if((x = xmlnode_get_tag(start, parent_tag)) == NULL) { | |
2441 /* | |
2442 * Descend? | |
2443 */ | |
2444 char *grand_parent = strcpy(g_malloc(strlen(parent_tag) + 1), parent_tag); | |
2445 char *parent; | |
2446 | |
2447 if((parent = strrchr(grand_parent, '/')) != NULL) { | |
2448 *(parent++) = '\0'; | |
2449 x = insert_tag_to_parent_tag(start, grand_parent, parent); | |
2450 } else { | |
2451 x = xmlnode_insert_tag(start, grand_parent); | |
2452 } | |
2453 g_free(grand_parent); | |
2454 } else { | |
2455 /* | |
2456 * We found *something* to be the parent node. | |
2457 * Note: may be the "root" node! | |
2458 */ | |
2459 xmlnode y; | |
2460 if((y = xmlnode_get_tag(x, new_tag)) != NULL) { | |
2461 return(y); | |
2462 } | |
2463 } | |
2464 } | |
2465 | |
2466 /* | |
2467 * insert the new tag into its parent node | |
2468 */ | |
2469 return(xmlnode_insert_tag((x == NULL? start : x), new_tag)); | |
2470 } | |
2471 | |
2472 /* | |
2473 * Find the tag name for a label | |
2474 * | |
2475 * Returns NULL on not found | |
2476 */ | |
2477 static char *tag_for_label(const char *label) | |
2478 { | |
2479 struct vcard_template *vc_tp = vcard_template_data; | |
2480 char *p = NULL; | |
2481 | |
2482 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
2483 if(strcmp(label, vc_tp->label) == 0) { | |
2484 p = vc_tp->tag; | |
2485 break; | |
2486 } | |
2487 } | |
2488 | |
2489 return(p); | |
2490 } | |
2491 | |
2492 /* | |
2493 * Send vCard info to Jabber server | |
2494 */ | |
2495 static void jabber_set_info(struct gaim_connection *gc, char *info) | |
2496 { | |
2497 xmlnode x, vc_node; | |
2498 char *id; | |
2499 struct jabber_data *jd = gc->proto_data; | |
2500 gjconn gjc = jd->gjc; | |
2501 | |
2502 x = xmlnode_new_tag("iq"); | |
2503 xmlnode_put_attrib(x,"type","set"); | |
2504 | |
2505 id = gjab_getid(gjc); | |
2506 | |
2507 xmlnode_put_attrib(x, "id", id); | |
2508 | |
2509 /* | |
2510 * Send only if there's actually any *information* to send | |
2511 */ | |
2512 if((vc_node = xmlstr2xmlnode(info)) != NULL && xmlnode_get_name(vc_node) != NULL && | |
2513 g_strncasecmp(xmlnode_get_name(vc_node), "vcard", 5) == 0) { | |
2514 xmlnode_insert_tag_node(x, vc_node); | |
2515 debug_printf("jabber: vCard packet: %s\n", xmlnode2str(x)); | |
2516 gjab_send(gjc, x); | |
2517 } | |
2518 | |
2519 xmlnode_free(x); | |
2520 } | |
2521 | |
2522 /* | |
2523 * This is the callback from the "ok clicked" for "set vCard" | |
2524 * | |
2525 * Formats GSList data into XML-encoded string and returns a pointer | |
2526 * to said string. | |
2527 * | |
2528 * g_free()'ing the returned string space is the responsibility of | |
2529 * the caller. | |
2530 */ | |
2531 static gchar *jabber_format_info(MultiEntryDlg *b) | |
2532 { | |
2533 xmlnode vc_node; | |
2534 GSList *list; | |
2535 MultiEntryData *med; | |
2536 MultiTextData *mtd; | |
2537 char *p; | |
2538 | |
2539 struct tag_attr *tag_attr; | |
2540 | |
2541 vc_node = xmlnode_new_tag("vCard"); | |
2542 | |
2543 for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr) | |
2544 xmlnode_put_attrib(vc_node, tag_attr->attr, tag_attr->value); | |
2545 | |
2546 for(list = b->multi_entry_items; list != NULL; list = list->next) { | |
2547 med = (MultiEntryData *) list->data; | |
2548 if(med->label != NULL && med->text != NULL && (med->text)[0] != '\0') { | |
2549 if((p = tag_for_label(med->label)) != NULL) { | |
2550 xmlnode xp; | |
2551 if((xp = insert_tag_to_parent_tag(vc_node, NULL, p)) != NULL) { | |
2552 xmlnode_insert_cdata(xp, med->text, -1); | |
2553 } | |
2554 } | |
2555 } | |
2556 } | |
2557 | |
2558 for(list = b->multi_text_items; list != NULL; list = list->next) { | |
2559 mtd = (MultiTextData *) list->data; | |
2560 if(mtd->label != NULL && mtd->text != NULL && (mtd->text)[0] != '\0') { | |
2561 if((p = tag_for_label(mtd->label)) != NULL) { | |
2562 xmlnode xp; | |
2563 if((xp = insert_tag_to_parent_tag(vc_node, NULL, p)) != NULL) { | |
2564 xmlnode_insert_cdata(xp, mtd->text, -1); | |
2565 } | |
2566 } | |
2567 } | |
2568 } | |
2569 | |
2570 | |
2571 p = g_strdup(xmlnode2str(vc_node)); | |
2572 xmlnode_free(vc_node); | |
2573 | |
2574 return(p); | |
2575 } | |
2576 | |
2577 /* | |
2578 * This gets executed by the proto action | |
2579 * | |
2580 * Creates a new MultiEntryDlg struct, gets the XML-formatted user_info | |
2581 * string (if any) into GSLists for the (multi-entry) edit dialog and | |
2582 * calls the set_vcard dialog. | |
2583 */ | |
2584 static void jabber_setup_set_info(struct gaim_connection *gc) | |
2585 { | |
2586 MultiEntryData *data; | |
2587 const struct vcard_template *vc_tp; | |
2588 char *user_info; | |
2589 MultiEntryDlg *b = multi_entry_dialog_new(); | |
2590 char *cdata; | |
2591 xmlnode x_vc_data = NULL; | |
2592 struct aim_user *tmp = gc->user; | |
2593 b->user = tmp; | |
2594 | |
2595 | |
2596 /* | |
2597 * Get existing, XML-formatted, user info | |
2598 */ | |
2599 if((user_info = g_malloc(strlen(tmp->user_info) + 1)) != NULL) { | |
2600 strcpy(user_info, tmp->user_info); | |
2601 x_vc_data = xmlstr2xmlnode(user_info); | |
2602 } | |
2603 | |
2604 /* | |
2605 * Set up GSLists for edit with labels from "template," data from user info | |
2606 */ | |
2607 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
2608 if((vc_tp->label)[0] == '\0') | |
2609 continue; | |
2610 if(vc_tp->ptag == NULL) { | |
2611 cdata = xmlnode_get_tag_data(x_vc_data, vc_tp->tag); | |
2612 } else { | |
2613 gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag); | |
2614 cdata = xmlnode_get_tag_data(x_vc_data, tag); | |
2615 g_free(tag); | |
2616 } | |
2617 if(strcmp(vc_tp->tag, "DESC") == 0) { | |
2618 multi_text_list_update(&(b->multi_text_items), | |
2619 vc_tp->label, cdata, TRUE); | |
2620 } else { | |
2621 data = multi_entry_list_update(&(b->multi_entry_items), | |
2622 vc_tp->label, cdata, TRUE); | |
2623 data->visible = vc_tp->visible; | |
2624 data->editable = vc_tp->editable; | |
2625 } | |
2626 } | |
2627 | |
2628 | |
2629 if(x_vc_data != NULL) { | |
2630 xmlnode_free(x_vc_data); | |
2631 } else { | |
2632 /* | |
2633 * Early Beta versions had a different user_info storage format--let's | |
2634 * see if that works. | |
2635 * | |
2636 * This goes away RSN. | |
2637 */ | |
2638 const char *record_separator = "<BR>"; | |
2639 const char *field_separator = ": "; | |
2640 gchar **str_list, **str_list_ptr, **str_list2; | |
2641 | |
2642 if((str_list = g_strsplit(user_info, record_separator, 0)) != NULL) { | |
2643 for(str_list_ptr = str_list; *str_list_ptr != NULL; ++str_list_ptr) { | |
2644 str_list2 = g_strsplit(*str_list_ptr, field_separator, 2); | |
2645 if(str_list2[0] != NULL && str_list2[1] != NULL) { | |
2646 g_strstrip(str_list2[0]); | |
2647 g_strstrip(str_list2[1]); | |
2648 /* this is ugly--so far */ | |
2649 if(strcmp(str_list2[0], "Description") == 0) { | |
2650 multi_text_list_update(&(b->multi_text_items), | |
2651 str_list2[0], str_list2[1], FALSE); | |
2652 } else { | |
2653 multi_entry_list_update(&(b->multi_entry_items), | |
2654 str_list2[0], str_list2[1], FALSE); | |
2655 } | |
2656 } | |
2657 g_strfreev(str_list2); | |
2658 } | |
2659 g_strfreev(str_list); | |
2660 } | |
2661 } | |
2662 | |
2663 if(user_info != NULL) { | |
2664 g_free(user_info); | |
2665 } | |
2666 | |
2667 b->title = "Gaim - vCard Wizzard"; | |
2668 b->wmclass_name = "set_info"; | |
2669 b->wmclass_class = "Gaim"; | |
2670 b->instructions->text = g_strdup(multi_entry_instructions); | |
2671 | |
2672 b->custom = (void *) jabber_format_info; | |
2673 | |
2674 show_set_vcard(b); | |
2675 } | |
2676 | |
2677 /*---------------------------------------*/ | |
2678 /* End Jabber "set info" (vCard) support */ | |
2679 /*---------------------------------------*/ | |
2680 | |
2681 /*----------------------------------------*/ | |
2682 /* Jabber "user registration" support */ | |
2683 /*----------------------------------------*/ | |
2684 | |
2685 /* | |
2686 * Three of the following four functions duplicate much of what | |
2687 * exists elsewhere: | |
2688 * | |
2689 * jabber_handleregresp() | |
2690 * gjab_reqreg() | |
2691 * jabber_handle_registration_state() | |
2692 * | |
2693 * It may be that an additional flag could be added to one of | |
2694 * the "local" structs and the duplicated code modified to | |
2695 * account for it--thus eliminating the duplication. Then again: | |
2696 * doing it the way it is may be much cleaner. | |
2697 * | |
2698 * TBD: Code to support requesting additional information server | |
2699 * wants at registration--incl. dialog. | |
2700 */ | |
2701 | |
2702 /* | |
2703 * Like jabber_handlepacket(), only different | |
2704 */ | |
2705 static void jabber_handleregresp(gjconn gjc, jpacket p) | |
2706 { | |
2707 if (jpacket_subtype(p) == JPACKET__RESULT) { | |
2708 xmlnode querynode; | |
2709 | |
2710 if((querynode = xmlnode_get_tag(p->x, "query")) != NULL) { | |
2711 char *xmlns; | |
2712 | |
2713 /* we damn well *better* have this! */ | |
2714 if((xmlns = xmlnode_get_attrib(querynode, "xmlns")) != NULL && | |
2715 strcmp(xmlns, NS_REGISTER) == 0) { | |
2716 | |
2717 char *tag; | |
2718 xmlnode child = xmlnode_get_firstchild(querynode); | |
2719 | |
2720 debug_printf("got registration requirments response!\n"); | |
2721 | |
2722 while(child != NULL) { | |
2723 if((tag = xmlnode_get_name(child)) != NULL) { | |
2724 char *data; | |
2725 | |
2726 fprintf(stderr, "DBG: got node: \"%s\"\n", tag); | |
2727 fflush(stderr); | |
2728 | |
2729 if((data = xmlnode_get_data(child)) != NULL) { | |
2730 fprintf(stderr, "DBG: got data: \"%s\"\n", data); | |
2731 fflush(stderr); | |
2732 } | |
2733 } | |
2734 child = xmlnode_get_nextsibling(child); | |
2735 } | |
2736 } | |
2737 } else { | |
2738 debug_printf("registration successful!\n"); | |
2739 | |
2740 hide_login_progress_notice(GJ_GC(gjc), "Server Registration successful!"); | |
2741 /* | |
2742 * TBD: is this the correct way to do away with a | |
2743 * gaim_connection and all its associated memory | |
2744 * allocs, etc.? | |
2745 */ | |
2746 signoff(GJ_GC(gjc)); | |
2747 } | |
2748 | |
2749 } else { | |
2750 xmlnode xerr; | |
2751 char *errmsg = NULL; | |
2752 int errcode = 0; | |
2753 struct jabber_data *jd = GJ_GC(gjc)->proto_data; | |
2754 | |
2755 debug_printf("registration failed\n"); | |
2756 xerr = xmlnode_get_tag(p->x, "error"); | |
2757 if (xerr) { | |
2758 char msg[BUF_LONG]; | |
2759 errmsg = xmlnode_get_data(xerr); | |
2760 if (xmlnode_get_attrib(xerr, "code")) { | |
2761 errcode = atoi(xmlnode_get_attrib(xerr, "code")); | |
2762 g_snprintf(msg, sizeof(msg), "Error %d: %s", errcode, errmsg); | |
2763 } else | |
2764 g_snprintf(msg, sizeof(msg), "%s", errmsg); | |
2765 hide_login_progress(GJ_GC(gjc), msg); | |
2766 } else { | |
2767 hide_login_progress(GJ_GC(gjc), "Unknown registration error"); | |
2768 } | |
2769 | |
2770 jd->die = TRUE; | |
2771 } | |
2772 } | |
2773 | |
2774 /* | |
2775 * Like gjab_reqauth(), only different | |
2776 */ | |
2777 static void gjab_reqreg(gjconn gjc) | |
2778 { | |
2779 xmlnode x, y, z; | |
2780 char *user; | |
2781 | |
2782 if (!gjc) | |
2783 return; | |
2784 | |
2785 x = jutil_iqnew(JPACKET__SET, NS_REGISTER); | |
2786 y = xmlnode_get_tag(x, "query"); | |
2787 | |
2788 user = gjc->user->user; | |
2789 | |
2790 if (user) { | |
2791 z = xmlnode_insert_tag(y, "username"); | |
2792 xmlnode_insert_cdata(z, user, -1); | |
2793 } | |
2794 z = xmlnode_insert_tag(y, "password"); | |
2795 xmlnode_insert_cdata(z, gjc->pass, -1); | |
2796 | |
2797 debug_printf("jabber: registration packet: %s\n", xmlnode2str(x)); | |
2798 gjab_send(gjc, x); | |
2799 xmlnode_free(x); | |
2800 } | |
2801 | |
2802 /* | |
2803 * Like gjab_reqauth(), only different | |
2804 */ | |
2805 static void gjab_reqregreqs(gjconn gjc) | |
2806 { | |
2807 xmlnode x, y, z; | |
2808 char *user; | |
2809 | |
2810 if (!gjc) | |
2811 return; | |
2812 | |
2813 x = jutil_iqnew(JPACKET__GET, NS_REGISTER); | |
2814 y = xmlnode_get_tag(x, "query"); | |
2815 | |
2816 xmlnode_put_attrib(x, "to", "jimsun.linxnet.com"); | |
2817 /* | |
2818 xmlnode_put_attrib(x, "from", "jseymour@jimsun.linxnet.com"); | |
2819 */ | |
2820 /* | |
2821 user = gjc->user->user; | |
2822 | |
2823 if (user) { | |
2824 z = xmlnode_insert_tag(y, "username"); | |
2825 xmlnode_insert_cdata(z, user, -1); | |
2826 } | |
2827 z = xmlnode_insert_tag(y, "password"); | |
2828 xmlnode_insert_cdata(z, gjc->pass, -1); | |
2829 */ | |
2830 | |
2831 debug_printf("jabber: registration packet: %s\n", xmlnode2str(x)); | |
2832 gjab_send(gjc, x); | |
2833 xmlnode_free(x); | |
2834 } | |
2835 | |
2836 /* | |
2837 * Like jabber_handlestate(), only different | |
2838 */ | |
2839 static void jabber_handle_registration_state(gjconn gjc, int state) | |
2840 { | |
2841 switch (state) { | |
2842 case JCONN_STATE_OFF: | |
2843 hide_login_progress(GJ_GC(gjc), "Unable to connect"); | |
2844 signoff(GJ_GC(gjc)); | |
2845 break; | |
2846 case JCONN_STATE_CONNECTED: | |
2847 /* | |
2848 * TBD? | |
2849 set_login_progress(GJ_GC(gjc), 2, "Connected"); | |
2850 */ | |
2851 break; | |
2852 case JCONN_STATE_ON: | |
2853 /* | |
2854 * TBD? | |
2855 set_login_progress(GJ_GC(gjc), 3, "Requesting Authentication Method"); | |
2856 */ | |
2857 gjab_reqreg(gjc); | |
2858 /* | |
2859 * TBD: A work-in-progress | |
2860 gjab_reqregreqs(gjc); | |
2861 */ | |
2862 break; | |
2863 default: | |
2864 debug_printf("state change: %d\n", state); | |
2865 } | |
2866 return; | |
2867 } | |
2868 | |
2869 /* | |
2870 * Like jabber_login(), only different | |
2871 */ | |
2872 void jabber_register_user(struct aim_user *au) | |
2873 { | |
2874 struct gaim_connection *gc = new_gaim_conn(au); | |
2875 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); | |
2876 char *loginname = create_valid_jid(au->username, DEFAULT_SERVER, "GAIM"); | |
2877 | |
2878 /* | |
2879 * These do nothing during registration | |
2880 */ | |
2881 jd->hash = NULL; | |
2882 jd->chats = NULL; | |
2883 | |
2884 if ((jd->gjc = gjab_new(loginname, au->password, gc)) == NULL) { | |
2885 g_free(loginname); | |
2886 debug_printf("jabber: unable to connect (jab_new failed)\n"); | |
2887 hide_login_progress(gc, "Unable to connect"); | |
2888 signoff(gc); | |
2889 } else { | |
2890 gjab_state_handler(jd->gjc, jabber_handle_registration_state); | |
2891 gjab_packet_handler(jd->gjc, jabber_handleregresp); | |
2892 jd->gjc->queries = NULL; | |
2893 gjab_start(jd->gjc); | |
2894 } | |
2895 | |
2896 g_free(loginname); | |
2897 } | |
2898 | |
2899 /*----------------------------------------*/ | |
2900 /* End Jabber "user registration" support */ | |
2901 /*----------------------------------------*/ | |
2902 | |
2903 static void jabber_do_action(struct gaim_connection *gc, char *act) | |
2904 { | |
2905 if (!strcmp(act, "Set User Info")) { | |
2906 jabber_setup_set_info(gc); | |
2907 /* | |
2908 } else if (!strcmp(act, "Set Dir Info")) { | |
2909 show_set_dir(gc); | |
2910 } else if (!strcmp(act, "Change Password")) { | |
2911 show_change_passwd(gc); | |
2912 */ | |
2913 } | |
2914 } | |
2915 | |
2916 static GList *jabber_actions() | |
2917 { | |
2918 GList *m = NULL; | |
2919 | |
2920 m = g_list_append(m, "Set User Info"); | |
2921 /* | |
2922 m = g_list_append(m, "Set Dir Info"); | |
2923 m = g_list_append(m, "Change Password"); | |
2924 */ | |
2925 | |
2926 return m; | |
2927 } | |
2928 | |
2086 | 2929 static struct prpl *my_protocol = NULL; |
2930 | |
2931 void jabber_init(struct prpl *ret) | |
2932 { | |
2933 /* the NULL's aren't required but they're nice to have */ | |
2934 ret->protocol = PROTO_JABBER; | |
2935 ret->options = OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_CHAT_TOPIC; | |
2936 ret->name = jabber_name; | |
2937 ret->list_icon = jabber_list_icon; | |
2938 ret->away_states = jabber_away_states; | |
2956 | 2939 ret->actions = jabber_actions; |
2940 ret->do_action = jabber_do_action; | |
2086 | 2941 ret->buddy_menu = jabber_buddy_menu; |
2942 ret->user_opts = jabber_user_opts; | |
2943 ret->login = jabber_login; | |
2944 ret->close = jabber_close; | |
2945 ret->send_im = jabber_send_im; | |
2956 | 2946 ret->set_info = jabber_set_info; |
2086 | 2947 ret->get_info = jabber_get_info; |
2956 | 2948 ret->get_cb_info = jabber_get_cb_info; |
2949 ret->get_cb_away = jabber_get_cb_away_msg; | |
2086 | 2950 ret->set_away = jabber_set_away; |
2951 ret->set_dir = NULL; | |
2952 ret->get_dir = NULL; | |
2953 ret->dir_search = NULL; | |
2954 ret->set_idle = jabber_set_idle; | |
2955 ret->change_passwd = NULL; | |
2956 ret->add_buddy = jabber_add_buddy; | |
2957 ret->add_buddies = NULL; | |
2958 ret->remove_buddy = jabber_remove_buddy; | |
2959 ret->add_permit = NULL; | |
2960 ret->add_deny = NULL; | |
2961 ret->rem_permit = NULL; | |
2962 ret->rem_deny = NULL; | |
2963 ret->set_permit_deny = NULL; | |
2964 ret->warn = NULL; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2965 ret->chat_info = jabber_chat_info; |
2086 | 2966 ret->join_chat = jabber_join_chat; |
2967 ret->chat_invite = jabber_chat_invite; | |
2968 ret->chat_leave = jabber_chat_leave; | |
2969 ret->chat_whisper = jabber_chat_whisper; | |
2970 ret->chat_send = jabber_chat_send; | |
2971 ret->keepalive = jabber_keepalive; | |
2972 ret->normalize = jabber_normalize; | |
2607
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
2973 ret->buddy_free = jabber_buddy_free; |
2956 | 2974 ret->register_user = jabber_register_user; |
2086 | 2975 |
2976 my_protocol = ret; | |
2977 } | |
2978 | |
2979 #ifndef STATIC | |
2980 | |
2981 char *gaim_plugin_init(GModule *handle) | |
2982 { | |
2983 load_protocol(jabber_init, sizeof(struct prpl)); | |
2984 return NULL; | |
2985 } | |
2986 | |
2987 void gaim_plugin_remove() | |
2988 { | |
2989 struct prpl *p = find_prpl(PROTO_JABBER); | |
2990 if (p == my_protocol) | |
2991 unload_protocol(p); | |
2992 } | |
2993 | |
2994 char *name() | |
2995 { | |
2996 return "Jabber"; | |
2997 } | |
2998 | |
2999 char *description() | |
3000 { | |
2162
a464da684307
[gaim-migrate @ 2172]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2154
diff
changeset
|
3001 return PRPL_DESC("Jabber"); |
2086 | 3002 } |
3003 | |
3004 #endif |