about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorswirl <roachh@protonmail.com>2021-07-01 21:29:09 -0400
committerswirl <roachh@protonmail.com>2021-08-17 14:09:48 -0400
commit5ea1ccbb468bd6c1195cb85fe29ac664e74436e7 (patch)
tree7521d0ae7768ed04df429903e39ec1465b964752
parentd9366a26d6ef1a82eeccd7d7523db25d91e4efc1 (diff)
downloadprofani-tty-5ea1ccbb468bd6c1195cb85fe29ac664e74436e7.tar.gz
/register: parameter updates
add auth param, switch host and username params, rename host param to server
-rw-r--r--src/command/cmd_defs.c18
-rw-r--r--src/command/cmd_funcs.c20
2 files changed, 24 insertions, 14 deletions
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 8a08e236..80d98827 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2649,23 +2649,25 @@ static struct cmd_t command_defs[] = {
       CMD_TAGS(
               CMD_TAG_CONNECTION)
       CMD_SYN(
-              "/register <host> <username> [port <port>] [tls force|allow|trust|legacy|disable]")
+              "/register <username> <server> [port <port>] [tls force|allow|trust|legacy|disable] [auth default|legacy]")
       CMD_DESC(
               "Register an account on a server.")
       CMD_ARGS(
-              { "<host>", "Server to register account on." },
               { "<username>", "Username to register with." },
+              { "<server>", "Server to register account on." },
               { "port <port>", "The port to use if different to the default (5222, or 5223 for SSL)." },
               { "tls force", "Force TLS connection, and fail if one cannot be established. This is the default behavior." },
               { "tls allow", "Use TLS for the connection if it is available." },
-              { "tls trust", "Force TLS connection and trust server's certificate." },
+              { "tls trust", "Force TLS connection and trust the server's certificate." },
               { "tls legacy", "Use legacy TLS for the connection. This forces TLS just after the TCP connection is established. Use when a server doesn't support STARTTLS." },
-              { "tls disable", "Disable TLS for the connection." })
+              { "tls disable", "Disable TLS for the connection." },
+              { "auth default", "Default authentication process." },
+              { "auth legacy", "Allow legacy authentication." })
       CMD_EXAMPLES(
-              "/register valhalla.edda odin",
-              "/register vanaheimr.edda freyr port 5678",
-              "/register 127.0.0.1 me tls disable",
-              "/register my.xmppserv.er someuser port 5443 tls force")
+              "/register odin valhalla.edda ",
+              "/register freyr vanaheimr.edda port 5678",
+              "/register me 127.0.0.1 tls disable",
+              "/register someuser my.xmppserv.er port 5443 tls force")
     },
 
     // NEXT-COMMAND (search helper)
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index a00c6a46..68eec91b 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -9545,7 +9545,7 @@ cmd_silence(ProfWin* window, const char* const command, gchar** args)
 gboolean
 cmd_register(ProfWin* window, const char* const command, gchar** args)
 {
-    gchar* opt_keys[] = { "port", "tls", NULL };
+    gchar* opt_keys[] = { "port", "tls", "auth", NULL };
     gboolean parsed;
 
     GHashTable* options = parse_options(&args[2], opt_keys, &parsed);
@@ -9579,17 +9579,25 @@ cmd_register(ProfWin* window, const char* const command, gchar** args)
         }
     }
 
-    char* host = args[0];
+    char* auth_policy = g_hash_table_lookup(options, "auth");
+    if (auth_policy && (g_strcmp0(auth_policy, "default") != 0) && (g_strcmp0(auth_policy, "legacy") != 0)) {
+        cons_bad_cmd_usage(command);
+        cons_show("");
+        options_destroy(options);
+        return TRUE;
+    }
+
+    char* server = args[1];
 
-    jabber_conn_status_t conn_status = connection_connect_raw(host, port, tls_policy, "default");
+    jabber_conn_status_t conn_status = connection_connect_raw(server, port, tls_policy, auth_policy);
 
     if (conn_status == JABBER_DISCONNECTED) {
-        cons_show_error("Connection attempt to server %s port %d failed.", host, port);
-        log_info("Connection attempt to server %s port %d failed.", host, port);
+        cons_show_error("Connection attempt to server %s port %d failed.", server, port);
+        log_info("Connection attempt to server %s port %d failed.", server, port);
         return TRUE;
     }
 
-    char* username = args[1];
+    char* username = args[0];
     char* passwd = ui_ask_password(false);
     char* confirm_passwd = ui_ask_password(true);