summaryrefslogtreecommitdiff
path: root/src/sp_cookie_encryption.c
diff options
context:
space:
mode:
authorxXx-caillou-xXx2018-07-13 10:36:50 +0200
committerjvoisin2018-07-13 08:36:50 +0000
commit7963580d72a358975133f86f01de2d2eab08ba38 (patch)
tree4bec345d70f687a2a6002b36e2f2fc79318959f6 /src/sp_cookie_encryption.c
parent12b740bc7bb01ffe397cecc5b6fa25b136304911 (diff)
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*`
Diffstat (limited to 'src/sp_cookie_encryption.c')
-rw-r--r--src/sp_cookie_encryption.c16
1 files changed, 8 insertions, 8 deletions
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 @@
4 4
5ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus) 5ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus)
6 6
7static inline const sp_cookie *sp_lookup_cookie_config(const char *key) { 7static inline const sp_cookie *sp_lookup_cookie_config(const zend_string *key) {
8 sp_list_node *it = SNUFFLEUPAGUS_G(config).config_cookie->cookies; 8 const sp_list_node *it = SNUFFLEUPAGUS_G(config).config_cookie->cookies;
9 9
10 while (it) { 10 while (it) {
11 const sp_cookie *config = it->data; 11 const sp_cookie *config = it->data;
@@ -20,7 +20,7 @@ static inline const sp_cookie *sp_lookup_cookie_config(const char *key) {
20/* called at RINIT time with each cookie, eventually decrypt said cookie */ 20/* called at RINIT time with each cookie, eventually decrypt said cookie */
21int decrypt_cookie(zval *pDest, int num_args, va_list args, 21int decrypt_cookie(zval *pDest, int num_args, va_list args,
22 zend_hash_key *hash_key) { 22 zend_hash_key *hash_key) {
23 const sp_cookie *cookie = sp_lookup_cookie_config(ZSTR_VAL(hash_key->key)); 23 const sp_cookie *cookie = sp_lookup_cookie_config(hash_key->key);
24 24
25 /* If the cookie isn't in the conf, it shouldn't be encrypted. */ 25 /* If the cookie isn't in the conf, it shouldn't be encrypted. */
26 if (!cookie || !cookie->encrypt) { 26 if (!cookie || !cookie->encrypt) {
@@ -35,9 +35,9 @@ int decrypt_cookie(zval *pDest, int num_args, va_list args,
35 return decrypt_zval(pDest, cookie->simulation, hash_key); 35 return decrypt_zval(pDest, cookie->simulation, hash_key);
36} 36}
37 37
38static zend_string *encrypt_data(char *data, unsigned long long data_len) { 38static zend_string *encrypt_data(zend_string *data) {
39 zend_string *z = encrypt_zval(data, data_len); 39 zend_string *z = encrypt_zval(data);
40 sp_log_debug("cookie_encryption", "Cookie value:%s:", z->val); 40 sp_log_debug("cookie_encryption", "Cookie value:%s:", ZSTR_VAL(z));
41 return z; 41 return z;
42} 42}
43 43
@@ -77,7 +77,7 @@ PHP_FUNCTION(sp_setcookie) {
77 } 77 }
78 78
79 /* lookup existing configuration for said cookie */ 79 /* lookup existing configuration for said cookie */
80 cookie_node = sp_lookup_cookie_config(ZSTR_VAL(name)); 80 cookie_node = sp_lookup_cookie_config(name);
81 81
82 /* If the cookie's value is encrypted, it won't be usable by 82 /* If the cookie's value is encrypted, it won't be usable by
83 * javascript anyway. 83 * javascript anyway.
@@ -88,7 +88,7 @@ PHP_FUNCTION(sp_setcookie) {
88 88
89 /* Shall we encrypt the cookie's value? */ 89 /* Shall we encrypt the cookie's value? */
90 if (cookie_node && cookie_node->encrypt && value) { 90 if (cookie_node && cookie_node->encrypt && value) {
91 zend_string *encrypted_data = encrypt_data(value->val, value->len); 91 zend_string *encrypted_data = encrypt_data(value);
92 ZVAL_STR_COPY(&params[1], encrypted_data); 92 ZVAL_STR_COPY(&params[1], encrypted_data);
93 zend_string_release(encrypted_data); 93 zend_string_release(encrypted_data);
94 } else if (value) { 94 } else if (value) {