|
1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
3 * |
|
4 * Copyright 2015 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 |
|
29 #ifndef DAVQLPARSER_H |
|
30 #define DAVQLPARSER_H |
|
31 |
|
32 #ifdef __cplusplus |
|
33 extern "C" { |
|
34 #endif |
|
35 |
|
36 #include "ucx/string.h" |
|
37 #include "ucx/list.h" |
|
38 |
|
39 /** |
|
40 * Enumeration of possible statement types. |
|
41 */ |
|
42 typedef enum {GET, PUT} davqltype_t; |
|
43 |
|
44 /** |
|
45 * Enumeration of possible expression types. |
|
46 */ |
|
47 typedef enum {LITERAL, UNARY, BINARY, LOGICAL} davqlexprtype_t; |
|
48 |
|
49 /** |
|
50 * Enumeration of possible expression operators. |
|
51 */ |
|
52 typedef enum { |
|
53 ADD, SUB, MUL, DIV, |
|
54 AND, OR, XOR, NEG, |
|
55 NOT, LAND, LOR |
|
56 } davqloperator_t; |
|
57 |
|
58 /** |
|
59 * An expression within a DAVQL query. |
|
60 */ |
|
61 typedef struct _davqlexpr DavQLExpression; |
|
62 |
|
63 /** |
|
64 * The structure for type DavQLExpression. |
|
65 */ |
|
66 struct _davqlexpr { |
|
67 /** |
|
68 * The original expression text. |
|
69 * Contains the literal value, if type is LITERAL. |
|
70 */ |
|
71 sstr_t srctext; |
|
72 /** |
|
73 * The expression type. |
|
74 */ |
|
75 davqlexprtype_t type; |
|
76 /** |
|
77 * Operator. |
|
78 * |
|
79 */ |
|
80 davqloperator_t op; |
|
81 /** |
|
82 * Left or single operand. |
|
83 * <code>NULL</code> for literals. |
|
84 */ |
|
85 DavQLExpression *expr1; |
|
86 /** |
|
87 * Right operand. |
|
88 * <code>NULL</code> for literals or unary expressions. |
|
89 */ |
|
90 DavQLExpression *expr2; |
|
91 }; |
|
92 |
|
93 |
|
94 /** |
|
95 * Query statement object. |
|
96 * Contains the binary information about the parsed query. |
|
97 */ |
|
98 typedef struct { |
|
99 /** |
|
100 * The original query text. |
|
101 */ |
|
102 sstr_t srctext; |
|
103 /** |
|
104 * The statement type. |
|
105 */ |
|
106 davqltype_t type; |
|
107 /** |
|
108 * The list of field names (sstr_t). |
|
109 * <ul> |
|
110 * <li>GET: the list of DAV properties for projection</li> |
|
111 * <li>PUT: the list of DAV properties that shall receive new values</li> |
|
112 * </ul> |
|
113 * This may be <code>NULL</code> for GET queries, to request all properties. |
|
114 */ |
|
115 UcxList* fields; |
|
116 /** |
|
117 * The list of DavQLExpressions for the new DAV property values. |
|
118 * This is <code>NULL</code> for GET queries. |
|
119 */ |
|
120 UcxList* putvalues; |
|
121 /** |
|
122 * Logical expression for selection. |
|
123 */ |
|
124 DavQLExpression* where; |
|
125 /** |
|
126 * The recursion depth for the statement. |
|
127 * Defaults to SIZE_MAX (unbound recursion). |
|
128 */ |
|
129 size_t depth; |
|
130 } DavQLStatement; |
|
131 |
|
132 |
|
133 #ifdef __cplusplus |
|
134 } |
|
135 #endif |
|
136 |
|
137 #endif /* DAVQLPARSER_H */ |
|
138 |