Mercurial > pidgin.yaz
annotate src/protocols/jabber/jabber.c @ 2231:8c4ff1a368bd
[gaim-migrate @ 2241]
blue:~/gaim/app/src/protocols $ ./gtk
icq: 0
irc: 0
jabber: 52
msn: 0
napster: 0
oscar: 7
toc: 17
yahoo: 0
zephyr: 1
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 07 Sep 2001 08:09:22 +0000 |
parents | cff4fbe01c7b |
children | 14e8978f86bb |
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 <gtk/gtk.h> | |
30 #ifdef MAX | |
31 #undef MAX | |
32 #endif | |
33 #ifdef MIN | |
34 #undef MIN | |
35 #endif | |
36 #include <netdb.h> | |
37 #include <unistd.h> | |
38 #include <errno.h> | |
39 #include <netinet/in.h> | |
40 #include <arpa/inet.h> | |
41 #include <string.h> | |
42 #include <stdlib.h> | |
43 #include <stdio.h> | |
44 #include <time.h> | |
45 #include <sys/socket.h> | |
46 #include <sys/utsname.h> | |
47 #include <sys/stat.h> | |
48 #include "multi.h" | |
49 #include "prpl.h" | |
50 #include "gaim.h" | |
51 #include "jabber.h" | |
52 #include "proxy.h" | |
53 | |
54 #include "pixmaps/available.xpm" | |
55 #include "pixmaps/available-away.xpm" | |
56 #include "pixmaps/available-chat.xpm" | |
57 #include "pixmaps/available-xa.xpm" | |
58 #include "pixmaps/available-dnd.xpm" | |
59 | |
60 /* The priv member of gjconn's is a gaim_connection for now. */ | |
61 #define GJ_GC(x) ((struct gaim_connection *)(x)->priv) | |
62 | |
63 #define IQID_AUTH "__AUTH__" | |
64 | |
65 #define IQ_NONE -1 | |
66 #define IQ_AUTH 0 | |
67 #define IQ_ROSTER 1 | |
68 | |
69 #define UC_AWAY 0x38 | |
70 #define UC_CHAT 0x48 | |
71 #define UC_XA 0x98 | |
72 #define UC_DND 0x118 | |
73 | |
74 #define DEFAULT_SERVER "jabber.org" | |
75 #define DEFAULT_GROUPCHAT "conference.jabber.org" | |
76 #define DEFAULT_PORT 5222 | |
77 | |
78 #define USEROPT_PORT 0 | |
79 | |
80 typedef struct gjconn_struct { | |
81 /* Core structure */ | |
82 pool p; /* Memory allocation pool */ | |
83 int state; /* Connection state flag */ | |
84 int fd; /* Connection file descriptor */ | |
85 jid user; /* User info */ | |
86 char *pass; /* User passwd */ | |
87 | |
88 /* Stream stuff */ | |
89 int id; /* id counter for jab_getid() function */ | |
90 char idbuf[9]; /* temporary storage for jab_getid() */ | |
91 char *sid; /* stream id from server, for digest auth */ | |
92 XML_Parser parser; /* Parser instance */ | |
93 xmlnode current; /* Current node in parsing instance.. */ | |
94 | |
95 /* Event callback ptrs */ | |
96 void (*on_state)(struct gjconn_struct *j, int state); | |
97 void (*on_packet)(struct gjconn_struct *j, jpacket p); | |
98 | |
99 void *priv; | |
100 | |
101 } *gjconn, gjconn_struct; | |
102 | |
103 typedef void (*gjconn_state_h)(gjconn j, int state); | |
104 typedef void (*gjconn_packet_h)(gjconn j, jpacket p); | |
105 | |
106 static gjconn gjab_new(char *user, char *pass, void *priv); | |
107 static void gjab_delete(gjconn j); | |
108 static void gjab_state_handler(gjconn j, gjconn_state_h h); | |
109 static void gjab_packet_handler(gjconn j, gjconn_packet_h h); | |
110 static void gjab_start(gjconn j); | |
111 static void gjab_stop(gjconn j); | |
112 /* | |
113 static int gjab_getfd(gjconn j); | |
114 static jid gjab_getjid(gjconn j); | |
115 static char *gjab_getsid(gjconn j); | |
116 */ | |
117 static char *gjab_getid(gjconn j); | |
118 static void gjab_send(gjconn j, xmlnode x); | |
119 static void gjab_send_raw(gjconn j, const char *str); | |
120 static void gjab_recv(gjconn j); | |
121 static void gjab_auth(gjconn j); | |
122 | |
123 struct jabber_data { | |
124 gjconn jc; | |
125 gboolean did_import; | |
126 GSList *pending_chats; | |
127 GSList *existing_chats; | |
128 GHashTable *hash; | |
129 time_t idle; | |
130 }; | |
131 | |
132 struct jabber_chat { | |
133 jid Jid; | |
134 struct gaim_connection *gc; | |
135 struct conversation *b; | |
136 int id; | |
137 }; | |
138 | |
139 static char *jabber_name() | |
140 { | |
141 return "Jabber"; | |
142 } | |
143 | |
144 #define STATE_EVT(arg) if(j->on_state) { (j->on_state)(j, (arg) ); } | |
145 | |
146 static char *create_valid_jid(const char *given, char *server, char *resource) | |
147 { | |
148 char *valid; | |
149 | |
150 if (!strchr(given, '@')) | |
151 valid = g_strdup_printf("%s@%s/%s", given, server, resource); | |
152 else if (!strchr(strchr(given, '@'), '/')) | |
153 valid = g_strdup_printf("%s/%s", given, resource); | |
154 else | |
155 valid = g_strdup(given); | |
156 | |
157 return valid; | |
158 } | |
159 | |
160 static gjconn gjab_new(char *user, char *pass, void *priv) | |
161 { | |
162 pool p; | |
163 gjconn j; | |
164 | |
165 if (!user) | |
166 return (NULL); | |
167 | |
168 p = pool_new(); | |
169 if (!p) | |
170 return (NULL); | |
171 j = pmalloc_x(p, sizeof(gjconn_struct), 0); | |
172 if (!j) | |
173 return (NULL); | |
174 j->p = p; | |
175 | |
176 j->user = jid_new(p, user); | |
177 j->pass = pstrdup(p, pass); | |
178 | |
179 j->state = JCONN_STATE_OFF; | |
180 j->id = 1; | |
181 j->fd = -1; | |
182 | |
183 j->priv = priv; | |
184 | |
185 return j; | |
186 } | |
187 | |
188 static void gjab_delete(gjconn j) | |
189 { | |
190 if (!j) | |
191 return; | |
192 | |
193 gjab_stop(j); | |
194 pool_free(j->p); | |
195 } | |
196 | |
197 static void gjab_state_handler(gjconn j, gjconn_state_h h) | |
198 { | |
199 if (!j) | |
200 return; | |
201 | |
202 j->on_state = h; | |
203 } | |
204 | |
205 static void gjab_packet_handler(gjconn j, gjconn_packet_h h) | |
206 { | |
207 if (!j) | |
208 return; | |
209 | |
210 j->on_packet = h; | |
211 } | |
212 | |
213 static void gjab_stop(gjconn j) | |
214 { | |
215 if (!j || j->state == JCONN_STATE_OFF) | |
216 return; | |
217 | |
218 j->state = JCONN_STATE_OFF; | |
219 gjab_send_raw(j, "</stream:stream>"); | |
220 close(j->fd); | |
221 j->fd = -1; | |
222 XML_ParserFree(j->parser); | |
223 j->parser = NULL; | |
224 } | |
225 | |
226 /* | |
227 static int gjab_getfd(gjconn j) | |
228 { | |
229 if (j) | |
230 return j->fd; | |
231 else | |
232 return -1; | |
233 } | |
234 | |
235 static jid gjab_getjid(gjconn j) | |
236 { | |
237 if (j) | |
238 return (j->user); | |
239 else | |
240 return NULL; | |
241 } | |
242 | |
243 static char *gjab_getsid(gjconn j) | |
244 { | |
245 if (j) | |
246 return (j->sid); | |
247 else | |
248 return NULL; | |
249 } | |
250 */ | |
251 | |
252 static char *gjab_getid(gjconn j) | |
253 { | |
254 snprintf(j->idbuf, 8, "%d", j->id++); | |
255 return &j->idbuf[0]; | |
256 } | |
257 | |
258 static void gjab_send(gjconn j, xmlnode x) | |
259 { | |
260 if (j && j->state != JCONN_STATE_OFF) { | |
261 char *buf = xmlnode2str(x); | |
262 if (buf) | |
263 write(j->fd, buf, strlen(buf)); | |
264 debug_printf("gjab_send: %s\n", buf); | |
265 } | |
266 } | |
267 | |
268 static void gjab_send_raw(gjconn j, const char *str) | |
269 { | |
270 if (j && j->state != JCONN_STATE_OFF) { | |
271 write(j->fd, str, strlen(str)); | |
272 debug_printf("gjab_send_raw: %s\n", str); | |
273 } | |
274 } | |
275 | |
276 static void gjab_reqroster(gjconn j) | |
277 { | |
278 xmlnode x; | |
279 | |
280 x = jutil_iqnew(JPACKET__GET, NS_ROSTER); | |
281 xmlnode_put_attrib(x, "id", gjab_getid(j)); | |
282 | |
283 gjab_send(j, x); | |
284 xmlnode_free(x); | |
285 } | |
286 | |
287 static void gjab_auth(gjconn j) | |
288 { | |
289 xmlnode x, y, z; | |
290 char *hash, *user; | |
291 | |
292 if (!j) | |
293 return; | |
294 | |
295 x = jutil_iqnew(JPACKET__SET, NS_AUTH); | |
296 xmlnode_put_attrib(x, "id", IQID_AUTH); | |
297 y = xmlnode_get_tag(x, "query"); | |
298 | |
299 user = j->user->user; | |
300 | |
301 if (user) { | |
302 z = xmlnode_insert_tag(y, "username"); | |
303 xmlnode_insert_cdata(z, user, -1); | |
304 } | |
305 | |
306 z = xmlnode_insert_tag(y, "resource"); | |
307 xmlnode_insert_cdata(z, j->user->resource, -1); | |
308 | |
309 if (j->sid) { | |
310 z = xmlnode_insert_tag(y, "digest"); | |
311 hash = pmalloc(x->p, strlen(j->sid) + strlen(j->pass) + 1); | |
312 strcpy(hash, j->sid); | |
313 strcat(hash, j->pass); | |
314 hash = shahash(hash); | |
315 xmlnode_insert_cdata(z, hash, 40); | |
316 } else { | |
317 z = xmlnode_insert_tag(y, "password"); | |
318 xmlnode_insert_cdata(z, j->pass, -1); | |
319 } | |
320 | |
321 gjab_send(j, x); | |
322 xmlnode_free(x); | |
323 | |
324 return; | |
325 } | |
326 | |
327 static void gjab_recv(gjconn j) | |
328 { | |
329 static char buf[4096]; | |
330 int len; | |
331 | |
332 if (!j || j->state == JCONN_STATE_OFF) | |
333 return; | |
334 | |
335 if ((len = read(j->fd, buf, sizeof(buf) - 1))) { | |
336 buf[len] = '\0'; | |
337 debug_printf("input (len %d): %s\n", len, buf); | |
338 XML_Parse(j->parser, buf, len, 0); | |
339 } else if (len <= 0) { | |
340 STATE_EVT(JCONN_STATE_OFF) | |
341 } | |
342 } | |
343 | |
344 static void startElement(void *userdata, const char *name, const char **attribs) | |
345 { | |
346 xmlnode x; | |
347 gjconn j = (gjconn) userdata; | |
348 | |
349 if (j->current) { | |
350 /* Append the node to the current one */ | |
351 x = xmlnode_insert_tag(j->current, name); | |
352 xmlnode_put_expat_attribs(x, attribs); | |
353 | |
354 j->current = x; | |
355 } else { | |
356 x = xmlnode_new_tag(name); | |
357 xmlnode_put_expat_attribs(x, attribs); | |
358 if (strcmp(name, "stream:stream") == 0) { | |
359 /* special case: name == stream:stream */ | |
360 /* id attrib of stream is stored for digest auth */ | |
361 j->sid = xmlnode_get_attrib(x, "id"); | |
362 /* STATE_EVT(JCONN_STATE_AUTH) */ | |
363 } else { | |
364 j->current = x; | |
365 } | |
366 } | |
367 } | |
368 | |
369 static void endElement(void *userdata, const char *name) | |
370 { | |
371 gjconn j = (gjconn) userdata; | |
372 xmlnode x; | |
373 jpacket p; | |
374 | |
375 if (j->current == NULL) { | |
376 /* we got </stream:stream> */ | |
377 STATE_EVT(JCONN_STATE_OFF) | |
378 return; | |
379 } | |
380 | |
381 x = xmlnode_get_parent(j->current); | |
382 | |
383 if (!x) { | |
384 /* it is time to fire the event */ | |
385 p = jpacket_new(j->current); | |
386 | |
387 if (j->on_packet) | |
388 (j->on_packet) (j, p); | |
389 else | |
390 xmlnode_free(j->current); | |
391 } | |
392 | |
393 j->current = x; | |
394 } | |
395 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
396 static void jabber_callback(gpointer data, gint source, GaimInputCondition condition) |
2086 | 397 { |
398 struct gaim_connection *gc = (struct gaim_connection *)data; | |
399 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; | |
400 | |
401 gjab_recv(jd->jc); | |
402 } | |
403 | |
404 static void charData(void *userdata, const char *s, int slen) | |
405 { | |
406 gjconn j = (gjconn) userdata; | |
407 | |
408 if (j->current) | |
409 xmlnode_insert_cdata(j->current, s, slen); | |
410 } | |
411 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
412 static void gjab_connected(gpointer data, gint source, GaimInputCondition cond) |
2086 | 413 { |
414 xmlnode x; | |
415 char *t, *t2; | |
416 struct gaim_connection *gc = data; | |
417 struct jabber_data *jd; | |
418 gjconn j; | |
419 | |
420 if (!g_slist_find(connections, gc)) { | |
421 close(source); | |
422 return; | |
423 } | |
424 | |
425 jd = gc->proto_data; | |
426 j = jd->jc; | |
427 | |
428 if (source == -1) { | |
429 STATE_EVT(JCONN_STATE_OFF) | |
430 return; | |
431 } | |
432 | |
433 if (j->fd != source) | |
434 j->fd = source; | |
435 | |
436 j->state = JCONN_STATE_CONNECTED; | |
437 STATE_EVT(JCONN_STATE_CONNECTED) | |
438 | |
439 /* start stream */ | |
440 x = jutil_header(NS_CLIENT, j->user->server); | |
441 t = xmlnode2str(x); | |
442 /* this is ugly, we can create the string here instead of jutil_header */ | |
443 /* what do you think about it? -madcat */ | |
444 t2 = strstr(t, "/>"); | |
445 *t2++ = '>'; | |
446 *t2 = '\0'; | |
447 gjab_send_raw(j, "<?xml version='1.0'?>"); | |
448 gjab_send_raw(j, t); | |
449 xmlnode_free(x); | |
450 | |
451 j->state = JCONN_STATE_ON; | |
452 STATE_EVT(JCONN_STATE_ON); | |
453 | |
454 gc = GJ_GC(j); | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
455 gc->inpa = gaim_input_add(j->fd, GAIM_INPUT_READ, jabber_callback, gc); |
2086 | 456 } |
457 | |
458 static void gjab_start(gjconn j) | |
459 { | |
460 struct aim_user *user; | |
461 int port; | |
462 | |
463 if (!j || j->state != JCONN_STATE_OFF) | |
464 return; | |
465 | |
466 user = GJ_GC(j)->user; | |
467 port = user->proto_opt[USEROPT_PORT][0] ? atoi(user->proto_opt[USEROPT_PORT]) : DEFAULT_PORT; | |
468 | |
469 j->parser = XML_ParserCreate(NULL); | |
470 XML_SetUserData(j->parser, (void *)j); | |
471 XML_SetElementHandler(j->parser, startElement, endElement); | |
472 XML_SetCharacterDataHandler(j->parser, charData); | |
473 | |
474 j->fd = proxy_connect(j->user->server, port, gjab_connected, GJ_GC(j)); | |
475 if (!user->gc || (j->fd < 0)) { | |
476 STATE_EVT(JCONN_STATE_OFF) | |
477 return; | |
478 } | |
479 } | |
480 | |
481 static struct conversation *find_chat(struct gaim_connection *gc, char *name) | |
482 { | |
483 GSList *bcs = gc->buddy_chats; | |
484 struct conversation *b = NULL; | |
485 char *chat = g_strdup(normalize(name)); | |
486 | |
487 while (bcs) { | |
488 b = bcs->data; | |
489 if (!strcasecmp(normalize(b->name), chat)) | |
490 break; | |
491 b = NULL; | |
492 bcs = bcs->next; | |
493 } | |
494 | |
495 g_free(chat); | |
496 return b; | |
497 } | |
498 | |
499 static struct jabber_chat *find_existing_chat(struct gaim_connection *gc, jid chat) | |
500 { | |
501 GSList *bcs = ((struct jabber_data *)gc->proto_data)->existing_chats; | |
502 struct jabber_chat *jc = NULL; | |
503 | |
504 while (bcs) { | |
505 jc = bcs->data; | |
506 if (!jid_cmpx(chat, jc->Jid, JID_USER | JID_SERVER)) | |
507 break; | |
508 jc = NULL; | |
509 bcs = bcs->next; | |
510 } | |
511 | |
512 return jc; | |
513 } | |
514 | |
515 static struct jabber_chat *find_pending_chat(struct gaim_connection *gc, jid chat) | |
516 { | |
517 GSList *bcs = ((struct jabber_data *)gc->proto_data)->pending_chats; | |
518 struct jabber_chat *jc = NULL; | |
519 | |
520 while (bcs) { | |
521 jc = bcs->data; | |
522 if (!jid_cmpx(chat, jc->Jid, JID_USER | JID_SERVER)) | |
523 break; | |
524 jc = NULL; | |
525 bcs = bcs->next; | |
526 } | |
527 | |
528 return jc; | |
529 } | |
530 | |
531 static gboolean find_chat_buddy(struct conversation *b, char *name) | |
532 { | |
533 GList *m = b->in_room; | |
534 | |
535 while (m) { | |
536 if (!strcmp(m->data, name)) | |
537 return TRUE; | |
538 m = m->next; | |
539 } | |
540 | |
541 return FALSE; | |
542 } | |
543 | |
544 static void jabber_handlemessage(gjconn j, jpacket p) | |
545 { | |
546 xmlnode y, xmlns, subj; | |
547 | |
548 char *from = NULL, *msg = NULL, *type = NULL, *topic = NULL; | |
549 char m[BUF_LONG * 2]; | |
550 | |
551 type = xmlnode_get_attrib(p->x, "type"); | |
552 | |
553 if (!type || !strcasecmp(type, "normal") || !strcasecmp(type, "chat")) { | |
554 | |
555 /* XXX namespaces could be handled better. (mid) */ | |
556 if ((xmlns = xmlnode_get_tag(p->x, "x"))) | |
557 type = xmlnode_get_attrib(xmlns, "xmlns"); | |
558 | |
559 from = jid_full(p->from); | |
560 /* | |
561 if ((y = xmlnode_get_tag(p->x, "html"))) { | |
562 msg = xmlnode_get_data(y); | |
563 } else | |
564 */ | |
565 if ((y = xmlnode_get_tag(p->x, "body"))) { | |
566 msg = xmlnode_get_data(y); | |
567 } | |
568 | |
569 msg = utf8_to_str(msg); | |
570 | |
571 if (!from) | |
572 return; | |
573 | |
574 if (type && !strcasecmp(type, "jabber:x:conference")) { | |
575 char *room; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
576 GList *m = NULL; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
577 char **data; |
2086 | 578 |
579 room = xmlnode_get_attrib(xmlns, "jid"); | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
580 data = g_strsplit(room, "@", 2); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
581 m = g_list_append(m, g_strdup(data[0])); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
582 m = g_list_append(m, g_strdup(data[1])); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
583 m = g_list_append(m, g_strdup(j->user->user)); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
584 g_strfreev(data); |
2086 | 585 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
586 serv_got_chat_invite(GJ_GC(j), room, from, msg, m); |
2086 | 587 } else if (msg) { /* whisper */ |
588 struct jabber_chat *jc; | |
589 g_snprintf(m, sizeof(m), "%s", msg); | |
590 if (((jc = find_existing_chat(GJ_GC(j), p->from)) != NULL) && jc->b) | |
591 serv_got_chat_in(GJ_GC(j), jc->b->id, p->from->resource, 1, m, time(NULL)); | |
592 else { | |
593 if (find_conversation(jid_full(p->from))) | |
594 serv_got_im(GJ_GC(j), jid_full(p->from), m, 0, time(NULL)); | |
595 else { | |
596 from = g_strdup_printf("%s@%s", p->from->user, p->from->server); | |
597 serv_got_im(GJ_GC(j), from, m, 0, time(NULL)); | |
598 g_free(from); | |
599 } | |
600 } | |
601 } | |
602 | |
603 if (msg) | |
604 g_free(msg); | |
605 | |
606 } else if (!strcasecmp(type, "error")) { | |
607 if ((y = xmlnode_get_tag(p->x, "error"))) { | |
608 type = xmlnode_get_attrib(y, "code"); | |
609 msg = xmlnode_get_data(y); | |
610 } | |
611 | |
612 if (msg) { | |
613 from = g_strdup_printf("Error %s", type ? type : ""); | |
614 do_error_dialog(msg, from); | |
615 g_free(from); | |
616 } | |
617 } else if (!strcasecmp(type, "groupchat")) { | |
618 struct jabber_chat *jc; | |
619 static int i = 0; | |
620 | |
621 /* | |
622 if ((y = xmlnode_get_tag(p->x, "html"))) { | |
623 msg = xmlnode_get_data(y); | |
624 } else | |
625 */ | |
626 if ((y = xmlnode_get_tag(p->x, "body"))) { | |
627 msg = xmlnode_get_data(y); | |
628 } | |
629 | |
630 msg = utf8_to_str(msg); | |
631 | |
632 if ((subj = xmlnode_get_tag(p->x, "subject"))) { | |
633 topic = xmlnode_get_data(subj); | |
634 } | |
635 topic = utf8_to_str(topic); | |
636 | |
637 jc = find_existing_chat(GJ_GC(j), p->from); | |
638 if (!jc) { | |
639 /* we're not in this chat. are we supposed to be? */ | |
640 struct jabber_data *jd = GJ_GC(j)->proto_data; | |
641 if ((jc = find_pending_chat(GJ_GC(j), p->from)) != NULL) { | |
642 /* yes, we're supposed to be. so now we are. */ | |
643 jc->b = serv_got_joined_chat(GJ_GC(j), i++, p->from->user); | |
644 jc->id = jc->b->id; | |
645 jd->existing_chats = g_slist_append(jd->existing_chats, jc); | |
646 jd->pending_chats = g_slist_remove(jd->pending_chats, jc); | |
647 } else { | |
648 /* no, we're not supposed to be. */ | |
649 g_free(msg); | |
650 return; | |
651 } | |
652 } | |
653 if (p->from->resource) { | |
654 if (!y) { | |
655 if (!find_chat_buddy(jc->b, p->from->resource)) | |
656 add_chat_buddy(jc->b, p->from->resource); | |
657 else if ((y = xmlnode_get_tag(p->x, "status"))) { | |
658 char buf[8192]; | |
659 msg = xmlnode_get_data(y); | |
660 g_snprintf(buf, sizeof(buf), "%s now has status: %s", | |
661 p->from->resource, msg); | |
662 write_to_conv(jc->b, buf, WFLAG_SYSTEM, NULL, time(NULL)); | |
663 } | |
664 } else if (jc->b && msg) { | |
665 char buf[8192]; | |
666 | |
667 if (topic) { | |
668 char tbuf[8192]; | |
669 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); | |
670 chat_set_topic(jc->b, p->from->resource, tbuf); | |
671 } | |
672 | |
673 | |
674 g_snprintf(buf, sizeof(buf), "%s", msg); | |
675 serv_got_chat_in(GJ_GC(j), jc->b->id, p->from->resource, 0, buf, time(NULL)); | |
676 } | |
677 } else { /* message from the server */ | |
678 if(jc->b && topic) { | |
679 char tbuf[8192]; | |
680 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); | |
681 chat_set_topic(jc->b, "", tbuf); | |
682 } | |
683 } | |
684 | |
685 g_free(msg); | |
686 g_free(topic); | |
687 | |
688 } else { | |
689 debug_printf("unhandled message %s\n", type); | |
690 } | |
691 } | |
692 | |
693 static void jabber_handlepresence(gjconn j, jpacket p) | |
694 { | |
695 char *to, *from, *type; | |
696 struct buddy *b = NULL; | |
697 jid who; | |
698 char *buddy; | |
699 xmlnode y; | |
700 char *show; | |
701 int state = UC_NORMAL; | |
702 GSList *resources; | |
703 char *res; | |
704 struct conversation *cnv = NULL; | |
705 struct jabber_chat *jc = NULL; | |
706 | |
707 to = xmlnode_get_attrib(p->x, "to"); | |
708 from = xmlnode_get_attrib(p->x, "from"); | |
709 type = xmlnode_get_attrib(p->x, "type"); | |
710 | |
711 if ((y = xmlnode_get_tag(p->x, "show"))) { | |
712 show = xmlnode_get_data(y); | |
713 if (!show) { | |
714 state = UC_NORMAL; | |
715 } else if (!strcasecmp(show, "away")) { | |
716 state = UC_AWAY; | |
717 } else if (!strcasecmp(show, "chat")) { | |
718 state = UC_CHAT; | |
719 } else if (!strcasecmp(show, "xa")) { | |
720 state = UC_XA; | |
721 } else if (!strcasecmp(show, "dnd")) { | |
722 state = UC_DND; | |
723 } | |
724 } else { | |
725 state = UC_NORMAL; | |
726 } | |
727 | |
728 who = jid_new(j->p, from); | |
729 if (who->user == NULL) { | |
730 /* FIXME: transport */ | |
731 return; | |
732 } | |
733 | |
734 buddy = g_strdup_printf("%s@%s", who->user, who->server); | |
735 | |
736 /* um. we're going to check if it's a chat. if it isn't, and there are pending | |
737 * chats, create the chat. if there aren't pending chats, add the buddy. */ | |
738 if ((cnv = find_chat(GJ_GC(j), who->user)) == NULL) { | |
739 static int i = 0x70; | |
740 struct jabber_data *jd = GJ_GC(j)->proto_data; | |
741 if ((jc = find_pending_chat(GJ_GC(j), who)) != NULL) { | |
742 jc->b = cnv = serv_got_joined_chat(GJ_GC(j), i++, who->user); | |
743 jc->id = jc->b->id; | |
744 jd->existing_chats = g_slist_append(jd->existing_chats, jc); | |
745 jd->pending_chats = g_slist_remove(jd->pending_chats, jc); | |
746 } else if (!(b = find_buddy(GJ_GC(j), buddy))) { | |
747 b = add_buddy(GJ_GC(j), "Buddies", buddy, buddy); | |
748 do_export(GJ_GC(j)); | |
749 } | |
750 } | |
751 | |
752 if (!cnv) { | |
753 resources = b->proto_data; | |
754 res = who->resource; | |
755 if (res) | |
756 while (resources) { | |
757 if (!strcmp(res, resources->data)) | |
758 break; | |
759 resources = resources->next; | |
760 } | |
761 | |
762 if (type && (strcasecmp(type, "unavailable") == 0)) { | |
763 if (resources) { | |
764 g_free(resources->data); | |
765 b->proto_data = g_slist_remove(b->proto_data, resources->data); | |
766 } | |
767 if (!b->proto_data) { | |
768 serv_got_update(GJ_GC(j), buddy, 0, 0, 0, 0, 0, 0); | |
769 } | |
770 } else { | |
771 /* keep track of away msg same as yahoo plugin */ | |
772 struct jabber_data *jd = GJ_GC(j)->proto_data; | |
773 gpointer val = g_hash_table_lookup(jd->hash, b->name); | |
774 if (val) | |
775 g_free(val); | |
776 g_hash_table_insert(jd->hash, g_strdup(b->name), g_strdup(xmlnode_get_tag_data(p->x, "status"))); | |
777 | |
778 | |
779 if (!resources) { | |
780 b->proto_data = g_slist_append(b->proto_data, g_strdup(res)); | |
781 } | |
782 | |
783 serv_got_update(GJ_GC(j), buddy, 1, 0, 0, 0, state, 0); | |
784 | |
785 } | |
786 } else { | |
787 if (who->resource) { | |
788 if (type && !strcasecmp(type, "unavailable")) { | |
789 struct jabber_data *jd; | |
790 if (!jc && !(jc = find_existing_chat(GJ_GC(j), who))) { | |
791 g_free(buddy); | |
792 return; | |
793 } | |
794 jd = jc->gc->proto_data; | |
795 if (strcmp(who->resource, jc->Jid->resource) && jc->b) { | |
796 remove_chat_buddy(jc->b, who->resource); | |
797 return; | |
798 } | |
799 | |
800 jd->existing_chats = g_slist_remove(jd->existing_chats, jc); | |
801 serv_got_chat_left(GJ_GC(j), jc->id); | |
802 g_free(jc); | |
803 } else { | |
804 if ((!jc && !(jc = find_existing_chat(GJ_GC(j), who))) || !jc->b) { | |
805 g_free(buddy); | |
806 return; | |
807 } | |
808 if (!find_chat_buddy(jc->b, who->resource)) | |
809 add_chat_buddy(jc->b, who->resource); | |
810 else if ((y = xmlnode_get_tag(p->x, "status"))) { | |
811 char buf[8192]; | |
812 char *msg = xmlnode_get_data(y); | |
813 g_snprintf(buf, sizeof(buf), "%s now has status: %s", | |
814 p->from->resource, msg); | |
815 write_to_conv(jc->b, buf, WFLAG_SYSTEM, NULL, time(NULL)); | |
816 } | |
817 } | |
818 } | |
819 } | |
820 | |
821 g_free(buddy); | |
822 | |
823 return; | |
824 } | |
825 | |
826 static void jabber_handles10n(gjconn j, jpacket p) | |
827 { | |
828 xmlnode g; | |
829 char *Jid = xmlnode_get_attrib(p->x, "from"); | |
830 char *ask = xmlnode_get_attrib(p->x, "type"); | |
831 | |
832 g = xmlnode_new_tag("presence"); | |
833 xmlnode_put_attrib(g, "to", Jid); | |
834 if (!strcmp(ask, "subscribe")) | |
835 xmlnode_put_attrib(g, "type", "subscribed"); | |
836 else if (!strcmp(ask, "unsubscribe")) | |
837 xmlnode_put_attrib(g, "type", "unsubscribed"); | |
838 else | |
839 return; | |
840 | |
841 gjab_send(j, g); | |
842 } | |
843 | |
844 static void jabber_handleroster(gjconn j, xmlnode querynode) | |
845 { | |
846 xmlnode x; | |
847 | |
848 x = xmlnode_get_firstchild(querynode); | |
849 while (x) { | |
850 xmlnode g; | |
851 char *Jid, *name, *sub, *ask; | |
852 jid who; | |
853 | |
854 Jid = xmlnode_get_attrib(x, "jid"); | |
855 name = xmlnode_get_attrib(x, "name"); | |
856 sub = xmlnode_get_attrib(x, "subscription"); | |
857 ask = xmlnode_get_attrib(x, "ask"); | |
858 who = jid_new(j->p, Jid); | |
859 | |
860 if ((g = xmlnode_get_firstchild(x))) { | |
861 while (g) { | |
2112
0ad5f2cf6728
[gaim-migrate @ 2122]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2111
diff
changeset
|
862 if (xmlnode_get_name(g) && |
0ad5f2cf6728
[gaim-migrate @ 2122]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2111
diff
changeset
|
863 g_strncasecmp(xmlnode_get_name(g), "group", 5) == 0) { |
2086 | 864 struct buddy *b = NULL; |
865 char *groupname, *buddyname; | |
866 | |
2111
109669b3887e
[gaim-migrate @ 2121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
867 if (!who || !who->user) { |
2086 | 868 /* FIXME: transport */ |
869 g = xmlnode_get_nextsibling(g); | |
870 continue; | |
871 } | |
872 buddyname = g_strdup_printf("%s@%s", who->user, who->server); | |
873 groupname = xmlnode_get_data(xmlnode_get_firstchild(g)); | |
874 if (groupname == NULL) | |
875 groupname = "Buddies"; | |
876 if (strcasecmp(sub, "from") && strcasecmp(sub, "none") && | |
877 !(b = find_buddy(GJ_GC(j), buddyname))) { | |
878 debug_printf("adding buddy: %s\n", buddyname); | |
879 b = add_buddy(GJ_GC(j), groupname, buddyname, | |
880 name ? name : buddyname); | |
881 do_export(GJ_GC(j)); | |
882 /* | |
883 } else if (b) { | |
884 debug_printf("updating buddy: %s/%s\n", buddyname, name); | |
885 g_snprintf(b->name, sizeof(b->name), "%s", buddyname); | |
886 g_snprintf(b->show, sizeof(b->show), "%s", | |
887 name ? name : buddyname); | |
888 */ | |
889 } | |
890 g_free(buddyname); | |
891 } | |
892 g = xmlnode_get_nextsibling(g); | |
893 } | |
894 } else { | |
895 struct buddy *b; | |
896 char *buddyname; | |
897 | |
2111
109669b3887e
[gaim-migrate @ 2121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
898 if (!who || !who->user) { |
2086 | 899 /* FIXME: transport */ |
900 x = xmlnode_get_nextsibling(x); | |
901 continue; | |
902 } | |
903 buddyname = g_strdup_printf("%s@%s", who->user, who->server); | |
904 if (strcasecmp(sub, "from") && strcasecmp(sub, "none") && | |
905 !(b = find_buddy(GJ_GC(j), buddyname))) { | |
906 debug_printf("adding buddy: %s\n", buddyname); | |
907 b = add_buddy(GJ_GC(j), "Buddies", buddyname, name ? name : Jid); | |
908 do_export(GJ_GC(j)); | |
909 } | |
910 g_free(buddyname); | |
911 } | |
912 | |
913 x = xmlnode_get_nextsibling(x); | |
914 } | |
915 | |
916 x = jutil_presnew(0, NULL, "Online"); | |
917 gjab_send(j, x); | |
918 xmlnode_free(x); | |
919 } | |
920 | |
921 static void jabber_handlevcard(gjconn j, xmlnode querynode, char *from) { | |
922 char buf[1024]; | |
923 char *fn, *url, *email, *nickname, *status, *desc; | |
924 jid who; | |
925 char *buddy; | |
926 struct jabber_data *jd = GJ_GC(j)->proto_data; | |
927 int at = 0; | |
928 | |
929 who = jid_new(j->p, from); | |
930 buddy = g_strdup_printf("%s@%s", who->user, who->server); | |
931 | |
932 fn = xmlnode_get_tag_data(querynode, "FN"); | |
933 url = xmlnode_get_tag_data(querynode, "URL"); | |
934 email = xmlnode_get_tag_data(querynode, "EMAIL"); | |
935 nickname = xmlnode_get_tag_data(querynode, "NICKNAME"); | |
936 desc = xmlnode_get_tag_data(querynode, "DESC"); | |
937 status = g_hash_table_lookup(jd->hash, buddy); | |
938 if (!status) | |
939 status = "Online"; | |
940 | |
941 at = g_snprintf(buf, sizeof buf, "<B>Jabber ID:</B> %s<BR>", buddy); | |
942 if (fn) | |
943 at += g_snprintf(buf + at, sizeof(buf) - at, "<B>Full Name:</B> %s<BR>", fn); | |
944 if (nickname) | |
945 at += g_snprintf(buf + at, sizeof(buf) - at, "<B>Nickname:</B> %s<BR>", nickname); | |
946 if (url) | |
947 at += g_snprintf(buf + at, sizeof(buf) - at, "<B>URL:</B> <A HREF=\"%s\">%s</A><BR>", | |
948 url, url); | |
949 if (email) | |
950 at += g_snprintf(buf + at, sizeof(buf) - at, | |
951 "<B>Email:</B> <A HREF=\"mailto:%s\">%s</A><BR>", email, email); | |
952 at += g_snprintf(buf + at, sizeof(buf) - at, "<B>Status:</B> %s\n", status); | |
953 if (desc) | |
954 at += g_snprintf(buf + at, sizeof(buf) - at, "<HR>%s<br>\n", desc); | |
955 | |
2137
18722ae5b882
[gaim-migrate @ 2147]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2131
diff
changeset
|
956 g_show_info_text(buf, NULL); |
2086 | 957 g_free(buddy); |
958 } | |
959 | |
960 static void jabber_handleauthresp(gjconn j, jpacket p) | |
961 { | |
962 if (jpacket_subtype(p) == JPACKET__RESULT) { | |
963 debug_printf("auth success\n"); | |
964 | |
965 account_online(GJ_GC(j)); | |
966 serv_finish_login(GJ_GC(j)); | |
967 | |
968 if (bud_list_cache_exists(GJ_GC(j))) | |
969 do_import(NULL, GJ_GC(j)); | |
970 | |
971 ((struct jabber_data *)GJ_GC(j)->proto_data)->did_import = TRUE; | |
972 | |
973 gjab_reqroster(j); | |
974 } else { | |
975 xmlnode xerr; | |
976 char *errmsg = NULL; | |
977 int errcode = 0; | |
978 | |
979 debug_printf("auth failed\n"); | |
980 xerr = xmlnode_get_tag(p->x, "error"); | |
981 if (xerr) { | |
982 char msg[BUF_LONG]; | |
983 errmsg = xmlnode_get_data(xerr); | |
984 if (xmlnode_get_attrib(xerr, "code")) { | |
985 errcode = atoi(xmlnode_get_attrib(xerr, "code")); | |
986 g_snprintf(msg, sizeof(msg), "Error %d: %s", errcode, errmsg); | |
987 } else | |
988 g_snprintf(msg, sizeof(msg), "%s", errmsg); | |
989 hide_login_progress(GJ_GC(j), msg); | |
990 } else { | |
991 hide_login_progress(GJ_GC(j), "Unknown login error"); | |
992 } | |
993 | |
994 signoff(GJ_GC(j)); | |
995 } | |
996 } | |
997 | |
998 static void jabber_handleversion(gjconn j, xmlnode iqnode) { | |
999 xmlnode querynode, x; | |
1000 char *id, *from; | |
1001 char os[1024]; | |
1002 struct utsname osinfo; | |
1003 | |
1004 uname(&osinfo); | |
1005 g_snprintf(os, sizeof os, "%s %s %s", osinfo.sysname, osinfo.release, osinfo.machine); | |
1006 | |
1007 id = xmlnode_get_attrib(iqnode, "id"); | |
1008 from = xmlnode_get_attrib(iqnode, "from"); | |
1009 | |
1010 x = jutil_iqnew(JPACKET__RESULT, NS_VERSION); | |
1011 | |
1012 xmlnode_put_attrib(x, "to", from); | |
1013 xmlnode_put_attrib(x, "id", id); | |
1014 querynode = xmlnode_get_tag(x, "query"); | |
1015 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "name"), PACKAGE, -1); | |
1016 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "version"), VERSION, -1); | |
1017 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "os"), os, -1); | |
1018 | |
1019 gjab_send(j, x); | |
1020 | |
1021 xmlnode_free(x); | |
1022 } | |
1023 | |
1024 static void jabber_handletime(gjconn j, xmlnode iqnode) { | |
1025 xmlnode querynode, x; | |
1026 char *id, *from; | |
1027 time_t now_t; | |
1028 struct tm *now; | |
1029 char buf[1024]; | |
1030 | |
1031 time(&now_t); | |
1032 now = localtime(&now_t); | |
1033 | |
1034 id = xmlnode_get_attrib(iqnode, "id"); | |
1035 from = xmlnode_get_attrib(iqnode, "from"); | |
1036 | |
1037 x = jutil_iqnew(JPACKET__RESULT, NS_TIME); | |
1038 | |
1039 xmlnode_put_attrib(x, "to", from); | |
1040 xmlnode_put_attrib(x, "id", id); | |
1041 querynode = xmlnode_get_tag(x, "query"); | |
1042 | |
1043 strftime(buf, 1024, "%Y%m%dT%T", now); | |
1044 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "utc"), buf, -1); | |
1045 strftime(buf, 1024, "%Z", now); | |
1046 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "tz"), buf, -1); | |
1047 strftime(buf, 1024, "%d %b %Y %T", now); | |
1048 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "display"), buf, -1); | |
1049 | |
1050 gjab_send(j, x); | |
1051 | |
1052 xmlnode_free(x); | |
1053 } | |
1054 | |
1055 static void jabber_handlelast(gjconn j, xmlnode iqnode) { | |
1056 xmlnode x, querytag; | |
1057 char *id, *from; | |
1058 struct jabber_data *jd = GJ_GC(j)->proto_data; | |
1059 char idle_time[32]; | |
1060 | |
1061 id = xmlnode_get_attrib(iqnode, "id"); | |
1062 from = xmlnode_get_attrib(iqnode, "from"); | |
1063 | |
1064 x = jutil_iqnew(JPACKET__RESULT, "jabber:iq:last"); | |
1065 | |
1066 xmlnode_put_attrib(x, "to", from); | |
1067 xmlnode_put_attrib(x, "id", id); | |
1068 querytag = xmlnode_get_tag(x, "query"); | |
1069 g_snprintf(idle_time, sizeof idle_time, "%ld", jd->idle ? time(NULL) - jd->idle : 0); | |
1070 xmlnode_put_attrib(querytag, "seconds", idle_time); | |
1071 | |
1072 gjab_send(j, x); | |
1073 xmlnode_free(x); | |
1074 } | |
1075 | |
1076 static void jabber_handlepacket(gjconn j, jpacket p) | |
1077 { | |
1078 switch (p->type) { | |
1079 case JPACKET_MESSAGE: | |
1080 jabber_handlemessage(j, p); | |
1081 break; | |
1082 case JPACKET_PRESENCE: | |
1083 jabber_handlepresence(j, p); | |
1084 break; | |
1085 case JPACKET_IQ: | |
1086 debug_printf("jpacket_subtype: %d\n", jpacket_subtype(p)); | |
1087 | |
1088 if (xmlnode_get_attrib(p->x, "id") && (strcmp(xmlnode_get_attrib(p->x, "id"), IQID_AUTH) == 0)) { | |
1089 jabber_handleauthresp(j, p); | |
1090 break; /* I'm not sure if you like this style, Eric. */ | |
1091 } | |
1092 | |
1093 if (jpacket_subtype(p) == JPACKET__SET) { | |
1094 } else if (jpacket_subtype(p) == JPACKET__GET) { | |
1095 xmlnode querynode; | |
1096 querynode = xmlnode_get_tag(p->x, "query"); | |
1097 if(NSCHECK(querynode, NS_VERSION)) { | |
1098 jabber_handleversion(j, p->x); | |
1099 } else if (NSCHECK(querynode, NS_TIME)) { | |
1100 jabber_handletime(j, p->x); | |
1101 } else if (NSCHECK(querynode, "jabber:iq:last")) { | |
1102 jabber_handlelast(j, p->x); | |
1103 } | |
1104 } else if (jpacket_subtype(p) == JPACKET__RESULT) { | |
1105 xmlnode querynode, vcard; | |
1106 char *xmlns, *from; | |
1107 | |
1108 from = xmlnode_get_attrib(p->x, "from"); | |
1109 querynode = xmlnode_get_tag(p->x, "query"); | |
1110 xmlns = xmlnode_get_attrib(querynode, "xmlns"); | |
1111 vcard = xmlnode_get_tag(p->x, "vCard"); | |
1112 | |
1113 if (NSCHECK(querynode, NS_ROSTER)) { | |
1114 jabber_handleroster(j, querynode); | |
1115 } else if (NSCHECK(querynode, NS_VCARD)) { | |
1116 jabber_handlevcard(j, querynode, from); | |
1117 } else if(vcard) { | |
1118 jabber_handlevcard(j, vcard, from); | |
1119 } else { | |
1120 /* debug_printf("jabber:iq:query: %s\n", xmlns); */ | |
1121 } | |
1122 | |
1123 } else if (jpacket_subtype(p) == JPACKET__ERROR) { | |
1124 xmlnode xerr; | |
1125 char *from, *errmsg = NULL; | |
1126 int errcode = 0; | |
1127 | |
1128 from = xmlnode_get_attrib(p->x, "from"); | |
1129 xerr = xmlnode_get_tag(p->x, "error"); | |
1130 if (xerr) { | |
1131 errmsg = xmlnode_get_data(xerr); | |
1132 if (xmlnode_get_attrib(xerr, "code")) | |
1133 errcode = atoi(xmlnode_get_attrib(xerr, "code")); | |
1134 } | |
1135 | |
1136 from = g_strdup_printf("Error %d (%s)", errcode, from); | |
1137 do_error_dialog(errmsg, from); | |
1138 g_free(from); | |
1139 | |
1140 } | |
1141 | |
1142 break; | |
1143 | |
1144 case JPACKET_S10N: | |
1145 jabber_handles10n(j, p); | |
1146 break; | |
1147 default: | |
1148 debug_printf("jabber: packet type %d (%s)\n", p->type, xmlnode2str(p->x)); | |
1149 } | |
1150 | |
1151 xmlnode_free(p->x); | |
1152 | |
1153 return; | |
1154 } | |
1155 | |
1156 static void jabber_handlestate(gjconn j, int state) | |
1157 { | |
1158 switch (state) { | |
1159 case JCONN_STATE_OFF: | |
1160 hide_login_progress(GJ_GC(j), "Unable to connect"); | |
1161 signoff(GJ_GC(j)); | |
1162 break; | |
1163 case JCONN_STATE_CONNECTED: | |
1164 set_login_progress(GJ_GC(j), 3, "Connected"); | |
1165 break; | |
1166 case JCONN_STATE_ON: | |
1167 set_login_progress(GJ_GC(j), 5, "Logging in..."); | |
1168 gjab_auth(j); | |
1169 break; | |
1170 default: | |
1171 debug_printf("state change: %d\n", state); | |
1172 } | |
1173 return; | |
1174 } | |
1175 | |
1176 static void jabber_login(struct aim_user *user) | |
1177 { | |
1178 struct gaim_connection *gc = new_gaim_conn(user); | |
1179 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); | |
1180 char *loginname = create_valid_jid(user->username, DEFAULT_SERVER, "GAIM"); | |
1181 | |
1182 jd->hash = g_hash_table_new(g_str_hash, g_str_equal); | |
1183 | |
1184 set_login_progress(gc, 1, "Connecting"); | |
1185 | |
1186 if (!(jd->jc = gjab_new(loginname, user->password, gc))) { | |
1187 g_free(loginname); | |
1188 debug_printf("jabber: unable to connect (jab_new failed)\n"); | |
1189 hide_login_progress(gc, "Unable to connect"); | |
1190 signoff(gc); | |
1191 return; | |
1192 } | |
1193 | |
1194 g_free(loginname); | |
1195 gjab_state_handler(jd->jc, jabber_handlestate); | |
1196 gjab_packet_handler(jd->jc, jabber_handlepacket); | |
1197 gjab_start(jd->jc); | |
1198 } | |
1199 | |
1200 static gboolean jabber_destroy_hash(gpointer key, gpointer val, gpointer data) { | |
1201 g_free(key); | |
1202 g_free(val); | |
1203 return TRUE; | |
1204 } | |
1205 | |
1206 static gboolean jabber_free(gpointer data) | |
1207 { | |
1208 gjab_delete(data); | |
1209 return FALSE; | |
1210 } | |
1211 | |
1212 static void jabber_close(struct gaim_connection *gc) | |
1213 { | |
1214 struct jabber_data *jd = gc->proto_data; | |
1215 g_hash_table_foreach_remove(jd->hash, jabber_destroy_hash, NULL); | |
1216 g_hash_table_destroy(jd->hash); | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1217 gaim_input_remove(gc->inpa); |
2086 | 1218 close(jd->jc->fd); |
2131
acc11216ec5d
[gaim-migrate @ 2141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
1219 g_timeout_add(50, jabber_free, jd->jc); |
2086 | 1220 jd->jc = NULL; |
1221 g_free(jd); | |
1222 gc->proto_data = NULL; | |
1223 } | |
1224 | |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
1225 static int jabber_send_im(struct gaim_connection *gc, char *who, char *message, int flags) |
2086 | 1226 { |
1227 xmlnode x, y; | |
1228 char *realwho; | |
1229 gjconn j = ((struct jabber_data *)gc->proto_data)->jc; | |
1230 | |
1231 if (!who || !message) | |
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2112
diff
changeset
|
1232 return 0; |
2086 | 1233 |
1234 x = xmlnode_new_tag("message"); | |
1235 if (!strchr(who, '@')) | |
1236 realwho = g_strdup_printf("%s@%s", who, j->user->server); | |
1237 else | |
1238 realwho = g_strdup(who); | |
1239 xmlnode_put_attrib(x, "to", realwho); | |
1240 g_free(realwho); | |
1241 | |
1242 xmlnode_put_attrib(x, "type", "chat"); | |
1243 | |
1244 if (message && strlen(message)) { | |
1245 char *utf8 = str_to_utf8(message); | |
1246 y = xmlnode_insert_tag(x, "body"); | |
1247 xmlnode_insert_cdata(y, utf8, -1); | |
1248 g_free(utf8); | |
1249 } | |
1250 | |
1251 gjab_send(((struct jabber_data *)gc->proto_data)->jc, x); | |
1252 xmlnode_free(x); | |
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2112
diff
changeset
|
1253 return 0; |
2086 | 1254 } |
1255 | |
1256 static void jabber_add_buddy(struct gaim_connection *gc, char *name) | |
1257 { | |
1258 xmlnode x, y; | |
1259 char *realwho; | |
1260 gjconn j = ((struct jabber_data *)gc->proto_data)->jc; | |
1261 | |
1262 if (!((struct jabber_data *)gc->proto_data)->did_import) | |
1263 return; | |
1264 | |
1265 if (!name) | |
1266 return; | |
1267 | |
1268 if (!strcmp(gc->username, name)) | |
1269 return; | |
1270 | |
1271 if (!strchr(name, '@')) | |
1272 realwho = g_strdup_printf("%s@%s", name, j->user->server); | |
1273 else { | |
1274 jid who = jid_new(j->p, name); | |
1275 if (who->user == NULL) { | |
1276 /* FIXME: transport */ | |
1277 return; | |
1278 } | |
1279 realwho = g_strdup_printf("%s@%s", who->user, who->server); | |
1280 } | |
1281 | |
1282 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); | |
1283 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); | |
1284 xmlnode_put_attrib(y, "jid", realwho); | |
1285 gjab_send(((struct jabber_data *)gc->proto_data)->jc, x); | |
1286 xmlnode_free(x); | |
1287 | |
1288 x = xmlnode_new_tag("presence"); | |
1289 xmlnode_put_attrib(x, "to", realwho); | |
1290 xmlnode_put_attrib(x, "type", "subscribe"); | |
1291 gjab_send(((struct jabber_data *)gc->proto_data)->jc, x); | |
1292 | |
1293 g_free(realwho); | |
1294 } | |
1295 | |
1296 static void jabber_remove_buddy(struct gaim_connection *gc, char *name) | |
1297 { | |
1298 xmlnode x, y; | |
1299 char *realwho; | |
1300 gjconn j = ((struct jabber_data *)gc->proto_data)->jc; | |
1301 | |
1302 if (!name) | |
1303 return; | |
1304 | |
1305 if (!strchr(name, '@')) | |
1306 realwho = g_strdup_printf("%s@%s", name, j->user->server); | |
1307 else | |
1308 realwho = g_strdup(name); | |
1309 | |
1310 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); | |
1311 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); | |
1312 xmlnode_put_attrib(y, "jid", realwho); | |
1313 xmlnode_put_attrib(y, "subscription", "remove"); | |
1314 gjab_send(((struct jabber_data *)gc->proto_data)->jc, x); | |
1315 | |
1316 g_free(realwho); | |
1317 xmlnode_free(x); | |
1318 } | |
1319 | |
1320 static char **jabber_list_icon(int uc) | |
1321 { | |
1322 switch (uc) { | |
1323 case UC_AWAY: | |
1324 return available_away_xpm; | |
1325 case UC_CHAT: | |
1326 return available_chat_xpm; | |
1327 case UC_XA: | |
1328 return available_xa_xpm; | |
1329 case UC_DND: | |
1330 return available_dnd_xpm; | |
1331 default: | |
1332 return available_xpm; | |
1333 } | |
1334 } | |
1335 | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1336 static GList *jabber_chat_info(struct gaim_connection *gc) |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1337 { |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1338 gjconn j = ((struct jabber_data *)gc->proto_data)->jc; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1339 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1340 GList *m = NULL; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1341 struct proto_chat_entry *pce; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1342 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1343 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1344 pce->label = _("Room:"); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1345 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1346 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1347 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1348 pce->label = _("Server:"); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1349 pce->def = DEFAULT_GROUPCHAT; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1350 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1351 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1352 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1353 pce->label = _("Handle:"); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1354 pce->def = j->user->user; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1355 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1356 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1357 return m; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1358 } |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1359 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1360 static void jabber_join_chat(struct gaim_connection *gc, GList *data) |
2086 | 1361 { |
1362 xmlnode x; | |
1363 char *realwho; | |
1364 gjconn j = ((struct jabber_data *)gc->proto_data)->jc; | |
1365 GSList *pc = ((struct jabber_data *)gc->proto_data)->pending_chats; | |
1366 struct jabber_chat *jc; | |
1367 | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1368 if (!data || !data->next || !data->next->next) |
2086 | 1369 return; |
1370 | |
1371 jc = g_new0(struct jabber_chat, 1); | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1372 realwho = create_valid_jid(data->data, data->next->data, |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1373 data->next->next->data); |
2086 | 1374 jc->Jid = jid_new(j->p, realwho); |
1375 jc->gc = gc; | |
1376 debug_printf("%s\n", realwho); | |
1377 | |
1378 x = jutil_presnew(0, realwho, NULL); | |
1379 gjab_send(j, x); | |
1380 xmlnode_free(x); | |
1381 g_free(realwho); | |
1382 | |
1383 ((struct jabber_data *)gc->proto_data)->pending_chats = g_slist_append(pc, jc); | |
1384 } | |
1385 | |
1386 static void jabber_chat_invite(struct gaim_connection *gc, int id, char *message, char *name) | |
1387 { | |
1388 xmlnode x, y; | |
1389 GSList *bcs = gc->buddy_chats; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1390 struct conversation *b = NULL; |
2086 | 1391 struct jabber_data *jd = gc->proto_data; |
1392 gjconn j = jd->jc; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1393 struct jabber_chat *jc = NULL; |
2086 | 1394 char *realwho, *subject; |
1395 | |
1396 if (!name) | |
1397 return; | |
1398 | |
1399 /* find which chat we're inviting to */ | |
1400 while (bcs) { | |
1401 b = bcs->data; | |
1402 if (id == b->id) | |
1403 break; | |
1404 bcs = bcs->next; | |
1405 } | |
1406 if (!bcs) | |
1407 return; | |
1408 | |
1409 bcs = jd->existing_chats; | |
1410 while (bcs) { | |
1411 jc = bcs->data; | |
1412 if (jc->b == b) | |
1413 break; | |
1414 bcs = bcs->next; | |
1415 } | |
1416 if (!bcs) | |
1417 return; | |
1418 | |
1419 x = xmlnode_new_tag("message"); | |
1420 if (!strchr(name, '@')) | |
1421 realwho = g_strdup_printf("%s@%s", name, j->user->server); | |
1422 else | |
1423 realwho = g_strdup(name); | |
1424 xmlnode_put_attrib(x, "to", realwho); | |
1425 g_free(realwho); | |
1426 | |
1427 y = xmlnode_insert_tag(x, "x"); | |
1428 xmlnode_put_attrib(y, "xmlns", "jabber:x:conference"); | |
1429 subject = g_strdup_printf("%s@%s", jc->Jid->user, jc->Jid->server); | |
1430 xmlnode_put_attrib(y, "jid", subject); | |
1431 g_free(subject); | |
1432 | |
1433 if (message && strlen(message)) { | |
1434 char *utf8 = str_to_utf8(message); | |
1435 y = xmlnode_insert_tag(x, "body"); | |
1436 xmlnode_insert_cdata(y, utf8, -1); | |
1437 g_free(utf8); | |
1438 } | |
1439 | |
1440 gjab_send(((struct jabber_data *)gc->proto_data)->jc, x); | |
1441 xmlnode_free(x); | |
1442 } | |
1443 | |
1444 static void jabber_chat_leave(struct gaim_connection *gc, int id) | |
1445 { | |
1446 GSList *bcs = gc->buddy_chats; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1447 struct conversation *b = NULL; |
2086 | 1448 struct jabber_data *jd = gc->proto_data; |
1449 gjconn j = jd->jc; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1450 struct jabber_chat *jc = NULL; |
2086 | 1451 char *realwho; |
1452 xmlnode x; | |
1453 | |
1454 while (bcs) { | |
1455 b = bcs->data; | |
1456 if (id == b->id) | |
1457 break; | |
1458 bcs = bcs->next; | |
1459 } | |
1460 if (!bcs) | |
1461 return; | |
1462 | |
1463 bcs = jd->existing_chats; | |
1464 while (bcs) { | |
1465 jc = bcs->data; | |
1466 if (jc->b == b) | |
1467 break; | |
1468 bcs = bcs->next; | |
1469 } | |
1470 if (!bcs) | |
1471 return; | |
1472 | |
1473 realwho = g_strdup_printf("%s@%s", jc->Jid->user, jc->Jid->server); | |
1474 x = jutil_presnew(0, realwho, NULL); | |
1475 g_free(realwho); | |
1476 xmlnode_put_attrib(x, "type", "unavailable"); | |
1477 gjab_send(j, x); | |
1478 xmlnode_free(x); | |
1479 jc->b = NULL; | |
1480 } | |
1481 | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1482 static int jabber_chat_send(struct gaim_connection *gc, int id, char *message) |
2086 | 1483 { |
1484 GSList *bcs = gc->buddy_chats; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1485 struct conversation *b = NULL; |
2086 | 1486 struct jabber_data *jd = gc->proto_data; |
1487 xmlnode x, y; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1488 struct jabber_chat *jc = NULL; |
2086 | 1489 char *chatname; |
1490 | |
1491 while (bcs) { | |
1492 b = bcs->data; | |
1493 if (id == b->id) | |
1494 break; | |
1495 bcs = bcs->next; | |
1496 } | |
1497 if (!bcs) | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1498 return -EINVAL; |
2086 | 1499 |
1500 bcs = jd->existing_chats; | |
1501 while (bcs) { | |
1502 jc = bcs->data; | |
1503 if (jc->b == b) | |
1504 break; | |
1505 bcs = bcs->next; | |
1506 } | |
1507 if (!bcs) | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1508 return -EINVAL; |
2086 | 1509 |
1510 x = xmlnode_new_tag("message"); | |
1511 xmlnode_put_attrib(x, "from", jid_full(jc->Jid)); | |
1512 chatname = g_strdup_printf("%s@%s", jc->Jid->user, jc->Jid->server); | |
1513 xmlnode_put_attrib(x, "to", chatname); | |
1514 g_free(chatname); | |
1515 xmlnode_put_attrib(x, "type", "groupchat"); | |
1516 | |
1517 if (message && strlen(message)) { | |
1518 char *utf8 = str_to_utf8(message); | |
1519 y = xmlnode_insert_tag(x, "body"); | |
1520 xmlnode_insert_cdata(y, utf8, -1); | |
1521 g_free(utf8); | |
1522 } | |
1523 | |
1524 gjab_send(((struct jabber_data *)gc->proto_data)->jc, x); | |
1525 xmlnode_free(x); | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1526 return 0; |
2086 | 1527 } |
1528 | |
1529 static void jabber_chat_set_topic(struct gaim_connection *gc, int id, char *topic) | |
1530 { | |
1531 GSList *bcs = gc->buddy_chats; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1532 struct conversation *b = NULL; |
2086 | 1533 struct jabber_data *jd = gc->proto_data; |
1534 xmlnode x, y; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1535 struct jabber_chat *jc = NULL; |
2086 | 1536 char *chatname; |
1537 char buf[8192]; | |
1538 | |
1539 while (bcs) { | |
1540 b = bcs->data; | |
1541 if (id == b->id) | |
1542 break; | |
1543 bcs = bcs->next; | |
1544 } | |
1545 if (!bcs) | |
1546 return; | |
1547 | |
1548 bcs = jd->existing_chats; | |
1549 while (bcs) { | |
1550 jc = bcs->data; | |
1551 if (jc->b == b) | |
1552 break; | |
1553 bcs = bcs->next; | |
1554 } | |
1555 if (!bcs) | |
1556 return; | |
1557 | |
1558 x = xmlnode_new_tag("message"); | |
1559 xmlnode_put_attrib(x, "from", jid_full(jc->Jid)); | |
1560 chatname = g_strdup_printf("%s@%s", jc->Jid->user, jc->Jid->server); | |
1561 xmlnode_put_attrib(x, "to", chatname); | |
1562 g_free(chatname); | |
1563 xmlnode_put_attrib(x, "type", "groupchat"); | |
1564 | |
1565 if (topic && strlen(topic)) { | |
1566 char *utf8 = str_to_utf8(topic); | |
1567 y = xmlnode_insert_tag(x, "subject"); | |
1568 xmlnode_insert_cdata(y, utf8, -1); | |
1569 y = xmlnode_insert_tag(x, "body"); | |
1570 g_snprintf(buf, sizeof(buf), "/me has changed the subject to: %s", utf8); | |
1571 xmlnode_insert_cdata(y, buf, -1); | |
1572 g_free(utf8); | |
1573 } | |
1574 | |
1575 gjab_send(((struct jabber_data *)gc->proto_data)->jc, x); | |
1576 xmlnode_free(x); | |
1577 } | |
1578 | |
1579 static void jabber_chat_whisper(struct gaim_connection *gc, int id, char *who, char *message) | |
1580 { | |
1581 GSList *bcs = gc->buddy_chats; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1582 struct conversation *b = NULL; |
2086 | 1583 struct jabber_data *jd = gc->proto_data; |
1584 xmlnode x, y; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1585 struct jabber_chat *jc = NULL; |
2086 | 1586 char *chatname; |
1587 | |
1588 while (bcs) { | |
1589 b = bcs->data; | |
1590 if (id == b->id) | |
1591 break; | |
1592 bcs = bcs->next; | |
1593 } | |
1594 if (!bcs) | |
1595 return; | |
1596 | |
1597 bcs = jd->existing_chats; | |
1598 while (bcs) { | |
1599 jc = bcs->data; | |
1600 if (jc->b == b) | |
1601 break; | |
1602 bcs = bcs->next; | |
1603 } | |
1604 if (!bcs) | |
1605 return; | |
1606 | |
1607 x = xmlnode_new_tag("message"); | |
1608 xmlnode_put_attrib(x, "from", jid_full(jc->Jid)); | |
1609 chatname = g_strdup_printf("%s@%s/%s", jc->Jid->user, jc->Jid->server, who); | |
1610 xmlnode_put_attrib(x, "to", chatname); | |
1611 g_free(chatname); | |
1612 xmlnode_put_attrib(x, "type", "normal"); | |
1613 | |
1614 if (message && strlen(message)) { | |
1615 char *utf8 = str_to_utf8(message); | |
1616 y = xmlnode_insert_tag(x, "body"); | |
1617 xmlnode_insert_cdata(y, utf8, -1); | |
1618 g_free(utf8); | |
1619 } | |
1620 | |
1621 gjab_send(((struct jabber_data *)gc->proto_data)->jc, x); | |
1622 xmlnode_free(x); | |
1623 } | |
1624 | |
1625 static GtkWidget *newname = NULL; | |
1626 static GtkWidget *newpass1 = NULL; | |
1627 static GtkWidget *newpass2 = NULL; | |
1628 static GtkWidget *newserv = NULL; | |
1629 static jconn regjconn = NULL; | |
1630 static int reginpa = 0; | |
1631 | |
1632 static void newdes() | |
1633 { | |
1634 newname = newpass1 = newpass2 = newserv = NULL; | |
1635 } | |
1636 | |
1637 static void jabber_draw_new_user(GtkWidget *box) | |
1638 { | |
1639 GtkWidget *hbox; | |
1640 GtkWidget *label; | |
1641 | |
1642 if (newname) | |
1643 return; | |
1644 | |
1645 label = gtk_label_new("Enter your name, password, and server to register on. If you " | |
1646 "already have a Jabber account and do not need to register one, " | |
1647 "use the Account Editor to add it to your list of accounts."); | |
1648 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
1649 gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 5); | |
1650 gtk_widget_show(label); | |
1651 | |
1652 hbox = gtk_hbox_new(FALSE, 5); | |
1653 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); | |
1654 gtk_widget_show(hbox); | |
1655 | |
1656 label = gtk_label_new("Username:"); | |
1657 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
1658 gtk_widget_show(label); | |
1659 | |
1660 newname = gtk_entry_new(); | |
1661 gtk_box_pack_end(GTK_BOX(hbox), newname, FALSE, FALSE, 5); | |
1662 gtk_signal_connect(GTK_OBJECT(newname), "destroy", GTK_SIGNAL_FUNC(newdes), NULL); | |
1663 gtk_widget_show(newname); | |
1664 | |
1665 hbox = gtk_hbox_new(FALSE, 5); | |
1666 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); | |
1667 gtk_widget_show(hbox); | |
1668 | |
1669 label = gtk_label_new("Password:"); | |
1670 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
1671 gtk_widget_show(label); | |
1672 | |
1673 newpass1 = gtk_entry_new(); | |
1674 gtk_box_pack_end(GTK_BOX(hbox), newpass1, FALSE, FALSE, 5); | |
1675 gtk_entry_set_visibility(GTK_ENTRY(newpass1), FALSE); | |
1676 gtk_widget_show(newpass1); | |
1677 | |
1678 hbox = gtk_hbox_new(FALSE, 5); | |
1679 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); | |
1680 gtk_widget_show(hbox); | |
1681 | |
1682 label = gtk_label_new("Confirm:"); | |
1683 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
1684 gtk_widget_show(label); | |
1685 | |
1686 newpass2 = gtk_entry_new(); | |
1687 gtk_box_pack_end(GTK_BOX(hbox), newpass2, FALSE, FALSE, 5); | |
1688 gtk_entry_set_visibility(GTK_ENTRY(newpass2), FALSE); | |
1689 gtk_widget_show(newpass2); | |
1690 | |
1691 hbox = gtk_hbox_new(FALSE, 5); | |
1692 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); | |
1693 gtk_widget_show(hbox); | |
1694 | |
1695 label = gtk_label_new("Server:"); | |
1696 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
1697 gtk_widget_show(label); | |
1698 | |
1699 newserv = gtk_entry_new(); | |
1700 gtk_entry_set_text(GTK_ENTRY(newserv), "jabber.org"); | |
1701 gtk_box_pack_end(GTK_BOX(hbox), newserv, FALSE, FALSE, 5); | |
1702 gtk_widget_show(newserv); | |
1703 } | |
1704 | |
1705 static void regstate(jconn j, int state) | |
1706 { | |
1707 static int catch = 0; | |
1708 switch (state) { | |
1709 case JCONN_STATE_OFF: | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1710 gaim_input_remove(reginpa); |
2086 | 1711 reginpa = 0; |
1712 jab_delete(j); | |
1713 break; | |
1714 case JCONN_STATE_CONNECTED: | |
1715 break; | |
1716 case JCONN_STATE_ON: | |
1717 if (catch) | |
1718 break; | |
1719 catch = 1; | |
1720 jab_reg(regjconn); | |
1721 catch = 0; | |
1722 break; | |
1723 case JCONN_STATE_AUTH: | |
1724 break; | |
1725 default: | |
1726 break; | |
1727 } | |
1728 } | |
1729 | |
1730 static void regpacket(jconn j, jpacket p) | |
1731 { | |
1732 static int here = 0; | |
1733 switch (p->type) { | |
1734 case JPACKET_MESSAGE: | |
1735 break; | |
1736 case JPACKET_PRESENCE: | |
1737 break; | |
1738 case JPACKET_IQ: | |
1739 if (jpacket_subtype(p) == JPACKET__RESULT) { | |
1740 xmlnode x, y, z; | |
1741 char *user, *id; | |
1742 | |
1743 if (here == 2) { | |
1744 struct aim_user *u; | |
1745 user = g_strdup(jid_full(j->user)); | |
1746 regjconn = NULL; | |
1747 here = 0; | |
1748 u = new_user(user, PROTO_JABBER, OPT_USR_REM_PASS); | |
1749 g_free(user); | |
1750 g_snprintf(u->password, sizeof(u->password), "%s", j->pass); | |
1751 save_prefs(); | |
1752 xmlnode_free(p->x); | |
1753 do_error_dialog("Registration successful! Your account has been" | |
1754 " added to the Account Editor.", "Jabber " | |
1755 "Registration"); | |
1756 gtk_entry_set_text(GTK_ENTRY(newname), ""); | |
1757 gtk_entry_set_text(GTK_ENTRY(newpass1), ""); | |
1758 gtk_entry_set_text(GTK_ENTRY(newpass2), ""); | |
1759 return; | |
1760 } else if (here == 1) { | |
1761 x = jutil_iqnew(JPACKET__SET, NS_AUTH); | |
1762 here = 2; | |
1763 } else { /* here == 0 */ | |
1764 here = 1; | |
1765 x = jutil_iqnew(JPACKET__GET, NS_AUTH); | |
1766 } | |
1767 | |
1768 id = jab_getid(j); | |
1769 xmlnode_put_attrib(x, "id", id); | |
1770 y = xmlnode_get_tag(x, "query"); | |
1771 | |
1772 user = j->user->user; | |
1773 if (user) | |
1774 { | |
1775 z = xmlnode_insert_tag(y, "username"); | |
1776 xmlnode_insert_cdata(z, user, -1); | |
1777 } | |
1778 | |
1779 if (here == 2) { | |
1780 z = xmlnode_insert_tag(y, "resource"); | |
1781 xmlnode_insert_cdata(z, j->user->resource, -1); | |
1782 z = xmlnode_insert_tag(y, "password"); | |
1783 xmlnode_insert_cdata(z, j->pass, -1); | |
1784 } | |
1785 | |
1786 jab_send(j, x); | |
1787 xmlnode_free(x); | |
1788 } else if (jpacket_subtype(p) == JPACKET__ERROR) { | |
1789 xmlnode x = xmlnode_get_tag(p->x, "error"); | |
1790 if (x) { | |
1791 char buf[8192]; | |
1792 g_snprintf(buf, sizeof(buf), "Registration failed: %d %s", | |
1793 atoi(xmlnode_get_attrib(x, "code")), | |
1794 xmlnode_get_data(xmlnode_get_firstchild(x))); | |
1795 do_error_dialog(buf, "Jabber Registration"); | |
1796 } else { | |
1797 do_error_dialog("Registration failed", "Jabber Registration"); | |
1798 } | |
1799 regjconn = NULL; | |
1800 xmlnode_free(p->x); | |
1801 here = 0; | |
1802 return; | |
1803 } | |
1804 break; | |
1805 case JPACKET_S10N: | |
1806 break; | |
1807 default: | |
1808 break; | |
1809 } | |
1810 | |
1811 xmlnode_free(p->x); | |
1812 } | |
1813 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1814 static void regjcall(gpointer data, gint source, GaimInputCondition cond) |
2086 | 1815 { |
1816 gjab_recv((gjconn)regjconn); | |
1817 } | |
1818 | |
1819 static void jabber_do_new_user() | |
1820 { | |
1821 const char *name, *pass1, *pass2, *serv; | |
1822 char *tmp; | |
1823 char *user; | |
1824 | |
1825 if (!newname || regjconn) | |
1826 return; | |
1827 | |
1828 pass1 = gtk_entry_get_text(GTK_ENTRY(newpass1)); | |
1829 pass2 = gtk_entry_get_text(GTK_ENTRY(newpass2)); | |
1830 if (pass1[0] == 0 || pass2[0] == 0) { | |
1831 do_error_dialog("Please enter the same valid password in both password entry boxes", | |
1832 "Registration error"); | |
1833 return; | |
1834 } | |
1835 if (strcmp(pass1, pass2)) { | |
1836 do_error_dialog("Mismatched passwords, please verify that both passwords are the same", | |
1837 "Registration error"); | |
1838 return; | |
1839 } | |
1840 name = gtk_entry_get_text(GTK_ENTRY(newname)); | |
1841 serv = gtk_entry_get_text(GTK_ENTRY(newserv)); | |
1842 if (name[0] == 0 || serv[0] == 0) { | |
1843 do_error_dialog("Please enter a valid username and server", "Registration error"); | |
1844 return; | |
1845 } | |
1846 | |
1847 user = g_strdup_printf("%s@%s/GAIM", name, serv); | |
1848 tmp = g_strdup(pass1); | |
1849 regjconn = jab_new(user, tmp); | |
1850 g_free(tmp); | |
1851 g_free(user); | |
1852 | |
1853 jab_state_handler(regjconn, regstate); | |
1854 jab_packet_handler(regjconn, regpacket); | |
1855 | |
1856 jab_start(regjconn); | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1857 reginpa = gaim_input_add(jab_getfd(regjconn), GAIM_INPUT_READ, regjcall, NULL); |
2086 | 1858 } |
1859 | |
1860 static char *jabber_normalize(const char *s) | |
1861 { | |
1862 static char buf[BUF_LEN]; | |
1863 char *t, *u; | |
1864 int x = 0; | |
1865 | |
1866 g_return_val_if_fail((s != NULL), NULL); | |
1867 | |
1868 u = t = g_strdup(s); | |
1869 | |
1870 g_strdown(t); | |
1871 | |
1872 while (*t && (x < BUF_LEN - 1)) { | |
1873 if (*t != ' ') | |
1874 buf[x++] = *t; | |
1875 t++; | |
1876 } | |
1877 buf[x] = '\0'; | |
1878 g_free(u); | |
1879 | |
1880 if (!strchr(buf, '@')) { | |
1881 strcat(buf, "@jabber.org"); /* this isn't always right, but eh */ | |
1882 } else if ((u = strchr(strchr(buf, '@'), '/')) != NULL) { | |
1883 *u = '\0'; | |
1884 } | |
1885 | |
1886 return buf; | |
1887 } | |
1888 | |
1889 static void jabber_get_info(struct gaim_connection *gc, char *who) { | |
1890 xmlnode x; | |
1891 char *id; | |
1892 struct jabber_data *jd = gc->proto_data; | |
1893 gjconn j = jd->jc; | |
1894 | |
1895 x = jutil_iqnew(JPACKET__GET, NS_VCARD); | |
1896 xmlnode_put_attrib(x, "to", who); | |
1897 id = gjab_getid(j); | |
1898 xmlnode_put_attrib(x, "id", id); | |
1899 | |
1900 gjab_send(j, x); | |
1901 | |
1902 xmlnode_free(x); | |
1903 | |
1904 } | |
1905 | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1906 static GList *jabber_buddy_menu(struct gaim_connection *gc, char *who) { |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1907 GList *m = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1908 struct proto_buddy_menu *pbm; |
2086 | 1909 |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1910 pbm = g_new0(struct proto_buddy_menu, 1); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1911 pbm->label = _("Get Info"); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1912 pbm->callback = jabber_get_info; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1913 pbm->gc = gc; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1914 m = g_list_append(m, pbm); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1915 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1916 return m; |
2086 | 1917 } |
1918 | |
1919 static GList *jabber_away_states() { | |
1920 GList *m = NULL; | |
1921 | |
1922 m = g_list_append(m, "Online"); | |
1923 m = g_list_append(m, "Chatty"); | |
1924 m = g_list_append(m, "Away"); | |
1925 m = g_list_append(m, "Extended Away"); | |
1926 m = g_list_append(m, "Do Not Disturb"); | |
1927 | |
1928 return m; | |
1929 } | |
1930 | |
1931 static void jabber_set_away(struct gaim_connection *gc, char *state, char *message) | |
1932 { | |
1933 xmlnode x, y; | |
1934 struct jabber_data *jd = gc->proto_data; | |
1935 gjconn j = jd->jc; | |
1936 | |
1937 gc->away = NULL; /* never send an auto-response */ | |
1938 | |
1939 x = xmlnode_new_tag("presence"); | |
1940 | |
1941 if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
1942 /* oh goody. Gaim is telling us what to do. */ | |
1943 if (message) { | |
1944 /* Gaim wants us to be away */ | |
1945 y = xmlnode_insert_tag(x, "show"); | |
1946 xmlnode_insert_cdata(y, "away", -1); | |
1947 y = xmlnode_insert_tag(x, "status"); | |
1948 xmlnode_insert_cdata(y, message, -1); | |
1949 gc->away = ""; | |
1950 } else { | |
1951 /* Gaim wants us to not be away */ | |
1952 /* but for Jabber, we can just send presence with no other information. */ | |
1953 } | |
1954 } else { | |
1955 /* state is one of our own strings. it won't be NULL. */ | |
1956 if (!strcmp(state, "Online")) { | |
1957 /* once again, we don't have to put anything here */ | |
1958 } else if (!strcmp(state, "Chatty")) { | |
1959 y = xmlnode_insert_tag(x, "show"); | |
1960 xmlnode_insert_cdata(y, "chat", -1); | |
1961 } else if (!strcmp(state, "Away")) { | |
1962 y = xmlnode_insert_tag(x, "show"); | |
1963 xmlnode_insert_cdata(y, "away", -1); | |
1964 gc->away = ""; | |
1965 } else if (!strcmp(state, "Extended Away")) { | |
1966 y = xmlnode_insert_tag(x, "show"); | |
1967 xmlnode_insert_cdata(y, "xa", -1); | |
1968 gc->away = ""; | |
1969 } else if (!strcmp(state, "Do Not Disturb")) { | |
1970 y = xmlnode_insert_tag(x, "show"); | |
1971 xmlnode_insert_cdata(y, "dnd", -1); | |
1972 gc->away = ""; | |
1973 } | |
1974 } | |
1975 | |
1976 gjab_send(j, x); | |
1977 xmlnode_free(x); | |
1978 } | |
1979 | |
1980 static void jabber_set_idle(struct gaim_connection *gc, int idle) { | |
1981 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; | |
1982 debug_printf("jabber_set_idle: setting idle %i\n", idle); | |
1983 jd->idle = idle ? time(NULL) - idle : idle; | |
1984 } | |
1985 | |
1986 static void jabber_keepalive(struct gaim_connection *gc) { | |
1987 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; | |
1988 gjab_send_raw(jd->jc, " \t "); | |
1989 } | |
1990 | |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
1991 static GList *jabber_user_opts() |
2086 | 1992 { |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
1993 GList *m = NULL; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
1994 struct proto_user_opt *puo; |
2086 | 1995 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
1996 puo = g_new0(struct proto_user_opt, 1); |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
1997 puo->label = "Port:"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
1998 puo->def = "5222"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
1999 puo->pos = USEROPT_PORT; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
2000 m = g_list_append(m, puo); |
2086 | 2001 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
2002 return m; |
2086 | 2003 } |
2004 | |
2005 static struct prpl *my_protocol = NULL; | |
2006 | |
2007 void jabber_init(struct prpl *ret) | |
2008 { | |
2009 /* the NULL's aren't required but they're nice to have */ | |
2010 ret->protocol = PROTO_JABBER; | |
2011 ret->options = OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_CHAT_TOPIC; | |
2012 ret->name = jabber_name; | |
2013 ret->list_icon = jabber_list_icon; | |
2014 ret->away_states = jabber_away_states; | |
2015 ret->buddy_menu = jabber_buddy_menu; | |
2016 ret->user_opts = jabber_user_opts; | |
2017 ret->draw_new_user = jabber_draw_new_user; | |
2018 ret->do_new_user = jabber_do_new_user; | |
2019 ret->login = jabber_login; | |
2020 ret->close = jabber_close; | |
2021 ret->send_im = jabber_send_im; | |
2022 ret->set_info = NULL; | |
2023 ret->get_info = jabber_get_info; | |
2024 ret->set_away = jabber_set_away; | |
2025 ret->get_away_msg = NULL; | |
2026 ret->set_dir = NULL; | |
2027 ret->get_dir = NULL; | |
2028 ret->dir_search = NULL; | |
2029 ret->set_idle = jabber_set_idle; | |
2030 ret->change_passwd = NULL; | |
2031 ret->add_buddy = jabber_add_buddy; | |
2032 ret->add_buddies = NULL; | |
2033 ret->remove_buddy = jabber_remove_buddy; | |
2034 ret->add_permit = NULL; | |
2035 ret->add_deny = NULL; | |
2036 ret->rem_permit = NULL; | |
2037 ret->rem_deny = NULL; | |
2038 ret->set_permit_deny = NULL; | |
2039 ret->warn = NULL; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2040 ret->chat_info = jabber_chat_info; |
2086 | 2041 ret->join_chat = jabber_join_chat; |
2042 ret->chat_invite = jabber_chat_invite; | |
2043 ret->chat_leave = jabber_chat_leave; | |
2044 ret->chat_whisper = jabber_chat_whisper; | |
2045 ret->chat_set_topic = jabber_chat_set_topic; | |
2046 ret->chat_send = jabber_chat_send; | |
2047 ret->keepalive = jabber_keepalive; | |
2048 ret->normalize = jabber_normalize; | |
2049 | |
2050 my_protocol = ret; | |
2051 } | |
2052 | |
2053 #ifndef STATIC | |
2054 | |
2055 char *gaim_plugin_init(GModule *handle) | |
2056 { | |
2057 load_protocol(jabber_init, sizeof(struct prpl)); | |
2058 return NULL; | |
2059 } | |
2060 | |
2061 void gaim_plugin_remove() | |
2062 { | |
2063 struct prpl *p = find_prpl(PROTO_JABBER); | |
2064 if (p == my_protocol) | |
2065 unload_protocol(p); | |
2066 } | |
2067 | |
2068 char *name() | |
2069 { | |
2070 return "Jabber"; | |
2071 } | |
2072 | |
2073 char *description() | |
2074 { | |
2162
a464da684307
[gaim-migrate @ 2172]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2154
diff
changeset
|
2075 return PRPL_DESC("Jabber"); |
2086 | 2076 } |
2077 | |
2078 #endif |