summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d5d9ee6)
raw | patch | inline | side by side (parent: d5d9ee6)
author | Pavel Rochnyack <pavel2000@ngs.ru> | |
Sat, 7 May 2016 07:01:33 +0000 (13:01 +0600) | ||
committer | Florian Forster <octo@collectd.org> | |
Sun, 27 Nov 2016 06:54:38 +0000 (07:54 +0100) |
src/daemon/utils_match.c | patch | blob | history | |
src/daemon/utils_match.h | patch | blob | history |
index 35102b6dec76b78e5062156dda586c3d773daae6..2a39e4d0552b439623de8b18bf59c2aab9b3eda4 100644 (file)
--- a/src/daemon/utils_match.c
+++ b/src/daemon/utils_match.c
#include <regex.h>
-#define UTILS_MATCH_FLAGS_FREE_USER_DATA 0x01
#define UTILS_MATCH_FLAGS_EXCLUDE_REGEX 0x02
struct cu_match_s
int (*callback) (const char *str, char * const *matches, size_t matches_num,
void *user_data);
void *user_data;
+ void (*free) (void *user_data);
};
/*
return (0);
} /* int default_callback */
+static void match_simple_free (void *data)
+{
+ free (data);
+} /* void match_simple_free */
+
/*
* Public functions
*/
cu_match_t *match_create_callback (const char *regex, const char *excluderegex,
int (*callback) (const char *str,
char * const *matches, size_t matches_num, void *user_data),
- void *user_data)
+ void *user_data, void (*free_user_data) (void *user_data))
{
cu_match_t *obj;
int status;
obj->callback = callback;
obj->user_data = user_data;
+ obj->free = free_user_data;
return (obj);
} /* cu_match_t *match_create_callback */
user_data->ds_type = match_ds_type;
obj = match_create_callback (regex, excluderegex,
- default_callback, user_data);
+ default_callback, user_data, match_simple_free);
if (obj == NULL)
{
sfree (user_data);
return (NULL);
}
-
- obj->flags |= UTILS_MATCH_FLAGS_FREE_USER_DATA;
-
return (obj);
} /* cu_match_t *match_create_simple */
if (obj == NULL)
return;
- if (obj->flags & UTILS_MATCH_FLAGS_FREE_USER_DATA)
- {
- sfree (obj->user_data);
- }
+ if ((obj->user_data != NULL) && (obj->free != NULL))
+ (*obj->free) (obj->user_data);
sfree (obj);
} /* void match_destroy */
index d43ae3b340a578e2be647c53afde1152fa2fb7ce..31dc66d804b84cfc18685e37076d47aa26b503ca 100644 (file)
--- a/src/daemon/utils_match.h
+++ b/src/daemon/utils_match.h
* callback.
* The optional `excluderegex' allows to exclude the line from the match, if
* the excluderegex matches.
+ * When `match_destroy' is called the `user_data' pointer is freed using
+ * the `free_user_data' callback - if it is not NULL.
*/
cu_match_t *match_create_callback (const char *regex, const char *excluderegex,
int (*callback) (const char *str,
char * const *matches, size_t matches_num, void *user_data),
- void *user_data);
+ void *user_data, void (*free_user_data) (void *user_data));
/*
* NAME