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