summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'data.c')
-rw-r--r--data.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/data.c b/data.c
index fef0f0f..223ad45 100644
--- a/data.c
+++ b/data.c
@@ -1409,14 +1409,19 @@ xs_str *static_get_meta(snac *snac, const char *id)
1409} 1409}
1410 1410
1411 1411
1412d_char *_history_fn(snac *snac, char *id) 1412/** history **/
1413
1414xs_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
1419double history_mtime(snac *snac, char * id) 1424double 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
1431void history_add(snac *snac, char *id, char *content, int size) 1436void 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
1444d_char *history_get(snac *snac, char *id) 1449xs_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
1459int history_del(snac *snac, char *id) 1464int 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
1466d_char *history_list(snac *snac) 1475xs_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