2 * collectd - src/curl_xml.c
3 * Copyright (C) 2009,2010 Amit Gupta
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Amit Gupta <amit.gupta221 at gmail.com>
25 #include "configfile.h"
26 #include "utils_llist.h"
28 #include <libxml/parser.h>
29 #include <libxml/tree.h>
30 #include <libxml/xpath.h>
31 #include <libxml/xpathInternals.h>
33 #include <curl/curl.h>
35 #define CX_DEFAULT_HOST "localhost"
38 * Private data structures
40 struct cx_values_s /* {{{ */
42 char path[DATA_MAX_NAME_LEN];
45 typedef struct cx_values_s cx_values_t;
48 struct cx_xpath_s /* {{{ */
54 char *instance_prefix;
59 typedef struct cx_xpath_s cx_xpath_t;
75 struct curl_slist *headers;
79 char curl_errbuf[CURL_ERROR_SIZE];
84 llist_t *list; /* list of xpath blocks */
86 typedef struct cx_s cx_t; /* }}} */
91 static size_t cx_curl_callback (void *buf, /* {{{ */
92 size_t size, size_t nmemb, void *user_data)
94 size_t len = size * nmemb;
100 ERROR ("curl_xml plugin: cx_curl_callback: "
101 "user_data pointer is NULL.");
108 if ((db->buffer_fill + len) >= db->buffer_size)
112 temp = (char *) realloc (db->buffer,
113 db->buffer_fill + len + 1);
116 ERROR ("curl_xml plugin: realloc failed.");
120 db->buffer_size = db->buffer_fill + len + 1;
123 memcpy (db->buffer + db->buffer_fill, (char *) buf, len);
124 db->buffer_fill += len;
125 db->buffer[db->buffer_fill] = 0;
128 } /* }}} size_t cx_curl_callback */
130 static void cx_xpath_free (cx_xpath_t *xpath) /* {{{ */
137 sfree (xpath->instance_prefix);
138 sfree (xpath->instance);
139 sfree (xpath->values);
141 } /* }}} void cx_xpath_free */
143 static void cx_list_free (llist_t *list) /* {{{ */
147 le = llist_head (list);
155 cx_xpath_free (le->value);
160 llist_destroy (list);
162 } /* }}} void cx_list_free */
164 static void cx_free (void *arg) /* {{{ */
168 DEBUG ("curl_xml plugin: cx_free (arg = %p);", arg);
175 if (db->curl != NULL)
176 curl_easy_cleanup (db->curl);
179 if (db->list != NULL)
180 cx_list_free (db->list);
183 sfree (db->instance);
189 sfree (db->credentials);
191 sfree (db->post_body);
192 curl_slist_free_all (db->headers);
193 sfree (db->namespaces);
196 } /* }}} void cx_free */
198 static int cx_config_append_string (const char *name, struct curl_slist **dest, /* {{{ */
201 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
203 WARNING ("curl_xml plugin: `%s' needs exactly one string argument.", name);
207 *dest = curl_slist_append(*dest, ci->values[0].value.string);
212 } /* }}} int cx_config_append_string */
214 static int cx_check_type (const data_set_t *ds, cx_xpath_t *xpath) /* {{{ */
218 WARNING ("curl_xml plugin: DataSet `%s' not defined.", xpath->type);
222 if (ds->ds_num != xpath->values_len)
224 WARNING ("curl_xml plugin: DataSet `%s' requires %i values, but config talks about %i",
225 xpath->type, ds->ds_num, xpath->values_len);
230 } /* }}} cx_check_type */
232 static xmlXPathObjectPtr cx_evaluate_xpath (xmlXPathContextPtr xpath_ctx, /* {{{ */
235 xmlXPathObjectPtr xpath_obj;
237 /* XXX: When to free this? */
238 xpath_obj = xmlXPathEvalExpression(BAD_CAST expr, xpath_ctx);
239 if (xpath_obj == NULL)
241 WARNING ("curl_xml plugin: "
242 "Error unable to evaluate xpath expression \"%s\". Skipping...", expr);
247 } /* }}} cx_evaluate_xpath */
249 static int cx_if_not_text_node (xmlNodePtr node) /* {{{ */
251 if (node->type == XML_TEXT_NODE || node->type == XML_ATTRIBUTE_NODE ||
252 node->type == XML_ELEMENT_NODE)
255 WARNING ("curl_xml plugin: "
256 "Node \"%s\" doesn't seem to be a text node. Skipping...", node->name);
258 } /* }}} cx_if_not_text_node */
261 * cx_register_namespaces:
262 * @xpath_ctx: the pointer to an XPath context.
263 * @nslist: the list of known namespaces in
264 * "<prefix1>=<href1> <prefix2>=href2> ..." format.
266 * Registers namespaces from @nslist in @xpath_ctx.
268 * Returns 0 on success and a negative value otherwise.
270 * author: Aleksey Sanin
272 * The following license statement applies to the function
273 * cx_register_namespaces only:
275 * Permission is hereby granted, free of charge, to any person obtaining a copy
276 * of this software and associated documentation files (the "Software"), to deal
277 * in the Software without restriction, including without limitation the rights
278 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
279 * copies of the Software, and to permit persons to whom the Software is fur-
280 * nished to do so, subject to the following conditions:
282 * The above copyright notice and this permission notice shall be included in
283 * all copies or substantial portions of the Software.
285 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
286 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
287 * NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
288 * DANIEL VEILLARD BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
289 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
290 * NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
292 * Except as contained in this notice, the name of Daniel Veillard shall not
293 * be used in advertising or otherwise to promote the sale, use or other deal-
294 * ings in this Software without prior written authorization from him.
296 static int cx_register_namespaces(xmlXPathContextPtr xpath_ctx, /* {{{ */
297 const xmlChar* nslist)
307 nslistdup = xmlStrdup(nslist);
308 if(nslistdup == NULL) {
309 ERROR ("curl_xml plugin: "
310 "unable to strdup namespaces list");
315 while(next != NULL) {
317 while((*next) == ' ') next++;
318 if((*next) == '\0') break;
322 next = (xmlChar*)xmlStrchr(next, '=');
324 ERROR ("curl_xml plugin: "
325 "invalid namespaces list format");
333 next = (xmlChar*)xmlStrchr(next, ' ');
338 /* do register namespace */
339 if(xmlXPathRegisterNs(xpath_ctx, prefix, href) != 0) {
340 ERROR ("curl_xml plugin: "
341 "unable to register NS with prefix=\"%s\" and href=\"%s\"\n",
350 } /* }}} cx_register_namespaces */
352 static int cx_handle_single_value_xpath (xmlXPathContextPtr xpath_ctx, /* {{{ */
354 const data_set_t *ds, value_list_t *vl, int index)
356 xmlXPathObjectPtr values_node_obj;
357 xmlNodeSetPtr values_node;
361 values_node_obj = cx_evaluate_xpath (xpath_ctx, BAD_CAST xpath->values[index].path);
362 if (values_node_obj == NULL)
363 return (-1); /* Error already logged. */
365 values_node = values_node_obj->nodesetval;
366 tmp_size = (values_node) ? values_node->nodeNr : 0;
370 WARNING ("curl_xml plugin: "
371 "relative xpath expression \"%s\" doesn't match any of the nodes. "
372 "Skipping...", xpath->values[index].path);
373 xmlXPathFreeObject (values_node_obj);
379 WARNING ("curl_xml plugin: "
380 "relative xpath expression \"%s\" is expected to return "
381 "only one node. Skipping...", xpath->values[index].path);
382 xmlXPathFreeObject (values_node_obj);
386 /* ignoring the element if other than textnode/attribute*/
387 if (cx_if_not_text_node(values_node->nodeTab[0]))
389 WARNING ("curl_xml plugin: "
390 "relative xpath expression \"%s\" is expected to return "
391 "only text/attribute node which is not the case. Skipping...",
392 xpath->values[index].path);
393 xmlXPathFreeObject (values_node_obj);
397 node_value = (char *) xmlNodeGetContent(values_node->nodeTab[0]);
398 switch (ds->ds[index].type)
400 case DS_TYPE_COUNTER:
401 vl->values[index].counter = (counter_t) strtoull (node_value,
402 /* endptr = */ NULL, /* base = */ 0);
405 vl->values[index].derive = (derive_t) strtoll (node_value,
406 /* endptr = */ NULL, /* base = */ 0);
408 case DS_TYPE_ABSOLUTE:
409 vl->values[index].absolute = (absolute_t) strtoull (node_value,
410 /* endptr = */ NULL, /* base = */ 0);
413 vl->values[index].gauge = (gauge_t) strtod (node_value,
414 /* endptr = */ NULL);
418 xmlXPathFreeObject (values_node_obj);
420 /* We have reached here which means that
421 * we have got something to work */
423 } /* }}} int cx_handle_single_value_xpath */
425 static int cx_handle_all_value_xpaths (xmlXPathContextPtr xpath_ctx, /* {{{ */
427 const data_set_t *ds, value_list_t *vl)
429 value_t values[xpath->values_len];
433 assert (xpath->values_len > 0);
434 assert (xpath->values_len == vl->values_len);
435 assert (xpath->values_len == ds->ds_num);
438 for (i = 0; i < xpath->values_len; i++)
440 status = cx_handle_single_value_xpath (xpath_ctx, xpath, ds, vl, i);
442 return (-1); /* An error has been printed. */
443 } /* for (i = 0; i < xpath->values_len; i++) */
445 plugin_dispatch_values (vl);
449 } /* }}} int cx_handle_all_value_xpaths */
451 static int cx_handle_instance_xpath (xmlXPathContextPtr xpath_ctx, /* {{{ */
452 cx_xpath_t *xpath, value_list_t *vl,
455 xmlXPathObjectPtr instance_node_obj = NULL;
456 xmlNodeSetPtr instance_node = NULL;
458 memset (vl->type_instance, 0, sizeof (vl->type_instance));
460 /* If the base xpath returns more than one block, the result is assumed to be
461 * a table. The `Instance' option is not optional in this case. Check for the
462 * condition and inform the user. */
463 if (is_table && (vl->type_instance == NULL))
465 WARNING ("curl_xml plugin: "
466 "Base-XPath %s is a table (more than one result was returned), "
467 "but no instance-XPath has been defined.",
472 /* instance has to be an xpath expression */
473 if (xpath->instance != NULL)
477 instance_node_obj = cx_evaluate_xpath (xpath_ctx, BAD_CAST xpath->instance);
478 if (instance_node_obj == NULL)
479 return (-1); /* error is logged already */
481 instance_node = instance_node_obj->nodesetval;
482 tmp_size = (instance_node) ? instance_node->nodeNr : 0;
486 WARNING ("curl_xml plugin: "
487 "relative xpath expression for 'InstanceFrom' \"%s\" doesn't match "
488 "any of the nodes. Skipping the node.", xpath->instance);
489 xmlXPathFreeObject (instance_node_obj);
495 WARNING ("curl_xml plugin: "
496 "relative xpath expression for 'InstanceFrom' \"%s\" is expected "
497 "to return only one text node. Skipping the node.", xpath->instance);
498 xmlXPathFreeObject (instance_node_obj);
502 /* ignoring the element if other than textnode/attribute */
503 if (cx_if_not_text_node(instance_node->nodeTab[0]))
505 WARNING ("curl_xml plugin: "
506 "relative xpath expression \"%s\" is expected to return only text node "
507 "which is not the case. Skipping the node.", xpath->instance);
508 xmlXPathFreeObject (instance_node_obj);
511 } /* if (xpath->instance != NULL) */
513 if (xpath->instance_prefix != NULL)
515 if (instance_node != NULL)
516 ssnprintf (vl->type_instance, sizeof (vl->type_instance),"%s%s",
517 xpath->instance_prefix, (char *) xmlNodeGetContent(instance_node->nodeTab[0]));
519 sstrncpy (vl->type_instance, xpath->instance_prefix,
520 sizeof (vl->type_instance));
524 /* If instance_prefix and instance_node are NULL, then
525 * don't set the type_instance */
526 if (instance_node != NULL)
527 sstrncpy (vl->type_instance, (char *) xmlNodeGetContent(instance_node->nodeTab[0]),
528 sizeof (vl->type_instance));
531 /* Free `instance_node_obj' this late, because `instance_node' points to
532 * somewhere inside this structure. */
533 xmlXPathFreeObject (instance_node_obj);
536 } /* }}} int cx_handle_instance_xpath */
538 static int cx_handle_base_xpath (char const *plugin_instance, /* {{{ */
540 xmlXPathContextPtr xpath_ctx, const data_set_t *ds,
541 char *base_xpath, cx_xpath_t *xpath)
546 xmlXPathObjectPtr base_node_obj = NULL;
547 xmlNodeSetPtr base_nodes = NULL;
549 value_list_t vl = VALUE_LIST_INIT;
551 base_node_obj = cx_evaluate_xpath (xpath_ctx, BAD_CAST base_xpath);
552 if (base_node_obj == NULL)
553 return -1; /* error is logged already */
555 base_nodes = base_node_obj->nodesetval;
556 total_nodes = (base_nodes) ? base_nodes->nodeNr : 0;
558 if (total_nodes == 0)
560 ERROR ("curl_xml plugin: "
561 "xpath expression \"%s\" doesn't match any of the nodes. "
562 "Skipping the xpath block...", base_xpath);
563 xmlXPathFreeObject (base_node_obj);
567 /* If base_xpath returned multiple results, then */
568 /* Instance in the xpath block is required */
569 if (total_nodes > 1 && xpath->instance == NULL)
571 ERROR ("curl_xml plugin: "
572 "InstanceFrom is must in xpath block since the base xpath expression \"%s\" "
573 "returned multiple results. Skipping the xpath block...", base_xpath);
577 /* set the values for the value_list */
578 vl.values_len = ds->ds_num;
579 sstrncpy (vl.type, xpath->type, sizeof (vl.type));
580 sstrncpy (vl.plugin, "curl_xml", sizeof (vl.plugin));
581 sstrncpy (vl.host, (host != NULL) ? host : hostname_g, sizeof (vl.host));
582 if (plugin_instance != NULL)
583 sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
585 for (i = 0; i < total_nodes; i++)
589 xpath_ctx->node = base_nodes->nodeTab[i];
591 status = cx_handle_instance_xpath (xpath_ctx, xpath, &vl,
592 /* is_table = */ (total_nodes > 1));
594 continue; /* An error has already been reported. */
596 status = cx_handle_all_value_xpaths (xpath_ctx, xpath, ds, &vl);
598 continue; /* An error has been logged. */
599 } /* for (i = 0; i < total_nodes; i++) */
601 /* free up the allocated memory */
602 xmlXPathFreeObject (base_node_obj);
605 } /* }}} cx_handle_base_xpath */
607 static int cx_handle_parsed_xml(xmlDocPtr doc, /* {{{ */
608 xmlXPathContextPtr xpath_ctx, cx_t *db)
611 const data_set_t *ds;
616 le = llist_head (db->list);
620 xpath = (cx_xpath_t *) le->value;
621 ds = plugin_get_ds (xpath->type);
623 if ( (cx_check_type(ds, xpath) == 0) &&
624 (cx_handle_base_xpath(db->instance, db->host,
625 xpath_ctx, ds, le->key, xpath) == 0) )
626 status = 0; /* we got atleast one success */
629 } /* while (le != NULL) */
632 } /* }}} cx_handle_parsed_xml */
634 static int cx_parse_stats_xml(xmlChar* xml, cx_t *db) /* {{{ */
638 xmlXPathContextPtr xpath_ctx;
641 doc = xmlParseDoc(xml);
644 ERROR ("curl_xml plugin: Failed to parse the xml document - %s", xml);
648 xpath_ctx = xmlXPathNewContext(doc);
649 if(xpath_ctx == NULL)
651 ERROR ("curl_xml plugin: Failed to create the xml context");
656 if((db->namespaces != NULL) &&
657 (cx_register_namespaces(xpath_ctx, BAD_CAST db->namespaces) < 0))
663 status = cx_handle_parsed_xml (doc, xpath_ctx, db);
665 xmlXPathFreeContext(xpath_ctx);
668 } /* }}} cx_parse_stats_xml */
670 static int cx_curl_perform (cx_t *db, CURL *curl) /* {{{ */
678 status = curl_easy_perform (curl);
679 if (status != CURLE_OK)
681 ERROR ("curl_xml plugin: curl_easy_perform failed with status %i: %s (%s)",
682 status, db->curl_errbuf, url);
686 curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
687 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &rc);
689 /* The response code is zero if a non-HTTP transport was used. */
690 if ((rc != 0) && (rc != 200))
692 ERROR ("curl_xml plugin: curl_easy_perform failed with response code %ld (%s)",
699 status = cx_parse_stats_xml(BAD_CAST ptr, db);
703 } /* }}} int cx_curl_perform */
705 static int cx_read (user_data_t *ud) /* {{{ */
709 if ((ud == NULL) || (ud->data == NULL))
711 ERROR ("curl_xml plugin: cx_read: Invalid user data.");
715 db = (cx_t *) ud->data;
717 return cx_curl_perform (db, db->curl);
718 } /* }}} int cx_read */
720 /* Configuration handling functions {{{ */
722 static int cx_config_add_values (const char *name, cx_xpath_t *xpath, /* {{{ */
727 if (ci->values_num < 1)
729 WARNING ("curl_xml plugin: `ValuesFrom' needs at least one argument.");
733 for (i = 0; i < ci->values_num; i++)
734 if (ci->values[i].type != OCONFIG_TYPE_STRING)
736 WARNING ("curl_xml plugin: `ValuesFrom' needs only string argument.");
740 sfree (xpath->values);
742 xpath->values_len = 0;
743 xpath->values = (cx_values_t *) malloc (sizeof (cx_values_t) * ci->values_num);
744 if (xpath->values == NULL)
746 xpath->values_len = ci->values_num;
748 /* populate cx_values_t structure */
749 for (i = 0; i < ci->values_num; i++)
751 xpath->values[i].path_len = sizeof (ci->values[i].value.string);
752 sstrncpy (xpath->values[i].path, ci->values[i].value.string, sizeof (xpath->values[i].path));
756 } /* }}} cx_config_add_values */
758 static int cx_config_add_xpath (cx_t *db, /* {{{ */
765 xpath = (cx_xpath_t *) malloc (sizeof (*xpath));
768 ERROR ("curl_xml plugin: malloc failed.");
771 memset (xpath, 0, sizeof (*xpath));
773 status = cf_util_get_string (ci, &xpath->path);
780 /* error out if xpath->path is an empty string */
781 if (*xpath->path == 0)
783 ERROR ("curl_xml plugin: invalid xpath. "
784 "xpath value can't be an empty string");
789 for (i = 0; i < ci->children_num; i++)
791 oconfig_item_t *child = ci->children + i;
793 if (strcasecmp ("Type", child->key) == 0)
794 status = cf_util_get_string (child, &xpath->type);
795 else if (strcasecmp ("InstancePrefix", child->key) == 0)
796 status = cf_util_get_string (child, &xpath->instance_prefix);
797 else if (strcasecmp ("InstanceFrom", child->key) == 0)
798 status = cf_util_get_string (child, &xpath->instance);
799 else if (strcasecmp ("ValuesFrom", child->key) == 0)
800 status = cx_config_add_values ("ValuesFrom", xpath, child);
803 WARNING ("curl_xml plugin: Option `%s' not allowed here.", child->key);
809 } /* for (i = 0; i < ci->children_num; i++) */
811 if (status == 0 && xpath->type == NULL)
813 WARNING ("curl_xml plugin: `Type' missing in `xpath' block.");
822 if (db->list == NULL)
824 db->list = llist_create();
825 if (db->list == NULL)
827 ERROR ("curl_xml plugin: list creation failed.");
832 name = strdup(xpath->path);
835 ERROR ("curl_xml plugin: strdup failed.");
839 le = llentry_create (name, xpath);
842 ERROR ("curl_xml plugin: llentry_create failed.");
846 llist_append (db->list, le);
850 } /* }}} int cx_config_add_xpath */
852 /* Initialize db->curl */
853 static int cx_init_curl (cx_t *db) /* {{{ */
855 db->curl = curl_easy_init ();
856 if (db->curl == NULL)
858 ERROR ("curl_xml plugin: curl_easy_init failed.");
862 curl_easy_setopt (db->curl, CURLOPT_NOSIGNAL, 1L);
863 curl_easy_setopt (db->curl, CURLOPT_WRITEFUNCTION, cx_curl_callback);
864 curl_easy_setopt (db->curl, CURLOPT_WRITEDATA, db);
865 curl_easy_setopt (db->curl, CURLOPT_USERAGENT,
866 PACKAGE_NAME"/"PACKAGE_VERSION);
867 curl_easy_setopt (db->curl, CURLOPT_ERRORBUFFER, db->curl_errbuf);
868 curl_easy_setopt (db->curl, CURLOPT_URL, db->url);
870 if (db->user != NULL)
872 size_t credentials_size;
874 credentials_size = strlen (db->user) + 2;
875 if (db->pass != NULL)
876 credentials_size += strlen (db->pass);
878 db->credentials = (char *) malloc (credentials_size);
879 if (db->credentials == NULL)
881 ERROR ("curl_xml plugin: malloc failed.");
885 ssnprintf (db->credentials, credentials_size, "%s:%s",
886 db->user, (db->pass == NULL) ? "" : db->pass);
887 curl_easy_setopt (db->curl, CURLOPT_USERPWD, db->credentials);
890 curl_easy_setopt (db->curl, CURLOPT_SSL_VERIFYPEER, db->verify_peer ? 1L : 0L);
891 curl_easy_setopt (db->curl, CURLOPT_SSL_VERIFYHOST,
892 db->verify_host ? 2L : 0L);
893 if (db->cacert != NULL)
894 curl_easy_setopt (db->curl, CURLOPT_CAINFO, db->cacert);
895 if (db->headers != NULL)
896 curl_easy_setopt (db->curl, CURLOPT_HTTPHEADER, db->headers);
897 if (db->post_body != NULL)
898 curl_easy_setopt (db->curl, CURLOPT_POSTFIELDS, db->post_body);
901 } /* }}} int cx_init_curl */
903 static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */
909 if ((ci->values_num != 1)
910 || (ci->values[0].type != OCONFIG_TYPE_STRING))
912 WARNING ("curl_xml plugin: The `URL' block "
913 "needs exactly one string argument.");
917 db = (cx_t *) malloc (sizeof (*db));
920 ERROR ("curl_xml plugin: malloc failed.");
923 memset (db, 0, sizeof (*db));
925 if (strcasecmp ("URL", ci->key) == 0)
927 status = cf_util_get_string (ci, &db->url);
936 ERROR ("curl_xml plugin: cx_config: "
937 "Invalid key: %s", ci->key);
941 /* Fill the `cx_t' structure.. */
942 for (i = 0; i < ci->children_num; i++)
944 oconfig_item_t *child = ci->children + i;
946 if (strcasecmp ("Instance", child->key) == 0)
947 status = cf_util_get_string (child, &db->instance);
948 else if (strcasecmp ("Host", child->key) == 0)
949 status = cf_util_get_string (child, &db->host);
950 else if (strcasecmp ("User", child->key) == 0)
951 status = cf_util_get_string (child, &db->user);
952 else if (strcasecmp ("Password", child->key) == 0)
953 status = cf_util_get_string (child, &db->pass);
954 else if (strcasecmp ("VerifyPeer", child->key) == 0)
955 status = cf_util_get_boolean (child, &db->verify_peer);
956 else if (strcasecmp ("VerifyHost", child->key) == 0)
957 status = cf_util_get_boolean (child, &db->verify_host);
958 else if (strcasecmp ("CACert", child->key) == 0)
959 status = cf_util_get_string (child, &db->cacert);
960 else if (strcasecmp ("xpath", child->key) == 0)
961 status = cx_config_add_xpath (db, child);
962 else if (strcasecmp ("Header", child->key) == 0)
963 status = cx_config_append_string ("Header", &db->headers, child);
964 else if (strcasecmp ("Post", child->key) == 0)
965 status = cf_util_get_string (child, &db->post_body);
966 else if (strcasecmp ("Namespaces", child->key) == 0)
967 status = cf_util_get_string (child, &db->namespaces);
970 WARNING ("curl_xml plugin: Option `%s' not allowed here.", child->key);
980 if (db->list == NULL)
982 WARNING ("curl_xml plugin: No (valid) `Key' block "
983 "within `URL' block `%s'.", db->url);
987 status = cx_init_curl (db);
990 /* If all went well, register this database for reading */
994 char cb_name[DATA_MAX_NAME_LEN];
996 if (db->instance == NULL)
997 db->instance = strdup("default");
999 DEBUG ("curl_xml plugin: Registering new read callback: %s",
1002 memset (&ud, 0, sizeof (ud));
1003 ud.data = (void *) db;
1004 ud.free_func = cx_free;
1006 ssnprintf (cb_name, sizeof (cb_name), "curl_xml-%s-%s",
1007 db->instance, db->url);
1009 plugin_register_complex_read (/* group = */ NULL, cb_name, cx_read,
1010 /* interval = */ NULL, &ud);
1019 } /* }}} int cx_config_add_url */
1021 /* }}} End of configuration handling functions */
1023 static int cx_config (oconfig_item_t *ci) /* {{{ */
1033 for (i = 0; i < ci->children_num; i++)
1035 oconfig_item_t *child = ci->children + i;
1037 if (strcasecmp ("URL", child->key) == 0)
1039 status = cx_config_add_url (child);
1047 WARNING ("curl_xml plugin: Option `%s' not allowed here.", child->key);
1052 if ((success == 0) && (errors > 0))
1054 ERROR ("curl_xml plugin: All statements failed.");
1059 } /* }}} int cx_config */
1061 void module_register (void)
1063 plugin_register_complex_config ("curl_xml", cx_config);
1064 } /* void module_register */
1066 /* vim: set sw=2 sts=2 et fdm=marker : */