diff options
| -rw-r--r-- | data.c | 31 | ||||
| -rw-r--r-- | snac.h | 10 |
2 files changed, 25 insertions, 16 deletions
| @@ -1409,14 +1409,19 @@ xs_str *static_get_meta(snac *snac, const char *id) | |||
| 1409 | } | 1409 | } |
| 1410 | 1410 | ||
| 1411 | 1411 | ||
| 1412 | d_char *_history_fn(snac *snac, char *id) | 1412 | /** history **/ |
| 1413 | |||
| 1414 | xs_str *_history_fn(snac *snac, const char *id) | ||
| 1413 | /* gets the filename for the history */ | 1415 | /* gets the filename for the history */ |
| 1414 | { | 1416 | { |
| 1415 | return xs_fmt("%s/history/%s", snac->basedir, id); | 1417 | if (strchr(id, '/')) |
| 1418 | return NULL; | ||
| 1419 | else | ||
| 1420 | return xs_fmt("%s/history/%s", snac->basedir, id); | ||
| 1416 | } | 1421 | } |
| 1417 | 1422 | ||
| 1418 | 1423 | ||
| 1419 | double history_mtime(snac *snac, char * id) | 1424 | double history_mtime(snac *snac, const char *id) |
| 1420 | { | 1425 | { |
| 1421 | double t = 0.0; | 1426 | double t = 0.0; |
| 1422 | xs *fn = _history_fn(snac, id); | 1427 | xs *fn = _history_fn(snac, id); |
| @@ -1428,26 +1433,26 @@ double history_mtime(snac *snac, char * id) | |||
| 1428 | } | 1433 | } |
| 1429 | 1434 | ||
| 1430 | 1435 | ||
| 1431 | void history_add(snac *snac, char *id, char *content, int size) | 1436 | void history_add(snac *snac, const char *id, const char *content, int size) |
| 1432 | /* adds something to the history */ | 1437 | /* adds something to the history */ |
| 1433 | { | 1438 | { |
| 1434 | xs *fn = _history_fn(snac, id); | 1439 | xs *fn = _history_fn(snac, id); |
| 1435 | FILE *f; | 1440 | FILE *f; |
| 1436 | 1441 | ||
| 1437 | if ((f = fopen(fn, "w")) != NULL) { | 1442 | if (fn && (f = fopen(fn, "w")) != NULL) { |
| 1438 | fwrite(content, size, 1, f); | 1443 | fwrite(content, size, 1, f); |
| 1439 | fclose(f); | 1444 | fclose(f); |
| 1440 | } | 1445 | } |
| 1441 | } | 1446 | } |
| 1442 | 1447 | ||
| 1443 | 1448 | ||
| 1444 | d_char *history_get(snac *snac, char *id) | 1449 | xs_str *history_get(snac *snac, const char *id) |
| 1445 | { | 1450 | { |
| 1446 | d_char *content = NULL; | 1451 | xs_str *content = NULL; |
| 1447 | xs *fn = _history_fn(snac, id); | 1452 | xs *fn = _history_fn(snac, id); |
| 1448 | FILE *f; | 1453 | FILE *f; |
| 1449 | 1454 | ||
| 1450 | if ((f = fopen(fn, "r")) != NULL) { | 1455 | if (fn && (f = fopen(fn, "r")) != NULL) { |
| 1451 | content = xs_readall(f); | 1456 | content = xs_readall(f); |
| 1452 | fclose(f); | 1457 | fclose(f); |
| 1453 | } | 1458 | } |
| @@ -1456,14 +1461,18 @@ d_char *history_get(snac *snac, char *id) | |||
| 1456 | } | 1461 | } |
| 1457 | 1462 | ||
| 1458 | 1463 | ||
| 1459 | int history_del(snac *snac, char *id) | 1464 | int history_del(snac *snac, const char *id) |
| 1460 | { | 1465 | { |
| 1461 | xs *fn = _history_fn(snac, id); | 1466 | xs *fn = _history_fn(snac, id); |
| 1462 | return unlink(fn); | 1467 | |
| 1468 | if (fn) | ||
| 1469 | return unlink(fn); | ||
| 1470 | else | ||
| 1471 | return -1; | ||
| 1463 | } | 1472 | } |
| 1464 | 1473 | ||
| 1465 | 1474 | ||
| 1466 | d_char *history_list(snac *snac) | 1475 | xs_list *history_list(snac *snac) |
| 1467 | { | 1476 | { |
| 1468 | xs *spec = xs_fmt("%s/history/" "*.html", snac->basedir); | 1477 | xs *spec = xs_fmt("%s/history/" "*.html", snac->basedir); |
| 1469 | 1478 | ||
| @@ -133,11 +133,11 @@ void static_put(snac *snac, const char *id, const char *data, int size); | |||
| 133 | void static_put_meta(snac *snac, const char *id, const char *str); | 133 | void static_put_meta(snac *snac, const char *id, const char *str); |
| 134 | xs_str *static_get_meta(snac *snac, const char *id); | 134 | xs_str *static_get_meta(snac *snac, const char *id); |
| 135 | 135 | ||
| 136 | double history_mtime(snac *snac, char *id); | 136 | double history_mtime(snac *snac, const char *id); |
| 137 | void history_add(snac *snac, char *id, char *content, int size); | 137 | void history_add(snac *snac, const char *id, const char *content, int size); |
| 138 | d_char *history_get(snac *snac, char *id); | 138 | xs_str *history_get(snac *snac, const char *id); |
| 139 | int history_del(snac *snac, char *id); | 139 | int history_del(snac *snac, const char *id); |
| 140 | d_char *history_list(snac *snac); | 140 | xs_list *history_list(snac *snac); |
| 141 | 141 | ||
| 142 | void lastlog_write(snac *snac); | 142 | void lastlog_write(snac *snac); |
| 143 | 143 | ||