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