libidav/davqlexec.h

Thu, 05 Dec 2019 10:46:39 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 05 Dec 2019 10:46:39 +0100
changeset 691
48ec0ab17011
parent 365
f04ab0420512
child 747
efbd59642577
permissions
-rw-r--r--

fix encryption of files with specific length

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2018 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 struct DavQLArg      DavQLArg;
typedef struct DavQLArgList  DavQLArgList;

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

struct DavQLArg {
    int type;
    union DavQLArgValue{
        int          d;
        unsigned int u;
        char         *s;
        time_t       t;
    } value;
    DavQLArg *next;
};

struct DavQLArgList {
    DavQLArg *first;
    DavQLArg *current;
};

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;

DavQLArgList* dav_ql_get_args(DavQLStatement *st, va_list ap);
void dav_ql_free_arglist(DavQLArgList *args);

int dav_ql_getarg_int(DavQLArgList *args);
unsigned int dav_ql_getarg_uint(DavQLArgList *args);
char* dav_ql_getarg_str(DavQLArgList *args);
time_t dav_ql_getarg_time(DavQLArgList *args);

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, DavQLArgList *args, davqlerror_t *error);
sstr_t dav_format_string(UcxAllocator *a, sstr_t fstr, DavQLArgList *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, DavQLArgList *ap);

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



#ifdef	__cplusplus
}
#endif

#endif	/* DAVQLEXEC_H */

mercurial