Blob Blame History Raw
From 85e6d59c4c9aeabb16cb9e0c68f13933b2c7ed7b Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
Date: Tue, 25 Aug 2015 15:49:13 +0200
Subject: [PATCH] curl: add a helper for HTTP GET

Please do not think I am an idiot but I really do not see any better way
to enable ABRT to use HTTP GET through libreport helper functions.

Related: rhbz#1256493

Signed-off-by: Jakub Filak <jfilak@redhat.com>
---
 src/include/libreport_curl.h | 10 ++++++++++
 src/lib/curl.c               |  4 ++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/include/libreport_curl.h b/src/include/libreport_curl.h
index 4b41ecc..5478fa6 100644
--- a/src/include/libreport_curl.h
+++ b/src/include/libreport_curl.h
@@ -70,6 +70,7 @@ enum {
     POST_DATA_FROMFILE_PUT = -3,
     POST_DATA_FROMFILE_AS_FORM_DATA = -4,
     POST_DATA_STRING_AS_FORM_DATA = -5,
+    POST_DATA_GET = -6,
 };
 int
 post(post_state_t *state,
@@ -79,6 +80,15 @@ post(post_state_t *state,
                 const char *data,
                 off_t data_size);
 static inline int
+get(post_state_t *state,
+                const char *url,
+                const char *content_type,
+                const char **additional_headers)
+{
+    return post(state, url, content_type, additional_headers,
+                     NULL, POST_DATA_GET);
+}
+static inline int
 post_string(post_state_t *state,
                 const char *url,
                 const char *content_type,
diff --git a/src/lib/curl.c b/src/lib/curl.c
index f7321b5..c927ece 100644
--- a/src/lib/curl.c
+++ b/src/lib/curl.c
@@ -351,7 +351,7 @@ post(post_state_t *state,
         xcurl_easy_setopt_ptr(handle, CURLOPT_PASSWORD, (state->password ? state->password : ""));
     }
 
-    if (data_size != POST_DATA_FROMFILE_PUT)
+    if (data_size != POST_DATA_FROMFILE_PUT && data_size != POST_DATA_GET)
     {
         // Do a HTTP POST. This also makes curl use
         // a "Content-Type: application/x-www-form-urlencoded" header.
@@ -459,7 +459,7 @@ post(post_state_t *state,
             error_msg_and_die("out of memory or read error (curl_formadd error code: %d)", (int)curlform_err);
         xcurl_easy_setopt_ptr(handle, CURLOPT_HTTPPOST, post);
     }
-    else
+    else if (data_size != POST_DATA_GET)
     {
         // ...from a blob in memory
         xcurl_easy_setopt_ptr(handle, CURLOPT_POSTFIELDS, data);
-- 
2.5.0