diff options
| author | Thibault "bui" Koechlin | 2017-12-28 17:04:06 +0100 |
|---|---|---|
| committer | jvoisin | 2017-12-28 17:04:06 +0100 |
| commit | 9f5e8d12f05fb24c915a5266a1e908a75c8aed08 (patch) | |
| tree | 9160075ea943c7fd29a3923f844a0ac0d6b8b457 /src/sp_config.c | |
| parent | 62c48bf9a85e0294b7b32cea438e904e1cd50669 (diff) | |
Clang-format pass
- `clang-format --style="{BasedOnStyle: google, SortIncludes: false}" -i snuffleu*.c sp_*.c sp_*.h`
- Update the documentation accordingly
Diffstat (limited to 'src/sp_config.c')
| -rw-r--r-- | src/sp_config.c | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/src/sp_config.c b/src/sp_config.c index f1c7b65..aeadd9d 100644 --- a/src/sp_config.c +++ b/src/sp_config.c | |||
| @@ -35,7 +35,8 @@ static int parse_line(char *line) { | |||
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | if (strncmp(ptr, SP_TOKEN_BASE, strlen(SP_TOKEN_BASE))) { | 37 | if (strncmp(ptr, SP_TOKEN_BASE, strlen(SP_TOKEN_BASE))) { |
| 38 | sp_log_err("config", "Invalid configuration prefix for '%s' on line %zu.", line, sp_line_no); | 38 | sp_log_err("config", "Invalid configuration prefix for '%s' on line %zu.", |
| 39 | line, sp_line_no); | ||
| 39 | return -1; | 40 | return -1; |
| 40 | } | 41 | } |
| 41 | ptr += strlen(SP_TOKEN_BASE); | 42 | ptr += strlen(SP_TOKEN_BASE); |
| @@ -45,7 +46,8 @@ static int parse_line(char *line) { | |||
| 45 | return sp_func[i].func(ptr + strlen(sp_func[i].token)); | 46 | return sp_func[i].func(ptr + strlen(sp_func[i].token)); |
| 46 | } | 47 | } |
| 47 | } | 48 | } |
| 48 | sp_log_err("config", "Invalid configuration section '%s' on line %zu.", line, sp_line_no); | 49 | sp_log_err("config", "Invalid configuration section '%s' on line %zu.", line, |
| 50 | sp_line_no); | ||
| 49 | return -1; | 51 | return -1; |
| 50 | } | 52 | } |
| 51 | 53 | ||
| @@ -60,32 +62,35 @@ int parse_php_type(char *restrict line, char *restrict keyword, void *retval) { | |||
| 60 | char *value = get_param(&consumed, line, SP_TYPE_STR, keyword); | 62 | char *value = get_param(&consumed, line, SP_TYPE_STR, keyword); |
| 61 | if (value) { | 63 | if (value) { |
| 62 | if (0 == strcasecmp("undef", value)) { | 64 | if (0 == strcasecmp("undef", value)) { |
| 63 | *(sp_php_type*)retval = SP_PHP_TYPE_UNDEF; | 65 | *(sp_php_type *)retval = SP_PHP_TYPE_UNDEF; |
| 64 | } else if (0 == strcasecmp("null", value)) { | 66 | } else if (0 == strcasecmp("null", value)) { |
| 65 | *(sp_php_type*)retval = SP_PHP_TYPE_NULL; | 67 | *(sp_php_type *)retval = SP_PHP_TYPE_NULL; |
| 66 | } else if (0 == strcasecmp("true", value)) { | 68 | } else if (0 == strcasecmp("true", value)) { |
| 67 | *(sp_php_type*)retval = SP_PHP_TYPE_TRUE; | 69 | *(sp_php_type *)retval = SP_PHP_TYPE_TRUE; |
| 68 | } else if (0 == strcasecmp("false", value)) { | 70 | } else if (0 == strcasecmp("false", value)) { |
| 69 | *(sp_php_type*)retval = SP_PHP_TYPE_FALSE; | 71 | *(sp_php_type *)retval = SP_PHP_TYPE_FALSE; |
| 70 | } else if (0 == strcasecmp("long", value)) { | 72 | } else if (0 == strcasecmp("long", value)) { |
| 71 | *(sp_php_type*)retval = SP_PHP_TYPE_LONG; | 73 | *(sp_php_type *)retval = SP_PHP_TYPE_LONG; |
| 72 | } else if (0 == strcasecmp("double", value)) { | 74 | } else if (0 == strcasecmp("double", value)) { |
| 73 | *(sp_php_type*)retval = SP_PHP_TYPE_DOUBLE; | 75 | *(sp_php_type *)retval = SP_PHP_TYPE_DOUBLE; |
| 74 | } else if (0 == strcasecmp("string", value)) { | 76 | } else if (0 == strcasecmp("string", value)) { |
| 75 | *(sp_php_type*)retval = SP_PHP_TYPE_STRING; | 77 | *(sp_php_type *)retval = SP_PHP_TYPE_STRING; |
| 76 | } else if (0 == strcasecmp("array", value)) { | 78 | } else if (0 == strcasecmp("array", value)) { |
| 77 | *(sp_php_type*)retval = SP_PHP_TYPE_ARRAY; | 79 | *(sp_php_type *)retval = SP_PHP_TYPE_ARRAY; |
| 78 | } else if (0 == strcasecmp("object", value)) { | 80 | } else if (0 == strcasecmp("object", value)) { |
| 79 | *(sp_php_type*)retval = SP_PHP_TYPE_OBJECT; | 81 | *(sp_php_type *)retval = SP_PHP_TYPE_OBJECT; |
| 80 | } else if (0 == strcasecmp("resource", value)) { | 82 | } else if (0 == strcasecmp("resource", value)) { |
| 81 | *(sp_php_type*)retval = SP_PHP_TYPE_RESOURCE; | 83 | *(sp_php_type *)retval = SP_PHP_TYPE_RESOURCE; |
| 82 | } else if (0 == strcasecmp("reference", value)) { | 84 | } else if (0 == strcasecmp("reference", value)) { |
| 83 | *(sp_php_type*)retval = SP_PHP_TYPE_REFERENCE; | 85 | *(sp_php_type *)retval = SP_PHP_TYPE_REFERENCE; |
| 84 | } else { | 86 | } else { |
| 85 | pefree(value, 1); | 87 | pefree(value, 1); |
| 86 | sp_log_err("error", "%s) is expecting a valid php type ('false', 'true'," | 88 | sp_log_err("error", |
| 87 | " 'array'. 'object', 'long', 'double', 'null', 'resource', 'reference'," | 89 | "%s) is expecting a valid php type ('false', 'true'," |
| 88 | " 'undef') on line %zu.", keyword, sp_line_no); | 90 | " 'array'. 'object', 'long', 'double', 'null', 'resource', " |
| 91 | "'reference'," | ||
| 92 | " 'undef') on line %zu.", | ||
| 93 | keyword, sp_line_no); | ||
| 89 | return -1; | 94 | return -1; |
| 90 | } | 95 | } |
| 91 | pefree(value, 1); | 96 | pefree(value, 1); |
| @@ -119,7 +124,8 @@ int parse_cidr(char *restrict line, char *restrict keyword, void *retval) { | |||
| 119 | *(sp_cidr **)retval = cidr; | 124 | *(sp_cidr **)retval = cidr; |
| 120 | return consumed; | 125 | return consumed; |
| 121 | } else { | 126 | } else { |
| 122 | sp_log_err("config", "%s doesn't contain a valid cidr on line %zu.", line, sp_line_no); | 127 | sp_log_err("config", "%s doesn't contain a valid cidr on line %zu.", line, |
| 128 | sp_line_no); | ||
| 123 | return -1; | 129 | return -1; |
| 124 | } | 130 | } |
| 125 | } | 131 | } |
| @@ -135,9 +141,10 @@ int parse_regexp(char *restrict line, char *restrict keyword, void *retval) { | |||
| 135 | const char *pcre_error; | 141 | const char *pcre_error; |
| 136 | int pcre_error_offset; | 142 | int pcre_error_offset; |
| 137 | pcre *compiled_re = sp_pcre_compile(value, PCRE_CASELESS, &pcre_error, | 143 | pcre *compiled_re = sp_pcre_compile(value, PCRE_CASELESS, &pcre_error, |
| 138 | &pcre_error_offset, NULL); | 144 | &pcre_error_offset, NULL); |
| 139 | if (NULL == compiled_re) { | 145 | if (NULL == compiled_re) { |
| 140 | sp_log_err("config", "Failed to compile '%s': %s on line %zu.", value, pcre_error, sp_line_no); | 146 | sp_log_err("config", "Failed to compile '%s': %s on line %zu.", value, |
| 147 | pcre_error, sp_line_no); | ||
| 141 | } else { | 148 | } else { |
| 142 | *(pcre **)retval = compiled_re; | 149 | *(pcre **)retval = compiled_re; |
| 143 | return consumed; | 150 | return consumed; |
| @@ -147,7 +154,8 @@ int parse_regexp(char *restrict line, char *restrict keyword, void *retval) { | |||
| 147 | if (NULL != closing_paren) { | 154 | if (NULL != closing_paren) { |
| 148 | closing_paren[0] = '\0'; | 155 | closing_paren[0] = '\0'; |
| 149 | } | 156 | } |
| 150 | sp_log_err("config", "'%s)' is expecting a valid regexp, and not '%s' on line %zu.", | 157 | sp_log_err("config", |
| 158 | "'%s)' is expecting a valid regexp, and not '%s' on line %zu.", | ||
| 151 | keyword, line, sp_line_no); | 159 | keyword, line, sp_line_no); |
| 152 | return -1; | 160 | return -1; |
| 153 | } | 161 | } |
| @@ -183,12 +191,11 @@ int sp_parse_config(const char *conf_file) { | |||
| 183 | return SUCCESS; | 191 | return SUCCESS; |
| 184 | } | 192 | } |
| 185 | 193 | ||
| 186 | void sp_disabled_function_list_free(sp_list_node* list) { | 194 | void sp_disabled_function_list_free(sp_list_node *list) { |
| 187 | sp_list_node* cursor = list; | 195 | sp_list_node *cursor = list; |
| 188 | while(cursor) { | 196 | while (cursor) { |
| 189 | sp_disabled_function* df = cursor->data; | 197 | sp_disabled_function *df = cursor->data; |
| 190 | if (df && df->functions_list) | 198 | if (df && df->functions_list) sp_list_free(df->functions_list); |
| 191 | sp_list_free(df->functions_list); | ||
| 192 | if (df) { | 199 | if (df) { |
| 193 | sp_tree_free(df->param); | 200 | sp_tree_free(df->param); |
| 194 | sp_tree_free(df->var); | 201 | sp_tree_free(df->var); |
