aboutsummaryrefslogtreecommitdiffstats
path: root/compat/include/cynara/cynara-monitor.h
blob: ce7b8d066d8329708eab114ac846800b0632a346 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/*
 *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License
 */
/**
 * @file        src/include/cynara-monitor.h
 * @author      Aleksander Zdyb <a.zdyb@samsung.com>
 * @version     1.0
 * @brief       This file contains client APIs of Cynara monitoring.
 */

#ifndef CYNARA_MONITOR_H
#define CYNARA_MONITOR_H

#include <stddef.h>
#include <time.h>

#include <cynara/cynara-error.h>
#include <cynara/cynara-limits.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct cynara_monitor_configuration cynara_monitor_configuration;
typedef struct cynara_monitor cynara_monitor;
typedef struct cynara_monitor_entry cynara_monitor_entry;

/**
 * \par Description:
 * Initializes cynara_monitor_configuration. Creates structure used in following configuration
 * API calls.
 *
 * \par Purpose:
 * For configuration parameter to be used in cynara_monitor_initialize() function, this API must be
 * called before any other Cynara monitor configuration API function.
 * It will create cynara_monitor_configuration structure, an optional parameter
 * of Cynara monitor initialization.
 *
 * \par Typical use case:
 * Once before setting parameters of Cynara monitor configuration and passing to
 * cynara_monitor_initialize().
 *
 * \par Method of function operation:
 * This API initializes inner library structures and in case of success returns pointer
 * to created cynara_monitor_configuration structure.
 *
 * \par Sync (or) Async:
 * This is a synchronous API.
 *
 * \par Thread-safety:
 * \parblock
 * This function is NOT thread-safe. If this function is called simultaneously with other functions
 * from described API in different threads, they must be put into protected critical section.
 *
 * \par Important notes:
 * Structure cynara_monitor_configuration created by cynara_monitor_configuration_create() call
 * should be released with cynara_monitor_configuration_destroy().
 * Structure cynara_monitor_configuration should be destroyed after passing it to
 * cynara_monitor_initialize().
 * \endparblock
 *
 * \param[out] pp_conf Placeholder for created cynara_monitor_configuration structure.
 *
 * \return CYNARA_API_SUCCESS on success
 *         or negative error code on error.
 */
int cynara_monitor_configuration_create(cynara_monitor_configuration **pp_conf);

/**
 * \par Description:
 * Releases cynara_monitor_configuration structure created
 * with cynara_monitor_configuration_create().
 *
 * \par Purpose:
 * This API should be used to clean up after usage of cynara_monitor_configuration.
 *
 * \par Typical use case:
 * Once cynara_monitor_configuration is not needed.
 *
 * \par Method of function operation:
 * This API releases inner library structure and destroys cynara_monitor_configuration structure.
 *
 * \par Sync (or) Async:
 * This is a synchronous API.
 *
 * \par Thread-safety:
 * This function is NOT thread-safe. If this function is called simultaneously with other functions
 * from described API in different threads, they must be put into protected critical section.
 *
 * \param[in] p_conf cynara_monitor_configuration structure. If NULL, the call has no effect.
 */
void cynara_monitor_configuration_destroy(cynara_monitor_configuration *p_conf);

/**
 * \par Description:
 * Set monitor entries buffer size.
 *
 * \par Purpose:
 * This API is used to change default number of monitor entries stored on server side
 * before returning them to client of libcynara-monitor. Buffer size cannot exceed value
 * of CYNARA_MAX_MONITOR_BUFFER_SIZE, otherwise CYNARA_API_INPUT_PARAM will be returned.
 *
 * \par Typical use case:
 * Once after cynara_configuration is created with cynara_monitor_configuration_create()
 * and before passing configuration to cynara_monitor_configuration().
 *
 * \par Method of function operation:
 * This API initializes buffer with given capacity.
 *
 * \par Sync (or) Async:
 * This is a synchronous API.
 *
 * \par Thread-safety:
 * This function is NOT thread-safe. If this function is called simultaneously with other functions
 * from described API in different threads, they must be put into protected critical section.
 *
 * \par Important notes:
 * After passing cynara_configuration to cynara_monitor_initialize() calling this API will have
 * no effect.
 *
 * If buffer size is not set with cynara_monitor_configuration_set_buffer_size(),
 * a default size will be taken.
 * \endparblock
 *
 * \param[in] p_conf cynara_monitor_configuration structure pointer.
 * \param[in] buffer_size buffer size to be set.
 *
 * \return CYNARA_API_SUCCESS on success
 *        or negative error code on error.
 */
int cynara_monitor_configuration_set_buffer_size(cynara_monitor_configuration *p_conf,
                                                 size_t buffer_size);

/**
 * \par Description:
 * Initializes cynara-monitor library with given configuration.
 * Creates structure used in following API calls.
 *
 * \par Purpose:
 * This API must be used by prior calling cynara_monitor_entries_get() function.
 *
 * \par Typical use case:
 * Once before a service can call cynara_monitor_entries_get().
 *
 * \par Method of function operation:
 * This API initializes inner library structures and in case of success
 * creates cynara_monitor structure.
 *
 * \par Sync (or) Async:
 * This is a Synchronous API.
 *
 * \par Thread-safeness:
 * This function is NOT thread-safe. If this function is called simultaneously with other functions
 * from described API in different threads, they must be put into protected critical section.
 *
 * \par Important notes:
 * Structure cynara_monitor created by cynara_monitor_initialize() call should be released
 * with cynara_monitor_finish().
 *
 * \param[out] pp_cynara_monitor Placeholder for created cynara_monitor structure.
 * \param[in] p_conf Configuration for cynara-monitor library. NULL for default parameters.
 *
 * \return CYNARA_API_SUCCESS on success, or error code on error.
 */
int cynara_monitor_initialize(cynara_monitor **pp_cynara_monitor,
                              const cynara_monitor_configuration *p_conf);

/**
 * \par Description:
 * Releases cynara-monitor library and destroys structure created with cynara_monitor_initialize().
 *
 * \par Purpose:
 * This API should be used to clean up after the usage of cynara-monitor library.
 *
 * \par Typical use case:
 * Once after last call to cynara_monitor_entries_get().
 *
 * \par Method of function operation:
 * This API releases inner library structures and destroys cynara_monitor structure.
 *
 * \par Sync (or) Async:
 * This is a Synchronous API.
 *
 * \par Thread-safeness:
 * This function is NOT thread-safe. If this function is called simultaneously with other functions
 * from described API in different threads, they must be put into protected critical section.
 *
 * \par Important notes:
 * No other call to libcynara-monitor should be made after call to cynara_monitor_finish().
 * This function cannot be called, if cynara_monitor_entries_get() haven't returned yet.
 *
 * \param[in] p_cynara_monitor Cynara monitor structure.
 *
 * \return CYNARA_API_SUCCESS on success, or error code on error.
 */
int cynara_monitor_finish(cynara_monitor *p_cynara_monitor);

/**
 * \brief Returns monitor entries.
 *
 * \par Description:
 *
 * Returns all available monitor entries right after the size of buffer reaches set limit.
 *
 * \par Purpose:
 * This API should be used to get available monitor entries.
 *
 * \par Typical use case:
 * Gathering information about possible accesses checked in Cynara by individual services.
 *
 * \par Method of function operation:
 * \parblock
 * Each call to cynara_check() made by individual services are logged. The logs can be obtained
 * by privileged clients with usage of libcynara-monitor (this API).
 *
 * In case of successful call CYNARA_API_SUCCESS is returned and *monitor_entries points
 * to newly created array of pointers to cynara_monitor_entry. It is responsibility
 * of the caller to release entries with cynara_monitor_entries_free().
 *
 * The function blocks until the size of buffer reaches set limit or cynara_monitor_entries_flush()
 * is called from another thread.
 * \endparblock
 *
 * \par Sync (or) Async:
 * This is a synchronous API.
 *
 * \par Thread-safeness:
 * This function is thread-safe.
 *
 * \par Important notes:
 * Although this function is thread-safe, no multiple calls are allowed.
 *
 * \param[in] p_cynara_monitor cynara_monitor structure.
 * \param[out] monitor_entries placeholder for NULL terminated array of pointers to
 *             monitor_entries structures.
 *
 * \return CYNARA_API_SUCCESS on success, or error code otherwise.
 */
int cynara_monitor_entries_get(cynara_monitor *p_cynara_monitor,
                               cynara_monitor_entry ***monitor_entries);

/**
 * \brief Makes cynara_monitor_entries_get() return immediately.
 *
 * \par Description:
 *
 * When called from another thread, makes cynara_monitor_entries_get() return immediately.
 *
 * \par Purpose:
 * This API should be used to make cynara_monitor_entries_get() return immediately.
 *
 * \par Typical use case:
 * User of libcynara-monitor wants to immediately get get monitor entries and/or make
 * cynara_monitor_entries_get() return without waiting for full batch of entries.
 *
 * \par Sync (or) Async:
 * This is a synchronous API.
 *
 * \par Thread-safeness:
 * This function is thread-safe.
 *
 * \param[in] p_cynara_monitor cynara_monitor structure.
 *
 * \return CYNARA_API_SUCCESS on success, or error code otherwise.
 */
int cynara_monitor_entries_flush(cynara_monitor *p_cynara_monitor);

/**
 * \brief Releases monitor entries.
 *
 * \par Description:
 *
 * Releases monitor entries obtained with cynara_monitor_entries_get().
 *
 * \par Purpose:
 * This API should be used to release array of cynara_monitor_entry obtained
 * with cynara_monitor_entries_get.
 *
 * \par Typical use case:
 * When user obtained all needed data from the entries and won't be accessing the
 * memory any more.
 *
 * \par Sync (or) Async:
 * This is a synchronous API.
 *
 * \par Thread-safeness:
 * This function is thread-safe.
 *
 * \param[in] monitor_entries NULL terminated array of cynara_monitor_entry to be released.
 */
void cynara_monitor_entries_free(cynara_monitor_entry **monitor_entries);

/**
 * \brief Gets client from monitor_entry
 *
 * \par Description:
 * Gives access to client field of monitor_entry given as a parameter.
 * Please refer to cynara_check() in cynara-client.h for more information on client field.
 *
 * \par Sync (or) Async:
 * This is a synchronous API.
 *
 * \par Thread-safeness:
 * This function is thread-safe.
 *
 * \par Important notes:
 * The returned pointer is valid as long as given monitor_entry is.
 *
 * \param[in] monitor_entry cynara_monitor_entry to be accessed.
 *
 * \return valid const char * pointer or NULL in case of error.
 */
const char *cynara_monitor_entry_get_client(const cynara_monitor_entry *monitor_entry);

/**
 * \brief Gets user from monitor_entry
 *
 * \par Description:
 * Gives access to user field of monitor_entry given as a parameter.
 * Please refer to cynara_check() in cynara-client.h for more information on user field.
 *
 * \par Sync (or) Async:
 * This is a synchronous API.
 *
 * \par Thread-safeness:
 * This function is thread-safe.
 *
 * \par Important notes:
 * The returned pointer is valid as long as given monitor_entry is.
 *
 * \param[in] monitor_entry cynara_monitor_entry to be accessed.
 *
 * \return valid const char * pointer or NULL in case of error.
 */
const char *cynara_monitor_entry_get_user(const cynara_monitor_entry *monitor_entry);

/**
 * \brief Gets privilege from monitor_entry
 *
 * \par Description:
 * Gives access to privilege field of monitor_entry given as a parameter.
 * Please refer to cynara_check() in cynara-client.h for more information on privilege field.
 *
 * \par Sync (or) Async:
 * This is a synchronous API.
 *
 * \par Thread-safeness:
 * This function is thread-safe.
 *
 * \par Important notes:
 * The returned pointer is valid as long as given monitor_entry is.
 *
 * \param[in] monitor_entry cynara_monitor_entry to be accessed.
 *
 * \return valid const char * pointer or NULL in case of error.
 */
const char *cynara_monitor_entry_get_privilege(const cynara_monitor_entry *monitor_entry);

/**
 * \brief Gets result from monitor_entry
 *
 * \par Description:
 * Gives access to result field of monitor_entry given as a parameter.
 * In case of successful get, the result is one of CYNARA_API_ACCESS_ALLOWED
 * or CYNARA_API_ACCESS_DENIED. In case of error a negative code error is returned.
 * Please refer to cynara-error.h for more information.
 *
 * \par Sync (or) Async:
 * This is a synchronous API.
 *
 * \par Thread-safeness:
 * This function is thread-safe.
 *
 * \param[in] monitor_entry cynara_monitor_entry to be accessed.
 *
 * \return CYNARA_API_ACCESS_ALLOWED on access allowed, CYNARA_API_ACCESS_DENIED on access denial
 * or other error code on error.
 */
int cynara_monitor_entry_get_result(const cynara_monitor_entry *monitor_entry);

/**
 * \brief Gets timestamp from monitor_entry
 *
 * \par Description:
 * Gives access to timestamp field of monitor_entry given as a parameter.
 * This is the time of cynara_check() being invoked. Please refer to cynara-client.h
 * for more information about cynara_check().
 *
 * \par Sync (or) Async:
 * This is a synchronous API.
 *
 * \par Thread-safeness:
 * This function is thread-safe.
 *
 * \par Important notes:
 * The returned pointer is valid as long as given monitor_entry is.
 *
 * \param[in] monitor_entry cynara_monitor_entry to be accessed.
 *
 * \return valid const istruct timspec * pointer or NULL in case of error.
 */
const struct timespec *cynara_monitor_entry_get_timestamp(
        const cynara_monitor_entry *monitor_entry);

#ifdef __cplusplus
}
#endif

#endif /* CYNARA_MONITOR_H */