55 * \date 2020
66 */
77
8- /*
8+ /*
99 * Copyright (C) 2020 CESNET, z.s.p.o.
1010 *
1111 * Redistribution and use in source and binary forms, with or without
@@ -51,13 +51,13 @@ extern "C" {
5151
5252#include <stdbool.h>
5353#include <stdint.h>
54- #include <stdlib.h>
54+ #include <stdlib.h>
5555
5656typedef struct fds_filter_error {
5757 /** The error code */
5858 int code ;
5959 /** The error message */
60- const char * msg ;
60+ char * msg ;
6161
6262 /** Location of the error, both can be NULL depending on the type of error */
6363 /** Pointer to the beginning of the error location in the input expression */
@@ -86,15 +86,15 @@ typedef enum fds_filter_datatype {
8686
8787 FDS_FDT_FLAGS ,
8888
89- FDS_FDT_CUSTOM = 1 << 29 , /**< Bit that indicates that the data type is custom */
89+ FDS_FDT_CUSTOM = 1 << 29 , /**< Bit that indicates that the data type is custom */
9090 FDS_FDT_LIST = 1 << 30 , /**< Bit that indicates that the data type is a list */
9191} fds_filter_datatype_e ;
9292
9393typedef union fds_filter_value fds_filter_value_u ; /**< Forward declaration because of list */
9494
9595/** The IP address type */
9696typedef struct fds_filter_ip {
97- /** The IP address version, 4 or 6 */
97+ /** The IP address version, 4 or 6 */
9898 uint8_t version ;
9999 /** The prefix length of the address */
100100 uint8_t prefix ;
@@ -161,25 +161,25 @@ typedef struct fds_filter_opts fds_filter_opts_t;
161161 *
162162 * \param[in] user_ctx The user context set by fds_filter_set_user_ctx
163163 * \param[in] name The name of the identifier
164- * \param[in] other_name The name of the first identifier on the other side if any
164+ * \param[in] other_name The name of the first identifier on the other side if any
165165 * \param[out] out_id The id of the identifier that will be passed to the const/data callbacks.
166166 * \param[out] out_datatype The data type of the identifier
167- * \param[out] out_flags The identifier flags. If set to FDS_FILTER_CONST_FLAG the identifier
167+ * \param[out] out_flags The identifier flags. If set to FDS_FILTER_CONST_FLAG the identifier
168168 * will be considered constant and the const callback will be used.
169169 *
170- * \return FDS_OK on success,
170+ * \return FDS_OK on success,
171171 * FDS_NOTFOUND if the identifier name is not recognized, which results in a filter error
172172 */
173173typedef int fds_filter_lookup_cb_t (
174174 void * user_ctx , const char * name , const char * other_name , int * out_id , int * out_datatype , int * out_flags );
175175
176176/**
177- * Get the value of a constant.
178- * An identifier is a constant if the FDS_FILTER_CONST_FLAG was set in the lookup callback.
177+ * Get the value of a constant.
178+ * An identifier is a constant if the FDS_FILTER_CONST_FLAG was set in the lookup callback.
179179 *
180180 * \param[in] user_ctx The user context set by fds_filter_set_user_ctx
181- * \param[in] id The id provided by the user in the lookup callback
182- * \param[out] out_value The value of the constant
181+ * \param[in] id The id provided by the user in the lookup callback
182+ * \param[out] out_value The value of the constant
183183 *
184184 */
185185typedef void fds_filter_const_cb_t (void * user_ctx , int id , fds_filter_value_u * out_value );
@@ -214,6 +214,9 @@ enum fds_filter_fds_filter_ast_flags_e {
214214
215215typedef struct fds_filter_ast_node {
216216 const char * symbol ;
217+
218+ #pragma GCC diagnostic ignored "-Wpedantic"
219+ // Anonymous unions and structs are not ISO C++ compliant
217220 union {
218221 struct {
219222 struct fds_filter_ast_node * left ;
@@ -225,6 +228,7 @@ typedef struct fds_filter_ast_node {
225228 struct fds_filter_ast_node * next ;
226229 };
227230 };
231+ #pragma GCC diagnostic pop
228232
229233 struct fds_filter_ast_node * parent ;
230234
@@ -239,7 +243,7 @@ typedef struct fds_filter_ast_node {
239243 // the position of the node in the input text, for error message purposes
240244 const char * cursor_begin ;
241245 const char * cursor_end ;
242-
246+
243247} fds_filter_ast_node_s ;
244248
245249////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -250,42 +254,42 @@ typedef struct fds_filter_ast_node {
250254
251255/**
252256 * Binary operation function type
253- *
257+ *
254258 * \param[in] arg1 The first (left) arg
255259 * \param[in] arg2 The second (right) arg
256260 * \param[out] result The output value
257- */
261+ */
258262typedef void fds_filter_binary_fn_t (fds_filter_value_u * arg1 , fds_filter_value_u * arg2 , fds_filter_value_u * result );
259263
260264/**
261265 * Unary operation function type
262- *
266+ *
263267 * \param[in] arg1 The first (left) arg
264268 * \param[out] result The output value
265- */
269+ */
266270typedef void fds_filter_unary_fn_t (fds_filter_value_u * arg , fds_filter_value_u * result );
267271
268272/**
269273 * Cast function type
270- *
274+ *
271275 * \param[in] arg The input value
272276 * \param[out] result The output value
273- */
277+ */
274278typedef void fds_filter_cast_fn_t (fds_filter_value_u * arg , fds_filter_value_u * result );
275279
276280/**
277281 * Constructor function type
278- *
282+ *
279283 * \param[in] arg The input value
280284 * \param[out] result The output value
281- *
285+ *
282286 * \return FDS_OK on success, error code on failure
283287 */
284288typedef int fds_filter_constructor_fn_t (fds_filter_value_u * arg , fds_filter_value_u * result );
285289
286290/**
287291 * Destructor function type
288- *
292+ *
289293 * \param[in] arg The value to destruct
290294 */
291295typedef void fds_filter_destructor_fn_t (fds_filter_value_u * arg );
@@ -295,13 +299,17 @@ typedef struct fds_filter_op {
295299 int out_dt ;
296300 int arg1_dt ;
297301 int arg2_dt ;
302+
303+ #pragma GCC diagnostic ignored "-Wpedantic"
304+ // Anonymous unions and structs are not ISO C++ compliant
298305 union {
299306 fds_filter_unary_fn_t * unary_fn ;
300307 fds_filter_binary_fn_t * binary_fn ;
301308 fds_filter_cast_fn_t * cast_fn ;
302309 fds_filter_constructor_fn_t * constructor_fn ;
303310 fds_filter_destructor_fn_t * destructor_fn ;
304311 };
312+ #pragma GCC diagnostic pop
305313} fds_filter_op_s ;
306314
307315
@@ -312,15 +320,15 @@ typedef struct fds_filter_op {
312320 .arg2_dt = (RIGHT_DT), \
313321 .out_dt = (OUT_DT), \
314322 .binary_fn = (FUNC) \
315- }
323+ }
316324#define FDS_FILTER_DEF_UNARY_OP (SYMBOL , OPERAND_DT , FUNC , OUT_DT ) \
317325 { \
318326 .symbol = (SYMBOL), \
319327 .arg1_dt = (OPERAND_DT), \
320328 .arg2_dt = FDS_FDT_NONE, \
321329 .out_dt = (OUT_DT), \
322330 .unary_fn = (FUNC) \
323- }
331+ }
324332#define FDS_FILTER_DEF_CAST (FROM_DT , FUNC , TO_DT ) \
325333 { \
326334 .symbol = "__cast__", \
@@ -355,16 +363,16 @@ typedef struct fds_filter_op {
355363
356364/**
357365 * Creates the default options structure.
358- * Because one options can be used by multiple filters, it has to be freed separately from the filter.
359- *
366+ * Because one options can be used by multiple filters, it has to be freed separately from the filter.
367+ *
360368 * \return the options or NULL on memory error
361369 */
362370FDS_API fds_filter_opts_t *
363371fds_filter_create_default_opts ();
364372
365373/**
366374 * Sets the lookup callback
367- *
375+ *
368376 * \param[inout] opts The options structure
369377 * \param[in] cb The callback
370378 */
@@ -373,7 +381,7 @@ fds_filter_opts_set_lookup_cb(fds_filter_opts_t *opts, fds_filter_lookup_cb_t *c
373381
374382/**
375383 * Sets the const callback
376- *
384+ *
377385 * \param[inout] opts The options structure
378386 * \param[in] cb The callback
379387 */
@@ -382,7 +390,7 @@ fds_filter_opts_set_const_cb(fds_filter_opts_t *opts, fds_filter_const_cb_t *cb)
382390
383391/**
384392 * Sets the data callback
385- *
393+ *
386394 * \param[in] opts The options structure
387395 * \param[in] cb The callback
388396 */
@@ -391,37 +399,37 @@ fds_filter_opts_set_data_cb(fds_filter_opts_t *opts, fds_filter_data_cb_t *cb);
391399
392400/**
393401 * Adds a filter operation
394- *
402+ *
395403 * \param[in] opts The options structure
396404 * \param[in] op The operation
397- *
405+ *
398406 * \return pointer to the new op on success, NULL on failure
399- */
407+ */
400408FDS_API fds_filter_op_s *
401409fds_filter_opts_add_op (fds_filter_opts_t * opts , fds_filter_op_s op );
402410
403411/**
404412 * Adds multiple filter operation
405- *
413+ *
406414 * \param[in] opts The options structure
407415 * \param[in] ops The operations with a FDS_FILTER_END_OP_LIST marking the end
408- *
416+ *
409417 * \return pointer to the first new op on success, NULL on failure
410- */
418+ */
411419FDS_API fds_filter_op_s *
412420fds_filter_opts_extend_ops (fds_filter_opts_t * opts , const fds_filter_op_s * ops );
413421
414422/**
415423 * Destroys the options structure
416- *
424+ *
417425 * \param[in] opts The options structure
418426 */
419427FDS_API void
420428fds_filter_destroy_opts (fds_filter_opts_t * opts );
421429
422430/**
423431 * Set the user context
424- *
432+ *
425433 * \param[in] opts The opts
426434 * \param[in] user_ctx The user context
427435 */
@@ -430,7 +438,7 @@ fds_filter_opts_set_user_ctx(fds_filter_opts_t *opts, void *user_ctx);
430438
431439/**
432440 * Get the user context
433- *
441+ *
434442 * \param[in] opts The opts
435443 * \return the user context
436444 */
@@ -445,15 +453,15 @@ fds_filter_opts_get_user_ctx(const fds_filter_opts_t *opts);
445453// Main API
446454
447455/**
448- *
456+ *
449457 * Creates the filter from an expression.
450458 *
451459 * \param[out] filter Pointer to where to allocate and construct the filter
452460 * \param[in] expr The filter expression
453461 * \param[in] opts The filter options
454- *
455- * User context is an arbitary pointer provided by the user that's passed to all subsequent
456- * data callback calls as the user_ctx argument. It's intended to carry information about state
462+ *
463+ * User context is an arbitary pointer provided by the user that's passed to all subsequent
464+ * data callback calls as the user_ctx argument. It's intended to carry information about state
457465 * that's required for the data callback function to correctly parse the data.
458466 *
459467 * On error, more detailed information about the error can be obtained using fds_filter_get_error.
@@ -466,30 +474,30 @@ fds_filter_create(fds_filter_t **filter, const char *expr, const fds_filter_opts
466474
467475/**
468476 * Evaluates the filter on the provided data.
469- *
477+ *
470478 * \param[in] filter The filter
471- * \param[in] data The data
479+ * \param[in] data The data
472480 *
473- * \return true if the data passes the filter, false if not
481+ * \return true if the data passes the filter, false if not
474482 */
475483FDS_API bool
476484fds_filter_eval (fds_filter_t * filter , void * data );
477485
478486/**
479487 * Destroys the filter.
480- *
488+ *
481489 * \param[in] filter The filter to be destroyed.
482490 */
483491FDS_API void
484492fds_filter_destroy (fds_filter_t * filter );
485493
486494/**
487495 * Gets the error from a filter.
488- *
496+ *
489497 * If the filter parameter is NULL then memory error is assumed.
490- *
498+ *
491499 * \param[in] filter The filter
492- *
500+ *
493501 * \return Pointer to the error, or NULL if there is no error.
494502 */
495503FDS_API fds_filter_error_s *
0 commit comments