Sat, 20 Apr 2024 12:50:38 +0200
remove disabled realloc debug code from libxattr
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2019 Olaf Wintermann. All rights reserved. |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "finfo.h" |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <stdio.h> |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include <stdlib.h> |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
33 | #include <string.h> |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
34 | #include <errno.h> |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include <sys/stat.h> |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
36 | #include <limits.h> |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
38 | #include <cx/string.h> |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
39 | #include <cx/list.h> |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
40 | #include <cx/array_list.h> |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
41 | #include <libidav/crypto.h> |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
42 | #include <libidav/utils.h> |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
43 | |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
44 | #ifndef _WIN32 |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
45 | #include <unistd.h> |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
46 | #endif |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
47 | |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
48 | #include "libxattr.h" |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
50 | uint32_t parse_finfo_settings(const char *str, char **error) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
51 | cxstring s = cx_str(str); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
52 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
53 | if(!cx_strcmp(s, CX_STR("*")) || !cx_strcmp(s, CX_STR("a")) || !cx_strcmp(s, CX_STR("all"))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
54 | return FINFO_MTIME|FINFO_OWNER|FINFO_MODE|FINFO_XATTR; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
55 | } |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
57 | CxStrtokCtx fs = cx_strtok(s, CX_STR(","), INT_MAX); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
58 | cxstring f; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
59 | uint32_t finfo = 0; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
60 | char *err = NULL; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
61 | while(cx_strtok_next(&fs, &f)) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
62 | if(!cx_strcasecmp(f, CX_STR("mtime"))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
63 | finfo |= FINFO_MTIME; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
64 | } else if(!cx_strcasecmp(f, CX_STR("owner"))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
65 | finfo |= FINFO_OWNER; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
66 | } else if(!cx_strcasecmp(f, CX_STR("mode"))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
67 | finfo |= FINFO_MODE; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
68 | } else if(!cx_strcasecmp(f, CX_STR("xattr"))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
69 | finfo |= FINFO_XATTR; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
70 | } else if(error && !err) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
71 | err = cx_strdup(f).ptr; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
72 | continue; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
73 | } |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | } |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | |
522
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
520
diff
changeset
|
76 | return err ? 0 : finfo; |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | } |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | int resource_set_finfo(const char *path, DavResource *res, uint32_t finfo) { |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | if(!path || finfo == 0) { |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | return 0; |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | } |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | struct stat s; |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | if(stat(path, &s)) { |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | fprintf(stderr, "failed to stat: %s\n", path); |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | return 1; |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | } |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | return resource_set_finfo_s(&s, res, finfo); |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | } |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | int resource_set_finfo_s(struct stat *s, DavResource *res, uint32_t finfo) { |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | if(finfo == 0) { |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | return 0; |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | } |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | DavXmlNode *content = NULL; |
519
ac5ac55b1b2e
adds file mode to fileinfo property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
98 | DavXmlNode *last = NULL; |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | |
646
37a8bfae995e
change metadata config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
100 | if((finfo & FINFO_MTIME) == FINFO_MTIME) { |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | char str[32]; |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | struct tm *date = gmtime(&s->st_mtime); |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT", date); |
736
40be8db6fe45
fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
104 | DavXmlNode *mtime = dav_text_element(res->session, DAV_PROPS_NS, "mtime", str); |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | content = mtime; |
519
ac5ac55b1b2e
adds file mode to fileinfo property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
106 | last = mtime; |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | } |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | #ifndef _WIN32 |
539
8deb52292c99
fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
527
diff
changeset
|
109 | if((finfo & FINFO_OWNER) == FINFO_OWNER) { |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | // TODO |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | } |
539
8deb52292c99
fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
527
diff
changeset
|
112 | if((finfo & FINFO_MODE) == FINFO_MODE) { |
519
ac5ac55b1b2e
adds file mode to fileinfo property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
113 | mode_t mode = s->st_mode & 07777; |
ac5ac55b1b2e
adds file mode to fileinfo property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
114 | char str[32]; |
ac5ac55b1b2e
adds file mode to fileinfo property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
115 | snprintf(str, 32, "%o", (int)mode); |
736
40be8db6fe45
fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
116 | DavXmlNode *xmode = dav_text_element(res->session, DAV_PROPS_NS, "mode", str); |
519
ac5ac55b1b2e
adds file mode to fileinfo property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
117 | if(last) { |
ac5ac55b1b2e
adds file mode to fileinfo property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
118 | last->next = xmode; |
ac5ac55b1b2e
adds file mode to fileinfo property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
119 | } else { |
ac5ac55b1b2e
adds file mode to fileinfo property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
120 | content = xmode; |
ac5ac55b1b2e
adds file mode to fileinfo property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
121 | } |
ac5ac55b1b2e
adds file mode to fileinfo property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
122 | last = xmode; |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | } |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | #endif |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
127 | dav_set_property_ns(res, DAV_PROPS_NS, "finfo", content);; |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | return 0; |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | } |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
131 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
132 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
133 | static void* array_realloc(void *array, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
134 | size_t capacity, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
135 | size_t elem_size, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
136 | struct cx_array_reallocator_s *alloc) |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
137 | { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
138 | return realloc(array, capacity * elem_size); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
139 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
140 | |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
141 | XAttributes* xml_get_attributes(DavXmlNode *xml) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
142 | XAttributes *attributes = calloc(1, sizeof(XAttributes)); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
143 | size_t x_names_size = 0; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
144 | size_t x_names_alloc = 8; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
145 | size_t x_values_size = 0; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
146 | size_t x_values_alloc = 8; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
147 | attributes->names = calloc(x_names_alloc, sizeof(char*)); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
148 | attributes->values = calloc(x_values_alloc, sizeof(cxmutstr)); |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
149 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
150 | struct cx_array_reallocator_s re = { .realloc = array_realloc }; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
151 | |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
152 | size_t count = 0; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
153 | |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
154 | char *hash = NULL; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
155 | |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
156 | DavXmlNode *node = xml; |
618
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
157 | for(;node;node=node->next) { |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
158 | if(node->type == DAV_XML_ELEMENT) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
159 | if(!strcmp(node->name, "hash")) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
160 | hash = dav_xml_getstring(node->children); |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
161 | } else if(!strcmp(node->name, "xattr")) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
162 | char *xattr_name = dav_xml_get_attr(node, "name"); |
618
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
163 | if(xattr_name) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
164 | char *xname = strdup(xattr_name); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
165 | cx_array_copy( |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
166 | (void**)&attributes->names, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
167 | &x_names_size, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
168 | &x_names_alloc, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
169 | count, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
170 | &xname, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
171 | sizeof(void*), |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
172 | 1, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
173 | &re); |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
174 | |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
175 | char *text = dav_xml_getstring(node->children); |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
176 | if(!text) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
177 | text = ""; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
178 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
179 | |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
180 | int len = 0; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
181 | char *val = util_base64decode_len(text, &len); |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
182 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
183 | cxmutstr value; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
184 | value.ptr = val; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
185 | value.length = len; |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
186 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
187 | cx_array_copy( |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
188 | (void**)&attributes->values, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
189 | &x_values_size, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
190 | &x_values_alloc, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
191 | count, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
192 | &value, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
193 | sizeof(cxmutstr), |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
194 | 1, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
195 | &re); |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
196 | |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
197 | count++; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
198 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
199 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
200 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
201 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
202 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
203 | if(count == 0) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
204 | free(attributes->names); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
205 | free(attributes->values); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
206 | free(attributes); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
207 | return NULL; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
208 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
209 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
210 | attributes->hash = hash ? strdup(hash) : NULL; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
211 | attributes->nattr = count; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
212 | |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
213 | return attributes; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
214 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
215 | |
618
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
216 | XAttributes* file_get_attributes( |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
217 | const char *path, |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
218 | xattr_filter_func filter, |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
219 | void *filterdata) |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
220 | { |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
221 | ssize_t nelm = 0; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
222 | char **attributes = xattr_list(path, &nelm); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
223 | if(nelm <= 0) { |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
224 | return NULL; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
225 | } |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
226 | |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
227 | XAttributes *xattr = malloc(sizeof(XAttributes)); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
228 | xattr->nattr = 0; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
229 | xattr->names = calloc(nelm, sizeof(char*)); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
230 | xattr->values = calloc(nelm, sizeof(cxmutstr)); |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
231 | |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
232 | DAV_SHA_CTX *sha256 = dav_hash_init(); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
233 | |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
234 | size_t nattr = 0; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
235 | for(int i=0;i<nelm;i++) { |
618
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
236 | if(filter) { |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
237 | // apply filter |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
238 | if(!filter(attributes[i], filterdata)) { |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
239 | // exclude attribute |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
240 | continue; |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
241 | } |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
242 | } |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
243 | |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
244 | ssize_t valuelen = 0; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
245 | char *value = xattr_get(path, attributes[i], &valuelen); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
246 | if(valuelen >= 0) { |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
247 | dav_hash_update(sha256, attributes[i], strlen(attributes[i])); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
248 | dav_hash_update(sha256, value, valuelen); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
249 | // add name and value |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
250 | xattr->names[nattr] = attributes[i]; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
251 | cxmutstr v; |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
252 | v.ptr = value; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
253 | v.length = valuelen; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
254 | xattr->values[nattr] = v; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
255 | nattr++; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
256 | } else { |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
257 | // discard not readable attributes |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
258 | free(attributes[i]); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
259 | } |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
260 | } |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
261 | |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
262 | xattr->nattr = nattr; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
263 | |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
264 | unsigned char hash[DAV_SHA256_DIGEST_LENGTH]; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
265 | dav_hash_final(sha256, hash); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
266 | xattr->hash = util_hexstr(hash, DAV_SHA256_DIGEST_LENGTH); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
267 | |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
268 | free(attributes); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
269 | |
524
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
270 | if(nattr > 0) { |
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
271 | return xattr; |
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
272 | } else { |
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
273 | xattributes_free(xattr); |
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
274 | return NULL; |
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
275 | } |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
276 | } |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
277 | |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
278 | int resource_set_xattr(DavResource *res, XAttributes *xattr) { |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
279 | if(!xattr || xattr->nattr == 0) { |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
280 | return 0; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
281 | } |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
282 | |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
283 | DavXmlNode *content = dav_xml_createnode_with_text(DAV_PROPS_NS, "hash", xattr->hash); |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
284 | DavXmlNode *last = content; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
285 | |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
286 | for(int i=0;i<xattr->nattr;i++) { |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
287 | DavXmlNode *attr = dav_xml_createnode(DAV_PROPS_NS, "xattr"); |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
288 | dav_xml_add_attr(attr, "name", xattr->names[i]); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
289 | last->next = attr; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
290 | last = attr; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
291 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
736
diff
changeset
|
292 | cxmutstr value = xattr->values[i]; |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
293 | if(value.length > 0) { |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
294 | char *encval = util_base64encode(value.ptr, value.length); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
295 | attr->children = dav_xml_createtextnode(encval); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
296 | free(encval); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
297 | } |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
298 | } |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
299 | |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
300 | dav_set_property_ns(res, DAV_PROPS_NS, "xattributes", content); |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
301 | |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
302 | return 0; |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
303 | } |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
304 | |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
305 | void xattributes_free(XAttributes *xattr) { |
524
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
306 | free(xattr->hash); |
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
307 | for(int i=0;i<xattr->nattr;i++) { |
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
308 | free(xattr->names[i]); |
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
309 | free(xattr->values[i].ptr); |
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
310 | } |
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
311 | free(xattr); |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
519
diff
changeset
|
312 | } |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
313 | |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
314 | char* get_xattr_hash(DavXmlNode *finfo) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
315 | DavXmlNode *node = finfo; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
316 | while(node) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
317 | if(node->type == DAV_XML_ELEMENT && !strcmp(node->name, "hash")) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
318 | return dav_xml_getstring(node->children); |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
319 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
320 | node = node->next; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
321 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
322 | return NULL; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
323 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
324 | |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
325 | void finfo_get_values(DavXmlNode *xml, FileInfo *outval) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
326 | memset(outval, 0, sizeof(FileInfo)); |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
327 | DavXmlNode *node = xml; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
328 | while(node) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
329 | if(node->type == DAV_XML_ELEMENT) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
330 | if(!strcmp(node->name, "mtime")) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
331 | char *mtime = dav_xml_getstring(node->children); |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
332 | if(mtime) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
333 | outval->last_modified = util_parse_lastmodified(mtime); |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
334 | outval->date_set = TRUE; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
335 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
336 | } else if(!strcmp(node->name, "mode")) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
337 | char *mode_str = dav_xml_getstring(node->children); |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
338 | if(mode_str) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
339 | char *end; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
340 | errno = 0; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
341 | long int mode = strtol(mode_str, &end, 8); |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
342 | if(errno == 0) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
343 | mode &= 07777; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
344 | outval->mode = mode; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
345 | outval->mode_set = TRUE; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
346 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
347 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
348 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
349 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
350 | node = node->next; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
351 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
352 | |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
353 | } |