Mercurial > pidgin.yaz
annotate src/protocols/jabber/jabber.c @ 11110:f7ce10cad83d
[gaim-migrate @ 13162]
Make drag-and-drop buddy icon setting work for protocols that don't have file transfer.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 17 Jul 2005 21:38:59 +0000 |
parents | 50224ac8184d |
children | 2c930d591492 |
rev | line source |
---|---|
2086 | 1 /* |
7014 | 2 * gaim - Jabber Protocol Plugin |
2086 | 3 * |
7014 | 4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> |
2086 | 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. | |
7014 | 10 * |
2086 | 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 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
21 #include "internal.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
22 |
7014 | 23 #include "account.h" |
24 #include "accountopt.h" | |
9030 | 25 #include "blist.h" |
9130 | 26 #include "cmds.h" |
10740 | 27 #include "connection.h" |
7014 | 28 #include "debug.h" |
29 #include "message.h" | |
7072 | 30 #include "notify.h" |
8713 | 31 #include "pluginpref.h" |
7014 | 32 #include "prpl.h" |
7072 | 33 #include "request.h" |
7014 | 34 #include "server.h" |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7072
diff
changeset
|
35 #include "util.h" |
9943 | 36 #include "version.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
37 |
7014 | 38 #include "auth.h" |
39 #include "buddy.h" | |
40 #include "chat.h" | |
8312 | 41 #include "disco.h" |
7014 | 42 #include "iq.h" |
43 #include "jutil.h" | |
44 #include "message.h" | |
45 #include "parser.h" | |
46 #include "presence.h" | |
47 #include "jabber.h" | |
48 #include "roster.h" | |
9466 | 49 #include "si.h" |
7923 | 50 #include "xdata.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
51 |
7014 | 52 #define JABBER_CONNECT_STEPS (js->gsc ? 8 : 5) |
2086 | 53 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
54 static GaimPlugin *my_protocol = NULL; |
4249 | 55 |
7014 | 56 static void jabber_stream_init(JabberStream *js) |
57 { | |
58 char *open_stream; | |
3340 | 59 |
7014 | 60 open_stream = g_strdup_printf("<stream:stream to='%s' " |
61 "xmlns='jabber:client' " | |
7395 | 62 "xmlns:stream='http://etherx.jabber.org/streams' " |
63 "version='1.0'>", | |
7291 | 64 js->user->domain); |
3311 | 65 |
7642 | 66 jabber_send_raw(js, open_stream, -1); |
2086 | 67 |
7014 | 68 g_free(open_stream); |
2086 | 69 } |
70 | |
7395 | 71 static void |
72 jabber_session_initialized_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
3311 | 73 { |
7014 | 74 const char *type = xmlnode_get_attrib(packet, "type"); |
75 if(type && !strcmp(type, "result")) { | |
76 jabber_stream_set_state(js, JABBER_STREAM_CONNECTED); | |
77 } else { | |
78 gaim_connection_error(js->gc, _("Error initializing session")); | |
3311 | 79 } |
80 } | |
81 | |
7014 | 82 static void jabber_session_init(JabberStream *js) |
3311 | 83 { |
7014 | 84 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); |
85 xmlnode *session; | |
3311 | 86 |
7395 | 87 jabber_iq_set_callback(iq, jabber_session_initialized_cb, NULL); |
3311 | 88 |
7014 | 89 session = xmlnode_new_child(iq->node, "session"); |
90 xmlnode_set_attrib(session, "xmlns", "urn:ietf:params:xml:ns:xmpp-session"); | |
3311 | 91 |
7014 | 92 jabber_iq_send(iq); |
3311 | 93 } |
94 | |
7395 | 95 static void jabber_bind_result_cb(JabberStream *js, xmlnode *packet, |
96 gpointer data) | |
97 { | |
8401 | 98 const char *type = xmlnode_get_attrib(packet, "type"); |
99 xmlnode *bind; | |
100 | |
101 if(type && !strcmp(type, "result") && | |
102 (bind = xmlnode_get_child_with_namespace(packet, "bind", "urn:ietf:params:xml:ns:xmpp-bind"))) { | |
103 xmlnode *jid; | |
104 char *full_jid; | |
105 if((jid = xmlnode_get_child(bind, "jid")) && (full_jid = xmlnode_get_data(jid))) { | |
10289 | 106 JabberBuddy *my_jb = NULL; |
8401 | 107 jabber_id_free(js->user); |
108 if(!(js->user = jabber_id_new(full_jid))) { | |
109 gaim_connection_error(js->gc, _("Invalid response from server.")); | |
110 } | |
10289 | 111 if((my_jb = jabber_buddy_find(js, full_jid, TRUE))) |
112 my_jb->subscription |= JABBER_SUB_BOTH; | |
10504 | 113 g_free(full_jid); |
8401 | 114 } |
115 } else { | |
116 char *msg = jabber_parse_error(js, packet); | |
117 gaim_connection_error(js->gc, msg); | |
118 g_free(msg); | |
119 } | |
7395 | 120 |
121 jabber_session_init(js); | |
122 } | |
123 | |
124 static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet) | |
125 { | |
8296 | 126 if(xmlnode_get_child(packet, "starttls")) { |
127 if(jabber_process_starttls(js, packet)) | |
128 return; | |
129 } | |
130 | |
10988 | 131 if(js->registration) { |
132 jabber_register_start(js); | |
133 } else if(xmlnode_get_child(packet, "mechanisms")) { | |
7395 | 134 jabber_auth_start(js, packet); |
135 } else if(xmlnode_get_child(packet, "bind")) { | |
136 xmlnode *bind, *resource; | |
137 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); | |
138 bind = xmlnode_new_child(iq->node, "bind"); | |
139 xmlnode_set_attrib(bind, "xmlns", "urn:ietf:params:xml:ns:xmpp-bind"); | |
140 resource = xmlnode_new_child(bind, "resource"); | |
141 xmlnode_insert_data(resource, js->user->resource, -1); | |
142 | |
143 jabber_iq_set_callback(iq, jabber_bind_result_cb, NULL); | |
144 | |
145 jabber_iq_send(iq); | |
8296 | 146 } else /* if(xmlnode_get_child_with_namespace(packet, "auth")) */ { |
147 /* If we get an empty stream:features packet, or we explicitly get | |
148 * an auth feature with namespace http://jabber.org/features/iq-auth | |
149 * we should revert back to iq:auth authentication, even though we're | |
150 * connecting to an XMPP server. */ | |
151 js->auth_type = JABBER_AUTH_IQ_AUTH; | |
152 jabber_stream_set_state(js, JABBER_STREAM_AUTHENTICATING); | |
7395 | 153 } |
154 } | |
155 | |
7014 | 156 static void jabber_stream_handle_error(JabberStream *js, xmlnode *packet) |
3311 | 157 { |
8401 | 158 char *msg = jabber_parse_error(js, packet); |
3311 | 159 |
8401 | 160 gaim_connection_error(js->gc, msg); |
161 g_free(msg); | |
2086 | 162 } |
163 | |
7014 | 164 static void tls_init(JabberStream *js); |
2086 | 165 |
7014 | 166 void jabber_process_packet(JabberStream *js, xmlnode *packet) |
2086 | 167 { |
7014 | 168 if(!strcmp(packet->name, "iq")) { |
7395 | 169 jabber_iq_parse(js, packet); |
7014 | 170 } else if(!strcmp(packet->name, "presence")) { |
171 jabber_presence_parse(js, packet); | |
172 } else if(!strcmp(packet->name, "message")) { | |
173 jabber_message_parse(js, packet); | |
174 } else if(!strcmp(packet->name, "stream:features")) { | |
7395 | 175 jabber_stream_features_parse(js, packet); |
7014 | 176 } else if(!strcmp(packet->name, "stream:error")) { |
177 jabber_stream_handle_error(js, packet); | |
178 } else if(!strcmp(packet->name, "challenge")) { | |
179 if(js->state == JABBER_STREAM_AUTHENTICATING) | |
180 jabber_auth_handle_challenge(js, packet); | |
181 } else if(!strcmp(packet->name, "success")) { | |
182 if(js->state == JABBER_STREAM_AUTHENTICATING) | |
183 jabber_auth_handle_success(js, packet); | |
184 } else if(!strcmp(packet->name, "failure")) { | |
185 if(js->state == JABBER_STREAM_AUTHENTICATING) | |
186 jabber_auth_handle_failure(js, packet); | |
187 } else if(!strcmp(packet->name, "proceed")) { | |
188 if(js->state == JABBER_STREAM_AUTHENTICATING && !js->gsc) | |
189 tls_init(js); | |
190 } else { | |
191 gaim_debug(GAIM_DEBUG_WARNING, "jabber", "Unknown packet: %s\n", | |
192 packet->name); | |
2086 | 193 } |
194 } | |
195 | |
7642 | 196 void jabber_send_raw(JabberStream *js, const char *data, int len) |
2086 | 197 { |
7014 | 198 int ret; |
2086 | 199 |
7014 | 200 /* because printing a tab to debug every minute gets old */ |
201 if(strcmp(data, "\t")) | |
8401 | 202 gaim_debug(GAIM_DEBUG_MISC, "jabber", "Sending%s: %s\n", |
7014 | 203 js->gsc ? " (ssl)" : "", data); |
2086 | 204 |
7014 | 205 if(js->gsc) { |
7642 | 206 ret = gaim_ssl_write(js->gsc, data, len == -1 ? strlen(data) : len); |
7014 | 207 } else { |
8013 | 208 if(js->fd < 0) |
209 return; | |
7642 | 210 ret = write(js->fd, data, len == -1 ? strlen(data) : len); |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
211 } |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
212 |
7014 | 213 if(ret < 0) |
214 gaim_connection_error(js->gc, _("Write error")); | |
215 | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
216 } |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
217 |
7014 | 218 void jabber_send(JabberStream *js, xmlnode *packet) |
2086 | 219 { |
7014 | 220 char *txt; |
7642 | 221 int len; |
2086 | 222 |
7642 | 223 txt = xmlnode_to_str(packet, &len); |
224 jabber_send_raw(js, txt, len); | |
7014 | 225 g_free(txt); |
2086 | 226 } |
227 | |
7014 | 228 static void jabber_keepalive(GaimConnection *gc) |
2086 | 229 { |
7642 | 230 jabber_send_raw(gc->proto_data, "\t", -1); |
2086 | 231 } |
232 | |
7014 | 233 static void |
234 jabber_recv_cb_ssl(gpointer data, GaimSslConnection *gsc, | |
6764 | 235 GaimInputCondition cond) |
236 { | |
7014 | 237 GaimConnection *gc = data; |
238 JabberStream *js = gc->proto_data; | |
6764 | 239 int len; |
7014 | 240 static char buf[4096]; |
6768 | 241 |
7014 | 242 if(!g_list_find(gaim_connections_get_all(), gc)) { |
6768 | 243 gaim_ssl_close(gsc); |
244 return; | |
245 } | |
246 | |
7014 | 247 if((len = gaim_ssl_read(gsc, buf, sizeof(buf) - 1)) > 0) { |
6764 | 248 buf[len] = '\0'; |
7014 | 249 gaim_debug(GAIM_DEBUG_INFO, "jabber", "Recv (ssl)(%d): %s\n", len, buf); |
250 jabber_parser_process(js, buf, len); | |
7177 | 251 } else { |
252 gaim_connection_error(gc, _("Read Error")); | |
2086 | 253 } |
254 } | |
255 | |
7014 | 256 static void |
257 jabber_recv_cb(gpointer data, gint source, GaimInputCondition condition) | |
2086 | 258 { |
5572 | 259 GaimConnection *gc = data; |
7014 | 260 JabberStream *js = gc->proto_data; |
261 int len; | |
262 static char buf[4096]; | |
2086 | 263 |
7014 | 264 if(!g_list_find(gaim_connections_get_all(), gc)) |
265 return; | |
2956 | 266 |
7014 | 267 if((len = read(js->fd, buf, sizeof(buf) - 1)) > 0) { |
268 buf[len] = '\0'; | |
269 gaim_debug(GAIM_DEBUG_INFO, "jabber", "Recv (%d): %s\n", len, buf); | |
270 jabber_parser_process(js, buf, len); | |
7177 | 271 } else { |
272 gaim_connection_error(gc, _("Read Error")); | |
7014 | 273 } |
2086 | 274 } |
275 | |
7014 | 276 static void |
277 jabber_login_callback_ssl(gpointer data, GaimSslConnection *gsc, | |
6764 | 278 GaimInputCondition cond) |
279 { | |
280 GaimConnection *gc = data; | |
7014 | 281 JabberStream *js = gc->proto_data; |
6764 | 282 |
7014 | 283 if(!g_list_find(gaim_connections_get_all(), gc)) { |
6764 | 284 gaim_ssl_close(gsc); |
285 return; | |
286 } | |
287 | |
7014 | 288 js->gsc = gsc; |
6764 | 289 |
7014 | 290 if(js->state == JABBER_STREAM_CONNECTING) |
7642 | 291 jabber_send_raw(js, "<?xml version='1.0' ?>", -1); |
6764 | 292 |
7014 | 293 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING); |
294 gaim_ssl_input_add(gsc, jabber_recv_cb_ssl, gc); | |
6764 | 295 } |
296 | |
7014 | 297 |
298 static void | |
299 jabber_login_callback(gpointer data, gint source, GaimInputCondition cond) | |
6764 | 300 { |
5572 | 301 GaimConnection *gc = data; |
7014 | 302 JabberStream *js = gc->proto_data; |
2086 | 303 |
8783 | 304 if (source < 0) { |
305 gaim_connection_error(gc, _("Couldn't connect to host")); | |
306 return; | |
307 } | |
308 | |
7014 | 309 if(!g_list_find(gaim_connections_get_all(), gc)) { |
2086 | 310 close(source); |
311 return; | |
312 } | |
313 | |
7014 | 314 js->fd = source; |
2956 | 315 |
7014 | 316 if(js->state == JABBER_STREAM_CONNECTING) |
7642 | 317 jabber_send_raw(js, "<?xml version='1.0' ?>", -1); |
2300
d2686f757d6e
[gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
318 |
7014 | 319 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING); |
320 gc->inpa = gaim_input_add(js->fd, GAIM_INPUT_READ, jabber_recv_cb, gc); | |
321 } | |
2086 | 322 |
7014 | 323 static void |
7426 | 324 jabber_ssl_connect_failure(GaimSslConnection *gsc, GaimSslErrorType error, |
325 gpointer data) | |
326 { | |
327 GaimConnection *gc = data; | |
8360 | 328 JabberStream *js = gc->proto_data; |
7426 | 329 |
330 switch(error) { | |
8362 | 331 case GAIM_SSL_CONNECT_FAILED: |
332 gaim_connection_error(gc, _("Connection Failed")); | |
333 break; | |
7426 | 334 case GAIM_SSL_HANDSHAKE_FAILED: |
335 gaim_connection_error(gc, _("SSL Handshake Failed")); | |
336 break; | |
337 } | |
8360 | 338 |
339 js->gsc = NULL; | |
7426 | 340 } |
341 | |
7427 | 342 static void tls_init(JabberStream *js) |
343 { | |
344 gaim_input_remove(js->gc->inpa); | |
345 js->gc->inpa = 0; | |
346 js->gsc = gaim_ssl_connect_fd(js->gc->account, js->fd, | |
347 jabber_login_callback_ssl, jabber_ssl_connect_failure, js->gc); | |
348 } | |
349 | |
350 | |
7426 | 351 static void |
10401 | 352 jabber_login(GaimAccount *account, GaimStatus *status) |
2086 | 353 { |
7014 | 354 int rc; |
355 GaimConnection *gc = gaim_account_get_connection(account); | |
356 const char *connect_server = gaim_account_get_string(account, | |
357 "connect_server", ""); | |
5572 | 358 const char *server; |
7014 | 359 JabberStream *js; |
10289 | 360 JabberBuddy *my_jb = NULL; |
2086 | 361 |
7014 | 362 gc->flags |= GAIM_CONNECTION_HTML; |
363 js = gc->proto_data = g_new0(JabberStream, 1); | |
364 js->gc = gc; | |
8013 | 365 js->fd = -1; |
8312 | 366 js->iq_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, |
367 g_free, g_free); | |
368 js->disco_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, | |
7395 | 369 g_free, g_free); |
7014 | 370 js->buddies = g_hash_table_new_full(g_str_hash, g_str_equal, |
7116 | 371 g_free, (GDestroyNotify)jabber_buddy_free); |
7014 | 372 js->chats = g_hash_table_new_full(g_str_hash, g_str_equal, |
8396 | 373 g_free, (GDestroyNotify)jabber_chat_free); |
8043 | 374 js->chat_servers = g_list_append(NULL, g_strdup("conference.jabber.org")); |
7014 | 375 js->user = jabber_id_new(gaim_account_get_username(account)); |
7322 | 376 js->next_id = g_random_int(); |
5613 | 377 |
7310 | 378 if(!js->user) { |
379 gaim_connection_error(gc, _("Invalid Jabber ID")); | |
380 return; | |
381 } | |
382 | |
7147 | 383 if(!js->user->resource) { |
384 char *me; | |
385 js->user->resource = g_strdup("Gaim"); | |
386 if(!js->user->node) { | |
387 js->user->node = js->user->domain; | |
388 js->user->domain = g_strdup("jabber.org"); | |
389 } | |
390 me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, | |
391 js->user->resource); | |
392 gaim_account_set_username(account, me); | |
393 g_free(me); | |
7145 | 394 } |
395 | |
10289 | 396 if((my_jb = jabber_buddy_find(js, gaim_account_get_username(account), TRUE))) |
397 my_jb->subscription |= JABBER_SUB_BOTH; | |
398 | |
7014 | 399 server = connect_server[0] ? connect_server : js->user->domain; |
2086 | 400 |
7014 | 401 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING); |
2956 | 402 |
7630 | 403 |
404 if(gaim_account_get_bool(account, "old_ssl", FALSE)) { | |
405 if(gaim_ssl_is_supported()) { | |
406 js->gsc = gaim_ssl_connect(account, server, | |
407 gaim_account_get_int(account, "port", 5222), | |
408 jabber_login_callback_ssl, jabber_ssl_connect_failure, gc); | |
409 } else { | |
410 gaim_connection_error(gc, _("SSL support unavailable")); | |
411 } | |
3311 | 412 } |
3770 | 413 |
7014 | 414 if(!js->gsc) { |
415 rc = gaim_proxy_connect(account, server, | |
416 gaim_account_get_int(account, "port", 5222), | |
417 jabber_login_callback, gc); | |
2086 | 418 |
7014 | 419 if (rc != 0) |
420 gaim_connection_error(gc, _("Unable to create socket")); | |
2956 | 421 } |
2086 | 422 } |
423 | |
7072 | 424 static gboolean |
425 conn_close_cb(gpointer data) | |
426 { | |
427 JabberStream *js = data; | |
10740 | 428 GaimAccount *account = gaim_connection_get_account(js->gc); |
429 | |
430 gaim_account_disconnect(account); | |
431 | |
7072 | 432 return FALSE; |
433 } | |
434 | |
435 static void | |
436 jabber_connection_schedule_close(JabberStream *js) | |
437 { | |
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8194
diff
changeset
|
438 gaim_timeout_add(0, conn_close_cb, js); |
7072 | 439 } |
440 | |
441 static void | |
7395 | 442 jabber_registration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
7072 | 443 { |
444 const char *type = xmlnode_get_attrib(packet, "type"); | |
445 char *buf; | |
446 | |
447 if(!strcmp(type, "result")) { | |
448 buf = g_strdup_printf(_("Registration of %s@%s successful"), | |
449 js->user->node, js->user->domain); | |
450 gaim_notify_info(NULL, _("Registration Successful"), | |
451 _("Registration Successful"), buf); | |
452 g_free(buf); | |
453 } else { | |
8401 | 454 char *msg = jabber_parse_error(js, packet); |
7072 | 455 |
8401 | 456 if(!msg) |
457 msg = g_strdup(_("Unknown Error")); | |
7072 | 458 |
459 gaim_notify_error(NULL, _("Registration Failed"), | |
8401 | 460 _("Registration Failed"), msg); |
461 g_free(msg); | |
7072 | 462 } |
463 jabber_connection_schedule_close(js); | |
464 } | |
465 | |
466 static void | |
467 jabber_register_cb(JabberStream *js, GaimRequestFields *fields) | |
468 { | |
469 GList *groups, *flds; | |
470 xmlnode *query, *y; | |
471 JabberIq *iq; | |
7264 | 472 char *username; |
7072 | 473 |
474 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
475 query = xmlnode_get_child(iq->node, "query"); | |
476 | |
477 for(groups = gaim_request_fields_get_groups(fields); groups; | |
478 groups = groups->next) { | |
479 for(flds = gaim_request_field_group_get_fields(groups->data); | |
480 flds; flds = flds->next) { | |
481 GaimRequestField *field = flds->data; | |
482 const char *id = gaim_request_field_get_id(field); | |
483 const char *value = gaim_request_field_string_get_value(field); | |
484 | |
485 if(!strcmp(id, "username")) { | |
486 y = xmlnode_new_child(query, "username"); | |
487 } else if(!strcmp(id, "password")) { | |
488 y = xmlnode_new_child(query, "password"); | |
489 } else if(!strcmp(id, "name")) { | |
490 y = xmlnode_new_child(query, "name"); | |
491 } else if(!strcmp(id, "email")) { | |
492 y = xmlnode_new_child(query, "email"); | |
493 } else if(!strcmp(id, "nick")) { | |
494 y = xmlnode_new_child(query, "nick"); | |
495 } else if(!strcmp(id, "first")) { | |
496 y = xmlnode_new_child(query, "first"); | |
497 } else if(!strcmp(id, "last")) { | |
498 y = xmlnode_new_child(query, "last"); | |
499 } else if(!strcmp(id, "address")) { | |
500 y = xmlnode_new_child(query, "address"); | |
501 } else if(!strcmp(id, "city")) { | |
502 y = xmlnode_new_child(query, "city"); | |
503 } else if(!strcmp(id, "state")) { | |
504 y = xmlnode_new_child(query, "state"); | |
505 } else if(!strcmp(id, "zip")) { | |
506 y = xmlnode_new_child(query, "zip"); | |
507 } else if(!strcmp(id, "phone")) { | |
508 y = xmlnode_new_child(query, "phone"); | |
509 } else if(!strcmp(id, "url")) { | |
510 y = xmlnode_new_child(query, "url"); | |
511 } else if(!strcmp(id, "date")) { | |
512 y = xmlnode_new_child(query, "date"); | |
513 } else { | |
514 continue; | |
515 } | |
516 xmlnode_insert_data(y, value, -1); | |
7264 | 517 if(!strcmp(id, "username")) { |
518 if(js->user->node) | |
519 g_free(js->user->node); | |
520 js->user->node = g_strdup(value); | |
521 } | |
7072 | 522 } |
523 } | |
524 | |
7264 | 525 username = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, |
526 js->user->resource); | |
527 gaim_account_set_username(js->gc->account, username); | |
528 g_free(username); | |
529 | |
7395 | 530 jabber_iq_set_callback(iq, jabber_registration_result_cb, NULL); |
7072 | 531 |
532 jabber_iq_send(iq); | |
533 | |
534 } | |
535 | |
536 static void | |
537 jabber_register_cancel_cb(JabberStream *js, GaimRequestFields *fields) | |
538 { | |
539 jabber_connection_schedule_close(js); | |
540 } | |
541 | |
7923 | 542 static void jabber_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) |
543 { | |
544 xmlnode *query; | |
545 JabberIq *iq; | |
546 | |
547 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
548 query = xmlnode_get_child(iq->node, "query"); | |
549 | |
550 xmlnode_insert_child(query, result); | |
551 | |
552 jabber_iq_set_callback(iq, jabber_registration_result_cb, NULL); | |
553 jabber_iq_send(iq); | |
554 } | |
555 | |
7072 | 556 void jabber_register_parse(JabberStream *js, xmlnode *packet) |
557 { | |
558 if(js->registration) { | |
559 GaimRequestFields *fields; | |
560 GaimRequestFieldGroup *group; | |
561 GaimRequestField *field; | |
7923 | 562 xmlnode *query, *x, *y; |
7072 | 563 char *instructions; |
564 | |
565 /* get rid of the login thingy */ | |
566 gaim_connection_set_state(js->gc, GAIM_CONNECTED); | |
567 | |
568 query = xmlnode_get_child(packet, "query"); | |
569 | |
570 if(xmlnode_get_child(query, "registered")) { | |
571 gaim_notify_error(NULL, _("Already Registered"), | |
572 _("Already Registered"), NULL); | |
573 jabber_connection_schedule_close(js); | |
574 return; | |
575 } | |
576 | |
8398 | 577 if((x = xmlnode_get_child_with_namespace(packet, "x", |
578 "jabber:x:data"))) { | |
579 jabber_x_data_request(js, x, jabber_register_x_data_cb, NULL); | |
580 return; | |
581 } else if((x = xmlnode_get_child_with_namespace(packet, "x", | |
582 "jabber:x:oob"))) { | |
583 xmlnode *url; | |
7923 | 584 |
8398 | 585 if((url = xmlnode_get_child(x, "url"))) { |
586 char *href; | |
587 if((href = xmlnode_get_data(url))) { | |
10240
95ca0db2d01d
[gaim-migrate @ 11377]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10216
diff
changeset
|
588 gaim_notify_uri(NULL, href); |
8398 | 589 g_free(href); |
590 js->gc->wants_to_die = TRUE; | |
591 jabber_connection_schedule_close(js); | |
592 return; | |
593 } | |
7923 | 594 } |
595 } | |
596 | |
597 /* as a last resort, use the old jabber:iq:register syntax */ | |
598 | |
7072 | 599 fields = gaim_request_fields_new(); |
600 group = gaim_request_field_group_new(NULL); | |
601 gaim_request_fields_add_group(fields, group); | |
602 | |
603 field = gaim_request_field_string_new("username", _("Username"), | |
604 js->user->node, FALSE); | |
605 gaim_request_field_group_add_field(group, field); | |
606 | |
607 field = gaim_request_field_string_new("password", _("Password"), | |
10740 | 608 gaim_connection_get_password(js->gc), FALSE); |
7072 | 609 gaim_request_field_string_set_masked(field, TRUE); |
610 gaim_request_field_group_add_field(group, field); | |
611 | |
612 if(xmlnode_get_child(query, "name")) { | |
613 field = gaim_request_field_string_new("name", _("Name"), | |
614 gaim_account_get_alias(js->gc->account), FALSE); | |
615 gaim_request_field_group_add_field(group, field); | |
616 } | |
617 if(xmlnode_get_child(query, "email")) { | |
618 field = gaim_request_field_string_new("email", _("E-Mail"), | |
619 NULL, FALSE); | |
620 gaim_request_field_group_add_field(group, field); | |
621 } | |
622 if(xmlnode_get_child(query, "nick")) { | |
623 field = gaim_request_field_string_new("nick", _("Nickname"), | |
624 NULL, FALSE); | |
625 gaim_request_field_group_add_field(group, field); | |
626 } | |
627 if(xmlnode_get_child(query, "first")) { | |
628 field = gaim_request_field_string_new("first", _("First Name"), | |
629 NULL, FALSE); | |
630 gaim_request_field_group_add_field(group, field); | |
631 } | |
632 if(xmlnode_get_child(query, "last")) { | |
633 field = gaim_request_field_string_new("last", _("Last Name"), | |
634 NULL, FALSE); | |
635 gaim_request_field_group_add_field(group, field); | |
636 } | |
637 if(xmlnode_get_child(query, "address")) { | |
638 field = gaim_request_field_string_new("address", _("Address"), | |
639 NULL, FALSE); | |
640 gaim_request_field_group_add_field(group, field); | |
641 } | |
642 if(xmlnode_get_child(query, "city")) { | |
643 field = gaim_request_field_string_new("city", _("City"), | |
644 NULL, FALSE); | |
645 gaim_request_field_group_add_field(group, field); | |
646 } | |
647 if(xmlnode_get_child(query, "state")) { | |
648 field = gaim_request_field_string_new("state", _("State"), | |
649 NULL, FALSE); | |
650 gaim_request_field_group_add_field(group, field); | |
651 } | |
652 if(xmlnode_get_child(query, "zip")) { | |
653 field = gaim_request_field_string_new("zip", _("Postal Code"), | |
654 NULL, FALSE); | |
655 gaim_request_field_group_add_field(group, field); | |
656 } | |
657 if(xmlnode_get_child(query, "phone")) { | |
658 field = gaim_request_field_string_new("phone", _("Phone"), | |
659 NULL, FALSE); | |
660 gaim_request_field_group_add_field(group, field); | |
661 } | |
662 if(xmlnode_get_child(query, "url")) { | |
663 field = gaim_request_field_string_new("url", _("URL"), | |
664 NULL, FALSE); | |
665 gaim_request_field_group_add_field(group, field); | |
666 } | |
667 if(xmlnode_get_child(query, "date")) { | |
668 field = gaim_request_field_string_new("date", _("Date"), | |
669 NULL, FALSE); | |
670 gaim_request_field_group_add_field(group, field); | |
671 } | |
672 | |
673 if((y = xmlnode_get_child(query, "instructions"))) | |
674 instructions = xmlnode_get_data(y); | |
675 else | |
676 instructions = g_strdup(_("Please fill out the information below " | |
677 "to register your new account.")); | |
678 | |
679 gaim_request_fields(js->gc, _("Register New Jabber Account"), | |
680 _("Register New Jabber Account"), instructions, fields, | |
681 _("Register"), G_CALLBACK(jabber_register_cb), | |
682 _("Cancel"), G_CALLBACK(jabber_register_cancel_cb), js); | |
683 } | |
684 } | |
685 | |
8016 | 686 void jabber_register_start(JabberStream *js) |
7072 | 687 { |
688 JabberIq *iq; | |
689 | |
690 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:register"); | |
691 jabber_iq_send(iq); | |
692 } | |
693 | |
694 static void jabber_register_account(GaimAccount *account) | |
695 { | |
696 GaimConnection *gc = gaim_account_get_connection(account); | |
697 JabberStream *js; | |
10289 | 698 JabberBuddy *my_jb = NULL; |
7072 | 699 const char *connect_server = gaim_account_get_string(account, |
700 "connect_server", ""); | |
701 const char *server; | |
702 int rc; | |
703 | |
704 js = gc->proto_data = g_new0(JabberStream, 1); | |
705 js->gc = gc; | |
706 js->registration = TRUE; | |
8312 | 707 js->iq_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, |
708 g_free, g_free); | |
709 js->disco_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, | |
7395 | 710 g_free, g_free); |
7072 | 711 js->user = jabber_id_new(gaim_account_get_username(account)); |
7322 | 712 js->next_id = g_random_int(); |
7072 | 713 |
7310 | 714 if(!js->user) { |
715 gaim_connection_error(gc, _("Invalid Jabber ID")); | |
716 return; | |
717 } | |
718 | |
7147 | 719 if(!js->user->resource) { |
720 char *me; | |
721 js->user->resource = g_strdup("Gaim"); | |
722 if(!js->user->node) { | |
723 js->user->node = js->user->domain; | |
724 js->user->domain = g_strdup("jabber.org"); | |
725 } | |
726 me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, | |
727 js->user->resource); | |
728 gaim_account_set_username(account, me); | |
729 g_free(me); | |
730 } | |
731 | |
10289 | 732 if((my_jb = jabber_buddy_find(js, gaim_account_get_username(account), TRUE))) |
733 my_jb->subscription |= JABBER_SUB_BOTH; | |
734 | |
7072 | 735 server = connect_server[0] ? connect_server : js->user->domain; |
736 | |
737 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING); | |
738 | |
7630 | 739 if(gaim_account_get_bool(account, "old_ssl", FALSE)) { |
740 if(gaim_ssl_is_supported()) { | |
741 js->gsc = gaim_ssl_connect(account, server, | |
742 gaim_account_get_int(account, "port", 5222), | |
743 jabber_login_callback_ssl, jabber_ssl_connect_failure, gc); | |
744 } else { | |
745 gaim_connection_error(gc, _("SSL support unavailable")); | |
746 } | |
7072 | 747 } |
748 | |
749 if(!js->gsc) { | |
750 rc = gaim_proxy_connect(account, server, | |
751 gaim_account_get_int(account, "port", 5222), | |
752 jabber_login_callback, gc); | |
753 | |
754 if (rc != 0) | |
755 gaim_connection_error(gc, _("Unable to create socket")); | |
756 } | |
757 } | |
758 | |
5572 | 759 static void jabber_close(GaimConnection *gc) |
2086 | 760 { |
7014 | 761 JabberStream *js = gc->proto_data; |
2956 | 762 |
10216 | 763 jabber_presence_send(gc->account, NULL); |
7642 | 764 jabber_send_raw(js, "</stream:stream>", -1); |
3311 | 765 |
7014 | 766 if(js->gsc) { |
767 gaim_ssl_close(js->gsc); | |
8360 | 768 } else if (js->fd > 0) { |
7072 | 769 if(js->gc->inpa) |
770 gaim_input_remove(js->gc->inpa); | |
7014 | 771 close(js->fd); |
772 } | |
3311 | 773 |
7587 | 774 if(js->context) |
775 g_markup_parse_context_free(js->context); | |
8312 | 776 if(js->iq_callbacks) |
777 g_hash_table_destroy(js->iq_callbacks); | |
778 if(js->disco_callbacks) | |
779 g_hash_table_destroy(js->disco_callbacks); | |
7072 | 780 if(js->buddies) |
781 g_hash_table_destroy(js->buddies); | |
782 if(js->chats) | |
783 g_hash_table_destroy(js->chats); | |
8043 | 784 while(js->chat_servers) { |
785 g_free(js->chat_servers->data); | |
786 js->chat_servers = g_list_delete_link(js->chat_servers, js->chat_servers); | |
787 } | |
7014 | 788 if(js->stream_id) |
789 g_free(js->stream_id); | |
7587 | 790 if(js->user) |
791 jabber_id_free(js->user); | |
10189 | 792 if(js->avatar_hash) |
793 g_free(js->avatar_hash); | |
7014 | 794 g_free(js); |
5093 | 795 } |
796 | |
7014 | 797 void jabber_stream_set_state(JabberStream *js, JabberStreamState state) |
3105 | 798 { |
9954 | 799 GaimPresence *gpresence; |
800 GaimStatus *status; | |
801 | |
7014 | 802 js->state = state; |
803 switch(state) { | |
804 case JABBER_STREAM_OFFLINE: | |
805 break; | |
806 case JABBER_STREAM_CONNECTING: | |
807 gaim_connection_update_progress(js->gc, _("Connecting"), 1, | |
808 JABBER_CONNECT_STEPS); | |
809 break; | |
810 case JABBER_STREAM_INITIALIZING: | |
811 gaim_connection_update_progress(js->gc, _("Initializing Stream"), | |
812 js->gsc ? 5 : 2, JABBER_CONNECT_STEPS); | |
813 jabber_stream_init(js); | |
814 jabber_parser_setup(js); | |
815 break; | |
816 case JABBER_STREAM_AUTHENTICATING: | |
817 gaim_connection_update_progress(js->gc, _("Authenticating"), | |
818 js->gsc ? 6 : 3, JABBER_CONNECT_STEPS); | |
8296 | 819 if(js->protocol_version == JABBER_PROTO_0_9 && js->registration) { |
820 jabber_register_start(js); | |
821 } else if(js->auth_type == JABBER_AUTH_IQ_AUTH) { | |
822 jabber_auth_start_old(js); | |
8016 | 823 } |
7014 | 824 break; |
825 case JABBER_STREAM_REINITIALIZING: | |
826 gaim_connection_update_progress(js->gc, _("Re-initializing Stream"), | |
827 6, JABBER_CONNECT_STEPS); | |
828 jabber_stream_init(js); | |
829 break; | |
830 case JABBER_STREAM_CONNECTED: | |
831 jabber_roster_request(js); | |
9954 | 832 gpresence = gaim_account_get_presence(js->gc->account); |
833 status = gaim_presence_get_active_status(gpresence); | |
10216 | 834 jabber_presence_send(js->gc->account, status); |
10941 | 835 gaim_connection_set_state(js->gc, GAIM_CONNECTED); |
8312 | 836 jabber_disco_items_server(js); |
7014 | 837 break; |
3105 | 838 } |
839 } | |
840 | |
7014 | 841 char *jabber_get_next_id(JabberStream *js) |
2086 | 842 { |
7322 | 843 return g_strdup_printf("gaim%x", js->next_id++); |
2086 | 844 } |
845 | |
7923 | 846 |
847 static void jabber_idle_set(GaimConnection *gc, int idle) | |
3340 | 848 { |
7014 | 849 JabberStream *js = gc->proto_data; |
3340 | 850 |
7014 | 851 js->idle = idle ? time(NULL) - idle : idle; |
3314 | 852 } |
853 | |
6695 | 854 static const char *jabber_list_icon(GaimAccount *a, GaimBuddy *b) |
2086 | 855 { |
4687 | 856 return "jabber"; |
857 } | |
4916 | 858 |
9954 | 859 static void jabber_list_emblems(GaimBuddy *b, const char **se, const char **sw, |
860 const char **nw, const char **ne) | |
4916 | 861 { |
7014 | 862 JabberStream *js; |
863 JabberBuddy *jb; | |
864 | |
865 if(!b->account->gc) | |
866 return; | |
867 js = b->account->gc->proto_data; | |
868 jb = jabber_buddy_find(js, b->name, FALSE); | |
5135 | 869 |
870 if(!GAIM_BUDDY_IS_ONLINE(b)) { | |
7014 | 871 if(jb && jb->error_msg) |
4927 | 872 *nw = "error"; |
5135 | 873 |
7014 | 874 if(jb && (jb->subscription & JABBER_SUB_PENDING || |
875 !(jb->subscription & JABBER_SUB_TO))) | |
5135 | 876 *se = "notauthorized"; |
877 else | |
878 *se = "offline"; | |
4916 | 879 } else { |
9954 | 880 GaimStatusType *status_type = gaim_status_get_type(gaim_presence_get_active_status(gaim_buddy_get_presence(b))); |
881 | |
882 if(gaim_status_type_get_primitive(status_type) > GAIM_STATUS_ONLINE) { | |
883 *se = gaim_status_type_get_id(status_type); | |
884 if(!strcmp(*se, "xa")) | |
7014 | 885 *se = "extendedaway"; |
4916 | 886 } |
2086 | 887 } |
4916 | 888 } |
2086 | 889 |
7014 | 890 static char *jabber_status_text(GaimBuddy *b) |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
891 { |
7014 | 892 JabberBuddy *jb = jabber_buddy_find(b->account->gc->proto_data, b->name, |
893 FALSE); | |
894 char *ret = NULL; | |
5234 | 895 |
7014 | 896 if(jb && !GAIM_BUDDY_IS_ONLINE(b) && (jb->subscription & JABBER_SUB_PENDING || !(jb->subscription & JABBER_SUB_TO))) { |
897 ret = g_strdup(_("Not Authorized")); | |
898 } else if(jb && !GAIM_BUDDY_IS_ONLINE(b) && jb->error_msg) { | |
899 ret = g_strdup(jb->error_msg); | |
2956 | 900 } else { |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7072
diff
changeset
|
901 char *stripped; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7072
diff
changeset
|
902 |
9954 | 903 if(!(stripped = gaim_markup_strip_html(jabber_buddy_get_status_msg(jb)))) { |
904 GaimStatus *status = gaim_presence_get_active_status(gaim_buddy_get_presence(b)); | |
2956 | 905 |
9954 | 906 if(!gaim_status_is_available(status)) |
907 stripped = g_strdup(gaim_status_get_name(status)); | |
908 } | |
2086 | 909 |
7014 | 910 if(stripped) { |
911 ret = g_markup_escape_text(stripped, -1); | |
912 g_free(stripped); | |
913 } | |
2086 | 914 } |
915 | |
7014 | 916 return ret; |
2956 | 917 } |
918 | |
6695 | 919 static char *jabber_tooltip_text(GaimBuddy *b) |
4744 | 920 { |
7014 | 921 JabberBuddy *jb = jabber_buddy_find(b->account->gc->proto_data, b->name, |
922 FALSE); | |
8194 | 923 GString *ret = g_string_new(""); |
7014 | 924 |
8194 | 925 if(jb) { |
926 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, NULL); | |
927 const char *sub; | |
928 if(jb->subscription & JABBER_SUB_FROM) { | |
929 if(jb->subscription & JABBER_SUB_TO) | |
930 sub = _("Both"); | |
931 else if(jb->subscription & JABBER_SUB_PENDING) | |
932 sub = _("From (To pending)"); | |
933 else | |
934 sub = _("From"); | |
935 } else { | |
936 if(jb->subscription & JABBER_SUB_TO) | |
937 sub = _("To"); | |
938 else if(jb->subscription & JABBER_SUB_PENDING) | |
939 sub = _("None (To pending)"); | |
940 else | |
941 sub = _("None"); | |
942 } | |
8591 | 943 g_string_append_printf(ret, "\n<b>%s:</b> %s", _("Subscription"), sub); |
8194 | 944 |
945 if(jbr) { | |
946 char *text = NULL; | |
947 if(jbr->status) { | |
948 char *stripped; | |
949 stripped = gaim_markup_strip_html(jbr->status); | |
950 text = g_markup_escape_text(stripped, -1); | |
951 g_free(stripped); | |
10941 | 952 /* XXX: need some nl to br love here */ |
8194 | 953 } |
954 | |
8591 | 955 g_string_append_printf(ret, "\n<b>%s:</b> %s%s%s", |
8194 | 956 _("Status"), |
9954 | 957 jabber_buddy_state_get_name(jbr->state), |
8194 | 958 text ? ": " : "", |
959 text ? text : ""); | |
960 if(text) | |
961 g_free(text); | |
962 } else if(!GAIM_BUDDY_IS_ONLINE(b) && jb->error_msg) { | |
8591 | 963 g_string_append_printf(ret, "\n<b>%s:</b> %s", |
8194 | 964 _("Error"), jb->error_msg); |
965 } | |
4745 | 966 } |
4744 | 967 |
8591 | 968 return g_string_free(ret, FALSE); |
4732 | 969 } |
970 | |
9954 | 971 static GList *jabber_status_types(GaimAccount *account) |
7014 | 972 { |
9954 | 973 GaimStatusType *type; |
974 GList *types = NULL; | |
975 | |
9980 | 976 type = gaim_status_type_new_with_attrs(GAIM_STATUS_OFFLINE, "offline", |
977 _("Offline"), FALSE, TRUE, FALSE, "message", _("Message"), | |
978 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
9954 | 979 types = g_list_append(types, type); |
980 | |
10490 | 981 type = gaim_status_type_new_with_attrs(GAIM_STATUS_ONLINE, "online", |
982 _("Online"), FALSE, TRUE, FALSE, "priority", _("Priority"), | |
983 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), | |
984 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
10486 | 985 types = g_list_append(types, type); |
986 | |
987 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE, "available", | |
988 _("Available"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
9980 | 989 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), |
990 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
991 types = g_list_append(types, type); | |
992 | |
993 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE, "chat", | |
994 _("Chatty"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
995 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), | |
996 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
9954 | 997 types = g_list_append(types, type); |
2086 | 998 |
9980 | 999 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY, "away", |
1000 _("Away"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
1001 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), | |
1002 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
9954 | 1003 types = g_list_append(types, type); |
1004 | |
9980 | 1005 type = gaim_status_type_new_with_attrs(GAIM_STATUS_EXTENDED_AWAY, "xa", |
1006 _("Extended Away"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
1007 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), | |
1008 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
9954 | 1009 types = g_list_append(types, type); |
1010 | |
9980 | 1011 type = gaim_status_type_new_with_attrs(GAIM_STATUS_UNAVAILABLE, "dnd", |
1012 _("Do Not Disturb"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
1013 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), | |
1014 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
9954 | 1015 types = g_list_append(types, type); |
1016 | |
1017 /* | |
8166 | 1018 if(js->protocol_version == JABBER_PROTO_0_9) |
1019 m = g_list_append(m, _("Invisible")); | |
10009 | 1020 */ |
2086 | 1021 |
9954 | 1022 return types; |
2086 | 1023 } |
1024 | |
7395 | 1025 static void |
1026 jabber_password_change_result_cb(JabberStream *js, xmlnode *packet, | |
1027 gpointer data) | |
7124 | 1028 { |
1029 const char *type; | |
1030 | |
1031 type = xmlnode_get_attrib(packet, "type"); | |
1032 | |
9414 | 1033 if(type && !strcmp(type, "result")) { |
7124 | 1034 gaim_notify_info(js->gc, _("Password Changed"), _("Password Changed"), |
1035 _("Your password has been changed.")); | |
1036 } else { | |
8401 | 1037 char *msg = jabber_parse_error(js, packet); |
7124 | 1038 |
8401 | 1039 gaim_notify_error(js->gc, _("Error changing password"), |
1040 _("Error changing password"), msg); | |
1041 g_free(msg); | |
7124 | 1042 } |
1043 } | |
1044 | |
1045 static void jabber_password_change_cb(JabberStream *js, | |
1046 GaimRequestFields *fields) | |
1047 { | |
1048 const char *p1, *p2; | |
1049 JabberIq *iq; | |
1050 xmlnode *query, *y; | |
1051 | |
1052 p1 = gaim_request_fields_get_string(fields, "password1"); | |
1053 p2 = gaim_request_fields_get_string(fields, "password2"); | |
1054 | |
1055 if(strcmp(p1, p2)) { | |
1056 gaim_notify_error(js->gc, NULL, _("New passwords do not match."), NULL); | |
1057 return; | |
1058 } | |
1059 | |
1060 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
1061 | |
1062 xmlnode_set_attrib(iq->node, "to", js->user->domain); | |
1063 | |
1064 query = xmlnode_get_child(iq->node, "query"); | |
1065 | |
1066 y = xmlnode_new_child(query, "username"); | |
1067 xmlnode_insert_data(y, js->user->node, -1); | |
1068 y = xmlnode_new_child(query, "password"); | |
1069 xmlnode_insert_data(y, p1, -1); | |
1070 | |
7395 | 1071 jabber_iq_set_callback(iq, jabber_password_change_result_cb, NULL); |
7124 | 1072 |
1073 jabber_iq_send(iq); | |
1074 | |
1075 gaim_account_set_password(js->gc->account, p1); | |
1076 } | |
1077 | |
9015 | 1078 static void jabber_password_change(GaimPluginAction *action) |
7124 | 1079 { |
9015 | 1080 |
1081 GaimConnection *gc = (GaimConnection *) action->context; | |
7124 | 1082 JabberStream *js = gc->proto_data; |
1083 GaimRequestFields *fields; | |
1084 GaimRequestFieldGroup *group; | |
1085 GaimRequestField *field; | |
1086 | |
1087 fields = gaim_request_fields_new(); | |
1088 group = gaim_request_field_group_new(NULL); | |
1089 gaim_request_fields_add_group(fields, group); | |
1090 | |
1091 field = gaim_request_field_string_new("password1", _("Password"), | |
1092 "", FALSE); | |
1093 gaim_request_field_string_set_masked(field, TRUE); | |
1094 gaim_request_field_group_add_field(group, field); | |
1095 | |
1096 field = gaim_request_field_string_new("password2", _("Password (again)"), | |
1097 "", FALSE); | |
1098 gaim_request_field_string_set_masked(field, TRUE); | |
1099 gaim_request_field_group_add_field(group, field); | |
1100 | |
1101 gaim_request_fields(js->gc, _("Change Jabber Password"), | |
1102 _("Change Jabber Password"), _("Please enter your new password"), | |
1103 fields, _("OK"), G_CALLBACK(jabber_password_change_cb), | |
1104 _("Cancel"), NULL, js); | |
1105 } | |
1106 | |
9015 | 1107 static GList *jabber_actions(GaimPlugin *plugin, gpointer context) |
2956 | 1108 { |
1109 GList *m = NULL; | |
9015 | 1110 GaimPluginAction *act; |
4333 | 1111 |
9015 | 1112 act = gaim_plugin_action_new(_("Set User Info"), |
1113 jabber_setup_set_info); | |
1114 m = g_list_append(m, act); | |
4333 | 1115 |
8296 | 1116 /* if (js->protocol_options & CHANGE_PASSWORD) { */ |
9015 | 1117 act = gaim_plugin_action_new(_("Change Password"), |
1118 jabber_password_change); | |
1119 m = g_list_append(m, act); | |
8296 | 1120 /* } */ |
2956 | 1121 |
1122 return m; | |
1123 } | |
1124 | |
7999 | 1125 static GaimChat *jabber_find_blist_chat(GaimAccount *account, const char *name) |
1126 { | |
1127 GaimBlistNode *gnode, *cnode; | |
1128 JabberID *jid; | |
1129 | |
1130 if(!(jid = jabber_id_new(name))) | |
1131 return NULL; | |
1132 | |
1133 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { | |
1134 for(cnode = gnode->child; cnode; cnode = cnode->next) { | |
1135 GaimChat *chat = (GaimChat*)cnode; | |
1136 const char *room, *server; | |
1137 if(!GAIM_BLIST_NODE_IS_CHAT(cnode)) | |
1138 continue; | |
1139 | |
1140 if(chat->account != account) | |
8011 | 1141 continue; |
7999 | 1142 |
1143 if(!(room = g_hash_table_lookup(chat->components, "room"))) | |
1144 continue; | |
1145 if(!(server = g_hash_table_lookup(chat->components, "server"))) | |
1146 continue; | |
1147 | |
8158 | 1148 if(jid->node && jid->domain && |
1149 !g_utf8_collate(room, jid->node) && !g_utf8_collate(server, jid->domain)) { | |
7999 | 1150 jabber_id_free(jid); |
1151 return chat; | |
1152 } | |
1153 } | |
1154 } | |
1155 jabber_id_free(jid); | |
1156 return NULL; | |
1157 } | |
1158 | |
8400 | 1159 static void jabber_convo_closed(GaimConnection *gc, const char *who) |
1160 { | |
1161 JabberStream *js = gc->proto_data; | |
1162 JabberID *jid; | |
1163 JabberBuddy *jb; | |
1164 JabberBuddyResource *jbr; | |
1165 | |
1166 if(!(jid = jabber_id_new(who))) | |
1167 return; | |
1168 | |
1169 if((jb = jabber_buddy_find(js, who, TRUE)) && | |
1170 (jbr = jabber_buddy_find_resource(jb, jid->resource))) { | |
1171 if(jbr->thread_id) { | |
1172 g_free(jbr->thread_id); | |
1173 jbr->thread_id = NULL; | |
1174 } | |
1175 } | |
1176 | |
1177 jabber_id_free(jid); | |
1178 } | |
1179 | |
8401 | 1180 |
1181 char *jabber_parse_error(JabberStream *js, xmlnode *packet) | |
1182 { | |
1183 xmlnode *error; | |
1184 const char *code = NULL, *text = NULL; | |
1185 const char *xmlns = xmlnode_get_attrib(packet, "xmlns"); | |
1186 char *cdata = NULL; | |
1187 | |
1188 if((error = xmlnode_get_child(packet, "error"))) { | |
1189 cdata = xmlnode_get_data(error); | |
1190 code = xmlnode_get_attrib(error, "code"); | |
1191 | |
1192 /* Stanza errors */ | |
1193 if(xmlnode_get_child(error, "bad-request")) { | |
1194 text = _("Bad Request"); | |
1195 } else if(xmlnode_get_child(error, "conflict")) { | |
1196 text = _("Conflict"); | |
1197 } else if(xmlnode_get_child(error, "feature-not-implemented")) { | |
1198 text = _("Feature Not Implemented"); | |
1199 } else if(xmlnode_get_child(error, "forbidden")) { | |
1200 text = _("Forbidden"); | |
1201 } else if(xmlnode_get_child(error, "gone")) { | |
1202 text = _("Gone"); | |
1203 } else if(xmlnode_get_child(error, "internal-server-error")) { | |
1204 text = _("Internal Server Error"); | |
1205 } else if(xmlnode_get_child(error, "item-not-found")) { | |
1206 text = _("Item Not Found"); | |
1207 } else if(xmlnode_get_child(error, "jid-malformed")) { | |
1208 text = _("Malformed Jabber ID"); | |
1209 } else if(xmlnode_get_child(error, "not-acceptable")) { | |
1210 text = _("Not Acceptable"); | |
1211 } else if(xmlnode_get_child(error, "not-allowed")) { | |
1212 text = _("Not Allowed"); | |
1213 } else if(xmlnode_get_child(error, "not-authorized")) { | |
1214 text = _("Not Authorized"); | |
1215 } else if(xmlnode_get_child(error, "payment-required")) { | |
1216 text = _("Payment Required"); | |
1217 } else if(xmlnode_get_child(error, "recipient-unavailable")) { | |
1218 text = _("Recipient Unavailable"); | |
1219 } else if(xmlnode_get_child(error, "redirect")) { | |
1220 /* XXX */ | |
1221 } else if(xmlnode_get_child(error, "registration-required")) { | |
1222 text = _("Registration Required"); | |
1223 } else if(xmlnode_get_child(error, "remote-server-not-found")) { | |
1224 text = _("Remote Server Not Found"); | |
1225 } else if(xmlnode_get_child(error, "remote-server-timeout")) { | |
1226 text = _("Remote Server Timeout"); | |
1227 } else if(xmlnode_get_child(error, "resource-constraint")) { | |
1228 text = _("Server Overloaded"); | |
1229 } else if(xmlnode_get_child(error, "service-unavailable")) { | |
1230 text = _("Service Unavailable"); | |
1231 } else if(xmlnode_get_child(error, "subscription-required")) { | |
1232 text = _("Subscription Required"); | |
1233 } else if(xmlnode_get_child(error, "unexpected-request")) { | |
1234 text = _("Unexpected Request"); | |
1235 } else if(xmlnode_get_child(error, "undefined-condition")) { | |
1236 text = _("Unknown Error"); | |
1237 } | |
1238 } else if(xmlns && !strcmp(xmlns, "urn:ietf:params:xml:ns:xmpp-sasl")) { | |
1239 if(xmlnode_get_child(packet, "aborted")) { | |
1240 js->gc->wants_to_die = TRUE; | |
1241 text = _("Authorization Aborted"); | |
1242 } else if(xmlnode_get_child(error, "incorrect-encoding")) { | |
1243 text = _("Incorrect encoding in authorization"); | |
1244 } else if(xmlnode_get_child(error, "invalid-authzid")) { | |
1245 js->gc->wants_to_die = TRUE; | |
1246 text = _("Invalid authzid"); | |
1247 } else if(xmlnode_get_child(error, "invalid-mechanism")) { | |
1248 js->gc->wants_to_die = TRUE; | |
1249 text = _("Invalid Authorization Mechanism"); | |
1250 } else if(xmlnode_get_child(error, "mechanism-too-weak")) { | |
1251 js->gc->wants_to_die = TRUE; | |
1252 text = _("Authorization mechanism too weak"); | |
1253 } else if(xmlnode_get_child(error, "not-authorized")) { | |
1254 js->gc->wants_to_die = TRUE; | |
1255 text = _("Not Authorized"); | |
1256 } else if(xmlnode_get_child(error, "temporary-auth-failure")) { | |
1257 text = _("Temporary Authentication Failure"); | |
1258 } else { | |
1259 text = _("Authentication Failure"); | |
1260 } | |
8402 | 1261 } else if(!strcmp(packet->name, "stream:error")) { |
1262 if(xmlnode_get_child(packet, "bad-format")) { | |
1263 text = _("Bad Format"); | |
1264 } else if(xmlnode_get_child(packet, "bad-namespace-prefix")) { | |
1265 text = _("Bad Namespace Prefix"); | |
1266 } else if(xmlnode_get_child(packet, "conflict")) { | |
1267 js->gc->wants_to_die = TRUE; | |
1268 text = _("Resource Conflict"); | |
1269 } else if(xmlnode_get_child(packet, "connection-timeout")) { | |
1270 text = _("Connection Timeout"); | |
1271 } else if(xmlnode_get_child(packet, "host-gone")) { | |
1272 text = _("Host Gone"); | |
1273 } else if(xmlnode_get_child(packet, "host-unknown")) { | |
1274 text = _("Host Unknown"); | |
1275 } else if(xmlnode_get_child(packet, "improper-addressing")) { | |
1276 text = _("Improper Addressing"); | |
1277 } else if(xmlnode_get_child(packet, "internal-server-error")) { | |
1278 text = _("Internal Server Error"); | |
1279 } else if(xmlnode_get_child(packet, "invalid-id")) { | |
1280 text = _("Invalid ID"); | |
1281 } else if(xmlnode_get_child(packet, "invalid-namespace")) { | |
1282 text = _("Invalid Namespace"); | |
1283 } else if(xmlnode_get_child(packet, "invalid-xml")) { | |
1284 text = _("Invalid XML"); | |
1285 } else if(xmlnode_get_child(packet, "nonmatching-hosts")) { | |
1286 text = _("Non-matching Hosts"); | |
1287 } else if(xmlnode_get_child(packet, "not-authorized")) { | |
1288 text = _("Not Authorized"); | |
1289 } else if(xmlnode_get_child(packet, "policy-violation")) { | |
1290 text = _("Policy Violation"); | |
1291 } else if(xmlnode_get_child(packet, "remote-connection-failed")) { | |
1292 text = _("Remote Connection Failed"); | |
1293 } else if(xmlnode_get_child(packet, "resource-constraint")) { | |
1294 text = _("Resource Constraint"); | |
1295 } else if(xmlnode_get_child(packet, "restricted-xml")) { | |
1296 text = _("Restricted XML"); | |
1297 } else if(xmlnode_get_child(packet, "see-other-host")) { | |
1298 text = _("See Other Host"); | |
1299 } else if(xmlnode_get_child(packet, "system-shutdown")) { | |
1300 text = _("System Shutdown"); | |
1301 } else if(xmlnode_get_child(packet, "undefined-condition")) { | |
1302 text = _("Undefined Condition"); | |
1303 } else if(xmlnode_get_child(packet, "unsupported-encoding")) { | |
1304 text = _("Unsupported Encoding"); | |
1305 } else if(xmlnode_get_child(packet, "unsupported-stanza-type")) { | |
1306 text = _("Unsupported Stanza Type"); | |
1307 } else if(xmlnode_get_child(packet, "unsupported-version")) { | |
1308 text = _("Unsupported Version"); | |
1309 } else if(xmlnode_get_child(packet, "xml-not-well-formed")) { | |
1310 text = _("XML Not Well Formed"); | |
1311 } else { | |
1312 text = _("Stream Error"); | |
1313 } | |
8401 | 1314 } |
1315 | |
1316 if(text || cdata) { | |
1317 char *ret = g_strdup_printf("%s%s%s", code ? code : "", | |
1318 code ? ": " : "", text ? text : cdata); | |
1319 g_free(cdata); | |
1320 return ret; | |
1321 } else { | |
1322 return NULL; | |
1323 } | |
1324 } | |
1325 | |
9130 | 1326 static GaimCmdRet jabber_cmd_chat_config(GaimConversation *conv, |
9597 | 1327 const char *cmd, char **args, char **error, void *data) |
9130 | 1328 { |
1329 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1330 jabber_chat_request_room_configure(chat); | |
1331 return GAIM_CMD_RET_OK; | |
1332 } | |
1333 | |
1334 static GaimCmdRet jabber_cmd_chat_register(GaimConversation *conv, | |
9597 | 1335 const char *cmd, char **args, char **error, void *data) |
9130 | 1336 { |
1337 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1338 jabber_chat_register(chat); | |
1339 return GAIM_CMD_RET_OK; | |
1340 } | |
1341 | |
1342 static GaimCmdRet jabber_cmd_chat_topic(GaimConversation *conv, | |
9597 | 1343 const char *cmd, char **args, char **error, void *data) |
9130 | 1344 { |
1345 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1346 jabber_chat_change_topic(chat, args ? args[0] : NULL); | |
1347 return GAIM_CMD_RET_OK; | |
1348 } | |
1349 | |
1350 static GaimCmdRet jabber_cmd_chat_nick(GaimConversation *conv, | |
9597 | 1351 const char *cmd, char **args, char **error, void *data) |
9130 | 1352 { |
1353 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1354 | |
1355 if(!args || !args[0]) | |
1356 return GAIM_CMD_RET_FAILED; | |
1357 | |
1358 jabber_chat_change_nick(chat, args[0]); | |
1359 return GAIM_CMD_RET_OK; | |
1360 } | |
1361 | |
1362 static GaimCmdRet jabber_cmd_chat_part(GaimConversation *conv, | |
9597 | 1363 const char *cmd, char **args, char **error, void *data) |
9130 | 1364 { |
1365 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1366 jabber_chat_part(chat, args ? args[0] : NULL); | |
1367 return GAIM_CMD_RET_OK; | |
1368 } | |
1369 | |
9152 | 1370 static GaimCmdRet jabber_cmd_chat_ban(GaimConversation *conv, |
9597 | 1371 const char *cmd, char **args, char **error, void *data) |
9152 | 1372 { |
1373 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1374 | |
1375 if(!args || !args[0]) | |
1376 return GAIM_CMD_RET_FAILED; | |
1377 | |
1378 if(!jabber_chat_ban_user(chat, args[0], args[1])) { | |
1379 *error = g_strdup_printf(_("Unable to ban user %s"), args[0]); | |
1380 return GAIM_CMD_RET_FAILED; | |
1381 } | |
1382 | |
1383 return GAIM_CMD_RET_OK; | |
1384 } | |
1385 | |
1386 static GaimCmdRet jabber_cmd_chat_invite(GaimConversation *conv, | |
9597 | 1387 const char *cmd, char **args, char **error, void *data) |
9152 | 1388 { |
1389 if(!args || !args[0]) | |
1390 return GAIM_CMD_RET_FAILED; | |
1391 | |
1392 jabber_chat_invite(gaim_conversation_get_gc(conv), | |
1393 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), args[1] ? args[1] : "", | |
1394 args[0]); | |
1395 | |
1396 return GAIM_CMD_RET_OK; | |
1397 } | |
1398 | |
1399 static GaimCmdRet jabber_cmd_chat_join(GaimConversation *conv, | |
9597 | 1400 const char *cmd, char **args, char **error, void *data) |
9152 | 1401 { |
1402 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1403 GHashTable *components; | |
1404 | |
1405 if(!args || !args[0]) | |
1406 return GAIM_CMD_RET_FAILED; | |
1407 | |
1408 components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); | |
1409 | |
1410 g_hash_table_replace(components, "room", args[0]); | |
1411 g_hash_table_replace(components, "server", chat->server); | |
1412 g_hash_table_replace(components, "handle", chat->handle); | |
1413 if(args[1]) | |
1414 g_hash_table_replace(components, "password", args[1]); | |
1415 | |
1416 jabber_chat_join(gaim_conversation_get_gc(conv), components); | |
1417 | |
1418 g_hash_table_destroy(components); | |
1419 return GAIM_CMD_RET_OK; | |
1420 } | |
1421 | |
1422 static GaimCmdRet jabber_cmd_chat_kick(GaimConversation *conv, | |
9597 | 1423 const char *cmd, char **args, char **error, void *data) |
9152 | 1424 { |
1425 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1426 | |
1427 if(!args || !args[0]) | |
1428 return GAIM_CMD_RET_FAILED; | |
1429 | |
1430 if(!jabber_chat_kick_user(chat, args[0], args[1])) { | |
1431 *error = g_strdup_printf(_("Unable to kick user %s"), args[0]); | |
1432 return GAIM_CMD_RET_FAILED; | |
1433 } | |
1434 | |
1435 return GAIM_CMD_RET_OK; | |
1436 } | |
1437 | |
1438 static GaimCmdRet jabber_cmd_chat_msg(GaimConversation *conv, | |
9597 | 1439 const char *cmd, char **args, char **error, void *data) |
9152 | 1440 { |
1441 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1442 char *who; | |
1443 | |
1444 who = g_strdup_printf("%s@%s/%s", chat->room, chat->server, args[0]); | |
1445 | |
1446 jabber_message_send_im(gaim_conversation_get_gc(conv), who, args[1], 0); | |
1447 | |
1448 g_free(who); | |
1449 return GAIM_CMD_RET_OK; | |
1450 } | |
1451 | |
9130 | 1452 static void jabber_register_commands(void) |
1453 { | |
1454 gaim_cmd_register("config", "", GAIM_CMD_P_PRPL, | |
9597 | 1455 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1456 "prpl-jabber", jabber_cmd_chat_config, | |
1457 _("config: Configure a chat room."), NULL); | |
9130 | 1458 gaim_cmd_register("configure", "", GAIM_CMD_P_PRPL, |
9597 | 1459 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1460 "prpl-jabber", jabber_cmd_chat_config, | |
1461 _("configure: Configure a chat room."), NULL); | |
9130 | 1462 gaim_cmd_register("nick", "s", GAIM_CMD_P_PRPL, |
9597 | 1463 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1464 "prpl-jabber", jabber_cmd_chat_nick, | |
1465 _("nick <new nickname>: Change your nickname."), | |
1466 NULL); | |
9130 | 1467 gaim_cmd_register("part", "s", GAIM_CMD_P_PRPL, |
9597 | 1468 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1469 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1470 jabber_cmd_chat_part, _("part [room]: Leave the room."), | |
1471 NULL); | |
9130 | 1472 gaim_cmd_register("register", "", GAIM_CMD_P_PRPL, |
9597 | 1473 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1474 "prpl-jabber", jabber_cmd_chat_register, | |
1475 _("register: Register with a chat room."), NULL); | |
9130 | 1476 /* XXX: there needs to be a core /topic cmd, methinks */ |
1477 gaim_cmd_register("topic", "s", GAIM_CMD_P_PRPL, | |
9597 | 1478 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1479 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1480 jabber_cmd_chat_topic, | |
1481 _("topic [new topic]: View or change the topic."), | |
1482 NULL); | |
9152 | 1483 gaim_cmd_register("ban", "ws", GAIM_CMD_P_PRPL, |
9597 | 1484 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1485 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1486 jabber_cmd_chat_ban, | |
1487 _("ban <user> [room]: Ban a user from the room."), | |
1488 NULL); | |
9152 | 1489 gaim_cmd_register("invite", "ws", GAIM_CMD_P_PRPL, |
9597 | 1490 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1491 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1492 jabber_cmd_chat_invite, | |
1493 _("invite <user> [room]: Invite a user to the room."), | |
1494 NULL); | |
9152 | 1495 gaim_cmd_register("join", "ws", GAIM_CMD_P_PRPL, |
9597 | 1496 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1497 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1498 jabber_cmd_chat_join, | |
1499 _("join: <room> [server]: Join a chat on this server."), | |
1500 NULL); | |
9152 | 1501 gaim_cmd_register("kick", "ws", GAIM_CMD_P_PRPL, |
9597 | 1502 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1503 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1504 jabber_cmd_chat_kick, | |
1505 _("kick <user> [room]: Kick a user from the room."), | |
1506 NULL); | |
9152 | 1507 gaim_cmd_register("msg", "ws", GAIM_CMD_P_PRPL, |
9597 | 1508 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1509 "prpl-jabber", jabber_cmd_chat_msg, | |
1510 _("msg <user> <message>: Send a private message to another user."), | |
1511 NULL); | |
9130 | 1512 } |
1513 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1514 static GaimPluginProtocolInfo prpl_info = |
2086 | 1515 { |
7014 | 1516 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME, |
9475 | 1517 NULL, /* user_splits */ |
1518 NULL, /* protocol_options */ | |
10189 | 1519 {"jpeg,gif,png", 0, 0, 96, 96, GAIM_ICON_SCALE_DISPLAY}, /* icon_spec */ |
9475 | 1520 jabber_list_icon, /* list_icon */ |
1521 jabber_list_emblems, /* list_emblems */ | |
1522 jabber_status_text, /* status_text */ | |
1523 jabber_tooltip_text, /* tooltip_text */ | |
9954 | 1524 jabber_status_types, /* status_types */ |
9475 | 1525 jabber_blist_node_menu, /* blist_node_menu */ |
1526 jabber_chat_info, /* chat_info */ | |
9754 | 1527 jabber_chat_info_defaults, /* chat_info_defaults */ |
9475 | 1528 jabber_login, /* login */ |
1529 jabber_close, /* close */ | |
1530 jabber_message_send_im, /* send_im */ | |
1531 jabber_set_info, /* set_info */ | |
1532 jabber_send_typing, /* send_typing */ | |
1533 jabber_buddy_get_info, /* get_info */ | |
10216 | 1534 jabber_presence_send, /* set_away */ |
9475 | 1535 jabber_idle_set, /* set_idle */ |
1536 NULL, /* change_passwd */ | |
1537 jabber_roster_add_buddy, /* add_buddy */ | |
1538 NULL, /* add_buddies */ | |
1539 jabber_roster_remove_buddy, /* remove_buddy */ | |
1540 NULL, /* remove_buddies */ | |
1541 NULL, /* add_permit */ | |
1542 NULL, /* add_deny */ | |
1543 NULL, /* rem_permit */ | |
1544 NULL, /* rem_deny */ | |
1545 NULL, /* set_permit_deny */ | |
1546 NULL, /* warn */ | |
1547 jabber_chat_join, /* join_chat */ | |
1548 NULL, /* reject_chat */ | |
9917 | 1549 jabber_get_chat_name, /* get_chat_name */ |
9475 | 1550 jabber_chat_invite, /* chat_invite */ |
1551 jabber_chat_leave, /* chat_leave */ | |
1552 NULL, /* chat_whisper */ | |
1553 jabber_message_send_chat, /* chat_send */ | |
1554 jabber_keepalive, /* keepalive */ | |
1555 jabber_register_account, /* register_user */ | |
1556 jabber_buddy_get_info_chat, /* get_cb_info */ | |
1557 NULL, /* get_cb_away */ | |
1558 jabber_roster_alias_change, /* alias_buddy */ | |
1559 jabber_roster_group_change, /* group_buddy */ | |
1560 jabber_roster_group_rename, /* rename_group */ | |
1561 NULL, /* buddy_free */ | |
1562 jabber_convo_closed, /* convo_closed */ | |
1563 jabber_normalize, /* normalize */ | |
10189 | 1564 jabber_set_buddy_icon, /* set_buddy_icon */ |
9475 | 1565 NULL, /* remove_group */ |
1566 jabber_chat_buddy_real_name, /* get_cb_real_name */ | |
1567 jabber_chat_set_topic, /* set_chat_topic */ | |
1568 jabber_find_blist_chat, /* find_blist_chat */ | |
1569 jabber_roomlist_get_list, /* roomlist_get_list */ | |
1570 jabber_roomlist_cancel, /* roomlist_cancel */ | |
1571 NULL, /* roomlist_expand_category */ | |
1572 NULL, /* can_receive_file */ | |
1573 jabber_si_xfer_send /* send_file */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1574 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1575 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1576 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1577 { |
9943 | 1578 GAIM_PLUGIN_MAGIC, |
1579 GAIM_MAJOR_VERSION, | |
1580 GAIM_MINOR_VERSION, | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1581 GAIM_PLUGIN_PROTOCOL, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1582 NULL, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1583 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1584 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1585 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1586 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1587 "prpl-jabber", /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1588 "Jabber", /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1589 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1590 /** summary */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1591 N_("Jabber Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1592 /** description */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1593 N_("Jabber Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1594 NULL, /**< author */ |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
1595 GAIM_WEBSITE, /**< homepage */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1596 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1597 NULL, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1598 NULL, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1599 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1600 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1601 NULL, /**< ui_info */ |
8993 | 1602 &prpl_info, /**< extra_info */ |
10487 | 1603 NULL, /**< prefs_info */ |
9015 | 1604 jabber_actions |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1605 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1606 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1607 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5894
diff
changeset
|
1608 init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1609 { |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1610 GaimAccountUserSplit *split; |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1611 GaimAccountOption *option; |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1612 |
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10988
diff
changeset
|
1613 gaim_debug_register_category("jabber"); |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10988
diff
changeset
|
1614 |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1615 split = gaim_account_user_split_new(_("Server"), "jabber.org", '@'); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1616 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1617 |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1618 split = gaim_account_user_split_new(_("Resource"), "Gaim", '/'); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1619 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1620 |
7630 | 1621 option = gaim_account_option_bool_new(_("Use TLS if available"), "use_tls", |
1622 TRUE); | |
1623 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
1624 option); | |
1625 | |
10941 | 1626 option = gaim_account_option_bool_new(_("Require TLS"), "require_tls", TRUE); |
1627 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
1628 | |
1629 option = gaim_account_option_bool_new(_("Force old (port 5223) SSL"), "old_ssl", FALSE); | |
7124 | 1630 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
1631 option); | |
6764 | 1632 |
8086 | 1633 option = gaim_account_option_bool_new( |
1634 _("Allow plaintext auth over unencrypted streams"), | |
1635 "auth_plain_in_clear", FALSE); | |
1636 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
1637 option); | |
1638 | |
7014 | 1639 option = gaim_account_option_int_new(_("Port"), "port", 5222); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1640 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
7014 | 1641 option); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1642 |
5685
43ea75092684
[gaim-migrate @ 6106]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
1643 option = gaim_account_option_string_new(_("Connect server"), |
7014 | 1644 "connect_server", NULL); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1645 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
7014 | 1646 option); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1647 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1648 my_protocol = plugin; |
7014 | 1649 |
10487 | 1650 gaim_prefs_remove("/plugins/prpl/jabber"); |
9130 | 1651 |
1652 jabber_register_commands(); | |
2086 | 1653 } |
1654 | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5894
diff
changeset
|
1655 GAIM_INIT_PLUGIN(jabber, init_plugin, info); |