From 868f96c759b6650d88ff9f4fbc5c048302134248 Mon Sep 17 00:00:00 2001 From: Sebastien Blot Date: Wed, 20 Sep 2017 10:11:01 +0200 Subject: Initial import --- src/sp_utils.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/sp_utils.h (limited to 'src/sp_utils.h') 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 @@ +#ifndef SP_UTILS_H +#define SP_UTILS_H + +#include "sp_config.h" +#include "sp_list.h" + +#if defined(__GNUC__) +# if __GNUC__ >= 3 +# define sp_pure __attribute__((pure)) +# define sp_const __attribute__((const)) +# else +# define sp_pure +# define sp_const +# endif +#endif +/* The dump filename are of the form + * `sp_dump_DATE_IPADDR.dump`, with: + * - DATE being the output of asctime, 26 chars long + * - IP_ADDR being an IP adress, with a maximum size of 15 + * + * We keep one char for the terminal \0, and one for the leading slash. + */ + +#define MAX_FOLDER_LEN \ + PATH_MAX - 1 - sizeof("sp_dump_") - 26 - sizeof("_") - 15 - \ + sizeof(".dump") - 1 + +#define VAR_AND_LEN(var) var, strlen(var) + +#define SHA256_SIZE 32 + +#define HOOK_FUNCTION(original_name, hook_table, new_function, execution) \ + hook_function(original_name, SNUFFLEUPAGUS_G(hook_table), new_function, execution) + +#define HOOK_FUNCTION_BY_REGEXP(regexp, hook_table, new_function, execution) \ + hook_regexp(regexp, SNUFFLEUPAGUS_G(hook_table), new_function, execution) + +#define LOG_NOTICE "notice" +#define LOG_DROP "drop" +#define LOG_DEBUG "debug" +#define LOG_ERROR "error" + +#define sp_log_err(feature, ...) sp_log_msg(feature, LOG_ERROR, __VA_ARGS__) +#ifdef SP_DEBUG + #define sp_log_debug(...) sp_log_msg("DEBUG", LOG_DEBUG, __VA_ARGS__) +#else + #define sp_log_debug(...) +#endif + +void sp_log_msg(char const *feature, char const *level, const char* fmt, ...); +int compute_hash(const char *const filename, char *file_hash); +char *sp_convert_to_string(zval *); +bool sp_match_value(const char *, const char *, const pcre *); +int sp_match_array_key(const zval *, const char *, const pcre *); +int sp_match_array_key_recurse(const zval *, sp_node_t *, const char *, + const pcre *); +void sp_log_disable(const char *restrict, const char *restrict, + const char *restrict, const sp_disabled_function *); +void sp_log_disable_ret(const char *restrict, const char *restrict, + const sp_disabled_function *); +char *sp_getenv(char *); +int is_regexp_matching(const pcre *, const char *); +int hook_function(const char *, HashTable *, + void (*)(INTERNAL_FUNCTION_PARAMETERS), bool); +int hook_regexp(const pcre *, HashTable *, + void (*)(INTERNAL_FUNCTION_PARAMETERS), bool); + +#endif /* SP_UTILS_H */ -- cgit v1.3