add /strophe command to modify libstrophe-specific settings

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel
2022-12-05 10:25:57 +01:00
parent 78496d6226
commit b1b6c6f62d
12 changed files with 194 additions and 23 deletions

View File

@@ -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)
{

View File

@@ -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)
};

View File

@@ -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)
{

View File

@@ -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);