xref: /lighttpd1.4/src/array.h (revision 70b5d729)
1 #ifndef ARRAY_H
2 #define ARRAY_H
3 #include "first.h"
4 
5 #include "buffer.h"
6 
7 struct data_unset; /* declaration */
8 
9 struct data_methods {
10 	void (*reset)(struct data_unset *p); \
11 	struct data_unset *(*copy)(const struct data_unset *src); \
12 	void (*free)(struct data_unset *p); \
13 	int (*insert_dup)(struct data_unset *dst, struct data_unset *src); \
14 	void (*print)(const struct data_unset *p, int depth);
15 };
16 
17 typedef enum { TYPE_UNSET, TYPE_STRING, TYPE_OTHER, TYPE_ARRAY, TYPE_INTEGER, TYPE_DONOTUSE, TYPE_CONFIG } data_type_t;
18 #define DATA_UNSET \
19 	buffer *key; \
20 	data_type_t type; \
21 	const struct data_methods *fn /* function table */
22 
23 typedef struct data_unset {
24 	DATA_UNSET;
25 } data_unset;
26 
27 typedef struct {
28 	data_unset  **data;
29 
30 	uint32_t *sorted;
31 
32 	uint32_t used; /* <= INT32_MAX */
33 	uint32_t size;
34 } array;
35 
36 typedef struct {
37 	DATA_UNSET;
38 
39 	buffer *value;
40 } data_string;
41 
42 data_string *data_string_init(void);
43 
44 typedef struct {
45 	DATA_UNSET;
46 
47 	array *value;
48 } data_array;
49 
50 data_array *data_array_init(void);
51 
52 typedef struct {
53 	DATA_UNSET;
54 
55 	int value;
56 } data_integer;
57 
58 data_integer *data_integer_init(void);
59 
60 array *array_init(void);
61 
62 __attribute_cold__
63 array *array_init_array(const array *a);
64 
65 void array_free(array *a);
66 
67 __attribute_cold__
68 void array_reset(array *a);
69 
70 __attribute_hot__
71 void array_reset_data_strings(array *a);
72 
73 __attribute_cold__
74 void array_insert_unique(array *a, data_unset *entry);
75 
76 __attribute_cold__
77 data_unset *array_pop(array *a); /* only works on "simple" lists with autogenerated keys */
78 
79 __attribute_cold__
80 __attribute_pure__
81 int array_is_vlist(const array *a);
82 
83 __attribute_cold__
84 __attribute_pure__
85 int array_is_kvany(const array *a);
86 
87 __attribute_cold__
88 __attribute_pure__
89 int array_is_kvarray(const array *a);
90 
91 __attribute_cold__
92 __attribute_pure__
93 int array_is_kvstring(const array *a);
94 
95 #define array_get_element(a, key) array_get_element_klen((a), (key), sizeof(key)-1)
96 __attribute_pure__
97 data_unset *array_get_element_klen(const array *a, const char *key, size_t klen);
98 
99 __attribute_cold__
100 data_unset *array_extract_element_klen(array *a, const char *key, size_t klen); /* removes found entry from array */
101 
102 int * array_get_int_ptr(array *a, const char *k, size_t klen);
103 
104 __attribute_hot__
105 buffer * array_get_buf_ptr(array *a, const char *k, size_t klen);
106 
107 void array_insert_value(array *a, const char *v, size_t vlen);
108 
109 static inline void array_set_key_value(array * const a, const char * const k, const size_t klen, const char * const v, const size_t vlen);
110 
111 static inline void array_set_key_value(array * const a, const char * const k, const size_t klen, const char * const v, const size_t vlen) {
112     buffer_copy_string_len(array_get_buf_ptr(a, k, klen), v, vlen);
113 }
114 
115 __attribute_cold__
116 void array_replace(array *a, data_unset *entry);
117 
118 __attribute_cold__
119 int array_print(const array *a, int depth);
120 
121 __attribute_cold__
122 void array_print_indent(int depth);
123 
124 __attribute_cold__
125 __attribute_pure__
126 size_t array_get_max_key_length(const array *a);
127 
128 __attribute_pure__
129 data_unset * array_match_key_prefix_klen (const array * const a, const char * const s, const size_t slen);
130 
131 __attribute_pure__
132 data_unset * array_match_key_prefix_nc_klen (const array * const a, const char * const s, const size_t slen);
133 
134 __attribute_pure__
135 data_unset * array_match_key_prefix (const array * const a, const buffer * const b);
136 
137 __attribute_pure__
138 data_unset * array_match_key_prefix_nc (const array * const a, const buffer * const b);
139 
140 __attribute_pure__
141 const buffer * array_match_value_prefix (const array * const a, const buffer * const b);
142 
143 __attribute_pure__
144 const buffer * array_match_value_prefix_nc (const array * const a, const buffer * const b);
145 
146 __attribute_pure__
147 data_unset * array_match_key_suffix (const array * const a, const buffer * const b);
148 
149 __attribute_pure__
150 data_unset * array_match_key_suffix_nc (const array * const a, const buffer * const b);
151 
152 __attribute_pure__
153 const buffer * array_match_value_suffix (const array * const a, const buffer * const b);
154 
155 __attribute_pure__
156 const buffer * array_match_value_suffix_nc (const array * const a, const buffer * const b);
157 
158 __attribute_pure__
159 data_unset * array_match_path_or_ext (const array * const a, const buffer * const b);
160 
161 #endif
162