X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fascent.c;h=6285176a9a6b9e7406d1bc5b47fdfd4a9e2e8770;hb=d3fc6d0831a63af2e96300f488a9f8f5fc3183fb;hp=8c0bbec600152aee448cd34a7008eae4dadabcc0;hpb=66e0fe82631c8a8e44ffcad8ffd378fab83bc83f;p=collectd.git diff --git a/src/ascent.c b/src/ascent.c index 8c0bbec6..6285176a 100644 --- a/src/ascent.c +++ b/src/ascent.c @@ -91,10 +91,12 @@ struct player_info_s typedef struct player_info_s player_info_t; #define PLAYER_INFO_STATIC_INIT { -1, -1, -1, -1, -1 } -static char *url = NULL; -static char *user = NULL; -static char *pass = NULL; -static char *cacert = NULL; +static char *url = NULL; +static char *user = NULL; +static char *pass = NULL; +static char *verify_peer = NULL; +static char *verify_host = NULL; +static char *cacert = NULL; static CURL *curl = NULL; @@ -108,6 +110,8 @@ static const char *config_keys[] = "URL", "User", "Password", + "VerifyPeer", + "VerifyHost", "CACert" }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); @@ -130,10 +134,12 @@ static int ascent_submit_gauge (const char *plugin_instance, /* {{{ */ sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + if (type_instance != NULL) sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); return (0); } /* }}} int ascent_submit_gauge */ @@ -271,10 +277,12 @@ static int ascent_xml_submit_gauge (xmlDoc *doc, xmlNode *node, /* {{{ */ value = strtod (str_ptr, &end_ptr); if (str_ptr == end_ptr) { + xmlFree(str_ptr); ERROR ("ascent plugin: ascent_xml_submit_gauge: strtod failed."); return (-1); } } + xmlFree(str_ptr); return (ascent_submit_gauge (plugin_instance, type, type_instance, value)); } /* }}} int ascent_xml_submit_gauge */ @@ -300,10 +308,12 @@ static int ascent_xml_read_int (xmlDoc *doc, xmlNode *node, /* {{{ */ value = strtol (str_ptr, &end_ptr, 0); if (str_ptr == end_ptr) { + xmlFree(str_ptr); ERROR ("ascent plugin: ascent_xml_read_int: strtol failed."); return (-1); } } + xmlFree(str_ptr); *ret_value = value; return (0); @@ -498,6 +508,10 @@ static int ascent_config (const char *key, const char *value) /* {{{ */ return (config_set (&user, value)); else if (strcasecmp (key, "Password") == 0) return (config_set (&pass, value)); + else if (strcasecmp (key, "VerifyPeer") == 0) + return (config_set (&verify_peer, value)); + else if (strcasecmp (key, "VerifyHost") == 0) + return (config_set (&verify_host, value)); else if (strcasecmp (key, "CACert") == 0) return (config_set (&cacert, value)); else @@ -534,7 +548,7 @@ static int ascent_init (void) /* {{{ */ { int status; - status = snprintf (credentials, sizeof (credentials), "%s:%s", + status = ssnprintf (credentials, sizeof (credentials), "%s:%s", user, (pass == NULL) ? "" : pass); if (status >= sizeof (credentials)) { @@ -542,13 +556,22 @@ static int ascent_init (void) /* {{{ */ "credentials have been truncated."); return (-1); } - credentials[sizeof (credentials) - 1] = '\0'; curl_easy_setopt (curl, CURLOPT_USERPWD, credentials); } curl_easy_setopt (curl, CURLOPT_URL, url); + if ((verify_peer == NULL) || (strcmp (verify_peer, "true") == 0)) + curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 1); + else + curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0); + + if ((verify_host == NULL) || (strcmp (verify_host, "true") == 0)) + curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 2); + else + curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0); + if (cacert != NULL) curl_easy_setopt (curl, CURLOPT_CAINFO, cacert);