about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-01-26 21:03:04 +0000
committerJames Booth <boothj5@gmail.com>2013-01-26 21:03:04 +0000
commit4092498de8ccb03d5f119fbd3d10d4fd4e0e73de (patch)
treeebe6bbc63d4779a4f8a27e224608772ad44aaf71
parentc03a936789569d362ff41a3a6f56732de0267ec6 (diff)
downloadprofani-tty-4092498de8ccb03d5f119fbd3d10d4fd4e0e73de.tar.gz
Reverted some previous changes to fix login attempt and reconnect issues
fixes #142
fixes #143
-rw-r--r--src/connection.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/connection.c b/src/connection.c
index 226a00f0..d117f6ed 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -108,12 +108,20 @@ jabber_restart(void)
 jabber_conn_status_t
 jabber_connect_with_account(ProfAccount *account, const char * const passwd)
 {
-    FREE_SET_NULL(saved_user.account);
+    saved_user.account = strdup(account->name);
 
-    if (account->name == NULL)
-        return JABBER_UNDEFINED;
+    if (saved_user.jid == NULL) {
+        saved_user.jid = strdup(account->jid);
+    }
+    if (saved_user.passwd == NULL) {
+        saved_user.passwd = strdup(passwd);
+    }
+    if (saved_user.altdomain == NULL) {
+        if (account->server != NULL) {
+            saved_user.altdomain = strdup(account->server);
+        }
+    }
 
-    saved_user.account = strdup(account->name);
     log_info("Connecting with account: %s", account->name);
     return jabber_connect(account->jid, passwd, account->server);
 }
@@ -122,17 +130,22 @@ jabber_conn_status_t
 jabber_connect(const char * const jid,
     const char * const passwd, const char * const altdomain)
 {
-    FREE_SET_NULL(saved_user.jid);
-    FREE_SET_NULL(saved_user.passwd);
-    FREE_SET_NULL(saved_user.altdomain);
-
-    if (jid == NULL || passwd == NULL)
-        return JABBER_UNDEFINED;
+    if (saved_user.account != NULL) {
+        free(saved_user.account);
+        saved_user.account = NULL;
+    }
 
-    saved_user.jid = strdup(jid);
-    saved_user.passwd = strdup(passwd);
-    if (altdomain != NULL)
-        saved_user.altdomain = strdup(altdomain);
+    if (saved_user.jid == NULL) {
+        saved_user.jid = strdup(jid);
+    }
+    if (saved_user.passwd == NULL) {
+        saved_user.passwd = strdup(passwd);
+    }
+    if (saved_user.altdomain == NULL) {
+        if (altdomain != NULL) {
+            saved_user.altdomain = strdup(altdomain);
+        }
+    }
 
     log_info("Connecting as %s", jid);
     xmpp_initialize();