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