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
|
|
423 js->connect_info = NULL;
|
|
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 {
|
|
468 js->connect_info = gaim_proxy_connect(js->gc->account, server,
|
|
469 port, jabber_login_callback, js->gc);
|
|
470
|
|
471 if (js->connect_info == NULL)
|
|
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 {
|
|
708 if(js->registration) {
|
|
709 GaimRequestFields *fields;
|
|
710 GaimRequestFieldGroup *group;
|
|
711 GaimRequestField *field;
|
|
712 xmlnode *query, *x, *y;
|
|
713 char *instructions;
|
|
714
|
|
715 /* get rid of the login thingy */
|
|
716 gaim_connection_set_state(js->gc, GAIM_CONNECTED);
|
|
717
|
|
718 query = xmlnode_get_child(packet, "query");
|
|
719
|
|
720 if(xmlnode_get_child(query, "registered")) {
|
|
721 gaim_notify_error(NULL, _("Already Registered"),
|
|
722 _("Already Registered"), NULL);
|
|
723 jabber_connection_schedule_close(js);
|
|
724 return;
|
|
725 }
|
|
726
|
|
727 if((x = xmlnode_get_child_with_namespace(packet, "x",
|
|
728 "jabber:x:data"))) {
|
|
729 jabber_x_data_request(js, x, jabber_register_x_data_cb, NULL);
|
|
730 return;
|
|
731 } else if((x = xmlnode_get_child_with_namespace(packet, "x",
|
|
732 "jabber:x:oob"))) {
|
|
733 xmlnode *url;
|
|
734
|
|
735 if((url = xmlnode_get_child(x, "url"))) {
|
|
736 char *href;
|
|
737 if((href = xmlnode_get_data(url))) {
|
|
738 gaim_notify_uri(NULL, href);
|
|
739 g_free(href);
|
|
740 js->gc->wants_to_die = TRUE;
|
|
741 jabber_connection_schedule_close(js);
|
|
742 return;
|
|
743 }
|
|
744 }
|
|
745 }
|
|
746
|
|
747 /* as a last resort, use the old jabber:iq:register syntax */
|
|
748
|
|
749 fields = gaim_request_fields_new();
|
|
750 group = gaim_request_field_group_new(NULL);
|
|
751 gaim_request_fields_add_group(fields, group);
|
|
752
|
|
753 field = gaim_request_field_string_new("username", _("Username"),
|
|
754 js->user->node, FALSE);
|
|
755 gaim_request_field_group_add_field(group, field);
|
|
756
|
|
757 field = gaim_request_field_string_new("password", _("Password"),
|
|
758 gaim_connection_get_password(js->gc), FALSE);
|
|
759 gaim_request_field_string_set_masked(field, TRUE);
|
|
760 gaim_request_field_group_add_field(group, field);
|
|
761
|
|
762 if(xmlnode_get_child(query, "name")) {
|
|
763 field = gaim_request_field_string_new("name", _("Name"),
|
|
764 gaim_account_get_alias(js->gc->account), FALSE);
|
|
765 gaim_request_field_group_add_field(group, field);
|
|
766 }
|
|
767 if(xmlnode_get_child(query, "email")) {
|
|
768 field = gaim_request_field_string_new("email", _("E-mail"),
|
|
769 NULL, FALSE);
|
|
770 gaim_request_field_group_add_field(group, field);
|
|
771 }
|
|
772 if(xmlnode_get_child(query, "nick")) {
|
|
773 field = gaim_request_field_string_new("nick", _("Nickname"),
|
|
774 NULL, FALSE);
|
|
775 gaim_request_field_group_add_field(group, field);
|
|
776 }
|
|
777 if(xmlnode_get_child(query, "first")) {
|
|
778 field = gaim_request_field_string_new("first", _("First name"),
|
|
779 NULL, FALSE);
|
|
780 gaim_request_field_group_add_field(group, field);
|
|
781 }
|
|
782 if(xmlnode_get_child(query, "last")) {
|
|
783 field = gaim_request_field_string_new("last", _("Last name"),
|
|
784 NULL, FALSE);
|
|
785 gaim_request_field_group_add_field(group, field);
|
|
786 }
|
|
787 if(xmlnode_get_child(query, "address")) {
|
|
788 field = gaim_request_field_string_new("address", _("Address"),
|
|
789 NULL, FALSE);
|
|
790 gaim_request_field_group_add_field(group, field);
|
|
791 }
|
|
792 if(xmlnode_get_child(query, "city")) {
|
|
793 field = gaim_request_field_string_new("city", _("City"),
|
|
794 NULL, FALSE);
|
|
795 gaim_request_field_group_add_field(group, field);
|
|
796 }
|
|
797 if(xmlnode_get_child(query, "state")) {
|
|
798 field = gaim_request_field_string_new("state", _("State"),
|
|
799 NULL, FALSE);
|
|
800 gaim_request_field_group_add_field(group, field);
|
|
801 }
|
|
802 if(xmlnode_get_child(query, "zip")) {
|
|
803 field = gaim_request_field_string_new("zip", _("Postal code"),
|
|
804 NULL, FALSE);
|
|
805 gaim_request_field_group_add_field(group, field);
|
|
806 }
|
|
807 if(xmlnode_get_child(query, "phone")) {
|
|
808 field = gaim_request_field_string_new("phone", _("Phone"),
|
|
809 NULL, FALSE);
|
|
810 gaim_request_field_group_add_field(group, field);
|
|
811 }
|
|
812 if(xmlnode_get_child(query, "url")) {
|
|
813 field = gaim_request_field_string_new("url", _("URL"),
|
|
814 NULL, FALSE);
|
|
815 gaim_request_field_group_add_field(group, field);
|
|
816 }
|
|
817 if(xmlnode_get_child(query, "date")) {
|
|
818 field = gaim_request_field_string_new("date", _("Date"),
|
|
819 NULL, FALSE);
|
|
820 gaim_request_field_group_add_field(group, field);
|
|
821 }
|
|
822
|
|
823 if((y = xmlnode_get_child(query, "instructions")))
|
|
824 instructions = xmlnode_get_data(y);
|
|
825 else
|
|
826 instructions = g_strdup(_("Please fill out the information below "
|
|
827 "to register your new account."));
|
|
828
|
|
829 gaim_request_fields(js->gc, _("Register New Jabber Account"),
|
|
830 _("Register New Jabber Account"), instructions, fields,
|
|
831 _("Register"), G_CALLBACK(jabber_register_cb),
|
|
832 _("Cancel"), G_CALLBACK(jabber_register_cancel_cb), js);
|
|
833
|
|
834 g_free(instructions);
|
|
835 }
|
|
836 }
|
|
837
|
|
838 void jabber_register_start(JabberStream *js)
|
|
839 {
|
|
840 JabberIq *iq;
|
|
841
|
|
842 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:register");
|
|
843 jabber_iq_send(iq);
|
|
844 }
|
|
845
|
|
846 static void jabber_register_account(GaimAccount *account)
|
|
847 {
|
|
848 GaimConnection *gc = gaim_account_get_connection(account);
|
|
849 JabberStream *js;
|
|
850 JabberBuddy *my_jb = NULL;
|
|
851 const char *connect_server = gaim_account_get_string(account,
|
|
852 "connect_server", "");
|
|
853 const char *server;
|
|
854
|
|
855 js = gc->proto_data = g_new0(JabberStream, 1);
|
|
856 js->gc = gc;
|
|
857 js->registration = TRUE;
|
|
858 js->iq_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal,
|
|
859 g_free, g_free);
|
|
860 js->disco_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal,
|
|
861 g_free, g_free);
|
|
862 js->user = jabber_id_new(gaim_account_get_username(account));
|
|
863 js->next_id = g_random_int();
|
|
864
|
|
865 if(!js->user) {
|
|
866 gaim_connection_error(gc, _("Invalid Jabber ID"));
|
|
867 return;
|
|
868 }
|
|
869
|
|
870 js->write_buffer = gaim_circ_buffer_new(512);
|
|
871
|
|
872 if(!js->user->resource) {
|
|
873 char *me;
|
|
874 js->user->resource = g_strdup("Home");
|
|
875 if(!js->user->node) {
|
|
876 js->user->node = js->user->domain;
|
|
877 js->user->domain = g_strdup("jabber.org");
|
|
878 }
|
|
879 me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain,
|
|
880 js->user->resource);
|
|
881 gaim_account_set_username(account, me);
|
|
882 g_free(me);
|
|
883 }
|
|
884
|
|
885 if((my_jb = jabber_buddy_find(js, gaim_account_get_username(account), TRUE)))
|
|
886 my_jb->subscription |= JABBER_SUB_BOTH;
|
|
887
|
|
888 server = connect_server[0] ? connect_server : js->user->domain;
|
|
889
|
|
890 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING);
|
|
891
|
|
892 if(gaim_account_get_bool(account, "old_ssl", FALSE)) {
|
|
893 if(gaim_ssl_is_supported()) {
|
|
894 js->gsc = gaim_ssl_connect(account, server,
|
|
895 gaim_account_get_int(account, "port", 5222),
|
|
896 jabber_login_callback_ssl, jabber_ssl_connect_failure, gc);
|
|
897 } else {
|
|
898 gaim_connection_error(gc, _("SSL support unavailable"));
|
|
899 }
|
|
900 }
|
|
901
|
|
902 if(!js->gsc) {
|
|
903 js->connect_info = gaim_proxy_connect(account, server,
|
|
904 gaim_account_get_int(account, "port", 5222),
|
|
905 jabber_login_callback, gc);
|
|
906
|
|
907 if (js->connect_info == NULL)
|
|
908 gaim_connection_error(gc, _("Unable to create socket"));
|
|
909 }
|
|
910 }
|
|
911
|
|
912 static void jabber_close(GaimConnection *gc)
|
|
913 {
|
|
914 JabberStream *js = gc->proto_data;
|
|
915
|
|
916 /* Don't perform any actions on the ssl connection
|
|
917 * if we were forcibly disconnected because it will crash
|
|
918 * on some SSL backends.
|
|
919 */
|
|
920 if (!gc->disconnect_timeout)
|
|
921 jabber_send_raw(js, "</stream:stream>", -1);
|
|
922
|
|
923 if (js->connect_info)
|
|
924 gaim_proxy_connect_cancel(js->connect_info);
|
|
925
|
|
926 if(js->gsc) {
|
|
927 #ifdef HAVE_OPENSSL
|
|
928 if (!gc->disconnect_timeout)
|
|
929 #endif
|
|
930 gaim_ssl_close(js->gsc);
|
|
931 } else if (js->fd > 0) {
|
|
932 if(js->gc->inpa)
|
|
933 gaim_input_remove(js->gc->inpa);
|
|
934 close(js->fd);
|
|
935 }
|
|
936 #ifndef HAVE_LIBXML
|
|
937 if(js->context)
|
|
938 g_markup_parse_context_free(js->context);
|
|
939 #endif
|
|
940 if(js->iq_callbacks)
|
|
941 g_hash_table_destroy(js->iq_callbacks);
|
|
942 if(js->disco_callbacks)
|
|
943 g_hash_table_destroy(js->disco_callbacks);
|
|
944 if(js->buddies)
|
|
945 g_hash_table_destroy(js->buddies);
|
|
946 if(js->chats)
|
|
947 g_hash_table_destroy(js->chats);
|
|
948 while(js->chat_servers) {
|
|
949 g_free(js->chat_servers->data);
|
|
950 js->chat_servers = g_list_delete_link(js->chat_servers, js->chat_servers);
|
|
951 }
|
|
952 while(js->user_directories) {
|
|
953 g_free(js->user_directories->data);
|
|
954 js->user_directories = g_list_delete_link(js->user_directories, js->user_directories);
|
|
955 }
|
|
956 if(js->stream_id)
|
|
957 g_free(js->stream_id);
|
|
958 if(js->user)
|
|
959 jabber_id_free(js->user);
|
|
960 if(js->avatar_hash)
|
|
961 g_free(js->avatar_hash);
|
|
962 gaim_circ_buffer_destroy(js->write_buffer);
|
|
963 if(js->writeh)
|
|
964 gaim_input_remove(js->writeh);
|
|
965 #ifdef HAVE_CYRUS_SASL
|
|
966 if(js->sasl)
|
|
967 sasl_dispose(&js->sasl);
|
|
968 if(js->sasl_mechs)
|
|
969 g_string_free(js->sasl_mechs, TRUE);
|
|
970 if(js->sasl_cb)
|
|
971 g_free(js->sasl_cb);
|
|
972 #endif
|
|
973 g_free(js);
|
|
974
|
|
975 gc->proto_data = NULL;
|
|
976 }
|
|
977
|
|
978 void jabber_stream_set_state(JabberStream *js, JabberStreamState state)
|
|
979 {
|
|
980 GaimPresence *gpresence;
|
|
981 GaimStatus *status;
|
|
982
|
|
983 js->state = state;
|
|
984 switch(state) {
|
|
985 case JABBER_STREAM_OFFLINE:
|
|
986 break;
|
|
987 case JABBER_STREAM_CONNECTING:
|
|
988 gaim_connection_update_progress(js->gc, _("Connecting"), 1,
|
|
989 JABBER_CONNECT_STEPS);
|
|
990 break;
|
|
991 case JABBER_STREAM_INITIALIZING:
|
|
992 gaim_connection_update_progress(js->gc, _("Initializing Stream"),
|
|
993 js->gsc ? 5 : 2, JABBER_CONNECT_STEPS);
|
|
994 jabber_stream_init(js);
|
|
995 break;
|
|
996 case JABBER_STREAM_AUTHENTICATING:
|
|
997 gaim_connection_update_progress(js->gc, _("Authenticating"),
|
|
998 js->gsc ? 6 : 3, JABBER_CONNECT_STEPS);
|
|
999 if(js->protocol_version == JABBER_PROTO_0_9 && js->registration) {
|
|
1000 jabber_register_start(js);
|
|
1001 } else if(js->auth_type == JABBER_AUTH_IQ_AUTH) {
|
|
1002 jabber_auth_start_old(js);
|
|
1003 }
|
|
1004 break;
|
|
1005 case JABBER_STREAM_REINITIALIZING:
|
|
1006 gaim_connection_update_progress(js->gc, _("Re-initializing Stream"),
|
|
1007 (js->gsc ? 7 : 4), JABBER_CONNECT_STEPS);
|
|
1008 if (js->gsc) {
|
|
1009 /* The stream will be reinitialized later, in jabber_recv_cb_ssl() */
|
|
1010 js->reinit = TRUE;
|
|
1011 } else {
|
|
1012 jabber_stream_init(js);
|
|
1013 }
|
|
1014 break;
|
|
1015 case JABBER_STREAM_CONNECTED:
|
|
1016 jabber_roster_request(js);
|
|
1017 gpresence = gaim_account_get_presence(js->gc->account);
|
|
1018 status = gaim_presence_get_active_status(gpresence);
|
|
1019 jabber_presence_send(js->gc->account, status);
|
|
1020 gaim_connection_set_state(js->gc, GAIM_CONNECTED);
|
|
1021 jabber_disco_items_server(js);
|
|
1022 break;
|
|
1023 }
|
|
1024 }
|
|
1025
|
|
1026 char *jabber_get_next_id(JabberStream *js)
|
|
1027 {
|
|
1028 return g_strdup_printf("gaim%x", js->next_id++);
|
|
1029 }
|
|
1030
|
|
1031
|
|
1032 static void jabber_idle_set(GaimConnection *gc, int idle)
|
|
1033 {
|
|
1034 JabberStream *js = gc->proto_data;
|
|
1035
|
|
1036 js->idle = idle ? time(NULL) - idle : idle;
|
|
1037 }
|
|
1038
|
|
1039 static const char *jabber_list_icon(GaimAccount *a, GaimBuddy *b)
|
|
1040 {
|
|
1041 return "jabber";
|
|
1042 }
|
|
1043
|
|
1044 static void jabber_list_emblems(GaimBuddy *b, const char **se, const char **sw,
|
|
1045 const char **nw, const char **ne)
|
|
1046 {
|
|
1047 JabberStream *js;
|
|
1048 JabberBuddy *jb = NULL;
|
|
1049
|
|
1050 if(!b->account->gc)
|
|
1051 return;
|
|
1052 js = b->account->gc->proto_data;
|
|
1053 if(js)
|
|
1054 jb = jabber_buddy_find(js, b->name, FALSE);
|
|
1055
|
|
1056 if(!GAIM_BUDDY_IS_ONLINE(b)) {
|
|
1057 if(jb && jb->error_msg)
|
|
1058 *nw = "error";
|
|
1059
|
|
1060 if(jb && (jb->subscription & JABBER_SUB_PENDING ||
|
|
1061 !(jb->subscription & JABBER_SUB_TO)))
|
|
1062 *se = "notauthorized";
|
|
1063 else
|
|
1064 *se = "offline";
|
|
1065 } else {
|
|
1066 GaimStatusType *status_type = gaim_status_get_type(gaim_presence_get_active_status(gaim_buddy_get_presence(b)));
|
|
1067 GaimStatusPrimitive primitive = gaim_status_type_get_primitive(status_type);
|
|
1068
|
|
1069 if(primitive > GAIM_STATUS_AVAILABLE) {
|
|
1070 *se = gaim_status_type_get_id(status_type);
|
|
1071 }
|
|
1072 }
|
|
1073 }
|
|
1074
|
|
1075 static char *jabber_status_text(GaimBuddy *b)
|
|
1076 {
|
|
1077 JabberBuddy *jb = jabber_buddy_find(b->account->gc->proto_data, b->name,
|
|
1078 FALSE);
|
|
1079 char *ret = NULL;
|
|
1080
|
|
1081 if(jb && !GAIM_BUDDY_IS_ONLINE(b) && (jb->subscription & JABBER_SUB_PENDING || !(jb->subscription & JABBER_SUB_TO))) {
|
|
1082 ret = g_strdup(_("Not Authorized"));
|
|
1083 } else if(jb && !GAIM_BUDDY_IS_ONLINE(b) && jb->error_msg) {
|
|
1084 ret = g_strdup(jb->error_msg);
|
|
1085 } else {
|
|
1086 char *stripped;
|
|
1087
|
|
1088 if(!(stripped = gaim_markup_strip_html(jabber_buddy_get_status_msg(jb)))) {
|
|
1089 GaimStatus *status = gaim_presence_get_active_status(gaim_buddy_get_presence(b));
|
|
1090
|
|
1091 if(!gaim_status_is_available(status))
|
|
1092 stripped = g_strdup(gaim_status_get_name(status));
|
|
1093 }
|
|
1094
|
|
1095 if(stripped) {
|
|
1096 ret = g_markup_escape_text(stripped, -1);
|
|
1097 g_free(stripped);
|
|
1098 }
|
|
1099 }
|
|
1100
|
|
1101 return ret;
|
|
1102 }
|
|
1103
|
|
1104 static void jabber_tooltip_text(GaimBuddy *b, GString *str, gboolean full)
|
|
1105 {
|
|
1106 JabberBuddy *jb;
|
|
1107
|
|
1108 g_return_if_fail(b != NULL);
|
|
1109 g_return_if_fail(b->account != NULL);
|
|
1110 g_return_if_fail(b->account->gc != NULL);
|
|
1111 g_return_if_fail(b->account->gc->proto_data != NULL);
|
|
1112
|
|
1113 jb = jabber_buddy_find(b->account->gc->proto_data, b->name,
|
|
1114 FALSE);
|
|
1115
|
|
1116 if(jb) {
|
|
1117 JabberBuddyResource *jbr = NULL;
|
|
1118 const char *sub;
|
|
1119 GList *l;
|
|
1120
|
|
1121 if (full) {
|
|
1122 if(jb->subscription & JABBER_SUB_FROM) {
|
|
1123 if(jb->subscription & JABBER_SUB_TO)
|
|
1124 sub = _("Both");
|
|
1125 else if(jb->subscription & JABBER_SUB_PENDING)
|
|
1126 sub = _("From (To pending)");
|
|
1127 else
|
|
1128 sub = _("From");
|
|
1129 } else {
|
|
1130 if(jb->subscription & JABBER_SUB_TO)
|
|
1131 sub = _("To");
|
|
1132 else if(jb->subscription & JABBER_SUB_PENDING)
|
|
1133 sub = _("None (To pending)");
|
|
1134 else
|
|
1135 sub = _("None");
|
|
1136 }
|
|
1137 g_string_append_printf(str, "\n<b>%s:</b> %s", _("Subscription"), sub);
|
|
1138 }
|
|
1139
|
|
1140 for(l=jb->resources; l; l = l->next) {
|
|
1141 char *text = NULL;
|
|
1142 char *res = NULL;
|
|
1143 const char *state;
|
|
1144
|
|
1145 jbr = l->data;
|
|
1146
|
|
1147 if(jbr->status) {
|
|
1148 char *tmp;
|
|
1149 text = gaim_strreplace(jbr->status, "\n", "<br />\n");
|
|
1150 tmp = gaim_markup_strip_html(text);
|
|
1151 g_free(text);
|
|
1152 text = g_markup_escape_text(tmp, -1);
|
|
1153 g_free(tmp);
|
|
1154 }
|
|
1155
|
|
1156 if(jbr->name)
|
|
1157 res = g_strdup_printf(" (%s)", jbr->name);
|
|
1158
|
|
1159 state = jabber_buddy_state_get_name(jbr->state);
|
|
1160 if (text != NULL && !gaim_utf8_strcasecmp(state, text)) {
|
|
1161 g_free(text);
|
|
1162 text = NULL;
|
|
1163 }
|
|
1164
|
|
1165 g_string_append_printf(str, "\n<b>%s%s:</b> %s%s%s",
|
|
1166 _("Status"),
|
|
1167 res ? res : "",
|
|
1168 state,
|
|
1169 text ? ": " : "",
|
|
1170 text ? text : "");
|
|
1171
|
|
1172 g_free(text);
|
|
1173 g_free(res);
|
|
1174 }
|
|
1175
|
|
1176 if(!GAIM_BUDDY_IS_ONLINE(b) && jb->error_msg) {
|
|
1177 g_string_append_printf(str, "\n<b>%s:</b> %s",
|
|
1178 _("Error"), jb->error_msg);
|
|
1179 }
|
|
1180 }
|
|
1181 }
|
|
1182
|
|
1183 static GList *jabber_status_types(GaimAccount *account)
|
|
1184 {
|
|
1185 GaimStatusType *type;
|
|
1186 GList *types = NULL;
|
|
1187 GaimValue *priority_value;
|
|
1188
|
|
1189 priority_value = gaim_value_new(GAIM_TYPE_INT);
|
|
1190 gaim_value_set_int(priority_value, 1);
|
|
1191 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE,
|
|
1192 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_ONLINE),
|
|
1193 NULL, TRUE, TRUE, FALSE,
|
|
1194 "priority", _("Priority"), priority_value,
|
|
1195 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
|
|
1196 NULL);
|
|
1197 types = g_list_append(types, type);
|
|
1198
|
|
1199 priority_value = gaim_value_new(GAIM_TYPE_INT);
|
|
1200 gaim_value_set_int(priority_value, 1);
|
|
1201 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE,
|
|
1202 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_CHAT),
|
|
1203 _("Chatty"), TRUE, TRUE, FALSE,
|
|
1204 "priority", _("Priority"), priority_value,
|
|
1205 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
|
|
1206 NULL);
|
|
1207 types = g_list_append(types, type);
|
|
1208
|
|
1209 priority_value = gaim_value_new(GAIM_TYPE_INT);
|
|
1210 gaim_value_set_int(priority_value, 0);
|
|
1211 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY,
|
|
1212 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_AWAY),
|
|
1213 NULL, TRUE, TRUE, FALSE,
|
|
1214 "priority", _("Priority"), priority_value,
|
|
1215 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
|
|
1216 NULL);
|
|
1217 types = g_list_append(types, type);
|
|
1218
|
|
1219 priority_value = gaim_value_new(GAIM_TYPE_INT);
|
|
1220 gaim_value_set_int(priority_value, 0);
|
|
1221 type = gaim_status_type_new_with_attrs(GAIM_STATUS_EXTENDED_AWAY,
|
|
1222 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_XA),
|
|
1223 NULL, TRUE, TRUE, FALSE,
|
|
1224 "priority", _("Priority"), priority_value,
|
|
1225 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
|
|
1226 NULL);
|
|
1227 types = g_list_append(types, type);
|
|
1228
|
|
1229 priority_value = gaim_value_new(GAIM_TYPE_INT);
|
|
1230 gaim_value_set_int(priority_value, 0);
|
|
1231 type = gaim_status_type_new_with_attrs(GAIM_STATUS_UNAVAILABLE,
|
|
1232 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_DND),
|
|
1233 _("Do Not Disturb"), TRUE, TRUE, FALSE,
|
|
1234 "priority", _("Priority"), priority_value,
|
|
1235 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
|
|
1236 NULL);
|
|
1237 types = g_list_append(types, type);
|
|
1238
|
|
1239 /*
|
|
1240 if(js->protocol_version == JABBER_PROTO_0_9)
|
|
1241 m = g_list_append(m, _("Invisible"));
|
|
1242 */
|
|
1243
|
|
1244 type = gaim_status_type_new_with_attrs(GAIM_STATUS_OFFLINE,
|
|
1245 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_UNAVAILABLE),
|
|
1246 NULL, FALSE, TRUE, FALSE,
|
|
1247 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
|
|
1248 NULL);
|
|
1249 types = g_list_append(types, type);
|
|
1250
|
|
1251 return types;
|
|
1252 }
|
|
1253
|
|
1254 static void
|
|
1255 jabber_password_change_result_cb(JabberStream *js, xmlnode *packet,
|
|
1256 gpointer data)
|
|
1257 {
|
|
1258 const char *type;
|
|
1259
|
|
1260 type = xmlnode_get_attrib(packet, "type");
|
|
1261
|
|
1262 if(type && !strcmp(type, "result")) {
|
|
1263 gaim_notify_info(js->gc, _("Password Changed"), _("Password Changed"),
|
|
1264 _("Your password has been changed."));
|
|
1265 } else {
|
|
1266 char *msg = jabber_parse_error(js, packet);
|
|
1267
|
|
1268 gaim_notify_error(js->gc, _("Error changing password"),
|
|
1269 _("Error changing password"), msg);
|
|
1270 g_free(msg);
|
|
1271 }
|
|
1272 }
|
|
1273
|
|
1274 static void jabber_password_change_cb(JabberStream *js,
|
|
1275 GaimRequestFields *fields)
|
|
1276 {
|
|
1277 const char *p1, *p2;
|
|
1278 JabberIq *iq;
|
|
1279 xmlnode *query, *y;
|
|
1280
|
|
1281 p1 = gaim_request_fields_get_string(fields, "password1");
|
|
1282 p2 = gaim_request_fields_get_string(fields, "password2");
|
|
1283
|
|
1284 if(strcmp(p1, p2)) {
|
|
1285 gaim_notify_error(js->gc, NULL, _("New passwords do not match."), NULL);
|
|
1286 return;
|
|
1287 }
|
|
1288
|
|
1289 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register");
|
|
1290
|
|
1291 xmlnode_set_attrib(iq->node, "to", js->user->domain);
|
|
1292
|
|
1293 query = xmlnode_get_child(iq->node, "query");
|
|
1294
|
|
1295 y = xmlnode_new_child(query, "username");
|
|
1296 xmlnode_insert_data(y, js->user->node, -1);
|
|
1297 y = xmlnode_new_child(query, "password");
|
|
1298 xmlnode_insert_data(y, p1, -1);
|
|
1299
|
|
1300 jabber_iq_set_callback(iq, jabber_password_change_result_cb, NULL);
|
|
1301
|
|
1302 jabber_iq_send(iq);
|
|
1303
|
|
1304 gaim_account_set_password(js->gc->account, p1);
|
|
1305 }
|
|
1306
|
|
1307 static void jabber_password_change(GaimPluginAction *action)
|
|
1308 {
|
|
1309
|
|
1310 GaimConnection *gc = (GaimConnection *) action->context;
|
|
1311 JabberStream *js = gc->proto_data;
|
|
1312 GaimRequestFields *fields;
|
|
1313 GaimRequestFieldGroup *group;
|
|
1314 GaimRequestField *field;
|
|
1315
|
|
1316 fields = gaim_request_fields_new();
|
|
1317 group = gaim_request_field_group_new(NULL);
|
|
1318 gaim_request_fields_add_group(fields, group);
|
|
1319
|
|
1320 field = gaim_request_field_string_new("password1", _("Password"),
|
|
1321 "", FALSE);
|
|
1322 gaim_request_field_string_set_masked(field, TRUE);
|
|
1323 gaim_request_field_group_add_field(group, field);
|
|
1324
|
|
1325 field = gaim_request_field_string_new("password2", _("Password (again)"),
|
|
1326 "", FALSE);
|
|
1327 gaim_request_field_string_set_masked(field, TRUE);
|
|
1328 gaim_request_field_group_add_field(group, field);
|
|
1329
|
|
1330 gaim_request_fields(js->gc, _("Change Jabber Password"),
|
|
1331 _("Change Jabber Password"), _("Please enter your new password"),
|
|
1332 fields, _("OK"), G_CALLBACK(jabber_password_change_cb),
|
|
1333 _("Cancel"), NULL, js);
|
|
1334 }
|
|
1335
|
|
1336 static GList *jabber_actions(GaimPlugin *plugin, gpointer context)
|
|
1337 {
|
|
1338 GList *m = NULL;
|
|
1339 GaimPluginAction *act;
|
|
1340
|
|
1341 act = gaim_plugin_action_new(_("Set User Info..."),
|
|
1342 jabber_setup_set_info);
|
|
1343 m = g_list_append(m, act);
|
|
1344
|
|
1345 /* if (js->protocol_options & CHANGE_PASSWORD) { */
|
|
1346 act = gaim_plugin_action_new(_("Change Password..."),
|
|
1347 jabber_password_change);
|
|
1348 m = g_list_append(m, act);
|
|
1349 /* } */
|
|
1350
|
|
1351 act = gaim_plugin_action_new(_("Search for Users..."),
|
|
1352 jabber_user_search_begin);
|
|
1353 m = g_list_append(m, act);
|
|
1354
|
|
1355 return m;
|
|
1356 }
|
|
1357
|
|
1358 static GaimChat *jabber_find_blist_chat(GaimAccount *account, const char *name)
|
|
1359 {
|
|
1360 GaimBlistNode *gnode, *cnode;
|
|
1361 JabberID *jid;
|
|
1362
|
|
1363 if(!(jid = jabber_id_new(name)))
|
|
1364 return NULL;
|
|
1365
|
|
1366 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) {
|
|
1367 for(cnode = gnode->child; cnode; cnode = cnode->next) {
|
|
1368 GaimChat *chat = (GaimChat*)cnode;
|
|
1369 const char *room, *server;
|
|
1370 if(!GAIM_BLIST_NODE_IS_CHAT(cnode))
|
|
1371 continue;
|
|
1372
|
|
1373 if(chat->account != account)
|
|
1374 continue;
|
|
1375
|
|
1376 if(!(room = g_hash_table_lookup(chat->components, "room")))
|
|
1377 continue;
|
|
1378 if(!(server = g_hash_table_lookup(chat->components, "server")))
|
|
1379 continue;
|
|
1380
|
|
1381 if(jid->node && jid->domain &&
|
|
1382 !g_utf8_collate(room, jid->node) && !g_utf8_collate(server, jid->domain)) {
|
|
1383 jabber_id_free(jid);
|
|
1384 return chat;
|
|
1385 }
|
|
1386 }
|
|
1387 }
|
|
1388 jabber_id_free(jid);
|
|
1389 return NULL;
|
|
1390 }
|
|
1391
|
|
1392 static void jabber_convo_closed(GaimConnection *gc, const char *who)
|
|
1393 {
|
|
1394 JabberStream *js = gc->proto_data;
|
|
1395 JabberID *jid;
|
|
1396 JabberBuddy *jb;
|
|
1397 JabberBuddyResource *jbr;
|
|
1398
|
|
1399 if(!(jid = jabber_id_new(who)))
|
|
1400 return;
|
|
1401
|
|
1402 if((jb = jabber_buddy_find(js, who, TRUE)) &&
|
|
1403 (jbr = jabber_buddy_find_resource(jb, jid->resource))) {
|
|
1404 if(jbr->thread_id) {
|
|
1405 g_free(jbr->thread_id);
|
|
1406 jbr->thread_id = NULL;
|
|
1407 }
|
|
1408 }
|
|
1409
|
|
1410 jabber_id_free(jid);
|
|
1411 }
|
|
1412
|
|
1413
|
|
1414 char *jabber_parse_error(JabberStream *js, xmlnode *packet)
|
|
1415 {
|
|
1416 xmlnode *error;
|
|
1417 const char *code = NULL, *text = NULL;
|
|
1418 const char *xmlns = xmlnode_get_namespace(packet);
|
|
1419 char *cdata = NULL;
|
|
1420
|
|
1421 if((error = xmlnode_get_child(packet, "error"))) {
|
|
1422 cdata = xmlnode_get_data(error);
|
|
1423 code = xmlnode_get_attrib(error, "code");
|
|
1424
|
|
1425 /* Stanza errors */
|
|
1426 if(xmlnode_get_child(error, "bad-request")) {
|
|
1427 text = _("Bad Request");
|
|
1428 } else if(xmlnode_get_child(error, "conflict")) {
|
|
1429 text = _("Conflict");
|
|
1430 } else if(xmlnode_get_child(error, "feature-not-implemented")) {
|
|
1431 text = _("Feature Not Implemented");
|
|
1432 } else if(xmlnode_get_child(error, "forbidden")) {
|
|
1433 text = _("Forbidden");
|
|
1434 } else if(xmlnode_get_child(error, "gone")) {
|
|
1435 text = _("Gone");
|
|
1436 } else if(xmlnode_get_child(error, "internal-server-error")) {
|
|
1437 text = _("Internal Server Error");
|
|
1438 } else if(xmlnode_get_child(error, "item-not-found")) {
|
|
1439 text = _("Item Not Found");
|
|
1440 } else if(xmlnode_get_child(error, "jid-malformed")) {
|
|
1441 text = _("Malformed Jabber ID");
|
|
1442 } else if(xmlnode_get_child(error, "not-acceptable")) {
|
|
1443 text = _("Not Acceptable");
|
|
1444 } else if(xmlnode_get_child(error, "not-allowed")) {
|
|
1445 text = _("Not Allowed");
|
|
1446 } else if(xmlnode_get_child(error, "not-authorized")) {
|
|
1447 text = _("Not Authorized");
|
|
1448 } else if(xmlnode_get_child(error, "payment-required")) {
|
|
1449 text = _("Payment Required");
|
|
1450 } else if(xmlnode_get_child(error, "recipient-unavailable")) {
|
|
1451 text = _("Recipient Unavailable");
|
|
1452 } else if(xmlnode_get_child(error, "redirect")) {
|
|
1453 /* XXX */
|
|
1454 } else if(xmlnode_get_child(error, "registration-required")) {
|
|
1455 text = _("Registration Required");
|
|
1456 } else if(xmlnode_get_child(error, "remote-server-not-found")) {
|
|
1457 text = _("Remote Server Not Found");
|
|
1458 } else if(xmlnode_get_child(error, "remote-server-timeout")) {
|
|
1459 text = _("Remote Server Timeout");
|
|
1460 } else if(xmlnode_get_child(error, "resource-constraint")) {
|
|
1461 text = _("Server Overloaded");
|
|
1462 } else if(xmlnode_get_child(error, "service-unavailable")) {
|
|
1463 text = _("Service Unavailable");
|
|
1464 } else if(xmlnode_get_child(error, "subscription-required")) {
|
|
1465 text = _("Subscription Required");
|
|
1466 } else if(xmlnode_get_child(error, "unexpected-request")) {
|
|
1467 text = _("Unexpected Request");
|
|
1468 } else if(xmlnode_get_child(error, "undefined-condition")) {
|
|
1469 text = _("Unknown Error");
|
|
1470 }
|
|
1471 } else if(xmlns && !strcmp(xmlns, "urn:ietf:params:xml:ns:xmpp-sasl")) {
|
|
1472 if(xmlnode_get_child(packet, "aborted")) {
|
|
1473 js->gc->wants_to_die = TRUE;
|
|
1474 text = _("Authorization Aborted");
|
|
1475 } else if(xmlnode_get_child(packet, "incorrect-encoding")) {
|
|
1476 text = _("Incorrect encoding in authorization");
|
|
1477 } else if(xmlnode_get_child(packet, "invalid-authzid")) {
|
|
1478 js->gc->wants_to_die = TRUE;
|
|
1479 text = _("Invalid authzid");
|
|
1480 } else if(xmlnode_get_child(packet, "invalid-mechanism")) {
|
|
1481 js->gc->wants_to_die = TRUE;
|
|
1482 text = _("Invalid Authorization Mechanism");
|
|
1483 } else if(xmlnode_get_child(packet, "mechanism-too-weak")) {
|
|
1484 js->gc->wants_to_die = TRUE;
|
|
1485 text = _("Authorization mechanism too weak");
|
|
1486 } else if(xmlnode_get_child(packet, "not-authorized")) {
|
|
1487 js->gc->wants_to_die = TRUE;
|
|
1488 text = _("Not Authorized");
|
|
1489 } else if(xmlnode_get_child(packet, "temporary-auth-failure")) {
|
|
1490 text = _("Temporary Authentication Failure");
|
|
1491 } else {
|
|
1492 js->gc->wants_to_die = TRUE;
|
|
1493 text = _("Authentication Failure");
|
|
1494 }
|
|
1495 } else if(!strcmp(packet->name, "stream:error")) {
|
|
1496 if(xmlnode_get_child(packet, "bad-format")) {
|
|
1497 text = _("Bad Format");
|
|
1498 } else if(xmlnode_get_child(packet, "bad-namespace-prefix")) {
|
|
1499 text = _("Bad Namespace Prefix");
|
|
1500 } else if(xmlnode_get_child(packet, "conflict")) {
|
|
1501 js->gc->wants_to_die = TRUE;
|
|
1502 text = _("Resource Conflict");
|
|
1503 } else if(xmlnode_get_child(packet, "connection-timeout")) {
|
|
1504 text = _("Connection Timeout");
|
|
1505 } else if(xmlnode_get_child(packet, "host-gone")) {
|
|
1506 text = _("Host Gone");
|
|
1507 } else if(xmlnode_get_child(packet, "host-unknown")) {
|
|
1508 text = _("Host Unknown");
|
|
1509 } else if(xmlnode_get_child(packet, "improper-addressing")) {
|
|
1510 text = _("Improper Addressing");
|
|
1511 } else if(xmlnode_get_child(packet, "internal-server-error")) {
|
|
1512 text = _("Internal Server Error");
|
|
1513 } else if(xmlnode_get_child(packet, "invalid-id")) {
|
|
1514 text = _("Invalid ID");
|
|
1515 } else if(xmlnode_get_child(packet, "invalid-namespace")) {
|
|
1516 text = _("Invalid Namespace");
|
|
1517 } else if(xmlnode_get_child(packet, "invalid-xml")) {
|
|
1518 text = _("Invalid XML");
|
|
1519 } else if(xmlnode_get_child(packet, "nonmatching-hosts")) {
|
|
1520 text = _("Non-matching Hosts");
|
|
1521 } else if(xmlnode_get_child(packet, "not-authorized")) {
|
|
1522 text = _("Not Authorized");
|
|
1523 } else if(xmlnode_get_child(packet, "policy-violation")) {
|
|
1524 text = _("Policy Violation");
|
|
1525 } else if(xmlnode_get_child(packet, "remote-connection-failed")) {
|
|
1526 text = _("Remote Connection Failed");
|
|
1527 } else if(xmlnode_get_child(packet, "resource-constraint")) {
|
|
1528 text = _("Resource Constraint");
|
|
1529 } else if(xmlnode_get_child(packet, "restricted-xml")) {
|
|
1530 text = _("Restricted XML");
|
|
1531 } else if(xmlnode_get_child(packet, "see-other-host")) {
|
|
1532 text = _("See Other Host");
|
|
1533 } else if(xmlnode_get_child(packet, "system-shutdown")) {
|
|
1534 text = _("System Shutdown");
|
|
1535 } else if(xmlnode_get_child(packet, "undefined-condition")) {
|
|
1536 text = _("Undefined Condition");
|
|
1537 } else if(xmlnode_get_child(packet, "unsupported-encoding")) {
|
|
1538 text = _("Unsupported Encoding");
|
|
1539 } else if(xmlnode_get_child(packet, "unsupported-stanza-type")) {
|
|
1540 text = _("Unsupported Stanza Type");
|
|
1541 } else if(xmlnode_get_child(packet, "unsupported-version")) {
|
|
1542 text = _("Unsupported Version");
|
|
1543 } else if(xmlnode_get_child(packet, "xml-not-well-formed")) {
|
|
1544 text = _("XML Not Well Formed");
|
|
1545 } else {
|
|
1546 text = _("Stream Error");
|
|
1547 }
|
|
1548 }
|
|
1549
|
|
1550 if(text || cdata) {
|
|
1551 char *ret = g_strdup_printf("%s%s%s", code ? code : "",
|
|
1552 code ? ": " : "", text ? text : cdata);
|
|
1553 g_free(cdata);
|
|
1554 return ret;
|
|
1555 } else {
|
|
1556 return NULL;
|
|
1557 }
|
|
1558 }
|
|
1559
|
|
1560 static GaimCmdRet jabber_cmd_chat_config(GaimConversation *conv,
|
|
1561 const char *cmd, char **args, char **error, void *data)
|
|
1562 {
|
|
1563 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1564 jabber_chat_request_room_configure(chat);
|
|
1565 return GAIM_CMD_RET_OK;
|
|
1566 }
|
|
1567
|
|
1568 static GaimCmdRet jabber_cmd_chat_register(GaimConversation *conv,
|
|
1569 const char *cmd, char **args, char **error, void *data)
|
|
1570 {
|
|
1571 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1572 jabber_chat_register(chat);
|
|
1573 return GAIM_CMD_RET_OK;
|
|
1574 }
|
|
1575
|
|
1576 static GaimCmdRet jabber_cmd_chat_topic(GaimConversation *conv,
|
|
1577 const char *cmd, char **args, char **error, void *data)
|
|
1578 {
|
|
1579 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1580 jabber_chat_change_topic(chat, args ? args[0] : NULL);
|
|
1581 return GAIM_CMD_RET_OK;
|
|
1582 }
|
|
1583
|
|
1584 static GaimCmdRet jabber_cmd_chat_nick(GaimConversation *conv,
|
|
1585 const char *cmd, char **args, char **error, void *data)
|
|
1586 {
|
|
1587 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1588
|
|
1589 if(!args || !args[0])
|
|
1590 return GAIM_CMD_RET_FAILED;
|
|
1591
|
|
1592 jabber_chat_change_nick(chat, args[0]);
|
|
1593 return GAIM_CMD_RET_OK;
|
|
1594 }
|
|
1595
|
|
1596 static GaimCmdRet jabber_cmd_chat_part(GaimConversation *conv,
|
|
1597 const char *cmd, char **args, char **error, void *data)
|
|
1598 {
|
|
1599 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1600 jabber_chat_part(chat, args ? args[0] : NULL);
|
|
1601 return GAIM_CMD_RET_OK;
|
|
1602 }
|
|
1603
|
|
1604 static GaimCmdRet jabber_cmd_chat_ban(GaimConversation *conv,
|
|
1605 const char *cmd, char **args, char **error, void *data)
|
|
1606 {
|
|
1607 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1608
|
|
1609 if(!args || !args[0])
|
|
1610 return GAIM_CMD_RET_FAILED;
|
|
1611
|
|
1612 if(!jabber_chat_ban_user(chat, args[0], args[1])) {
|
|
1613 *error = g_strdup_printf(_("Unable to ban user %s"), args[0]);
|
|
1614 return GAIM_CMD_RET_FAILED;
|
|
1615 }
|
|
1616
|
|
1617 return GAIM_CMD_RET_OK;
|
|
1618 }
|
|
1619
|
|
1620 static GaimCmdRet jabber_cmd_chat_affiliate(GaimConversation *conv,
|
|
1621 const char *cmd, char **args, char **error, void *data)
|
|
1622 {
|
|
1623 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1624
|
|
1625 if (!args || !args[0] || !args[1])
|
|
1626 return GAIM_CMD_RET_FAILED;
|
|
1627
|
|
1628 if (strcmp(args[1], "owner") != 0 &&
|
|
1629 strcmp(args[1], "admin") != 0 &&
|
|
1630 strcmp(args[1], "member") != 0 &&
|
|
1631 strcmp(args[1], "outcast") != 0 &&
|
|
1632 strcmp(args[1], "none") != 0) {
|
|
1633 *error = g_strdup_printf(_("Unknown affiliation: \"%s\""), args[1]);
|
|
1634 return GAIM_CMD_RET_FAILED;
|
|
1635 }
|
|
1636
|
|
1637 if (!jabber_chat_affiliate_user(chat, args[0], args[1])) {
|
|
1638 *error = g_strdup_printf(_("Unable to affiliate user %s as \"%s\""), args[0], args[1]);
|
|
1639 return GAIM_CMD_RET_FAILED;
|
|
1640 }
|
|
1641
|
|
1642 return GAIM_CMD_RET_OK;
|
|
1643 }
|
|
1644
|
|
1645 static GaimCmdRet jabber_cmd_chat_role(GaimConversation *conv,
|
|
1646 const char *cmd, char **args, char **error, void *data)
|
|
1647 {
|
|
1648 JabberChat *chat;
|
|
1649
|
|
1650 if (!args || !args[0] || !args[1])
|
|
1651 return GAIM_CMD_RET_FAILED;
|
|
1652
|
|
1653 if (strcmp(args[1], "moderator") != 0 &&
|
|
1654 strcmp(args[1], "participant") != 0 &&
|
|
1655 strcmp(args[1], "visitor") != 0 &&
|
|
1656 strcmp(args[1], "none") != 0) {
|
|
1657 *error = g_strdup_printf(_("Unknown role: \"%s\""), args[1]);
|
|
1658 return GAIM_CMD_RET_FAILED;
|
|
1659 }
|
|
1660
|
|
1661 chat = jabber_chat_find_by_conv(conv);
|
|
1662
|
|
1663 if (!jabber_chat_role_user(chat, args[0], args[1])) {
|
|
1664 *error = g_strdup_printf(_("Unable to set role \"%s\" for user: %s"),
|
|
1665 args[1], args[0]);
|
|
1666 return GAIM_CMD_RET_FAILED;
|
|
1667 }
|
|
1668
|
|
1669 return GAIM_CMD_RET_OK;
|
|
1670 }
|
|
1671
|
|
1672 static GaimCmdRet jabber_cmd_chat_invite(GaimConversation *conv,
|
|
1673 const char *cmd, char **args, char **error, void *data)
|
|
1674 {
|
|
1675 if(!args || !args[0])
|
|
1676 return GAIM_CMD_RET_FAILED;
|
|
1677
|
|
1678 jabber_chat_invite(gaim_conversation_get_gc(conv),
|
|
1679 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), args[1] ? args[1] : "",
|
|
1680 args[0]);
|
|
1681
|
|
1682 return GAIM_CMD_RET_OK;
|
|
1683 }
|
|
1684
|
|
1685 static GaimCmdRet jabber_cmd_chat_join(GaimConversation *conv,
|
|
1686 const char *cmd, char **args, char **error, void *data)
|
|
1687 {
|
|
1688 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1689 GHashTable *components;
|
|
1690
|
|
1691 if(!args || !args[0])
|
|
1692 return GAIM_CMD_RET_FAILED;
|
|
1693
|
|
1694 components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
|
|
1695
|
|
1696 g_hash_table_replace(components, "room", args[0]);
|
|
1697 g_hash_table_replace(components, "server", chat->server);
|
|
1698 g_hash_table_replace(components, "handle", chat->handle);
|
|
1699 if(args[1])
|
|
1700 g_hash_table_replace(components, "password", args[1]);
|
|
1701
|
|
1702 jabber_chat_join(gaim_conversation_get_gc(conv), components);
|
|
1703
|
|
1704 g_hash_table_destroy(components);
|
|
1705 return GAIM_CMD_RET_OK;
|
|
1706 }
|
|
1707
|
|
1708 static GaimCmdRet jabber_cmd_chat_kick(GaimConversation *conv,
|
|
1709 const char *cmd, char **args, char **error, void *data)
|
|
1710 {
|
|
1711 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1712
|
|
1713 if(!args || !args[0])
|
|
1714 return GAIM_CMD_RET_FAILED;
|
|
1715
|
|
1716 if(!jabber_chat_kick_user(chat, args[0], args[1])) {
|
|
1717 *error = g_strdup_printf(_("Unable to kick user %s"), args[0]);
|
|
1718 return GAIM_CMD_RET_FAILED;
|
|
1719 }
|
|
1720
|
|
1721 return GAIM_CMD_RET_OK;
|
|
1722 }
|
|
1723
|
|
1724 static GaimCmdRet jabber_cmd_chat_msg(GaimConversation *conv,
|
|
1725 const char *cmd, char **args, char **error, void *data)
|
|
1726 {
|
|
1727 JabberChat *chat = jabber_chat_find_by_conv(conv);
|
|
1728 char *who;
|
|
1729
|
|
1730 who = g_strdup_printf("%s@%s/%s", chat->room, chat->server, args[0]);
|
|
1731
|
|
1732 jabber_message_send_im(gaim_conversation_get_gc(conv), who, args[1], 0);
|
|
1733
|
|
1734 g_free(who);
|
|
1735 return GAIM_CMD_RET_OK;
|
|
1736 }
|
|
1737
|
|
1738 static gboolean jabber_offline_message(const GaimBuddy *buddy)
|
|
1739 {
|
|
1740 return TRUE;
|
|
1741 }
|
|
1742
|
|
1743 static void jabber_register_commands(void)
|
|
1744 {
|
|
1745 gaim_cmd_register("config", "", GAIM_CMD_P_PRPL,
|
|
1746 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1747 "prpl-jabber", jabber_cmd_chat_config,
|
|
1748 _("config: Configure a chat room."), NULL);
|
|
1749 gaim_cmd_register("configure", "", GAIM_CMD_P_PRPL,
|
|
1750 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1751 "prpl-jabber", jabber_cmd_chat_config,
|
|
1752 _("configure: Configure a chat room."), NULL);
|
|
1753 gaim_cmd_register("nick", "s", GAIM_CMD_P_PRPL,
|
|
1754 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1755 "prpl-jabber", jabber_cmd_chat_nick,
|
|
1756 _("nick <new nickname>: Change your nickname."),
|
|
1757 NULL);
|
|
1758 gaim_cmd_register("part", "s", GAIM_CMD_P_PRPL,
|
|
1759 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1760 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1761 jabber_cmd_chat_part, _("part [room]: Leave the room."),
|
|
1762 NULL);
|
|
1763 gaim_cmd_register("register", "", GAIM_CMD_P_PRPL,
|
|
1764 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1765 "prpl-jabber", jabber_cmd_chat_register,
|
|
1766 _("register: Register with a chat room."), NULL);
|
|
1767 /* XXX: there needs to be a core /topic cmd, methinks */
|
|
1768 gaim_cmd_register("topic", "s", GAIM_CMD_P_PRPL,
|
|
1769 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1770 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1771 jabber_cmd_chat_topic,
|
|
1772 _("topic [new topic]: View or change the topic."),
|
|
1773 NULL);
|
|
1774 gaim_cmd_register("ban", "ws", GAIM_CMD_P_PRPL,
|
|
1775 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1776 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1777 jabber_cmd_chat_ban,
|
|
1778 _("ban <user> [room]: Ban a user from the room."),
|
|
1779 NULL);
|
|
1780 gaim_cmd_register("affiliate", "ws", GAIM_CMD_P_PRPL,
|
|
1781 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1782 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1783 jabber_cmd_chat_affiliate,
|
|
1784 _("affiliate <user> <owner|admin|member|outcast|none>: Set a user's affiliation with the room."),
|
|
1785 NULL);
|
|
1786 gaim_cmd_register("role", "ws", GAIM_CMD_P_PRPL,
|
|
1787 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1788 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1789 jabber_cmd_chat_role,
|
|
1790 _("role <user> <moderator|participant|visitor|none>: Set a user's role in the room."),
|
|
1791 NULL);
|
|
1792 gaim_cmd_register("invite", "ws", GAIM_CMD_P_PRPL,
|
|
1793 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1794 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1795 jabber_cmd_chat_invite,
|
|
1796 _("invite <user> [message]: Invite a user to the room."),
|
|
1797 NULL);
|
|
1798 gaim_cmd_register("join", "ws", GAIM_CMD_P_PRPL,
|
|
1799 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1800 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1801 jabber_cmd_chat_join,
|
|
1802 _("join: <room> [server]: Join a chat on this server."),
|
|
1803 NULL);
|
|
1804 gaim_cmd_register("kick", "ws", GAIM_CMD_P_PRPL,
|
|
1805 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1806 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
|
|
1807 jabber_cmd_chat_kick,
|
|
1808 _("kick <user> [room]: Kick a user from the room."),
|
|
1809 NULL);
|
|
1810 gaim_cmd_register("msg", "ws", GAIM_CMD_P_PRPL,
|
|
1811 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1812 "prpl-jabber", jabber_cmd_chat_msg,
|
|
1813 _("msg <user> <message>: Send a private message to another user."),
|
|
1814 NULL);
|
|
1815 }
|
|
1816
|
|
1817 static GaimPluginProtocolInfo prpl_info =
|
|
1818 {
|
|
1819 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME,
|
|
1820 NULL, /* user_splits */
|
|
1821 NULL, /* protocol_options */
|
|
1822 {"jpeg,gif,png", 0, 0, 96, 96, GAIM_ICON_SCALE_DISPLAY}, /* icon_spec */
|
|
1823 jabber_list_icon, /* list_icon */
|
|
1824 jabber_list_emblems, /* list_emblems */
|
|
1825 jabber_status_text, /* status_text */
|
|
1826 jabber_tooltip_text, /* tooltip_text */
|
|
1827 jabber_status_types, /* status_types */
|
|
1828 jabber_blist_node_menu, /* blist_node_menu */
|
|
1829 jabber_chat_info, /* chat_info */
|
|
1830 jabber_chat_info_defaults, /* chat_info_defaults */
|
|
1831 jabber_login, /* login */
|
|
1832 jabber_close, /* close */
|
|
1833 jabber_message_send_im, /* send_im */
|
|
1834 jabber_set_info, /* set_info */
|
|
1835 jabber_send_typing, /* send_typing */
|
|
1836 jabber_buddy_get_info, /* get_info */
|
|
1837 jabber_presence_send, /* set_away */
|
|
1838 jabber_idle_set, /* set_idle */
|
|
1839 NULL, /* change_passwd */
|
|
1840 jabber_roster_add_buddy, /* add_buddy */
|
|
1841 NULL, /* add_buddies */
|
|
1842 jabber_roster_remove_buddy, /* remove_buddy */
|
|
1843 NULL, /* remove_buddies */
|
|
1844 NULL, /* add_permit */
|
|
1845 NULL, /* add_deny */
|
|
1846 NULL, /* rem_permit */
|
|
1847 NULL, /* rem_deny */
|
|
1848 NULL, /* set_permit_deny */
|
|
1849 jabber_chat_join, /* join_chat */
|
|
1850 NULL, /* reject_chat */
|
|
1851 jabber_get_chat_name, /* get_chat_name */
|
|
1852 jabber_chat_invite, /* chat_invite */
|
|
1853 jabber_chat_leave, /* chat_leave */
|
|
1854 NULL, /* chat_whisper */
|
|
1855 jabber_message_send_chat, /* chat_send */
|
|
1856 jabber_keepalive, /* keepalive */
|
|
1857 jabber_register_account, /* register_user */
|
|
1858 jabber_buddy_get_info_chat, /* get_cb_info */
|
|
1859 NULL, /* get_cb_away */
|
|
1860 jabber_roster_alias_change, /* alias_buddy */
|
|
1861 jabber_roster_group_change, /* group_buddy */
|
|
1862 jabber_roster_group_rename, /* rename_group */
|
|
1863 NULL, /* buddy_free */
|
|
1864 jabber_convo_closed, /* convo_closed */
|
|
1865 jabber_normalize, /* normalize */
|
|
1866 jabber_set_buddy_icon, /* set_buddy_icon */
|
|
1867 NULL, /* remove_group */
|
|
1868 jabber_chat_buddy_real_name, /* get_cb_real_name */
|
|
1869 jabber_chat_set_topic, /* set_chat_topic */
|
|
1870 jabber_find_blist_chat, /* find_blist_chat */
|
|
1871 jabber_roomlist_get_list, /* roomlist_get_list */
|
|
1872 jabber_roomlist_cancel, /* roomlist_cancel */
|
|
1873 NULL, /* roomlist_expand_category */
|
|
1874 NULL, /* can_receive_file */
|
|
1875 jabber_si_xfer_send, /* send_file */
|
|
1876 jabber_si_new_xfer, /* new_xfer */
|
|
1877 jabber_offline_message, /* offline_message */
|
|
1878 NULL, /* whiteboard_prpl_ops */
|
|
1879 };
|
|
1880
|
|
1881 static GaimPluginInfo info =
|
|
1882 {
|
|
1883 GAIM_PLUGIN_MAGIC,
|
|
1884 GAIM_MAJOR_VERSION,
|
|
1885 GAIM_MINOR_VERSION,
|
|
1886 GAIM_PLUGIN_PROTOCOL, /**< type */
|
|
1887 NULL, /**< ui_requirement */
|
|
1888 0, /**< flags */
|
|
1889 NULL, /**< dependencies */
|
|
1890 GAIM_PRIORITY_DEFAULT, /**< priority */
|
|
1891
|
|
1892 "prpl-jabber", /**< id */
|
|
1893 "Jabber", /**< name */
|
|
1894 VERSION, /**< version */
|
|
1895 /** summary */
|
|
1896 N_("Jabber Protocol Plugin"),
|
|
1897 /** description */
|
|
1898 N_("Jabber Protocol Plugin"),
|
|
1899 NULL, /**< author */
|
|
1900 GAIM_WEBSITE, /**< homepage */
|
|
1901
|
|
1902 NULL, /**< load */
|
|
1903 NULL, /**< unload */
|
|
1904 NULL, /**< destroy */
|
|
1905
|
|
1906 NULL, /**< ui_info */
|
|
1907 &prpl_info, /**< extra_info */
|
|
1908 NULL, /**< prefs_info */
|
|
1909 jabber_actions
|
|
1910 };
|
|
1911
|
|
1912 static void
|
|
1913 init_plugin(GaimPlugin *plugin)
|
|
1914 {
|
|
1915 GaimAccountUserSplit *split;
|
|
1916 GaimAccountOption *option;
|
|
1917
|
|
1918 split = gaim_account_user_split_new(_("Server"), "jabber.org", '@');
|
|
1919 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);
|
|
1920
|
|
1921 split = gaim_account_user_split_new(_("Resource"), "Home", '/');
|
|
1922 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);
|
|
1923
|
|
1924 option = gaim_account_option_bool_new(_("Use TLS if available"), "use_tls",
|
|
1925 TRUE);
|
|
1926 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
|
|
1927 option);
|
|
1928
|
|
1929 option = gaim_account_option_bool_new(_("Require TLS"), "require_tls", TRUE);
|
|
1930 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
1931
|
|
1932 option = gaim_account_option_bool_new(_("Force old (port 5223) SSL"), "old_ssl", FALSE);
|
|
1933 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
|
|
1934 option);
|
|
1935
|
|
1936 option = gaim_account_option_bool_new(
|
|
1937 _("Allow plaintext auth over unencrypted streams"),
|
|
1938 "auth_plain_in_clear", FALSE);
|
|
1939 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
|
|
1940 option);
|
|
1941
|
|
1942 option = gaim_account_option_int_new(_("Connect port"), "port", 5222);
|
|
1943 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
|
|
1944 option);
|
|
1945
|
|
1946 option = gaim_account_option_string_new(_("Connect server"),
|
|
1947 "connect_server", NULL);
|
|
1948 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
|
|
1949 option);
|
|
1950
|
|
1951 my_protocol = plugin;
|
|
1952
|
|
1953 gaim_prefs_remove("/plugins/prpl/jabber");
|
|
1954
|
|
1955 /* XXX - If any other plugin wants SASL this won't be good ... */
|
|
1956 #ifdef HAVE_CYRUS_SASL
|
|
1957 sasl_client_init(NULL);
|
|
1958 #endif
|
|
1959 jabber_register_commands();
|
|
1960 }
|
|
1961
|
|
1962 GAIM_INIT_PLUGIN(jabber, init_plugin, info);
|