Sun, 05 Jul 2020 11:47:24 +0200
adds support for option terminator '--'
also adds support for option arguments within the same cmd arg
e.g. -omyoutfile does now work
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 | * |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
609
diff
changeset
|
4 | * Copyright 2019 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 | |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
29 | #include <assert.h> |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <stdio.h> |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <stdlib.h> |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include <string.h> |
182
ca07f14f7bfe
added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
181
diff
changeset
|
33 | #include <stdbool.h> |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
34 | #include <errno.h> |
4 | 35 | #include <unistd.h> |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
36 | #include <time.h> |
4 | 37 | #include <sys/types.h> |
715
f4da6141e233
removes win32 support for dav edit
Mike Becker <universe@uap-core.de>
parents:
712
diff
changeset
|
38 | #ifndef _WIN32 |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
39 | #include <sys/wait.h> |
715
f4da6141e233
removes win32 support for dav edit
Mike Becker <universe@uap-core.de>
parents:
712
diff
changeset
|
40 | #endif |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
41 | #include <ucx/string.h> |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
42 | #include <ucx/utils.h> |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
43 | #include <dirent.h> |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
45 | #include <libidav/utils.h> |
40
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
46 | #include <libidav/crypto.h> |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
47 | #include <libidav/session.h> |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
355
diff
changeset
|
48 | #include <libidav/xml.h> |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
49 | #include "config.h" |
191
0e45b04236a7
more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
50 | #include "error.h" |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
51 | #include "assistant.h" |
410
0b9bea2d7283
adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
398
diff
changeset
|
52 | #include "system.h" |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
53 | #include "pwd.h" |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
54 | #include "finfo.h" |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | #include "main.h" |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
57 | static DavContext *ctx; |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
58 | |
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
59 | static int printxmlerror = 1; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
60 | 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
|
61 | if(printxmlerror) { |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
62 | va_list ap; |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
63 | va_start(ap, msg); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
64 | vfprintf(stderr, msg, ap); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
65 | va_end(ap); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
66 | } |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
69 | //define DO_THE_TEST |
363
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
70 | //include <libidav/davqlparser.h> |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
71 | //include <libidav/davqlexec.h> |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
72 | //include "tags.h" |
587
3c917df041b8
add func for creating the content of crypto-prop properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
540
diff
changeset
|
73 | //include <libidav/resource.h> |
363
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
74 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
75 | void test() { |
363
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
76 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
77 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
78 | |
687
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
79 | int dav_main(int argc, char **argv); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
80 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
81 | #ifdef _WIN32 |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
82 | static char* wchar2utf8(const wchar_t *wstr, size_t wlen) { |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
83 | size_t maxlen = wlen * 4; |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
84 | char *ret = malloc(maxlen + 1); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
85 | int ret_len = WideCharToMultiByte( |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
86 | CP_UTF8, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
87 | 0, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
88 | wstr, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
89 | wlen, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
90 | ret, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
91 | maxlen, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
92 | NULL, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
93 | NULL); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
94 | ret[ret_len] = 0; |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
95 | return ret; |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
96 | } |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
97 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
98 | int wmain(int argc, wchar_t **argv) { |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
99 | char **argv_utf8 = calloc(argc, sizeof(char*)); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
100 | for(int i=0;i<argc;i++) { |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
101 | argv_utf8[i] = wchar2utf8(argv[i], wcslen(argv[i])); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
102 | } |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
103 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
104 | int ret = dav_main(argc, argv_utf8); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
105 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
106 | for(int i=0;i<argc;i++) { |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
107 | free(argv_utf8[i]); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
108 | } |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
109 | free(argv_utf8); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
110 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
111 | return ret; |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
112 | } |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
113 | #else |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | int main(int argc, char **argv) { |
687
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
115 | return dav_main(argc, argv); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
116 | } |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
117 | #endif |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
118 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
119 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
120 | int dav_main(int argc, char **argv) { |
34
1b87b3b1921e
removed debug code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
121 | if(argc < 2) { |
11 | 122 | fprintf(stderr, "Missing command\n"); |
123 | print_usage(argv[0]); | |
124 | return -1; | |
125 | } | |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
126 | |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
127 | putenv("LC_TIME=C"); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
128 | |
34
1b87b3b1921e
removed debug code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
129 | char *cmd = argv[1]; |
1b87b3b1921e
removed debug code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
130 | CmdArgs *args = cmd_parse_args(argc - 2, argv + 2); |
11 | 131 | if(!args) { |
132 | print_usage(argv[0]); | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | return -1; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
609
diff
changeset
|
136 | sys_init(); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
137 | xmlGenericErrorFunc fnc = xmlerrorfnc; |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
138 | initGenericErrorDefaultFunc(&fnc); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
139 | ctx = dav_context_new(); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
140 | dav_add_namespace(ctx, "apache", "http://apache.org/dav/props/"); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
141 | int cfgret = load_config(ctx); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
142 | int ret = EXIT_FAILURE; |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
143 | printxmlerror = 0; |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
144 | #ifdef DO_THE_TEST |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
145 | test(); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
146 | return 0; |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
147 | #endif |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
148 | if(!strcmp(cmd, "check") || !strcmp(cmd, "check-config")) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
149 | if(!cfgret) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
150 | fprintf(stdout, "Configuration OK.\n"); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
151 | ret = EXIT_SUCCESS; |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
152 | } else { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
153 | /* no output, the warnings are written by load_config */ |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
154 | ret = EXIT_FAILURE; |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
155 | } |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
156 | } else if(!cfgret) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
157 | if(!strcasecmp(cmd, "list") || !strcasecmp(cmd, "ls")) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
158 | ret = cmd_list(args); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
159 | } else if(!strcasecmp(cmd, "get")) { |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
160 | ret = cmd_get(args, FALSE); |
511
59a216f8d4e8
adds command alias 'cat' for 'get -o -'
Mike Becker <universe@uap-core.de>
parents:
510
diff
changeset
|
161 | } else if(!strcasecmp(cmd, "cat")) { |
59a216f8d4e8
adds command alias 'cat' for 'get -o -'
Mike Becker <universe@uap-core.de>
parents:
510
diff
changeset
|
162 | ucx_map_cstr_put(args->options, "output", "-"); |
59a216f8d4e8
adds command alias 'cat' for 'get -o -'
Mike Becker <universe@uap-core.de>
parents:
510
diff
changeset
|
163 | ret = cmd_get(args, FALSE); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
164 | } else if(!strcasecmp(cmd, "edit")) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
165 | ret = cmd_edit(args); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
166 | } else if(!strcasecmp(cmd, "put")) { |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
167 | ret = cmd_put(args, FALSE); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
168 | } else if( |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
169 | !strcasecmp(cmd, "remove") || |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
170 | !strcasecmp(cmd, "rm") || |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
171 | !strcasecmp(cmd, "delete")) |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
172 | { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
173 | ret = cmd_remove(args); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
174 | } else if(!strcasecmp(cmd, "mkdir") || !strcasecmp(cmd, "mkcol")) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
175 | ret = cmd_mkdir(args); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
176 | } else if(!strcasecmp(cmd, "copy") || !strcasecmp(cmd, "cp")) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
177 | ret = cmd_move(args, true); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
178 | } else if(!strcasecmp(cmd, "move") || !strcasecmp(cmd, "mv")) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
179 | ret = cmd_move(args, false); |
498
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
180 | } else if(!strcasecmp(cmd, "rename")) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
181 | ret = cmd_rename(args); |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
182 | } else if(!strcasecmp(cmd, "export")) { |
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
183 | ret = cmd_get(args, TRUE); |
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
184 | } else if(!strcasecmp(cmd, "import")) { |
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
185 | ret = cmd_put(args, TRUE); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
186 | } else if(!strcasecmp(cmd, "date")) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
187 | ret = cmd_date(args); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
188 | } else if(!strcasecmp(cmd, "set-property")) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
189 | ret = cmd_set_property(args); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
190 | } else if(!strcasecmp(cmd, "get-property")) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
191 | ret = cmd_get_property(args); |
304
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
192 | } else if(!strcasecmp(cmd, "remove-property")) { |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
193 | ret = cmd_remove_property(args); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
194 | } else if(!strcasecmp(cmd, "lock")) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
195 | ret = cmd_lock(args); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
196 | } else if(!strcasecmp(cmd, "unlock")) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
197 | ret = cmd_unlock(args); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
198 | } else if(!strcasecmp(cmd, "info")) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
199 | ret = cmd_info(args); |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
200 | } else if(!strcasecmp(cmd, "checkout")) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
201 | ret = cmd_checkout(args); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
202 | } else if(!strcasecmp(cmd, "checkin")) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
203 | ret = cmd_checkin(args); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
204 | } else if(!strcasecmp(cmd, "uncheckout")) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
205 | ret = cmd_uncheckout(args); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
206 | } else if(!strcasecmp(cmd, "versioncontrol")) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
207 | ret = cmd_versioncontrol(args); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
208 | } else if(!strcasecmp(cmd, "list-versions") || !strcasecmp(cmd, "lsv")) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
209 | ret = cmd_list_versions(args); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
210 | } else if(!strcasecmp(cmd, "add-repository") |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
211 | || !strcasecmp(cmd, "add-repo")) { |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
212 | ret = cmd_add_repository(args); |
398
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
213 | } else if(!strcasecmp(cmd, "remove-repository") |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
214 | || !strcasecmp(cmd, "remove-repo") |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
215 | || !strcasecmp(cmd, "rm-repo")) { |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
216 | ret = cmd_remove_repository(args); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
217 | } else if(!strcasecmp(cmd, "list-repositories") |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
218 | || !strcasecmp(cmd, "list-repos")) { |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
219 | ret = list_repositories(); |
419
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
220 | } else if(!strcasecmp(cmd, "repository-url") |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
221 | || !strcasecmp(cmd, "repo-url")) { |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
222 | ret = cmd_repository_url(args); |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
223 | } else if(!strcasecmp(cmd, "add-user")) { |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
224 | ret = cmd_add_user(args); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
225 | } else if(!strcasecmp(cmd, "list-users")) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
226 | ret = cmd_list_users(args); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
227 | } else if(!strcasecmp(cmd, "remove-user")) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
228 | ret = cmd_remove_user(args); |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
229 | } else if(!strcasecmp(cmd, "edit-user")) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
230 | ret = cmd_edit_user(args); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
231 | } else if(!strcasecmp(cmd, "version") || !strcasecmp(cmd, "-version") |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
232 | || !strcasecmp(cmd, "--version")) { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
233 | fprintf(stderr, "dav %s\n", DAV_VERSION); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
234 | } else if(!strcasecmp(cmd, "complete")) { |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
235 | ret = cmd_complete(args); |
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
236 | } else { |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
237 | print_usage(argv[0]); |
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
241
diff
changeset
|
238 | } |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | } |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
240 | |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
241 | dav_context_destroy(ctx); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
242 | cmd_args_free(args); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
243 | free_config(); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
244 | xmlCleanupParser(); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
245 | curl_global_cleanup(); |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
609
diff
changeset
|
246 | sys_uninit(); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
248 | return ret; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
251 | static char *cmdusageinfo[] = { |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
252 | "list [-altdepcR] [-u <date>] <url>", |
476
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
253 | "get [-pcRK] [-o <file>] [-u <date>] [-V <version>] <url>", |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
254 | "put [-pcR] [-k <key>] [-L <lock>] <url> <file...>", |
720
2b8a65ed6f4c
adds support for -L option in dav edit
Mike Becker <universe@uap-core.de>
parents:
719
diff
changeset
|
255 | "edit [-pc] [-k <key>] [-V <version>] [-L <lock>] <url>", |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
256 | "mkdir [-pc] [-k <key>] [-L <lock>] <url> [file...]", |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
257 | "remove [-pc] [-L <lock>] <url> [file...]", |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
258 | "copy [-pcO] [-L <lock>] <url> <url>", |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
259 | "move [-pcO] [-L <lock>] <url> <url>", |
498
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
260 | "rename [-pcO] [-L <lock>] <url> <name>", |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
261 | "export [-pc] [-o <file>] [-u <date>] <url>", |
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
262 | "import [-pc] [-k <key>] [-L <lock>] <url> <file>", |
476
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
263 | "get-property [-pcx] [-V <version>] [-n <uri>] <url> <property>", |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
264 | "set-property [-pcx] [-L <lock>] [-n <uri>] <url> <property> [value]", |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
265 | "remove-property [-pc] [-n <uri>] <url> <property>", |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
266 | "lock [-pc] [-T timeout] <url>", |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
267 | "unlock [-pc] [-L <lock>] <url>", |
476
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
268 | "info [-pc] [-V <version>] <url>", |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
269 | "date [url]", |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
270 | NULL |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
271 | }; |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
272 | |
384
8bfde5687890
fixes definite chance of a memory leak in cmd_unlock() + marks a further possible source of memory leaks
Mike Becker <universe@uap-core.de>
parents:
383
diff
changeset
|
273 | char* find_usage_str(const char *cmd) { |
508
4575da18a27d
fixes todo: use scstr instead of sstr
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
274 | scstr_t c = scstr(cmd); |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
275 | for(int i=0;;i++) { |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
276 | char *str = cmdusageinfo[i]; |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
277 | if(!str) { |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
278 | break; |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
279 | } |
508
4575da18a27d
fixes todo: use scstr instead of sstr
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
280 | scstr_t u = scstr(str); |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
281 | if(sstrprefix(u, c)) { |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
282 | return str; |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
283 | } |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
284 | } |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
285 | return NULL; |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
286 | } |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
287 | |
11 | 288 | void print_usage(char *cmd) { |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
289 | fprintf(stderr, "Usage: %s command [options] arguments...\n\n", cmd); |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
290 | |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
291 | fprintf(stderr, "Commands:\n"); |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
292 | for(int i=0;;i++) { |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
293 | char *str = cmdusageinfo[i]; |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
294 | if(!str) { |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
295 | break; |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
296 | } |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
297 | fprintf(stderr, " %s\n", str); |
511
59a216f8d4e8
adds command alias 'cat' for 'get -o -'
Mike Becker <universe@uap-core.de>
parents:
510
diff
changeset
|
298 | } |
11 | 299 | fprintf(stderr, "Options:\n"); |
300 | fprintf(stderr, | |
703
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
301 | " -k <key> Key to use for encryption\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
302 | fprintf(stderr, " -p Don't encrypt or decrypt files\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
303 | fprintf(stderr, " -c Enable full encryption\n"); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
304 | fprintf(stderr, |
703
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
305 | " -R " |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
306 | "Recursively do the operation for all children\n"); |
703
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
307 | fprintf(stderr, " -K Keep already present files\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
308 | fprintf(stderr, " -o <file> Write output to file (use '-' for stdout)\n"); |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
309 | fprintf( |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
310 | stderr, |
703
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
311 | " -u <date> " |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
312 | "Get resources which are modified since the specified date\n"); |
703
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
313 | fprintf(stderr, " -V <version> Download a specific version of a resource\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
314 | fprintf(stderr, " -a show all files\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
315 | fprintf(stderr, " -l print resources in long list format\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
316 | fprintf(stderr, " -t print content type\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
317 | fprintf(stderr, " -d order by last modified date\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
318 | fprintf(stderr, " -e show extended flags\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
319 | fprintf(stderr, " -O override resources\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
320 | fprintf(stderr, " -L <lock> specificy lock token\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
321 | fprintf(stderr, " -T <sec> timeout in seconds\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
322 | fprintf(stderr, " -n <uri> specify namespace uri\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
323 | fprintf(stderr, " -x xml property content\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
324 | fprintf(stderr, " -N disable authentication prompt (all commands)\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
325 | fprintf(stderr, " -i disable cert verification (all commands)\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
326 | fprintf(stderr, " -v verbose output (all commands)\n"); |
11 | 327 | fprintf(stderr, "\n"); |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
328 | fprintf(stderr, "Advanced commands:\n"); |
507
dea7d1b4eea0
nicer dav usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
500
diff
changeset
|
329 | fprintf(stderr, " versioncontrol list-versions checkout checkin uncheckout\n\n"); |
198
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
197
diff
changeset
|
330 | fprintf(stderr, "Config commands:\n"); |
507
dea7d1b4eea0
nicer dav usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
500
diff
changeset
|
331 | fprintf(stderr, " add-repository remove-repository list-repositories repository-url\n"); |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
332 | fprintf(stderr, " add-user remove-user edit-user list-users\n"); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
333 | fprintf(stderr, " check-config\n"); |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
334 | fprintf(stderr, "\n"); |
11 | 335 | fprintf(stderr, |
336 | "Instead of an url you can pass a repository name " | |
337 | "with an optional path:\n"); | |
338 | fprintf(stderr, " <repository>/path/\n"); | |
339 | fprintf(stderr, "\n"); | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
342 | |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
343 | int request_auth2(DavSession *sn, void *userdata) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
344 | Repository *repo = userdata; |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
345 | |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
346 | char *user = NULL; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
347 | char ubuf[256]; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
348 | if(repo->user) { |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
349 | user = repo->user; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
350 | } else { |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
351 | fprintf(stderr, "User: "); |
146
e48048334602
hidden password input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
352 | fflush(stderr); |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
353 | user = fgets(ubuf, 256, stdin); |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
354 | } |
258
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
355 | if(!user) { |
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
356 | return 0; |
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
357 | } |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
358 | |
150
37fb12574acd
added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
359 | char *password = util_password_input("Password: "); |
258
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
360 | if(!password || strlen(password) == 0) { |
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
361 | return 0; |
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
362 | } |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
363 | |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
364 | size_t ulen = strlen(user); |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
365 | if(user[ulen-1] == '\n') { |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
366 | user[ulen-1] = '\0'; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
367 | } |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
368 | |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
369 | dav_session_set_auth(sn, user, password); |
146
e48048334602
hidden password input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
370 | free(password); |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
371 | |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
372 | return 0; |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
373 | } |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
374 | |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
375 | static Repository* url2repo_s(sstr_t url, char **path) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
376 | *path = NULL; |
4 | 377 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
378 | int s; |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
379 | if(sstrprefix(url, SC("http://"))) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
380 | s = 7; |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
381 | } else if(sstrprefix(url, SC("https://"))) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
382 | s = 8; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
383 | } else { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
384 | s = 1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
385 | } |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
386 | |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
387 | // split URL into repository and path |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
388 | sstr_t r = sstrsubs(url, s); |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
389 | sstr_t p = sstrchr(r, '/'); |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
390 | r = sstrsubsl(url, 0, url.length-p.length); |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
391 | if(p.length == 0) { |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
392 | p = sstrn("/", 1); |
4 | 393 | } |
394 | ||
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
395 | Repository *repo = get_repository(r); |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
396 | if(repo) { |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
397 | *path = sstrdup(p).ptr; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
398 | } else { |
384
8bfde5687890
fixes definite chance of a memory leak in cmd_unlock() + marks a further possible source of memory leaks
Mike Becker <universe@uap-core.de>
parents:
383
diff
changeset
|
399 | // TODO: who is responsible for freeing this repository? |
8bfde5687890
fixes definite chance of a memory leak in cmd_unlock() + marks a further possible source of memory leaks
Mike Becker <universe@uap-core.de>
parents:
383
diff
changeset
|
400 | // how can the callee know, if he has to call free()? |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
401 | repo = calloc(1, sizeof(Repository)); |
70 | 402 | repo->name = strdup(""); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
403 | repo->decrypt_content = true; |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
201
diff
changeset
|
404 | repo->verification = true; |
187
38295f2fa231
added missing repo authmethods initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
405 | repo->authmethods = CURLAUTH_BASIC; |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
406 | if(url.ptr[url.length-1] == '/') { |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
407 | repo->url = sstrdup(url).ptr; |
70 | 408 | *path = strdup("/"); |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
409 | } else if (sstrchr(url, '/').length > 0) { |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
410 | // TODO: fix the following workaround after |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
411 | // fixing the inconsistent behavior of util_url_*() |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
412 | repo->url = util_url_base_s(url); |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
413 | sstr_t truncated = sstrdup(url); |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
414 | *path = strdup(util_url_path(truncated.ptr)); |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
415 | free(truncated.ptr); |
100
f4127c4d1018
improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
416 | } else { |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
417 | repo->url = sstrdup(url).ptr; |
100
f4127c4d1018
improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
84
diff
changeset
|
418 | *path = strdup("/"); |
70 | 419 | } |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
420 | } |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
421 | |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
422 | return repo; |
4 | 423 | } |
424 | ||
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
425 | static Repository* url2repo(char *url, char **path) { |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
426 | return url2repo_s(sstr(url), path); |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
427 | } |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
428 | |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
429 | 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
|
430 | char *plain = cmd_getoption(a, "plain"); |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
431 | char *crypt = cmd_getoption(a, "crypt"); |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
432 | |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
433 | if(plain && crypt) { |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
434 | 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
|
435 | return 1; |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
436 | } |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
437 | |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
438 | if (plain) { |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
439 | sn->flags &= ~DAV_SESSION_FULL_ENCRYPTION; |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
440 | } else if(crypt) { |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
441 | sn->flags |= DAV_SESSION_FULL_ENCRYPTION; |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
442 | } |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
443 | |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
444 | if (cmd_getoption(a, "verbose")) { |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
445 | 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
|
446 | 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
|
447 | } |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
448 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
449 | return 0; |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
450 | } |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
451 | |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
452 | 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
|
453 | char *locktoken = cmd_getoption(a, "lock"); |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
454 | if(locktoken) { |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
455 | 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
|
456 | dav_add_collection_lock(sn, "/", lock); |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
457 | } |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
458 | } |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
459 | |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
460 | static int decrypt_secrets(CmdArgs *a, PwdStore *secrets) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
461 | if(cmd_getoption(a, "noinput")) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
462 | return 1; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
463 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
464 | |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
465 | char *ps_password = util_password_input("Master password: "); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
466 | if(!ps_password) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
467 | return 1; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
468 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
469 | if(pwdstore_setpassword(secrets, ps_password)) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
470 | fprintf(stderr, "Error: cannot create key from password\n"); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
471 | return 1; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
472 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
473 | if(pwdstore_decrypt(secrets)) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
474 | fprintf(stderr, "Error: cannot decrypt secrets store\n"); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
475 | return 1; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
476 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
477 | return 0; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
478 | } |
472
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
479 | |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
480 | static int get_stored_credentials(CmdArgs *a, char *credid, char **user, char **password) { |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
481 | if(!credid) { |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
482 | return 0; |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
483 | } |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
484 | |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
485 | PwdStore *secrets = get_pwdstore(); |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
486 | if(!secrets) { |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
487 | fprintf(stderr, "Error: no secrets store available\n"); |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
488 | return 0; |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
489 | } |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
490 | |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
491 | if(pwdstore_has_id(secrets, credid)) { |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
492 | if(!secrets->isdecrypted) { |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
493 | if(decrypt_secrets(a, secrets)) { |
472
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
494 | return 0; |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
495 | } |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
496 | } |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
497 | |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
498 | PwdEntry *s_cred = pwdstore_get(secrets, credid); |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
499 | if(s_cred) { |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
500 | *user = s_cred->user; |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
501 | *password = s_cred->password; |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
502 | return 1; |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
503 | } |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
504 | } else { |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
505 | fprintf(stderr, "Error: credentials id '%s' not found\n", credid); |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
506 | } |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
507 | |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
508 | return 0; |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
509 | } |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
510 | |
489
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
511 | typedef struct CredLocation { |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
512 | char *id; |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
513 | char *location; |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
514 | } CredLocation; |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
515 | |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
516 | static int cmp_url_cred_entry(CredLocation *e1, CredLocation *e2, void *n) { |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
517 | return strcmp(e2->location, e1->location); |
472
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
518 | } |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
519 | |
489
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
520 | static void free_cred_location(CredLocation *c) { |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
521 | // c->id is not a copy, therefore we don't have to free it |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
522 | free(c->location); |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
523 | free(c); |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
524 | } |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
525 | |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
526 | static int get_location_credentials(CmdArgs *a, Repository *repo, char *path, char **user, char **password) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
527 | PwdStore *secrets = get_pwdstore(); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
528 | if(!secrets) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
529 | return 0; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
530 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
531 | |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
532 | /* |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
533 | * The list secrets->location contains urls or repo names as |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
534 | * location strings. We need a list, that contains only urls |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
535 | */ |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
536 | UcxList *locations = NULL; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
537 | UCX_FOREACH(elm, secrets->locations) { |
474
017a4f09e6fa
improves secret store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
473
diff
changeset
|
538 | PwdIndexEntry *e = elm->data; |
489
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
539 | |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
540 | UCX_FOREACH(loc, e->locations) { |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
541 | char *path; |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
542 | Repository *r = url2repo(loc->data, &path); |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
543 | CredLocation *urlentry = calloc(1, sizeof(CredLocation)); |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
544 | urlentry->id = e->id; |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
545 | urlentry->location = util_concat_path(r->url, path); |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
546 | locations = ucx_list_append(locations, urlentry); |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
547 | } |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
548 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
549 | // the list must be sorted |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
550 | locations = ucx_list_sort(locations, (cmp_func)cmp_url_cred_entry, NULL); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
551 | |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
552 | // create full request url string and remove protocol prefix |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
553 | sstr_t req_url_proto = sstr(util_concat_path(repo->url, path)); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
554 | sstr_t req_url = req_url_proto; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
555 | if(sstrprefix(req_url, S("http://"))) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
556 | req_url = sstrsubs(req_url, 7); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
557 | } else if(sstrprefix(req_url, S("https://"))) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
558 | req_url = sstrsubs(req_url, 8); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
559 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
560 | |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
561 | // iterate over sorted locations and check if a location is a prefix |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
562 | // of the requested url |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
563 | char *id = NULL; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
564 | int ret = 0; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
565 | UCX_FOREACH(elm, locations) { |
489
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
566 | CredLocation *cred = elm->data; |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
567 | sstr_t cred_url = sstr(cred->location); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
568 | |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
569 | // remove protocol prefix |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
570 | if(sstrprefix(cred_url, S("http://"))) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
571 | cred_url = sstrsubs(cred_url, 7); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
572 | } else if(sstrprefix(cred_url, S("https://"))) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
573 | cred_url = sstrsubs(cred_url, 8); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
574 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
575 | |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
576 | if(sstrprefix(req_url, cred_url)) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
577 | id = cred->id; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
578 | break; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
579 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
580 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
581 | |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
582 | // if an id is found and we can access the decrypted secret store |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
583 | // we can set the user/password |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
584 | if(id && (secrets->isdecrypted || !decrypt_secrets(a, secrets))) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
585 | PwdEntry *cred = pwdstore_get(secrets, id); |
674
92bf06a65d08
increase security in case of broken secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
673
diff
changeset
|
586 | if(cred) { |
92bf06a65d08
increase security in case of broken secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
673
diff
changeset
|
587 | *user = cred->user; |
92bf06a65d08
increase security in case of broken secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
673
diff
changeset
|
588 | *password = cred->password; |
92bf06a65d08
increase security in case of broken secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
673
diff
changeset
|
589 | ret = 1; |
92bf06a65d08
increase security in case of broken secret stores
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
673
diff
changeset
|
590 | } |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
591 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
592 | |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
593 | free(req_url_proto.ptr); |
489
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
594 | ucx_list_free_content(locations, (ucx_destructor)free_cred_location); |
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
595 | ucx_list_free(locations); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
596 | |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
597 | return ret; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
598 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
599 | |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
600 | static DavSession* connect_to_repo(Repository *repo, char *path, CmdArgs *a) { |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
601 | char *user = repo->user; |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
602 | char *password = repo->password; |
472
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
603 | |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
604 | if(!user && !password) { |
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
605 | if(!get_stored_credentials(a, repo->stored_user, &user, &password)) { |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
606 | get_location_credentials(a, repo, path, &user, &password); |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
607 | } |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
608 | } |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
609 | |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
610 | DavSession *sn = dav_session_new_auth(ctx, repo->url, user, password); |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
611 | sn->flags = get_repository_flags(repo); |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
612 | 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
|
613 | 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
|
614 | 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
|
615 | if(repo->cert) { |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
616 | curl_easy_setopt(sn->handle, CURLOPT_CAINFO, repo->cert); |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
617 | } |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
618 | if(!repo->verification || cmd_getoption(a, "insecure")) { |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
619 | curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYPEER, 0); |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
620 | curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0); |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
621 | } |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
622 | if(!cmd_getoption(a, "noinput")) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
623 | dav_session_set_authcallback(sn, request_auth2, repo); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
624 | } |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
625 | return sn; |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
626 | } |
4 | 627 | |
355
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
628 | int update_progress(DavResource *res, int64_t total, int64_t now, Progress *p) { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
629 | int ret = 0; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
630 | if(res != p->last_resource) { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
631 | p->cur += p->last_res_total - p->last_res_cur; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
632 | ret = 1; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
633 | } else { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
634 | p->cur += now - p->last_res_cur; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
635 | } |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
636 | |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
637 | p->last_resource = res; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
638 | p->last_res_cur = now; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
639 | p->last_res_total = total; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
640 | |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
641 | return ret; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
642 | } |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
643 | |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
644 | void download_progress(DavResource *res, int64_t total, int64_t now, void *data) { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
645 | Progress *p = data; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
646 | int newres = update_progress(res, total, now, p); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
647 | |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
648 | time_t newts = time(NULL); |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
649 | if((p->ts != newts)) { |
355
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
650 | fprintf(p->out, "[%s]: %" PRId64 "k/%" PRId64 "k total: %" PRId64 "M/%" PRId64 "M\n", res->name, now/1024, total/1024, p->cur/(1024*1024), p->total/(1024*1024)); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
651 | fflush(p->out); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
652 | } |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
653 | p->ts = newts; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
654 | } |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
655 | |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
656 | |
297
3cbe57eeaed1
adds option to sort dav list by lastmodified date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
271
diff
changeset
|
657 | #define LIST_QUERY_ORDER_BY_NAME "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery,apache:executable from %s with depth = %d where lastmodified > %t order by iscollection desc, name" |
3cbe57eeaed1
adds option to sort dav list by lastmodified date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
271
diff
changeset
|
658 | #define LIST_QUERY_ORDER_BY_DATE "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery,apache:executable from %s with depth = %d where lastmodified > %t order by iscollection desc, lastmodified desc" |
3cbe57eeaed1
adds option to sort dav list by lastmodified date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
271
diff
changeset
|
659 | |
11 | 660 | int cmd_list(CmdArgs *a) { |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
661 | if(a->argc != 1) { |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
662 | fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
663 | fprintf(stderr, "Usage: dav %s\n", find_usage_str("list")); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
664 | return -1; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
665 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
666 | |
11 | 667 | 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
|
668 | char *path = NULL; |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
669 | Repository *repo = url2repo(url, &path); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
670 | DavSession *sn = connect_to_repo(repo, path, a); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
671 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
672 | if(set_session_config(sn, a)) { |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
673 | return -1; |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
674 | } |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
675 | |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
676 | char *update = cmd_getoption(a, "update"); |
297
3cbe57eeaed1
adds option to sort dav list by lastmodified date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
271
diff
changeset
|
677 | char *date = cmd_getoption(a, "date"); |
136
59058927b885
empty field results will no longer be added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
678 | time_t t = -1; |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
679 | if(update) { |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
680 | t = util_parse_lastmodified(update); |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
681 | } |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
682 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
683 | int depth = cmd_getoption(a, "recursive") ? -1 : 1; |
425
ae4d89c3477c
fixes dav list return value
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
421
diff
changeset
|
684 | int ret = 0; |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
685 | DavResource *ls = dav_query( |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
686 | sn, |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
687 | date ? LIST_QUERY_ORDER_BY_DATE : LIST_QUERY_ORDER_BY_NAME, |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
688 | path, |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
689 | depth, |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
690 | t); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
691 | if(ls) { |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
692 | // parameters |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
693 | void (*print_func)(DavResource*, char *, CmdArgs *); |
213
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
694 | 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
|
695 | print_func = ls_print_list_elm; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
696 | } else { |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
697 | print_func = ls_print_elm; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
698 | } |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
699 | |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
700 | DavResource *child = ls->children; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
701 | while(child) { |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
702 | print_func(child, path, a); |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
703 | child = child->next; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
704 | } |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
705 | } else { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
706 | print_resource_error(sn, path); |
425
ae4d89c3477c
fixes dav list return value
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
421
diff
changeset
|
707 | ret = -1; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
708 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
709 | |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
710 | free(path); |
40
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
711 | //free(base); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
712 | |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
713 | dav_session_destroy(sn); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
714 | |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
715 | return ret; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
716 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
717 | |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
718 | 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
|
719 | struct tm t; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
720 | struct tm n; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
721 | time_t now = time(NULL); |
32 | 722 | #ifdef _WIN32 |
723 | memcpy(&t, localtime(&tm), sizeof(struct tm)); | |
724 | memcpy(&n, localtime(&now), sizeof(struct tm)); | |
725 | #else | |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
726 | localtime_r(&tm, &t); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
727 | localtime_r(&now, &n); |
32 | 728 | #endif /* _WIN32 */ |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
729 | char *str = malloc(16); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
730 | if(t.tm_year == n.tm_year) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
731 | 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
|
732 | } else { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
733 | strftime(str, 16, "%b %d %Y", &t); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
734 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
735 | return str; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
736 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
737 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
738 | static char* ls_size_str(DavResource *res) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
739 | char *str = malloc(16); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
740 | uint64_t size = res->contentlength; |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
741 | |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
742 | if(res->iscollection) { |
165
b66bed169fc3
fixed zero-length format string in ls_size_str
Mike Becker <universe@uap-core.de>
parents:
154
diff
changeset
|
743 | 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
|
744 | } else if(size < 0x400) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
745 | snprintf(str, 16, "%" PRIu64 " bytes", size); |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
746 | } else if(size < 0x100000) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
747 | float s = (float)size/0x400; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
748 | int diff = (s*100 - (int)s*100); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
749 | if(diff > 90) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
750 | diff = 0; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
751 | s += 0.10f; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
752 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
753 | if(size < 0x2800 && diff != 0) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
754 | // size < 10 KiB |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
755 | snprintf(str, 16, "%.1f KiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
756 | } else { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
757 | snprintf(str, 16, "%.0f KiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
758 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
759 | } else if(size < 0x40000000) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
760 | float s = (float)size/0x100000; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
761 | int diff = (s*100 - (int)s*100); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
762 | if(diff > 90) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
763 | diff = 0; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
764 | s += 0.10f; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
765 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
766 | if(size < 0xa00000 && diff != 0) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
767 | // size < 10 MiB |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
768 | snprintf(str, 16, "%.1f MiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
769 | } else { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
770 | size /= 0x100000; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
771 | snprintf(str, 16, "%.0f MiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
772 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
773 | } else if(size < 0x1000000000ULL) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
774 | float s = (float)size/0x40000000; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
775 | int diff = (s*100 - (int)s*100); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
776 | if(diff > 90) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
777 | diff = 0; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
778 | s += 0.10f; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
779 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
780 | if(size < 0x280000000 && diff != 0) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
781 | // size < 10 GiB |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
782 | snprintf(str, 16, "%.1f GiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
783 | } else { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
784 | size /= 0x40000000; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
785 | snprintf(str, 16, "%.0f GiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
786 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
787 | } else { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
788 | size /= 1024; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
789 | float s = (float)size/0x40000000; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
790 | int diff = (s*100 - (int)s*100); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
791 | if(diff > 90) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
792 | diff = 0; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
793 | s += 0.10f; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
794 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
795 | if(size < 0x280000000 && diff != 0) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
796 | // size < 10 TiB |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
797 | snprintf(str, 16, "%.1f TiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
798 | } else { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
799 | size /= 0x40000000; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
800 | snprintf(str, 16, "%.0f TiB", s); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
801 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
802 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
803 | return str; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
804 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
805 | |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
806 | static char* ls_name(char *parent, char *path, int *len) { |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
807 | if(parent) { |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
808 | path += strlen(parent); |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
809 | } |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
810 | if(path[0] == '/') { |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
811 | path++; |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
812 | } |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
813 | int pathlen = strlen(path); |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
814 | if(path[pathlen-1] == '/') { |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
815 | pathlen--; |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
816 | } |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
817 | *len = pathlen; |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
818 | return path; |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
819 | } |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
820 | |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
821 | void ls_print_list_elm(DavResource *res, char *parent, CmdArgs *a) { |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
822 | 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
|
823 | 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
|
824 | 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
|
825 | return; |
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
826 | } |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
827 | |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
828 | char flags[16]; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
829 | memset(flags, '-', 15); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
830 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
831 | int type_width = 0; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
832 | char *type = res->contenttype; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
833 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
834 | if(res->iscollection) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
835 | flags[0] = 'd'; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
836 | type = ""; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
837 | } |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
330
diff
changeset
|
838 | char *keyprop = dav_get_string_property_ns( |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
839 | res, |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
840 | DAV_NS, |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
841 | "crypto-key"); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
842 | if(keyprop) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
843 | flags[1] = 'c'; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
844 | } |
213
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
845 | |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
846 | 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
|
847 | flags[6] = '\0'; |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
330
diff
changeset
|
848 | if(dav_get_string_property(res, "D:lockdiscovery")) { |
213
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
849 | flags[2] = 'l'; |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
850 | } |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
330
diff
changeset
|
851 | char *executable = dav_get_string_property_ns( |
213
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
852 | res, |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
853 | "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
|
854 | "executable"); |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
855 | 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
|
856 | flags[3] = 'x'; |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
857 | } |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
858 | } else { |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
859 | flags[2] = '\0'; |
211
3d12817414e9
dav list indicates locks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
860 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
861 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
862 | if(cmd_getoption(a, "type")) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
863 | type_width = 20; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
864 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
865 | if(type == NULL || type_width == 0) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
866 | type = ""; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
867 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
868 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
869 | char *date = ls_date_str(res->lastmodified); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
870 | char *size = ls_size_str(res); |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
871 | int namelen = strlen(res->name); |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
872 | char *name = recursive ? ls_name(parent, res->path, &namelen) : res->name; |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
873 | |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
874 | //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
|
875 | printf( |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
876 | "%s %*s %10s %12s %.*s\n", |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
877 | flags, |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
878 | type_width, type, |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
879 | size, |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
880 | date, |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
881 | namelen, |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
882 | name); |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
883 | free(date); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
884 | free(size); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
885 | |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
886 | if(recursive) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
887 | DavResource *child = res->children; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
888 | while(child) { |
138
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
889 | //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
|
890 | if(child->name[0] != '.' || show_all) { |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
891 | ls_print_list_elm(child, parent, a); |
138
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
892 | } |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
893 | child = child->next; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
894 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
895 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
896 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
897 | |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
898 | void ls_print_elm(DavResource *res, char *parent, CmdArgs *a) { |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
899 | 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
|
900 | 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
|
901 | 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
|
902 | return; |
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
903 | } |
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
904 | |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
905 | int namelen = strlen(res->name); |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
906 | char *name = recursive ? ls_name(parent, res->path, &namelen) : res->name; |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
907 | printf("%.*s\n", namelen, name); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
908 | if(recursive) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
909 | DavResource *child = res->children; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
910 | while(child) { |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
911 | ls_print_elm(child, parent, a); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
912 | child = child->next; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
913 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
914 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
915 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
916 | |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
917 | static void free_getres(void *r) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
918 | GetResource *getres = r; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
919 | free(getres->path); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
920 | free(getres); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
921 | } |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
922 | |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
923 | int cmd_get(CmdArgs *a, DavBool export) { |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
924 | if(a->argc != 1) { |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
925 | // 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
|
926 | fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
927 | fprintf(stderr, "Usage: dav %s\n", find_usage_str("get")); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
928 | return -1; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
929 | } |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
930 | if(export) { |
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
931 | ucx_map_cstr_put(a->options, "recursive", ""); |
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
932 | } |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
933 | |
11 | 934 | 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
|
935 | char *path = NULL; |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
936 | Repository *repo = url2repo(url, &path); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
937 | DavSession *sn = connect_to_repo(repo, path, a); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
938 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
939 | if(set_session_config(sn, a)) { |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
940 | return -1; |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
941 | } |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
942 | |
355
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
943 | char *progressfile = cmd_getoption(a, "progressfile"); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
944 | Progress pdata; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
945 | memset(&pdata, 0, sizeof(Progress)); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
946 | if(progressfile) { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
947 | if(!strcmp(progressfile, "-")) { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
948 | pdata.out = stdout; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
949 | pdata.isstdout = 1; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
950 | } else { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
951 | pdata.out = fopen(progressfile, "w"); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
952 | } |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
953 | if(pdata.out) { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
954 | dav_session_set_progresscallback(sn, download_progress, NULL, &pdata); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
955 | } |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
956 | } |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
957 | |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
958 | char *update = cmd_getoption(a, "update"); |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
959 | time_t t = -1; |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
960 | if(update) { |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
961 | t = util_parse_lastmodified(update); |
329
2dc61cc5a8ac
adds error message to dav, when an invalid date format is specified for the -u option
Mike Becker <universe@uap-core.de>
parents:
318
diff
changeset
|
962 | if (t == 0) { |
2dc61cc5a8ac
adds error message to dav, when an invalid date format is specified for the -u option
Mike Becker <universe@uap-core.de>
parents:
318
diff
changeset
|
963 | fprintf(stderr, |
2dc61cc5a8ac
adds error message to dav, when an invalid date format is specified for the -u option
Mike Becker <universe@uap-core.de>
parents:
318
diff
changeset
|
964 | "Invalid date format. Possible formats are:\n" |
2dc61cc5a8ac
adds error message to dav, when an invalid date format is specified for the -u option
Mike Becker <universe@uap-core.de>
parents:
318
diff
changeset
|
965 | " RFC-1123 - example: Thu, 29 Nov 2012 21:35:35 GMT\n" |
2dc61cc5a8ac
adds error message to dav, when an invalid date format is specified for the -u option
Mike Becker <universe@uap-core.de>
parents:
318
diff
changeset
|
966 | " RFC-3339 - example: 2012-11-29T21:35:35Z\n"); |
2dc61cc5a8ac
adds error message to dav, when an invalid date format is specified for the -u option
Mike Becker <universe@uap-core.de>
parents:
318
diff
changeset
|
967 | return -1; |
2dc61cc5a8ac
adds error message to dav, when an invalid date format is specified for the -u option
Mike Becker <universe@uap-core.de>
parents:
318
diff
changeset
|
968 | } |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
969 | } |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
970 | |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
971 | int recursive = cmd_getoption(a, "recursive") ? 1 : 0; |
476
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
972 | char *version = cmd_getoption(a, "version"); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
973 | |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
974 | if(recursive && version) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
975 | fprintf(stderr, "-V option can only be used without -R option\n"); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
976 | return -1; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
977 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
978 | |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
979 | DavResource *res; |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
980 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
981 | int depth = recursive ? -1 : 1; |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
982 | res = dav_query( |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
983 | sn, |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
984 | "select - from %s with depth = %d where iscollection or lastmodified > %t", |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
985 | path, |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
986 | depth, |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
987 | t); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
988 | if(!res) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
989 | 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
|
990 | return -1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
991 | } |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
992 | if(!recursive && res->iscollection) { |
235
0468df02e18f
fixed dav get with -u option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
230
diff
changeset
|
993 | 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
|
994 | 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
|
995 | return -1; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
996 | } |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
997 | |
476
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
998 | if(version) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
999 | DavResource *vres = find_version(res, version); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1000 | if(!vres) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1001 | fprintf(stderr, "Cannot find version '%s' for resource.\n", version); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1002 | return -1; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1003 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1004 | dav_resource_free_all(res); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1005 | res = vres; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1006 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1007 | |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
1008 | /* |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
1009 | * determine the output file |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
1010 | * 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
|
1011 | */ |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
1012 | char *outfile = cmd_getoption(a, "output"); |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1013 | char *basepath = outfile; |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
1014 | if(!outfile) { |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1015 | if(res->iscollection) { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1016 | basepath = ""; |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1017 | } else { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1018 | basepath = res->name; |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1019 | } |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
1020 | if(export) { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1021 | outfile = "-"; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1022 | } |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
1023 | } else if(export) { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1024 | basepath = ""; |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1025 | } else if(res->iscollection && !strcmp(outfile, "-")) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1026 | fprintf( |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1027 | stderr, |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1028 | "Cannot write output to stdout " |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1029 | "if the requested resource is a collection.\n"); |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1030 | return -1; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1031 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1032 | |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1033 | // get list of resources |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1034 | UcxList *reslist = NULL; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1035 | uint64_t totalsize = 0; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1036 | uint64_t rescount = 0; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1037 | |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1038 | GetResource *getres = malloc(sizeof(GetResource)); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1039 | getres->res = res; |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1040 | getres->path = strdup(basepath); |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1041 | |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1042 | char *structure = cmd_getoption(a, "structure"); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1043 | |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1044 | // iterate over resource tree |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1045 | UcxList *stack = ucx_list_prepend(NULL, getres); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1046 | while(stack) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1047 | GetResource *g = stack->data; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1048 | stack = ucx_list_remove(stack, stack); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1049 | |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1050 | if(g->res->iscollection) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1051 | DavResource *child = g->res->children; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1052 | while(child) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1053 | // add resource to stack |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1054 | size_t pathlen = strlen(g->path); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1055 | GetResource *newres = malloc(sizeof(GetResource)); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1056 | newres->res = child; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1057 | newres->path = pathlen > 0 ? |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1058 | util_concat_path(g->path, child->name) : strdup(child->name); |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1059 | |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1060 | stack = ucx_list_prepend(stack, newres); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1061 | |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1062 | child = child->next; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1063 | } |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1064 | } else { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1065 | if(structure) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1066 | // download only directory structure |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1067 | // this is a hidden feature and will be replaced in the future |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1068 | continue; // skip non-collection resource |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1069 | } |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1070 | totalsize += g->res->contentlength; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1071 | rescount++; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1072 | } |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1073 | |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1074 | if(strlen(g->path) == 0) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1075 | free_getres(g); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1076 | } else { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1077 | reslist = ucx_list_append(reslist, g); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1078 | } |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1079 | } |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1080 | |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1081 | // download resources |
355
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
1082 | pdata.total = totalsize; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
1083 | |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1084 | int ret; |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1085 | getfunc get; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1086 | TarOutputStream *tout = NULL; |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
1087 | if(export) { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1088 | get = (getfunc)resource2tar; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1089 | FILE *tarfile = strcmp(outfile, "-") ? fopen(outfile, "wb") : stdout; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1090 | if(!tarfile) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1091 | perror("Cannot open tar output file"); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1092 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1093 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1094 | tout = tar_open(tarfile); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1095 | } else { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1096 | get = get_resource; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1097 | } |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1098 | UCX_FOREACH(elm, reslist) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1099 | GetResource *getres = elm->data; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1100 | |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1101 | ret = get(repo, getres, a, tout); |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1102 | if(ret) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1103 | break; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1104 | } |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1105 | } |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
1106 | if(export) { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1107 | // close tar stream |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1108 | if(tar_close(tout)) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1109 | fprintf(stderr, "tar stream broken\n"); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1110 | ret = -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1111 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1112 | } |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1113 | |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1114 | ucx_list_free_content(reslist, free_getres); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1115 | ucx_list_free(reslist); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
1116 | free(path); |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1117 | |
355
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
1118 | if(pdata.out && !pdata.isstdout) { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
1119 | fclose(pdata.out); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
1120 | } |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1121 | return ret; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1122 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1123 | |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1124 | static int file_seek(FILE *f, curl_off_t offset, int origin) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1125 | int ret = fseek(f, offset, origin); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1126 | return ret == 0 ? CURL_SEEKFUNC_OK : CURL_SEEKFUNC_CANTSEEK; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1127 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1128 | |
711
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1129 | static int check_encryption_key(CmdArgs *a, DavSession *sn) { |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1130 | // override the session key if the -k option is specified |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1131 | char *keyname = cmd_getoption(a, "key"); |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1132 | if(keyname) { |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1133 | DavKey *key = dav_context_get_key(ctx, keyname); |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1134 | if(key) { |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1135 | sn->key = key; |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1136 | } else { |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1137 | fprintf(stderr, "Key %s not found!\nAbort.\n", keyname); |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1138 | return 1; |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1139 | } |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1140 | |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1141 | /* |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1142 | * If a key is explicitly specified, we can safely assume that the user |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1143 | * wants to encrypt. For security reasons we report an error, if no |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1144 | * encryption is enabled. |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1145 | */ |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1146 | if(!DAV_IS_ENCRYPTED(sn)) { |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1147 | fprintf(stderr, "A key has been explicitly specified, but no " |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1148 | "encryption is requested.\n" |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1149 | "You have the following options:\n" |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1150 | " - pass '-c' as command line argument to request encryption\n" |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1151 | " - activate encryption in the config.xml\n" |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1152 | " - don't use '-k <key>' " |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1153 | "(warning: encryption will NOT happen)\n"); |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1154 | return 1; |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1155 | } |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1156 | } |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1157 | |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1158 | // if encryption is requested, but we still don't know the key, report error |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1159 | if(DAV_IS_ENCRYPTED(sn) && !(sn->key)) { |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1160 | fprintf(stderr, "Encryption has been requested, " |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1161 | "but no default key is configured.\n" |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1162 | "You may specify a custom key with the '-k' option.\n"); |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1163 | return 1; |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1164 | } |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1165 | |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1166 | return 0; |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1167 | } |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1168 | |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1169 | int cmd_edit(CmdArgs *a) { |
715
f4da6141e233
removes win32 support for dav edit
Mike Becker <universe@uap-core.de>
parents:
712
diff
changeset
|
1170 | #ifdef _WIN32 |
f4da6141e233
removes win32 support for dav edit
Mike Becker <universe@uap-core.de>
parents:
712
diff
changeset
|
1171 | fprintf(stderr, "This feature is not supported on your platform.\n"); |
f4da6141e233
removes win32 support for dav edit
Mike Becker <universe@uap-core.de>
parents:
712
diff
changeset
|
1172 | return -1; |
f4da6141e233
removes win32 support for dav edit
Mike Becker <universe@uap-core.de>
parents:
712
diff
changeset
|
1173 | #else |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1174 | if(a->argc != 1) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1175 | fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1176 | fprintf(stderr, "Usage: dav %s\n", find_usage_str("edit")); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1177 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1178 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1179 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1180 | char *url = a->argv[0]; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1181 | char *path = NULL; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1182 | Repository *repo = url2repo(url, &path); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1183 | DavSession *sn = connect_to_repo(repo, path, a); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1184 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1185 | if(set_session_config(sn, a)) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1186 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1187 | } |
720
2b8a65ed6f4c
adds support for -L option in dav edit
Mike Becker <universe@uap-core.de>
parents:
719
diff
changeset
|
1188 | set_session_lock(sn, a); |
711
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1189 | |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1190 | if(check_encryption_key(a, sn)) { |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1191 | return -1; |
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1192 | } |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1193 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1194 | char *version = cmd_getoption(a, "version"); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1195 | DavResource *res; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1196 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1197 | res = dav_resource_new(sn, path); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1198 | int fresh_resource = !dav_exists(res); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1199 | if(fresh_resource) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1200 | // create the resource to check if the resource can be created |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1201 | // we don't want the user to invest time in editing and fail afterwards |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1202 | if(dav_create(res)) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1203 | fprintf(stderr, "Resource does not exist and cannot be created.\n"); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1204 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1205 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1206 | } else { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1207 | if(!res) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1208 | print_resource_error(sn, path); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1209 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1210 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1211 | if(res->iscollection) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1212 | fprintf(stderr, "Resource %s is a collection " |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1213 | "and cannot be opened in an editor.\n", res->path); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1214 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1215 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1216 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1217 | if(version) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1218 | DavResource *vres = find_version(res, version); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1219 | if(!vres) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1220 | fprintf(stderr, "Cannot find version '%s' for resource.\n", version); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1221 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1222 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1223 | dav_resource_free_all(res); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1224 | res = vres; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1225 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1226 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1227 | |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1228 | // get temp dir |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1229 | char* envtmp = getenv("TMPDIR"); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1230 | char* outfile; |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1231 | if(envtmp) { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1232 | size_t len = strlen(envtmp); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1233 | outfile = malloc(len+24); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1234 | memcpy(outfile, envtmp, len+1); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1235 | if(outfile[len-1] != '/') { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1236 | outfile[len] = '/'; |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1237 | outfile[len+1] = 0; |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1238 | } |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1239 | } else { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1240 | outfile = malloc(24); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1241 | strncpy(outfile, "/tmp/", 24); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1242 | } |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1243 | |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1244 | // check temp dir and fall back to $HOME |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1245 | if(access(outfile, W_OK)) { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1246 | char* home = getenv("HOME"); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1247 | if(home) { |
718
e71ffa69d3fe
cmd_edit. fixes wrong variable in second strlen() call
Mike Becker <universe@uap-core.de>
parents:
717
diff
changeset
|
1248 | size_t len = strlen(home); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1249 | outfile = malloc(len+24); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1250 | memcpy(outfile, home, len+1); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1251 | if(outfile[len-1] != '/') { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1252 | outfile[len] = '/'; |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1253 | outfile[len+1] = 0; |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1254 | } |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1255 | } else { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1256 | // fallback did not work, report last error from access() |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1257 | perror("Cannot write to temporary location"); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1258 | free(outfile); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1259 | return -1; |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1260 | } |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1261 | } |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1262 | |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1263 | // create temp file and open it |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1264 | outfile = strncat(outfile, ".dav-edit-XXXXXX", 23); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1265 | int tmp_fd = mkstemp(outfile); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1266 | if(tmp_fd < 0) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1267 | perror("Cannot open temporary file"); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1268 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1269 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1270 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1271 | // get resource |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1272 | if(!fresh_resource) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1273 | FILE* tmp_stream = sys_fopen(outfile, "wb"); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1274 | if(!tmp_stream) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1275 | perror("Cannot open temporary file"); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1276 | free(outfile); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1277 | close(tmp_fd); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1278 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1279 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1280 | if(dav_get_content(res, tmp_stream, (dav_write_func)fwrite)) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1281 | print_resource_error(sn, path); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1282 | free(outfile); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1283 | close(tmp_fd); |
716
5c2e4da00b04
cmd_edit: replaces unlink() with sys_unlink() + keep tmp file on resource error
Mike Becker <universe@uap-core.de>
parents:
715
diff
changeset
|
1284 | sys_unlink(outfile); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1285 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1286 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1287 | fclose(tmp_stream); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1288 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1289 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1290 | // remember time s.t. we can later check if the file has changed |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1291 | SYS_STAT tmp_stat; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1292 | if(sys_stat(outfile, &tmp_stat)) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1293 | perror("Cannot stat temporary file"); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1294 | free(outfile); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1295 | close(tmp_fd); |
716
5c2e4da00b04
cmd_edit: replaces unlink() with sys_unlink() + keep tmp file on resource error
Mike Becker <universe@uap-core.de>
parents:
715
diff
changeset
|
1296 | sys_unlink(outfile); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1297 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1298 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1299 | time_t dl_mtime = tmp_stat.st_mtime; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1300 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1301 | // open in editor |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1302 | char* default_editor = "vi"; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1303 | char* editor = getenv("EDITOR"); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1304 | if(!editor) editor = default_editor; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1305 | char* viargs[3] = {editor, outfile, NULL}; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1306 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1307 | int ret = 0; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1308 | pid_t pid = fork(); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1309 | if(pid < 0) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1310 | perror("Cannot create process for editor"); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1311 | ret = -1; |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1312 | } else if(pid == 0) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1313 | if(execvp(viargs[0], viargs)) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1314 | perror("Opening the editor failed"); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1315 | return -1; |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1316 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1317 | } else { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1318 | int status = -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1319 | ret = waitpid(pid, &status, 0); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1320 | if(ret < 0) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1321 | perror("Error waiting for editor"); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1322 | } else if(WEXITSTATUS(status)) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1323 | fprintf(stderr, |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1324 | "Editor closed abnormally - file will not be uploaded.\n"); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1325 | ret = -1; |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1326 | } else { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1327 | // check if the file has changed |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1328 | if (sys_stat(outfile, &tmp_stat)) { |
716
5c2e4da00b04
cmd_edit: replaces unlink() with sys_unlink() + keep tmp file on resource error
Mike Becker <universe@uap-core.de>
parents:
715
diff
changeset
|
1329 | // very rare case when someone concurrently changes permissions |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1330 | perror("Cannot stat temporary file"); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1331 | ret = -1; |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1332 | } else if (dl_mtime < tmp_stat.st_mtime) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1333 | // upload changed file |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1334 | FILE* tmp_stream = sys_fopen(outfile, "rb"); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1335 | if(!tmp_stream) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1336 | perror("Cannot open temporary file"); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1337 | ret = -1; |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1338 | } else { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1339 | dav_set_content(res, tmp_stream, |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1340 | (dav_read_func)fread, |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1341 | (dav_seek_func)file_seek); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1342 | dav_set_content_length(res, tmp_stat.st_size); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1343 | ret = dav_store(res); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1344 | fclose(tmp_stream); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1345 | if(ret) { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1346 | print_resource_error(sn, path); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1347 | } |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1348 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1349 | } else { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1350 | printf("No changes by user - file will not be uploaded.\n"); |
719
be012dd45b4b
cmd_edit: fixes wrong return code if the user did not change the file
Mike Becker <universe@uap-core.de>
parents:
718
diff
changeset
|
1351 | ret = 0; |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1352 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1353 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1354 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1355 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1356 | close(tmp_fd); |
716
5c2e4da00b04
cmd_edit: replaces unlink() with sys_unlink() + keep tmp file on resource error
Mike Becker <universe@uap-core.de>
parents:
715
diff
changeset
|
1357 | if(ret) { |
5c2e4da00b04
cmd_edit: replaces unlink() with sys_unlink() + keep tmp file on resource error
Mike Becker <universe@uap-core.de>
parents:
715
diff
changeset
|
1358 | // if someone went wrong, we are most likely unable to unlink anyway |
5c2e4da00b04
cmd_edit: replaces unlink() with sys_unlink() + keep tmp file on resource error
Mike Becker <universe@uap-core.de>
parents:
715
diff
changeset
|
1359 | fprintf(stderr, "File location: %s\n", outfile); |
5c2e4da00b04
cmd_edit: replaces unlink() with sys_unlink() + keep tmp file on resource error
Mike Becker <universe@uap-core.de>
parents:
715
diff
changeset
|
1360 | } else { |
5c2e4da00b04
cmd_edit: replaces unlink() with sys_unlink() + keep tmp file on resource error
Mike Becker <universe@uap-core.de>
parents:
715
diff
changeset
|
1361 | sys_unlink(outfile); |
5c2e4da00b04
cmd_edit: replaces unlink() with sys_unlink() + keep tmp file on resource error
Mike Becker <universe@uap-core.de>
parents:
715
diff
changeset
|
1362 | } |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1363 | free(outfile); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1364 | free(path); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1365 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1366 | return ret; |
715
f4da6141e233
removes win32 support for dav edit
Mike Becker <universe@uap-core.de>
parents:
712
diff
changeset
|
1367 | #endif |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1368 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1369 | |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1370 | int get_resource(Repository *repo, GetResource *getres, CmdArgs *a, void *unused) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1371 | DavResource *res = getres->res; |
350
5fc457fb2cb1
fixes wrong output path in dav get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
1372 | char *out = getres->path; |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1373 | |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1374 | if(res->iscollection) { |
309
8a474d2ad209
adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
1375 | printf("get: %s\n", res->path); |
8a474d2ad209
adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
1376 | |
412
dc74f736aea1
adds more fs abstraction
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
410
diff
changeset
|
1377 | int ret = sys_mkdir(out); |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1378 | if(ret != 0 && errno != EEXIST) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1379 | fprintf(stderr, "Cannot create directory '%s': ", out); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1380 | perror(""); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1381 | return 1; |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1382 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1383 | |
309
8a474d2ad209
adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
1384 | return 0; |
8a474d2ad209
adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
1385 | } |
8a474d2ad209
adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
1386 | |
330
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1387 | int isstdout = !strcmp(out, "-"); |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1388 | if(cmd_getoption(a, "keep") && !isstdout) { |
410
0b9bea2d7283
adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
398
diff
changeset
|
1389 | SYS_STAT s; |
0b9bea2d7283
adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
398
diff
changeset
|
1390 | if(sys_stat(out, &s)) { |
330
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1391 | if(errno != ENOENT) { |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1392 | perror("stat"); |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1393 | } |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1394 | } else { |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1395 | if(cmd_getoption(a, "recursive")) { |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1396 | printf("skip: %s\n", res->path); |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1397 | } |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1398 | return 0; |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1399 | } |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1400 | } |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1401 | |
309
8a474d2ad209
adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
1402 | // print some status message in recursive mode |
8a474d2ad209
adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
1403 | if(cmd_getoption(a, "recursive")) { |
8a474d2ad209
adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
1404 | printf("get: %s\n", res->path); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1405 | } |
330
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1406 | |
410
0b9bea2d7283
adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
398
diff
changeset
|
1407 | FILE *fout = isstdout ? stdout : sys_fopen(out, "wb"); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1408 | if(!fout) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1409 | 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
|
1410 | return -1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1411 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1412 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
1413 | 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
|
1414 | fclose(fout); |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1415 | if(ret && strcmp(out, "-")) { |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
204
diff
changeset
|
1416 | print_resource_error(res->session, res->path); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
204
diff
changeset
|
1417 | //if(strcmp(out, "-")) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
204
diff
changeset
|
1418 | // unlink(out); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
204
diff
changeset
|
1419 | //} |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1420 | } |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1421 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1422 | return 0; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1423 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1424 | |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1425 | #define DEFAULT_DIR_MODE T_IRUSR | T_IWUSR | T_IXUSR | T_IRGRP | T_IXGRP | T_IROTH | T_IXOTH |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1426 | #define DEFAULT_FILE_MODE T_IRUSR | T_IWUSR | T_IRGRP | T_IROTH |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1427 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1428 | int resource2tar(Repository *repo, GetResource *res, CmdArgs *a, TarOutputStream *tar) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1429 | DavResource *d = res->res; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1430 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1431 | if(d->iscollection) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1432 | fprintf(stderr, "add d: %s\n", res->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1433 | return tar_add_dir(tar, res->path, DEFAULT_DIR_MODE, d->lastmodified); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1434 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1435 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1436 | fprintf(stderr, "add f: %s\n", res->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1437 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1438 | // add tar file header |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1439 | if(tar_begin_file(tar, res->path, DEFAULT_FILE_MODE, d->contentlength, d->lastmodified)) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1440 | fprintf(stderr, "TAR Error: %s\n", tar_error2str(tar->error)); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1441 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1442 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1443 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1444 | if(dav_get_content(d, tar, (dav_write_func)tar_fwrite)) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1445 | print_resource_error(d->session, d->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1446 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1447 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1448 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1449 | // download content |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1450 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1451 | return tar_end_file(tar); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1452 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1453 | |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
1454 | int cmd_put(CmdArgs *a, DavBool import) { |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1455 | if(a->argc < 2) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1456 | fprintf(stderr, "Too few arguments\n"); |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1457 | fprintf(stderr, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1458 | "Usage: dav %s\n", |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1459 | find_usage_str(import ? "import" : "put")); |
4 | 1460 | return -1; |
3
323689ada09d
disabled ssl cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
1461 | } |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1462 | DavBool use_stdin = FALSE; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1463 | for(int i=1;i<a->argc;i++) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1464 | if(!strcmp(a->argv[i], "-")) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1465 | if(use_stdin) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1466 | fprintf(stderr, "Error: stdin can only occur once in input list\n"); |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1467 | return -1; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1468 | } else { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1469 | use_stdin = TRUE; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1470 | } |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1471 | } |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1472 | } |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1473 | |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
1474 | if(import) { |
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
1475 | ucx_map_cstr_put(a->options, "resursive", ""); |
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
1476 | } |
3
323689ada09d
disabled ssl cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
1477 | |
11 | 1478 | 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
|
1479 | char *path = NULL; |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
1480 | Repository *repo = url2repo(url, &path); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
1481 | DavSession *sn = connect_to_repo(repo, path, a); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
1482 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
1483 | if(set_session_config(sn, a)) { |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
1484 | return -1; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
1485 | } |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
1486 | set_session_lock(sn, a); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
1487 | |
494
3aed354185eb
fixes cmd_mkdir() not verifying the presence of a key + specifying a key with '-k' without requesting encryption is now considered an error
Mike Becker <universe@uap-core.de>
parents:
489
diff
changeset
|
1488 | if(check_encryption_key(a, sn)) { |
3aed354185eb
fixes cmd_mkdir() not verifying the presence of a key + specifying a key with '-k' without requesting encryption is now considered an error
Mike Becker <universe@uap-core.de>
parents:
489
diff
changeset
|
1489 | // TODO: free |
352
76bd29a11cc9
fixes a segfault when full encryption is requested during a put without specifying the key
Mike Becker <universe@uap-core.de>
parents:
350
diff
changeset
|
1490 | return -1; |
711
8d40b5ccc43e
adds check for encryption key (otherwise segfault when trying to create a fresh encrypted file without a key)
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
1491 | } |
352
76bd29a11cc9
fixes a segfault when full encryption is requested during a put without specifying the key
Mike Becker <universe@uap-core.de>
parents:
350
diff
changeset
|
1492 | |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1493 | DavBool printfile = FALSE; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1494 | DavBool ignoredirerr = FALSE; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1495 | if(a->argc > 2) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1496 | printfile = TRUE; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1497 | ignoredirerr = TRUE; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1498 | } else if(ucx_map_cstr_get(a->options, "recursive")) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1499 | printfile = TRUE; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1500 | } |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1501 | |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1502 | char *finfo_str = cmd_getoption(a, "finfo"); |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1503 | uint32_t finfo = 0; |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1504 | if(finfo_str) { |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
1505 | finfo = parse_finfo_settings(finfo_str, NULL); |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1506 | } |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1507 | |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1508 | int ret; |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1509 | for(int i=1;i<a->argc;i++) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1510 | char *file = a->argv[i]; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1511 | if(!import) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1512 | if(!strcmp(file, "-")) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1513 | FILE *in = stdin; |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1514 | ret = put_file(repo, a, sn, path, "stdin", 0, NULL, in, 0); |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1515 | } else { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1516 | ret = put_entry( |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1517 | repo, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1518 | a, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1519 | sn, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1520 | path, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1521 | file, |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1522 | finfo, |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1523 | TRUE, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1524 | printfile, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1525 | ignoredirerr); |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1526 | } |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1527 | } else { |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1528 | ret = put_tar(repo, a, sn, file, path); |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1529 | } |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1530 | if(ret) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1531 | break; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1532 | } |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1533 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1534 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
1535 | free(path); |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1536 | dav_session_destroy(sn); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1537 | return ret; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1538 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1539 | |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1540 | int put_entry( |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1541 | Repository *repo, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1542 | CmdArgs *a, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1543 | DavSession *sn, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1544 | char *path, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1545 | char *file, |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1546 | uint32_t finfo, |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1547 | DavBool root, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1548 | DavBool printfile, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1549 | DavBool ignoredirerr) |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1550 | { |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1551 | int recursive = cmd_getoption(a, "recursive") ? 1 : 0; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1552 | struct stat s; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1553 | if(stat(file, &s)) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1554 | perror("stat"); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1555 | 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
|
1556 | return -1; |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
1557 | } |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
1558 | |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1559 | int ret = 0; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1560 | if(S_ISDIR(s.st_mode)) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1561 | if(!recursive) { |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1562 | if(ignoredirerr) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1563 | printf("skip: %s\n", file); |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1564 | } else { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1565 | fprintf( |
241
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1566 | stderr, |
318
7e0694423838
dav-sync bugfix: files that are not in the db but on the server should not be pushed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1567 | "%s is a directory.\nUse the -R option to upload directories.\n", |
241
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1568 | file); |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1569 | return 1; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1570 | } |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1571 | } |
271
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1572 | |
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1573 | if(!root) { |
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1574 | printf("mkcol: %s\n", file); |
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1575 | } |
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1576 | |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1577 | DIR *dir = opendir(file); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1578 | if(!dir) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1579 | // error |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1580 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1581 | struct dirent *entry; |
241
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1582 | int nument = 0; |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1583 | while((entry = readdir(dir)) != NULL) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1584 | if(!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1585 | continue; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1586 | } |
241
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1587 | nument++; |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1588 | char *entry_file = util_concat_path(file, entry->d_name); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1589 | char *entry_path = util_concat_path(path, entry->d_name); |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1590 | int r = put_entry( |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1591 | repo, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1592 | a, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1593 | sn, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1594 | entry_path, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1595 | entry_file, |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1596 | finfo, |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1597 | FALSE, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1598 | printfile, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1599 | ignoredirerr); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1600 | free(entry_path); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1601 | free(entry_file); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1602 | if(r) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1603 | ret = 1; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1604 | break; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1605 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1606 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1607 | closedir(dir); |
241
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1608 | |
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1609 | if(nument == 0) { |
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1610 | // create empty directory |
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1611 | DavResource *res = dav_resource_new(sn, path); |
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1612 | res->iscollection = TRUE; |
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1613 | if(!dav_exists(res)) { |
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1614 | if(dav_create(res)) { |
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1615 | fprintf(stderr, "Cannot create collection %s\n", path); |
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1616 | print_resource_error(sn, res->path); |
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1617 | ret = 1; |
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1618 | } |
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1619 | } |
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1620 | dav_resource_free(res); |
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1621 | } |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1622 | } else if(S_ISREG(s.st_mode)) { |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1623 | if(printfile) { |
271
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1624 | printf("put: %s\n", file); |
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1625 | } |
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1626 | |
72
aac29f2e8030
dav now opens files in binary mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
70
diff
changeset
|
1627 | FILE *in = fopen(file, "rb"); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1628 | if(!in) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1629 | fprintf(stderr, "cannot open input file\n"); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1630 | return -1; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1631 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1632 | char *filename = util_resource_name(file); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1633 | //path = util_concat_path(path, filename); |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1634 | ret = put_file(repo, a, sn, path, filename, finfo, file, in, s.st_size); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1635 | //free(path); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1636 | fclose(in); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1637 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1638 | |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1639 | return ret; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1640 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1641 | |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1642 | int put_tar(Repository *repo, CmdArgs *a, DavSession *sn, char *tarfile, char *path) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1643 | int isstdin = !strcmp(tarfile, "-"); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1644 | FILE *in = isstdin ? stdin : fopen(tarfile, "rb"); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1645 | if(!in) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1646 | perror("Cannot open tar file"); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1647 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1648 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1649 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
1650 | DavResource *col = dav_query(sn, "select - from %s", path); |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1651 | if(!col) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1652 | if(sn->error == DAV_NOT_FOUND) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1653 | col = dav_resource_new(sn, path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1654 | col->iscollection = TRUE; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1655 | if(dav_create(col)) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1656 | print_resource_error(sn, path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1657 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1658 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1659 | } else { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1660 | print_resource_error(sn, path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1661 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1662 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1663 | } else if(!col->iscollection) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1664 | fprintf(stderr, "%s is not a collection\n", col->href); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1665 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1666 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1667 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1668 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1669 | int ret = 0; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1670 | TarInputStream *tar = tar_inputstream_open(in); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1671 | TarEntry *e = NULL; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1672 | while((e = tar_read_entry(tar)) != NULL) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1673 | char *newpath = util_concat_path(path, e->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1674 | if(e->type == TAR_TYPE_FILE) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1675 | fprintf(stderr, "put: %s\n", e->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1676 | DavResource *res = dav_resource_new(sn, newpath); |
478
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
476
diff
changeset
|
1677 | dav_set_content(res, tar, (dav_read_func)tar_fread, (dav_seek_func)tar_seek); |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1678 | dav_set_content_length(res, (size_t)e->size); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1679 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1680 | if(dav_store(res)) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1681 | print_resource_error(sn, res->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1682 | fprintf(stderr, "Cannot upload file.\n"); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1683 | if(sn->errorstr) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1684 | fprintf(stderr, "%s\n", sn->errorstr); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1685 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1686 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1687 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1688 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1689 | } else if(e->type == TAR_TYPE_DIRECTORY) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1690 | printf("mkcol: %s\n", e->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1691 | DavResource *res = dav_resource_new(sn, newpath); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1692 | res->iscollection = TRUE; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1693 | if(!dav_exists(res)) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1694 | if(dav_create(res)) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1695 | fprintf(stderr, "Cannot create collection %s\n", newpath); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1696 | print_resource_error(sn, res->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1697 | ret = 1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1698 | free(newpath); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1699 | break; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1700 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1701 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1702 | } else { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1703 | fprintf(stderr, "skip: %s\n", e->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1704 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1705 | free(newpath); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1706 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1707 | if(tar->error != TAR_OK) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1708 | ret = -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1709 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1710 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1711 | if(!isstdin) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1712 | fclose(in); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1713 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1714 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1715 | return ret; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1716 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1717 | |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1718 | int put_file( |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1719 | Repository *repo, |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1720 | CmdArgs *a, |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1721 | DavSession *sn, |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1722 | char *path, |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1723 | char *name, |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1724 | uint32_t finfo, |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1725 | const char *fpath, |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1726 | FILE *in, |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1727 | off_t len) |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1728 | { |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
1729 | DavResource *res = dav_query(sn, "select - from %s", path); |
201
8e5856182668
auth input for dav get, put, mkdir and remove commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
1730 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1731 | if(!res) { |
24
a317202ae787
implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
1732 | if(sn->error == DAV_NOT_FOUND) { |
21 | 1733 | 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
|
1734 | if(dav_create(res)) { |
a317202ae787
implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
1735 | fprintf(stderr, "Cannot create resource.\n"); |
a317202ae787
implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
1736 | return -1; |
a317202ae787
implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
1737 | } |
21 | 1738 | } else { |
198
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
197
diff
changeset
|
1739 | print_resource_error(sn, path); |
21 | 1740 | return -1; |
1741 | } | |
1742 | } else if(res->iscollection) { | |
1743 | // TODO: free res | |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1744 | char *newpath = util_concat_path(path, name); |
353
e554f3d72d9e
fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents:
352
diff
changeset
|
1745 | |
e554f3d72d9e
fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents:
352
diff
changeset
|
1746 | if (!strcmp(path, newpath)) { |
e554f3d72d9e
fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents:
352
diff
changeset
|
1747 | // TODO: free res |
e554f3d72d9e
fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents:
352
diff
changeset
|
1748 | fprintf(stderr, "Cannot put file, because a collection with " |
e554f3d72d9e
fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents:
352
diff
changeset
|
1749 | "that name already exists.\n"); |
e554f3d72d9e
fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents:
352
diff
changeset
|
1750 | free(newpath); |
e554f3d72d9e
fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents:
352
diff
changeset
|
1751 | return -1; |
e554f3d72d9e
fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents:
352
diff
changeset
|
1752 | } |
e554f3d72d9e
fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents:
352
diff
changeset
|
1753 | |
21 | 1754 | path = newpath; |
1755 | res = dav_resource_new(sn, path); | |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1756 | int ret = put_file(repo, a, sn, res->path, NULL, finfo, fpath, in, len); |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1757 | // TODO: free res |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
1758 | free(newpath); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
1759 | return ret; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1760 | } |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1761 | |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1762 | if(resource_set_finfo(fpath, res, finfo)) { |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1763 | fprintf(stderr, "Cannot set finfo: %s.\n", strerror(errno)); |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1764 | } |
539
8deb52292c99
fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
1765 | if((finfo & FINFO_XATTR) == FINFO_XATTR) { |
618
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1766 | XAttributes *xattr = file_get_attributes(fpath, NULL, NULL); |
520
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
1767 | if(xattr) { |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
1768 | resource_set_xattr(res, xattr); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
1769 | } |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
1770 | } |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
1771 | |
478
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
476
diff
changeset
|
1772 | dav_set_content(res, in, (dav_read_func)fread, (dav_seek_func)file_seek); |
180
5b58389ab9dd
fixed large file support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
179
diff
changeset
|
1773 | if(len > 0 && len < 0x7d000000) { |
179
802b48ae791d
enable sharepoint put fix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
178
diff
changeset
|
1774 | 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
|
1775 | } |
4 | 1776 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1777 | if(dav_store(res)) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1778 | print_resource_error(sn, res->path); |
13
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
1779 | fprintf(stderr, "Cannot upload file.\n"); |
22
e593f7e41be0
added more error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
1780 | if(sn->errorstr) { |
e593f7e41be0
added more error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
1781 | fprintf(stderr, "%s\n", sn->errorstr); |
e593f7e41be0
added more error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
1782 | } |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1783 | return -1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1784 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1785 | return 0; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1786 | } |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1787 | |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1788 | static int dav_create_col(DavResource *res) { |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1789 | res->iscollection = 1; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1790 | return dav_create(res); |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1791 | } |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1792 | |
628
1f76d9624db8
fix url2repo not creating a string dup in case a repo doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
1793 | static void print_cannoterr(DavSession *sn, const char *message) { |
1f76d9624db8
fix url2repo not creating a string dup in case a repo doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
1794 | switch(sn->error) { |
1f76d9624db8
fix url2repo not creating a string dup in case a repo doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
1795 | case DAV_UNSUPPORTED_PROTOCOL: |
1f76d9624db8
fix url2repo not creating a string dup in case a repo doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
1796 | case DAV_COULDNT_RESOLVE_PROXY: |
1f76d9624db8
fix url2repo not creating a string dup in case a repo doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
1797 | case DAV_COULDNT_RESOLVE_HOST: |
1f76d9624db8
fix url2repo not creating a string dup in case a repo doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
1798 | case DAV_COULDNT_CONNECT: |
1f76d9624db8
fix url2repo not creating a string dup in case a repo doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
1799 | case DAV_TIMEOUT: |
1f76d9624db8
fix url2repo not creating a string dup in case a repo doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
1800 | case DAV_SSL_ERROR: break; |
1f76d9624db8
fix url2repo not creating a string dup in case a repo doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
1801 | default: fprintf(stderr, "Cannot %s.\n", message); |
1f76d9624db8
fix url2repo not creating a string dup in case a repo doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
1802 | } |
1f76d9624db8
fix url2repo not creating a string dup in case a repo doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
1803 | } |
1f76d9624db8
fix url2repo not creating a string dup in case a repo doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
1804 | |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1805 | static int cmd_operation_on_resources(CmdArgs* a, |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1806 | int(*operation)(DavResource*), |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1807 | const char* command, |
683
53bcb5e47220
fix -c option for dav rm command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
1808 | const char* message, |
53bcb5e47220
fix -c option for dav rm command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
1809 | DavBool check_key) |
53bcb5e47220
fix -c option for dav rm command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
1810 | { |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1811 | if(a->argc < 1) { |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1812 | fprintf(stderr, "Too few arguments\n"); |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1813 | fprintf(stderr, "Usage: dav %s\n", find_usage_str(command)); |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1814 | return -1; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1815 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1816 | |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1817 | char *url = a->argv[0]; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1818 | 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
|
1819 | Repository *repo = url2repo(url, &path); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
1820 | DavSession *sn = connect_to_repo(repo, path, a); |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1821 | |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1822 | int exit_code = -1; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1823 | assert(!!path && !!sn); |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1824 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
1825 | if(set_session_config(sn, a)) { |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1826 | goto cmd_oponres_exit; |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
1827 | } |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1828 | |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
1829 | set_session_lock(sn, a); |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
1830 | |
683
53bcb5e47220
fix -c option for dav rm command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
1831 | if(check_key && check_encryption_key(a, sn)) { |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1832 | goto cmd_oponres_exit; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1833 | } |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1834 | |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1835 | DavResource *res = dav_resource_new(sn, path); |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1836 | assert(!!res); |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1837 | res->iscollection = 1; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1838 | |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1839 | if(a->argc == 1) { |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1840 | if(operation(res)) { |
628
1f76d9624db8
fix url2repo not creating a string dup in case a repo doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
1841 | print_cannoterr(sn, message); |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1842 | print_resource_error(sn, res->path); |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1843 | goto cmd_oponres_exit; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1844 | } |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1845 | } else { |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1846 | for(int i = 1 ; i < a->argc ;++i) { |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1847 | DavResource *child = dav_resource_new_child(sn, res, a->argv[i]); |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1848 | assert(!!child); |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1849 | child->iscollection = 1; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1850 | if(operation(child)) { |
628
1f76d9624db8
fix url2repo not creating a string dup in case a repo doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
1851 | print_cannoterr(sn, message); |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1852 | print_resource_error(sn, child->path); |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1853 | goto cmd_oponres_exit; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1854 | } |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1855 | } |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1856 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1857 | |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1858 | exit_code = 0; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1859 | cmd_oponres_exit: |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
1860 | free(path); |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1861 | dav_session_destroy(sn); |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1862 | return exit_code; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1863 | } |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1864 | |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1865 | int cmd_remove(CmdArgs *a) { |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1866 | return cmd_operation_on_resources(a, dav_delete, |
683
53bcb5e47220
fix -c option for dav rm command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
1867 | "remove", "delete resource", FALSE); |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1868 | } |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
1869 | |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
1870 | int cmd_mkdir(CmdArgs *a) { |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1871 | return cmd_operation_on_resources(a, dav_create_col, |
683
53bcb5e47220
fix -c option for dav rm command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
1872 | "mkdir", "create collection", TRUE); |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
1873 | } |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1874 | |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1875 | int cmd_move(CmdArgs *a, int cp) { |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1876 | const char* actionstr = cp ? "copy" : "move"; |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1877 | |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1878 | if(a->argc != 2) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1879 | // 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
|
1880 | fprintf(stderr, "Too %s arguments\n", a->argc < 2 ? "few":"many"); |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1881 | fprintf(stderr, "Usage: dav %s\n", find_usage_str(actionstr)); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1882 | return -1; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1883 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1884 | |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1885 | char *srcurl = a->argv[0]; |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1886 | char *srcpath = NULL; |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1887 | Repository *srcrepo = url2repo(srcurl, &srcpath); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1888 | |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
1889 | DavSession *srcsn = connect_to_repo(srcrepo, srcpath, a); |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1890 | if(set_session_config(srcsn, a)) { |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1891 | return -1; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1892 | } |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1893 | set_session_lock(srcsn, a); |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
1894 | |
182
ca07f14f7bfe
added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
181
diff
changeset
|
1895 | 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
|
1896 | |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1897 | char *desturl = a->argv[1]; |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1898 | char *destpath = NULL; |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1899 | Repository *destrepo = url2repo(desturl, &destpath); |
382
1ce7211a1021
fixes memory leak in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
380
diff
changeset
|
1900 | |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1901 | if(srcrepo == destrepo) { |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1902 | DavResource *res = dav_resource_new(srcsn, srcpath); |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1903 | int err = cp ? dav_copy_o(res, destpath, override) |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1904 | : dav_move_o(res, destpath, override); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1905 | if(err) { |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1906 | print_resource_error(srcsn, res->path); |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1907 | fprintf(stderr, "Cannot %s resource.\n", actionstr); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1908 | return -1; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1909 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1910 | } else { |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1911 | char *srchost = util_url_base(srcrepo->url); |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1912 | char *desthost = util_url_base(destrepo->url); |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1913 | if(!strcmp(srchost, desthost)) { |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
1914 | DavSession *destsn = connect_to_repo(destrepo, destpath, a); |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1915 | if(set_session_config(destsn, a)) { |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1916 | return -1; |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1917 | } |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1918 | DavResource *dest = dav_resource_new(destsn, destpath); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1919 | char *desthref = dav_resource_get_href(dest); |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1920 | char *desturl = util_get_url(destsn, desthref); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1921 | |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1922 | DavResource *res = dav_resource_new(srcsn, srcpath); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1923 | int err = cp ? dav_copyto(res, desturl, override) |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1924 | : dav_moveto(res, desturl, override); |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1925 | |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1926 | free(desturl); |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1927 | dav_session_destroy(destsn); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1928 | |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1929 | if(err) { |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1930 | print_resource_error(srcsn, res->path); |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1931 | fprintf(stderr, "Cannot %s resource.\n", actionstr); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1932 | return -1; |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1933 | } |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1934 | } else { |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1935 | fprintf(stderr, "Cannot %s between different hosts.\n", actionstr); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1936 | return -1; |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1937 | } |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1938 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1939 | |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1940 | dav_session_destroy(srcsn); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1941 | |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1942 | return 0; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1943 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1944 | |
498
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1945 | int cmd_rename(CmdArgs *a) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1946 | if(a->argc != 2) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1947 | // TODO: change, when creation of multiple dirs is supported |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1948 | fprintf(stderr, "Too %s arguments\n", a->argc < 2 ? "few":"many"); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1949 | fprintf(stderr, "Usage: dav %s\n", find_usage_str("rename")); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1950 | return -1; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1951 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1952 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1953 | char *name = a->argv[1]; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1954 | size_t namelen = strlen(name); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1955 | for(size_t i=0;i<namelen;i++) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1956 | char c = name[i]; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1957 | if(c == '/') { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1958 | fprintf(stderr, "Illegal character in name: '/'\n"); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1959 | return 1; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1960 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1961 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1962 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1963 | char *url = a->argv[0]; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1964 | char *path = NULL; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1965 | Repository *repo = url2repo(url, &path); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1966 | DavSession *sn = connect_to_repo(repo, path, a); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1967 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1968 | if(set_session_config(sn, a)) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1969 | return -1; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1970 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1971 | set_session_lock(sn, a); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1972 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1973 | int ret = 0; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1974 | DavResource *res = dav_get(sn, path, NULL); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1975 | if(res) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1976 | char *cryptoname = dav_get_string_property_ns(res, DAV_NS, "crypto-name"); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1977 | char *cryptokey = dav_get_string_property_ns(res, DAV_NS, "crypto-key"); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1978 | if(cryptoname && cryptokey) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1979 | // encrypted resource with an encrypted name |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1980 | // renaming is done by simply setting the crypto-name property |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1981 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1982 | DavKey *key = dav_context_get_key(ctx, cryptokey); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1983 | if(key) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1984 | // check if a resource with this name already exists |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1985 | char *parent = util_parent_path(res->path); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1986 | char *newpath = util_concat_path(parent, name); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1987 | DavResource *testres = dav_resource_new(sn, newpath); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1988 | if(dav_exists(testres)) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1989 | fprintf(stderr, "A resource with this name already exists.\nAbort.\n"); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1990 | ret = 1; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1991 | } else { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1992 | char *crname = aes_encrypt(name, namelen, key); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1993 | dav_set_string_property_ns(res, DAV_NS, "crypto-name", crname); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1994 | free(crname); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1995 | if(dav_store(res)) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1996 | print_resource_error(sn, res->path); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1997 | fprintf(stderr, "Cannot store crypto-name property.\n"); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1998 | ret = 1; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1999 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2000 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2001 | free(parent); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2002 | free(newpath); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2003 | } else { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2004 | fprintf(stderr, "Key %s not found.\n", cryptokey); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2005 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2006 | } else { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2007 | // rename the resource by changing the url mapping with MOVE |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2008 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2009 | char *parent = util_parent_path(res->href); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2010 | char *new_href = util_concat_path(parent, name); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2011 | char *dest = util_get_url(sn, new_href); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2012 | free(parent); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2013 | free(new_href); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2014 | if(dav_moveto(res, dest, false)) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2015 | print_resource_error(sn, path); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2016 | fprintf(stderr, "Cannot rename resource.\n"); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2017 | ret = 1; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2018 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2019 | free(dest); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2020 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2021 | } else { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2022 | print_resource_error(sn, path); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2023 | fprintf(stderr, "Cannot rename resource.\n"); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2024 | ret = 1; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2025 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2026 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2027 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2028 | dav_session_destroy(sn); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2029 | free(path); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2030 | return ret; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2031 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
2032 | |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2033 | |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2034 | 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
|
2035 | char **date_str = (char**)data; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2036 | |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2037 | //printf("header: %.*s\n", s*n, header); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2038 | sstr_t h = sstrn(header, s*n); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2039 | if(sstrprefix(h, S("Date:"))) { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2040 | sstr_t v = sstrsubs(h, 5); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2041 | v = sstrdup(sstrtrim(v)); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2042 | *date_str = v.ptr; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2043 | } |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2044 | return s*n; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2045 | } |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2046 | |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2047 | int cmd_date(CmdArgs *a) { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2048 | if(a->argc < 1) { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2049 | time_t now = time(NULL); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2050 | struct tm *date = gmtime(&now); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2051 | char str[32]; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2052 | putenv("LC_TIME=C"); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2053 | 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
|
2054 | fwrite(str, 1, len, stdout); |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
2055 | } else if (a->argc == 1) { |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2056 | char *url = a->argv[0]; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2057 | char *path = NULL; |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2058 | Repository *repo = url2repo(url, &path); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2059 | DavSession *sn = connect_to_repo(repo, path, a); |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2060 | |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2061 | DavResource *res = dav_resource_new(sn, path); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2062 | char *date = NULL; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2063 | 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
|
2064 | curl_easy_setopt(sn->handle, CURLOPT_WRITEHEADER, &date); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2065 | if(dav_exists(res) && date) { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2066 | printf("%s\n", date); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2067 | } else { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2068 | return -1; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2069 | } |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
2070 | free(path); |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
2071 | return 0; |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
2072 | } else { |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
2073 | fprintf(stderr, "Too many arguments\n"); |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
2074 | fprintf(stderr, "Usage: dav %s\n", find_usage_str("date")); |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
2075 | return -1; |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2076 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
2077 | return 0; |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
2078 | } |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
2079 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2080 | int cmd_get_property(CmdArgs *a) { |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
2081 | if(a->argc < 2) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
2082 | fprintf(stderr, "Too few arguments\n"); |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
2083 | fprintf(stderr, "Usage: dav %s\n", find_usage_str("get-property")); |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
2084 | return -1; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
2085 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
2086 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2087 | char *url = a->argv[0]; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2088 | char *path = NULL; |
258
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
2089 | Repository *repo = url2repo(url, &path); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2090 | DavSession *sn = connect_to_repo(repo, path, a); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2091 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2092 | if(set_session_config(sn, a)) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2093 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2094 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2095 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2096 | char *namespace = cmd_getoption(a, "namespace"); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2097 | char *property = a->argv[1]; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2098 | |
476
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2099 | char *version = cmd_getoption(a, "version"); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2100 | |
298
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
2101 | DavPropName propname; |
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
2102 | if(namespace) { |
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
2103 | propname.ns = namespace; |
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
2104 | propname.name = property; |
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
2105 | } else { |
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
2106 | dav_get_property_namespace_str(ctx, property, &propname.ns, &propname.name); |
317
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
316
diff
changeset
|
2107 | if(!propname.ns || !propname.name) { |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
316
diff
changeset
|
2108 | fprintf(stderr, "Error: unknown namespace prefix\n"); |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
316
diff
changeset
|
2109 | return -1; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
316
diff
changeset
|
2110 | } |
298
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
2111 | } |
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
2112 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2113 | DavResource *res = dav_resource_new(sn, path); |
476
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2114 | if(version) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2115 | DavResource *vres = find_version(res, version); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2116 | if(!vres) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2117 | fprintf(stderr, "Cannot find version '%s' for resource.\n", version); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2118 | return -1; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2119 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2120 | dav_resource_free_all(res); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2121 | res = vres; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2122 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2123 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2124 | if(dav_load_prop(res, &propname, 1)) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2125 | print_resource_error(sn, res->path); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2126 | return -1; |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2127 | } |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2128 | free(path); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2129 | |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2130 | DavXmlNode *x = dav_get_property_ns(res, propname.ns, propname.name); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2131 | if(!x) { |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2132 | 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
|
2133 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2134 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2135 | |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2136 | if(cmd_getoption(a, "xml")) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2137 | // print a real xml document on stdout |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2138 | printxmldoc(stdout, propname.name, propname.ns, x); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2139 | } else { |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2140 | // in this mode a simple string is printed on stdout |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2141 | // or simplified and nicely formatted xml is printed on stderr |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2142 | if(dav_xml_isstring(x)) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2143 | printf("%s\n", dav_xml_getstring(x)); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2144 | } else { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2145 | char *str = xml2str(x); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2146 | fprintf(stderr, "%s", str); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2147 | free(str); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2148 | } |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2149 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2150 | |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2151 | return 0; |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2152 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2153 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2154 | int cmd_set_property(CmdArgs *a) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2155 | if(a->argc < 2) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2156 | fprintf(stderr, "Too few arguments\n"); |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
2157 | fprintf(stderr, "Usage: dav %s\n", find_usage_str("set-property")); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2158 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2159 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2160 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2161 | char *url = a->argv[0]; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2162 | char *path = NULL; |
258
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
2163 | Repository *repo = url2repo(url, &path); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2164 | DavSession *sn = connect_to_repo(repo, path, a); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2165 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2166 | if(set_session_config(sn, a)) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2167 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2168 | } |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
2169 | set_session_lock(sn, a); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2170 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2171 | DavResource *res = dav_resource_new(sn, path); |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2172 | if(!dav_exists(res)) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2173 | print_resource_error(sn, res->path); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2174 | return -1; |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2175 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2176 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2177 | char *namespace = cmd_getoption(a, "namespace"); |
371
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2178 | char *xml = cmd_getoption(a, "xml"); |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2179 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2180 | char *property = a->argv[1]; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2181 | 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
|
2182 | |
371
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2183 | int ret = 0; |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2184 | if(xml) { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2185 | DavXmlNode *xmlvalue = dav_parse_xml(sn, value, strlen(value)); |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2186 | if(xmlvalue) { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2187 | if(namespace) { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2188 | dav_set_property_ns(res, namespace, property, xmlvalue->children); |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2189 | } else { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2190 | dav_set_property(res, property, xmlvalue->children); |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2191 | } |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2192 | } else { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2193 | fprintf(stderr, "Error: property content is not valid xml\n"); |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2194 | ret = 1; |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2195 | } |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2196 | } else { |
371
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2197 | if(namespace) { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2198 | dav_set_string_property_ns(res, namespace, property, value); |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2199 | } else { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2200 | dav_set_string_property(res, property, value); |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2201 | } |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2202 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2203 | |
371
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2204 | if(ret == 0) { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2205 | if(dav_store(res)) { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2206 | print_resource_error(sn, res->path); |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2207 | fprintf(stderr, "Cannot set property.\n"); |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2208 | ret = -1; |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2209 | } |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2210 | } else |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2211 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
2212 | free(path); |
371
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
2213 | dav_session_destroy(sn); |
258
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
2214 | return ret; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
2215 | } |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2216 | |
304
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2217 | int cmd_remove_property(CmdArgs *a) { |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2218 | if(a->argc < 2) { |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2219 | fprintf(stderr, "Too few arguments\n"); |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
2220 | fprintf(stderr, "Usage: dav %s\n", find_usage_str("remove-property")); |
304
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2221 | return -1; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2222 | } |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2223 | |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2224 | char *url = a->argv[0]; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2225 | char *path = NULL; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2226 | Repository *repo = url2repo(url, &path); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2227 | DavSession *sn = connect_to_repo(repo, path, a); |
304
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2228 | |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2229 | if(set_session_config(sn, a)) { |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2230 | return -1; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2231 | } |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2232 | |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2233 | char *namespace = cmd_getoption(a, "namespace"); |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2234 | char *property = a->argv[1]; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2235 | |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2236 | DavPropName propname; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2237 | if(namespace) { |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2238 | propname.ns = namespace; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2239 | propname.name = property; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2240 | } else { |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2241 | dav_get_property_namespace_str(ctx, property, &propname.ns, &propname.name); |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2242 | } |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2243 | |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2244 | int ret = 0; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2245 | DavResource *res = dav_resource_new(sn, path); |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2246 | dav_remove_property_ns(res, propname.ns, propname.name); |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2247 | |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2248 | if(dav_store(res)) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2249 | print_resource_error(sn, res->path); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2250 | fprintf(stderr, "Cannot set property.\n"); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2251 | ret = -1; |
304
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2252 | } |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2253 | |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2254 | free(path); |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2255 | return ret; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2256 | } |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
2257 | |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2258 | int cmd_lock(CmdArgs *a) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2259 | if(a->argc != 1) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2260 | fprintf(stderr, "Too %s arguments\n", a->argc > 1 ? "many" : "few"); |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
2261 | fprintf(stderr, "Usage: dav %s\n", find_usage_str("lock")); |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2262 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2263 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2264 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2265 | char *url = a->argv[0]; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2266 | char *path = NULL; |
258
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
2267 | Repository *repo = url2repo(url, &path); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2268 | DavSession *sn = connect_to_repo(repo, path, a); |
230
fdcbde1d7d65
fixed memory leaks in lock and unlock commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
229
diff
changeset
|
2269 | 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
|
2270 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2271 | if(set_session_config(sn, a)) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2272 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2273 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2274 | |
315
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
2275 | time_t timeout = 0; |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
2276 | char *timeoutstr = cmd_getoption(a, "timeout"); |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
2277 | if(timeoutstr) { |
316
9d0505d80044
adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
2278 | if(!sstrcasecmp(sstr(timeoutstr), S("infinite"))) { |
315
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
2279 | timeout = -1; |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
2280 | } else { |
509
0576dd6409f3
fixed TODO: use strtol
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
508
diff
changeset
|
2281 | uint64_t i; |
512
3320a015a3bc
fixes signed vs unsigned inaccuracy for the -T option
Mike Becker <universe@uap-core.de>
parents:
511
diff
changeset
|
2282 | if(util_strtouint(timeoutstr, &i)) { |
509
0576dd6409f3
fixed TODO: use strtol
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
508
diff
changeset
|
2283 | timeout = (time_t)i; |
0576dd6409f3
fixed TODO: use strtol
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
508
diff
changeset
|
2284 | } else { |
0576dd6409f3
fixed TODO: use strtol
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
508
diff
changeset
|
2285 | fprintf(stderr, "Error: -T option has invalid value\n"); |
0576dd6409f3
fixed TODO: use strtol
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
508
diff
changeset
|
2286 | return -1; |
0576dd6409f3
fixed TODO: use strtol
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
508
diff
changeset
|
2287 | } |
315
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
2288 | } |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
2289 | } |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
2290 | |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2291 | DavResource *res = dav_resource_new(sn, path); |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2292 | if(dav_lock_t(res, timeout)) { |
264
94c0a938b66c
fixes error detection loop in dav lock/unlock/get-property/set-property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
2293 | print_resource_error(sn, res->path); |
94c0a938b66c
fixes error detection loop in dav lock/unlock/get-property/set-property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
2294 | return -1; |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2295 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2296 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2297 | 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
|
2298 | if(!lock) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2299 | // this should really not happen |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2300 | // do some damage control |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2301 | dav_unlock(res); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2302 | 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
|
2303 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2304 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2305 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2306 | printf("%s\n", lock->token); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2307 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2308 | dav_session_destroy(sn); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2309 | return 0; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2310 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2311 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2312 | static char* read_line() { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2313 | 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
|
2314 | int c; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2315 | while((c = getchar()) != EOF) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2316 | if(c == '\n') { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2317 | break; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2318 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2319 | ucx_buffer_putc(buf, c); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2320 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2321 | char *str = NULL; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2322 | 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
|
2323 | if(line.length != 0) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2324 | str = sstrdup(line).ptr; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2325 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2326 | ucx_buffer_free(buf); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2327 | return str; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2328 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2329 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2330 | int cmd_unlock(CmdArgs *a) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2331 | if(a->argc != 1) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2332 | fprintf(stderr, "Too %s arguments\n", a->argc > 1 ? "many" : "few"); |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
2333 | fprintf(stderr, "Usage: dav %s\n", find_usage_str("unlock")); |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2334 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2335 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2336 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2337 | char *url = a->argv[0]; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2338 | char *path = NULL; |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2339 | Repository *repo = url2repo(url, &path); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2340 | DavSession *sn = connect_to_repo(repo, path, a); |
230
fdcbde1d7d65
fixed memory leaks in lock and unlock commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
229
diff
changeset
|
2341 | 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
|
2342 | if(set_session_config(sn, a)) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2343 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2344 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2345 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2346 | char *locktoken = cmd_getoption(a, "lock"); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2347 | if(locktoken) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2348 | 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
|
2349 | dav_add_collection_lock(sn, "/", lock); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2350 | } else { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2351 | locktoken = read_line(); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2352 | if(!locktoken) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2353 | 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
|
2354 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2355 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2356 | 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
|
2357 | 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
|
2358 | free(locktoken); |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2359 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2360 | |
258
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
2361 | int ret = 0; |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2362 | DavResource *res = dav_resource_new(sn, path); |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2363 | if(dav_unlock(res)) { |
264
94c0a938b66c
fixes error detection loop in dav lock/unlock/get-property/set-property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
2364 | print_resource_error(sn, res->path); |
94c0a938b66c
fixes error detection loop in dav lock/unlock/get-property/set-property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
2365 | ret = -1; |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2366 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2367 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2368 | dav_session_destroy(sn); |
258
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
2369 | return ret; |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2370 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2371 | |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2372 | static int count_children(DavResource *res) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2373 | DavResource *child = res->children; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2374 | int count = 0; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2375 | while(child) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2376 | count++; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2377 | child = child->next; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2378 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2379 | return count; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2380 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2381 | |
373
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2382 | void print_xml_infostr(DavXmlNode *xml) { |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2383 | if(xml->children) { |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2384 | printf("<%s>...</%s>", xml->name, xml->name); |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2385 | } else { |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2386 | printf("<%s/>", xml->name); |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2387 | } |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2388 | } |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2389 | |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2390 | int cmd_info(CmdArgs *a) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2391 | if(a->argc < 1) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2392 | fprintf(stderr, "Too few arguments\n"); |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
2393 | fprintf(stderr, "Usage: dav %s\n", find_usage_str("info")); |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2394 | return -1; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2395 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2396 | |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2397 | char *url = a->argv[0]; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2398 | char *path = NULL; |
258
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
2399 | Repository *repo = url2repo(url, &path); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2400 | DavSession *sn = connect_to_repo(repo, path, a); |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2401 | |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2402 | if(set_session_config(sn, a)) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2403 | return -1; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2404 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2405 | |
476
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2406 | char *version = cmd_getoption(a, "version"); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2407 | |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2408 | DavResource *res = dav_resource_new(sn, path); |
476
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2409 | if(version) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2410 | DavResource *vres = find_version(res, version); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2411 | if(!vres) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2412 | fprintf(stderr, "Cannot find version '%s' for resource.\n", version); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2413 | return -1; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2414 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2415 | dav_resource_free_all(res); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2416 | res = vres; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2417 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2418 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2419 | if(!dav_load(res)) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2420 | printf("name: %s\n", res->name); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2421 | printf("path: %s\n", res->path); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2422 | |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2423 | char *server = util_url_base(sn->base_url); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2424 | char *url = util_concat_path(server, res->href); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2425 | printf("url: %s\n", url); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2426 | free(url); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2427 | free(server); |
258
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
2428 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2429 | if(res->iscollection) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2430 | printf("type: collection\n"); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2431 | printf("size: %d\n", count_children(res)); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2432 | } else { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2433 | printf("type: resource\n"); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2434 | char *len = ls_size_str(res); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2435 | printf("size: %s\n", len); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2436 | free(len); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2437 | } |
258
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
2438 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2439 | size_t count = 0; |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2440 | DavPropName *properties = dav_get_property_names(res, &count); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2441 | |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2442 | char *last_ns = NULL; |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2443 | for(int i=0;i<count;i++) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2444 | DavPropName p = properties[i]; |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2445 | if(!last_ns || strcmp(last_ns, p.ns)) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2446 | printf("\nnamespace: %s\n", p.ns); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2447 | last_ns = p.ns; |
258
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
2448 | } |
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
2449 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2450 | DavXmlNode *xval = dav_get_property_ns(res, p.ns, p.name); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2451 | if(dav_xml_isstring(xval)) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2452 | sstr_t value = sstr(dav_xml_getstring(xval)); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2453 | printf(" %s: %.*s\n", p.name, (int)value.length, value.ptr); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2454 | } else { |
373
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2455 | // find some xml elements |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2456 | printf(" %s: ", p.name); |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2457 | DavXmlNode *x = xval->type == DAV_XML_ELEMENT ? xval : dav_xml_nextelm(xval); |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2458 | for(int i=0;i<3;i++) { |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2459 | if(x) { |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2460 | if(i == 2) { |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2461 | printf(" ..."); |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2462 | break; |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2463 | } else { |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2464 | print_xml_infostr(x); |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2465 | } |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2466 | } else { |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2467 | break; |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2468 | } |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2469 | x = dav_xml_nextelm(x); |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2470 | } |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2471 | printf("\n"); |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2472 | |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2473 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2474 | } |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2475 | } |
258
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
2476 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2477 | dav_session_free(sn, properties); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2478 | return 0; |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2479 | } else { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2480 | print_resource_error(sn, res->path); |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2481 | } |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2482 | |
258
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
2483 | return -1; |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2484 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2485 | |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2486 | int cmd_checkout(CmdArgs *a) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2487 | if(a->argc < 1) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2488 | fprintf(stderr, "Too few arguments\n"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2489 | fprintf(stderr, "Usage: dav %s\n", "checkout [-pc] <url>"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2490 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2491 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2492 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2493 | char *url = a->argv[0]; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2494 | char *path = NULL; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2495 | Repository *repo = url2repo(url, &path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2496 | DavSession *sn = connect_to_repo(repo, path, a); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2497 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2498 | if(set_session_config(sn, a)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2499 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2500 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2501 | set_session_lock(sn, a); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2502 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2503 | int ret = 0; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2504 | DavResource *res = dav_resource_new(sn, path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2505 | if(dav_checkout(res)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2506 | print_resource_error(sn, res->path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2507 | ret = 1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2508 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2509 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2510 | return ret; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2511 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2512 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2513 | int cmd_checkin(CmdArgs *a) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2514 | if(a->argc < 1) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2515 | fprintf(stderr, "Too few arguments\n"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2516 | fprintf(stderr, "Usage: dav %s\n", "checkin [-pc] <url>"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2517 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2518 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2519 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2520 | char *url = a->argv[0]; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2521 | char *path = NULL; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2522 | Repository *repo = url2repo(url, &path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2523 | DavSession *sn = connect_to_repo(repo, path, a); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2524 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2525 | if(set_session_config(sn, a)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2526 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2527 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2528 | set_session_lock(sn, a); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2529 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2530 | int ret = 0; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2531 | DavResource *res = dav_resource_new(sn, path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2532 | if(dav_checkin(res)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2533 | print_resource_error(sn, res->path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2534 | ret = 1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2535 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2536 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2537 | return ret; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2538 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2539 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2540 | int cmd_uncheckout(CmdArgs *a) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2541 | if(a->argc < 1) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2542 | fprintf(stderr, "Too few arguments\n"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2543 | fprintf(stderr, "Usage: dav %s\n", "uncheckout [-pc] <url>"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2544 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2545 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2546 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2547 | char *url = a->argv[0]; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2548 | char *path = NULL; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2549 | Repository *repo = url2repo(url, &path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2550 | DavSession *sn = connect_to_repo(repo, path, a); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2551 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2552 | if(set_session_config(sn, a)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2553 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2554 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2555 | set_session_lock(sn, a); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2556 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2557 | int ret = 0; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2558 | DavResource *res = dav_resource_new(sn, path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2559 | if(dav_uncheckout(res)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2560 | print_resource_error(sn, res->path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2561 | ret = 1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2562 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2563 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2564 | return ret; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2565 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2566 | int cmd_versioncontrol(CmdArgs *a) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2567 | if(a->argc < 1) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2568 | fprintf(stderr, "Too few arguments\n"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2569 | fprintf(stderr, "Usage: dav %s\n", "versioncontrol [-pc] <url>"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2570 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2571 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2572 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2573 | char *url = a->argv[0]; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2574 | char *path = NULL; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2575 | Repository *repo = url2repo(url, &path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2576 | DavSession *sn = connect_to_repo(repo, path, a); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2577 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2578 | if(set_session_config(sn, a)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2579 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2580 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2581 | set_session_lock(sn, a); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2582 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2583 | int ret = 0; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2584 | DavResource *res = dav_resource_new(sn, path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2585 | if(dav_versioncontrol(res)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2586 | print_resource_error(sn, res->path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2587 | ret = 1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2588 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2589 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2590 | return ret; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2591 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2592 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2593 | int cmd_list_versions(CmdArgs *a) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2594 | if(a->argc < 1) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2595 | fprintf(stderr, "Too few arguments\n"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2596 | fprintf(stderr, "Usage: dav %s\n", "list-versions [-pc] <url>"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2597 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2598 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2599 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2600 | char *url = a->argv[0]; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2601 | char *path = NULL; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2602 | Repository *repo = url2repo(url, &path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2603 | DavSession *sn = connect_to_repo(repo, path, a); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2604 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2605 | if(set_session_config(sn, a)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2606 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2607 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2608 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2609 | DavResource *res = dav_resource_new(sn, path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2610 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2611 | int ret = 0; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2612 | DavResource *list = dav_versiontree(res, NULL); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2613 | if(list) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2614 | char* longlist = cmd_getoption(a, "list"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2615 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2616 | DavResource *v = list; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2617 | int addnl = 0; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2618 | while(v) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2619 | char *vname = dav_get_string_property(v, "D:version-name"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2620 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2621 | if(longlist) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2622 | if(addnl) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2623 | putchar('\n'); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2624 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2625 | printf("name: %s\n", vname); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2626 | printf("href: %s\n", v->href); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2627 | addnl = 1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2628 | } else { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2629 | printf("%s\n", vname); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2630 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2631 | v = v->next; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2632 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2633 | } else if(sn->error != DAV_OK) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2634 | print_resource_error(sn, path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2635 | ret = 1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2636 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2637 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2638 | return ret; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2639 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2640 | |
476
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2641 | DavResource* find_version(DavResource *res, char *version) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2642 | DavResource *list = dav_versiontree(res, NULL); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2643 | DavResource *ret = NULL; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2644 | while(list) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2645 | DavResource *next = list->next; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2646 | if(!ret) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2647 | char *vname = dav_get_string_property(list, "D:version-name"); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2648 | if(vname && !strcmp(vname, version)) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2649 | ret = list; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2650 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2651 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2652 | if(list != ret) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2653 | dav_resource_free(list); |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2654 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2655 | list = next; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2656 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2657 | return ret; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2658 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2659 | |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2660 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2661 | char* stdin2str() { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2662 | UcxBuffer *buf = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
2663 | size_t size = ucx_stream_copy(stdin, buf, fread, ucx_buffer_write); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2664 | if(size == 0) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2665 | ucx_buffer_free(buf); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2666 | return NULL; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2667 | } else { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2668 | ucx_buffer_putc(buf, '\0'); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2669 | char *str = buf->space; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2670 | free(buf); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2671 | return str; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2672 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2673 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2674 | |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2675 | static void xml2str_i(DavXmlNode *node, UcxBuffer *buf, int indent) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2676 | while(node) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2677 | if(node->type == DAV_XML_ELEMENT) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2678 | if(node->children) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2679 | if(dav_xml_isstring(node->children)) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2680 | sstr_t s = sstrtrim(sstr(dav_xml_getstring(node->children))); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2681 | ucx_bprintf( |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2682 | buf, |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2683 | "%*s<%s>%.*s</%s>\n", |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2684 | indent, |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2685 | "", |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2686 | node->name, |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2687 | (int)s.length, |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2688 | s.ptr, |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2689 | node->name); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2690 | } else { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2691 | ucx_bprintf(buf, "%*s<%s>\n", indent, "", node->name); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2692 | xml2str_i(node->children, buf, indent+2); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2693 | ucx_bprintf(buf, "%*s</%s>\n", indent, "", node->name); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2694 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2695 | } else { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2696 | ucx_bprintf(buf, "%*s<%s />", indent, "", node->name); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2697 | ucx_buffer_putc(buf, '\n'); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2698 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2699 | } else if(node->type == DAV_XML_TEXT) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2700 | sstr_t val = sstrtrim(sstrn(node->content, node->contentlength)); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2701 | if(val.length > 0) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2702 | ucx_bprintf(buf, "%*.*s", indent, (int)val.length, val.ptr); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2703 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2704 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2705 | |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2706 | node = node->next; |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2707 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2708 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2709 | |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2710 | char* xml2str(DavXmlNode *node) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2711 | char *str = malloc(256); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2712 | UcxBuffer *buf = ucx_buffer_new(str, 256, UCX_BUFFER_AUTOEXTEND); |
346
3e20fd78e555
fixes missing string terminator when printing simplified xml (dav get-property)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
338
diff
changeset
|
2713 | xml2str_i(node, buf, 0); |
3e20fd78e555
fixes missing string terminator when printing simplified xml (dav get-property)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
338
diff
changeset
|
2714 | ucx_buffer_putc(buf, 0); |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2715 | char *space = buf->space; |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2716 | ucx_buffer_free(buf); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2717 | return space; |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2718 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2719 | |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2720 | void printxmldoc(FILE *out, char *root, char *rootns, DavXmlNode *content) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2721 | UcxMap *nsmap = ucx_map_new(16); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2722 | |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2723 | ucx_map_cstr_put(nsmap, rootns, "x0"); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2724 | fprintf(out, "%s", "<?xml version=\"1.0\"?>\n"); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2725 | fprintf(out, "<x0:%s xmlns:x0=\"%s\">", root, rootns); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2726 | |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
355
diff
changeset
|
2727 | dav_print_node(out, (write_func)fwrite, nsmap, content); |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2728 | |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2729 | fprintf(out, "</x0:%s>\n", root); |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
355
diff
changeset
|
2730 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
355
diff
changeset
|
2731 | // cleanup namespace map |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
355
diff
changeset
|
2732 | ucx_map_cstr_remove(nsmap, rootns); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
355
diff
changeset
|
2733 | ucx_map_free_content(nsmap, free); |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
355
diff
changeset
|
2734 | ucx_map_free(nsmap); |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2735 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2736 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2737 | |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2738 | /* ---------- config commands ---------- */ |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2739 | |
195
4b7823a58199
fixed add-repository function name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
194
diff
changeset
|
2740 | int cmd_add_repository(CmdArgs *args) { |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2741 | 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
|
2742 | char *name = assistant_getcfg("name"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2743 | if(!name) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2744 | fprintf(stderr, "Abort\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2745 | return -1; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2746 | } |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2747 | if(get_repository(sstr(name))) { |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
2748 | 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
|
2749 | return -1; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2750 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2751 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2752 | printf("\nSpecify the repository base url.\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2753 | char *url = assistant_getcfg("url"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2754 | if(!url) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2755 | fprintf(stderr, "Abort\n"); |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2756 | return -1; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2757 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2758 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2759 | printf("\nUser for HTTP authentication.\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2760 | char *user = assistant_getoptcfg("user"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2761 | |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2762 | char *password = NULL; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2763 | if(user) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2764 | password = assistant_gethiddenoptcfg("password"); |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2765 | } |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2766 | printf("\n"); |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2767 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2768 | Repository repo; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2769 | memset(&repo, 0, sizeof(Repository)); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2770 | repo.name = name; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2771 | repo.url = url; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2772 | repo.user = user; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2773 | repo.password = password; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2774 | |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2775 | int ret = 0; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2776 | if(add_repository(&repo)) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2777 | fprintf(stderr, "Cannot write config.xml\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2778 | ret = -1; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2779 | } else { |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
2780 | 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
|
2781 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2782 | |
197
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2783 | free(name); |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2784 | free(url); |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2785 | if(user) { |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2786 | free(user); |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2787 | } |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2788 | if(password) { |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2789 | free(password); |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2790 | } |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2791 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2792 | return ret; |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2793 | } |
398
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2794 | |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2795 | int cmd_remove_repository(CmdArgs *args) { |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2796 | if(args->argc < 1) { |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2797 | fprintf(stderr, "Too few arguments\n"); |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2798 | fprintf(stderr, "Usage: dav remove-repository <name...>\n"); |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2799 | return -1; |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2800 | } |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2801 | |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2802 | for(int i = 0 ; i < args->argc ; i++) { |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2803 | sstr_t reponame = sstr(args->argv[i]); |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2804 | Repository* repo = get_repository(reponame); |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2805 | if(repo) { |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2806 | if(remove_repository(repo)) { |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2807 | fprintf(stderr, "Cannot write config.xml\n"); |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2808 | return -1; |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2809 | } |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2810 | } else { |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2811 | fprintf(stderr, "Repository %s does not exist - skipped.\n", |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2812 | reponame.ptr); |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2813 | return -1; |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2814 | } |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2815 | } |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2816 | |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2817 | return -1; |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2818 | } |
419
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2819 | |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2820 | int cmd_repository_url(CmdArgs *args) { |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2821 | if(args->argc != 1) { |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2822 | fprintf(stderr, "Too few arguments\n"); |
421
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2823 | fprintf(stderr, "Usage: dav repository-url [-p] <name>\n"); |
419
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2824 | return -1; |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2825 | } |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2826 | |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2827 | sstr_t reponame = sstr(args->argv[0]); |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2828 | Repository* repo = get_repository(reponame); |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2829 | if(repo) { |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2830 | sstr_t url = sstr(repo->url); |
421
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2831 | if(repo->user && !cmd_getoption(args, "plain")) { |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2832 | int hostindex = 0; |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2833 | if(sstrprefix(url, S("https://"))) { |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2834 | printf("https://"); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2835 | hostindex = 8; |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2836 | } else if(sstrprefix(url, S("http://"))) { |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2837 | printf("http://"); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2838 | hostindex = 7; |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2839 | } |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2840 | printf("%s", repo->user); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2841 | if(repo->password) { |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2842 | CURL *curl = curl_easy_init(); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2843 | char *pw = curl_easy_escape( |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2844 | curl, |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2845 | repo->password, |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2846 | strlen(repo->password)); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2847 | printf(":%s", pw); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2848 | curl_free(pw); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2849 | curl_easy_cleanup(curl); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2850 | } |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2851 | putchar('@'); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2852 | printf("%.*s", (int)url.length-hostindex, url.ptr+hostindex); |
419
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2853 | } else { |
421
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2854 | printf("%s", url.ptr); |
419
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2855 | } |
421
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2856 | if(url.ptr[url.length-1] != '/') { |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2857 | putchar('/'); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2858 | } |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2859 | putchar('\n'); |
419
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2860 | } else { |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2861 | fprintf(stderr, "Repository %s does not exist.\n", reponame.ptr); |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2862 | return -1; |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2863 | } |
488
29b979ca8750
adds dav_pw2key commoncrypto implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
478
diff
changeset
|
2864 | return 0; |
419
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2865 | } |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
2866 | |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2867 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2868 | typedef int(*sscmd_func)(CmdArgs *, PwdStore *, void *userdata); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2869 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2870 | static int secretstore_after_decrypt( |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2871 | CmdArgs *args, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2872 | PwdStore *secrets, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2873 | sscmd_func cb, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2874 | void *userdata); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2875 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2876 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2877 | /* |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2878 | * opens the secret store, executes a callback func before and after |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2879 | * decryption |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2880 | * Aborts if a callback returns 1 |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2881 | */ |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2882 | static int secretstore_cmd( |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2883 | CmdArgs *args, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2884 | DavBool create, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2885 | sscmd_func beforedecrypt, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2886 | sscmd_func afterdecrypt, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2887 | void *userdata) |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2888 | { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2889 | PwdStore *secrets = get_pwdstore(); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2890 | if(!secrets) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2891 | if(create) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2892 | secrets = pwdstore_new(); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2893 | } else { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2894 | return 1; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2895 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2896 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2897 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2898 | int ret = 0; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2899 | if(beforedecrypt) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2900 | ret = beforedecrypt(args, secrets, userdata); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2901 | if(ret) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2902 | afterdecrypt = NULL; // exit |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2903 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2904 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2905 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2906 | if(afterdecrypt) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2907 | ret = secretstore_after_decrypt(args, secrets, afterdecrypt, userdata); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2908 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2909 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2910 | pwdstore_free(secrets); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2911 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2912 | return ret; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2913 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2914 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2915 | static int secretstore_after_decrypt( |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2916 | CmdArgs *args, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2917 | PwdStore *secrets, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2918 | sscmd_func cb, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2919 | void *userdata) |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2920 | { |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2921 | char *master_pw = util_password_input("Master password: "); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2922 | if(!master_pw) { |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2923 | fprintf(stderr, "Error: master password required.\nAbort.\n"); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2924 | return 1; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2925 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2926 | |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2927 | int err = pwdstore_setpassword(secrets, master_pw); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2928 | free(master_pw); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2929 | if(err) { |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2930 | fprintf(stderr, "Error: Cannot generate key from password.\nAbort.\n"); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2931 | return 1; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2932 | } |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2933 | |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2934 | if(pwdstore_decrypt(secrets)) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2935 | fprintf(stderr, "Error: Cannot decrypt secrets store.\nAbort.\n"); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2936 | return 1; |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2937 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2938 | |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2939 | return cb(args, secrets, userdata); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2940 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2941 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2942 | static int cmd_ss_add_user(CmdArgs *Args, PwdStore *secrets, void *userdata) { |
472
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
2943 | char *id = assistant_getcfg("Credentials identifier"); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2944 | if(!id) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2945 | fprintf(stderr, "Identifier required.\n"); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2946 | return 1; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2947 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2948 | if(pwdstore_get(secrets, id)) { |
653
f503c272bd70
update secret store format description
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
652
diff
changeset
|
2949 | fprintf(stderr, "Credentials with this id already exist.\n"); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2950 | return 1; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2951 | } |
472
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
2952 | |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2953 | // get user name and password (required) |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
2954 | char *user = assistant_getcfg("User"); |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
2955 | char *password = util_password_input("Password: "); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2956 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2957 | // optionally, get one or more locations |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2958 | char *location = NULL; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2959 | UcxList *locations = NULL; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2960 | while((location = assistant_getoptcfg("Location"))) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2961 | locations = ucx_list_append(locations, location); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2962 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2963 | |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2964 | int ret = 1; |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
2965 | if(user && password) { |
489
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
2966 | pwdstore_put_index(secrets, id, locations); |
474
017a4f09e6fa
improves secret store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
473
diff
changeset
|
2967 | pwdstore_put(secrets, id, user, password); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2968 | ret = pwdstore_save(secrets); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2969 | if(ret) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2970 | fprintf(stderr, "Error: saving srcrets store failed.\n"); |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
2971 | } |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
2972 | } |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2973 | |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2974 | if(id) free(id); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2975 | if(user) free(user); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2976 | if(password) free(password); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2977 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2978 | ucx_list_free_content(locations, free); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2979 | ucx_list_free(locations); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2980 | |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2981 | return ret; |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
2982 | } |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
2983 | |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2984 | int cmd_add_user(CmdArgs *args) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2985 | return secretstore_cmd(args, TRUE, NULL, cmd_ss_add_user, NULL); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2986 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2987 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2988 | /* |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2989 | * called before the secret store is decrypted |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2990 | */ |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2991 | static int cmd_ss_list_users_bc(CmdArgs *Args, PwdStore *secrets, int *ret) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2992 | if(secrets->index->count == 0) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2993 | return 1; // abort, because the secret store is empty |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2994 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2995 | // set ret to 1, because decrypt could fail and this should be an error |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2996 | *ret = 1; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2997 | return 0; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2998 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2999 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3000 | /* |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3001 | * called after the secret store is decrypted |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3002 | */ |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3003 | static int cmd_ss_list_users(CmdArgs *args, PwdStore *secrets, int *ret) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3004 | *ret = 0; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3005 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3006 | UcxList *list = secrets->locations; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3007 | for(int i=0;i<2;i++) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3008 | UCX_FOREACH(elm, list) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3009 | PwdIndexEntry *index = elm->data; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3010 | PwdEntry *e = ucx_map_cstr_get(secrets->ids, index->id); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3011 | if(e) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3012 | printf("Id: %s\n", e->id); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3013 | printf("User: %s\n", e->user); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3014 | UCX_FOREACH(loc, index->locations) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3015 | char *location = loc->data; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3016 | printf("Location: %s\n", location); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3017 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3018 | printf("\n"); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3019 | } else { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3020 | // broken index |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3021 | fprintf(stderr, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3022 | "Warning: id '%s' not in secret store.\n", |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3023 | index->id); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3024 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3025 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3026 | list = secrets->noloc; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3027 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3028 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3029 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3030 | return 0; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3031 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3032 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3033 | int cmd_list_users(CmdArgs *args) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3034 | int ret = 0; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3035 | secretstore_cmd(args, FALSE, (sscmd_func)cmd_ss_list_users_bc, (sscmd_func)cmd_ss_list_users, &ret); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3036 | return ret; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3037 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3038 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3039 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3040 | static int cmd_ss_remove_user(CmdArgs *args, PwdStore *secrets, void *ud) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3041 | char *id = assistant_getcfg("Credentials identifier"); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3042 | if(!id) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3043 | fprintf(stderr, "Identifier required.\n"); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3044 | return 1; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3045 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3046 | if(!pwdstore_get(secrets, id)) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3047 | fprintf(stderr, "Credentials with this id doesn't exist.\n"); |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3048 | free(id); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3049 | return 1; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3050 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3051 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3052 | pwdstore_remove_entry(secrets, id); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3053 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3054 | int ret = pwdstore_save(secrets); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3055 | if(ret) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3056 | fprintf(stderr, "Error: saving srcrets store failed.\n"); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3057 | } |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3058 | free(id); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3059 | return ret; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3060 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3061 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3062 | int cmd_remove_user(CmdArgs *args) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3063 | return secretstore_cmd(args, FALSE, NULL, cmd_ss_remove_user, NULL); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
3064 | } |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3065 | |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3066 | static void secrets_print_user_info(PwdStore *secrets, const char *id) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3067 | PwdEntry *entry = pwdstore_get(secrets, id); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3068 | if(!entry) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3069 | return; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3070 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3071 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3072 | PwdIndexEntry *index = ucx_map_cstr_get(secrets->index, id); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3073 | if(!index) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3074 | return; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3075 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3076 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3077 | printf("Id: %s\n", entry->id); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3078 | printf("User: %s\n", entry->user); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3079 | UCX_FOREACH(elm, index->locations) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3080 | printf("Location: %s\n", (char*)elm->data); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3081 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3082 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3083 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3084 | static void secrets_remove_location(PwdIndexEntry *index) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3085 | if(!index->locations) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3086 | printf("no locations\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3087 | return; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3088 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3089 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3090 | printf("0: abort\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3091 | int i = 1; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3092 | UCX_FOREACH(elm, index->locations) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3093 | printf("%d: %s\n", i, (char*)elm->data); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3094 | i++; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3095 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3096 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3097 | char *input = assistant_getcfg("Choose location"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3098 | if(!input) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3099 | return; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3100 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3101 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3102 | int64_t ln = 0; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3103 | if(util_strtoint(input, &ln) && (ln >= 0 && ln < i)) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3104 | if(ln == 0) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3105 | return; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3106 | } else { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3107 | UcxList *elm = ucx_list_get(index->locations, ln - 1); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3108 | if(elm) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3109 | free(elm->data); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3110 | index->locations = ucx_list_remove(index->locations, elm); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3111 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3112 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3113 | } else { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3114 | printf("illegal input, choose 0 - %d\n", i-1); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3115 | secrets_remove_location(index); // try again |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3116 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3117 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3118 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3119 | static int cmd_ss_edit_user(CmdArgs *args, PwdStore *secrets, void *ud) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3120 | char *id = assistant_getcfg("Credentials identifier"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3121 | if(!id) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3122 | fprintf(stderr, "Identifier required.\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3123 | return 1; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3124 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3125 | PwdEntry *entry = pwdstore_get(secrets, id); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3126 | PwdIndexEntry *index = ucx_map_cstr_get(secrets->index, id); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3127 | if(!entry || !index) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3128 | fprintf(stderr, "Credentials with this id doesn't exist.\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3129 | return 1; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3130 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3131 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3132 | secrets_print_user_info(secrets, id); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3133 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3134 | int save = 0; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3135 | int loop = 1; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3136 | while(loop) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3137 | printf("\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3138 | printf("0: change user name\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3139 | printf("1: change password\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3140 | printf("2: add location\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3141 | printf("3: remove location\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3142 | printf("4: list locations\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3143 | printf("5: save and exit\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3144 | printf("6: exit without saving\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3145 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3146 | char *opt = assistant_getcfg("Choose action"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3147 | if(!opt) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3148 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3149 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3150 | int64_t mnu = 0; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3151 | if(util_strtoint(opt, &mnu) && (mnu >= 0 && mnu <= 6)) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3152 | printf("\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3153 | switch(mnu) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3154 | case 0: { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3155 | // change user name |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3156 | char *user = assistant_getcfg("User"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3157 | if(user) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3158 | if(entry->user) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3159 | free(entry->user); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3160 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3161 | entry->user = user; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3162 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3163 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3164 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3165 | case 1: { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3166 | // change password |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3167 | char *password = util_password_input("Password: "); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3168 | if(password) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3169 | if(entry->password) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3170 | free(entry->password); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3171 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3172 | entry->password = password; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3173 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3174 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3175 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3176 | case 2: { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3177 | // add location |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3178 | char *location = assistant_getoptcfg("Location"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3179 | if(location) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3180 | index->locations = ucx_list_append(index->locations, location); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3181 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3182 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3183 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3184 | case 3: { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3185 | // remove location |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3186 | secrets_remove_location(index); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3187 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3188 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3189 | case 4: { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3190 | // list locations |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3191 | if(!index->locations) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3192 | printf("no locations\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3193 | } else { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3194 | UCX_FOREACH(elm, index->locations) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3195 | printf("Location: %s\n", (char*)elm->data); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3196 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3197 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3198 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3199 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3200 | case 5: { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3201 | // save and exit |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3202 | loop = 0; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3203 | save = 1; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3204 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3205 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3206 | case 6: { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3207 | // exit without saving |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3208 | loop = 0; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3209 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3210 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3211 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3212 | } else { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3213 | printf("illegal input, choose 0 - 5\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3214 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3215 | free(opt); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3216 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3217 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3218 | int ret = 0; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3219 | if(save) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3220 | ret = pwdstore_save(secrets); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3221 | if(ret) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3222 | fprintf(stderr, "Error: saving srcrets store failed.\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3223 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3224 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3225 | return ret; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3226 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3227 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3228 | int cmd_edit_user(CmdArgs *args) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3229 | return secretstore_cmd(args, FALSE, NULL, cmd_ss_edit_user, NULL); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3230 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3231 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
3232 | |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3233 | static char** read_args_from_stdin(int *argc) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3234 | // read stdin into buffer |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3235 | UcxBuffer *in = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3236 | ucx_stream_copy(stdin, in, (read_func)fread, (write_func)ucx_buffer_write); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3237 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3238 | // split input into lines |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3239 | ssize_t count = 0; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3240 | sstr_t *lines = scstrsplit(scstrn(in->space, in->pos), SC("\n"), &count); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3241 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3242 | char **args = NULL; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3243 | if(count > 0) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3244 | args = calloc(count, sizeof(char*)); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3245 | for(int i=0;i<count;i++) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3246 | args[i] = lines[i].ptr; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3247 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3248 | free(lines); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3249 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3250 | *argc = count; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3251 | } else { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3252 | *argc = 0; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3253 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3254 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3255 | // cleanup |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3256 | ucx_buffer_free(in); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3257 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3258 | return args; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3259 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3260 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3261 | int cmd_complete(CmdArgs *args) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3262 | if(args->argc != 1) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3263 | return 1; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3264 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3265 | char *index_str = args->argv[0]; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3266 | int64_t index = 0; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3267 | if(!util_strtoint(index_str, &index)) { |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3268 | return 1; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3269 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3270 | |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3271 | // The completion bash script passes the input words to stdin |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3272 | int comp_argc; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3273 | char **comp_argv = read_args_from_stdin(&comp_argc); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3274 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3275 | // Try to parse the args |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3276 | char *cmd = NULL; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3277 | if(comp_argc > 1) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3278 | cmd = comp_argv[1]; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3279 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3280 | CmdArgs *comp_args = cmd_parse_args(comp_argc - 2, comp_argv + 2); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3281 | if(comp_args) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3282 | // check whether the arglist contains options |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3283 | if(comp_args->argc + 2 != comp_argc) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3284 | // index points to the arg in the raw arglist, however we have to |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3285 | // know the index for this item in comp_args->argv |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3286 | // any arg that is an option or an option value creates a |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3287 | // difference between the two lists |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3288 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3289 | // adjust index to comp_args->argv |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3290 | int j = 0; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3291 | for(int i=0;i<comp_argc-2;i++) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3292 | if(index == i-2) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3293 | break; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3294 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3295 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3296 | if(strcmp(comp_argv[i+2], comp_args->argv[j])) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3297 | index--; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3298 | } else { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3299 | j++; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3300 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3301 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3302 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3303 | } else { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3304 | comp_args = NULL; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3305 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3306 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3307 | // generate output for shell completion |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3308 | int ret = 1; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3309 | if(comp_args) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3310 | ret = shell_completion(cmd, comp_args, index); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3311 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3312 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3313 | // cleanup |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3314 | cmd_args_free(comp_args); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3315 | free(comp_argv); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3316 | return ret; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3317 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3318 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3319 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3320 | int shell_completion(char *cmd, CmdArgs *args, int index) { |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3321 | if(index == 1) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3322 | sstr_t prefix = { NULL, 0 }; |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3323 | if(cmd) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3324 | prefix = sstr(cmd); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3325 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3326 | for(int i=0;;i++) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3327 | char *str = cmdusageinfo[i]; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3328 | if(!str) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3329 | break; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3330 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3331 | int len = (int)strlen(str); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3332 | int maxlen = len; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3333 | for(int w=0;w<len;w++) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3334 | if(str[w] == ' ') { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3335 | maxlen = w; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3336 | break; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3337 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3338 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3339 | if(prefix.ptr) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3340 | if(!sstrprefix(sstrn(str, maxlen), prefix)) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3341 | continue; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3342 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3343 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3344 | printf("%.*s\n", (int)maxlen, str); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3345 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3346 | return 0; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3347 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3348 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3349 | if(!strcmp(cmd, "date")) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3350 | return 0; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3351 | } |
458
295eaa04fc41
fixes url completion segfaulting for empty strings (in case the user hasn't already started typing an URL)
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
3352 | |
295eaa04fc41
fixes url completion segfaulting for empty strings (in case the user hasn't already started typing an URL)
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
3353 | // get already typed URL or NULL, if the user hasn't started typing yet |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3354 | char *url = args->argc > 0 ? args->argv[0] : NULL; |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3355 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3356 | //printf("index: {%s}\n", args->argv[0]); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3357 | //printf("dav: {%s}\n", args->argv[1]); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3358 | //printf("cmd: {%s}\n", cmd); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3359 | //printf("url: {%s}\n", url); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3360 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3361 | if(index == 2) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3362 | // url completion |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3363 | return url_completion(args, url); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3364 | } else if (index == 3) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3365 | if(!strcmp(cmd, "put") || !strcmp(cmd, "import")) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3366 | // file completion |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3367 | return 12; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3368 | } else if(!strcmp(cmd, "copy") || !strcmp(cmd, "cp") || !strcmp(cmd, "move") || !strcmp(cmd, "mv")) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3369 | // url completion |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3370 | return url_completion(args, url); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3371 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3372 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3373 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3374 | return 0; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3375 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3376 | |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3377 | int url_completion(CmdArgs *args, char *u) { |
458
295eaa04fc41
fixes url completion segfaulting for empty strings (in case the user hasn't already started typing an URL)
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
3378 | sstr_t url; |
295eaa04fc41
fixes url completion segfaulting for empty strings (in case the user hasn't already started typing an URL)
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
3379 | url.ptr = u; |
295eaa04fc41
fixes url completion segfaulting for empty strings (in case the user hasn't already started typing an URL)
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
3380 | url.length = u ? strlen(u) : 0; |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3381 | |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3382 | // if the user wants the URL to be quoted, we conform to their wish |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3383 | // a null-char is an indicator, that the strings shall not be quoted |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3384 | char quote = '\0'; |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3385 | if(url.length > 0 && (url.ptr[0] == '\'' || url.ptr[0] == '\"' )) { |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3386 | quote = url.ptr[0]; |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3387 | |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3388 | // for completing the url, we want to proceed without the quote |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3389 | url.ptr++; |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3390 | url.length--; |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3391 | |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3392 | // the user may have also prepared the ending quote, remove it for now |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3393 | if (url.ptr[url.length-1] == quote) { |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3394 | url.length--; |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3395 | } |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3396 | } |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3397 | |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3398 | // repo completion |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3399 | int repocomp = 1; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3400 | for(int i=0;i<url.length;i++) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3401 | if(url.ptr[i] == '/') { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3402 | repocomp = 0; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3403 | break; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3404 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3405 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3406 | if(repocomp) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3407 | UcxList *repos = get_repositories(); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3408 | UCX_FOREACH(elm, repos) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3409 | Repository *repo = elm->data; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3410 | if(sstrprefix(sstr(repo->name), url)) { |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3411 | if(quote == '\0') { |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3412 | printf("%s/\n", repo->name); |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3413 | } else { |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3414 | printf("%c%s/%c\n", quote, repo->name, quote); |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3415 | } |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3416 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3417 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3418 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3419 | } else { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3420 | // url completion |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3421 | ucx_map_cstr_put(args->options, "noinput", ""); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3422 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3423 | char *path = NULL; |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3424 | Repository *repo = url2repo_s(url, &path); |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3425 | DavSession *sn = connect_to_repo(repo, path, args); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3426 | if(!sn) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3427 | return 0; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3428 | } |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3429 | if(set_session_config(sn, args)) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3430 | return 0; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3431 | } |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3432 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3433 | size_t plen = strlen(path); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3434 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3435 | sstr_t filter; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3436 | char *lspath = NULL; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3437 | if(path[plen-1] == '/') { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3438 | lspath = strdup(path); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3439 | filter = S(""); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3440 | } else { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3441 | lspath = util_parent_path(path); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3442 | filter = sstr(util_resource_name(path)); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3443 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3444 | |
433
7096666628ca
fixes url completion output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
432
diff
changeset
|
3445 | DavResource *ls = dav_query(sn, "select - from %s order by name", lspath); |
435
def0359fb48f
adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
433
diff
changeset
|
3446 | DavResource *elm = ls ? ls->children : NULL; |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3447 | while(elm) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3448 | sstr_t name = sstr(elm->name); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3449 | if(sstrprefix(name, filter)) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3450 | int space = 0; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3451 | for(int i=0;i<name.length;i++) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3452 | if(name.ptr[i] == ' ') { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3453 | space = 1; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3454 | break; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3455 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3456 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3457 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3458 | UcxBuffer *out = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3459 | ucx_buffer_puts(out, repo->name); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3460 | if(space) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3461 | size_t l = strlen(elm->path); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3462 | for(int i=0;i<l;i++) { |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3463 | // only if we do not quote, we have to escape spaces |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3464 | if(elm->path[i] == ' ' && quote == '\0') { |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3465 | ucx_buffer_puts(out, "\\ "); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3466 | } else { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3467 | ucx_buffer_putc(out, elm->path[i]); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3468 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3469 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3470 | } else { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3471 | ucx_buffer_puts(out, elm->path); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3472 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3473 | if(elm->iscollection) { |
433
7096666628ca
fixes url completion output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
432
diff
changeset
|
3474 | if(out->space[out->pos-1] != '/') { |
7096666628ca
fixes url completion output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
432
diff
changeset
|
3475 | ucx_buffer_putc(out, '/'); |
7096666628ca
fixes url completion output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
432
diff
changeset
|
3476 | } |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3477 | } |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3478 | if (quote == '\0') { |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3479 | printf("%.*s\n", (int)out->pos, out->space); |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3480 | } else { |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3481 | printf("%c%.*s%c\n", |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3482 | quote, (int)out->pos, out->space, quote); |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3483 | } |
432
a213ecaf3f4a
adjusts completion index, if options are specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
431
diff
changeset
|
3484 | |
a213ecaf3f4a
adjusts completion index, if options are specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
431
diff
changeset
|
3485 | ucx_buffer_free(out); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3486 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3487 | elm = elm->next; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3488 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3489 | |
432
a213ecaf3f4a
adjusts completion index, if options are specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
431
diff
changeset
|
3490 | free(lspath); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3491 | |
432
a213ecaf3f4a
adjusts completion index, if options are specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
431
diff
changeset
|
3492 | dav_session_destroy(sn); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3493 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3494 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3495 | return 10; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3496 | } |