Mercurial > pidgin.yaz
annotate src/protocols/jabber/jabber.c @ 8398:66db94ff619c
[gaim-migrate @ 9127]
handle web page registration hints
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 05 Mar 2004 16:24:05 +0000 |
parents | 387ba791d5f9 |
children | 681b1661ee8b |
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" | |
25 #include "debug.h" | |
26 #include "message.h" | |
27 #include "multi.h" | |
7072 | 28 #include "notify.h" |
7014 | 29 #include "prpl.h" |
7072 | 30 #include "request.h" |
7014 | 31 #include "server.h" |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7072
diff
changeset
|
32 #include "util.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
33 |
7014 | 34 #include "auth.h" |
35 #include "buddy.h" | |
36 #include "chat.h" | |
8312 | 37 #include "disco.h" |
7014 | 38 #include "iq.h" |
39 #include "jutil.h" | |
40 #include "message.h" | |
41 #include "parser.h" | |
42 #include "presence.h" | |
43 #include "jabber.h" | |
44 #include "roster.h" | |
7923 | 45 #include "xdata.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
46 |
7014 | 47 #define JABBER_CONNECT_STEPS (js->gsc ? 8 : 5) |
2086 | 48 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
49 static GaimPlugin *my_protocol = NULL; |
4249 | 50 |
7014 | 51 static void jabber_stream_init(JabberStream *js) |
52 { | |
53 char *open_stream; | |
3340 | 54 |
7014 | 55 open_stream = g_strdup_printf("<stream:stream to='%s' " |
56 "xmlns='jabber:client' " | |
7395 | 57 "xmlns:stream='http://etherx.jabber.org/streams' " |
58 "version='1.0'>", | |
7291 | 59 js->user->domain); |
3311 | 60 |
7642 | 61 jabber_send_raw(js, open_stream, -1); |
2086 | 62 |
7014 | 63 g_free(open_stream); |
2086 | 64 } |
65 | |
7395 | 66 static void |
67 jabber_session_initialized_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
3311 | 68 { |
7014 | 69 const char *type = xmlnode_get_attrib(packet, "type"); |
70 if(type && !strcmp(type, "result")) { | |
71 jabber_stream_set_state(js, JABBER_STREAM_CONNECTED); | |
72 } else { | |
73 gaim_connection_error(js->gc, _("Error initializing session")); | |
3311 | 74 } |
75 } | |
76 | |
7014 | 77 static void jabber_session_init(JabberStream *js) |
3311 | 78 { |
7014 | 79 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); |
80 xmlnode *session; | |
3311 | 81 |
7395 | 82 jabber_iq_set_callback(iq, jabber_session_initialized_cb, NULL); |
3311 | 83 |
7014 | 84 session = xmlnode_new_child(iq->node, "session"); |
85 xmlnode_set_attrib(session, "xmlns", "urn:ietf:params:xml:ns:xmpp-session"); | |
3311 | 86 |
7014 | 87 jabber_iq_send(iq); |
3311 | 88 } |
89 | |
7395 | 90 static void jabber_bind_result_cb(JabberStream *js, xmlnode *packet, |
91 gpointer data) | |
92 { | |
7923 | 93 /* XXX: check for errors, re-set our own js->user JID */ |
7395 | 94 |
95 jabber_session_init(js); | |
96 } | |
97 | |
98 static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet) | |
99 { | |
8296 | 100 if(xmlnode_get_child(packet, "starttls")) { |
101 if(jabber_process_starttls(js, packet)) | |
102 return; | |
103 } | |
104 | |
7395 | 105 if(xmlnode_get_child(packet, "mechanisms")) { |
106 jabber_auth_start(js, packet); | |
107 } else if(xmlnode_get_child(packet, "bind")) { | |
108 xmlnode *bind, *resource; | |
109 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); | |
110 bind = xmlnode_new_child(iq->node, "bind"); | |
111 xmlnode_set_attrib(bind, "xmlns", "urn:ietf:params:xml:ns:xmpp-bind"); | |
112 resource = xmlnode_new_child(bind, "resource"); | |
113 xmlnode_insert_data(resource, js->user->resource, -1); | |
114 | |
115 jabber_iq_set_callback(iq, jabber_bind_result_cb, NULL); | |
116 | |
117 jabber_iq_send(iq); | |
8296 | 118 } else /* if(xmlnode_get_child_with_namespace(packet, "auth")) */ { |
119 /* If we get an empty stream:features packet, or we explicitly get | |
120 * an auth feature with namespace http://jabber.org/features/iq-auth | |
121 * we should revert back to iq:auth authentication, even though we're | |
122 * connecting to an XMPP server. */ | |
123 js->auth_type = JABBER_AUTH_IQ_AUTH; | |
124 jabber_stream_set_state(js, JABBER_STREAM_AUTHENTICATING); | |
7395 | 125 } |
126 } | |
127 | |
7014 | 128 static void jabber_stream_handle_error(JabberStream *js, xmlnode *packet) |
3311 | 129 { |
7014 | 130 xmlnode *textnode; |
131 char *error_text = NULL; | |
132 const char *text; | |
133 char *buf; | |
3311 | 134 |
7014 | 135 if(xmlnode_get_child(packet, "bad-format")) { |
136 text = _("Bad Format"); | |
137 } else if(xmlnode_get_child(packet, "bad-namespace-prefix")) { | |
138 text = _("Bad Namespace Prefix"); | |
139 } else if(xmlnode_get_child(packet, "conflict")) { | |
140 js->gc->wants_to_die = TRUE; | |
141 text = _("Resource Conflict"); | |
142 } else if(xmlnode_get_child(packet, "connection-timeout")) { | |
143 text = _("Connection Timeout"); | |
144 } else if(xmlnode_get_child(packet, "host-gone")) { | |
145 text = _("Host Gone"); | |
146 } else if(xmlnode_get_child(packet, "host-unknown")) { | |
147 text = _("Host Unknown"); | |
148 } else if(xmlnode_get_child(packet, "improper-addressing")) { | |
149 text = _("Improper Addressing"); | |
150 } else if(xmlnode_get_child(packet, "internal-server-error")) { | |
151 text = _("Internal Server Error"); | |
152 } else if(xmlnode_get_child(packet, "invalid-id")) { | |
153 text = _("Invalid ID"); | |
154 } else if(xmlnode_get_child(packet, "invalid-namespace")) { | |
155 text = _("Invalid Namespace"); | |
156 } else if(xmlnode_get_child(packet, "invalid-xml")) { | |
157 text = _("Invalid XML"); | |
158 } else if(xmlnode_get_child(packet, "nonmatching-hosts")) { | |
159 text = _("Non-matching Hosts"); | |
160 } else if(xmlnode_get_child(packet, "not-authorized")) { | |
161 text = _("Not Authorized"); | |
162 } else if(xmlnode_get_child(packet, "policy-violation")) { | |
163 text = _("Policy Violation"); | |
164 } else if(xmlnode_get_child(packet, "remote-connection-failed")) { | |
165 text = _("Remote Connection Failed"); | |
166 } else if(xmlnode_get_child(packet, "resource-constraint")) { | |
167 text = _("Resource Constraint"); | |
168 } else if(xmlnode_get_child(packet, "restricted-xml")) { | |
169 text = _("Restricted XML"); | |
170 } else if(xmlnode_get_child(packet, "see-other-host")) { | |
171 text = _("See Other Host"); | |
172 } else if(xmlnode_get_child(packet, "system-shutdown")) { | |
173 text = _("System Shutdown"); | |
174 } else if(xmlnode_get_child(packet, "undefined-condition")) { | |
175 text = _("Undefined Condition"); | |
176 } else if(xmlnode_get_child(packet, "unsupported-encoding")) { | |
7417 | 177 text = _("Unsupported Encoding"); |
7014 | 178 } else if(xmlnode_get_child(packet, "unsupported-stanza-type")) { |
179 text = _("Unsupported Stanza Type"); | |
180 } else if(xmlnode_get_child(packet, "unsupported-version")) { | |
181 text = _("Unsupported Version"); | |
182 } else if(xmlnode_get_child(packet, "xml-not-well-formed")) { | |
183 text = _("XML Not Well Formed"); | |
3311 | 184 } else { |
7014 | 185 text = _("Stream Error"); |
3311 | 186 } |
187 | |
7014 | 188 if((textnode = xmlnode_get_child(packet, "text"))) |
189 error_text = xmlnode_get_data(textnode); | |
2086 | 190 |
7014 | 191 buf = g_strdup_printf("%s%s%s", text, |
192 error_text ? ": " : "", | |
193 error_text ? error_text : ""); | |
194 gaim_connection_error(js->gc, buf); | |
195 g_free(buf); | |
196 if(error_text) | |
197 g_free(error_text); | |
2086 | 198 } |
199 | |
7014 | 200 static void tls_init(JabberStream *js); |
2086 | 201 |
7014 | 202 void jabber_process_packet(JabberStream *js, xmlnode *packet) |
2086 | 203 { |
7014 | 204 if(!strcmp(packet->name, "iq")) { |
7395 | 205 jabber_iq_parse(js, packet); |
7014 | 206 } else if(!strcmp(packet->name, "presence")) { |
207 jabber_presence_parse(js, packet); | |
208 } else if(!strcmp(packet->name, "message")) { | |
209 jabber_message_parse(js, packet); | |
210 } else if(!strcmp(packet->name, "stream:features")) { | |
7395 | 211 jabber_stream_features_parse(js, packet); |
7014 | 212 } else if(!strcmp(packet->name, "stream:error")) { |
213 jabber_stream_handle_error(js, packet); | |
214 } else if(!strcmp(packet->name, "challenge")) { | |
215 if(js->state == JABBER_STREAM_AUTHENTICATING) | |
216 jabber_auth_handle_challenge(js, packet); | |
217 } else if(!strcmp(packet->name, "success")) { | |
218 if(js->state == JABBER_STREAM_AUTHENTICATING) | |
219 jabber_auth_handle_success(js, packet); | |
220 } else if(!strcmp(packet->name, "failure")) { | |
221 if(js->state == JABBER_STREAM_AUTHENTICATING) | |
222 jabber_auth_handle_failure(js, packet); | |
223 } else if(!strcmp(packet->name, "proceed")) { | |
224 if(js->state == JABBER_STREAM_AUTHENTICATING && !js->gsc) | |
225 tls_init(js); | |
226 } else { | |
227 gaim_debug(GAIM_DEBUG_WARNING, "jabber", "Unknown packet: %s\n", | |
228 packet->name); | |
2086 | 229 } |
230 } | |
231 | |
7642 | 232 void jabber_send_raw(JabberStream *js, const char *data, int len) |
2086 | 233 { |
7014 | 234 int ret; |
2086 | 235 |
7014 | 236 /* because printing a tab to debug every minute gets old */ |
237 if(strcmp(data, "\t")) | |
238 gaim_debug(GAIM_DEBUG_MISC, "jabber", "Sending%s: %s\n", | |
239 js->gsc ? " (ssl)" : "", data); | |
2086 | 240 |
7014 | 241 if(js->gsc) { |
7642 | 242 ret = gaim_ssl_write(js->gsc, data, len == -1 ? strlen(data) : len); |
7014 | 243 } else { |
8013 | 244 if(js->fd < 0) |
245 return; | |
7642 | 246 ret = write(js->fd, data, len == -1 ? strlen(data) : len); |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
247 } |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
248 |
7014 | 249 if(ret < 0) |
250 gaim_connection_error(js->gc, _("Write error")); | |
251 | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
252 } |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
253 |
7014 | 254 void jabber_send(JabberStream *js, xmlnode *packet) |
2086 | 255 { |
7014 | 256 char *txt; |
7642 | 257 int len; |
2086 | 258 |
7642 | 259 txt = xmlnode_to_str(packet, &len); |
260 jabber_send_raw(js, txt, len); | |
7014 | 261 g_free(txt); |
2086 | 262 } |
263 | |
7014 | 264 static void jabber_keepalive(GaimConnection *gc) |
2086 | 265 { |
7642 | 266 jabber_send_raw(gc->proto_data, "\t", -1); |
2086 | 267 } |
268 | |
7014 | 269 static void |
270 jabber_recv_cb_ssl(gpointer data, GaimSslConnection *gsc, | |
6764 | 271 GaimInputCondition cond) |
272 { | |
7014 | 273 GaimConnection *gc = data; |
274 JabberStream *js = gc->proto_data; | |
6764 | 275 int len; |
7014 | 276 static char buf[4096]; |
6768 | 277 |
7014 | 278 if(!g_list_find(gaim_connections_get_all(), gc)) { |
6768 | 279 gaim_ssl_close(gsc); |
280 return; | |
281 } | |
282 | |
7014 | 283 if((len = gaim_ssl_read(gsc, buf, sizeof(buf) - 1)) > 0) { |
6764 | 284 buf[len] = '\0'; |
7014 | 285 gaim_debug(GAIM_DEBUG_INFO, "jabber", "Recv (ssl)(%d): %s\n", len, buf); |
286 jabber_parser_process(js, buf, len); | |
7177 | 287 } else { |
288 gaim_connection_error(gc, _("Read Error")); | |
2086 | 289 } |
290 } | |
291 | |
7014 | 292 static void |
293 jabber_recv_cb(gpointer data, gint source, GaimInputCondition condition) | |
2086 | 294 { |
5572 | 295 GaimConnection *gc = data; |
7014 | 296 JabberStream *js = gc->proto_data; |
297 int len; | |
298 static char buf[4096]; | |
2086 | 299 |
7014 | 300 if(!g_list_find(gaim_connections_get_all(), gc)) |
301 return; | |
2956 | 302 |
7014 | 303 if((len = read(js->fd, buf, sizeof(buf) - 1)) > 0) { |
304 buf[len] = '\0'; | |
305 gaim_debug(GAIM_DEBUG_INFO, "jabber", "Recv (%d): %s\n", len, buf); | |
306 jabber_parser_process(js, buf, len); | |
7177 | 307 } else { |
308 gaim_connection_error(gc, _("Read Error")); | |
7014 | 309 } |
2086 | 310 } |
311 | |
7014 | 312 static void |
313 jabber_login_callback_ssl(gpointer data, GaimSslConnection *gsc, | |
6764 | 314 GaimInputCondition cond) |
315 { | |
316 GaimConnection *gc = data; | |
7014 | 317 JabberStream *js = gc->proto_data; |
6764 | 318 |
7014 | 319 if(!g_list_find(gaim_connections_get_all(), gc)) { |
6764 | 320 gaim_ssl_close(gsc); |
321 return; | |
322 } | |
323 | |
7014 | 324 js->gsc = gsc; |
6764 | 325 |
7014 | 326 if(js->state == JABBER_STREAM_CONNECTING) |
7642 | 327 jabber_send_raw(js, "<?xml version='1.0' ?>", -1); |
6764 | 328 |
7014 | 329 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING); |
330 gaim_ssl_input_add(gsc, jabber_recv_cb_ssl, gc); | |
6764 | 331 } |
332 | |
7014 | 333 |
334 static void | |
335 jabber_login_callback(gpointer data, gint source, GaimInputCondition cond) | |
6764 | 336 { |
5572 | 337 GaimConnection *gc = data; |
7014 | 338 JabberStream *js = gc->proto_data; |
2086 | 339 |
7014 | 340 if(!g_list_find(gaim_connections_get_all(), gc)) { |
2086 | 341 close(source); |
342 return; | |
343 } | |
344 | |
7014 | 345 js->fd = source; |
2956 | 346 |
7014 | 347 if(js->state == JABBER_STREAM_CONNECTING) |
7642 | 348 jabber_send_raw(js, "<?xml version='1.0' ?>", -1); |
2300
d2686f757d6e
[gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
349 |
7014 | 350 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING); |
351 gc->inpa = gaim_input_add(js->fd, GAIM_INPUT_READ, jabber_recv_cb, gc); | |
352 } | |
2086 | 353 |
7014 | 354 static void |
7426 | 355 jabber_ssl_connect_failure(GaimSslConnection *gsc, GaimSslErrorType error, |
356 gpointer data) | |
357 { | |
358 GaimConnection *gc = data; | |
8360 | 359 JabberStream *js = gc->proto_data; |
7426 | 360 |
361 switch(error) { | |
8362 | 362 case GAIM_SSL_CONNECT_FAILED: |
363 gaim_connection_error(gc, _("Connection Failed")); | |
364 break; | |
7426 | 365 case GAIM_SSL_HANDSHAKE_FAILED: |
366 gaim_connection_error(gc, _("SSL Handshake Failed")); | |
367 break; | |
368 } | |
8360 | 369 |
370 js->gsc = NULL; | |
7426 | 371 } |
372 | |
7427 | 373 static void tls_init(JabberStream *js) |
374 { | |
375 gaim_input_remove(js->gc->inpa); | |
376 js->gc->inpa = 0; | |
377 js->gsc = gaim_ssl_connect_fd(js->gc->account, js->fd, | |
378 jabber_login_callback_ssl, jabber_ssl_connect_failure, js->gc); | |
379 } | |
380 | |
381 | |
7426 | 382 static void |
7014 | 383 jabber_login(GaimAccount *account) |
2086 | 384 { |
7014 | 385 int rc; |
386 GaimConnection *gc = gaim_account_get_connection(account); | |
387 const char *connect_server = gaim_account_get_string(account, | |
388 "connect_server", ""); | |
5572 | 389 const char *server; |
7014 | 390 JabberStream *js; |
2086 | 391 |
7014 | 392 gc->flags |= GAIM_CONNECTION_HTML; |
393 js = gc->proto_data = g_new0(JabberStream, 1); | |
394 js->gc = gc; | |
8013 | 395 js->fd = -1; |
8312 | 396 js->iq_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, |
397 g_free, g_free); | |
398 js->disco_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, | |
7395 | 399 g_free, g_free); |
7014 | 400 js->buddies = g_hash_table_new_full(g_str_hash, g_str_equal, |
7116 | 401 g_free, (GDestroyNotify)jabber_buddy_free); |
7014 | 402 js->chats = g_hash_table_new_full(g_str_hash, g_str_equal, |
8396 | 403 g_free, (GDestroyNotify)jabber_chat_free); |
8043 | 404 js->chat_servers = g_list_append(NULL, g_strdup("conference.jabber.org")); |
7014 | 405 js->user = jabber_id_new(gaim_account_get_username(account)); |
7322 | 406 js->next_id = g_random_int(); |
5613 | 407 |
7310 | 408 if(!js->user) { |
409 gaim_connection_error(gc, _("Invalid Jabber ID")); | |
410 return; | |
411 } | |
412 | |
7147 | 413 if(!js->user->resource) { |
414 char *me; | |
415 js->user->resource = g_strdup("Gaim"); | |
416 if(!js->user->node) { | |
417 js->user->node = js->user->domain; | |
418 js->user->domain = g_strdup("jabber.org"); | |
419 } | |
420 me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, | |
421 js->user->resource); | |
422 gaim_account_set_username(account, me); | |
423 g_free(me); | |
7145 | 424 } |
425 | |
7014 | 426 server = connect_server[0] ? connect_server : js->user->domain; |
2086 | 427 |
7014 | 428 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING); |
2956 | 429 |
7630 | 430 |
431 if(gaim_account_get_bool(account, "old_ssl", FALSE)) { | |
432 if(gaim_ssl_is_supported()) { | |
433 js->gsc = gaim_ssl_connect(account, server, | |
434 gaim_account_get_int(account, "port", 5222), | |
435 jabber_login_callback_ssl, jabber_ssl_connect_failure, gc); | |
436 } else { | |
437 gaim_connection_error(gc, _("SSL support unavailable")); | |
438 } | |
3311 | 439 } |
3770 | 440 |
7014 | 441 if(!js->gsc) { |
442 rc = gaim_proxy_connect(account, server, | |
443 gaim_account_get_int(account, "port", 5222), | |
444 jabber_login_callback, gc); | |
2086 | 445 |
7014 | 446 if (rc != 0) |
447 gaim_connection_error(gc, _("Unable to create socket")); | |
2956 | 448 } |
2086 | 449 } |
450 | |
7072 | 451 static gboolean |
452 conn_close_cb(gpointer data) | |
453 { | |
454 JabberStream *js = data; | |
455 gaim_connection_destroy(js->gc); | |
456 return FALSE; | |
457 } | |
458 | |
459 static void | |
460 jabber_connection_schedule_close(JabberStream *js) | |
461 { | |
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8194
diff
changeset
|
462 gaim_timeout_add(0, conn_close_cb, js); |
7072 | 463 } |
464 | |
465 static void | |
7395 | 466 jabber_registration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
7072 | 467 { |
468 const char *type = xmlnode_get_attrib(packet, "type"); | |
469 char *buf; | |
470 | |
471 if(!strcmp(type, "result")) { | |
472 buf = g_strdup_printf(_("Registration of %s@%s successful"), | |
473 js->user->node, js->user->domain); | |
474 gaim_notify_info(NULL, _("Registration Successful"), | |
475 _("Registration Successful"), buf); | |
476 g_free(buf); | |
477 } else { | |
478 char *error; | |
479 xmlnode *y; | |
480 | |
481 if((y = xmlnode_get_child(packet, "error"))) { | |
482 error = xmlnode_get_data(y); | |
483 } else { | |
484 error = g_strdup(_("Unknown Error")); | |
485 } | |
486 | |
487 buf = g_strdup_printf(_("Registration of %s@%s failed: %s"), | |
488 js->user->node, js->user->domain, error); | |
489 gaim_notify_error(NULL, _("Registration Failed"), | |
490 _("Registration Failed"), buf); | |
491 g_free(buf); | |
492 g_free(error); | |
493 } | |
494 jabber_connection_schedule_close(js); | |
495 } | |
496 | |
497 static void | |
498 jabber_register_cb(JabberStream *js, GaimRequestFields *fields) | |
499 { | |
500 GList *groups, *flds; | |
501 xmlnode *query, *y; | |
502 JabberIq *iq; | |
7264 | 503 char *username; |
7072 | 504 |
505 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
506 query = xmlnode_get_child(iq->node, "query"); | |
507 | |
508 for(groups = gaim_request_fields_get_groups(fields); groups; | |
509 groups = groups->next) { | |
510 for(flds = gaim_request_field_group_get_fields(groups->data); | |
511 flds; flds = flds->next) { | |
512 GaimRequestField *field = flds->data; | |
513 const char *id = gaim_request_field_get_id(field); | |
514 const char *value = gaim_request_field_string_get_value(field); | |
515 | |
516 if(!strcmp(id, "username")) { | |
517 y = xmlnode_new_child(query, "username"); | |
518 } else if(!strcmp(id, "password")) { | |
519 y = xmlnode_new_child(query, "password"); | |
520 } else if(!strcmp(id, "name")) { | |
521 y = xmlnode_new_child(query, "name"); | |
522 } else if(!strcmp(id, "email")) { | |
523 y = xmlnode_new_child(query, "email"); | |
524 } else if(!strcmp(id, "nick")) { | |
525 y = xmlnode_new_child(query, "nick"); | |
526 } else if(!strcmp(id, "first")) { | |
527 y = xmlnode_new_child(query, "first"); | |
528 } else if(!strcmp(id, "last")) { | |
529 y = xmlnode_new_child(query, "last"); | |
530 } else if(!strcmp(id, "address")) { | |
531 y = xmlnode_new_child(query, "address"); | |
532 } else if(!strcmp(id, "city")) { | |
533 y = xmlnode_new_child(query, "city"); | |
534 } else if(!strcmp(id, "state")) { | |
535 y = xmlnode_new_child(query, "state"); | |
536 } else if(!strcmp(id, "zip")) { | |
537 y = xmlnode_new_child(query, "zip"); | |
538 } else if(!strcmp(id, "phone")) { | |
539 y = xmlnode_new_child(query, "phone"); | |
540 } else if(!strcmp(id, "url")) { | |
541 y = xmlnode_new_child(query, "url"); | |
542 } else if(!strcmp(id, "date")) { | |
543 y = xmlnode_new_child(query, "date"); | |
544 } else { | |
545 continue; | |
546 } | |
547 xmlnode_insert_data(y, value, -1); | |
7264 | 548 if(!strcmp(id, "username")) { |
549 if(js->user->node) | |
550 g_free(js->user->node); | |
551 js->user->node = g_strdup(value); | |
552 } | |
7072 | 553 } |
554 } | |
555 | |
7264 | 556 username = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, |
557 js->user->resource); | |
558 gaim_account_set_username(js->gc->account, username); | |
559 g_free(username); | |
560 | |
7395 | 561 jabber_iq_set_callback(iq, jabber_registration_result_cb, NULL); |
7072 | 562 |
563 jabber_iq_send(iq); | |
564 | |
565 } | |
566 | |
567 static void | |
568 jabber_register_cancel_cb(JabberStream *js, GaimRequestFields *fields) | |
569 { | |
570 jabber_connection_schedule_close(js); | |
571 } | |
572 | |
7923 | 573 static void jabber_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) |
574 { | |
575 xmlnode *query; | |
576 JabberIq *iq; | |
577 | |
578 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
579 query = xmlnode_get_child(iq->node, "query"); | |
580 | |
581 xmlnode_insert_child(query, result); | |
582 | |
583 jabber_iq_set_callback(iq, jabber_registration_result_cb, NULL); | |
584 jabber_iq_send(iq); | |
585 } | |
586 | |
7072 | 587 void jabber_register_parse(JabberStream *js, xmlnode *packet) |
588 { | |
589 if(js->registration) { | |
590 GaimRequestFields *fields; | |
591 GaimRequestFieldGroup *group; | |
592 GaimRequestField *field; | |
7923 | 593 xmlnode *query, *x, *y; |
7072 | 594 char *instructions; |
595 | |
596 /* get rid of the login thingy */ | |
597 gaim_connection_set_state(js->gc, GAIM_CONNECTED); | |
598 | |
599 query = xmlnode_get_child(packet, "query"); | |
600 | |
601 if(xmlnode_get_child(query, "registered")) { | |
602 gaim_notify_error(NULL, _("Already Registered"), | |
603 _("Already Registered"), NULL); | |
604 jabber_connection_schedule_close(js); | |
605 return; | |
606 } | |
607 | |
8398 | 608 if((x = xmlnode_get_child_with_namespace(packet, "x", |
609 "jabber:x:data"))) { | |
610 jabber_x_data_request(js, x, jabber_register_x_data_cb, NULL); | |
611 return; | |
612 } else if((x = xmlnode_get_child_with_namespace(packet, "x", | |
613 "jabber:x:oob"))) { | |
614 xmlnode *url; | |
7923 | 615 |
8398 | 616 if((url = xmlnode_get_child(x, "url"))) { |
617 char *href; | |
618 if((href = xmlnode_get_data(url))) { | |
619 gaim_notify_uri(NULL, href); | |
620 g_free(href); | |
621 js->gc->wants_to_die = TRUE; | |
622 jabber_connection_schedule_close(js); | |
623 return; | |
624 } | |
7923 | 625 } |
626 } | |
627 | |
628 /* as a last resort, use the old jabber:iq:register syntax */ | |
629 | |
7072 | 630 fields = gaim_request_fields_new(); |
631 group = gaim_request_field_group_new(NULL); | |
632 gaim_request_fields_add_group(fields, group); | |
633 | |
634 field = gaim_request_field_string_new("username", _("Username"), | |
635 js->user->node, FALSE); | |
636 gaim_request_field_group_add_field(group, field); | |
637 | |
638 field = gaim_request_field_string_new("password", _("Password"), | |
639 gaim_account_get_password(js->gc->account), FALSE); | |
640 gaim_request_field_string_set_masked(field, TRUE); | |
641 gaim_request_field_group_add_field(group, field); | |
642 | |
643 if(xmlnode_get_child(query, "name")) { | |
644 field = gaim_request_field_string_new("name", _("Name"), | |
645 gaim_account_get_alias(js->gc->account), FALSE); | |
646 gaim_request_field_group_add_field(group, field); | |
647 } | |
648 if(xmlnode_get_child(query, "email")) { | |
649 field = gaim_request_field_string_new("email", _("E-Mail"), | |
650 NULL, FALSE); | |
651 gaim_request_field_group_add_field(group, field); | |
652 } | |
653 if(xmlnode_get_child(query, "nick")) { | |
654 field = gaim_request_field_string_new("nick", _("Nickname"), | |
655 NULL, FALSE); | |
656 gaim_request_field_group_add_field(group, field); | |
657 } | |
658 if(xmlnode_get_child(query, "first")) { | |
659 field = gaim_request_field_string_new("first", _("First Name"), | |
660 NULL, FALSE); | |
661 gaim_request_field_group_add_field(group, field); | |
662 } | |
663 if(xmlnode_get_child(query, "last")) { | |
664 field = gaim_request_field_string_new("last", _("Last Name"), | |
665 NULL, FALSE); | |
666 gaim_request_field_group_add_field(group, field); | |
667 } | |
668 if(xmlnode_get_child(query, "address")) { | |
669 field = gaim_request_field_string_new("address", _("Address"), | |
670 NULL, FALSE); | |
671 gaim_request_field_group_add_field(group, field); | |
672 } | |
673 if(xmlnode_get_child(query, "city")) { | |
674 field = gaim_request_field_string_new("city", _("City"), | |
675 NULL, FALSE); | |
676 gaim_request_field_group_add_field(group, field); | |
677 } | |
678 if(xmlnode_get_child(query, "state")) { | |
679 field = gaim_request_field_string_new("state", _("State"), | |
680 NULL, FALSE); | |
681 gaim_request_field_group_add_field(group, field); | |
682 } | |
683 if(xmlnode_get_child(query, "zip")) { | |
684 field = gaim_request_field_string_new("zip", _("Postal Code"), | |
685 NULL, FALSE); | |
686 gaim_request_field_group_add_field(group, field); | |
687 } | |
688 if(xmlnode_get_child(query, "phone")) { | |
689 field = gaim_request_field_string_new("phone", _("Phone"), | |
690 NULL, FALSE); | |
691 gaim_request_field_group_add_field(group, field); | |
692 } | |
693 if(xmlnode_get_child(query, "url")) { | |
694 field = gaim_request_field_string_new("url", _("URL"), | |
695 NULL, FALSE); | |
696 gaim_request_field_group_add_field(group, field); | |
697 } | |
698 if(xmlnode_get_child(query, "date")) { | |
699 field = gaim_request_field_string_new("date", _("Date"), | |
700 NULL, FALSE); | |
701 gaim_request_field_group_add_field(group, field); | |
702 } | |
703 | |
704 if((y = xmlnode_get_child(query, "instructions"))) | |
705 instructions = xmlnode_get_data(y); | |
706 else | |
707 instructions = g_strdup(_("Please fill out the information below " | |
708 "to register your new account.")); | |
709 | |
710 gaim_request_fields(js->gc, _("Register New Jabber Account"), | |
711 _("Register New Jabber Account"), instructions, fields, | |
712 _("Register"), G_CALLBACK(jabber_register_cb), | |
713 _("Cancel"), G_CALLBACK(jabber_register_cancel_cb), js); | |
714 } | |
715 } | |
716 | |
8016 | 717 void jabber_register_start(JabberStream *js) |
7072 | 718 { |
719 JabberIq *iq; | |
720 | |
721 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:register"); | |
722 jabber_iq_send(iq); | |
723 } | |
724 | |
725 static void jabber_register_account(GaimAccount *account) | |
726 { | |
727 GaimConnection *gc = gaim_account_get_connection(account); | |
728 JabberStream *js; | |
729 const char *connect_server = gaim_account_get_string(account, | |
730 "connect_server", ""); | |
731 const char *server; | |
732 int rc; | |
733 | |
734 js = gc->proto_data = g_new0(JabberStream, 1); | |
735 js->gc = gc; | |
736 js->registration = TRUE; | |
8312 | 737 js->iq_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, |
738 g_free, g_free); | |
739 js->disco_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, | |
7395 | 740 g_free, g_free); |
7072 | 741 js->user = jabber_id_new(gaim_account_get_username(account)); |
7322 | 742 js->next_id = g_random_int(); |
7072 | 743 |
7310 | 744 if(!js->user) { |
745 gaim_connection_error(gc, _("Invalid Jabber ID")); | |
746 return; | |
747 } | |
748 | |
7147 | 749 if(!js->user->resource) { |
750 char *me; | |
751 js->user->resource = g_strdup("Gaim"); | |
752 if(!js->user->node) { | |
753 js->user->node = js->user->domain; | |
754 js->user->domain = g_strdup("jabber.org"); | |
755 } | |
756 me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, | |
757 js->user->resource); | |
758 gaim_account_set_username(account, me); | |
759 g_free(me); | |
760 } | |
761 | |
7072 | 762 server = connect_server[0] ? connect_server : js->user->domain; |
763 | |
764 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING); | |
765 | |
7630 | 766 if(gaim_account_get_bool(account, "old_ssl", FALSE)) { |
767 if(gaim_ssl_is_supported()) { | |
768 js->gsc = gaim_ssl_connect(account, server, | |
769 gaim_account_get_int(account, "port", 5222), | |
770 jabber_login_callback_ssl, jabber_ssl_connect_failure, gc); | |
771 } else { | |
772 gaim_connection_error(gc, _("SSL support unavailable")); | |
773 } | |
7072 | 774 } |
775 | |
776 if(!js->gsc) { | |
777 rc = gaim_proxy_connect(account, server, | |
778 gaim_account_get_int(account, "port", 5222), | |
779 jabber_login_callback, gc); | |
780 | |
781 if (rc != 0) | |
782 gaim_connection_error(gc, _("Unable to create socket")); | |
783 } | |
784 } | |
785 | |
5572 | 786 static void jabber_close(GaimConnection *gc) |
2086 | 787 { |
7014 | 788 JabberStream *js = gc->proto_data; |
2956 | 789 |
7642 | 790 jabber_send_raw(js, "</stream:stream>", -1); |
3311 | 791 |
7014 | 792 if(js->gsc) { |
793 gaim_ssl_close(js->gsc); | |
8360 | 794 } else if (js->fd > 0) { |
7072 | 795 if(js->gc->inpa) |
796 gaim_input_remove(js->gc->inpa); | |
7014 | 797 close(js->fd); |
798 } | |
3311 | 799 |
7587 | 800 if(js->context) |
801 g_markup_parse_context_free(js->context); | |
8312 | 802 if(js->iq_callbacks) |
803 g_hash_table_destroy(js->iq_callbacks); | |
804 if(js->disco_callbacks) | |
805 g_hash_table_destroy(js->disco_callbacks); | |
7072 | 806 if(js->buddies) |
807 g_hash_table_destroy(js->buddies); | |
808 if(js->chats) | |
809 g_hash_table_destroy(js->chats); | |
8043 | 810 while(js->chat_servers) { |
811 g_free(js->chat_servers->data); | |
812 js->chat_servers = g_list_delete_link(js->chat_servers, js->chat_servers); | |
813 } | |
7014 | 814 if(js->stream_id) |
815 g_free(js->stream_id); | |
7587 | 816 if(js->user) |
817 jabber_id_free(js->user); | |
7014 | 818 g_free(js); |
5093 | 819 } |
820 | |
7014 | 821 void jabber_stream_set_state(JabberStream *js, JabberStreamState state) |
3105 | 822 { |
7014 | 823 js->state = state; |
824 switch(state) { | |
825 case JABBER_STREAM_OFFLINE: | |
826 break; | |
827 case JABBER_STREAM_CONNECTING: | |
828 gaim_connection_update_progress(js->gc, _("Connecting"), 1, | |
829 JABBER_CONNECT_STEPS); | |
830 break; | |
831 case JABBER_STREAM_INITIALIZING: | |
832 gaim_connection_update_progress(js->gc, _("Initializing Stream"), | |
833 js->gsc ? 5 : 2, JABBER_CONNECT_STEPS); | |
834 jabber_stream_init(js); | |
835 jabber_parser_setup(js); | |
836 break; | |
837 case JABBER_STREAM_AUTHENTICATING: | |
838 gaim_connection_update_progress(js->gc, _("Authenticating"), | |
839 js->gsc ? 6 : 3, JABBER_CONNECT_STEPS); | |
8296 | 840 if(js->protocol_version == JABBER_PROTO_0_9 && js->registration) { |
841 jabber_register_start(js); | |
842 } else if(js->auth_type == JABBER_AUTH_IQ_AUTH) { | |
843 jabber_auth_start_old(js); | |
8016 | 844 } |
7014 | 845 break; |
846 case JABBER_STREAM_REINITIALIZING: | |
847 gaim_connection_update_progress(js->gc, _("Re-initializing Stream"), | |
848 6, JABBER_CONNECT_STEPS); | |
849 jabber_stream_init(js); | |
850 break; | |
851 case JABBER_STREAM_CONNECTED: | |
852 gaim_connection_set_state(js->gc, GAIM_CONNECTED); | |
853 jabber_roster_request(js); | |
854 jabber_presence_send(js->gc, js->gc->away_state, js->gc->away); | |
8312 | 855 jabber_disco_items_server(js); |
7014 | 856 serv_finish_login(js->gc); |
857 break; | |
3105 | 858 } |
859 } | |
860 | |
7014 | 861 char *jabber_get_next_id(JabberStream *js) |
2086 | 862 { |
7322 | 863 return g_strdup_printf("gaim%x", js->next_id++); |
2086 | 864 } |
865 | |
7923 | 866 |
867 static void jabber_idle_set(GaimConnection *gc, int idle) | |
3340 | 868 { |
7014 | 869 JabberStream *js = gc->proto_data; |
3340 | 870 |
7014 | 871 js->idle = idle ? time(NULL) - idle : idle; |
3314 | 872 } |
873 | |
6695 | 874 static const char *jabber_list_icon(GaimAccount *a, GaimBuddy *b) |
2086 | 875 { |
4687 | 876 return "jabber"; |
877 } | |
4916 | 878 |
7014 | 879 static void jabber_list_emblems(GaimBuddy *b, char **se, char **sw, |
880 char **nw, char **ne) | |
4916 | 881 { |
7014 | 882 JabberStream *js; |
883 JabberBuddy *jb; | |
884 | |
885 if(!b->account->gc) | |
886 return; | |
887 js = b->account->gc->proto_data; | |
888 jb = jabber_buddy_find(js, b->name, FALSE); | |
5135 | 889 |
890 if(!GAIM_BUDDY_IS_ONLINE(b)) { | |
7014 | 891 if(jb && jb->error_msg) |
4927 | 892 *nw = "error"; |
5135 | 893 |
7014 | 894 if(jb && (jb->subscription & JABBER_SUB_PENDING || |
895 !(jb->subscription & JABBER_SUB_TO))) | |
5135 | 896 *se = "notauthorized"; |
897 else | |
898 *se = "offline"; | |
4916 | 899 } else { |
900 switch (b->uc) { | |
7014 | 901 case JABBER_STATE_AWAY: |
902 *se = "away"; | |
903 break; | |
904 case JABBER_STATE_CHAT: | |
905 *se = "chat"; | |
906 break; | |
907 case JABBER_STATE_XA: | |
908 *se = "extendedaway"; | |
909 break; | |
910 case JABBER_STATE_DND: | |
8193 | 911 *se = "dnd"; |
7014 | 912 break; |
913 case JABBER_STATE_ERROR: | |
914 *se = "error"; | |
915 break; | |
4916 | 916 } |
2086 | 917 } |
4916 | 918 } |
2086 | 919 |
7014 | 920 static char *jabber_status_text(GaimBuddy *b) |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
921 { |
7014 | 922 JabberBuddy *jb = jabber_buddy_find(b->account->gc->proto_data, b->name, |
923 FALSE); | |
924 char *ret = NULL; | |
5234 | 925 |
7014 | 926 if(jb && !GAIM_BUDDY_IS_ONLINE(b) && (jb->subscription & JABBER_SUB_PENDING || !(jb->subscription & JABBER_SUB_TO))) { |
927 ret = g_strdup(_("Not Authorized")); | |
928 } else if(jb && !GAIM_BUDDY_IS_ONLINE(b) && jb->error_msg) { | |
929 ret = g_strdup(jb->error_msg); | |
2956 | 930 } else { |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7072
diff
changeset
|
931 char *stripped; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7072
diff
changeset
|
932 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7072
diff
changeset
|
933 stripped = gaim_markup_strip_html(jabber_buddy_get_status_msg(jb)); |
2956 | 934 |
7014 | 935 if(!stripped && b->uc & UC_UNAVAILABLE) |
936 stripped = g_strdup(jabber_get_state_string(b->uc)); | |
2086 | 937 |
7014 | 938 if(stripped) { |
939 ret = g_markup_escape_text(stripped, -1); | |
940 g_free(stripped); | |
941 } | |
2086 | 942 } |
943 | |
7014 | 944 return ret; |
2956 | 945 } |
946 | |
6695 | 947 static char *jabber_tooltip_text(GaimBuddy *b) |
4744 | 948 { |
7014 | 949 JabberBuddy *jb = jabber_buddy_find(b->account->gc->proto_data, b->name, |
950 FALSE); | |
8194 | 951 GString *ret = g_string_new(""); |
952 char *r = NULL; | |
7014 | 953 |
8194 | 954 if(jb) { |
955 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, NULL); | |
956 const char *sub; | |
957 if(jb->subscription & JABBER_SUB_FROM) { | |
958 if(jb->subscription & JABBER_SUB_TO) | |
959 sub = _("Both"); | |
960 else if(jb->subscription & JABBER_SUB_PENDING) | |
961 sub = _("From (To pending)"); | |
962 else | |
963 sub = _("From"); | |
964 } else { | |
965 if(jb->subscription & JABBER_SUB_TO) | |
966 sub = _("To"); | |
967 else if(jb->subscription & JABBER_SUB_PENDING) | |
968 sub = _("None (To pending)"); | |
969 else | |
970 sub = _("None"); | |
971 } | |
972 g_string_append_printf(ret, "<b>%s:</b> %s\n", _("Subscription"), sub); | |
973 | |
974 if(jbr) { | |
975 char *text = NULL; | |
976 if(jbr->status) { | |
977 char *stripped; | |
978 stripped = gaim_markup_strip_html(jbr->status); | |
979 text = g_markup_escape_text(stripped, -1); | |
980 g_free(stripped); | |
981 } | |
982 | |
983 g_string_append_printf(ret, "<b>%s:</b> %s%s%s\n", | |
984 _("Status"), | |
985 jabber_get_state_string(jbr->state), | |
986 text ? ": " : "", | |
987 text ? text : ""); | |
988 if(text) | |
989 g_free(text); | |
990 } else if(!GAIM_BUDDY_IS_ONLINE(b) && jb->error_msg) { | |
991 g_string_append_printf(ret, "<b>%s:</b> %s\n", | |
992 _("Error"), jb->error_msg); | |
993 } | |
4745 | 994 } |
4744 | 995 |
8194 | 996 if(ret->len > 0) { |
997 g_string_truncate(ret, ret->len-1); | |
998 r = ret->str; | |
999 g_string_free(ret, FALSE); | |
1000 } else { | |
1001 g_string_free(ret, TRUE); | |
1002 } | |
1003 | |
1004 return r; | |
4732 | 1005 } |
1006 | |
7014 | 1007 static GList *jabber_away_states(GaimConnection *gc) |
1008 { | |
8166 | 1009 JabberStream *js = gc->proto_data; |
2086 | 1010 GList *m = NULL; |
1011 | |
4982 | 1012 m = g_list_append(m, _("Online")); |
1013 m = g_list_append(m, _("Chatty")); | |
1014 m = g_list_append(m, _("Away")); | |
1015 m = g_list_append(m, _("Extended Away")); | |
1016 m = g_list_append(m, _("Do Not Disturb")); | |
8166 | 1017 if(js->protocol_version == JABBER_PROTO_0_9) |
1018 m = g_list_append(m, _("Invisible")); | |
4110 | 1019 m = g_list_append(m, GAIM_AWAY_CUSTOM); |
2086 | 1020 |
1021 return m; | |
1022 } | |
1023 | |
7395 | 1024 static void |
1025 jabber_password_change_result_cb(JabberStream *js, xmlnode *packet, | |
1026 gpointer data) | |
7124 | 1027 { |
1028 const char *type; | |
1029 | |
1030 type = xmlnode_get_attrib(packet, "type"); | |
1031 | |
1032 if(!strcmp(type, "result")) { | |
1033 gaim_notify_info(js->gc, _("Password Changed"), _("Password Changed"), | |
1034 _("Your password has been changed.")); | |
1035 } else { | |
1036 xmlnode *error; | |
1037 char *buf, *error_txt = NULL; | |
1038 | |
1039 | |
1040 if((error = xmlnode_get_child(packet, "error"))) | |
1041 error_txt = xmlnode_get_data(error); | |
1042 | |
1043 if(error_txt) { | |
1044 buf = g_strdup_printf(_("Error changing password: %s"), | |
1045 error_txt); | |
1046 g_free(error_txt); | |
1047 } else { | |
1048 buf = g_strdup(_("Unknown error occurred changing password")); | |
1049 } | |
1050 | |
1051 gaim_notify_error(js->gc, _("Error"), _("Error"), buf); | |
1052 g_free(buf); | |
1053 } | |
1054 } | |
1055 | |
1056 static void jabber_password_change_cb(JabberStream *js, | |
1057 GaimRequestFields *fields) | |
1058 { | |
1059 const char *p1, *p2; | |
1060 JabberIq *iq; | |
1061 xmlnode *query, *y; | |
1062 | |
1063 p1 = gaim_request_fields_get_string(fields, "password1"); | |
1064 p2 = gaim_request_fields_get_string(fields, "password2"); | |
1065 | |
1066 if(strcmp(p1, p2)) { | |
1067 gaim_notify_error(js->gc, NULL, _("New passwords do not match."), NULL); | |
1068 return; | |
1069 } | |
1070 | |
1071 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
1072 | |
1073 xmlnode_set_attrib(iq->node, "to", js->user->domain); | |
1074 | |
1075 query = xmlnode_get_child(iq->node, "query"); | |
1076 | |
1077 y = xmlnode_new_child(query, "username"); | |
1078 xmlnode_insert_data(y, js->user->node, -1); | |
1079 y = xmlnode_new_child(query, "password"); | |
1080 xmlnode_insert_data(y, p1, -1); | |
1081 | |
7395 | 1082 jabber_iq_set_callback(iq, jabber_password_change_result_cb, NULL); |
7124 | 1083 |
1084 jabber_iq_send(iq); | |
1085 | |
1086 gaim_account_set_password(js->gc->account, p1); | |
1087 } | |
1088 | |
1089 static void jabber_password_change(GaimConnection *gc) | |
1090 { | |
1091 JabberStream *js = gc->proto_data; | |
1092 GaimRequestFields *fields; | |
1093 GaimRequestFieldGroup *group; | |
1094 GaimRequestField *field; | |
1095 | |
1096 fields = gaim_request_fields_new(); | |
1097 group = gaim_request_field_group_new(NULL); | |
1098 gaim_request_fields_add_group(fields, group); | |
1099 | |
1100 field = gaim_request_field_string_new("password1", _("Password"), | |
1101 "", FALSE); | |
1102 gaim_request_field_string_set_masked(field, TRUE); | |
1103 gaim_request_field_group_add_field(group, field); | |
1104 | |
1105 field = gaim_request_field_string_new("password2", _("Password (again)"), | |
1106 "", FALSE); | |
1107 gaim_request_field_string_set_masked(field, TRUE); | |
1108 gaim_request_field_group_add_field(group, field); | |
1109 | |
1110 gaim_request_fields(js->gc, _("Change Jabber Password"), | |
1111 _("Change Jabber Password"), _("Please enter your new password"), | |
1112 fields, _("OK"), G_CALLBACK(jabber_password_change_cb), | |
1113 _("Cancel"), NULL, js); | |
1114 } | |
1115 | |
5572 | 1116 static GList *jabber_actions(GaimConnection *gc) |
2956 | 1117 { |
1118 GList *m = NULL; | |
4333 | 1119 struct proto_actions_menu *pam; |
1120 | |
1121 pam = g_new0(struct proto_actions_menu, 1); | |
1122 pam->label = _("Set User Info"); | |
1123 pam->callback = jabber_setup_set_info; | |
1124 pam->gc = gc; | |
1125 m = g_list_append(m, pam); | |
1126 | |
8296 | 1127 /* if (js->protocol_options & CHANGE_PASSWORD) { */ |
7124 | 1128 pam = g_new0(struct proto_actions_menu, 1); |
1129 pam->label = _("Change Password"); | |
1130 pam->callback = jabber_password_change; | |
1131 pam->gc = gc; | |
1132 m = g_list_append(m, pam); | |
8296 | 1133 /* } */ |
2956 | 1134 |
1135 return m; | |
1136 } | |
1137 | |
7999 | 1138 static GaimChat *jabber_find_blist_chat(GaimAccount *account, const char *name) |
1139 { | |
1140 GaimBlistNode *gnode, *cnode; | |
1141 JabberID *jid; | |
1142 | |
1143 if(!(jid = jabber_id_new(name))) | |
1144 return NULL; | |
1145 | |
1146 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { | |
1147 for(cnode = gnode->child; cnode; cnode = cnode->next) { | |
1148 GaimChat *chat = (GaimChat*)cnode; | |
1149 const char *room, *server; | |
1150 if(!GAIM_BLIST_NODE_IS_CHAT(cnode)) | |
1151 continue; | |
1152 | |
1153 if(chat->account != account) | |
8011 | 1154 continue; |
7999 | 1155 |
1156 if(!(room = g_hash_table_lookup(chat->components, "room"))) | |
1157 continue; | |
1158 if(!(server = g_hash_table_lookup(chat->components, "server"))) | |
1159 continue; | |
1160 | |
8158 | 1161 if(jid->node && jid->domain && |
1162 !g_utf8_collate(room, jid->node) && !g_utf8_collate(server, jid->domain)) { | |
7999 | 1163 jabber_id_free(jid); |
1164 return chat; | |
1165 } | |
1166 } | |
1167 } | |
1168 jabber_id_free(jid); | |
1169 return NULL; | |
1170 } | |
1171 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1172 static GaimPluginProtocolInfo prpl_info = |
2086 | 1173 { |
7014 | 1174 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1175 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1176 NULL, |
8170 | 1177 NULL, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1178 jabber_list_icon, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1179 jabber_list_emblems, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1180 jabber_status_text, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1181 jabber_tooltip_text, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1182 jabber_away_states, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1183 jabber_actions, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1184 jabber_buddy_menu, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1185 jabber_chat_info, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1186 jabber_login, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1187 jabber_close, |
7014 | 1188 jabber_message_send_im, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1189 jabber_set_info, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1190 jabber_send_typing, |
7014 | 1191 jabber_buddy_get_info, |
1192 jabber_presence_send, | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1193 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1194 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1195 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1196 NULL, |
7014 | 1197 jabber_idle_set, |
7514 | 1198 NULL, |
7014 | 1199 jabber_roster_add_buddy, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1200 NULL, |
7014 | 1201 jabber_roster_remove_buddy, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1202 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1203 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1204 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1205 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1206 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1207 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1208 NULL, |
7014 | 1209 jabber_chat_join, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1210 jabber_chat_invite, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1211 jabber_chat_leave, |
7400 | 1212 NULL, |
7014 | 1213 jabber_message_send_chat, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1214 jabber_keepalive, |
7072 | 1215 jabber_register_account, |
7014 | 1216 jabber_buddy_get_info_chat, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1217 NULL, |
7014 | 1218 jabber_roster_alias_change, |
1219 jabber_roster_group_change, | |
1220 jabber_roster_group_rename, | |
1221 NULL, | |
1222 NULL, /* convo_closed */ /* XXX: thread_ids */ | |
7398 | 1223 jabber_normalize, |
1224 NULL, /* set_buddy_icon */ | |
1225 NULL, /* remove_group */ | |
7971 | 1226 jabber_chat_buddy_real_name, |
7999 | 1227 jabber_chat_set_topic, |
8113 | 1228 jabber_find_blist_chat, |
1229 jabber_roomlist_get_list, | |
1230 jabber_roomlist_cancel, | |
1231 NULL | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1232 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1233 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1234 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1235 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1236 2, /**< api_version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1237 GAIM_PLUGIN_PROTOCOL, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1238 NULL, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1239 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1240 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1241 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1242 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1243 "prpl-jabber", /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1244 "Jabber", /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1245 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1246 /** summary */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1247 N_("Jabber Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1248 /** description */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1249 N_("Jabber Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1250 NULL, /**< author */ |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
1251 GAIM_WEBSITE, /**< homepage */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1252 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1253 NULL, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1254 NULL, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1255 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1256 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1257 NULL, /**< ui_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1258 &prpl_info /**< extra_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1259 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1260 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1261 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5894
diff
changeset
|
1262 init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1263 { |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1264 GaimAccountUserSplit *split; |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1265 GaimAccountOption *option; |
8170 | 1266 struct proto_pref *ppref; |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1267 |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1268 split = gaim_account_user_split_new(_("Server"), "jabber.org", '@'); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1269 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
|
1270 |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1271 split = gaim_account_user_split_new(_("Resource"), "Gaim", '/'); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1272 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
|
1273 |
7630 | 1274 option = gaim_account_option_bool_new(_("Use TLS if available"), "use_tls", |
1275 TRUE); | |
1276 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
1277 option); | |
1278 | |
1279 option = gaim_account_option_bool_new(_("Force old SSL"), "old_ssl", FALSE); | |
7124 | 1280 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
1281 option); | |
6764 | 1282 |
8086 | 1283 option = gaim_account_option_bool_new( |
1284 _("Allow plaintext auth over unencrypted streams"), | |
1285 "auth_plain_in_clear", FALSE); | |
1286 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
1287 option); | |
1288 | |
7014 | 1289 option = gaim_account_option_int_new(_("Port"), "port", 5222); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1290 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
7014 | 1291 option); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1292 |
5685
43ea75092684
[gaim-migrate @ 6106]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
1293 option = gaim_account_option_string_new(_("Connect server"), |
7014 | 1294 "connect_server", NULL); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1295 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
7014 | 1296 option); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1297 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1298 my_protocol = plugin; |
7014 | 1299 |
1300 gaim_prefs_add_none("/plugins/prpl/jabber"); | |
1301 gaim_prefs_add_bool("/plugins/prpl/jabber/hide_os", FALSE); | |
8170 | 1302 |
1303 ppref = g_new0(struct proto_pref, 1); | |
1304 ppref->key = NULL; | |
1305 ppref->label = _("Privacy"); | |
1306 prpl_info.protocol_prefs = g_list_append(prpl_info.protocol_prefs, ppref); | |
1307 | |
1308 ppref = g_new0(struct proto_pref, 1); | |
1309 ppref->key = "/plugins/prpl/jabber/hide_os"; | |
1310 ppref->label = _("Hide Operating System"); /* XXX: come up with a better name for this */ | |
1311 prpl_info.protocol_prefs = g_list_append(prpl_info.protocol_prefs, ppref); | |
2086 | 1312 } |
1313 | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5894
diff
changeset
|
1314 GAIM_INIT_PLUGIN(jabber, init_plugin, info); |