# HG changeset patch
# User Mike Becker <universe@uap-core.de>
# Date 1427117370 -3600
# Node ID 4c48ce3b9045106f976b97e01d7a7700c758c8be
# Parent  56962faf2b4267597d827e6b26b6d2a2e35e4063
structure draft for DavQL statements

diff -r 56962faf2b42 -r 4c48ce3b9045 libidav/Makefile
--- a/libidav/Makefile	Sun Feb 08 16:49:03 2015 +0100
+++ b/libidav/Makefile	Mon Mar 23 14:29:30 2015 +0100
@@ -34,6 +34,7 @@
 SRC += resource.c
 SRC += methods.c
 SRC += utils.c
+SRC += davqlparser.c
 SRC += davql.c
 SRC += crypto.c
 
diff -r 56962faf2b42 -r 4c48ce3b9045 libidav/davqlparser.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libidav/davqlparser.c	Mon Mar 23 14:29:30 2015 +0100
@@ -0,0 +1,30 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2015 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "davqlparser.h"
+
diff -r 56962faf2b42 -r 4c48ce3b9045 libidav/davqlparser.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libidav/davqlparser.h	Mon Mar 23 14:29:30 2015 +0100
@@ -0,0 +1,138 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2015 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DAVQLPARSER_H
+#define	DAVQLPARSER_H
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+#include "ucx/string.h"
+#include "ucx/list.h"
+
+/**
+ * Enumeration of possible statement types.
+ */
+typedef enum {GET, PUT} davqltype_t;
+
+/**
+ * Enumeration of possible expression types.
+ */
+typedef enum {LITERAL, UNARY, BINARY, LOGICAL} davqlexprtype_t;
+
+/**
+ * Enumeration of possible expression operators.
+ */
+typedef enum {
+    ADD, SUB, MUL, DIV,
+    AND, OR, XOR, NEG,
+    NOT, LAND, LOR
+} davqloperator_t;
+
+/**
+ * An expression within a DAVQL query.
+ */
+typedef struct _davqlexpr DavQLExpression;
+
+/**
+ * The structure for type DavQLExpression.
+ */
+struct _davqlexpr {
+    /**
+     * The original expression text.
+     * Contains the literal value, if type is LITERAL.
+     */
+    sstr_t srctext;
+    /**
+     * The expression type.
+     */
+    davqlexprtype_t type;
+    /**
+     * Operator.
+     * 
+     */
+    davqloperator_t op;
+    /**
+     * Left or single operand.
+     * <code>NULL</code> for literals.
+     */
+    DavQLExpression *expr1;
+    /**
+     * Right operand.
+     * <code>NULL</code> for literals or unary expressions.
+     */
+    DavQLExpression *expr2;
+};
+
+
+/**
+ * Query statement object.
+ * Contains the binary information about the parsed query.
+ */
+typedef struct {
+    /**
+     * The original query text.
+     */
+    sstr_t srctext;
+    /**
+     * The statement type.
+     */
+    davqltype_t type;
+    /**
+     * The list of field names (sstr_t).
+     * <ul>
+     * <li>GET: the list of DAV properties for projection</li>
+     * <li>PUT: the list of DAV properties that shall receive new values</li>
+     * </ul>
+     * This may be <code>NULL</code> for GET queries, to request all properties.
+     */
+    UcxList* fields;
+    /**
+     * The list of DavQLExpressions for the new DAV property values.
+     * This is <code>NULL</code> for GET queries.
+     */
+    UcxList* putvalues;
+    /**
+     * Logical expression for selection.
+     */
+    DavQLExpression* where;
+    /**
+     * The recursion depth for the statement.
+     * Defaults to SIZE_MAX (unbound recursion).
+     */
+    size_t depth;
+} DavQLStatement;
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* DAVQLPARSER_H */
+