libreport  2.1.2
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  unsigned header_cnt;
41  char **headers;
42  char *curl_error_msg;
43  char *body;
44  size_t body_size;
45  char errmsg[CURL_ERROR_SIZE];
46 } post_state_t;
47 
48 post_state_t *new_post_state(int flags);
49 void free_post_state(post_state_t *state);
50 char *find_header_in_post_state(post_state_t *state, const char *str);
51 
52 enum {
53  POST_WANT_HEADERS = (1 << 0),
54  POST_WANT_ERROR_MSG = (1 << 1),
55  POST_WANT_BODY = (1 << 2),
56  POST_WANT_SSL_VERIFY = (1 << 3),
57 };
58 enum {
59  /* Must be -1! CURLOPT_POSTFIELDSIZE interprets -1 as "use strlen" */
60  POST_DATA_STRING = -1,
61  POST_DATA_FROMFILE = -2,
62  POST_DATA_FROMFILE_AS_FORM_DATA = -3,
63  POST_DATA_STRING_AS_FORM_DATA = -4,
64 };
65 int
66 post(post_state_t *state,
67  const char *url,
68  const char *content_type,
69  const char **additional_headers,
70  const char *data,
71  off_t data_size);
72 static inline int
73 post_string(post_state_t *state,
74  const char *url,
75  const char *content_type,
76  const char **additional_headers,
77  const char *str)
78 {
79  return post(state, url, content_type, additional_headers,
80  str, POST_DATA_STRING);
81 }
82 static inline int
83 post_string_as_form_data(post_state_t *state,
84  const char *url,
85  const char *content_type,
86  const char **additional_headers,
87  const char *str)
88 {
89  return post(state, url, content_type, additional_headers,
90  str, POST_DATA_STRING_AS_FORM_DATA);
91 }
92 static inline int
93 post_file(post_state_t *state,
94  const char *url,
95  const char *content_type,
96  const char **additional_headers,
97  const char *filename)
98 {
99  return post(state, url, content_type, additional_headers,
100  filename, POST_DATA_FROMFILE);
101 }
102 static inline int
103 post_file_as_form(post_state_t *state,
104  const char *url,
105  const char *content_type,
106  const char **additional_headers,
107  const char *filename)
108 {
109  return post(state, url, content_type, additional_headers,
110  filename, POST_DATA_FROMFILE_AS_FORM_DATA);
111 }
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif