UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2019 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 MAIN_H 30 #define MAIN_H 31 32 #include <time.h> 33 #include <curl/curl.h> 34 #include "optparser.h" 35 #include <libidav/webdav.h> 36 37 #include "tar.h" 38 #include "version.h" 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 typedef struct { 45 DavResource *res; 46 char *path; 47 } GetResource; 48 49 typedef struct { 50 FILE *out; 51 int isstdout; 52 int64_t total; 53 int64_t cur; 54 int64_t last_res_cur; 55 int64_t last_res_total; 56 DavResource *last_resource; 57 time_t ts; 58 } Progress; 59 60 typedef int(*getfunc)(DavCfgRepository *, GetResource *, CmdArgs *, void *); 61 62 void print_usage(char *cmd); 63 64 int update_progress(DavResource *res, int64_t total, int64_t now, Progress *p); 65 void download_progress(DavResource *res, int64_t total, int64_t now, void *data); 66 67 int cmd_list(CmdArgs *args); 68 void ls_print_list_elm(DavResource *res, char *parent, CmdArgs *args); 69 void ls_print_elm(DavResource *res, char *parent, CmdArgs *args); 70 71 int cmd_get(CmdArgs *args, DavBool export); 72 int get_resource(DavCfgRepository *repo, GetResource *res, CmdArgs *a, void *unused); 73 int resource2tar(DavCfgRepository *repo, GetResource *res, CmdArgs *a, TarOutputStream *tar); 74 75 int cmd_put(CmdArgs *args, DavBool import); 76 int put_entry( 77 DavCfgRepository *repo, 78 CmdArgs *a, 79 DavSession *sn, 80 char *path, 81 char *file, 82 uint32_t finfo, 83 DavBool root, 84 DavBool printfile, 85 DavBool ignoredirerr); 86 int put_tar(DavCfgRepository *repo, CmdArgs *a, DavSession *sn, char *tarfile, char *path); 87 int put_file( 88 DavCfgRepository *repo, 89 CmdArgs *a, 90 DavSession *sn, 91 const char *path, 92 const char *name, 93 uint32_t finfo, 94 const char *fpath, 95 FILE *in, 96 off_t len); 97 98 int cmd_edit(CmdArgs *args); 99 100 int cmd_remove(CmdArgs *args); 101 int cmd_mkdir(CmdArgs *args); 102 103 int cmd_move(CmdArgs *args, int cp); 104 int cmd_rename(CmdArgs *args); 105 106 int cmd_date(CmdArgs *args); 107 108 int cmd_get_property(CmdArgs *args); 109 int cmd_set_property(CmdArgs *args); 110 int cmd_remove_property(CmdArgs *args); 111 112 int cmd_lock(CmdArgs *args); 113 int cmd_unlock(CmdArgs *args); 114 115 int cmd_info(CmdArgs *args); 116 117 int cmd_checkout(CmdArgs *args); 118 int cmd_checkin(CmdArgs *args); 119 int cmd_uncheckout(CmdArgs *args); 120 int cmd_versioncontrol(CmdArgs *args); 121 int cmd_list_versions(CmdArgs *args); 122 123 DavResource* find_version(DavResource *res, char *version); 124 125 char* stdin2str(); 126 char* xml2str(DavXmlNode *node); 127 void printxmldoc(FILE *out, char *root, char *rootns, DavXmlNode *content); 128 129 int cmd_add_repository(CmdArgs *args); 130 int cmd_remove_repository(CmdArgs *args); 131 int cmd_list_repositories(void); 132 133 int cmd_repository_url(CmdArgs *args); 134 135 int cmd_add_user(CmdArgs *args); 136 int cmd_list_users(CmdArgs *args); 137 int cmd_remove_user(CmdArgs *args); 138 int cmd_edit_user(CmdArgs *args); 139 140 int cmd_set_master_password(CmdArgs *args); 141 142 int cmd_complete(CmdArgs *args); 143 144 int shell_completion(char *cmd, CmdArgs *args, int index); 145 146 int url_completion(CmdArgs *args, char *url); 147 148 #ifdef __cplusplus 149 } 150 #endif 151 152 #endif /* MAIN_H */ 153 154