degesch: mostly finish /alias sans name checking

This commit is contained in:
Přemysl Eric Janouch 2015-07-11 03:27:59 +02:00
parent b987b2cc64
commit a24c068a3b

View File

@ -6818,9 +6818,15 @@ show_aliases_list (struct app_context *ctx)
log_global_indent (ctx, ""); log_global_indent (ctx, "");
log_global_indent (ctx, "Aliases:"); log_global_indent (ctx, "Aliases:");
struct str_map_iter iter; struct str_map *aliases = get_aliases_config (ctx);
str_map_iter_init (&iter, get_aliases_config (ctx)); if (!aliases->len)
{
log_global_indent (ctx, " (none)");
return true;
}
struct str_map_iter iter;
str_map_iter_init (&iter, aliases);
struct config_item_ *alias; struct config_item_ *alias;
while ((alias = str_map_iter_next (&iter))) while ((alias = str_map_iter_next (&iter)))
{ {
@ -6839,15 +6845,22 @@ show_aliases_list (struct app_context *ctx)
static bool static bool
handle_command_alias (struct handler_args *a) handle_command_alias (struct handler_args *a)
{ {
char *name = cut_word (&a->arguments); if (!*a->arguments)
if (!*name)
return show_aliases_list (a->ctx); return show_aliases_list (a->ctx);
char *definition = cut_word (&a->arguments); // TODO: validate the name; maybe also while loading configuration
if (!*definition) char *name = cut_word (&a->arguments);
if (!*a->arguments)
return false; return false;
// TODO: set the alias "name" to "definition" struct config_item_ *alias = config_item_string_from_cstr (a->arguments);
struct str definition;
str_init (&definition);
config_item_write_string (&definition, &alias->value.string);
str_map_set (get_aliases_config (a->ctx), name, alias);
log_global_status (a->ctx, "Created alias /#s: #s", name, definition.str);
str_free (&definition);
return true; return true;
} }