diff options
| author | 2024-05-08 10:27:30 +0200 | |
|---|---|---|
| committer | 2024-05-08 10:27:30 +0200 | |
| commit | dc74cac6c9c3f6e9edc848381422a1f124abac73 (patch) | |
| tree | afa60f85839300e03affa44ed792d79cbe9626cd | |
| parent | New function search_by_content(). (diff) | |
| download | penes-snac2-dc74cac6c9c3f6e9edc848381422a1f124abac73.tar.gz penes-snac2-dc74cac6c9c3f6e9edc848381422a1f124abac73.tar.xz penes-snac2-dc74cac6c9c3f6e9edc848381422a1f124abac73.zip | |
Added a timeout flag to search_by_content().
| -rw-r--r-- | data.c | 13 | ||||
| -rw-r--r-- | main.c | 3 | ||||
| -rw-r--r-- | snac.h | 2 |
3 files changed, 11 insertions, 7 deletions
| @@ -2491,25 +2491,28 @@ void notify_clear(snac *snac) | |||
| 2491 | /** searches **/ | 2491 | /** searches **/ |
| 2492 | 2492 | ||
| 2493 | xs_list *search_by_content(snac *user, const xs_list *timeline, | 2493 | xs_list *search_by_content(snac *user, const xs_list *timeline, |
| 2494 | const char *regex, int timeout) | 2494 | const char *regex, int max_secs, int *timeout) |
| 2495 | /* returns a list of posts which content matches the regex */ | 2495 | /* returns a list of posts which content matches the regex */ |
| 2496 | { | 2496 | { |
| 2497 | xs_list *r = xs_list_new(); | 2497 | xs_list *r = xs_list_new(); |
| 2498 | 2498 | ||
| 2499 | if (timeout == 0) | 2499 | if (max_secs == 0) |
| 2500 | timeout = 3; | 2500 | max_secs = 3; |
| 2501 | 2501 | ||
| 2502 | int c = 0; | 2502 | int c = 0; |
| 2503 | char *v; | 2503 | char *v; |
| 2504 | 2504 | ||
| 2505 | time_t t = time(NULL) + timeout; | 2505 | time_t t = time(NULL) + max_secs; |
| 2506 | *timeout = 0; | ||
| 2506 | 2507 | ||
| 2507 | while (xs_list_next(timeline, &v, &c)) { | 2508 | while (xs_list_next(timeline, &v, &c)) { |
| 2508 | xs *post = NULL; | 2509 | xs *post = NULL; |
| 2509 | 2510 | ||
| 2510 | /* timeout? */ | 2511 | /* timeout? */ |
| 2511 | if (time(NULL) > t) | 2512 | if (time(NULL) > t) { |
| 2513 | *timeout = 1; | ||
| 2512 | break; | 2514 | break; |
| 2515 | } | ||
| 2513 | 2516 | ||
| 2514 | int status; | 2517 | int status; |
| 2515 | 2518 | ||
| @@ -377,9 +377,10 @@ int main(int argc, char *argv[]) | |||
| 377 | 377 | ||
| 378 | if (strcmp(cmd, "search") == 0) { /** **/ | 378 | if (strcmp(cmd, "search") == 0) { /** **/ |
| 379 | xs *tl = timeline_simple_list(&snac, "private", 0, XS_ALL); | 379 | xs *tl = timeline_simple_list(&snac, "private", 0, XS_ALL); |
| 380 | int to; | ||
| 380 | 381 | ||
| 381 | /* 'url' contains the regex */ | 382 | /* 'url' contains the regex */ |
| 382 | xs *r = search_by_content(&snac, tl, url, 10); | 383 | xs *r = search_by_content(&snac, tl, url, 10, &to); |
| 383 | 384 | ||
| 384 | int c = 0; | 385 | int c = 0; |
| 385 | char *v; | 386 | char *v; |
| @@ -180,7 +180,7 @@ xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int | |||
| 180 | void list_distribute(snac *user, const char *who, const xs_dict *post); | 180 | void list_distribute(snac *user, const char *who, const xs_dict *post); |
| 181 | 181 | ||
| 182 | xs_list *search_by_content(snac *user, const xs_list *timeline, | 182 | xs_list *search_by_content(snac *user, const xs_list *timeline, |
| 183 | const char *regex, int timeout); | 183 | const char *regex, int max_secs, int *timeout); |
| 184 | 184 | ||
| 185 | int actor_add(const char *actor, xs_dict *msg); | 185 | int actor_add(const char *actor, xs_dict *msg); |
| 186 | int actor_get(const char *actor, xs_dict **data); | 186 | int actor_get(const char *actor, xs_dict **data); |