diff options
| author | Ben Fuhrmannek | 2021-02-16 11:16:59 +0100 |
|---|---|---|
| committer | Ben Fuhrmannek | 2021-02-16 11:16:59 +0100 |
| commit | 5484bcb5eb2714e7438927e2566c86a74d7c51af (patch) | |
| tree | b78326d2999397be4c08e06b23209981f82a4ea9 /src/sp_utils.h | |
| parent | 7ac1e3866ef4f146c6c93a5ca13b9aebb14e936a (diff) | |
| parent | cecfdd808da67be908dbe7144cc8c74dfb3f855e (diff) | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src/sp_utils.h')
| -rw-r--r-- | src/sp_utils.h | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/src/sp_utils.h b/src/sp_utils.h index 9df196c..d2b88fb 100644 --- a/src/sp_utils.h +++ b/src/sp_utils.h | |||
| @@ -28,24 +28,42 @@ | |||
| 28 | #define HOOK_FUNCTION_BY_REGEXP(regexp, hook_table, new_function) \ | 28 | #define HOOK_FUNCTION_BY_REGEXP(regexp, hook_table, new_function) \ |
| 29 | hook_regexp(regexp, SNUFFLEUPAGUS_G(hook_table), new_function) | 29 | hook_regexp(regexp, SNUFFLEUPAGUS_G(hook_table), new_function) |
| 30 | 30 | ||
| 31 | #define SP_LOG_SIMULATION E_WARNING | 31 | #define SP_TYPE_LOG (0) |
| 32 | #define SP_LOG_DROP E_ERROR | 32 | #define SP_TYPE_DROP (1) |
| 33 | #define SP_TYPE_SIMULATION (2) | ||
| 34 | |||
| 33 | #define SP_LOG_DEBUG E_NOTICE | 35 | #define SP_LOG_DEBUG E_NOTICE |
| 34 | #define SP_LOG_ERROR E_ERROR | 36 | #define SP_LOG_ERROR E_ERROR |
| 35 | #define SP_LOG_WARN E_WARNING | 37 | #define SP_LOG_WARN E_WARNING |
| 36 | 38 | ||
| 37 | #define sp_log_err(feature, ...) sp_log_msg(feature, SP_LOG_ERROR, __VA_ARGS__) | 39 | #define sp_log_msg(feature, level, ...) \ |
| 38 | #define sp_log_warn(feature, ...) sp_log_msg(feature, SP_LOG_WARN, __VA_ARGS__) | 40 | sp_log_msgf(feature, level, SP_TYPE_LOG, __VA_ARGS__) |
| 41 | #define sp_log_drop(feature, ...) \ | ||
| 42 | sp_log_msgf(feature, SP_LOG_ERROR, SP_TYPE_DROP, __VA_ARGS__) | ||
| 43 | #define sp_log_simulation(feature, ...) \ | ||
| 44 | sp_log_msgf(feature, SP_LOG_WARN, SP_TYPE_SIMULATION, __VA_ARGS__) | ||
| 45 | #define sp_log_auto(feature, is_simulation, ...) \ | ||
| 46 | sp_log_msgf(feature, (is_simulation ? SP_LOG_WARN : SP_LOG_ERROR), \ | ||
| 47 | (is_simulation ? SP_TYPE_SIMULATION : SP_TYPE_DROP), \ | ||
| 48 | __VA_ARGS__) | ||
| 49 | |||
| 50 | #define sp_log_err(feature, ...) \ | ||
| 51 | sp_log_msgf(feature, SP_LOG_ERROR, SP_TYPE_LOG, __VA_ARGS__) | ||
| 52 | #define sp_log_warn(feature, ...) \ | ||
| 53 | sp_log_msgf(feature, SP_LOG_WARN, SP_TYPE_LOG, __VA_ARGS__) | ||
| 39 | #ifdef SP_DEBUG | 54 | #ifdef SP_DEBUG |
| 40 | #define sp_log_debug(fmt, ...) sp_log_msg("DEBUG", SP_LOG_DEBUG, "%s(): " fmt, __FUNCTION__, ##__VA_ARGS__) | 55 | #define sp_log_debug(...) \ |
| 56 | sp_log_msgf("DEBUG", SP_LOG_DEBUG, SP_TYPE_LOG, "%s(): " fmt, __FUNCTION__, ##__VA_ARGS__) | ||
| 41 | #else | 57 | #else |
| 42 | #define sp_log_debug(...) | 58 | #define sp_log_debug(...) |
| 43 | #endif | 59 | #endif |
| 44 | 60 | ||
| 45 | #define GET_SUFFIX(x) (x == 1) ? "st" : ((x == 2) ? "nd" : "th") | 61 | #define GET_SUFFIX(x) (x == 1) ? "st" : ((x == 2) ? "nd" : "th") |
| 46 | 62 | ||
| 47 | void sp_log_msg(char const *feature, int type, const char *fmt, ...); | 63 | const char *get_ipaddr(void); |
| 48 | int compute_hash(const char *const filename, char *file_hash); | 64 | void sp_log_msgf(char const *restrict feature, int level, int type, |
| 65 | const char *restrict fmt, ...); | ||
| 66 | int compute_hash(const char *const restrict filename, char *restrict file_hash); | ||
| 49 | const zend_string *sp_zval_to_zend_string(const zval *); | 67 | const zend_string *sp_zval_to_zend_string(const zval *); |
| 50 | bool sp_match_value(const zend_string *, const zend_string *, const sp_pcre *); | 68 | bool sp_match_value(const zend_string *, const zend_string *, const sp_pcre *); |
| 51 | bool sp_match_array_key(const zval *, const zend_string *, const sp_pcre *); | 69 | bool sp_match_array_key(const zval *, const zend_string *, const sp_pcre *); |
| @@ -54,11 +72,12 @@ void sp_log_disable(const char *restrict, const char *restrict, | |||
| 54 | const zend_string *restrict, const sp_disabled_function *); | 72 | const zend_string *restrict, const sp_disabled_function *); |
| 55 | void sp_log_disable_ret(const char *restrict, const zend_string *restrict, | 73 | void sp_log_disable_ret(const char *restrict, const zend_string *restrict, |
| 56 | const sp_disabled_function *); | 74 | const sp_disabled_function *); |
| 57 | int hook_function(const char *, HashTable *, zif_handler); | 75 | bool hook_function(const char *, HashTable *, zif_handler); |
| 58 | int hook_regexp(const sp_pcre *, HashTable *, zif_handler); | 76 | int hook_regexp(const sp_pcre *, HashTable *, zif_handler); |
| 59 | bool check_is_in_eval_whitelist(const zend_string *const function_name); | 77 | bool check_is_in_eval_whitelist(const zend_string *const function_name); |
| 60 | int sp_log_request(const zend_string *folder, const zend_string *text_repr, | 78 | int sp_log_request(const zend_string *restrict folder, |
| 61 | char *from); | 79 | const zend_string *restrict text_repr, |
| 80 | char const *const from); | ||
| 62 | bool sp_zend_string_equals(const zend_string *s1, const zend_string *s2); | 81 | bool sp_zend_string_equals(const zend_string *s1, const zend_string *s2); |
| 63 | 82 | ||
| 64 | #endif /* SP_UTILS_H */ | 83 | #endif /* SP_UTILS_H */ |
