Unified error strings.

This commit is contained in:
default 2022-09-19 22:30:04 +02:00
parent 1ad66e5166
commit 368cf465fc

33
snac.c
View file

@ -78,7 +78,7 @@ int srv_open(char *basedir)
cfg_file = xs_fmt("%s/server.json", basedir); cfg_file = xs_fmt("%s/server.json", basedir);
if ((f = fopen(cfg_file, "r")) == NULL) if ((f = fopen(cfg_file, "r")) == NULL)
srv_log(xs_fmt("cannot open %s", cfg_file)); srv_log(xs_fmt("error opening '%s'", cfg_file));
else { else {
xs *cfg_data; xs *cfg_data;
@ -89,7 +89,7 @@ int srv_open(char *basedir)
srv_config = xs_json_loads(cfg_data); srv_config = xs_json_loads(cfg_data);
if (srv_config == NULL) if (srv_config == NULL)
srv_log(xs_fmt("cannot parse %s", cfg_file)); srv_log(xs_fmt("cannot parse '%s'", cfg_file));
else { else {
char *host; char *host;
char *prefix; char *prefix;
@ -134,6 +134,17 @@ int validate_uid(char *uid)
} }
void snac_free(snac *snac)
/* frees a user snac */
{
free(snac->uid);
free(snac->basedir);
free(snac->config);
free(snac->key);
free(snac->actor);
}
int snac_open(snac *snac, char *uid) int snac_open(snac *snac, char *uid)
/* opens a user */ /* opens a user */
{ {
@ -172,13 +183,13 @@ int snac_open(snac *snac, char *uid)
ret = 1; ret = 1;
} }
else else
srv_log(xs_fmt("cannot parse %s", key_file)); srv_log(xs_fmt("cannot parse '%s'", key_file));
} }
else else
srv_log(xs_fmt("error opening '%s'", key_file)); srv_log(xs_fmt("error opening '%s'", key_file));
} }
else else
srv_log(xs_fmt("cannot parse %s", cfg_file)); srv_log(xs_fmt("cannot parse '%s'", cfg_file));
} }
else else
srv_log(xs_fmt("error opening '%s'", cfg_file)); srv_log(xs_fmt("error opening '%s'", cfg_file));
@ -186,21 +197,13 @@ int snac_open(snac *snac, char *uid)
else else
srv_log(xs_fmt("invalid user '%s'", uid)); srv_log(xs_fmt("invalid user '%s'", uid));
if (!ret)
snac_free(snac);
return ret; return ret;
} }
void snac_free(snac *snac)
/* frees a user snac */
{
free(snac->uid);
free(snac->basedir);
free(snac->config);
free(snac->key);
free(snac->actor);
}
void snac_debug(snac *snac, int level, d_char *str) void snac_debug(snac *snac, int level, d_char *str)
/* prints a user debugging information */ /* prints a user debugging information */
{ {