Mercurial > irccd
comparison plugins/links/links.c @ 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 | ae8b91ec4e4a |
children | f06e9761cc90 |
comparison
equal
deleted
inserted
replaced
1114:cda2076a7ece | 1115:b9421902ba71 |
---|---|
187 | 187 |
188 static void | 188 static void |
189 req_finish(struct req *); | 189 req_finish(struct req *); |
190 | 190 |
191 static void | 191 static void |
192 complete(struct req *req) | 192 complete(void *data) |
193 { | 193 { |
194 struct req *req = data; | |
194 char *title; | 195 char *title; |
195 | 196 |
196 if (req->status && (title = parse(req))) | 197 if (req->status && (title = parse(req))) |
197 irc_server_message(req->server, req->chan, fmt(req, title)); | 198 irc_server_message(req->server, req->chan, fmt(req, title)); |
198 | 199 |
202 | 203 |
203 /* | 204 /* |
204 * This function is running in a separate thread. | 205 * This function is running in a separate thread. |
205 */ | 206 */ |
206 static void * | 207 static void * |
207 routine(struct req *req) | 208 routine(void *data) |
208 { | 209 { |
209 typedef void (*func_t)(void *); | 210 struct req *req = data; |
210 | 211 long code = 0; |
211 if (curl_easy_perform(req->curl) == 0) | 212 |
212 req->status = 1; | 213 if (curl_easy_perform(req->curl) == 0) { |
213 | 214 /* We only accept 200 result. */ |
214 irc_bot_post((func_t)complete, req); | 215 curl_easy_getinfo(req->curl, CURLINFO_RESPONSE_CODE, &code); |
216 req->status = code == 200; | |
217 } | |
218 | |
219 irc_bot_post(complete, req); | |
215 | 220 |
216 return NULL; | 221 return NULL; |
217 } | 222 } |
218 | 223 |
219 static void | 224 static void |
276 } | 281 } |
277 | 282 |
278 static void | 283 static void |
279 req_start(struct req *req) | 284 req_start(struct req *req) |
280 { | 285 { |
281 typedef void *(*func_t)(void *); | 286 if (pthread_create(&req->thr, NULL, routine, req) != 0) |
282 | |
283 if (pthread_create(&req->thr, NULL, (func_t)routine, req) != 0) | |
284 req_finish(req); | 287 req_finish(req); |
285 } | 288 } |
286 | 289 |
287 void | 290 void |
288 links_event(const struct irc_event *ev) | 291 links_event(const struct irc_event *ev) |