1 #ifndef ARRAY_H 2 #define ARRAY_H 3 #include "first.h" 4 5 #ifdef HAVE_PCRE_H 6 # include <pcre.h> 7 #endif 8 9 #include "buffer.h" 10 #include "vector.h" 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_OTHER, 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 36 size_t used; /* <= SSIZE_MAX */ 37 size_t size; 38 39 size_t unique_ndx; 40 } array; 41 42 typedef struct { 43 DATA_UNSET; 44 45 buffer *value; 46 } data_string; 47 48 data_string *data_string_init(void); 49 data_string *data_response_init(void); 50 51 typedef struct { 52 DATA_UNSET; 53 54 array *value; 55 } data_array; 56 57 data_array *data_array_init(void); 58 59 /** 60 * possible compare ops in the configfile parser 61 */ 62 typedef enum { 63 CONFIG_COND_UNSET, 64 CONFIG_COND_EQ, /** == */ 65 CONFIG_COND_MATCH, /** =~ */ 66 CONFIG_COND_NE, /** != */ 67 CONFIG_COND_NOMATCH, /** !~ */ 68 CONFIG_COND_ELSE /** (always true if reached) */ 69 } config_cond_t; 70 71 /** 72 * possible fields to match against 73 */ 74 typedef enum { 75 COMP_UNSET, 76 COMP_SERVER_SOCKET, 77 COMP_HTTP_URL, 78 COMP_HTTP_HOST, 79 COMP_HTTP_REFERER, /*(subsumed by COMP_HTTP_REQUEST_HEADER)*/ 80 COMP_HTTP_USER_AGENT, 81 COMP_HTTP_LANGUAGE, 82 COMP_HTTP_COOKIE, /*(subsumed by COMP_HTTP_REQUEST_HEADER)*/ 83 COMP_HTTP_REMOTE_IP, 84 COMP_HTTP_QUERY_STRING, 85 COMP_HTTP_SCHEME, 86 COMP_HTTP_REQUEST_METHOD, 87 COMP_HTTP_REQUEST_HEADER, 88 89 COMP_LAST_ELEMENT 90 } comp_key_t; 91 92 /* $HTTP["host"] == "incremental.home.kneschke.de" { ... } 93 * for print: comp_key op string 94 * for compare: comp cond string/regex 95 */ 96 97 typedef struct data_config data_config; 98 DEFINE_TYPED_VECTOR_NO_RELEASE(config_weak, data_config*); 99 100 struct data_config { 101 DATA_UNSET; 102 103 array *value; 104 105 buffer *comp_tag; 106 buffer *comp_key; 107 comp_key_t comp; 108 109 config_cond_t cond; 110 buffer *op; 111 112 int context_ndx; /* more or less like an id */ 113 vector_config_weak children; 114 /* nested */ 115 data_config *parent; 116 /* for chaining only */ 117 data_config *prev; 118 data_config *next; 119 120 buffer *string; 121 #ifdef HAVE_PCRE_H 122 pcre *regex; 123 pcre_extra *regex_study; 124 #endif 125 }; 126 127 data_config *data_config_init(void); 128 129 typedef struct { 130 DATA_UNSET; 131 132 int value; 133 } data_integer; 134 135 data_integer *data_integer_init(void); 136 137 typedef struct { 138 DATA_UNSET; 139 140 buffer *host; 141 142 unsigned short port; 143 144 time_t disable_ts; 145 int is_disabled; 146 size_t balance; 147 148 int usage; /* fair-balancing needs the no. of connections active on this host */ 149 int last_used_ndx; /* round robin */ 150 } data_fastcgi; 151 152 data_fastcgi *data_fastcgi_init(void); 153 154 array *array_init(void); 155 array *array_init_array(array *a); 156 void array_free(array *a); 157 void array_reset(array *a); 158 void array_insert_unique(array *a, data_unset *entry); 159 data_unset *array_pop(array *a); /* only works on "simple" lists with autogenerated keys */ 160 int array_print(array *a, int depth); 161 data_unset *array_get_unused_element(array *a, data_type_t t); 162 data_unset *array_get_element(array *a, const char *key); 163 data_unset *array_extract_element(array *a, const char *key); /* removes found entry from array */ 164 void array_set_key_value(array *hdrs, const char *key, size_t key_len, const char *value, size_t val_len); 165 void array_replace(array *a, data_unset *entry); 166 int array_strcasecmp(const char *a, size_t a_len, const char *b, size_t b_len); 167 void array_print_indent(int depth); 168 size_t array_get_max_key_length(array *a); 169 170 #endif 171