Mercurial > pidgin.yaz
annotate src/protocols/jabber/jabber.c @ 10487:659edfcac14e
[gaim-migrate @ 11777]
Removed protocol preferences.
MSN will display closed conversation messages but not timeouts.
Jabber will not display your OS.
I left the preferences for OSCAR, but removed them from the UI. OSCAR is
complicated because it stores prefs on the server. I'll let Mark figure
out a smarter way to handle that.
As with all slashed prefs, feel free to voice objections.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 08 Jan 2005 20:30:41 +0000 |
parents | 84bc372a621e |
children | a3a540ed2518 |
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 | |
10486 | 974 type = gaim_status_type_new_full(GAIM_STATUS_ONLINE, "online", _("Online"), FALSE, TRUE, FALSE); |
975 types = g_list_append(types, type); | |
976 | |
977 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE, "available", | |
978 _("Available"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
9980 | 979 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), |
980 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
981 types = g_list_append(types, type); | |
982 | |
983 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE, "chat", | |
984 _("Chatty"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
985 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), | |
986 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
9954 | 987 types = g_list_append(types, type); |
2086 | 988 |
9980 | 989 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY, "away", |
990 _("Away"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
991 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), | |
992 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
9954 | 993 types = g_list_append(types, type); |
994 | |
9980 | 995 type = gaim_status_type_new_with_attrs(GAIM_STATUS_EXTENDED_AWAY, "xa", |
996 _("Extended Away"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
997 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), | |
998 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
9954 | 999 types = g_list_append(types, type); |
1000 | |
9980 | 1001 type = gaim_status_type_new_with_attrs(GAIM_STATUS_UNAVAILABLE, "dnd", |
1002 _("Do Not Disturb"), TRUE, TRUE, FALSE, "priority", _("Priority"), | |
1003 gaim_value_new(GAIM_TYPE_INT), "message", _("Message"), | |
1004 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
9954 | 1005 types = g_list_append(types, type); |
1006 | |
1007 /* | |
8166 | 1008 if(js->protocol_version == JABBER_PROTO_0_9) |
1009 m = g_list_append(m, _("Invisible")); | |
10009 | 1010 */ |
2086 | 1011 |
9954 | 1012 return types; |
2086 | 1013 } |
1014 | |
7395 | 1015 static void |
1016 jabber_password_change_result_cb(JabberStream *js, xmlnode *packet, | |
1017 gpointer data) | |
7124 | 1018 { |
1019 const char *type; | |
1020 | |
1021 type = xmlnode_get_attrib(packet, "type"); | |
1022 | |
9414 | 1023 if(type && !strcmp(type, "result")) { |
7124 | 1024 gaim_notify_info(js->gc, _("Password Changed"), _("Password Changed"), |
1025 _("Your password has been changed.")); | |
1026 } else { | |
8401 | 1027 char *msg = jabber_parse_error(js, packet); |
7124 | 1028 |
8401 | 1029 gaim_notify_error(js->gc, _("Error changing password"), |
1030 _("Error changing password"), msg); | |
1031 g_free(msg); | |
7124 | 1032 } |
1033 } | |
1034 | |
1035 static void jabber_password_change_cb(JabberStream *js, | |
1036 GaimRequestFields *fields) | |
1037 { | |
1038 const char *p1, *p2; | |
1039 JabberIq *iq; | |
1040 xmlnode *query, *y; | |
1041 | |
1042 p1 = gaim_request_fields_get_string(fields, "password1"); | |
1043 p2 = gaim_request_fields_get_string(fields, "password2"); | |
1044 | |
1045 if(strcmp(p1, p2)) { | |
1046 gaim_notify_error(js->gc, NULL, _("New passwords do not match."), NULL); | |
1047 return; | |
1048 } | |
1049 | |
1050 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
1051 | |
1052 xmlnode_set_attrib(iq->node, "to", js->user->domain); | |
1053 | |
1054 query = xmlnode_get_child(iq->node, "query"); | |
1055 | |
1056 y = xmlnode_new_child(query, "username"); | |
1057 xmlnode_insert_data(y, js->user->node, -1); | |
1058 y = xmlnode_new_child(query, "password"); | |
1059 xmlnode_insert_data(y, p1, -1); | |
1060 | |
7395 | 1061 jabber_iq_set_callback(iq, jabber_password_change_result_cb, NULL); |
7124 | 1062 |
1063 jabber_iq_send(iq); | |
1064 | |
1065 gaim_account_set_password(js->gc->account, p1); | |
1066 } | |
1067 | |
9015 | 1068 static void jabber_password_change(GaimPluginAction *action) |
7124 | 1069 { |
9015 | 1070 |
1071 GaimConnection *gc = (GaimConnection *) action->context; | |
7124 | 1072 JabberStream *js = gc->proto_data; |
1073 GaimRequestFields *fields; | |
1074 GaimRequestFieldGroup *group; | |
1075 GaimRequestField *field; | |
1076 | |
1077 fields = gaim_request_fields_new(); | |
1078 group = gaim_request_field_group_new(NULL); | |
1079 gaim_request_fields_add_group(fields, group); | |
1080 | |
1081 field = gaim_request_field_string_new("password1", _("Password"), | |
1082 "", FALSE); | |
1083 gaim_request_field_string_set_masked(field, TRUE); | |
1084 gaim_request_field_group_add_field(group, field); | |
1085 | |
1086 field = gaim_request_field_string_new("password2", _("Password (again)"), | |
1087 "", FALSE); | |
1088 gaim_request_field_string_set_masked(field, TRUE); | |
1089 gaim_request_field_group_add_field(group, field); | |
1090 | |
1091 gaim_request_fields(js->gc, _("Change Jabber Password"), | |
1092 _("Change Jabber Password"), _("Please enter your new password"), | |
1093 fields, _("OK"), G_CALLBACK(jabber_password_change_cb), | |
1094 _("Cancel"), NULL, js); | |
1095 } | |
1096 | |
9015 | 1097 static GList *jabber_actions(GaimPlugin *plugin, gpointer context) |
2956 | 1098 { |
1099 GList *m = NULL; | |
9015 | 1100 GaimPluginAction *act; |
4333 | 1101 |
9015 | 1102 act = gaim_plugin_action_new(_("Set User Info"), |
1103 jabber_setup_set_info); | |
1104 m = g_list_append(m, act); | |
4333 | 1105 |
8296 | 1106 /* if (js->protocol_options & CHANGE_PASSWORD) { */ |
9015 | 1107 act = gaim_plugin_action_new(_("Change Password"), |
1108 jabber_password_change); | |
1109 m = g_list_append(m, act); | |
8296 | 1110 /* } */ |
2956 | 1111 |
1112 return m; | |
1113 } | |
1114 | |
7999 | 1115 static GaimChat *jabber_find_blist_chat(GaimAccount *account, const char *name) |
1116 { | |
1117 GaimBlistNode *gnode, *cnode; | |
1118 JabberID *jid; | |
1119 | |
1120 if(!(jid = jabber_id_new(name))) | |
1121 return NULL; | |
1122 | |
1123 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { | |
1124 for(cnode = gnode->child; cnode; cnode = cnode->next) { | |
1125 GaimChat *chat = (GaimChat*)cnode; | |
1126 const char *room, *server; | |
1127 if(!GAIM_BLIST_NODE_IS_CHAT(cnode)) | |
1128 continue; | |
1129 | |
1130 if(chat->account != account) | |
8011 | 1131 continue; |
7999 | 1132 |
1133 if(!(room = g_hash_table_lookup(chat->components, "room"))) | |
1134 continue; | |
1135 if(!(server = g_hash_table_lookup(chat->components, "server"))) | |
1136 continue; | |
1137 | |
8158 | 1138 if(jid->node && jid->domain && |
1139 !g_utf8_collate(room, jid->node) && !g_utf8_collate(server, jid->domain)) { | |
7999 | 1140 jabber_id_free(jid); |
1141 return chat; | |
1142 } | |
1143 } | |
1144 } | |
1145 jabber_id_free(jid); | |
1146 return NULL; | |
1147 } | |
1148 | |
8400 | 1149 static void jabber_convo_closed(GaimConnection *gc, const char *who) |
1150 { | |
1151 JabberStream *js = gc->proto_data; | |
1152 JabberID *jid; | |
1153 JabberBuddy *jb; | |
1154 JabberBuddyResource *jbr; | |
1155 | |
1156 if(!(jid = jabber_id_new(who))) | |
1157 return; | |
1158 | |
1159 if((jb = jabber_buddy_find(js, who, TRUE)) && | |
1160 (jbr = jabber_buddy_find_resource(jb, jid->resource))) { | |
1161 if(jbr->thread_id) { | |
1162 g_free(jbr->thread_id); | |
1163 jbr->thread_id = NULL; | |
1164 } | |
1165 } | |
1166 | |
1167 jabber_id_free(jid); | |
1168 } | |
1169 | |
8401 | 1170 |
1171 char *jabber_parse_error(JabberStream *js, xmlnode *packet) | |
1172 { | |
1173 xmlnode *error; | |
1174 const char *code = NULL, *text = NULL; | |
1175 const char *xmlns = xmlnode_get_attrib(packet, "xmlns"); | |
1176 char *cdata = NULL; | |
1177 | |
1178 if((error = xmlnode_get_child(packet, "error"))) { | |
1179 cdata = xmlnode_get_data(error); | |
1180 code = xmlnode_get_attrib(error, "code"); | |
1181 | |
1182 /* Stanza errors */ | |
1183 if(xmlnode_get_child(error, "bad-request")) { | |
1184 text = _("Bad Request"); | |
1185 } else if(xmlnode_get_child(error, "conflict")) { | |
1186 text = _("Conflict"); | |
1187 } else if(xmlnode_get_child(error, "feature-not-implemented")) { | |
1188 text = _("Feature Not Implemented"); | |
1189 } else if(xmlnode_get_child(error, "forbidden")) { | |
1190 text = _("Forbidden"); | |
1191 } else if(xmlnode_get_child(error, "gone")) { | |
1192 text = _("Gone"); | |
1193 } else if(xmlnode_get_child(error, "internal-server-error")) { | |
1194 text = _("Internal Server Error"); | |
1195 } else if(xmlnode_get_child(error, "item-not-found")) { | |
1196 text = _("Item Not Found"); | |
1197 } else if(xmlnode_get_child(error, "jid-malformed")) { | |
1198 text = _("Malformed Jabber ID"); | |
1199 } else if(xmlnode_get_child(error, "not-acceptable")) { | |
1200 text = _("Not Acceptable"); | |
1201 } else if(xmlnode_get_child(error, "not-allowed")) { | |
1202 text = _("Not Allowed"); | |
1203 } else if(xmlnode_get_child(error, "not-authorized")) { | |
1204 text = _("Not Authorized"); | |
1205 } else if(xmlnode_get_child(error, "payment-required")) { | |
1206 text = _("Payment Required"); | |
1207 } else if(xmlnode_get_child(error, "recipient-unavailable")) { | |
1208 text = _("Recipient Unavailable"); | |
1209 } else if(xmlnode_get_child(error, "redirect")) { | |
1210 /* XXX */ | |
1211 } else if(xmlnode_get_child(error, "registration-required")) { | |
1212 text = _("Registration Required"); | |
1213 } else if(xmlnode_get_child(error, "remote-server-not-found")) { | |
1214 text = _("Remote Server Not Found"); | |
1215 } else if(xmlnode_get_child(error, "remote-server-timeout")) { | |
1216 text = _("Remote Server Timeout"); | |
1217 } else if(xmlnode_get_child(error, "resource-constraint")) { | |
1218 text = _("Server Overloaded"); | |
1219 } else if(xmlnode_get_child(error, "service-unavailable")) { | |
1220 text = _("Service Unavailable"); | |
1221 } else if(xmlnode_get_child(error, "subscription-required")) { | |
1222 text = _("Subscription Required"); | |
1223 } else if(xmlnode_get_child(error, "unexpected-request")) { | |
1224 text = _("Unexpected Request"); | |
1225 } else if(xmlnode_get_child(error, "undefined-condition")) { | |
1226 text = _("Unknown Error"); | |
1227 } | |
1228 } else if(xmlns && !strcmp(xmlns, "urn:ietf:params:xml:ns:xmpp-sasl")) { | |
1229 if(xmlnode_get_child(packet, "aborted")) { | |
1230 js->gc->wants_to_die = TRUE; | |
1231 text = _("Authorization Aborted"); | |
1232 } else if(xmlnode_get_child(error, "incorrect-encoding")) { | |
1233 text = _("Incorrect encoding in authorization"); | |
1234 } else if(xmlnode_get_child(error, "invalid-authzid")) { | |
1235 js->gc->wants_to_die = TRUE; | |
1236 text = _("Invalid authzid"); | |
1237 } else if(xmlnode_get_child(error, "invalid-mechanism")) { | |
1238 js->gc->wants_to_die = TRUE; | |
1239 text = _("Invalid Authorization Mechanism"); | |
1240 } else if(xmlnode_get_child(error, "mechanism-too-weak")) { | |
1241 js->gc->wants_to_die = TRUE; | |
1242 text = _("Authorization mechanism too weak"); | |
1243 } else if(xmlnode_get_child(error, "not-authorized")) { | |
1244 js->gc->wants_to_die = TRUE; | |
1245 text = _("Not Authorized"); | |
1246 } else if(xmlnode_get_child(error, "temporary-auth-failure")) { | |
1247 text = _("Temporary Authentication Failure"); | |
1248 } else { | |
1249 text = _("Authentication Failure"); | |
1250 } | |
8402 | 1251 } else if(!strcmp(packet->name, "stream:error")) { |
1252 if(xmlnode_get_child(packet, "bad-format")) { | |
1253 text = _("Bad Format"); | |
1254 } else if(xmlnode_get_child(packet, "bad-namespace-prefix")) { | |
1255 text = _("Bad Namespace Prefix"); | |
1256 } else if(xmlnode_get_child(packet, "conflict")) { | |
1257 js->gc->wants_to_die = TRUE; | |
1258 text = _("Resource Conflict"); | |
1259 } else if(xmlnode_get_child(packet, "connection-timeout")) { | |
1260 text = _("Connection Timeout"); | |
1261 } else if(xmlnode_get_child(packet, "host-gone")) { | |
1262 text = _("Host Gone"); | |
1263 } else if(xmlnode_get_child(packet, "host-unknown")) { | |
1264 text = _("Host Unknown"); | |
1265 } else if(xmlnode_get_child(packet, "improper-addressing")) { | |
1266 text = _("Improper Addressing"); | |
1267 } else if(xmlnode_get_child(packet, "internal-server-error")) { | |
1268 text = _("Internal Server Error"); | |
1269 } else if(xmlnode_get_child(packet, "invalid-id")) { | |
1270 text = _("Invalid ID"); | |
1271 } else if(xmlnode_get_child(packet, "invalid-namespace")) { | |
1272 text = _("Invalid Namespace"); | |
1273 } else if(xmlnode_get_child(packet, "invalid-xml")) { | |
1274 text = _("Invalid XML"); | |
1275 } else if(xmlnode_get_child(packet, "nonmatching-hosts")) { | |
1276 text = _("Non-matching Hosts"); | |
1277 } else if(xmlnode_get_child(packet, "not-authorized")) { | |
1278 text = _("Not Authorized"); | |
1279 } else if(xmlnode_get_child(packet, "policy-violation")) { | |
1280 text = _("Policy Violation"); | |
1281 } else if(xmlnode_get_child(packet, "remote-connection-failed")) { | |
1282 text = _("Remote Connection Failed"); | |
1283 } else if(xmlnode_get_child(packet, "resource-constraint")) { | |
1284 text = _("Resource Constraint"); | |
1285 } else if(xmlnode_get_child(packet, "restricted-xml")) { | |
1286 text = _("Restricted XML"); | |
1287 } else if(xmlnode_get_child(packet, "see-other-host")) { | |
1288 text = _("See Other Host"); | |
1289 } else if(xmlnode_get_child(packet, "system-shutdown")) { | |
1290 text = _("System Shutdown"); | |
1291 } else if(xmlnode_get_child(packet, "undefined-condition")) { | |
1292 text = _("Undefined Condition"); | |
1293 } else if(xmlnode_get_child(packet, "unsupported-encoding")) { | |
1294 text = _("Unsupported Encoding"); | |
1295 } else if(xmlnode_get_child(packet, "unsupported-stanza-type")) { | |
1296 text = _("Unsupported Stanza Type"); | |
1297 } else if(xmlnode_get_child(packet, "unsupported-version")) { | |
1298 text = _("Unsupported Version"); | |
1299 } else if(xmlnode_get_child(packet, "xml-not-well-formed")) { | |
1300 text = _("XML Not Well Formed"); | |
1301 } else { | |
1302 text = _("Stream Error"); | |
1303 } | |
8401 | 1304 } |
1305 | |
1306 if(text || cdata) { | |
1307 char *ret = g_strdup_printf("%s%s%s", code ? code : "", | |
1308 code ? ": " : "", text ? text : cdata); | |
1309 g_free(cdata); | |
1310 return ret; | |
1311 } else { | |
1312 return NULL; | |
1313 } | |
1314 } | |
1315 | |
9130 | 1316 static GaimCmdRet jabber_cmd_chat_config(GaimConversation *conv, |
9597 | 1317 const char *cmd, char **args, char **error, void *data) |
9130 | 1318 { |
1319 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1320 jabber_chat_request_room_configure(chat); | |
1321 return GAIM_CMD_RET_OK; | |
1322 } | |
1323 | |
1324 static GaimCmdRet jabber_cmd_chat_register(GaimConversation *conv, | |
9597 | 1325 const char *cmd, char **args, char **error, void *data) |
9130 | 1326 { |
1327 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1328 jabber_chat_register(chat); | |
1329 return GAIM_CMD_RET_OK; | |
1330 } | |
1331 | |
1332 static GaimCmdRet jabber_cmd_chat_topic(GaimConversation *conv, | |
9597 | 1333 const char *cmd, char **args, char **error, void *data) |
9130 | 1334 { |
1335 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1336 jabber_chat_change_topic(chat, args ? args[0] : NULL); | |
1337 return GAIM_CMD_RET_OK; | |
1338 } | |
1339 | |
1340 static GaimCmdRet jabber_cmd_chat_nick(GaimConversation *conv, | |
9597 | 1341 const char *cmd, char **args, char **error, void *data) |
9130 | 1342 { |
1343 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1344 | |
1345 if(!args || !args[0]) | |
1346 return GAIM_CMD_RET_FAILED; | |
1347 | |
1348 jabber_chat_change_nick(chat, args[0]); | |
1349 return GAIM_CMD_RET_OK; | |
1350 } | |
1351 | |
1352 static GaimCmdRet jabber_cmd_chat_part(GaimConversation *conv, | |
9597 | 1353 const char *cmd, char **args, char **error, void *data) |
9130 | 1354 { |
1355 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1356 jabber_chat_part(chat, args ? args[0] : NULL); | |
1357 return GAIM_CMD_RET_OK; | |
1358 } | |
1359 | |
9152 | 1360 static GaimCmdRet jabber_cmd_chat_ban(GaimConversation *conv, |
9597 | 1361 const char *cmd, char **args, char **error, void *data) |
9152 | 1362 { |
1363 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1364 | |
1365 if(!args || !args[0]) | |
1366 return GAIM_CMD_RET_FAILED; | |
1367 | |
1368 if(!jabber_chat_ban_user(chat, args[0], args[1])) { | |
1369 *error = g_strdup_printf(_("Unable to ban user %s"), args[0]); | |
1370 return GAIM_CMD_RET_FAILED; | |
1371 } | |
1372 | |
1373 return GAIM_CMD_RET_OK; | |
1374 } | |
1375 | |
1376 static GaimCmdRet jabber_cmd_chat_invite(GaimConversation *conv, | |
9597 | 1377 const char *cmd, char **args, char **error, void *data) |
9152 | 1378 { |
1379 if(!args || !args[0]) | |
1380 return GAIM_CMD_RET_FAILED; | |
1381 | |
1382 jabber_chat_invite(gaim_conversation_get_gc(conv), | |
1383 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), args[1] ? args[1] : "", | |
1384 args[0]); | |
1385 | |
1386 return GAIM_CMD_RET_OK; | |
1387 } | |
1388 | |
1389 static GaimCmdRet jabber_cmd_chat_join(GaimConversation *conv, | |
9597 | 1390 const char *cmd, char **args, char **error, void *data) |
9152 | 1391 { |
1392 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1393 GHashTable *components; | |
1394 | |
1395 if(!args || !args[0]) | |
1396 return GAIM_CMD_RET_FAILED; | |
1397 | |
1398 components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); | |
1399 | |
1400 g_hash_table_replace(components, "room", args[0]); | |
1401 g_hash_table_replace(components, "server", chat->server); | |
1402 g_hash_table_replace(components, "handle", chat->handle); | |
1403 if(args[1]) | |
1404 g_hash_table_replace(components, "password", args[1]); | |
1405 | |
1406 jabber_chat_join(gaim_conversation_get_gc(conv), components); | |
1407 | |
1408 g_hash_table_destroy(components); | |
1409 return GAIM_CMD_RET_OK; | |
1410 } | |
1411 | |
1412 static GaimCmdRet jabber_cmd_chat_kick(GaimConversation *conv, | |
9597 | 1413 const char *cmd, char **args, char **error, void *data) |
9152 | 1414 { |
1415 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1416 | |
1417 if(!args || !args[0]) | |
1418 return GAIM_CMD_RET_FAILED; | |
1419 | |
1420 if(!jabber_chat_kick_user(chat, args[0], args[1])) { | |
1421 *error = g_strdup_printf(_("Unable to kick user %s"), args[0]); | |
1422 return GAIM_CMD_RET_FAILED; | |
1423 } | |
1424 | |
1425 return GAIM_CMD_RET_OK; | |
1426 } | |
1427 | |
1428 static GaimCmdRet jabber_cmd_chat_msg(GaimConversation *conv, | |
9597 | 1429 const char *cmd, char **args, char **error, void *data) |
9152 | 1430 { |
1431 JabberChat *chat = jabber_chat_find_by_conv(conv); | |
1432 char *who; | |
1433 | |
1434 who = g_strdup_printf("%s@%s/%s", chat->room, chat->server, args[0]); | |
1435 | |
1436 jabber_message_send_im(gaim_conversation_get_gc(conv), who, args[1], 0); | |
1437 | |
1438 g_free(who); | |
1439 return GAIM_CMD_RET_OK; | |
1440 } | |
1441 | |
9130 | 1442 static void jabber_register_commands(void) |
1443 { | |
1444 gaim_cmd_register("config", "", GAIM_CMD_P_PRPL, | |
9597 | 1445 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1446 "prpl-jabber", jabber_cmd_chat_config, | |
1447 _("config: Configure a chat room."), NULL); | |
9130 | 1448 gaim_cmd_register("configure", "", GAIM_CMD_P_PRPL, |
9597 | 1449 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1450 "prpl-jabber", jabber_cmd_chat_config, | |
1451 _("configure: Configure a chat room."), NULL); | |
9130 | 1452 gaim_cmd_register("nick", "s", GAIM_CMD_P_PRPL, |
9597 | 1453 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1454 "prpl-jabber", jabber_cmd_chat_nick, | |
1455 _("nick <new nickname>: Change your nickname."), | |
1456 NULL); | |
9130 | 1457 gaim_cmd_register("part", "s", GAIM_CMD_P_PRPL, |
9597 | 1458 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1459 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1460 jabber_cmd_chat_part, _("part [room]: Leave the room."), | |
1461 NULL); | |
9130 | 1462 gaim_cmd_register("register", "", GAIM_CMD_P_PRPL, |
9597 | 1463 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1464 "prpl-jabber", jabber_cmd_chat_register, | |
1465 _("register: Register with a chat room."), NULL); | |
9130 | 1466 /* XXX: there needs to be a core /topic cmd, methinks */ |
1467 gaim_cmd_register("topic", "s", GAIM_CMD_P_PRPL, | |
9597 | 1468 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1469 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1470 jabber_cmd_chat_topic, | |
1471 _("topic [new topic]: View or change the topic."), | |
1472 NULL); | |
9152 | 1473 gaim_cmd_register("ban", "ws", GAIM_CMD_P_PRPL, |
9597 | 1474 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1475 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1476 jabber_cmd_chat_ban, | |
1477 _("ban <user> [room]: Ban a user from the room."), | |
1478 NULL); | |
9152 | 1479 gaim_cmd_register("invite", "ws", GAIM_CMD_P_PRPL, |
9597 | 1480 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1481 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1482 jabber_cmd_chat_invite, | |
1483 _("invite <user> [room]: Invite a user to the room."), | |
1484 NULL); | |
9152 | 1485 gaim_cmd_register("join", "ws", GAIM_CMD_P_PRPL, |
9597 | 1486 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1487 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1488 jabber_cmd_chat_join, | |
1489 _("join: <room> [server]: Join a chat on this server."), | |
1490 NULL); | |
9152 | 1491 gaim_cmd_register("kick", "ws", GAIM_CMD_P_PRPL, |
9597 | 1492 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1493 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", | |
1494 jabber_cmd_chat_kick, | |
1495 _("kick <user> [room]: Kick a user from the room."), | |
1496 NULL); | |
9152 | 1497 gaim_cmd_register("msg", "ws", GAIM_CMD_P_PRPL, |
9597 | 1498 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1499 "prpl-jabber", jabber_cmd_chat_msg, | |
1500 _("msg <user> <message>: Send a private message to another user."), | |
1501 NULL); | |
9130 | 1502 } |
1503 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1504 static GaimPluginProtocolInfo prpl_info = |
2086 | 1505 { |
7014 | 1506 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME, |
9475 | 1507 NULL, /* user_splits */ |
1508 NULL, /* protocol_options */ | |
10189 | 1509 {"jpeg,gif,png", 0, 0, 96, 96, GAIM_ICON_SCALE_DISPLAY}, /* icon_spec */ |
9475 | 1510 jabber_list_icon, /* list_icon */ |
1511 jabber_list_emblems, /* list_emblems */ | |
1512 jabber_status_text, /* status_text */ | |
1513 jabber_tooltip_text, /* tooltip_text */ | |
9954 | 1514 jabber_status_types, /* status_types */ |
9475 | 1515 jabber_blist_node_menu, /* blist_node_menu */ |
1516 jabber_chat_info, /* chat_info */ | |
9754 | 1517 jabber_chat_info_defaults, /* chat_info_defaults */ |
9475 | 1518 jabber_login, /* login */ |
1519 jabber_close, /* close */ | |
1520 jabber_message_send_im, /* send_im */ | |
1521 jabber_set_info, /* set_info */ | |
1522 jabber_send_typing, /* send_typing */ | |
1523 jabber_buddy_get_info, /* get_info */ | |
10216 | 1524 jabber_presence_send, /* set_away */ |
9475 | 1525 jabber_idle_set, /* set_idle */ |
1526 NULL, /* change_passwd */ | |
1527 jabber_roster_add_buddy, /* add_buddy */ | |
1528 NULL, /* add_buddies */ | |
1529 jabber_roster_remove_buddy, /* remove_buddy */ | |
1530 NULL, /* remove_buddies */ | |
1531 NULL, /* add_permit */ | |
1532 NULL, /* add_deny */ | |
1533 NULL, /* rem_permit */ | |
1534 NULL, /* rem_deny */ | |
1535 NULL, /* set_permit_deny */ | |
1536 NULL, /* warn */ | |
1537 jabber_chat_join, /* join_chat */ | |
1538 NULL, /* reject_chat */ | |
9917 | 1539 jabber_get_chat_name, /* get_chat_name */ |
9475 | 1540 jabber_chat_invite, /* chat_invite */ |
1541 jabber_chat_leave, /* chat_leave */ | |
1542 NULL, /* chat_whisper */ | |
1543 jabber_message_send_chat, /* chat_send */ | |
1544 jabber_keepalive, /* keepalive */ | |
1545 jabber_register_account, /* register_user */ | |
1546 jabber_buddy_get_info_chat, /* get_cb_info */ | |
1547 NULL, /* get_cb_away */ | |
1548 jabber_roster_alias_change, /* alias_buddy */ | |
1549 jabber_roster_group_change, /* group_buddy */ | |
1550 jabber_roster_group_rename, /* rename_group */ | |
1551 NULL, /* buddy_free */ | |
1552 jabber_convo_closed, /* convo_closed */ | |
1553 jabber_normalize, /* normalize */ | |
10189 | 1554 jabber_set_buddy_icon, /* set_buddy_icon */ |
9475 | 1555 NULL, /* remove_group */ |
1556 jabber_chat_buddy_real_name, /* get_cb_real_name */ | |
1557 jabber_chat_set_topic, /* set_chat_topic */ | |
1558 jabber_find_blist_chat, /* find_blist_chat */ | |
1559 jabber_roomlist_get_list, /* roomlist_get_list */ | |
1560 jabber_roomlist_cancel, /* roomlist_cancel */ | |
1561 NULL, /* roomlist_expand_category */ | |
1562 NULL, /* can_receive_file */ | |
1563 jabber_si_xfer_send /* send_file */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1564 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1565 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1566 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1567 { |
9943 | 1568 GAIM_PLUGIN_MAGIC, |
1569 GAIM_MAJOR_VERSION, | |
1570 GAIM_MINOR_VERSION, | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1571 GAIM_PLUGIN_PROTOCOL, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1572 NULL, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1573 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1574 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1575 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1576 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1577 "prpl-jabber", /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1578 "Jabber", /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1579 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1580 /** summary */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1581 N_("Jabber Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1582 /** description */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1583 N_("Jabber Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1584 NULL, /**< author */ |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
1585 GAIM_WEBSITE, /**< homepage */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1586 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1587 NULL, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1588 NULL, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1589 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1590 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1591 NULL, /**< ui_info */ |
8993 | 1592 &prpl_info, /**< extra_info */ |
10487 | 1593 NULL, /**< prefs_info */ |
9015 | 1594 jabber_actions |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1595 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1596 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1597 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5894
diff
changeset
|
1598 init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1599 { |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1600 GaimAccountUserSplit *split; |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1601 GaimAccountOption *option; |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1602 |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1603 split = gaim_account_user_split_new(_("Server"), "jabber.org", '@'); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1604 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
|
1605 |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1606 split = gaim_account_user_split_new(_("Resource"), "Gaim", '/'); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1607 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
|
1608 |
7630 | 1609 option = gaim_account_option_bool_new(_("Use TLS if available"), "use_tls", |
1610 TRUE); | |
1611 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
1612 option); | |
1613 | |
1614 option = gaim_account_option_bool_new(_("Force old SSL"), "old_ssl", FALSE); | |
7124 | 1615 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
1616 option); | |
6764 | 1617 |
8086 | 1618 option = gaim_account_option_bool_new( |
1619 _("Allow plaintext auth over unencrypted streams"), | |
1620 "auth_plain_in_clear", FALSE); | |
1621 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
1622 option); | |
1623 | |
7014 | 1624 option = gaim_account_option_int_new(_("Port"), "port", 5222); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1625 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
7014 | 1626 option); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1627 |
5685
43ea75092684
[gaim-migrate @ 6106]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
1628 option = gaim_account_option_string_new(_("Connect server"), |
7014 | 1629 "connect_server", NULL); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5613
diff
changeset
|
1630 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
7014 | 1631 option); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1632 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5174
diff
changeset
|
1633 my_protocol = plugin; |
7014 | 1634 |
10487 | 1635 gaim_prefs_remove("/plugins/prpl/jabber"); |
9130 | 1636 |
1637 jabber_register_commands(); | |
2086 | 1638 } |
1639 | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5894
diff
changeset
|
1640 GAIM_INIT_PLUGIN(jabber, init_plugin, info); |