diff options
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 52 |
1 files changed, 25 insertions, 27 deletions
| @@ -1538,21 +1538,10 @@ int limited(snac *user, const char *id, int cmd) | |||
| 1538 | 1538 | ||
| 1539 | /** static data **/ | 1539 | /** static data **/ |
| 1540 | 1540 | ||
| 1541 | xs_str *_static_fn(snac *snac, const char *id) | 1541 | static int _load_raw_file(const char *fn, xs_val **data, int *size, |
| 1542 | /* gets the filename for a static file */ | 1542 | const char *inm, xs_str **etag) |
| 1543 | /* loads a cached file */ | ||
| 1543 | { | 1544 | { |
| 1544 | if (strchr(id, '/')) | ||
| 1545 | return NULL; | ||
| 1546 | else | ||
| 1547 | return xs_fmt("%s/static/%s", snac->basedir, id); | ||
| 1548 | } | ||
| 1549 | |||
| 1550 | |||
| 1551 | int static_get(snac *snac, const char *id, xs_val **data, int *size, | ||
| 1552 | const char *inm, xs_str **etag) | ||
| 1553 | /* returns static content */ | ||
| 1554 | { | ||
| 1555 | xs *fn = _static_fn(snac, id); | ||
| 1556 | int status = 404; | 1545 | int status = 404; |
| 1557 | 1546 | ||
| 1558 | if (fn) { | 1547 | if (fn) { |
| @@ -1584,7 +1573,7 @@ int static_get(snac *snac, const char *id, xs_val **data, int *size, | |||
| 1584 | if (etag != NULL) | 1573 | if (etag != NULL) |
| 1585 | *etag = xs_dup(e); | 1574 | *etag = xs_dup(e); |
| 1586 | 1575 | ||
| 1587 | srv_debug(1, xs_fmt("static_get(): %s %d", id, status)); | 1576 | srv_debug(1, xs_fmt("_load_raw_file(): %s %d", fn, status)); |
| 1588 | } | 1577 | } |
| 1589 | } | 1578 | } |
| 1590 | 1579 | ||
| @@ -1592,6 +1581,26 @@ int static_get(snac *snac, const char *id, xs_val **data, int *size, | |||
| 1592 | } | 1581 | } |
| 1593 | 1582 | ||
| 1594 | 1583 | ||
| 1584 | xs_str *_static_fn(snac *snac, const char *id) | ||
| 1585 | /* gets the filename for a static file */ | ||
| 1586 | { | ||
| 1587 | if (strchr(id, '/')) | ||
| 1588 | return NULL; | ||
| 1589 | else | ||
| 1590 | return xs_fmt("%s/static/%s", snac->basedir, id); | ||
| 1591 | } | ||
| 1592 | |||
| 1593 | |||
| 1594 | int static_get(snac *snac, const char *id, xs_val **data, int *size, | ||
| 1595 | const char *inm, xs_str **etag) | ||
| 1596 | /* returns static content */ | ||
| 1597 | { | ||
| 1598 | xs *fn = _static_fn(snac, id); | ||
| 1599 | |||
| 1600 | return _load_raw_file(fn, data, size, inm, etag); | ||
| 1601 | } | ||
| 1602 | |||
| 1603 | |||
| 1595 | void static_put(snac *snac, const char *id, const char *data, int size) | 1604 | void static_put(snac *snac, const char *id, const char *data, int size) |
| 1596 | /* writes status content */ | 1605 | /* writes status content */ |
| 1597 | { | 1606 | { |
| @@ -1685,19 +1694,8 @@ int history_get(snac *snac, const char *id, xs_str **content, int *size, | |||
| 1685 | const char *inm, xs_str **etag) | 1694 | const char *inm, xs_str **etag) |
| 1686 | { | 1695 | { |
| 1687 | xs *fn = _history_fn(snac, id); | 1696 | xs *fn = _history_fn(snac, id); |
| 1688 | FILE *f; | ||
| 1689 | int status = 404; | ||
| 1690 | |||
| 1691 | if (fn && (f = fopen(fn, "r")) != NULL) { | ||
| 1692 | *content = xs_readall(f); | ||
| 1693 | fclose(f); | ||
| 1694 | 1697 | ||
| 1695 | *size = strlen(*content); | 1698 | return _load_raw_file(fn, content, size, inm, etag); |
| 1696 | |||
| 1697 | status = 200; | ||
| 1698 | } | ||
| 1699 | |||
| 1700 | return status; | ||
| 1701 | } | 1699 | } |
| 1702 | 1700 | ||
| 1703 | 1701 | ||