diff options
| author | 2024-05-08 10:27:30 +0200 | |
|---|---|---|
| committer | 2024-05-08 10:27:30 +0200 | |
| commit | dc74cac6c9c3f6e9edc848381422a1f124abac73 (patch) | |
| tree | afa60f85839300e03affa44ed792d79cbe9626cd /data.c | |
| parent | New function search_by_content(). (diff) | |
| download | snac2-dc74cac6c9c3f6e9edc848381422a1f124abac73.tar.gz snac2-dc74cac6c9c3f6e9edc848381422a1f124abac73.tar.xz snac2-dc74cac6c9c3f6e9edc848381422a1f124abac73.zip | |
Added a timeout flag to search_by_content().
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 13 |
1 files changed, 8 insertions, 5 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 | ||