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