libreport  2.1.4
A tool to inform users about various problems on the running system
libreport_curl.h
1 /*
2  Copyright (C) 2010 ABRT team
3  Copyright (C) 2010 RedHat Inc
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 #ifndef LIBREPORT_CURL_H_
20 #define LIBREPORT_CURL_H_
21 
22 #include <curl/curl.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 CURL* xcurl_easy_init();
29 
30 /* Set proxy according to the url and call curl_easy_perform */
31 CURLcode curl_easy_perform_with_proxy(CURL *handle, const char *url);
32 
33 typedef struct post_state {
34  /* Supplied by caller: */
35  int flags;
36  const char *username;
37  const char *password;
38  /* Results of POST transaction: */
39  int http_resp_code;
40  /* cast from CURLcode enum.
41  * 0 = success.
42  * -1 = curl_easy_perform wasn't even reached (file open error, etc).
43  * Else curl_easy_perform's error (which is positive, see curl/curl.h).
44  */
45  int curl_result;
46  unsigned header_cnt;
47  char **headers;
48  char *curl_error_msg;
49  char *body;
50  size_t body_size;
51  char errmsg[CURL_ERROR_SIZE];
52 } post_state_t;
53 
54 post_state_t *new_post_state(int flags);
55 void free_post_state(post_state_t *state);
56 char *find_header_in_post_state(post_state_t *state, const char *str);
57 
58 enum {
59  POST_WANT_HEADERS = (1 << 0),
60  POST_WANT_ERROR_MSG = (1 << 1),
61  POST_WANT_BODY = (1 << 2),
62  POST_WANT_SSL_VERIFY = (1 << 3),
63 };
64 enum {
65  /* Must be -1! CURLOPT_POSTFIELDSIZE interprets -1 as "use strlen" */
66  POST_DATA_STRING = -1,
67  POST_DATA_FROMFILE = -2,
68  POST_DATA_FROMFILE_PUT = -3,
69  POST_DATA_FROMFILE_AS_FORM_DATA = -4,
70  POST_DATA_STRING_AS_FORM_DATA = -5,
71 };
72 int
73 post(post_state_t *state,
74  const char *url,
75  const char *content_type,
76  const char **additional_headers,
77  const char *data,
78  off_t data_size);
79 static inline int
80 post_string(post_state_t *state,
81  const char *url,
82  const char *content_type,
83  const char **additional_headers,
84  const char *str)
85 {
86  return post(state, url, content_type, additional_headers,
87  str, POST_DATA_STRING);
88 }
89 static inline int
90 post_string_as_form_data(post_state_t *state,
91  const char *url,
92  const char *content_type,
93  const char **additional_headers,
94  const char *str)
95 {
96  return post(state, url, content_type, additional_headers,
97  str, POST_DATA_STRING_AS_FORM_DATA);
98 }
99 static inline int
100 post_file(post_state_t *state,
101  const char *url,
102  const char *content_type,
103  const char **additional_headers,
104  const char *filename)
105 {
106  return post(state, url, content_type, additional_headers,
107  filename, POST_DATA_FROMFILE);
108 }
109 static inline int
110 post_file_as_form(post_state_t *state,
111  const char *url,
112  const char *content_type,
113  const char **additional_headers,
114  const char *filename)
115 {
116  return post(state, url, content_type, additional_headers,
117  filename, POST_DATA_FROMFILE_AS_FORM_DATA);
118 }
119 
120 #define upload_file libreport_upload_file
121 char *upload_file(const char *url, const char *filename);
122 
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 #endif