libreport 2.13.1
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
25extern "C" {
26#endif
27
28CURL* xcurl_easy_init();
29
30/* Set proxy according to the url and call curl_easy_perform */
31CURLcode curl_easy_perform_with_proxy(CURL *handle, const char *url);
32
33typedef struct post_state {
34 /* Supplied by caller: */
35 int flags;
36 const char *username;
37 const char *password;
38 const char *client_cert_path;
39 const char *client_key_path;
40 const char *cert_authority_cert_path;
41 /* SSH key files */
42 const char *client_ssh_public_keyfile;
43 const char *client_ssh_private_keyfile;
44 /* Results of POST transaction: */
45 int http_resp_code;
46 /* cast from CURLcode enum.
47 * 0 = success.
48 * -1 = curl_easy_perform wasn't even reached (file open error, etc).
49 * Else curl_easy_perform's error (which is positive, see curl/curl.h).
50 */
51 int curl_result;
52 unsigned header_cnt;
53 char **headers;
54 char *curl_error_msg;
55 char *body;
56 size_t body_size;
57 char errmsg[CURL_ERROR_SIZE];
59
60post_state_t *new_post_state(int flags);
61void free_post_state(post_state_t *state);
62char *find_header_in_post_state(post_state_t *state, const char *str);
63
64enum {
65 POST_WANT_HEADERS = (1 << 0),
66 POST_WANT_ERROR_MSG = (1 << 1),
67 POST_WANT_BODY = (1 << 2),
68 POST_WANT_SSL_VERIFY = (1 << 3),
69};
70enum {
71 /* Must be -1! CURLOPT_POSTFIELDSIZE interprets -1 as "use strlen" */
72 POST_DATA_STRING = -1,
73 POST_DATA_FROMFILE = -2,
74 POST_DATA_FROMFILE_PUT = -3,
75 POST_DATA_FROMFILE_AS_FORM_DATA = -4,
76 POST_DATA_STRING_AS_FORM_DATA = -5,
77 POST_DATA_GET = -6,
78};
79int
80post(post_state_t *state,
81 const char *url,
82 const char *content_type,
83 const char **additional_headers,
84 const char *data,
85 off_t data_size);
86static inline int
87get(post_state_t *state,
88 const char *url,
89 const char *content_type,
90 const char **additional_headers)
91{
92 return post(state, url, content_type, additional_headers,
93 NULL, POST_DATA_GET);
94}
95static inline int
96post_string(post_state_t *state,
97 const char *url,
98 const char *content_type,
99 const char **additional_headers,
100 const char *str)
101{
102 return post(state, url, content_type, additional_headers,
103 str, POST_DATA_STRING);
104}
105static inline int
106post_string_as_form_data(post_state_t *state,
107 const char *url,
108 const char *content_type,
109 const char **additional_headers,
110 const char *str)
111{
112 return post(state, url, content_type, additional_headers,
113 str, POST_DATA_STRING_AS_FORM_DATA);
114}
115static inline int
116post_file(post_state_t *state,
117 const char *url,
118 const char *content_type,
119 const char **additional_headers,
120 const char *filename)
121{
122 return post(state, url, content_type, additional_headers,
123 filename, POST_DATA_FROMFILE);
124}
125static inline int
126post_file_as_form(post_state_t *state,
127 const char *url,
128 const char *content_type,
129 const char **additional_headers,
130 const char *filename)
131{
132 return post(state, url, content_type, additional_headers,
133 filename, POST_DATA_FROMFILE_AS_FORM_DATA);
134}
135
136enum {
137 UPLOAD_FILE_NOFLAGS = 0,
138 UPLOAD_FILE_HANDLE_ACCESS_DENIALS = 1 << 0,
139};
140
141char *libreport_upload_file(const char *url, const char *filename);
142
143/* Uploads filename to url.
144 *
145 * If url does not ends with '/', base name of filename will be amended.
146 *
147 * Fails if the url does not have scheme or hostname.
148 *
149 * @return Resulting URL on success (the URL does not contain userinfo);
150 * otherwise NULL.
151 */
152char *libreport_upload_file_ext(post_state_t *post_state,
153 const char *url,
154 const char *filename,
155 int flags);
156
157#ifdef __cplusplus
158}
159#endif
160
161#endif