diff options
Diffstat (limited to 'src/sp_utils.h')
| -rw-r--r-- | src/sp_utils.h | 68 |
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 | |||
| 50 | void sp_log_msg(char const *feature, char const *level, const char* fmt, ...); | ||
| 51 | int compute_hash(const char *const filename, char *file_hash); | ||
| 52 | char *sp_convert_to_string(zval *); | ||
| 53 | bool sp_match_value(const char *, const char *, const pcre *); | ||
| 54 | int sp_match_array_key(const zval *, const char *, const pcre *); | ||
| 55 | int sp_match_array_key_recurse(const zval *, sp_node_t *, const char *, | ||
| 56 | const pcre *); | ||
| 57 | void sp_log_disable(const char *restrict, const char *restrict, | ||
| 58 | const char *restrict, const sp_disabled_function *); | ||
| 59 | void sp_log_disable_ret(const char *restrict, const char *restrict, | ||
| 60 | const sp_disabled_function *); | ||
| 61 | char *sp_getenv(char *); | ||
| 62 | int is_regexp_matching(const pcre *, const char *); | ||
| 63 | int hook_function(const char *, HashTable *, | ||
| 64 | void (*)(INTERNAL_FUNCTION_PARAMETERS), bool); | ||
| 65 | int hook_regexp(const pcre *, HashTable *, | ||
| 66 | void (*)(INTERNAL_FUNCTION_PARAMETERS), bool); | ||
| 67 | |||
| 68 | #endif /* SP_UTILS_H */ | ||
