UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2018 Olaf Wintermann. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 #ifndef DAVQLEXEC_H 29 #define DAVQLEXEC_H 30 31 #include <stdarg.h> 32 #include "davqlparser.h" 33 #include "webdav.h" 34 35 #include <cx/buffer.h> 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 typedef struct DavQLCmd DavQLCmd; 42 typedef struct DavQLStackObj DavQLStackObj; 43 typedef struct DavQLRes DavQLRes; 44 45 typedef struct DavQLArg DavQLArg; 46 typedef struct DavQLArgList DavQLArgList; 47 48 typedef void*(*davql_func)(); // TODO: interface? 49 50 struct DavQLArg { 51 int type; 52 union DavQLArgValue{ 53 int d; 54 unsigned int u; 55 char *s; 56 time_t t; 57 } value; 58 DavQLArg *next; 59 }; 60 61 struct DavQLArgList { 62 DavQLArg *first; 63 DavQLArg *current; 64 }; 65 66 typedef enum { 67 DAVQL_OK = 0, 68 DAVQL_UNSUPPORTED_FORMATCHAR, 69 DAVQL_UNKNOWN_FORMATCHAR, 70 DAVQL_OOM 71 } davqlerror_t; 72 73 typedef enum { 74 DAVQL_CMD_INT = 0, 75 DAVQL_CMD_STRING, 76 DAVQL_CMD_TIMESTAMP, 77 DAVQL_CMD_RES_IDENTIFIER, 78 DAVQL_CMD_PROP_IDENTIFIER, 79 //DAVQL_CMD_OP_UNARY_ADD, 80 DAVQL_CMD_OP_UNARY_SUB, 81 DAVQL_CMD_OP_UNARY_NEG, 82 DAVQL_CMD_OP_BINARY_ADD, 83 DAVQL_CMD_OP_BINARY_SUB, 84 DAVQL_CMD_OP_BINARY_MUL, 85 DAVQL_CMD_OP_BINARY_DIV, 86 DAVQL_CMD_OP_BINARY_AND, 87 DAVQL_CMD_OP_BINARY_OR, 88 DAVQL_CMD_OP_BINARY_XOR, 89 DAVQL_CMD_OP_LOGICAL_NOT, 90 DAVQL_CMD_OP_LOGICAL_AND, 91 DAVQL_CMD_OP_LOGICAL_OR_L, 92 DAVQL_CMD_OP_LOGICAL_OR, 93 DAVQL_CMD_OP_LOGICAL_XOR, 94 DAVQL_CMD_OP_EQ, 95 DAVQL_CMD_OP_NEQ, 96 DAVQL_CMD_OP_LT, 97 DAVQL_CMD_OP_GT, 98 DAVQL_CMD_OP_LE, 99 DAVQL_CMD_OP_GE, 100 DAVQL_CMD_OP_LIKE, 101 DAVQL_CMD_OP_UNLIKE, 102 DAVQL_CMD_CALL 103 } davqlcmdtype_t; 104 105 typedef enum { 106 DAVQL_RES_NAME = 0, 107 DAVQL_RES_PATH, 108 DAVQL_RES_HREF, 109 DAVQL_RES_CONTENTLENGTH, 110 DAVQL_RES_CONTENTTYPE, 111 DAVQL_RES_CREATIONDATE, 112 DAVQL_RES_LASTMODIFIED, 113 DAVQL_RES_ISCOLLECTION 114 } davqlresprop_t; 115 116 struct DavQLCmd { 117 davqlcmdtype_t type; 118 union DavQLCmdData { 119 int64_t integer; 120 cxmutstr string; 121 time_t timestamp; 122 davqlresprop_t resprop; 123 DavPropName property; 124 davql_func func; 125 } data; 126 }; 127 128 struct DavQLStackObj { 129 int32_t type; // 0: int, 1: string, 2: xml 130 uint32_t length; 131 union DavQLStackData { 132 int64_t integer; 133 char *string; 134 DavXmlNode *node; 135 } data; 136 }; 137 138 struct DavQLRes { 139 DavResource *resource; 140 int depth; 141 }; 142 143 typedef struct DavCompiledField { 144 char *ns; 145 char *name; 146 CxBuffer *code; 147 } DavCompiledField; 148 149 typedef struct DavOrderCriterion { 150 int type; // 0: resprop, 1: property 151 union DavQLColumn { 152 davqlresprop_t resprop; 153 CxHashKey property; 154 } column; 155 _Bool descending; 156 } DavOrderCriterion; 157 158 DavQLArgList* dav_ql_get_args(DavQLStatement *st, va_list ap); 159 void dav_ql_free_arglist(DavQLArgList *args); 160 161 int dav_ql_getarg_int(DavQLArgList *args); 162 unsigned int dav_ql_getarg_uint(DavQLArgList *args); 163 char* dav_ql_getarg_str(DavQLArgList *args); 164 time_t dav_ql_getarg_time(DavQLArgList *args); 165 166 DavResult dav_statement_exec(DavSession *sn, DavQLStatement *st, ...); 167 DavResult dav_statement_execv(DavSession *sn, DavQLStatement *st, va_list ap); 168 169 CxBuffer* dav_path_string(cxmutstr src, DavQLArgList *args, davqlerror_t *error); 170 cxmutstr dav_format_string(const CxAllocator *a, cxstring fstr, DavQLArgList *ap, davqlerror_t *error); 171 172 DavResult dav_exec_select(DavSession *sn, DavQLStatement *st, va_list ap); 173 174 int dav_identifier2resprop(cxstring src, davqlresprop_t *prop); 175 176 CxBuffer* dav_compile_expr(DavContext *ctx, const CxAllocator *a, DavQLExpression *lexpr, DavQLArgList *ap); 177 178 int dav_exec_expr(CxBuffer *bcode, DavResource *res, DavQLStackObj *result); 179 180 181 182 #ifdef __cplusplus 183 } 184 #endif 185 186 #endif /* DAVQLEXEC_H */ 187 188