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[] =
{
};
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);
}
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",
}
}
- apache_buffer_len = 0;
+ apache_buffer_fill = 0;
return (0);
} /* int apache_read */