summaryrefslogtreecommitdiff
path: root/src/sp_config.c
diff options
context:
space:
mode:
authorjvoisin2017-09-25 14:04:21 +0200
committerjvoisin2017-09-25 14:04:21 +0200
commitbed568094b95b65a43c44d7b4d38aced394fce1c (patch)
treedfa1fece12df05adee964eb27b98b46cb5a34ead /src/sp_config.c
parent302dd00ff445a3b8257fa75bdb24ed354a513746 (diff)
Show the line number in case of processing error
Diffstat (limited to 'src/sp_config.c')
-rw-r--r--src/sp_config.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/sp_config.c b/src/sp_config.c
index 37a34b9..3da027c 100644
--- a/src/sp_config.c
+++ b/src/sp_config.c
@@ -6,6 +6,8 @@
6 6
7ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus) 7ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus)
8 8
9size_t sp_line_no;
10
9sp_config_tokens const sp_func[] = { 11sp_config_tokens const sp_func[] = {
10 {.func = parse_unserialize, .token = SP_TOKEN_UNSERIALIZE_HMAC}, 12 {.func = parse_unserialize, .token = SP_TOKEN_UNSERIALIZE_HMAC},
11 {.func = parse_random, .token = SP_TOKEN_HARDEN_RANDOM}, 13 {.func = parse_random, .token = SP_TOKEN_HARDEN_RANDOM},
@@ -33,7 +35,7 @@ static int parse_line(char *line) {
33 } 35 }
34 36
35 if (strncmp(ptr, SP_TOKEN_BASE, strlen(SP_TOKEN_BASE))) { 37 if (strncmp(ptr, SP_TOKEN_BASE, strlen(SP_TOKEN_BASE))) {
36 sp_log_err("config", "Invalid configuration prefix for '%s'.", line); 38 sp_log_err("config", "Invalid configuration prefix for '%s' on line %zu.", line, sp_line_no);
37 return -1; 39 return -1;
38 } 40 }
39 ptr += strlen(SP_TOKEN_BASE); 41 ptr += strlen(SP_TOKEN_BASE);
@@ -43,7 +45,7 @@ static int parse_line(char *line) {
43 return sp_func[i].func(ptr + strlen(sp_func[i].token)); 45 return sp_func[i].func(ptr + strlen(sp_func[i].token));
44 } 46 }
45 } 47 }
46 sp_log_err("config", "Invalid configuration section '%s'.", line); 48 sp_log_err("config", "Invalid configuration section '%s' on line %zu.", line, sp_line_no);
47 return -1; 49 return -1;
48} 50}
49 51
@@ -61,7 +63,7 @@ int parse_int(char *restrict line, char *restrict keyword, void *retval) {
61 pefree(value, 1); 63 pefree(value, 1);
62 return consumed; 64 return consumed;
63 } else { 65 } else {
64 sp_log_err("error", "%s) is expecting a valid integer.", keyword); 66 sp_log_err("error", "%s) is expecting a valid integer on line %zu.", keyword, sp_line_no);
65 return -1; 67 return -1;
66 } 68 }
67} 69}
@@ -96,7 +98,7 @@ int parse_php_type(char *restrict line, char *restrict keyword, void *retval) {
96 pefree(value, 1); 98 pefree(value, 1);
97 sp_log_err("error", "%s) is expecting a valid php type ('false', 'true'," 99 sp_log_err("error", "%s) is expecting a valid php type ('false', 'true',"
98 " 'array'. 'object', 'long', 'double', 'null', 'resource', 'reference'," 100 " 'array'. 'object', 'long', 'double', 'null', 'resource', 'reference',"
99 " 'undef').", keyword); 101 " 'undef') on line %zu.", keyword, sp_line_no);
100 return -1; 102 return -1;
101 } 103 }
102 pefree(value, 1); 104 pefree(value, 1);
@@ -130,7 +132,7 @@ int parse_cidr(char *restrict line, char *restrict keyword, void *retval) {
130 *(sp_cidr **)retval = cidr; 132 *(sp_cidr **)retval = cidr;
131 return consumed; 133 return consumed;
132 } else { 134 } else {
133 sp_log_err("config", "%s doesn't contain a valid cidr.", line); 135 sp_log_err("config", "%s doesn't contain a valid cidr on line %zu.", line, sp_line_no);
134 return -1; 136 return -1;
135 } 137 }
136} 138}
@@ -148,7 +150,7 @@ int parse_regexp(char *restrict line, char *restrict keyword, void *retval) {
148 pcre *compiled_re = sp_pcre_compile(value, PCRE_CASELESS, &pcre_error, 150 pcre *compiled_re = sp_pcre_compile(value, PCRE_CASELESS, &pcre_error,
149 &pcre_error_offset, NULL); 151 &pcre_error_offset, NULL);
150 if (NULL == compiled_re) { 152 if (NULL == compiled_re) {
151 sp_log_err("config", "Failed to compile '%s': %s.", value, pcre_error); 153 sp_log_err("config", "Failed to compile '%s': %s on line %zu.", value, pcre_error, sp_line_no);
152 } else { 154 } else {
153 *(pcre **)retval = compiled_re; 155 *(pcre **)retval = compiled_re;
154 return consumed; 156 return consumed;
@@ -158,8 +160,8 @@ int parse_regexp(char *restrict line, char *restrict keyword, void *retval) {
158 if (NULL != closing_paren) { 160 if (NULL != closing_paren) {
159 closing_paren[0] = '\0'; 161 closing_paren[0] = '\0';
160 } 162 }
161 sp_log_err("config", "'%s)' is expecting a valid regexp, and not '%s'.", 163 sp_log_err("config", "'%s)' is expecting a valid regexp, and not '%s' on line %zu.",
162 keyword, line); 164 keyword, line, sp_line_no);
163 return -1; 165 return -1;
164} 166}
165 167
@@ -167,6 +169,7 @@ int sp_parse_config(const char *conf_file) {
167 FILE *fd = fopen(conf_file, "r"); 169 FILE *fd = fopen(conf_file, "r");
168 char *lineptr = NULL; 170 char *lineptr = NULL;
169 size_t n = 0; 171 size_t n = 0;
172 sp_line_no = 1;
170 173
171 if (fd == NULL) { 174 if (fd == NULL) {
172 sp_log_err("config", "Could not open configuration file %s : %s", conf_file, 175 sp_log_err("config", "Could not open configuration file %s : %s", conf_file,
@@ -187,6 +190,7 @@ int sp_parse_config(const char *conf_file) {
187 free(lineptr); 190 free(lineptr);
188 lineptr = NULL; 191 lineptr = NULL;
189 n = 0; 192 n = 0;
193 sp_line_no++;
190 } 194 }
191 fclose(fd); 195 fclose(fd);
192 return SUCCESS; 196 return SUCCESS;