Mercurial > irccd
changeset 1115:b9421902ba71
plugin links: don't print title if HTTP status is not 200
While here, be more pedantic.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 10 Nov 2021 15:35:39 +0100 |
parents | cda2076a7ece |
children | 337b6eb1fa19 |
files | plugins/links/links.c |
diffstat | 1 files changed, 12 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/links/links.c Thu Nov 04 14:50:10 2021 +0100 +++ b/plugins/links/links.c Wed Nov 10 15:35:39 2021 +0100 @@ -189,8 +189,9 @@ req_finish(struct req *); static void -complete(struct req *req) +complete(void *data) { + struct req *req = data; char *title; if (req->status && (title = parse(req))) @@ -204,14 +205,18 @@ * This function is running in a separate thread. */ static void * -routine(struct req *req) +routine(void *data) { - typedef void (*func_t)(void *); + struct req *req = data; + long code = 0; - if (curl_easy_perform(req->curl) == 0) - req->status = 1; + if (curl_easy_perform(req->curl) == 0) { + /* We only accept 200 result. */ + curl_easy_getinfo(req->curl, CURLINFO_RESPONSE_CODE, &code); + req->status = code == 200; + } - irc_bot_post((func_t)complete, req); + irc_bot_post(complete, req); return NULL; } @@ -278,9 +283,7 @@ static void req_start(struct req *req) { - typedef void *(*func_t)(void *); - - if (pthread_create(&req->thr, NULL, (func_t)routine, req) != 0) + if (pthread_create(&req->thr, NULL, routine, req) != 0) req_finish(req); }