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