2005-02-20 14:27:00 +00:00
|
|
|
#ifndef ARRAY_H
|
|
|
|
#define ARRAY_H
|
2016-03-19 15:14:35 +00:00
|
|
|
#include "first.h"
|
2009-10-11 14:31:42 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
#ifdef HAVE_PCRE_H
|
|
|
|
# include <pcre.h>
|
|
|
|
#endif
|
2009-10-11 14:31:42 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
#include "buffer.h"
|
2016-03-19 15:27:38 +00:00
|
|
|
#include "vector.h"
|
2005-02-20 14:27:00 +00:00
|
|
|
|
2009-10-11 14:31:42 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
#define DATA_IS_STRING(x) (x->type == TYPE_STRING)
|
|
|
|
|
|
|
|
typedef enum { TYPE_UNSET, TYPE_STRING, TYPE_COUNT, TYPE_ARRAY, TYPE_INTEGER, TYPE_FASTCGI, TYPE_CONFIG } data_type_t;
|
|
|
|
#define DATA_UNSET \
|
|
|
|
data_type_t type; \
|
|
|
|
buffer *key; \
|
2005-08-23 14:35:01 +00:00
|
|
|
int is_index_key; /* 1 if key is a array index (autogenerated keys) */ \
|
2005-08-08 16:36:51 +00:00
|
|
|
struct data_unset *(*copy)(const struct data_unset *src); \
|
2005-02-20 14:27:00 +00:00
|
|
|
void (* free)(struct data_unset *p); \
|
|
|
|
void (* reset)(struct data_unset *p); \
|
|
|
|
int (*insert_dup)(struct data_unset *dst, struct data_unset *src); \
|
2005-08-08 16:36:51 +00:00
|
|
|
void (*print)(const struct data_unset *p, int depth)
|
2005-02-20 14:27:00 +00:00
|
|
|
|
|
|
|
typedef struct data_unset {
|
|
|
|
DATA_UNSET;
|
|
|
|
} data_unset;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
data_unset **data;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
size_t *sorted;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2016-03-15 18:41:57 +00:00
|
|
|
size_t used; /* <= SSIZE_MAX */
|
2005-02-20 14:27:00 +00:00
|
|
|
size_t size;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
size_t unique_ndx;
|
|
|
|
} array;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DATA_UNSET;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
int count;
|
|
|
|
} data_count;
|
|
|
|
|
|
|
|
data_count *data_count_init(void);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DATA_UNSET;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *value;
|
|
|
|
} data_string;
|
|
|
|
|
|
|
|
data_string *data_string_init(void);
|
|
|
|
data_string *data_response_init(void);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DATA_UNSET;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
array *value;
|
|
|
|
} data_array;
|
|
|
|
|
|
|
|
data_array *data_array_init(void);
|
|
|
|
|
2006-09-07 11:05:41 +00:00
|
|
|
/**
|
|
|
|
* possible compare ops in the configfile parser
|
|
|
|
*/
|
2006-10-04 13:26:23 +00:00
|
|
|
typedef enum {
|
|
|
|
CONFIG_COND_UNSET,
|
2006-09-07 11:05:41 +00:00
|
|
|
CONFIG_COND_EQ, /** == */
|
|
|
|
CONFIG_COND_MATCH, /** =~ */
|
|
|
|
CONFIG_COND_NE, /** != */
|
|
|
|
CONFIG_COND_NOMATCH /** !~ */
|
|
|
|
} config_cond_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* possible fields to match against
|
|
|
|
*/
|
2005-08-08 17:25:06 +00:00
|
|
|
typedef enum {
|
|
|
|
COMP_UNSET,
|
2006-10-04 13:26:23 +00:00
|
|
|
COMP_SERVER_SOCKET,
|
|
|
|
COMP_HTTP_URL,
|
|
|
|
COMP_HTTP_HOST,
|
|
|
|
COMP_HTTP_REFERER,
|
2008-03-02 11:46:44 +00:00
|
|
|
COMP_HTTP_USER_AGENT,
|
2009-02-05 22:36:58 +00:00
|
|
|
COMP_HTTP_LANGUAGE,
|
2006-10-04 13:26:23 +00:00
|
|
|
COMP_HTTP_COOKIE,
|
2008-03-02 11:46:44 +00:00
|
|
|
COMP_HTTP_REMOTE_IP,
|
|
|
|
COMP_HTTP_QUERY_STRING,
|
2007-11-04 16:53:17 +00:00
|
|
|
COMP_HTTP_SCHEME,
|
2008-03-02 11:46:44 +00:00
|
|
|
COMP_HTTP_REQUEST_METHOD,
|
2007-08-18 09:27:11 +00:00
|
|
|
|
|
|
|
COMP_LAST_ELEMENT
|
2005-08-08 17:25:06 +00:00
|
|
|
} comp_key_t;
|
|
|
|
|
2006-10-04 13:26:23 +00:00
|
|
|
/* $HTTP["host"] == "incremental.home.kneschke.de" { ... }
|
2005-08-08 17:25:06 +00:00
|
|
|
* for print: comp_key op string
|
|
|
|
* for compare: comp cond string/regex
|
2005-02-20 14:27:00 +00:00
|
|
|
*/
|
|
|
|
|
2016-03-19 15:27:38 +00:00
|
|
|
typedef struct data_config data_config;
|
|
|
|
DEFINE_TYPED_VECTOR_NO_RELEASE(config_weak, data_config*);
|
|
|
|
|
|
|
|
struct data_config {
|
2005-02-20 14:27:00 +00:00
|
|
|
DATA_UNSET;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
array *value;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *comp_key;
|
2005-08-08 17:25:06 +00:00
|
|
|
comp_key_t comp;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
config_cond_t cond;
|
2005-08-08 17:25:06 +00:00
|
|
|
buffer *op;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-08-08 13:48:33 +00:00
|
|
|
int context_ndx; /* more or less like an id */
|
2016-03-19 15:27:38 +00:00
|
|
|
vector_config_weak children;
|
2005-08-08 13:48:33 +00:00
|
|
|
/* nested */
|
2016-03-19 15:27:38 +00:00
|
|
|
data_config *parent;
|
2005-08-08 13:48:33 +00:00
|
|
|
/* for chaining only */
|
2016-03-19 15:27:38 +00:00
|
|
|
data_config *prev;
|
|
|
|
data_config *next;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-08-08 13:48:33 +00:00
|
|
|
buffer *string;
|
2005-02-20 14:27:00 +00:00
|
|
|
#ifdef HAVE_PCRE_H
|
2005-08-08 13:48:33 +00:00
|
|
|
pcre *regex;
|
|
|
|
pcre_extra *regex_study;
|
2005-02-20 14:27:00 +00:00
|
|
|
#endif
|
2016-03-19 15:27:38 +00:00
|
|
|
};
|
2005-02-20 14:27:00 +00:00
|
|
|
|
|
|
|
data_config *data_config_init(void);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DATA_UNSET;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
int value;
|
|
|
|
} data_integer;
|
|
|
|
|
|
|
|
data_integer *data_integer_init(void);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DATA_UNSET;
|
|
|
|
|
|
|
|
buffer *host;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
unsigned short port;
|
|
|
|
|
|
|
|
time_t disable_ts;
|
2005-05-08 06:25:17 +00:00
|
|
|
int is_disabled;
|
|
|
|
size_t balance;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-05-08 06:25:17 +00:00
|
|
|
int usage; /* fair-balancing needs the no. of connections active on this host */
|
|
|
|
int last_used_ndx; /* round robin */
|
2005-02-20 14:27:00 +00:00
|
|
|
} data_fastcgi;
|
|
|
|
|
|
|
|
data_fastcgi *data_fastcgi_init(void);
|
|
|
|
|
|
|
|
array *array_init(void);
|
2005-08-08 14:40:47 +00:00
|
|
|
array *array_init_array(array *a);
|
2005-02-20 14:27:00 +00:00
|
|
|
void array_free(array *a);
|
|
|
|
void array_reset(array *a);
|
2016-03-15 18:26:57 +00:00
|
|
|
void array_insert_unique(array *a, data_unset *entry);
|
|
|
|
data_unset *array_pop(array *a); /* only works on "simple" lists with autogenerated keys */
|
2005-08-08 10:16:53 +00:00
|
|
|
int array_print(array *a, int depth);
|
2005-02-20 14:27:00 +00:00
|
|
|
data_unset *array_get_unused_element(array *a, data_type_t t);
|
|
|
|
data_unset *array_get_element(array *a, const char *key);
|
2016-03-15 18:56:02 +00:00
|
|
|
data_unset *array_extract_element(array *a, const char *key); /* removes found entry from array */
|
2009-06-10 13:08:15 +00:00
|
|
|
void array_set_key_value(array *hdrs, const char *key, size_t key_len, const char *value, size_t val_len);
|
2016-03-15 18:26:57 +00:00
|
|
|
void array_replace(array *a, data_unset *entry);
|
2005-02-20 14:27:00 +00:00
|
|
|
int array_strcasecmp(const char *a, size_t a_len, const char *b, size_t b_len);
|
2005-08-08 10:16:53 +00:00
|
|
|
void array_print_indent(int depth);
|
2005-08-17 06:47:07 +00:00
|
|
|
size_t array_get_max_key_length(array *a);
|
2005-02-20 14:27:00 +00:00
|
|
|
|
|
|
|
#endif
|