libidav/davqlexec.h

Thu, 14 Nov 2024 23:22:35 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 14 Nov 2024 23:22:35 +0100
changeset 85
44ebbb4c8a13
parent 1
b5bb7b3cd597
permissions
-rw-r--r--

add support for secret store credentials when connecting to repositories, resolves #496

/*
 * 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 <cx/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,
    DAVQL_OOM
} 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;
        cxmutstr       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;
    CxBuffer *code;
} DavCompiledField;

typedef struct DavOrderCriterion {
    int type; // 0: resprop, 1: property
    union DavQLColumn {
        davqlresprop_t resprop;
        CxHashKey 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);

CxBuffer* dav_path_string(cxmutstr src, DavQLArgList *args, davqlerror_t *error);
cxmutstr dav_format_string(const CxAllocator *a, cxstring fstr, DavQLArgList *ap, davqlerror_t *error);

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

int dav_identifier2resprop(cxstring src, davqlresprop_t *prop);

CxBuffer* dav_compile_expr(DavContext *ctx, const CxAllocator *a, DavQLExpression *lexpr, DavQLArgList *ap);

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



#ifdef	__cplusplus
}
#endif

#endif	/* DAVQLEXEC_H */

mercurial