summaryrefslogtreecommitdiff
path: root/src/sp_utils.h
diff options
context:
space:
mode:
authorSebastien Blot2017-09-20 10:11:01 +0200
committerSebastien Blot2017-09-20 10:11:01 +0200
commit868f96c759b6650d88ff9f4fbc5c048302134248 (patch)
treec0de0af318bf77a8959164ef11aeeeb2b7bab294 /src/sp_utils.h
Initial import
Diffstat (limited to 'src/sp_utils.h')
-rw-r--r--src/sp_utils.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/sp_utils.h b/src/sp_utils.h
new file mode 100644
index 0000000..37dd2c0
--- /dev/null
+++ b/src/sp_utils.h
@@ -0,0 +1,68 @@
1#ifndef SP_UTILS_H
2#define SP_UTILS_H
3
4#include "sp_config.h"
5#include "sp_list.h"
6
7#if defined(__GNUC__)
8# if __GNUC__ >= 3
9# define sp_pure __attribute__((pure))
10# define sp_const __attribute__((const))
11# else
12# define sp_pure
13# define sp_const
14# endif
15#endif
16/* The dump filename are of the form
17 * `sp_dump_DATE_IPADDR.dump`, with:
18 * - DATE being the output of asctime, 26 chars long
19 * - IP_ADDR being an IP adress, with a maximum size of 15
20 *
21 * We keep one char for the terminal \0, and one for the leading slash.
22 */
23
24#define MAX_FOLDER_LEN \
25 PATH_MAX - 1 - sizeof("sp_dump_") - 26 - sizeof("_") - 15 - \
26 sizeof(".dump") - 1
27
28#define VAR_AND_LEN(var) var, strlen(var)
29
30#define SHA256_SIZE 32
31
32#define HOOK_FUNCTION(original_name, hook_table, new_function, execution) \
33 hook_function(original_name, SNUFFLEUPAGUS_G(hook_table), new_function, execution)
34
35#define HOOK_FUNCTION_BY_REGEXP(regexp, hook_table, new_function, execution) \
36 hook_regexp(regexp, SNUFFLEUPAGUS_G(hook_table), new_function, execution)
37
38#define LOG_NOTICE "notice"
39#define LOG_DROP "drop"
40#define LOG_DEBUG "debug"
41#define LOG_ERROR "error"
42
43#define sp_log_err(feature, ...) sp_log_msg(feature, LOG_ERROR, __VA_ARGS__)
44#ifdef SP_DEBUG
45 #define sp_log_debug(...) sp_log_msg("DEBUG", LOG_DEBUG, __VA_ARGS__)
46#else
47 #define sp_log_debug(...)
48#endif
49
50void sp_log_msg(char const *feature, char const *level, const char* fmt, ...);
51int compute_hash(const char *const filename, char *file_hash);
52char *sp_convert_to_string(zval *);
53bool sp_match_value(const char *, const char *, const pcre *);
54int sp_match_array_key(const zval *, const char *, const pcre *);
55int sp_match_array_key_recurse(const zval *, sp_node_t *, const char *,
56 const pcre *);
57void sp_log_disable(const char *restrict, const char *restrict,
58 const char *restrict, const sp_disabled_function *);
59void sp_log_disable_ret(const char *restrict, const char *restrict,
60 const sp_disabled_function *);
61char *sp_getenv(char *);
62int is_regexp_matching(const pcre *, const char *);
63int hook_function(const char *, HashTable *,
64 void (*)(INTERNAL_FUNCTION_PARAMETERS), bool);
65int hook_regexp(const pcre *, HashTable *,
66 void (*)(INTERNAL_FUNCTION_PARAMETERS), bool);
67
68#endif /* SP_UTILS_H */