Tue, 13 Nov 2018 23:33:59 +0100
fixes dav_session_get_href() generating random names when encrypt-name is disabled
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2018 Olaf Wintermann. All rights reserved. |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
b6f2462ee055
adds xattr lib and tag support
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 |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdio.h> |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <stdlib.h> |
400
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
31 | #include <string.h> |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
32 | #include <ctype.h> |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include <ucx/string.h> |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include <ucx/utils.h> |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #include "libxattr.h" |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include "tags.h" |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | |
363
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
41 | #ifdef __APPLE__ |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
42 | #include <CoreFoundation/CoreFoundation.h> |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
43 | #endif |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
44 | |
390
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
45 | void free_dav_tag(DavTag* tag) { |
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
46 | free(tag->name); |
403
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
400
diff
changeset
|
47 | if(tag->color) { |
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
400
diff
changeset
|
48 | free(tag->color); |
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
400
diff
changeset
|
49 | } |
390
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
50 | free(tag); |
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
51 | } |
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
52 | |
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
53 | int compare_tagname(DavTag* left, DavTag* right, void* ignorecase) { |
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
54 | sstr_t leftname = sstr(left->name); |
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
55 | sstr_t rightname = sstr(right->name); |
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
56 | if (ignorecase && *((int*) ignorecase)) { |
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
57 | return sstrcasecmp(leftname, rightname); |
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
58 | } else { |
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
59 | return sstrcmp(leftname, rightname); |
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
60 | } |
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
61 | } |
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
388
diff
changeset
|
62 | |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | UcxList* parse_text_taglist(const char *buf, size_t length) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | UcxList *tags = NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | int line_start = 0; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | for(int i=0;i<length;i++) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | if(buf[i] == '\n' || i == length-1) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | sstr_t line = sstrtrim(sstrn((char*)buf + line_start, i - line_start)); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | if(line.length > 0) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | DavTag *tag = calloc(1, sizeof(DavTag)); |
423
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
72 | sstr_t color = sstrchr(line, '#'); |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
73 | if(color.length>0) { |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
74 | sstr_t name = line; |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
75 | name.length = (int)(color.ptr-line.ptr); |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
76 | if(name.length != 0) { |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
77 | tag->name = sstrdup(name).ptr; |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
78 | color.ptr++; |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
79 | color.length--; |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
80 | if(color.length > 0) { |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
81 | tag->color = sstrdup(color).ptr; |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
82 | } |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
83 | } else { |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
84 | free(tag); |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
85 | } |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
86 | } else { |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
87 | tag->name = sstrdup(line).ptr; |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
88 | tag->color = NULL; |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
89 | } |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
90 | |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | tags = ucx_list_append(tags, tag); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | line_start = i+1; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | return tags; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | UcxBuffer* create_text_taglist(UcxList *tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | if(!tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | return NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | UCX_FOREACH(elm, tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | DavTag *tag = elm->data; |
423
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
108 | if(tag->color) { |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
109 | ucx_bprintf(buf, "%s#%s\n", tag->name, tag->color); |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
110 | } else { |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
111 | ucx_bprintf(buf, "%s\n", tag->name); |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
112 | } |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | return buf; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | UcxList* parse_csv_taglist(const char *buf, size_t length) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | UcxList *taglist = NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | sstr_t str = sstrn((char*)buf, length); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | ssize_t count = 0; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | sstr_t *tags = sstrsplit(str, S(","), &count); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | for(int i=0;i<count;i++) { |
393
438c8fe7d62f
parse_csv_taglist() now skips empty tags
Mike Becker <universe@uap-core.de>
parents:
390
diff
changeset
|
125 | sstr_t trimmed_tag = sstrtrim(tags[i]); |
438c8fe7d62f
parse_csv_taglist() now skips empty tags
Mike Becker <universe@uap-core.de>
parents:
390
diff
changeset
|
126 | if (trimmed_tag.length > 0) { |
438c8fe7d62f
parse_csv_taglist() now skips empty tags
Mike Becker <universe@uap-core.de>
parents:
390
diff
changeset
|
127 | DavTag *tag = malloc(sizeof(DavTag)); |
438c8fe7d62f
parse_csv_taglist() now skips empty tags
Mike Becker <universe@uap-core.de>
parents:
390
diff
changeset
|
128 | tag->name = sstrdup(trimmed_tag).ptr; |
438c8fe7d62f
parse_csv_taglist() now skips empty tags
Mike Becker <universe@uap-core.de>
parents:
390
diff
changeset
|
129 | tag->color = NULL; |
438c8fe7d62f
parse_csv_taglist() now skips empty tags
Mike Becker <universe@uap-core.de>
parents:
390
diff
changeset
|
130 | taglist = ucx_list_append(taglist, tag); |
438c8fe7d62f
parse_csv_taglist() now skips empty tags
Mike Becker <universe@uap-core.de>
parents:
390
diff
changeset
|
131 | } |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | free(tags[i].ptr); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | if(tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | free(tags); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | return taglist; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | UcxBuffer* create_csv_taglist(UcxList *tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | int insertsep = 0; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | UCX_FOREACH(elm, tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | DavTag *tag = elm->data; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | if(insertsep) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | ucx_buffer_putc(buf, ','); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | ucx_buffer_puts(buf, tag->name); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | insertsep = 1; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | return buf; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | static DavTag* parse_xml_dav_tag(DavXmlNode *node) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | char *name = NULL; |
423
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
157 | char *color = NULL; |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | DavXmlNode *c = node->children; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | while(c) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | if(c->type == DAV_XML_ELEMENT) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | char *value = dav_xml_getstring(c->children); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | if(value) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | if(!strcmp(c->namespace, DAV_NS)) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | if(!strcmp(c->name, "name")) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | char *value = dav_xml_getstring(c->children); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | if(value) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | name = value; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | } |
423
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
171 | if(!strcmp(c->name, "color")) { |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
172 | char *value = dav_xml_getstring(c->children); |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
173 | if(value) { |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
174 | color = value; |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
175 | } |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
176 | } |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | c = c->next; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | DavTag *tag = NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | if(name) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | tag = malloc(sizeof(DavTag)); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | tag->name = strdup(name); |
423
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
187 | tag->color = color ? strdup(color) : NULL; |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | return tag; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | UcxList* parse_dav_xml_taglist(DavXmlNode *taglistnode) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | UcxList *tags = NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | DavXmlNode *node = taglistnode; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | while(node) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | if(node->type == DAV_XML_ELEMENT) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | if(!strcmp(node->namespace, DAV_NS) && !strcmp(node->name, "tag")) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | DavTag *tag = parse_xml_dav_tag(node); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | if(tag) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | tags = ucx_list_append(tags, tag); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | node = node->next; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | return tags; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | DavXmlNode* create_xml_taglist(UcxList *tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | DavXmlNode *tag1 = NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | DavXmlNode *lasttag = NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | UCX_FOREACH(elm, tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | DavTag *tag = elm->data; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | DavXmlNode *tagelm = dav_xml_createnode(DAV_NS, "tag"); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | DavXmlNode *tagname = dav_xml_createnode_with_text(DAV_NS, "name", tag->name); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | tagelm->children = tagname; |
423
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
220 | if(tag->color) { |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
221 | DavXmlNode *tagcolor = dav_xml_createnode_with_text(DAV_NS, "color", tag->color); |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
222 | tagname->next = tagcolor; |
84e6c407b431
adds support for tag colors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
223 | } |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | if(lasttag) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | lasttag->next = tagelm; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | tagelm->prev = lasttag; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | } else { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | tag1 = tagelm; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | lasttag = tagelm; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | return tag1; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | } |
363
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
235 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
236 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
237 | #ifdef __APPLE__ |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
238 | static DavTag* tagstr2davtag(const char *str) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
239 | const char *name = str; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
240 | const char *color = NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
241 | size_t len = strlen(str); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
242 | size_t namelen = len; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
243 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
244 | if(len == 0) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
245 | return NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
246 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
247 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
248 | // start with 1 because the first char should not be a linebreak |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
249 | for(int i=1;i<len;i++) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
250 | if(str[i] == '\n') { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
251 | if(!color) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
252 | color = str + i + 1; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
253 | namelen = i; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
254 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
255 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
256 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
257 | int colorlen = len - namelen - 1; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
258 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
259 | DavTag *tag = malloc(sizeof(DavTag)); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
260 | tag->name = malloc(namelen + 1); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
261 | memcpy(tag->name, name, namelen); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
262 | tag->name[namelen] = 0; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
263 | if(colorlen > 0) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
264 | tag->color = malloc(colorlen + 1); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
265 | memcpy(tag->color, color, colorlen); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
266 | tag->color[colorlen] = 0; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
267 | } else { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
268 | tag->color = NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
269 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
270 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
271 | return tag; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
272 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
273 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
274 | UcxList* parse_macos_taglist(const char *buf, size_t length) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
275 | UcxList *taglist = NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
276 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
277 | CFDataRef data = CFDataCreateWithBytesNoCopy( |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
278 | kCFAllocatorDefault, |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
279 | (const UInt8*)buf, |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
280 | length, |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
281 | kCFAllocatorNull); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
282 | CFPropertyListRef propertylist = CFPropertyListCreateWithData(kCFAllocatorDefault, data, 0, NULL, NULL); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
283 | CFArrayRef array = propertylist; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
284 | int count = CFArrayGetCount(array); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
285 | for(int i=0;i<count;i++) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
286 | CFStringRef str = CFArrayGetValueAtIndex(array, i); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
287 | int slen = CFStringGetLength(str); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
288 | size_t cstrbuflen = slen * 4 + 4; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
289 | char *cstr = malloc(cstrbuflen); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
290 | if(CFStringGetCString(str, cstr, cstrbuflen, kCFStringEncodingUTF8)) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
291 | DavTag *tag = tagstr2davtag(cstr); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
292 | if(tag) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
293 | taglist = ucx_list_append(taglist, tag); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
294 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
295 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
296 | free(cstr); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
297 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
298 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
299 | CFRelease(propertylist); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
300 | CFRelease(data); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
301 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
302 | return taglist; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
303 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
304 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
305 | UcxBuffer* create_macos_taglist(UcxList *tags) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
306 | size_t count = ucx_list_size(tags); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
307 | if(count == 0) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
308 | return NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
309 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
310 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
311 | CFStringRef *strings = calloc(sizeof(CFStringRef), count); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
312 | int i = 0; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
313 | UCX_FOREACH(elm, tags) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
314 | DavTag *tag = elm->data; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
315 | CFStringRef str = NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
316 | if(tag->color) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
317 | sstr_t s = sstrcat(3, sstr(tag->name), S("\n"), sstr(tag->color)); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
318 | str = CFStringCreateWithCString(kCFAllocatorDefault, s.ptr, kCFStringEncodingUTF8); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
319 | free(s.ptr); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
320 | } else { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
321 | str = CFStringCreateWithCString(kCFAllocatorDefault, tag->name, kCFStringEncodingUTF8); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
322 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
323 | strings[i] = str; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
324 | i++; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
325 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
326 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
327 | CFPropertyListRef array = CFArrayCreate(kCFAllocatorDefault, (const void**)strings, count, &kCFTypeArrayCallBacks); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
328 | CFDataRef data = CFPropertyListCreateData(kCFAllocatorDefault, array, kCFPropertyListBinaryFormat_v1_0, 0, NULL); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
329 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
330 | UcxBuffer *buf = NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
331 | if(data) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
332 | int datalen = CFDataGetLength(data); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
333 | CFRange range; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
334 | range.location = 0; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
335 | range.length = datalen; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
336 | buf = ucx_buffer_new(NULL, datalen, 0); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
337 | CFDataGetBytes(data, range, (UInt8*)buf->space); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
338 | buf->size = datalen; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
339 | CFRelease(data); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
340 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
341 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
342 | for(int i=0;i<count;i++) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
343 | CFRelease(strings[i]); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
344 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
345 | CFRelease(array); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
346 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
347 | return buf; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
348 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
349 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
350 | #else |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
351 | UcxList* parse_macos_taglist(const char *buf, size_t length) { |
373
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
363
diff
changeset
|
352 | fprintf(stderr, "Error: macos tags not supported on this platform.\n"); |
363
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
353 | return NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
354 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
355 | UcxBuffer* create_macos_taglist(UcxList *tags) { |
373
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
363
diff
changeset
|
356 | fprintf(stderr, "Error: macos tags not supported on this platform.\n"); |
363
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
357 | return NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
358 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
359 | #endif |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
360 | |
400
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
361 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
362 | /* ----------- ----------- tag filter ---------------------- */ |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
363 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
364 | // TODO: use scstr_t after update to UCX 2.0 |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
365 | static size_t rtrimskip(sstr_t str, size_t skip) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
366 | while (skip < str.length && isspace(str.ptr[skip])) skip++; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
367 | return skip; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
368 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
369 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
370 | static size_t parse_tagfilter_taglist(sstr_t fs, SyncTagFilter* tagfilter) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
371 | size_t csvlen; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
372 | for (csvlen = 0 ; csvlen < fs.length ; ++csvlen) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
373 | if (fs.ptr[csvlen] == ')') break; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
374 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
375 | fs.length = csvlen; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
376 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
377 | tagfilter->tags = parse_csv_taglist(fs.ptr, fs.length); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
378 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
379 | return csvlen; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
380 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
381 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
382 | static size_t parse_tagfilter_subfilters(sstr_t fs, SyncTagFilter* tagfilter); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
383 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
384 | static size_t parse_tagfilter_filter(sstr_t fs, SyncTagFilter* tagfilter) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
385 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
386 | size_t consumed = rtrimskip(fs, 0); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
387 | fs = sstrsubs(fs, consumed); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
388 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
389 | if (fs.length == 0) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
390 | return consumed; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
391 | } else { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
392 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
393 | // optional operator |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
394 | int hasop = 0; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
395 | if (fs.ptr[0] == '&') { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
396 | tagfilter->mode = DAV_SYNC_TAGFILTER_AND; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
397 | hasop = 1; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
398 | } else if (fs.ptr[0] == '|') { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
399 | tagfilter->mode = DAV_SYNC_TAGFILTER_OR; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
400 | hasop = 1; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
401 | } else if (fs.ptr[0] == '0') { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
402 | tagfilter->mode = DAV_SYNC_TAGFILTER_NONE; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
403 | hasop = 1; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
404 | } else if (fs.ptr[0] == '1') { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
405 | tagfilter->mode = DAV_SYNC_TAGFILTER_ONE; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
406 | hasop = 1; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
407 | } else { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
408 | // default operator is AND |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
409 | tagfilter->mode = DAV_SYNC_TAGFILTER_AND; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
410 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
411 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
412 | if (hasop) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
413 | size_t skip = rtrimskip(fs, 1); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
414 | consumed += skip; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
415 | fs = sstrsubs(fs, skip); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
416 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
417 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
418 | if (fs.length > 0 && fs.ptr[0] == '(') { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
419 | size_t c = parse_tagfilter_subfilters(fs, tagfilter); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
420 | if (c) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
421 | return consumed + c; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
422 | } else { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
423 | return 0; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
424 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
425 | } else { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
426 | tagfilter->subfilter_count = 0; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
427 | tagfilter->subfilters = NULL; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
428 | return consumed + parse_tagfilter_taglist(fs, tagfilter); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
429 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
430 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
431 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
432 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
433 | /* |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
434 | * Parses: ( "(" , filter , ")" )+ |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
435 | */ |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
436 | static size_t parse_tagfilter_subfilters(sstr_t fs, SyncTagFilter* f) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
437 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
438 | // strategy: allocate much and give back later (instead of reallocs in loop) |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
439 | size_t subfilter_cap = 8; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
440 | f->subfilters = calloc(subfilter_cap, sizeof(SyncTagFilter*)); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
441 | f->subfilter_count = 0; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
442 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
443 | size_t total_consumed = 0; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
444 | size_t c; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
445 | do { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
446 | // skip leading parenthesis (and white spaces) |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
447 | c = rtrimskip(fs, 1); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
448 | fs = sstrsubs(fs, c); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
449 | total_consumed += c; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
450 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
451 | // increase array capacity, if necessary |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
452 | if (f->subfilter_count >= subfilter_cap) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
453 | subfilter_cap *= 2; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
454 | SyncTagFilter** newarr = realloc(f->subfilters, |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
455 | subfilter_cap * sizeof(SyncTagFilter*)); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
456 | if (newarr) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
457 | f->subfilters = newarr; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
458 | } else { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
459 | abort(); // no error handling reachable, so we are fucked |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
460 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
461 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
462 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
463 | // allocate space for a new filter |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
464 | SyncTagFilter* subf = calloc(1, sizeof(SyncTagFilter)); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
465 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
466 | // parse that filter |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
467 | c = parse_tagfilter_filter(fs, subf); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
468 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
469 | // sanity check: we must end with a closing parenthesis |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
470 | if (c > 0 && fs.ptr[c] == ')') { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
471 | f->subfilters[f->subfilter_count++] = subf; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
472 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
473 | // consume ')' and find the next parenthesis or the end-of-string |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
474 | c = rtrimskip(fs, 1+c); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
475 | fs = sstrsubs(fs, c); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
476 | total_consumed += c; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
477 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
478 | if (fs.length == 0 || fs.ptr[0] == ')') { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
479 | // our job is done |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
480 | break; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
481 | } else if (fs.ptr[0] != '(') { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
482 | // anything else than a parenthesis or end-of-string is an error |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
483 | return 0; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
484 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
485 | } else { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
486 | free(subf); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
487 | break; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
488 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
489 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
490 | } while(1); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
491 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
492 | // try to shrink the array |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
493 | if (f->subfilter_count > 0) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
494 | SyncTagFilter** shrinked_array = realloc(f->subfilters, |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
495 | f->subfilter_count * sizeof(SyncTagFilter*)); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
496 | if (shrinked_array) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
497 | f->subfilters = shrinked_array; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
498 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
499 | } else { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
500 | free(f->subfilters); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
501 | f->subfilters = NULL; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
502 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
503 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
504 | return total_consumed; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
505 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
506 | |
414
ea50585ec9d9
adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
403
diff
changeset
|
507 | SyncTagFilter* parse_tagfilter_string(const char* filterstring, int scope) { |
400
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
508 | SyncTagFilter* tagfilter = calloc(1, sizeof(SyncTagFilter)); |
414
ea50585ec9d9
adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
403
diff
changeset
|
509 | tagfilter->scope = scope; |
400
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
510 | if (!filterstring) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
511 | return tagfilter; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
512 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
513 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
514 | // TODO: use scstr_t after update to UCX 2.0 |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
515 | sstr_t fs = sstr((char*) filterstring); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
516 | size_t consumed = parse_tagfilter_filter(fs, tagfilter); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
517 | if (!consumed) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
518 | free_tagfilter(tagfilter); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
519 | return NULL; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
520 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
521 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
522 | // consume trailing white spaces |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
523 | consumed = rtrimskip(fs, consumed); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
524 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
525 | // sanity check: have we consumed the whole string? |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
526 | if (consumed != fs.length) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
527 | free_tagfilter(tagfilter); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
528 | return NULL; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
529 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
530 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
531 | return tagfilter; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
532 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
533 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
534 | void free_tagfilter(SyncTagFilter* filter) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
535 | for (size_t i = 0 ; i < filter->subfilter_count ; i++) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
536 | free_tagfilter(filter->subfilters[i]); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
537 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
538 | free(filter->subfilters); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
539 | free(filter); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
540 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
541 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
542 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
543 | static int matches_tags_and(UcxList *dav_tags, UcxList *tags, int ignorecase) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
544 | UCX_FOREACH(e, tags) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
545 | if (!ucx_list_contains(dav_tags, e->data, |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
546 | (cmp_func) compare_tagname, &ignorecase)) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
547 | return 0; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
548 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
549 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
550 | return 1; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
551 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
552 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
553 | static int matches_tags_or(UcxList *dav_tags, UcxList *tags, int ignorecase) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
554 | UCX_FOREACH(e, tags) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
555 | if (ucx_list_contains(dav_tags, e->data, |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
556 | (cmp_func) compare_tagname, &ignorecase)) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
557 | return 1; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
558 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
559 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
560 | return 0; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
561 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
562 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
563 | static int matches_tags_one(UcxList *dav_tags, UcxList *tags, int ignorecase) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
564 | int matches_exactly_one = 0; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
565 | UCX_FOREACH(e, tags) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
566 | if (ucx_list_contains(dav_tags, e->data, |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
567 | (cmp_func) compare_tagname, &ignorecase)) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
568 | if (matches_exactly_one) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
569 | return 0; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
570 | } else { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
571 | matches_exactly_one = 1; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
572 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
573 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
574 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
575 | return matches_exactly_one; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
576 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
577 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
578 | static int matches_subfilters_and(UcxList *dav_tags, SyncTagFilter *filter) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
579 | int ret = 1; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
580 | for (size_t i = 0 ; i < filter->subfilter_count ; i++) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
581 | ret &= matches_tagfilter(dav_tags, filter->subfilters[i]); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
582 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
583 | return ret; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
584 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
585 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
586 | static int matches_subfilters_or(UcxList *dav_tags, SyncTagFilter *filter) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
587 | int ret = 0; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
588 | for (size_t i = 0 ; i < filter->subfilter_count ; i++) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
589 | ret |= matches_tagfilter(dav_tags, filter->subfilters[i]); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
590 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
591 | return ret; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
592 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
593 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
594 | static int matches_subfilters_one(UcxList *dav_tags, SyncTagFilter *filter) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
595 | int one = 0; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
596 | for (size_t i = 0 ; i < filter->subfilter_count ; i++) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
597 | if (matches_tagfilter(dav_tags, filter->subfilters[i])) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
598 | if (one) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
599 | return 0; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
600 | } else { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
601 | one = 1; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
602 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
603 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
604 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
605 | return one; |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
606 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
607 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
608 | int matches_tagfilter(UcxList *dav_tags, SyncTagFilter *tagfilter) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
609 | |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
610 | if (tagfilter->subfilter_count > 0) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
611 | switch (tagfilter->mode) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
612 | case DAV_SYNC_TAGFILTER_OR: |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
613 | return matches_subfilters_or(dav_tags, tagfilter); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
614 | case DAV_SYNC_TAGFILTER_AND: |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
615 | return matches_subfilters_and(dav_tags, tagfilter); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
616 | case DAV_SYNC_TAGFILTER_NONE: |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
617 | return !matches_subfilters_or(dav_tags, tagfilter); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
618 | case DAV_SYNC_TAGFILTER_ONE: |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
619 | return matches_subfilters_one(dav_tags, tagfilter); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
620 | default: |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
621 | abort(); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
622 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
623 | } else { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
624 | int ignorecase = 0; // TODO: maybe add support later |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
625 | switch (tagfilter->mode) { |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
626 | case DAV_SYNC_TAGFILTER_OR: |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
627 | return matches_tags_or(dav_tags, tagfilter->tags, ignorecase); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
628 | case DAV_SYNC_TAGFILTER_AND: |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
629 | return matches_tags_and(dav_tags, tagfilter->tags, ignorecase); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
630 | case DAV_SYNC_TAGFILTER_NONE: |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
631 | return !matches_tags_or(dav_tags, tagfilter->tags, ignorecase); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
632 | case DAV_SYNC_TAGFILTER_ONE: |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
633 | return matches_tags_one(dav_tags, tagfilter->tags, ignorecase); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
634 | default: |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
635 | abort(); |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
636 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
637 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
638 | } |
90c6bfa94fa2
moves tag filter to tags.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
639 |