Mon, 23 May 2016 12:12:53 +0200
added install target
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 | * |
185
cd42cccee550
updated copyright notice
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
182
diff
changeset
|
4 | * Copyright 2016 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 | 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 | 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> |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
44 | #include "config.h" |
191
0e45b04236a7
more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
45 | #include "error.h" |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
46 | #include "assistant.h" |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | #include "main.h" |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
49 | static DavContext *ctx; |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
50 | |
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
51 | static int printxmlerror = 1; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
52 | 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
|
53 | if(printxmlerror) { |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
54 | va_list ap; |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
55 | va_start(ap, msg); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
56 | vfprintf(stderr, msg, ap); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
57 | va_end(ap); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
58 | } |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
61 | //define DO_THE_TEST |
105
ee0de2b1872e
fixed control flow in int_cmd + committed testcase (enable with #define DO_THE_TEST)
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
62 | #include <libidav/davqlparser.h> |
123
806c4dccf2ae
added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
63 | #include <libidav/davqlexec.h> |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
64 | void test() { |
123
806c4dccf2ae
added where clause compiler prototype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
65 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
66 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
67 | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | int main(int argc, char **argv) { |
8
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
69 | xmlGenericErrorFunc fnc = xmlerrorfnc; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | initGenericErrorDefaultFunc(&fnc); |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
71 | ctx = dav_context_new(); |
213
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
72 | dav_add_namespace(ctx, "apache", "http://apache.org/dav/props/"); |
40
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
73 | load_config(ctx); |
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
74 | printxmlerror = 0; |
105
ee0de2b1872e
fixed control flow in int_cmd + committed testcase (enable with #define DO_THE_TEST)
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
75 | #ifdef DO_THE_TEST |
ee0de2b1872e
fixed control flow in int_cmd + committed testcase (enable with #define DO_THE_TEST)
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
76 | test(); |
107
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
105
diff
changeset
|
77 | return 0; |
105
ee0de2b1872e
fixed control flow in int_cmd + committed testcase (enable with #define DO_THE_TEST)
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
78 | #endif |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
79 | |
36 | 80 | memcpy(ctx->http_proxy, get_http_proxy(), sizeof(Proxy)); |
81 | memcpy(ctx->https_proxy, get_https_proxy(), sizeof(Proxy)); | |
82 | ||
34
1b87b3b1921e
removed debug code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
83 | if(argc < 2) { |
11 | 84 | fprintf(stderr, "Missing command\n"); |
85 | print_usage(argv[0]); | |
86 | return -1; | |
87 | } | |
88 | ||
34
1b87b3b1921e
removed debug code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
89 | char *cmd = argv[1]; |
1b87b3b1921e
removed debug code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
90 | CmdArgs *args = cmd_parse_args(argc - 2, argv + 2); |
11 | 91 | if(!args) { |
92 | print_usage(argv[0]); | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
93 | cmd_args_free(args); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | return -1; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | |
212
01e80c7cfe96
added noinput option to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
97 | |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
98 | int ret = -1; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
99 | if(!strcasecmp(cmd, "list") || !strcasecmp(cmd, "ls")) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
100 | ret = cmd_list(args); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
101 | } else if(!strcasecmp(cmd, "get")) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
102 | ret = cmd_get(args); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
103 | } else if(!strcasecmp(cmd, "put")) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
104 | ret = cmd_put(args); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
105 | } else if( |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
106 | !strcasecmp(cmd, "remove") || |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
107 | !strcasecmp(cmd, "rm") || |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
108 | !strcasecmp(cmd, "delete")) |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
109 | { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
110 | ret = cmd_remove(args); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
111 | } else if(!strcasecmp(cmd, "mkdir") || !strcasecmp(cmd, "mkcol")) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
112 | ret = cmd_mkdir(args); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
113 | } else if(!strcasecmp(cmd, "copy") || !strcasecmp(cmd, "cp")) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
114 | ret = cmd_move(args, true); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
115 | } else if(!strcasecmp(cmd, "move") || !strcasecmp(cmd, "mv")) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
116 | ret = cmd_move(args, false); |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
117 | } else if(!strcasecmp(cmd, "date")) { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
118 | ret = cmd_date(args); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
119 | } else if(!strcasecmp(cmd, "set-property")) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
120 | ret = cmd_set_property(args); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
121 | } else if(!strcasecmp(cmd, "get-property")) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
122 | ret = cmd_get_property(args); |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
123 | } else if(!strcasecmp(cmd, "lock")) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
124 | ret = cmd_lock(args); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
125 | } else if(!strcasecmp(cmd, "unlock")) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
126 | ret = cmd_unlock(args); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
127 | } else if(!strcasecmp(cmd, "info")) { |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
128 | ret = cmd_info(args); |
197
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
129 | } else if(!strcasecmp(cmd, "add-repository")) { |
196 | 130 | ret = cmd_add_repository(args); |
198
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
197
diff
changeset
|
131 | } else if(!strcasecmp(cmd, "list-repositories")) { |
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
197
diff
changeset
|
132 | ret = list_repositories(); |
188
753c8fcde12f
added version info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
133 | } else if(!strcasecmp(cmd, "version") || !strcasecmp(cmd, "-version") || !strcasecmp(cmd, "--version")) { |
753c8fcde12f
added version info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
134 | fprintf(stderr, "dav %s\n", DAV_VERSION); |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
135 | } else { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
136 | print_usage(argv[0]); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | } |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
138 | |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
139 | dav_context_destroy(ctx); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
140 | cmd_args_free(args); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
141 | free_config(); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
142 | xmlCleanupParser(); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
143 | curl_global_cleanup(); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
145 | return ret; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | |
11 | 148 | void print_usage(char *cmd) { |
149 | fprintf(stderr, "Usage: %s command [options] arguments...\n\n", cmd); | |
150 | fprintf(stderr, "Commands:\n"); | |
213
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
151 | fprintf(stderr, " list [-altepcR] [-u <date>] <url>\n"); |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
152 | fprintf( |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
153 | stderr, |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
154 | " get [-pcR] [-o <file>] [-u <date>] <url>\n"); |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
155 | fprintf(stderr, " put [-pcR] [-k <key>] [-L <lock>] <url> <file>\n"); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
156 | fprintf(stderr, " mkdir [-pc] [-k <key>] [-L <lock>] <url>\n"); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
157 | fprintf(stderr, " remove [-pc] [-L <lock>] <url>\n"); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
158 | fprintf(stderr, " copy [-pcO] [-L <lock>] <url> <url>\n"); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
159 | fprintf(stderr, " move [-pcO] [-L <lock>] <url> <url>\n"); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
160 | fprintf( |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
161 | stderr, |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
162 | " get-property [-pc] [-n <uri>] <url> <property>\n"); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
163 | fprintf( |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
164 | stderr, |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
165 | " set-property [-pc] [-L <lock>] [-n <uri>] <url> <property> [value]\n"); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
166 | fprintf(stderr, " lock [-pc] <url>\n"); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
167 | fprintf(stderr, " unlock [-pc] [-L <lock>] <url>\n"); |
100
f4127c4d1018
improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
168 | fprintf(stderr, " info [-pc] <url>\n"); |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
169 | fprintf(stderr, " date [url]\n"); |
11 | 170 | fprintf(stderr, "\n"); |
171 | fprintf(stderr, "Options:\n"); | |
172 | fprintf(stderr, | |
100
f4127c4d1018
improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
173 | " -k <key> Key to use for encryption\n"); |
11 | 174 | 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
|
175 | fprintf(stderr, " -c Enable full encryption\n"); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
176 | fprintf(stderr, |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
177 | " -R " |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
178 | "Recursively do the operation for all children\n"); |
11 | 179 | 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
|
180 | fprintf( |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
181 | stderr, |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
182 | " -u <date> " |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
183 | "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
|
184 | fprintf(stderr, " -a show all files\n"); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
185 | 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
|
186 | fprintf(stderr, " -t print content type\n"); |
213
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
187 | 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
|
188 | fprintf(stderr, " -O override resources\n"); |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
189 | fprintf(stderr, " -L <lock> specificy lock token\n"); |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
190 | fprintf(stderr, " -n <uri> specify namespace uri\n"); |
229
df158262f802
fixed dav_context_get_key
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
191 | fprintf(stderr, " -N disable authentication prompt (all commands)\n"); |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
192 | fprintf(stderr, " -i disable cert verification (all commands)\n"); |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
193 | fprintf(stderr, " -v verbose output (all commands)\n"); |
11 | 194 | fprintf(stderr, "\n"); |
198
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
197
diff
changeset
|
195 | fprintf(stderr, "Config commands:\n"); |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
196 | fprintf(stderr, " add-repository\n"); |
198
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
197
diff
changeset
|
197 | fprintf(stderr, " list-repositories\n"); |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
198 | fprintf(stderr, "\n"); |
11 | 199 | fprintf(stderr, |
200 | "Instead of an url you can pass a repository name " | |
201 | "with an optional path:\n"); | |
202 | fprintf(stderr, " <repository>/path/\n"); | |
203 | fprintf(stderr, "\n"); | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | |
212
01e80c7cfe96
added noinput option to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
206 | int request_auth(Repository *repo, DavSession *sn, CmdArgs *a) { |
01e80c7cfe96
added noinput option to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
207 | if(cmd_getoption(a, "noinput")) { |
01e80c7cfe96
added noinput option to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
208 | return 0; |
01e80c7cfe96
added noinput option to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
209 | } |
01e80c7cfe96
added noinput option to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
210 | |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
211 | static int login = 0; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
212 | if(login) { |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
213 | return 0; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
214 | } |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
215 | |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
216 | char *user = NULL; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
217 | char ubuf[256]; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
218 | if(repo->user) { |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
219 | user = repo->user; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
220 | } else { |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
221 | fprintf(stderr, "User: "); |
146
e48048334602
hidden password input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
222 | fflush(stderr); |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
223 | user = fgets(ubuf, 256, stdin); |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
224 | } |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
225 | |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
226 | char *password = util_password_input("Password: "); |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
227 | |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
228 | size_t ulen = strlen(user); |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
229 | if(user[ulen-1] == '\n') { |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
230 | user[ulen-1] = '\0'; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
231 | } |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
232 | |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
233 | dav_session_set_auth(sn, user, password); |
146
e48048334602
hidden password input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
234 | free(password); |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
235 | login = 1; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
236 | return 1; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
237 | } |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
238 | |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
239 | 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
|
240 | 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
|
241 | *path = NULL; |
4 | 242 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
243 | int s; |
11 | 244 | 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
|
245 | s = 7; |
11 | 246 | } 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
|
247 | s = 8; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
248 | } else { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
249 | s = 1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
250 | } |
4 | 251 | |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
252 | sstr_t r = sstr(url); |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
253 | 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
|
254 | 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
|
255 | char c = url[i]; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
256 | if(c == '/') { |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
257 | r = sstrn(url, i); |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
258 | 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
|
259 | if(p.length == 0) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
260 | p = sstrn("/", 1); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
261 | } |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
262 | break; |
4 | 263 | } |
264 | } | |
265 | ||
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
266 | Repository *repo = get_repository(r); |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
267 | if(repo) { |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
268 | *path = sstrdup(p).ptr; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
269 | } else { |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
270 | repo = calloc(1, sizeof(Repository)); |
70 | 271 | repo->name = strdup(""); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
272 | repo->decrypt_content = true; |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
201
diff
changeset
|
273 | repo->verification = true; |
187
38295f2fa231
added missing repo authmethods initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
274 | repo->authmethods = CURLAUTH_BASIC; |
70 | 275 | if(url[ulen-1] == '/') { |
276 | repo->url = strdup(url); | |
277 | *path = strdup("/"); | |
100
f4127c4d1018
improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
278 | } else if (strchr(url, '/')) { |
70 | 279 | repo->url = util_parent_path(url); |
280 | // TODO: check/fix | |
281 | *path = strdup(util_resource_name(url)-1); | |
100
f4127c4d1018
improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
282 | } else { |
f4127c4d1018
improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
283 | repo->url = strdup(url); |
f4127c4d1018
improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
284 | *path = strdup("/"); |
70 | 285 | } |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
286 | } |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
287 | |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
288 | return repo; |
4 | 289 | } |
290 | ||
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
291 | 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
|
292 | char *plain = cmd_getoption(a, "plain"); |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
293 | char *crypt = cmd_getoption(a, "crypt"); |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
294 | |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
295 | if(plain && crypt) { |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
296 | 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
|
297 | return 1; |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
298 | } |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
299 | |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
300 | if (plain) { |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
301 | sn->flags &= ~DAV_SESSION_FULL_ENCRYPTION; |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
302 | } else if(crypt) { |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
303 | sn->flags |= DAV_SESSION_FULL_ENCRYPTION; |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
304 | } |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
305 | |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
306 | if (cmd_getoption(a, "verbose")) { |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
307 | 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
|
308 | 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
|
309 | } |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
310 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
311 | return 0; |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
312 | } |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
313 | |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
314 | 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
|
315 | char *locktoken = cmd_getoption(a, "lock"); |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
316 | if(locktoken) { |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
317 | 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
|
318 | dav_add_collection_lock(sn, "/", lock); |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
319 | } |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
320 | } |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
321 | |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
322 | 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
|
323 | 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
|
324 | sn->flags = get_repository_flags(repo); |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
325 | 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
|
326 | 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
|
327 | 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
|
328 | if(repo->cert) { |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
329 | curl_easy_setopt(sn->handle, CURLOPT_CAINFO, repo->cert); |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
330 | } |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
331 | if(!repo->verification || cmd_getoption(a, "insecure")) { |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
332 | curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYPEER, 0); |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
333 | curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0); |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
334 | } |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
335 | return sn; |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
336 | } |
4 | 337 | |
11 | 338 | int cmd_list(CmdArgs *a) { |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
339 | if(a->argc != 1) { |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
340 | fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341 | return -1; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343 | |
11 | 344 | 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
|
345 | char *path = NULL; |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
346 | Repository *repo = url2repo(url, &path); |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
347 | DavSession *sn = connect_to_repo(repo, a); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
349 | if(set_session_config(sn, a)) { |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
350 | return -1; |
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 | |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
353 | char *update = cmd_getoption(a, "update"); |
136
59058927b885
empty field results will no longer be added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
354 | time_t t = -1; |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
355 | if(update) { |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
356 | t = util_parse_lastmodified(update); |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
357 | } |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
358 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
359 | 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
|
360 | int ret = -1; |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
361 | DavResource *ls; |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
362 | while(ret != 0) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
363 | ls = dav_query( |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
364 | sn, |
213
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
365 | "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery,apache:executable from %s with depth = %d where lastmodified > %t order by iscollection desc, name", |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
366 | path, |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
367 | depth, |
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
368 | t); |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
369 | |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
370 | if(!ls) { |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
371 | if(sn->error == DAV_UNAUTHORIZED) { |
212
01e80c7cfe96
added noinput option to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
372 | if(request_auth(repo, sn, a)) { |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
373 | continue; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
374 | } |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
375 | } |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
376 | print_resource_error(sn, path); |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
377 | break; |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
378 | } |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
379 | |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
380 | // parameters |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
381 | void (*print_func)(DavResource*, CmdArgs *); |
213
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
382 | 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
|
383 | print_func = ls_print_list_elm; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
384 | } else { |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
385 | print_func = ls_print_elm; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
386 | } |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
387 | |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
388 | DavResource *child = ls->children; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
389 | while(child) { |
138
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
390 | print_func(child, a); |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
391 | child = child->next; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
392 | } |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
393 | |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
394 | // leave loop |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
395 | ret = 0; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
396 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
397 | |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
398 | free(path); |
40
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
399 | //free(base); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
400 | |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
401 | dav_session_destroy(sn); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
402 | |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
403 | return ret; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405 | |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
406 | 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
|
407 | struct tm t; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
408 | struct tm n; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
409 | time_t now = time(NULL); |
32 | 410 | #ifdef _WIN32 |
411 | memcpy(&t, localtime(&tm), sizeof(struct tm)); | |
412 | memcpy(&n, localtime(&now), sizeof(struct tm)); | |
413 | #else | |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
414 | localtime_r(&tm, &t); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
415 | localtime_r(&now, &n); |
32 | 416 | #endif /* _WIN32 */ |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
417 | char *str = malloc(16); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
418 | if(t.tm_year == n.tm_year) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
419 | 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
|
420 | } else { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
421 | strftime(str, 16, "%b %d %Y", &t); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
422 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
423 | return str; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
424 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
425 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
426 | static char* ls_size_str(DavResource *res) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
427 | char *str = malloc(16); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
428 | uint64_t size = res->contentlength; |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
429 | |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
430 | if(res->iscollection) { |
165
b66bed169fc3
fixed zero-length format string in ls_size_str
Mike Becker <universe@uap-core.de>
parents:
154
diff
changeset
|
431 | 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
|
432 | } else if(size < 0x400) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
433 | snprintf(str, 16, "%" PRIu64 " bytes", size); |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
434 | } else if(size < 0x100000) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
435 | float s = (float)size/0x400; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
436 | int diff = (s*100 - (int)s*100); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
437 | if(diff > 90) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
438 | diff = 0; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
439 | s += 0.10f; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
440 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
441 | if(size < 0x2800 && diff != 0) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
442 | // size < 10 KiB |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
443 | snprintf(str, 16, "%.1f KiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
444 | } else { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
445 | snprintf(str, 16, "%.0f KiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
446 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
447 | } else if(size < 0x40000000) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
448 | float s = (float)size/0x100000; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
449 | int diff = (s*100 - (int)s*100); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
450 | if(diff > 90) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
451 | diff = 0; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
452 | s += 0.10f; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
453 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
454 | if(size < 0xa00000 && diff != 0) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
455 | // size < 10 MiB |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
456 | snprintf(str, 16, "%.1f MiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
457 | } else { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
458 | size /= 0x100000; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
459 | snprintf(str, 16, "%.0f MiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
460 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
461 | } else if(size < 0x1000000000ULL) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
462 | float s = (float)size/0x40000000; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
463 | int diff = (s*100 - (int)s*100); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
464 | if(diff > 90) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
465 | diff = 0; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
466 | s += 0.10f; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
467 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
468 | if(size < 0x280000000 && diff != 0) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
469 | // size < 10 GiB |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
470 | snprintf(str, 16, "%.1f GiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
471 | } else { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
472 | size /= 0x40000000; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
473 | snprintf(str, 16, "%.0f GiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
474 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
475 | } else { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
476 | size /= 1024; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
477 | float s = (float)size/0x40000000; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
478 | int diff = (s*100 - (int)s*100); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
479 | if(diff > 90) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
480 | diff = 0; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
481 | s += 0.10f; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
482 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
483 | if(size < 0x280000000 && diff != 0) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
484 | // size < 10 TiB |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
485 | snprintf(str, 16, "%.1f TiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
486 | } else { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
487 | size /= 0x40000000; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
488 | snprintf(str, 16, "%.0f TiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
489 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
490 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
491 | return str; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
492 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
493 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
494 | void ls_print_list_elm(DavResource *res, CmdArgs *a) { |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
495 | 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
|
496 | 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
|
497 | 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
|
498 | return; |
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
499 | } |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
500 | |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
501 | char flags[16]; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
502 | memset(flags, '-', 15); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
503 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
504 | int type_width = 0; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
505 | char *type = res->contenttype; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
506 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
507 | if(res->iscollection) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
508 | flags[0] = 'd'; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
509 | type = ""; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
510 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
511 | char *keyprop = dav_get_property_ns( |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
512 | res, |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
513 | DAV_NS, |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
514 | "crypto-key"); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
515 | if(keyprop) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
516 | flags[1] = 'c'; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
517 | } |
213
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
518 | |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
519 | 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
|
520 | flags[6] = '\0'; |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
521 | if(dav_get_property(res, "D:lockdiscovery")) { |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
522 | flags[2] = 'l'; |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
523 | } |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
524 | char *executable = dav_get_property_ns( |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
525 | res, |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
526 | "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
|
527 | "executable"); |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
528 | 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
|
529 | flags[3] = 'x'; |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
530 | } |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
531 | } else { |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
532 | flags[2] = '\0'; |
211
3d12817414e9
dav list indicates locks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
533 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
534 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
535 | if(cmd_getoption(a, "type")) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
536 | type_width = 20; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
537 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
538 | if(type == NULL || type_width == 0) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
539 | type = ""; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
540 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
541 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
542 | char *date = ls_date_str(res->lastmodified); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
543 | char *size = ls_size_str(res); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
544 | 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
|
545 | printf( |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
546 | "%s %*s %10s %12s %s\n", |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
547 | flags, |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
548 | type_width, type, |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
549 | size, |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
550 | date, |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
551 | name); |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
552 | free(date); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
553 | free(size); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
554 | |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
555 | if(recursive) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
556 | DavResource *child = res->children; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
557 | while(child) { |
138
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
558 | //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
|
559 | if(child->name[0] != '.' || show_all) { |
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
560 | 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
|
561 | } |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
562 | child = child->next; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
563 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
564 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
565 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
566 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
567 | void ls_print_elm(DavResource *res, CmdArgs *a) { |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
568 | 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
|
569 | 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
|
570 | 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
|
571 | return; |
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
572 | } |
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
573 | |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
574 | char *name = recursive ? res->path+1 : res->name; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
575 | printf("%s\n", name); |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
576 | if(recursive) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
577 | DavResource *child = res->children; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
578 | while(child) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
579 | ls_print_elm(child, a); |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
580 | child = child->next; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
581 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
582 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
583 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
584 | |
11 | 585 | int cmd_get(CmdArgs *a) { |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
586 | if(a->argc != 1) { |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
587 | // 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
|
588 | fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
589 | return -1; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
590 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
591 | |
11 | 592 | 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
|
593 | char *path = NULL; |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
594 | Repository *repo = url2repo(url, &path); |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
595 | DavSession *sn = connect_to_repo(repo, a); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
596 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
597 | if(set_session_config(sn, a)) { |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
598 | return -1; |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
599 | } |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
600 | |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
601 | char *update = cmd_getoption(a, "update"); |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
602 | time_t t = -1; |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
603 | if(update) { |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
604 | t = util_parse_lastmodified(update); |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
605 | } |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
606 | |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
607 | int recursive = cmd_getoption(a, "recursive") ? 1 : 0; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
608 | DavResource *res; |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
609 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
610 | int depth = recursive ? -1 : 1; |
201
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
611 | for(int i=0;i<2;i++) { |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
612 | res = dav_query( |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
613 | sn, |
235
0468df02e18f
fixed dav get with -u option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
230
diff
changeset
|
614 | "select - from %s with depth = %d where iscollection or lastmodified > %t", |
201
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
615 | path, |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
616 | depth, |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
617 | t); |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
618 | if(!res && sn->error == DAV_UNAUTHORIZED) { |
212
01e80c7cfe96
added noinput option to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
619 | if(request_auth(repo, sn, a)) { |
201
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
620 | continue; |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
621 | } |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
622 | } |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
623 | break; |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
624 | } |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
625 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
626 | if(!res) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
627 | 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
|
628 | return -1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
629 | } |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
630 | if(!recursive && res->iscollection) { |
235
0468df02e18f
fixed dav get with -u option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
230
diff
changeset
|
631 | 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
|
632 | 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
|
633 | return -1; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
634 | } |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
635 | |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
636 | /* |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
637 | * determine the output file |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
638 | * 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
|
639 | */ |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
640 | char *outfile = cmd_getoption(a, "output"); |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
641 | if(!outfile) { |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
642 | if(res->iscollection) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
643 | outfile = ""; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
644 | } else { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
645 | outfile = res->name; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
646 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
647 | } else if(res->iscollection && !strcmp(outfile, "-")) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
648 | fprintf( |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
649 | stderr, |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
650 | "Cannot write output to stdout " |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
651 | "if the requested resource is a collection.\n"); |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
652 | return -1; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
653 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
654 | |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
655 | int ret = get_resource(repo, res, a, outfile); |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
656 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
657 | free(path); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
658 | return ret; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
659 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
660 | |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
661 | int get_resource(Repository *repo, DavResource *res, CmdArgs *a, char *out) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
662 | size_t outlen = strlen(out); |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
663 | // print some status message in recursive mode |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
664 | if(cmd_getoption(a, "recursive")) { |
235
0468df02e18f
fixed dav get with -u option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
230
diff
changeset
|
665 | printf("get: %s\n", res->path); |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
666 | } |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
667 | |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
668 | if(res->iscollection) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
669 | // create directory |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
670 | if(outlen != 0) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
671 | mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
32 | 672 | int ret = util_mkdir(out, mode); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
673 | if(ret != 0 && errno != EEXIST) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
674 | return 1; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
675 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
676 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
677 | |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
678 | DavResource *child = res->children; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
679 | while(child) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
680 | char *newout = outlen > 0 ? |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
681 | util_concat_path(out, child->name) : child->name; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
682 | int ret = get_resource(repo, child, a, newout); |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
683 | if(outlen > 0) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
684 | free(newout); |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
685 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
686 | if(ret) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
687 | return 1; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
688 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
689 | child = child->next; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
690 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
691 | |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
692 | return 0; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
693 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
694 | |
72
aac29f2e8030
dav now opens files in binary mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
695 | FILE *fout = !strcmp(out, "-") ? stdout : fopen(out, "wb"); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
696 | if(!fout) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
697 | 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
|
698 | return -1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
699 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
700 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
701 | 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
|
702 | fclose(fout); |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
703 | if(ret && strcmp(out, "-")) { |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
204
diff
changeset
|
704 | print_resource_error(res->session, res->path); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
204
diff
changeset
|
705 | //if(strcmp(out, "-")) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
204
diff
changeset
|
706 | // unlink(out); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
204
diff
changeset
|
707 | //} |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
708 | } |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
709 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
710 | return 0; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
711 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
712 | |
11 | 713 | int cmd_put(CmdArgs *a) { |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
714 | if(a->argc != 2) { |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
715 | // 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
|
716 | fprintf(stderr, "Too %s arguments\n", a->argc < 2 ? "few":"many"); |
4 | 717 | return -1; |
3
323689ada09d
disabled ssl cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
718 | } |
323689ada09d
disabled ssl cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
719 | |
11 | 720 | char *url = a->argv[0]; |
721 | 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
|
722 | char *path = NULL; |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
723 | Repository *repo = url2repo(url, &path); |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
724 | DavSession *sn = connect_to_repo(repo, a); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
725 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
726 | if(set_session_config(sn, a)) { |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
727 | return -1; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
728 | } |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
729 | set_session_lock(sn, a); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
730 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
731 | // 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
|
732 | char *keyname = cmd_getoption(a, "key"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
733 | if(keyname) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
734 | DavKey *key = dav_context_get_key(ctx, keyname); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
735 | if(key) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
736 | sn->key = key; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
737 | } else { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
738 | fprintf(stderr, "Key %s not found!\nAbort.\n", keyname); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
739 | // TODO: free |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
740 | return -1; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
741 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
742 | } |
4 | 743 | |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
744 | int ret; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
745 | if(!strcmp(file, "-")) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
746 | FILE *in = stdin; |
178
e137883e620f
using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
747 | ret = put_file(repo, a, sn, path, "stdin", in, 0); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
748 | } else { |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
749 | ret = put_entry(repo, a, sn, path, file); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
750 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
751 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
752 | free(path); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
753 | return ret; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
754 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
755 | |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
756 | int put_entry(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *file) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
757 | int recursive = cmd_getoption(a, "recursive") ? 1 : 0; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
758 | if(recursive) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
759 | printf("put: %s\n", file); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
760 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
761 | struct stat s; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
762 | if(stat(file, &s)) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
763 | perror("stat"); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
764 | 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
|
765 | return -1; |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
766 | } |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
767 | |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
768 | int ret = 0; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
769 | if(S_ISDIR(s.st_mode)) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
770 | if(!recursive) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
771 | return 1; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
772 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
773 | DIR *dir = opendir(file); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
774 | if(!dir) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
775 | // error |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
776 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
777 | struct dirent *entry; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
778 | while((entry = readdir(dir)) != NULL) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
779 | if(!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
780 | continue; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
781 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
782 | char *entry_file = util_concat_path(file, entry->d_name); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
783 | char *entry_path = util_concat_path(path, entry->d_name); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
784 | int r = put_entry(repo, a, sn, entry_path, entry_file); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
785 | free(entry_path); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
786 | free(entry_file); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
787 | if(r) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
788 | ret = 1; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
789 | break; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
790 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
791 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
792 | closedir(dir); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
793 | } else if(S_ISREG(s.st_mode)) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
794 | /* |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
795 | * use stdin if the input file is - |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
796 | */ |
72
aac29f2e8030
dav now opens files in binary mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
797 | FILE *in = fopen(file, "rb"); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
798 | if(!in) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
799 | fprintf(stderr, "cannot open input file\n"); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
800 | return -1; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
801 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
802 | char *filename = util_resource_name(file); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
803 | //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
|
804 | 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
|
805 | //free(path); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
806 | fclose(in); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
807 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
808 | |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
809 | return ret; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
810 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
811 | |
178
e137883e620f
using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
812 | int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len) { |
201
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
813 | DavResource *res = NULL; |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
814 | for(int i=0;i<2;i++) { |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
815 | res = dav_query(sn, "select - from %s", path); |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
816 | if(!res && sn->error == DAV_UNAUTHORIZED) { |
212
01e80c7cfe96
added noinput option to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
817 | if(request_auth(repo, sn, a)) { |
201
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
818 | continue; |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
819 | } |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
820 | } |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
821 | break; |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
822 | } |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
823 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
824 | if(!res) { |
24
a317202ae787
implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
825 | if(sn->error == DAV_NOT_FOUND) { |
21 | 826 | 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
|
827 | if(dav_create(res)) { |
a317202ae787
implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
828 | fprintf(stderr, "Cannot create resource.\n"); |
a317202ae787
implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
829 | return -1; |
a317202ae787
implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
830 | } |
21 | 831 | } else { |
198
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
197
diff
changeset
|
832 | print_resource_error(sn, path); |
21 | 833 | return -1; |
834 | } | |
835 | } else if(res->iscollection) { | |
836 | // TODO: free res | |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
837 | char *newpath = util_concat_path(path, name); |
21 | 838 | path = newpath; |
839 | res = dav_resource_new(sn, path); | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
840 | free(newpath); |
178
e137883e620f
using content-length header in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
841 | 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
|
842 | // TODO: free res |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
843 | return ret; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
844 | } |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
845 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
846 | 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
|
847 | if(len > 0 && len < 0x7d000000) { |
179
802b48ae791d
enable sharepoint put fix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
178
diff
changeset
|
848 | 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
|
849 | } |
4 | 850 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
851 | if(dav_store(res)) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
852 | print_resource_error(sn, res->path); |
13
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
853 | fprintf(stderr, "Cannot upload file.\n"); |
22
e593f7e41be0
added more error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
854 | if(sn->errorstr) { |
e593f7e41be0
added more error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
855 | fprintf(stderr, "%s\n", sn->errorstr); |
e593f7e41be0
added more error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
856 | } |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
857 | return -1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
858 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
859 | return 0; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
860 | } |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
861 | |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
862 | |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
863 | int cmd_remove(CmdArgs *a) { |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
864 | if(a->argc != 1) { |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
865 | // 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
|
866 | fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
867 | return -1; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
868 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
869 | |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
870 | char *url = a->argv[0]; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
871 | 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
|
872 | 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
|
873 | DavSession *sn = connect_to_repo(repo, a); |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
874 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
875 | if(set_session_config(sn, a)) { |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
876 | return -1; |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
877 | } |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
878 | set_session_lock(sn, a); |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
879 | |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
880 | DavResource *res = dav_resource_new(sn, path); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
881 | if(!res) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
882 | fprintf(stderr, "error\n"); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
883 | return -1; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
884 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
885 | |
201
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
886 | int err = 0; |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
887 | for(int i=0;i<2;i++) { |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
888 | err = dav_delete(res); |
212
01e80c7cfe96
added noinput option to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
889 | if(err && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn, a)) { |
201
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
890 | continue; |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
891 | } else { |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
892 | break; |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
893 | } |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
894 | } |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
895 | |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
896 | if(err) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
897 | print_resource_error(sn, res->path); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
898 | fprintf(stderr, "Cannot delete resource.\n"); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
899 | return -1; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
900 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
901 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
902 | free(path); |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
903 | return 0; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
904 | } |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
905 | |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
906 | int cmd_mkdir(CmdArgs *a) { |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
907 | if(a->argc != 1) { |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
908 | // 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
|
909 | fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
910 | return -1; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
911 | } |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
912 | |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
913 | char *url = a->argv[0]; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
914 | 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
|
915 | 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
|
916 | DavSession *sn = connect_to_repo(repo, a); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
917 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
918 | if(set_session_config(sn, a)) { |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
919 | return -1; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
920 | } |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
921 | set_session_lock(sn, a); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
922 | |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
923 | // 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
|
924 | char *keyname = cmd_getoption(a, "key"); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
925 | if(keyname) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
926 | DavKey *key = dav_context_get_key(ctx, keyname); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
927 | if(key) { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
928 | sn->key = key; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
929 | } else { |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
930 | fprintf(stderr, "Key %s not found!\nAbort.\n", keyname); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
931 | // TODO: free |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
932 | return -1; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
933 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
934 | } |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
935 | |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
936 | DavResource *res = dav_resource_new(sn, path); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
937 | if(!res) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
938 | fprintf(stderr, "error\n"); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
939 | return -1; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
940 | } |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
941 | res->iscollection = 1; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
942 | |
201
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
943 | int err = 0; |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
944 | for(int i=0;i<2;i++) { |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
945 | err = dav_create(res); |
212
01e80c7cfe96
added noinput option to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
946 | if(err && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn, a)) { |
201
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
947 | continue; |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
948 | } else { |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
949 | break; |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
950 | } |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
951 | } |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
952 | |
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
953 | if(err) { |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
954 | print_resource_error(sn, res->path); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
955 | fprintf(stderr, "Cannot create collection.\n"); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
956 | return -1; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
957 | } |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
958 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
959 | free(path); |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
960 | return 0; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
961 | } |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
962 | |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
963 | int cmd_move(CmdArgs *a, int cp) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
964 | if(a->argc != 2) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
965 | // 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
|
966 | fprintf(stderr, "Too %s arguments\n", a->argc < 2 ? "few":"many"); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
967 | return -1; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
968 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
969 | |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
970 | char *url1 = a->argv[0]; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
971 | char *path1 = NULL; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
972 | Repository *repo1 = url2repo(url1, &path1); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
973 | |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
974 | char *url2 = a->argv[1]; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
975 | char *path2 = NULL; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
976 | Repository *repo2 = url2repo(url2, &path2); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
977 | |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
978 | 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
|
979 | if(set_session_config(sn, a)) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
980 | return -1; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
981 | } |
236
6b4ce32d0c4e
copy/move with lock tokens works now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
235
diff
changeset
|
982 | set_session_lock(sn, a); |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
983 | |
182
ca07f14f7bfe
added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
181
diff
changeset
|
984 | 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
|
985 | |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
986 | if(repo1 == repo2) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
987 | 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
|
988 | 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
|
989 | : dav_move_o(res, path2, override); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
990 | if(err) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
991 | print_resource_error(sn, res->path); |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
992 | 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
|
993 | return -1; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
994 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
995 | } else { |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
996 | char *server1 = util_url_base(repo1->url); |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
997 | char *server2 = util_url_base(repo2->url); |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
998 | if(!strcmp(server1, server2)) { |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
999 | DavSession *sn2 = connect_to_repo(repo2, a); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1000 | if(set_session_config(sn2, a)) { |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1001 | return -1; |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1002 | } |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1003 | DavResource *dest = dav_resource_new(sn2, path2); |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1004 | char *desthref = dav_resource_get_href(dest); |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1005 | char *desturl = util_get_url(sn2, desthref); |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1006 | |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1007 | DavResource *res = dav_resource_new(sn, path1); |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1008 | int err = cp ? dav_copyto(res, desturl, override) |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1009 | : dav_moveto(res, desturl, override); |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1010 | |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1011 | free(desturl); |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1012 | dav_session_destroy(sn2); |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1013 | |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1014 | if(err) { |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1015 | print_resource_error(sn, res->path); |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1016 | fprintf(stderr, "Cannot %s resource.\n", cp ? "copy" : "move"); |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1017 | return -1; |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1018 | } |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1019 | } else { |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1020 | 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
|
1021 | return -1; |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1022 | } |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1023 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1024 | |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1025 | dav_session_destroy(sn); |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1026 | |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1027 | return 0; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1028 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1029 | |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1030 | |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1031 | 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
|
1032 | char **date_str = (char**)data; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1033 | |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1034 | //printf("header: %.*s\n", s*n, header); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1035 | sstr_t h = sstrn(header, s*n); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1036 | if(sstrprefix(h, S("Date:"))) { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1037 | sstr_t v = sstrsubs(h, 5); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1038 | v = sstrdup(sstrtrim(v)); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1039 | *date_str = v.ptr; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1040 | } |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1041 | return s*n; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1042 | } |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1043 | |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1044 | int cmd_date(CmdArgs *a) { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1045 | if(a->argc < 1) { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1046 | time_t now = time(NULL); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1047 | struct tm *date = gmtime(&now); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1048 | char str[32]; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1049 | putenv("LC_TIME=C"); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1050 | 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
|
1051 | fwrite(str, 1, len, stdout); |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
1052 | } else if (a->argc == 1) { |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1053 | char *url = a->argv[0]; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1054 | char *path = NULL; |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
1055 | DavSession *sn = connect_to_repo(url2repo(url, &path), a); |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1056 | |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1057 | DavResource *res = dav_resource_new(sn, path); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1058 | char *date = NULL; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1059 | 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
|
1060 | curl_easy_setopt(sn->handle, CURLOPT_WRITEHEADER, &date); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1061 | if(dav_exists(res) && date) { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1062 | printf("%s\n", date); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1063 | } else { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1064 | return -1; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1065 | } |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
1066 | free(path); |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
1067 | return 0; |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
1068 | } else { |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
1069 | fprintf(stderr, "Too many arguments\n"); |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
1070 | return -1; |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1071 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
1072 | return 0; |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1073 | } |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1074 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1075 | int cmd_get_property(CmdArgs *a) { |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1076 | if(a->argc < 2) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1077 | fprintf(stderr, "Too few arguments\n"); |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1078 | return -1; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1079 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1080 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1081 | char *url = a->argv[0]; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1082 | char *path = NULL; |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
1083 | DavSession *sn = connect_to_repo(url2repo(url, &path), a); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1084 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1085 | if(set_session_config(sn, a)) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1086 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1087 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1088 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1089 | char *namespace = cmd_getoption(a, "namespace"); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1090 | char *property = a->argv[1]; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1091 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1092 | DavResource *res = dav_resource_new(sn, path); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1093 | if(dav_load(res)) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1094 | print_resource_error(sn, res->path); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1095 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1096 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1097 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1098 | char *value = namespace ? |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1099 | dav_get_property_ns(res, namespace, property) : |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1100 | dav_get_property(res, property); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1101 | if(!value) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1102 | 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
|
1103 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1104 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1105 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1106 | int ret = 0; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1107 | if(value) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1108 | printf("%s\n", value); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1109 | } else { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1110 | // TODO: correct error message |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1111 | fprintf(stderr, "Error: property not found.\n"); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1112 | ret = -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1113 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1114 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
1115 | free(path); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1116 | return ret; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1117 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1118 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1119 | int cmd_set_property(CmdArgs *a) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1120 | if(a->argc < 2) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1121 | fprintf(stderr, "Too few arguments\n"); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1122 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1123 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1124 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1125 | char *url = a->argv[0]; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1126 | char *path = NULL; |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
1127 | DavSession *sn = connect_to_repo(url2repo(url, &path), a); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1128 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1129 | if(set_session_config(sn, a)) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1130 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1131 | } |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
1132 | set_session_lock(sn, a); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1133 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1134 | DavResource *res = dav_resource_new(sn, path); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1135 | if(!dav_exists(res)) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1136 | print_resource_error(sn, res->path); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1137 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1138 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1139 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1140 | char *namespace = cmd_getoption(a, "namespace"); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1141 | char *property = a->argv[1]; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1142 | 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
|
1143 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1144 | if(namespace) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1145 | dav_set_property_ns(res, namespace, property, value); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1146 | } else { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1147 | dav_set_property(res, property, value); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1148 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1149 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1150 | if(dav_store(res)) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1151 | print_resource_error(sn, res->path); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1152 | fprintf(stderr, "Cannot set property.\n"); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1153 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1154 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1155 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
1156 | free(path); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1157 | return 0; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1158 | } |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1159 | |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1160 | int cmd_lock(CmdArgs *a) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1161 | if(a->argc != 1) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1162 | fprintf(stderr, "Too %s arguments\n", a->argc > 1 ? "many" : "few"); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1163 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1164 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1165 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1166 | char *url = a->argv[0]; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1167 | char *path = NULL; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1168 | 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
|
1169 | 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
|
1170 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1171 | if(set_session_config(sn, a)) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1172 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1173 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1174 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1175 | DavResource *res = dav_resource_new(sn, path); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1176 | if(dav_lock(res)) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1177 | print_resource_error(sn, res->path); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1178 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1179 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1180 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1181 | 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
|
1182 | if(!lock) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1183 | // this should really not happen |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1184 | // do some damage control |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1185 | dav_unlock(res); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1186 | 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
|
1187 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1188 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1189 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1190 | printf("%s\n", lock->token); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1191 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1192 | dav_session_destroy(sn); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1193 | return 0; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1194 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1195 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1196 | static char* read_line() { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1197 | 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
|
1198 | int c; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1199 | while((c = getchar()) != EOF) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1200 | if(c == '\n') { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1201 | break; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1202 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1203 | ucx_buffer_putc(buf, c); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1204 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1205 | char *str = NULL; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1206 | 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
|
1207 | if(line.length != 0) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1208 | str = sstrdup(line).ptr; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1209 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1210 | ucx_buffer_free(buf); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1211 | return str; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1212 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1213 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1214 | int cmd_unlock(CmdArgs *a) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1215 | if(a->argc != 1) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1216 | fprintf(stderr, "Too %s arguments\n", a->argc > 1 ? "many" : "few"); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1217 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1218 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1219 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1220 | char *url = a->argv[0]; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1221 | char *path = NULL; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1222 | 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
|
1223 | 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
|
1224 | if(set_session_config(sn, a)) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1225 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1226 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1227 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1228 | char *locktoken = cmd_getoption(a, "lock"); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1229 | if(locktoken) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1230 | 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
|
1231 | dav_add_collection_lock(sn, "/", lock); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1232 | } else { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1233 | locktoken = read_line(); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1234 | if(!locktoken) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1235 | 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
|
1236 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1237 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1238 | 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
|
1239 | 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
|
1240 | free(locktoken); |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1241 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1242 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1243 | DavResource *res = dav_resource_new(sn, path); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1244 | if(dav_unlock(res)) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1245 | print_resource_error(sn, res->path); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1246 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1247 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1248 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1249 | dav_session_destroy(sn); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1250 | return 0; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1251 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1252 | |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1253 | static int count_children(DavResource *res) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1254 | DavResource *child = res->children; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1255 | int count = 0; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1256 | while(child) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1257 | count++; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1258 | child = child->next; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1259 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1260 | return count; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1261 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1262 | |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1263 | int cmd_info(CmdArgs *a) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1264 | if(a->argc < 1) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1265 | fprintf(stderr, "Too few arguments\n"); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1266 | return -1; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1267 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1268 | |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1269 | char *url = a->argv[0]; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1270 | char *path = NULL; |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
1271 | DavSession *sn = connect_to_repo(url2repo(url, &path), a); |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1272 | |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1273 | if(set_session_config(sn, a)) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1274 | return -1; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1275 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1276 | |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1277 | DavResource *res = dav_resource_new(sn, path); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1278 | if(!dav_load(res)) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1279 | printf("name: %s\n", res->name); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1280 | printf("path: %s\n", res->path); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1281 | |
151
a316613205dc
fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
150
diff
changeset
|
1282 | char *server = util_url_base(sn->base_url); |
a316613205dc
fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
150
diff
changeset
|
1283 | char *url = util_concat_path(server, res->href); |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1284 | printf("url: %s\n", url); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1285 | free(url); |
151
a316613205dc
fixed some memory leaks, content verification and dav info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
150
diff
changeset
|
1286 | free(server); |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1287 | |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1288 | if(res->iscollection) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1289 | printf("type: collection\n"); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1290 | printf("size: %d\n", count_children(res)); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1291 | } else { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1292 | printf("type: resource\n"); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1293 | char *len = ls_size_str(res); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1294 | printf("size: %s\n", len); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1295 | free(len); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1296 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1297 | |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1298 | size_t count = 0; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1299 | DavPropName *properties = dav_get_property_names(res, &count); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1300 | |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1301 | char *last_ns = NULL; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1302 | for(int i=0;i<count;i++) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1303 | DavPropName p = properties[i]; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1304 | if(!last_ns || strcmp(last_ns, p.ns)) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1305 | printf("\nnamespace: %s\n", p.ns); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1306 | last_ns = p.ns; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1307 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1308 | |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1309 | sstr_t value = sstr(dav_get_property_ns(res, p.ns, p.name)); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1310 | value = sstrtrim(value); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1311 | printf(" %s: %.*s\n", p.name, (int)value.length, value.ptr); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1312 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1313 | |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1314 | dav_session_free(sn, properties); |
105
ee0de2b1872e
fixed control flow in int_cmd + committed testcase (enable with #define DO_THE_TEST)
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
1315 | return 0; |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1316 | } else { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1317 | print_resource_error(sn, res->path); |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1318 | return -1; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1319 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1320 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1321 | |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
1322 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1323 | char* stdin2str() { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1324 | UcxBuffer *buf = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1325 | size_t size = ucx_stream_hcopy(stdin, buf, fread, ucx_buffer_write); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1326 | if(size == 0) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1327 | ucx_buffer_free(buf); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1328 | return NULL; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1329 | } else { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1330 | ucx_buffer_putc(buf, '\0'); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1331 | char *str = buf->space; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1332 | free(buf); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1333 | return str; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1334 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1335 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1336 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1337 | |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
1338 | /* ---------- config commands ---------- */ |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
1339 | |
195
4b7823a58199
fixed add-repository function name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
194
diff
changeset
|
1340 | int cmd_add_repository(CmdArgs *args) { |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1341 | 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
|
1342 | char *name = assistant_getcfg("name"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1343 | if(!name) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1344 | fprintf(stderr, "Abort\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1345 | return -1; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1346 | } |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1347 | if(get_repository(sstr(name))) { |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
1348 | 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
|
1349 | return -1; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
1350 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
1351 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1352 | printf("\nSpecify the repository base url.\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1353 | char *url = assistant_getcfg("url"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1354 | if(!url) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1355 | fprintf(stderr, "Abort\n"); |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
1356 | return -1; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
1357 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
1358 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1359 | printf("\nUser for HTTP authentication.\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1360 | char *user = assistant_getoptcfg("user"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1361 | |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1362 | char *password = NULL; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1363 | if(user) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1364 | password = assistant_gethiddenoptcfg("password"); |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
1365 | } |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1366 | printf("\n"); |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
1367 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1368 | Repository repo; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1369 | memset(&repo, 0, sizeof(Repository)); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1370 | repo.name = name; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1371 | repo.url = url; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1372 | repo.user = user; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1373 | repo.password = password; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1374 | |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1375 | int ret = 0; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1376 | if(add_repository(&repo)) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1377 | fprintf(stderr, "Cannot write config.xml\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1378 | ret = -1; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1379 | } else { |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
1380 | 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
|
1381 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
1382 | |
197
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
1383 | free(name); |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
1384 | free(url); |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
1385 | if(user) { |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
1386 | free(user); |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
1387 | } |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
1388 | if(password) { |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
1389 | free(password); |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
1390 | } |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
1391 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1392 | return ret; |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
1393 | } |