summaryrefslogtreecommitdiff
path: root/src/sp_config_utils.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_config_utils.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_config_utils.c')
-rw-r--r--src/sp_config_utils.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/sp_config_utils.c b/src/sp_config_utils.c
index 130f07e..d72561b 100644
--- a/src/sp_config_utils.c
+++ b/src/sp_config_utils.c
@@ -32,18 +32,18 @@ int parse_keywords(sp_config_functions *funcs, char *line) {
32 return 0; 32 return 0;
33} 33}
34 34
35char *get_param(size_t *consumed, char *restrict line, sp_type type, 35zend_string *get_param(size_t *consumed, char *restrict line, sp_type type,
36 const char *restrict keyword) { 36 const char *restrict keyword) {
37 enum { IN_ESCAPE, NONE } state = NONE; 37 enum { IN_ESCAPE, NONE } state = NONE;
38 char *original_line = line; 38 char *original_line = line;
39 size_t j = 0; 39 size_t j = 0;
40 40
41 char *ret = NULL; 41 zend_string *ret = NULL;
42 if (NULL == line || '\0' == *line) { 42 if (NULL == line || '\0' == *line) {
43 goto err; 43 goto err;
44 } 44 }
45 45
46 ret = pecalloc(sizeof(char), strlen(original_line) + 1, 1); 46 ret = zend_string_alloc(strlen(line) + 1, 1);
47 47
48 /* The first char of a string is always '"', since they MUST be quoted. */ 48 /* The first char of a string is always '"', since they MUST be quoted. */
49 if ('"' == *line) { 49 if ('"' == *line) {
@@ -65,6 +65,11 @@ char *get_param(size_t *consumed, char *restrict line, sp_type type,
65 2. the SP_TOKEN_END_PARAM 65 2. the SP_TOKEN_END_PARAM
66 */ 66 */
67 *consumed = i + 2; 67 *consumed = i + 2;
68 // Make sure that the string we return is the right size,
69 // as it can be smaller than strlen(line)
70 ret = zend_string_truncate(ret, j, 1);
71 // truncate does not add a \0
72 ZSTR_VAL(ret)[ZSTR_LEN(ret)] = 0;
68 return ret; 73 return ret;
69 } else if (state == IN_ESCAPE) { 74 } else if (state == IN_ESCAPE) {
70 break; // we're on an escped double quote 75 break; // we're on an escped double quote
@@ -82,7 +87,7 @@ char *get_param(size_t *consumed, char *restrict line, sp_type type,
82 if (state == IN_ESCAPE) { 87 if (state == IN_ESCAPE) {
83 state = NONE; 88 state = NONE;
84 } 89 }
85 ret[j++] = line[i]; 90 ZSTR_VAL(ret)[j++] = line[i];
86 } 91 }
87err: 92err:
88 if (0 == j) { 93 if (0 == j) {