dav/tags.c

Wed, 30 May 2018 16:51:52 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 30 May 2018 16:51:52 +0200
changeset 393
438c8fe7d62f
parent 390
26998dc980f9
child 400
90c6bfa94fa2
permissions
-rw-r--r--

parse_csv_taglist() now skips empty tags

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>
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <ucx/string.h>
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <ucx/utils.h>
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "libxattr.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 "tags.h"
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
363
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
39 #ifdef __APPLE__
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
40 #include <CoreFoundation/CoreFoundation.h>
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
41 #endif
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
42
390
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
43 void free_dav_tag(DavTag* tag) {
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
44 free(tag->name);
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
45 free(tag->color);
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
46 free(tag);
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
47 }
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
48
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
49 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
50 sstr_t leftname = sstr(left->name);
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
51 sstr_t rightname = sstr(right->name);
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
52 if (ignorecase && *((int*) ignorecase)) {
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
53 return sstrcasecmp(leftname, rightname);
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
54 } else {
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
55 return sstrcmp(leftname, rightname);
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
56 }
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
57 }
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 388
diff changeset
58
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 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
60 UcxList *tags = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 int line_start = 0;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 for(int i=0;i<length;i++) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 if(buf[i] == '\n' || i == length-1) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 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
66 if(line.length > 0) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 DavTag *tag = calloc(1, sizeof(DavTag));
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 tag->name = sstrdup(line).ptr;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 tag->color = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 tags = ucx_list_append(tags, tag);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 line_start = i+1;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 return tags;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 UcxBuffer* create_text_taglist(UcxList *tags) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 if(!tags) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 return NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 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
85 UCX_FOREACH(elm, tags) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 DavTag *tag = elm->data;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 ucx_bprintf(buf, "%s\n", tag->name);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 return buf;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
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 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
94 UcxList *taglist = NULL;
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 sstr_t str = sstrn((char*)buf, length);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 ssize_t count = 0;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 sstr_t *tags = sstrsplit(str, S(","), &count);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 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
100 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
101 if (trimmed_tag.length > 0) {
438c8fe7d62f parse_csv_taglist() now skips empty tags
Mike Becker <universe@uap-core.de>
parents: 390
diff changeset
102 DavTag *tag = malloc(sizeof(DavTag));
438c8fe7d62f parse_csv_taglist() now skips empty tags
Mike Becker <universe@uap-core.de>
parents: 390
diff changeset
103 tag->name = sstrdup(trimmed_tag).ptr;
438c8fe7d62f parse_csv_taglist() now skips empty tags
Mike Becker <universe@uap-core.de>
parents: 390
diff changeset
104 tag->color = NULL;
438c8fe7d62f parse_csv_taglist() now skips empty tags
Mike Becker <universe@uap-core.de>
parents: 390
diff changeset
105 taglist = ucx_list_append(taglist, tag);
438c8fe7d62f parse_csv_taglist() now skips empty tags
Mike Becker <universe@uap-core.de>
parents: 390
diff changeset
106 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 free(tags[i].ptr);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 if(tags) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 free(tags);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 return taglist;
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
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 UcxBuffer* create_csv_taglist(UcxList *tags) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 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
117 int insertsep = 0;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 UCX_FOREACH(elm, tags) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 DavTag *tag = elm->data;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 if(insertsep) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 ucx_buffer_putc(buf, ',');
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 ucx_buffer_puts(buf, tag->name);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 insertsep = 1;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 return buf;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 static DavTag* parse_xml_dav_tag(DavXmlNode *node) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 char *name = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 DavXmlNode *c = node->children;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 while(c) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 if(c->type == DAV_XML_ELEMENT) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 char *value = dav_xml_getstring(c->children);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 if(value) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 if(!strcmp(c->namespace, DAV_NS)) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 if(!strcmp(c->name, "name")) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 char *value = dav_xml_getstring(c->children);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 if(value) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 name = value;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 // TODO: color, ...
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 }
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 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 c = c->next;
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
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 DavTag *tag = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 if(name) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 tag = malloc(sizeof(DavTag));
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 tag->name = strdup(name);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 tag->color = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 return tag;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 UcxList* parse_dav_xml_taglist(DavXmlNode *taglistnode) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 UcxList *tags = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 DavXmlNode *node = taglistnode;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 while(node) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 if(node->type == DAV_XML_ELEMENT) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 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
168 DavTag *tag = parse_xml_dav_tag(node);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 if(tag) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 tags = ucx_list_append(tags, tag);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 node = node->next;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 return tags;
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 DavXmlNode* create_xml_taglist(UcxList *tags) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 DavXmlNode *tag1 = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 DavXmlNode *lasttag = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 UCX_FOREACH(elm, tags) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 DavTag *tag = elm->data;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 DavXmlNode *tagelm = dav_xml_createnode(DAV_NS, "tag");
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 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
188 // TODO: color
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 tagelm->children = tagname;
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 if(lasttag) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 lasttag->next = tagelm;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 tagelm->prev = lasttag;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 } else {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 tag1 = tagelm;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 lasttag = tagelm;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 return tag1;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 }
363
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
201
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
202
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
203 #ifdef __APPLE__
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
204 static DavTag* tagstr2davtag(const char *str) {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
205 const char *name = str;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
206 const char *color = NULL;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
207 size_t len = strlen(str);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
208 size_t namelen = len;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
209
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
210 if(len == 0) {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
211 return NULL;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
212 }
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
213
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
214 // 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
215 for(int i=1;i<len;i++) {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
216 if(str[i] == '\n') {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
217 if(!color) {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
218 color = str + i + 1;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
219 namelen = i;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
220 }
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
221 }
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
222 }
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
223 int colorlen = len - namelen - 1;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
224
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
225 DavTag *tag = malloc(sizeof(DavTag));
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
226 tag->name = malloc(namelen + 1);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
227 memcpy(tag->name, name, namelen);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
228 tag->name[namelen] = 0;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
229 if(colorlen > 0) {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
230 tag->color = malloc(colorlen + 1);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
231 memcpy(tag->color, color, colorlen);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
232 tag->color[colorlen] = 0;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
233 } else {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
234 tag->color = NULL;
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 return tag;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
238 }
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
239
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
240 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
241 UcxList *taglist = NULL;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
242
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
243 CFDataRef data = CFDataCreateWithBytesNoCopy(
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
244 kCFAllocatorDefault,
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
245 (const UInt8*)buf,
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
246 length,
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
247 kCFAllocatorNull);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
248 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
249 CFArrayRef array = propertylist;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
250 int count = CFArrayGetCount(array);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
251 for(int i=0;i<count;i++) {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
252 CFStringRef str = CFArrayGetValueAtIndex(array, i);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
253 int slen = CFStringGetLength(str);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
254 size_t cstrbuflen = slen * 4 + 4;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
255 char *cstr = malloc(cstrbuflen);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
256 if(CFStringGetCString(str, cstr, cstrbuflen, kCFStringEncodingUTF8)) {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
257 DavTag *tag = tagstr2davtag(cstr);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
258 if(tag) {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
259 taglist = ucx_list_append(taglist, tag);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
260 }
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
261 }
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
262 free(cstr);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
263 }
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
264
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
265 CFRelease(propertylist);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
266 CFRelease(data);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
267
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
268 return taglist;
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 UcxBuffer* create_macos_taglist(UcxList *tags) {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
272 size_t count = ucx_list_size(tags);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
273 if(count == 0) {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
274 return NULL;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
275 }
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 CFStringRef *strings = calloc(sizeof(CFStringRef), count);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
278 int i = 0;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
279 UCX_FOREACH(elm, tags) {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
280 DavTag *tag = elm->data;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
281 CFStringRef str = NULL;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
282 if(tag->color) {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
283 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
284 str = CFStringCreateWithCString(kCFAllocatorDefault, s.ptr, kCFStringEncodingUTF8);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
285 free(s.ptr);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
286 } else {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
287 str = CFStringCreateWithCString(kCFAllocatorDefault, tag->name, kCFStringEncodingUTF8);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
288 }
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
289 strings[i] = str;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
290 i++;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
291 }
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
292
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
293 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
294 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
295
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
296 UcxBuffer *buf = NULL;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
297 if(data) {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
298 int datalen = CFDataGetLength(data);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
299 CFRange range;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
300 range.location = 0;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
301 range.length = datalen;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
302 buf = ucx_buffer_new(NULL, datalen, 0);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
303 CFDataGetBytes(data, range, (UInt8*)buf->space);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
304 buf->size = datalen;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
305 CFRelease(data);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
306 }
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
307
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
308 for(int i=0;i<count;i++) {
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
309 CFRelease(strings[i]);
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 CFRelease(array);
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
312
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
313 return buf;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
314 }
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
315
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
316 #else
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
317 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
318 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
319 return NULL;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
320 }
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
321 UcxBuffer* create_macos_taglist(UcxList *tags) {
373
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 363
diff changeset
322 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
323 return NULL;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
324 }
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
325 #endif
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
326

mercurial