Annotation of embedaddon/lighttpd/src/array.h, revision 1.1.1.2
1.1 misho 1: #ifndef ARRAY_H
2: #define ARRAY_H
1.1.1.2 ! misho 3: #include "first.h"
1.1 misho 4:
5: #ifdef HAVE_PCRE_H
6: # include <pcre.h>
7: #endif
8:
9: #include "buffer.h"
1.1.1.2 ! misho 10: #include "vector.h"
1.1 misho 11:
12: #include <stdlib.h>
13:
14: #define DATA_IS_STRING(x) (x->type == TYPE_STRING)
15:
16: typedef enum { TYPE_UNSET, TYPE_STRING, TYPE_COUNT, TYPE_ARRAY, TYPE_INTEGER, TYPE_FASTCGI, TYPE_CONFIG } data_type_t;
17: #define DATA_UNSET \
18: data_type_t type; \
19: buffer *key; \
20: int is_index_key; /* 1 if key is a array index (autogenerated keys) */ \
21: struct data_unset *(*copy)(const struct data_unset *src); \
22: void (* free)(struct data_unset *p); \
23: void (* reset)(struct data_unset *p); \
24: int (*insert_dup)(struct data_unset *dst, struct data_unset *src); \
25: void (*print)(const struct data_unset *p, int depth)
26:
27: typedef struct data_unset {
28: DATA_UNSET;
29: } data_unset;
30:
31: typedef struct {
32: data_unset **data;
33:
34: size_t *sorted;
35:
1.1.1.2 ! misho 36: size_t used; /* <= SSIZE_MAX */
1.1 misho 37: size_t size;
38:
39: size_t unique_ndx;
40: } array;
41:
42: typedef struct {
43: DATA_UNSET;
44:
45: int count;
46: } data_count;
47:
48: data_count *data_count_init(void);
49:
50: typedef struct {
51: DATA_UNSET;
52:
53: buffer *value;
54: } data_string;
55:
56: data_string *data_string_init(void);
57: data_string *data_response_init(void);
58:
59: typedef struct {
60: DATA_UNSET;
61:
62: array *value;
63: } data_array;
64:
65: data_array *data_array_init(void);
66:
67: /**
68: * possible compare ops in the configfile parser
69: */
70: typedef enum {
71: CONFIG_COND_UNSET,
72: CONFIG_COND_EQ, /** == */
73: CONFIG_COND_MATCH, /** =~ */
74: CONFIG_COND_NE, /** != */
75: CONFIG_COND_NOMATCH /** !~ */
76: } config_cond_t;
77:
78: /**
79: * possible fields to match against
80: */
81: typedef enum {
82: COMP_UNSET,
83: COMP_SERVER_SOCKET,
84: COMP_HTTP_URL,
85: COMP_HTTP_HOST,
86: COMP_HTTP_REFERER,
87: COMP_HTTP_USER_AGENT,
88: COMP_HTTP_LANGUAGE,
89: COMP_HTTP_COOKIE,
90: COMP_HTTP_REMOTE_IP,
91: COMP_HTTP_QUERY_STRING,
92: COMP_HTTP_SCHEME,
93: COMP_HTTP_REQUEST_METHOD,
94:
95: COMP_LAST_ELEMENT
96: } comp_key_t;
97:
98: /* $HTTP["host"] == "incremental.home.kneschke.de" { ... }
99: * for print: comp_key op string
100: * for compare: comp cond string/regex
101: */
102:
1.1.1.2 ! misho 103: typedef struct data_config data_config;
! 104: DEFINE_TYPED_VECTOR_NO_RELEASE(config_weak, data_config*);
! 105:
! 106: struct data_config {
1.1 misho 107: DATA_UNSET;
108:
109: array *value;
110:
111: buffer *comp_key;
112: comp_key_t comp;
113:
114: config_cond_t cond;
115: buffer *op;
116:
117: int context_ndx; /* more or less like an id */
1.1.1.2 ! misho 118: vector_config_weak children;
1.1 misho 119: /* nested */
120: data_config *parent;
121: /* for chaining only */
122: data_config *prev;
123: data_config *next;
124:
125: buffer *string;
126: #ifdef HAVE_PCRE_H
127: pcre *regex;
128: pcre_extra *regex_study;
129: #endif
130: };
131:
132: data_config *data_config_init(void);
133:
134: typedef struct {
135: DATA_UNSET;
136:
137: int value;
138: } data_integer;
139:
140: data_integer *data_integer_init(void);
141:
142: typedef struct {
143: DATA_UNSET;
144:
145: buffer *host;
146:
147: unsigned short port;
148:
149: time_t disable_ts;
150: int is_disabled;
151: size_t balance;
152:
153: int usage; /* fair-balancing needs the no. of connections active on this host */
154: int last_used_ndx; /* round robin */
155: } data_fastcgi;
156:
157: data_fastcgi *data_fastcgi_init(void);
158:
159: array *array_init(void);
160: array *array_init_array(array *a);
161: void array_free(array *a);
162: void array_reset(array *a);
1.1.1.2 ! misho 163: void array_insert_unique(array *a, data_unset *entry);
! 164: data_unset *array_pop(array *a); /* only works on "simple" lists with autogenerated keys */
1.1 misho 165: int array_print(array *a, int depth);
166: data_unset *array_get_unused_element(array *a, data_type_t t);
167: data_unset *array_get_element(array *a, const char *key);
1.1.1.2 ! misho 168: data_unset *array_extract_element(array *a, const char *key); /* removes found entry from array */
1.1 misho 169: void array_set_key_value(array *hdrs, const char *key, size_t key_len, const char *value, size_t val_len);
1.1.1.2 ! misho 170: void array_replace(array *a, data_unset *entry);
1.1 misho 171: int array_strcasecmp(const char *a, size_t a_len, const char *b, size_t b_len);
172: void array_print_indent(int depth);
173: size_t array_get_max_key_length(array *a);
174:
175: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>