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