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