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