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