src/server/plugins/postgresql/vfs.h

changeset 385
a1f4cb076d2f
parent 374
77506ec632a4
equal deleted inserted replaced
210:21274e5950af 385:a1f4cb076d2f
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_VFS_H
30 #define WS_PG_VFS_H
31
32 #include "../../public/nsapi.h"
33 #include "../../public/vfs.h"
34
35 #include "config.h"
36
37 #include <libpq-fe.h>
38 #include <libpq/libpq-fs.h>
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 #define PG_ETAG_MAXLEN 48
45
46 typedef struct PgVFS {
47 ResourceData *pg_resource;
48 PGconn *connection;
49 char root_resource_id_str[32];
50 int64_t root_resource_id;
51 } PgVFS;
52
53 typedef struct PgFile {
54 int64_t resource_id;
55 int64_t parent_id;
56 WSBool iscollection;
57 Oid oid;
58 int fd;
59 int oflags;
60 char etag[PG_ETAG_MAXLEN];
61 struct stat s;
62 } PgFile;
63
64 typedef struct PgDir {
65 VFSFile *file;
66 PGresult *result;
67 int row;
68 int nrows;
69 } PgDir;
70
71 void* pg_vfs_init(ServerConfiguration *cfg, pool_handle_t *pool, WSConfigNode *config);
72
73 VFS* pg_vfs_create(Session *sn, Request *rq, pblock *pb, void *initData);
74
75 VFS* pg_vfs_create_from_resourcedata(Session *sn, Request *rq, PgRepository *repo, ResourceData *resdata);
76
77
78 /*
79 * Resolve a path into a parent_id and resource name
80 *
81 * Only absolute paths are supported, therefore path[0] must be '/'
82 *
83 * If the resource is not found, res_errno is set to ENOENT
84 */
85 int pg_resolve_path(
86 PGconn *connection,
87 const char *path,
88 const char *root_id,
89 int64_t *parent_id,
90 int64_t *resource_id,
91 Oid *oid,
92 const char **resource_name,
93 WSBool *iscollection,
94 struct stat *s,
95 char *etag,
96 int *res_errno);
97
98 void pg_set_stat(
99 struct stat *s,
100 const char *iscollection,
101 const char *lastmodified,
102 const char *creationdate,
103 const char *contentlength);
104
105 int pg_create_file(
106 VFSContext *ctx,
107 PgVFS *pg,
108 const char *path,
109 int64_t *new_resource_id,
110 int64_t *res_parent_id,
111 Oid *oid,
112 const char **resource_name,
113 struct stat *s,
114 WSBool collection);
115
116 int pg_remove_res(
117 VFSContext *ctx,
118 PgVFS *pg,
119 int64_t resource_id,
120 Oid oid);
121
122 int pg_update_resource(PgVFS *pg, int64_t resource_id, int64_t contentlength);
123
124 SYS_FILE pg_vfs_open(VFSContext *ctx, const char *path, int oflags);
125 int pg_vfs_stat(VFSContext *ctx, const char *path, struct stat *buf);
126 int pg_vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf);
127 VFS_DIR pg_vfs_opendir(VFSContext *ctx, const char *path);
128 VFS_DIR pg_vfs_fdopendir(VFSContext *ctx, SYS_FILE fd);
129 int pg_vfs_mkdir(VFSContext *ctx, const char *path);
130 int pg_vfs_unlink(VFSContext *ctx, const char *path);
131 int pg_vfs_rmdir(VFSContext *ctx, const char *path);
132
133
134 ssize_t pg_vfs_io_read(SYS_FILE fd, void *buf, size_t nbyte);
135 ssize_t pg_vfs_io_write(SYS_FILE fd, const void *buf, size_t nbyte);
136 ssize_t pg_vfs_io_pread(SYS_FILE fd, void *buf, size_t nbyte, off_t offset);
137 ssize_t pg_vfs_io_pwrite(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset);
138 off_t pg_vfs_io_seek(SYS_FILE fd, off_t offset, int whence);
139 off_t pg_vfs_io_tell(SYS_FILE fd);
140 void pg_vfs_io_close(SYS_FILE fd);
141 const char *pg_vfs_io_getetag(SYS_FILE fd);
142
143
144 int pg_vfs_dirio_readdir(VFS_DIR dir, VFS_ENTRY *entry, int getstat);
145 void pg_vfs_dirio_close(VFS_DIR dir);
146
147 time_t pg_convert_timestamp(const char *timestamp);
148 int pg_convert_timestamp_tm(const char *timestamp, struct tm *tm);
149
150 #ifdef __cplusplus
151 }
152 #endif
153
154 #endif /* WS_PG_VFS_H */
155

mercurial