summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fb63811)
raw | patch | inline | side by side (parent: fb63811)
author | Dan Fandrich <dan@coneharvesters.com> | |
Wed, 6 Feb 2013 20:47:10 +0000 (21:47 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Sat, 16 Mar 2013 12:45:55 +0000 (13:45 +0100) |
Signed-off-by: Florian Forster <octo@collectd.org>
src/collectd.conf.pod | patch | blob | history | |
src/curl_xml.c | patch | blob | history |
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index e85ac1d4666ee79f5f169c51ba5245839086a170..63d8e23a05da3a27ef4b5b76160639d797ddc139 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
Use I<Instance> as the plugin instance when submitting values. Defaults to an
empty string (no plugin instance).
+=item B<Namespaces> I<Namespace-list>
+
+If an XPath expression references namespaces, they must be specified
+with this option. The argument is a string of the form "prefix1=URI1
+prefix2=URI2 ...",
+e.g. C<Namespaces "s=http://schemas.xmlsoap.org/soap/envelope/">
+
=item B<User> I<User>
=item B<Password> I<Password>
=item B<VerifyPeer> B<true>|B<false>
diff --git a/src/curl_xml.c b/src/curl_xml.c
index eda87d09655ae92c6454899a2125ee1e174e8305..db5cd61167cbd18a8395964fb5566662a286a3c3 100644 (file)
--- a/src/curl_xml.c
+++ b/src/curl_xml.c
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
#include <curl/curl.h>
char *cacert;
char *post_body;
struct curl_slist *headers;
+ char *namespaces;
CURL *curl;
char curl_errbuf[CURL_ERROR_SIZE];
sfree (db->cacert);
sfree (db->post_body);
curl_slist_free_all (db->headers);
+ sfree (db->namespaces);
sfree (db);
} /* }}} void cx_free */
return -1;
} /* }}} cx_if_not_text_node */
+/**
+ * cx_register_namespaces:
+ * @xpath_ctx: the pointer to an XPath context.
+ * @nslist: the list of known namespaces in
+ * "<prefix1>=<href1> <prefix2>=href2> ..." format.
+ *
+ * Registers namespaces from @nslist in @xpath_ctx.
+ *
+ * Returns 0 on success and a negative value otherwise.
+ *
+ * author: Aleksey Sanin
+ *
+ * The following license statement applies to the function
+ * cx_register_namespaces only:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is fur-
+ * nished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
+ * NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * DANIEL VEILLARD BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
+ * NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Daniel Veillard shall not
+ * be used in advertising or otherwise to promote the sale, use or other deal-
+ * ings in this Software without prior written authorization from him.
+ */
+static int cx_register_namespaces(xmlXPathContextPtr xpath_ctx, /* {{{ */
+ const xmlChar* nslist)
+{
+ xmlChar* nslistdup;
+ xmlChar* prefix;
+ xmlChar* href;
+ xmlChar* next;
+
+ assert(xpath_ctx);
+ assert(nslist);
+
+ nslistdup = xmlStrdup(nslist);
+ if(nslistdup == NULL) {
+ ERROR ("curl_xml plugin: "
+ "unable to strdup namespaces list");
+ return (-1);
+ }
+
+ next = nslistdup;
+ while(next != NULL) {
+ /* skip spaces */
+ while((*next) == ' ') next++;
+ if((*next) == '\0') break;
+
+ /* find prefix */
+ prefix = next;
+ next = (xmlChar*)xmlStrchr(next, '=');
+ if(next == NULL) {
+ ERROR ("curl_xml plugin: "
+ "invalid namespaces list format");
+ xmlFree(nslistdup);
+ return (-1);
+ }
+ *(next++) = '\0';
+
+ /* find href */
+ href = next;
+ next = (xmlChar*)xmlStrchr(next, ' ');
+ if(next != NULL) {
+ *(next++) = '\0';
+ }
+
+ /* do register namespace */
+ if(xmlXPathRegisterNs(xpath_ctx, prefix, href) != 0) {
+ ERROR ("curl_xml plugin: "
+ "unable to register NS with prefix=\"%s\" and href=\"%s\"\n",
+ prefix, href);
+ xmlFree(nslistdup);
+ return (-1);
+ }
+ }
+
+ xmlFree(nslistdup);
+ return (0);
+} /* }}} cx_register_namespaces */
+
static int cx_handle_single_value_xpath (xmlXPathContextPtr xpath_ctx, /* {{{ */
cx_xpath_t *xpath,
const data_set_t *ds, value_list_t *vl, int index)
memset (vl->type_instance, 0, sizeof (vl->type_instance));
/* If the base xpath returns more than one block, the result is assumed to be
- * a table. The `Instnce' option is not optional in this case. Check for the
+ * a table. The `Instance' option is not optional in this case. Check for the
* condition and inform the user. */
if (is_table && (vl->type_instance == NULL))
{
return (-1);
}
+ if((db->namespaces != NULL) &&
+ (cx_register_namespaces(xpath_ctx, BAD_CAST db->namespaces) < 0))
+ {
+ xmlFreeDoc(doc);
+ return (-1);
+ }
+
status = cx_handle_parsed_xml (doc, xpath_ctx, db);
/* Cleanup */
xmlXPathFreeContext(xpath_ctx);
status = cx_config_append_string ("Header", &db->headers, child);
else if (strcasecmp ("Post", child->key) == 0)
status = cf_util_get_string (child, &db->post_body);
+ else if (strcasecmp ("Namespaces", child->key) == 0)
+ status = cf_util_get_string (child, &db->namespaces);
else
{
WARNING ("curl_xml plugin: Option `%s' not allowed here.", child->key);