[mod_auth] require digest uri= match original URI
[lighttpd.git] / src / data_string.c
blob14f58de05c99329a2ee18cb6233b788ae31e15df
1 #include "first.h"
3 #include "array.h"
5 #include <string.h>
6 #include <stdio.h>
7 #include <stdlib.h>
9 static data_unset *data_string_copy(const data_unset *s) {
10 data_string *src = (data_string *)s;
11 data_string *ds = data_string_init();
13 buffer_copy_buffer(ds->key, src->key);
14 buffer_copy_buffer(ds->value, src->value);
15 ds->is_index_key = src->is_index_key;
16 return (data_unset *)ds;
19 static void data_string_free(data_unset *d) {
20 data_string *ds = (data_string *)d;
22 buffer_free(ds->key);
23 buffer_free(ds->value);
25 free(d);
28 static void data_string_reset(data_unset *d) {
29 data_string *ds = (data_string *)d;
31 /* reused array elements */
32 buffer_reset(ds->key);
33 buffer_reset(ds->value);
36 static int data_string_insert_dup(data_unset *dst, data_unset *src) {
37 data_string *ds_dst = (data_string *)dst;
38 data_string *ds_src = (data_string *)src;
40 if (!buffer_is_empty(ds_dst->value)) {
41 buffer_append_string_len(ds_dst->value, CONST_STR_LEN(", "));
42 buffer_append_string_buffer(ds_dst->value, ds_src->value);
43 } else {
44 buffer_copy_buffer(ds_dst->value, ds_src->value);
47 src->fn->free(src);
49 return 0;
52 static void data_string_print(const data_unset *d, int depth) {
53 data_string *ds = (data_string *)d;
54 size_t i, len;
55 UNUSED(depth);
57 /* empty and uninitialized strings */
58 if (buffer_string_is_empty(ds->value)) {
59 fputs("\"\"", stdout);
60 return;
63 /* print out the string as is, except prepend " with backslash */
64 putc('"', stdout);
65 len = buffer_string_length(ds->value);
66 for (i = 0; i < len; i++) {
67 unsigned char c = ds->value->ptr[i];
68 if (c == '"') {
69 fputs("\\\"", stdout);
70 } else {
71 putc(c, stdout);
74 putc('"', stdout);
78 data_string *data_string_init(void) {
79 static const struct data_methods fn = {
80 data_string_reset,
81 data_string_copy,
82 data_string_free,
83 data_string_insert_dup,
84 data_string_print,
86 data_string *ds;
88 ds = calloc(1, sizeof(*ds));
89 force_assert(NULL != ds);
91 ds->key = buffer_init();
92 ds->value = buffer_init();
94 ds->type = TYPE_STRING;
95 ds->fn = &fn;
97 return ds;