UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2022 Olaf Wintermann. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef WS_PG_WEBDAV_H 30 #define WS_PG_WEBDAV_H 31 32 #include "../../public/nsapi.h" 33 #include "../../public/webdav.h" 34 35 #include "config.h" 36 37 #include <libpq-fe.h> 38 #include <cx/buffer.h> 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 #define PG_MAX_PATH_LEN 0x8000 45 46 typedef struct PgWebdavBackend { 47 ResourceData *pg_resource; 48 PGconn *connection; 49 PgRepository *repository; 50 char root_resource_id_str[32]; 51 } PgWebdavBackend; 52 53 typedef struct PgPropfindExtCol { 54 /* 55 * property extension config 56 */ 57 PgPropertyStoreExt *ext; 58 /* 59 * Result field number 60 */ 61 int field_num; 62 } PgPropfindExtCol; 63 64 typedef struct PgPropfind { 65 const char *path; 66 int64_t resource_id; 67 WebdavVFSProperties vfsproperties; 68 PGresult *result; 69 PgPropfindExtCol *ext; 70 size_t numext; 71 int nrows; 72 } PgPropfind; 73 74 typedef struct PgProppatchExtProp PgProppatchExtProp; 75 struct PgProppatchExtProp { 76 PgPropertyStoreExt *column; 77 WebdavProperty *property; 78 PgProppatchExtProp *next; 79 }; 80 81 typedef struct { 82 PgProppatchExtProp *set_begin; 83 PgProppatchExtProp *set_end; 84 PgProppatchExtProp *remove_begin; 85 PgProppatchExtProp *remove_end; 86 WSBool isused; 87 } PgProppatchExt; 88 89 typedef struct { 90 int64_t resource_id; 91 PgProppatchExt *ext; 92 size_t numext; 93 WSBool extensions_used; 94 } PgProppatch; 95 96 void* pg_webdav_init(ServerConfiguration *cfg, pool_handle_t *pool, WSConfigNode *config); 97 WebdavBackend* pg_webdav_create(Session *sn, Request *rq, pblock *pb, void *initData); 98 WebdavBackend* pg_webdav_create_from_resdata(Session *sn, Request *rq, PgRepository *repo, ResourceData *resdata); 99 100 WebdavBackend* pg_webdav_prop_create(Session *sn, Request *rq, pblock *pb); 101 102 int pg_create_property_param_arrays(WebdavPList *plist, CxBuffer *xmlns, CxBuffer *pname); 103 104 /* ----------------- webdav backend functions ----------------- */ 105 int pg_dav_propfind_init( 106 WebdavPropfindRequest *rq, 107 const char *path, 108 const char *href, 109 WebdavPList **outplist); 110 111 int pg_dav_propfind_do( 112 WebdavPropfindRequest *rq, 113 WebdavResponse *response, 114 VFS_DIR parent, 115 WebdavResource *resource, 116 struct stat *s); 117 118 int pg_dav_propfind_finish(WebdavPropfindRequest *rq); 119 120 int pg_dav_proppatch_do( 121 WebdavProppatchRequest *request, 122 WebdavResource *response, 123 VFSFile *file, 124 WebdavPList **out_set, 125 WebdavPList **out_remove); 126 127 int pg_dav_proppatch_finish( 128 WebdavProppatchRequest *request, 129 WebdavResource *response, 130 VFSFile *file, 131 WSBool commit); 132 133 #ifdef __cplusplus 134 } 135 #endif 136 137 #endif /* PG_WEBDAV_H */ 138 139