Sun, 07 Jan 2018 12:59:21 +0100
adds support for macos file 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 | |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | 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
|
44 | UcxList *tags = NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | int line_start = 0; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | for(int i=0;i<length;i++) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | if(buf[i] == '\n' || i == length-1) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | 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
|
50 | if(line.length > 0) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | DavTag *tag = calloc(1, sizeof(DavTag)); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | tag->name = sstrdup(line).ptr; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | tag->color = NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | tags = ucx_list_append(tags, tag); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | line_start = i+1; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | return tags; |
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 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | UcxBuffer* create_text_taglist(UcxList *tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | if(!tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | return NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | 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
|
69 | UCX_FOREACH(elm, tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | DavTag *tag = elm->data; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | ucx_bprintf(buf, "%s\n", tag->name); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | return buf; |
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 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | 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
|
78 | UcxList *taglist = NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | sstr_t str = sstrn((char*)buf, length); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | ssize_t count = 0; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | sstr_t *tags = sstrsplit(str, S(","), &count); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | for(int i=0;i<count;i++) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | DavTag *tag = malloc(sizeof(DavTag)); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | tag->name = sstrdup(sstrtrim(tags[i])).ptr; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | tag->color = NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | taglist = ucx_list_append(taglist, tag); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | free(tags[i].ptr); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | if(tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | free(tags); |
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 | return taglist; |
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 | UcxBuffer* create_csv_taglist(UcxList *tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | 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
|
98 | int insertsep = 0; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | UCX_FOREACH(elm, tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | DavTag *tag = elm->data; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | if(insertsep) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | ucx_buffer_putc(buf, ','); |
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 | ucx_buffer_puts(buf, tag->name); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | insertsep = 1; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | return buf; |
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 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | static DavTag* parse_xml_dav_tag(DavXmlNode *node) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | char *name = NULL; |
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 | DavXmlNode *c = node->children; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | while(c) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | if(c->type == DAV_XML_ELEMENT) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | char *value = dav_xml_getstring(c->children); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | if(value) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | if(!strcmp(c->namespace, DAV_NS)) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | if(!strcmp(c->name, "name")) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | char *value = dav_xml_getstring(c->children); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | if(value) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | name = value; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | } |
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 | // TODO: color, ... |
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 | c = c->next; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | } |
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 | DavTag *tag = NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | if(name) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | tag = malloc(sizeof(DavTag)); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | tag->name = strdup(name); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | tag->color = NULL; |
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 | return tag; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | UcxList* parse_dav_xml_taglist(DavXmlNode *taglistnode) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | UcxList *tags = NULL; |
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 | DavXmlNode *node = taglistnode; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | while(node) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | if(node->type == DAV_XML_ELEMENT) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | 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
|
149 | DavTag *tag = parse_xml_dav_tag(node); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | if(tag) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | tags = ucx_list_append(tags, tag); |
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 | node = node->next; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | } |
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 tags; |
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 | DavXmlNode* create_xml_taglist(UcxList *tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | DavXmlNode *tag1 = NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | DavXmlNode *lasttag = NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | UCX_FOREACH(elm, tags) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | DavTag *tag = elm->data; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | DavXmlNode *tagelm = dav_xml_createnode(DAV_NS, "tag"); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | 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
|
169 | // TODO: color |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | tagelm->children = tagname; |
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 | if(lasttag) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | lasttag->next = tagelm; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | tagelm->prev = lasttag; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | } else { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | tag1 = tagelm; |
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 | lasttag = tagelm; |
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 | return tag1; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | } |
363
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
182 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
183 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
184 | #ifdef __APPLE__ |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
185 | static DavTag* tagstr2davtag(const char *str) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
186 | const char *name = str; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
187 | const char *color = NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
188 | size_t len = strlen(str); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
189 | size_t namelen = len; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
190 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
191 | if(len == 0) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
192 | return NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
193 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
194 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
195 | // 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
|
196 | for(int i=1;i<len;i++) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
197 | if(str[i] == '\n') { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
198 | if(!color) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
199 | color = str + i + 1; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
200 | namelen = i; |
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 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
204 | int colorlen = len - namelen - 1; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
205 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
206 | DavTag *tag = malloc(sizeof(DavTag)); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
207 | tag = malloc(sizeof(DavTag)); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
208 | tag->name = malloc(namelen + 1); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
209 | memcpy(tag->name, name, namelen); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
210 | tag->name[namelen] = 0; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
211 | if(colorlen > 0) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
212 | tag->color = malloc(colorlen + 1); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
213 | memcpy(tag->color, color, colorlen); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
214 | tag->color[colorlen] = 0; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
215 | } else { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
216 | tag->color = NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
217 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
218 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
219 | return tag; |
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 | 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
|
223 | UcxList *taglist = NULL; |
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 | CFDataRef data = CFDataCreateWithBytesNoCopy( |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
226 | kCFAllocatorDefault, |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
227 | (const UInt8*)buf, |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
228 | length, |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
229 | kCFAllocatorNull); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
230 | 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
|
231 | CFArrayRef array = propertylist; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
232 | int count = CFArrayGetCount(array); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
233 | for(int i=0;i<count;i++) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
234 | CFStringRef str = CFArrayGetValueAtIndex(array, i); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
235 | int slen = CFStringGetLength(str); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
236 | size_t cstrbuflen = slen * 4 + 4; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
237 | char *cstr = malloc(cstrbuflen); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
238 | if(CFStringGetCString(str, cstr, cstrbuflen, kCFStringEncodingUTF8)) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
239 | DavTag *tag = tagstr2davtag(cstr); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
240 | if(tag) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
241 | taglist = ucx_list_append(taglist, tag); |
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 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
244 | free(cstr); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
245 | } |
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 | CFRelease(propertylist); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
248 | CFRelease(data); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
249 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
250 | return taglist; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
251 | } |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
252 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
253 | UcxBuffer* create_macos_taglist(UcxList *tags) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
254 | size_t count = ucx_list_size(tags); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
255 | if(count == 0) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
256 | return NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
257 | } |
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 | CFStringRef *strings = calloc(sizeof(CFStringRef), count); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
260 | int i = 0; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
261 | UCX_FOREACH(elm, tags) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
262 | DavTag *tag = elm->data; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
263 | CFStringRef str = NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
264 | if(tag->color) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
265 | 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
|
266 | str = CFStringCreateWithCString(kCFAllocatorDefault, s.ptr, kCFStringEncodingUTF8); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
267 | free(s.ptr); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
268 | } else { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
269 | str = CFStringCreateWithCString(kCFAllocatorDefault, tag->name, kCFStringEncodingUTF8); |
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 | strings[i] = str; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
272 | i++; |
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 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
275 | 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
|
276 | 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
|
277 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
278 | UcxBuffer *buf = NULL; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
279 | if(data) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
280 | int datalen = CFDataGetLength(data); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
281 | CFRange range; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
282 | range.location = 0; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
283 | range.length = datalen; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
284 | buf = ucx_buffer_new(NULL, datalen, 0); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
285 | CFDataGetBytes(data, range, (UInt8*)buf->space); |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
286 | buf->size = datalen; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
287 | CFRelease(data); |
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 | |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
290 | for(int i=0;i<count;i++) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
291 | CFRelease(strings[i]); |
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 | CFRelease(array); |
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 | return buf; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
296 | } |
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 | #else |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
299 | 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
|
300 | return NULL; |
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 | UcxBuffer* create_macos_taglist(UcxList *tags) { |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
303 | return NULL; |
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 | #endif |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
306 |