degesch: simplify check_server_name_for_addition()
This commit is contained in:
parent
c573435996
commit
855a9d81ba
24
degesch.c
24
degesch.c
|
@ -6491,21 +6491,16 @@ validate_server_name (const char *name)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static const char *
|
||||||
check_server_name_for_addition (struct app_context *ctx, const char *name)
|
check_server_name_for_addition (struct app_context *ctx, const char *name)
|
||||||
{
|
{
|
||||||
if (!strcasecmp_ascii (name, ctx->global_buffer->name))
|
if (!strcasecmp_ascii (name, ctx->global_buffer->name))
|
||||||
log_global_error (ctx, "Cannot create server `#s': #s",
|
return "name collides with the global buffer";
|
||||||
name, "name collides with the global buffer");
|
if (str_map_find (&ctx->servers, name))
|
||||||
else if (str_map_find (&ctx->servers, name))
|
return "server already exists";
|
||||||
log_global_error (ctx, "Cannot create server `#s': #s",
|
if (!validate_server_name (name))
|
||||||
name, "server already exists");
|
return "invalid server name";
|
||||||
else if (!validate_server_name (name))
|
return NULL;
|
||||||
log_global_error (ctx, "Cannot create server `#s': #s",
|
|
||||||
name, "invalid server name");
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct server *
|
static struct server *
|
||||||
|
@ -7511,7 +7506,10 @@ handle_server_add (struct handler_args *a)
|
||||||
|
|
||||||
struct app_context *ctx = a->ctx;
|
struct app_context *ctx = a->ctx;
|
||||||
char *name = cut_word (&a->arguments);
|
char *name = cut_word (&a->arguments);
|
||||||
if (check_server_name_for_addition (ctx, name))
|
const char *err;
|
||||||
|
if ((err = check_server_name_for_addition (ctx, name)))
|
||||||
|
log_global_error (ctx, "Cannot create server `#s': #s", name, err);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
server_add_new (ctx, name);
|
server_add_new (ctx, name);
|
||||||
log_global_status (ctx, "Server added: #s", name);
|
log_global_status (ctx, "Server added: #s", name);
|
||||||
|
|
Loading…
Reference in New Issue