X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fapache.c;h=54a5d562a31043714100b131b272efdd171c4757;hb=e7929dac268957cbbd9082717759c3917ac1b51e;hp=280c687feebd79dcbb5c36ed80bce50d3c4ae844;hpb=107a919d0d15d51d774c92ac72879d869e0fa4ee;p=collectd.git diff --git a/src/apache.c b/src/apache.c index 280c687f..54a5d562 100644 --- a/src/apache.c +++ b/src/apache.c @@ -36,10 +36,10 @@ static char *cacert = NULL; static CURL *curl = NULL; -#define ABUFFER_SIZE 16384 -static char apache_buffer[ABUFFER_SIZE]; -static int apache_buffer_len = 0; -static char apache_curl_error[CURL_ERROR_SIZE]; +static char *apache_buffer = NULL; +static size_t apache_buffer_size = 0; +static size_t apache_buffer_fill = 0; +static char apache_curl_error[CURL_ERROR_SIZE]; static const char *config_keys[] = { @@ -50,21 +50,32 @@ static const char *config_keys[] = }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); -static size_t apache_curl_callback (void *buf, size_t size, size_t nmemb, void *stream) +static size_t apache_curl_callback (void *buf, size_t size, size_t nmemb, + void *stream) { size_t len = size * nmemb; - if ((apache_buffer_len + len) >= ABUFFER_SIZE) - { - len = (ABUFFER_SIZE - 1) - apache_buffer_len; - } - if (len <= 0) return (len); - memcpy (apache_buffer + apache_buffer_len, (char *) buf, len); - apache_buffer_len += len; - apache_buffer[apache_buffer_len] = '\0'; + if ((apache_buffer_fill + len) >= apache_buffer_size) + { + char *temp; + + temp = (char *) realloc (apache_buffer, + apache_buffer_fill + len + 1); + if (temp == NULL) + { + ERROR ("apache plugin: realloc failed."); + return (0); + } + apache_buffer = temp; + apache_buffer_size = apache_buffer_fill + len + 1; + } + + memcpy (apache_buffer + apache_buffer_fill, (char *) buf, len); + apache_buffer_fill += len; + apache_buffer[apache_buffer_fill] = 0; return (len); } @@ -162,9 +173,9 @@ static void submit_counter (const char *type, const char *type_instance, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "apache"); - strcpy (vl.plugin_instance, ""); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "apache", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); if (type_instance != NULL) { @@ -187,9 +198,9 @@ static void submit_gauge (const char *type, const char *type_instance, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "apache"); - strcpy (vl.plugin_instance, ""); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "apache", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); if (type_instance != NULL) { @@ -269,7 +280,7 @@ static int apache_read (void) if (url == NULL) return (-1); - apache_buffer_len = 0; + apache_buffer_fill = 0; if (curl_easy_perform (curl) != 0) { ERROR ("apache: curl_easy_perform failed: %s", @@ -312,7 +323,7 @@ static int apache_read (void) } } - apache_buffer_len = 0; + apache_buffer_fill = 0; return (0); } /* int apache_read */