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