1311
|
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; 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 <gtk/gtk.h>
|
|
31 #include <unistd.h>
|
|
32 #include <errno.h>
|
|
33 #include <netinet/in.h>
|
|
34 #include <arpa/inet.h>
|
|
35 #include <string.h>
|
|
36 #include <stdlib.h>
|
|
37 #include <stdio.h>
|
|
38 #include <time.h>
|
|
39 #include <sys/socket.h>
|
|
40 #include <sys/stat.h>
|
|
41 #include "multi.h"
|
|
42 #include "prpl.h"
|
|
43 #include "gaim.h"
|
|
44 #include <jabber/jabber.h>
|
|
45
|
|
46 /* The priv member of gjconn's is a gaim_connection for now. */
|
|
47 #define GJ_GC(x) ((struct gaim_connection *)(x)->priv)
|
|
48
|
|
49 #define IQ_NONE -1
|
|
50 #define IQ_AUTH 0
|
|
51 #define IQ_ROSTER 1
|
|
52
|
|
53 typedef struct gjconn_struct
|
|
54 {
|
|
55 /* Core structure */
|
|
56 pool p; /* Memory allocation pool */
|
|
57 int state; /* Connection state flag */
|
|
58 int fd; /* Connection file descriptor */
|
|
59 jid user; /* User info */
|
|
60 char *pass; /* User passwd */
|
|
61
|
|
62 /* Stream stuff */
|
|
63 int id; /* id counter for jab_getid() function */
|
|
64 char idbuf[9]; /* temporary storage for jab_getid() */
|
|
65 char *sid; /* stream id from server, for digest auth */
|
|
66 XML_Parser parser; /* Parser instance */
|
|
67 xmlnode current; /* Current node in parsing instance.. */
|
|
68
|
|
69 /* Event callback ptrs */
|
|
70 void (*on_state)(struct gjconn_struct *j, int state);
|
|
71 void (*on_packet)(struct gjconn_struct *j, jpacket p);
|
|
72
|
|
73 void *priv;
|
|
74
|
|
75 } *gjconn, gjconn_struct;
|
|
76
|
|
77 typedef void (*gjconn_state_h)(gjconn j, int state);
|
|
78 typedef void (*gjconn_packet_h)(gjconn j, jpacket p);
|
|
79
|
|
80 static gjconn gjab_new(char *user, char *pass, void *priv);
|
|
81 static void gjab_delete(gjconn j);
|
|
82 static void gjab_state_handler(gjconn j, gjconn_state_h h);
|
|
83 static void gjab_packet_handler(gjconn j, gjconn_packet_h h);
|
|
84 static void gjab_start(gjconn j);
|
|
85 static void gjab_stop(gjconn j);
|
|
86 static int gjab_getfd(gjconn j);
|
|
87 static jid gjab_getjid(gjconn j);
|
|
88 static char *gjab_getsid(gjconn j);
|
|
89 static char *gjab_getid(gjconn j);
|
|
90 static void gjab_send(gjconn j, xmlnode x);
|
|
91 static void gjab_send_raw(gjconn j, const char *str);
|
|
92 static void gjab_recv(gjconn j);
|
|
93 static char *gjab_auth(gjconn j);
|
|
94
|
|
95 struct jabber_data {
|
|
96 gjconn jc;
|
|
97 };
|
|
98
|
|
99 static char *jabber_name() {
|
|
100 return "Jabber";
|
|
101 }
|
|
102
|
|
103 char *name() {
|
|
104 return "Jabber";
|
|
105 }
|
|
106
|
|
107 char *description() {
|
|
108 return "Allows gaim to use the Jabber protocol";
|
|
109 }
|
|
110
|
|
111 #define STATE_EVT(arg) if(j->on_state) { (j->on_state)(j, (arg) ); }
|
|
112
|
|
113 static gjconn gjab_new(char *user, char *pass, void *priv)
|
|
114 {
|
|
115 pool p;
|
|
116 gjconn j;
|
|
117
|
|
118 if(!user)
|
|
119 return(NULL);
|
|
120
|
|
121 p = pool_new();
|
|
122 if(!p)
|
|
123 return(NULL);
|
|
124 j = pmalloc_x(p, sizeof(gjconn_struct), 0);
|
|
125 if(!j)
|
|
126 return(NULL);
|
|
127 j->p = p;
|
|
128
|
|
129 j->user = jid_new(p, user);
|
|
130 j->pass = pstrdup(p, pass);
|
|
131
|
|
132 j->state = JCONN_STATE_OFF;
|
|
133 j->id = 1;
|
|
134 j->fd = -1;
|
|
135
|
|
136 j->priv = priv;
|
|
137
|
|
138 return j;
|
|
139 }
|
|
140
|
|
141 static void gjab_delete(gjconn j)
|
|
142 {
|
|
143 if(!j)
|
|
144 return;
|
|
145
|
|
146 gjab_stop(j);
|
|
147 pool_free(j->p);
|
|
148 }
|
|
149
|
|
150 static void gjab_state_handler(gjconn j, gjconn_state_h h)
|
|
151 {
|
|
152 if(!j)
|
|
153 return;
|
|
154
|
|
155 j->on_state = h;
|
|
156 }
|
|
157
|
|
158 static void gjab_packet_handler(gjconn j, gjconn_packet_h h)
|
|
159 {
|
|
160 if(!j)
|
|
161 return;
|
|
162
|
|
163 j->on_packet = h;
|
|
164 }
|
|
165
|
|
166 static void gjab_stop(gjconn j)
|
|
167 {
|
|
168 if(!j || j->state == JCONN_STATE_OFF)
|
|
169 return;
|
|
170
|
|
171 j->state = JCONN_STATE_OFF;
|
|
172 close(j->fd);
|
|
173 j->fd = -1;
|
|
174 XML_ParserFree(j->parser);
|
|
175 }
|
|
176
|
|
177 static int gjab_getfd(gjconn j)
|
|
178 {
|
|
179 if(j)
|
|
180 return j->fd;
|
|
181 else
|
|
182 return -1;
|
|
183 }
|
|
184
|
|
185 static jid gjab_getjid(gjconn j)
|
|
186 {
|
|
187 if(j)
|
|
188 return(j->user);
|
|
189 else
|
|
190 return NULL;
|
|
191 }
|
|
192
|
|
193 static char *gjab_getsid(gjconn j)
|
|
194 {
|
|
195 if(j)
|
|
196 return(j->sid);
|
|
197 else
|
|
198 return NULL;
|
|
199 }
|
|
200
|
|
201 static char *gjab_getid(gjconn j)
|
|
202 {
|
|
203 snprintf(j->idbuf, 8, "%d", j->id++);
|
|
204 return &j->idbuf[0];
|
|
205 }
|
|
206
|
|
207 static void gjab_send(gjconn j, xmlnode x)
|
|
208 {
|
|
209 if (j && j->state != JCONN_STATE_OFF) {
|
|
210 char *buf = xmlnode2str(x);
|
|
211 if (buf)
|
|
212 write(j->fd, buf, strlen(buf));
|
|
213 debug_printf("gjab_send: %s\n", buf);
|
|
214 }
|
|
215 }
|
|
216
|
|
217 static void gjab_send_raw(gjconn j, const char *str)
|
|
218 {
|
|
219 if (j && j->state != JCONN_STATE_OFF) {
|
|
220 write(j->fd, str, strlen(str));
|
|
221 debug_printf("gjab_send_raw: %s\n", str);
|
|
222 }
|
|
223 }
|
|
224
|
|
225 static void gjab_reqroster(gjconn j)
|
|
226 {
|
|
227 xmlnode x;
|
|
228 char *id;
|
|
229
|
|
230 x = jutil_iqnew(JPACKET__GET, NS_ROSTER);
|
|
231 id = gjab_getid(j);
|
|
232 xmlnode_put_attrib(x, "id", id);
|
|
233
|
|
234 gjab_send(j, x);
|
|
235 xmlnode_free(x);
|
|
236 }
|
|
237
|
|
238 static char *gjab_auth(gjconn j)
|
|
239 {
|
|
240 xmlnode x,y,z;
|
|
241 char *hash, *user, *id;
|
|
242
|
|
243 if(!j)
|
|
244 return NULL;
|
|
245
|
|
246 x = jutil_iqnew(JPACKET__SET, NS_AUTH);
|
|
247 id = gjab_getid(j);
|
|
248 xmlnode_put_attrib(x, "id", id);
|
|
249 y = xmlnode_get_tag(x,"query");
|
|
250
|
|
251 user = j->user->user;
|
|
252
|
|
253 if (user) {
|
|
254 z = xmlnode_insert_tag(y, "username");
|
|
255 xmlnode_insert_cdata(z, user, -1);
|
|
256 }
|
|
257
|
|
258 z = xmlnode_insert_tag(y, "resource");
|
|
259 xmlnode_insert_cdata(z, j->user->resource, -1);
|
|
260
|
|
261 if (j->sid) {
|
|
262 z = xmlnode_insert_tag(y, "digest");
|
|
263 hash = pmalloc(x->p, strlen(j->sid)+strlen(j->pass)+1);
|
|
264 strcpy(hash, j->sid);
|
|
265 strcat(hash, j->pass);
|
|
266 hash = shahash(hash);
|
|
267 xmlnode_insert_cdata(z, hash, 40);
|
|
268 } else {
|
|
269 z = xmlnode_insert_tag(y, "password");
|
|
270 xmlnode_insert_cdata(z, j->pass, -1);
|
|
271 }
|
|
272
|
|
273 gjab_send(j, x);
|
|
274 xmlnode_free(x);
|
|
275
|
|
276 return id;
|
|
277 }
|
|
278
|
|
279 static void gjab_recv(gjconn j)
|
|
280 {
|
|
281 static char buf[4096];
|
|
282 int len;
|
|
283
|
|
284 if(!j || j->state == JCONN_STATE_OFF)
|
|
285 return;
|
|
286
|
|
287 if ((len = read(j->fd, buf, sizeof(buf)-1))) {
|
|
288 buf[len] = '\0';
|
|
289 debug_printf("input: %s\n", buf);
|
|
290 XML_Parse(j->parser, buf, len, 0);
|
|
291 } else if (len < 0) {
|
|
292 STATE_EVT(JCONN_STATE_OFF);
|
|
293 gjab_stop(j);
|
|
294 }
|
|
295 }
|
|
296
|
|
297 static void startElement(void *userdata, const char *name, const char **attribs)
|
|
298 {
|
|
299 xmlnode x;
|
|
300 gjconn j = (gjconn)userdata;
|
|
301
|
|
302 if(j->current) {
|
|
303 /* Append the node to the current one */
|
|
304 x = xmlnode_insert_tag(j->current, name);
|
|
305 xmlnode_put_expat_attribs(x, attribs);
|
|
306
|
|
307 j->current = x;
|
|
308 } else {
|
|
309 x = xmlnode_new_tag(name);
|
|
310 xmlnode_put_expat_attribs(x, attribs);
|
|
311 if(strcmp(name, "stream:stream") == 0) {
|
|
312 /* special case: name == stream:stream */
|
|
313 /* id attrib of stream is stored for digest auth */
|
|
314 j->sid = xmlnode_get_attrib(x, "id");
|
|
315 /* STATE_EVT(JCONN_STATE_AUTH) */
|
|
316 } else {
|
|
317 j->current = x;
|
|
318 }
|
|
319 }
|
|
320 }
|
|
321
|
|
322 static void endElement(void *userdata, const char *name)
|
|
323 {
|
|
324 gjconn j = (gjconn)userdata;
|
|
325 xmlnode x;
|
|
326 jpacket p;
|
|
327
|
|
328 if(j->current == NULL) {
|
|
329 /* we got </stream:stream> */
|
|
330 STATE_EVT(JCONN_STATE_OFF)
|
|
331 return;
|
|
332 }
|
|
333
|
|
334 x = xmlnode_get_parent(j->current);
|
|
335
|
|
336 if(!x) {
|
|
337 /* it is time to fire the event */
|
|
338 p = jpacket_new(j->current);
|
|
339
|
|
340 if(j->on_packet)
|
|
341 (j->on_packet)(j, p);
|
|
342 else
|
|
343 xmlnode_free(j->current);
|
|
344 }
|
|
345
|
|
346 j->current = x;
|
|
347 }
|
|
348
|
|
349 static void charData(void *userdata, const char *s, int slen)
|
|
350 {
|
|
351 gjconn j = (gjconn)userdata;
|
|
352
|
|
353 if (j->current)
|
|
354 xmlnode_insert_cdata(j->current, s, slen);
|
|
355 }
|
|
356
|
|
357 static void gjab_start(gjconn j)
|
|
358 {
|
|
359 xmlnode x;
|
|
360 char *t,*t2;
|
|
361
|
|
362 if(!j || j->state != JCONN_STATE_OFF)
|
|
363 return;
|
|
364
|
|
365 j->parser = XML_ParserCreate(NULL);
|
|
366 XML_SetUserData(j->parser, (void *)j);
|
|
367 XML_SetElementHandler(j->parser, startElement, endElement);
|
|
368 XML_SetCharacterDataHandler(j->parser, charData);
|
|
369
|
|
370 j->fd = make_netsocket(5222, j->user->server, NETSOCKET_CLIENT);
|
|
371 if(j->fd < 0) {
|
|
372 STATE_EVT(JCONN_STATE_OFF)
|
|
373 return;
|
|
374 }
|
|
375 j->state = JCONN_STATE_CONNECTED;
|
|
376 STATE_EVT(JCONN_STATE_CONNECTED)
|
|
377
|
|
378 /* start stream */
|
|
379 x = jutil_header(NS_CLIENT, j->user->server);
|
|
380 t = xmlnode2str(x);
|
|
381 /* this is ugly, we can create the string here instead of jutil_header */
|
|
382 /* what do you think about it? -madcat */
|
|
383 t2 = strstr(t,"/>");
|
|
384 *t2++ = '>';
|
|
385 *t2 = '\0';
|
|
386 gjab_send_raw(j,"<?xml version='1.0'?>");
|
|
387 gjab_send_raw(j,t);
|
|
388 xmlnode_free(x);
|
|
389
|
|
390 j->state = JCONN_STATE_ON;
|
|
391 STATE_EVT(JCONN_STATE_ON)
|
|
392 }
|
|
393
|
|
394 static void jabber_callback(gpointer data, gint source, GdkInputCondition condition) {
|
|
395 struct gaim_connection *gc = (struct gaim_connection *)data;
|
|
396 struct jabber_data *jd = (struct jabber_data *)gc->proto_data;
|
|
397
|
|
398 debug_printf("jabber_callback!\n");
|
|
399
|
|
400 gjab_recv(jd->jc);
|
|
401 }
|
|
402
|
|
403 static void jabber_handlemessage(gjconn j, jpacket p)
|
|
404 {
|
|
405 xmlnode y;
|
|
406
|
|
407 char *from = NULL, *msg = NULL;
|
|
408
|
|
409 from = jid_full(p->from);
|
|
410 if ((y = xmlnode_get_tag(p->x, "body"))) {
|
|
411 msg = xmlnode_get_data(y);
|
|
412 }
|
|
413
|
|
414 if (!from || !msg) {
|
|
415 return;
|
|
416 }
|
|
417
|
|
418 debug_printf("jabber: msg from %s: %s\n", from, msg);
|
|
419
|
|
420 serv_got_im(GJ_GC(j), from, msg, 0);
|
|
421
|
|
422 return;
|
|
423 }
|
|
424
|
|
425 static void jabber_handlepresence(gjconn j, jpacket p)
|
|
426 {
|
|
427 char *to, *from, *type;
|
|
428 struct buddy *b;
|
|
429
|
|
430 to = xmlnode_get_attrib(p->x, "to");
|
|
431 from = xmlnode_get_attrib(p->x, "from");
|
|
432 type = xmlnode_get_attrib(p->x, "type");
|
|
433
|
|
434 debug_printf("jabber: presence: %s, %s %s\n", to, from, type);
|
|
435
|
|
436 if (!(b = find_buddy(GJ_GC(j), from)))
|
|
437 add_buddy(GJ_GC(j), "Extra", from, from);
|
|
438
|
|
439 if (type && (strcasecmp(type, "unavailable") == 0))
|
|
440 serv_got_update(GJ_GC(j), from, 0, 0, 0, 0, 0, 0);
|
|
441 else
|
|
442 serv_got_update(GJ_GC(j), from, 1, 0, 0, 0, 0, 0);
|
|
443
|
|
444 return;
|
|
445 }
|
|
446
|
|
447 static void jabber_handleroster(gjconn j, xmlnode querynode)
|
|
448 {
|
|
449 xmlnode x;
|
|
450
|
|
451 x = xmlnode_get_firstchild(querynode);
|
|
452 while (x) {
|
|
453 xmlnode g;
|
|
454 char *jid, *name, *sub, *ask;
|
|
455
|
|
456 jid = xmlnode_get_attrib(x, "jid");
|
|
457 name = xmlnode_get_attrib(x, "name");
|
|
458 if (name)
|
|
459 printf("name = %s\n", name);
|
|
460 sub = xmlnode_get_attrib(x, "subscription");
|
|
461 ask = xmlnode_get_attrib(x, "ask");
|
|
462
|
|
463 if (ask) {
|
|
464 /* XXX do something */
|
|
465 debug_printf("jabber: unhandled subscription request (%s/%s/%s/%s)\n", jid, name, sub, ask);
|
|
466 }
|
|
467
|
|
468 if ((g = xmlnode_get_firstchild(x))) {
|
|
469 while (g) {
|
|
470 if (strncasecmp(xmlnode_get_name(g), "group", 5) == 0) {
|
|
471 struct buddy *b;
|
|
472 char *groupname;
|
|
473
|
|
474 groupname = xmlnode_get_data(xmlnode_get_firstchild(g));
|
|
475 if (!(b = find_buddy(GJ_GC(j), jid))) {
|
|
476 printf("adding buddy: %s\n", jid);
|
|
477 b = add_buddy(GJ_GC(j), groupname, jid, name?name:jid);
|
|
478 } else {
|
|
479 printf("updating buddy: %s/%s\n", jid, name);
|
|
480 g_snprintf(b->name, sizeof(b->name), "%s", jid);
|
|
481 g_snprintf(b->show, sizeof(b->show), "%s", name?name:jid);
|
|
482 }
|
|
483 //serv_got_update(GJ_GC(j), b->name, 1, 0, 0, 0, 0, 0);
|
|
484 }
|
|
485 g = xmlnode_get_nextsibling(g);
|
|
486 }
|
|
487 } else {
|
|
488 struct buddy *b;
|
|
489 if (!(b = find_buddy(GJ_GC(j), jid))) {
|
|
490 b = add_buddy(GJ_GC(j), "Extra", jid, name?name:jid);
|
|
491 }
|
|
492 }
|
|
493
|
|
494 x = xmlnode_get_nextsibling(x);
|
|
495 }
|
|
496 }
|
|
497
|
|
498 static void jabber_handlepacket(gjconn j, jpacket p)
|
|
499 {
|
|
500 switch (p->type) {
|
|
501 case JPACKET_MESSAGE:
|
|
502 jabber_handlemessage(j, p);
|
|
503 break;
|
|
504 case JPACKET_PRESENCE:
|
|
505 jabber_handlepresence(j, p);
|
|
506 break;
|
|
507 case JPACKET_IQ: {
|
|
508
|
|
509 if (jpacket_subtype(p) == JPACKET__RESULT) {
|
|
510 xmlnode querynode;
|
|
511 char *xmlns;
|
|
512
|
|
513 querynode = xmlnode_get_tag(p->x, "query");
|
|
514 xmlns = xmlnode_get_attrib(querynode, "xmlns");
|
|
515
|
|
516 /* XXX this just doesn't look right */
|
|
517 if (!xmlns || NSCHECK(querynode, NS_AUTH)) {
|
|
518 xmlnode x;
|
|
519
|
|
520 debug_printf("auth success\n");
|
|
521 x = jutil_presnew(0, NULL, NULL);
|
|
522 gjab_send(j, x);
|
|
523 xmlnode_free(x);
|
|
524
|
|
525 account_online(GJ_GC(j));
|
|
526 serv_finish_login(GJ_GC(j));
|
|
527
|
|
528 gjab_reqroster(j);
|
|
529
|
|
530 } else if (NSCHECK(querynode, NS_ROSTER)) {
|
|
531 jabber_handleroster(j, querynode);
|
|
532 } else {
|
|
533 debug_printf("jabber:iq:query: %s\n", xmlns);
|
|
534 }
|
|
535
|
|
536 } else {
|
|
537 xmlnode x;
|
|
538
|
|
539 debug_printf("auth failed\n");
|
|
540 x = xmlnode_get_tag(p->x, "error");
|
|
541 if (x) {
|
|
542 debug_printf("error %d: %s\n\n",
|
|
543 atoi(xmlnode_get_attrib(x, "code")),
|
|
544 xmlnode_get_data(xmlnode_get_firstchild(x)));
|
|
545 hide_login_progress(GJ_GC(j), xmlnode_get_data(xmlnode_get_firstchild(x)));
|
|
546
|
|
547 } else
|
|
548 hide_login_progress(GJ_GC(j), "unknown error");
|
|
549
|
|
550 signoff(GJ_GC(j));
|
|
551 }
|
|
552 break;
|
|
553 }
|
|
554 default:
|
|
555 debug_printf("jabber: packet type %d (%s)\n", p->type, xmlnode2str(p->x));
|
|
556 }
|
|
557
|
|
558 xmlnode_free(p->x);
|
|
559
|
|
560 return;
|
|
561 }
|
|
562
|
|
563 static void jabber_handlestate(gjconn j, int state)
|
|
564 {
|
|
565 switch (state) {
|
|
566 case JCONN_STATE_OFF:
|
|
567 debug_printf("jabber: connection closed\n");
|
|
568 hide_login_progress(GJ_GC(j), "Unable to connect");
|
|
569 signoff(GJ_GC(j));
|
|
570 break;
|
|
571 case JCONN_STATE_CONNECTED:
|
|
572 debug_printf("jabber: connected.\n");
|
|
573 set_login_progress(GJ_GC(j), 1, "Connected");
|
|
574 break;
|
|
575 case JCONN_STATE_ON:
|
|
576 debug_printf("jabber: logging in...\n");
|
|
577 set_login_progress(GJ_GC(j), 1, "Logging in...");
|
|
578 gjab_auth(j);
|
|
579 break;
|
|
580 default:
|
|
581 debug_printf("state change: %d\n", state);
|
|
582 }
|
|
583 return;
|
|
584 }
|
|
585
|
|
586 static void jabber_login(struct aim_user *user) {
|
|
587 struct gaim_connection *gc = new_gaim_conn(user);
|
|
588 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1);
|
|
589
|
|
590 debug_printf("jabber_login (u=%s/p=%s)\n", user->username, user->password);
|
|
591
|
|
592 set_login_progress(gc, 1, "Connecting");
|
|
593 while (gtk_events_pending())
|
|
594 gtk_main_iteration();
|
|
595
|
|
596 if (!(jd->jc = gjab_new(user->username, user->password, gc))) {
|
|
597 debug_printf("jabber: unable to connect (jab_new failed)\n");
|
|
598 hide_login_progress(gc, "Unable to connect");
|
|
599 signoff(gc);
|
|
600 return;
|
|
601 }
|
|
602
|
|
603 gjab_state_handler(jd->jc, jabber_handlestate);
|
|
604 gjab_packet_handler(jd->jc, jabber_handlepacket);
|
|
605 gjab_start(jd->jc);
|
|
606
|
|
607
|
|
608 gc->user = user; /* XXX I assume this is okay...OSCAR does it */
|
|
609
|
|
610 gc->inpa = gdk_input_add(jd->jc->fd,
|
|
611 GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
|
|
612 jabber_callback, gc);
|
|
613
|
|
614 return;
|
|
615
|
|
616 //signoff(gc);
|
|
617
|
|
618 #if 0
|
|
619 struct yahoo_options opt;
|
|
620 struct yahoo_context *ctxt;
|
|
621 opt.connect_mode = YAHOO_CONNECT_NORMAL;
|
|
622 opt.proxy_host = NULL;
|
|
623 ctxt = yahoo_init(user->username, user->password, &opt);
|
|
624 yd->ctxt = ctxt;
|
|
625
|
|
626 set_login_progress(gc, 1, "Connecting");
|
|
627 while (gtk_events_pending())
|
|
628 gtk_main_iteration();
|
|
629
|
|
630 if (!ctxt || !yahoo_connect(ctxt)) {
|
|
631 debug_printf("Yahoo: Unable to connect\n");
|
|
632 hide_login_progress(gc, "Unable to connect");
|
|
633 signoff(gc);
|
|
634 return;
|
|
635 }
|
|
636
|
|
637 debug_printf("Yahoo: connected\n");
|
|
638
|
|
639 set_login_progress(gc, 3, "Getting Config");
|
|
640 while (gtk_events_pending())
|
|
641 gtk_main_iteration();
|
|
642
|
|
643 yahoo_get_config(ctxt);
|
|
644
|
|
645 if (yahoo_cmd_logon(ctxt, YAHOO_STATUS_AVAILABLE)) {
|
|
646 debug_printf("Yahoo: Unable to login\n");
|
|
647 hide_login_progress(gc, "Unable to login");
|
|
648 signoff(gc);
|
|
649 return;
|
|
650 }
|
|
651
|
|
652 if (ctxt->buddies) {
|
|
653 struct yahoo_buddy **buddies;
|
|
654
|
|
655 for (buddies = ctxt->buddies; *buddies; buddies++) {
|
|
656 struct yahoo_buddy *bud = *buddies;
|
|
657 struct buddy *b;
|
|
658 struct group *g;
|
|
659
|
|
660 b = find_buddy(gc, bud->id);
|
|
661 if (!b) add_buddy(gc, bud->group, bud->id, bud->id);
|
|
662 }
|
|
663 }
|
|
664
|
|
665 debug_printf("Yahoo: logged in %s\n", gc->username);
|
|
666 account_online(gc);
|
|
667 serv_finish_login(gc);
|
|
668
|
|
669 gc->inpa = gdk_input_add(ctxt->sockfd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
|
|
670 yahoo_callback, gc);
|
|
671 #endif
|
|
672 }
|
|
673
|
|
674 static void jabber_close(struct gaim_connection *gc) {
|
|
675 #if 0
|
|
676 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
677 if (gc->inpa)
|
|
678 gdk_input_remove(gc->inpa);
|
|
679 gc->inpa = -1;
|
|
680 yahoo_cmd_logoff(yd->ctxt);
|
|
681 g_free(yd);
|
|
682 #endif
|
|
683 }
|
|
684
|
|
685 static void jabber_send_im(struct gaim_connection *gc, char *who, char *message, int away) {
|
|
686 xmlnode x, y;
|
|
687
|
|
688 if (!who || !message)
|
|
689 return;
|
|
690
|
|
691 x = xmlnode_new_tag("message");
|
|
692 xmlnode_put_attrib(x, "to", who);
|
|
693
|
|
694 xmlnode_put_attrib(x, "type", "chat");
|
|
695
|
|
696 if (message && strlen(message)) {
|
|
697 y = xmlnode_insert_tag(x, "body");
|
|
698 xmlnode_insert_cdata(y, message, -1);
|
|
699 }
|
|
700
|
|
701 gjab_send(((struct jabber_data *)gc->proto_data)->jc, x);
|
|
702 }
|
|
703
|
|
704 static void jabber_keepalive(struct gaim_connection *gc) {
|
|
705 #if 0
|
|
706 yahoo_cmd_ping(((struct yahoo_data *)gc->proto_data)->ctxt);
|
|
707 #endif
|
|
708 }
|
|
709
|
|
710 static void jabber_add_buddy(struct gaim_connection *gc, char *name) {
|
|
711 #if 0
|
|
712 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
713 struct yahoo_buddy *tmpbuddy;
|
|
714 struct group *g = find_group_by_buddy(gc, name);
|
|
715 char *group = NULL;
|
|
716
|
|
717 if (g) {
|
|
718 group = g->name;
|
|
719 } else if (yd->ctxt && yd->ctxt->buddies[0]) {
|
|
720 tmpbuddy = yd->ctxt->buddies[0];
|
|
721 group = tmpbuddy->group;
|
|
722 }
|
|
723
|
|
724 if (group)
|
|
725 yahoo_add_buddy(yd->ctxt, name, gc->username, group, "");
|
|
726 #endif
|
|
727 }
|
|
728
|
|
729 static struct prpl *my_protocol = NULL;
|
|
730
|
|
731 void Jabber_init(struct prpl *ret) {
|
|
732 /* the NULL's aren't required but they're nice to have */
|
|
733 ret->protocol = PROTO_JABBER;
|
|
734 ret->name = jabber_name;
|
|
735 ret->list_icon = NULL;
|
|
736 ret->action_menu = NULL;
|
|
737 ret->login = jabber_login;
|
|
738 ret->close = jabber_close;
|
|
739 ret->send_im = jabber_send_im;
|
|
740 ret->set_info = NULL;
|
|
741 ret->get_info = NULL;
|
|
742 ret->set_away = NULL;
|
|
743 ret->get_away_msg = NULL;
|
|
744 ret->set_dir = NULL;
|
|
745 ret->get_dir = NULL;
|
|
746 ret->dir_search = NULL;
|
|
747 ret->set_idle = NULL;
|
|
748 ret->change_passwd = NULL;
|
|
749 ret->add_buddy = jabber_add_buddy;
|
|
750 ret->add_buddies = NULL;
|
|
751 ret->remove_buddy = NULL;
|
|
752 ret->add_permit = NULL;
|
|
753 ret->add_deny = NULL;
|
|
754 ret->rem_permit = NULL;
|
|
755 ret->rem_deny = NULL;
|
|
756 ret->set_permit_deny = NULL;
|
|
757 ret->warn = NULL;
|
|
758 ret->accept_chat = NULL;
|
|
759 ret->join_chat = NULL;
|
|
760 ret->chat_invite = NULL;
|
|
761 ret->chat_leave = NULL;
|
|
762 ret->chat_whisper = NULL;
|
|
763 ret->chat_send = NULL;
|
|
764 ret->keepalive = jabber_keepalive;
|
|
765
|
|
766 my_protocol = ret;
|
|
767 }
|
|
768
|
|
769 char *gaim_plugin_init(GModule *handle) {
|
|
770 load_protocol(Jabber_init);
|
|
771 return NULL;
|
|
772 }
|
|
773
|
|
774 void gaim_plugin_remove() {
|
|
775 struct prpl *p = find_prpl(PROTO_JABBER);
|
|
776 if (p == my_protocol)
|
|
777 unload_protocol(p);
|
|
778 }
|