You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lighttpd1.4/src/data_string.c

104 lines
2.2 KiB
C

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "array.h"
static data_unset *data_string_copy(data_unset *s) {
data_string *src = (data_string *)s;
data_string *ds = data_string_init();
ds->key = buffer_init_buffer(src->key);
ds->value = buffer_init_buffer(src->value);
return (data_unset *)ds;
}
static void data_string_free(data_unset *d) {
data_string *ds = (data_string *)d;
buffer_free(ds->key);
buffer_free(ds->value);
free(d);
}
static void data_string_reset(data_unset *d) {
data_string *ds = (data_string *)d;
/* reused array elements */
buffer_reset(ds->key);
buffer_reset(ds->value);
}
static int data_string_insert_dup(data_unset *dst, data_unset *src) {
data_string *ds_dst = (data_string *)dst;
data_string *ds_src = (data_string *)src;
if (ds_dst->value->used) {
buffer_append_string(ds_dst->value, ", ");
buffer_append_string_buffer(ds_dst->value, ds_src->value);
} else {
buffer_copy_string_buffer(ds_dst->value, ds_src->value);
}
src->free(src);
return 0;
}
static int data_response_insert_dup(data_unset *dst, data_unset *src) {
data_string *ds_dst = (data_string *)dst;
data_string *ds_src = (data_string *)src;
if (ds_dst->value->used) {
buffer_append_string(ds_dst->value, "\r\n");
buffer_append_string_buffer(ds_dst->value, ds_dst->key);
buffer_append_string(ds_dst->value, ": ");
buffer_append_string_buffer(ds_dst->value, ds_src->value);
} else {
buffer_copy_string_buffer(ds_dst->value, ds_src->value);
}
src->free(src);
return 0;
}
static void data_string_print(data_unset *d, int depth) {
data_string *ds = (data_string *)d;
array_print_indent(depth);
fprintf(stderr, "{%s: %s}", ds->key->ptr, ds->value->used ? ds->value->ptr : "");
}
data_string *data_string_init(void) {
data_string *ds;
ds = calloc(1, sizeof(*ds));
assert(ds);
ds->key = buffer_init();
ds->value = buffer_init();
ds->copy = data_string_copy;
ds->free = data_string_free;
ds->reset = data_string_reset;
ds->insert_dup = data_string_insert_dup;
ds->print = data_string_print;
ds->type = TYPE_STRING;
return ds;
}
data_string *data_response_init(void) {
data_string *ds;
ds = data_string_init();
ds->insert_dup = data_response_insert_dup;
return ds;
}