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