dav/main.c

Sun, 29 Apr 2018 11:16:41 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 29 Apr 2018 11:16:41 +0200
changeset 373
dcc03142eb5f
parent 371
604e7e335b3b
child 375
39fd327f81da
permissions
-rw-r--r--

dav info prints simplified xml values

1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
364
3769ba002fd1 updates copyright date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 363
diff changeset
4 * Copyright 2018 Olaf Wintermann. All rights reserved.
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1bcaac272cdf added existing source code
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
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
182
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
32 #include <stdbool.h>
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
33 #include <errno.h>
4
ae5a98f0545c added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
34 #include <unistd.h>
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
35 #include <time.h>
4
ae5a98f0545c added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
36 #include <sys/types.h>
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
37 #include <ucx/string.h>
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
38 #include <ucx/utils.h>
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
39 #include <dirent.h>
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 32
diff changeset
41 #include <libidav/utils.h>
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
42 #include <libidav/crypto.h>
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
43 #include <libidav/session.h>
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
44 #include <libidav/xml.h>
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
45 #include "config.h"
191
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
46 #include "error.h"
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
47 #include "assistant.h"
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 #include "main.h"
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
12
493128ef1b12 added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
50 static DavContext *ctx;
493128ef1b12 added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
51
142
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
52 static int printxmlerror = 1;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
53 static void xmlerrorfnc(void * c, const char * msg, ... ) {
142
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
54 if(printxmlerror) {
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
55 va_list ap;
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
56 va_start(ap, msg);
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
57 vfprintf(stderr, msg, ap);
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
58 va_end(ap);
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
59 }
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 126
diff changeset
62 //define DO_THE_TEST
363
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
63 //include <libidav/davqlparser.h>
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
64 //include <libidav/davqlexec.h>
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
65 //include "tags.h"
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
66
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
67 void test() {
363
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
68
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
69 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
70
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 int main(int argc, char **argv) {
34
1b87b3b1921e removed debug code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
72 if(argc < 2) {
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
73 fprintf(stderr, "Missing command\n");
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
74 print_usage(argv[0]);
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
75 return -1;
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
76 }
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
77
34
1b87b3b1921e removed debug code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
78 char *cmd = argv[1];
1b87b3b1921e removed debug code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
79 CmdArgs *args = cmd_parse_args(argc - 2, argv + 2);
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
80 if(!args) {
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
81 print_usage(argv[0]);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
82 cmd_args_free(args);
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 return -1;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
86 xmlGenericErrorFunc fnc = xmlerrorfnc;
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
87 initGenericErrorDefaultFunc(&fnc);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
88 ctx = dav_context_new();
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
89 dav_add_namespace(ctx, "apache", "http://apache.org/dav/props/");
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
90 int cfgret = load_config(ctx);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
91 int ret = EXIT_FAILURE;
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
92 printxmlerror = 0;
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
93 #ifdef DO_THE_TEST
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
94 test();
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
95 return 0;
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
96 #endif
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
97 if(!strcmp(cmd, "check") || !strcmp(cmd, "check-config")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
98 if(!cfgret) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
99 fprintf(stdout, "Configuration OK.\n");
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
100 ret = EXIT_SUCCESS;
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
101 } else {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
102 /* no output, the warnings are written by load_config */
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
103 ret = EXIT_FAILURE;
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
104 }
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
105 } else if(!cfgret) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
106 if(!strcasecmp(cmd, "list") || !strcasecmp(cmd, "ls")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
107 ret = cmd_list(args);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
108 } else if(!strcasecmp(cmd, "get")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
109 ret = cmd_get(args);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
110 } else if(!strcasecmp(cmd, "put")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
111 ret = cmd_put(args);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
112 } else if(
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
113 !strcasecmp(cmd, "remove") ||
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
114 !strcasecmp(cmd, "rm") ||
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
115 !strcasecmp(cmd, "delete"))
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
116 {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
117 ret = cmd_remove(args);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
118 } else if(!strcasecmp(cmd, "mkdir") || !strcasecmp(cmd, "mkcol")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
119 ret = cmd_mkdir(args);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
120 } else if(!strcasecmp(cmd, "copy") || !strcasecmp(cmd, "cp")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
121 ret = cmd_move(args, true);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
122 } else if(!strcasecmp(cmd, "move") || !strcasecmp(cmd, "mv")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
123 ret = cmd_move(args, false);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
124 } else if(!strcasecmp(cmd, "date")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
125 ret = cmd_date(args);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
126 } else if(!strcasecmp(cmd, "set-property")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
127 ret = cmd_set_property(args);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
128 } else if(!strcasecmp(cmd, "get-property")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
129 ret = cmd_get_property(args);
304
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
130 } else if(!strcasecmp(cmd, "remove-property")) {
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
131 ret = cmd_remove_property(args);
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
132 } else if(!strcasecmp(cmd, "lock")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
133 ret = cmd_lock(args);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
134 } else if(!strcasecmp(cmd, "unlock")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
135 ret = cmd_unlock(args);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
136 } else if(!strcasecmp(cmd, "info")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
137 ret = cmd_info(args);
256
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
138 } else if(!strcasecmp(cmd, "add-repository")
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
139 || !strcasecmp(cmd, "add-repo")) {
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
140 ret = cmd_add_repository(args);
256
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
141 } else if(!strcasecmp(cmd, "list-repositories")
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
142 || !strcasecmp(cmd, "list-repos")) {
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
143 ret = list_repositories();
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
144 } else if(!strcasecmp(cmd, "version") || !strcasecmp(cmd, "-version")
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
145 || !strcasecmp(cmd, "--version")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
146 fprintf(stderr, "dav %s\n", DAV_VERSION);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
147 } else {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
148 print_usage(argv[0]);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 241
diff changeset
149 }
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 }
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
151
16
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
152 dav_context_destroy(ctx);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
153 cmd_args_free(args);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
154 free_config();
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
155 xmlCleanupParser();
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
156 curl_global_cleanup();
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157
16
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
158 return ret;
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
161 static char *cmdusageinfo[] = {
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
162 "list [-altdepcR] [-u <date>] <url>",
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
163 "get [-pcRKA] [-o <file>] [-u <date>] <url>",
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
164 "put [-pcRA] [-k <key>] [-L <lock>] <url> <file>",
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
165 "mkdir [-pc] [-k <key>] [-L <lock>] <url>",
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
166 "remove [-pc] [-L <lock>] <url>",
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
167 "copy [-pcO] [-L <lock>] <url> <url>",
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
168 "move [-pcO] [-L <lock>] <url> <url>",
338
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
169 "get-property [-pcx] [-n <uri>] <url> <property>",
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
170 "set-property [-pcx] [-L <lock>] [-n <uri>] <url> <property> [value]",
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
171 "remove-property [-pc] [-n <uri>] <url> <property>",
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
172 "lock [-pc] [-T timeout] <url>",
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
173 "unlock [-pc] [-L <lock>] <url>",
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
174 "info [-pc] <url>",
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
175 "date [url]",
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
176 NULL
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
177 };
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
178
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
179 char* find_usage_str(char *cmd) {
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
180 sstr_t c = sstr(cmd);
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
181 for(int i=0;;i++) {
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
182 char *str = cmdusageinfo[i];
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
183 if(!str) {
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
184 break;
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
185 }
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
186 sstr_t u = sstr(str);
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
187 if(sstrprefix(u, c)) {
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
188 return str;
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
189 }
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
190 }
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
191 return NULL;
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
192 }
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
193
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
194 void print_usage(char *cmd) {
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
195 for(int i=0;;i++) {
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
196 char *str = cmdusageinfo[i];
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
197 if(!str) {
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
198 break;
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
199 }
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
200 fprintf(stderr, " %s\n", str);
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
201 }
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
202
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
203 fprintf(stderr, "\n");
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
204 fprintf(stderr, "Options:\n");
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
205 fprintf(stderr,
100
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
206 " -k <key> Key to use for encryption\n");
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
207 fprintf(stderr, " -p Don't encrypt or decrypt files\n");
45
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
208 fprintf(stderr, " -c Enable full encryption\n");
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
209 fprintf(stderr,
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
210 " -R "
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
211 "Recursively do the operation for all children\n");
330
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
212 fprintf(stderr, " -K Keep already present files\n");
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
213 fprintf(stderr, " -o <file> Write output to file\n");
30
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
214 fprintf(
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
215 stderr,
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
216 " -u <date> "
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
217 "Get resources which are modified since the specified date\n");
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
218 fprintf(stderr, " -a show all files\n");
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
219 fprintf(stderr, " -l print resources in long list format\n");
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
220 fprintf(stderr, " -t print content type\n");
305
c3d98b2cccf3 adds tests for crypto util functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 304
diff changeset
221 fprintf(stderr, " -d order by last modified date\n");
213
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
222 fprintf(stderr, " -e show extended flags\n");
182
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
223 fprintf(stderr, " -O override resources\n");
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
224 fprintf(stderr, " -A tar import/export\n");
209
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
225 fprintf(stderr, " -L <lock> specificy lock token\n");
315
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
226 fprintf(stderr, " -T <sec> timeout in seconds\n");
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
227 fprintf(stderr, " -n <uri> specify namespace uri\n");
338
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
228 fprintf(stderr, " -x xml property content\n");
229
df158262f802 fixed dav_context_get_key
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
229 fprintf(stderr, " -N disable authentication prompt (all commands)\n");
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
230 fprintf(stderr, " -i disable cert verification (all commands)\n");
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
231 fprintf(stderr, " -v verbose output (all commands)\n");
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
232 fprintf(stderr, "\n");
198
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
233 fprintf(stderr, "Config commands:\n");
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
234 fprintf(stderr, " add-repository\n");
198
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
235 fprintf(stderr, " list-repositories\n");
256
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
236 fprintf(stderr, " check-config\n");
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
237 fprintf(stderr, "\n");
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
238 fprintf(stderr,
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
239 "Instead of an url you can pass a repository name "
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
240 "with an optional path:\n");
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
241 fprintf(stderr, " <repository>/path/\n");
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
242 fprintf(stderr, "\n");
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
245
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
246 int request_auth2(DavSession *sn, void *userdata) {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
247 Repository *repo = userdata;
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
248
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
249 char *user = NULL;
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
250 char ubuf[256];
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
251 if(repo->user) {
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
252 user = repo->user;
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
253 } else {
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
254 fprintf(stderr, "User: ");
146
e48048334602 hidden password input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
255 fflush(stderr);
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
256 user = fgets(ubuf, 256, stdin);
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
257 }
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
258 if(!user) {
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
259 return 0;
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
260 }
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
261
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
262 char *password = util_password_input("Password: ");
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
263 if(!password || strlen(password) == 0) {
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
264 return 0;
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
265 }
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
266
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
267 size_t ulen = strlen(user);
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
268 if(user[ulen-1] == '\n') {
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
269 user[ulen-1] = '\0';
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
270 }
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
271
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
272 dav_session_set_auth(sn, user, password);
146
e48048334602 hidden password input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
273 free(password);
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
274
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
275 return 0;
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
276 }
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
277
210
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
278 static Repository* url2repo(char *url, char **path) {
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
279 size_t ulen = strlen(url);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
280 *path = NULL;
4
ae5a98f0545c added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
281
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
282 int s;
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
283 if(ulen > 7 && !strncasecmp(url, "http://", 7)) {
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
284 s = 7;
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
285 } else if(ulen > 8 && !strncasecmp(url, "https://", 8)) {
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
286 s = 8;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
287 } else {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
288 s = 1;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
289 }
4
ae5a98f0545c added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
290
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
291 sstr_t r = sstr(url);
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
292 sstr_t p = sstr("/");
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
293 for(int i=s;i<ulen;i++) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
294 char c = url[i];
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
295 if(c == '/') {
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
296 r = sstrn(url, i);
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
297 p = sstrsubs(sstr(url), i);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
298 if(p.length == 0) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
299 p = sstrn("/", 1);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
300 }
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
301 break;
4
ae5a98f0545c added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
302 }
ae5a98f0545c added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
303 }
ae5a98f0545c added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
304
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
305 Repository *repo = get_repository(r);
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
306 if(repo) {
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
307 *path = sstrdup(p).ptr;
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
308 } else {
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
309 repo = calloc(1, sizeof(Repository));
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
310 repo->name = strdup("");
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
311 repo->decrypt_content = true;
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 201
diff changeset
312 repo->verification = true;
187
38295f2fa231 added missing repo authmethods initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
313 repo->authmethods = CURLAUTH_BASIC;
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
314 if(url[ulen-1] == '/') {
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
315 repo->url = strdup(url);
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
316 *path = strdup("/");
100
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
317 } else if (strchr(url, '/')) {
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
318 repo->url = util_parent_path(url);
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
319 // TODO: check/fix
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
320 *path = strdup(util_resource_name(url)-1);
100
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
321 } else {
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
322 repo->url = strdup(url);
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
323 *path = strdup("/");
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
324 }
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
325 }
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
326
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
327 return repo;
4
ae5a98f0545c added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
328 }
ae5a98f0545c added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
329
210
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
330 static int set_session_config(DavSession *sn, CmdArgs *a) {
45
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
331 char *plain = cmd_getoption(a, "plain");
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
332 char *crypt = cmd_getoption(a, "crypt");
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
333
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
334 if(plain && crypt) {
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
335 fprintf(stderr, "Error: -p and -c option set\n");
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
336 return 1;
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
337 }
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
338
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
339 if (plain) {
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
340 sn->flags &= ~DAV_SESSION_FULL_ENCRYPTION;
45
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
341 } else if(crypt) {
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
342 sn->flags |= DAV_SESSION_FULL_ENCRYPTION;
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
343 }
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
344
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
345 if (cmd_getoption(a, "verbose")) {
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
346 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L);
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
347 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr);
45
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
348 }
210
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
349
45
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
350 return 0;
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
351 }
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
352
210
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
353 static void set_session_lock(DavSession *sn, CmdArgs *a) {
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
354 char *locktoken = cmd_getoption(a, "lock");
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
355 if(locktoken) {
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
356 DavLock *lock = dav_create_lock(sn, locktoken, NULL);
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
357 dav_add_collection_lock(sn, "/", lock);
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
358 }
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
359 }
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
360
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
361 static DavSession* connect_to_repo(Repository *repo, CmdArgs *a) {
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
362 DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password);
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
363 sn->flags = get_repository_flags(repo);
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
364 sn->key = dav_context_get_key(ctx, repo->default_key);
154
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 152
diff changeset
365 curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods);
73
41e88442ad4e ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
366 curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version);
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
367 if(repo->cert) {
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
368 curl_easy_setopt(sn->handle, CURLOPT_CAINFO, repo->cert);
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
369 }
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
370 if(!repo->verification || cmd_getoption(a, "insecure")) {
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
371 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYPEER, 0);
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
372 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0);
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
373 }
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
374 if(!cmd_getoption(a, "noinput")) {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
375 dav_session_set_authcallback(sn, request_auth2, repo);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
376 }
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
377 return sn;
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
378 }
4
ae5a98f0545c added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
379
355
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
380 int update_progress(DavResource *res, int64_t total, int64_t now, Progress *p) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
381 int ret = 0;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
382 if(res != p->last_resource) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
383 p->cur += p->last_res_total - p->last_res_cur;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
384 ret = 1;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
385 } else {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
386 p->cur += now - p->last_res_cur;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
387 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
388
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
389 p->last_resource = res;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
390 p->last_res_cur = now;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
391 p->last_res_total = total;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
392
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
393 return ret;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
394 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
395
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
396 void download_progress(DavResource *res, int64_t total, int64_t now, void *data) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
397 Progress *p = data;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
398 int newres = update_progress(res, total, now, p);
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
399
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
400 time_t newts = time(NULL);
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
401 if(newres || (p->ts != newts)) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
402 fprintf(p->out, "[%s]: %" PRId64 "k/%" PRId64 "k total: %" PRId64 "M/%" PRId64 "M\n", res->name, now/1024, total/1024, p->cur/(1024*1024), p->total/(1024*1024));
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
403 fflush(p->out);
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
404 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
405 p->ts = newts;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
406 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
407
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
408
297
3cbe57eeaed1 adds option to sort dav list by lastmodified date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
409 #define LIST_QUERY_ORDER_BY_NAME "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery,apache:executable from %s with depth = %d where lastmodified > %t order by iscollection desc, name"
3cbe57eeaed1 adds option to sort dav list by lastmodified date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
410 #define LIST_QUERY_ORDER_BY_DATE "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery,apache:executable from %s with depth = %d where lastmodified > %t order by iscollection desc, lastmodified desc"
3cbe57eeaed1 adds option to sort dav list by lastmodified date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
411
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
412 int cmd_list(CmdArgs *a) {
35
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
413 if(a->argc != 1) {
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
414 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many");
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
415 fprintf(stderr, "Usage: dav %s\n", find_usage_str("list"));
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
416 return -1;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
417 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
418
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
419 char *url = a->argv[0];
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
420 char *path = NULL;
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
421 Repository *repo = url2repo(url, &path);
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
422 DavSession *sn = connect_to_repo(repo, a);
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
423
45
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
424 if(set_session_config(sn, a)) {
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
425 return -1;
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
426 }
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
427
30
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
428 char *update = cmd_getoption(a, "update");
297
3cbe57eeaed1 adds option to sort dav list by lastmodified date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
429 char *date = cmd_getoption(a, "date");
136
59058927b885 empty field results will no longer be added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
430 time_t t = -1;
30
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
431 if(update) {
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
432 t = util_parse_lastmodified(update);
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
433 }
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
434
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
435 int depth = cmd_getoption(a, "recursive") ? -1 : 1;
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
436 int ret = -1;
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
437 DavResource *ls = dav_query(
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
438 sn,
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
439 date ? LIST_QUERY_ORDER_BY_DATE : LIST_QUERY_ORDER_BY_NAME,
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
440 path,
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
441 depth,
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
442 t);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
443 if(ls) {
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
444 // parameters
270
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
445 void (*print_func)(DavResource*, char *, CmdArgs *);
213
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
446 if(cmd_getoption(a, "list") || cmd_getoption(a, "extended")) {
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
447 print_func = ls_print_list_elm;
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
448 } else {
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
449 print_func = ls_print_elm;
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
450 }
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 126
diff changeset
451
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
452 DavResource *child = ls->children;
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
453 while(child) {
270
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
454 print_func(child, path, a);
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
455 child = child->next;
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
456 }
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
457 } else {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
458 print_resource_error(sn, path);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
459 }
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
460
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
461 free(path);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
462 //free(base);
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
463
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
464 dav_session_destroy(sn);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
465
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
466 return ret;
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
467 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
468
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
469 static char* ls_date_str(time_t tm) {
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
470 struct tm t;
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
471 struct tm n;
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
472 time_t now = time(NULL);
32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
473 #ifdef _WIN32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
474 memcpy(&t, localtime(&tm), sizeof(struct tm));
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
475 memcpy(&n, localtime(&now), sizeof(struct tm));
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
476 #else
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
477 localtime_r(&tm, &t);
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
478 localtime_r(&now, &n);
32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
479 #endif /* _WIN32 */
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
480 char *str = malloc(16);
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
481 if(t.tm_year == n.tm_year) {
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
482 strftime(str, 16, "%b %d %H:%M", &t);
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
483 } else {
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
484 strftime(str, 16, "%b %d %Y", &t);
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
485 }
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
486 return str;
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
487 }
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
488
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
489 static char* ls_size_str(DavResource *res) {
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
490 char *str = malloc(16);
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
491 uint64_t size = res->contentlength;
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
492
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
493 if(res->iscollection) {
165
b66bed169fc3 fixed zero-length format string in ls_size_str
Mike Becker <universe@uap-core.de>
parents: 154
diff changeset
494 str[0] = '\0'; // currently no information for collections
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
495 } else if(size < 0x400) {
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
496 snprintf(str, 16, "%" PRIu64 " bytes", size);
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
497 } else if(size < 0x100000) {
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
498 float s = (float)size/0x400;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
499 int diff = (s*100 - (int)s*100);
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
500 if(diff > 90) {
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
501 diff = 0;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
502 s += 0.10f;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
503 }
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
504 if(size < 0x2800 && diff != 0) {
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
505 // size < 10 KiB
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
506 snprintf(str, 16, "%.1f KiB", s);
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
507 } else {
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
508 snprintf(str, 16, "%.0f KiB", s);
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
509 }
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
510 } else if(size < 0x40000000) {
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
511 float s = (float)size/0x100000;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
512 int diff = (s*100 - (int)s*100);
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
513 if(diff > 90) {
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
514 diff = 0;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
515 s += 0.10f;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
516 }
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
517 if(size < 0xa00000 && diff != 0) {
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
518 // size < 10 MiB
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
519 snprintf(str, 16, "%.1f MiB", s);
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
520 } else {
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
521 size /= 0x100000;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
522 snprintf(str, 16, "%.0f MiB", s);
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
523 }
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
524 } else if(size < 0x1000000000ULL) {
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
525 float s = (float)size/0x40000000;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
526 int diff = (s*100 - (int)s*100);
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
527 if(diff > 90) {
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
528 diff = 0;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
529 s += 0.10f;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
530 }
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
531 if(size < 0x280000000 && diff != 0) {
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
532 // size < 10 GiB
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
533 snprintf(str, 16, "%.1f GiB", s);
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
534 } else {
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
535 size /= 0x40000000;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
536 snprintf(str, 16, "%.0f GiB", s);
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
537 }
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
538 } else {
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
539 size /= 1024;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
540 float s = (float)size/0x40000000;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
541 int diff = (s*100 - (int)s*100);
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
542 if(diff > 90) {
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
543 diff = 0;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
544 s += 0.10f;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
545 }
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
546 if(size < 0x280000000 && diff != 0) {
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
547 // size < 10 TiB
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
548 snprintf(str, 16, "%.1f TiB", s);
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
549 } else {
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
550 size /= 0x40000000;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
551 snprintf(str, 16, "%.0f TiB", s);
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
552 }
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
553 }
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
554 return str;
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
555 }
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
556
270
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
557 static char* ls_name(char *parent, char *path, int *len) {
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
558 if(parent) {
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
559 path += strlen(parent);
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
560 }
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
561 if(path[0] == '/') {
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
562 path++;
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
563 }
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
564 int pathlen = strlen(path);
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
565 if(path[pathlen-1] == '/') {
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
566 pathlen--;
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
567 }
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
568 *len = pathlen;
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
569 return path;
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
570 }
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
571
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
572 void ls_print_list_elm(DavResource *res, char *parent, CmdArgs *a) {
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
573 int recursive = cmd_getoption(a, "recursive") ? 1 : 0;
138
6a3248e22d58 -a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
574 int show_all = cmd_getoption(a, "all") ? 1 : 0;
6a3248e22d58 -a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
575 if(res->name[0] == '.' && !show_all) {
6a3248e22d58 -a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
576 return;
6a3248e22d58 -a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
577 }
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
578
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
579 char flags[16];
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
580 memset(flags, '-', 15);
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
581
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
582 int type_width = 0;
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
583 char *type = res->contenttype;
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
584
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
585 if(res->iscollection) {
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
586 flags[0] = 'd';
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
587 type = "";
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
588 }
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 330
diff changeset
589 char *keyprop = dav_get_string_property_ns(
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
590 res,
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
591 DAV_NS,
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
592 "crypto-key");
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
593 if(keyprop) {
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
594 flags[1] = 'c';
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
595 }
213
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
596
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
597 if(cmd_getoption(a, "extended")) {
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
598 flags[6] = '\0';
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 330
diff changeset
599 if(dav_get_string_property(res, "D:lockdiscovery")) {
213
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
600 flags[2] = 'l';
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
601 }
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 330
diff changeset
602 char *executable = dav_get_string_property_ns(
213
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
603 res,
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
604 "http://apache.org/dav/props/",
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
605 "executable");
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
606 if(executable && util_getboolean(executable)) {
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
607 flags[3] = 'x';
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
608 }
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
609 } else {
cd870d5f8659 added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
610 flags[2] = '\0';
211
3d12817414e9 dav list indicates locks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 210
diff changeset
611 }
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
612
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
613 if(cmd_getoption(a, "type")) {
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
614 type_width = 20;
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
615 }
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
616 if(type == NULL || type_width == 0) {
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
617 type = "";
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
618 }
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
619
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
620 char *date = ls_date_str(res->lastmodified);
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
621 char *size = ls_size_str(res);
270
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
622 int namelen = strlen(res->name);
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
623 char *name = recursive ? ls_name(parent, res->path, &namelen) : res->name;
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
624
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
625 //char *name = recursive ? res->path+1 : res->name;
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
626 printf(
270
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
627 "%s %*s %10s %12s %.*s\n",
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
628 flags,
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
629 type_width, type,
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
630 size,
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
631 date,
270
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
632 namelen,
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
633 name);
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
634 free(date);
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
635 free(size);
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
636
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
637 if(recursive) {
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
638 DavResource *child = res->children;
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
639 while(child) {
138
6a3248e22d58 -a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
640 //ls_print_list_elm(child, a);
6a3248e22d58 -a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
641 if(child->name[0] != '.' || show_all) {
270
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
642 ls_print_list_elm(child, parent, a);
138
6a3248e22d58 -a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
643 }
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
644 child = child->next;
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
645 }
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
646 }
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
647 }
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
648
270
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
649 void ls_print_elm(DavResource *res, char *parent, CmdArgs *a) {
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
650 int recursive = cmd_getoption(a, "recursive") ? 1 : 0;
138
6a3248e22d58 -a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
651 int show_all = cmd_getoption(a, "all") ? 1 : 0;
6a3248e22d58 -a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
652 if(res->name[0] == '.' && !show_all) {
6a3248e22d58 -a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
653 return;
6a3248e22d58 -a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
654 }
6a3248e22d58 -a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
655
270
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
656 int namelen = strlen(res->name);
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
657 char *name = recursive ? ls_name(parent, res->path, &namelen) : res->name;
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
658 printf("%.*s\n", namelen, name);
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
659 if(recursive) {
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
660 DavResource *child = res->children;
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
661 while(child) {
270
0edfb4c0e7f8 fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 264
diff changeset
662 ls_print_elm(child, parent, a);
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
663 child = child->next;
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
664 }
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
665 }
14
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
666 }
d1a43035d3a2 added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
667
333
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
668 static void free_getres(void *r) {
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
669 GetResource *getres = r;
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
670 free(getres->path);
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
671 free(getres);
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
672 }
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
673
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
674 int cmd_get(CmdArgs *a) {
35
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
675 if(a->argc != 1) {
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
676 // TODO: change this, when get supports retrieval of multiple files
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
677 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many");
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
678 fprintf(stderr, "Usage: dav %s\n", find_usage_str("get"));
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
679 return -1;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
680 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
681
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
682 char *url = a->argv[0];
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
683 char *path = NULL;
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
684 Repository *repo = url2repo(url, &path);
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
685 DavSession *sn = connect_to_repo(repo, a);
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
686
45
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
687 if(set_session_config(sn, a)) {
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
688 return -1;
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
689 }
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
690
355
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
691 char *progressfile = cmd_getoption(a, "progressfile");
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
692 Progress pdata;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
693 memset(&pdata, 0, sizeof(Progress));
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
694 if(progressfile) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
695 if(!strcmp(progressfile, "-")) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
696 pdata.out = stdout;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
697 pdata.isstdout = 1;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
698 } else {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
699 pdata.out = fopen(progressfile, "w");
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
700 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
701 if(pdata.out) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
702 dav_session_set_progresscallback(sn, download_progress, NULL, &pdata);
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
703 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
704 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
705
30
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
706 char *update = cmd_getoption(a, "update");
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 126
diff changeset
707 time_t t = -1;
30
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
708 if(update) {
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
709 t = util_parse_lastmodified(update);
329
2dc61cc5a8ac adds error message to dav, when an invalid date format is specified for the -u option
Mike Becker <universe@uap-core.de>
parents: 318
diff changeset
710 if (t == 0) {
2dc61cc5a8ac adds error message to dav, when an invalid date format is specified for the -u option
Mike Becker <universe@uap-core.de>
parents: 318
diff changeset
711 fprintf(stderr,
2dc61cc5a8ac adds error message to dav, when an invalid date format is specified for the -u option
Mike Becker <universe@uap-core.de>
parents: 318
diff changeset
712 "Invalid date format. Possible formats are:\n"
2dc61cc5a8ac adds error message to dav, when an invalid date format is specified for the -u option
Mike Becker <universe@uap-core.de>
parents: 318
diff changeset
713 " RFC-1123 - example: Thu, 29 Nov 2012 21:35:35 GMT\n"
2dc61cc5a8ac adds error message to dav, when an invalid date format is specified for the -u option
Mike Becker <universe@uap-core.de>
parents: 318
diff changeset
714 " RFC-3339 - example: 2012-11-29T21:35:35Z\n");
2dc61cc5a8ac adds error message to dav, when an invalid date format is specified for the -u option
Mike Becker <universe@uap-core.de>
parents: 318
diff changeset
715 return -1;
2dc61cc5a8ac adds error message to dav, when an invalid date format is specified for the -u option
Mike Becker <universe@uap-core.de>
parents: 318
diff changeset
716 }
30
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
717 }
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
718
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
719 int recursive = cmd_getoption(a, "recursive") ? 1 : 0;
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
720 DavResource *res;
30
9a5a7a513a96 added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
721
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
722 int depth = recursive ? -1 : 1;
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
723 res = dav_query(
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
724 sn,
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
725 "select - from %s with depth = %d where iscollection or lastmodified > %t",
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
726 path,
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
727 depth,
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
728 t);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
729 if(!res) {
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
730 print_resource_error(sn, path);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
731 return -1;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
732 }
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
733 if(!recursive && res->iscollection) {
235
0468df02e18f fixed dav get with -u option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 230
diff changeset
734 fprintf(stderr, "Resource %s is a collection.\n", res->path);
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
735 fprintf(stderr, "Use the -R option to download collections.\n");
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
736 return -1;
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
737 }
12
493128ef1b12 added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
738
493128ef1b12 added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
739 /*
493128ef1b12 added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
740 * determine the output file
493128ef1b12 added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
741 * use stdout if the output file is -
493128ef1b12 added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
742 */
493128ef1b12 added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
743 char *outfile = cmd_getoption(a, "output");
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
744 char *basepath = outfile;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
745 char *tar = cmd_getoption(a, "tar");
12
493128ef1b12 added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
746 if(!outfile) {
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
747 if(res->iscollection) {
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
748 basepath = "";
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
749 } else {
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
750 basepath = res->name;
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
751 }
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
752 if(tar) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
753 outfile = "-";
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
754 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
755 } else if(tar) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
756 basepath = "";
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
757 } else if(res->iscollection && !strcmp(outfile, "-")) {
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
758 fprintf(
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
759 stderr,
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
760 "Cannot write output to stdout "
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
761 "if the requested resource is a collection.\n");
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
762 return -1;
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
763 }
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
764
333
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
765 // get list of resources
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
766 UcxList *reslist = NULL;
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
767 uint64_t totalsize = 0;
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
768 uint64_t rescount = 0;
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
769
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
770 GetResource *getres = malloc(sizeof(GetResource));
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
771 getres->res = res;
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
772 getres->path = strdup(basepath);
333
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
773
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
774 char *structure = cmd_getoption(a, "structure");
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
775
333
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
776 // iterate over resource tree
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
777 UcxList *stack = ucx_list_prepend(NULL, getres);
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
778 while(stack) {
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
779 GetResource *g = stack->data;
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
780 stack = ucx_list_remove(stack, stack);
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
781
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
782 if(g->res->iscollection) {
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
783 DavResource *child = g->res->children;
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
784 while(child) {
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
785 // add resource to stack
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
786 size_t pathlen = strlen(g->path);
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
787 GetResource *newres = malloc(sizeof(GetResource));
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
788 newres->res = child;
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
789 newres->path = pathlen > 0 ?
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
790 util_concat_path(g->path, child->name) : strdup(child->name);
333
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
791
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
792 stack = ucx_list_prepend(stack, newres);
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
793
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
794 child = child->next;
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
795 }
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
796 } else {
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
797 if(structure) {
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
798 // download only directory structure
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
799 // this is a hidden feature and will be replaced in the future
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
800 continue; // skip non-collection resource
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
801 }
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
802 totalsize += g->res->contentlength;
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
803 rescount++;
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
804 }
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
805
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
806 if(strlen(g->path) == 0) {
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
807 free_getres(g);
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
808 } else {
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
809 reslist = ucx_list_append(reslist, g);
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
810 }
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
811 }
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
812
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
813 // download resources
355
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
814 pdata.total = totalsize;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
815
333
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
816 int ret;
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
817 getfunc get;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
818 TarOutputStream *tout = NULL;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
819 if(tar) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
820 get = (getfunc)resource2tar;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
821 FILE *tarfile = strcmp(outfile, "-") ? fopen(outfile, "wb") : stdout;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
822 if(!tarfile) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
823 perror("Cannot open tar output file");
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
824 return -1;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
825 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
826 tout = tar_open(tarfile);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
827 } else {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
828 get = get_resource;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
829 }
333
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
830 UCX_FOREACH(elm, reslist) {
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
831 GetResource *getres = elm->data;
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
832
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
833 ret = get(repo, getres, a, tout);
333
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
834 if(ret) {
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
835 break;
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
836 }
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
837 }
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
838 if(tar) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
839 // close tar stream
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
840 if(tar_close(tout)) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
841 fprintf(stderr, "tar stream broken\n");
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
842 ret = -1;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
843 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
844 }
333
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
845
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
846 ucx_list_free_content(reslist, free_getres);
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
847 ucx_list_free(reslist);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
848 free(path);
333
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
849
355
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
850 if(pdata.out && !pdata.isstdout) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
851 fclose(pdata.out);
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
852 }
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
853 return ret;
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
854 }
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
855
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
856 int get_resource(Repository *repo, GetResource *getres, CmdArgs *a, void *unused) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
857 DavResource *res = getres->res;
350
5fc457fb2cb1 fixes wrong output path in dav get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
858 char *out = getres->path;
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
859
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
860 if(res->iscollection) {
309
8a474d2ad209 adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 305
diff changeset
861 printf("get: %s\n", res->path);
8a474d2ad209 adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 305
diff changeset
862
333
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
863 mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
864 int ret = util_mkdir(out, mode);
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
865 if(ret != 0 && errno != EEXIST) {
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
866 fprintf(stderr, "Cannot create directory '%s': ", out);
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
867 perror("");
000cdd124115 refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 332
diff changeset
868 return 1;
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
869 }
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
870
309
8a474d2ad209 adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 305
diff changeset
871 return 0;
8a474d2ad209 adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 305
diff changeset
872 }
8a474d2ad209 adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 305
diff changeset
873
330
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
874 int isstdout = !strcmp(out, "-");
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
875 if(cmd_getoption(a, "keep") && !isstdout) {
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
876 struct stat s;
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
877 if(stat(out, &s)) {
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
878 if(errno != ENOENT) {
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
879 perror("stat");
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
880 }
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
881 } else {
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
882 if(cmd_getoption(a, "recursive")) {
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
883 printf("skip: %s\n", res->path);
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
884 }
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
885 return 0;
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
886 }
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
887 }
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
888
309
8a474d2ad209 adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 305
diff changeset
889 // print some status message in recursive mode
8a474d2ad209 adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 305
diff changeset
890 if(cmd_getoption(a, "recursive")) {
8a474d2ad209 adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 305
diff changeset
891 printf("get: %s\n", res->path);
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
892 }
330
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
893
54819e984a19 adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 329
diff changeset
894 FILE *fout = isstdout ? stdout : fopen(out, "wb");
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
895 if(!fout) {
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
896 fprintf(stderr, "cannot open output file\n");
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
897 return -1;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
898 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
899
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
900 int ret = dav_get_content(res, fout, (dav_write_func)fwrite);
18
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
901 fclose(fout);
651989681053 recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
902 if(ret && strcmp(out, "-")) {
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 204
diff changeset
903 print_resource_error(res->session, res->path);
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 204
diff changeset
904 //if(strcmp(out, "-")) {
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 204
diff changeset
905 // unlink(out);
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 204
diff changeset
906 //}
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
907 }
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
908
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
909 return 0;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
910 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
911
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
912 #define DEFAULT_DIR_MODE T_IRUSR | T_IWUSR | T_IXUSR | T_IRGRP | T_IXGRP | T_IROTH | T_IXOTH
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
913 #define DEFAULT_FILE_MODE T_IRUSR | T_IWUSR | T_IRGRP | T_IROTH
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
914
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
915 int resource2tar(Repository *repo, GetResource *res, CmdArgs *a, TarOutputStream *tar) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
916 DavResource *d = res->res;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
917
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
918 if(d->iscollection) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
919 fprintf(stderr, "add d: %s\n", res->path);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
920 return tar_add_dir(tar, res->path, DEFAULT_DIR_MODE, d->lastmodified);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
921 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
922
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
923 fprintf(stderr, "add f: %s\n", res->path);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
924
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
925 // add tar file header
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
926 if(tar_begin_file(tar, res->path, DEFAULT_FILE_MODE, d->contentlength, d->lastmodified)) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
927 fprintf(stderr, "TAR Error: %s\n", tar_error2str(tar->error));
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
928 return -1;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
929 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
930
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
931 if(dav_get_content(d, tar, (dav_write_func)tar_fwrite)) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
932 print_resource_error(d->session, d->path);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
933 return -1;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
934 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
935
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
936 // download content
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
937
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
938 return tar_end_file(tar);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
939 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
940
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
941 int cmd_put(CmdArgs *a) {
35
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
942 if(a->argc != 2) {
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
943 // TODO: change, when put supports multiple files (however it should do)
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
944 fprintf(stderr, "Too %s arguments\n", a->argc < 2 ? "few":"many");
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
945 fprintf(stderr, "Usage: dav %s\n", find_usage_str("put"));
4
ae5a98f0545c added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
946 return -1;
3
323689ada09d disabled ssl cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
947 }
323689ada09d disabled ssl cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
948
11
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
949 char *url = a->argv[0];
5db6178d8b58 added usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
950 char *file = a->argv[1];
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
951 char *path = NULL;
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
952 Repository *repo = url2repo(url, &path);
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
953 DavSession *sn = connect_to_repo(repo, a);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
954
45
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
955 if(set_session_config(sn, a)) {
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
956 return -1;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
957 }
210
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
958 set_session_lock(sn, a);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
959
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
960 // override the session key if the -k option is specified
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
961 char *keyname = cmd_getoption(a, "key");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
962 if(keyname) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
963 DavKey *key = dav_context_get_key(ctx, keyname);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
964 if(key) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
965 sn->key = key;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
966 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
967 fprintf(stderr, "Key %s not found!\nAbort.\n", keyname);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
968 // TODO: free
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
969 return -1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
970 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
971 }
352
76bd29a11cc9 fixes a segfault when full encryption is requested during a put without specifying the key
Mike Becker <universe@uap-core.de>
parents: 350
diff changeset
972
76bd29a11cc9 fixes a segfault when full encryption is requested during a put without specifying the key
Mike Becker <universe@uap-core.de>
parents: 350
diff changeset
973 // if encryption is requested, but we still don't know the key, abort
76bd29a11cc9 fixes a segfault when full encryption is requested during a put without specifying the key
Mike Becker <universe@uap-core.de>
parents: 350
diff changeset
974 if (DAV_IS_ENCRYPTED(sn) && !(sn->key)) {
76bd29a11cc9 fixes a segfault when full encryption is requested during a put without specifying the key
Mike Becker <universe@uap-core.de>
parents: 350
diff changeset
975 fprintf(stderr, "Encryption has been requested, "
76bd29a11cc9 fixes a segfault when full encryption is requested during a put without specifying the key
Mike Becker <universe@uap-core.de>
parents: 350
diff changeset
976 "but no default key is configured.\n"
76bd29a11cc9 fixes a segfault when full encryption is requested during a put without specifying the key
Mike Becker <universe@uap-core.de>
parents: 350
diff changeset
977 "You may specify a custom key with the '-k' option.\n");
76bd29a11cc9 fixes a segfault when full encryption is requested during a put without specifying the key
Mike Becker <universe@uap-core.de>
parents: 350
diff changeset
978 return -1;
76bd29a11cc9 fixes a segfault when full encryption is requested during a put without specifying the key
Mike Becker <universe@uap-core.de>
parents: 350
diff changeset
979 }
4
ae5a98f0545c added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
980
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
981 char *tar = cmd_getoption(a, "tar");
352
76bd29a11cc9 fixes a segfault when full encryption is requested during a put without specifying the key
Mike Becker <universe@uap-core.de>
parents: 350
diff changeset
982
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
983 int ret;
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
984 if(!tar) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
985 if(!strcmp(file, "-")) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
986 FILE *in = stdin;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
987 ret = put_file(repo, a, sn, path, "stdin", in, 0);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
988 } else {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
989 ret = put_entry(repo, a, sn, path, file, TRUE);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
990 }
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
991 } else {
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
992 ret = put_tar(repo, a, sn, file, path);
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
993 }
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
994
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
995 free(path);
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
996 return ret;
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
997 }
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
998
241
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
999 int put_entry(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *file, DavBool root) {
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1000 int recursive = cmd_getoption(a, "recursive") ? 1 : 0;
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1001 struct stat s;
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1002 if(stat(file, &s)) {
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1003 perror("stat");
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1004 fprintf(stderr, "cannot stat file %s\n", file);
12
493128ef1b12 added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
1005 return -1;
493128ef1b12 added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
1006 }
493128ef1b12 added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
1007
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1008 int ret = 0;
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1009 if(S_ISDIR(s.st_mode)) {
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1010 if(!recursive) {
241
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1011 fprintf(
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1012 stderr,
318
7e0694423838 dav-sync bugfix: files that are not in the db but on the server should not be pushed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
1013 "%s is a directory.\nUse the -R option to upload directories.\n",
241
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1014 file);
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1015 return 1;
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1016 }
271
7b1ca53f3897 fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
1017
7b1ca53f3897 fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
1018 if(!root) {
7b1ca53f3897 fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
1019 printf("mkcol: %s\n", file);
7b1ca53f3897 fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
1020 }
7b1ca53f3897 fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
1021
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1022 DIR *dir = opendir(file);
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1023 if(!dir) {
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1024 // error
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1025 }
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1026 struct dirent *entry;
241
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1027 int nument = 0;
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1028 while((entry = readdir(dir)) != NULL) {
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1029 if(!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) {
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1030 continue;
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1031 }
241
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1032 nument++;
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1033 char *entry_file = util_concat_path(file, entry->d_name);
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1034 char *entry_path = util_concat_path(path, entry->d_name);
241
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1035 int r = put_entry(repo, a, sn, entry_path, entry_file, FALSE);
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1036 free(entry_path);
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1037 free(entry_file);
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1038 if(r) {
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1039 ret = 1;
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1040 break;
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1041 }
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1042 }
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1043 closedir(dir);
241
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1044
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1045 if(nument == 0) {
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1046 // create empty directory
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1047 DavResource *res = dav_resource_new(sn, path);
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1048 res->iscollection = TRUE;
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1049 if(!dav_exists(res)) {
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1050 if(dav_create(res)) {
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1051 fprintf(stderr, "Cannot create collection %s\n", path);
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1052 print_resource_error(sn, res->path);
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1053 ret = 1;
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1054 }
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1055 }
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1056 dav_resource_free(res);
da7ace67deab improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 236
diff changeset
1057 }
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1058 } else if(S_ISREG(s.st_mode)) {
271
7b1ca53f3897 fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
1059 if(recursive) {
7b1ca53f3897 fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
1060 printf("put: %s\n", file);
7b1ca53f3897 fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
1061 }
7b1ca53f3897 fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
1062
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1063 /*
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1064 * use stdin if the input file is -
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1065 */
72
aac29f2e8030 dav now opens files in binary mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
1066 FILE *in = fopen(file, "rb");
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1067 if(!in) {
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1068 fprintf(stderr, "cannot open input file\n");
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1069 return -1;
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1070 }
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1071 char *filename = util_resource_name(file);
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1072 //path = util_concat_path(path, filename);
178
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
1073 ret = put_file(repo, a, sn, path, filename, in, s.st_size);
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 32
diff changeset
1074 //free(path);
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1075 fclose(in);
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1076 }
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1077
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1078 return ret;
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1079 }
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1080
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1081 int put_tar(Repository *repo, CmdArgs *a, DavSession *sn, char *tarfile, char *path) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1082 int isstdin = !strcmp(tarfile, "-");
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1083 FILE *in = isstdin ? stdin : fopen(tarfile, "rb");
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1084 if(!in) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1085 perror("Cannot open tar file");
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1086 return -1;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1087 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1088
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1089 DavResource *col = dav_query(sn, "select - from %s", path);
334
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1090 if(!col) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1091 if(sn->error == DAV_NOT_FOUND) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1092 col = dav_resource_new(sn, path);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1093 col->iscollection = TRUE;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1094 if(dav_create(col)) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1095 print_resource_error(sn, path);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1096 return -1;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1097 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1098 } else {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1099 print_resource_error(sn, path);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1100 return -1;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1101 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1102 } else if(!col->iscollection) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1103 fprintf(stderr, "%s is not a collection\n", col->href);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1104 return -1;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1105 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1106
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1107
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1108 int ret = 0;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1109 TarInputStream *tar = tar_inputstream_open(in);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1110 TarEntry *e = NULL;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1111 while((e = tar_read_entry(tar)) != NULL) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1112 char *newpath = util_concat_path(path, e->path);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1113 if(e->type == TAR_TYPE_FILE) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1114 fprintf(stderr, "put: %s\n", e->path);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1115 DavResource *res = dav_resource_new(sn, newpath);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1116 dav_set_content(res, tar, (dav_read_func)tar_fread);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1117 dav_set_content_length(res, (size_t)e->size);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1118
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1119 if(dav_store(res)) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1120 print_resource_error(sn, res->path);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1121 fprintf(stderr, "Cannot upload file.\n");
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1122 if(sn->errorstr) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1123 fprintf(stderr, "%s\n", sn->errorstr);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1124 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1125 return -1;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1126 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1127
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1128 } else if(e->type == TAR_TYPE_DIRECTORY) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1129 printf("mkcol: %s\n", e->path);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1130 DavResource *res = dav_resource_new(sn, newpath);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1131 res->iscollection = TRUE;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1132 if(!dav_exists(res)) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1133 if(dav_create(res)) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1134 fprintf(stderr, "Cannot create collection %s\n", newpath);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1135 print_resource_error(sn, res->path);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1136 ret = 1;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1137 free(newpath);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1138 break;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1139 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1140 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1141 } else {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1142 fprintf(stderr, "skip: %s\n", e->path);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1143 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1144 free(newpath);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1145 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1146 if(tar->error != TAR_OK) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1147 ret = -1;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1148 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1149
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1150 if(!isstdin) {
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1151 fclose(in);
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1152 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1153
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1154 return ret;
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1155 }
5f80c5d0e87f adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 333
diff changeset
1156
178
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
1157 int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len) {
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1158 DavResource *res = dav_query(sn, "select - from %s", path);
201
8e5856182668 auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
1159
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
1160 if(!res) {
24
a317202ae787 implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
1161 if(sn->error == DAV_NOT_FOUND) {
21
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
1162 res = dav_resource_new(sn, path);
24
a317202ae787 implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
1163 if(dav_create(res)) {
a317202ae787 implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
1164 fprintf(stderr, "Cannot create resource.\n");
a317202ae787 implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
1165 return -1;
a317202ae787 implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
1166 }
21
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
1167 } else {
198
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
1168 print_resource_error(sn, path);
21
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
1169 return -1;
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
1170 }
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
1171 } else if(res->iscollection) {
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
1172 // TODO: free res
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1173 char *newpath = util_concat_path(path, name);
353
e554f3d72d9e fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents: 352
diff changeset
1174
e554f3d72d9e fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents: 352
diff changeset
1175 if (!strcmp(path, newpath)) {
e554f3d72d9e fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents: 352
diff changeset
1176 // TODO: free res
e554f3d72d9e fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents: 352
diff changeset
1177 fprintf(stderr, "Cannot put file, because a collection with "
e554f3d72d9e fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents: 352
diff changeset
1178 "that name already exists.\n");
e554f3d72d9e fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents: 352
diff changeset
1179 free(newpath);
e554f3d72d9e fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents: 352
diff changeset
1180 return -1;
e554f3d72d9e fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents: 352
diff changeset
1181 }
e554f3d72d9e fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents: 352
diff changeset
1182
21
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
1183 path = newpath;
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
1184 res = dav_resource_new(sn, path);
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
1185 free(newpath);
178
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
1186 int ret = put_file(repo, a, sn, res->path, NULL, in, len);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1187 // TODO: free res
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1188 return ret;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
1189 }
12
493128ef1b12 added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
1190
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1191 dav_set_content(res, in, (dav_read_func)fread);
180
5b58389ab9dd fixed large file support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
1192 if(len > 0 && len < 0x7d000000) {
179
802b48ae791d enable sharepoint put fix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 178
diff changeset
1193 dav_set_content_length(res, (size_t)len);
178
e137883e620f using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
1194 }
4
ae5a98f0545c added put method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
1195
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
1196 if(dav_store(res)) {
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1197 print_resource_error(sn, res->path);
13
8a0cc4d90de7 added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
1198 fprintf(stderr, "Cannot upload file.\n");
22
e593f7e41be0 added more error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
1199 if(sn->errorstr) {
e593f7e41be0 added more error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
1200 fprintf(stderr, "%s\n", sn->errorstr);
e593f7e41be0 added more error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
1201 }
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
1202 return -1;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
1203 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
1204 return 0;
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1205 }
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1206
28
4e46c65711ef added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
1207
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1208 int cmd_remove(CmdArgs *a) {
35
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
1209 if(a->argc != 1) {
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
1210 // TODO: change, when removal of multiple files is supported
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
1211 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many");
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1212 fprintf(stderr, "Usage: dav %s\n", find_usage_str("remove"));
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1213 return -1;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1214 }
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1215
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1216 char *url = a->argv[0];
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1217 char *path = NULL;
201
8e5856182668 auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
1218 Repository *repo = url2repo(url, &path);
8e5856182668 auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
1219 DavSession *sn = connect_to_repo(repo, a);
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1220
45
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
1221 if(set_session_config(sn, a)) {
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
1222 return -1;
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
1223 }
210
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
1224 set_session_lock(sn, a);
45
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
1225
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1226 DavResource *res = dav_resource_new(sn, path);
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1227 if(!res) {
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1228 fprintf(stderr, "error\n");
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1229 return -1;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1230 }
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1231
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1232 if(dav_delete(res)) {
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1233 print_resource_error(sn, res->path);
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1234 fprintf(stderr, "Cannot delete resource.\n");
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1235 return -1;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1236 }
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1237
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
1238 free(path);
15
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1239 return 0;
182af08b4813 added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
1240 }
16
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1241
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1242 int cmd_mkdir(CmdArgs *a) {
35
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
1243 if(a->argc != 1) {
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
1244 // TODO: change, when creation of multiple dirs is supported
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
1245 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many");
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1246 fprintf(stderr, "Usage: dav %s\n", find_usage_str("mkdir"));
16
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1247 return -1;
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1248 }
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1249
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1250 char *url = a->argv[0];
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1251 char *path = NULL;
201
8e5856182668 auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
1252 Repository *repo = url2repo(url, &path);
8e5856182668 auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
1253 DavSession *sn = connect_to_repo(repo, a);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1254
45
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
1255 if(set_session_config(sn, a)) {
e3839719b079 added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
1256 return -1;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1257 }
210
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
1258 set_session_lock(sn, a);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1259
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1260 // override the session key if the -k option is specified
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1261 char *keyname = cmd_getoption(a, "key");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1262 if(keyname) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1263 DavKey *key = dav_context_get_key(ctx, keyname);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1264 if(key) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1265 sn->key = key;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1266 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1267 fprintf(stderr, "Key %s not found!\nAbort.\n", keyname);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1268 // TODO: free
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1269 return -1;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1270 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1271 }
16
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1272
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1273 DavResource *res = dav_resource_new(sn, path);
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1274 if(!res) {
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1275 fprintf(stderr, "error\n");
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1276 return -1;
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1277 }
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1278 res->iscollection = 1;
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1279
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1280 if(dav_create(res)) {
16
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1281 print_resource_error(sn, res->path);
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1282 fprintf(stderr, "Cannot create collection.\n");
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1283 return -1;
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1284 }
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1285
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
1286 free(path);
16
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1287 return 0;
5dbef9e07376 added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
1288 }
29
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1289
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1290 int cmd_move(CmdArgs *a, int cp) {
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1291 if(a->argc != 2) {
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1292 // TODO: change, when creation of multiple dirs is supported
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1293 fprintf(stderr, "Too %s arguments\n", a->argc < 2 ? "few":"many");
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1294 fprintf(stderr, "Usage: dav %s\n", find_usage_str(cp ? "copy" : "move"));
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1295 return -1;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1296 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1297
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1298 char *url1 = a->argv[0];
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1299 char *path1 = NULL;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1300 Repository *repo1 = url2repo(url1, &path1);
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1301
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1302 char *url2 = a->argv[1];
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1303 char *path2 = NULL;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1304 Repository *repo2 = url2repo(url2, &path2);
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1305
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
1306 DavSession *sn = connect_to_repo(repo1, a);
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1307 if(set_session_config(sn, a)) {
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1308 return -1;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1309 }
236
6b4ce32d0c4e copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
1310 set_session_lock(sn, a);
210
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
1311
182
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
1312 DavBool override = cmd_getoption(a, "override") ? true : false;
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
1313
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1314 if(repo1 == repo2) {
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1315 DavResource *res = dav_resource_new(sn, path1);
182
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
1316 int err = cp ? dav_copy_o(res, path2, override)
ca07f14f7bfe added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
1317 : dav_move_o(res, path2, override);
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1318 if(err) {
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1319 print_resource_error(sn, res->path);
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1320 fprintf(stderr, "Cannot %s resource.\n", cp ? "copy" : "move");
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1321 return -1;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1322 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1323 } else {
186
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1324 char *server1 = util_url_base(repo1->url);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1325 char *server2 = util_url_base(repo2->url);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1326 if(!strcmp(server1, server2)) {
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
1327 DavSession *sn2 = connect_to_repo(repo2, a);
186
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1328 if(set_session_config(sn2, a)) {
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1329 return -1;
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1330 }
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1331 DavResource *dest = dav_resource_new(sn2, path2);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1332 char *desthref = dav_resource_get_href(dest);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1333 char *desturl = util_get_url(sn2, desthref);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1334
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1335 DavResource *res = dav_resource_new(sn, path1);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1336 int err = cp ? dav_copyto(res, desturl, override)
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1337 : dav_moveto(res, desturl, override);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1338
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1339 free(desturl);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1340 dav_session_destroy(sn2);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1341
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1342 if(err) {
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1343 print_resource_error(sn, res->path);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1344 fprintf(stderr, "Cannot %s resource.\n", cp ? "copy" : "move");
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1345 return -1;
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1346 }
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1347 } else {
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1348 fprintf(stderr, "Copy or Move not supported for different hosts.\n");
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1349 return -1;
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1350 }
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1351 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1352
186
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1353 dav_session_destroy(sn);
05d11fbcaeb3 improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1354
181
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1355 return 0;
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1356 }
a8f8cdbf85df implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
1357
29
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1358
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1359 static size_t get_date_header_cb(void *header, int s, int n, void *data) {
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1360 char **date_str = (char**)data;
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1361
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1362 //printf("header: %.*s\n", s*n, header);
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1363 sstr_t h = sstrn(header, s*n);
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1364 if(sstrprefix(h, S("Date:"))) {
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1365 sstr_t v = sstrsubs(h, 5);
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1366 v = sstrdup(sstrtrim(v));
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1367 *date_str = v.ptr;
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1368 }
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1369 return s*n;
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1370 }
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1371
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1372 int cmd_date(CmdArgs *a) {
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1373 if(a->argc < 1) {
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1374 time_t now = time(NULL);
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1375 struct tm *date = gmtime(&now);
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1376 char str[32];
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1377 putenv("LC_TIME=C");
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1378 size_t len = strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT\n", date);
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1379 fwrite(str, 1, len, stdout);
35
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
1380 } else if (a->argc == 1) {
29
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1381 char *url = a->argv[0];
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1382 char *path = NULL;
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
1383 DavSession *sn = connect_to_repo(url2repo(url, &path), a);
29
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1384
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1385 DavResource *res = dav_resource_new(sn, path);
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1386 char *date = NULL;
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1387 curl_easy_setopt(sn->handle, CURLOPT_HEADERFUNCTION, get_date_header_cb);
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1388 curl_easy_setopt(sn->handle, CURLOPT_WRITEHEADER, &date);
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1389 if(dav_exists(res) && date) {
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1390 printf("%s\n", date);
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1391 } else {
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1392 return -1;
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1393 }
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
1394 free(path);
35
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
1395 return 0;
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
1396 } else {
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
1397 fprintf(stderr, "Too many arguments\n");
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1398 fprintf(stderr, "Usage: dav %s\n", find_usage_str("date"));
35
ad0c9dacd7e3 errors on too many arguments
Mike Becker <universe@uap-core.de>
parents: 34
diff changeset
1399 return -1;
29
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1400 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
1401 return 0;
29
938957a4eea7 added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
1402 }
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 32
diff changeset
1403
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1404 int cmd_get_property(CmdArgs *a) {
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 32
diff changeset
1405 if(a->argc < 2) {
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 32
diff changeset
1406 fprintf(stderr, "Too few arguments\n");
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1407 fprintf(stderr, "Usage: dav %s\n", find_usage_str("get-property"));
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 32
diff changeset
1408 return -1;
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 32
diff changeset
1409 }
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 32
diff changeset
1410
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1411 char *url = a->argv[0];
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1412 char *path = NULL;
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1413 Repository *repo = url2repo(url, &path);
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1414 DavSession *sn = connect_to_repo(repo, a);
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1415
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1416 if(set_session_config(sn, a)) {
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1417 return -1;
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1418 }
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1419
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1420 char *namespace = cmd_getoption(a, "namespace");
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1421 char *property = a->argv[1];
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1422
298
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 297
diff changeset
1423 DavPropName propname;
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 297
diff changeset
1424 if(namespace) {
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 297
diff changeset
1425 propname.ns = namespace;
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 297
diff changeset
1426 propname.name = property;
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 297
diff changeset
1427 } else {
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 297
diff changeset
1428 dav_get_property_namespace_str(ctx, property, &propname.ns, &propname.name);
317
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 316
diff changeset
1429 if(!propname.ns || !propname.name) {
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 316
diff changeset
1430 fprintf(stderr, "Error: unknown namespace prefix\n");
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 316
diff changeset
1431 return -1;
7eea57f6d847 adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 316
diff changeset
1432 }
298
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 297
diff changeset
1433 }
755b8198b071 dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 297
diff changeset
1434
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1435 DavResource *res = dav_resource_new(sn, path);
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1436 if(dav_load_prop(res, &propname, 1)) {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1437 print_resource_error(sn, res->path);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1438 return -1;
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1439 }
338
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1440 free(path);
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1441
338
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1442 DavXmlNode *x = dav_get_property_ns(res, propname.ns, propname.name);
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1443 if(!x) {
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1444 fprintf(stderr, "Error: no property value.\n");
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1445 return -1;
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1446 }
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1447
338
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1448 if(cmd_getoption(a, "xml")) {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1449 // print a real xml document on stdout
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1450 printxmldoc(stdout, propname.name, propname.ns, x);
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1451 } else {
338
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1452 // in this mode a simple string is printed on stdout
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1453 // or simplified and nicely formatted xml is printed on stderr
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1454 if(dav_xml_isstring(x)) {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1455 printf("%s\n", dav_xml_getstring(x));
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1456 } else {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1457 char *str = xml2str(x);
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1458 fprintf(stderr, "%s", str);
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1459 free(str);
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1460 }
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1461 }
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1462
338
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1463 return 0;
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1464 }
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1465
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1466 int cmd_set_property(CmdArgs *a) {
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1467 if(a->argc < 2) {
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1468 fprintf(stderr, "Too few arguments\n");
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1469 fprintf(stderr, "Usage: dav %s\n", find_usage_str("set-property"));
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1470 return -1;
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1471 }
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1472
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1473 char *url = a->argv[0];
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1474 char *path = NULL;
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1475 Repository *repo = url2repo(url, &path);
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1476 DavSession *sn = connect_to_repo(repo, a);
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1477
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1478 if(set_session_config(sn, a)) {
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1479 return -1;
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1480 }
210
1d19e0ff18d9 added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
1481 set_session_lock(sn, a);
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1482
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1483 DavResource *res = dav_resource_new(sn, path);
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1484 if(!dav_exists(res)) {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1485 print_resource_error(sn, res->path);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1486 return -1;
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1487 }
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1488
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1489 char *namespace = cmd_getoption(a, "namespace");
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1490 char *xml = cmd_getoption(a, "xml");
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1491
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1492 char *property = a->argv[1];
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1493 char *value = a->argc > 2 ? a->argv[2] : stdin2str();
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1494
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1495 int ret = 0;
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1496 if(xml) {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1497 DavXmlNode *xmlvalue = dav_parse_xml(sn, value, strlen(value));
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1498 if(xmlvalue) {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1499 if(namespace) {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1500 dav_set_property_ns(res, namespace, property, xmlvalue->children);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1501 } else {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1502 dav_set_property(res, property, xmlvalue->children);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1503 }
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1504 } else {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1505 fprintf(stderr, "Error: property content is not valid xml\n");
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1506 ret = 1;
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1507 }
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1508 } else {
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1509 if(namespace) {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1510 dav_set_string_property_ns(res, namespace, property, value);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1511 } else {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1512 dav_set_string_property(res, property, value);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1513 }
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1514 }
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1515
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1516 if(ret == 0) {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1517 if(dav_store(res)) {
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1518 print_resource_error(sn, res->path);
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1519 fprintf(stderr, "Cannot set property.\n");
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1520 ret = -1;
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1521 }
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1522 } else
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1523
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
1524 free(path);
371
604e7e335b3b adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 364
diff changeset
1525 dav_session_destroy(sn);
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1526 return ret;
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 32
diff changeset
1527 }
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1528
304
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1529 int cmd_remove_property(CmdArgs *a) {
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1530 if(a->argc < 2) {
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1531 fprintf(stderr, "Too few arguments\n");
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1532 fprintf(stderr, "Usage: dav %s\n", find_usage_str("remove-property"));
304
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1533 return -1;
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1534 }
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1535
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1536 char *url = a->argv[0];
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1537 char *path = NULL;
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1538 Repository *repo = url2repo(url, &path);
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1539 DavSession *sn = connect_to_repo(repo, a);
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1540
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1541 if(set_session_config(sn, a)) {
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1542 return -1;
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1543 }
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1544
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1545 char *namespace = cmd_getoption(a, "namespace");
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1546 char *property = a->argv[1];
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1547
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1548 DavPropName propname;
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1549 if(namespace) {
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1550 propname.ns = namespace;
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1551 propname.name = property;
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1552 } else {
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1553 dav_get_property_namespace_str(ctx, property, &propname.ns, &propname.name);
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1554 }
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1555
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1556 int ret = 0;
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1557 DavResource *res = dav_resource_new(sn, path);
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1558 dav_remove_property_ns(res, propname.ns, propname.name);
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1559
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1560 if(dav_store(res)) {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1561 print_resource_error(sn, res->path);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1562 fprintf(stderr, "Cannot set property.\n");
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1563 ret = -1;
304
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1564 }
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1565
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1566 free(path);
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1567 return ret;
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1568 }
a4d3ff32d49c adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
1569
209
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1570 int cmd_lock(CmdArgs *a) {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1571 if(a->argc != 1) {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1572 fprintf(stderr, "Too %s arguments\n", a->argc > 1 ? "many" : "few");
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1573 fprintf(stderr, "Usage: dav %s\n", find_usage_str("lock"));
209
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1574 return -1;
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1575 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1576
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1577 char *url = a->argv[0];
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1578 char *path = NULL;
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1579 Repository *repo = url2repo(url, &path);
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1580 DavSession *sn = connect_to_repo(repo, a);
230
fdcbde1d7d65 fixed memory leaks in lock and unlock commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
1581 ucx_mempool_reg_destr(sn->mp, path, free);
209
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1582
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1583 if(set_session_config(sn, a)) {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1584 return -1;
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1585 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1586
315
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
1587 time_t timeout = 0;
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
1588 char *timeoutstr = cmd_getoption(a, "timeout");
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
1589 if(timeoutstr) {
316
9d0505d80044 adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
1590 if(!sstrcasecmp(sstr(timeoutstr), S("infinite"))) {
315
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
1591 timeout = -1;
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
1592 } else {
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
1593 timeout = (time_t)atoi(timeoutstr); // TODO: use strtol
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
1594 }
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
1595 }
7db4dbf4e6f9 adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
1596
209
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1597 DavResource *res = dav_resource_new(sn, path);
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1598 if(dav_lock_t(res, timeout)) {
264
94c0a938b66c fixes error detection loop in dav lock/unlock/get-property/set-property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 258
diff changeset
1599 print_resource_error(sn, res->path);
94c0a938b66c fixes error detection loop in dav lock/unlock/get-property/set-property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 258
diff changeset
1600 return -1;
209
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1601 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1602
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1603 DavLock *lock = dav_get_lock(sn, res->path);
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1604 if(!lock) {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1605 // this should really not happen
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1606 // do some damage control
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1607 dav_unlock(res);
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1608 fprintf(stderr, "Error: Cannot find lock token for %s\n", res->path);
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1609 return -1;
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1610 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1611
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1612 printf("%s\n", lock->token);
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1613
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1614 dav_session_destroy(sn);
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1615 return 0;
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1616 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1617
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1618 static char* read_line() {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1619 UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND);
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1620 int c;
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1621 while((c = getchar()) != EOF) {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1622 if(c == '\n') {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1623 break;
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1624 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1625 ucx_buffer_putc(buf, c);
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1626 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1627 char *str = NULL;
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1628 sstr_t line = sstrtrim(sstrn(buf->space, buf->size));
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1629 if(line.length != 0) {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1630 str = sstrdup(line).ptr;
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1631 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1632 ucx_buffer_free(buf);
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1633 return str;
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1634 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1635
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1636 int cmd_unlock(CmdArgs *a) {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1637 if(a->argc != 1) {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1638 fprintf(stderr, "Too %s arguments\n", a->argc > 1 ? "many" : "few");
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1639 fprintf(stderr, "Usage: dav %s\n", find_usage_str("unlock"));
209
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1640 return -1;
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1641 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1642
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1643 char *url = a->argv[0];
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1644 char *path = NULL;
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1645 Repository *repo = url2repo(url, &path);
209
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1646 DavSession *sn = connect_to_repo(url2repo(url, &path), a);
230
fdcbde1d7d65 fixed memory leaks in lock and unlock commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
1647 ucx_mempool_reg_destr(sn->mp, path, free);
209
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1648 if(set_session_config(sn, a)) {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1649 return -1;
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1650 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1651
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1652 char *locktoken = cmd_getoption(a, "lock");
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1653 if(locktoken) {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1654 DavLock *lock = dav_create_lock(sn, locktoken, NULL);
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1655 dav_add_collection_lock(sn, "/", lock);
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1656 } else {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1657 locktoken = read_line();
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1658 if(!locktoken) {
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1659 fprintf(stderr, "No lock token specified.\nAbort.\n");
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1660 return -1;
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1661 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1662 DavLock *lock = dav_create_lock(sn, locktoken, NULL);
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1663 dav_add_collection_lock(sn, "/", lock);
230
fdcbde1d7d65 fixed memory leaks in lock and unlock commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 229
diff changeset
1664 free(locktoken);
209
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1665 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1666
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1667 int ret = 0;
209
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1668 DavResource *res = dav_resource_new(sn, path);
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1669 if(dav_unlock(res)) {
264
94c0a938b66c fixes error detection loop in dav lock/unlock/get-property/set-property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 258
diff changeset
1670 print_resource_error(sn, res->path);
94c0a938b66c fixes error detection loop in dav lock/unlock/get-property/set-property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 258
diff changeset
1671 ret = -1;
209
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1672 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1673
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1674 dav_session_destroy(sn);
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1675 return ret;
209
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1676 }
d24761f1e07c added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
1677
84
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1678 static int count_children(DavResource *res) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1679 DavResource *child = res->children;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1680 int count = 0;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1681 while(child) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1682 count++;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1683 child = child->next;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1684 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1685 return count;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1686 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1687
373
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1688 void print_xml_infostr(DavXmlNode *xml) {
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1689 if(xml->children) {
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1690 printf("<%s>...</%s>", xml->name, xml->name);
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1691 } else {
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1692 printf("<%s/>", xml->name);
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1693 }
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1694 }
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1695
84
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1696 int cmd_info(CmdArgs *a) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1697 if(a->argc < 1) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1698 fprintf(stderr, "Too few arguments\n");
332
5587282ebe1c dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1699 fprintf(stderr, "Usage: dav %s\n", find_usage_str("info"));
84
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1700 return -1;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1701 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1702
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1703 char *url = a->argv[0];
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1704 char *path = NULL;
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1705 Repository *repo = url2repo(url, &path);
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1706 DavSession *sn = connect_to_repo(repo, a);
84
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1707
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1708 if(set_session_config(sn, a)) {
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1709 return -1;
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1710 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1711
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1712 DavResource *res = dav_resource_new(sn, path);
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1713 if(!dav_load(res)) {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1714 printf("name: %s\n", res->name);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1715 printf("path: %s\n", res->path);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1716
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1717 char *server = util_url_base(sn->base_url);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1718 char *url = util_concat_path(server, res->href);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1719 printf("url: %s\n", url);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1720 free(url);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1721 free(server);
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1722
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1723 if(res->iscollection) {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1724 printf("type: collection\n");
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1725 printf("size: %d\n", count_children(res));
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1726 } else {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1727 printf("type: resource\n");
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1728 char *len = ls_size_str(res);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1729 printf("size: %s\n", len);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1730 free(len);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1731 }
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1732
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1733 size_t count = 0;
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1734 DavPropName *properties = dav_get_property_names(res, &count);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1735
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1736 char *last_ns = NULL;
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1737 for(int i=0;i<count;i++) {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1738 DavPropName p = properties[i];
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1739 if(!last_ns || strcmp(last_ns, p.ns)) {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1740 printf("\nnamespace: %s\n", p.ns);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1741 last_ns = p.ns;
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1742 }
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1743
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1744 DavXmlNode *xval = dav_get_property_ns(res, p.ns, p.name);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1745 if(dav_xml_isstring(xval)) {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1746 sstr_t value = sstr(dav_xml_getstring(xval));
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1747 printf(" %s: %.*s\n", p.name, (int)value.length, value.ptr);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1748 } else {
373
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1749 // find some xml elements
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1750 printf(" %s: ", p.name);
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1751 DavXmlNode *x = xval->type == DAV_XML_ELEMENT ? xval : dav_xml_nextelm(xval);
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1752 for(int i=0;i<3;i++) {
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1753 if(x) {
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1754 if(i == 2) {
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1755 printf(" ...");
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1756 break;
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1757 } else {
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1758 print_xml_infostr(x);
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1759 }
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1760 } else {
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1761 break;
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1762 }
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1763 x = dav_xml_nextelm(x);
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1764 }
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1765 printf("\n");
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1766
dcc03142eb5f dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
1767
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1768 }
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1769 }
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1770
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1771 dav_session_free(sn, properties);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1772 return 0;
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1773 } else {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1774 print_resource_error(sn, res->path);
84
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1775 }
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 353
diff changeset
1776
258
571b62700df6 adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
1777 return -1;
84
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1778 }
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1779
7fca3788261d added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
1780
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1781 char* stdin2str() {
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1782 UcxBuffer *buf = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND);
256
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
1783 size_t size = ucx_stream_copy(stdin, buf, fread, ucx_buffer_write);
62
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1784 if(size == 0) {
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1785 ucx_buffer_free(buf);
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1786 return NULL;
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1787 } else {
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1788 ucx_buffer_putc(buf, '\0');
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1789 char *str = buf->space;
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1790 free(buf);
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1791 return str;
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1792 }
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1793 }
3b813c57c106 added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1794
338
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1795 static void xml2str_i(DavXmlNode *node, UcxBuffer *buf, int indent) {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1796 while(node) {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1797 if(node->type == DAV_XML_ELEMENT) {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1798 if(node->children) {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1799 if(dav_xml_isstring(node->children)) {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1800 sstr_t s = sstrtrim(sstr(dav_xml_getstring(node->children)));
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1801 ucx_bprintf(
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1802 buf,
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1803 "%*s<%s>%.*s</%s>\n",
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1804 indent,
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1805 "",
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1806 node->name,
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1807 (int)s.length,
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1808 s.ptr,
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1809 node->name);
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1810 } else {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1811 ucx_bprintf(buf, "%*s<%s>\n", indent, "", node->name);
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1812 xml2str_i(node->children, buf, indent+2);
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1813 ucx_bprintf(buf, "%*s</%s>\n", indent, "", node->name);
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1814 }
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1815 } else {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1816 ucx_bprintf(buf, "%*s<%s />", indent, "", node->name);
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1817 ucx_buffer_putc(buf, '\n');
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1818 }
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1819 } else if(node->type == DAV_XML_TEXT) {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1820 sstr_t val = sstrtrim(sstrn(node->content, node->contentlength));
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1821 if(val.length > 0) {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1822 ucx_bprintf(buf, "%*.*s", indent, (int)val.length, val.ptr);
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1823 }
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1824 }
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1825
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1826 node = node->next;
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1827 }
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1828 }
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1829
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1830 char* xml2str(DavXmlNode *node) {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1831 char *str = malloc(256);
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1832 UcxBuffer *buf = ucx_buffer_new(str, 256, UCX_BUFFER_AUTOEXTEND);
346
3e20fd78e555 fixes missing string terminator when printing simplified xml (dav get-property)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
1833 xml2str_i(node, buf, 0);
3e20fd78e555 fixes missing string terminator when printing simplified xml (dav get-property)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 338
diff changeset
1834 ucx_buffer_putc(buf, 0);
338
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1835 char *space = buf->space;
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1836 ucx_buffer_free(buf);
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1837 return space;
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1838 }
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1839
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1840 void printxmldoc(FILE *out, char *root, char *rootns, DavXmlNode *content) {
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1841 UcxMap *nsmap = ucx_map_new(16);
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1842
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1843 ucx_map_cstr_put(nsmap, rootns, "x0");
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1844 fprintf(out, "%s", "<?xml version=\"1.0\"?>\n");
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1845 fprintf(out, "<x0:%s xmlns:x0=\"%s\">", root, rootns);
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1846
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
1847 dav_print_node(out, (write_func)fwrite, nsmap, content);
338
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1848
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1849 fprintf(out, "</x0:%s>\n", root);
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
1850
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
1851 // cleanup namespace map
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
1852 ucx_map_cstr_remove(nsmap, rootns);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
1853 ucx_map_free_content(nsmap, free);
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
1854 ucx_map_free(nsmap);
338
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1855 }
c7f3fe4abdb2 dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 334
diff changeset
1856
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1857
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1858 /* ---------- config commands ---------- */
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1859
195
4b7823a58199 fixed add-repository function name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
1860 int cmd_add_repository(CmdArgs *args) {
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1861 printf("Each repository must have an unique name.\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1862 char *name = assistant_getcfg("name");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1863 if(!name) {
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1864 fprintf(stderr, "Abort\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1865 return -1;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1866 }
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1867 if(get_repository(sstr(name))) {
200
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
1868 fprintf(stderr, "Repository %s already exists.\nAbort\n", name);
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1869 return -1;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1870 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1871
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1872 printf("\nSpecify the repository base url.\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1873 char *url = assistant_getcfg("url");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1874 if(!url) {
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1875 fprintf(stderr, "Abort\n");
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1876 return -1;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1877 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1878
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1879 printf("\nUser for HTTP authentication.\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1880 char *user = assistant_getoptcfg("user");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1881
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1882 char *password = NULL;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1883 if(user) {
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1884 password = assistant_gethiddenoptcfg("password");
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1885 }
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1886 printf("\n");
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1887
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1888 Repository repo;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1889 memset(&repo, 0, sizeof(Repository));
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1890 repo.name = name;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1891 repo.url = url;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1892 repo.user = user;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1893 repo.password = password;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1894
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1895 int ret = 0;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1896 if(add_repository(&repo)) {
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1897 fprintf(stderr, "Cannot write config.xml\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1898 ret = -1;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1899 } else {
200
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
1900 printf("\nAdded repository: %s (%s)\n", name, url);
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1901 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1902
197
79a866256be4 added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
1903 free(name);
79a866256be4 added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
1904 free(url);
79a866256be4 added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
1905 if(user) {
79a866256be4 added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
1906 free(user);
79a866256be4 added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
1907 }
79a866256be4 added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
1908 if(password) {
79a866256be4 added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
1909 free(password);
79a866256be4 added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
1910 }
79a866256be4 added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
1911
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1912 return ret;
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 107
diff changeset
1913 }

mercurial