14192
|
1 /*
|
|
2 * gaim - Jabber Protocol Plugin
|
|
3 *
|
|
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
|
|
5 *
|
|
6 * This program is free software; you can redistribute it and/or modify
|
|
7 * it under the terms of the GNU General Public License as published by
|
|
8 * the Free Software Foundation; either version 2 of the License, or
|
|
9 * (at your option) any later version.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful,
|
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 * GNU General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program; if not, write to the Free Software
|
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19 *
|
|
20 */
|
|
21 #include "internal.h"
|
|
22
|
|
23 #include "account.h"
|
|
24 #include "accountopt.h"
|
|
25 #include "blist.h"
|
|
26 #include "cmds.h"
|
|
27 #include "connection.h"
|
|
28 #include "debug.h"
|
|
29 #include "dnssrv.h"
|
|
30 #include "message.h"
|
|
31 #include "notify.h"
|
|
32 #include "pluginpref.h"
|
|
33 #include "proxy.h"
|
|
34 #include "prpl.h"
|
|
35 #include "request.h"
|
|
36 #include "server.h"
|
|
37 #include "util.h"
|
|
38 #include "version.h"
|
|
39
|
|
40 #include "auth.h"
|
|
41 #include "buddy.h"
|
|
42 #include "chat.h"
|
|
43 #include "disco.h"
|
|
44 #include "iq.h"
|
|
45 #include "jutil.h"
|
|
46 #include "message.h"
|
|
47 #include "parser.h"
|
|
48 #include "presence.h"
|
|
49 #include "jabber.h"
|
|
50 #include "roster.h"
|
|
51 #include "si.h"
|
|
52 #include "xdata.h"
|
|
53
|
|
54 #define JABBER_CONNECT_STEPS (js->gsc ? 8 : 5)
|
|
55
|
|
56 static GaimPlugin *my_protocol = NULL;
|
|
57
|
|
58 static void jabber_stream_init(JabberStream *js)
|
|
59 {
|
|
60 char *open_stream;
|
|
61
|
|
62 open_stream = g_strdup_printf("<stream:stream to='%s' "
|
|
63 "xmlns='jabber:client' "
|
|
64 "xmlns:stream='http://etherx.jabber.org/streams' "
|
|
65 "version='1.0'>",
|
|
66 js->user->domain);
|
|
67 /* setup the parser fresh for each stream */
|
|
68 jabber_parser_setup(js);
|
|
69 jabber_send_raw(js, open_stream, -1);
|
|
70 js->reinit = FALSE;
|
|
71 g_free(open_stream);
|
|
72 }
|
|
73
|
|
74 static void
|
|
75 jabber_session_initialized_cb(JabberStream *js, xmlnode *packet, gpointer data)
|
|
76 {
|
|
77 const char *type = xmlnode_get_attrib(packet, "type");
|
|
78 if(type && !strcmp(type, "result")) {
|
|
79 jabber_stream_set_state(js, JABBER_STREAM_CONNECTED);
|
|
80 } else {
|
|
81 gaim_connection_error(js->gc, _("Error initializing session"));
|
|
82 }
|
|
83 }
|
|
84
|
|
85 static void jabber_session_init(JabberStream *js)
|
|
86 {
|
|
87 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET);
|
|
88 xmlnode *session;
|
|
89
|
|
90 jabber_iq_set_callback(iq, jabber_session_initialized_cb, NULL);
|
|
91
|
|
92 session = xmlnode_new_child(iq->node, "session");
|
|
93 xmlnode_set_namespace(session, "urn:ietf:params:xml:ns:xmpp-session");
|
|
94
|
|
95 jabber_iq_send(iq);
|
|
96 }
|
|
97
|
|
98 static void jabber_bind_result_cb(JabberStream *js, xmlnode *packet,
|
|
99 gpointer data)
|
|
100 {
|
|
101 const char *type = xmlnode_get_attrib(packet, "type");
|
|
102 xmlnode *bind;
|
|
103
|
|
104 if(type && !strcmp(type, "result") &&
|
|
105 (bind = xmlnode_get_child_with_namespace(packet, "bind", "urn:ietf:params:xml:ns:xmpp-bind"))) {
|
|
106 xmlnode *jid;
|
|
107 char *full_jid;
|
|
108 if((jid = xmlnode_get_child(bind, "jid")) && (full_jid = xmlnode_get_data(jid))) {
|
|
109 JabberBuddy *my_jb = NULL;
|
|
110 jabber_id_free(js->user);
|
|
111 if(!(js->user = jabber_id_new(full_jid))) {
|
|
112 gaim_connection_error(js->gc, _("Invalid response from server."));
|
|
113 }
|
|
114 if((my_jb = jabber_buddy_find(js, full_jid, TRUE)))
|
|
115 my_jb->subscription |= JABBER_SUB_BOTH;
|
|
116 g_free(full_jid);
|
|
117 }
|
|
118 } else {
|
|
119 char *msg = jabber_parse_error(js, packet);
|
|
120 gaim_connection_error(js->gc, msg);
|
|
121 g_free(msg);
|
|
122 }
|
|
123
|
|
124 jabber_session_init(js);
|
|
125 }
|
|
126
|
|
127 static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet)
|
|
128 {
|
|
129 if(xmlnode_get_child(packet, "starttls")) {
|
|
130 if(jabber_process_starttls(js, packet))
|
|
131 return;
|
|
132 }
|
|
133
|
|
134 if(js->registration) {
|
|
135 jabber_register_start(js);
|
|
136 } else if(xmlnode_get_child(packet, "mechanisms")) {
|
|
137 jabber_auth_start(js, packet);
|
|
138 } else if(xmlnode_get_child(packet, "bind")) {
|
|
139 xmlnode *bind, *resource;
|
|
140 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET);
|
|
141 bind = xmlnode_new_child(iq->node, "bind");
|
|
142 xmlnode_set_namespace(bind, "urn:ietf:params:xml:ns:xmpp-bind");
|
|
143 resource = xmlnode_new_child(bind, "resource");
|
|
144 xmlnode_insert_data(resource, js->user->resource, -1);
|
|
145
|
|
146 jabber_iq_set_callback(iq, jabber_bind_result_cb, NULL);
|
|
147
|
|
148 jabber_iq_send(iq);
|
|
149 } else /* if(xmlnode_get_child_with_namespace(packet, "auth")) */ {
|
|
150 /* If we get an empty stream:features packet, or we explicitly get
|
|
151 * an auth feature with namespace http://jabber.org/features/iq-auth
|
|
152 * we should revert back to iq:auth authentication, even though we're
|
|
153 * connecting to an XMPP server. */
|
|
154 js->auth_type = JABBER_AUTH_IQ_AUTH;
|
|
155 jabber_stream_set_state(js, JABBER_STREAM_AUTHENTICATING);
|
|
156 }
|
|
157 }
|
|
158
|
|
159 static void jabber_stream_handle_error(JabberStream *js, xmlnode *packet)
|
|
160 {
|
|
161 char *msg = jabber_parse_error(js, packet);
|
|
162
|
|
163 gaim_connection_error(js->gc, msg);
|
|
164 g_free(msg);
|
|
165 }
|
|
166
|
|
167 static void tls_init(JabberStream *js);
|
|
168
|
|
169 void jabber_process_packet(JabberStream *js, xmlnode *packet)
|
|
170 {
|
|
171 if(!strcmp(packet->name, "iq")) {
|
|
172 jabber_iq_parse(js, packet);
|
|
173 } else if(!strcmp(packet->name, "presence")) {
|
|
174 jabber_presence_parse(js, packet);
|
|
175 } else if(!strcmp(packet->name, "message")) {
|
|
176 jabber_message_parse(js, packet);
|
|
177 } else if(!strcmp(packet->name, "stream:features")) {
|
|
178 jabber_stream_features_parse(js, packet);
|
|
179 } else if (!strcmp(packet->name, "features") &&
|
|
180 !strcmp(xmlnode_get_namespace(packet), "http://etherx.jabber.org/streams")) {
|
|
181 jabber_stream_features_parse(js, packet);
|
|
182 } else if(!strcmp(packet->name, "stream:error")) {
|
|
183 jabber_stream_handle_error(js, packet);
|
|
184 } else if (!strcmp(packet->name, "error") &&
|
|
185 !strcmp(xmlnode_get_namespace(packet), "http://etherx.jabber.org/streams")) {
|
|
186 jabber_stream_handle_error(js, packet);
|
|
187 } else if(!strcmp(packet->name, "challenge")) {
|
|
188 if(js->state == JABBER_STREAM_AUTHENTICATING)
|
|
189 jabber_auth_handle_challenge(js, packet);
|
|
190 } else if(!strcmp(packet->name, "success")) {
|
|
191 if(js->state == JABBER_STREAM_AUTHENTICATING)
|
|
192 jabber_auth_handle_success(js, packet);
|
|
193 } else if(!strcmp(packet->name, "failure")) {
|
|
194 if(js->state == JABBER_STREAM_AUTHENTICATING)
|
|
195 jabber_auth_handle_failure(js, packet);
|
|
196 } else if(!strcmp(packet->name, "proceed")) {
|
|
197 if(js->state == JABBER_STREAM_AUTHENTICATING && !js->gsc)
|
|
198 tls_init(js);
|
|
199 } else {
|
|
200 gaim_debug(GAIM_DEBUG_WARNING, "jabber", "Unknown packet: %s\n",
|
|
201 packet->name);
|
|
202 }
|
|
203 }
|
|
204
|
|
205 static int jabber_do_send(JabberStream *js, const char *data, int len)
|
|
206 {
|
|
207 int ret;
|
|
208
|
|
209 if (js->gsc)
|
|
210 ret = gaim_ssl_write(js->gsc, data, len);
|
|
211 else
|
|
212 ret = write(js->fd, data, len);
|
|
213
|
|
214 return ret;
|
|
215 }
|
|
216
|
|
217 static void jabber_send_cb(gpointer data, gint source, GaimInputCondition cond)
|
|
218 {
|
|
219 JabberStream *js = data;
|
|
220 int ret, writelen;
|
|
221 writelen = gaim_circ_buffer_get_max_read(js->write_buffer);
|
|
222
|
|
223 if (writelen == 0) {
|
|
224 gaim_input_remove(js->writeh);
|
|
225 js->writeh = 0;
|
|
226 return;
|
|
227 }
|
|
228
|
|
229 ret = jabber_do_send(js, js->write_buffer->outptr, writelen);
|
|
230
|
|
231 if (ret < 0 && errno == EAGAIN)
|
|
232 return;
|
|
233 else if (ret <= 0) {
|
|
234 gaim_connection_error(js->gc, _("Write error"));
|
|
235 return;
|
|
236 }
|
|
237
|
|
238 gaim_circ_buffer_mark_read(js->write_buffer, ret);
|
|
239 }
|
|
240
|
|
241 void jabber_send_raw(JabberStream *js, const char *data, int len)
|
|
242 {
|
|
243 int ret;
|
|
244
|
|
245 /* because printing a tab to debug every minute gets old */
|
|
246 if(strcmp(data, "\t"))
|
|
247 gaim_debug(GAIM_DEBUG_MISC, "jabber", "Sending%s: %s\n",
|
|
248 js->gsc ? " (ssl)" : "", data);
|
|
249
|
|
250 /* If we've got a security layer, we need to encode the data,
|
|
251 * splitting it on the maximum buffer length negotiated */
|
|
252
|
|
253 #ifdef HAVE_CYRUS_SASL
|
|
254 if (js->sasl_maxbuf>0) {
|
|
255 int pos;
|
|
256
|
|
257 if (!js->gsc && js->fd<0)
|
|
258 return;
|
|
259 pos = 0;
|
|
260 if (len == -1)
|
|
261 len = strlen(data);
|
|
262 while (pos < len) {
|
|
263 int towrite;
|
|
264 const char *out;
|
|
265 unsigned olen;
|
|
266
|
|
267 if ((len - pos) < js->sasl_maxbuf)
|
|
268 towrite = len - pos;
|
|
269 else
|
|
270 towrite = js->sasl_maxbuf;
|
|
271
|
|
272 sasl_encode(js->sasl, &data[pos], towrite, &out, &olen);
|
|
273 pos += towrite;
|
|
274
|
|
275 if (js->writeh > 0)
|
|
276 ret = jabber_do_send(js, out, olen);
|
|
277 else {
|
|
278 ret = -1;
|
|
279 errno = EAGAIN;
|
|
280 }
|
|
281
|
|
282 if (ret < 0 && errno != EAGAIN)
|
|
283 gaim_connection_error(js->gc, _("Write error"));
|
|
284 else if (ret < olen) {
|
|
285 if (ret < 0)
|
|
286 ret = 0;
|
|
287 if (js->writeh == 0)
|
|
288 js->writeh = gaim_input_add(
|
|
289 js->gsc ? js->gsc->fd : js->fd,
|
|
290 GAIM_INPUT_WRITE,
|
|
291 jabber_send_cb, js);
|
|
292 gaim_circ_buffer_append(js->write_buffer,
|
|
293 out + ret, olen - ret);
|
|
294 }
|
|
295 }
|
|
296 return;
|
|
297 }
|
|
298 #endif
|
|
299
|
|
300 if (len == -1)
|
|
301 len = strlen(data);
|
|
302
|
|
303 if (js->writeh == 0)
|
|
304 ret = jabber_do_send(js, data, len);
|
|
305 else {
|
|
306 ret = -1;
|
|
307 errno = EAGAIN;
|
|
308 }
|
|
309
|
|
310 if (ret < 0 && errno != EAGAIN)
|
|
311 gaim_connection_error(js->gc, _("Write error"));
|
|
312 else if (ret < len) {
|
|
313 if (ret < 0)
|
|
314 ret = 0;
|
|
315 if (js->writeh == 0)
|
|
316 js->writeh = gaim_input_add(
|
|
317 js->gsc ? js->gsc->fd : js->fd,
|
|
318 GAIM_INPUT_WRITE, jabber_send_cb, js);
|
|
319 gaim_circ_buffer_append(js->write_buffer,
|
|
320 data + ret, len - ret);
|
|
321 }
|
|
322
|
|
323 }
|
|
324
|
|
325 void jabber_send(JabberStream *js, xmlnode *packet)
|
|
326 {
|
|
327 char *txt;
|
|
328 int len;
|
|
329
|
|
330 txt = xmlnode_to_str(packet, &len);
|
|
331 jabber_send_raw(js, txt, len);
|
|
332 g_free(txt);
|
|
333 }
|
|
334
|
|
335 static void jabber_keepalive(GaimConnection *gc)
|
|
336 {
|
|
337 jabber_send_raw(gc->proto_data, "\t", -1);
|
|
338 }
|
|
339
|
|
340 static void
|
|
341 jabber_recv_cb_ssl(gpointer data, GaimSslConnection *gsc,
|
|
342 GaimInputCondition cond)
|
|
343 {
|
|
344 GaimConnection *gc = data;
|
|
345 JabberStream *js = gc->proto_data;
|
|
346 int len;
|
|
347 static char buf[4096];
|
|
348
|
|
349 /* TODO: It should be possible to make this check unnecessary */
|
|
350 if(!GAIM_CONNECTION_IS_VALID(gc)) {
|
|
351 gaim_ssl_close(gsc);
|
|
352 return;
|
|
353 }
|
|
354
|
|
355 while((len = gaim_ssl_read(gsc, buf, sizeof(buf) - 1)) > 0) {
|
|
356 buf[len] = '\0';
|
|
357 gaim_debug(GAIM_DEBUG_INFO, "jabber", "Recv (ssl)(%d): %s\n", len, buf);
|
|
358 jabber_parser_process(js, buf, len);
|
|
359 if(js->reinit)
|
|
360 jabber_stream_init(js);
|
|
361 }
|
|
362
|
|
363 if(errno == EAGAIN)
|
|
364 return;
|
|
365 else
|
|
366 gaim_connection_error(gc, _("Read Error"));
|
|
367 }
|
|
368
|
|
369 static void
|
|
370 jabber_recv_cb(gpointer data, gint source, GaimInputCondition condition)
|
|
371 {
|
|
372 GaimConnection *gc = data;
|
|
373 JabberStream *js = gc->proto_data;
|
|
374 int len;
|
|
375 static char buf[4096];
|
|
376
|
|
377 if(!GAIM_CONNECTION_IS_VALID(gc))
|
|
378 return;
|
|
379
|
|
380 if((len = read(js->fd, buf, sizeof(buf) - 1)) > 0) {
|
|
381 #ifdef HAVE_CYRUS_SASL
|
|
382 if (js->sasl_maxbuf>0) {
|
|
383 const char *out;
|
|
384 int olen;
|
|
385 sasl_decode(js->sasl, buf, len, &out, &olen);
|
|
386 if (olen>0) {
|
|
387 gaim_debug(GAIM_DEBUG_INFO, "jabber", "RecvSASL (%d): %s\n", olen, out);
|
|
388 jabber_parser_process(js,out,olen);
|
|
389 }
|
|
390 return;
|
|
391 }
|
|
392 #endif
|
|
393 buf[len] = '\0';
|
|
394 gaim_debug(GAIM_DEBUG_INFO, "jabber", "Recv (%d): %s\n", len, buf);
|
|
395 jabber_parser_process(js, buf, len);
|
|
396 } else if(errno == EAGAIN) {
|
|
397 return;
|
|
398 } else {
|
|
399 gaim_connection_error(gc, _("Read Error"));
|
|
400 }
|
|
401 }
|
|
402
|
|
403 static void
|
|
404 jabber_login_callback_ssl(gpointer data, GaimSslConnection *gsc,
|
|
405 GaimInputCondition cond)
|
|
406 {
|
|
407 GaimConnection *gc = data;
|
|
408 JabberStream *js = gc->proto_data;
|
|
409
|
|
410 if(js->state == JABBER_STREAM_CONNECTING)
|
|
411 jabber_send_raw(js, "<?xml version='1.0' ?>", -1);
|
|
412 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING);
|
|
413 gaim_ssl_input_add(gsc, jabber_recv_cb_ssl, gc);
|
|
414 }
|
|
415
|
|
416
|
|
417 static void
|
|
418 jabber_login_callback(gpointer data, gint source, const gchar *error)
|
|
419 {
|
|
420 GaimConnection *gc = data;
|
|
421 JabberStream *js = gc->proto_data;
|
|
422
|
14262
|
423 js->connect_data = NULL;
|
14192
|
424
|
|
425 if (source < 0) {
|
|
426 gaim_connection_error(gc, _("Couldn't connect to host"));
|
|
427 return;
|
|
428 }
|
|
429
|
|
430 js->fd = source;
|
|
431
|
|
432 if(js->state == JABBER_STREAM_CONNECTING)
|
|
433 jabber_send_raw(js, "<?xml version='1.0' ?>", -1);
|
|
434
|
|
435 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING);
|
|
436 gc->inpa = gaim_input_add(js->fd, GAIM_INPUT_READ, jabber_recv_cb, gc);
|
|
437 }
|
|
438
|
|
439 static void
|
|
440 jabber_ssl_connect_failure(GaimSslConnection *gsc, GaimSslErrorType error,
|
|
441 gpointer data)
|
|
442 {
|
|
443 GaimConnection *gc = data;
|
|
444 JabberStream *js = gc->proto_data;
|
|
445
|
14250
|
446 js->gsc = NULL;
|
|
447
|
14192
|
448 switch(error) {
|
|
449 case GAIM_SSL_CONNECT_FAILED:
|
|
450 gaim_connection_error(gc, _("Connection Failed"));
|
|
451 break;
|
|
452 case GAIM_SSL_HANDSHAKE_FAILED:
|
|
453 gaim_connection_error(gc, _("SSL Handshake Failed"));
|
|
454 break;
|
|
455 }
|
|
456 }
|
|
457
|
|
458 static void tls_init(JabberStream *js)
|
|
459 {
|
|
460 gaim_input_remove(js->gc->inpa);
|
|
461 js->gc->inpa = 0;
|
|
462 js->gsc = gaim_ssl_connect_fd(js->gc->account, js->fd,
|
|
463 jabber_login_callback_ssl, jabber_ssl_connect_failure, js->gc);
|
|
464 }
|
|
465
|
|
466 static void jabber_login_connect(JabberStream *js, const char *server, int port)
|
|
467 {
|
14262
|
468 js->connect_data = gaim_proxy_connect(js->gc->account, server,
|
14192
|
469 port, jabber_login_callback, js->gc);
|
|
470
|
14262
|
471 if (js->connect_data == NULL)
|
14192
|
472 gaim_connection_error(js->gc, _("Unable to create socket"));
|
|
473 }
|
|
474
|
|
475 static void srv_resolved_cb(GaimSrvResponse *resp, int results, gpointer data)
|
|
476 {
|
|
477 GaimConnection *gc;
|
|
478 JabberStream *js;
|
|
479
|
|
480 gc = data;
|
|
481 if (!GAIM_CONNECTION_IS_VALID(gc))
|
|
482 {
|
|
483 /* This connection has been closed */
|
|
484 g_free(resp);
|
|
485 return;
|
|
486 }
|
|
487
|
|
488 js = (JabberStream*)gc->proto_data;
|
|
489
|
|
490 if(results) {
|
|
491 jabber_login_connect(js, resp->hostname, resp->port);
|
|
492 g_free(resp);
|
|
493 } else {
|
|
494 jabber_login_connect(js, js->user->domain,
|
|
495 gaim_account_get_int(js->gc->account, "port", 5222));
|
|
496 }
|
|
497 }
|
|
498
|
|
499
|
|
500
|
|
501 static void
|
|
502 jabber_login(GaimAccount *account)
|
|
503 {
|
|
504 GaimConnection *gc = gaim_account_get_connection(account);
|
|
505 const char *connect_server = gaim_account_get_string(account,
|
|
506 "connect_server", "");
|
|
507 JabberStream *js;
|
|
508 JabberBuddy *my_jb = NULL;
|
|
509
|
|
510 gc->flags |= GAIM_CONNECTION_HTML;
|
|
511 js = gc->proto_data = g_new0(JabberStream, 1);
|
|
512 js->gc = gc;
|
|
513 js->fd = -1;
|
|
514 js->iq_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal,
|
|
515 g_free, g_free);
|
|
516 js->disco_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal,
|
|
517 g_free, g_free);
|
|
518 js->buddies = g_hash_table_new_full(g_str_hash, g_str_equal,
|
|
519 g_free, (GDestroyNotify)jabber_buddy_free);
|
|
520 js->chats = g_hash_table_new_full(g_str_hash, g_str_equal,
|
|
521 g_free, (GDestroyNotify)jabber_chat_free);
|
|
522 js->chat_servers = g_list_append(NULL, g_strdup("conference.jabber.org"));
|
|
523 js->user = jabber_id_new(gaim_account_get_username(account));
|
|
524 js->next_id = g_random_int();
|
|
525 js->write_buffer = gaim_circ_buffer_new(512);
|
|
526
|
|
527 if(!js->user) {
|
|
528 gaim_connection_error(gc, _("Invalid Jabber ID"));
|
|
529 return;
|
|
530 }
|
|
531
|
|
532 if(!js->user->resource) {
|
|
533 char *me;
|
|
534 js->user->resource = g_strdup("Home");
|
|
535 if(!js->user->node) {
|
|
536 js->user->node = js->user->domain;
|
|
537 js->user->domain = g_strdup("jabber.org");
|
|
538 }
|
|
539 me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain,
|
|
540 js->user->resource);
|
|
541 gaim_account_set_username(account, me);
|
|
542 g_free(me);
|
|
543 }
|
|
544
|
|
545 if((my_jb = jabber_buddy_find(js, gaim_account_get_username(account), TRUE)))
|
|
546 my_jb->subscription |= JABBER_SUB_BOTH;
|
|
547
|
|
548 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING);
|
|
549
|
|
550 /* if they've got old-ssl mode going, we probably want to ignore SRV lookups */
|
|
551 if(gaim_account_get_bool(js->gc->account, "old_ssl", FALSE)) {
|
|
552 if(gaim_ssl_is_supported()) {
|
|
553 js->gsc = gaim_ssl_connect(js->gc->account,
|
|
554 connect_server[0] ? connect_server : js->user->domain,
|
|
555 gaim_account_get_int(account, "port", 5223), jabber_login_callback_ssl,
|
|
556 jabber_ssl_connect_failure, js->gc);
|
|
557 } else {
|
|
558 gaim_connection_error(js->gc, _("SSL support unavailable"));
|
|
559 }
|
|
560 }
|
|
561
|
|
562 /* no old-ssl, so if they've specified a connect server, we'll use that, otherwise we'll
|
|
563 * invoke the magic of SRV lookups, to figure out host and port */
|
|
564 if(!js->gsc) {
|
|
565 if(connect_server[0]) {
|
|
566 jabber_login_connect(js, connect_server, gaim_account_get_int(account, "port", 5222));
|
|
567 } else {
|
|
568 gaim_srv_resolve("xmpp-client", "tcp", js->user->domain, srv_resolved_cb, gc);
|
|
569 }
|
|
570 }
|
|
571 }
|
|
572
|
|
573
|
|
574 static gboolean
|
|
575 conn_close_cb(gpointer data)
|
|
576 {
|
|
577 JabberStream *js = data;
|
|
578 GaimAccount *account = gaim_connection_get_account(js->gc);
|
|
579
|
|
580 gaim_account_disconnect(account);
|
|
581
|
|
582 return FALSE;
|
|
583 }
|
|
584
|
|
585 static void
|
|
586 jabber_connection_schedule_close(JabberStream *js)
|
|
587 {
|
|
588 gaim_timeout_add(0, conn_close_cb, js);
|
|
589 }
|
|
590
|
|
591 static void
|
|
592 jabber_registration_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
|
|
593 {
|
|
594 const char *type = xmlnode_get_attrib(packet, "type");
|
|
595 char *buf;
|
|
596
|
|
597 if(!strcmp(type, "result")) {
|
|
598 buf = g_strdup_printf(_("Registration of %s@%s successful"),
|
|
599 js->user->node, js->user->domain);
|
|
600 gaim_notify_info(NULL, _("Registration Successful"),
|
|
601 _("Registration Successful"), buf);
|
|
602 g_free(buf);
|
|
603 } else {
|
|
604 char *msg = jabber_parse_error(js, packet);
|
|
605
|
|
606 if(!msg)
|
|
607 msg = g_strdup(_("Unknown Error"));
|
|
608
|
|
609 gaim_notify_error(NULL, _("Registration Failed"),
|
|
610 _("Registration Failed"), msg);
|
|
611 g_free(msg);
|
|
612 }
|
|
613 jabber_connection_schedule_close(js);
|
|
614 }
|
|
615
|
|
616 static void
|
|
617 jabber_register_cb(JabberStream *js, GaimRequestFields *fields)
|
|
618 {
|
|
619 GList *groups, *flds;
|
|
620 xmlnode *query, *y;
|
|
621 JabberIq *iq;
|
|
622 char *username;
|
|
623
|
|
624 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register");
|
|
625 query = xmlnode_get_child(iq->node, "query");
|
|
626
|
|
627 for(groups = gaim_request_fields_get_groups(fields); groups;
|
|
628 groups = groups->next) {
|
|
629 for(flds = gaim_request_field_group_get_fields(groups->data);
|
|
630 flds; flds = flds->next) {
|
|
631 GaimRequestField *field = flds->data;
|
|
632 const char *id = gaim_request_field_get_id(field);
|
|
633 const char *value = gaim_request_field_string_get_value(field);
|
|
634
|
|
635 if(!strcmp(id, "username")) {
|
|
636 y = xmlnode_new_child(query, "username");
|
|
637 } else if(!strcmp(id, "password")) {
|
|
638 y = xmlnode_new_child(query, "password");
|
|
639 } else if(!strcmp(id, "name")) {
|
|
640 y = xmlnode_new_child(query, "name");
|
|
641 } else if(!strcmp(id, "email")) {
|
|
642 y = xmlnode_new_child(query, "email");
|
|
643 } else if(!strcmp(id, "nick")) {
|
|
644 y = xmlnode_new_child(query, "nick");
|
|
645 } else if(!strcmp(id, "first")) {
|
|
646 y = xmlnode_new_child(query, "first");
|
|
647 } else if(!strcmp(id, "last")) {
|
|
648 y = xmlnode_new_child(query, "last");
|
|
649 } else if(!strcmp(id, "address")) {
|
|
650 y = xmlnode_new_child(query, "address");
|
|
651 } else if(!strcmp(id, "city")) {
|
|
652 y = xmlnode_new_child(query, "city");
|
|
653 } else if(!strcmp(id, "state")) {
|
|
654 y = xmlnode_new_child(query, "state");
|
|
655 } else if(!strcmp(id, "zip")) {
|
|
656 y = xmlnode_new_child(query, "zip");
|
|
657 } else if(!strcmp(id, "phone")) {
|
|
658 y = xmlnode_new_child(query, "phone");
|
|
659 } else if(!strcmp(id, "url")) {
|
|
660 y = xmlnode_new_child(query, "url");
|
|
661 } else if(!strcmp(id, "date")) {
|
|
662 y = xmlnode_new_child(query, "date");
|
|
663 } else {
|
|
664 continue;
|
|
665 }
|
|
666 xmlnode_insert_data(y, value, -1);
|
|
667 if(!strcmp(id, "username")) {
|
|
668 if(js->user->node)
|
|
669 g_free(js->user->node);
|
|
670 js->user->node = g_strdup(value);
|
|
671 }
|
|
672 }
|
|
673 }
|
|
674
|
|
675 username = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain,
|
|
676 js->user->resource);
|
|
677 gaim_account_set_username(js->gc->account, username);
|
|
678 g_free(username);
|
|
679
|
|
680 jabber_iq_set_callback(iq, jabber_registration_result_cb, NULL);
|
|
681
|
|
682 jabber_iq_send(iq);
|
|
683
|
|
684 }
|
|
685
|
|
686 static void
|
|
687 jabber_register_cancel_cb(JabberStream *js, GaimRequestFields *fields)
|
|
688 {
|
|
689 jabber_connection_schedule_close(js);
|
|
690 }
|
|
691
|
|
692 static void jabber_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data)
|
|
693 {
|
|
694 xmlnode *query;
|
|
695 JabberIq *iq;
|
|
696
|
|
697 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register");
|
|
698 query = xmlnode_get_child(iq->node, "query");
|
|
699
|
|
700 xmlnode_insert_child(query, result);
|
|
701
|
|
702 jabber_iq_set_callback(iq, jabber_registration_result_cb, NULL);
|
|
703 jabber_iq_send(iq);
|
|
704 }
|
|
705
|
|
706 void jabber_register_parse(JabberStream *js, xmlnode *packet)
|
|
707 {
|
14294
|
708 const char *type;
|
|
709 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result"))
|
|
710 return;
|
|
711
|
14192
|
712 if(js->registration) {
|
|
713 GaimRequestFields *fields;
|
|
714 GaimRequestFieldGroup *group;
|
|
715 GaimRequestField *field;
|
|
716 xmlnode *query, *x, *y;
|
|
717 char *instructions;
|
|
718
|
|
719 /* get rid of the login thingy */
|
|
720 gaim_connection_set_state(js->gc, GAIM_CONNECTED);
|
|
721
|
|
722 query = xmlnode_get_child(packet, "query");
|
|
723
|
|
724 if(xmlnode_get_child(query, "registered")) {
|
|
725 gaim_notify_error(NULL, _("Already Registered"),
|
|
726 _("Already Registered"), NULL);
|
|
727 jabber_connection_schedule_close(js);
|
|
728 return;
|
|
729 }
|
|
730
|
|
731 if((x = xmlnode_get_child_with_namespace(packet, "x",
|
|
732 "jabber:x:data"))) {
|
|
733 jabber_x_data_request(js, x, jabber_register_x_data_cb, NULL);
|
|
734 return;
|
|
735 } else if((x = xmlnode_get_child_with_namespace(packet, "x",
|
|
736 "jabber:x:oob"))) {
|
|
737 xmlnode *url;
|
|
738
|
|
739 if((url = xmlnode_get_child(x, "url"))) {
|
|
740 char *href;
|
|
741 if((href = xmlnode_get_data(url))) {
|
|
742 gaim_notify_uri(NULL, href);
|
|
743 g_free(href);
|
|
744 js->gc->wants_to_die = TRUE;
|
|
745 jabber_connection_schedule_close(js);
|
|
746 return;
|
|
747 }
|
|
748 }
|
|
749 }
|
|
750
|
|
751 /* as a last resort, use the old jabber:iq:register syntax */
|
|
752
|
|
753 fields = gaim_request_fields_new();
|
|
754 group = gaim_request_field_group_new(NULL);
|
|
755 gaim_request_fields_add_group(fields, group);
|
|
756
|
|
757 field = gaim_request_field_string_new("username", _("Username"),
|
|
758 js->user->node, FALSE);
|
|
759 gaim_request_field_group_add_field(group, field);
|
|
760
|
|
761 field = gaim_request_field_string_new("password", _("Password"),
|
|
762 gaim_connection_get_password(js->gc), FALSE);
|
|
763 gaim_request_field_string_set_masked(field, TRUE);
|
|
764 gaim_request_field_group_add_field(group, field);
|
|
765
|
|
766 if(xmlnode_get_child(query, "name")) {
|
|
767 field = gaim_request_field_string_new("name", _("Name"),
|
|
768 gaim_account_get_alias(js->gc->account), FALSE);
|
|
769 gaim_request_field_group_add_field(group, field);
|
|
770 }
|
|
771 if(xmlnode_get_child(query, "email")) {
|
|
772 field = gaim_request_field_string_new("email", _("E-mail"),
|
|
773 NULL, FALSE);
|
|
774 gaim_request_field_group_add_field(group, field);
|
|
775 }
|
|
776 if(xmlnode_get_child(query, "nick")) {
|
|
777 field = gaim_request_field_string_new("nick", _("Nickname"),
|
|
778 NULL, FALSE);
|
|
779 gaim_request_field_group_add_field(group, field);
|
|
780 }
|
|
781 if(xmlnode_get_child(query, "first")) {
|
|
782 field = gaim_request_field_string_new("first", _("First name"),
|
|
783 NULL, FALSE);
|
|
784 gaim_request_field_group_add_field(group, field);
|
|
785 }
|
|
786 if(xmlnode_get_child(query, "last")) {
|
|
787 field = gaim_request_field_string_new("last", _("Last name"),
|
|
788 NULL, FALSE);
|
|
789 gaim_request_field_group_add_field(group, field);
|
|
790 }
|
|
791 if(xmlnode_get_child(query, "address")) {
|
|
792 field = gaim_request_field_string_new("address", _("Address"),
|
|
793 NULL, FALSE);
|
|
794 gaim_request_field_group_add_field(group, field);
|
|
795 }
|
|
796 if(xmlnode_get_child(query, "city")) {
|
|
797 field = gaim_request_field_string_new("city", _("City"),
|
|
798 NULL, FALSE);
|
|
799 gaim_request_field_group_add_field(group, field);
|
|
800 }
|
|
801 if(xmlnode_get_child(query, "state")) {
|
|
802 field = gaim_request_field_string_new("state", _("State"),
|
|
803 NULL, FALSE);
|
|
804 gaim_request_field_group_add_field(group, field);
|
|
805 }
|
|
806 if(xmlnode_get_child(query, "zip")) {
|
|
807 field = gaim_request_field_string_new("zip", _("Postal code"),
|
|
808 NULL, FALSE);
|
|
809 gaim_request_field_group_add_field(group, field);
|
|
810 }
|
|
811 if(xmlnode_get_child(query, "phone")) {
|
|
812 field = gaim_request_field_string_new("phone", _("Phone"),
|
|
813 NULL, FALSE);
|
|
814 gaim_request_field_group_add_field(group, field);
|
|
815 }
|
|
816 if(xmlnode_get_child(query, "url")) {
|
|
817 field = gaim_request_field_string_new("url", _("URL"),
|
|
818 NULL, FALSE);
|
|
819 gaim_request_field_group_add_field(group, field);
|
|
820 }
|
|
821 if(xmlnode_get_child(query, "date")) {
|
|
822 field = gaim_request_field_string_new("date", _("Date"),
|
|
823 NULL, FALSE);
|
|
824 gaim_request_field_group_add_field(group, field);
|
|
825 }
|
|
826
|
|
827 if((y = xmlnode_get_child(query, "instructions")))
|
|
828 instructions = xmlnode_get_data(y);
|
|
829 else
|
|
830 instructions = g_strdup(_("Please fill out the information below "
|
|
831 "to register your new account."));
|
|
832
|
|
833 gaim_request_fields(js->gc, _("Register New Jabber Account"),
|
|
834 _("Register New Jabber Account"), instructions, fields,
|
|
835 _("Register"), G_CALLBACK(jabber_register_cb),
|
|
836 _("Cancel"), G_CALLBACK(jabber_register_cancel_cb), js);
|
|
837
|
|
838 g_free(instructions);
|
|
839 }
|
|
840 }
|
|
841
|
|
842 void jabber_register_start(JabberStream *js)
|
|
843 {
|
|
844 JabberIq *iq;
|
|
845
|
|
846 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:register");
|
|
847 jabber_iq_send(iq);
|
|
848 }
|
|
849
|
|
850 static void jabber_register_account(GaimAccount *account)
|
|
851 {
|
|
852 GaimConnection *gc = gaim_account_get_connection(account);
|
|
853 JabberStream *js;
|
|
854 JabberBuddy *my_jb = NULL;
|
|
855 const char *connect_server = gaim_account_get_string(account,
|
|
856 "connect_server", "");
|
|
857 const char *server;
|
|
858
|
|
859 js = gc->proto_data = g_new0(JabberStream, 1);
|
|
860 js->gc = gc;
|
|
861 js->registration = TRUE;
|
|
862 js->iq_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal,
|
|
863 g_free, g_free);
|
|
864 js->disco_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal,
|
|
865 g_free, g_free);
|
|
866 js->user = jabber_id_new(gaim_account_get_username(account));
|
|
867 js->next_id = g_random_int();
|
|
868
|
|
869 if(!js->user) {
|
|
870 gaim_connection_error(gc, _("Invalid Jabber ID"));
|
|
871 return;
|
|
872 }
|
|
873
|
|
874 js->write_buffer = gaim_circ_buffer_new(512);
|
|
875
|
|
876 if(!js->user->resource) {
|
|
877 char *me;
|
|
878 js->user->resource = g_strdup("Home");
|
|
879 if(!js->user->node) {
|
|
880 js->user->node = js->user->domain;
|
|
881 js->user->domain = g_strdup("jabber.org");
|
|
882 }
|
|
883 me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain,
|
|
884 js->user->resource);
|
|
885 gaim_account_set_username(account, me);
|
|
886 g_free(me);
|
|
887 }
|
|
888
|
|
889 if((my_jb = jabber_buddy_find(js, gaim_account_get_username(account), TRUE)))
|
|
890 my_jb->subscription |= JABBER_SUB_BOTH;
|
|
891
|
|
892 server = connect_server[0] ? connect_server : js->user->domain;
|
|
893
|
|
894 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING);
|
|
895
|
|
896 if(gaim_account_get_bool(account, "old_ssl", FALSE)) {
|
|
897 if(gaim_ssl_is_supported()) {
|
|
898 js->gsc = gaim_ssl_connect(account, server,
|
|
899 gaim_account_get_int(account, "port", 5222),
|
|
900 jabber_login_callback_ssl, jabber_ssl_connect_failure, gc);
|
|
901 } else {
|
|
902 gaim_connection_error(gc, _("SSL support unavailable"));
|
|
903 }
|
|
904 }
|
|
905
|
|
906 if(!js->gsc) {
|
14262
|
907 js->connect_data = gaim_proxy_connect(account, server,
|
14192
|
908 gaim_account_get_int(account, "port", 5222),
|
|
909 jabber_login_callback, gc);
|
|
910
|
14262
|
911 if (js->connect_data == NULL)
|
14192
|
912 gaim_connection_error(gc, _("Unable to create socket"));
|
|
913 }
|
|
914 }
|
|
915
|
|
916 static void jabber_close(GaimConnection *gc)
|
|
917 {
|
|
918 JabberStream *js = gc->proto_data;
|
|
919
|
|
920 /* Don't perform any actions on the ssl connection
|
|
921 * if we were forcibly disconnected because it will crash
|
|
922 * on some SSL backends.
|
|
923 */
|
|
924 if (!gc->disconnect_timeout)
|
|
925 jabber_send_raw(js, "</stream:stream>", -1);
|
|
926
|
14262
|
927 if (js->connect_data)
|
|
928 gaim_proxy_connect_cancel(js->connect_data);
|
14192
|
929
|
|
930 if(js->gsc) {
|
|
931 #ifdef HAVE_OPENSSL
|
|
932 if (!gc->disconnect_timeout)
|
|
933 #endif
|
|
934 gaim_ssl_close(js->gsc);
|
|
935 } else if (js->fd > 0) {
|
|
936 if(js->gc->inpa)
|
|
937 gaim_input_remove(js->gc->inpa);
|
|
938 close(js->fd);
|
|
939 }
|
|
940 #ifndef HAVE_LIBXML
|
|
941 if(js->context)
|
|
942 g_markup_parse_context_free(js->context);
|
|
943 #endif
|
|
944 if(js->iq_callbacks)
|
|
945 g_hash_table_destroy(js->iq_callbacks);
|
|
946 if(js->disco_callbacks)
|
|
947 g_hash_table_destroy(js->disco_callbacks);
|
|
948 if(js->buddies)
|
|
949 g_hash_table_destroy(js->buddies);
|
|
950 if(js->chats)
|
|
951 g_hash_table_destroy(js->chats);
|
|
952 while(js->chat_servers) {
|
|
953 g_free(js->chat_servers->data);
|
|
954 js->chat_servers = g_list_delete_link(js->chat_servers, js->chat_servers);
|
|
955 }
|
|
956 while(js->user_directories) {
|
|
957 g_free(js->user_directories->data);
|
|
958 js->user_directories = g_list_delete_link(js->user_directories, js->user_directories);
|
|
959 }
|
|
960 if(js->stream_id)
|
|
961 g_free(js->stream_id);
|
|
962 if(js->user)
|
|
963 jabber_id_free(js->user);
|
|
964 if(js->avatar_hash)
|
|
965 g_free(js->avatar_hash);
|
|
966 gaim_circ_buffer_destroy(js->write_buffer);
|
|
967 if(js->writeh)
|
|
968 gaim_input_remove(js->writeh);
|
|
969 #ifdef HAVE_CYRUS_SASL
|
|
970 if(js->sasl)
|
|
971 sasl_dispose(&js->sasl);
|
|
972 if(js->sasl_mechs)
|
|
973 g_string_free(js->sasl_mechs, TRUE);
|
|
974 if(js->sasl_cb)
|
|
975 g_free(js->sasl_cb);
|
|
976 #endif
|
|
977 g_free(js);
|
|
978
|
|
979 gc->proto_data = NULL;
|
|
980 }
|
|
981
|
|
982 void jabber_stream_set_state(JabberStream *js, JabberStreamState state)
|
|
983 {
|
|
984 GaimPresence *gpresence;
|
|
985 GaimStatus *status;
|
|
986
|
|
987 js->state = state;
|
|
988 switch(state) {
|
|
989 case JABBER_STREAM_OFFLINE:
|
|
990 break;
|
|
991 case JABBER_STREAM_CONNECTING:
|
|
992 gaim_connection_update_progress(js->gc, _("Connecting"), 1,
|
|
993 JABBER_CONNECT_STEPS);
|
|
994 break;
|
|
995 case JABBER_STREAM_INITIALIZING:
|
|
996 gaim_connection_update_progress(js->gc, _("Initializing Stream"),
|
|
997 js->gsc ? 5 : 2, JABBER_CONNECT_STEPS);
|
|
998 jabber_stream_init(js);
|
|
999 break;
|
|
1000 case JABBER_STREAM_AUTHENTICATING:
|
|
1001 gaim_connection_update_progress(js->gc, _("Authenticating"),
|
|
1002 js->gsc ? 6 : 3, JABBER_CONNECT_STEPS);
|
|
1003 if(js->protocol_version == JABBER_PROTO_0_9 && js->registration) {
|
|
1004 jabber_register_start(js);
|
|
1005 } else if(js->auth_type == JABBER_AUTH_IQ_AUTH) {
|
|
1006 jabber_auth_start_old(js);
|
|
1007 }
|
|
1008 break;
|
|
1009 case JABBER_STREAM_REINITIALIZING:
|
|
1010 gaim_connection_update_progress(js->gc, _("Re-initializing Stream"),
|
|
1011 (js->gsc ? 7 : 4), JABBER_CONNECT_STEPS);
|
|
1012 if (js->gsc) {
|
|
1013 /* The stream will be reinitialized later, in jabber_recv_cb_ssl() */
|
|
1014 js->reinit = TRUE;
|
|
1015 } else {
|
|
1016 jabber_stream_init(js);
|
|
1017 }
|
|
1018 break;
|
|
1019 case JABBER_STREAM_CONNECTED:
|
|
1020 jabber_roster_request(js);
|
|
1021 gpresence = gaim_account_get_presence(js->gc->account);
|
|
1022 status = gaim_presence_get_active_status(gpresence);
|
|
1023 jabber_presence_send(js->gc->account, status);
|
|
1024 gaim_connection_set_state(js->gc, GAIM_CONNECTED);
|
|
1025 jabber_disco_items_server(js);
|
|
1026 break;
|
|
1027 }
|
|
1028 }
|
|
1029
|
|
1030 char *jabber_get_next_id(JabberStream *js)
|
|
1031 {
|
|
1032 return g_strdup_printf("gaim%x", js->next_id++);
|
|
1033 }
|
|
1034
|
|
1035
|
|
1036 static void jabber_idle_set(GaimConnection *gc, int idle)
|
|
1037 {
|
|
1038 JabberStream *js = gc->proto_data;
|
|
1039
|
|
1040 js->idle = idle ? time(NULL) - idle : idle;
|
|
1041 }
|
|
1042
|
|
1043 static const char *jabber_list_icon(GaimAccount *a, GaimBuddy *b)
|
|
1044 {
|
|
1045 return "jabber";
|
|
1046 }
|
|
1047
|
|
1048 static void jabber_list_emblems(GaimBuddy *b, const char **se, const char **sw,
|
|
1049 const char **nw, const char **ne)
|
|
1050 {
|
|
1051 JabberStream *js;
|
|
1052 JabberBuddy *jb = NULL;
|
|
1053
|
|
1054 if(!b->account->gc)
|
|
1055 return;
|
|
1056 js = b->account->gc->proto_data;
|
|
1057 if(js)
|
|
1058 jb = jabber_buddy_find(js, b->name, FALSE);
|
|
1059
|
|
1060 if(!GAIM_BUDDY_IS_ONLINE(b)) {
|
|
1061 if(jb && jb->error_msg)
|
|
1062 *nw = "error";
|
|
1063
|
|
1064 if(jb && (jb->subscription & JABBER_SUB_PENDING ||
|
|
1065 !(jb->subscription & JABBER_SUB_TO)))
|
|
1066 *se = "notauthorized";
|
|
1067 else
|
|
1068 *se = "offline";
|
|
1069 } else {
|
|
1070 GaimStatusType *status_type = gaim_status_get_type(gaim_presence_get_active_status(gaim_buddy_get_presence(b)));
|
|
1071 GaimStatusPrimitive primitive = gaim_status_type_get_primitive(status_type);
|
|
1072
|
|
1073 if(primitive > GAIM_STATUS_AVAILABLE) {
|
|
1074 *se = gaim_status_type_get_id(status_type);
|
|
1075 }
|
|
1076 }
|
|
1077 }
|
|
1078
|
|
1079 static char *jabber_status_text(GaimBuddy *b)
|
|
1080 {
|
|
1081 JabberBuddy *jb = jabber_buddy_find(b->account->gc->proto_data, b->name,
|
|
1082 FALSE);
|
|
1083 char *ret = NULL;
|
|
1084
|
|
1085 if(jb && !GAIM_BUDDY_IS_ONLINE(b) && (jb->subscription & JABBER_SUB_PENDING || !(jb->subscription & JABBER_SUB_TO))) {
|
|
1086 ret = g_strdup(_("Not Authorized"));
|
|
1087 } else if(jb && !GAIM_BUDDY_IS_ONLINE(b) && jb->error_msg) {
|
|
1088 ret = g_strdup(jb->error_msg);
|
|
1089 } else {
|
|
1090 char *stripped;
|
|
1091
|
|
1092 if(!(stripped = gaim_markup_strip_html(jabber_buddy_get_status_msg(jb)))) {
|
|
1093 GaimStatus *status = gaim_presence_get_active_status(gaim_buddy_get_presence(b));
|
|
1094
|
|
1095 if(!gaim_status_is_available(status))
|
|
1096 stripped = g_strdup(gaim_status_get_name(status));
|
|
1097 }
|
|
1098
|
|
1099 if(stripped) {
|
|
1100 ret = g_markup_escape_text(stripped, -1);
|
|
1101 g_free(stripped);
|
|
1102 }
|
|
1103 }
|
|
1104
|
|
1105 return ret;
|
|
1106 }
|
|
1107
|
|
1108 static void jabber_tooltip_text(GaimBuddy *b, GString *str, gboolean full)
|
|
1109 {
|
|
1110 JabberBuddy *jb;
|
|
1111
|
|
1112 g_return_if_fail(b != NULL);
|
|
1113 g_return_if_fail(b->account != NULL);
|
|
1114 g_return_if_fail(b->account->gc != NULL);
|
|
1115 g_return_if_fail(b->account->gc->proto_data != NULL);
|
|
1116
|
|
1117 jb = jabber_buddy_find(b->account->gc->proto_data, b->name,
|
|
1118 FALSE);
|
|
1119
|
|
1120 if(jb) {
|
|
1121 JabberBuddyResource *jbr = NULL;
|
|
1122 const char *sub;
|
|
1123 GList *l;
|
|
1124
|
|
1125 if (full) {
|
|
1126 if(jb->subscription & JABBER_SUB_FROM) {
|
|
1127 if(jb->subscription & JABBER_SUB_TO)
|
|
1128 sub = _("Both");
|
|
1129 else if(jb->subscription & JABBER_SUB_PENDING)
|
|
1130 sub = _("From (To pending)");
|
|
1131 else
|
|
1132 sub = _("From");
|
|
1133 } else {
|
|
1134 if(jb->subscription & JABBER_SUB_TO)
|
|
1135 sub = _("To");
|
|
1136 else if(jb->subscription & JABBER_SUB_PENDING)
|
|
1137 sub = _("None (To pending)");
|
|
1138 else
|
|
1139 sub = _("None");
|
|
1140 }
|
|
1141 g_string_append_printf(str, "\n<b>%s:</b> %s", _("Subscription"), sub);
|
|
1142 }
|
|
1143
|
|
1144 for(l=jb->resources; l; l = l->next) {
|
|
1145 char *text = NULL;
|
|
1146 char *res = NULL;
|
|
1147 const char *state;
|
|
1148
|
|
1149 jbr = l->data;
|
|
1150
|
|
1151 if(jbr->status) {
|
|
1152 char *tmp;
|
|
1153 text = gaim_strreplace(jbr->status, "\n", "<br />\n");
|
|
1154 tmp = gaim_markup_strip_html(text);
|
|
1155 g_free(text);
|
|
1156 text = g_markup_escape_text(tmp, -1);
|
|
1157 g_free(tmp);
|
|
1158 }
|
|
1159
|
|
1160 if(jbr->name)
|
|
1161 res = g_strdup_printf(" (%s)", jbr->name);
|
|
1162
|
|
1163 state = jabber_buddy_state_get_name(jbr->state);
|
|
1164 if (text != NULL && !gaim_utf8_strcasecmp(state, text)) {
|
|
1165 g_free(text);
|
|
1166 text = NULL;
|
|
1167 }
|
|
1168
|
|
1169 g_string_append_printf(str, "\n<b>%s%s:</b> %s%s%s",
|
|
1170 _("Status"),
|
|
1171 res ? res : "",
|
|
1172 state,
|
|
1173 text ? ": " : "",
|
|
1174 text ? text : "");
|
|
1175
|
|
1176 g_free(text);
|
|
1177 g_free(res);
|
|
1178 }
|
|
1179
|
|
1180 if(!GAIM_BUDDY_IS_ONLINE(b) && jb->error_msg) {
|
|
1181 g_string_append_printf(str, "\n<b>%s:</b> %s",
|
|
1182 _("Error"), jb->error_msg);
|
|
1183 }
|
|
1184 }
|
|
1185 }
|
|
1186
|
|
1187 static GList *jabber_status_types(GaimAccount *account)
|
|
1188 {
|
|
1189 GaimStatusType *type;
|
|
1190 GList *types = NULL;
|
|
1191 GaimValue *priority_value;
|
|
1192
|
|
1193 priority_value = gaim_value_new(GAIM_TYPE_INT);
|
|
1194 gaim_value_set_int(priority_value, 1);
|
|
1195 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE,
|
|
1196 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_ONLINE),
|
|
1197 NULL, TRUE, TRUE, FALSE,
|
|
1198 "priority", _("Priority"), priority_value,
|
|
1199 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
|
|
1200 NULL);
|
|
1201 types = g_list_append(types, type);
|
|
1202
|
|
1203 priority_value = gaim_value_new(GAIM_TYPE_INT);
|
|
1204 gaim_value_set_int(priority_value, 1);
|
|
1205 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE,
|
|
1206 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_CHAT),
|
|
1207 _("Chatty"), TRUE, TRUE, FALSE,
|
|
1208 "priority", _("Priority"), priority_value,
|
|
1209 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
|
|
1210 NULL);
|
|
1211 types = g_list_append(types, type);
|
|
1212
|
|
1213 priority_value = gaim_value_new(GAIM_TYPE_INT);
|
|
1214 gaim_value_set_int(priority_value, 0);
|
|
1215 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY,
|
|
1216 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_AWAY),
|
|
1217 NULL, TRUE, TRUE, FALSE,
|
|
1218 "priority", _("Priority"), priority_value,
|
|
1219 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
|
|
1220 NULL);
|
|
1221 types = g_list_append(types, type);
|
|
1222
|
|
1223 priority_value = gaim_value_new(GAIM_TYPE_INT);
|
|
1224 gaim_value_set_int(priority_value, 0);
|
|
1225 type = gaim_status_type_new_with_attrs(GAIM_STATUS_EXTENDED_AWAY,
|
|
1226 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_XA),
|
|
1227 NULL, TRUE, TRUE, FALSE,
|
|
1228 "priority", _("Priority"), priority_value,
|
|
1229 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
|
|
1230 NULL);
|
|
1231 types = g_list_append(types, type);
|
|
1232
|
|
1233 priority_value = gaim_value_new(GAIM_TYPE_INT);
|
|
1234 gaim_value_set_int(priority_value, 0);
|
|
1235 type = gaim_status_type_new_with_attrs(GAIM_STATUS_UNAVAILABLE,
|
|
1236 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_DND),
|
|
1237 _("Do Not Disturb"), TRUE, TRUE, FALSE,
|
|
1238 "priority", _("Priority"), priority_value,
|
|
1239 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
|
|
1240 NULL);
|
|
1241 types = g_list_append(types, type);
|
|
1242
|
|
1243 /*
|
|
1244 if(js->protocol_version == JABBER_PROTO_0_9)
|
|
1245 m = g_list_append(m, _("Invisible"));
|
|
1246 */
|
|
1247
|
|
1248 type = gaim_status_type_new_with_attrs(GAIM_STATUS_OFFLINE,
|
|
1249 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_UNAVAILABLE),
|
|
1250 NULL, FALSE, TRUE, FALSE,
|
|
1251 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
|
|
1252 NULL);
|
|
1253 types = g_list_append(types, type);
|
|
1254
|
|
1255 return types;
|
|
1256 }
|
|
1257
|
|
1258 static void
|
|
1259 jabber_password_change_result_cb(JabberStream *js, xmlnode *packet,
|
|
1260 gpointer data)
|
|
1261 {
|
|
1262 const char *type;
|
|
1263
|
|
1264 type = xmlnode_get_attrib(packet, "type");
|
|
1265
|
|
1266 if(type && !strcmp(type, "result")) {
|
|
1267 gaim_notify_info(js->gc, _("Password Changed"), _("Password Changed"),
|
|
1268 _("Your password has been changed."));
|
|
1269 } else {
|
|
1270 char *msg = jabber_parse_error(js, packet);
|
|
1271
|
|
1272 gaim_notify_error(js->gc, _("Error changing password"),
|
|
1273 _("Error changing password"), msg);
|
|
1274 g_free(msg);
|
|
1275 }
|
|
1276 }
|
|
1277
|
|
1278 static void jabber_password_change_cb(JabberStream *js,
|
|
1279 GaimRequestFields *fields)
|
|
1280 {
|
|
1281 const char *p1, *p2;
|
|
1282 JabberIq *iq;
|
|
1283 xmlnode *query, *y;
|
|
1284
|
|
1285 p1 = gaim_request_fields_get_string(fields, "password1");
|
|
1286 p2 = gaim_request_fields_get_string(fields, "password2");
|
|
1287
|
|
1288 if(strcmp(p1, p2)) {
|
|
1289 gaim_notify_error(js->gc, NULL, _("New passwords do not match."), NULL);
|
|
1290 return;
|
|
1291 }
|
|
1292
|
|
1293 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register");
|
|
1294
|
|
1295 xmlnode_set_attrib(iq->node, "to", js->user->domain);
|
|
1296
|
|
1297 query = xmlnode_get_child(iq->node, "query");
|
|
1298
|
|
1299 y = xmlnode_new_child(query, "username");
|
|
1300 xmlnode_insert_data(y, js->user->node, -1);
|
|
1301 y = xmlnode_new_child(query, "password");
|
|
1302 xmlnode_insert_data(y, p1, -1);
|
|
1303
|
|
1304 jabber_iq_set_callback(iq, jabber_password_change_result_cb, NULL);
|
|
1305
|
|
1306 jabber_iq_send(iq);
|
|
1307
|
|
1308 gaim_account_set_password(js->gc->account, p1);
|
|
1309 }
|
|
1310
|
|
1311 static void jabber_password_change(GaimPluginAction *action)
|
|
1312 {
|
|
1313
|
|
1314 GaimConnection *gc = (GaimConnection *) action->context;
|
|
1315 JabberStream *js = gc->proto_data;
|
|
1316 GaimRequestFields *fields;
|
|
1317 GaimRequestFieldGroup *group;
|
|
1318 GaimRequestField *field;
|
|
1319
|
|
1320 fields = gaim_request_fields_new();
|
|
1321 group = gaim_request_field_group_new(NULL);
|
|
1322 gaim_request_fields_add_group(fields, group);
|
|
1323
|
|
1324 field = gaim_request_field_string_new("password1", _("Password"),
|
|
1325 "", FALSE);
|
|
1326 gaim_request_field_string_set_masked(field, TRUE);
|
|
1327 gaim_request_field_group_add_field(group, field);
|
|
1328
|
|
1329 field = gaim_request_field_string_new("password2", _("Password (again)"),
|
|
1330 "", FALSE);
|
|
1331 gaim_request_field_string_set_masked(field, TRUE);
|
|
1332 gaim_request_field_group_add_field(group, field);
|
|
1333
|
|
1334 gaim_request_fields(js->gc, _("Change Jabber Password"),
|
|
1335 _("Change Jabber Password"), _("Please enter your new password"),
|
|
1336 fields, _("OK"), G_CALLBACK(jabber_password_change_cb),
|
|
1337 _("Cancel"), NULL, js);
|
|
1338 }
|
|
1339
|
|
1340 static GList *jabber_actions(GaimPlugin *plugin, gpointer context)
|
|
1341 {
|
|
1342 GList *m = NULL;
|
|
1343 GaimPluginAction *act;
|
|
1344
|
|
1345 act = gaim_plugin_action_new(_("Set User Info..."),
|
|
1346 jabber_setup_set_info);
|
|
1347 m = g_list_append(m, act);
|
|
1348
|
|
1349 /* if (js->protocol_options & CHANGE_PASSWORD) { */
|
|
1350 act = gaim_plugin_action_new(_("Change Password..."),
|
|
1351 jabber_password_change);
|
|
1352 m = g_list_append(m, act);
|
|
1353 /* } */
|
|
1354
|
|
1355 act = gaim_plugin_action_new(_("Search for Users..."),
|
|
1356 jabber_user_search_begin);
|
|
1357 m = g_list_append(m, act);
|
|
1358
|
|
1359 return m;
|
|
1360 }
|
|
1361
|
|
1362 static GaimChat *jabber_find_blist_chat(GaimAccount *account, const char *name)
|
|
1363 {
|
|
1364 GaimBlistNode *gnode, *cnode;
|
|
1365 JabberID *jid;
|
|
1366
|
|
1367 if(!(jid = jabber_id_new(name)))
|
|
1368 return NULL;
|
|
1369
|
|
1370 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) {
|
|
1371 for(cnode = gnode->child; cnode; cnode = cnode->next) {
|
|
1372 GaimChat *chat = (GaimChat*)cnode;
|
|
1373 const char *room, *server;
|
|
1374 if(!GAIM_BLIST_NODE_IS_CHAT(cnode))
|
|
1375 continue;
|
|
1376
|
|
1377 if(chat->account != account)
|
|
1378 continue;
|
|
1379
|
|
1380 if(!(room = g_hash_table_lookup(chat->components, "room")))
|
|
1381 continue;
|
|
1382 if(!(server = g_hash_table_lookup(chat->components, "server")))
|
|
1383 continue;
|
|
1384
|
|
1385 if(jid->node && jid->domain &&
|
|
1386 !g_utf8_collate(room, jid->node) && !g_utf8_collate(server, jid->domain)) {
|
|
1387 jabber_id_free(jid);
|
|
1388 return chat;
|
|
1389 }
|
|
1390 }
|
|
1391 }
|
|
1392 jabber_id_free(jid);
|
|
1393 return NULL;
|
|
1394 }
|
|
1395
|
|
1396 static void jabber_convo_closed(GaimConnection *gc, const char *who)
|
|
1397 {
|
|
1398 JabberStream *js = gc->proto_data;
|
|
1399 JabberID *jid;
|
|
1400 JabberBuddy *jb;
|
|
1401 JabberBuddyResource *jbr;
|
|
1402
|
|
1403 if(!(jid = jabber_id_new(who)))
|
|
1404 return;
|
|
1405
|
|
1406 if((jb = jabber_buddy_find(js, who, TRUE)) &&
|
|
1407 (jbr = jabber_buddy_find_resource(jb, jid->resource))) {
|
|
1408 if(jbr->thread_id) {
|
|
1409 g_free(jbr->thread_id);
|
|
1410 jbr->thread_id = NULL;
|
|
1411 }
|
|
1412 }
|
|
1413
|
|
1414 jabber_id_free(jid);
|
|
1415 }
|
|
1416
|
|
1417
|
|
1418 char *jabber_parse_error(JabberStream *js, xmlnode *packet)
|
|
1419 {
|
|
1420 xmlnode *error;
|
|
1421 const char *code = NULL, *text = NULL;
|
|
1422 const char *xmlns = xmlnode_get_namespace(packet);
|
|
1423 char *cdata = NULL;
|
|
1424
|
|
1425 if((error = xmlnode_get_child(packet, "error"))) {
|
|
1426 cdata = xmlnode_get_data(error);
|
|
1427 code = xmlnode_get_attrib(error, "code");
|
|
1428
|
|
1429 /* Stanza errors */
|
|
1430 if(xmlnode_get_child(error, "bad-request")) {
|
|
1431 text = _("Bad Request");
|
|
1432 } else if(xmlnode_get_child(error, "conflict")) {
|
|
1433 text = _("Conflict");
|
|
1434 } else if(xmlnode_get_child(error, "feature-not-implemented")) {
|
|
1435 text = _("Feature Not Implemented");
|
|
1436 } else if(xmlnode_get_child(error, "forbidden")) {
|
|
1437 text = _("Forbidden");
|
|
1438 } else if(xmlnode_get_child(error, "gone")) {
|
|
1439 text = _("Gone");
|
|
1440 } else if(xmlnode_get_child(error, "internal-server-error")) {
|
|
1441 text = _("Internal Server Error");
|
|
1442 } else if(xmlnode_get_child(error, "item-not-found")) {
|
|
1443 text = _("Item Not Found");
|
|
1444 } else if(xmlnode_get_child(error, "jid-malformed")) {
|
|
1445 text = _("Malformed Jabber ID");
|
|
1446 } else if(xmlnode_get_child(error, "not-acceptable")) {
|
|
1447 text = _("Not Acceptable");
|
|
1448 } else if(xmlnode_get_child(error, "not-allowed")) {
|
|
1449 text = _("Not Allowed");
|
|
1450 } else if(xmlnode_get_child(error, "not-authorized")) {
|
|
1451 text = _("Not Authorized");
|
|
1452 } else if(xmlnode_get_child(error, "payment-required")) {
|
|
1453 text = _("Payment Required");
|
|
1454 } else if(xmlnode_get_child(error, "recipient-unavailable")) {
|
|
1455 text = _("Recipient Unavailable");
|
|
1456 } else if(xmlnode_get_child(error, "redirect")) {
|
|
1457 /* XXX */
|
|
1458 } else if(xmlnode_get_child(error, "registration-required")) {
|
|
1459 text = _("Registration Required");
|
|
1460 } else if(xmlnode_get_child(error, "remote-server-not-found")) {
|
|
1461 text = _("Remote Server Not Found");
|
|
1462 } else if(xmlnode_get_child(error, "remote-server-timeout")) {
|
|
1463 text = _("Remote Server Timeout");
|
|
1464 } else if(xmlnode_get_child(error, "resource-constraint")) {
|
|
1465 text = _("Server Overloaded");
|
|
1466 } else if(xmlnode_get_child(error, "service-unavailable")) {
|
|
1467 text = _("Service Unavailable");
|
|
1468 } else if(xmlnode_get_child(error, "subscription-required")) {
|
|
1469 text = _("Subscription Required");
|
|
1470 } else if(xmlnode_get_child(error, "unexpected-request")) {
|
|
1471 text = _("Unexpected Request");
|
|
1472 } else if(xmlnode_get_child(error, "undefined-condition")) {
|
|
1473 text = _("Unknown Error");
|
|
1474 }
|
|
1475 } else if(xmlns && !strcmp(xmlns, "urn:ietf:params:xml:ns:xmpp-sasl")) {
|
|
1476 if(xmlnode_get_child(packet, "aborted")) {
|
|
1477 js->gc->wants_to_die = TRUE;
|
|
1478 text = _("Authorization Aborted");
|
|
1479 } else if(xmlnode_get_child(packet, "incorrect-encoding")) {
|
|
1480 text = _("Incorrect encoding in authorization");
|
|
1481 } else if(xmlnode_get_child(packet, "invalid-authzid")) {
|
|
1482 js->gc->wants_to_die = TRUE;
|
|
1483 text = _("Invalid authzid");
|
|
1484 } else if(xmlnode_get_child(packet, "invalid-mechanism")) {
|
|
1485 js->gc->wants_to_die = TRUE;
|
|
1486 text = _("Invalid Authorization Mechanism");
|
|
1487 } else if(xmlnode_get_child(packet, "mechanism-too-weak")) {
|
|
1488 js->gc->wants_to_die = TRUE;
|
|
1489 text = _("Authorization mechanism too weak");
|
|
1490 } else if(xmlnode_get_child(packet, "not-authorized")) {
|
|
1491 js->gc->wants_to_die = TRUE;
|
|
1492 text = _("Not Authorized");
|
|
1493 } else if(xmlnode_get_child(packet, "temporary-auth-failure")) {
|
|
1494 text = _("Temporary Authentication Failure");
|
|
1495 } else {
|
|
1496 js->gc->wants_to_die = TRUE;
|
|
1497 text = _("Authentication Failure");
|
|
1498 }
|
|
1499 } else if(!strcmp(packet->name, "stream:error")) {
|
|
1500 if(xmlnode_get_child(packet, "bad-format")) {
|
|
1501 text = _("Bad Format");
|
|
1502 } else if(xmlnode_get_child(packet, "bad-namespace-prefix")) {
|
|
1503 text = _("Bad Namespace Prefix");
|
|
1504 } else if(xmlnode_get_child(packet, "conflict")) {
|
|
1505 js->gc->wants_to_die = TRUE;
|
|
1506 text = _("Resource Conflict");
|
|
1507 } else if(xmlnode_get_child(packet, "connection-timeout")) {
|
|
1508 text = _("Connection Timeout");
|
|
1509 } else if(xmlnode_get_child(packet, "host-gone")) {
|
|
1510 text = _("Host Gone");
|
|
1511 } else if(xmlnode_get_child(packet, "host-unknown")) {
|
|
1512 text = _("Host Unknown");
|
|
1513 } else if(xmlnode_get_child(packet, "improper-addressing")) {
|
|
1514 text = _("Improper Addressing");
|
|
1515 } else if(xmlnode_get_child(packet, "internal-server-error")) {
|
|
1516 text = _("Internal Server Error");
|
|
1517 } else if(xmlnode_get_child(packet, "invalid-id")) {
|
|
1518 text = _("Invalid ID");
|
|
1519 } else if(xmlnode_get_child(packet, "invalid-namespace")) {
|
|
1520 text = _("Invalid Namespace");
|
|
1521 } else if(xmlnode_get_child(packet, "invalid-xml")) {
|
|
1522 text = _("Invalid XML");
|
|
1523 } else if(xmlnode_get_child(packet, "nonmatching-hosts")) {
|
|
1524 text = _("Non-matching Hosts");
|
|
1525 } else if(xmlnode_get_child(packet, "not-authorized")) {
|
|
1526 text = _("Not Authorized");
|
|
1527 } else if(xmlnode_get_child(packet, "policy-violation")) {
|
|
1528 text = _("Policy Violation");
|
|
1529 } else if(xmlnode_get_child(packet, "remote-connection-failed")) {
|
|
1530 text = _("Remote Connection Failed");
|
|
1531 } else if(xmlnode_get_child(packet, "resource-constraint")) {
|
|
1532 text = _("Resource Constraint");
|
|
1533 } else if(xmlnode_get_child(packet, "restricted-xml")) {
|
|
1534 text = _("Restricted XML");
|
|
1535 } else if(xmlnode_get_child(packet, "see-other-host")) {
|
|
1536 text = _("See Other Host");
|
|
1537 } else if(xmlnode_get_child(packet, "system-shutdown")) {
|
|
1538 text = _("System Shutdown");
|
|
1539 } else if(xmlnode_get_child(packet, "undefined-condition")) {
|
|
1540 text = _("Undefined Condition");
|
|
1541 } else if(xmlnode_get_child(packet, "unsupported-encoding")) {
|
|
1542 text = _("Unsupported Encoding");
|
|
1543 } else if(xmlnode_get_child(packet, "unsupported-stanza-type")) {
|
|
1544 text = _("Unsupported Stanza Type");
|
|
1545 } else if(xmlnode_get_child(packet, "unsupported-version")) {
|
|
1546 text = _("Unsupported Version");
|
|
1547 } else if(xmlnode_get_child(packet, "xml-not-well-formed")) {
|
|
1548 text = _("XML Not Well Formed");
|
|
1549 } else {
|
|
1550 text = _("Stream Error");
|
|
1551 }
|
|
1552 }
|
|
1553
|
|
1554 if(text || cdata) {
|
|
1555 char *ret = g_strdup_printf("%s%s%s", code ? code : "",
|
|
1556 code ? ": " : "", text ? text : cdata);
|
|
1557 g_free(cdata);
|
|
1558 return ret;
|
|
1559 } else {
|
|
1560 return NULL;
|
|
1561 }
|
|
1562 }
|
|
1563
|
|
1564 static GaimCmdRet jabber_cmd_chat_config(GaimConversation *conv,
|
|
1565 const char *cmd, char **args, char **error, void *data)
|
|
1566 {
|
|
1567 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1568 jabber_chat_request_room_configure(chat);
|
|
1569 return GAIM_CMD_RET_OK;
|
|
1570 }
|
|
1571
|
|
1572 static GaimCmdRet jabber_cmd_chat_register(GaimConversation *conv,
|
|
1573 const char *cmd, char **args, char **error, void *data)
|
|
1574 {
|
|
1575 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1576 jabber_chat_register(chat);
|
|
1577 return GAIM_CMD_RET_OK;
|
|
1578 }
|
|
1579
|
|
1580 static GaimCmdRet jabber_cmd_chat_topic(GaimConversation *conv,
|
|
1581 const char *cmd, char **args, char **error, void *data)
|
|
1582 {
|
|
1583 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1584 jabber_chat_change_topic(chat, args ? args[0] : NULL);
|
|
1585 return GAIM_CMD_RET_OK;
|
|
1586 }
|
|
1587
|
|
1588 static GaimCmdRet jabber_cmd_chat_nick(GaimConversation *conv,
|
|
1589 const char *cmd, char **args, char **error, void *data)
|
|
1590 {
|
|
1591 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1592
|
|
1593 if(!args || !args[0])
|
|
1594 return GAIM_CMD_RET_FAILED;
|
|
1595
|
|
1596 jabber_chat_change_nick(chat, args[0]);
|
|
1597 return GAIM_CMD_RET_OK;
|
|
1598 }
|
|
1599
|
|
1600 static GaimCmdRet jabber_cmd_chat_part(GaimConversation *conv,
|
|
1601 const char *cmd, char **args, char **error, void *data)
|
|
1602 {
|
|
1603 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1604 jabber_chat_part(chat, args ? args[0] : NULL);
|
|
1605 return GAIM_CMD_RET_OK;
|
|
1606 }
|
|
1607
|
|
1608 static GaimCmdRet jabber_cmd_chat_ban(GaimConversation *conv,
|
|
1609 const char *cmd, char **args, char **error, void *data)
|
|
1610 {
|
|
1611 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1612
|
|
1613 if(!args || !args[0])
|
|
1614 return GAIM_CMD_RET_FAILED;
|
|
1615
|
|
1616 if(!jabber_chat_ban_user(chat, args[0], args[1])) {
|
|
1617 *error = g_strdup_printf(_("Unable to ban user %s"), args[0]);
|
|
1618 return GAIM_CMD_RET_FAILED;
|
|
1619 }
|
|
1620
|
|
1621 return GAIM_CMD_RET_OK;
|
|
1622 }
|
|
1623
|
|
1624 static GaimCmdRet jabber_cmd_chat_affiliate(GaimConversation *conv,
|
|
1625 const char *cmd, char **args, char **error, void *data)
|
|
1626 {
|
|
1627 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1628
|
|
1629 if (!args || !args[0] || !args[1])
|
|
1630 return GAIM_CMD_RET_FAILED;
|
|
1631
|
|
1632 if (strcmp(args[1], "owner") != 0 &&
|
|
1633 strcmp(args[1], "admin") != 0 &&
|
|
1634 strcmp(args[1], "member") != 0 &&
|
|
1635 strcmp(args[1], "outcast") != 0 &&
|
|
1636 strcmp(args[1], "none") != 0) {
|
|
1637 *error = g_strdup_printf(_("Unknown affiliation: \"%s\""), args[1]);
|
|
1638 return GAIM_CMD_RET_FAILED;
|
|
1639 }
|
|
1640
|
|
1641 if (!jabber_chat_affiliate_user(chat, args[0], args[1])) {
|
|
1642 *error = g_strdup_printf(_("Unable to affiliate user %s as \"%s\""), args[0], args[1]);
|
|
1643 return GAIM_CMD_RET_FAILED;
|
|
1644 }
|
|
1645
|
|
1646 return GAIM_CMD_RET_OK;
|
|
1647 }
|
|
1648
|
|
1649 static GaimCmdRet jabber_cmd_chat_role(GaimConversation *conv,
|
|
1650 const char *cmd, char **args, char **error, void *data)
|
|
1651 {
|
|
1652 JabberChat *chat;
|
|
1653
|
|
1654 if (!args || !args[0] || !args[1])
|
|
1655 return GAIM_CMD_RET_FAILED;
|
|
1656
|
|
1657 if (strcmp(args[1], "moderator") != 0 &&
|
|
1658 strcmp(args[1], "participant") != 0 &&
|
|
1659 strcmp(args[1], "visitor") != 0 &&
|
|
1660 strcmp(args[1], "none") != 0) {
|
|
1661 *error = g_strdup_printf(_("Unknown role: \"%s\""), args[1]);
|
|
1662 return GAIM_CMD_RET_FAILED;
|
|
1663 }
|
|
1664
|
|
1665 chat = jabber_chat_find_by_conv(conv);
|
|
1666
|
|
1667 if (!jabber_chat_role_user(chat, args[0], args[1])) {
|
|
1668 *error = g_strdup_printf(_("Unable to set role \"%s\" for user: %s"),
|
|
1669 args[1], args[0]);
|
|
1670 return GAIM_CMD_RET_FAILED;
|
|
1671 }
|
|
1672
|
|
1673 return GAIM_CMD_RET_OK;
|
|
1674 }
|
|
1675
|
|
1676 static GaimCmdRet jabber_cmd_chat_invite(GaimConversation *conv,
|
|
1677 const char *cmd, char **args, char **error, void *data)
|
|
1678 {
|
|
1679 if(!args || !args[0])
|
|
1680 return GAIM_CMD_RET_FAILED;
|
|
1681
|
|
1682 jabber_chat_invite(gaim_conversation_get_gc(conv),
|
|
1683 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), args[1] ? args[1] : "",
|
|
1684 args[0]);
|
|
1685
|
|
1686 return GAIM_CMD_RET_OK;
|
|
1687 }
|
|
1688
|
|
1689 static GaimCmdRet jabber_cmd_chat_join(GaimConversation *conv,
|
|
1690 const char *cmd, char **args, char **error, void *data)
|
|
1691 {
|
|
1692 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1693 GHashTable *components;
|
|
1694
|
|
1695 if(!args || !args[0])
|
|
1696 return GAIM_CMD_RET_FAILED;
|
|
1697
|
|
1698 components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
|
|
1699
|
|
1700 g_hash_table_replace(components, "room", args[0]);
|
|
1701 g_hash_table_replace(components, "server", chat->server);
|
|
1702 g_hash_table_replace(components, "handle", chat->handle);
|
|
1703 if(args[1])
|
|
1704 g_hash_table_replace(components, "password", args[1]);
|
|
1705
|
|
1706 jabber_chat_join(gaim_conversation_get_gc(conv), components);
|
|
1707
|
|
1708 g_hash_table_destroy(components);
|
|
1709 return GAIM_CMD_RET_OK;
|
|
1710 }
|
|
1711
|
|
1712 static GaimCmdRet jabber_cmd_chat_kick(GaimConversation *conv,
|
|
1713 const char *cmd, char **args, char **error, void *data)
|
|
1714 {
|
|
1715 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1716
|
|
1717 if(!args || !args[0])
|
|
1718 return GAIM_CMD_RET_FAILED;
|
|
1719
|
|
1720 if(!jabber_chat_kick_user(chat, args[0], args[1])) {
|
|
1721 *error = g_strdup_printf(_("Unable to kick user %s"), args[0]);
|
|
1722 return GAIM_CMD_RET_FAILED;
|
|
1723 }
|
|
1724
|
|
1725 return GAIM_CMD_RET_OK;
|
|
1726 }
|
|
1727
|
|
1728 static GaimCmdRet jabber_cmd_chat_msg(GaimConversation *conv,
|
|
1729 const char *cmd, char **args, char **error, void *data)
|
|
1730 {
|
|
1731 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1732 char *who;
|
|
1733
|
|
1734 who = g_strdup_printf("%s@%s/%s", chat->room, chat->server, args[0]);
|
|
1735
|
|
1736 jabber_message_send_im(gaim_conversation_get_gc(conv), who, args[1], 0);
|
|
1737
|
|
1738 g_free(who);
|
|
1739 return GAIM_CMD_RET_OK;
|
|
1740 }
|
|
1741
|
|
1742 static gboolean jabber_offline_message(const GaimBuddy *buddy)
|
|
1743 {
|
|
1744 return TRUE;
|
|
1745 }
|
|
1746
|
|
1747 static void jabber_register_commands(void)
|
|
1748 {
|
|
1749 gaim_cmd_register("config", "", GAIM_CMD_P_PRPL,
|
|
1750 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1751 "prpl-jabber", jabber_cmd_chat_config,
|
|
1752 _("config: Configure a chat room."), NULL);
|
|
1753 gaim_cmd_register("configure", "", GAIM_CMD_P_PRPL,
|
|
1754 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1755 "prpl-jabber", jabber_cmd_chat_config,
|
|
1756 _("configure: Configure a chat room."), NULL);
|
|
1757 gaim_cmd_register("nick", "s", GAIM_CMD_P_PRPL,
|
|
1758 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1759 "prpl-jabber", jabber_cmd_chat_nick,
|
|
1760 _("nick <new nickname>: Change your nickname."),
|
|
1761 NULL);
|
|
1762 gaim_cmd_register("part", "s", GAIM_CMD_P_PRPL,
|
|
1763 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1764 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1765 jabber_cmd_chat_part, _("part [room]: Leave the room."),
|
|
1766 NULL);
|
|
1767 gaim_cmd_register("register", "", GAIM_CMD_P_PRPL,
|
|
1768 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1769 "prpl-jabber", jabber_cmd_chat_register,
|
|
1770 _("register: Register with a chat room."), NULL);
|
|
1771 /* XXX: there needs to be a core /topic cmd, methinks */
|
|
1772 gaim_cmd_register("topic", "s", GAIM_CMD_P_PRPL,
|
|
1773 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1774 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1775 jabber_cmd_chat_topic,
|
|
1776 _("topic [new topic]: View or change the topic."),
|
|
1777 NULL);
|
|
1778 gaim_cmd_register("ban", "ws", GAIM_CMD_P_PRPL,
|
|
1779 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1780 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1781 jabber_cmd_chat_ban,
|
|
1782 _("ban <user> [room]: Ban a user from the room."),
|
|
1783 NULL);
|
|
1784 gaim_cmd_register("affiliate", "ws", GAIM_CMD_P_PRPL,
|
|
1785 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1786 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1787 jabber_cmd_chat_affiliate,
|
|
1788 _("affiliate <user> <owner|admin|member|outcast|none>: Set a user's affiliation with the room."),
|
|
1789 NULL);
|
|
1790 gaim_cmd_register("role", "ws", GAIM_CMD_P_PRPL,
|
|
1791 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1792 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1793 jabber_cmd_chat_role,
|
|
1794 _("role <user> <moderator|participant|visitor|none>: Set a user's role in the room."),
|
|
1795 NULL);
|
|
1796 gaim_cmd_register("invite", "ws", GAIM_CMD_P_PRPL,
|
|
1797 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1798 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1799 jabber_cmd_chat_invite,
|
|
1800 _("invite <user> [message]: Invite a user to the room."),
|
|
1801 NULL);
|
|
1802 gaim_cmd_register("join", "ws", GAIM_CMD_P_PRPL,
|
|
1803 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1804 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1805 jabber_cmd_chat_join,
|
|
1806 _("join: <room> [server]: Join a chat on this server."),
|
|
1807 NULL);
|
|
1808 gaim_cmd_register("kick", "ws", GAIM_CMD_P_PRPL,
|
|
1809 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1810 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1811 jabber_cmd_chat_kick,
|
|
1812 _("kick <user> [room]: Kick a user from the room."),
|
|
1813 NULL);
|
|
1814 gaim_cmd_register("msg", "ws", GAIM_CMD_P_PRPL,
|
|
1815 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1816 "prpl-jabber", jabber_cmd_chat_msg,
|
|
1817 _("msg <user> <message>: Send a private message to another user."),
|
|
1818 NULL);
|
|
1819 }
|
|
1820
|
|
1821 static GaimPluginProtocolInfo prpl_info =
|
|
1822 {
|
|
1823 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME,
|
|
1824 NULL, /* user_splits */
|
|
1825 NULL, /* protocol_options */
|
|
1826 {"jpeg,gif,png", 0, 0, 96, 96, GAIM_ICON_SCALE_DISPLAY}, /* icon_spec */
|
|
1827 jabber_list_icon, /* list_icon */
|
|
1828 jabber_list_emblems, /* list_emblems */
|
|
1829 jabber_status_text, /* status_text */
|
|
1830 jabber_tooltip_text, /* tooltip_text */
|
|
1831 jabber_status_types, /* status_types */
|
|
1832 jabber_blist_node_menu, /* blist_node_menu */
|
|
1833 jabber_chat_info, /* chat_info */
|
|
1834 jabber_chat_info_defaults, /* chat_info_defaults */
|
|
1835 jabber_login, /* login */
|
|
1836 jabber_close, /* close */
|
|
1837 jabber_message_send_im, /* send_im */
|
|
1838 jabber_set_info, /* set_info */
|
|
1839 jabber_send_typing, /* send_typing */
|
|
1840 jabber_buddy_get_info, /* get_info */
|
|
1841 jabber_presence_send, /* set_away */
|
|
1842 jabber_idle_set, /* set_idle */
|
|
1843 NULL, /* change_passwd */
|
|
1844 jabber_roster_add_buddy, /* add_buddy */
|
|
1845 NULL, /* add_buddies */
|
|
1846 jabber_roster_remove_buddy, /* remove_buddy */
|
|
1847 NULL, /* remove_buddies */
|
|
1848 NULL, /* add_permit */
|
|
1849 NULL, /* add_deny */
|
|
1850 NULL, /* rem_permit */
|
|
1851 NULL, /* rem_deny */
|
|
1852 NULL, /* set_permit_deny */
|
|
1853 jabber_chat_join, /* join_chat */
|
|
1854 NULL, /* reject_chat */
|
|
1855 jabber_get_chat_name, /* get_chat_name */
|
|
1856 jabber_chat_invite, /* chat_invite */
|
|
1857 jabber_chat_leave, /* chat_leave */
|
|
1858 NULL, /* chat_whisper */
|
|
1859 jabber_message_send_chat, /* chat_send */
|
|
1860 jabber_keepalive, /* keepalive */
|
|
1861 jabber_register_account, /* register_user */
|
|
1862 jabber_buddy_get_info_chat, /* get_cb_info */
|
|
1863 NULL, /* get_cb_away */
|
|
1864 jabber_roster_alias_change, /* alias_buddy */
|
|
1865 jabber_roster_group_change, /* group_buddy */
|
|
1866 jabber_roster_group_rename, /* rename_group */
|
|
1867 NULL, /* buddy_free */
|
|
1868 jabber_convo_closed, /* convo_closed */
|
|
1869 jabber_normalize, /* normalize */
|
|
1870 jabber_set_buddy_icon, /* set_buddy_icon */
|
|
1871 NULL, /* remove_group */
|
|
1872 jabber_chat_buddy_real_name, /* get_cb_real_name */
|
|
1873 jabber_chat_set_topic, /* set_chat_topic */
|
|
1874 jabber_find_blist_chat, /* find_blist_chat */
|
|
1875 jabber_roomlist_get_list, /* roomlist_get_list */
|
|
1876 jabber_roomlist_cancel, /* roomlist_cancel */
|
|
1877 NULL, /* roomlist_expand_category */
|
|
1878 NULL, /* can_receive_file */
|
|
1879 jabber_si_xfer_send, /* send_file */
|
|
1880 jabber_si_new_xfer, /* new_xfer */
|
|
1881 jabber_offline_message, /* offline_message */
|
|
1882 NULL, /* whiteboard_prpl_ops */
|
|
1883 };
|
|
1884
|
|
1885 static GaimPluginInfo info =
|
|
1886 {
|
|
1887 GAIM_PLUGIN_MAGIC,
|
|
1888 GAIM_MAJOR_VERSION,
|
|
1889 GAIM_MINOR_VERSION,
|
|
1890 GAIM_PLUGIN_PROTOCOL, /**< type */
|
|
1891 NULL, /**< ui_requirement */
|
|
1892 0, /**< flags */
|
|
1893 NULL, /**< dependencies */
|
|
1894 GAIM_PRIORITY_DEFAULT, /**< priority */
|
|
1895
|
|
1896 "prpl-jabber", /**< id */
|
|
1897 "Jabber", /**< name */
|
|
1898 VERSION, /**< version */
|
|
1899 /** summary */
|
|
1900 N_("Jabber Protocol Plugin"),
|
|
1901 /** description */
|
|
1902 N_("Jabber Protocol Plugin"),
|
|
1903 NULL, /**< author */
|
|
1904 GAIM_WEBSITE, /**< homepage */
|
|
1905
|
|
1906 NULL, /**< load */
|
|
1907 NULL, /**< unload */
|
|
1908 NULL, /**< destroy */
|
|
1909
|
|
1910 NULL, /**< ui_info */
|
|
1911 &prpl_info, /**< extra_info */
|
|
1912 NULL, /**< prefs_info */
|
|
1913 jabber_actions
|
|
1914 };
|
|
1915
|
|
1916 static void
|
|
1917 init_plugin(GaimPlugin *plugin)
|
|
1918 {
|
|
1919 GaimAccountUserSplit *split;
|
|
1920 GaimAccountOption *option;
|
|
1921
|
|
1922 split = gaim_account_user_split_new(_("Server"), "jabber.org", '@');
|
|
1923 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);
|
|
1924
|
|
1925 split = gaim_account_user_split_new(_("Resource"), "Home", '/');
|
|
1926 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);
|
|
1927
|
|
1928 option = gaim_account_option_bool_new(_("Use TLS if available"), "use_tls",
|
|
1929 TRUE);
|
|
1930 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
|
|
1931 option);
|
|
1932
|
|
1933 option = gaim_account_option_bool_new(_("Require TLS"), "require_tls", TRUE);
|
|
1934 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
1935
|
|
1936 option = gaim_account_option_bool_new(_("Force old (port 5223) SSL"), "old_ssl", FALSE);
|
|
1937 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
|
|
1938 option);
|
|
1939
|
|
1940 option = gaim_account_option_bool_new(
|
|
1941 _("Allow plaintext auth over unencrypted streams"),
|
|
1942 "auth_plain_in_clear", FALSE);
|
|
1943 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
|
|
1944 option);
|
|
1945
|
|
1946 option = gaim_account_option_int_new(_("Connect port"), "port", 5222);
|
|
1947 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
|
|
1948 option);
|
|
1949
|
|
1950 option = gaim_account_option_string_new(_("Connect server"),
|
|
1951 "connect_server", NULL);
|
|
1952 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
|
|
1953 option);
|
|
1954
|
|
1955 my_protocol = plugin;
|
|
1956
|
|
1957 gaim_prefs_remove("/plugins/prpl/jabber");
|
|
1958
|
|
1959 /* XXX - If any other plugin wants SASL this won't be good ... */
|
|
1960 #ifdef HAVE_CYRUS_SASL
|
|
1961 sasl_client_init(NULL);
|
|
1962 #endif
|
|
1963 jabber_register_commands();
|
14294
|
1964
|
|
1965 jabber_iq_init();
|
14192
|
1966 }
|
|
1967
|
|
1968 GAIM_INIT_PLUGIN(jabber, init_plugin, info);
|