mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-14 17:45:04 +00:00
Added a timeout flag to search_by_content().
This commit is contained in:
parent
3ab733cdf5
commit
dc74cac6c9
3 changed files with 11 additions and 7 deletions
13
data.c
13
data.c
|
@ -2491,25 +2491,28 @@ void notify_clear(snac *snac)
|
|||
/** searches **/
|
||||
|
||||
xs_list *search_by_content(snac *user, const xs_list *timeline,
|
||||
const char *regex, int timeout)
|
||||
const char *regex, int max_secs, int *timeout)
|
||||
/* returns a list of posts which content matches the regex */
|
||||
{
|
||||
xs_list *r = xs_list_new();
|
||||
|
||||
if (timeout == 0)
|
||||
timeout = 3;
|
||||
if (max_secs == 0)
|
||||
max_secs = 3;
|
||||
|
||||
int c = 0;
|
||||
char *v;
|
||||
|
||||
time_t t = time(NULL) + timeout;
|
||||
time_t t = time(NULL) + max_secs;
|
||||
*timeout = 0;
|
||||
|
||||
while (xs_list_next(timeline, &v, &c)) {
|
||||
xs *post = NULL;
|
||||
|
||||
/* timeout? */
|
||||
if (time(NULL) > t)
|
||||
if (time(NULL) > t) {
|
||||
*timeout = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
int status;
|
||||
|
||||
|
|
3
main.c
3
main.c
|
@ -377,9 +377,10 @@ int main(int argc, char *argv[])
|
|||
|
||||
if (strcmp(cmd, "search") == 0) { /** **/
|
||||
xs *tl = timeline_simple_list(&snac, "private", 0, XS_ALL);
|
||||
int to;
|
||||
|
||||
/* 'url' contains the regex */
|
||||
xs *r = search_by_content(&snac, tl, url, 10);
|
||||
xs *r = search_by_content(&snac, tl, url, 10, &to);
|
||||
|
||||
int c = 0;
|
||||
char *v;
|
||||
|
|
2
snac.h
2
snac.h
|
@ -180,7 +180,7 @@ xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int
|
|||
void list_distribute(snac *user, const char *who, const xs_dict *post);
|
||||
|
||||
xs_list *search_by_content(snac *user, const xs_list *timeline,
|
||||
const char *regex, int timeout);
|
||||
const char *regex, int max_secs, int *timeout);
|
||||
|
||||
int actor_add(const char *actor, xs_dict *msg);
|
||||
int actor_get(const char *actor, xs_dict **data);
|
||||
|
|
Loading…
Reference in a new issue