[core] inline array as part of data_array value
(instead of value being (array *))
This commit is contained in:
parent
6eb34ef5ab
commit
c2238256e2
41
src/array.c
41
src/array.c
|
@ -29,33 +29,32 @@ array *array_init(void) {
|
|||
return a;
|
||||
}
|
||||
|
||||
array *array_init_array(const array * const src) {
|
||||
array *a = array_init();
|
||||
|
||||
if (0 == src->size) return a;
|
||||
|
||||
a->used = src->used;
|
||||
a->size = src->size;
|
||||
|
||||
a->data = calloc(src->size, sizeof(*src->data));
|
||||
force_assert(NULL != a->data);
|
||||
for (uint32_t i = 0; i < src->used; ++i) {
|
||||
a->data[i] = src->data[i]->fn->copy(src->data[i]);
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
void array_free(array * const a) {
|
||||
if (!a) return;
|
||||
|
||||
void array_free_data(array * const a) {
|
||||
data_unset ** const data = a->data;
|
||||
const uint32_t sz = a->size;
|
||||
for (uint32_t i = 0; i < sz; ++i) {
|
||||
if (data[i]) data[i]->fn->free(data[i]);
|
||||
}
|
||||
free(data);
|
||||
}
|
||||
|
||||
if (data) free(data);
|
||||
void array_copy_array(array * const dst, const array * const src) {
|
||||
array_free_data(dst);
|
||||
if (0 == src->size) return;
|
||||
|
||||
dst->used = src->used;
|
||||
dst->size = src->size;
|
||||
|
||||
dst->data = calloc(src->size, sizeof(*src->data));
|
||||
force_assert(NULL != dst->data);
|
||||
for (uint32_t i = 0; i < src->used; ++i) {
|
||||
dst->data[i] = src->data[i]->fn->copy(src->data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void array_free(array * const a) {
|
||||
if (!a) return;
|
||||
array_free_data(a);
|
||||
free(a);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ data_string *data_string_init(void);
|
|||
typedef struct {
|
||||
DATA_UNSET;
|
||||
|
||||
array *value;
|
||||
array value;
|
||||
} data_array;
|
||||
|
||||
data_array *data_array_init(void);
|
||||
|
@ -57,8 +57,10 @@ __attribute_returns_nonnull__
|
|||
array *array_init(void);
|
||||
|
||||
__attribute_cold__
|
||||
__attribute_returns_nonnull__
|
||||
array *array_init_array(const array *a);
|
||||
void array_copy_array(array *dst, const array *src);
|
||||
|
||||
__attribute_cold__
|
||||
void array_free_data(array *a);
|
||||
|
||||
void array_free(array *a);
|
||||
|
||||
|
|
|
@ -54,8 +54,8 @@ int config_insert_values_internal(server *srv, const array *ca, const config_val
|
|||
size_t j;
|
||||
const data_array *da = (const data_array *)du;
|
||||
|
||||
for (j = 0; j < da->value->used; j++) {
|
||||
data_unset *ds = da->value->data[j];
|
||||
for (j = 0; j < da->value.used; j++) {
|
||||
data_unset *ds = da->value.data[j];
|
||||
if (ds->type == TYPE_STRING || ds->type == TYPE_INTEGER || ds->type == TYPE_ARRAY) {
|
||||
array_insert_unique(cv[i].destination, ds->fn->copy(ds));
|
||||
} else {
|
||||
|
|
|
@ -95,8 +95,8 @@ static data_unset *configparser_merge_data(data_unset *op1, const data_unset *op
|
|||
((data_integer *)op1)->value += ((data_integer *)op2)->value;
|
||||
break;
|
||||
case TYPE_ARRAY: {
|
||||
array *dst = ((data_array *)op1)->value;
|
||||
array *src = ((data_array *)op2)->value;
|
||||
array *dst = &((data_array *)op1)->value;
|
||||
array *src = &((data_array *)op2)->value;
|
||||
data_unset *du;
|
||||
size_t i;
|
||||
|
||||
|
@ -341,8 +341,7 @@ value(A) ::= INTEGER(B). {
|
|||
}
|
||||
value(A) ::= array(B). {
|
||||
A = (data_unset *)data_array_init();
|
||||
array_free(((data_array *)(A))->value);
|
||||
((data_array *)(A))->value = B;
|
||||
array_copy_array(&((data_array *)(A))->value, B);
|
||||
B = NULL;
|
||||
}
|
||||
array(A) ::= LPARAN RPARAN. {
|
||||
|
|
|
@ -11,8 +11,7 @@ static data_unset *data_array_copy(const data_unset *s) {
|
|||
data_array *ds = data_array_init();
|
||||
|
||||
if (!buffer_is_empty(&src->key)) buffer_copy_buffer(&ds->key, &src->key);
|
||||
array_free(ds->value);
|
||||
ds->value = array_init_array(src->value);
|
||||
array_copy_array(&ds->value, &src->value);
|
||||
return (data_unset *)ds;
|
||||
}
|
||||
|
||||
|
@ -20,7 +19,7 @@ static void data_array_free(data_unset *d) {
|
|||
data_array *ds = (data_array *)d;
|
||||
|
||||
free(ds->key.ptr);
|
||||
array_free(ds->value);
|
||||
array_free_data(&ds->value);
|
||||
|
||||
free(d);
|
||||
}
|
||||
|
@ -38,7 +37,7 @@ __attribute_cold__
|
|||
static void data_array_print(const data_unset *d, int depth) {
|
||||
data_array *ds = (data_array *)d;
|
||||
|
||||
array_print(ds->value, depth);
|
||||
array_print(&ds->value, depth);
|
||||
}
|
||||
|
||||
data_array *data_array_init(void) {
|
||||
|
@ -53,8 +52,6 @@ data_array *data_array_init(void) {
|
|||
ds = calloc(1, sizeof(*ds));
|
||||
force_assert(NULL != ds);
|
||||
|
||||
ds->value = array_init();
|
||||
|
||||
ds->type = TYPE_ARRAY;
|
||||
ds->fn = &fn;
|
||||
|
||||
|
|
|
@ -20,8 +20,7 @@ static data_unset *data_config_copy(const data_unset *s) {
|
|||
if (!buffer_is_empty(&src->key)) buffer_copy_buffer(&ds->key, &src->key);
|
||||
buffer_copy_buffer(ds->comp_tag, src->comp_tag);
|
||||
buffer_copy_buffer(ds->comp_key, src->comp_key);
|
||||
array_free(ds->value);
|
||||
ds->value = array_init_array(src->value);
|
||||
array_copy_array(ds->value, src->value);
|
||||
return (data_unset *)ds;
|
||||
}
|
||||
|
||||
|
|
|
@ -1185,7 +1185,7 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const data_unset *du
|
|||
|
||||
if (NULL == da) return 1;
|
||||
|
||||
if (da->type != TYPE_ARRAY || !array_is_kvarray(da->value)) {
|
||||
if (da->type != TYPE_ARRAY || !array_is_kvarray(&da->value)) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "s",
|
||||
"unexpected value for xxxxx.server; expected "
|
||||
"( \"ext\" => ( \"backend-label\" => ( \"key\" => \"value\" )))");
|
||||
|
@ -1206,8 +1206,8 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const data_unset *du
|
|||
* "<ext>" => ( ... ) )
|
||||
*/
|
||||
|
||||
for (size_t j = 0; j < da->value->used; ++j) {
|
||||
data_array *da_ext = (data_array *)da->value->data[j];
|
||||
for (size_t j = 0; j < da->value.used; ++j) {
|
||||
data_array *da_ext = (data_array *)da->value.data[j];
|
||||
|
||||
/*
|
||||
* da_ext->key == name of the extension
|
||||
|
@ -1221,8 +1221,8 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const data_unset *du
|
|||
* "<ext>" => ... )
|
||||
*/
|
||||
|
||||
for (size_t n = 0; n < da_ext->value->used; ++n) {
|
||||
data_array *da_host = (data_array *)da_ext->value->data[n];
|
||||
for (size_t n = 0; n < da_ext->value.used; ++n) {
|
||||
data_array *da_host = (data_array *)da_ext->value.data[n];
|
||||
|
||||
config_values_t fcv[] = {
|
||||
{ "host", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 0 */
|
||||
|
@ -1256,7 +1256,7 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const data_unset *du
|
|||
};
|
||||
unsigned short host_mode = GW_RESPONDER;
|
||||
|
||||
if (da_host->type != TYPE_ARRAY || !array_is_kvany(da_host->value)){
|
||||
if (da_host->type != TYPE_ARRAY || !array_is_kvany(&da_host->value)){
|
||||
log_error_write(srv, __FILE__, __LINE__, "SBS",
|
||||
"unexpected value for gw.server near [",
|
||||
&da_host->key, "](string); expected ( \"ext\" => ( \"backend-label\" => ( \"key\" => \"value\" )))");
|
||||
|
@ -1308,15 +1308,15 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const data_unset *du
|
|||
fcv[21].destination = host->xsendfile_docroot;
|
||||
fcv[22].destination = &(host->tcp_fin_propagate);
|
||||
|
||||
if (0 != config_insert_values_internal(srv, da_host->value, fcv, T_CONFIG_SCOPE_CONNECTION)) {
|
||||
if (0 != config_insert_values_internal(srv, &da_host->value, fcv, T_CONFIG_SCOPE_CONNECTION)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
for (size_t m = 0; m < da_host->value->used; ++m) {
|
||||
if (NULL != strchr(da_host->value->data[m]->key.ptr, '_')) {
|
||||
for (size_t m = 0; m < da_host->value.used; ++m) {
|
||||
if (NULL != strchr(da_host->value.data[m]->key.ptr, '_')) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "sb",
|
||||
"incorrect directive contains underscore ('_') instead of dash ('-'):",
|
||||
&da_host->value->data[m]->key);
|
||||
&da_host->value.data[m]->key);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -314,7 +314,7 @@ SETDEFAULTS_FUNC(mod_auth_set_defaults) {
|
|||
/* no auth.require for this section */
|
||||
if (NULL == (da = (const data_array *)array_get_element_klen(config->value, CONST_STR_LEN("auth.require")))) continue;
|
||||
|
||||
if (da->type != TYPE_ARRAY || !array_is_kvarray(da->value)) {
|
||||
if (da->type != TYPE_ARRAY || !array_is_kvarray(&da->value)) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "ss",
|
||||
"unexpected value for auth.require; expected ",
|
||||
"auth.require = ( \"urlpath\" => ( \"option\" => \"value\" ) )");
|
||||
|
@ -322,15 +322,15 @@ SETDEFAULTS_FUNC(mod_auth_set_defaults) {
|
|||
}
|
||||
|
||||
|
||||
for (n = 0; n < da->value->used; n++) {
|
||||
for (n = 0; n < da->value.used; n++) {
|
||||
size_t m;
|
||||
data_array *da_file = (data_array *)da->value->data[n];
|
||||
data_array *da_file = (data_array *)da->value.data[n];
|
||||
const buffer *method = NULL, *realm = NULL, *require = NULL;
|
||||
const http_auth_scheme_t *auth_scheme;
|
||||
buffer *algos = NULL;
|
||||
int algorithm = HTTP_AUTH_DIGEST_SESS;
|
||||
|
||||
if (!array_is_kvstring(da_file->value)) {
|
||||
if (!array_is_kvstring(&da_file->value)) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "ss",
|
||||
"unexpected value for auth.require; expected ",
|
||||
"auth.require = ( \"urlpath\" => ( \"option\" => \"value\" ) )");
|
||||
|
@ -338,9 +338,9 @@ SETDEFAULTS_FUNC(mod_auth_set_defaults) {
|
|||
return HANDLER_ERROR;
|
||||
}
|
||||
|
||||
for (m = 0; m < da_file->value->used; m++) {
|
||||
if (da_file->value->data[m]->type == TYPE_STRING) {
|
||||
data_string *ds = (data_string *)da_file->value->data[m];
|
||||
for (m = 0; m < da_file->value.used; m++) {
|
||||
if (da_file->value.data[m]->type == TYPE_STRING) {
|
||||
data_string *ds = (data_string *)da_file->value.data[m];
|
||||
if (buffer_is_equal_string(&ds->key, CONST_STR_LEN("method"))) {
|
||||
method = &ds->value;
|
||||
} else if (buffer_is_equal_string(&ds->key, CONST_STR_LEN("realm"))) {
|
||||
|
@ -353,7 +353,7 @@ SETDEFAULTS_FUNC(mod_auth_set_defaults) {
|
|||
log_error_write(srv, __FILE__, __LINE__, "ssbs",
|
||||
"the field is unknown in:",
|
||||
"auth.require = ( \"...\" => ( ..., -> \"",
|
||||
&da_file->value->data[m]->key,
|
||||
&da_file->value.data[m]->key,
|
||||
"\" <- => \"...\" ) )");
|
||||
|
||||
return HANDLER_ERROR;
|
||||
|
@ -362,7 +362,7 @@ SETDEFAULTS_FUNC(mod_auth_set_defaults) {
|
|||
log_error_write(srv, __FILE__, __LINE__, "ssbs",
|
||||
"a string was expected for:",
|
||||
"auth.require = ( \"...\" => ( ..., -> \"",
|
||||
&da_file->value->data[m]->key,
|
||||
&da_file->value.data[m]->key,
|
||||
"\" <- => \"...\" ) )");
|
||||
|
||||
return HANDLER_ERROR;
|
||||
|
|
|
@ -277,9 +277,9 @@ SETDEFAULTS_FUNC(mod_dirlisting_set_defaults) {
|
|||
}
|
||||
|
||||
if (NULL != (du_excludes = array_get_element_klen(config->value, CONST_STR_LEN(CONFIG_EXCLUDE)))) {
|
||||
array *excludes_list;
|
||||
const array *excludes_list;
|
||||
|
||||
excludes_list = ((const data_array*)du_excludes)->value;
|
||||
excludes_list = &((const data_array*)du_excludes)->value;
|
||||
|
||||
if (du_excludes->type != TYPE_ARRAY || !array_is_vlist(excludes_list)) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "s",
|
||||
|
|
|
@ -1281,9 +1281,10 @@ SETDEFAULTS_FUNC(mod_openssl_set_defaults)
|
|||
if (!buffer_string_is_empty(b))
|
||||
buffer_copy_buffer(s->ssl_cipher_list, b);
|
||||
}
|
||||
s->ssl_conf_cmd = (0 == i)
|
||||
? array_init()
|
||||
: array_init_array(p->config_storage[0]->ssl_conf_cmd);
|
||||
s->ssl_conf_cmd = array_init();
|
||||
if (0 != i)
|
||||
array_copy_array(s->ssl_conf_cmd,
|
||||
p->config_storage[0]->ssl_conf_cmd);
|
||||
s->ssl_acme_tls_1 = buffer_init();
|
||||
|
||||
cv[0].destination = &(s->ssl_log_noise);
|
||||
|
|
|
@ -252,19 +252,19 @@ SETDEFAULTS_FUNC(mod_proxy_set_defaults) {
|
|||
&& !buffer_is_equal_string(&ds->value, CONST_STR_LEN("0"));
|
||||
continue;
|
||||
}
|
||||
if (da->type != TYPE_ARRAY || !array_is_kvstring(da->value)) {
|
||||
if (da->type != TYPE_ARRAY || !array_is_kvstring(&da->value)) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "sb",
|
||||
"unexpected value for proxy.header; expected ( \"param\" => ( \"key\" => \"value\" ) ) near key", &da->key);
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
if (buffer_is_equal_string(&da->key, CONST_STR_LEN("map-urlpath"))) {
|
||||
s->header.urlpaths = da->value;
|
||||
s->header.urlpaths = &da->value;
|
||||
}
|
||||
else if (buffer_is_equal_string(&da->key, CONST_STR_LEN("map-host-request"))) {
|
||||
s->header.hosts_request = da->value;
|
||||
s->header.hosts_request = &da->value;
|
||||
}
|
||||
else if (buffer_is_equal_string(&da->key, CONST_STR_LEN("map-host-response"))) {
|
||||
s->header.hosts_response = da->value;
|
||||
s->header.hosts_response = &da->value;
|
||||
}
|
||||
else {
|
||||
log_error_write(srv, __FILE__, __LINE__, "sb",
|
||||
|
|
|
@ -91,14 +91,14 @@ SETDEFAULTS_FUNC(mod_redirect_set_defaults) {
|
|||
|
||||
da = (const data_array *)du;
|
||||
|
||||
if (du->type != TYPE_ARRAY || !array_is_kvstring(da->value)) {
|
||||
if (du->type != TYPE_ARRAY || !array_is_kvstring(&da->value)) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "s",
|
||||
"unexpected value for url.redirect; expected list of \"regex\" => \"redirect\"");
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
|
||||
for (j = 0; j < da->value->used; j++) {
|
||||
data_string *ds = (data_string *)da->value->data[j];
|
||||
for (j = 0; j < da->value.used; j++) {
|
||||
data_string *ds = (data_string *)da->value.data[j];
|
||||
if (srv->srvconf.http_url_normalize) {
|
||||
pcre_keyvalue_burl_normalize_key(&ds->key, srv->tmp_buf);
|
||||
pcre_keyvalue_burl_normalize_value(&ds->value, srv->tmp_buf);
|
||||
|
|
|
@ -76,14 +76,14 @@ static int parse_config_entry(server *srv, array *ca, pcre_keyvalue_buffer *kvb,
|
|||
if (NULL != da) {
|
||||
size_t j;
|
||||
|
||||
if (da->type != TYPE_ARRAY || !array_is_kvstring(da->value)) {
|
||||
if (da->type != TYPE_ARRAY || !array_is_kvstring(&da->value)) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "SSS",
|
||||
"unexpected value for ", option, "; expected list of \"regex\" => \"subst\"");
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
|
||||
for (j = 0; j < da->value->used; j++) {
|
||||
data_string *ds = (data_string *)da->value->data[j];
|
||||
for (j = 0; j < da->value.used; j++) {
|
||||
data_string *ds = (data_string *)da->value.data[j];
|
||||
if (srv->srvconf.http_url_normalize) {
|
||||
pcre_keyvalue_burl_normalize_key(&ds->key, srv->tmp_buf);
|
||||
pcre_keyvalue_burl_normalize_value(&ds->value, srv->tmp_buf);
|
||||
|
|
Loading…
Reference in New Issue