src/server/util/object.h

changeset 83
28433f06d5ee
parent 61
c858850f3d3a
child 95
74a81d9e19d0
--- a/src/server/util/object.h	Sun Jun 30 15:11:48 2013 +0200
+++ b/src/server/util/object.h	Mon Jul 01 18:05:13 2013 +0200
@@ -51,6 +51,10 @@
 
 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;
@@ -81,8 +85,71 @@
 
 struct Condition {
     Condition  *parent;
-    int        expression;
-    int        index; /* used by NSAPIContext to link expression with result */
+    Expression *expression;
+    int        index; // used by NSAPIContext to link expression with result
+};
+
+enum OperandType {
+    EXPR_OP_NULL = 0,   // no operand
+    EXPR_OP_STRING,     // string literal
+    EXPR_OP_INTEGER,    // integer literal
+    EXPR_OP_VAR,        // variable
+    EXPR_OP_FUNC,       // function,
+    EXPR_OP_EXPRESSION  // operand is an expression
+};
+
+enum Operator {
+    OP_NOOP = 0,
+    OP_NOT,          // not, !
+    OP_AND,          // and, &&
+    OP_OR,           // or, ||
+    OP_XOR,          // xor, ^
+    OP_WILDCARD,     // =
+    OP_REGEX,        // =~
+    OP_NREGEX,       // !~
+    OP_ADD,          // +
+    OP_SUB,          // -
+    OP_CAT,          // .
+    OP_DEF,          // defined
+    OP_DEXISTS,      // -d
+    OP_FDEXISTS,     // -e
+    OP_FEXISTS,      // -f
+    OP_LEXISTS,      // -l
+    OP_READABLE,     // -r
+    OP_FSIZE,        // -s
+    OP_UMAP,         // -U
+    OP_LESS,         // <
+    OP_LESSEQ,       // <=
+    OP_GREATER,      // >
+    OP_GREATEREQ,    // >=
+    OP_STRLESS,      // lt
+    OP_STRLESSEQ,    // le
+    OP_STRGREATER,   // gt
+    OP_STRGREATEREQ, // ge
+    OP_EQUAL,        // ==
+    OP_NOTEQUAL,     // !=
+    OP_STREQUAL,     // eq
+    OP_STRNOTEQUAL,  // ne
+};
+
+enum VarType {
+    VAR_NULL = 0,
+    VAR_STRING,
+    VAR_INTEGER,
+    VAR_BOOL
+};
+
+struct Expression {
+    // type of the operands
+    OperandType optype[2];
+    // operand data
+    void *opdata[2];
+    // operator
+    Operator expr_operator;
+    // logical connective to next expression
+    Operator next_operator;
+    // next expression
+    Expression *next;
 };
 
 
@@ -91,6 +158,7 @@
 
     ConditionResult   **results;
     int               nres;
+    int               nmaxres;
 
     //httpd_objset      *objset;
     int last_req_code;
@@ -156,6 +224,24 @@
  */
 void nsapi_context_next_stage(NSAPIContext *context);
 
+Condition* condition_from_str(pool_handle_t *pool, char *expr, size_t len);
+Expression* expression_from_str(pool_handle_t *pool, char *expr, size_t len);
+Operator expr_operator(char *token, size_t len);
+
+/*
+ * get the type of the token
+ * 
+ * returns
+ *   0: operand
+ *   1: operator
+ */
+int expr_token_type(char *token, size_t len);
+void expr_set_op(pool_handle_t *pool, OperandType *type, void **val, char *token, size_t len);
+
+
+int condition_evaluate(Condition *condition, Session *sn, Request *rq);
+int expression_evaluate(Expression *ex, Session *sn, Request *rq);
+int expr_get_var(char *var, Session *sn, Request *rq, void **val, VarType *t);
 
 #ifdef	__cplusplus
 }

mercurial