libreport  2.9.4
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 one of
119  * the following string: 'rhsm', 'puppet'.
120  */
121 #define ureport_server_config_set_client_auth libreport_ureport_server_config_set_client_auth
122 void
123 ureport_server_config_set_client_auth(struct ureport_server_config *config,
124  const char *client_auth);
125 
126 /*
127  * Configure user name and password for HTTP Basic authentication
128  *
129  * @param config Configured structure
130  * @param username User name
131  * @param password Password
132  */
133 #define ureport_server_config_set_basic_auth libreport_ureport_server_config_set_basic_auth
134 void
135 ureport_server_config_set_basic_auth(struct ureport_server_config *config,
136  const char *username, const char *password);
137 
138 /*
139  * Configure user name and password for HTTP Basic authentication according to
140  * user preferences.
141  *
142  * "rhts-credentials" - Uses Login= and Password= from rhtsupport.conf
143  * "<user_name>:<password>" - Manually supply user name and password.
144  * "<user_name>" - Manually supply user name and be asked for password.
145  *
146  * The function uses ask_password() function from client.h
147  *
148  * @param config Configured structure
149  * @param http_auth_pref User HTTP Authentication preferences
150  */
151 void
152 ureport_server_config_load_basic_auth(struct ureport_server_config *config,
153  const char *http_auth_pref);
154 
155 /*
156  * uReport server response
157  */
159 {
161  char *urr_value;
162  char *urr_message;
163  char *urr_bthash;
165  char *urr_solution;
167 };
168 
169 /* Can't include "abrt_curl.h", it's not a public API.
170  * Resorting to just forward-declaring the struct we need.
171  */
172 struct post_state;
173 
174 /*
175  * Parse server reply
176  *
177  * @param post_state Server reply
178  * @param config Configuration used in communication
179  * @return Pointer to malloced memory or NULL in case of error in communication
180  */
181 #define ureport_server_response_from_reply libreport_ureport_server_response_from_reply
183 ureport_server_response_from_reply(struct post_state *post_state,
184  struct ureport_server_config *config);
185 
186 /*
187  * Save response in dump dir files
188  *
189  * @param resp Parsed server response
190  * @param dump_dir_pat Path to dump directory
191  * @param config Configuration used in communication
192  * @return False in case of any error; otherwise True.
193  */
194 #define ureport_server_response_save_in_dump_dir libreport_ureport_server_response_save_in_dump_dir
195 bool
196 ureport_server_response_save_in_dump_dir(struct ureport_server_response *resp,
197  const char *dump_dir_path,
198  struct ureport_server_config *config);
199 
200 /*
201  * Build URL to submitted uReport
202  *
203  * @param resp Parsed server response
204  * @param config Configuration used in communication
205  * @return Malloced zero-terminated string
206  */
207 #define ureport_server_response_get_report_url libreport_ureport_server_response_get_report_url
208 char *
209 ureport_server_response_get_report_url(struct ureport_server_response *resp,
210  struct ureport_server_config *config);
211 
212 /*
213  * Release allocated resources
214  *
215  * @param resp Released structured
216  */
217 #define ureport_server_response_free libreport_ureport_server_response_free
218 void
219 ureport_server_response_free(struct ureport_server_response *resp);
220 
221 /*
222  * Send JSON to server and obtain reply
223  *
224  * @param json Sent data
225  * @param config Configuration used in communication
226  * @param url_sfx Local part of the upload URL
227  * @return Malloced server reply or NULL in case of communication errors
228  */
229 #define ureport_do_post libreport_ureport_do_post
230 struct post_state *
231 ureport_do_post(const char *json, struct ureport_server_config *config,
232  const char *url_sfx);
233 
234 /*
235  * Submit uReport on server
236  *
237  * @param json Sent data
238  * @param config Configuration used in communication
239  * @return Malloced, parsed server response
240  */
241 #define ureport_submit libreport_ureport_submit
243 ureport_submit(const char *json_ureport, struct ureport_server_config *config);
244 
245 /*
246  * Build a new uReport attachement from give arguments
247  *
248  * @param bthash ID of uReport
249  * @param type Type of attachement recognized by uReport Server
250  * @param data Attached data
251  * @returm Malloced JSON string
252  */
253 char *
254 ureport_json_attachment_new(const char *bthash, const char *type, const char *data);
255 
256 /*
257  * Attach given string to uReport
258  *
259  * @param bthash uReport identifier
260  * @param type Type of attachment
261  * @param data Attached data
262  * @param config Configuration used in communication
263  * @return True in case of any error; otherwise False
264  */
265 #define ureport_attach_string libreport_ureport_attach_string
266 bool
267 ureport_attach_string(const char *bthash, const char *type, const char *data,
268  struct ureport_server_config *config);
269 
270 /*
271  * Attach given integer to uReport
272  *
273  * @param bthash uReport identifier
274  * @param type Type of attachment
275  * @param data Attached data
276  * @param config Configuration used in communication
277  * @return True in case of any error; otherwise False
278  */
279 #define ureport_attach_int libreport_ureport_attach_int
280 bool
281 ureport_attach_int(const char *bthash, const char *type, int data,
282  struct ureport_server_config *config);
283 
284 /*
285  * Build uReport from dump dir
286  *
287  * @param dump_dir_path FS path to dump dir
288  * @return Malloced JSON string
289  */
290 #define ureport_from_dump_dir libreport_ureport_from_dump_dir
291 char *
292 ureport_from_dump_dir(const char *dump_dir_path);
293 
294 #define ureport_from_dump_dir_ext libreport_ureport_from_dump_dir_ext
295 char *ureport_from_dump_dir_ext(const char *dump_dir_path,
296  const struct ureport_preferences *preferences);
297 
298 #ifdef __cplusplus
299 }
300 #endif
301 
302 #endif
char * urr_bthash
uReport&#39;s server side identifier
Definition: ureport.h:163
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:160
GList * urr_reported_to_list
Definition: ureport.h:164
char * urr_value
Value of the response.
Definition: ureport.h:161
int urp_flags
See enum ureport_preferences_flags.
Definition: ureport.h:51
char * urr_message
Additional message.
Definition: ureport.h:162
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:166
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