libreport  2.3.0
A tool to inform users about various problems on the running system
ureport.h
1 /*
2  Copyright (C) 2012 ABRT team
3  Copyright (C) 2012 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 UREPORT_H_
20 #define UREPORT_H_
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #include "internal_libreport.h"
27 
28 #define UREPORT_CONF_FILE_PATH PLUGINS_CONF_DIR"/ureport.conf"
29 
30 #define UREPORT_OPTION_VALUE_FROM_CONF(settings, opt, var, tr) do { const char *value = getenv("uReport_"opt); \
31  if (!value) { value = get_map_string_item_or_NULL(settings, opt); } if (value) { var = tr(value); } \
32  } while(0)
33 
34 #define UREPORT_SUBMIT_ACTION "reports/new/"
35 #define UREPORT_ATTACH_ACTION "reports/attach/"
36 
37 /*
38  * uReport generation configuration
39  */
41 {
42  GList *urp_auth_items;
43 };
44 
45 /*
46  * uReport server configuration
47  */
49 {
50  char *ur_url;
53  char *ur_client_key;
55  char *ur_username;
56  char *ur_password;
57  map_string_t *ur_http_headers;
58 
60 };
61 
62 /*
63  * Initialize structure members
64  *
65  * @param config Initialized structure
66  */
67 #define ureport_server_config_init libreport_ureport_server_config_init
68 void
69 ureport_server_config_init(struct ureport_server_config *config);
70 
71 /*
72  * Release all allocated resources
73  *
74  * @param config Released structure
75  */
76 #define ureport_server_config_destroy libreport_ureport_server_config_destroy
77 void
78 ureport_server_config_destroy(struct ureport_server_config *config);
79 
80 /*
81  * Loads uReport configuration from various sources.
82  *
83  * Replaces a value of an already configured option only if the
84  * option was found in a configuration source.
85  *
86  * @param config a server configuration to be populated
87  */
88 #define ureport_server_config_load libreport_ureport_server_config_load
89 void
90 ureport_server_config_load(struct ureport_server_config *config,
91  map_string_t *settings);
92 
93 /*
94  * Configure HTTP(S) URL to server's index page
95  *
96  * @param config Where the url is stored
97  * @param server_url Index URL
98  */
99 #define ureport_server_config_set_url libreport_ureport_server_config_set_url
100 void
101 ureport_server_config_set_url(struct ureport_server_config *config,
102  char *server_url);
103 
104 /*
105  * Configure client certificate paths
106  *
107  * @param config Where the paths are stored
108  * @param client_path Path in form of cert_full_path:key_full_path or one of
109  * the following string: 'rhsm', 'puppet'.
110  */
111 #define ureport_server_config_set_client_auth libreport_ureport_server_config_set_client_auth
112 void
113 ureport_server_config_set_client_auth(struct ureport_server_config *config,
114  const char *client_auth);
115 
116 /*
117  * Configure user name and password for HTTP Basic authentication
118  *
119  * @param config Configured structure
120  * @param username User name
121  * @param password Password
122  */
123 #define ureport_server_config_set_basic_auth libreport_ureport_server_config_set_basic_auth
124 void
125 ureport_server_config_set_basic_auth(struct ureport_server_config *config,
126  const char *username, const char *password);
127 
128 /*
129  * uReport server response
130  */
132 {
134  char *urr_value;
135  char *urr_message;
136  char *urr_bthash;
138  char *urr_solution;
140 };
141 
142 /* Can't include "abrt_curl.h", it's not a public API.
143  * Resorting to just forward-declaring the struct we need.
144  */
145 struct post_state;
146 
147 /*
148  * Parse server reply
149  *
150  * @param post_state Server reply
151  * @param config Configuration used in communication
152  * @return Pointer to malloced memory or NULL in case of error in communication
153  */
154 #define ureport_server_response_from_reply libreport_ureport_server_response_from_reply
156 ureport_server_response_from_reply(struct post_state *post_state,
157  struct ureport_server_config *config);
158 
159 /*
160  * Save response in dump dir files
161  *
162  * @param resp Parsed server response
163  * @param dump_dir_pat Path to dump directory
164  * @param config Configuration used in communication
165  * @return False in case of any error; otherwise True.
166  */
167 #define ureport_server_response_save_in_dump_dir libreport_ureport_server_response_save_in_dump_dir
168 bool
169 ureport_server_response_save_in_dump_dir(struct ureport_server_response *resp,
170  const char *dump_dir_path,
171  struct ureport_server_config *config);
172 
173 /*
174  * Build URL to submitted uReport
175  *
176  * @param resp Parsed server response
177  * @param config Configuration used in communication
178  * @return Malloced zero-terminated string
179  */
180 #define ureport_server_response_get_report_url libreport_ureport_server_response_get_report_url
181 char *
182 ureport_server_response_get_report_url(struct ureport_server_response *resp,
183  struct ureport_server_config *config);
184 
185 /*
186  * Release allocated resources
187  *
188  * @param resp Released structured
189  */
190 #define ureport_server_response_free libreport_ureport_server_response_free
191 void
192 ureport_server_response_free(struct ureport_server_response *resp);
193 
194 /*
195  * Send JSON to server and obtain reply
196  *
197  * @param json Sent data
198  * @param config Configuration used in communication
199  * @param url_sfx Local part of the upload URL
200  * @return Malloced server reply or NULL in case of communication errors
201  */
202 #define ureport_do_post libreport_ureport_do_post
203 struct post_state *
204 ureport_do_post(const char *json, struct ureport_server_config *config,
205  const char *url_sfx);
206 
207 /*
208  * Submit uReport on server
209  *
210  * @param json Sent data
211  * @param config Configuration used in communication
212  * @return Malloced, parsed server response
213  */
214 #define ureport_submit libreport_ureport_submit
216 ureport_submit(const char *json_ureport, struct ureport_server_config *config);
217 
218 /*
219  * Build a new uReport attachement from give arguments
220  *
221  * @param bthash ID of uReport
222  * @param type Type of attachement recognized by uReport Server
223  * @param data Attached data
224  * @returm Malloced JSON string
225  */
226 char *
227 ureport_json_attachment_new(const char *bthash, const char *type, const char *data);
228 
229 /*
230  * Attach given string to uReport
231  *
232  * @param bthash uReport identifier
233  * @param type Type of attachment
234  * @param data Attached data
235  * @param config Configuration used in communication
236  * @return True in case of any error; otherwise False
237  */
238 #define ureport_attach_string libreport_ureport_attach_string
239 bool
240 ureport_attach_string(const char *bthash, const char *type, const char *data,
241  struct ureport_server_config *config);
242 
243 /*
244  * Attach given integer to uReport
245  *
246  * @param bthash uReport identifier
247  * @param type Type of attachment
248  * @param data Attached data
249  * @param config Configuration used in communication
250  * @return True in case of any error; otherwise False
251  */
252 #define ureport_attach_int libreport_ureport_attach_int
253 bool
254 ureport_attach_int(const char *bthash, const char *type, int data,
255  struct ureport_server_config *config);
256 
257 /*
258  * Build uReport from dump dir
259  *
260  * @param dump_dir_path FS path to dump dir
261  * @return Malloced JSON string
262  */
263 #define ureport_from_dump_dir libreport_ureport_from_dump_dir
264 char *
265 ureport_from_dump_dir(const char *dump_dir_path);
266 
267 #define ureport_from_dump_dir_ext libreport_ureport_from_dump_dir_ext
268 char *ureport_from_dump_dir_ext(const char *dump_dir_path,
269  const struct ureport_preferences *preferences);
270 
271 #ifdef __cplusplus
272 }
273 #endif
274 
275 #endif
char * urr_bthash
uReport's server side identifier
Definition: ureport.h:136
map_string_t * ur_http_headers
Additional HTTP headers.
Definition: ureport.h:57
struct ureport_preferences ur_prefs
configuration for uReport generation
Definition: ureport.h:59
GList * urp_auth_items
list of file names included in 'auth' key
Definition: ureport.h:42
char * ur_password
password for basic HTTP auth
Definition: ureport.h:56
char * ur_url
Web service URL.
Definition: ureport.h:50
bool urr_is_error
True if server replied with error response.
Definition: ureport.h:133
GList * urr_reported_to_list
Definition: ureport.h:137
char * urr_value
Value of the response.
Definition: ureport.h:134
char * urr_message
Additional message.
Definition: ureport.h:135
char * ur_client_key
Private key for the certificate.
Definition: ureport.h:54
bool ur_ssl_verify
Verify HOST and PEER certificates.
Definition: ureport.h:51
char * urr_solution
URL pointing to solution for uReport.
Definition: ureport.h:139
char * ur_username
username for basic HTTP auth
Definition: ureport.h:55
char * ur_client_cert
Definition: ureport.h:52