Mercurial > pidgin
annotate src/protocols/jabber/jabber.c @ 10481:bcfea6c3d5c9
[gaim-migrate @ 11769]
Patch 1093958 from Felipe Contreras. It fixes stuff.
I also made some tweaks to make valgrind a bit happier.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Fri, 07 Jan 2005 02:48:33 +0000 |
parents | 3e4ecbdf8d0a |
children | 84bc372a621e |
rev | line source |
---|---|
2086 | 1 /* |
7014 | 2 * gaim - Jabber Protocol Plugin |
2086 | 3 * |
7014 | 4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> |
2086 | 5 * |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
7014 | 10 * |
2086 | 11 * This program is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
21 #include "internal.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
22 |
7014 | 23 #include "account.h" |
24 #include "accountopt.h" | |
9030 | 25 #include "blist.h" |
9130 | 26 #include "cmds.h" |
7014 | 27 #include "debug.h" |
28 #include "message.h" | |
7072 | 29 #include "notify.h" |
8713 | 30 #include "pluginpref.h" |
7014 | 31 #include "prpl.h" |
7072 | 32 #include "request.h" |
7014 | 33 #include "server.h" |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7072
diff
changeset
|
34 #include "util.h" |
9943 | 35 #include "version.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
36 |
7014 | 37 #include "auth.h" |
38 #include "buddy.h" | |
39 #include "chat.h" | |
8312 | 40 #include "disco.h" |
7014 | 41 #include "iq.h" |
42 #include "jutil.h" | |
43 #include "message.h" | |
44 #include "parser.h" | |
45 #include "presence.h" | |
46 #include "jabber.h" | |
47 #include "roster.h" | |
9466 | 48 #include "si.h" |
7923 | 49 #include "xdata.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
50 |
7014 | 51 #define JABBER_CONNECT_STEPS (js->gsc ? 8 : 5) |
2086 | 52 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
53 static GaimPlugin *my_protocol = NULL; |
4249 | 54 |
7014 | 55 static void jabber_stream_init(JabberStream *js) |
56 { | |
57 char *open_stream; | |
3340 | 58 |
7014 | 59 open_stream = g_strdup_printf("<stream:stream to='%s' " |
60 "xmlns='jabber:client' " | |
7395 | 61 "xmlns:stream='http://etherx.jabber.org/streams' " |
62 "version='1.0'>", | |
7291 | 63 js->user->domain); |
3311 | 64 |
7642 | 65 jabber_send_raw(js, open_stream, -1); |
2086 | 66 |
7014 | 67 g_free(open_stream); |
2086 | 68 } |
69 | |
7395 | 70 static void |
71 jabber_session_initialized_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
3311 | 72 { |
7014 | 73 const char *type = xmlnode_get_attrib(packet, "type"); |
74 if(type && !strcmp(type, "result")) { | |
75 jabber_stream_set_state(js, JABBER_STREAM_CONNECTED); | |
76 } else { | |
77 gaim_connection_error(js->gc, _("Error initializing session")); | |
3311 | 78 } |
79 } | |
80 | |
7014 | 81 static void jabber_session_init(JabberStream *js) |
3311 | 82 { |
7014 | 83 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); |
84 xmlnode *session; | |
3311 | 85 |
7395 | 86 jabber_iq_set_callback(iq, jabber_session_initialized_cb, NULL); |
3311 | 87 |
7014 | 88 session = xmlnode_new_child(iq->node, "session"); |
89 xmlnode_set_attrib(session, "xmlns", "urn:ietf:params:xml:ns:xmpp-session"); | |
3311 | 90 |
7014 | 91 jabber_iq_send(iq); |
3311 | 92 } |
93 | |
7395 | 94 static void jabber_bind_result_cb(JabberStream *js, xmlnode *packet, |
95 gpointer data) | |
96 { | |
8401 | 97 const char *type = xmlnode_get_attrib(packet, "type"); |
98 xmlnode *bind; | |
99 | |
100 if(type && !strcmp(type, "result") && | |
101 (bind = xmlnode_get_child_with_namespace(packet, "bind", "urn:ietf:params:xml:ns:xmpp-bind"))) { | |
102 xmlnode *jid; | |
103 char *full_jid; | |
104 if((jid = xmlnode_get_child(bind, "jid")) && (full_jid = xmlnode_get_data(jid))) { | |
10289 | 105 JabberBuddy *my_jb = NULL; |
8401 | 106 jabber_id_free(js->user); |
107 if(!(js->user = jabber_id_new(full_jid))) { | |
108 gaim_connection_error(js->gc, _("Invalid response from server.")); | |
109 } | |
10289 | 110 if((my_jb = jabber_buddy_find(js, full_jid, TRUE))) |
111 my_jb->subscription |= JABBER_SUB_BOTH; | |
8401 | 112 } |
113 } else { | |
114 char *msg = jabber_parse_error(js, packet); | |
115 gaim_connection_error(js->gc, msg); | |
116 g_free(msg); | |
117 } | |
7395 | 118 |
119 jabber_session_init(js); | |
120 } | |
121 | |
122 static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet) | |
123 { | |
8296 | 124 if(xmlnode_get_child(packet, "starttls")) { |
125 if(jabber_process_starttls(js, packet)) | |
126 return; | |
127 } | |
128 | |
7395 | 129 if(xmlnode_get_child(packet, "mechanisms")) { |
130 jabber_auth_start(js, packet); | |
131 } else if(xmlnode_get_child(packet, "bind")) { | |
132 xmlnode *bind, *resource; | |
133 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); | |
134 bind = xmlnode_new_child(iq->node, "bind"); | |
135 xmlnode_set_attrib(bind, "xmlns", "urn:ietf:params:xml:ns:xmpp-bind"); | |
136 resource = xmlnode_new_child(bind, "resource"); | |
137 xmlnode_insert_data(resource, js->user->resource, -1); | |
138 | |
139 jabber_iq_set_callback(iq, jabber_bind_result_cb, NULL); | |
140 | |
141 jabber_iq_send(iq); | |
8296 | 142 } else /* if(xmlnode_get_child_with_namespace(packet, "auth")) */ { |
143 /* If we get an empty stream:features packet, or we explicitly get | |
144 * an auth feature with namespace http://jabber.org/features/iq-auth | |
145 * we should revert back to iq:auth authentication, even though we're | |
146 * connecting to an XMPP server. */ | |
147 js->auth_type = JABBER_AUTH_IQ_AUTH; | |
148 jabber_stream_set_state(js, JABBER_STREAM_AUTHENTICATING); | |
7395 | 149 } |
150 } | |
151 | |
7014 | 152 static void jabber_stream_handle_error(JabberStream *js, xmlnode *packet) |
3311 | 153 { |
8401 | 154 char *msg = jabber_parse_error(js, packet); |
3311 | 155 |
8401 | 156 gaim_connection_error(js->gc, msg); |
157 g_free(msg); | |
2086 | 158 } |
159 | |
7014 | 160 static void tls_init(JabberStream *js); |
2086 | 161 |
7014 | 162 void jabber_process_packet(JabberStream *js, xmlnode *packet) |
2086 | 163 { |
7014 | 164 if(!strcmp(packet->name, "iq")) { |
7395 | 165 jabber_iq_parse(js, packet); |
7014 | 166 } else if(!strcmp(packet->name, "presence")) { |
167 jabber_presence_parse(js, packet); | |
168 } else if(!strcmp(packet->name, "message")) { | |
169 jabber_message_parse(js, packet); | |
170 } else if(!strcmp(packet->name, "stream:features")) { | |
7395 | 171 jabber_stream_features_parse(js, packet); |
7014 | 172 } else if(!strcmp(packet->name, "stream:error")) { |
173 jabber_stream_handle_error(js, packet); | |
174 } else if(!strcmp(packet->name, "challenge")) { | |
175 if(js->state == JABBER_STREAM_AUTHENTICATING) | |
176 jabber_auth_handle_challenge(js, packet); | |
177 } else if(!strcmp(packet->name, "success")) { | |
178 if(js->state == JABBER_STREAM_AUTHENTICATING) | |
179 jabber_auth_handle_success(js, packet); | |
180 } else if(!strcmp(packet->name, "failure")) { | |
181 if(js->state == JABBER_STREAM_AUTHENTICATING) | |
182 jabber_auth_handle_failure(js, packet); | |
183 } else if(!strcmp(packet->name, "proceed")) { | |
184 if(js->state == JABBER_STREAM_AUTHENTICATING && !js->gsc) | |
185 tls_init(js); | |
186 } else { | |
187 gaim_debug(GAIM_DEBUG_WARNING, "jabber", "Unknown packet: %s\n", | |
188 packet->name); | |
2086 | 189 } |
190 } | |
191 | |
7642 | 192 void jabber_send_raw(JabberStream *js, const char *data, int len) |
2086 | 193 { |
7014 | 194 int ret; |
2086 | 195 |
7014 | 196 /* because printing a tab to debug every minute gets old */ |
197 if(strcmp(data, "\t")) | |
8401 | 198 gaim_debug(GAIM_DEBUG_MISC, "jabber", "Sending%s: %s\n", |
7014 | 199 js->gsc ? " (ssl)" : "", data); |
2086 | 200 |
7014 | 201 if(js->gsc) { |
7642 | 202 ret = gaim_ssl_write(js->gsc, data, len == -1 ? strlen(data) : len); |
7014 | 203 } else { |
8013 | 204 if(js->fd < 0) |
205 return; | |
7642 | 206 ret = write(js->fd, data, len == -1 ? strlen(data) : len); |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
207 } |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
208 |
7014 | 209 if(ret < 0) |
210 gaim_connection_error(js->gc, _("Write error")); | |
211 | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
212 } |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
213 |
7014 | 214 void jabber_send(JabberStream *js, xmlnode *packet) |
2086 | 215 { |
7014 | 216 char *txt; |
7642 | 217 int len; |
2086 | 218 |
7642 | 219 txt = xmlnode_to_str(packet, &len); |
220 jabber_send_raw(js, txt, len); | |
7014 | 221 g_free(txt); |
2086 | 222 } |
223 | |
7014 | 224 static void jabber_keepalive(GaimConnection *gc) |
2086 | 225 { |
7642 | 226 jabber_send_raw(gc->proto_data, "\t", -1); |
2086 | 227 } |
228 | |
7014 | 229 static void |
230 jabber_recv_cb_ssl(gpointer data, GaimSslConnection *gsc, | |
6764 | 231 GaimInputCondition cond) |
232 { | |
7014 | 233 GaimConnection *gc = data; |
234 JabberStream *js = gc->proto_data; | |
6764 | 235 int len; |
7014 | 236 static char buf[4096]; |
6768 | 237 |
7014 | 238 if(!g_list_find(gaim_connections_get_all(), gc)) { |
6768 | 239 gaim_ssl_close(gsc); |
240 return; | |
241 } | |
242 | |
7014 | 243 if((len = gaim_ssl_read(gsc, buf, sizeof(buf) - 1)) > 0) { |
6764 | 244 buf[len] = '\0'; |
7014 | 245 gaim_debug(GAIM_DEBUG_INFO, "jabber", "Recv (ssl)(%d): %s\n", len, buf); |
246 jabber_parser_process(js, buf, len); | |
7177 | 247 } else { |
248 gaim_connection_error(gc, _("Read Error")); | |
2086 | 249 } |
250 } | |
251 | |
7014 | 252 static void |
253 jabber_recv_cb(gpointer data, gint source, GaimInputCondition condition) | |
2086 | 254 { |
5572 | 255 GaimConnection *gc = data; |
7014 | 256 JabberStream *js = gc->proto_data; |
257 int len; | |
258 static char buf[4096]; | |
2086 | 259 |
7014 | 260 if(!g_list_find(gaim_connections_get_all(), gc)) |
261 return; | |
2956 | 262 |
7014 | 263 if((len = read(js->fd, buf, sizeof(buf) - 1)) > 0) { |
264 buf[len] = '\0'; | |
265 gaim_debug(GAIM_DEBUG_INFO, "jabber", "Recv (%d): %s\n", len, buf); | |
266 jabber_parser_process(js, buf, len); | |
7177 | 267 } else { |
268 gaim_connection_error(gc, _("Read Error")); | |
7014 | 269 } |
2086 | 270 } |
271 | |
7014 | 272 static void |
273 jabber_login_callback_ssl(gpointer data, GaimSslConnection *gsc, | |
6764 | 274 GaimInputCondition cond) |
275 { | |
276 GaimConnection *gc = data; | |
7014 | 277 JabberStream *js = gc->proto_data; |
6764 | 278 |
7014 | 279 if(!g_list_find(gaim_connections_get_all(), gc)) { |
6764 | 280 gaim_ssl_close(gsc); |
281 return; | |
282 } | |
283 | |
7014 | 284 js->gsc = gsc; |
6764 | 285 |
7014 | 286 if(js->state == JABBER_STREAM_CONNECTING) |
7642 | 287 jabber_send_raw(js, "<?xml version='1.0' ?>", -1); |
6764 | 288 |
7014 | 289 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING); |
290 gaim_ssl_input_add(gsc, jabber_recv_cb_ssl, gc); | |
6764 | 291 } |
292 | |
7014 | 293 |
294 static void | |
295 jabber_login_callback(gpointer data, gint source, GaimInputCondition cond) | |
6764 | 296 { |
5572 | 297 GaimConnection *gc = data; |
7014 | 298 JabberStream *js = gc->proto_data; |
2086 | 299 |
8783 | 300 if (source < 0) { |
301 gaim_connection_error(gc, _("Couldn't connect to host")); | |
302 return; | |
303 } | |
304 | |
7014 | 305 if(!g_list_find(gaim_connections_get_all(), gc)) { |
2086 | 306 close(source); |
307 return; | |
308 } | |
309 | |
7014 | 310 js->fd = source; |
2956 | 311 |
7014 | 312 if(js->state == JABBER_STREAM_CONNECTING) |
7642 | 313 jabber_send_raw(js, "<?xml version='1.0' ?>", -1); |
2300
d2686f757d6e
[gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
314 |
7014 | 315 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING); |
316 gc->inpa = gaim_input_add(js->fd, GAIM_INPUT_READ, jabber_recv_cb, gc); | |
317 } | |
2086 | 318 |
7014 | 319 static void |
7426 | 320 jabber_ssl_connect_failure(GaimSslConnection *gsc, GaimSslErrorType error, |
321 gpointer data) | |
322 { | |
323 GaimConnection *gc = data; | |
8360 | 324 JabberStream *js = gc->proto_data; |
7426 | 325 |
326 switch(error) { | |
8362 | 327 case GAIM_SSL_CONNECT_FAILED: |
328 gaim_connection_error(gc, _("Connection Failed")); | |
329 break; | |
7426 | 330 case GAIM_SSL_HANDSHAKE_FAILED: |
331 gaim_connection_error(gc, _("SSL Handshake Failed")); | |
332 break; | |
333 } | |
8360 | 334 |
335 js->gsc = NULL; | |
7426 | 336 } |
337 | |
7427 | 338 static void tls_init(JabberStream *js) |
339 { | |
340 gaim_input_remove(js->gc->inpa); | |
341 js->gc->inpa = 0; | |
342 js->gsc = gaim_ssl_connect_fd(js->gc->account, js->fd, | |
343 jabber_login_callback_ssl, jabber_ssl_connect_failure, js->gc); | |
344 } | |
345 | |
346 | |
7426 | 347 static void |
10401 | 348 jabber_login(GaimAccount *account, GaimStatus *status) |
2086 | 349 { |
7014 | 350 int rc; |
351 GaimConnection *gc = gaim_account_get_connection(account); | |
352 const char *connect_server = gaim_account_get_string(account, | |
353 "connect_server", ""); | |
5572 | 354 const char *server; |
7014 | 355 JabberStream *js; |
10289 | 356 JabberBuddy *my_jb = NULL; |
2086 | 357 |
7014 | 358 gc->flags |= GAIM_CONNECTION_HTML; |
359 js = gc->proto_data = g_new0(JabberStream, 1); | |
360 js->gc = gc; | |
8013 | 361 js->fd = -1; |
8312 | 362 js->iq_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, |
363 g_free, g_free); | |
364 js->disco_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, | |
7395 | 365 g_free, g_free); |
7014 | 366 js->buddies = g_hash_table_new_full(g_str_hash, g_str_equal, |
7116 | 367 g_free, (GDestroyNotify)jabber_buddy_free); |
7014 | 368 js->chats = g_hash_table_new_full(g_str_hash, g_str_equal, |
8396 | 369 g_free, (GDestroyNotify)jabber_chat_free); |
8043 | 370 js->chat_servers = g_list_append(NULL, g_strdup("conference.jabber.org")); |
7014 | 371 js->user = jabber_id_new(gaim_account_get_username(account)); |
7322 | 372 js->next_id = g_random_int(); |
5613 | 373 |
7310 | 374 if(!js->user) { |
375 gaim_connection_error(gc, _("Invalid Jabber ID")); | |
376 return; | |
377 } | |
378 | |
7147 | 379 if(!js->user->resource) { |
380 char *me; | |
381 js->user->resource = g_strdup("Gaim"); | |
382 if(!js->user->node) { | |
383 js->user->node = js->user->domain; | |
384 js->user->domain = g_strdup("jabber.org"); | |
385 } | |
386 me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, | |
387 js->user->resource); | |
388 gaim_account_set_username(account, me); | |
389 g_free(me); | |
7145 | 390 } |
391 | |
10289 | 392 if((my_jb = jabber_buddy_find(js, gaim_account_get_username(account), TRUE))) |
393 my_jb->subscription |= JABBER_SUB_BOTH; | |
394 | |
7014 | 395 server = connect_server[0] ? connect_server : js->user->domain; |
2086 | 396 |
7014 | 397 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING); |
2956 | 398 |
7630 | 399 |
400 if(gaim_account_get_bool(account, "old_ssl", FALSE)) { | |
401 if(gaim_ssl_is_supported()) { | |
402 js->gsc = gaim_ssl_connect(account, server, | |
403 gaim_account_get_int(account, "port", 5222), | |
404 jabber_login_callback_ssl, jabber_ssl_connect_failure, gc); | |
405 } else { | |
406 gaim_connection_error(gc, _("SSL support unavailable")); | |
407 } | |
3311 | 408 } |
3770 | 409 |
7014 | 410 if(!js->gsc) { |
411 rc = gaim_proxy_connect(account, server, | |
412 gaim_account_get_int(account, "port", 5222), | |
413 jabber_login_callback, gc); | |
2086 | 414 |
7014 | 415 if (rc != 0) |
416 gaim_connection_error(gc, _("Unable to create socket")); | |
2956 | 417 } |
2086 | 418 } |
419 | |
7072 | 420 static gboolean |
421 conn_close_cb(gpointer data) | |
422 { | |
423 JabberStream *js = data; | |
424 gaim_connection_destroy(js->gc); | |
425 return FALSE; | |
426 } | |
427 | |
428 static void | |
429 jabber_connection_schedule_close(JabberStream *js) | |
430 { | |
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8194
diff
changeset
|
431 gaim_timeout_add(0, conn_close_cb, js); |
7072 | 432 } |
433 | |
434 static void | |
7395 | 435 jabber_registration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
7072 | 436 { |
437 const char *type = xmlnode_get_attrib(packet, "type"); | |
438 char *buf; | |
439 | |
440 if(!strcmp(type, "result")) { | |
441 buf = g_strdup_printf(_("Registration of %s@%s successful"), | |
442 js->user->node, js->user->domain); | |
443 gaim_notify_info(NULL, _("Registration Successful"), | |
444 _("Registration Successful"), buf); | |
445 g_free(buf); | |
446 } else { | |
8401 | 447 char *msg = jabber_parse_error(js, packet); |
7072 | 448 |
8401 | 449 if(!msg) |
450 msg = g_strdup(_("Unknown Error")); | |
7072 | 451 |
452 gaim_notify_error(NULL, _("Registration Failed"), | |
8401 | 453 _("Registration Failed"), msg); |
454 g_free(msg); | |
7072 | 455 } |
456 jabber_connection_schedule_close(js); | |
457 } | |
458 | |
459 static void | |
460 jabber_register_cb(JabberStream *js, GaimRequestFields *fields) | |
461 { | |
462 GList *groups, *flds; | |
463 xmlnode *query, *y; | |
464 JabberIq *iq; | |
7264 | 465 char *username; |
7072 | 466 |
467 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
468 query = xmlnode_get_child(iq->node, "query"); | |
469 | |
470 for(groups = gaim_request_fields_get_groups(fields); groups; | |
471 groups = groups->next) { | |
472 for(flds = gaim_request_field_group_get_fields(groups->data); | |
473 flds; flds = flds->next) { | |
474 GaimRequestField *field = flds->data; | |
475 const char *id = gaim_request_field_get_id(field); | |
476 const char *value = gaim_request_field_string_get_value(field); | |
477 | |
478 if(!strcmp(id, "username")) { | |
479 y = xmlnode_new_child(query, "username"); | |
480 } else if(!strcmp(id, "password")) { | |
481 y = xmlnode_new_child(query, "password"); | |
482 } else if(!strcmp(id, "name")) { | |
483 y = xmlnode_new_child(query, "name"); | |
484 } else if(!strcmp(id, "email")) { | |
485 y = xmlnode_new_child(query, "email"); | |
486 } else if(!strcmp(id, "nick")) { | |
487 y = xmlnode_new_child(query, "nick"); | |
488 } else if(!strcmp(id, "first")) { | |
489 y = xmlnode_new_child(query, "first"); | |
490 } else if(!strcmp(id, "last")) { | |
491 y = xmlnode_new_child(query, "last"); | |
492 } else if(!strcmp(id, "address")) { | |
493 y = xmlnode_new_child(query, "address"); | |
494 } else if(!strcmp(id, "city")) { | |
495 y = xmlnode_new_child(query, "city"); | |
496 } else if(!strcmp(id, "state")) { | |
497 y = xmlnode_new_child(query, "state"); | |
498 } else if(!strcmp(id, "zip")) { | |
499 y = xmlnode_new_child(query, "zip"); | |
500 } else if(!strcmp(id, "phone")) { | |
501 y = xmlnode_new_child(query, "phone"); | |
502 } else if(!strcmp(id, "url")) { | |
503 y = xmlnode_new_child(query, "url"); | |
504 } else if(!strcmp(id, "date")) { | |
505 y = xmlnode_new_child(query, "date"); | |
506 } else { | |
507 continue; | |
508 } | |
509 xmlnode_insert_data(y, value, -1); | |
7264 | 510 if(!strcmp(id, "username")) { |
511 if(js->user->node) | |
512 g_free(js->user->node); | |
513 js->user->node = g_strdup(value); | |
514 } | |
7072 | 515 } |
516 } | |
517 | |
7264 | 518 username = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, |
519 js->user->resource); | |
520 gaim_account_set_username(js->gc->account, username); | |
521 g_free(username); | |
522 | |
7395 | 523 jabber_iq_set_callback(iq, jabber_registration_result_cb, NULL); |
7072 | 524 |
525 jabber_iq_send(iq); | |
526 | |
527 } | |
528 | |
529 static void | |
530 jabber_register_cancel_cb(JabberStream *js, GaimRequestFields *fields) | |
531 { | |
532 jabber_connection_schedule_close(js); | |
533 } | |
534 | |
7923 | 535 static void jabber_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) |
536 { | |
537 xmlnode *query; | |
538 JabberIq *iq; | |
539 | |
540 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
541 query = xmlnode_get_child(iq->node, "query"); | |
542 | |
543 xmlnode_insert_child(query, result); | |
544 | |
545 jabber_iq_set_callback(iq, jabber_registration_result_cb, NULL); | |
546 jabber_iq_send(iq); | |
547 } | |
548 | |
7072 | 549 void jabber_register_parse(JabberStream *js, xmlnode *packet) |
550 { | |
551 if(js->registration) { | |
552 GaimRequestFields *fields; | |
553 GaimRequestFieldGroup *group; | |
554 GaimRequestField *field; | |
7923 | 555 xmlnode *query, *x, *y; |
7072 | 556 char *instructions; |
557 | |
558 /* get rid of the login thingy */ | |
559 gaim_connection_set_state(js->gc, GAIM_CONNECTED); | |
560 | |
561 query = xmlnode_get_child(packet, "query"); | |
562 | |
563 if(xmlnode_get_child(query, "registered")) { | |
564 gaim_notify_error(NULL, _("Already Registered"), | |
565 _("Already Registered"), NULL); | |
566 jabber_connection_schedule_close(js); | |
567 return; | |
568 } | |
569 | |
8398 | 570 if((x = xmlnode_get_child_with_namespace(packet, "x", |
571 "jabber:x:data"))) { | |
572 jabber_x_data_request(js, x, jabber_register_x_data_cb, NULL); | |
573 return; | |
574 } else if((x = xmlnode_get_child_with_namespace(packet, "x", | |
575 "jabber:x:oob"))) { | |
576 xmlnode *url; | |
7923 | 577 |
8398 | 578 if((url = xmlnode_get_child(x, "url"))) { |
579 char *href; | |
580 if((href = xmlnode_get_data(url))) { | |
10240
95ca0db2d01d
[gaim-migrate @ 11377]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10216
diff
changeset
|
581 gaim_notify_uri(NULL, href); |
8398 | 582 g_free(href); |
583 js->gc->wants_to_die = TRUE; | |
584 jabber_connection_schedule_close(js); | |
585 return; | |
586 } | |
7923 | 587 } |
588 } | |
589 | |
590 /* as a last resort, use the old jabber:iq:register syntax */ | |
591 | |
7072 | 592 fields = gaim_request_fields_new(); |
593 group = gaim_request_field_group_new(NULL); | |
594 gaim_request_fields_add_group(fields, group); | |
595 | |
596 field = gaim_request_field_string_new("username", _("Username"), | |
597 js->user->node, FALSE); | |
598 gaim_request_field_group_add_field(group, field); | |
599 | |
600 field = gaim_request_field_string_new("password", _("Password"), | |
601 gaim_account_get_password(js->gc->account), FALSE); | |
602 gaim_request_field_string_set_masked(field, TRUE); | |
603 gaim_request_field_group_add_field(group, field); | |
604 | |
605 if(xmlnode_get_child(query, "name")) { | |
606 field = gaim_request_field_string_new("name", _("Name"), | |
607 gaim_account_get_alias(js->gc->account), FALSE); | |
608 gaim_request_field_group_add_field(group, field); | |
609 } | |
610 if(xmlnode_get_child(query, "email")) { | |
611 field = gaim_request_field_string_new("email", _("E-Mail"), | |
612 NULL, FALSE); | |
613 gaim_request_field_group_add_field(group, field); | |
614 } | |
615 if(xmlnode_get_child(query, "nick")) { | |
616 field = gaim_request_field_string_new("nick", _("Nickname"), | |
617 NULL, FALSE); | |
618 gaim_request_field_group_add_field(group, field); | |
619 } | |
620 if(xmlnode_get_child(query, "first")) { | |
621 field = gaim_request_field_string_new("first", _("First Name"), | |
622 NULL, FALSE); | |
623 gaim_request_field_group_add_field(group, field); | |
624 } | |
625 if(xmlnode_get_child(query, "last")) { | |
626 field = gaim_request_field_string_new("last", _("Last Name"), | |
627 NULL, FALSE); | |
628 gaim_request_field_group_add_field(group, field); | |
629 } | |
630 if(xmlnode_get_child(query, "address")) { | |
631 field = gaim_request_field_string_new("address", _("Address"), | |
632 NULL, FALSE); | |
633 gaim_request_field_group_add_field(group, field); | |
634 } | |
635 if(xmlnode_get_child(query, "city")) { | |
636 field = gaim_request_field_string_new("city", _("City"), | |
637 NULL, FALSE); | |
638 gaim_request_field_group_add_field(group, field); | |
639 } | |
640 if(xmlnode_get_child(query, "state")) { | |
641 field = gaim_request_field_string_new("state", _("State"), | |
642 NULL, FALSE); | |
643 gaim_request_field_group_add_field(group, field); | |
644 } | |
645 if(xmlnode_get_child(query, "zip")) { | |
646 field = gaim_request_field_string_new("zip", _("Postal Code"), | |
647 NULL, FALSE); | |
648 gaim_request_field_group_add_field(group, field); | |
649 } | |
650 if(xmlnode_get_child(query, "phone")) { | |
651 field = gaim_request_field_string_new("phone", _("Phone"), | |
652 NULL, FALSE); | |
653 gaim_request_field_group_add_field(group, field); | |
654 } | |
655 if(xmlnode_get_child(query, "url")) { | |
656 field = gaim_request_field_string_new("url", _("URL"), | |
657 NULL, FALSE); | |
658 gaim_request_field_group_add_field(group, field); | |
659 } | |
660 if(xmlnode_get_child(query, "date")) { | |
661 field = gaim_request_field_string_new("date", _("Date"), | |
662 NULL, FALSE); | |
663 gaim_request_field_group_add_field(group, field); | |
664 } | |
665 | |
666 if((y = xmlnode_get_child(query, "instructions"))) | |
667 instructions = xmlnode_get_data(y); | |
668 else | |
669 instructions = g_strdup(_("Please fill out the information below " | |
670 "to register your new account.")); | |
671 | |
672 gaim_request_fields(js->gc, _("Register New Jabber Account"), | |
673 _("Register New Jabber Account"), instructions, fields, | |
674 _("Register"), G_CALLBACK(jabber_register_cb), | |
675 _("Cancel"), G_CALLBACK(jabber_register_cancel_cb), js); | |
676 } | |
677 } | |
678 | |
8016 | 679 void jabber_register_start(JabberStream *js) |
7072 | 680 { |
681 JabberIq *iq; | |
682 | |
683 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:register"); | |
684 jabber_iq_send(iq); | |
685 } | |
686 | |
687 static void jabber_register_account(GaimAccount *account) | |
688 { | |
689 GaimConnection *gc = gaim_account_get_connection(account); | |
690 JabberStream *js; | |
10289 | 691 JabberBuddy *my_jb = NULL; |
7072 | 692 const char *connect_server = gaim_account_get_string(account, |
693 "connect_server", ""); | |
694 const char *server; | |
695 int rc; | |
696 | |
697 js = gc->proto_data = g_new0(JabberStream, 1); | |
698 js->gc = gc; | |
699 js->registration = TRUE; | |
8312 | 700 js->iq_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, |
701 g_free, g_free); | |
702 js->disco_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, | |
7395 | 703 g_free, g_free); |
7072 | 704 js->user = jabber_id_new(gaim_account_get_username(account)); |
7322 | 705 js->next_id = g_random_int(); |
7072 | 706 |
7310 | 707 if(!js->user) { |
708 gaim_connection_error(gc, _("Invalid Jabber ID")); | |
709 return; | |
710 } | |
711 | |
7147 | 712 if(!js->user->resource) { |
713 char *me; | |
714 js->user->resource = g_strdup("Gaim"); | |
715 if(!js->user->node) { | |
716 js->user->node = js->user->domain; | |
717 js->user->domain = g_strdup("jabber.org"); | |
718 } | |
719 me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, | |
720 js->user->resource); | |
721 gaim_account_set_username(account, me); | |
722 g_free(me); | |
723 } | |
724 | |
10289 | 725 if((my_jb = jabber_buddy_find(js, gaim_account_get_username(account), TRUE))) |
726 my_jb->subscription |= JABBER_SUB_BOTH; | |
727 | |
7072 | 728 server = connect_server[0] ? connect_server : js->user->domain; |
729 | |
730 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING); | |
731 | |
7630 | 732 if(gaim_account_get_bool(account, "old_ssl", FALSE)) { |
733 if(gaim_ssl_is_supported()) { | |
734 js->gsc = gaim_ssl_connect(account, server, | |
735 gaim_account_get_int(account, "port", 5222), | |
736 jabber_login_callback_ssl, jabber_ssl_connect_failure, gc); | |
737 } else { | |
738 gaim_connection_error(gc, _("SSL support unavailable")); | |
739 } | |
7072 | 740 } |
741 | |
742 if(!js->gsc) { | |
743 rc = gaim_proxy_connect(account, server, | |
744 gaim_account_get_int(account, "port", 5222), | |
745 jabber_login_callback, gc); | |
746 | |
747 if (rc != 0) | |
748 gaim_connection_error(gc, _("Unable to create socket")); | |
749 } | |
750 } | |
751 | |
5572 | 752 static void jabber_close(GaimConnection *gc) |
2086 | 753 { |
7014 | 754 JabberStream *js = gc->proto_data; |
2956 | 755 |
10216 | 756 jabber_presence_send(gc->account, NULL); |
7642 | 757 jabber_send_raw(js, "</stream:stream>", -1); |
3311 | 758 |
7014 | 759 if(js->gsc) { |
760 gaim_ssl_close(js->gsc); | |
8360 | 761 } else if (js->fd > 0) { |
7072 | 762 if(js->gc->inpa) |
763 gaim_input_remove(js->gc->inpa); | |
7014 | 764 close(js->fd); |
765 } | |
3311 | 766 |
7587 | 767 if(js->context) |
768 g_markup_parse_context_free(js->context); | |
8312 | 769 if(js->iq_callbacks) |
770 g_hash_table_destroy(js->iq_callbacks); | |
771 if(js->disco_callbacks) | |
772 g_hash_table_destroy(js->disco_callbacks); | |
7072 | 773 if(js->buddies) |
774 g_hash_table_destroy(js->buddies); | |
775 if(js->chats) | |
776 g_hash_table_destroy(js->chats); | |
8043 | 777 while(js->chat_servers) { |
778 g_free(js->chat_servers->data); | |
779 js->chat_servers = g_list_delete_link(js->chat_servers, js->chat_servers); | |
780 } | |
7014 | 781 if(js->stream_id) |
782 g_free(js->stream_id); | |
7587 | 783 if(js->user) |
784 jabber_id_free(js->user); | |
10189 | 785 if(js->avatar_hash) |
786 g_free(js->avatar_hash); | |
7014 | 787 g_free(js); |
5093 | 788 } |
789 | |
7014 | 790 void jabber_stream_set_state(JabberStream *js, JabberStreamState state) |
3105 | 791 { |
9954 | 792 GaimPresence *gpresence; |
793 GaimStatus *status; | |
794 | |
7014 | 795 js->state = state; |
796 switch(state) { | |
797 case JABBER_STREAM_OFFLINE: | |
798 break; | |
799 case JABBER_STREAM_CONNECTING: | |
800 gaim_connection_update_progress(js->gc, _("Connecting"), 1, | |
801 JABBER_CONNECT_STEPS); | |
802 break; | |
803 case JABBER_STREAM_INITIALIZING: | |
804 gaim_connection_update_progress(js->gc, _("Initializing Stream"), | |
805 js->gsc ? 5 : 2, JABBER_CONNECT_STEPS); | |
806 jabber_stream_init(js); | |
807 jabber_parser_setup(js); | |
808 break; | |
809 case JABBER_STREAM_AUTHENTICATING: | |
810 gaim_connection_update_progress(js->gc, _("Authenticating"), | |
811 js->gsc ? 6 : 3, JABBER_CONNECT_STEPS); | |
8296 | 812 if(js->protocol_version == JABBER_PROTO_0_9 && js->registration) { |
813 jabber_register_start(js); | |
814 } else if(js->auth_type == JABBER_AUTH_IQ_AUTH) { | |
815 jabber_auth_start_old(js); | |
8016 | 816 } |
7014 | 817 break; |
818 case JABBER_STREAM_REINITIALIZING: | |
819 gaim_connection_update_progress(js->gc, _("Re-initializing Stream"), | |
820 6, JABBER_CONNECT_STEPS); | |
821 jabber_stream_init(js); | |
822 break; | |
823 case JABBER_STREAM_CONNECTED: | |
824 gaim_connection_set_state(js->gc, GAIM_CONNECTED); | |
825 jabber_roster_request(js); | |
9954 | 826 gpresence = gaim_account_get_presence(js->gc->account); |
827 status = gaim_presence_get_active_status(gpresence); | |
10216 | 828 jabber_presence_send(js->gc->account, status); |
8312 | 829 jabber_disco_items_server(js); |
7014 | 830 serv_finish_login(js->gc); |
831 break; | |
3105 | 832 } |
833 } | |
834 | |
7014 | 835 char *jabber_get_next_id(JabberStream *js) |
2086 | 836 { |
7322 | 837 return g_strdup_printf("gaim%x", js->next_id++); |
2086 | 838 } |
839 | |
7923 | 840 |
841 static void jabber_idle_set(GaimConnection *gc, int idle) | |
3340 | 842 { |
7014 | 843 JabberStream *js = gc->proto_data; |
3340 | 844 |
7014 | 845 js->idle = idle ? time(NULL) - idle : idle; |
3314 | 846 } |
847 | |
6695 | 848 static const char *jabber_list_icon(GaimAccount *a, GaimBuddy *b) |
2086 | 849 { |
4687 | 850 return "jabber"; |
851 } | |
4916 | 852 |
9954 | 853 static void jabber_list_emblems(GaimBuddy *b, const char **se, const char **sw, |
854 const char **nw, const char **ne) | |
4916 | 855 { |
7014 | 856 JabberStream *js; |
857 JabberBuddy *jb; | |
858 | |
859 if(!b->account->gc) | |
860 return; | |
861 js = b->account->gc->proto_data; | |
862 jb = jabber_buddy_find(js, b->name, FALSE); | |
5135 | 863 |
864 if(!GAIM_BUDDY_IS_ONLINE(b)) { | |
7014 | 865 if(jb && jb->error_msg) |
4927 | 866 *nw = "error"; |
5135 | 867 |
7014 | 868 if(jb && (jb->subscription & JABBER_SUB_PENDING || |
869 !(jb->subscription & JABBER_SUB_TO))) | |
5135 | 870 *se = "notauthorized"; |
871 else | |
872 *se = "offline"; | |
4916 | 873 } else { |
9954 | 874 GaimStatusType *status_type = gaim_status_get_type(gaim_presence_get_active_status(gaim_buddy_get_presence(b))); |
875 | |
876 if(gaim_status_type_get_primitive(status_type) > GAIM_STATUS_ONLINE) { | |
877 *se = gaim_status_type_get_id(status_type); | |
878 if(!strcmp(*se, "xa")) | |
7014 | 879 *se = "extendedaway"; |
4916 | 880 } |
2086 | 881 } |
4916 | 882 } |
2086 | 883 |
7014 | 884 static char *jabber_status_text(GaimBuddy *b) |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
885 { |
7014 | 886 JabberBuddy *jb = jabber_buddy_find(b->account->gc->proto_data, b->name, |
887 FALSE); | |
888 char *ret = NULL; | |
5234 | 889 |
7014 | 890 if(jb && !GAIM_BUDDY_IS_ONLINE(b) && (jb->subscription & JABBER_SUB_PENDING || !(jb->subscription & JABBER_SUB_TO))) { |
891 ret = g_strdup(_("Not Authorized")); | |
892 } else if(jb && !GAIM_BUDDY_IS_ONLINE(b) && jb->error_msg) { | |
893 ret = g_strdup(jb->error_msg); | |
2956 | 894 } else { |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7072
diff
changeset
|
895 char *stripped; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7072
diff
changeset
|
896 |
9954 | 897 if(!(stripped = gaim_markup_strip_html(jabber_buddy_get_status_msg(jb)))) { |
898 GaimStatus *status = gaim_presence_get_active_status(gaim_buddy_get_presence(b)); | |
2956 | 899 |
9954 | 900 if(!gaim_status_is_available(status)) |
901 stripped = g_strdup(gaim_status_get_name(status)); | |
902 } | |
2086 | 903 |
7014 | 904 if(stripped) { |
905 ret = g_markup_escape_text(stripped, -1); | |
906 g_free(stripped); | |
907 } | |
2086 | 908 } |
909 | |
7014 | 910 return ret; |
2956 | 911 } |
912 | |
6695 | 913 static char *jabber_tooltip_text(GaimBuddy *b) |
4744 | 914 { |
7014 | 915 JabberBuddy *jb = jabber_buddy_find(b->account->gc->proto_data, b->name, |
916 FALSE); | |
8194 | 917 GString *ret = g_string_new(""); |
7014 | 918 |
8194 | 919 if(jb) { |
920 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, NULL); | |
921 const char *sub; | |
922 if(jb->subscription & JABBER_SUB_FROM) { | |
923 if(jb->subscription & JABBER_SUB_TO) | |
924 sub = _("Both"); | |
925 else if(jb->subscription & JABBER_SUB_PENDING) | |
926 sub = _("From (To pending)"); | |
927 else | |
928 sub = _("From"); | |
929 } else { | |
930 if(jb->subscription & JABBER_SUB_TO) | |
931 sub = _("To"); | |
932 else if(jb->subscription & JABBER_SUB_PENDING) | |
933 sub = _("None (To pending)"); | |
934 else | |
935 sub = _("None"); | |
936 } | |
8591 | 937 g_string_append_printf(ret, "\n<b>%s:</b> %s", _("Subscription"), sub); |
8194 | 938 |
939 if(jbr) { | |
940 char *text = NULL; | |
941 if(jbr->status) { | |
942 char *stripped; | |
943 stripped = gaim_markup_strip_html(jbr->status); | |
944 text = g_markup_escape_text(stripped, -1); | |
945 g_free(stripped); | |
946 } | |
947 | |
8591 | 948 g_string_append_printf(ret, "\n<b>%s:</b> %s%s%s", |
8194 | 949 _("Status"), |
9954 | 950 jabber_buddy_state_get_name(jbr->state), |
8194 | 951 text ? ": " : "", |
952 text ? text : ""); | |
953 if(text) | |
954 g_free(text); | |
955 } else if(!GAIM_BUDDY_IS_ONLINE(b) && jb->error_msg) { | |
8591 | 956 g_string_append_printf(ret, "\n<b>%s:</b> %s", |
8194 | 957 _("Error"), jb->error_msg); |
958 } | |
4745 | 959 } |
4744 | 960 |
8591 | 961 return g_string_free(ret, FALSE); |
4732 | 962 } |
963 | |
9954 | 964 static GList *jabber_status_types(GaimAccount *account) |
7014 | 965 { |
9954 | 966 GaimStatusType *type; |
967 GList *types = NULL; | |
968 | |
9980 | 969 type = gaim_status_type_new_with_attrs(GAIM_STATUS_OFFLINE, "offline", |
970 _("Offline"), FALSE, TRUE, FALSE, "message", _("Message"), | |
971 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
9954 | 972 types = g_list_append(types, type); |
973 | |
9980 | 974 type = gaim_status_type_new_with_attrs(GAIM_STATUS_ONLINE, "online", |
975 _("Online"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
976 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), | |
977 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
978 types = g_list_append(types, type); | |
979 | |
980 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE, "chat", | |
981 _("Chatty"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
982 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), | |
983 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
9954 | 984 types = g_list_append(types, type); |
2086 | 985 |
9980 | 986 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY, "away", |
987 _("Away"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
988 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), | |
989 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
9954 | 990 types = g_list_append(types, type); |
991 | |
9980 | 992 type = gaim_status_type_new_with_attrs(GAIM_STATUS_EXTENDED_AWAY, "xa", |
993 _("Extended Away"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
994 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), | |
995 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
9954 | 996 types = g_list_append(types, type); |
997 | |
9980 | 998 type = gaim_status_type_new_with_attrs(GAIM_STATUS_UNAVAILABLE, "dnd", |
999 _("Do Not Disturb"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
1000 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), | |
1001 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
9954 | 1002 types = g_list_append(types, type); |
1003 | |
1004 /* | |
8166 | 1005 if(js->protocol_version == JABBER_PROTO_0_9) |
1006 m = g_list_append(m, _("Invisible")); | |
10009 | 1007 */ |
2086 | 1008 |
9954 | 1009 return types; |
2086 | 1010 } |
1011 | |
7395 | 1012 static void |
1013 jabber_password_change_result_cb(JabberStream *js, xmlnode *packet, | |
1014 gpointer data) | |
7124 | 1015 { |
1016 const char *type; | |
1017 | |
1018 type = xmlnode_get_attrib(packet, "type"); | |
1019 | |
9414 | 1020 if(type && !strcmp(type, "result")) { |
7124 | 1021 gaim_notify_info(js->gc, _("Password Changed"), _("Password Changed"), |
1022 _("Your password has been changed.")); | |
1023 } else { | |
8401 | 1024 char *msg = jabber_parse_error(js, packet); |
7124 | 1025 |
8401 | 1026 gaim_notify_error(js->gc, _("Error changing password"), |
1027 _("Error changing password"), msg); | |
1028 g_free(msg); | |
7124 | 1029 } |
1030 } | |
1031 | |
1032 static void jabber_password_change_cb(JabberStream *js, | |
1033 GaimRequestFields *fields) | |
1034 { | |
1035 const char *p1, *p2; | |
1036 JabberIq *iq; | |
1037 xmlnode *query, *y; | |
1038 | |
1039 p1 = gaim_request_fields_get_string(fields, "password1"); | |
1040 p2 = gaim_request_fields_get_string(fields, "password2"); | |
1041 | |
1042 if(strcmp(p1, p2)) { | |
1043 gaim_notify_error(js->gc, NULL, _("New passwords do not match."), NULL); | |
1044 return; | |
1045 } | |
1046 | |
1047 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
1048 | |
1049 xmlnode_set_attrib(iq->node, "to", js->user->domain); | |
1050 | |
1051 query = xmlnode_get_child(iq->node, "query"); | |
1052 | |
1053 y = xmlnode_new_child(query, "username"); | |
1054 xmlnode_insert_data(y, js->user->node, -1); | |
1055 y = xmlnode_new_child(query, "password"); | |
1056 xmlnode_insert_data(y, p1, -1); | |
1057 | |
7395 | 1058 jabber_iq_set_callback(iq, jabber_password_change_result_cb, NULL); |
7124 | 1059 |
1060 jabber_iq_send(iq); | |
1061 | |
1062 gaim_account_set_password(js->gc->account, p1); | |
1063 } | |
1064 | |
9015 | 1065 static void jabber_password_change(GaimPluginAction *action) |
7124 | 1066 { |
9015 | 1067 |
1068 GaimConnection *gc = (GaimConnection *) action->context; | |
7124 | 1069 JabberStream *js = gc->proto_data; |
1070 GaimRequestFields *fields; | |
1071 GaimRequestFieldGroup *group; | |
1072 GaimRequestField *field; | |
1073 | |
1074 fields = gaim_request_fields_new(); | |
1075 group = gaim_request_field_group_new(NULL); | |
1076 gaim_request_fields_add_group(fields, group); | |
1077 | |
1078 field = gaim_request_field_string_new("password1", _("Password"), | |
1079 "", FALSE); | |
1080 gaim_request_field_string_set_masked(field, TRUE); | |
1081 gaim_request_field_group_add_field(group, field); | |
1082 | |
1083 field = gaim_request_field_string_new("password2", _("Password (again)"), | |
1084 "", FALSE); | |
1085 gaim_request_field_string_set_masked(field, TRUE); | |
1086 gaim_request_field_group_add_field(group, field); | |
1087 | |
1088 gaim_request_fields(js->gc, _("Change Jabber Password"), | |
1089 _("Change Jabber Password"), _("Please enter your new password"), | |
1090 fields, _("OK"), G_CALLBACK(jabber_password_change_cb), | |
1091 _("Cancel"), NULL, js); | |
1092 } | |
1093 | |
9015 | 1094 static GList *jabber_actions(GaimPlugin *plugin, gpointer context) |
2956 | 1095 { |
1096 GList *m = NULL; | |
9015 | 1097 GaimPluginAction *act; |
4333 | 1098 |
9015 | 1099 act = gaim_plugin_action_new(_("Set User Info"), |
1100 jabber_setup_set_info); | |
1101 m = g_list_append(m, act); | |
4333 | 1102 |
8296 | 1103 /* if (js->protocol_options & CHANGE_PASSWORD) { */ |
9015 | 1104 act = gaim_plugin_action_new(_("Change Password"), |
1105 jabber_password_change); | |
1106 m = g_list_append(m, act); | |
8296 | 1107 /* } */ |
2956 | 1108 |
1109 return m; | |
1110 } | |
1111 | |
7999 | 1112 static GaimChat *jabber_find_blist_chat(GaimAccount *account, const char *name) |
1113 { | |
1114 GaimBlistNode *gnode, *cnode; | |
1115 JabberID *jid; | |
1116 | |
1117 if(!(jid = jabber_id_new(name))) | |
1118 return NULL; | |
1119 | |
1120 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { | |
1121 for(cnode = gnode->child; cnode; cnode = cnode->next) { | |
1122 GaimChat *chat = (GaimChat*)cnode; | |
1123 const char *room, *server; | |
1124 if(!GAIM_BLIST_NODE_IS_CHAT(cnode)) | |
1125 continue; | |
1126 | |
1127 if(chat->account != account) | |
8011 | 1128 continue; |
7999 | 1129 |
1130 if(!(room = g_hash_table_lookup(chat->components, "room"))) | |
1131 continue; | |
1132 if(!(server = g_hash_table_lookup(chat->components, "server"))) | |
1133 continue; | |
1134 | |
8158 | 1135 if(jid->node && jid->domain && |
1136 !g_utf8_collate(room, jid->node) && !g_utf8_collate(server, jid->domain)) { | |
7999 | 1137 jabber_id_free(jid); |
1138 return chat; | |
1139 } | |
1140 } | |
1141 } | |
1142 jabber_id_free(jid); | |
1143 return NULL; | |
1144 } | |
1145 | |
8400 | 1146 static void jabber_convo_closed(GaimConnection *gc, const char *who) |
1147 { | |
1148 JabberStream *js = gc->proto_data; | |
1149 JabberID *jid; | |
1150 JabberBuddy *jb; | |
1151 JabberBuddyResource *jbr; | |
1152 | |
1153 if(!(jid = jabber_id_new(who))) | |
1154 return; | |
1155 | |
1156 if((jb = jabber_buddy_find(js, who, TRUE)) && | |
1157 (jbr = jabber_buddy_find_resource(jb, jid->resource))) { | |
1158 if(jbr->thread_id) { | |
1159 g_free(jbr->thread_id); | |
1160 jbr->thread_id = NULL; | |
1161 } | |
1162 } | |
1163 | |
1164 jabber_id_free(jid); | |
1165 } | |
1166 | |
8401 | 1167 |
1168 char *jabber_parse_error(JabberStream *js, xmlnode *packet) | |
1169 { | |
1170 xmlnode *error; | |
1171 const char *code = NULL, *text = NULL; | |
1172 const char *xmlns = xmlnode_get_attrib(packet, "xmlns"); | |
1173 char *cdata = NULL; | |
1174 | |
1175 if((error = xmlnode_get_child(packet, "error"))) { | |
1176 cdata = xmlnode_get_data(error); | |
1177 code = xmlnode_get_attrib(error, "code"); | |
1178 | |
1179 /* Stanza errors */ | |
1180 if(xmlnode_get_child(error, "bad-request")) { | |
1181 text = _("Bad Request"); | |
1182 } else if(xmlnode_get_child(error, "conflict")) { | |
1183 text = _("Conflict"); | |
1184 } else if(xmlnode_get_child(error, "feature-not-implemented")) { | |
1185 text = _("Feature Not Implemented"); | |
1186 } else if(xmlnode_get_child(error, "forbidden")) { | |
1187 text = _("Forbidden"); | |
1188 } else if(xmlnode_get_child(error, "gone")) { | |
1189 text = _("Gone"); | |
1190 } else if(xmlnode_get_child(error, "internal-server-error")) { | |
1191 text = _("Internal Server Error"); | |
1192 } else if(xmlnode_get_child(error, "item-not-found")) { | |
1193 text = _("Item Not Found"); | |
1194 } else if(xmlnode_get_child(error, "jid-malformed")) { | |
1195 text = _("Malformed Jabber ID"); | |
1196 } else if(xmlnode_get_child(error, "not-acceptable")) { | |
1197 text = _("Not Acceptable"); | |
1198 } else if(xmlnode_get_child(error, "not-allowed")) { | |
1199 text = _("Not Allowed"); | |
1200 } else if(xmlnode_get_child(error, "not-authorized")) { | |
1201 text = _("Not Authorized"); | |
1202 } else if(xmlnode_get_child(error, "payment-required")) { | |
1203 text = _("Payment Required"); | |
1204 } else if(xmlnode_get_child(error, "recipient-unavailable")) { | |
1205 text = _("Recipient Unavailable"); | |
1206 } else if(xmlnode_get_child(error, "redirect")) { | |
1207 /* XXX */ | |
1208 } else if(xmlnode_get_child(error, "registration-required")) { | |
1209 text = _("Registration Required"); | |
1210 } else if(xmlnode_get_child(error, "remote-server-not-found")) { | |
1211 text = _("Remote Server Not Found"); | |
1212 } else if(xmlnode_get_child(error, "remote-server-timeout")) { | |
1213 text = _("Remote Server Timeout"); | |
1214 } else if(xmlnode_get_child(error, "resource-constraint")) { | |
1215 text = _("Server Overloaded"); | |
1216 } else if(xmlnode_get_child(error, "service-unavailable")) { | |
1217 text = _("Service Unavailable"); | |
1218 } else if(xmlnode_get_child(error, "subscription-required")) { | |
1219 text = _("Subscription Required"); | |
1220 } else if(xmlnode_get_child(error, "unexpected-request")) { | |
1221 text = _("Unexpected Request"); | |
1222 } else if(xmlnode_get_child(error, "undefined-condition")) { | |
1223 text = _("Unknown Error"); | |
1224 } | |
1225 } else if(xmlns && !strcmp(xmlns, "urn:ietf:params:xml:ns:xmpp-sasl")) { | |
1226 if(xmlnode_get_child(packet, "aborted")) { | |
1227 js->gc->wants_to_die = TRUE; | |
1228 text = _("Authorization Aborted"); | |
1229 } else if(xmlnode_get_child(error, "incorrect-encoding")) { | |
1230 text = _("Incorrect encoding in authorization"); | |
1231 } else if(xmlnode_get_child(error, "invalid-authzid")) { | |
1232 js->gc->wants_to_die = TRUE; | |
1233 text = _("Invalid authzid"); | |
1234 } else if(xmlnode_get_child(error, "invalid-mechanism")) { | |
1235 js->gc->wants_to_die = TRUE; | |
1236 text = _("Invalid Authorization Mechanism"); | |
1237 } else if(xmlnode_get_child(error, "mechanism-too-weak")) { | |
1238 js->gc->wants_to_die = TRUE; | |
1239 text = _("Authorization mechanism too weak"); | |
1240 } else if(xmlnode_get_child(error, "not-authorized")) { | |
1241 js->gc->wants_to_die = TRUE; | |
1242 text = _("Not Authorized"); | |
1243 } else if(xmlnode_get_child(error, "temporary-auth-failure")) { | |
1244 text = _("Temporary Authentication Failure"); | |
1245 } else { | |
1246 text = _("Authentication Failure"); | |
1247 } | |
8402 | 1248 } else if(!strcmp(packet->name, "stream:error")) { |
1249 if(xmlnode_get_child(packet, "bad-format")) { | |
1250 text = _("Bad Format"); | |
1251 } else if(xmlnode_get_child(packet, "bad-namespace-prefix")) { | |
1252 text = _("Bad Namespace Prefix"); | |
1253 } else if(xmlnode_get_child(packet, "conflict")) { | |
1254 js->gc->wants_to_die = TRUE; | |
1255 text = _("Resource Conflict"); | |
1256 } else if(xmlnode_get_child(packet, "connection-timeout")) { | |
1257 text = _("Connection Timeout"); | |
1258 } else if(xmlnode_get_child(packet, "host-gone")) { | |
1259 text = _("Host Gone"); | |
1260 } else if(xmlnode_get_child(packet, "host-unknown")) { | |
1261 text = _("Host Unknown"); | |
1262 } else if(xmlnode_get_child(packet, "improper-addressing")) { | |
1263 text = _("Improper Addressing"); | |
1264 } else if(xmlnode_get_child(packet, "internal-server-error")) { | |
1265 text = _("Internal Server Error"); | |
1266 } else if(xmlnode_get_child(packet, "invalid-id")) { | |
1267 text = _("Invalid ID"); | |
1268 } else if(xmlnode_get_child(packet, "invalid-namespace")) { | |
1269 text = _("Invalid Namespace"); | |
1270 } else if(xmlnode_get_child(packet, "invalid-xml")) { | |
1271 text = _("Invalid XML"); | |
1272 } else if(xmlnode_get_child(packet, "nonmatching-hosts")) { | |
1273 text = _("Non-matching Hosts"); | |
1274 } else if(xmlnode_get_child(packet, "not-authorized")) { | |
1275 text = _("Not Authorized"); | |
1276 } else if(xmlnode_get_child(packet, "policy-violation")) { | |
1277 text = _("Policy Violation"); | |
1278 } else if(xmlnode_get_child(packet, "remote-connection-failed")) { | |
1279 text = _("Remote Connection Failed"); | |
1280 } else if(xmlnode_get_child(packet, "resource-constraint")) { | |
1281 text = _("Resource Constraint"); | |
1282 } else if(xmlnode_get_child(packet, "restricted-xml")) { | |
1283 text = _("Restricted XML"); | |
1284 } else if(xmlnode_get_child(packet, "see-other-host")) { | |
1285 text = _("See Other Host"); | |
1286 } else if(xmlnode_get_child(packet, "system-shutdown")) { | |
1287 text = _("System Shutdown"); | |
1288 } else if(xmlnode_get_child(packet, "undefined-condition")) { | |
1289 text = _("Undefined Condition"); | |
1290 } else if(xmlnode_get_child(packet, "unsupported-encoding")) { | |
1291 text = _("Unsupported Encoding"); | |
1292 } else if(xmlnode_get_child(packet, "unsupported-stanza-type")) { | |
1293 text = _("Unsupported Stanza Type"); | |
1294 } else if(xmlnode_get_child(packet, "unsupported-version")) { | |
1295 text = _("Unsupported Version"); | |
1296 } else if(xmlnode_get_child(packet, "xml-not-well-formed")) { | |
1297 text = _("XML Not Well Formed"); | |
1298 } else { | |
1299 text = _("Stream Error"); | |
1300 } | |
8401 | 1301 } |
1302 | |
1303 if(text || cdata) { | |
1304 char *ret = g_strdup_printf("%s%s%s", code ? code : "", | |
1305 code ? ": " : "", text ? text : cdata); | |
1306 g_free(cdata); | |
1307 return ret; | |
1308 } else { | |
1309 return NULL; | |
1310 } | |
1311 } | |
1312 | |
9130 | 1313 static GaimCmdRet jabber_cmd_chat_config(GaimConversation *conv, |
9597 | 1314 const char *cmd, char **args, char **error, void *data) |
9130 | 1315 { |
1316 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1317 jabber_chat_request_room_configure(chat); | |
1318 return GAIM_CMD_RET_OK; | |
1319 } | |
1320 | |
1321 static GaimCmdRet jabber_cmd_chat_register(GaimConversation *conv, | |
9597 | 1322 const char *cmd, char **args, char **error, void *data) |
9130 | 1323 { |
1324 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1325 jabber_chat_register(chat); | |
1326 return GAIM_CMD_RET_OK; | |
1327 } | |
1328 | |
1329 static GaimCmdRet jabber_cmd_chat_topic(GaimConversation *conv, | |
9597 | 1330 const char *cmd, char **args, char **error, void *data) |
9130 | 1331 { |
1332 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1333 jabber_chat_change_topic(chat, args ? args[0] : NULL); | |
1334 return GAIM_CMD_RET_OK; | |
1335 } | |
1336 | |
1337 static GaimCmdRet jabber_cmd_chat_nick(GaimConversation *conv, | |
9597 | 1338 const char *cmd, char **args, char **error, void *data) |
9130 | 1339 { |
1340 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1341 | |
1342 if(!args || !args[0]) | |
1343 return GAIM_CMD_RET_FAILED; | |
1344 | |
1345 jabber_chat_change_nick(chat, args[0]); | |
1346 return GAIM_CMD_RET_OK; | |
1347 } | |
1348 | |
1349 static GaimCmdRet jabber_cmd_chat_part(GaimConversation *conv, | |
9597 | 1350 const char *cmd, char **args, char **error, void *data) |
9130 | 1351 { |
1352 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1353 jabber_chat_part(chat, args ? args[0] : NULL); | |
1354 return GAIM_CMD_RET_OK; | |
1355 } | |
1356 | |
9152 | 1357 static GaimCmdRet jabber_cmd_chat_ban(GaimConversation *conv, |
9597 | 1358 const char *cmd, char **args, char **error, void *data) |
9152 | 1359 { |
1360 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1361 | |
1362 if(!args || !args[0]) | |
1363 return GAIM_CMD_RET_FAILED; | |
1364 | |
1365 if(!jabber_chat_ban_user(chat, args[0], args[1])) { | |
1366 *error = g_strdup_printf(_("Unable to ban user %s"), args[0]); | |
1367 return GAIM_CMD_RET_FAILED; | |
1368 } | |
1369 | |
1370 return GAIM_CMD_RET_OK; | |
1371 } | |
1372 | |
1373 static GaimCmdRet jabber_cmd_chat_invite(GaimConversation *conv, | |
9597 | 1374 const char *cmd, char **args, char **error, void *data) |
9152 | 1375 { |
1376 if(!args || !args[0]) | |
1377 return GAIM_CMD_RET_FAILED; | |
1378 | |
1379 jabber_chat_invite(gaim_conversation_get_gc(conv), | |
1380 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), args[1] ? args[1] : "", | |
1381 args[0]); | |
1382 | |
1383 return GAIM_CMD_RET_OK; | |
1384 } | |
1385 | |
1386 static GaimCmdRet jabber_cmd_chat_join(GaimConversation *conv, | |
9597 | 1387 const char *cmd, char **args, char **error, void *data) |
9152 | 1388 { |
1389 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1390 GHashTable *components; | |
1391 | |
1392 if(!args || !args[0]) | |
1393 return GAIM_CMD_RET_FAILED; | |
1394 | |
1395 components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); | |
1396 | |
1397 g_hash_table_replace(components, "room", args[0]); | |
1398 g_hash_table_replace(components, "server", chat->server); | |
1399 g_hash_table_replace(components, "handle", chat->handle); | |
1400 if(args[1]) | |
1401 g_hash_table_replace(components, "password", args[1]); | |
1402 | |
1403 jabber_chat_join(gaim_conversation_get_gc(conv), components); | |
1404 | |
1405 g_hash_table_destroy(components); | |
1406 return GAIM_CMD_RET_OK; | |
1407 } | |
1408 | |
1409 static GaimCmdRet jabber_cmd_chat_kick(GaimConversation *conv, | |
9597 | 1410 const char *cmd, char **args, char **error, void *data) |
9152 | 1411 { |
1412 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1413 | |
1414 if(!args || !args[0]) | |
1415 return GAIM_CMD_RET_FAILED; | |
1416 | |
1417 if(!jabber_chat_kick_user(chat, args[0], args[1])) { | |
1418 *error = g_strdup_printf(_("Unable to kick user %s"), args[0]); | |
1419 return GAIM_CMD_RET_FAILED; | |
1420 } | |
1421 | |
1422 return GAIM_CMD_RET_OK; | |
1423 } | |
1424 | |
1425 static GaimCmdRet jabber_cmd_chat_msg(GaimConversation *conv, | |
9597 | 1426 const char *cmd, char **args, char **error, void *data) |
9152 | 1427 { |
1428 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1429 char *who; | |
1430 | |
1431 who = g_strdup_printf("%s@%s/%s", chat->room, chat->server, args[0]); | |
1432 | |
1433 jabber_message_send_im(gaim_conversation_get_gc(conv), who, args[1], 0); | |
1434 | |
1435 g_free(who); | |
1436 return GAIM_CMD_RET_OK; | |
1437 } | |
1438 | |
9130 | 1439 static void jabber_register_commands(void) |
1440 { | |
1441 gaim_cmd_register("config", "", GAIM_CMD_P_PRPL, | |
9597 | 1442 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1443 "prpl-jabber", jabber_cmd_chat_config, | |
1444 _("config: Configure a chat room."), NULL); | |
9130 | 1445 gaim_cmd_register("configure", "", GAIM_CMD_P_PRPL, |
9597 | 1446 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1447 "prpl-jabber", jabber_cmd_chat_config, | |
1448 _("configure: Configure a chat room."), NULL); | |
9130 | 1449 gaim_cmd_register("nick", "s", GAIM_CMD_P_PRPL, |
9597 | 1450 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1451 "prpl-jabber", jabber_cmd_chat_nick, | |
1452 _("nick <new nickname>: Change your nickname."), | |
1453 NULL); | |
9130 | 1454 gaim_cmd_register("part", "s", GAIM_CMD_P_PRPL, |
9597 | 1455 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1456 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1457 jabber_cmd_chat_part, _("part [room]: Leave the room."), | |
1458 NULL); | |
9130 | 1459 gaim_cmd_register("register", "", GAIM_CMD_P_PRPL, |
9597 | 1460 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1461 "prpl-jabber", jabber_cmd_chat_register, | |
1462 _("register: Register with a chat room."), NULL); | |
9130 | 1463 /* XXX: there needs to be a core /topic cmd, methinks */ |
1464 gaim_cmd_register("topic", "s", GAIM_CMD_P_PRPL, | |
9597 | 1465 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1466 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1467 jabber_cmd_chat_topic, | |
1468 _("topic [new topic]: View or change the topic."), | |
1469 NULL); | |
9152 | 1470 gaim_cmd_register("ban", "ws", GAIM_CMD_P_PRPL, |
9597 | 1471 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1472 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1473 jabber_cmd_chat_ban, | |
1474 _("ban <user> [room]: Ban a user from the room."), | |
1475 NULL); | |
9152 | 1476 gaim_cmd_register("invite", "ws", GAIM_CMD_P_PRPL, |
9597 | 1477 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1478 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1479 jabber_cmd_chat_invite, | |
1480 _("invite <user> [room]: Invite a user to the room."), | |
1481 NULL); | |
9152 | 1482 gaim_cmd_register("join", "ws", GAIM_CMD_P_PRPL, |
9597 | 1483 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1484 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1485 jabber_cmd_chat_join, | |
1486 _("join: <room> [server]: Join a chat on this server."), | |
1487 NULL); | |
9152 | 1488 gaim_cmd_register("kick", "ws", GAIM_CMD_P_PRPL, |
9597 | 1489 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1490 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1491 jabber_cmd_chat_kick, | |
1492 _("kick <user> [room]: Kick a user from the room."), | |
1493 NULL); | |
9152 | 1494 gaim_cmd_register("msg", "ws", GAIM_CMD_P_PRPL, |
9597 | 1495 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1496 "prpl-jabber", jabber_cmd_chat_msg, | |
1497 _("msg <user> <message>: Send a private message to another user."), | |
1498 NULL); | |
9130 | 1499 } |
1500 | |
8713 | 1501 static GaimPluginPrefFrame * |
1502 get_plugin_pref_frame(GaimPlugin *plugin) { | |
1503 GaimPluginPrefFrame *frame; | |
1504 GaimPluginPref *ppref; | |
1505 | |
1506 frame = gaim_plugin_pref_frame_new(); | |
1507 | |
1508 ppref = gaim_plugin_pref_new_with_label(_("Privacy")); | |
1509 gaim_plugin_pref_frame_add(frame, ppref); | |
1510 | |
1511 ppref = gaim_plugin_pref_new_with_name_and_label("/plugins/prpl/jabber/hide_os", | |
1512 _("Hide Operating System")); | |
1513 gaim_plugin_pref_frame_add(frame, ppref); | |
1514 | |
1515 return frame; | |
1516 } | |
1517 | |
1518 static GaimPluginUiInfo prefs_info = { | |
1519 get_plugin_pref_frame | |
1520 }; | |
1521 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1522 static GaimPluginProtocolInfo prpl_info = |
2086 | 1523 { |
7014 | 1524 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME, |
9475 | 1525 NULL, /* user_splits */ |
1526 NULL, /* protocol_options */ | |
10189 | 1527 {"jpeg,gif,png", 0, 0, 96, 96, GAIM_ICON_SCALE_DISPLAY}, /* icon_spec */ |
9475 | 1528 jabber_list_icon, /* list_icon */ |
1529 jabber_list_emblems, /* list_emblems */ | |
1530 jabber_status_text, /* status_text */ | |
1531 jabber_tooltip_text, /* tooltip_text */ | |
9954 | 1532 jabber_status_types, /* status_types */ |
9475 | 1533 jabber_blist_node_menu, /* blist_node_menu */ |
1534 jabber_chat_info, /* chat_info */ | |
9754 | 1535 jabber_chat_info_defaults, /* chat_info_defaults */ |
9475 | 1536 jabber_login, /* login */ |
1537 jabber_close, /* close */ | |
1538 jabber_message_send_im, /* send_im */ | |
1539 jabber_set_info, /* set_info */ | |
1540 jabber_send_typing, /* send_typing */ | |
1541 jabber_buddy_get_info, /* get_info */ | |
10216 | 1542 jabber_presence_send, /* set_away */ |
9475 | 1543 jabber_idle_set, /* set_idle */ |
1544 NULL, /* change_passwd */ | |
1545 jabber_roster_add_buddy, /* add_buddy */ | |
1546 NULL, /* add_buddies */ | |
1547 jabber_roster_remove_buddy, /* remove_buddy */ | |
1548 NULL, /* remove_buddies */ | |
1549 NULL, /* add_permit */ | |
1550 NULL, /* add_deny */ | |
1551 NULL, /* rem_permit */ | |
1552 NULL, /* rem_deny */ | |
1553 NULL, /* set_permit_deny */ | |
1554 NULL, /* warn */ | |
1555 jabber_chat_join, /* join_chat */ | |
1556 NULL, /* reject_chat */ | |
9917 | 1557 jabber_get_chat_name, /* get_chat_name */ |
9475 | 1558 jabber_chat_invite, /* chat_invite */ |
1559 jabber_chat_leave, /* chat_leave */ | |
1560 NULL, /* chat_whisper */ | |
1561 jabber_message_send_chat, /* chat_send */ | |
1562 jabber_keepalive, /* keepalive */ | |
1563 jabber_register_account, /* register_user */ | |
1564 jabber_buddy_get_info_chat, /* get_cb_info */ | |
1565 NULL, /* get_cb_away */ | |
1566 jabber_roster_alias_change, /* alias_buddy */ | |
1567 jabber_roster_group_change, /* group_buddy */ | |
1568 jabber_roster_group_rename, /* rename_group */ | |
1569 NULL, /* buddy_free */ | |
1570 jabber_convo_closed, /* convo_closed */ | |
1571 jabber_normalize, /* normalize */ | |
10189 | 1572 jabber_set_buddy_icon, /* set_buddy_icon */ |
9475 | 1573 NULL, /* remove_group */ |
1574 jabber_chat_buddy_real_name, /* get_cb_real_name */ | |
1575 jabber_chat_set_topic, /* set_chat_topic */ | |
1576 jabber_find_blist_chat, /* find_blist_chat */ | |
1577 jabber_roomlist_get_list, /* roomlist_get_list */ | |
1578 jabber_roomlist_cancel, /* roomlist_cancel */ | |
1579 NULL, /* roomlist_expand_category */ | |
1580 NULL, /* can_receive_file */ | |
1581 jabber_si_xfer_send /* send_file */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1582 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1583 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1584 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1585 { |
9943 | 1586 GAIM_PLUGIN_MAGIC, |
1587 GAIM_MAJOR_VERSION, | |
1588 GAIM_MINOR_VERSION, | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1589 GAIM_PLUGIN_PROTOCOL, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1590 NULL, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1591 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1592 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1593 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1594 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1595 "prpl-jabber", /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1596 "Jabber", /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1597 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1598 /** summary */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1599 N_("Jabber Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1600 /** description */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1601 N_("Jabber Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1602 NULL, /**< author */ |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
1603 GAIM_WEBSITE, /**< homepage */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1604 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1605 NULL, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1606 NULL, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1607 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1608 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1609 NULL, /**< ui_info */ |
8993 | 1610 &prpl_info, /**< extra_info */ |
1611 &prefs_info, /**< prefs_info */ | |
9015 | 1612 jabber_actions |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1613 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1614 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1615 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5894
diff
changeset
|
1616 init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1617 { |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1618 GaimAccountUserSplit *split; |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1619 GaimAccountOption *option; |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1620 |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1621 split = gaim_account_user_split_new(_("Server"), "jabber.org", '@'); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1622 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
|
1623 |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1624 split = gaim_account_user_split_new(_("Resource"), "Gaim", '/'); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1625 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
|
1626 |
7630 | 1627 option = gaim_account_option_bool_new(_("Use TLS if available"), "use_tls", |
1628 TRUE); | |
1629 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
1630 option); | |
1631 | |
1632 option = gaim_account_option_bool_new(_("Force old SSL"), "old_ssl", FALSE); | |
7124 | 1633 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
1634 option); | |
6764 | 1635 |
8086 | 1636 option = gaim_account_option_bool_new( |
1637 _("Allow plaintext auth over unencrypted streams"), | |
1638 "auth_plain_in_clear", FALSE); | |
1639 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
1640 option); | |
1641 | |
7014 | 1642 option = gaim_account_option_int_new(_("Port"), "port", 5222); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1643 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
7014 | 1644 option); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1645 |
5685
43ea75092684
[gaim-migrate @ 6106]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
1646 option = gaim_account_option_string_new(_("Connect server"), |
7014 | 1647 "connect_server", NULL); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1648 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
7014 | 1649 option); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1650 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1651 my_protocol = plugin; |
7014 | 1652 |
1653 gaim_prefs_add_none("/plugins/prpl/jabber"); | |
1654 gaim_prefs_add_bool("/plugins/prpl/jabber/hide_os", FALSE); | |
9130 | 1655 |
1656 jabber_register_commands(); | |
2086 | 1657 } |
1658 | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5894
diff
changeset
|
1659 GAIM_INIT_PLUGIN(jabber, init_plugin, info); |