mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 19:50:26 +03:00
Fail on static data ids with / in them.
This commit is contained in:
parent
1de8095b33
commit
51bee249d4
18
data.c
18
data.c
@ -1326,9 +1326,14 @@ int actor_get(snac *snac, const char *actor, d_char **data)
|
||||
}
|
||||
|
||||
|
||||
/** static data **/
|
||||
|
||||
d_char *_static_fn(snac *snac, const char *id)
|
||||
/* gets the filename for a static file */
|
||||
{
|
||||
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;
|
||||
int status = 404;
|
||||
|
||||
if (fn && (f = fopen(fn, "rb")) != NULL) {
|
||||
*size = XS_ALL;
|
||||
|
||||
if ((f = fopen(fn, "rb")) != NULL) {
|
||||
*data = xs_read(f, size);
|
||||
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);
|
||||
FILE *f;
|
||||
|
||||
if ((f = fopen(fn, "wb")) != NULL) {
|
||||
if (fn && (f = fopen(fn, "wb")) != NULL) {
|
||||
fwrite(data, size, 1, f);
|
||||
fclose(f);
|
||||
}
|
||||
@ -1370,6 +1374,8 @@ void static_put_meta(snac *snac, const char *id, const char *str)
|
||||
/* puts metadata (i.e. a media description string) to id */
|
||||
{
|
||||
xs *fn = _static_fn(snac, id);
|
||||
|
||||
if (fn) {
|
||||
fn = xs_str_cat(fn, ".txt");
|
||||
FILE *f;
|
||||
|
||||
@ -1378,20 +1384,24 @@ void static_put_meta(snac *snac, const char *id, const char *str)
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
xs_str *static_get_meta(snac *snac, const char *id)
|
||||
/* gets metadata from a media */
|
||||
{
|
||||
xs *fn = _static_fn(snac, id);
|
||||
fn = xs_str_cat(fn, ".txt");
|
||||
xs_str *r = NULL;
|
||||
|
||||
if (fn) {
|
||||
fn = xs_str_cat(fn, ".txt");
|
||||
FILE *f;
|
||||
|
||||
if ((f = fopen(fn, "r")) != NULL) {
|
||||
r = xs_strip_i(xs_readline(f));
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
else
|
||||
r = xs_str_new("");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user