diff options
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 44 |
1 files changed, 44 insertions, 0 deletions
| @@ -1500,6 +1500,50 @@ int actor_get(snac *snac1, const char *actor, xs_dict **data) | |||
| 1500 | } | 1500 | } |
| 1501 | 1501 | ||
| 1502 | 1502 | ||
| 1503 | /** user limiting (announce blocks) **/ | ||
| 1504 | |||
| 1505 | int limited(snac *user, const char *id, int cmd) | ||
| 1506 | /* announce messages from a followed (0: check, 1: limit; 2: unlimit) */ | ||
| 1507 | { | ||
| 1508 | int ret = 0; | ||
| 1509 | xs *fn = xs_fmt("%s/limited/", user->basedir); | ||
| 1510 | mkdirx(fn); | ||
| 1511 | |||
| 1512 | xs *md5 = xs_md5_hex(id, strlen(id)); | ||
| 1513 | fn = xs_str_cat(fn, md5); | ||
| 1514 | |||
| 1515 | switch (cmd) { | ||
| 1516 | case 0: /** check **/ | ||
| 1517 | ret = !!(mtime(fn) > 0.0); | ||
| 1518 | break; | ||
| 1519 | |||
| 1520 | case 1: /** limit **/ | ||
| 1521 | if (mtime(fn) > 0.0) | ||
| 1522 | ret = -1; | ||
| 1523 | else { | ||
| 1524 | FILE *f; | ||
| 1525 | |||
| 1526 | if ((f = fopen(fn, "w")) != NULL) { | ||
| 1527 | fprintf(f, "%s\n", id); | ||
| 1528 | fclose(f); | ||
| 1529 | } | ||
| 1530 | else | ||
| 1531 | ret = -2; | ||
| 1532 | } | ||
| 1533 | break; | ||
| 1534 | |||
| 1535 | case 2: /** unlimit **/ | ||
| 1536 | if (mtime(fn) > 0.0) | ||
| 1537 | ret = unlink(fn); | ||
| 1538 | else | ||
| 1539 | ret = -1; | ||
| 1540 | break; | ||
| 1541 | } | ||
| 1542 | |||
| 1543 | return ret; | ||
| 1544 | } | ||
| 1545 | |||
| 1546 | |||
| 1503 | /** static data **/ | 1547 | /** static data **/ |
| 1504 | 1548 | ||
| 1505 | xs_str *_static_fn(snac *snac, const char *id) | 1549 | xs_str *_static_fn(snac *snac, const char *id) |