+} /* }}} int wh_callback_init */
+
+static int wh_flush_nolock (int timeout, wh_callback_t *cb) /* {{{ */
+{
+ int status;
+
+ DEBUG ("write_http plugin: wh_flush_nolock: timeout = %i; "
+ "send_buffer_fill = %zu;",
+ timeout, cb->send_buffer_fill);
+
+ if (timeout > 0)
+ {
+ time_t now;
+
+ now = time (NULL);
+ if ((cb->send_buffer_init_time + timeout) > now)
+ return (0);
+ }
+
+ if (cb->send_buffer_fill <= 0)
+ {
+ cb->send_buffer_init_time = time (NULL);
+ return (0);
+ }
+
+ status = wh_send_buffer (cb);
+ wh_reset_buffer (cb);
+
+ return (status);
+} /* }}} wh_flush_nolock */
+
+static int wh_flush (int timeout, /* {{{ */
+ const char *identifier __attribute__((unused)),
+ user_data_t *user_data)
+{
+ wh_callback_t *cb;
+ int status;
+
+ if (user_data == NULL)
+ return (-EINVAL);
+
+ cb = user_data->data;
+
+ pthread_mutex_lock (&cb->send_lock);
+
+ if (cb->curl == NULL)
+ {
+ status = wh_callback_init (cb);
+ if (status != 0)
+ {
+ ERROR ("write_http plugin: wh_callback_init failed.");
+ pthread_mutex_unlock (&cb->send_lock);
+ return (-1);
+ }
+ }
+
+ status = wh_flush_nolock (timeout, cb);
+ pthread_mutex_unlock (&cb->send_lock);
+
+ return (status);
+} /* }}} int wh_flush */
+
+static void wh_callback_free (void *data) /* {{{ */
+{
+ wh_callback_t *cb;
+
+ if (data == NULL)
+ return;
+
+ cb = data;
+
+ wh_flush_nolock (/* timeout = */ -1, cb);
+
+ curl_easy_cleanup (cb->curl);
+ sfree (cb->location);
+ sfree (cb->user);
+ sfree (cb->pass);
+ sfree (cb->credentials);
+
+ sfree (cb);
+} /* }}} void wh_callback_free */