Move connection_connect
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#ifdef HAVE_LIBMESODE
|
#ifdef HAVE_LIBMESODE
|
||||||
#include <mesode.h>
|
#include <mesode.h>
|
||||||
@@ -45,6 +46,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "config/preferences.h"
|
||||||
#include "event/server_events.h"
|
#include "event/server_events.h"
|
||||||
#include "xmpp/connection.h"
|
#include "xmpp/connection.h"
|
||||||
#include "xmpp/session.h"
|
#include "xmpp/session.h"
|
||||||
@@ -67,6 +69,10 @@ static void _xmpp_file_logger(void *const userdata, const xmpp_log_level_t level
|
|||||||
static log_level_t _get_log_level(const xmpp_log_level_t xmpp_level);
|
static log_level_t _get_log_level(const xmpp_log_level_t xmpp_level);
|
||||||
static void _connection_handler(xmpp_conn_t *const conn, const xmpp_conn_event_t status, const int error,
|
static void _connection_handler(xmpp_conn_t *const conn, const xmpp_conn_event_t status, const int error,
|
||||||
xmpp_stream_error_t *const stream_error, void *const userdata);
|
xmpp_stream_error_t *const stream_error, void *const userdata);
|
||||||
|
static jabber_conn_status_t
|
||||||
|
_connection_connect(const char *const fulljid, const char *const passwd, const char *const altdomain, int port,
|
||||||
|
const char *const tls_policy, char *cert_path);
|
||||||
|
|
||||||
#ifdef HAVE_LIBMESODE
|
#ifdef HAVE_LIBMESODE
|
||||||
static int _connection_certfail_cb(xmpp_tlscert_t *xmpptlscert, const char *const errormsg);
|
static int _connection_certfail_cb(xmpp_tlscert_t *xmpptlscert, const char *const errormsg);
|
||||||
#endif
|
#endif
|
||||||
@@ -81,7 +87,37 @@ void connection_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
jabber_conn_status_t
|
jabber_conn_status_t
|
||||||
connection_connect(const char *const fulljid, const char *const passwd, const char *const altdomain, int port,
|
connection_connect_main(const char *const fulljid, const char *const passwd, const char *const altdomain, int port,
|
||||||
|
const char *const tls_policy)
|
||||||
|
{
|
||||||
|
assert(fulljid != NULL);
|
||||||
|
assert(passwd != NULL);
|
||||||
|
|
||||||
|
Jid *jid = jid_create(fulljid);
|
||||||
|
|
||||||
|
if (jid == NULL) {
|
||||||
|
log_error("Malformed JID not able to connect: %s", fulljid);
|
||||||
|
conn.conn_status = JABBER_DISCONNECTED;
|
||||||
|
return conn.conn_status;
|
||||||
|
} else if (jid->fulljid == NULL) {
|
||||||
|
log_error("Full JID required to connect, received: %s", fulljid);
|
||||||
|
conn.conn_status = JABBER_DISCONNECTED;
|
||||||
|
jid_destroy(jid);
|
||||||
|
return conn.conn_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
jid_destroy(jid);
|
||||||
|
|
||||||
|
log_info("Connecting as %s", fulljid);
|
||||||
|
char *cert_path = prefs_get_string(PREF_TLS_CERTPATH);
|
||||||
|
jabber_conn_status_t status = _connection_connect(fulljid, passwd, altdomain, port, tls_policy, cert_path);
|
||||||
|
prefs_free_string(cert_path);
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
static jabber_conn_status_t
|
||||||
|
_connection_connect(const char *const fulljid, const char *const passwd, const char *const altdomain, int port,
|
||||||
const char *const tls_policy, char *cert_path)
|
const char *const tls_policy, char *cert_path)
|
||||||
{
|
{
|
||||||
if (conn.log) {
|
if (conn.log) {
|
||||||
|
|||||||
@@ -39,8 +39,8 @@
|
|||||||
|
|
||||||
void connection_init(void);
|
void connection_init(void);
|
||||||
|
|
||||||
jabber_conn_status_t connection_connect(const char *const fulljid, const char *const passwd, const char *const altdomain,
|
jabber_conn_status_t connection_connect_main(const char *const fulljid, const char *const passwd, const char *const altdomain, int port,
|
||||||
int port, const char *const tls_policy, char *cert_path);
|
const char *const tls_policy);
|
||||||
|
|
||||||
char *connection_get_domain(void);
|
char *connection_get_domain(void);
|
||||||
|
|
||||||
|
|||||||
@@ -86,9 +86,6 @@ static struct {
|
|||||||
|
|
||||||
static GTimer *reconnect_timer;
|
static GTimer *reconnect_timer;
|
||||||
|
|
||||||
static jabber_conn_status_t _session_connect(const char *const fulljid, const char *const passwd,
|
|
||||||
const char *const altdomain, int port, const char *const tls_policy);
|
|
||||||
|
|
||||||
static void _session_reconnect(void);
|
static void _session_reconnect(void);
|
||||||
|
|
||||||
static void _session_free_saved_account(void);
|
static void _session_free_saved_account(void);
|
||||||
@@ -129,7 +126,7 @@ session_connect_with_account(const ProfAccount *const account)
|
|||||||
// connect with fulljid
|
// connect with fulljid
|
||||||
Jid *jidp = jid_create_from_bare_and_resource(account->jid, account->resource);
|
Jid *jidp = jid_create_from_bare_and_resource(account->jid, account->resource);
|
||||||
jabber_conn_status_t result =
|
jabber_conn_status_t result =
|
||||||
_session_connect(jidp->fulljid, account->password, account->server, account->port, account->tls_policy);
|
connection_connect_main(jidp->fulljid, account->password, account->server, account->port, account->tls_policy);
|
||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -175,7 +172,7 @@ session_connect_with_details(const char *const jid, const char *const passwd, co
|
|||||||
// connect with fulljid
|
// connect with fulljid
|
||||||
log_info("Connecting without account, JID: %s", saved_details.jid);
|
log_info("Connecting without account, JID: %s", saved_details.jid);
|
||||||
|
|
||||||
return _session_connect(
|
return connection_connect_main(
|
||||||
saved_details.jid,
|
saved_details.jid,
|
||||||
passwd,
|
passwd,
|
||||||
saved_details.altdomain,
|
saved_details.altdomain,
|
||||||
@@ -427,36 +424,6 @@ _session_info_destroy(DiscoInfo *info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static jabber_conn_status_t
|
|
||||||
_session_connect(const char *const fulljid, const char *const passwd, const char *const altdomain, int port,
|
|
||||||
const char *const tls_policy)
|
|
||||||
{
|
|
||||||
assert(fulljid != NULL);
|
|
||||||
assert(passwd != NULL);
|
|
||||||
|
|
||||||
Jid *jid = jid_create(fulljid);
|
|
||||||
|
|
||||||
if (jid == NULL) {
|
|
||||||
log_error("Malformed JID not able to connect: %s", fulljid);
|
|
||||||
connection_set_status(JABBER_DISCONNECTED);
|
|
||||||
return connection_get_status();
|
|
||||||
} else if (jid->fulljid == NULL) {
|
|
||||||
log_error("Full JID required to connect, received: %s", fulljid);
|
|
||||||
connection_set_status(JABBER_DISCONNECTED);
|
|
||||||
jid_destroy(jid);
|
|
||||||
return connection_get_status();
|
|
||||||
}
|
|
||||||
|
|
||||||
jid_destroy(jid);
|
|
||||||
|
|
||||||
log_info("Connecting as %s", fulljid);
|
|
||||||
char *cert_path = prefs_get_string(PREF_TLS_CERTPATH);
|
|
||||||
jabber_conn_status_t status = connection_connect(fulljid, passwd, altdomain, port, tls_policy, cert_path);
|
|
||||||
prefs_free_string(cert_path);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_session_reconnect(void)
|
_session_reconnect(void)
|
||||||
{
|
{
|
||||||
@@ -468,7 +435,7 @@ _session_reconnect(void)
|
|||||||
} else {
|
} else {
|
||||||
char *fulljid = create_fulljid(account->jid, account->resource);
|
char *fulljid = create_fulljid(account->jid, account->resource);
|
||||||
log_debug("Attempting reconnect with account %s", account->name);
|
log_debug("Attempting reconnect with account %s", account->name);
|
||||||
_session_connect(fulljid, saved_account.passwd, account->server, account->port, account->tls_policy);
|
connection_connect_main(fulljid, saved_account.passwd, account->server, account->port, account->tls_policy);
|
||||||
free(fulljid);
|
free(fulljid);
|
||||||
g_timer_start(reconnect_timer);
|
g_timer_start(reconnect_timer);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user