libidav/davqlexec.c

Sun, 15 Dec 2019 18:08:14 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 15 Dec 2019 18:08:14 +0100
changeset 707
33c9b0f17cb2
parent 610
aa3baf1dd81b
child 738
b62ea7f31593
permissions
-rw-r--r--

change version to 1.3.0

104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
4 * Copyright 2018 Olaf Wintermann. All rights reserved.
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
249
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
32 #include <inttypes.h>
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include <ucx/utils.h>
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
35 #include <ucx/map.h>
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "davqlexec.h"
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
37 #include "utils.h"
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
38 #include "methods.h"
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
39 #include "session.h"
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
40 #include "resource.h"
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
42 DavQLArgList* dav_ql_get_args(DavQLStatement *st, va_list ap) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
43 DavQLArgList *args = malloc(sizeof(DavQLArgList));
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
44 if(!args) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
45 return NULL;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
46 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
47 args->first = NULL;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
48
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
49 DavQLArg *cur = NULL;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
50 UCX_FOREACH(elm, st->args) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
51 intptr_t type = (intptr_t)elm->data;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
52 DavQLArg *arg = calloc(1, sizeof(DavQLArg));
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
53 if(!arg) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
54 dav_ql_free_arglist(args);
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
55 return NULL;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
56 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
57 arg->type = type;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
58 switch(type) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
59 case 'd': {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
60 arg->value.d = va_arg(ap, int);
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
61 break;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
62 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
63 case 'u': {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
64 arg->value.u = va_arg(ap, unsigned int);
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
65 break;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
66 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
67 case 's': {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
68 arg->value.s = va_arg(ap, char*);
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
69 break;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
70 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
71 case 't': {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
72 arg->value.t = va_arg(ap, time_t);
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
73 break;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
74 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
75 default: {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
76 free(arg);
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
77 dav_ql_free_arglist(args);
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
78 return NULL;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
79 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
80 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
81 if(cur) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
82 cur->next = arg;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
83 } else {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
84 args->first = arg;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
85 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
86 cur = arg;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
87 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
88 args->current = args->first;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
89 return args;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
90 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
91
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
92 void dav_ql_free_arglist(DavQLArgList *args) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
93 DavQLArg *arg = args->first;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
94 while(arg) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
95 DavQLArg *next = arg->next;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
96 free(arg);
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
97 arg = next;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
98 }
387
92f8a2a243fc fixes dav_ql_free_arglist() not freeing the list container
Mike Becker <universe@uap-core.de>
parents: 365
diff changeset
99 free(args);
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
100 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
101
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
102 static DavQLArg* arglist_get(DavQLArgList *args) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
103 DavQLArg *a = args->current;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
104 if(a) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
105 args->current = a->next;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
106 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
107 return a;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
108 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
109
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
110 int dav_ql_getarg_int(DavQLArgList *args) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
111 DavQLArg *a = arglist_get(args);
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
112 if(a && a->type == 'd') {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
113 return a->value.d;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
114 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
115 return 0;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
116 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
117
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
118 unsigned int dav_ql_getarg_uint(DavQLArgList *args) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
119 DavQLArg *a = arglist_get(args);
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
120 if(a && a->type == 'u') {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
121 return a->value.u;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
122 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
123 return 0;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
124 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
125
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
126 char* dav_ql_getarg_str(DavQLArgList *args) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
127 DavQLArg *a = arglist_get(args);
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
128 if(a && a->type == 's') {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
129 return a->value.s;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
130 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
131 return "";
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
132 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
133
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
134 time_t dav_ql_getarg_time(DavQLArgList *args) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
135 DavQLArg *a = arglist_get(args);
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
136 if(a && a->type == 't') {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
137 return a->value.t;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
138 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
139 return 0;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
140 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
141
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
142
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
143 DavResult dav_statement_exec(DavSession *sn, DavQLStatement *st, ...) {
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 va_list ap;
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 va_start(ap, st);
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
146 DavResult result = dav_statement_execv(sn, st, ap);
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 va_end(ap);
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 return result;
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
151 DavResult dav_statement_execv(DavSession *sn, DavQLStatement *st, va_list ap) {
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
152 DavResult result;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
153 result.result = NULL;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
154 result.status = 1;
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 // make sure the statement was successfully parsed
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 if(st->type == DAVQL_ERROR) {
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 return result;
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160
127
7072a2b4ae35 renamed GET to SELECT in davql syntax
Mike Becker <universe@uap-core.de>
parents: 126
diff changeset
161 if(st->type == DAVQL_SELECT) {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
162 return dav_exec_select(sn, st, ap);
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 } else {
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 // TODO
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 return result;
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
170 sstr_t dav_format_string(UcxAllocator *a, sstr_t fstr, DavQLArgList *ap, davqlerror_t *error) {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
171 UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND);
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 int placeholder = 0;
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
174 for(int i=0;i<fstr.length;i++) {
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
175 char c = fstr.ptr[i];
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 if(placeholder) {
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 if(c == '%') {
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 // no placeholder, %% transposes to %
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
179 ucx_buffer_putc(buf, c);
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 } else {
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 // detect placeholder type and insert arg
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 int err = 0;
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 switch(c) {
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 case 's': {
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
185 char *arg = dav_ql_getarg_str(ap);
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
186 ucx_buffer_puts(buf, arg);
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 break;
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 case 'd': {
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
190 int arg = dav_ql_getarg_int(ap);
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
191 ucx_bprintf(buf, "%d", arg);
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 break;
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 case 'u': {
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
195 unsigned int arg = dav_ql_getarg_uint(ap);
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
196 ucx_bprintf(buf, "%u", arg);
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 break;
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 case 't': {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
200 // time arguments not supported for strings
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 err = 1;
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 break;
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 default: {
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 *error = DAVQL_UNKNOWN_FORMATCHAR;
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 err = 1;
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 if(err) {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
210 ucx_buffer_free(buf);
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
211 sstr_t n;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
212 n.ptr = NULL;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
213 n.length = 0;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
214 return n;
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 placeholder = 0;
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 } else {
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 if(c == '%') {
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 placeholder = 1;
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 } else {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
222 ucx_buffer_putc(buf, c);
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 *error = DAVQL_OK;
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
227
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
228 sstr_t ret = sstrdup_a(a, sstrn(buf->space, buf->size));
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
229 ucx_buffer_free(buf);
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
230 return ret;
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
233 static int fl_add_properties(DavSession *sn, UcxMempool *mp, UcxMap *map, DavQLExpression *expression) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
234 if(!expression) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
235 return 0;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
236 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
237
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
238 if(expression->type == DAVQL_IDENTIFIER) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
239 DavProperty *property = ucx_mempool_malloc(mp, sizeof(DavProperty));
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
240
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
241 char *name;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
242 DavNamespace *ns = dav_get_property_namespace(
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
243 sn->context,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
244 sstrdup_a(mp->allocator, expression->srctext).ptr,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
245 &name);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
246 if(!ns) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
247 return -1;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
248 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
249
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
250 property->ns = ns;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
251 property->name = name;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
252 property->value = NULL;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
253
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
254 ucx_map_sstr_put(map, expression->srctext, property);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
255 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
256
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
257 if(expression->left) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
258 if(fl_add_properties(sn, mp, map, expression->left)) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
259 return -1;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
260 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
261 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
262 if(expression->right) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
263 if(fl_add_properties(sn, mp, map, expression->right)) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
264 return -1;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
265 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
266 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
267
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
268 return 0;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
269 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
270
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
271 static UcxBuffer* fieldlist2propfindrequest(DavSession *sn, UcxMempool *mp, UcxList *fields, int *isallprop) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
272 UcxMap *properties = ucx_map_new(32);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
273 *isallprop = 0;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
274
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
275 UCX_FOREACH(elm, fields) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
276 DavQLField *field = elm->data;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
277 if(!sstrcmp(field->name, S("*"))) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
278 ucx_map_free(properties);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
279 *isallprop = 1;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
280 return create_allprop_propfind_request();
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
281 } else if(!sstrcmp(field->name, S("-"))) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
282 ucx_map_free(properties);
475
52e4171d42ce adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 387
diff changeset
283 return create_propfind_request(sn, NULL, "propfind", 0);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
284 } else {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
285 if(fl_add_properties(sn, mp, properties, field->expr)) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
286 // TODO: set error
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
287 ucx_map_free(properties);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
288 return NULL;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
289 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
290 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
291 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
292
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
293 UcxMapIterator i = ucx_map_iterator(properties);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
294 UcxKey key;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
295 DavProperty *value;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
296 UcxList *list = NULL;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
297 UCX_MAP_FOREACH(key, value, i) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
298 list = ucx_list_append(list, value);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
299 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
300
475
52e4171d42ce adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 387
diff changeset
301 UcxBuffer *reqbuf = create_propfind_request(sn, list, "propfind", 0);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
302 ucx_list_free(list);
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
303 ucx_map_free(properties);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
304 return reqbuf;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
305 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
306
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
307 static int reset_properties(DavSession *sn, DavResult *result, DavResource *res, UcxList *fields) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
308 UcxMap *new_properties = ucx_map_new_a(sn->mp->allocator, 32);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
309 DavResourceData *data = (DavResourceData*)res->data;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
310
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
311 // add basic properties
609
dc3d70848c7c implement encrypted properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 538
diff changeset
312 void *value;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
313
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
314 sstr_t cl_keystr = dav_property_key("DAV:", "getcontentlength");
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
315 UcxKey cl_key = ucx_key(cl_keystr.ptr, cl_keystr.length);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
316 value = ucx_map_get(data->properties, cl_key);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
317 if(value) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
318 ucx_map_put(new_properties, cl_key, value);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
319 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
320
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
321 sstr_t cd_keystr = dav_property_key("DAV:", "creationdate");
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
322 UcxKey cd_key = ucx_key(cd_keystr.ptr, cd_keystr.length);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
323 value = ucx_map_get(data->properties, cd_key);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
324 if(value) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
325 ucx_map_put(new_properties, cd_key, value);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
326 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
327
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
328 sstr_t lm_keystr = dav_property_key("DAV:", "getlastmodified");
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
329 UcxKey lm_key = ucx_key(lm_keystr.ptr, lm_keystr.length);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
330 value = ucx_map_get(data->properties, lm_key);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
331 if(value) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
332 ucx_map_put(new_properties, lm_key, value);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
333 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
334
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
335 sstr_t ct_keystr = dav_property_key("DAV:", "getcontenttype");
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
336 UcxKey ct_key = ucx_key(ct_keystr.ptr, ct_keystr.length);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
337 value = ucx_map_get(data->properties, ct_key);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
338 if(value) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
339 ucx_map_put(new_properties, ct_key, value);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
340 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
341
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
342 sstr_t rt_keystr = dav_property_key("DAV:", "resourcetype");
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
343 UcxKey rt_key = ucx_key(rt_keystr.ptr, rt_keystr.length);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
344 value = ucx_map_get(data->properties, rt_key);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
345 if(value) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
346 ucx_map_put(new_properties, rt_key, value);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
347 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
348
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
349 sstr_t cn_keystr = dav_property_key(DAV_NS, "crypto-name");
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
350 UcxKey cn_key = ucx_key(cn_keystr.ptr, cn_keystr.length);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
351 value = ucx_map_get(data->properties, cn_key);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
352 if(value) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
353 ucx_map_put(new_properties, cn_key, value);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
354 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
355
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
356 sstr_t ck_keystr = dav_property_key(DAV_NS, "crypto-key");
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
357 UcxKey ck_key = ucx_key(ck_keystr.ptr, ck_keystr.length);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
358 value = ucx_map_get(data->properties, ck_key);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
359 if(value) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
360 ucx_map_put(new_properties, ck_key, value);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
361 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
362
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
363 sstr_t ch_keystr = dav_property_key(DAV_NS, "crypto-hash");
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
364 UcxKey ch_key = ucx_key(ch_keystr.ptr, ch_keystr.length);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
365 value = ucx_map_get(data->properties, ch_key);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
366 if(value) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
367 ucx_map_put(new_properties, ch_key, value);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
368 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
369
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
370 // add properties from field list
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
371 UCX_FOREACH(elm, fields) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
372 DavCompiledField *field = elm->data;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
373 DavQLStackObj field_result;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
374 if(!dav_exec_expr(field->code, res, &field_result)) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
375 sstr_t str;
136
59058927b885 empty field results will no longer be added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
376 str.ptr = NULL;
59058927b885 empty field results will no longer be added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
377 str.length = 0;
348
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
378 DavXmlNode *node = NULL;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
379 if(field_result.type == 0) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
380 str = ucx_asprintf(
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
381 sn->mp->allocator,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
382 "%d",
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
383 field_result.data.integer);
348
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
384 } else if(field_result.type == 1) {
136
59058927b885 empty field results will no longer be added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
385 if(field_result.data.string) {
59058927b885 empty field results will no longer be added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
386 str = sstrdup_a(sn->mp->allocator, sstrn(
59058927b885 empty field results will no longer be added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
387 field_result.data.string,
59058927b885 empty field results will no longer be added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
388 field_result.length));
59058927b885 empty field results will no longer be added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
389 }
348
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
390 } else if(field_result.type == 2) {
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
391 node = dav_copy_node(field_result.data.node);
348
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
392 } else {
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
393 // unknown type
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
394 // TODO: error
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
395 resource_free_properties(sn, new_properties);
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
396 return -1;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
397 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
398 if(str.ptr) {
348
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
399 node = dav_session_malloc(sn, sizeof(DavXmlNode));
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
400 memset(node, 0, sizeof(DavXmlNode));
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
401 node->type = DAV_XML_TEXT;
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
402 node->content = str.ptr;
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
403 node->contentlength = str.length;
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
404 }
b79fb94f9e0a davqlexec handles xml properties now (not really, but it doesn't destroy everything)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
405 if(node) {
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
406 sstr_t key = dav_property_key(field->ns, field->name);
610
aa3baf1dd81b fix bug in davqlexec introduced by refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
407
aa3baf1dd81b fix bug in davqlexec introduced by refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
408 DavNamespace *namespace = dav_session_malloc(sn, sizeof(DavNamespace));
aa3baf1dd81b fix bug in davqlexec introduced by refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
409 namespace->prefix = NULL;
aa3baf1dd81b fix bug in davqlexec introduced by refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
410 namespace->name = dav_session_strdup(sn, field->ns);
aa3baf1dd81b fix bug in davqlexec introduced by refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
411
aa3baf1dd81b fix bug in davqlexec introduced by refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
412 DavProperty *prop = dav_session_malloc(sn, sizeof(DavProperty));
aa3baf1dd81b fix bug in davqlexec introduced by refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
413 prop->name = dav_session_strdup(sn, field->name);
aa3baf1dd81b fix bug in davqlexec introduced by refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
414 prop->ns = namespace;
aa3baf1dd81b fix bug in davqlexec introduced by refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
415 prop->value = node;
aa3baf1dd81b fix bug in davqlexec introduced by refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
416
aa3baf1dd81b fix bug in davqlexec introduced by refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 609
diff changeset
417 ucx_map_sstr_put(new_properties, key, prop);
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
418 free(key.ptr);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
419 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
420 } else {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
421 // TODO: error
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
422 resource_free_properties(sn, new_properties);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
423 return -1;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
424 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
425 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
426
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
427 ucx_map_remove(data->properties, cl_key);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
428 ucx_map_remove(data->properties, cd_key);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
429 ucx_map_remove(data->properties, lm_key);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
430 ucx_map_remove(data->properties, ct_key);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
431 ucx_map_remove(data->properties, rt_key);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
432 ucx_map_remove(data->properties, cn_key);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
433 ucx_map_remove(data->properties, ck_key);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
434 ucx_map_remove(data->properties, ch_key);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
435
137
01cb9aabff05 fixed horrible bugs, davql hopefully just works now (without order by yet)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
436 resource_free_properties(sn, data->properties);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
437 data->properties = new_properties;
136
59058927b885 empty field results will no longer be added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
438
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
439 free(cl_keystr.ptr);
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
440 free(cd_keystr.ptr);
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
441 free(lm_keystr.ptr);
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
442 free(ct_keystr.ptr);
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
443 free(rt_keystr.ptr);
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
444 free(cn_keystr.ptr);
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
445 free(ck_keystr.ptr);
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
446 free(ch_keystr.ptr);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
447
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
448 return 0;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
449 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
450
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
451 /*
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
452 * execute a davql select statement
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
453 */
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
454 DavResult dav_exec_select(DavSession *sn, DavQLStatement *st, va_list ap) {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
455 UcxMempool *mp = ucx_mempool_new(128);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
456 DavResult result;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
457 result.result = NULL;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
458 result.status = 1;
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
459
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
460 DavQLArgList *args = dav_ql_get_args(st, ap);
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
461 if(!args) {
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
462 return result;
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
463 }
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
464 ucx_mempool_reg_destr(mp, args, (ucx_destructor)dav_ql_free_arglist);
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
465
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
466 int isallprop;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
467 UcxBuffer *rqbuf = fieldlist2propfindrequest(sn, mp, st->fields, &isallprop);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
468 if(!rqbuf) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
469 ucx_mempool_destroy(mp);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
470 return result;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
471 }
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
472 ucx_mempool_reg_destr(mp, rqbuf, (ucx_destructor)ucx_buffer_free);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
473
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
474 // compile field list
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
475 UcxList *cfieldlist = NULL;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
476 UCX_FOREACH(elm, st->fields) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
477 DavQLField *field = elm->data;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
478 if(sstrcmp(field->name, S("*")) && sstrcmp(field->name, S("-"))) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
479 // compile field expression
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
480 UcxBuffer *code = dav_compile_expr(
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
481 sn->context,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
482 mp->allocator,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
483 field->expr,
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
484 args);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
485 if(!code) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
486 // TODO: set error string
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
487 return result;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
488 }
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
489 ucx_mempool_reg_destr(mp, code, (ucx_destructor)ucx_buffer_free);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
490 DavCompiledField *cfield = ucx_mempool_malloc(
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
491 mp,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
492 sizeof(DavCompiledField));
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
493
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
494 char *ns;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
495 char *name;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
496 dav_get_property_namespace_str(
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
497 sn->context,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
498 sstrdup_a(mp->allocator, field->name).ptr,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
499 &ns,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
500 &name);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
501 if(!ns || !name) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
502 // TODO: set error string
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
503 return result;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
504 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
505 cfield->ns = ns;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
506 cfield->name = name;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
507 cfield->code = code;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
508 cfieldlist = ucx_list_append_a(mp->allocator, cfieldlist, cfield);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
509 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
510 }
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
511
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
512 // get path string
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
513 davqlerror_t error;
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
514 sstr_t path = dav_format_string(mp->allocator, st->path, args, &error);
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
515 if(error) {
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
516 // TODO: cleanup
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
517 ucx_mempool_destroy(mp);
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
518 return result;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
519 }
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
520
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
521 int depth = st->depth == DAV_DEPTH_PLACEHOLDER ?
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
522 dav_ql_getarg_int(args) : st->depth;
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
523
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
524 UcxBuffer *where = dav_compile_expr(sn->context, mp->allocator, st->where, args);
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
525 if(st->where && !where) {
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
526 // TODO: cleanup
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
527 ucx_mempool_destroy(mp);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
528 return result;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
529 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
530 if(where) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
531 ucx_mempool_reg_destr(mp, where, (ucx_destructor)ucx_buffer_free);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
532 }
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
533
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
534 // compile order criterion
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
535 UcxList *ordercr = NULL;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
536 UCX_FOREACH(elm, st->orderby) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
537 DavQLOrderCriterion *oc = elm->data;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
538 DavQLExpression *column = oc->column;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
539 //printf("%.*s %s\n", column->srctext.length, column->srctext.ptr, oc->descending ? "desc" : "asc");
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
540 if(column->type == DAVQL_IDENTIFIER) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
541 // TODO: remove code duplication (add_cmd)
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
542 davqlresprop_t resprop;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
543 sstr_t propertyname = sstrchr(column->srctext, ':');
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
544 if(propertyname.length > 0) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
545 char *ns;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
546 char *name;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
547 dav_get_property_namespace_str(
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
548 sn->context,
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
549 sstrdup_a(mp->allocator, column->srctext).ptr,
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
550 &ns,
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
551 &name);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
552 if(ns && name) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
553 DavOrderCriterion *cr = ucx_mempool_malloc(mp, sizeof(DavOrderCriterion));
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
554 cr->type = 1;
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
555 sstr_t keystr = dav_property_key_a(mp->allocator, ns, name);
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 478
diff changeset
556 cr->column.property = ucx_key(keystr.ptr, keystr.length);
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
557 cr->descending = oc->descending;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
558 ordercr = ucx_list_append_a(mp->allocator, ordercr, cr);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
559 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
560 // error
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
561 // TODO: cleanup
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
562 ucx_mempool_destroy(mp);
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
563 return result;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
564 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
565 } else if(dav_identifier2resprop(column->srctext, &resprop)) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
566 DavOrderCriterion *cr = ucx_mempool_malloc(mp, sizeof(DavOrderCriterion));
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
567 cr->type = 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
568 cr->column.resprop = resprop;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
569 cr->descending = oc->descending;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
570 ordercr = ucx_list_append_a(mp->allocator, ordercr, cr);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
571 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
572 // error
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
573 // TODO: cleanup
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
574 ucx_mempool_destroy(mp);
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
575 return result;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
576 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
577
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
578 } else if(column->type == DAVQL_NUMBER) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
579 // TODO: implement
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
580 fprintf(stderr, "order by number not supported\n");
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
581 return result;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
582 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
583 // something is broken
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
584 // TODO: cleanup
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
585 ucx_mempool_destroy(mp);
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
586 return result;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
587 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
588 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
589
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
590 DavResource *selroot = dav_resource_new(sn, path.ptr);
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
591
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
592 UcxList *stack = NULL; // stack with DavResource* elements
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
593 // initialize the stack with the requested resource
157
8dccc3063e28 changed name of a local variable to avoid a later name collision
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
594 DavQLRes *res = ucx_mempool_malloc(mp, sizeof(DavQLRes));
8dccc3063e28 changed name of a local variable to avoid a later name collision
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
595 res->resource = selroot;
8dccc3063e28 changed name of a local variable to avoid a later name collision
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
596 res->depth = 0;
8dccc3063e28 changed name of a local variable to avoid a later name collision
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
597 stack = ucx_list_prepend(stack, res);
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
598
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
599 // reuseable response buffer
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
600 UcxBuffer *rpbuf = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND);
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
601 if(!rpbuf) {
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
602 // TODO: cleanup
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
603 ucx_mempool_destroy(mp);
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
604 return result;
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
605 }
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
606 ucx_mempool_reg_destr(mp, rpbuf, (ucx_destructor)ucx_buffer_free);
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
607
137
01cb9aabff05 fixed horrible bugs, davql hopefully just works now (without order by yet)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
608 result.result = selroot;
01cb9aabff05 fixed horrible bugs, davql hopefully just works now (without order by yet)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
609 result.status = 0;
01cb9aabff05 fixed horrible bugs, davql hopefully just works now (without order by yet)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
610
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
611 // do a propfind request for each resource on the stack
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
612 while(stack) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
613 DavQLRes *sr = stack->data; // get first element from the stack
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
614 stack = ucx_list_remove(stack, stack); // remove first element
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
615 DavResource *root = sr->resource;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
616
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
617 util_set_url(sn, dav_resource_get_href(sr->resource));
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 351
diff changeset
618 CURLcode ret = do_propfind_request(sn, rqbuf, rpbuf);
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
619 long http_status = 0;
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
620 curl_easy_getinfo(sn->handle, CURLINFO_RESPONSE_CODE, &http_status);
137
01cb9aabff05 fixed horrible bugs, davql hopefully just works now (without order by yet)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
621 //printf("rpbuf: %s %s\n%.*s\n\n", sr->resource->path, sr->resource->href, rpbuf->pos, rpbuf->space);
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
622
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
623 if(ret == CURLE_OK && http_status == 207) {
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
624 // in case of an redirect we have to adjust resource->href
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
625 dav_set_effective_href(sn, root);
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 475
diff changeset
626
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
627 // propfind request successful, now parse the response
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
628 char *url = "http://url/";
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
629 PropfindParser *parser = create_propfind_parser(rpbuf, url);
137
01cb9aabff05 fixed horrible bugs, davql hopefully just works now (without order by yet)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
630 // TODO: test if parser is null
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
631 ResponseTag response;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
632 int r;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
633 while((r = get_propfind_response(parser, &response)) != 0) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
634 if(r == -1) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
635 // error
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
636 result.status = -1;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
637 // TODO: free resources
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
638 cleanup_response(&response);
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
639 break;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
640 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
641
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
642 // the propfind multistatus response contains responses
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
643 // for the requested resource and all childs
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
644 // determine if the response is a child or not
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
645 if(hrefeq(sn, root->href, response.href)) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
646 // response is the currently requested resource
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
647 // and not a child
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
648
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
649 // add properties
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
650 add_properties(root, &response);
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
651 cleanup_response(&response);
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
652
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
653 if(root == selroot) {
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
654 // The current root is the root of the select query.
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
655 // In this case we have to check the where clause.
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
656 // If root is not selroot, the where clause was
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
657 // already checked for the resource before it was
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
658 // added to the stack.
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
659 DavQLStackObj where_result;
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
660 if(!dav_exec_expr(where, root, &where_result)) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 148
diff changeset
661 if(where_result.data.integer != 0) {
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
662 if(!reset_properties(sn, &result, root, cfieldlist)) {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
663 continue;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
664 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
665 result.status = -1;
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
666 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
667 }
143
d8b01bed3d83 fixed get command and davql exec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
668 result.result = NULL;
d8b01bed3d83 fixed get command and davql exec
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
669 result.status = -1;
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
670 dav_resource_free_all(selroot);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
671 ucx_list_free(stack);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
672 break;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
673 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
674 } else {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
675 DavResource *child = response2resource(
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
676 sn,
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
677 &response,
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
678 root->path);
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
679 cleanup_response(&response);
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
680 // check where clause
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
681 DavQLStackObj where_result;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
682 if(!dav_exec_expr(where, child, &where_result)) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
683 if(where_result.data.integer != 0) {
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
684 if(!reset_properties(sn, &result, child, cfieldlist)) {
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
685 //resource_add_child(root, child);
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
686 resource_add_ordered_child(root, child, ordercr);
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
687 if(child->iscollection &&
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
688 (depth < 0 || depth > sr->depth+1))
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
689 {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
690 DavQLRes *rs = ucx_mempool_malloc(
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
691 mp,
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
692 sizeof(DavQLRes));
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
693 rs->resource = child;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
694 rs->depth = sr->depth + 1;
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
695 stack = ucx_list_prepend(stack, rs);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
696 }
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
697 } else {
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
698 dav_resource_free(child);
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
699 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
700 } else {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
701 dav_resource_free(child);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
702 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
703 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
704 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
705 }
148
f21ee22170bf fixed many davql exec memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
706 destroy_propfind_parser(parser);
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
707 } else {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
708 dav_session_set_error(sn, ret, http_status);
137
01cb9aabff05 fixed horrible bugs, davql hopefully just works now (without order by yet)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
709 result.result = NULL;
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
710 result.status = -1;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
711 dav_resource_free_all(selroot);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
712 break;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
713 }
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
714
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
715 // reset response buffer
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
716 ucx_buffer_seek(rpbuf, SEEK_SET, 0);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
717 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
718
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
719 ucx_mempool_destroy(mp);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
720 return result;
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
721 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
722
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
723 static int count_func_args(DavQLExpression *expr) {
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
724 int count = 0;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
725 DavQLExpression *arg = expr->right;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
726 while(arg) {
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
727 count++;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
728 if(arg->op == DAVQL_ARGLIST) {
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
729 arg = arg->right;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
730 } else {
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
731 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
732 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
733 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
734 return count;
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
735 }
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
736
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
737 int dav_identifier2resprop(sstr_t src, davqlresprop_t *prop) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
738 if(!sstrcmp(src, S("name"))) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
739 *prop = DAVQL_RES_NAME;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
740 } else if(!sstrcmp(src, S("path"))) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
741 *prop = DAVQL_RES_PATH;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
742 } else if(!sstrcmp(src, S("href"))) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
743 *prop = DAVQL_RES_HREF;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
744 } else if(!sstrcmp(src, S("contentlength"))) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
745 *prop = DAVQL_RES_CONTENTLENGTH;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
746 } else if(!sstrcmp(src, S("contenttype"))) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
747 *prop = DAVQL_RES_CONTENTTYPE;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
748 } else if(!sstrcmp(src, S("creationdate"))) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
749 *prop = DAVQL_RES_CREATIONDATE;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
750 } else if(!sstrcmp(src, S("lastmodified"))) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
751 *prop = DAVQL_RES_LASTMODIFIED;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
752 } else if(!sstrcmp(src, S("iscollection"))) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
753 *prop = DAVQL_RES_ISCOLLECTION;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
754 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
755 return 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
756 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
757 return 1;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
758 }
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
759
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
760 static int add_cmd(DavContext *ctx, UcxAllocator *a, UcxBuffer *bcode, DavQLExpression *expr, DavQLArgList *ap) {
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
761 if(!expr) {
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
762 return 0;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
763 }
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
764
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
765 int numcmd = 1;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
766 DavQLCmd cmd;
538
a7402e35ad87 fixes wrong memset
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 505
diff changeset
767 memset(&cmd, 0, sizeof(DavQLCmd));
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
768 davqlerror_t error;
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
769
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
770 sstr_t src = expr->srctext;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
771 switch(expr->type) {
145
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
772 default: break;
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
773 case DAVQL_NUMBER: {
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
774 cmd.type = DAVQL_CMD_INT;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
775 if(src.ptr[0] == '%') {
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
776 cmd.data.integer = dav_ql_getarg_int(ap);
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
777 } else if(util_strtoint(src.ptr, &cmd.data.integer)) {
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
778 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
779 } else {
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
780 // error
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
781 return -1;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
782 }
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
783
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
784 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
785 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
786 case DAVQL_STRING: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
787 cmd.type = DAVQL_CMD_STRING;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
788 cmd.data.string = dav_format_string(a, src, ap, &error);
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
789 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
790 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
791 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
792 case DAVQL_TIMESTAMP: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
793 if(src.ptr[0] == '%') {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
794 cmd.type = DAVQL_CMD_TIMESTAMP;
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
795 cmd.data.timestamp = dav_ql_getarg_time(ap);
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
796 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
797 } else {
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
798 // error
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
799 return -1;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
800 }
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
801 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
802 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
803 case DAVQL_IDENTIFIER: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
804 sstr_t propertyname = sstrchr(src, ':');
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
805 cmd.type = DAVQL_CMD_RES_IDENTIFIER;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
806 if(propertyname.length > 0) {
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
807 cmd.type = DAVQL_CMD_PROP_IDENTIFIER;
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
808 char *ns;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
809 char *name;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
810 dav_get_property_namespace_str(
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
811 ctx,
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
812 sstrdup_a(a, src).ptr,
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
813 &ns,
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
814 &name);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
815 if(ns && name) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
816 cmd.data.property.ns = ns;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
817 cmd.data.property.name = name;
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
818 } else {
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
819 // error
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
820 return -1;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
821 }
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
822 } else if(!dav_identifier2resprop(src, &cmd.data.resprop)) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
823 if(!sstrcmp(src, S("true"))) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
824 cmd.type = DAVQL_CMD_INT;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
825 cmd.data.integer = 1;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
826 } else if(!sstrcmp(src, S("false"))) {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
827 cmd.type = DAVQL_CMD_INT;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
828 cmd.data.integer = 0;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
829 } else {
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
830 // error, unknown identifier
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
831 return -1;
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
832 }
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
833 }
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
834 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
835 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
836 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
837 case DAVQL_UNARY: {
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
838 numcmd += add_cmd(ctx, a, bcode, expr->left, ap);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
839 switch(expr->op) {
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
840 case DAVQL_ADD: {
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
841 // noop
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
842 numcmd = 0;
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
843 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
844 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
845 case DAVQL_SUB: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
846 cmd.type = DAVQL_CMD_OP_UNARY_SUB;
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
847 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
848 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
849 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
850 case DAVQL_NEG: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
851 cmd.type = DAVQL_CMD_OP_UNARY_NEG;
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
852 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
853 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
854 }
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
855 default: break;
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
856 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
857 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
858 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
859 case DAVQL_BINARY: {
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
860 numcmd += add_cmd(ctx, a, bcode, expr->left, ap);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
861 numcmd += add_cmd(ctx, a, bcode, expr->right, ap);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
862 switch(expr->op) {
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
863 case DAVQL_ADD: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
864 cmd.type = DAVQL_CMD_OP_BINARY_ADD;
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
865 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
866 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
867 case DAVQL_SUB: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
868 cmd.type = DAVQL_CMD_OP_BINARY_SUB;
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
869 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
870 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
871 case DAVQL_MUL: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
872 cmd.type = DAVQL_CMD_OP_BINARY_MUL;
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
873 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
874 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
875 case DAVQL_DIV: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
876 cmd.type = DAVQL_CMD_OP_BINARY_DIV;
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
877 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
878 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
879 case DAVQL_AND: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
880 cmd.type = DAVQL_CMD_OP_BINARY_AND;
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
881 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
882 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
883 case DAVQL_OR: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
884 cmd.type = DAVQL_CMD_OP_BINARY_OR;
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
885 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
886 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
887 case DAVQL_XOR: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
888 cmd.type = DAVQL_CMD_OP_BINARY_XOR;
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
889 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
890 }
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
891 default: break;
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
892 }
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
893 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
894 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
895 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
896 case DAVQL_LOGICAL: {
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
897 if(expr->left && expr->right && expr->op != DAVQL_LOR) {
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
898 numcmd += add_cmd(ctx, a, bcode, expr->left, ap);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
899 numcmd += add_cmd(ctx, a, bcode, expr->right, ap);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
900 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
901
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
902 switch(expr->op) {
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
903 case DAVQL_NOT: {
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
904 numcmd += add_cmd(ctx, a, bcode, expr->left, ap);
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
905 cmd.type = DAVQL_CMD_OP_LOGICAL_NOT;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
906 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
907 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
908 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
909 case DAVQL_LAND: {
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
910 cmd.type = DAVQL_CMD_OP_LOGICAL_AND;
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
911 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
912 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
913 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
914 case DAVQL_LOR: {
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
915 int nleft = add_cmd(ctx, a, bcode, expr->left, ap);
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
916
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
917 cmd.type = DAVQL_CMD_OP_LOGICAL_OR_L;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
918 DavQLCmd *or_l = (DavQLCmd*)(bcode->space + bcode->pos);
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
919 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
920
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
921 int nright = add_cmd(ctx, a, bcode, expr->right, ap);
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
922 or_l->data.integer = nright + 1;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
923
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
924 cmd.type = DAVQL_CMD_OP_LOGICAL_OR;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
925 cmd.data.integer = 0;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
926 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
927
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
928 numcmd += nleft + nright;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
929 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
930 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
931 case DAVQL_LXOR: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
932 cmd.type = DAVQL_CMD_OP_LOGICAL_XOR;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
933 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
934 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
935 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
936 case DAVQL_EQ: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
937 cmd.type = DAVQL_CMD_OP_EQ;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
938 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
939 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
940 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
941 case DAVQL_NEQ: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
942 cmd.type = DAVQL_CMD_OP_NEQ;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
943 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
944 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
945 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
946 case DAVQL_LT: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
947 cmd.type = DAVQL_CMD_OP_LT;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
948 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
949 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
950 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
951 case DAVQL_GT: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
952 cmd.type = DAVQL_CMD_OP_GT;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
953 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
954 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
955 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
956 case DAVQL_LE: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
957 cmd.type = DAVQL_CMD_OP_LE;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
958 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
959 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
960 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
961 case DAVQL_GE: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
962 cmd.type = DAVQL_CMD_OP_GE;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
963 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
964 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
965 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
966 case DAVQL_LIKE: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
967 cmd.type = DAVQL_CMD_OP_LIKE;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
968 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
969 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
970 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
971 case DAVQL_UNLIKE: {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
972 cmd.type = DAVQL_CMD_OP_UNLIKE;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
973 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
974 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
975 }
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
976 default: break;
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
977 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
978 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
979 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
980 case DAVQL_FUNCCALL: {
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
981 switch(expr->op) {
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
982 case DAVQL_CALL: {
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
983 int nright = add_cmd(ctx, a, bcode, expr->right, ap);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
984 // TODO: count args
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
985 DavQLExpression *funcid = expr->left;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
986 if(!funcid && funcid->type != DAVQL_IDENTIFIER) {
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
987 // fail
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
988 return -1;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
989 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
990
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
991 // numargs
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
992 cmd.type = DAVQL_CMD_INT;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
993 cmd.data.integer = count_func_args(expr);
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
994 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
995
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
996 // TODO: resolve function name
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
997 cmd.type = DAVQL_CMD_CALL;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
998 cmd.data.func = NULL;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
999 ucx_buffer_write(&cmd, sizeof(cmd), 1, bcode);
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
1000
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
1001 numcmd = 2;
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1002 numcmd += nright;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1003 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1004 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1005 case DAVQL_ARGLIST: {
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1006 numcmd = 0;
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
1007 numcmd += add_cmd(ctx, a, bcode, expr->left, ap);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
1008 numcmd += add_cmd(ctx, a, bcode, expr->right, ap);
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1009 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1010 }
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
1011 default: break;
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1012 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1013 break;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1014 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1015 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1016 return numcmd;
104
6fb4d24d9df9 added davqlexec source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1017 }
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1018
365
f04ab0420512 fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
1019 UcxBuffer* dav_compile_expr(DavContext *ctx, UcxAllocator *a, DavQLExpression *lexpr, DavQLArgList *ap) {
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1020 UcxBuffer *bcode = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND);
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1021 if(!bcode) {
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1022 return NULL;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1023 }
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1024
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
1025 if(add_cmd(ctx, a, bcode, lexpr, ap) <= 0) {
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
1026 ucx_buffer_free(bcode);
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
1027 return NULL;
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
1028 }
123
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1029
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1030 return bcode;
806c4dccf2ae added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
1031 }
124
41939c8f3f9c expression compiler generates byte code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
1032
249
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1033 static int cmd_str_cmp(DavQLStackObj obj1, DavQLStackObj obj2, davqlcmdtype_t cmd) {
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1034 sstr_t s1 = obj1.type == 1 ?
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1035 sstrn(obj1.data.string, obj1.length) :
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1036 ucx_sprintf("%" PRId64, obj1.data.integer);
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1037 sstr_t s2 = obj1.type == 1 ?
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1038 sstrn(obj2.data.string, obj2.length) :
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1039 ucx_sprintf("%" PRId64, obj2.data.integer);
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1040
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1041 int res = 0;
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1042 switch(cmd) {
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1043 case DAVQL_CMD_OP_EQ: {
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1044 res = sstrcmp(s1, s2) == 0;
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1045 break;
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1046 }
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1047 case DAVQL_CMD_OP_NEQ: {
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1048 res = sstrcmp(s1, s2) != 0;
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1049 break;
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1050 }
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1051 case DAVQL_CMD_OP_LT: {
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1052 res = sstrcmp(s1, s2) < 0;
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1053 break;
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1054 }
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1055 case DAVQL_CMD_OP_GT: {
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1056 res = sstrcmp(s1, s2) > 0;
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1057 break;
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1058 }
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1059 case DAVQL_CMD_OP_LE: {
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1060 res = sstrcmp(s1, s2) <= 0;
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1061 break;
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1062 }
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1063 case DAVQL_CMD_OP_GE: {
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1064 res = sstrcmp(s1, s2) >= 0;
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1065 break;
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1066 }
351
11789a88d0b0 fixes some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
1067 default: break;
249
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1068 }
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1069
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1070 if(obj1.type == 0) {
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1071 free(s1.ptr);
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1072 }
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1073 if(obj2.type == 0) {
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1074 free(s2.ptr);
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1075 }
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1076
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1077 return res;
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1078 }
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1079
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1080 int dav_exec_expr(UcxBuffer *bcode, DavResource *res, DavQLStackObj *result) {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1081 if(!bcode) {
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1082 result->type = 0;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1083 result->length = 0;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1084 result->data.integer = 1;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1085 return 0;
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1086 }
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1087
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1088 size_t count = bcode->pos / sizeof(DavQLCmd);
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1089 DavQLCmd *cmds = (DavQLCmd*)bcode->space;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1090
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1091 // create execution stack
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1092 size_t stsize = 64;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1093 size_t stpos = 0;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1094 DavQLStackObj *stack = calloc(stsize, sizeof(DavQLStackObj));
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1095 #define DAVQL_PUSH(obj) \
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1096 if(stpos == stsize) { \
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1097 stsize += 64; \
290
1e3e374d9386 adds clean handling in case the stack of dav_exec_expr() runs out of memory
Mike Becker <universe@uap-core.de>
parents: 289
diff changeset
1098 DavQLStackObj *stack_newptr; \
1e3e374d9386 adds clean handling in case the stack of dav_exec_expr() runs out of memory
Mike Becker <universe@uap-core.de>
parents: 289
diff changeset
1099 stack_newptr = realloc(stack, stsize * sizeof(DavQLStackObj)); \
1e3e374d9386 adds clean handling in case the stack of dav_exec_expr() runs out of memory
Mike Becker <universe@uap-core.de>
parents: 289
diff changeset
1100 if(stack_newptr) { \
1e3e374d9386 adds clean handling in case the stack of dav_exec_expr() runs out of memory
Mike Becker <universe@uap-core.de>
parents: 289
diff changeset
1101 stack = stack_newptr; \
1e3e374d9386 adds clean handling in case the stack of dav_exec_expr() runs out of memory
Mike Becker <universe@uap-core.de>
parents: 289
diff changeset
1102 } else { \
1e3e374d9386 adds clean handling in case the stack of dav_exec_expr() runs out of memory
Mike Becker <universe@uap-core.de>
parents: 289
diff changeset
1103 free(stack); \
1e3e374d9386 adds clean handling in case the stack of dav_exec_expr() runs out of memory
Mike Becker <universe@uap-core.de>
parents: 289
diff changeset
1104 return -1; \
1e3e374d9386 adds clean handling in case the stack of dav_exec_expr() runs out of memory
Mike Becker <universe@uap-core.de>
parents: 289
diff changeset
1105 }\
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1106 } \
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1107 stack[stpos++] = obj;
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1108 #define DAVQL_PUSH_INT(intval) \
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1109 { \
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1110 DavQLStackObj intobj; \
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1111 intobj.type = 0; \
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1112 intobj.length = 0; \
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1113 intobj.data.integer = intval; \
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1114 DAVQL_PUSH(intobj); \
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1115 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1116 #define DAVQL_POP() stack[--stpos]
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1117
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1118 DavQLStackObj obj;
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1119 int ret = 0;
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1120 for(size_t i=0;i<count;i++) {
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1121 DavQLCmd cmd = cmds[i];
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1122 switch(cmd.type) {
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1123 case DAVQL_CMD_INT: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1124 //printf("int %lld\n", cmd.data.integer);
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1125 obj.type = 0;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1126 obj.length = 0;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1127 obj.data.integer = cmd.data.integer;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1128 DAVQL_PUSH(obj);
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1129 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1130 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1131 case DAVQL_CMD_STRING: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1132 //printf("string \"%.*s\"\n", cmd.data.string.length, cmd.data.string.ptr);
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1133 obj.type = 1;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1134 obj.length = cmd.data.string.length;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1135 obj.data.string = cmd.data.string.ptr;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1136 DAVQL_PUSH(obj);
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1137 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1138 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1139 case DAVQL_CMD_TIMESTAMP: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1140 //printf("timestamp %d\n", cmd.data.timestamp);
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1141 obj.type = 0;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1142 obj.length = 0;
136
59058927b885 empty field results will no longer be added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
1143 obj.data.integer = (int64_t)cmd.data.timestamp;
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1144 DAVQL_PUSH(obj);
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1145 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1146 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1147 case DAVQL_CMD_RES_IDENTIFIER: {
139
c6424aebcf5e implemented davql order by
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
1148 //char *rid[8] = {"name", "path", "href", "contentlength", "contenttype", "creationdate", "lastmodified", "iscollection"};
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1149 //printf("resprop %s\n", rid[cmd.data.resprop]);
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1150 switch(cmd.data.resprop) {
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1151 case DAVQL_RES_NAME: {
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1152 obj.type = 1;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1153 obj.length = strlen(res->name);
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1154 obj.data.string = res->name;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1155 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1156 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1157 case DAVQL_RES_PATH: {
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1158 obj.type = 1;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1159 obj.length = strlen(res->path);
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1160 obj.data.string = res->path;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1161 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1162 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1163 case DAVQL_RES_HREF: {
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1164 obj.type = 1;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1165 obj.length = strlen(res->href);
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1166 obj.data.string = res->href;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1167 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1168 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1169 case DAVQL_RES_CONTENTLENGTH: {
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1170 obj.type = 0;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1171 obj.length = 0;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1172 obj.data.integer = res->contentlength;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1173 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1174 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1175 case DAVQL_RES_CONTENTTYPE: {
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1176 obj.type = 1;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1177 obj.length = strlen(res->contenttype);
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1178 obj.data.string = res->contenttype;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1179 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1180 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1181 case DAVQL_RES_CREATIONDATE: {
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1182 obj.type = 0;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1183 obj.length = 0;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1184 obj.data.integer = res->creationdate;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1185 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1186 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1187 case DAVQL_RES_LASTMODIFIED: {
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1188 obj.type = 0;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1189 obj.length = 0;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1190 obj.data.integer = res->lastmodified;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1191 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1192 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1193 case DAVQL_RES_ISCOLLECTION: {
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1194 obj.type = 0;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1195 obj.length = 0;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1196 obj.data.integer = res->iscollection;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1197 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1198 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1199 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1200 DAVQL_PUSH(obj);
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1201 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1202 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1203 case DAVQL_CMD_PROP_IDENTIFIER: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1204 //printf("property %s:%s\n", cmd.data.property.ns, cmd.data.property.name);
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1205 //char *value = dav_get_string_property_ns(res, cmd.data.property.ns, cmd.data.property.name);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1206 DavXmlNode *value = dav_get_property_ns(res, cmd.data.property.ns, cmd.data.property.name);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1207 if(dav_xml_isstring(value)) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1208 obj.type = 1;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1209 obj.length = (uint32_t)value->contentlength;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1210 obj.data.string = value->content;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1211 } else {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1212 obj.type = 2;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1213 obj.length = 0;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1214 obj.data.node = value;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
1215 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1216 DAVQL_PUSH(obj);
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1217 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1218 }
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1219 //case DAVQL_CMD_OP_UNARY_ADD: {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1220 // printf("uadd\n");
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1221 // break;
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1222 //}
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1223 case DAVQL_CMD_OP_UNARY_SUB: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1224 //printf("usub\n");
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1225 obj = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1226 if(obj.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1227 obj.data.integer = -obj.data.integer;
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1228 DAVQL_PUSH(obj);
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1229 } else {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1230 ret = -1;
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1231 i = count; // end loop
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1232 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1233 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1234 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1235 case DAVQL_CMD_OP_UNARY_NEG: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1236 //printf("uneg\n");
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1237 obj = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1238 if(obj.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1239 obj.data.integer = obj.data.integer == 0 ? 1 : 0;
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1240 DAVQL_PUSH(obj);
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1241 } else {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1242 ret = -1;
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1243 i = count; // end loop
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1244 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1245 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1246 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1247 case DAVQL_CMD_OP_BINARY_ADD: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1248 //printf("add\n");
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1249 DavQLStackObj obj2 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1250 DavQLStackObj obj1 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1251 if(obj1.type == 0 && obj2.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1252 DAVQL_PUSH_INT(obj1.data.integer + obj2.data.integer);
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1253 } else {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1254 // TODO: string concat
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1255 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1256 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1257 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1258 case DAVQL_CMD_OP_BINARY_SUB: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1259 //printf("sub\n");
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1260 DavQLStackObj obj2 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1261 DavQLStackObj obj1 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1262 if(obj1.type == 0 && obj2.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1263 DAVQL_PUSH_INT(obj1.data.integer - obj2.data.integer);
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1264 } else {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1265 // error
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1266 ret = -1;
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1267 i = count; // end loop
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1268 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1269 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1270 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1271 case DAVQL_CMD_OP_BINARY_MUL: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1272 //printf("mul\n");
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1273 DavQLStackObj obj2 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1274 DavQLStackObj obj1 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1275 if(obj1.type == 0 && obj2.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1276 DAVQL_PUSH_INT(obj1.data.integer * obj2.data.integer);
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1277 } else {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1278 // error
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1279 ret = -1;
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1280 i = count; // end loop
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1281 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1282 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1283 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1284 case DAVQL_CMD_OP_BINARY_DIV: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1285 //printf("div\n");
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1286 DavQLStackObj obj2 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1287 DavQLStackObj obj1 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1288 if(obj1.type == 0 && obj2.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1289 DAVQL_PUSH_INT(obj1.data.integer / obj2.data.integer);
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1290 } else {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1291 // error
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1292 ret = -1;
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1293 i = count; // end loop
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1294 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1295 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1296 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1297 case DAVQL_CMD_OP_BINARY_AND: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1298 //printf("and\n");
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1299 DavQLStackObj obj2 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1300 DavQLStackObj obj1 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1301 if(obj1.type == 0 && obj2.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1302 DAVQL_PUSH_INT(obj1.data.integer & obj2.data.integer);
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1303 } else {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1304 // error
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1305 ret = -1;
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1306 i = count; // end loop
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1307 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1308 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1309 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1310 case DAVQL_CMD_OP_BINARY_OR: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1311 //printf("or\n");
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1312 DavQLStackObj obj2 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1313 DavQLStackObj obj1 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1314 if(obj1.type == 0 && obj2.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1315 DAVQL_PUSH_INT(obj1.data.integer | obj2.data.integer);
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1316 } else {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1317 // error
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1318 ret = -1;
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1319 i = count; // end loop
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1320 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1321 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1322 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1323 case DAVQL_CMD_OP_BINARY_XOR: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1324 //printf("xor\n");
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1325 DavQLStackObj obj2 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1326 DavQLStackObj obj1 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1327 if(obj1.type == 0 && obj2.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1328 DAVQL_PUSH_INT(obj1.data.integer ^ obj2.data.integer);
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1329 } else {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1330 // error
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1331 ret = -1;
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1332 i = count; // end loop
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1333 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1334 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1335 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1336 case DAVQL_CMD_OP_LOGICAL_NOT: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1337 //printf("not\n");
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1338 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1339 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1340 case DAVQL_CMD_OP_LOGICAL_AND: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1341 //printf("land\n");
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1342 DavQLStackObj obj2 = DAVQL_POP();
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1343 DavQLStackObj obj1 = DAVQL_POP();
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1344 int v1 = obj1.type == 0 ? (int)obj1.data.integer : (obj1.data.string ? 1 : 0);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1345 int v2 = obj2.type == 0 ? (int)obj2.data.integer : (obj2.data.string ? 1 : 0);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1346 DAVQL_PUSH_INT(v1 && v2);
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1347 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1348 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1349 case DAVQL_CMD_OP_LOGICAL_OR_L: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1350 //printf("or_l %d\n", cmd.data.integer);
235
0468df02e18f fixed dav get with -u option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1351 DavQLStackObj obj1 = stack[stpos];
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1352 if((obj1.type == 0 && obj1.data.integer) || (obj1.type == 1 && obj1.data.string)) {
235
0468df02e18f fixed dav get with -u option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
1353 stpos--;
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1354 DAVQL_PUSH_INT(1);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1355 i += cmd.data.integer; // jump, skip right subtree of 'or'
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1356 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1357 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1358 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1359 case DAVQL_CMD_OP_LOGICAL_OR: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1360 //printf("or\n");
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1361 DavQLStackObj obj2 = DAVQL_POP();
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1362 DavQLStackObj obj1 = DAVQL_POP();
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1363 int v1 = obj1.type == 0 ? (int)obj1.data.integer : (obj1.data.string ? 1 : 0);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1364 int v2 = obj2.type == 0 ? (int)obj2.data.integer : (obj2.data.string ? 1 : 0);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1365 DAVQL_PUSH_INT(v1 || v2);
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1366 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1367 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1368 case DAVQL_CMD_OP_LOGICAL_XOR: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1369 //printf("lxor\n");
134
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1370 DavQLStackObj obj2 = DAVQL_POP();
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1371 DavQLStackObj obj1 = DAVQL_POP();
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1372 int v1 = obj1.type == 0 ? (int)obj1.data.integer : (obj1.data.string ? 1 : 0);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1373 int v2 = obj2.type == 0 ? (int)obj2.data.integer : (obj2.data.string ? 1 : 0);
4bccc18820e8 implemented execution of field list expressions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
1374 DAVQL_PUSH_INT(!v1 != !v2);
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1375 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1376 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1377 case DAVQL_CMD_OP_EQ: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1378 //printf("eq\n");
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1379 DavQLStackObj obj2 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1380 DavQLStackObj obj1 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1381 if(obj1.type == 0 && obj2.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1382 DAVQL_PUSH_INT(obj1.data.integer == obj2.data.integer);
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1383 } else {
249
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1384 DAVQL_PUSH_INT(cmd_str_cmp(obj1, obj2, cmd.type));
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1385 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1386 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1387 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1388 case DAVQL_CMD_OP_NEQ: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1389 //printf("neq\n");
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1390 DavQLStackObj obj2 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1391 DavQLStackObj obj1 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1392 if(obj1.type == 0 && obj2.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1393 DAVQL_PUSH_INT(obj1.data.integer != obj2.data.integer);
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1394 } else {
249
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1395 DAVQL_PUSH_INT(cmd_str_cmp(obj1, obj2, cmd.type));
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1396 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1397 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1398 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1399 case DAVQL_CMD_OP_LT: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1400 //printf("lt\n");
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1401 DavQLStackObj obj2 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1402 DavQLStackObj obj1 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1403 if(obj1.type == 0 && obj2.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1404 DAVQL_PUSH_INT(obj1.data.integer < obj2.data.integer);
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1405 } else {
249
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1406 DAVQL_PUSH_INT(cmd_str_cmp(obj1, obj2, cmd.type));
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1407 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1408 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1409 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1410 case DAVQL_CMD_OP_GT: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1411 //printf("gt\n");
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1412 DavQLStackObj obj2 = DAVQL_POP();
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1413 DavQLStackObj obj1 = DAVQL_POP();
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1414 if(obj1.type == 0 && obj2.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1415 DAVQL_PUSH_INT(obj1.data.integer > obj2.data.integer);
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1416 } else {
249
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1417 DAVQL_PUSH_INT(cmd_str_cmp(obj1, obj2, cmd.type));
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1418 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1419 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1420 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1421 case DAVQL_CMD_OP_LE: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1422 //printf("le\n");
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1423 DavQLStackObj obj2 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1424 DavQLStackObj obj1 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1425 if(obj1.type == 0 && obj2.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1426 DAVQL_PUSH_INT(obj1.data.integer <= obj2.data.integer);
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1427 } else {
249
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1428 DAVQL_PUSH_INT(cmd_str_cmp(obj1, obj2, cmd.type));
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1429 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1430 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1431 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1432 case DAVQL_CMD_OP_GE: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1433 //printf("ge\n");
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1434 DavQLStackObj obj2 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1435 DavQLStackObj obj1 = DAVQL_POP();
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1436 if(obj1.type == 0 && obj2.type == 0) {
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1437 DAVQL_PUSH_INT(obj1.data.integer >= obj2.data.integer);
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1438 } else {
249
50fb9c9f6671 implemented string functionality for some davql operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1439 DAVQL_PUSH_INT(cmd_str_cmp(obj1, obj2, cmd.type));
133
8c37028f5024 implemented some davql integer operations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
1440 }
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1441 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1442 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1443 case DAVQL_CMD_OP_LIKE: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1444 //printf("like\n");
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1445 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1446 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1447 case DAVQL_CMD_OP_UNLIKE: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1448 //printf("unlike\n");
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1449 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1450 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1451 case DAVQL_CMD_CALL: {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
1452 //printf("call %x\n", cmd.data.func);
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1453 break;
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1454 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1455 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1456 }
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1457
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
1458 if(stpos == 1) {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
1459 *result = stack[0];
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
1460 } else {
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
1461 ret = -1;
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1462 }
128
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
1463 free(stack);
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
1464
649eb328674a implemented minimal executor features and added missing ucx files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
1465 return ret;
126
b156cae29e65 added expression executor prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 124
diff changeset
1466 }

mercurial