move control socket handling to separate file
[mizunara.git] / libidav / davqlexec.h
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 <ucx/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 } davqlerror_t;
71
72 typedef enum {
73     DAVQL_CMD_INT = 0,
74     DAVQL_CMD_STRING,
75     DAVQL_CMD_TIMESTAMP,
76     DAVQL_CMD_RES_IDENTIFIER,
77     DAVQL_CMD_PROP_IDENTIFIER,
78     //DAVQL_CMD_OP_UNARY_ADD,
79     DAVQL_CMD_OP_UNARY_SUB,
80     DAVQL_CMD_OP_UNARY_NEG,
81     DAVQL_CMD_OP_BINARY_ADD,
82     DAVQL_CMD_OP_BINARY_SUB,
83     DAVQL_CMD_OP_BINARY_MUL,
84     DAVQL_CMD_OP_BINARY_DIV,
85     DAVQL_CMD_OP_BINARY_AND,
86     DAVQL_CMD_OP_BINARY_OR,
87     DAVQL_CMD_OP_BINARY_XOR,
88     DAVQL_CMD_OP_LOGICAL_NOT,
89     DAVQL_CMD_OP_LOGICAL_AND,
90     DAVQL_CMD_OP_LOGICAL_OR_L,
91     DAVQL_CMD_OP_LOGICAL_OR,
92     DAVQL_CMD_OP_LOGICAL_XOR,
93     DAVQL_CMD_OP_EQ,
94     DAVQL_CMD_OP_NEQ,
95     DAVQL_CMD_OP_LT,
96     DAVQL_CMD_OP_GT,
97     DAVQL_CMD_OP_LE,
98     DAVQL_CMD_OP_GE,
99     DAVQL_CMD_OP_LIKE,
100     DAVQL_CMD_OP_UNLIKE,
101     DAVQL_CMD_CALL
102 } davqlcmdtype_t;
103
104 typedef enum {
105     DAVQL_RES_NAME = 0,
106     DAVQL_RES_PATH,
107     DAVQL_RES_HREF,
108     DAVQL_RES_CONTENTLENGTH,
109     DAVQL_RES_CONTENTTYPE,
110     DAVQL_RES_CREATIONDATE,
111     DAVQL_RES_LASTMODIFIED,
112     DAVQL_RES_ISCOLLECTION
113 } davqlresprop_t;
114
115 struct DavQLCmd {
116     davqlcmdtype_t type;
117     union DavQLCmdData {
118         int64_t        integer;
119         sstr_t         string;
120         time_t         timestamp;
121         davqlresprop_t resprop;
122         DavPropName    property;
123         davql_func     func;
124     } data;
125 };
126
127 struct DavQLStackObj {
128     int32_t  type; // 0: int, 1: string, 2: xml
129     uint32_t length;
130     union DavQLStackData {
131         int64_t    integer;
132         char       *string;
133         DavXmlNode *node;
134     } data;
135 };
136
137 struct DavQLRes {
138     DavResource *resource;
139     int depth;
140 };
141
142 typedef struct DavCompiledField {
143     char *ns;
144     char *name;
145     UcxBuffer *code;
146 } DavCompiledField;
147
148 typedef struct DavOrderCriterion {
149     int type; // 0: resprop, 1: property
150     union DavQLColumn {
151         davqlresprop_t resprop;
152         UcxKey property;
153     } column;
154     _Bool descending;
155 } DavOrderCriterion;
156
157 DavQLArgList* dav_ql_get_args(DavQLStatement *st, va_list ap);
158 void dav_ql_free_arglist(DavQLArgList *args);
159
160 int dav_ql_getarg_int(DavQLArgList *args);
161 unsigned int dav_ql_getarg_uint(DavQLArgList *args);
162 char* dav_ql_getarg_str(DavQLArgList *args);
163 time_t dav_ql_getarg_time(DavQLArgList *args);
164
165 DavResult dav_statement_exec(DavSession *sn, DavQLStatement *st, ...);
166 DavResult dav_statement_execv(DavSession *sn, DavQLStatement *st, va_list ap);
167
168 UcxBuffer* dav_path_string(sstr_t src, DavQLArgList *args, davqlerror_t *error);
169 sstr_t dav_format_string(UcxAllocator *a, sstr_t fstr, DavQLArgList *ap, davqlerror_t *error);
170
171 DavResult dav_exec_select(DavSession *sn, DavQLStatement *st, va_list ap);
172
173 int dav_identifier2resprop(sstr_t src, davqlresprop_t *prop);
174
175 UcxBuffer* dav_compile_expr(DavContext *ctx, UcxAllocator *a, DavQLExpression *lexpr, DavQLArgList *ap);
176
177 int dav_exec_expr(UcxBuffer *bcode, DavResource *res, DavQLStackObj *result);
178
179
180
181 #ifdef  __cplusplus
182 }
183 #endif
184
185 #endif  /* DAVQLEXEC_H */
186