2
0
Fork 0
lighttpd2/include/lighttpd/condition.h

132 lines
3.1 KiB
C
Raw Normal View History

2008-06-29 15:48:28 +00:00
#ifndef _LIGHTTPD_CONDITION_H_
#define _LIGHTTPD_CONDITION_H_
#ifndef _LIGHTTPD_BASE_H_
#error Please include <lighttpd/base.h> instead of this file
#endif
2008-06-29 15:48:28 +00:00
/**
* possible compare ops in the configfile parser
*/
typedef enum {
2008-06-30 10:25:01 +00:00
/* everything */
2008-06-29 15:48:28 +00:00
CONFIG_COND_EQ, /** == */
CONFIG_COND_NE, /** != */
2008-06-30 10:25:01 +00:00
/* only with string */
CONFIG_COND_PREFIX, /** =^ */
CONFIG_COND_NOPREFIX,/** !^ */
CONFIG_COND_SUFFIX, /** =$ */
CONFIG_COND_NOSUFFIX,/** !$ */
2008-07-25 20:38:42 +00:00
/* only usable with pcre */
2008-06-30 10:25:01 +00:00
CONFIG_COND_MATCH, /** =~ */
2008-06-29 15:48:28 +00:00
CONFIG_COND_NOMATCH, /** !~ */
2008-06-30 10:25:01 +00:00
2008-07-25 20:38:42 +00:00
CONFIG_COND_IP,
CONFIG_COND_NOTIP,
2008-06-30 10:25:01 +00:00
/* only with int */
2008-06-29 15:48:28 +00:00
CONFIG_COND_GT, /** > */
CONFIG_COND_GE, /** >= */
CONFIG_COND_LT, /** < */
CONFIG_COND_LE /** <= */
} comp_operator_t;
2008-06-29 15:48:28 +00:00
/**
* possible fields to match against
*/
typedef enum {
COMP_REQUEST_LOCALIP,
COMP_REQUEST_REMOTEIP,
2008-06-30 11:38:52 +00:00
COMP_REQUEST_PATH,
COMP_REQUEST_HOST,
COMP_REQUEST_SCHEME,
COMP_REQUEST_QUERY_STRING,
COMP_REQUEST_METHOD,
2008-06-30 12:01:53 +00:00
COMP_REQUEST_CONTENT_LENGTH,
2008-06-29 15:48:28 +00:00
COMP_PHYSICAL_PATH,
2008-06-30 11:38:52 +00:00
COMP_PHYSICAL_PATH_EXISTS,
COMP_PHYSICAL_SIZE,
/* needs a key */
2008-08-07 12:12:51 +00:00
COMP_REQUEST_HEADER /**< needs lowercase key, enforced by condition_lvalue_new */
} cond_lvalue_t;
#define COND_LVALUE_FIRST_WITH_KEY COMP_REQUEST_HEADER
#define COND_LVALUE_END (1+COMP_REQUEST_HEADER)
struct condition_lvalue {
int refcount;
cond_lvalue_t type;
GString *key;
};
2008-06-29 15:48:28 +00:00
2008-06-30 10:25:01 +00:00
typedef enum {
COND_VALUE_NUMBER,
2008-06-30 10:25:01 +00:00
COND_VALUE_STRING,
#ifdef HAVE_PCRE_H
COND_VALUE_REGEXP,
#endif
2008-07-25 20:38:42 +00:00
COND_VALUE_SOCKET_IPV4, /** only match ip/netmask */
COND_VALUE_SOCKET_IPV6 /** only match ip/netmask */
} cond_rvalue_t;
2008-06-30 10:25:01 +00:00
struct condition_rvalue {
cond_rvalue_t type;
GString *string;
#ifdef HAVE_PCRE_H
struct {
pcre *regex;
pcre_extra *regex_study;
2008-09-18 07:13:32 +00:00
} pcre;
#endif
gint64 i;
struct {
guint32 addr;
guint32 networkmask;
} ipv4;
struct {
guint8 addr[16];
guint network;
} ipv6;
};
2008-06-29 15:48:28 +00:00
#include <lighttpd/base.h>
2008-06-29 15:48:28 +00:00
struct condition {
int refcount;
comp_operator_t op;
condition_lvalue *lvalue;
condition_rvalue rvalue;
2008-06-29 15:48:28 +00:00
};
/* lvalue */
LI_API condition_lvalue* condition_lvalue_new(cond_lvalue_t type, GString *key);
LI_API void condition_lvalue_acquire(condition_lvalue *lvalue);
LI_API void condition_lvalue_release(condition_lvalue *lvalue);
2008-06-29 15:48:28 +00:00
LI_API condition* condition_new_string(server *srv, comp_operator_t op, condition_lvalue *lvalue, GString *str);
2008-07-25 20:38:42 +00:00
LI_API condition* condition_new_int(server *srv, comp_operator_t op, condition_lvalue *lvalue, gint64 i);
LI_API void condition_acquire(condition *c);
LI_API void condition_release(server *srv, condition* c);
2008-06-29 15:48:28 +00:00
LI_API const char* comp_op_to_string(comp_operator_t op);
LI_API const char* cond_lvalue_to_string(cond_lvalue_t t);
2008-06-30 10:25:01 +00:00
struct vrequest;
LI_API handler_t condition_check(struct vrequest *vr, condition *cond, gboolean *result);
2008-06-30 10:25:01 +00:00
2008-07-25 20:38:42 +00:00
/* parser */
2008-07-25 22:42:08 +00:00
/** parse an IPv4 (if netmask is not NULL with cidr netmask) */
2008-07-25 20:38:42 +00:00
LI_API gboolean parse_ipv4(const char *str, guint32 *ip, guint32 *netmask);
2008-07-25 22:42:08 +00:00
/** parse an IPv6 (if network is not NULL with cidr network) */
2008-07-25 20:38:42 +00:00
LI_API gboolean parse_ipv6(const char *str, guint8 *ip, guint *network);
LI_API GString* ipv6_tostring(const guint8 ip[16]);
2008-06-29 15:48:28 +00:00
#endif