summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2024-05-08 10:27:30 +0200
committerGravatar default2024-05-08 10:27:30 +0200
commitdc74cac6c9c3f6e9edc848381422a1f124abac73 (patch)
treeafa60f85839300e03affa44ed792d79cbe9626cd
parentNew function search_by_content(). (diff)
downloadpenes-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.c13
-rw-r--r--main.c3
-rw-r--r--snac.h2
3 files changed, 11 insertions, 7 deletions
diff --git a/data.c b/data.c
index bc9f979..82f36a4 100644
--- a/data.c
+++ b/data.c
@@ -2491,25 +2491,28 @@ void notify_clear(snac *snac)
2491/** searches **/ 2491/** searches **/
2492 2492
2493xs_list *search_by_content(snac *user, const xs_list *timeline, 2493xs_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
diff --git a/main.c b/main.c
index 2e1a77c..9244b5a 100644
--- a/main.c
+++ b/main.c
@@ -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;
diff --git a/snac.h b/snac.h
index ae8fc59..7f069ab 100644
--- a/snac.h
+++ b/snac.h
@@ -180,7 +180,7 @@ xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int
180void list_distribute(snac *user, const char *who, const xs_dict *post); 180void list_distribute(snac *user, const char *who, const xs_dict *post);
181 181
182xs_list *search_by_content(snac *user, const xs_list *timeline, 182xs_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
185int actor_add(const char *actor, xs_dict *msg); 185int actor_add(const char *actor, xs_dict *msg);
186int actor_get(const char *actor, xs_dict **data); 186int actor_get(const char *actor, xs_dict **data);