Browse Source

[core] buffer string in data_config

(instead of (buffer *))
personal/stbuehler/ci-build
Glenn Strauss 2 years ago
parent
commit
5aadcba456
  1. 12
      src/configfile-glue.c
  2. 4
      src/configfile.c
  3. 2
      src/configfile.h
  4. 6
      src/configparser.y
  5. 16
      src/data_config.c
  6. 2
      src/mod_rewrite.c
  7. 6
      src/network.c

12
src/configfile-glue.c

@ -233,7 +233,7 @@ static int config_addrstr_eq_remote_ip_mask(server *srv, const char *addrstr, in
return sock_addr_is_addr_eq_bits(&addr, rmt, nm_bits);
}
static int config_addrbuf_eq_remote_ip_mask(server *srv, buffer *string, char *nm_slash, sock_addr *rmt) {
static int config_addrbuf_eq_remote_ip_mask(server *srv, const buffer *string, char *nm_slash, sock_addr *rmt) {
char *err;
int nm_bits = strtol(nm_slash + 1, &err, 10);
size_t addrstrlen = (size_t)(nm_slash - string->ptr);
@ -364,7 +364,7 @@ static cond_result_t config_check_cond_nocache(server *srv, connection *con, con
case CONFIG_COND_EQ:
port = sock_addr_get_port(&srv_sock->addr);
if (0 == port) break;
ck_colon = strchr(dc->string->ptr, ':');
ck_colon = strchr(dc->string.ptr, ':');
val_colon = strchr(l->ptr, ':');
if (NULL != ck_colon && NULL == val_colon) {
@ -400,8 +400,8 @@ static cond_result_t config_check_cond_nocache(server *srv, connection *con, con
if ((dc->cond == CONFIG_COND_EQ ||
dc->cond == CONFIG_COND_NE) &&
(NULL != (nm_slash = strchr(dc->string->ptr, '/')))) {
switch (config_addrbuf_eq_remote_ip_mask(srv, dc->string, nm_slash, &con->dst_addr)) {
(NULL != (nm_slash = strchr(dc->string.ptr, '/')))) {
switch (config_addrbuf_eq_remote_ip_mask(srv, &dc->string, nm_slash, &con->dst_addr)) {
case 1: return (dc->cond == CONFIG_COND_EQ) ? COND_RESULT_TRUE : COND_RESULT_FALSE;
case 0: return (dc->cond == CONFIG_COND_EQ) ? COND_RESULT_FALSE : COND_RESULT_TRUE;
case -1: return COND_RESULT_FALSE; /*(error parsing configfile entry)*/
@ -449,12 +449,12 @@ static cond_result_t config_check_cond_nocache(server *srv, connection *con, con
if (con->conf.log_condition_handling) {
log_error_write(srv, __FILE__, __LINE__, "bsbsb", dc->comp_key,
"(", l, ") compare to ", dc->string);
"(", l, ") compare to ", &dc->string);
}
switch(dc->cond) {
case CONFIG_COND_NE:
case CONFIG_COND_EQ:
if (buffer_is_equal(l, dc->string)) {
if (buffer_is_equal(l, &dc->string)) {
return (dc->cond == CONFIG_COND_EQ) ? COND_RESULT_TRUE : COND_RESULT_FALSE;
} else {
return (dc->cond == CONFIG_COND_EQ) ? COND_RESULT_FALSE : COND_RESULT_TRUE;

4
src/configfile.c

@ -496,11 +496,11 @@ static int config_insert(server *srv) {
case CONFIG_COND_EQ:
/* (can use this routine as long as it does not perform
* any regex-specific normalization of first arg) */
pcre_keyvalue_burl_normalize_key(config->string, srv->tmp_buf);
pcre_keyvalue_burl_normalize_key(&config->string, srv->tmp_buf);
break;
case CONFIG_COND_NOMATCH:
case CONFIG_COND_MATCH:
pcre_keyvalue_burl_normalize_key(config->string, srv->tmp_buf);
pcre_keyvalue_burl_normalize_key(&config->string, srv->tmp_buf);
if (!data_config_pcre_compile(config)) {
ret = HANDLER_ERROR;
}

2
src/configfile.h

@ -72,7 +72,7 @@ struct data_config {
data_config *prev;
data_config *next;
buffer *string;
buffer string;
#ifdef HAVE_PCRE_H
void *regex;
struct pcre_extra *regex_study;

6
src/configparser.y

@ -463,8 +463,8 @@ condlines(A) ::= condlines(B) eols ELSE cond_else(C). {
buffer_copy_buffer(&C->key, &B->key);
C->comp = B->comp;
/*buffer_copy_buffer(C->comp_key, B->comp_key);*/
/*C->string = buffer_init_buffer(B->string);*/
pos = buffer_string_length(&C->key)-buffer_string_length(B->string)-2;
/*buffer_copy_buffer(&C->string, &B->string);*/
pos = buffer_string_length(&C->key)-buffer_string_length(&B->string)-2;
switch(B->cond) {
case CONFIG_COND_NE:
C->key.ptr[pos] = '='; /* opposite cond */
@ -693,7 +693,7 @@ context ::= DOLLAR SRVVARNAME(B) LBRACKET stringop(C) RBRACKET cond(E) expressio
}
}
dc->string = buffer_init_buffer(rvalue);
buffer_copy_buffer(&dc->string, rvalue);
if (ctx->ok) switch(E) {
case CONFIG_COND_NE:

16
src/data_config.c

@ -35,7 +35,7 @@ static void data_config_free(data_unset *d) {
array_free(ds->value);
vector_config_weak_clear(&ds->children);
if (ds->string) buffer_free(ds->string);
free(ds->string.ptr);
#ifdef HAVE_PCRE_H
if (ds->regex) pcre_free(ds->regex);
if (ds->regex_study) pcre_free(ds->regex_study);
@ -66,7 +66,7 @@ static void data_config_print(const data_unset *d, int depth) {
else {
if (ds->cond != CONFIG_COND_ELSE) {
fprintf(stdout, "$%s %s \"%s\" {\n",
ds->comp_key->ptr, ds->op, ds->string->ptr);
ds->comp_key->ptr, ds->op, ds->string.ptr);
} else {
fprintf(stdout, "{\n");
}
@ -110,7 +110,7 @@ static void data_config_print(const data_unset *d, int depth) {
if (0 != ds->context_ndx) {
if (ds->cond != CONFIG_COND_ELSE) {
fprintf(stdout, " # end of $%s %s \"%s\"",
ds->comp_key->ptr, ds->op, ds->string->ptr);
ds->comp_key->ptr, ds->op, ds->string.ptr);
} else {
fprintf(stdout, " # end of else");
}
@ -155,17 +155,17 @@ int data_config_pcre_compile(data_config *dc) {
if (dc->regex) pcre_free(dc->regex);
if (dc->regex_study) pcre_free(dc->regex_study);
dc->regex = pcre_compile(dc->string->ptr, 0, &errptr, &erroff, NULL);
dc->regex = pcre_compile(dc->string.ptr, 0, &errptr, &erroff, NULL);
if (NULL == dc->regex) {
fprintf(stderr, "parsing regex failed: %s -> %s at offset %d\n",
dc->string->ptr, errptr, erroff);
dc->string.ptr, errptr, erroff);
return 0;
}
dc->regex_study = pcre_study(dc->regex, 0, &errptr);
if (NULL == dc->regex_study && errptr != NULL) {
fprintf(stderr, "studying regex failed: %s -> %s\n",
dc->string->ptr, errptr);
dc->string.ptr, errptr);
return 0;
}
@ -173,11 +173,11 @@ int data_config_pcre_compile(data_config *dc) {
&captures);
if (0 != erroff) {
fprintf(stderr, "getting capture count for regex failed: %s\n",
dc->string->ptr);
dc->string.ptr);
return 0;
} else if (captures > 9) {
fprintf(stderr, "Too many captures in regex, use (?:...) instead of (...): %s\n",
dc->string->ptr);
dc->string.ptr);
return 0;
}
return 1;

2
src/mod_rewrite.c

@ -244,7 +244,7 @@ static handler_t process_rewrite_rules(server *srv, connection *con, plugin_data
return HANDLER_ERROR;
}
log_error_write(srv, __FILE__, __LINE__, "SbsSBS",
"ENDLESS LOOP IN rewrite-rule DETECTED ... aborting request, perhaps you want to use url.rewrite-once instead of url.rewrite-repeat ($", dc->comp_key, dc->op, "\"", dc->string, "\")");
"ENDLESS LOOP IN rewrite-rule DETECTED ... aborting request, perhaps you want to use url.rewrite-once instead of url.rewrite-repeat ($", dc->comp_key, dc->op, "\"", &dc->string, "\")");
return HANDLER_ERROR;
}

6
src/network.c

@ -487,16 +487,16 @@ int network_init(server *srv, int stdin_fd) {
if (dc->cond == CONFIG_COND_NE) {
socklen_t addr_len = sizeof(sock_addr);
sock_addr addr;
if (0 != network_host_parse_addr(srv, &addr, &addr_len, dc->string, srv->config_storage[i]->use_ipv6)) {
if (0 != network_host_parse_addr(srv, &addr, &addr_len, &dc->string, srv->config_storage[i]->use_ipv6)) {
return -1;
}
network_host_normalize_addr_str(dc->string, &addr);
network_host_normalize_addr_str(&dc->string, &addr);
continue;
}
if (dc->cond != CONFIG_COND_EQ) continue;
if (0 != network_server_init(srv, dc->string, i, -1)) return -1;
if (0 != network_server_init(srv, &dc->string, i, -1)) return -1;
}
if (srv->srvconf.systemd_socket_activation) {

Loading…
Cancel
Save