about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-11-22 00:39:52 +0000
committerJames Booth <boothj5@gmail.com>2016-11-22 00:39:52 +0000
commite043029a5069a30e8a7154a07d46260bece6358c (patch)
tree8e5affaa094513ae5d9c8c0c082f20f57e83629c /src/xmpp
parentc441dbfa42e58796f87fdcbb02ee4aa19cca2469 (diff)
downloadprofani-tty-e043029a5069a30e8a7154a07d46260bece6358c.tar.gz
Allow clearing account resource
issue #880
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/connection.c28
-rw-r--r--src/xmpp/jid.c4
-rw-r--r--src/xmpp/jid.h2
-rw-r--r--src/xmpp/session.c27
4 files changed, 37 insertions, 24 deletions
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 4e0ca9a8..2c74f1e4 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -108,26 +108,21 @@ connection_shutdown(void)
 }
 
 jabber_conn_status_t
-connection_connect(const char *const fulljid, const char *const passwd, const char *const altdomain, int port,
+connection_connect(const char *const jid, const char *const passwd, const char *const altdomain, int port,
     const char *const tls_policy)
 {
-    assert(fulljid != NULL);
+    assert(jid != NULL);
     assert(passwd != NULL);
 
-    Jid *jid = jid_create(fulljid);
-    if (jid == NULL) {
-        log_error("Malformed JID not able to connect: %s", fulljid);
+    Jid *jidp = jid_create(jid);
+    if (jidp == NULL) {
+        log_error("Malformed JID not able to connect: %s", jid);
         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);
+    jid_destroy(jidp);
 
-    log_info("Connecting as %s", fulljid);
+    log_info("Connecting as %s", jid);
 
     if (conn.xmpp_log) {
         free(conn.xmpp_log);
@@ -150,7 +145,7 @@ connection_connect(const char *const fulljid, const char *const passwd, const ch
         log_warning("Failed to get libstrophe conn during connect");
         return JABBER_DISCONNECTED;
     }
-    xmpp_conn_set_jid(conn.xmpp_conn, fulljid);
+    xmpp_conn_set_jid(conn.xmpp_conn, jid);
     xmpp_conn_set_pass(conn.xmpp_conn, passwd);
 
     if (!tls_policy || (g_strcmp0(tls_policy, "force") == 0)) {
@@ -349,7 +344,12 @@ connection_get_ctx(void)
 const char*
 connection_get_fulljid(void)
 {
-    return xmpp_conn_get_jid(conn.xmpp_conn);
+    const char *jid = xmpp_conn_get_bound_jid(conn.xmpp_conn);
+    if (jid) {
+        return jid;
+    } else {
+        return xmpp_conn_get_jid(conn.xmpp_conn);
+    }
 }
 
 GHashTable*
diff --git a/src/xmpp/jid.c b/src/xmpp/jid.c
index 7289ca4c..135a21df 100644
--- a/src/xmpp/jid.c
+++ b/src/xmpp/jid.c
@@ -106,10 +106,10 @@ jid_create(const gchar *const str)
 }
 
 Jid*
-jid_create_from_bare_and_resource(const char *const room, const char *const nick)
+jid_create_from_bare_and_resource(const char *const barejid, const char *const resource)
 {
     Jid *result;
-    char *jid = create_fulljid(room, nick);
+    char *jid = create_fulljid(barejid, resource);
     result = jid_create(jid);
     free(jid);
 
diff --git a/src/xmpp/jid.h b/src/xmpp/jid.h
index d82c3add..16e6e78b 100644
--- a/src/xmpp/jid.h
+++ b/src/xmpp/jid.h
@@ -49,7 +49,7 @@ struct jid_t {
 typedef struct jid_t Jid;
 
 Jid* jid_create(const gchar *const str);
-Jid* jid_create_from_bare_and_resource(const char *const room, const char *const nick);
+Jid* jid_create_from_bare_and_resource(const char *const barejid, const char *const resource);
 void jid_destroy(Jid *jid);
 
 gboolean jid_is_valid_room_form(Jid *jid);
diff --git a/src/xmpp/session.c b/src/xmpp/session.c
index 95930802..032ca77a 100644
--- a/src/xmpp/session.c
+++ b/src/xmpp/session.c
@@ -118,15 +118,22 @@ session_connect_with_account(const ProfAccount *const account)
     }
     saved_account.passwd = strdup(account->password);
 
-    // connect with fulljid
-    Jid *jidp = jid_create_from_bare_and_resource(account->jid, account->resource);
+    char *jid = NULL;
+    if (account->resource) {
+        Jid *jidp = jid_create_from_bare_and_resource(account->jid, account->resource);
+        jid = strdup(jidp->fulljid);
+        jid_destroy(jidp);
+    } else {
+        jid = strdup(account->jid);
+    }
+
     jabber_conn_status_t result = connection_connect(
-        jidp->fulljid,
+        jid,
         account->password,
         account->server,
         account->port,
         account->tls_policy);
-    jid_destroy(jidp);
+    free(jid);
 
     return result;
 }
@@ -499,10 +506,16 @@ _session_reconnect(void)
         return;
     }
 
-    char *fulljid = create_fulljid(account->jid, account->resource);
+    char *jid = NULL;
+    if (account->resource) {
+        jid = create_fulljid(account->jid, account->resource);
+    } else {
+        jid = strdup(account->jid);
+    }
+
     log_debug("Attempting reconnect with account %s", account->name);
-    connection_connect(fulljid, saved_account.passwd, account->server, account->port, account->tls_policy);
-    free(fulljid);
+    connection_connect(jid, saved_account.passwd, account->server, account->port, account->tls_policy);
+    free(jid);
     account_free(account);
     g_timer_start(reconnect_timer);
 }