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