From 7963580d72a358975133f86f01de2d2eab08ba38 Mon Sep 17 00:00:00 2001 From: xXx-caillou-xXx Date: Fri, 13 Jul 2018 10:36:50 +0200 Subject: Massively optimize how rules are handled This commit does a lot of things: - Use hashtables instead of lists to store the rules - Rules that can be applied at launch time won't be tried at runtime - Improve feedback when writing nonsensical rules - Make intensive use of `zend_string` instead of `char*`--- src/sp_cookie_encryption.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/sp_cookie_encryption.c') diff --git a/src/sp_cookie_encryption.c b/src/sp_cookie_encryption.c index 6cb1ff7..3f58fb0 100644 --- a/src/sp_cookie_encryption.c +++ b/src/sp_cookie_encryption.c @@ -4,8 +4,8 @@ ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus) -static inline const sp_cookie *sp_lookup_cookie_config(const char *key) { - sp_list_node *it = SNUFFLEUPAGUS_G(config).config_cookie->cookies; +static inline const sp_cookie *sp_lookup_cookie_config(const zend_string *key) { + const sp_list_node *it = SNUFFLEUPAGUS_G(config).config_cookie->cookies; while (it) { const sp_cookie *config = it->data; @@ -20,7 +20,7 @@ static inline const sp_cookie *sp_lookup_cookie_config(const char *key) { /* called at RINIT time with each cookie, eventually decrypt said cookie */ int decrypt_cookie(zval *pDest, int num_args, va_list args, zend_hash_key *hash_key) { - const sp_cookie *cookie = sp_lookup_cookie_config(ZSTR_VAL(hash_key->key)); + const sp_cookie *cookie = sp_lookup_cookie_config(hash_key->key); /* If the cookie isn't in the conf, it shouldn't be encrypted. */ if (!cookie || !cookie->encrypt) { @@ -35,9 +35,9 @@ int decrypt_cookie(zval *pDest, int num_args, va_list args, return decrypt_zval(pDest, cookie->simulation, hash_key); } -static zend_string *encrypt_data(char *data, unsigned long long data_len) { - zend_string *z = encrypt_zval(data, data_len); - sp_log_debug("cookie_encryption", "Cookie value:%s:", z->val); +static zend_string *encrypt_data(zend_string *data) { + zend_string *z = encrypt_zval(data); + sp_log_debug("cookie_encryption", "Cookie value:%s:", ZSTR_VAL(z)); return z; } @@ -77,7 +77,7 @@ PHP_FUNCTION(sp_setcookie) { } /* lookup existing configuration for said cookie */ - cookie_node = sp_lookup_cookie_config(ZSTR_VAL(name)); + cookie_node = sp_lookup_cookie_config(name); /* If the cookie's value is encrypted, it won't be usable by * javascript anyway. @@ -88,7 +88,7 @@ PHP_FUNCTION(sp_setcookie) { /* Shall we encrypt the cookie's value? */ if (cookie_node && cookie_node->encrypt && value) { - zend_string *encrypted_data = encrypt_data(value->val, value->len); + zend_string *encrypted_data = encrypt_data(value); ZVAL_STR_COPY(¶ms[1], encrypted_data); zend_string_release(encrypted_data); } else if (value) { -- cgit v1.3