src/server/webdav/xattrbackend.c

changeset 480
9f69e4b8b695
parent 479
2a42ba73ecdd
child 481
31affbf33911
equal deleted inserted replaced
479:2a42ba73ecdd 480:9f69e4b8b695
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 29
30 #include "xattrbackend.h" 30 #include "xattrbackend.h"
31
32 #include "../util/util.h"
33 #include "../util/libxattr.h"
31 34
32 35
33 static WebdavBackend webdav_xattr_backend = { 36 static WebdavBackend webdav_xattr_backend = {
34 webdav_xattr_propfind_init, 37 webdav_xattr_propfind_init,
35 webdav_xattr_propfind_do, 38 webdav_xattr_propfind_do,
59 if(!repo) { 62 if(!repo) {
60 return NULL; 63 return NULL;
61 } 64 }
62 65
63 // TODO: config 66 // TODO: config
67 repo->xattr_name = "webdav_properties";
64 68
65 return repo; 69 return repo;
66 } 70 }
67 71
68 WebdavBackend* webdav_xattr_create(Session *sn, Request *rq, pblock *pb, void *initData) { 72 WebdavBackend* webdav_xattr_create(Session *sn, Request *rq, pblock *pb, void *initData) {
91 WebdavPropfindRequest *rq, 95 WebdavPropfindRequest *rq,
92 const char *path, 96 const char *path,
93 const char *href, 97 const char *href,
94 WebdavPList **outplist) 98 WebdavPList **outplist)
95 { 99 {
100 // make sure the sys vfs is used, because currently only
101 // native sysfs xattr is supported
102 if(rq->rq->vfs) {
103 log_ereport(LOG_FAILURE, "webdav-propfind: xattr backend unsupported with non-native VFS");
104 return 1;
105 }
106
107 XAttrPropfind *xprop = pool_malloc(rq->sn->pool, sizeof(XAttrPropfind));
108 if(!xprop) {
109 return 1;
110 }
111 rq->userdata = xprop;
112
113 xprop->base_href = href;
114 xprop->base_path = path;
115
96 return 0; 116 return 0;
97 } 117 }
98 118
99 int webdav_xattr_propfind_do( 119 int webdav_xattr_propfind_do(
100 WebdavPropfindRequest *request, 120 WebdavPropfindRequest *request,
101 WebdavResponse *response, 121 WebdavResponse *response,
102 VFS_DIR parent, 122 VFS_DIR parent,
103 WebdavResource *resource, 123 WebdavResource *resource,
104 struct stat *s) 124 struct stat *s)
105 { 125 {
126 Session *sn = request->sn;
127 Request *rq = request->rq;
128
129 WebdavXAttrBackend *xdav = request->dav->instance;
130 WebdavXAttrRepository *repo = xdav->repo;
131 XAttrPropfind *xprop = request->userdata;
132
133 const char *path;
134 char *path_dp = NULL;
135 if(!parent) {
136 // use base path
137 path = xprop->base_path;
138 } else {
139 size_t base_href_len = strlen(xprop->base_href);
140 size_t base_path_len = strlen(xprop->base_path);
141 char *res_path = resource->href + base_href_len;
142 size_t res_path_len = strlen(res_path);
143
144 path_dp = pool_malloc(sn->pool, base_path_len + res_path_len + 2);
145 memcpy(path_dp, xprop->base_path, base_path_len);
146 int s = 0;
147 if(path_dp[base_path_len-1] != '/' && res_path[0] != '/') {
148 path_dp[base_path_len] = '/';
149 s = 1;
150 }
151 memcpy(path_dp + base_path_len + s, res_path, res_path_len);
152 path_dp[base_path_len + s + res_path_len] = 0;
153
154 path = path_dp;
155 }
156
157 ssize_t xattr_data_len = 0;
158 char *xattr_data = xattr_get_alloc(
159 sn->pool,
160 (libxattr_malloc_func)pool_malloc,
161 (libxattr_free_func)pool_free,
162 path,
163 repo->xattr_name,
164 &xattr_data_len);
165
166
106 return 0; 167 return 0;
107 } 168 }
108 169
109 int webdav_xattr_propfind_finish(WebdavPropfindRequest *rq) { 170 int webdav_xattr_propfind_finish(WebdavPropfindRequest *rq) {
110 return 0; 171 return 0;

mercurial