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