1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
80
81
82
83
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
155
156