#ifndef OBJECT_H
#define OBJECT_H
#include "../public/nsapi.h"
#include "pool.h"
#include <inttypes.h>
#include <cx/list.h>
#ifdef __cplusplus
extern "C" {
#endif
enum RequestStage {
NSAPIAuthTrans =
0,
NSAPINameTrans,
NSAPIPathCheck,
NSAPIObjectType,
NSAPIService,
NSAPIError,
NSAPIAddLog,
REQ_FINISH,
NUM_NSAPI_TYPES
};
typedef enum RequestStage RequestStage;
typedef struct Condition Condition;
typedef int8_t ConditionResult;
typedef struct Expression Expression;
typedef enum OperandType OperandType;
typedef enum Operator Operator;
typedef enum VarType VarType;
typedef struct NSAPIContext NSAPIContext;
typedef struct HTTPObjectConfig HTTPObjectConfig;
struct directive {
FuncStruct *func;
pblock *param;
Condition *cond;
};
struct dtable {
directive **dirs;
int ndir;
int alloc;
};
struct httpd_object {
pool_handle_t *pool;
char *name;
char *path;
dtable *dt;
int nd;
};
struct httpd_objset {
httpd_object **obj;
int pos;
};
struct Condition {
Condition *parent;
Condition *ifnot;
Expression *expression;
int depth;
int index;
};
struct Expression {
int n;
};
struct NSAPIContext{
HTTPObjectConfig *conf;
ConditionResult **results;
int nres;
int nmaxres;
int last_req_code;
int objset_index;
int dtable_index;
};
struct HTTPObjectConfig {
httpd_object **objects;
int nobj;
pool_handle_t *pool;
uint32_t ref;
};
typedef struct NSAPIExpression NSAPIExpression;
typedef enum NSAPIExpressionType NSAPIExpressionType;
typedef enum NSAPIExpressionOperator NSAPIExpressionOperator;
enum NSAPIExpressionType {
NSAPI_EXPRESSION_BOOL =
0,
NSAPI_EXPRESSION_INT,
NSAPI_EXPRESSION_DOUBLE,
NSAPI_EXPRESSION_STRING,
NSAPI_EXPRESSION_VARIABLE,
NSAPI_EXPRESSION_LOGICAL,
NSAPI_EXPRESSION_UNARY,
NSAPI_EXPRESSION_BINARY,
NSAPI_EXPRESSION_IDENTIFIER
};
enum NSAPIExpressionOperator {
NSAPI_EXPRESSION_NOOP =
0,
NSAPI_EXPRESSION_CALL,
NSAPI_EXPRESSION_ARG,
NSAPI_EXPRESSION_WILDCARD_MATCH,
NSAPI_EXPRESSION_REGEX_MATCH,
NSAPI_EXPRESSION_REGEX_MISMATCH,
NSAPI_EXPRESSION_EQ,
NSAPI_EXPRESSION_NEQ,
NSAPI_EXPRESSION_GT,
NSAPI_EXPRESSION_LT,
NSAPI_EXPRESSION_GE,
NSAPI_EXPRESSION_LE,
NSAPI_EXPRESSION_ADD,
NSAPI_EXPRESSION_SUB,
NSAPI_EXPRESSION_MUL,
NSAPI_EXPRESSION_DIV,
NSAPI_EXPRESSION_MOD,
NSAPI_EXPRESSION_STRCAT,
NSAPI_EXPRESSION_NOT,
NSAPI_EXPRESSION_AND,
NSAPI_EXPRESSION_OR,
NSAPI_EXPRESSION_XOR,
NSAPI_EXPRESSION_VALUE_DEFINED,
NSAPI_EXPRESSION_DIR_EXISTS,
NSAPI_EXPRESSION_FILE_DIR_EXISTS,
NSAPI_EXPRESSION_FILE_EXISTS,
NSAPI_EXPRESSION_SYMLINK_EXISTS,
NSAPI_EXPRESSION_FILE_READABLE,
NSAPI_EXPRESSION_FILE_SIZE
};
union NSAPIExpressionValue {
cxstring str;
cxstring var;
cxstring identifier;
int64_t i;
double f;
int b;
};
struct NSAPIExpression {
union NSAPIExpressionValue value;
NSAPIExpressionType type;
NSAPIExpressionOperator operator;
NSAPIExpression *left;
NSAPIExpression *right;
};
httpd_object* object_new(
pool_handle_t *pool,
char *name);
void object_free(httpd_object *obj);
int object_add_directive(httpd_object *obj, directive *dir,
int dt);
#define object_get_dtable(obj,type) &obj->dt[type];
httpd_objset* objset_create(
pool_handle_t *pool);
void objset_add_object(
pool_handle_t *p, httpd_objset *os, httpd_object *obj);
void httpobjconf_add_object(HTTPObjectConfig *conf, httpd_object *obj);
void nsapi_context_next_stage(NSAPIContext *context);
Expression* condition_create(
pool_handle_t *pool, CxList *tokens);
NSAPIExpression* expr_parse_logical_expr(
pool_handle_t *pool, CxList *tokens,
size_t *pos);
int condition_evaluate(Condition *condition, Session *sn, Request *rq);
#ifdef __cplusplus
}
#endif
#endif