annotate plugins/jabber.c @ 1298:38f8096975ef

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