diff options
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 40 |
1 files changed, 25 insertions, 15 deletions
| @@ -1326,10 +1326,15 @@ int actor_get(snac *snac, const char *actor, d_char **data) | |||
| 1326 | } | 1326 | } |
| 1327 | 1327 | ||
| 1328 | 1328 | ||
| 1329 | /** static data **/ | ||
| 1330 | |||
| 1329 | d_char *_static_fn(snac *snac, const char *id) | 1331 | d_char *_static_fn(snac *snac, const char *id) |
| 1330 | /* gets the filename for a static file */ | 1332 | /* gets the filename for a static file */ |
| 1331 | { | 1333 | { |
| 1332 | return xs_fmt("%s/static/%s", snac->basedir, id); | 1334 | if (strchr(id, '/')) |
| 1335 | return NULL; | ||
| 1336 | else | ||
| 1337 | return xs_fmt("%s/static/%s", snac->basedir, id); | ||
| 1333 | } | 1338 | } |
| 1334 | 1339 | ||
| 1335 | 1340 | ||
| @@ -1340,9 +1345,8 @@ int static_get(snac *snac, const char *id, d_char **data, int *size) | |||
| 1340 | FILE *f; | 1345 | FILE *f; |
| 1341 | int status = 404; | 1346 | int status = 404; |
| 1342 | 1347 | ||
| 1343 | *size = XS_ALL; | 1348 | if (fn && (f = fopen(fn, "rb")) != NULL) { |
| 1344 | 1349 | *size = XS_ALL; | |
| 1345 | if ((f = fopen(fn, "rb")) != NULL) { | ||
| 1346 | *data = xs_read(f, size); | 1350 | *data = xs_read(f, size); |
| 1347 | fclose(f); | 1351 | fclose(f); |
| 1348 | 1352 | ||
| @@ -1359,7 +1363,7 @@ void static_put(snac *snac, const char *id, const char *data, int size) | |||
| 1359 | xs *fn = _static_fn(snac, id); | 1363 | xs *fn = _static_fn(snac, id); |
| 1360 | FILE *f; | 1364 | FILE *f; |
| 1361 | 1365 | ||
| 1362 | if ((f = fopen(fn, "wb")) != NULL) { | 1366 | if (fn && (f = fopen(fn, "wb")) != NULL) { |
| 1363 | fwrite(data, size, 1, f); | 1367 | fwrite(data, size, 1, f); |
| 1364 | fclose(f); | 1368 | fclose(f); |
| 1365 | } | 1369 | } |
| @@ -1370,12 +1374,15 @@ void static_put_meta(snac *snac, const char *id, const char *str) | |||
| 1370 | /* puts metadata (i.e. a media description string) to id */ | 1374 | /* puts metadata (i.e. a media description string) to id */ |
| 1371 | { | 1375 | { |
| 1372 | xs *fn = _static_fn(snac, id); | 1376 | xs *fn = _static_fn(snac, id); |
| 1373 | fn = xs_str_cat(fn, ".txt"); | ||
| 1374 | FILE *f; | ||
| 1375 | 1377 | ||
| 1376 | if ((f = fopen(fn, "w")) != NULL) { | 1378 | if (fn) { |
| 1377 | fprintf(f, "%s\n", str); | 1379 | fn = xs_str_cat(fn, ".txt"); |
| 1378 | fclose(f); | 1380 | FILE *f; |
| 1381 | |||
| 1382 | if ((f = fopen(fn, "w")) != NULL) { | ||
| 1383 | fprintf(f, "%s\n", str); | ||
| 1384 | fclose(f); | ||
| 1385 | } | ||
| 1379 | } | 1386 | } |
| 1380 | } | 1387 | } |
| 1381 | 1388 | ||
| @@ -1384,13 +1391,16 @@ xs_str *static_get_meta(snac *snac, const char *id) | |||
| 1384 | /* gets metadata from a media */ | 1391 | /* gets metadata from a media */ |
| 1385 | { | 1392 | { |
| 1386 | xs *fn = _static_fn(snac, id); | 1393 | xs *fn = _static_fn(snac, id); |
| 1387 | fn = xs_str_cat(fn, ".txt"); | ||
| 1388 | xs_str *r = NULL; | 1394 | xs_str *r = NULL; |
| 1389 | FILE *f; | ||
| 1390 | 1395 | ||
| 1391 | if ((f = fopen(fn, "r")) != NULL) { | 1396 | if (fn) { |
| 1392 | r = xs_strip_i(xs_readline(f)); | 1397 | fn = xs_str_cat(fn, ".txt"); |
| 1393 | fclose(f); | 1398 | FILE *f; |
| 1399 | |||
| 1400 | if ((f = fopen(fn, "r")) != NULL) { | ||
| 1401 | r = xs_strip_i(xs_readline(f)); | ||
| 1402 | fclose(f); | ||
| 1403 | } | ||
| 1394 | } | 1404 | } |
| 1395 | else | 1405 | else |
| 1396 | r = xs_str_new(""); | 1406 | r = xs_str_new(""); |