Merge pull request #3329 from efuss/fix-3311
[collectd.git] / src / curl.c
1 /**
2  * collectd - src/curl.c
3  * Copyright (C) 2006-2009  Florian octo Forster
4  * Copyright (C) 2009       Aman Gupta
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation; only version 2 of the License is applicable.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  *
19  * Authors:
20  *   Florian octo Forster <octo at collectd.org>
21  *   Aman Gupta <aman at tmm1.net>
22  **/
23
24 #include "collectd.h"
25
26 #include "plugin.h"
27 #include "utils/common/common.h"
28 #include "utils/curl_stats/curl_stats.h"
29 #include "utils/match/match.h"
30 #include "utils_time.h"
31
32 #include <curl/curl.h>
33
34 /*
35  * Data types
36  */
37 struct web_match_s;
38 typedef struct web_match_s web_match_t;
39 struct web_match_s /* {{{ */
40 {
41   char *regex;
42   char *exclude_regex;
43   int dstype;
44   char *type;
45   char *instance;
46
47   cu_match_t *match;
48
49   web_match_t *next;
50 }; /* }}} */
51
52 struct web_page_s;
53 typedef struct web_page_s web_page_t;
54 struct web_page_s /* {{{ */
55 {
56   char *plugin_name;
57   char *instance;
58
59   char *url;
60   int address_family;
61   char *user;
62   char *pass;
63   char *credentials;
64   bool digest;
65   bool verify_peer;
66   bool verify_host;
67   char *cacert;
68   struct curl_slist *headers;
69   char *post_body;
70   bool response_time;
71   bool response_code;
72   int timeout;
73   curl_stats_t *stats;
74
75   CURL *curl;
76   char curl_errbuf[CURL_ERROR_SIZE];
77   char *buffer;
78   size_t buffer_size;
79   size_t buffer_fill;
80
81   web_match_t *matches;
82 }; /* }}} */
83
84 /*
85  * Private functions
86  */
87 static int cc_read_page(user_data_t *ud);
88
89 static size_t cc_curl_callback(void *buf, /* {{{ */
90                                size_t size, size_t nmemb, void *user_data) {
91   web_page_t *wp;
92   size_t len;
93
94   len = size * nmemb;
95   if (len == 0)
96     return len;
97
98   wp = user_data;
99   if (wp == NULL)
100     return 0;
101
102   if ((wp->buffer_fill + len) >= wp->buffer_size) {
103     char *temp;
104     size_t temp_size;
105
106     temp_size = wp->buffer_fill + len + 1;
107     temp = realloc(wp->buffer, temp_size);
108     if (temp == NULL) {
109       ERROR("curl plugin: realloc failed.");
110       return 0;
111     }
112     wp->buffer = temp;
113     wp->buffer_size = temp_size;
114   }
115
116   memcpy(wp->buffer + wp->buffer_fill, (char *)buf, len);
117   wp->buffer_fill += len;
118   wp->buffer[wp->buffer_fill] = 0;
119
120   return len;
121 } /* }}} size_t cc_curl_callback */
122
123 static void cc_web_match_free(web_match_t *wm) /* {{{ */
124 {
125   if (wm == NULL)
126     return;
127
128   sfree(wm->regex);
129   sfree(wm->type);
130   sfree(wm->instance);
131   match_destroy(wm->match);
132   cc_web_match_free(wm->next);
133   sfree(wm);
134 } /* }}} void cc_web_match_free */
135
136 static void cc_web_page_free(void *arg) /* {{{ */
137 {
138   web_page_t *wp = (web_page_t *)arg;
139   if (wp == NULL)
140     return;
141
142   if (wp->curl != NULL)
143     curl_easy_cleanup(wp->curl);
144   wp->curl = NULL;
145
146   sfree(wp->plugin_name);
147   sfree(wp->instance);
148
149   sfree(wp->url);
150   sfree(wp->user);
151   sfree(wp->pass);
152   sfree(wp->credentials);
153   sfree(wp->cacert);
154   sfree(wp->post_body);
155   curl_slist_free_all(wp->headers);
156   curl_stats_destroy(wp->stats);
157
158   sfree(wp->buffer);
159
160   cc_web_match_free(wp->matches);
161   sfree(wp);
162 } /* }}} void cc_web_page_free */
163
164 static int cc_config_append_string(const char *name,
165                                    struct curl_slist **dest, /* {{{ */
166                                    oconfig_item_t *ci) {
167   struct curl_slist *temp = NULL;
168   if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
169     WARNING("curl plugin: `%s' needs exactly one string argument.", name);
170     return -1;
171   }
172
173   temp = curl_slist_append(*dest, ci->values[0].value.string);
174   if (temp == NULL)
175     return -1;
176
177   *dest = temp;
178
179   return 0;
180 } /* }}} int cc_config_append_string */
181
182 static int cc_config_add_match_dstype(int *dstype_ret, /* {{{ */
183                                       oconfig_item_t *ci) {
184   int dstype;
185
186   if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
187     WARNING("curl plugin: `DSType' needs exactly one string argument.");
188     return -1;
189   }
190
191   if (strncasecmp("Gauge", ci->values[0].value.string, strlen("Gauge")) == 0) {
192     dstype = UTILS_MATCH_DS_TYPE_GAUGE;
193     if (strcasecmp("GaugeAverage", ci->values[0].value.string) == 0)
194       dstype |= UTILS_MATCH_CF_GAUGE_AVERAGE;
195     else if (strcasecmp("GaugeMin", ci->values[0].value.string) == 0)
196       dstype |= UTILS_MATCH_CF_GAUGE_MIN;
197     else if (strcasecmp("GaugeMax", ci->values[0].value.string) == 0)
198       dstype |= UTILS_MATCH_CF_GAUGE_MAX;
199     else if (strcasecmp("GaugeLast", ci->values[0].value.string) == 0)
200       dstype |= UTILS_MATCH_CF_GAUGE_LAST;
201     else
202       dstype = 0;
203   } else if (strncasecmp("Counter", ci->values[0].value.string,
204                          strlen("Counter")) == 0) {
205     dstype = UTILS_MATCH_DS_TYPE_COUNTER;
206     if (strcasecmp("CounterSet", ci->values[0].value.string) == 0)
207       dstype |= UTILS_MATCH_CF_COUNTER_SET;
208     else if (strcasecmp("CounterAdd", ci->values[0].value.string) == 0)
209       dstype |= UTILS_MATCH_CF_COUNTER_ADD;
210     else if (strcasecmp("CounterInc", ci->values[0].value.string) == 0)
211       dstype |= UTILS_MATCH_CF_COUNTER_INC;
212     else
213       dstype = 0;
214   } else if (strncasecmp("Derive", ci->values[0].value.string,
215                          strlen("Derive")) == 0) {
216     dstype = UTILS_MATCH_DS_TYPE_DERIVE;
217     if (strcasecmp("DeriveSet", ci->values[0].value.string) == 0)
218       dstype |= UTILS_MATCH_CF_DERIVE_SET;
219     else if (strcasecmp("DeriveAdd", ci->values[0].value.string) == 0)
220       dstype |= UTILS_MATCH_CF_DERIVE_ADD;
221     else if (strcasecmp("DeriveInc", ci->values[0].value.string) == 0)
222       dstype |= UTILS_MATCH_CF_DERIVE_INC;
223     else
224       dstype = 0;
225   } else if (strncasecmp("Absolute", ci->values[0].value.string,
226                          strlen("Absolute")) == 0) {
227     dstype = UTILS_MATCH_DS_TYPE_ABSOLUTE;
228     if (strcasecmp("AbsoluteSet", ci->values[0].value.string) ==
229         0) /* Absolute DS is reset-on-read so no sense doin anything else but
230               set */
231       dstype |= UTILS_MATCH_CF_ABSOLUTE_SET;
232     else
233       dstype = 0;
234   }
235
236   else {
237     dstype = 0;
238   }
239
240   if (dstype == 0) {
241     WARNING("curl plugin: `%s' is not a valid argument to `DSType'.",
242             ci->values[0].value.string);
243     return -1;
244   }
245
246   *dstype_ret = dstype;
247   return 0;
248 } /* }}} int cc_config_add_match_dstype */
249
250 static int cc_config_add_match(web_page_t *page, /* {{{ */
251                                oconfig_item_t *ci) {
252   web_match_t *match;
253   int status;
254
255   if (ci->values_num != 0) {
256     WARNING("curl plugin: Ignoring arguments for the `Match' block.");
257   }
258
259   match = calloc(1, sizeof(*match));
260   if (match == NULL) {
261     ERROR("curl plugin: calloc failed.");
262     return -1;
263   }
264
265   status = 0;
266   for (int i = 0; i < ci->children_num; i++) {
267     oconfig_item_t *child = ci->children + i;
268
269     if (strcasecmp("Regex", child->key) == 0)
270       status = cf_util_get_string(child, &match->regex);
271     else if (strcasecmp("ExcludeRegex", child->key) == 0)
272       status = cf_util_get_string(child, &match->exclude_regex);
273     else if (strcasecmp("DSType", child->key) == 0)
274       status = cc_config_add_match_dstype(&match->dstype, child);
275     else if (strcasecmp("Type", child->key) == 0)
276       status = cf_util_get_string(child, &match->type);
277     else if (strcasecmp("Instance", child->key) == 0)
278       status = cf_util_get_string(child, &match->instance);
279     else {
280       WARNING("curl plugin: Option `%s' not allowed here.", child->key);
281       status = -1;
282     }
283
284     if (status != 0)
285       break;
286   } /* for (i = 0; i < ci->children_num; i++) */
287
288   while (status == 0) {
289     if (match->regex == NULL) {
290       WARNING("curl plugin: `Regex' missing in `Match' block.");
291       status = -1;
292     }
293
294     if (match->type == NULL) {
295       WARNING("curl plugin: `Type' missing in `Match' block.");
296       status = -1;
297     }
298
299     if (match->dstype == 0) {
300       WARNING("curl plugin: `DSType' missing in `Match' block.");
301       status = -1;
302     }
303
304     break;
305   } /* while (status == 0) */
306
307   if (status != 0) {
308     cc_web_match_free(match);
309     return status;
310   }
311
312   match->match =
313       match_create_simple(match->regex, match->exclude_regex, match->dstype);
314   if (match->match == NULL) {
315     ERROR("curl plugin: match_create_simple failed.");
316     cc_web_match_free(match);
317     return -1;
318   } else {
319     web_match_t *prev;
320
321     prev = page->matches;
322     while ((prev != NULL) && (prev->next != NULL))
323       prev = prev->next;
324
325     if (prev == NULL)
326       page->matches = match;
327     else
328       prev->next = match;
329   }
330
331   return 0;
332 } /* }}} int cc_config_add_match */
333
334 static int cc_page_init_curl(web_page_t *wp) /* {{{ */
335 {
336   wp->curl = curl_easy_init();
337   if (wp->curl == NULL) {
338     ERROR("curl plugin: curl_easy_init failed.");
339     return -1;
340   }
341
342   curl_easy_setopt(wp->curl, CURLOPT_NOSIGNAL, 1L);
343   curl_easy_setopt(wp->curl, CURLOPT_WRITEFUNCTION, cc_curl_callback);
344   curl_easy_setopt(wp->curl, CURLOPT_WRITEDATA, wp);
345   curl_easy_setopt(wp->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
346   curl_easy_setopt(wp->curl, CURLOPT_ERRORBUFFER, wp->curl_errbuf);
347   curl_easy_setopt(wp->curl, CURLOPT_FOLLOWLOCATION, 1L);
348   curl_easy_setopt(wp->curl, CURLOPT_MAXREDIRS, 50L);
349   curl_easy_setopt(wp->curl, CURLOPT_IPRESOLVE, wp->address_family);
350
351   if (wp->user != NULL) {
352 #ifdef HAVE_CURLOPT_USERNAME
353     curl_easy_setopt(wp->curl, CURLOPT_USERNAME, wp->user);
354     curl_easy_setopt(wp->curl, CURLOPT_PASSWORD,
355                      (wp->pass == NULL) ? "" : wp->pass);
356 #else
357     size_t credentials_size;
358
359     credentials_size = strlen(wp->user) + 2;
360     if (wp->pass != NULL)
361       credentials_size += strlen(wp->pass);
362
363     wp->credentials = malloc(credentials_size);
364     if (wp->credentials == NULL) {
365       ERROR("curl plugin: malloc failed.");
366       return -1;
367     }
368
369     snprintf(wp->credentials, credentials_size, "%s:%s", wp->user,
370              (wp->pass == NULL) ? "" : wp->pass);
371     curl_easy_setopt(wp->curl, CURLOPT_USERPWD, wp->credentials);
372 #endif
373
374     if (wp->digest)
375       curl_easy_setopt(wp->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
376   }
377
378   curl_easy_setopt(wp->curl, CURLOPT_SSL_VERIFYPEER, (long)wp->verify_peer);
379   curl_easy_setopt(wp->curl, CURLOPT_SSL_VERIFYHOST, wp->verify_host ? 2L : 0L);
380   if (wp->cacert != NULL)
381     curl_easy_setopt(wp->curl, CURLOPT_CAINFO, wp->cacert);
382   if (wp->headers != NULL)
383     curl_easy_setopt(wp->curl, CURLOPT_HTTPHEADER, wp->headers);
384   if (wp->post_body != NULL)
385     curl_easy_setopt(wp->curl, CURLOPT_POSTFIELDS, wp->post_body);
386
387 #ifdef HAVE_CURLOPT_TIMEOUT_MS
388   if (wp->timeout >= 0)
389     curl_easy_setopt(wp->curl, CURLOPT_TIMEOUT_MS, (long)wp->timeout);
390   else
391     curl_easy_setopt(wp->curl, CURLOPT_TIMEOUT_MS,
392                      (long)CDTIME_T_TO_MS(plugin_get_interval()));
393 #endif
394
395   return 0;
396 } /* }}} int cc_page_init_curl */
397
398 static int cc_config_add_page(oconfig_item_t *ci) /* {{{ */
399 {
400   cdtime_t interval = 0;
401   web_page_t *page;
402   int status;
403
404   if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
405     WARNING("curl plugin: `Page' blocks need exactly one string argument.");
406     return -1;
407   }
408
409   page = calloc(1, sizeof(*page));
410   if (page == NULL) {
411     ERROR("curl plugin: calloc failed.");
412     return -1;
413   }
414   page->plugin_name = NULL;
415   page->url = NULL;
416   page->address_family = CURL_IPRESOLVE_WHATEVER;
417   page->user = NULL;
418   page->pass = NULL;
419   page->digest = false;
420   page->verify_peer = true;
421   page->verify_host = true;
422   page->response_time = false;
423   page->response_code = false;
424   page->timeout = -1;
425   page->stats = NULL;
426
427   page->instance = strdup(ci->values[0].value.string);
428   if (page->instance == NULL) {
429     ERROR("curl plugin: strdup failed.");
430     sfree(page);
431     return -1;
432   }
433
434   /* Process all children */
435   status = 0;
436   for (int i = 0; i < ci->children_num; i++) {
437     oconfig_item_t *child = ci->children + i;
438
439     if (strcasecmp("Plugin", child->key) == 0)
440       status = cf_util_get_string(child, &page->plugin_name);
441     else if (strcasecmp("URL", child->key) == 0)
442       status = cf_util_get_string(child, &page->url);
443     else if (strcasecmp("AddressFamily", child->key) == 0) {
444       char *af = NULL;
445       status = cf_util_get_string(child, &af);
446       if (status != 0 || af == NULL) {
447         WARNING("curl plugin: Cannot parse value of `%s' "
448                 "for instance `%s'.",
449                 child->key, page->instance);
450       } else if (strcasecmp("any", af) == 0) {
451         page->address_family = CURL_IPRESOLVE_WHATEVER;
452       } else if (strcasecmp("ipv4", af) == 0) {
453         page->address_family = CURL_IPRESOLVE_V4;
454       } else if (strcasecmp("ipv6", af) == 0) {
455         /* If curl supports ipv6, use it. If not, log a warning and
456          * fall back to default - don't set status to non-zero.
457          */
458         curl_version_info_data *curl_info = curl_version_info(CURLVERSION_NOW);
459         if (curl_info->features & CURL_VERSION_IPV6)
460           page->address_family = CURL_IPRESOLVE_V6;
461         else
462           WARNING("curl plugin: IPv6 not supported by this libCURL. "
463                   "Using fallback `any'.");
464       } else {
465         WARNING("curl plugin: Unsupported value of `%s' "
466                 "for instance `%s'.",
467                 child->key, page->instance);
468         status = -1;
469       }
470     } else if (strcasecmp("User", child->key) == 0)
471       status = cf_util_get_string(child, &page->user);
472     else if (strcasecmp("Password", child->key) == 0)
473       status = cf_util_get_string(child, &page->pass);
474     else if (strcasecmp("Digest", child->key) == 0)
475       status = cf_util_get_boolean(child, &page->digest);
476     else if (strcasecmp("VerifyPeer", child->key) == 0)
477       status = cf_util_get_boolean(child, &page->verify_peer);
478     else if (strcasecmp("VerifyHost", child->key) == 0)
479       status = cf_util_get_boolean(child, &page->verify_host);
480     else if (strcasecmp("MeasureResponseTime", child->key) == 0)
481       status = cf_util_get_boolean(child, &page->response_time);
482     else if (strcasecmp("MeasureResponseCode", child->key) == 0)
483       status = cf_util_get_boolean(child, &page->response_code);
484     else if (strcasecmp("CACert", child->key) == 0)
485       status = cf_util_get_string(child, &page->cacert);
486     else if (strcasecmp("Match", child->key) == 0)
487       /* Be liberal with failing matches => don't set `status'. */
488       cc_config_add_match(page, child);
489     else if (strcasecmp("Header", child->key) == 0)
490       status = cc_config_append_string("Header", &page->headers, child);
491     else if (strcasecmp("Post", child->key) == 0)
492       status = cf_util_get_string(child, &page->post_body);
493     else if (strcasecmp("Interval", child->key) == 0)
494       status = cf_util_get_cdtime(child, &interval);
495     else if (strcasecmp("Timeout", child->key) == 0)
496       status = cf_util_get_int(child, &page->timeout);
497     else if (strcasecmp("Statistics", child->key) == 0) {
498       page->stats = curl_stats_from_config(child);
499       if (page->stats == NULL)
500         status = -1;
501     } else {
502       WARNING("curl plugin: Option `%s' not allowed here.", child->key);
503       status = -1;
504     }
505
506     if (status != 0)
507       break;
508   } /* for (i = 0; i < ci->children_num; i++) */
509
510   /* Additionial sanity checks and libCURL initialization. */
511   while (status == 0) {
512     if (page->url == NULL) {
513       WARNING("curl plugin: `URL' missing in `Page' block.");
514       status = -1;
515     }
516
517     if (page->matches == NULL && page->stats == NULL && !page->response_time &&
518         !page->response_code) {
519       assert(page->instance != NULL);
520       WARNING("curl plugin: No (valid) `Match' block "
521               "or Statistics or MeasureResponseTime or MeasureResponseCode "
522               "within `Page' block `%s'.",
523               page->instance);
524       status = -1;
525     }
526
527     if (status == 0)
528       status = cc_page_init_curl(page);
529
530     break;
531   } /* while (status == 0) */
532
533   if (status != 0) {
534     cc_web_page_free(page);
535     return status;
536   }
537
538   /* If all went well, register this page for reading */
539   char *cb_name = ssnprintf_alloc("curl-%s-%s", page->instance, page->url);
540
541   plugin_register_complex_read(/* group = */ NULL, cb_name, cc_read_page,
542                                interval,
543                                &(user_data_t){
544                                    .data = page,
545                                    .free_func = cc_web_page_free,
546                                });
547   sfree(cb_name);
548
549   return 0;
550 } /* }}} int cc_config_add_page */
551
552 static int cc_config(oconfig_item_t *ci) /* {{{ */
553 {
554   int success;
555   int errors;
556   int status;
557
558   success = 0;
559   errors = 0;
560
561   for (int i = 0; i < ci->children_num; i++) {
562     oconfig_item_t *child = ci->children + i;
563
564     if (strcasecmp("Page", child->key) == 0) {
565       status = cc_config_add_page(child);
566       if (status == 0)
567         success++;
568       else
569         errors++;
570     } else {
571       WARNING("curl plugin: Option `%s' not allowed here.", child->key);
572       errors++;
573     }
574   }
575
576   if ((success == 0) && (errors > 0)) {
577     ERROR("curl plugin: All statements failed.");
578     return -1;
579   }
580
581   return 0;
582 } /* }}} int cc_config */
583
584 static int cc_init(void) /* {{{ */
585 {
586   curl_global_init(CURL_GLOBAL_SSL);
587   return 0;
588 } /* }}} int cc_init */
589
590 static void cc_submit(const web_page_t *wp, const web_match_t *wm, /* {{{ */
591                       value_t value) {
592   value_list_t vl = VALUE_LIST_INIT;
593
594   vl.values = &value;
595   vl.values_len = 1;
596   sstrncpy(vl.plugin, (wp->plugin_name != NULL) ? wp->plugin_name : "curl",
597            sizeof(vl.plugin));
598   sstrncpy(vl.plugin_instance, wp->instance, sizeof(vl.plugin_instance));
599   sstrncpy(vl.type, wm->type, sizeof(vl.type));
600   if (wm->instance != NULL)
601     sstrncpy(vl.type_instance, wm->instance, sizeof(vl.type_instance));
602
603   plugin_dispatch_values(&vl);
604 } /* }}} void cc_submit */
605
606 static void cc_submit_response_code(const web_page_t *wp, long code) /* {{{ */
607 {
608   value_list_t vl = VALUE_LIST_INIT;
609
610   vl.values = &(value_t){.gauge = (gauge_t)code};
611   vl.values_len = 1;
612   sstrncpy(vl.plugin, (wp->plugin_name != NULL) ? wp->plugin_name : "curl",
613            sizeof(vl.plugin));
614   sstrncpy(vl.plugin_instance, wp->instance, sizeof(vl.plugin_instance));
615   sstrncpy(vl.type, "response_code", sizeof(vl.type));
616
617   plugin_dispatch_values(&vl);
618 } /* }}} void cc_submit_response_code */
619
620 static void cc_submit_response_time(const web_page_t *wp, /* {{{ */
621                                     gauge_t response_time) {
622   value_list_t vl = VALUE_LIST_INIT;
623
624   vl.values = &(value_t){.gauge = response_time};
625   vl.values_len = 1;
626   sstrncpy(vl.plugin, (wp->plugin_name != NULL) ? wp->plugin_name : "curl",
627            sizeof(vl.plugin));
628   sstrncpy(vl.plugin_instance, wp->instance, sizeof(vl.plugin_instance));
629   sstrncpy(vl.type, "response_time", sizeof(vl.type));
630
631   plugin_dispatch_values(&vl);
632 } /* }}} void cc_submit_response_time */
633
634 static int cc_read_page(user_data_t *ud) /* {{{ */
635 {
636
637   if ((ud == NULL) || (ud->data == NULL)) {
638     ERROR("curl plugin: cc_read_page: Invalid user data.");
639     return -1;
640   }
641
642   web_page_t *wp = (web_page_t *)ud->data;
643
644   int status;
645   cdtime_t start = 0;
646
647   if (wp->response_time)
648     start = cdtime();
649
650   wp->buffer_fill = 0;
651
652   curl_easy_setopt(wp->curl, CURLOPT_URL, wp->url);
653
654   status = curl_easy_perform(wp->curl);
655   if (status != CURLE_OK) {
656     ERROR("curl plugin: curl_easy_perform failed with status %i: %s", status,
657           wp->curl_errbuf);
658     return -1;
659   }
660
661   if (wp->response_time)
662     cc_submit_response_time(wp, CDTIME_T_TO_DOUBLE(cdtime() - start));
663   if (wp->stats != NULL)
664     curl_stats_dispatch(wp->stats, wp->curl, NULL, "curl", wp->instance);
665
666   if (wp->response_code) {
667     long response_code = 0;
668     status =
669         curl_easy_getinfo(wp->curl, CURLINFO_RESPONSE_CODE, &response_code);
670     if (status != CURLE_OK) {
671       ERROR("curl plugin: Fetching response code failed with status %i: %s",
672             status, wp->curl_errbuf);
673     } else {
674       cc_submit_response_code(wp, response_code);
675     }
676   }
677
678   for (web_match_t *wm = wp->matches; wm != NULL; wm = wm->next) {
679     cu_match_value_t *mv;
680
681     status = match_apply(wm->match, wp->buffer);
682     if (status != 0) {
683       WARNING("curl plugin: match_apply failed.");
684       continue;
685     }
686
687     mv = match_get_user_data(wm->match);
688     if (mv == NULL) {
689       WARNING("curl plugin: match_get_user_data returned NULL.");
690       continue;
691     }
692
693     cc_submit(wp, wm, mv->value);
694     match_value_reset(mv);
695   } /* for (wm = wp->matches; wm != NULL; wm = wm->next) */
696
697   return 0;
698 } /* }}} int cc_read_page */
699
700 void module_register(void) {
701   plugin_register_complex_config("curl", cc_config);
702   plugin_register_init("curl", cc_init);
703 } /* void module_register */