Signed-off-by: Nikola Pajkovsky <[email protected]>
---
Will it be better to prefix post*() and enums with libreport prefix?

---
 src/include/libreport_curl.h  |   56 ++++++++++++++++++++---------------------
 src/lib/curl.c                |   38 ++++++++++++++--------------
 src/lib/json.c                |   10 ++++----
 src/lib/ureport.h             |    2 +-
 src/plugins/abrt-bodhi.c      |    9 ++++---
 src/plugins/abrt_rh_support.c |   42 +++++++++++++++----------------
 src/plugins/ureport.c         |    6 ++---
 7 files changed, 82 insertions(+), 81 deletions(-)

diff --git a/src/include/libreport_curl.h b/src/include/libreport_curl.h
index ca3c5b8..e0f976e 100644
--- a/src/include/libreport_curl.h
+++ b/src/include/libreport_curl.h
@@ -16,8 +16,8 @@
     with this program; if not, write to the Free Software Foundation, Inc.,
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
-#ifndef ABRT_CURL_H_
-#define ABRT_CURL_H_
+#ifndef LIBREPORT_CURL_H_
+#define LIBREPORT_CURL_H_
 
 #include <curl/curl.h>
 
@@ -30,7 +30,7 @@ CURL* xcurl_easy_init();
 /* Set proxy according to the url and call curl_easy_perform */
 CURLcode curl_easy_perform_with_proxy(CURL *handle, const char *url);
 
-typedef struct abrt_post_state {
+typedef struct post_state {
     /* Supplied by caller: */
     int         flags;
     const char  *username;
@@ -43,71 +43,71 @@ typedef struct abrt_post_state {
     char        *body;
     size_t      body_size;
     char        errmsg[CURL_ERROR_SIZE];
-} abrt_post_state_t;
+} post_state_t;
 
-abrt_post_state_t *new_abrt_post_state(int flags);
-void free_abrt_post_state(abrt_post_state_t *state);
-char *find_header_in_abrt_post_state(abrt_post_state_t *state, const char 
*str);
+post_state_t *new_post_state(int flags);
+void free_post_state(post_state_t *state);
+char *find_header_in_post_state(post_state_t *state, const char *str);
 
 enum {
-    ABRT_POST_WANT_HEADERS    = (1 << 0),
-    ABRT_POST_WANT_ERROR_MSG  = (1 << 1),
-    ABRT_POST_WANT_BODY       = (1 << 2),
-    ABRT_POST_WANT_SSL_VERIFY = (1 << 3),
+    POST_WANT_HEADERS    = (1 << 0),
+    POST_WANT_ERROR_MSG  = (1 << 1),
+    POST_WANT_BODY       = (1 << 2),
+    POST_WANT_SSL_VERIFY = (1 << 3),
 };
 enum {
     /* Must be -1! CURLOPT_POSTFIELDSIZE interprets -1 as "use strlen" */
-    ABRT_POST_DATA_STRING = -1,
-    ABRT_POST_DATA_FROMFILE = -2,
-    ABRT_POST_DATA_FROMFILE_AS_FORM_DATA = -3,
-    ABRT_POST_DATA_STRING_AS_FORM_DATA = -4,
+    POST_DATA_STRING = -1,
+    POST_DATA_FROMFILE = -2,
+    POST_DATA_FROMFILE_AS_FORM_DATA = -3,
+    POST_DATA_STRING_AS_FORM_DATA = -4,
 };
 int
-abrt_post(abrt_post_state_t *state,
+post(post_state_t *state,
                 const char *url,
                 const char *content_type,
                 const char **additional_headers,
                 const char *data,
                 off_t data_size);
 static inline int
-abrt_post_string(abrt_post_state_t *state,
+post_string(post_state_t *state,
                 const char *url,
                 const char *content_type,
                 const char **additional_headers,
                 const char *str)
 {
-    return abrt_post(state, url, content_type, additional_headers,
-                     str, ABRT_POST_DATA_STRING);
+    return post(state, url, content_type, additional_headers,
+                     str, POST_DATA_STRING);
 }
 static inline int
-abrt_post_string_as_form_data(abrt_post_state_t *state,
+post_string_as_form_data(post_state_t *state,
                 const char *url,
                 const char *content_type,
                 const char **additional_headers,
                 const char *str)
 {
-    return abrt_post(state, url, content_type, additional_headers,
-                     str, ABRT_POST_DATA_STRING_AS_FORM_DATA);
+    return post(state, url, content_type, additional_headers,
+                     str, POST_DATA_STRING_AS_FORM_DATA);
 }
 static inline int
-abrt_post_file(abrt_post_state_t *state,
+post_file(post_state_t *state,
                 const char *url,
                 const char *content_type,
                 const char **additional_headers,
                 const char *filename)
 {
-    return abrt_post(state, url, content_type, additional_headers,
-                     filename, ABRT_POST_DATA_FROMFILE);
+    return post(state, url, content_type, additional_headers,
+                     filename, POST_DATA_FROMFILE);
 }
 static inline int
-abrt_post_file_as_form(abrt_post_state_t *state,
+post_file_as_form(post_state_t *state,
                 const char *url,
                 const char *content_type,
                 const char **additional_headers,
                 const char *filename)
 {
-    return abrt_post(state, url, content_type, additional_headers,
-                     filename, ABRT_POST_DATA_FROMFILE_AS_FORM_DATA);
+    return post(state, url, content_type, additional_headers,
+                     filename, POST_DATA_FROMFILE_AS_FORM_DATA);
 }
 
 #ifdef __cplusplus
diff --git a/src/lib/curl.c b/src/lib/curl.c
index 98b24f5..e30e9a6 100644
--- a/src/lib/curl.c
+++ b/src/lib/curl.c
@@ -106,14 +106,14 @@ CURLcode curl_easy_perform_with_proxy(CURL *handle, const 
char *url)
  * post_state utility functions
  */
 
-abrt_post_state_t *new_abrt_post_state(int flags)
+post_state_t *new_post_state(int flags)
 {
-    abrt_post_state_t *state = (abrt_post_state_t *)xzalloc(sizeof(*state));
+    post_state_t *state = (post_state_t *)xzalloc(sizeof(*state));
     state->flags = flags;
     return state;
 }
 
-void free_abrt_post_state(abrt_post_state_t *state)
+void free_post_state(post_state_t *state)
 {
     char **headers = state->headers;
     if (headers)
@@ -127,7 +127,7 @@ void free_abrt_post_state(abrt_post_state_t *state)
     free(state);
 }
 
-char *find_header_in_abrt_post_state(abrt_post_state_t *state, const char *str)
+char *find_header_in_post_state(post_state_t *state, const char *str)
 {
     char **headers = state->headers;
     if (headers)
@@ -144,14 +144,14 @@ char *find_header_in_abrt_post_state(abrt_post_state_t 
*state, const char *str)
 }
 
 /*
- * abrt_post: perform HTTP POST transaction
+ * post: perform HTTP POST transaction
  */
 
 /* "save headers" callback */
 static size_t
 save_headers(void *buffer_pv, size_t count, size_t nmemb, void *ptr)
 {
-    abrt_post_state_t* state = (abrt_post_state_t*)ptr;
+    post_state_t* state = (post_state_t*)ptr;
     size_t size = count * nmemb;
 
     char *h = xstrndup((char*)buffer_pv, size);
@@ -248,7 +248,7 @@ static int curl_debug(CURL *handle, curl_infotype it, char 
*buf, size_t bufsize,
 }
 
 int
-abrt_post(abrt_post_state_t *state,
+post(post_state_t *state,
                 const char *url,
                 const char *content_type,
                 const char **additional_headers,
@@ -257,9 +257,9 @@ abrt_post(abrt_post_state_t *state,
 {
     CURLcode curl_err;
     long response_code;
-    abrt_post_state_t localstate;
+    post_state_t localstate;
 
-    VERB3 log("abrt_post('%s','%s')", url, data);
+    VERB3 log("%s('%s','%s')", __func__, url, data);
 
     if (!state)
     {
@@ -308,7 +308,7 @@ abrt_post(abrt_post_state_t *state,
     struct curl_httppost* post = NULL;
     struct curl_httppost* last = NULL;
     FILE* data_file = NULL;
-    if (data_size == ABRT_POST_DATA_FROMFILE) {
+    if (data_size == POST_DATA_FROMFILE) {
         // ...from a file
         data_file = fopen(data, "r");
         if (!data_file)
@@ -323,7 +323,7 @@ abrt_post(abrt_post_state_t *state,
         off_t sz = ftello(data_file);
         fseeko(data_file, 0, SEEK_SET);
         xcurl_easy_setopt_off_t(handle, CURLOPT_POSTFIELDSIZE_LARGE, sz);
-    } else if (data_size == ABRT_POST_DATA_FROMFILE_AS_FORM_DATA) {
+    } else if (data_size == POST_DATA_FROMFILE_AS_FORM_DATA) {
         // ...from a file, in multipart/formdata format
         const char *basename = strrchr(data, '/');
         if (basename) basename++;
@@ -362,7 +362,7 @@ abrt_post(abrt_post_state_t *state,
 //FIXME:
             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 if (data_size == ABRT_POST_DATA_STRING_AS_FORM_DATA) {
+    } else if (data_size == POST_DATA_STRING_AS_FORM_DATA) {
         CURLFORMcode curlform_err = curl_formadd(&post, &last,
                         CURLFORM_PTRNAME, "file", // element name
                         // curl bug - missing filename 
@@ -383,7 +383,7 @@ abrt_post(abrt_post_state_t *state,
     } else {
         // .. from a blob in memory
         xcurl_easy_setopt_ptr(handle, CURLOPT_POSTFIELDS, data);
-        // note1: if data_size == ABRT_POST_DATA_STRING == -1, curl will use 
strlen(data)
+        // note1: if data_size == POST_DATA_STRING == -1, curl will use 
strlen(data)
         xcurl_easy_setopt_long(handle, CURLOPT_POSTFIELDSIZE, data_size);
         // We don't use CURLOPT_POSTFIELDSIZE_LARGE because
         // I'm not sure CURLOPT_POSTFIELDSIZE_LARGE special-cases -1.
@@ -393,8 +393,8 @@ abrt_post(abrt_post_state_t *state,
     struct curl_slist *httpheader_list = NULL;
 
     // Override "Content-Type:"
-    if (data_size != ABRT_POST_DATA_FROMFILE_AS_FORM_DATA
-        && data_size != ABRT_POST_DATA_STRING_AS_FORM_DATA)
+    if (data_size != POST_DATA_FROMFILE_AS_FORM_DATA
+        && data_size != POST_DATA_STRING_AS_FORM_DATA)
     {
         char *content_type_header = xasprintf("Content-Type: %s", 
content_type);
         // Note: curl_slist_append() copies content_type_header
@@ -440,20 +440,20 @@ abrt_post(abrt_post_state_t *state,
 #endif
 
     // Prepare for saving information
-    if (state->flags & ABRT_POST_WANT_HEADERS)
+    if (state->flags & POST_WANT_HEADERS)
     {
         xcurl_easy_setopt_ptr(handle, CURLOPT_HEADERFUNCTION, 
(void*)save_headers);
         xcurl_easy_setopt_ptr(handle, CURLOPT_WRITEHEADER, state);
     }
     FILE* body_stream = NULL;
-    if (state->flags & ABRT_POST_WANT_BODY)
+    if (state->flags & POST_WANT_BODY)
     {
         body_stream = open_memstream(&state->body, &state->body_size);
         if (!body_stream)
             error_msg_and_die("out of memory");
         xcurl_easy_setopt_ptr(handle, CURLOPT_WRITEDATA, body_stream);
     }
-    if (!(state->flags & ABRT_POST_WANT_SSL_VERIFY))
+    if (!(state->flags & POST_WANT_SSL_VERIFY))
     {
         xcurl_easy_setopt_long(handle, CURLOPT_SSL_VERIFYPEER, 0);
         xcurl_easy_setopt_long(handle, CURLOPT_SSL_VERIFYHOST, 0);
@@ -465,7 +465,7 @@ abrt_post(abrt_post_state_t *state,
     if (curl_err)
     {
         VERB2 log("curl_easy_perform: error %d", (int)curl_err);
-        if (state->flags & ABRT_POST_WANT_ERROR_MSG)
+        if (state->flags & POST_WANT_ERROR_MSG)
         {
             state->curl_error_msg = check_curl_error(curl_err, 
"curl_easy_perform");
             VERB3 log("curl_easy_perform: error_msg: %s", 
state->curl_error_msg);
diff --git a/src/lib/json.c b/src/lib/json.c
index 651010d..91039ef 100644
--- a/src/lib/json.c
+++ b/src/lib/json.c
@@ -251,14 +251,14 @@ char *new_json_ureport(problem_data_t *pd)
     return j;
 }
 
-struct abrt_post_state *post_ureport(problem_data_t *pd, struct 
ureport_server_config *config)
+struct post_state *post_ureport(problem_data_t *pd, struct 
ureport_server_config *config)
 {
-    int flags = ABRT_POST_WANT_BODY | ABRT_POST_WANT_ERROR_MSG;
+    int flags = POST_WANT_BODY | POST_WANT_ERROR_MSG;
 
     if (config->ur_ssl_verify)
-        flags |= ABRT_POST_WANT_SSL_VERIFY;
+        flags |= POST_WANT_SSL_VERIFY;
 
-    abrt_post_state_t *post_state = new_abrt_post_state(flags);
+    struct post_state *post_state = new_post_state(flags);
 
     static const char *headers[] = {
         "Accept: application/json",
@@ -268,7 +268,7 @@ struct abrt_post_state *post_ureport(problem_data_t *pd, 
struct ureport_server_c
 
     char *json_ureport = new_json_ureport(pd);
 
-    abrt_post_string_as_form_data(post_state, config->ur_url, 
"application/json",
+    post_string_as_form_data(post_state, config->ur_url, "application/json",
                      headers, json_ureport);
 
     free(json_ureport);
diff --git a/src/lib/ureport.h b/src/lib/ureport.h
index b1b1d89..4e1bfcc 100644
--- a/src/lib/ureport.h
+++ b/src/lib/ureport.h
@@ -37,7 +37,7 @@ struct ureport_server_config
 struct abrt_post_state;
 
 #define post_ureport libreport_post_ureport
-struct abrt_post_state *post_ureport(problem_data_t *pd, struct 
ureport_server_config *config);
+struct post_state *post_ureport(problem_data_t *pd, struct 
ureport_server_config *config);
 
 #ifdef __cplusplus
 }
diff --git a/src/plugins/abrt-bodhi.c b/src/plugins/abrt-bodhi.c
index 632a351..b24c0a7 100644
--- a/src/plugins/abrt-bodhi.c
+++ b/src/plugins/abrt-bodhi.c
@@ -289,15 +289,16 @@ static GHashTable *bodhi_query_list(const char *query, 
const char *release)
 {
     char *bodhi_url_bugs = xasprintf("%s/list", bodhi_url);
 
-    abrt_post_state_t *post_state = new_abrt_post_state(
-        ABRT_POST_WANT_BODY | ABRT_POST_WANT_SSL_VERIFY | 
ABRT_POST_WANT_ERROR_MSG);
+    post_state_t *post_state = new_post_state(POST_WANT_BODY
+                                              | POST_WANT_SSL_VERIFY
+                                              | POST_WANT_ERROR_MSG);
 
     const char *headers[] = {
         "Accept: application/json",
         NULL
     };
 
-    abrt_post_string(post_state, bodhi_url_bugs, 
"application/x-www-form-urlencoded",
+    post_string(post_state, bodhi_url_bugs, 
"application/x-www-form-urlencoded",
                      headers, query);
 
     if (post_state->http_resp_code != 200)
@@ -316,7 +317,7 @@ static GHashTable *bodhi_query_list(const char *query, 
const char *release)
 
     GHashTable *bodhi_table = bodhi_parse_json(json, release);
     json_object_put(json);
-    free_abrt_post_state(post_state);
+    free_post_state(post_state);
 
     return bodhi_table;
 }
diff --git a/src/plugins/abrt_rh_support.c b/src/plugins/abrt_rh_support.c
index 233edfa..9f7810a 100644
--- a/src/plugins/abrt_rh_support.c
+++ b/src/plugins/abrt_rh_support.c
@@ -332,21 +332,21 @@ post_case_to_url(const char* url,
 
     int redirect_count = 0;
     char *errmsg;
-    abrt_post_state_t *case_state;
+    post_state_t *case_state;
 
  redirect_case:
-    case_state = new_abrt_post_state(0
-            + ABRT_POST_WANT_HEADERS
-            + ABRT_POST_WANT_BODY
-            + ABRT_POST_WANT_ERROR_MSG
-            + (ssl_verify ? ABRT_POST_WANT_SSL_VERIFY : 0)
+    case_state = new_post_state(0
+            + POST_WANT_HEADERS
+            + POST_WANT_BODY
+            + POST_WANT_ERROR_MSG
+            + (ssl_verify ? POST_WANT_SSL_VERIFY : 0)
     );
     case_state->username = username;
     case_state->password = password;
 
-    abrt_post_string(case_state, url, "application/xml", additional_headers, 
case_data);
+    post_string(case_state, url, "application/xml", additional_headers, 
case_data);
 
-    char *case_location = find_header_in_abrt_post_state(case_state, 
"Location:");
+    char *case_location = find_header_in_post_state(case_state, "Location:");
 
     switch (case_state->http_resp_code)
     {
@@ -367,7 +367,7 @@ post_case_to_url(const char* url,
         {
             free(url_copy);
             url = url_copy = xstrdup(case_location);
-            free_abrt_post_state(case_state);
+            free_post_state(case_state);
             goto redirect_case;
         }
         /* fall through */
@@ -416,7 +416,7 @@ post_case_to_url(const char* url,
     result->body = case_state->body;
     case_state->body = NULL;
 
-    free_abrt_post_state(case_state);
+    free_post_state(case_state);
     free(case_data);
     free(url_copy);
     return result;
@@ -436,14 +436,14 @@ post_file_to_url(const char* url,
 
     int redirect_count = 0;
     char *errmsg;
-    abrt_post_state_t *atch_state;
+    post_state_t *atch_state;
 
  redirect_attach:
-    atch_state = new_abrt_post_state(0
-            + ABRT_POST_WANT_HEADERS
-            + ABRT_POST_WANT_BODY
-            + ABRT_POST_WANT_ERROR_MSG
-            + (ssl_verify ? ABRT_POST_WANT_SSL_VERIFY : 0)
+    atch_state = new_post_state(0
+            + POST_WANT_HEADERS
+            + POST_WANT_BODY
+            + POST_WANT_ERROR_MSG
+            + (ssl_verify ? POST_WANT_SSL_VERIFY : 0)
     );
     atch_state->username = username;
     atch_state->password = password;
@@ -452,7 +452,7 @@ post_file_to_url(const char* url,
         /* Sends data in multipart/mixed document. One detail is that
         * file *name* is also sent to the server.
         */
-        abrt_post_file_as_form(atch_state,
+        post_file_as_form(atch_state,
             url,
             "application/octet-stream",
             additional_headers,
@@ -462,7 +462,7 @@ post_file_to_url(const char* url,
     else
     {
         /* Sends file's raw contents */
-        abrt_post_file(atch_state,
+        post_file(atch_state,
             url,
             "application/octet-stream",
             additional_headers,
@@ -470,7 +470,7 @@ post_file_to_url(const char* url,
         );
     }
 
-    char *atch_location = find_header_in_abrt_post_state(atch_state, 
"Location:");
+    char *atch_location = find_header_in_post_state(atch_state, "Location:");
 
     switch (atch_state->http_resp_code)
     {
@@ -479,7 +479,7 @@ post_file_to_url(const char* url,
         {
             free(url_copy);
             url = url_copy = xstrdup(atch_location);
-            free_abrt_post_state(atch_state);
+            free_post_state(atch_state);
             goto redirect_attach;
         }
         /* fall through */
@@ -514,7 +514,7 @@ post_file_to_url(const char* url,
     result->body = atch_state->body;
     atch_state->body = NULL;
 
-    free_abrt_post_state(atch_state);
+    free_post_state(atch_state);
     free(url_copy);
     return result;
 }
diff --git a/src/plugins/ureport.c b/src/plugins/ureport.c
index c75af63..97a7891 100644
--- a/src/plugins/ureport.c
+++ b/src/plugins/ureport.c
@@ -123,7 +123,7 @@ int main(int argc, char **argv)
     if (!pd)
         xfunc_die(); /* create_problem_data_for_reporting already emitted 
error msg */
 
-    abrt_post_state_t *post_state = NULL;
+    post_state_t *post_state = NULL;
     post_state = post_ureport(pd, &config);
     free_problem_data(pd);
 
@@ -133,7 +133,7 @@ int main(int argc, char **argv)
         if (errmsg && *errmsg)
         {
             error_msg("%s '%s'", errmsg, config.ur_url);
-            free_abrt_post_state(post_state);
+            free_post_state(post_state);
             return 1;
         }
     }
@@ -186,7 +186,7 @@ int main(int argc, char **argv)
 format_err:
     json_object_put(json);
 err:
-    free_abrt_post_state(post_state);
+    free_post_state(post_state);
 
     return ret;
 }
-- 
1.7.10.2

Reply via email to