aboutsummaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorswirl <roachh@protonmail.com>2021-07-01 19:30:30 -0400
committerswirl <roachh@protonmail.com>2021-08-17 14:09:48 -0400
commitd9366a26d6ef1a82eeccd7d7523db25d91e4efc1 (patch)
treed3416bf02c3dca0c44b7702e65a3cb8ce8715c81 /src/command
parent4641537721df7e89090206802f623213a9abcb1a (diff)
downloadprofani-tty-d9366a26d6ef1a82eeccd7d7523db25d91e4efc1.tar.gz
initial register command test
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cmd_defs.c27
-rw-r--r--src/command/cmd_funcs.c65
-rw-r--r--src/command/cmd_funcs.h2
3 files changed, 94 insertions, 0 deletions
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 423de94e..8a08e236 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2642,6 +2642,32 @@ static struct cmd_t command_defs[] = {
CMD_NOEXAMPLES
},
+ { "/register",
+ parse_args, 2, 6, NULL,
+ CMD_NOSUBFUNCS
+ CMD_MAINFUNC(cmd_register)
+ CMD_TAGS(
+ CMD_TAG_CONNECTION)
+ CMD_SYN(
+ "/register <host> <username> [port <port>] [tls force|allow|trust|legacy|disable]")
+ CMD_DESC(
+ "Register an account on a server.")
+ CMD_ARGS(
+ { "<host>", "Server to register account on." },
+ { "<username>", "Username to register with." },
+ { "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 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." })
+ 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")
+ },
+
// NEXT-COMMAND (search helper)
};
@@ -3012,3 +3038,4 @@ command_mangen(void)
g_free(header);
g_list_free(cmds);
}
+
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 96b541b8..a00c6a46 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -9541,3 +9541,68 @@ cmd_silence(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
+
+gboolean
+cmd_register(ProfWin* window, const char* const command, gchar** args)
+{
+ gchar* opt_keys[] = { "port", "tls", NULL };
+ gboolean parsed;
+
+ GHashTable* options = parse_options(&args[2], opt_keys, &parsed);
+ if (!parsed) {
+ cons_bad_cmd_usage(command);
+ cons_show("");
+ options_destroy(options);
+ return TRUE;
+ }
+
+ char* tls_policy = g_hash_table_lookup(options, "tls");
+ if (tls_policy && (g_strcmp0(tls_policy, "force") != 0) && (g_strcmp0(tls_policy, "allow") != 0) && (g_strcmp0(tls_policy, "trust") != 0) && (g_strcmp0(tls_policy, "disable") != 0) && (g_strcmp0(tls_policy, "legacy") != 0)) {
+ cons_bad_cmd_usage(command);
+ cons_show("");
+ options_destroy(options);
+ return TRUE;
+ }
+
+ int port = 0;
+ if (g_hash_table_contains(options, "port")) {
+ char* port_str = g_hash_table_lookup(options, "port");
+ char* err_msg = NULL;
+ gboolean res = strtoi_range(port_str, &port, 1, 65535, &err_msg);
+ if (!res) {
+ cons_show(err_msg);
+ cons_show("");
+ free(err_msg);
+ port = 0;
+ options_destroy(options);
+ return TRUE;
+ }
+ }
+
+ char* host = args[0];
+
+ jabber_conn_status_t conn_status = connection_connect_raw(host, port, tls_policy, "default");
+
+ 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);
+ return TRUE;
+ }
+
+ char* username = args[1];
+ char* passwd = ui_ask_password(false);
+ char* confirm_passwd = ui_ask_password(true);
+
+ if (g_strcmp0(passwd, confirm_passwd) == 0) {
+ iq_register_new_account(username, passwd);
+ } else {
+ cons_show("The two passwords do not match.");
+ }
+
+ free(username);
+ free(passwd);
+ free(confirm_passwd);
+
+ return TRUE;
+}
+
diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h
index 54cc6e78..dee71371 100644
--- a/src/command/cmd_funcs.h
+++ b/src/command/cmd_funcs.h
@@ -247,5 +247,7 @@ gboolean cmd_executable_editor(ProfWin* window, const char* const command, gchar
gboolean cmd_mam(ProfWin* window, const char* const command, gchar** args);
gboolean cmd_editor(ProfWin* window, const char* const command, gchar** args);
gboolean cmd_silence(ProfWin* window, const char* const command, gchar** args);
+gboolean cmd_register(ProfWin* window, const char* const command, gchar** args);
#endif
+