commit dc74cac

default  ·  2024-05-08 08:27:30 +0000 UTC
parent 3ab733c
Added a timeout flag to search_by_content().
3 files changed,  +11, -7
M data.c
M main.c
M snac.h
M data.c
+8, -5
 1@@ -2491,25 +2491,28 @@ void notify_clear(snac *snac)
 2 /** searches **/
 3 
 4 xs_list *search_by_content(snac *user, const xs_list *timeline,
 5-                            const char *regex, int timeout)
 6+                            const char *regex, int max_secs, int *timeout)
 7 /* returns a list of posts which content matches the regex */
 8 {
 9     xs_list *r = xs_list_new();
10 
11-    if (timeout == 0)
12-        timeout = 3;
13+    if (max_secs == 0)
14+        max_secs = 3;
15 
16     int c = 0;
17     char *v;
18 
19-    time_t t = time(NULL) + timeout;
20+    time_t t = time(NULL) + max_secs;
21+    *timeout = 0;
22 
23     while (xs_list_next(timeline, &v, &c)) {
24         xs *post = NULL;
25 
26         /* timeout? */
27-        if (time(NULL) > t)
28+        if (time(NULL) > t) {
29+            *timeout = 1;
30             break;
31+        }
32 
33         int status;
34 
M main.c
+2, -1
 1@@ -377,9 +377,10 @@ int main(int argc, char *argv[])
 2 
 3     if (strcmp(cmd, "search") == 0) { /** **/
 4         xs *tl = timeline_simple_list(&snac, "private", 0, XS_ALL);
 5+        int to;
 6 
 7         /* 'url' contains the regex */
 8-        xs *r = search_by_content(&snac, tl, url, 10);
 9+        xs *r = search_by_content(&snac, tl, url, 10, &to);
10 
11         int c = 0;
12         char *v;
M snac.h
+1, -1
1@@ -180,7 +180,7 @@ xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int
2 void list_distribute(snac *user, const char *who, const xs_dict *post);
3 
4 xs_list *search_by_content(snac *user, const xs_list *timeline,
5-                            const char *regex, int timeout);
6+                            const char *regex, int max_secs, int *timeout);
7 
8 int actor_add(const char *actor, xs_dict *msg);
9 int actor_get(const char *actor, xs_dict **data);