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