From 144742cb701084cf143b7d996e05e3b3e5449758 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 24 Feb 2022 11:41:53 +0100 Subject: ox: add autocomplete for /ox announce --- src/command/cmd_ac.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/command') diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 81597a2d..6d5c67db 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -2589,6 +2589,10 @@ _ox_autocomplete(ProfWin* window, const char* const input, gboolean previous) return found; } + if (strncmp(input, "/ox announce ", 13) == 0) { + return cmd_ac_complete_filepath(input, "/ox announce", previous); + } + gboolean result; gchar** args = parse_args(input, 2, 3, &result); if ((strncmp(input, "/ox", 4) == 0) && (result == TRUE)) { -- cgit From 6d17b36605292a0eda148178677f72819c80b6fe Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 24 Feb 2022 11:57:25 +0100 Subject: ox: expand file and check for existance before trying to announce Output before: ``` 11:00:00 - Annonuce OpenPGP Key for OX ~/test/testuser.pub.gpg ... ``` After: ``` 11:00:00 - Annonuce OpenPGP Key for OX /home/user/test/testuser.pub.gpg ... ``` Now we expand the path so that we can check for `~` properly. And test if the file is actually a normal file. --- src/command/cmd_funcs.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/command') diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 4b79b145..0219b61f 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -7613,7 +7613,22 @@ cmd_ox(ProfWin* window, const char* const command, gchar** args) return TRUE; } else if (g_strcmp0(args[0], "announce") == 0) { if (args[1]) { - ox_announce_public_key(args[1]); + gchar* filename = get_expanded_path(args[1]); + + if (access(filename, R_OK) != 0) { + cons_show_error("File not found: %s", filename); + g_free(filename); + return TRUE; + } + + if (!is_regular_file(filename)) { + cons_show_error("Not a file: %s", filename); + g_free(filename); + return TRUE; + } + + ox_announce_public_key(filename); + free(filename); } else { cons_show("Filename is required"); } -- cgit From 62eedb1cd592e18a3bf6ac185ae86257233a12cc Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 24 Feb 2022 12:02:13 +0100 Subject: Fix memleak in cmd_export --- src/command/cmd_funcs.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/command') diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 0219b61f..be469c28 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -1101,6 +1101,7 @@ cmd_export(ProfWin* window, const char* const command, gchar** args) char* path = get_expanded_path(args[0]); fd = open(path, O_WRONLY | O_CREAT, 00600); + free(path); if (-1 == fd) { cons_show("error: cannot open %s: %s", args[0], strerror(errno)); -- cgit From a086d3cd16a39ace45fac46763811081293207de Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Fri, 25 Feb 2022 20:07:47 +0100 Subject: Remove useless comment --- src/command/cmd_ac.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/command') diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 6d5c67db..da961aae 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -2553,11 +2553,6 @@ _pgp_autocomplete(ProfWin* window, const char* const input, gboolean previous) return NULL; } -/*! - * \brief Auto completion for XEP-0373: OpenPGP for XMPP command. - * - * - */ static char* _ox_autocomplete(ProfWin* window, const char* const input, gboolean previous) { -- cgit From cdb8383260ce132e1b4784841727a4b210688b91 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Fri, 25 Feb 2022 20:09:09 +0100 Subject: Remove strange block from ox autocomplete Not sure what this should do. Can't see what kind of key we want to complete here. `/ox help` also doesn't list anything that needs a key. --- src/command/cmd_ac.c | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'src/command') diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index da961aae..9635211d 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -2588,24 +2588,6 @@ _ox_autocomplete(ProfWin* window, const char* const input, gboolean previous) return cmd_ac_complete_filepath(input, "/ox announce", previous); } - gboolean result; - gchar** args = parse_args(input, 2, 3, &result); - if ((strncmp(input, "/ox", 4) == 0) && (result == TRUE)) { - GString* beginning = g_string_new("/ox "); - g_string_append(beginning, args[0]); - if (args[1]) { - g_string_append(beginning, " "); - g_string_append(beginning, args[1]); - } - found = autocomplete_param_with_func(input, beginning->str, p_gpg_autocomplete_key, previous, NULL); - g_string_free(beginning, TRUE); - if (found) { - g_strfreev(args); - return found; - } - } - g_strfreev(args); - if (conn_status == JABBER_CONNECTED) { found = autocomplete_param_with_func(input, "/ox setkey", roster_barejid_autocomplete, previous, NULL); if (found) { -- cgit