mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-15 01:55:03 +00:00
Fail on static data ids with / in them.
This commit is contained in:
parent
1de8095b33
commit
51bee249d4
1 changed files with 25 additions and 15 deletions
40
data.c
40
data.c
|
@ -1326,10 +1326,15 @@ int actor_get(snac *snac, const char *actor, d_char **data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** static data **/
|
||||||
|
|
||||||
d_char *_static_fn(snac *snac, const char *id)
|
d_char *_static_fn(snac *snac, const char *id)
|
||||||
/* gets the filename for a static file */
|
/* gets the filename for a static file */
|
||||||
{
|
{
|
||||||
return xs_fmt("%s/static/%s", snac->basedir, id);
|
if (strchr(id, '/'))
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
return xs_fmt("%s/static/%s", snac->basedir, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1340,9 +1345,8 @@ int static_get(snac *snac, const char *id, d_char **data, int *size)
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int status = 404;
|
int status = 404;
|
||||||
|
|
||||||
*size = XS_ALL;
|
if (fn && (f = fopen(fn, "rb")) != NULL) {
|
||||||
|
*size = XS_ALL;
|
||||||
if ((f = fopen(fn, "rb")) != NULL) {
|
|
||||||
*data = xs_read(f, size);
|
*data = xs_read(f, size);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
@ -1359,7 +1363,7 @@ void static_put(snac *snac, const char *id, const char *data, int size)
|
||||||
xs *fn = _static_fn(snac, id);
|
xs *fn = _static_fn(snac, id);
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if ((f = fopen(fn, "wb")) != NULL) {
|
if (fn && (f = fopen(fn, "wb")) != NULL) {
|
||||||
fwrite(data, size, 1, f);
|
fwrite(data, size, 1, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
@ -1370,12 +1374,15 @@ void static_put_meta(snac *snac, const char *id, const char *str)
|
||||||
/* puts metadata (i.e. a media description string) to id */
|
/* puts metadata (i.e. a media description string) to id */
|
||||||
{
|
{
|
||||||
xs *fn = _static_fn(snac, id);
|
xs *fn = _static_fn(snac, id);
|
||||||
fn = xs_str_cat(fn, ".txt");
|
|
||||||
FILE *f;
|
|
||||||
|
|
||||||
if ((f = fopen(fn, "w")) != NULL) {
|
if (fn) {
|
||||||
fprintf(f, "%s\n", str);
|
fn = xs_str_cat(fn, ".txt");
|
||||||
fclose(f);
|
FILE *f;
|
||||||
|
|
||||||
|
if ((f = fopen(fn, "w")) != NULL) {
|
||||||
|
fprintf(f, "%s\n", str);
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1384,13 +1391,16 @@ xs_str *static_get_meta(snac *snac, const char *id)
|
||||||
/* gets metadata from a media */
|
/* gets metadata from a media */
|
||||||
{
|
{
|
||||||
xs *fn = _static_fn(snac, id);
|
xs *fn = _static_fn(snac, id);
|
||||||
fn = xs_str_cat(fn, ".txt");
|
|
||||||
xs_str *r = NULL;
|
xs_str *r = NULL;
|
||||||
FILE *f;
|
|
||||||
|
|
||||||
if ((f = fopen(fn, "r")) != NULL) {
|
if (fn) {
|
||||||
r = xs_strip_i(xs_readline(f));
|
fn = xs_str_cat(fn, ".txt");
|
||||||
fclose(f);
|
FILE *f;
|
||||||
|
|
||||||
|
if ((f = fopen(fn, "r")) != NULL) {
|
||||||
|
r = xs_strip_i(xs_readline(f));
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
r = xs_str_new("");
|
r = xs_str_new("");
|
||||||
|
|
Loading…
Reference in a new issue