Mercurial > pidgin
annotate src/protocols/jabber/jabber.c @ 7587:1d9698ab5465
[gaim-migrate @ 8205]
hrmm, I remember changing this some time ago, why didn't it get committed?
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 21 Nov 2003 09:31:16 +0000 |
parents | 43a214a385d1 |
children | 2df4d470c12a |
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 |
7426 | 349 jabber_ssl_connect_failure(GaimSslConnection *gsc, GaimSslErrorType error, |
350 gpointer data) | |
351 { | |
352 GaimConnection *gc = data; | |
353 | |
354 switch(error) { | |
355 case GAIM_SSL_HANDSHAKE_FAILED: | |
356 gaim_connection_error(gc, _("SSL Handshake Failed")); | |
357 break; | |
358 } | |
359 } | |
360 | |
7427 | 361 static void tls_init(JabberStream *js) |
362 { | |
363 gaim_input_remove(js->gc->inpa); | |
364 js->gc->inpa = 0; | |
365 js->gsc = gaim_ssl_connect_fd(js->gc->account, js->fd, | |
366 jabber_login_callback_ssl, jabber_ssl_connect_failure, js->gc); | |
367 } | |
368 | |
369 | |
7426 | 370 static void |
7014 | 371 jabber_login(GaimAccount *account) |
2086 | 372 { |
7014 | 373 int rc; |
374 GaimConnection *gc = gaim_account_get_connection(account); | |
375 const char *connect_server = gaim_account_get_string(account, | |
376 "connect_server", ""); | |
5572 | 377 const char *server; |
7014 | 378 JabberStream *js; |
2086 | 379 |
7014 | 380 gc->flags |= GAIM_CONNECTION_HTML; |
381 js = gc->proto_data = g_new0(JabberStream, 1); | |
382 js->gc = gc; | |
383 js->callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, | |
7395 | 384 g_free, g_free); |
7014 | 385 js->buddies = g_hash_table_new_full(g_str_hash, g_str_equal, |
7116 | 386 g_free, (GDestroyNotify)jabber_buddy_free); |
7014 | 387 js->chats = g_hash_table_new_full(g_str_hash, g_str_equal, |
388 g_free, NULL); | |
389 js->user = jabber_id_new(gaim_account_get_username(account)); | |
7322 | 390 js->next_id = g_random_int(); |
5613 | 391 |
7310 | 392 if(!js->user) { |
393 gaim_connection_error(gc, _("Invalid Jabber ID")); | |
394 return; | |
395 } | |
396 | |
7147 | 397 if(!js->user->resource) { |
398 char *me; | |
399 js->user->resource = g_strdup("Gaim"); | |
400 if(!js->user->node) { | |
401 js->user->node = js->user->domain; | |
402 js->user->domain = g_strdup("jabber.org"); | |
403 } | |
404 me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, | |
405 js->user->resource); | |
406 gaim_account_set_username(account, me); | |
407 g_free(me); | |
7145 | 408 } |
409 | |
7014 | 410 server = connect_server[0] ? connect_server : js->user->domain; |
2086 | 411 |
7014 | 412 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING); |
2956 | 413 |
6880 | 414 if(gaim_account_get_bool(account, "old_ssl", FALSE) |
6764 | 415 && gaim_ssl_is_supported()) { |
7014 | 416 js->gsc = gaim_ssl_connect(account, server, |
417 gaim_account_get_int(account, "port", 5222), | |
7426 | 418 jabber_login_callback_ssl, jabber_ssl_connect_failure, gc); |
3311 | 419 } |
3770 | 420 |
7014 | 421 if(!js->gsc) { |
422 rc = gaim_proxy_connect(account, server, | |
423 gaim_account_get_int(account, "port", 5222), | |
424 jabber_login_callback, gc); | |
2086 | 425 |
7014 | 426 if (rc != 0) |
427 gaim_connection_error(gc, _("Unable to create socket")); | |
2956 | 428 } |
2086 | 429 } |
430 | |
7072 | 431 static gboolean |
432 conn_close_cb(gpointer data) | |
433 { | |
434 JabberStream *js = data; | |
435 gaim_connection_destroy(js->gc); | |
436 return FALSE; | |
437 } | |
438 | |
439 static void | |
440 jabber_connection_schedule_close(JabberStream *js) | |
441 { | |
442 g_timeout_add(0, conn_close_cb, js); | |
443 } | |
444 | |
445 static void | |
7395 | 446 jabber_registration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
7072 | 447 { |
448 const char *type = xmlnode_get_attrib(packet, "type"); | |
449 char *buf; | |
450 | |
451 if(!strcmp(type, "result")) { | |
452 buf = g_strdup_printf(_("Registration of %s@%s successful"), | |
453 js->user->node, js->user->domain); | |
454 gaim_notify_info(NULL, _("Registration Successful"), | |
455 _("Registration Successful"), buf); | |
456 g_free(buf); | |
457 } else { | |
458 char *error; | |
459 xmlnode *y; | |
460 | |
461 if((y = xmlnode_get_child(packet, "error"))) { | |
462 error = xmlnode_get_data(y); | |
463 } else { | |
464 error = g_strdup(_("Unknown Error")); | |
465 } | |
466 | |
467 buf = g_strdup_printf(_("Registration of %s@%s failed: %s"), | |
468 js->user->node, js->user->domain, error); | |
469 gaim_notify_error(NULL, _("Registration Failed"), | |
470 _("Registration Failed"), buf); | |
471 g_free(buf); | |
472 g_free(error); | |
473 } | |
474 jabber_connection_schedule_close(js); | |
475 } | |
476 | |
477 static void | |
478 jabber_register_cb(JabberStream *js, GaimRequestFields *fields) | |
479 { | |
480 GList *groups, *flds; | |
481 xmlnode *query, *y; | |
482 JabberIq *iq; | |
7264 | 483 char *username; |
7072 | 484 |
485 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
486 query = xmlnode_get_child(iq->node, "query"); | |
487 | |
488 for(groups = gaim_request_fields_get_groups(fields); groups; | |
489 groups = groups->next) { | |
490 for(flds = gaim_request_field_group_get_fields(groups->data); | |
491 flds; flds = flds->next) { | |
492 GaimRequestField *field = flds->data; | |
493 const char *id = gaim_request_field_get_id(field); | |
494 const char *value = gaim_request_field_string_get_value(field); | |
495 | |
496 if(!strcmp(id, "username")) { | |
497 y = xmlnode_new_child(query, "username"); | |
498 } else if(!strcmp(id, "password")) { | |
499 y = xmlnode_new_child(query, "password"); | |
500 } else if(!strcmp(id, "name")) { | |
501 y = xmlnode_new_child(query, "name"); | |
502 } else if(!strcmp(id, "email")) { | |
503 y = xmlnode_new_child(query, "email"); | |
504 } else if(!strcmp(id, "nick")) { | |
505 y = xmlnode_new_child(query, "nick"); | |
506 } else if(!strcmp(id, "first")) { | |
507 y = xmlnode_new_child(query, "first"); | |
508 } else if(!strcmp(id, "last")) { | |
509 y = xmlnode_new_child(query, "last"); | |
510 } else if(!strcmp(id, "address")) { | |
511 y = xmlnode_new_child(query, "address"); | |
512 } else if(!strcmp(id, "city")) { | |
513 y = xmlnode_new_child(query, "city"); | |
514 } else if(!strcmp(id, "state")) { | |
515 y = xmlnode_new_child(query, "state"); | |
516 } else if(!strcmp(id, "zip")) { | |
517 y = xmlnode_new_child(query, "zip"); | |
518 } else if(!strcmp(id, "phone")) { | |
519 y = xmlnode_new_child(query, "phone"); | |
520 } else if(!strcmp(id, "url")) { | |
521 y = xmlnode_new_child(query, "url"); | |
522 } else if(!strcmp(id, "date")) { | |
523 y = xmlnode_new_child(query, "date"); | |
524 } else { | |
525 continue; | |
526 } | |
527 xmlnode_insert_data(y, value, -1); | |
7264 | 528 if(!strcmp(id, "username")) { |
529 if(js->user->node) | |
530 g_free(js->user->node); | |
531 js->user->node = g_strdup(value); | |
532 } | |
7072 | 533 } |
534 } | |
535 | |
7264 | 536 username = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, |
537 js->user->resource); | |
538 gaim_account_set_username(js->gc->account, username); | |
539 g_free(username); | |
540 | |
7395 | 541 jabber_iq_set_callback(iq, jabber_registration_result_cb, NULL); |
7072 | 542 |
543 jabber_iq_send(iq); | |
544 | |
545 } | |
546 | |
547 static void | |
548 jabber_register_cancel_cb(JabberStream *js, GaimRequestFields *fields) | |
549 { | |
550 jabber_connection_schedule_close(js); | |
551 } | |
552 | |
553 void jabber_register_parse(JabberStream *js, xmlnode *packet) | |
554 { | |
555 if(js->registration) { | |
556 GaimRequestFields *fields; | |
557 GaimRequestFieldGroup *group; | |
558 GaimRequestField *field; | |
559 xmlnode *query, *y; | |
560 char *instructions; | |
561 | |
562 /* get rid of the login thingy */ | |
563 gaim_connection_set_state(js->gc, GAIM_CONNECTED); | |
564 | |
565 query = xmlnode_get_child(packet, "query"); | |
566 | |
567 if(xmlnode_get_child(query, "registered")) { | |
568 gaim_notify_error(NULL, _("Already Registered"), | |
569 _("Already Registered"), NULL); | |
570 jabber_connection_schedule_close(js); | |
571 return; | |
572 } | |
573 | |
574 fields = gaim_request_fields_new(); | |
575 group = gaim_request_field_group_new(NULL); | |
576 gaim_request_fields_add_group(fields, group); | |
577 | |
578 field = gaim_request_field_string_new("username", _("Username"), | |
579 js->user->node, FALSE); | |
580 gaim_request_field_group_add_field(group, field); | |
581 | |
582 field = gaim_request_field_string_new("password", _("Password"), | |
583 gaim_account_get_password(js->gc->account), FALSE); | |
584 gaim_request_field_string_set_masked(field, TRUE); | |
585 gaim_request_field_group_add_field(group, field); | |
586 | |
587 if(xmlnode_get_child(query, "name")) { | |
588 field = gaim_request_field_string_new("name", _("Name"), | |
589 gaim_account_get_alias(js->gc->account), FALSE); | |
590 gaim_request_field_group_add_field(group, field); | |
591 } | |
592 if(xmlnode_get_child(query, "email")) { | |
593 field = gaim_request_field_string_new("email", _("E-Mail"), | |
594 NULL, FALSE); | |
595 gaim_request_field_group_add_field(group, field); | |
596 } | |
597 if(xmlnode_get_child(query, "nick")) { | |
598 field = gaim_request_field_string_new("nick", _("Nickname"), | |
599 NULL, FALSE); | |
600 gaim_request_field_group_add_field(group, field); | |
601 } | |
602 if(xmlnode_get_child(query, "first")) { | |
603 field = gaim_request_field_string_new("first", _("First Name"), | |
604 NULL, FALSE); | |
605 gaim_request_field_group_add_field(group, field); | |
606 } | |
607 if(xmlnode_get_child(query, "last")) { | |
608 field = gaim_request_field_string_new("last", _("Last Name"), | |
609 NULL, FALSE); | |
610 gaim_request_field_group_add_field(group, field); | |
611 } | |
612 if(xmlnode_get_child(query, "address")) { | |
613 field = gaim_request_field_string_new("address", _("Address"), | |
614 NULL, FALSE); | |
615 gaim_request_field_group_add_field(group, field); | |
616 } | |
617 if(xmlnode_get_child(query, "city")) { | |
618 field = gaim_request_field_string_new("city", _("City"), | |
619 NULL, FALSE); | |
620 gaim_request_field_group_add_field(group, field); | |
621 } | |
622 if(xmlnode_get_child(query, "state")) { | |
623 field = gaim_request_field_string_new("state", _("State"), | |
624 NULL, FALSE); | |
625 gaim_request_field_group_add_field(group, field); | |
626 } | |
627 if(xmlnode_get_child(query, "zip")) { | |
628 field = gaim_request_field_string_new("zip", _("Postal Code"), | |
629 NULL, FALSE); | |
630 gaim_request_field_group_add_field(group, field); | |
631 } | |
632 if(xmlnode_get_child(query, "phone")) { | |
633 field = gaim_request_field_string_new("phone", _("Phone"), | |
634 NULL, FALSE); | |
635 gaim_request_field_group_add_field(group, field); | |
636 } | |
637 if(xmlnode_get_child(query, "url")) { | |
638 field = gaim_request_field_string_new("url", _("URL"), | |
639 NULL, FALSE); | |
640 gaim_request_field_group_add_field(group, field); | |
641 } | |
642 if(xmlnode_get_child(query, "date")) { | |
643 field = gaim_request_field_string_new("date", _("Date"), | |
644 NULL, FALSE); | |
645 gaim_request_field_group_add_field(group, field); | |
646 } | |
647 | |
648 if((y = xmlnode_get_child(query, "instructions"))) | |
649 instructions = xmlnode_get_data(y); | |
650 else | |
651 instructions = g_strdup(_("Please fill out the information below " | |
652 "to register your new account.")); | |
653 | |
654 gaim_request_fields(js->gc, _("Register New Jabber Account"), | |
655 _("Register New Jabber Account"), instructions, fields, | |
656 _("Register"), G_CALLBACK(jabber_register_cb), | |
657 _("Cancel"), G_CALLBACK(jabber_register_cancel_cb), js); | |
658 } | |
659 } | |
660 | |
661 static void jabber_register_start(JabberStream *js) | |
662 { | |
663 JabberIq *iq; | |
664 | |
665 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:register"); | |
666 jabber_iq_send(iq); | |
667 } | |
668 | |
669 static void jabber_register_account(GaimAccount *account) | |
670 { | |
671 GaimConnection *gc = gaim_account_get_connection(account); | |
672 JabberStream *js; | |
673 const char *connect_server = gaim_account_get_string(account, | |
674 "connect_server", ""); | |
675 const char *server; | |
676 int rc; | |
677 | |
678 js = gc->proto_data = g_new0(JabberStream, 1); | |
679 js->gc = gc; | |
680 js->registration = TRUE; | |
681 js->callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, | |
7395 | 682 g_free, g_free); |
7072 | 683 js->user = jabber_id_new(gaim_account_get_username(account)); |
7322 | 684 js->next_id = g_random_int(); |
7072 | 685 |
7310 | 686 if(!js->user) { |
687 gaim_connection_error(gc, _("Invalid Jabber ID")); | |
688 return; | |
689 } | |
690 | |
7147 | 691 if(!js->user->resource) { |
692 char *me; | |
693 js->user->resource = g_strdup("Gaim"); | |
694 if(!js->user->node) { | |
695 js->user->node = js->user->domain; | |
696 js->user->domain = g_strdup("jabber.org"); | |
697 } | |
698 me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, | |
699 js->user->resource); | |
700 gaim_account_set_username(account, me); | |
701 g_free(me); | |
702 } | |
703 | |
7072 | 704 server = connect_server[0] ? connect_server : js->user->domain; |
705 | |
706 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING); | |
707 | |
708 if(gaim_account_get_bool(account, "old_ssl", FALSE) | |
709 && gaim_ssl_is_supported()) { | |
710 js->gsc = gaim_ssl_connect(account, server, | |
711 gaim_account_get_int(account, "port", 5222), | |
7274
448e39ace278
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
7264
diff
changeset
|
712 jabber_login_callback_ssl, NULL, gc); |
7072 | 713 } |
714 | |
715 if(!js->gsc) { | |
716 rc = gaim_proxy_connect(account, server, | |
717 gaim_account_get_int(account, "port", 5222), | |
718 jabber_login_callback, gc); | |
719 | |
720 if (rc != 0) | |
721 gaim_connection_error(gc, _("Unable to create socket")); | |
722 } | |
723 } | |
724 | |
5572 | 725 static void jabber_close(GaimConnection *gc) |
2086 | 726 { |
7014 | 727 JabberStream *js = gc->proto_data; |
2956 | 728 |
7014 | 729 jabber_send_raw(js, "</stream:stream>"); |
3311 | 730 |
7014 | 731 if(js->gsc) { |
732 gaim_ssl_close(js->gsc); | |
733 } else { | |
7072 | 734 if(js->gc->inpa) |
735 gaim_input_remove(js->gc->inpa); | |
7014 | 736 close(js->fd); |
737 } | |
3311 | 738 |
7587 | 739 if(js->context) |
740 g_markup_parse_context_free(js->context); | |
7072 | 741 if(js->callbacks) |
742 g_hash_table_destroy(js->callbacks); | |
743 if(js->buddies) | |
744 g_hash_table_destroy(js->buddies); | |
745 if(js->chats) | |
746 g_hash_table_destroy(js->chats); | |
7014 | 747 if(js->stream_id) |
748 g_free(js->stream_id); | |
7587 | 749 if(js->user) |
750 jabber_id_free(js->user); | |
7014 | 751 g_free(js); |
5093 | 752 } |
753 | |
7395 | 754 static void jabber_server_probe(JabberStream *js) |
755 { | |
756 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_GET, | |
757 "http://jabber.org/protocol/disco#items"); | |
758 | |
759 xmlnode_set_attrib(iq->node, "to", js->user->domain); | |
760 jabber_iq_send(iq); | |
761 } | |
762 | |
7014 | 763 void jabber_stream_set_state(JabberStream *js, JabberStreamState state) |
3105 | 764 { |
7014 | 765 js->state = state; |
766 switch(state) { | |
767 case JABBER_STREAM_OFFLINE: | |
768 break; | |
769 case JABBER_STREAM_CONNECTING: | |
770 gaim_connection_update_progress(js->gc, _("Connecting"), 1, | |
771 JABBER_CONNECT_STEPS); | |
772 break; | |
773 case JABBER_STREAM_INITIALIZING: | |
774 gaim_connection_update_progress(js->gc, _("Initializing Stream"), | |
775 js->gsc ? 5 : 2, JABBER_CONNECT_STEPS); | |
776 jabber_stream_init(js); | |
777 jabber_parser_setup(js); | |
778 break; | |
779 case JABBER_STREAM_AUTHENTICATING: | |
780 gaim_connection_update_progress(js->gc, _("Authenticating"), | |
781 js->gsc ? 6 : 3, JABBER_CONNECT_STEPS); | |
7072 | 782 if(js->registration) |
783 jabber_register_start(js); | |
784 else if(js->protocol_version == JABBER_PROTO_0_9) | |
7014 | 785 jabber_auth_start_old(js); |
786 break; | |
787 case JABBER_STREAM_REINITIALIZING: | |
788 gaim_connection_update_progress(js->gc, _("Re-initializing Stream"), | |
789 6, JABBER_CONNECT_STEPS); | |
790 jabber_stream_init(js); | |
791 break; | |
792 case JABBER_STREAM_CONNECTED: | |
793 gaim_connection_set_state(js->gc, GAIM_CONNECTED); | |
794 jabber_roster_request(js); | |
795 jabber_presence_send(js->gc, js->gc->away_state, js->gc->away); | |
7395 | 796 jabber_server_probe(js); |
7014 | 797 serv_finish_login(js->gc); |
798 break; | |
3105 | 799 } |
800 } | |
801 | |
7014 | 802 char *jabber_get_next_id(JabberStream *js) |
2086 | 803 { |
7322 | 804 return g_strdup_printf("gaim%x", js->next_id++); |
2086 | 805 } |
806 | |
7014 | 807 void jabber_idle_set(GaimConnection *gc, int idle) |
3340 | 808 { |
7014 | 809 JabberStream *js = gc->proto_data; |
3340 | 810 |
7014 | 811 js->idle = idle ? time(NULL) - idle : idle; |
3314 | 812 } |
813 | |
6695 | 814 static const char *jabber_list_icon(GaimAccount *a, GaimBuddy *b) |
2086 | 815 { |
4687 | 816 return "jabber"; |
817 } | |
4916 | 818 |
7014 | 819 static void jabber_list_emblems(GaimBuddy *b, char **se, char **sw, |
820 char **nw, char **ne) | |
4916 | 821 { |
7014 | 822 JabberStream *js; |
823 JabberBuddy *jb; | |
824 | |
825 if(!b->account->gc) | |
826 return; | |
827 js = b->account->gc->proto_data; | |
828 jb = jabber_buddy_find(js, b->name, FALSE); | |
5135 | 829 |
830 if(!GAIM_BUDDY_IS_ONLINE(b)) { | |
7014 | 831 if(jb && jb->error_msg) |
4927 | 832 *nw = "error"; |
5135 | 833 |
7014 | 834 if(jb && (jb->subscription & JABBER_SUB_PENDING || |
835 !(jb->subscription & JABBER_SUB_TO))) | |
5135 | 836 *se = "notauthorized"; |
837 else | |
838 *se = "offline"; | |
4916 | 839 } else { |
840 switch (b->uc) { | |
7014 | 841 case JABBER_STATE_AWAY: |
842 *se = "away"; | |
843 break; | |
844 case JABBER_STATE_CHAT: | |
845 *se = "chat"; | |
846 break; | |
847 case JABBER_STATE_XA: | |
848 *se = "extendedaway"; | |
849 break; | |
850 case JABBER_STATE_DND: | |
851 *se = "extendedaway"; | |
852 break; | |
853 case JABBER_STATE_ERROR: | |
854 *se = "error"; | |
855 break; | |
4916 | 856 } |
2086 | 857 } |
4916 | 858 } |
2086 | 859 |
7014 | 860 static char *jabber_status_text(GaimBuddy *b) |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
861 { |
7014 | 862 JabberBuddy *jb = jabber_buddy_find(b->account->gc->proto_data, b->name, |
863 FALSE); | |
864 char *ret = NULL; | |
5234 | 865 |
7014 | 866 if(jb && !GAIM_BUDDY_IS_ONLINE(b) && (jb->subscription & JABBER_SUB_PENDING || !(jb->subscription & JABBER_SUB_TO))) { |
867 ret = g_strdup(_("Not Authorized")); | |
868 } else if(jb && !GAIM_BUDDY_IS_ONLINE(b) && jb->error_msg) { | |
869 ret = g_strdup(jb->error_msg); | |
2956 | 870 } else { |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7072
diff
changeset
|
871 char *stripped; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7072
diff
changeset
|
872 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7072
diff
changeset
|
873 stripped = gaim_markup_strip_html(jabber_buddy_get_status_msg(jb)); |
2956 | 874 |
7014 | 875 if(!stripped && b->uc & UC_UNAVAILABLE) |
876 stripped = g_strdup(jabber_get_state_string(b->uc)); | |
2086 | 877 |
7014 | 878 if(stripped) { |
879 ret = g_markup_escape_text(stripped, -1); | |
880 g_free(stripped); | |
881 } | |
2086 | 882 } |
883 | |
7014 | 884 return ret; |
2956 | 885 } |
886 | |
6695 | 887 static char *jabber_tooltip_text(GaimBuddy *b) |
4744 | 888 { |
7014 | 889 JabberBuddy *jb = jabber_buddy_find(b->account->gc->proto_data, b->name, |
890 FALSE); | |
891 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, NULL); | |
5135 | 892 char *ret = NULL; |
7014 | 893 |
894 if(jbr) { | |
4777 | 895 char *text = NULL; |
7014 | 896 if(jbr->status) { |
897 char *stripped; | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7072
diff
changeset
|
898 stripped = gaim_markup_strip_html(jbr->status); |
7014 | 899 text = g_markup_escape_text(stripped, -1); |
900 g_free(stripped); | |
901 } | |
902 | |
5236 | 903 ret = g_strdup_printf("<b>%s:</b> %s%s%s", |
904 _("Status"), | |
7014 | 905 jabber_get_state_string(jbr->state), |
906 text ? ": " : "", | |
4745 | 907 text ? text : ""); |
7014 | 908 if(text) |
4745 | 909 g_free(text); |
7014 | 910 } else if(jb && !GAIM_BUDDY_IS_ONLINE(b) && jb->error_msg) { |
911 ret = g_strdup_printf("<b>%s:</b> %s", | |
912 _("Error"), jb->error_msg); | |
913 } else if(jb && !GAIM_BUDDY_IS_ONLINE(b) && | |
914 (jb->subscription & JABBER_SUB_PENDING || | |
915 !(jb->subscription & JABBER_SUB_TO))) { | |
916 ret = g_strdup_printf("<b>%s:</b> %s", | |
917 _("Status"), _("Not Authorized")); | |
4745 | 918 } |
4744 | 919 |
5135 | 920 return ret; |
4732 | 921 } |
922 | |
7014 | 923 static GList *jabber_away_states(GaimConnection *gc) |
924 { | |
2086 | 925 GList *m = NULL; |
926 | |
4982 | 927 m = g_list_append(m, _("Online")); |
928 m = g_list_append(m, _("Chatty")); | |
929 m = g_list_append(m, _("Away")); | |
930 m = g_list_append(m, _("Extended Away")); | |
931 m = g_list_append(m, _("Do Not Disturb")); | |
932 m = g_list_append(m, _("Invisible")); | |
4110 | 933 m = g_list_append(m, GAIM_AWAY_CUSTOM); |
2086 | 934 |
935 return m; | |
936 } | |
937 | |
7395 | 938 static void |
939 jabber_password_change_result_cb(JabberStream *js, xmlnode *packet, | |
940 gpointer data) | |
7124 | 941 { |
942 const char *type; | |
943 | |
944 type = xmlnode_get_attrib(packet, "type"); | |
945 | |
946 if(!strcmp(type, "result")) { | |
947 gaim_notify_info(js->gc, _("Password Changed"), _("Password Changed"), | |
948 _("Your password has been changed.")); | |
949 } else { | |
950 xmlnode *error; | |
951 char *buf, *error_txt = NULL; | |
952 | |
953 | |
954 if((error = xmlnode_get_child(packet, "error"))) | |
955 error_txt = xmlnode_get_data(error); | |
956 | |
957 if(error_txt) { | |
958 buf = g_strdup_printf(_("Error changing password: %s"), | |
959 error_txt); | |
960 g_free(error_txt); | |
961 } else { | |
962 buf = g_strdup(_("Unknown error occurred changing password")); | |
963 } | |
964 | |
965 gaim_notify_error(js->gc, _("Error"), _("Error"), buf); | |
966 g_free(buf); | |
967 } | |
968 } | |
969 | |
970 static void jabber_password_change_cb(JabberStream *js, | |
971 GaimRequestFields *fields) | |
972 { | |
973 const char *p1, *p2; | |
974 JabberIq *iq; | |
975 xmlnode *query, *y; | |
976 | |
977 p1 = gaim_request_fields_get_string(fields, "password1"); | |
978 p2 = gaim_request_fields_get_string(fields, "password2"); | |
979 | |
980 if(strcmp(p1, p2)) { | |
981 gaim_notify_error(js->gc, NULL, _("New passwords do not match."), NULL); | |
982 return; | |
983 } | |
984 | |
985 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
986 | |
987 xmlnode_set_attrib(iq->node, "to", js->user->domain); | |
988 | |
989 query = xmlnode_get_child(iq->node, "query"); | |
990 | |
991 y = xmlnode_new_child(query, "username"); | |
992 xmlnode_insert_data(y, js->user->node, -1); | |
993 y = xmlnode_new_child(query, "password"); | |
994 xmlnode_insert_data(y, p1, -1); | |
995 | |
7395 | 996 jabber_iq_set_callback(iq, jabber_password_change_result_cb, NULL); |
7124 | 997 |
998 jabber_iq_send(iq); | |
999 | |
1000 gaim_account_set_password(js->gc->account, p1); | |
1001 } | |
1002 | |
1003 static void jabber_password_change(GaimConnection *gc) | |
1004 { | |
1005 JabberStream *js = gc->proto_data; | |
1006 GaimRequestFields *fields; | |
1007 GaimRequestFieldGroup *group; | |
1008 GaimRequestField *field; | |
1009 | |
1010 fields = gaim_request_fields_new(); | |
1011 group = gaim_request_field_group_new(NULL); | |
1012 gaim_request_fields_add_group(fields, group); | |
1013 | |
1014 field = gaim_request_field_string_new("password1", _("Password"), | |
1015 "", FALSE); | |
1016 gaim_request_field_string_set_masked(field, TRUE); | |
1017 gaim_request_field_group_add_field(group, field); | |
1018 | |
1019 field = gaim_request_field_string_new("password2", _("Password (again)"), | |
1020 "", FALSE); | |
1021 gaim_request_field_string_set_masked(field, TRUE); | |
1022 gaim_request_field_group_add_field(group, field); | |
1023 | |
1024 gaim_request_fields(js->gc, _("Change Jabber Password"), | |
1025 _("Change Jabber Password"), _("Please enter your new password"), | |
1026 fields, _("OK"), G_CALLBACK(jabber_password_change_cb), | |
1027 _("Cancel"), NULL, js); | |
1028 } | |
1029 | |
5572 | 1030 static GList *jabber_actions(GaimConnection *gc) |
2956 | 1031 { |
7124 | 1032 JabberStream *js = gc->proto_data; |
2956 | 1033 GList *m = NULL; |
4333 | 1034 struct proto_actions_menu *pam; |
1035 | |
1036 pam = g_new0(struct proto_actions_menu, 1); | |
1037 pam->label = _("Set User Info"); | |
1038 pam->callback = jabber_setup_set_info; | |
1039 pam->gc = gc; | |
1040 m = g_list_append(m, pam); | |
1041 | |
7124 | 1042 if(js->protocol_version == JABBER_PROTO_0_9) { |
1043 pam = g_new0(struct proto_actions_menu, 1); | |
1044 pam->label = _("Change Password"); | |
1045 pam->callback = jabber_password_change; | |
1046 pam->gc = gc; | |
1047 m = g_list_append(m, pam); | |
1048 } | |
2956 | 1049 |
1050 return m; | |
1051 } | |
1052 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1053 static GaimPluginProtocolInfo prpl_info = |
2086 | 1054 { |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1055 GAIM_PROTO_JABBER, |
7014 | 1056 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1057 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1058 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1059 jabber_list_icon, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1060 jabber_list_emblems, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1061 jabber_status_text, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1062 jabber_tooltip_text, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1063 jabber_away_states, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1064 jabber_actions, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1065 jabber_buddy_menu, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1066 jabber_chat_info, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1067 jabber_login, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1068 jabber_close, |
7014 | 1069 jabber_message_send_im, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1070 jabber_set_info, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1071 jabber_send_typing, |
7014 | 1072 jabber_buddy_get_info, |
1073 jabber_presence_send, | |
5205
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, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1076 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1077 NULL, |
7014 | 1078 jabber_idle_set, |
7514 | 1079 NULL, |
7014 | 1080 jabber_roster_add_buddy, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1081 NULL, |
7014 | 1082 jabber_roster_remove_buddy, |
5205
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, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1088 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1089 NULL, |
7014 | 1090 jabber_chat_join, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1091 jabber_chat_invite, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1092 jabber_chat_leave, |
7400 | 1093 NULL, |
7014 | 1094 jabber_message_send_chat, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1095 jabber_keepalive, |
7072 | 1096 jabber_register_account, |
7014 | 1097 jabber_buddy_get_info_chat, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1098 NULL, |
7014 | 1099 jabber_roster_alias_change, |
1100 jabber_roster_group_change, | |
1101 jabber_roster_group_rename, | |
1102 NULL, | |
1103 NULL, /* convo_closed */ /* XXX: thread_ids */ | |
7398 | 1104 jabber_normalize, |
1105 NULL, /* set_buddy_icon */ | |
1106 NULL, /* remove_group */ | |
1107 jabber_chat_buddy_real_name | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1108 }; |
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 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1111 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1112 2, /**< api_version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1113 GAIM_PLUGIN_PROTOCOL, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1114 NULL, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1115 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1116 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1117 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1118 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1119 "prpl-jabber", /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1120 "Jabber", /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1121 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1122 /** summary */ |
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 /** description */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1125 N_("Jabber Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1126 NULL, /**< author */ |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
1127 GAIM_WEBSITE, /**< homepage */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1128 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1129 NULL, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1130 NULL, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1131 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1132 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1133 NULL, /**< ui_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1134 &prpl_info /**< extra_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1135 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1136 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1137 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5894
diff
changeset
|
1138 init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1139 { |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1140 GaimAccountUserSplit *split; |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1141 GaimAccountOption *option; |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1142 |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1143 split = gaim_account_user_split_new(_("Server"), "jabber.org", '@'); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1144 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
|
1145 |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1146 split = gaim_account_user_split_new(_("Resource"), "Gaim", '/'); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1147 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
|
1148 |
7124 | 1149 option = gaim_account_option_bool_new(_("Force Old SSL"), "old_ssl", FALSE); |
1150 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
1151 option); | |
6764 | 1152 |
7014 | 1153 option = gaim_account_option_int_new(_("Port"), "port", 5222); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1154 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
7014 | 1155 option); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1156 |
5685
43ea75092684
[gaim-migrate @ 6106]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
1157 option = gaim_account_option_string_new(_("Connect server"), |
7014 | 1158 "connect_server", NULL); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1159 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
7014 | 1160 option); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1161 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1162 my_protocol = plugin; |
7014 | 1163 |
1164 gaim_prefs_add_none("/plugins/prpl/jabber"); | |
1165 gaim_prefs_add_bool("/plugins/prpl/jabber/hide_os", FALSE); | |
2086 | 1166 } |
1167 | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5894
diff
changeset
|
1168 GAIM_INIT_PLUGIN(jabber, init_plugin, info); |