aboutsummaryrefslogtreecommitdiffstats
path: root/src/rspamadm/rspamadm.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-01 14:52:30 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-01 14:52:30 +0100
commit20d46fb63c0e65e9d2d7b6601b0ff2035fd54117 (patch)
tree4825b585ed0903d6e931648c0d81f37c17d6e840 /src/rspamadm/rspamadm.c
parente3079ec0183ba274ef58822f548e020249be23fa (diff)
downloadrspamd-20d46fb63c0e65e9d2d7b6601b0ff2035fd54117.tar.gz
rspamd-20d46fb63c0e65e9d2d7b6601b0ff2035fd54117.zip
[Minor] Add aliases support to rspamadm commands
Diffstat (limited to 'src/rspamadm/rspamadm.c')
-rw-r--r--src/rspamadm/rspamadm.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c
index eff27c1e9..68dbdeb85 100644
--- a/src/rspamadm/rspamadm.c
+++ b/src/rspamadm/rspamadm.c
@@ -282,6 +282,28 @@ rspamdadm_commands_sort_func (gconstpointer a, gconstpointer b)
return strcmp (cmda->name, cmdb->name);
}
+static gboolean
+rspamadm_command_maybe_match_name (const gchar *cmd, const gchar *input)
+{
+ gsize clen, inplen;
+
+ clen = strlen (cmd);
+ inplen = strlen (input);
+
+ if (rspamd_strings_levenshtein_distance (cmd, clen,
+ input, inplen, 1) == 1) {
+ return TRUE;
+ }
+ else if ((clen > inplen &&
+ rspamd_substring_search (cmd, clen, input, inplen) != -1) ||
+ (inplen > clen &&
+ rspamd_substring_search (input, inplen, cmd, clen) != -1)) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
gint
main (gint argc, gchar **argv, gchar **env)
{
@@ -427,20 +449,18 @@ main (gint argc, gchar **argv, gchar **env)
/* Try fuzz search */
rspamd_fprintf (stderr, "Suggested commands:\n");
PTR_ARRAY_FOREACH (all_commands, i, cmd) {
- gsize clen, inplen;
+ guint j;
+ const gchar *alias;
- clen = strlen (cmd->name);
- inplen = strlen (cmd_name);
-
- if (rspamd_strings_levenshtein_distance (cmd->name, clen,
- cmd_name, inplen, 1) == 1) {
+ if (rspamadm_command_maybe_match_name (cmd->name, cmd_name)) {
rspamd_fprintf (stderr, "%s\n", cmd->name);
}
- else if ((clen > inplen &&
- rspamd_substring_search (cmd->name, clen, cmd_name, inplen) != -1) ||
- (inplen > clen &&
- rspamd_substring_search (cmd_name, inplen, cmd->name, clen) != -1)) {
- rspamd_fprintf (stderr, "%s\n", cmd->name);
+ else {
+ PTR_ARRAY_FOREACH (cmd->aliases, j, alias) {
+ if (rspamadm_command_maybe_match_name (alias, cmd_name)) {
+ rspamd_fprintf (stderr, "%s\n", alias);
+ }
+ }
}
}