about summary refs log tree commit diff stats
path: root/src/command/commands.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-01-18 01:45:05 +0000
committerJames Booth <boothj5@gmail.com>2014-01-18 01:45:05 +0000
commite7013408e5640cd41524a17c6f8f112eef1b54da (patch)
tree07f9e1aa8adb2f4bb2b0f5073f15c2621dc048d3 /src/command/commands.c
parentb1de8a400525e685b1e1d24fcb790d523bcacecd (diff)
downloadprofani-tty-e7013408e5640cd41524a17c6f8f112eef1b54da.tar.gz
WIP - Adding port to account options
Diffstat (limited to 'src/command/commands.c')
-rw-r--r--src/command/commands.c68
1 files changed, 65 insertions, 3 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index b1bbfce8..8a6f6d7b 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -69,10 +69,72 @@ cmd_connect(gchar **args, struct cmd_help_t help)
         result = TRUE;
     } else {
         char *user = args[0];
-        char *altdomain = args[1];
+        char *opt1 = args[1];
+        char *opt1val = args[2];
+        char *opt2 = args[3];
+        char *opt2val = args[4];
         char *lower = g_utf8_strdown(user, -1);
         char *jid;
 
+        // parse options
+        char *altdomain = NULL;
+        int port = 0;
+        gboolean altdomain_set = FALSE;
+        gboolean port_set = FALSE;
+        if (opt1 != NULL) {
+            if (opt1val == NULL) {
+                cons_show("Usage: %s", help.usage);
+                cons_show("");
+                return TRUE;
+            }
+            if (strcmp(opt1, "server") == 0) {
+                altdomain = opt1val;
+                altdomain_set = TRUE;
+            } else if (strcmp(opt1, "port") == 0) {
+                if (_strtoi(opt1val, &port, 1, 65536) != 0) {
+                    port = 0;
+                    cons_show("Port must be in the range 1 to 65535.");
+                } else {
+                    port_set = TRUE;
+                }
+            } else {
+                cons_show("Usage: %s", help.usage);
+                cons_show("");
+                return TRUE;
+            }
+
+            if (opt2 != NULL) {
+                if (opt2val == NULL) {
+                    cons_show("Usage: %s", help.usage);
+                    cons_show("");
+                    return TRUE;
+                }
+                if (strcmp(opt2, "server") == 0) {
+                    if (altdomain_set) {
+                        cons_show("Usage: %s", help.usage);
+                        return TRUE;
+                    }
+                    altdomain = opt2val;
+                    altdomain_set = TRUE;
+                } else if (strcmp(opt2, "port") == 0) {
+                    if (port_set) {
+                        cons_show("Usage: %s", help.usage);
+                        return TRUE;
+                    }
+                    if (_strtoi(opt2val, &port, 1, 65536) != 0) {
+                        port = 0;
+                        cons_show("Port must be in the range 1 to 65535.");
+                    } else {
+                        port_set = TRUE;
+                    }
+                } else {
+                    cons_show("Usage: %s", help.usage);
+                    cons_show("");
+                    return TRUE;
+                }
+            }
+        }
+
         ProfAccount *account = accounts_get_account(lower);
         if (account != NULL) {
             jid = accounts_create_full_jid(account);
@@ -86,7 +148,7 @@ cmd_connect(gchar **args, struct cmd_help_t help)
             char *passwd = ui_ask_password();
             jid = strdup(lower);
             cons_show("Connecting as %s", jid);
-            conn_status = jabber_connect_with_details(jid, passwd, altdomain);
+            conn_status = jabber_connect_with_details(jid, passwd, altdomain, port);
             free(passwd);
         }
         g_free(lower);
@@ -140,7 +202,7 @@ cmd_account(gchar **args, struct cmd_help_t help)
         if (account_name == NULL) {
             cons_show("Usage: %s", help.usage);
         } else {
-            accounts_add(account_name, NULL);
+            accounts_add(account_name, NULL, 0);
             cons_show("Account created.");
             cons_show("");
         }