Jakub Filak<jfilak(a)redhat.com> writes:
> Signed-off-by: Jakub Filak<jfilak(a)redhat.com>
> ---
> src/lib/abrt_curl.c | 21 ++++++++++++++++++++-
> src/lib/abrt_curl.h | 11 +++++++++++
> src/lib/json.c | 4 ++--
> src/plugins/ureport.c | 4 ++++
> 4 files changed, 37 insertions(+), 3 deletions(-)
>
> diff --git a/src/lib/abrt_curl.c b/src/lib/abrt_curl.c
> index 9ec77d1..1ae773d 100644
> --- a/src/lib/abrt_curl.c
> +++ b/src/lib/abrt_curl.c
> @@ -362,6 +362,24 @@ 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) {
> + CURLFORMcode curlform_err = curl_formadd(&post,&last,
> + CURLFORM_PTRNAME, "file", // element name
> + // curl bug - missing filename
> + //
http://curl.haxx.se/mail/lib-2011-07/0176.html
> + //
https://github.com/bagder/curl/commit/45d883d
> + // fixed in curl-7.22.0~144
> + // tested with curl-7.24.0-3
> + // should be working on F17
> + CURLFORM_BUFFER, "*buffer*", // provides filename
> + CURLFORM_BUFFERPTR, data,
> + CURLFORM_BUFFERLENGTH, (long)strlen(data),
> +//FIXME: what if file size doesn't fit in long?
> + CURLFORM_CONTENTTYPE, content_type,
> + CURLFORM_END);
> + if (curlform_err != 0)
> + 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 {
> // .. from a blob in memory
> xcurl_easy_setopt_ptr(handle, CURLOPT_POSTFIELDS, data);
> @@ -375,7 +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)
> + if (data_size != ABRT_POST_DATA_FROMFILE_AS_FORM_DATA
> +&& data_size != ABRT_POST_DATA_STRING_AS_FORM_DATA)
> {
> char *content_type_header = xasprintf("Content-Type: %s",
content_type);
> // Note: curl_slist_append() copies content_type_header
> diff --git a/src/lib/abrt_curl.h b/src/lib/abrt_curl.h
> index dfca303..ca3c5b8 100644
> --- a/src/lib/abrt_curl.h
> +++ b/src/lib/abrt_curl.h
> @@ -60,6 +60,7 @@ enum {
> 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,
> };
> int
> abrt_post(abrt_post_state_t *state,
> @@ -79,6 +80,16 @@ abrt_post_string(abrt_post_state_t *state,
> str, ABRT_POST_DATA_STRING);
> }
> static inline int
> +abrt_post_string_as_form_data(abrt_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);
> +}
> +static inline int
> abrt_post_file(abrt_post_state_t *state,
> const char *url,
> const char *content_type,
> diff --git a/src/lib/json.c b/src/lib/json.c
> index 2adf4ee..3bf3844 100644
> --- a/src/lib/json.c
> +++ b/src/lib/json.c
> @@ -237,14 +237,14 @@ abrt_post_state_t *post_ureport(problem_data_t *pd, const char
*ureport_url)
> | ABRT_POST_WANT_ERROR_MSG);
>
> static const char *headers[] = {
> - "Accept: text/plain",
> + "Accept: application/json",
> "Connection: close",
> NULL,
> };
>
> char *json_ureport = new_json_ureport(pd);
>
> - abrt_post_string(post_state, ureport_url, "application/json",
> + abrt_post_string_as_form_data(post_state, ureport_url,
"application/json",
> headers, json_ureport);
>
> free(json_ureport);
> diff --git a/src/plugins/ureport.c b/src/plugins/ureport.c
> index f0a6428..ed01cc7 100644
> --- a/src/plugins/ureport.c
> +++ b/src/plugins/ureport.c
> @@ -63,12 +63,16 @@ int main(int argc, char **argv)
> }
> }
>
> + // TODO : parse JSON response
> char *line = strtok(post_state->body, "\n");
> + VERB2 log("Response:\n----\n%s\n----", line);
it's already printed in VERB2, you don't have to do it twice
> int ret = 0;
> while (line)
> {
> if (!prefixcmp(line, "ERROR "))
> {
> + log("%s", line);
don't print anything on err