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 DB_H 30 #define DB_H 31 32 #include <inttypes.h> 33 #include <libidav/webdav.h> 34 #include <cx/hash_map.h> 35 #include <cx/linked_list.h> 36 #include <cx/buffer.h> 37 #include <time.h> 38 39 #include <libxml/xmlreader.h> 40 41 #include "finfo.h" 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 #define DB_STORE_MODE 1 48 #define DB_STORE_OWNER 2 49 50 typedef struct LocalResource LocalResource; 51 typedef struct FilePart FilePart; 52 typedef struct SyncDatabase SyncDatabase; 53 54 struct LocalResource { 55 char *name; 56 char *path; 57 char *etag; 58 char *hash; 59 time_t last_modified; 60 mode_t mode; 61 uid_t uid; 62 gid_t gid; 63 off_t size; 64 DavBool isdirectory; 65 DavBool skipped; 66 CxBuffer *cached_tags; 67 XAttributes *xattr; 68 char *tags_hash; 69 char *xattr_hash; 70 char *remote_tags_hash; 71 72 char *local_path; 73 74 char *link_target; 75 char *link_target_db; 76 77 FilePart *parts; 78 size_t numparts; 79 80 int64_t blocksize; 81 82 DavBool tags_updated; 83 DavBool finfo_updated; 84 DavBool xattr_updated; 85 DavBool metadata_updated; 86 DavBool link_updated; 87 88 DavBool keep; 89 DavBool restore; 90 91 DavBool versioncontrol; 92 93 DavBool isnew; 94 LocalResource *origin; 95 char *conflict_source; 96 97 char *prev_hash; 98 }; 99 100 struct FilePart { 101 uint64_t block; 102 char *hash; 103 char *etag; 104 }; 105 106 struct SyncDatabase { 107 CxMap *resources; 108 CxMap *conflict; 109 }; 110 111 SyncDatabase* load_db(char *name); 112 int store_db(SyncDatabase *db, char *name, uint32_t settings); 113 void destroy_db(SyncDatabase *db); 114 115 void local_resource_free(LocalResource *res); 116 117 void local_resource_copy_parts(LocalResource *from, LocalResource *to); 118 119 LocalResource* local_resource_copy(LocalResource *src, const char *new_path); 120 121 void filepart_free(FilePart *part); 122 123 CxMap* create_hash_index(SyncDatabase *db); 124 125 LocalResource* process_resource(xmlTextReaderPtr reader); 126 LocalResource* process_conflict(xmlTextReaderPtr reader); 127 128 129 #ifdef __cplusplus 130 } 131 #endif 132 133 #endif /* DB_H */ 134 135