d189def
From 85e6d59c4c9aeabb16cb9e0c68f13933b2c7ed7b Mon Sep 17 00:00:00 2001
d189def
From: Jakub Filak <jfilak@redhat.com>
d189def
Date: Tue, 25 Aug 2015 15:49:13 +0200
d189def
Subject: [PATCH] curl: add a helper for HTTP GET
d189def
d189def
Please do not think I am an idiot but I really do not see any better way
d189def
to enable ABRT to use HTTP GET through libreport helper functions.
d189def
d189def
Related: rhbz#1256493
d189def
d189def
Signed-off-by: Jakub Filak <jfilak@redhat.com>
d189def
---
d189def
 src/include/libreport_curl.h | 10 ++++++++++
d189def
 src/lib/curl.c               |  4 ++--
d189def
 2 files changed, 12 insertions(+), 2 deletions(-)
d189def
d189def
diff --git a/src/include/libreport_curl.h b/src/include/libreport_curl.h
d189def
index 4b41ecc..5478fa6 100644
d189def
--- a/src/include/libreport_curl.h
d189def
+++ b/src/include/libreport_curl.h
d189def
@@ -70,6 +70,7 @@ enum {
d189def
     POST_DATA_FROMFILE_PUT = -3,
d189def
     POST_DATA_FROMFILE_AS_FORM_DATA = -4,
d189def
     POST_DATA_STRING_AS_FORM_DATA = -5,
d189def
+    POST_DATA_GET = -6,
d189def
 };
d189def
 int
d189def
 post(post_state_t *state,
d189def
@@ -79,6 +80,15 @@ post(post_state_t *state,
d189def
                 const char *data,
d189def
                 off_t data_size);
d189def
 static inline int
d189def
+get(post_state_t *state,
d189def
+                const char *url,
d189def
+                const char *content_type,
d189def
+                const char **additional_headers)
d189def
+{
d189def
+    return post(state, url, content_type, additional_headers,
d189def
+                     NULL, POST_DATA_GET);
d189def
+}
d189def
+static inline int
d189def
 post_string(post_state_t *state,
d189def
                 const char *url,
d189def
                 const char *content_type,
d189def
diff --git a/src/lib/curl.c b/src/lib/curl.c
d189def
index f7321b5..c927ece 100644
d189def
--- a/src/lib/curl.c
d189def
+++ b/src/lib/curl.c
d189def
@@ -351,7 +351,7 @@ post(post_state_t *state,
d189def
         xcurl_easy_setopt_ptr(handle, CURLOPT_PASSWORD, (state->password ? state->password : ""));
d189def
     }
d189def
 
d189def
-    if (data_size != POST_DATA_FROMFILE_PUT)
d189def
+    if (data_size != POST_DATA_FROMFILE_PUT && data_size != POST_DATA_GET)
d189def
     {
d189def
         // Do a HTTP POST. This also makes curl use
d189def
         // a "Content-Type: application/x-www-form-urlencoded" header.
d189def
@@ -459,7 +459,7 @@ post(post_state_t *state,
d189def
             error_msg_and_die("out of memory or read error (curl_formadd error code: %d)", (int)curlform_err);
d189def
         xcurl_easy_setopt_ptr(handle, CURLOPT_HTTPPOST, post);
d189def
     }
d189def
-    else
d189def
+    else if (data_size != POST_DATA_GET)
d189def
     {
d189def
         // ...from a blob in memory
d189def
         xcurl_easy_setopt_ptr(handle, CURLOPT_POSTFIELDS, data);
d189def
-- 
d189def
2.5.0
d189def