Mercurial > irccd
changeset 990:daaf92c097e6
plugin links: add timeout support
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 10 Feb 2021 18:11:46 +0100 |
parents | 73fdae7aa902 |
children | 2e8ba5a5630d |
files | plugins/links/links.c |
diffstat | 1 files changed, 31 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/links/links.c Wed Feb 10 17:56:14 2021 +0100 +++ b/plugins/links/links.c Wed Feb 10 18:11:46 2021 +0100 @@ -58,6 +58,8 @@ TPL_INFO }; +static unsigned long timeout = 30; + static char templates[][512] = { [TPL_INFO] = "#{nickname}, voici le lien: #{title}" }; @@ -193,6 +195,7 @@ curl_easy_setopt(req->curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(req->curl, CURLOPT_WRITEFUNCTION, callback); curl_easy_setopt(req->curl, CURLOPT_WRITEDATA, req); + curl_easy_setopt(req->curl, CURLOPT_TIMEOUT, timeout); return req; @@ -263,6 +266,34 @@ return keys; } +void +links_set_option(const char *key, const char *value) +{ + if (strcmp(key, "timeout") == 0) + timeout = atol(value); +} + +const char * +links_get_option(const char *key) +{ + static char out[32]; + + if (strcmp(key, "timeout") == 0) { + snprintf(out, sizeof (out), "%lu", timeout); + return out; + } + + return NULL; +} + +const char ** +links_get_options(void) +{ + static const char *keys[] = { "timeout", NULL }; + + return keys; +} + const char *links_description = "Parse links from messages"; const char *links_version = IRCCD_VERSION; const char *links_license = "ISC";