summaryrefslogtreecommitdiff
path: root/src/sp_utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/sp_utils.h')
-rw-r--r--src/sp_utils.h41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/sp_utils.h b/src/sp_utils.h
index b5a1691..0e595d8 100644
--- a/src/sp_utils.h
+++ b/src/sp_utils.h
@@ -23,16 +23,17 @@
23#define SHA256_SIZE 32 23#define SHA256_SIZE 32
24 24
25#define HOOK_FUNCTION(original_name, hook_table, new_function) \ 25#define HOOK_FUNCTION(original_name, hook_table, new_function) \
26 hook_function(original_name, SNUFFLEUPAGUS_G(hook_table), new_function) 26 hook_function(original_name, SPG(hook_table), new_function)
27 27
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, SPG(hook_table), new_function)
30 30
31#define SP_TYPE_LOG (0) 31#define SP_TYPE_LOG (0)
32#define SP_TYPE_DROP (1) 32#define SP_TYPE_DROP (1)
33#define SP_TYPE_SIMULATION (2) 33#define SP_TYPE_SIMULATION (2)
34 34
35#define SP_LOG_DEBUG E_NOTICE 35#define SP_LOG_DEBUG E_NOTICE
36#define SP_LOG_INFO E_NOTICE
36#define SP_LOG_ERROR E_ERROR 37#define SP_LOG_ERROR E_ERROR
37#define SP_LOG_WARN E_WARNING 38#define SP_LOG_WARN E_WARNING
38 39
@@ -57,11 +58,11 @@
57#ifdef SP_DEBUG_STDERR 58#ifdef SP_DEBUG_STDERR
58extern int sp_debug_stderr; 59extern int sp_debug_stderr;
59#define sp_log_debug(fmt, ...) \ 60#define sp_log_debug(fmt, ...) \
60 dprintf(sp_debug_stderr, "[snuffleupagus][DEBUG] %s(): " fmt "\n", __FUNCTION__, ##__VA_ARGS__); 61 if (sp_debug_stderr > 0) dprintf(sp_debug_stderr, "[snuffleupagus][DEBUG] %s(): " fmt "\n", __FUNCTION__, ##__VA_ARGS__);
61#else 62#else
62#define sp_log_debug(...) \ 63#define sp_log_debug(fmt, ...) \
63 sp_log_msgf("DEBUG", SP_LOG_DEBUG, SP_TYPE_LOG, __VA_ARGS__) 64 sp_log_msgf("DEBUG", SP_LOG_DEBUG, SP_TYPE_LOG, "%s(): " fmt, __FUNCTION__, ##__VA_ARGS__)
64#endif 65#endif
65 66
66#else 67#else
67#define sp_log_debug(...) 68#define sp_log_debug(...)
@@ -70,23 +71,21 @@ extern int sp_debug_stderr;
70#define GET_SUFFIX(x) (x == 1) ? "st" : ((x == 2) ? "nd" : "th") 71#define GET_SUFFIX(x) (x == 1) ? "st" : ((x == 2) ? "nd" : "th")
71 72
72const char *get_ipaddr(void); 73const char *get_ipaddr(void);
73void sp_log_msgf(char const *restrict feature, int level, int type, 74void sp_log_msgf(char const *restrict feature, int level, int type, const char *restrict fmt, ...);
74 const char *restrict fmt, ...);
75int compute_hash(const char *const restrict filename, char *restrict file_hash); 75int compute_hash(const char *const restrict filename, char *restrict file_hash);
76const zend_string *sp_zval_to_zend_string(const zval *); 76const zend_string *sp_zval_to_zend_string(const zval *);
77bool sp_match_value(const zend_string *, const zend_string *, const sp_pcre *); 77bool sp_match_value(const zend_string* value, const zend_string* to_match, const sp_regexp* rx);
78bool sp_match_array_key(const zval *, const zend_string *, const sp_pcre *); 78bool sp_match_array_key(const zval *, const zend_string *, const sp_regexp *);
79bool sp_match_array_value(const zval *, const zend_string *, const sp_pcre *); 79bool sp_match_array_value(const zval *, const zend_string *, const sp_regexp *);
80void sp_log_disable(const char *restrict, const char *restrict, 80void sp_log_disable(const char *restrict, const char *restrict, const zend_string *restrict, const sp_disabled_function *);
81 const zend_string *restrict, const sp_disabled_function *); 81void sp_log_disable_ret(const char *restrict, const zend_string *restrict, const sp_disabled_function *);
82void sp_log_disable_ret(const char *restrict, const zend_string *restrict,
83 const sp_disabled_function *);
84bool hook_function(const char *, HashTable *, zif_handler); 82bool hook_function(const char *, HashTable *, zif_handler);
83void unhook_functions(HashTable *ht);
85int hook_regexp(const sp_pcre *, HashTable *, zif_handler); 84int hook_regexp(const sp_pcre *, HashTable *, zif_handler);
86bool check_is_in_eval_whitelist(const zend_string *const function_name); 85bool check_is_in_eval_whitelist(const char* function_name);
87int sp_log_request(const zend_string *restrict folder, 86int sp_log_request(const zend_string *restrict folder, const zend_string *restrict text_repr);
88 const zend_string *restrict text_repr, 87#define sp_zend_string_equals(s1, s2) zend_string_equals((zend_string*)s1, (zend_string*)s2)
89 char const *const from); 88static inline bool sp_zend_string_equals_str(const zend_string* s1, const char *str, size_t len) {
90bool sp_zend_string_equals(const zend_string *s1, const zend_string *s2); 89 return (ZSTR_LEN(s1) == len && !memcmp(ZSTR_VAL(s1), str, len));
91 90}
92#endif /* SP_UTILS_H */ 91#endif /* SP_UTILS_H */