libreport  2.12.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  * 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 #define ureport_server_config_init libreport_ureport_server_config_init
77 void
78 ureport_server_config_init(struct ureport_server_config *config);
79 
80 /*
81  * Release all allocated resources
82  *
83  * @param config Released structure
84  */
85 #define ureport_server_config_destroy libreport_ureport_server_config_destroy
86 void
87 ureport_server_config_destroy(struct ureport_server_config *config);
88 
89 /*
90  * Loads uReport configuration from various sources.
91  *
92  * Replaces a value of an already configured option only if the
93  * option was found in a configuration source.
94  *
95  * @param config a server configuration to be populated
96  */
97 #define ureport_server_config_load libreport_ureport_server_config_load
98 void
99 ureport_server_config_load(struct ureport_server_config *config,
100  map_string_t *settings);
101 
102 /*
103  * Configure HTTP(S) URL to server's index page
104  *
105  * @param config Where the url is stored
106  * @param server_url Index URL
107  */
108 #define ureport_server_config_set_url libreport_ureport_server_config_set_url
109 void
110 ureport_server_config_set_url(struct ureport_server_config *config,
111  char *server_url);
112 
113 /*
114  * Configure client certificate paths
115  *
116  * @param config Where the paths are stored
117  * @param client_path Path in form of cert_full_path:key_full_path or one of
118  * the following string: 'rhsm', '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  * "rhts-credentials" - Uses Login= and Password= from rhtsupport.conf
142  * "<user_name>:<password>" - Manually supply user name and password.
143  * "<user_name>" - Manually supply user name and be asked for password.
144  *
145  * The function uses ask_password() function from client.h
146  *
147  * @param config Configured structure
148  * @param http_auth_pref User HTTP Authentication preferences
149  */
150 void
151 ureport_server_config_load_basic_auth(struct ureport_server_config *config,
152  const char *http_auth_pref);
153 
154 /*
155  * uReport server response
156  */
158 {
160  char *urr_value;
161  char *urr_message;
162  char *urr_bthash;
164  char *urr_solution;
166 };
167 
168 /* Can't include "abrt_curl.h", it's not a public API.
169  * Resorting to just forward-declaring the struct we need.
170  */
171 struct post_state;
172 
173 /*
174  * Parse server reply
175  *
176  * @param post_state Server reply
177  * @param config Configuration used in communication
178  * @return Pointer to malloced memory or NULL in case of error in communication
179  */
180 #define ureport_server_response_from_reply libreport_ureport_server_response_from_reply
182 ureport_server_response_from_reply(struct post_state *post_state,
183  struct ureport_server_config *config);
184 
185 /*
186  * Save response in dump dir files
187  *
188  * @param resp Parsed server response
189  * @param dump_dir_pat Path to dump directory
190  * @param config Configuration used in communication
191  * @return False in case of any error; otherwise True.
192  */
193 #define ureport_server_response_save_in_dump_dir libreport_ureport_server_response_save_in_dump_dir
194 bool
195 ureport_server_response_save_in_dump_dir(struct ureport_server_response *resp,
196  const char *dump_dir_path,
197  struct ureport_server_config *config);
198 
199 /*
200  * Build URL to submitted uReport
201  *
202  * @param resp Parsed server response
203  * @param config Configuration used in communication
204  * @return Malloced zero-terminated string
205  */
206 #define ureport_server_response_get_report_url libreport_ureport_server_response_get_report_url
207 char *
208 ureport_server_response_get_report_url(struct ureport_server_response *resp,
209  struct ureport_server_config *config);
210 
211 /*
212  * Release allocated resources
213  *
214  * @param resp Released structured
215  */
216 #define ureport_server_response_free libreport_ureport_server_response_free
217 void
218 ureport_server_response_free(struct ureport_server_response *resp);
219 
220 /*
221  * Send JSON to server and obtain reply
222  *
223  * @param json Sent data
224  * @param config Configuration used in communication
225  * @param url_sfx Local part of the upload URL
226  * @return Malloced server reply or NULL in case of communication errors
227  */
228 #define ureport_do_post libreport_ureport_do_post
229 struct post_state *
230 ureport_do_post(const char *json, struct ureport_server_config *config,
231  const char *url_sfx);
232 
233 /*
234  * Submit uReport on server
235  *
236  * @param json Sent data
237  * @param config Configuration used in communication
238  * @return Malloced, parsed server response
239  */
240 #define ureport_submit libreport_ureport_submit
242 ureport_submit(const char *json_ureport, struct ureport_server_config *config);
243 
244 /*
245  * Build a new uReport attachement from give arguments
246  *
247  * @param bthash ID of uReport
248  * @param type Type of attachement recognized by uReport Server
249  * @param data Attached data
250  * @returm Malloced JSON string
251  */
252 char *
253 ureport_json_attachment_new(const char *bthash, const char *type, const char *data);
254 
255 /*
256  * Attach given string to uReport
257  *
258  * @param config Configuration used in communication
259  * @param bthash uReport identifier
260  * @param type Type of attachment
261  * @param data Attached data
262  * @return True in case of any error; otherwise False
263  */
264 bool
265 ureport_attach_string(struct ureport_server_config *config,
266  const char *bthash,
267  const char *type,
268  const char *data);
269 
270 /*
271  * Attach formatted data to uReport
272  *
273  * @param config Configuration used in communication
274  * @param bthash uReport identifier
275  * @param type Type of attachment
276  * @param format Data format string
277  * @param ... Values to replace format specifiers
278  * @return True in case of any error; otherwise False
279  */
280 bool
281 ureport_attach(struct ureport_server_config *config,
282  const char *bthash,
283  const char *type,
284  const char *format,
285  ...) G_GNUC_PRINTF(4, 5);
286 
287 /*
288  * Build uReport from dump dir
289  *
290  * @param dump_dir_path FS path to dump dir
291  * @return Malloced JSON string
292  */
293 #define ureport_from_dump_dir libreport_ureport_from_dump_dir
294 char *
295 ureport_from_dump_dir(const char *dump_dir_path);
296 
297 #define ureport_from_dump_dir_ext libreport_ureport_from_dump_dir_ext
298 char *ureport_from_dump_dir_ext(const char *dump_dir_path,
299  const struct ureport_preferences *preferences);
300 
301 #ifdef __cplusplus
302 }
303 #endif
304 
305 #endif
char * urr_bthash
uReport's server side identifier
Definition: ureport.h:162
struct ureport_preferences ur_prefs
configuration for uReport generation
Definition: ureport.h:68
GList * urp_auth_items
list of file names included in 'auth' 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:159
GList * urr_reported_to_list
Definition: ureport.h:163
char * urr_value
Value of the response.
Definition: ureport.h:160
int urp_flags
See enum ureport_preferences_flags.
Definition: ureport.h:51
char * urr_message
Additional message.
Definition: ureport.h:161
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:165
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