2005-02-20 14:27:00 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "array.h"
|
|
|
|
|
2005-08-08 14:40:47 +00:00
|
|
|
static data_unset *data_config_copy(data_unset *s) {
|
|
|
|
data_config *src = (data_config *)s;
|
|
|
|
data_config *ds = data_config_init();
|
|
|
|
|
|
|
|
ds->key = buffer_init_buffer(src->key);
|
|
|
|
ds->comp_key = buffer_init_buffer(src->comp_key);
|
|
|
|
ds->value = array_init_array(src->value);
|
|
|
|
return (data_unset *)ds;
|
|
|
|
}
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
static void data_config_free(data_unset *d) {
|
|
|
|
data_config *ds = (data_config *)d;
|
|
|
|
|
|
|
|
buffer_free(ds->key);
|
|
|
|
buffer_free(ds->comp_key);
|
|
|
|
|
|
|
|
array_free(ds->value);
|
|
|
|
|
2005-08-08 13:48:33 +00:00
|
|
|
if (ds->string) buffer_free(ds->string);
|
2005-02-20 14:27:00 +00:00
|
|
|
#ifdef HAVE_PCRE_H
|
2005-08-08 13:48:33 +00:00
|
|
|
if (ds->regex) pcre_free(ds->regex);
|
|
|
|
if (ds->regex_study) pcre_free(ds->regex_study);
|
2005-02-20 14:27:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
free(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void data_config_reset(data_unset *d) {
|
|
|
|
data_config *ds = (data_config *)d;
|
|
|
|
|
|
|
|
/* reused array elements */
|
|
|
|
buffer_reset(ds->key);
|
|
|
|
buffer_reset(ds->comp_key);
|
|
|
|
array_reset(ds->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int data_config_insert_dup(data_unset *dst, data_unset *src) {
|
|
|
|
UNUSED(dst);
|
|
|
|
|
|
|
|
src->free(src);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-08 10:16:53 +00:00
|
|
|
static void data_config_print(data_unset *d, int depth) {
|
2005-02-20 14:27:00 +00:00
|
|
|
data_config *ds = (data_config *)d;
|
|
|
|
|
2005-08-08 10:16:53 +00:00
|
|
|
array_print_indent(depth);
|
|
|
|
fprintf(stderr, "{%s:\n", ds->key->ptr);
|
|
|
|
array_print(ds->value, depth + 1);
|
|
|
|
array_print_indent(depth);
|
|
|
|
fprintf(stderr, "}");
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data_config *data_config_init(void) {
|
|
|
|
data_config *ds;
|
|
|
|
|
|
|
|
ds = calloc(1, sizeof(*ds));
|
|
|
|
|
|
|
|
ds->key = buffer_init();
|
|
|
|
ds->comp_key = buffer_init();
|
|
|
|
ds->value = array_init();
|
|
|
|
|
2005-08-08 14:40:47 +00:00
|
|
|
ds->copy = data_config_copy;
|
2005-02-20 14:27:00 +00:00
|
|
|
ds->free = data_config_free;
|
|
|
|
ds->reset = data_config_reset;
|
|
|
|
ds->insert_dup = data_config_insert_dup;
|
|
|
|
ds->print = data_config_print;
|
|
|
|
ds->type = TYPE_CONFIG;
|
|
|
|
|
|
|
|
return ds;
|
|
|
|
}
|