libidav/davqlexec.h

Thu, 21 Dec 2017 19:48:27 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 21 Dec 2017 19:48:27 +0100
changeset 359
bacb54502b24
parent 348
b79fb94f9e0a
child 365
f04ab0420512
permissions
-rw-r--r--

davql: allow ANYWHERE keyword in SELECT statements

This may seem pointless, but users might want to be explicit about this and the grammar is more consistent.

This commit also adds some no-ops to the functions body of the SET parser, because some day the grammar might allow more clauses after the WHERE clause.

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2016 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 DAVQLEXEC_H
#define	DAVQLEXEC_H

#include <stdarg.h>
#include "davqlparser.h"
#include "webdav.h"

#include <ucx/buffer.h>

#ifdef	__cplusplus
extern "C" {
#endif
    
typedef struct DavQLCmd      DavQLCmd;
typedef struct DavQLStackObj DavQLStackObj;
typedef struct DavQLRes      DavQLRes;

typedef void*(*davql_func)(); // TODO: interface?

typedef enum {
    DAVQL_OK = 0,
    DAVQL_UNSUPPORTED_FORMATCHAR,
    DAVQL_UNKNOWN_FORMATCHAR
} davqlerror_t;

typedef enum {
    DAVQL_CMD_INT = 0,
    DAVQL_CMD_STRING,
    DAVQL_CMD_TIMESTAMP,
    DAVQL_CMD_RES_IDENTIFIER,
    DAVQL_CMD_PROP_IDENTIFIER,
    //DAVQL_CMD_OP_UNARY_ADD,
    DAVQL_CMD_OP_UNARY_SUB,
    DAVQL_CMD_OP_UNARY_NEG,
    DAVQL_CMD_OP_BINARY_ADD,
    DAVQL_CMD_OP_BINARY_SUB,
    DAVQL_CMD_OP_BINARY_MUL,
    DAVQL_CMD_OP_BINARY_DIV,
    DAVQL_CMD_OP_BINARY_AND,
    DAVQL_CMD_OP_BINARY_OR,
    DAVQL_CMD_OP_BINARY_XOR,
    DAVQL_CMD_OP_LOGICAL_NOT,
    DAVQL_CMD_OP_LOGICAL_AND,
    DAVQL_CMD_OP_LOGICAL_OR_L,
    DAVQL_CMD_OP_LOGICAL_OR,
    DAVQL_CMD_OP_LOGICAL_XOR,
    DAVQL_CMD_OP_EQ,
    DAVQL_CMD_OP_NEQ,
    DAVQL_CMD_OP_LT,
    DAVQL_CMD_OP_GT,
    DAVQL_CMD_OP_LE,
    DAVQL_CMD_OP_GE,
    DAVQL_CMD_OP_LIKE,
    DAVQL_CMD_OP_UNLIKE,
    DAVQL_CMD_CALL
} davqlcmdtype_t;

typedef enum {
    DAVQL_RES_NAME = 0,
    DAVQL_RES_PATH,
    DAVQL_RES_HREF,
    DAVQL_RES_CONTENTLENGTH,
    DAVQL_RES_CONTENTTYPE,
    DAVQL_RES_CREATIONDATE,
    DAVQL_RES_LASTMODIFIED,
    DAVQL_RES_ISCOLLECTION
} davqlresprop_t;

struct DavQLCmd {
    davqlcmdtype_t type;
    union DavQLCmdData {
        int64_t        integer;
        sstr_t         string;
        time_t         timestamp;
        davqlresprop_t resprop;
        DavPropName    property;
        davql_func     func;
    } data;
};

struct DavQLStackObj {
    int32_t  type; // 0: int, 1: string, 2: xml
    uint32_t length;
    union DavQLStackData {
        int64_t    integer;
        char       *string;
        DavXmlNode *node;
    } data;
};

struct DavQLRes {
    DavResource *resource;
    int depth;
};

typedef struct DavCompiledField {
    char *ns;
    char *name;
    UcxBuffer *code;
} DavCompiledField;

typedef struct DavOrderCriterion {
    int type; // 0: resprop, 1: property
    union DavQLColumn {
        davqlresprop_t resprop;
        UcxKey property;
    } column;
    _Bool descending;
} DavOrderCriterion;
    
DavResult dav_statement_exec(DavSession *sn, DavQLStatement *st, ...);
DavResult dav_statement_execv(DavSession *sn, DavQLStatement *st, va_list ap);

UcxBuffer* dav_path_string(sstr_t src, va_list ap, davqlerror_t *error);
sstr_t dav_format_string(UcxAllocator *a, sstr_t fstr, va_list ap, davqlerror_t *error);

DavResult dav_exec_select(DavSession *sn, DavQLStatement *st, va_list ap);

int dav_identifier2resprop(sstr_t src, davqlresprop_t *prop);

UcxBuffer* dav_compile_expr(DavContext *ctx, UcxAllocator *a, DavQLExpression *lexpr, va_list ap);

int dav_exec_expr(UcxBuffer *bcode, DavResource *res, DavQLStackObj *result);



#ifdef	__cplusplus
}
#endif

#endif	/* DAVQLEXEC_H */

mercurial