comparison src/protocols/jabber/jabber.c @ 11387:012bb2eed54b

[gaim-migrate @ 13615] jabber SRV goodness committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Wed, 31 Aug 2005 18:21:42 +0000
parents 90be432e8385
children 098cfd8152bc
comparison
equal deleted inserted replaced
11386:4eaa0f7eb3c9 11387:012bb2eed54b
24 #include "accountopt.h" 24 #include "accountopt.h"
25 #include "blist.h" 25 #include "blist.h"
26 #include "cmds.h" 26 #include "cmds.h"
27 #include "connection.h" 27 #include "connection.h"
28 #include "debug.h" 28 #include "debug.h"
29 #include "dnssrv.h"
29 #include "message.h" 30 #include "message.h"
30 #include "notify.h" 31 #include "notify.h"
31 #include "pluginpref.h" 32 #include "pluginpref.h"
32 #include "prpl.h" 33 #include "prpl.h"
33 #include "request.h" 34 #include "request.h"
345 js->gc->inpa = 0; 346 js->gc->inpa = 0;
346 js->gsc = gaim_ssl_connect_fd(js->gc->account, js->fd, 347 js->gsc = gaim_ssl_connect_fd(js->gc->account, js->fd,
347 jabber_login_callback_ssl, jabber_ssl_connect_failure, js->gc); 348 jabber_login_callback_ssl, jabber_ssl_connect_failure, js->gc);
348 } 349 }
349 350
351 static void jabber_login_connect(JabberStream *js, const char *server, int port)
352 {
353 int rc;
354
355 rc = gaim_proxy_connect(js->gc->account, server,
356 port, jabber_login_callback, js->gc);
357
358 if (rc != 0)
359 gaim_connection_error(js->gc, _("Unable to create socket"));
360 }
361
362 static void srv_resolved_cb(struct srv_response *resp, int results, gpointer data)
363 {
364 JabberStream *js = (JabberStream*)data;
365 int config_port = gaim_account_get_int(js->gc->account, "port", 0);
366
367 if(results) {
368 jabber_login_connect(js, resp->hostname, config_port ? config_port : resp->port);
369 g_free(resp);
370 } else {
371 jabber_login_connect(js, js->user->domain, config_port);
372 }
373 }
374
375
350 376
351 static void 377 static void
352 jabber_login(GaimAccount *account, GaimStatus *status) 378 jabber_login(GaimAccount *account, GaimStatus *status)
353 { 379 {
354 int rc;
355 GaimConnection *gc = gaim_account_get_connection(account); 380 GaimConnection *gc = gaim_account_get_connection(account);
356 const char *connect_server = gaim_account_get_string(account, 381 const char *connect_server = gaim_account_get_string(account,
357 "connect_server", ""); 382 "connect_server", "");
358 const char *server;
359 JabberStream *js; 383 JabberStream *js;
360 JabberBuddy *my_jb = NULL; 384 JabberBuddy *my_jb = NULL;
361 385
362 gc->flags |= GAIM_CONNECTION_HTML; 386 gc->flags |= GAIM_CONNECTION_HTML;
363 js = gc->proto_data = g_new0(JabberStream, 1); 387 js = gc->proto_data = g_new0(JabberStream, 1);
394 } 418 }
395 419
396 if((my_jb = jabber_buddy_find(js, gaim_account_get_username(account), TRUE))) 420 if((my_jb = jabber_buddy_find(js, gaim_account_get_username(account), TRUE)))
397 my_jb->subscription |= JABBER_SUB_BOTH; 421 my_jb->subscription |= JABBER_SUB_BOTH;
398 422
399 server = connect_server[0] ? connect_server : js->user->domain;
400
401 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING); 423 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING);
402 424
403 425 /* if they've got old-ssl mode going, we probably want to ignore SRV lookups */
404 if(gaim_account_get_bool(account, "old_ssl", FALSE)) { 426 if(gaim_account_get_bool(js->gc->account, "old_ssl", FALSE)) {
405 if(gaim_ssl_is_supported()) { 427 if(gaim_ssl_is_supported()) {
406 js->gsc = gaim_ssl_connect(account, server, 428 js->gsc = gaim_ssl_connect(js->gc->account,
407 gaim_account_get_int(account, "port", 5222), 429 connect_server[0] ? connect_server : js->user->domain,
408 jabber_login_callback_ssl, jabber_ssl_connect_failure, gc); 430 gaim_account_get_int(account, "port", 5223), jabber_login_callback_ssl,
431 jabber_ssl_connect_failure, js->gc);
409 } else { 432 } else {
410 gaim_connection_error(gc, _("SSL support unavailable")); 433 gaim_connection_error(js->gc, _("SSL support unavailable"));
411 } 434 }
412 } 435 }
413 436
437 /* no old-ssl, so if they've specified a connect server, we'll use that, otherwise we'll
438 * invoke the magic of SRV lookups, to figure out host and port */
414 if(!js->gsc) { 439 if(!js->gsc) {
415 rc = gaim_proxy_connect(account, server, 440 if(connect_server[0]) {
416 gaim_account_get_int(account, "port", 5222), 441 jabber_login_connect(js, connect_server, gaim_account_get_int(account, "port", 5222));
417 jabber_login_callback, gc); 442 } else {
418 443 gaim_srv_resolve("xmpp-client", "tcp", js->user->domain, srv_resolved_cb, js);
419 if (rc != 0) 444 }
420 gaim_connection_error(gc, _("Unable to create socket")); 445 }
421 } 446 }
422 } 447
423 448
424 static gboolean 449 static gboolean
425 conn_close_cb(gpointer data) 450 conn_close_cb(gpointer data)
426 { 451 {
427 JabberStream *js = data; 452 JabberStream *js = data;
1631 _("Allow plaintext auth over unencrypted streams"), 1656 _("Allow plaintext auth over unencrypted streams"),
1632 "auth_plain_in_clear", FALSE); 1657 "auth_plain_in_clear", FALSE);
1633 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, 1658 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
1634 option); 1659 option);
1635 1660
1636 option = gaim_account_option_int_new(_("Port"), "port", 5222); 1661 option = gaim_account_option_int_new(_("Connect port"), "port", 5222);
1637 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, 1662 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
1638 option); 1663 option);
1639 1664
1640 option = gaim_account_option_string_new(_("Connect server"), 1665 option = gaim_account_option_string_new(_("Connect server"),
1641 "connect_server", NULL); 1666 "connect_server", NULL);