UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2018 Olaf Wintermann. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef TAGS_H 30 #define TAGS_H 31 32 #include <cx/string.h> 33 #include <cx/buffer.h> 34 #include <cx/list.h> 35 36 #include <libidav/webdav.h> 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 43 /* OFF must be zero, other constants are arbitrary */ 44 #define DAV_SYNC_TAGFILTER_OFF 0 45 #define DAV_SYNC_TAGFILTER_AND 1 46 #define DAV_SYNC_TAGFILTER_OR 2 47 #define DAV_SYNC_TAGFILTER_ONE 3 48 #define DAV_SYNC_TAGFILTER_NONE 4 49 50 #define DAV_SYNC_TAGFILTER_SCOPE_RESOURCE 1 51 #define DAV_SYNC_TAGFILTER_SCOPE_COLLECTION 2 52 53 typedef struct DavTag { 54 char *name; 55 char *color; 56 } DavTag; 57 58 /** 59 * filter ::= operator? , (tag_list | ("(" , filter , ")")+) 60 * tag_list ::= tag , ("," tag)* 61 * operator ::= "&" | "|" | "1" | "0" 62 */ 63 typedef struct SyncTagFilter SyncTagFilter; 64 65 struct SyncTagFilter { 66 int scope; 67 int mode; 68 CxList* tags; 69 size_t subfilter_count; 70 SyncTagFilter** subfilters; 71 }; 72 73 void free_dav_tag(DavTag* tag); 74 75 void free_taglist(CxList *list); 76 77 int compare_tagname(DavTag* left, DavTag* right, void* ignorecase); 78 79 CxMap* taglist2map(CxList *tags); 80 81 CxList* parse_text_taglist(const char *buf, size_t length); 82 CxBuffer* create_text_taglist(CxList *tags); 83 84 CxList* parse_csv_taglist(const char *buf, size_t length); 85 CxBuffer* create_csv_taglist(CxList *tags); 86 87 CxList* parse_dav_xml_taglist(DavXmlNode *taglistnode); 88 DavXmlNode* create_xml_taglist(CxList *tags); 89 90 CxList* parse_macos_taglist(const char *buf, size_t length); 91 CxBuffer* create_macos_taglist(CxList *tags); 92 93 int compare_taglists(CxList *tags1, CxList *tags2); 94 95 char* create_tags_hash(CxList *tags); 96 97 CxList* merge_tags(CxList *tags1, CxList *tags2); 98 99 /* 100 * Adds tag colors from the colored list to taglist if tags have the same name 101 */ 102 void add_tag_colors(CxList *taglist, CxList *colored); 103 104 /* ----------- ----------- tag filter ---------------------- */ 105 106 SyncTagFilter* parse_tagfilter_string(const char* filterstring, int scope); 107 void free_tagfilter(SyncTagFilter* filter); 108 109 int matches_tagfilter(CxList *dav_tags, SyncTagFilter *tagfilter); 110 111 #ifdef __cplusplus 112 } 113 #endif 114 115 #endif /* TAGS_H */ 116 117