comparison libgaim/protocols/jabber/jabber.c @ 14192:60b1bc8dbf37

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