+/* safe curl wrappers */
+#define init_curl_storage(ch) \
+ {\
+ http_request_storage *st = pecalloc(1, sizeof(http_request_storage), 1); \
+ curl_easy_setopt(ch, CURLOPT_PRIVATE, st); \
+ curl_easy_setopt(ch, CURLOPT_ERRORBUFFER, st->errorbuffer); \
+ }
+
+static void *safe_curl_init(void)
+{
+ CURL *ch;
+
+ if ((ch = curl_easy_init())) {
+ init_curl_storage(ch);
+ return ch;
+ }
+ return NULL;
+}
+static void *safe_curl_copy(void *p)
+{
+ CURL *ch;
+
+ if ((ch = curl_easy_duphandle(p))) {
+ init_curl_storage(ch);
+ return ch;
+ }
+ return NULL;
+}
+static void safe_curl_dtor(void *p) {
+ http_request_storage *st = http_request_storage_get(p);
+
+ curl_easy_cleanup(p);
+
+ if (st) {
+ if (st->url) {
+ pefree(st->url, 1);
+ }
+ if (st->cookiestore) {
+ pefree(st->cookiestore, 1);
+ }
+ pefree(st, 1);
+ }
+}
+/* }}} */
+