From b1b6c6f62d69fb366fb347cb7e78a7791107f456 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 5 Dec 2022 10:25:57 +0100 Subject: [PATCH 01/10] add `/strophe` command to modify libstrophe-specific settings Signed-off-by: Steffen Jaeckel --- src/command/cmd_ac.c | 39 +++++++++++++++++++++++++++++++++ src/command/cmd_defs.c | 19 ++++++++++++++++ src/command/cmd_funcs.c | 35 ++++++++++++++++++++++++++++++ src/command/cmd_funcs.h | 1 + src/common.c | 42 +++++++++++++++++++++++++++--------- src/common.h | 9 +++++++- src/config/preferences.c | 19 +++++++++++++--- src/config/preferences.h | 7 ++++-- src/ui/console.c | 16 ++++++++++++++ src/ui/ui.h | 1 + src/xmpp/connection.c | 24 +++++++++++++++------ tests/unittests/ui/stub_ui.c | 5 +++++ 12 files changed, 194 insertions(+), 23 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index f0210713..e8d0680a 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -131,6 +131,7 @@ static char* _executable_autocomplete(ProfWin* window, const char* const input, static char* _lastactivity_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _intype_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _mood_autocomplete(ProfWin* window, const char* const input, gboolean previous); +static char* _strophe_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _adhoc_cmd_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _vcard_autocomplete(ProfWin* window, const char* const input, gboolean previous); @@ -276,6 +277,9 @@ static Autocomplete executable_ac; static Autocomplete intype_ac; static Autocomplete mood_ac; static Autocomplete mood_type_ac; +static Autocomplete strophe_ac; +static Autocomplete strophe_sm_ac; +static Autocomplete strophe_verbosity_ac; static Autocomplete adhoc_cmd_ac; static Autocomplete lastactivity_ac; static Autocomplete vcard_ac; @@ -1098,6 +1102,19 @@ cmd_ac_init(void) autocomplete_add(intype_ac, "console"); autocomplete_add(intype_ac, "titlebar"); + strophe_ac = autocomplete_new(); + autocomplete_add(strophe_ac, "sm"); + autocomplete_add(strophe_ac, "verbosity"); + strophe_sm_ac = autocomplete_new(); + autocomplete_add(strophe_sm_ac, "on"); + autocomplete_add(strophe_sm_ac, "no-resend"); + autocomplete_add(strophe_sm_ac, "off"); + strophe_verbosity_ac = autocomplete_new(); + autocomplete_add(strophe_verbosity_ac, "0"); + autocomplete_add(strophe_verbosity_ac, "1"); + autocomplete_add(strophe_verbosity_ac, "2"); + autocomplete_add(strophe_verbosity_ac, "3"); + mood_ac = autocomplete_new(); autocomplete_add(mood_ac, "set"); autocomplete_add(mood_ac, "clear"); @@ -1595,6 +1612,9 @@ cmd_ac_reset(ProfWin* window) autocomplete_reset(intype_ac); autocomplete_reset(mood_ac); autocomplete_reset(mood_type_ac); + autocomplete_reset(strophe_verbosity_ac); + autocomplete_reset(strophe_sm_ac); + autocomplete_reset(strophe_ac); autocomplete_reset(adhoc_cmd_ac); autocomplete_reset(vcard_ac); @@ -2057,6 +2077,7 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ g_hash_table_insert(ac_funcs, "/lastactivity", _lastactivity_autocomplete); g_hash_table_insert(ac_funcs, "/intype", _intype_autocomplete); g_hash_table_insert(ac_funcs, "/mood", _mood_autocomplete); + g_hash_table_insert(ac_funcs, "/strophe", _strophe_autocomplete); g_hash_table_insert(ac_funcs, "/cmd", _adhoc_cmd_autocomplete); g_hash_table_insert(ac_funcs, "/vcard", _vcard_autocomplete); @@ -4442,6 +4463,24 @@ _mood_autocomplete(ProfWin* window, const char* const input, gboolean previous) return result; } +static char* +_strophe_autocomplete(ProfWin* window, const char* const input, gboolean previous) +{ + char* result = NULL; + + result = autocomplete_param_with_ac(input, "/strophe sm", strophe_sm_ac, FALSE, previous); + if (result) { + return result; + } + + result = autocomplete_param_with_ac(input, "/strophe verbosity", strophe_verbosity_ac, FALSE, previous); + if (result) { + return result; + } + + return autocomplete_param_with_ac(input, "/strophe", strophe_ac, FALSE, previous); +} + static char* _adhoc_cmd_autocomplete(ProfWin* window, const char* const input, gboolean previous) { diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 0a2a7440..e65e2f00 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2862,6 +2862,25 @@ static struct cmd_t command_defs[] = { "/mood set amazed", "/mood clear") }, + + { "/strophe", + parse_args, 2, 2, &cons_strophe_setting, + CMD_NOSUBFUNCS + CMD_MAINFUNC(cmd_strophe) + CMD_TAGS( + CMD_TAG_CONNECTION) + CMD_SYN( + "/strophe verbosity 0-3", + "/strophe sm on|no-resend|off") + CMD_DESC( + "Modify libstrophe settings.") + CMD_ARGS( + { "verbosity 0-3", "Set libstrophe verbosity level when log level is 'DEBUG'." }, + { "sm on|no-resend|off", "Enable or disable Stream-Management (SM) as of XEP-0198. The 'no-resend' option enables SM, but won't re-send un-ACK'ed messages on re-connect." }) + CMD_EXAMPLES( + "/strophe verbosity 3", + "/strophe sm no-resend") + }, // NEXT-COMMAND (search helper) }; diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index da38f405..c0c0d036 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9856,6 +9856,41 @@ cmd_mood(ProfWin* window, const char* const command, gchar** args) return TRUE; } +gboolean +cmd_strophe(ProfWin* window, const char* const command, gchar** args) +{ + if (g_strcmp0(args[0], "verbosity") == 0) { + int verbosity; + auto_gchar gchar* err_msg = NULL; + if (string_to_verbosity(args[1], &verbosity, &err_msg)) { + xmpp_ctx_set_verbosity(connection_get_ctx(), verbosity); + prefs_set_string(PREF_STROPHE_VERBOSITY, args[1]); + return TRUE; + } else { + cons_show(err_msg); + } + } else if (g_strcmp0(args[0], "sm") == 0) { + if (g_strcmp0(args[1], "no-resend") == 0) { + cons_show("Stream Management set to 'no-resend'."); + prefs_set_boolean(PREF_STROPHE_SM_ENABLED, TRUE); + prefs_set_boolean(PREF_STROPHE_SM_RESEND, FALSE); + return TRUE; + } else if (g_strcmp0(args[1], "on") == 0) { + cons_show("Stream Management enabled."); + prefs_set_boolean(PREF_STROPHE_SM_ENABLED, TRUE); + prefs_set_boolean(PREF_STROPHE_SM_RESEND, TRUE); + return TRUE; + } else if (g_strcmp0(args[1], "off") == 0) { + cons_show("Stream Management disabled."); + prefs_set_boolean(PREF_STROPHE_SM_ENABLED, FALSE); + prefs_set_boolean(PREF_STROPHE_SM_RESEND, FALSE); + return TRUE; + } + } + cons_bad_cmd_usage(command); + return FALSE; +} + gboolean cmd_vcard(ProfWin* window, const char* const command, gchar** args) { diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index 597164f3..58f42a61 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -253,6 +253,7 @@ gboolean cmd_correct_editor(ProfWin* window, const char* const command, gchar** gboolean cmd_silence(ProfWin* window, const char* const command, gchar** args); gboolean cmd_register(ProfWin* window, const char* const command, gchar** args); gboolean cmd_mood(ProfWin* window, const char* const command, gchar** args); +gboolean cmd_strophe(ProfWin* window, const char* const command, gchar** args); gboolean cmd_stamp(ProfWin* window, const char* const command, gchar** args); gboolean cmd_vcard(ProfWin* window, const char* const command, gchar** args); gboolean cmd_vcard_add(ProfWin* window, const char* const command, gchar** args); diff --git a/src/common.c b/src/common.c index d00e096f..86fd5612 100644 --- a/src/common.c +++ b/src/common.c @@ -70,6 +70,28 @@ struct curl_data_t static size_t _data_callback(void* ptr, size_t size, size_t nmemb, void* data); +void +auto_free_gchar(gchar** str) +{ + if (str == NULL) + return; + g_free(*str); +} + +void +auto_free_char(char** str) +{ + if (str == NULL) + return; + free(*str); +} + +gboolean +string_to_verbosity(const char* cmd, int* verbosity, gchar** err_msg) +{ + return strtoi_range(cmd, verbosity, 0, 3, err_msg); +} + gboolean create_dir(const char* name) { @@ -136,24 +158,24 @@ str_replace(const char* string, const char* substr, } gboolean -strtoi_range(char* str, int* saveptr, int min, int max, char** err_msg) +strtoi_range(const char* str, int* saveptr, int min, int max, gchar** err_msg) { char* ptr; int val; - + if (str == NULL) { + if (err_msg) + *err_msg = g_strdup_printf("'str' input pointer can not be NULL"); + return FALSE; + } errno = 0; val = (int)strtol(str, &ptr, 0); if (errno != 0 || *str == '\0' || *ptr != '\0') { - GString* err_str = g_string_new(""); - g_string_printf(err_str, "Could not convert \"%s\" to a number.", str); - *err_msg = err_str->str; - g_string_free(err_str, FALSE); + if (err_msg) + *err_msg = g_strdup_printf("Could not convert \"%s\" to a number.", str); return FALSE; } else if (val < min || val > max) { - GString* err_str = g_string_new(""); - g_string_printf(err_str, "Value %s out of range. Must be in %d..%d.", str, min, max); - *err_msg = err_str->str; - g_string_free(err_str, FALSE); + if (err_msg) + *err_msg = g_strdup_printf("Value %s out of range. Must be in %d..%d.", str, min, max); return FALSE; } diff --git a/src/common.h b/src/common.h index 27d1684d..7b30ec56 100644 --- a/src/common.h +++ b/src/common.h @@ -47,6 +47,11 @@ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +void auto_free_gchar(gchar** str); +#define auto_gchar __attribute__((__cleanup__(auto_free_gchar))) +void auto_free_char(char** str); +#define auto_char __attribute__((__cleanup__(auto_free_char))) + // assume malloc stores at most 8 bytes for size of allocated memory // and page size is at least 4KB #define READ_BUF_SIZE 4088 @@ -80,10 +85,12 @@ typedef enum { RESOURCE_XA } resource_presence_t; +gboolean string_to_verbosity(const char* cmd, int* verbosity, gchar** err_msg); + gboolean create_dir(const char* name); gboolean copy_file(const char* const src, const char* const target, const gboolean overwrite_existing); char* str_replace(const char* string, const char* substr, const char* replacement); -gboolean strtoi_range(char* str, int* saveptr, int min, int max, char** err_msg); +gboolean strtoi_range(const char* str, int* saveptr, int min, int max, char** err_msg); int utf8_display_len(const char* const str); char* release_get_latest(void); diff --git a/src/config/preferences.c b/src/config/preferences.c index de455245..f15952cd 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -533,7 +533,7 @@ prefs_set_boolean(preference_t pref, gboolean value) g_key_file_set_boolean(prefs, group, key, value); } -char* +gchar* prefs_get_string(preference_t pref) { const char* group = _get_group(pref); @@ -553,14 +553,14 @@ prefs_get_string(preference_t pref) } } -char* +gchar* prefs_get_string_with_option(preference_t pref, gchar* option) { const char* group = _get_group(pref); const char* key = _get_key(pref); char* def = _get_default_string(pref); - char* result = g_key_file_get_locale_string(prefs, group, key, option, NULL); + gchar* result = g_key_file_get_locale_string(prefs, group, key, option, NULL); if (result == NULL) { // check for user set default @@ -1869,6 +1869,9 @@ _get_group(preference_t pref) case PREF_CORRECTION_ALLOW: case PREF_MAM: case PREF_SILENCE_NON_ROSTER: + case PREF_STROPHE_VERBOSITY: + case PREF_STROPHE_SM_ENABLED: + case PREF_STROPHE_SM_RESEND: return PREF_GROUP_CONNECTION; case PREF_OTR_LOG: case PREF_OTR_POLICY: @@ -2165,6 +2168,12 @@ _get_key(preference_t pref) return "mood"; case PREF_VCARD_PHOTO_CMD: return "vcard.photo.cmd"; + case PREF_STROPHE_VERBOSITY: + return "strophe.verbosity"; + case PREF_STROPHE_SM_ENABLED: + return "strophe.sm.enabled"; + case PREF_STROPHE_SM_RESEND: + return "strophe.sm.resend"; default: return NULL; } @@ -2217,6 +2226,8 @@ _get_default_boolean(preference_t pref) case PREF_INTYPE_CONSOLE: case PREF_NOTIFY_MENTION_WHOLE_WORD: case PREF_MOOD: + case PREF_STROPHE_SM_ENABLED: + case PREF_STROPHE_SM_RESEND: return TRUE; default: return FALSE; @@ -2316,6 +2327,8 @@ _get_default_string(preference_t pref) return NULL; // Default to built-in method. case PREF_OX_LOG: return "on"; + case PREF_STROPHE_VERBOSITY: + return "0"; default: return NULL; } diff --git a/src/config/preferences.h b/src/config/preferences.h index 95a84865..ca8acea4 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -182,6 +182,9 @@ typedef enum { PREF_NOTIFY_ROOM_OFFLINE, PREF_OX_LOG, PREF_MOOD, + PREF_STROPHE_VERBOSITY, + PREF_STROPHE_SM_ENABLED, + PREF_STROPHE_SM_RESEND, PREF_VCARD_PHOTO_CMD, } preference_t; @@ -329,8 +332,8 @@ void prefs_save_win_placement(ProfWinPlacement* placement); gboolean prefs_get_boolean(preference_t pref); void prefs_set_boolean(preference_t pref, gboolean value); -char* prefs_get_string(preference_t pref); -char* prefs_get_string_with_option(preference_t pref, gchar* option); +gchar* prefs_get_string(preference_t pref); +gchar* prefs_get_string_with_option(preference_t pref, gchar* option); void prefs_set_string(preference_t pref, char* value); void prefs_set_string_with_option(preference_t pref, char* option, char* value); void prefs_set_string_list_with_option(preference_t pref, char* option, const gchar* const* values); diff --git a/src/ui/console.c b/src/ui/console.c index 5937a42a..b1720415 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2311,6 +2311,7 @@ cons_show_connection_prefs(void) cons_autoping_setting(); cons_autoconnect_setting(); cons_rooms_cache_setting(); + cons_strophe_setting(); cons_alert(NULL); } @@ -2994,3 +2995,18 @@ cons_mood_setting(void) cons_show("Display user mood (/mood) : OFF"); } } + +void +cons_strophe_setting(void) +{ + const char* sm_setting = "OFF"; + if (prefs_get_boolean(PREF_STROPHE_SM_ENABLED)) { + if (prefs_get_boolean(PREF_STROPHE_SM_RESEND)) { + sm_setting = "ON"; + } else { + sm_setting = "NO-RESEND"; + } + } + cons_show("XEP-0198 Stream-Management : %s", sm_setting); + cons_show("libstrophe Verbosity : %s", prefs_get_string(PREF_STROPHE_VERBOSITY)); +} diff --git a/src/ui/ui.h b/src/ui/ui.h index 94d1c716..d9534ed5 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -341,6 +341,7 @@ void cons_slashguard_setting(void); void cons_mam_setting(void); void cons_silence_setting(void); void cons_mood_setting(void); +void cons_strophe_setting(void); void cons_show_contact_online(PContact contact, Resource* resource, GDateTime* last_activity); void cons_show_contact_offline(PContact contact, char* resource, char* status); void cons_theme_properties(void); diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 2de4a842..d57a1376 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -140,6 +140,14 @@ connection_init(void) conn.requested_features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL); conn.xmpp_ctx = xmpp_ctx_new(&prof_mem, &prof_log); + auto_gchar gchar* v = prefs_get_string(PREF_STROPHE_VERBOSITY); + auto_gchar gchar* err_msg = NULL; + int verbosity; + if (string_to_verbosity(v, &verbosity, &err_msg)) { + xmpp_ctx_set_verbosity(conn.xmpp_ctx, verbosity); + } else { + cons_show(err_msg); + } conn.xmpp_conn = xmpp_conn_new(conn.xmpp_ctx); _random_bytes_init(); @@ -1000,13 +1008,15 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status // lost connection for unknown reason if (conn.conn_status == JABBER_CONNECTED) { - int send_queue_len = xmpp_conn_send_queue_len(conn.xmpp_conn); - log_debug("Connection handler: Lost connection for unknown reason"); - conn.sm_state = xmpp_conn_get_sm_state(conn.xmpp_conn); - if (send_queue_len > 0) { - conn.queued_messages = calloc(send_queue_len + 1, sizeof(*conn.queued_messages)); - for (int n = 0; n < send_queue_len && conn.queued_messages[n]; ++n) { - conn.queued_messages[n] = xmpp_conn_send_queue_drop_element(conn.xmpp_conn, XMPP_QUEUE_OLDEST); + if (prefs_get_boolean(PREF_STROPHE_SM_ENABLED)) { + int send_queue_len = xmpp_conn_send_queue_len(conn.xmpp_conn); + log_debug("Connection handler: Lost connection for unknown reason"); + conn.sm_state = xmpp_conn_get_sm_state(conn.xmpp_conn); + if (send_queue_len > 0 && prefs_get_boolean(PREF_STROPHE_SM_RESEND)) { + conn.queued_messages = calloc(send_queue_len + 1, sizeof(*conn.queued_messages)); + for (int n = 0; n < send_queue_len && conn.queued_messages[n]; ++n) { + conn.queued_messages[n] = xmpp_conn_send_queue_drop_element(conn.xmpp_conn, XMPP_QUEUE_OLDEST); + } } } session_lost_connection(); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 204a8c35..d8272aab 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -1155,6 +1155,11 @@ cons_mood_setting(void) { } +void +cons_strophe_setting(void) +{ +} + void cons_show_bookmarks_ignore(gchar** list, gsize len) { From e9aaba938b4f1b62b5f9018583a82ed7e7180977 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 14 Nov 2022 15:51:05 +0100 Subject: [PATCH 02/10] minor changes * fix typo * less code duplication * less `GString` usage * more `auto_gchar` usage * document connecting to servers supporting SASL ANONYMOUS * ignore valgrind output Signed-off-by: Steffen Jaeckel --- .gitignore | 3 +++ src/command/cmd_defs.c | 12 ++++++--- src/command/cmd_funcs.c | 32 +++++++++------------- src/log.c | 18 ++++++++----- src/log.h | 2 +- src/profanity.c | 3 ++- src/tools/autocomplete.c | 49 +++++++--------------------------- tests/unittests/log/stub_log.c | 6 ++--- 8 files changed, 49 insertions(+), 76 deletions(-) diff --git a/.gitignore b/.gitignore index 446a3868..cc3402a9 100644 --- a/.gitignore +++ b/.gitignore @@ -55,6 +55,9 @@ tests/unittests/unittests.log tests/unittests/unittests.trs test-suite.log +# valgrind output +profval* + # local scripts clean-test.sh gen_docs.sh diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index e65e2f00..83dc1bbf 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -170,15 +170,18 @@ static struct cmd_t command_defs[] = { CMD_TAG_CONNECTION) CMD_SYN( "/connect []", - "/connect [server ] [port ] [tls force|allow|trust|legacy|disable] [auth default|legacy]") + "/connect [server ] [port ] [tls force|allow|trust|legacy|disable] [auth default|legacy]", + "/connect ") CMD_DESC( "Login to a chat service. " "If no account is specified, the default is used if one is configured. " - "A local account is created with the JID as it's name if it doesn't already exist.") + "A local account is created with the JID as it's name if it doesn't already exist. " + "In case you want to connect to a server via SASL ANONYMOUS (c.f. XEP-0175) you can also do that.") CMD_ARGS( { "", "The local account you wish to connect with, or a JID if connecting for the first time." }, { "server ", "Supply a server if it is different to the domain part of your JID." }, { "port ", "The port to use if different to the default (5222, or 5223 for SSL)." }, + { "", "Connect to said server in an anonymous way. (Be aware: There aren't many servers that support this.)" }, { "tls force", "Force TLS connection, and fail if one cannot be established, this is default behaviour." }, { "tls allow", "Use TLS for the connection if it is available." }, { "tls trust", "Force TLS connection and trust server's certificate." }, @@ -192,7 +195,8 @@ static struct cmd_t command_defs[] = { "/connect odin@valhalla.edda server talk.google.com", "/connect freyr@vanaheimr.edda port 5678", "/connect me@localhost.test.org server 127.0.0.1 tls disable", - "/connect me@chatty server chatty.com port 5443") + "/connect me@chatty server chatty.com port 5443", + "/connect server.supporting.sasl.anonymous.example") }, { "/tls", @@ -2013,7 +2017,7 @@ static struct cmd_t command_defs[] = { { "rotate on|off", "Rotate log, default on. Does not take effect if you specified a filename yourself when starting Profanity." }, { "maxsize ", "With rotate enabled, specifies the max log size, defaults to 10485760 (10MB)." }, { "shared on|off", "Share logs between all instances, default: on. When off, the process id will be included in the log filename. Does not take effect if you specified a filename yourself when starting Profanity." }, - {"level INFO|DEBUG|WARN|EFFOR", "Set the log level. Default is INFO. Only works with default log file, not with user provided log file during startup via -f." }) + {"level INFO|DEBUG|WARN|ERROR", "Set the log level. Default is INFO. Only works with default log file, not with user provided log file during startup via -f." }) CMD_NOEXAMPLES }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index c0c0d036..795ea817 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -120,8 +120,8 @@ static void _update_presence(const resource_presence_t presence, const char* const show, gchar** args); -static void _cmd_set_boolean_preference(gchar* arg, const char* const command, - const char* const display, preference_t pref); +static gboolean _cmd_set_boolean_preference(gchar* arg, const char* const command, + const char* const display, preference_t pref); static void _who_room(ProfWin* window, const char* const command, gchar** args); static void _who_roster(ProfWin* window, const char* const command, gchar** args); static gboolean _cmd_execute(ProfWin* window, const char* const command, const char* const inp); @@ -6517,9 +6517,8 @@ cmd_log(ProfWin* window, const char* const command, gchar** args) } if (strcmp(subcmd, "level") == 0) { - if (g_strcmp0(value, "INFO") == 0 || g_strcmp0(value, "DEBUG") == 0 || g_strcmp0(value, "WARN") == 0 || g_strcmp0(value, "ERROR") == 0) { - - log_level_t prof_log_level = log_level_from_string(value); + log_level_t prof_log_level; + if (log_level_from_string(value, &prof_log_level) == 0) { log_close(); log_init(prof_log_level, NULL); @@ -8580,31 +8579,24 @@ _update_presence(const resource_presence_t resource_presence, } // helper function for boolean preference commands -static void +static gboolean _cmd_set_boolean_preference(gchar* arg, const char* const command, const char* const display, preference_t pref) { if (arg == NULL) { cons_bad_cmd_usage(command); - } else if (strcmp(arg, "on") == 0) { - GString* enabled = g_string_new(display); - g_string_append(enabled, " enabled."); - - cons_show(enabled->str); + return FALSE; + } else if (g_strcmp0(arg, "on") == 0) { + cons_show("%s enabled.", display); prefs_set_boolean(pref, TRUE); - - g_string_free(enabled, TRUE); - } else if (strcmp(arg, "off") == 0) { - GString* disabled = g_string_new(display); - g_string_append(disabled, " disabled."); - - cons_show(disabled->str); + } else if (g_strcmp0(arg, "off") == 0) { + cons_show("%s disabled.", display); prefs_set_boolean(pref, FALSE); - - g_string_free(disabled, TRUE); } else { cons_bad_cmd_usage(command); + return FALSE; } + return TRUE; } gboolean diff --git a/src/log.c b/src/log.c index 97c1a149..a1b7bb1d 100644 --- a/src/log.c +++ b/src/log.c @@ -233,21 +233,25 @@ log_msg(log_level_t level, const char* const area, const char* const msg) } } -log_level_t -log_level_from_string(char* log_level) +int +log_level_from_string(char* log_level, log_level_t* level) { + int ret = 0; assert(log_level != NULL); + assert(level != NULL); if (strcmp(log_level, "DEBUG") == 0) { - return PROF_LEVEL_DEBUG; + *level = PROF_LEVEL_DEBUG; } else if (strcmp(log_level, "INFO") == 0) { - return PROF_LEVEL_INFO; + *level = PROF_LEVEL_INFO; } else if (strcmp(log_level, "WARN") == 0) { - return PROF_LEVEL_WARN; + *level = PROF_LEVEL_WARN; } else if (strcmp(log_level, "ERROR") == 0) { - return PROF_LEVEL_ERROR; + *level = PROF_LEVEL_ERROR; } else { // default logging is warn - return PROF_LEVEL_WARN; + *level = PROF_LEVEL_WARN; + ret = -1; } + return ret; } const char* diff --git a/src/log.h b/src/log.h index 2a955c90..3bf092b3 100644 --- a/src/log.h +++ b/src/log.h @@ -55,7 +55,7 @@ void log_info(const char* const msg, ...); void log_warning(const char* const msg, ...); void log_error(const char* const msg, ...); void log_msg(log_level_t level, const char* const area, const char* const msg); -log_level_t log_level_from_string(char* log_level); +int log_level_from_string(char* log_level, log_level_t* level); const char* log_string_from_level(log_level_t level); void log_stderr_init(log_level_t level); diff --git a/src/profanity.c b/src/profanity.c index 49adc4a0..869ab561 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -175,7 +175,8 @@ _init(char* log_level, char* config_file, char* log_file, char* theme_name) pthread_mutex_lock(&lock); files_create_directories(); - log_level_t prof_log_level = log_level_from_string(log_level); + log_level_t prof_log_level; + log_level_from_string(log_level, &prof_log_level); prefs_load(config_file); log_init(prof_log_level, log_file); log_stderr_init(PROF_LEVEL_ERROR); diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index 9450b98f..2f1acc1f 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -367,34 +367,20 @@ char* autocomplete_param_no_with_func(const char* const input, char* command, int arg_number, autocomplete_func func, gboolean previous, void* context) { if (strncmp(input, command, strlen(command)) == 0) { - GString* result_str = NULL; - // count tokens properly int num_tokens = count_tokens(input); // if correct number of tokens, then candidate for autocompletion of last param if (num_tokens == arg_number) { - gchar* start_str = get_start(input, arg_number); - gchar* comp_str = g_strdup(&input[strlen(start_str)]); + auto_gchar gchar* start_str = get_start(input, arg_number); + auto_gchar gchar* comp_str = g_strdup(&input[strlen(start_str)]); // autocomplete param if (comp_str) { - char* found = func(comp_str, previous, context); + auto_gchar gchar* found = func(comp_str, previous, context); if (found) { - result_str = g_string_new(""); - g_string_append(result_str, start_str); - g_string_append(result_str, found); - - free(start_str); - free(comp_str); - - char* result = result_str->str; - g_string_free(result_str, FALSE); - - return result; + return g_strdup_printf("%s%s", start_str, found); } - } else { - free(start_str); } } } @@ -418,14 +404,12 @@ autocomplete_remove_older_than_max_reverse(Autocomplete ac, int maxsize) static gchar* _search(Autocomplete ac, GList* curr, gboolean quote, search_direction direction) { - gchar* search_str_ascii = g_str_to_ascii(ac->search_str, NULL); - gchar* search_str_lower = g_ascii_strdown(search_str_ascii, -1); - g_free(search_str_ascii); + auto_gchar gchar* search_str_ascii = g_str_to_ascii(ac->search_str, NULL); + auto_gchar gchar* search_str_lower = g_ascii_strdown(search_str_ascii, -1); while (curr) { - gchar* curr_ascii = g_str_to_ascii(curr->data, NULL); - gchar* curr_lower = g_ascii_strdown(curr_ascii, -1); - g_free(curr_ascii); + auto_gchar gchar* curr_ascii = g_str_to_ascii(curr->data, NULL); + auto_gchar gchar* curr_lower = g_ascii_strdown(curr_ascii, -1); // match found if (strncmp(curr_lower, search_str_lower, strlen(search_str_lower)) == 0) { @@ -435,27 +419,13 @@ _search(Autocomplete ac, GList* curr, gboolean quote, search_direction direction // if contains space, quote before returning if (quote && g_strrstr(curr->data, " ")) { - GString* quoted = g_string_new("\""); - g_string_append(quoted, curr->data); - g_string_append(quoted, "\""); - - gchar* result = quoted->str; - g_string_free(quoted, FALSE); - - g_free(search_str_lower); - g_free(curr_lower); - return result; - + return g_strdup_printf("\"%s\"", (gchar*)curr->data); // otherwise just return the string } else { - g_free(search_str_lower); - g_free(curr_lower); return strdup(curr->data); } } - g_free(curr_lower); - if (direction == PREVIOUS) { curr = g_list_previous(curr); } else { @@ -463,6 +433,5 @@ _search(Autocomplete ac, GList* curr, gboolean quote, search_direction direction } } - g_free(search_str_lower); return NULL; } diff --git a/tests/unittests/log/stub_log.c b/tests/unittests/log/stub_log.c index dfa2619a..18d05eca 100644 --- a/tests/unittests/log/stub_log.c +++ b/tests/unittests/log/stub_log.c @@ -67,10 +67,10 @@ get_log_file_location(void) return mock_ptr_type(char*); } -log_level_t -log_level_from_string(char* log_level) +int +log_level_from_string(char* log_level, log_level_t* level) { - return mock_type(log_level_t); + return mock_type(int); } void From a45f05a45e7daceab95af4daa0f661874a3bd057 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 20 Dec 2022 09:29:36 +0100 Subject: [PATCH 03/10] slightly improve `command_defs[]` * make the struct `const` * use designated initializers * remove `CMD_NOxyz` macros * fix function-pointer correctness of `sub_func[]` Signed-off-by: Steffen Jaeckel --- src/command/cmd_ac.c | 2 +- src/command/cmd_ac.h | 2 +- src/command/cmd_defs.c | 714 +++++++++++++++------------------------- src/command/cmd_funcs.c | 9 +- src/command/cmd_funcs.h | 6 +- 5 files changed, 272 insertions(+), 461 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index e8d0680a..559b3bda 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1315,7 +1315,7 @@ cmd_ac_add_help(const char* const value) } void -cmd_ac_add_cmd(Command* command) +cmd_ac_add_cmd(const Command* command) { autocomplete_add(commands_ac, command->cmd); autocomplete_add(help_ac, command->cmd + 1); diff --git a/src/command/cmd_ac.h b/src/command/cmd_ac.h index ef715310..ceab49b2 100644 --- a/src/command/cmd_ac.h +++ b/src/command/cmd_ac.h @@ -47,7 +47,7 @@ gboolean cmd_ac_exists(char* cmd); void cmd_ac_add(const char* const value); void cmd_ac_add_help(const char* const value); -void cmd_ac_add_cmd(Command* command); +void cmd_ac_add_cmd(const Command* command); void cmd_ac_add_alias(ProfAlias* alias); void cmd_ac_add_alias_value(char* value); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 83dc1bbf..6b494e1a 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -88,31 +88,14 @@ #define CMD_TAG_UI "ui" #define CMD_TAG_PLUGINS "plugins" -#define CMD_MAINFUNC(func) func, -#define CMD_NOMAINFUNC NULL, -#define CMD_SUBFUNCS(...) { __VA_ARGS__, { NULL, NULL } }, -#define CMD_NOSUBFUNCS { { NULL, NULL } }, - -#define CMD_NOTAGS \ - { \ - { NULL }, -#define CMD_TAGS(...) \ - { \ - { __VA_ARGS__, NULL }, -#define CMD_SYN(...) { __VA_ARGS__, NULL }, -#define CMD_DESC(desc) desc, -#define CMD_NOARGS { { NULL, NULL } }, -#define CMD_ARGS(...) { __VA_ARGS__, { NULL, NULL } }, -#define CMD_NOEXAMPLES \ - { \ - NULL \ - } \ - } -#define CMD_EXAMPLES(...) \ - { \ - __VA_ARGS__, NULL \ - } \ - } +#define CMD_PREAMBLE(c, p, min, max, set) .cmd = c, .parser = p, .min_args = min, .max_args = max, .setting_func = set, +#define CMD_MAINFUNC(f) .func = f, +#define CMD_SUBFUNCS(...) .sub_funcs = { __VA_ARGS__, { NULL, NULL } }, +#define CMD_TAGS(...) .help.tags = { __VA_ARGS__, NULL }, +#define CMD_SYN(...) .help.synopsis = { __VA_ARGS__, NULL }, +#define CMD_DESC(d) .help.desc = d, +#define CMD_ARGS(...) .help.args = { __VA_ARGS__, { NULL, NULL } }, +#define CMD_EXAMPLES(...) .help.examples = { __VA_ARGS__, NULL } GHashTable* commands = NULL; @@ -123,12 +106,10 @@ static gboolean _cmd_has_tag(Command* pcmd, const char* const tag); */ // clang-format off -static struct cmd_t command_defs[] = { - { "/help", - parse_args_with_freetext, 0, 2, NULL, - CMD_NOSUBFUNCS +static const struct cmd_t command_defs[] = { + { CMD_PREAMBLE("/help", + parse_args_with_freetext, 0, 2, NULL) CMD_MAINFUNC(cmd_help) - CMD_NOTAGS CMD_SYN( "/help [||search_all|search_any] []") CMD_DESC( @@ -149,22 +130,17 @@ static struct cmd_t command_defs[] = { "/help who") }, - { "/about", - parse_args, 0, 0, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/about", + parse_args, 0, 0, NULL) CMD_MAINFUNC(cmd_about) - CMD_NOTAGS CMD_SYN( "/about") CMD_DESC( "Show version and license information.") - CMD_NOARGS - CMD_NOEXAMPLES }, - { "/connect", - parse_args, 0, 7, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/connect", + parse_args, 0, 7, NULL) CMD_MAINFUNC(cmd_connect) CMD_TAGS( CMD_TAG_CONNECTION) @@ -199,51 +175,48 @@ static struct cmd_t command_defs[] = { "/connect server.supporting.sasl.anonymous.example") }, - { "/tls", - parse_args, 1, 3, NULL, + { CMD_PREAMBLE("/tls", + parse_args, 1, 3, NULL) CMD_SUBFUNCS( { "certpath", cmd_tls_certpath }, { "trust", cmd_tls_trust }, { "trusted", cmd_tls_trusted }, { "revoke", cmd_tls_revoke }, { "cert", cmd_tls_cert }) - CMD_NOMAINFUNC - CMD_TAGS( - CMD_TAG_CONNECTION, - CMD_TAG_UI) - CMD_SYN( - "/tls allow", - "/tls always", - "/tls deny", - "/tls cert []", - "/tls trust", - "/tls trusted", - "/tls revoke ", - "/tls certpath", - "/tls certpath set ", - "/tls certpath clear", - "/tls certpath default") - CMD_DESC( - "Handle TLS certificates. ") - CMD_ARGS( - { "allow", "Allow connection to continue with TLS certificate." }, - { "always", "Always allow connections with TLS certificate." }, - { "deny", "Abort connection." }, - { "cert", "Show the current TLS certificate." }, - { "cert ", "Show details of trusted certificate." }, - { "trust", "Add the current TLS certificate to manually trusted certificates." }, - { "trusted", "List summary of manually trusted certificates (with '/tls always' or '/tls trust')." }, - { "revoke ", "Remove a manually trusted certificate." }, - { "certpath", "Show the trusted certificate path." }, - { "certpath set ", "Specify filesystem path containing trusted certificates." }, - { "certpath clear", "Clear the trusted certificate path." }, - { "certpath default", "Use default system certificate path, if it can be found." }) - CMD_NOEXAMPLES + CMD_TAGS( + CMD_TAG_CONNECTION, + CMD_TAG_UI) + CMD_SYN( + "/tls allow", + "/tls always", + "/tls deny", + "/tls cert []", + "/tls trust", + "/tls trusted", + "/tls revoke ", + "/tls certpath", + "/tls certpath set ", + "/tls certpath clear", + "/tls certpath default") + CMD_DESC( + "Handle TLS certificates. ") + CMD_ARGS( + { "allow", "Allow connection to continue with TLS certificate." }, + { "always", "Always allow connections with TLS certificate." }, + { "deny", "Abort connection." }, + { "cert", "Show the current TLS certificate." }, + { "cert ", "Show details of trusted certificate." }, + { "trust", "Add the current TLS certificate to manually trusted certificates." }, + { "trusted", "List summary of manually trusted certificates (with '/tls always' or '/tls trust')." }, + { "revoke ", "Remove a manually trusted certificate." }, + { "certpath", "Show the trusted certificate path." }, + { "certpath set ", "Specify filesystem path containing trusted certificates." }, + { "certpath clear", "Clear the trusted certificate path." }, + { "certpath default", "Use default system certificate path, if it can be found." }) }, - { "/disconnect", - parse_args, 0, 0, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/disconnect", + parse_args, 0, 0, NULL) CMD_MAINFUNC(cmd_disconnect) CMD_TAGS( CMD_TAG_CONNECTION) @@ -251,13 +224,10 @@ static struct cmd_t command_defs[] = { "/disconnect") CMD_DESC( "Disconnect from the current chat service.") - CMD_NOARGS - CMD_NOEXAMPLES }, - { "/msg", - parse_args_with_freetext, 1, 2, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/msg", + parse_args_with_freetext, 1, 2, NULL) CMD_MAINFUNC(cmd_msg) CMD_TAGS( CMD_TAG_CHAT) @@ -280,8 +250,8 @@ static struct cmd_t command_defs[] = { "/msg \"My Friend\" Hi, how are you?") }, - { "/roster", - parse_args_with_freetext, 0, 4, NULL, + { CMD_PREAMBLE("/roster", + parse_args_with_freetext, 0, 4, NULL) CMD_SUBFUNCS( { "group", cmd_group }) CMD_MAINFUNC(cmd_roster) @@ -423,9 +393,8 @@ static struct cmd_t command_defs[] = { "/roster group remove colleagues boss@work.com") }, - { "/blocked", - parse_args_with_freetext, 0, 3, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/blocked", + parse_args_with_freetext, 0, 3, NULL) CMD_MAINFUNC(cmd_blocked) CMD_TAGS( CMD_TAG_ROSTER, @@ -451,9 +420,8 @@ static struct cmd_t command_defs[] = { "/blocked add profanity@rooms.dismail.de/spammy-user") }, - { "/info", - parse_args, 0, 1, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/info", + parse_args, 0, 1, NULL) CMD_MAINFUNC(cmd_info) CMD_TAGS( CMD_TAG_ROSTER, @@ -474,9 +442,8 @@ static struct cmd_t command_defs[] = { "/info heimdall") }, - { "/caps", - parse_args, 0, 1, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/caps", + parse_args, 0, 1, NULL) CMD_MAINFUNC(cmd_caps) CMD_TAGS( CMD_TAG_DISCOVERY, @@ -497,9 +464,8 @@ static struct cmd_t command_defs[] = { "/caps aegir") }, - { "/software", - parse_args, 0, 1, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/software", + parse_args, 0, 1, NULL) CMD_MAINFUNC(cmd_software) CMD_TAGS( CMD_TAG_DISCOVERY, @@ -521,12 +487,11 @@ static struct cmd_t command_defs[] = { "/software thor") }, - { "/status", - parse_args, 2, 3, NULL, + { CMD_PREAMBLE("/status", + parse_args, 2, 3, NULL) CMD_SUBFUNCS( { "get", cmd_status_get }, { "set", cmd_status_set }) - CMD_NOMAINFUNC CMD_TAGS( CMD_TAG_CHAT, CMD_TAG_GROUPCHAT) @@ -547,9 +512,8 @@ static struct cmd_t command_defs[] = { "/status set online") }, - { "/resource", - parse_args, 1, 2, &cons_resource_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/resource", + parse_args, 1, 2, &cons_resource_setting) CMD_MAINFUNC(cmd_resource) CMD_TAGS( CMD_TAG_CHAT, @@ -566,12 +530,10 @@ static struct cmd_t command_defs[] = { { "off", "Let the server choose which resource to route messages to." }, { "title on|off", "Show or hide the current resource in the titlebar." }, { "message on|off", "Show or hide the resource when showing an incoming message." }) - CMD_NOEXAMPLES }, - { "/join", - parse_args, 0, 5, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/join", + parse_args, 0, 5, NULL) CMD_MAINFUNC(cmd_join) CMD_TAGS( CMD_TAG_GROUPCHAT) @@ -598,9 +560,8 @@ static struct cmd_t command_defs[] = { "/join mychannel") }, - { "/invite", - parse_args_with_freetext, 1, 3, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/invite", + parse_args_with_freetext, 1, 3, NULL) CMD_MAINFUNC(cmd_invite) CMD_TAGS( CMD_TAG_GROUPCHAT) @@ -623,9 +584,8 @@ static struct cmd_t command_defs[] = { "/invite list") }, - { "/room", - parse_args, 1, 1, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/room", + parse_args, 1, 1, NULL) CMD_MAINFUNC(cmd_room) CMD_TAGS( CMD_TAG_GROUPCHAT) @@ -637,12 +597,10 @@ static struct cmd_t command_defs[] = { { "accept", "Accept default room configuration." }, { "destroy", "Reject default room configuration, and destroy the room." }, { "config", "Edit room configuration." }) - CMD_NOEXAMPLES }, - { "/kick", - parse_args_with_freetext, 1, 2, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/kick", + parse_args_with_freetext, 1, 2, NULL) CMD_MAINFUNC(cmd_kick) CMD_TAGS( CMD_TAG_GROUPCHAT) @@ -653,11 +611,10 @@ static struct cmd_t command_defs[] = { CMD_ARGS( { "", "Nickname of the occupant to kick from the room." }, { "", "Optional reason for kicking the occupant." }) - CMD_NOEXAMPLES }, + }, - { "/ban", - parse_args_with_freetext, 1, 2, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/ban", + parse_args_with_freetext, 1, 2, NULL) CMD_MAINFUNC(cmd_ban) CMD_TAGS( CMD_TAG_GROUPCHAT) @@ -668,12 +625,10 @@ static struct cmd_t command_defs[] = { CMD_ARGS( { "", "Bare JID of the user to ban from the room." }, { "", "Optional reason for banning the user." }) - CMD_NOEXAMPLES }, - { "/subject", - parse_args_with_freetext, 0, 2, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/subject", + parse_args_with_freetext, 0, 2, NULL) CMD_MAINFUNC(cmd_subject) CMD_TAGS( CMD_TAG_GROUPCHAT) @@ -693,12 +648,10 @@ static struct cmd_t command_defs[] = { { "prepend ", "Prepend text to the current room subject, use double quotes if a trailing space is needed." }, { "append ", "Append text to the current room subject, use double quotes if a preceding space is needed." }, { "clear", "Clear the room subject." }) - CMD_NOEXAMPLES }, - { "/affiliation", - parse_args_with_freetext, 1, 4, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/affiliation", + parse_args_with_freetext, 1, 4, NULL) CMD_MAINFUNC(cmd_affiliation) CMD_TAGS( CMD_TAG_GROUPCHAT) @@ -715,12 +668,10 @@ static struct cmd_t command_defs[] = { { "list []", "List all users with the specified affiliation, or all if none specified." }, { "request", "Request voice."}, { "register", "Register your nickname with the MUC."}) - CMD_NOEXAMPLES }, - { "/role", - parse_args_with_freetext, 1, 4, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/role", + parse_args_with_freetext, 1, 4, NULL) CMD_MAINFUNC(cmd_role) CMD_TAGS( CMD_TAG_GROUPCHAT) @@ -733,12 +684,10 @@ static struct cmd_t command_defs[] = { CMD_ARGS( { "set []", "Set the role of occupant with nick, with an optional reason." }, { "list []", "List all occupants with the specified role, or all if none specified." }) - CMD_NOEXAMPLES }, - { "/occupants", - parse_args, 1, 3, cons_occupants_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/occupants", + parse_args, 1, 3, cons_occupants_setting) CMD_MAINFUNC(cmd_occupants) CMD_TAGS( CMD_TAG_GROUPCHAT, @@ -773,12 +722,10 @@ static struct cmd_t command_defs[] = { { "header char ", "Prefix occupants headers with specified character." }, { "header char none", "Remove occupants header character prefix." }, { "wrap on|off", "Enable or disable line wrapping in occupants panel." }) - CMD_NOEXAMPLES }, - { "/form", - parse_args, 1, 2, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/form", + parse_args, 1, 2, NULL) CMD_MAINFUNC(cmd_form) CMD_TAGS( CMD_TAG_GROUPCHAT) @@ -794,12 +741,10 @@ static struct cmd_t command_defs[] = { { "submit", "Submit the current form." }, { "cancel", "Cancel changes to the current form." }, { "help []", "Display help for form, or a specific field." }) - CMD_NOEXAMPLES }, - { "/rooms", - parse_args, 0, 4, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/rooms", + parse_args, 0, 4, NULL) CMD_MAINFUNC(cmd_rooms) CMD_TAGS( CMD_TAG_GROUPCHAT) @@ -825,8 +770,8 @@ static struct cmd_t command_defs[] = { "/rooms service conference.jabber.org filter \"News Room\"") }, - { "/bookmark", - parse_args, 0, 8, NULL, + { CMD_PREAMBLE("/bookmark", + parse_args, 0, 8, NULL) CMD_SUBFUNCS( { "ignore", cmd_bookmark_ignore }) CMD_MAINFUNC(cmd_bookmark) @@ -870,9 +815,8 @@ static struct cmd_t command_defs[] = { "/bookmark remove room@example.com") }, - { "/disco", - parse_args, 1, 2, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/disco", + parse_args, 1, 2, NULL) CMD_MAINFUNC(cmd_disco) CMD_TAGS( CMD_TAG_DISCOVERY) @@ -893,9 +837,8 @@ static struct cmd_t command_defs[] = { "/disco info odin@valhalla.edda/laptop") }, - { "/sendfile", - parse_args_with_freetext, 1, 1, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/sendfile", + parse_args_with_freetext, 1, 1, NULL) CMD_MAINFUNC(cmd_sendfile) CMD_TAGS( CMD_TAG_CHAT, @@ -911,9 +854,8 @@ static struct cmd_t command_defs[] = { "/sendfile ~/images/sweet_cat.jpg") }, - { "/lastactivity", - parse_args, 1, 2, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/lastactivity", + parse_args, 1, 2, NULL) CMD_MAINFUNC(cmd_lastactivity) CMD_TAGS( CMD_TAG_PRESENCE) @@ -933,9 +875,8 @@ static struct cmd_t command_defs[] = { "/lastactivity get someserver.com") }, - { "/nick", - parse_args_with_freetext, 1, 1, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/nick", + parse_args_with_freetext, 1, 1, NULL) CMD_MAINFUNC(cmd_nick) CMD_TAGS( CMD_TAG_GROUPCHAT) @@ -945,12 +886,10 @@ static struct cmd_t command_defs[] = { "Change your nickname in the current chat room.") CMD_ARGS( { "", "Your new nickname." }) - CMD_NOEXAMPLES }, - { "/win", - parse_args, 1, 1, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/win", + parse_args, 1, 1, NULL) CMD_MAINFUNC(cmd_win) CMD_TAGS( CMD_TAG_UI) @@ -984,8 +923,8 @@ static struct cmd_t command_defs[] = { "/win wikipedia") }, - { "/wins", - parse_args, 0, 3, NULL, + { CMD_PREAMBLE("/wins", + parse_args, 0, 3, NULL) CMD_SUBFUNCS( { "unread", cmd_wins_unread }, { "attention", cmd_wins_attention }, @@ -1008,12 +947,10 @@ static struct cmd_t command_defs[] = { { "attention", "List windows that have been marked with the attention flag (alt+v). You can toggle between marked windows with alt+m." }, { "prune", "Close all windows with no unread messages." }, { "swap ", "Swap windows, target may be an empty position." }) - CMD_NOEXAMPLES }, - { "/sub", - parse_args, 1, 2, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/sub", + parse_args, 1, 2, NULL) CMD_MAINFUNC(cmd_sub) CMD_TAGS( CMD_TAG_ROSTER) @@ -1041,9 +978,8 @@ static struct cmd_t command_defs[] = { "/sub sent") }, - { "/who", - parse_args, 0, 2, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/who", + parse_args, 0, 2, NULL) CMD_MAINFUNC(cmd_who) CMD_TAGS( CMD_TAG_CHAT, @@ -1074,9 +1010,8 @@ static struct cmd_t command_defs[] = { "/who admin") }, - { "/close", - parse_args, 0, 1, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/close", + parse_args, 0, 1, NULL) CMD_MAINFUNC(cmd_close) CMD_TAGS( CMD_TAG_UI) @@ -1101,12 +1036,10 @@ static struct cmd_t command_defs[] = { { "xmlconsole", "Close the XML Console window if open." }, { "all", "Close all windows." }, { "read", "Close all windows that have no unread messages." }) - CMD_NOEXAMPLES }, - { "/clear", - parse_args, 0, 2, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/clear", + parse_args, 0, 2, NULL) CMD_MAINFUNC(cmd_clear) CMD_TAGS( CMD_TAG_UI) @@ -1124,22 +1057,17 @@ static struct cmd_t command_defs[] = { "/clear persist_history on") }, - { "/quit", - parse_args, 0, 0, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/quit", + parse_args, 0, 0, NULL) CMD_MAINFUNC(cmd_quit) - CMD_NOTAGS - CMD_SYN( + CMD_SYN( "/quit") CMD_DESC( "Logout of any current session, and quit Profanity.") - CMD_NOARGS - CMD_NOEXAMPLES }, - { "/privileges", - parse_args, 1, 1, &cons_privileges_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/privileges", + parse_args, 1, 1, &cons_privileges_setting) CMD_MAINFUNC(cmd_privileges) CMD_TAGS( CMD_TAG_GROUPCHAT, @@ -1150,12 +1078,10 @@ static struct cmd_t command_defs[] = { "Group occupants panel by role, and show role information in chat rooms.") CMD_ARGS( { "on|off", "Enable or disable privilege information." }) - CMD_NOEXAMPLES }, - { "/charset", - parse_args, 0, 0, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/charset", + parse_args, 0, 0, NULL) CMD_MAINFUNC(cmd_charset) CMD_TAGS( CMD_TAG_UI) @@ -1163,13 +1089,10 @@ static struct cmd_t command_defs[] = { "/charset") CMD_DESC( "Display information about the current character set supported by the terminal. ") - CMD_NOARGS - CMD_NOEXAMPLES }, - { "/beep", - parse_args, 1, 1, &cons_beep_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/beep", + parse_args, 1, 1, &cons_beep_setting) CMD_MAINFUNC(cmd_beep) CMD_TAGS( CMD_TAG_UI) @@ -1181,12 +1104,10 @@ static struct cmd_t command_defs[] = { "If the terminal does not support sounds, it may attempt to flash the screen instead.") CMD_ARGS( { "on|off", "Enable or disable terminal bell." }) - CMD_NOEXAMPLES }, - { "/console", - parse_args, 2, 2, &cons_console_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/console", + parse_args, 2, 2, &cons_console_setting) CMD_MAINFUNC(cmd_console) CMD_TAGS( CMD_TAG_UI, @@ -1210,12 +1131,10 @@ static struct cmd_t command_defs[] = { { "private all", "Indicate all new private room messages in the console." }, { "private first", "Indicate only the first private room message in the console." }, { "private none", "Do not show any new private room messages in the console window." }) - CMD_NOEXAMPLES }, - { "/presence", - parse_args, 2, 2, &cons_presence_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/presence", + parse_args, 2, 2, &cons_presence_setting) CMD_MAINFUNC(cmd_presence) CMD_TAGS( CMD_TAG_UI, @@ -1246,9 +1165,8 @@ static struct cmd_t command_defs[] = { "/presence room all") }, - { "/wrap", - parse_args, 1, 1, &cons_wrap_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/wrap", + parse_args, 1, 1, &cons_wrap_setting) CMD_MAINFUNC(cmd_wrap) CMD_TAGS( CMD_TAG_UI) @@ -1258,12 +1176,10 @@ static struct cmd_t command_defs[] = { "Word wrapping.") CMD_ARGS( { "on|off", "Enable or disable word wrapping in the main window." }) - CMD_NOEXAMPLES }, - { "/time", - parse_args, 1, 3, &cons_time_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/time", + parse_args, 1, 3, &cons_time_setting) CMD_MAINFUNC(cmd_time) CMD_TAGS( CMD_TAG_UI) @@ -1308,9 +1224,8 @@ static struct cmd_t command_defs[] = { "/time all set \"%d-%m-%y %H:%M:%S\"") }, - { "/inpblock", - parse_args, 2, 2, &cons_inpblock_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/inpblock", + parse_args, 2, 2, &cons_inpblock_setting) CMD_MAINFUNC(cmd_inpblock) CMD_TAGS( CMD_TAG_UI) @@ -1322,11 +1237,11 @@ static struct cmd_t command_defs[] = { CMD_ARGS( { "timeout ", "Time to wait (1-1000) in milliseconds before reading input from the terminal buffer, default: 1000." }, { "dynamic on|off", "Start with 0 millis and dynamically increase up to timeout when no activity, default: on." }) - CMD_NOEXAMPLES }, + }, - { "/titlebar", - parse_args, 1, 2, &cons_titlebar_setting, + { CMD_PREAMBLE("/titlebar", + parse_args, 1, 2, &cons_titlebar_setting) CMD_SUBFUNCS( { "show", cmd_titlebar_show_hide }, { "hide", cmd_titlebar_show_hide }) @@ -1353,9 +1268,8 @@ static struct cmd_t command_defs[] = { "/titlebar hide encwarn") }, - { "/mainwin", - parse_args, 1, 1, &cons_winpos_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/mainwin", + parse_args, 1, 1, &cons_winpos_setting) CMD_MAINFUNC(cmd_mainwin) CMD_TAGS( CMD_TAG_UI) @@ -1367,12 +1281,10 @@ static struct cmd_t command_defs[] = { CMD_ARGS( { "up", "Move the main window up the screen." }, { "down", "Move the main window down the screen." }) - CMD_NOEXAMPLES }, - { "/statusbar", - parse_args, 1, 2, &cons_statusbar_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/statusbar", + parse_args, 1, 2, &cons_statusbar_setting) CMD_MAINFUNC(cmd_statusbar) CMD_TAGS( CMD_TAG_UI) @@ -1409,9 +1321,8 @@ static struct cmd_t command_defs[] = { "/statusbar hide name") }, - { "/inputwin", - parse_args, 1, 1, &cons_winpos_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/inputwin", + parse_args, 1, 1, &cons_winpos_setting) CMD_MAINFUNC(cmd_inputwin) CMD_TAGS( CMD_TAG_UI) @@ -1423,12 +1334,10 @@ static struct cmd_t command_defs[] = { CMD_ARGS( { "up", "Move the input window up the screen." }, { "down", "Move the input window down the screen." }) - CMD_NOEXAMPLES }, - { "/notify", - parse_args_with_freetext, 0, 4, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/notify", + parse_args_with_freetext, 0, 4, NULL) CMD_MAINFUNC(cmd_notify) CMD_TAGS( CMD_TAG_UI, @@ -1501,9 +1410,8 @@ static struct cmd_t command_defs[] = { "/notify invite on") }, - { "/flash", - parse_args, 1, 1, &cons_flash_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/flash", + parse_args, 1, 1, &cons_flash_setting) CMD_MAINFUNC(cmd_flash) CMD_TAGS( CMD_TAG_UI) @@ -1514,12 +1422,10 @@ static struct cmd_t command_defs[] = { "If the terminal doesn't support flashing, it may attempt to beep.") CMD_ARGS( { "on|off", "Enable or disable terminal flash." }) - CMD_NOEXAMPLES }, - { "/tray", - parse_args, 1, 2, &cons_tray_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/tray", + parse_args, 1, 2, &cons_tray_setting) CMD_MAINFUNC(cmd_tray) CMD_TAGS( CMD_TAG_UI) @@ -1533,12 +1439,10 @@ static struct cmd_t command_defs[] = { { "on|off", "Show tray icon." }, { "read on|off", "Show tray icon when no unread messages." }, { "timer ", "Set tray icon timer, seconds must be between 1-10." }) - CMD_NOEXAMPLES }, - { "/intype", - parse_args, 2, 2, &cons_intype_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/intype", + parse_args, 2, 2, &cons_intype_setting) CMD_MAINFUNC(cmd_intype) CMD_TAGS( CMD_TAG_UI, @@ -1550,12 +1454,10 @@ static struct cmd_t command_defs[] = { CMD_ARGS( { "titlebar on|off", "Enable or disable contact typing messages notification in titlebar." }, { "console on|off", "Enable or disable contact typing messages notification in console window." }) - CMD_NOEXAMPLES }, - { "/splash", - parse_args, 1, 1, &cons_splash_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/splash", + parse_args, 1, 1, &cons_splash_setting) CMD_MAINFUNC(cmd_splash) CMD_TAGS( CMD_TAG_UI) @@ -1565,12 +1467,10 @@ static struct cmd_t command_defs[] = { "Switch on or off the ascii logo on start up and when the /about command is called.") CMD_ARGS( { "on|off", "Enable or disable splash logo." }) - CMD_NOEXAMPLES }, - { "/autoconnect", - parse_args, 1, 2, &cons_autoconnect_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/autoconnect", + parse_args, 1, 2, &cons_autoconnect_setting) CMD_MAINFUNC(cmd_autoconnect) CMD_TAGS( CMD_TAG_CONNECTION) @@ -1588,8 +1488,8 @@ static struct cmd_t command_defs[] = { "/autoconnect off") }, - { "/vcard", - parse_args, 0, 7, NULL, + { CMD_PREAMBLE("/vcard", + parse_args, 0, 7, NULL) CMD_SUBFUNCS( {"add", cmd_vcard_add}, {"remove", cmd_vcard_remove}, @@ -1703,12 +1603,10 @@ static struct cmd_t command_defs[] = { { "remove ", "Remove a element in your vCard by index" }, { "refresh", "Refreshes the local copy of the current account's vCard (undoes all your unpublished modifications)" }, { "save", "Save changes to the server" }) - CMD_NOEXAMPLES }, - { "/vercheck", - parse_args, 0, 1, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/vercheck", + parse_args, 0, 1, NULL) CMD_MAINFUNC(cmd_vercheck) CMD_TAGS( CMD_TAG_UI) @@ -1718,12 +1616,10 @@ static struct cmd_t command_defs[] = { "Check for new versions when Profanity starts, and when the /about command is run.") CMD_ARGS( { "on|off", "Enable or disable the version check." }) - CMD_NOEXAMPLES }, - { "/wintitle", - parse_args, 2, 2, &cons_wintitle_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/wintitle", + parse_args, 2, 2, &cons_wintitle_setting) CMD_MAINFUNC(cmd_wintitle) CMD_TAGS( CMD_TAG_UI) @@ -1735,14 +1631,11 @@ static struct cmd_t command_defs[] = { CMD_ARGS( { "show on|off", "Show current logged in user, and unread messages as the window title." }, { "goodbye on|off", "Show a message in the title when exiting profanity." }) - CMD_NOEXAMPLES }, - { "/alias", - parse_args_with_freetext, 1, 3, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/alias", + parse_args_with_freetext, 1, 3, NULL) CMD_MAINFUNC(cmd_alias) - CMD_NOTAGS CMD_SYN( "/alias list", "/alias add ", @@ -1761,9 +1654,8 @@ static struct cmd_t command_defs[] = { "/alias list") }, - { "/logging", - parse_args, 2, 3, &cons_logging_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/logging", + parse_args, 2, 3, &cons_logging_setting) CMD_MAINFUNC(cmd_logging) CMD_TAGS( CMD_TAG_CHAT) @@ -1782,9 +1674,8 @@ static struct cmd_t command_defs[] = { "/logging group off") }, - { "/states", - parse_args, 1, 1, &cons_states_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/states", + parse_args, 1, 1, &cons_states_setting) CMD_MAINFUNC(cmd_states) CMD_TAGS( CMD_TAG_CHAT) @@ -1794,11 +1685,10 @@ static struct cmd_t command_defs[] = { "Send chat state notifications to recipient during chat sessions, such as typing, paused, active, gone.") CMD_ARGS( { "on|off", "Enable or disable sending of chat state notifications." }) - CMD_NOEXAMPLES }, + }, - { "/pgp", - parse_args, 1, 3, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/pgp", + parse_args, 1, 3, NULL) CMD_MAINFUNC(cmd_pgp) CMD_TAGS( CMD_TAG_CHAT, @@ -1837,8 +1727,8 @@ static struct cmd_t command_defs[] = { // XEP-0373: OpenPGP for XMPP #ifdef HAVE_LIBGPGME - { "/ox", - parse_args, 1, 3, NULL, + { CMD_PREAMBLE("/ox", + parse_args, 1, 3, NULL) CMD_SUBFUNCS( { "log", cmd_ox_log }) CMD_MAINFUNC(cmd_ox) @@ -1879,8 +1769,8 @@ static struct cmd_t command_defs[] = { }, #endif // HAVE_LIBGPGME - { "/otr", - parse_args, 1, 3, NULL, + { CMD_PREAMBLE("/otr", + parse_args, 1, 3, NULL) CMD_SUBFUNCS( { "char", cmd_otr_char }, { "log", cmd_otr_log }, @@ -1897,7 +1787,6 @@ static struct cmd_t command_defs[] = { { "question", cmd_otr_question }, { "answer", cmd_otr_answer }, { "sendfile", cmd_otr_sendfile }) - CMD_NOMAINFUNC CMD_TAGS( CMD_TAG_CHAT, CMD_TAG_UI) @@ -1951,9 +1840,8 @@ static struct cmd_t command_defs[] = { "/otr char *") }, - { "/outtype", - parse_args, 1, 1, &cons_outtype_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/outtype", + parse_args, 1, 1, &cons_outtype_setting) CMD_MAINFUNC(cmd_outtype) CMD_TAGS( CMD_TAG_CHAT) @@ -1963,12 +1851,10 @@ static struct cmd_t command_defs[] = { "Send typing notifications, chat states (/states) will be enabled if this setting is enabled.") CMD_ARGS( { "on|off", "Enable or disable sending typing notifications." }) - CMD_NOEXAMPLES }, - { "/gone", - parse_args, 1, 1, &cons_gone_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/gone", + parse_args, 1, 1, &cons_gone_setting) CMD_MAINFUNC(cmd_gone) CMD_TAGS( CMD_TAG_CHAT) @@ -1979,12 +1865,10 @@ static struct cmd_t command_defs[] = { "Chat states (/states) will be enabled if this setting is set.") CMD_ARGS( { "", "Number of minutes of inactivity before sending the 'gone' state, a value of 0 will disable sending this state." }) - CMD_NOEXAMPLES }, - { "/history", - parse_args, 1, 1, &cons_history_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/history", + parse_args, 1, 1, &cons_history_setting) CMD_MAINFUNC(cmd_history) CMD_TAGS( CMD_TAG_UI, @@ -1996,14 +1880,11 @@ static struct cmd_t command_defs[] = { "When history is enabled, previous messages are shown in chat windows.") CMD_ARGS( { "on|off", "Enable or disable showing chat history." }) - CMD_NOEXAMPLES }, - { "/log", - parse_args, 1, 2, &cons_log_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/log", + parse_args, 1, 2, &cons_log_setting) CMD_MAINFUNC(cmd_log) - CMD_NOTAGS CMD_SYN( "/log where", "/log rotate on|off", @@ -2018,12 +1899,10 @@ static struct cmd_t command_defs[] = { { "maxsize ", "With rotate enabled, specifies the max log size, defaults to 10485760 (10MB)." }, { "shared on|off", "Share logs between all instances, default: on. When off, the process id will be included in the log filename. Does not take effect if you specified a filename yourself when starting Profanity." }, {"level INFO|DEBUG|WARN|ERROR", "Set the log level. Default is INFO. Only works with default log file, not with user provided log file during startup via -f." }) - CMD_NOEXAMPLES }, - { "/carbons", - parse_args, 1, 1, &cons_carbons_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/carbons", + parse_args, 1, 1, &cons_carbons_setting) CMD_MAINFUNC(cmd_carbons) CMD_TAGS( CMD_TAG_CHAT) @@ -2034,12 +1913,10 @@ static struct cmd_t command_defs[] = { "Message carbons ensure that both sides of all conversations are shared with all the user's clients that implement this protocol.") CMD_ARGS( { "on|off", "Enable or disable message carbons." }) - CMD_NOEXAMPLES }, - { "/receipts", - parse_args, 2, 2, &cons_receipts_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/receipts", + parse_args, 2, 2, &cons_receipts_setting) CMD_MAINFUNC(cmd_receipts) CMD_TAGS( CMD_TAG_CHAT) @@ -2051,12 +1928,10 @@ static struct cmd_t command_defs[] = { CMD_ARGS( { "request on|off", "Whether or not to request a receipt upon sending a message." }, { "send on|off", "Whether or not to send a receipt if one has been requested with a received message." }) - CMD_NOEXAMPLES }, - { "/reconnect", - parse_args, 1, 1, &cons_reconnect_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/reconnect", + parse_args, 1, 1, &cons_reconnect_setting) CMD_MAINFUNC(cmd_reconnect) CMD_TAGS( CMD_TAG_CONNECTION) @@ -2066,12 +1941,10 @@ static struct cmd_t command_defs[] = { "Set the reconnect attempt interval for when the connection is lost.") CMD_ARGS( { "", "Number of seconds before attempting to reconnect, a value of 0 disables reconnect." }) - CMD_NOEXAMPLES }, - { "/autoping", - parse_args, 2, 2, &cons_autoping_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/autoping", + parse_args, 2, 2, &cons_autoping_setting) CMD_MAINFUNC(cmd_autoping) CMD_TAGS( CMD_TAG_CONNECTION) @@ -2083,12 +1956,10 @@ static struct cmd_t command_defs[] = { CMD_ARGS( { "set ", "Number of seconds between sending pings, a value of 0 disables autoping." }, { "timeout ", "Seconds to wait for autoping responses, after which the connection is considered broken." }) - CMD_NOEXAMPLES }, - { "/ping", - parse_args, 0, 1, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/ping", + parse_args, 0, 1, NULL) CMD_MAINFUNC(cmd_ping) CMD_TAGS( CMD_TAG_CONNECTION) @@ -2099,12 +1970,10 @@ static struct cmd_t command_defs[] = { "If no JID is supplied, your chat server will be pinged.") CMD_ARGS( { "", "The Jabber ID to send the ping request to." }) - CMD_NOEXAMPLES }, - { "/autoaway", - parse_args_with_freetext, 2, 3, &cons_autoaway_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/autoaway", + parse_args_with_freetext, 2, 3, &cons_autoaway_setting) CMD_MAINFUNC(cmd_autoaway) CMD_TAGS( CMD_TAG_PRESENCE) @@ -2135,9 +2004,8 @@ static struct cmd_t command_defs[] = { "/autoaway check off") }, - { "/priority", - parse_args, 1, 1, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/priority", + parse_args, 1, 1, NULL) CMD_MAINFUNC(cmd_priority) CMD_TAGS( CMD_TAG_PRESENCE) @@ -2148,11 +2016,10 @@ static struct cmd_t command_defs[] = { "See the /account command for specific priority settings per presence status.") CMD_ARGS( { "", "Number between -128 and 127, default: 0." }) - CMD_NOEXAMPLES }, - { "/account", - parse_args, 0, 4, NULL, + { CMD_PREAMBLE("/account", + parse_args, 0, 4, NULL) CMD_SUBFUNCS( { "list", cmd_account_list }, { "show", cmd_account_show }, @@ -2264,8 +2131,8 @@ static struct cmd_t command_defs[] = { "/account clear me pgpkeyid") }, - { "/plugins", - parse_args, 0, 3, NULL, + { CMD_PREAMBLE("/plugins", + parse_args, 0, 3, NULL) CMD_SUBFUNCS( { "install", cmd_plugins_install }, { "uninstall", cmd_plugins_uninstall }, @@ -2275,7 +2142,6 @@ static struct cmd_t command_defs[] = { { "reload", cmd_plugins_reload }, { "python_version", cmd_plugins_python_version }) CMD_MAINFUNC(cmd_plugins) - CMD_NOTAGS CMD_SYN( "/plugins", "/plugins install []", @@ -2305,11 +2171,9 @@ static struct cmd_t command_defs[] = { "/plugins reload wikipedia.py") }, - { "/prefs", - parse_args, 0, 1, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/prefs", + parse_args, 0, 1, NULL) CMD_MAINFUNC(cmd_prefs) - CMD_NOTAGS CMD_SYN( "/prefs [ui|desktop|chat|log|conn|presence|otr|pgp|omemo]") CMD_DESC( @@ -2325,12 +2189,10 @@ static struct cmd_t command_defs[] = { { "otr", "Off The Record preferences." }, { "pgp", "OpenPGP preferences." }, { "omemo", "OMEMO preferences." }) - CMD_NOEXAMPLES }, - { "/theme", - parse_args, 1, 2, &cons_theme_setting, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/theme", + parse_args, 1, 2, &cons_theme_setting) CMD_MAINFUNC(cmd_theme) CMD_TAGS( CMD_TAG_UI) @@ -2353,9 +2215,8 @@ static struct cmd_t command_defs[] = { "/theme load forest") }, - { "/xmlconsole", - parse_args, 0, 0, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/xmlconsole", + parse_args, 0, 0, NULL) CMD_MAINFUNC(cmd_xmlconsole) CMD_TAGS( CMD_TAG_UI) @@ -2363,15 +2224,11 @@ static struct cmd_t command_defs[] = { "/xmlconsole") CMD_DESC( "Open the XML console to view incoming and outgoing XMPP traffic.") - CMD_NOARGS - CMD_NOEXAMPLES }, - { "/script", - parse_args, 1, 2, NULL, - CMD_NOSUBFUNCS + { CMD_PREAMBLE("/script", + parse_args, 1, 2, NULL) CMD_MAINFUNC(cmd_script) - CMD_NOTAGS CMD_SYN( "/script run