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