Wed, 24 Jul 2024 23:45:31 +0200
fix dav add-repo crash in case .dav/config.xml doesn't exist
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> |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
35 | #include <time.h> |
4 | 36 | #include <sys/types.h> |
715
f4da6141e233
removes win32 support for dav edit
Mike Becker <universe@uap-core.de>
parents:
712
diff
changeset
|
37 | #ifndef _WIN32 |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
38 | #include <sys/wait.h> |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
39 | #include <unistd.h> |
715
f4da6141e233
removes win32 support for dav edit
Mike Becker <universe@uap-core.de>
parents:
712
diff
changeset
|
40 | #endif |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
41 | #include <cx/string.h> |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
42 | #include <cx/utils.h> |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
43 | #include <cx/printf.h> |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
44 | #include <cx/hash_map.h> |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
45 | #include <cx/linked_list.h> |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
46 | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
48 | #include <libidav/utils.h> |
40
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
49 | #include <libidav/crypto.h> |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
50 | #include <libidav/session.h> |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
355
diff
changeset
|
51 | #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
|
52 | #include "config.h" |
191
0e45b04236a7
more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
53 | #include "error.h" |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
54 | #include "assistant.h" |
410
0b9bea2d7283
adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
398
diff
changeset
|
55 | #include "system.h" |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
56 | #include "pwd.h" |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
57 | #include "finfo.h" |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | #include "main.h" |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
60 | static DavContext *ctx; |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
61 | |
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
62 | static int printxmlerror = 1; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
63 | 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
|
64 | if(printxmlerror) { |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
65 | va_list ap; |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
66 | va_start(ap, msg); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
67 | vfprintf(stderr, msg, ap); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
68 | va_end(ap); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
69 | } |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
72 | //define DO_THE_TEST |
363
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
73 | //include <libidav/davqlparser.h> |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
74 | //include <libidav/davqlexec.h> |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
75 | //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
|
76 | //include <libidav/resource.h> |
363
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
77 | |
728 | 78 | void test(CmdArgs *a) { |
363
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
79 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
80 | } |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
81 | |
687
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
82 | 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
|
83 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
84 | #ifdef _WIN32 |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
85 | |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
86 | #define strcasecmp _stricmp |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
87 | |
687
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
88 | 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
|
89 | size_t maxlen = wlen * 4; |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
90 | char *ret = malloc(maxlen + 1); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
91 | int ret_len = WideCharToMultiByte( |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
92 | CP_UTF8, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
93 | 0, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
94 | wstr, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
95 | wlen, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
96 | ret, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
97 | maxlen, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
98 | NULL, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
99 | NULL); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
100 | ret[ret_len] = 0; |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
101 | return ret; |
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 wmain(int argc, wchar_t **argv) { |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
105 | 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
|
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 | 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
|
108 | } |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
109 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
110 | 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
|
111 | |
728 | 112 | |
687
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
113 | 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
|
114 | free(argv_utf8[i]); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
115 | } |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
116 | free(argv_utf8); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
117 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
118 | return ret; |
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 | #else |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | 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
|
122 | return dav_main(argc, argv); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
123 | } |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
124 | #endif |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
125 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
126 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
684
diff
changeset
|
127 | int dav_main(int argc, char **argv) { |
34
1b87b3b1921e
removed debug code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
128 | if(argc < 2) { |
11 | 129 | fprintf(stderr, "Missing command\n"); |
130 | print_usage(argv[0]); | |
131 | return -1; | |
132 | } | |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
133 | |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
134 | putenv("LC_TIME=C"); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
135 | |
34
1b87b3b1921e
removed debug code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
136 | char *cmd = argv[1]; |
1b87b3b1921e
removed debug code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
137 | CmdArgs *args = cmd_parse_args(argc - 2, argv + 2); |
11 | 138 | if(!args) { |
139 | print_usage(argv[0]); | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | return -1; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
609
diff
changeset
|
143 | 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
|
144 | 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
|
145 | 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
|
146 | 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
|
147 | 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
|
148 | 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
|
149 | 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
|
150 | 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
|
151 | #ifdef DO_THE_TEST |
728 | 152 | test(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
|
153 | 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
|
154 | #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
|
155 | 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
|
156 | 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 | 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
|
158 | 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
|
159 | } 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
|
160 | /* 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
|
161 | 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
|
162 | } |
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
|
163 | } 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
|
164 | 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
|
165 | 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
|
166 | } 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
|
167 | ret = cmd_get(args, FALSE); |
511
59a216f8d4e8
adds command alias 'cat' for 'get -o -'
Mike Becker <universe@uap-core.de>
parents:
510
diff
changeset
|
168 | } else if(!strcasecmp(cmd, "cat")) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
169 | cxMapPut(args->options, cx_hash_key_str("output"), "-"); |
511
59a216f8d4e8
adds command alias 'cat' for 'get -o -'
Mike Becker <universe@uap-core.de>
parents:
510
diff
changeset
|
170 | ret = cmd_get(args, FALSE); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
171 | } else if(!strcasecmp(cmd, "edit")) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
172 | 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
|
173 | } 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
|
174 | 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
|
175 | } 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
|
176 | !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
|
177 | !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
|
178 | !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
|
179 | { |
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
|
180 | 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
|
181 | } 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
|
182 | 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
|
183 | } 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
|
184 | 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
|
185 | } 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
|
186 | ret = cmd_move(args, false); |
498
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
187 | } else if(!strcasecmp(cmd, "rename")) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
188 | 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
|
189 | } 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
|
190 | 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
|
191 | } 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
|
192 | 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
|
193 | } 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
|
194 | 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
|
195 | } 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
|
196 | 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
|
197 | } 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
|
198 | ret = cmd_get_property(args); |
304
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
199 | } else if(!strcasecmp(cmd, "remove-property")) { |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
200 | 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
|
201 | } 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
|
202 | 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
|
203 | } 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
|
204 | 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
|
205 | } 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
|
206 | ret = cmd_info(args); |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
207 | } else if(!strcasecmp(cmd, "checkout")) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
208 | ret = cmd_checkout(args); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
209 | } else if(!strcasecmp(cmd, "checkin")) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
210 | ret = cmd_checkin(args); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
211 | } else if(!strcasecmp(cmd, "uncheckout")) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
212 | ret = cmd_uncheckout(args); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
213 | } else if(!strcasecmp(cmd, "versioncontrol")) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
214 | ret = cmd_versioncontrol(args); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
215 | } else if(!strcasecmp(cmd, "list-versions") || !strcasecmp(cmd, "lsv")) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
216 | ret = cmd_list_versions(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, "add-repository") |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
218 | || !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
|
219 | ret = cmd_add_repository(args); |
398
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
220 | } else if(!strcasecmp(cmd, "remove-repository") |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
221 | || !strcasecmp(cmd, "remove-repo") |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
222 | || !strcasecmp(cmd, "rm-repo")) { |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
223 | ret = cmd_remove_repository(args); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
224 | } else if(!strcasecmp(cmd, "list-repositories") |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
225 | || !strcasecmp(cmd, "list-repos")) { |
798
d7f5067a27ce
remove list_repositories() config.c function in favor of a cmd_list_repositories() function in main.c
Mike Becker <universe@uap-core.de>
parents:
796
diff
changeset
|
226 | ret = cmd_list_repositories(); |
419
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
227 | } else if(!strcasecmp(cmd, "repository-url") |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
228 | || !strcasecmp(cmd, "repo-url")) { |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
229 | ret = cmd_repository_url(args); |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
230 | } else if(!strcasecmp(cmd, "add-user")) { |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
231 | ret = cmd_add_user(args); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
232 | } else if(!strcasecmp(cmd, "list-users")) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
233 | ret = cmd_list_users(args); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
234 | } else if(!strcasecmp(cmd, "remove-user")) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
235 | ret = cmd_remove_user(args); |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
236 | } else if(!strcasecmp(cmd, "edit-user")) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
237 | ret = cmd_edit_user(args); |
733
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
238 | } else if(!strcasecmp(cmd, "set-master-password") || !strcasecmp(cmd, "set-master-pw")) { |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
239 | ret = cmd_set_master_password(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
|
240 | } 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
|
241 | || !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
|
242 | fprintf(stderr, "dav %s\n", DAV_VERSION); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
243 | } else if(!strcasecmp(cmd, "complete")) { |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
244 | 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
|
245 | } 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
|
246 | 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
|
247 | } |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | } |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
249 | |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
250 | dav_context_destroy(ctx); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
251 | cmd_args_free(args); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
252 | free_config(); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
253 | xmlCleanupParser(); |
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
254 | curl_global_cleanup(); |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
609
diff
changeset
|
255 | sys_uninit(); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
257 | return ret; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
260 | static char *cmdusageinfo[] = { |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
261 | "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
|
262 | "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
|
263 | "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
|
264 | "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
|
265 | "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
|
266 | "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
|
267 | "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
|
268 | "move [-pcO] [-L <lock>] <url> <url>", |
498
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
269 | "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
|
270 | "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
|
271 | "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
|
272 | "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
|
273 | "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
|
274 | "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
|
275 | "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
|
276 | "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
|
277 | "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
|
278 | "date [url]", |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
279 | NULL |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
280 | }; |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
281 | |
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
|
282 | char* find_usage_str(const char *cmd) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
283 | cxstring c = cx_str(cmd); |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
284 | 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
|
285 | 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
|
286 | if(!str) { |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
287 | break; |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
288 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
289 | cxstring u = cx_str(str); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
290 | if(cx_strprefix(u, c)) { |
332
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
291 | return str; |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
292 | } |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
293 | } |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
294 | return NULL; |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
295 | } |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
296 | |
11 | 297 | void print_usage(char *cmd) { |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
298 | 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
|
299 | |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
300 | 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
|
301 | 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
|
302 | 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
|
303 | if(!str) { |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
304 | break; |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
305 | } |
5587282ebe1c
dav prints command usage info if argument count is wrong
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
306 | fprintf(stderr, " %s\n", str); |
511
59a216f8d4e8
adds command alias 'cat' for 'get -o -'
Mike Becker <universe@uap-core.de>
parents:
510
diff
changeset
|
307 | } |
11 | 308 | fprintf(stderr, "Options:\n"); |
309 | fprintf(stderr, | |
703
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
310 | " -k <key> Key to use for encryption\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
311 | fprintf(stderr, " -p Don't encrypt or decrypt files\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
312 | fprintf(stderr, " -c Enable full encryption\n"); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
313 | fprintf(stderr, |
703
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
314 | " -R " |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
315 | "Recursively do the operation for all children\n"); |
703
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
316 | fprintf(stderr, " -K Keep already present files\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
317 | 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
|
318 | fprintf( |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
319 | stderr, |
703
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
320 | " -u <date> " |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
321 | "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
|
322 | 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
|
323 | fprintf(stderr, " -a show all files\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
324 | fprintf(stderr, " -l print resources in long list format\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
325 | fprintf(stderr, " -t print content type\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
326 | fprintf(stderr, " -d order by last modified date\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
327 | fprintf(stderr, " -e show extended flags\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
328 | fprintf(stderr, " -O override resources\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
329 | fprintf(stderr, " -L <lock> specificy lock token\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
330 | fprintf(stderr, " -T <sec> timeout in seconds\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
331 | fprintf(stderr, " -n <uri> specify namespace uri\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
332 | fprintf(stderr, " -x xml property content\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
333 | fprintf(stderr, " -N disable authentication prompt (all commands)\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
334 | fprintf(stderr, " -i disable cert verification (all commands)\n"); |
2e3a24b9896a
update man pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
335 | fprintf(stderr, " -v verbose output (all commands)\n"); |
11 | 336 | fprintf(stderr, "\n"); |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
337 | fprintf(stderr, "Advanced commands:\n"); |
507
dea7d1b4eea0
nicer dav usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
500
diff
changeset
|
338 | 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
|
339 | fprintf(stderr, "Config commands:\n"); |
507
dea7d1b4eea0
nicer dav usage info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
500
diff
changeset
|
340 | fprintf(stderr, " add-repository remove-repository list-repositories repository-url\n"); |
733
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
341 | fprintf(stderr, " add-user remove-user edit-user list-users set-master-password\n"); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
342 | fprintf(stderr, " check-config\n"); |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
343 | fprintf(stderr, "\n"); |
11 | 344 | fprintf(stderr, |
345 | "Instead of an url you can pass a repository name " | |
346 | "with an optional path:\n"); | |
347 | fprintf(stderr, " <repository>/path/\n"); | |
348 | fprintf(stderr, "\n"); | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
351 | |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
352 | |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
353 | 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
|
354 | char *plain = cmd_getoption(a, "plain"); |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
355 | char *crypt = cmd_getoption(a, "crypt"); |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
356 | |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
357 | if(plain && crypt) { |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
358 | 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
|
359 | return 1; |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
360 | } |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
361 | |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
362 | if (plain) { |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
363 | sn->flags &= ~DAV_SESSION_FULL_ENCRYPTION; |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
364 | } else if(crypt) { |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
365 | sn->flags |= DAV_SESSION_FULL_ENCRYPTION; |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
366 | } |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
367 | |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
368 | if (cmd_getoption(a, "verbose")) { |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
369 | 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
|
370 | curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
788
9b9420041d8e
add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
775
diff
changeset
|
371 | sn->logfunc = dav_verbose_log; |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
372 | } |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
373 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
374 | return 0; |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
375 | } |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
376 | |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
377 | 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
|
378 | char *locktoken = cmd_getoption(a, "lock"); |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
379 | if(locktoken) { |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
380 | 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
|
381 | dav_add_collection_lock(sn, "/", lock); |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
382 | } |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
383 | } |
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
384 | |
4 | 385 | |
355
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
386 | 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
|
387 | int ret = 0; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
388 | if(res != p->last_resource) { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
389 | 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
|
390 | ret = 1; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
391 | } else { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
392 | p->cur += now - p->last_res_cur; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
393 | } |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
394 | |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
395 | p->last_resource = res; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
396 | p->last_res_cur = now; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
397 | p->last_res_total = total; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
398 | |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
399 | return ret; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
400 | } |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
401 | |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
402 | 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
|
403 | Progress *p = data; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
404 | int newres = update_progress(res, total, now, p); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
405 | |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
406 | 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
|
407 | if((p->ts != newts)) { |
355
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
408 | 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
|
409 | fflush(p->out); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
410 | } |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
411 | p->ts = newts; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
412 | } |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
413 | |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
414 | |
297
3cbe57eeaed1
adds option to sort dav list by lastmodified date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
271
diff
changeset
|
415 | #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
|
416 | #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
|
417 | |
11 | 418 | int cmd_list(CmdArgs *a) { |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
419 | if(a->argc != 1) { |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
420 | 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
|
421 | 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
|
422 | return -1; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
423 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
424 | |
11 | 425 | 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
|
426 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
427 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
428 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
429 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
430 | if(set_session_config(sn, a)) { |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
431 | return -1; |
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 | |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
434 | 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
|
435 | 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
|
436 | time_t t = -1; |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
437 | if(update) { |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
438 | t = util_parse_lastmodified(update); |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
439 | } |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
440 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
441 | 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
|
442 | int ret = 0; |
806
673a803d2203
fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
798
diff
changeset
|
443 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
444 | DavResource *ls = dav_query( |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
445 | sn, |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
446 | 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
|
447 | path, |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
448 | depth, |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
449 | t); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
450 | if(ls) { |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
451 | // parameters |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
452 | 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
|
453 | 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
|
454 | print_func = ls_print_list_elm; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
455 | } else { |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
456 | print_func = ls_print_elm; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
457 | } |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
458 | |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
459 | DavResource *child = ls->children; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
460 | while(child) { |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
461 | print_func(child, path, a); |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
462 | child = child->next; |
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
463 | } |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
464 | } else { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
465 | print_resource_error(sn, path); |
425
ae4d89c3477c
fixes dav list return value
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
421
diff
changeset
|
466 | ret = -1; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
467 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
468 | |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
469 | free(path); |
40
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
470 | //free(base); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
471 | |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
472 | dav_session_destroy(sn); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
473 | |
38
b855f76e965b
code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
474 | return ret; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
475 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
476 | |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
477 | 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
|
478 | if(parent) { |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
479 | path += strlen(parent); |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
480 | } |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
481 | if(path[0] == '/') { |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
482 | path++; |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
483 | } |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
484 | int pathlen = strlen(path); |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
485 | if(path[pathlen-1] == '/') { |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
486 | pathlen--; |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
487 | } |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
488 | *len = pathlen; |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
489 | return path; |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
490 | } |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
491 | |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
492 | 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
|
493 | 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
|
494 | 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
|
495 | 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
|
496 | return; |
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
497 | } |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
498 | |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
499 | char flags[16]; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
500 | memset(flags, '-', 15); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
501 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
502 | int type_width = 0; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
503 | char *type = res->contenttype; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
504 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
505 | if(res->iscollection) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
506 | flags[0] = 'd'; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
507 | type = ""; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
508 | } |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
330
diff
changeset
|
509 | 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
|
510 | res, |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
511 | DAV_NS, |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
512 | "crypto-key"); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
513 | if(keyprop) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
514 | flags[1] = 'c'; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
515 | } |
213
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
516 | |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
517 | 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
|
518 | flags[6] = '\0'; |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
330
diff
changeset
|
519 | 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
|
520 | flags[2] = 'l'; |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
521 | } |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
330
diff
changeset
|
522 | 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
|
523 | res, |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
524 | "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
|
525 | "executable"); |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
526 | 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
|
527 | flags[3] = 'x'; |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
528 | } |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
529 | } else { |
cd870d5f8659
added options for extended list flags and changed version output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
212
diff
changeset
|
530 | flags[2] = '\0'; |
211
3d12817414e9
dav list indicates locks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
531 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
532 | |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
533 | if(cmd_getoption(a, "type")) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
534 | type_width = 20; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
535 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
536 | if(type == NULL || type_width == 0) { |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
537 | type = ""; |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
538 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
539 | |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
720
diff
changeset
|
540 | char *date = util_date_str(res->lastmodified); |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
720
diff
changeset
|
541 | char *size = util_size_str(res->iscollection, res->contentlength); |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
542 | int namelen = strlen(res->name); |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
543 | 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
|
544 | |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
545 | //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
|
546 | printf( |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
547 | "%s %*s %10s %12s %.*s\n", |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
548 | flags, |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
549 | type_width, type, |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
550 | size, |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
551 | date, |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
552 | namelen, |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
553 | name); |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
554 | free(date); |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
555 | free(size); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
556 | |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
557 | if(recursive) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
558 | DavResource *child = res->children; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
559 | while(child) { |
138
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
560 | //ls_print_list_elm(child, a); |
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
561 | if(child->name[0] != '.' || show_all) { |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
562 | 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
|
563 | } |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
564 | child = child->next; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
565 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
566 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
567 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
568 | |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
569 | 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
|
570 | 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
|
571 | 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
|
572 | 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
|
573 | return; |
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
574 | } |
6a3248e22d58
-a option wasn't working correctly in recursive mode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
575 | |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
576 | int namelen = strlen(res->name); |
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
577 | 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
|
578 | printf("%.*s\n", namelen, name); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
579 | if(recursive) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
580 | DavResource *child = res->children; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
581 | while(child) { |
270
0edfb4c0e7f8
fixes dav list -R output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
582 | ls_print_elm(child, parent, a); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
583 | child = child->next; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
584 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
585 | } |
14
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
586 | } |
d1a43035d3a2
added some options to list command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
587 | |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
588 | static void free_getres(void *r) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
589 | GetResource *getres = r; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
590 | free(getres->path); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
591 | free(getres); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
592 | } |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
593 | |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
594 | int cmd_get(CmdArgs *a, DavBool export) { |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
595 | if(a->argc != 1) { |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
596 | // 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
|
597 | 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
|
598 | 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
|
599 | return -1; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
600 | } |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
601 | if(export) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
602 | cxMapPut(a->options, cx_hash_key_str("recursive"), ""); |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
603 | } |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
604 | |
11 | 605 | 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
|
606 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
607 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
608 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
609 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
610 | if(set_session_config(sn, a)) { |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
611 | return -1; |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
612 | } |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
613 | |
355
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
614 | char *progressfile = cmd_getoption(a, "progressfile"); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
615 | Progress pdata; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
616 | memset(&pdata, 0, sizeof(Progress)); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
617 | if(progressfile) { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
618 | if(!strcmp(progressfile, "-")) { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
619 | pdata.out = stdout; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
620 | pdata.isstdout = 1; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
621 | } else { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
622 | pdata.out = fopen(progressfile, "w"); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
623 | } |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
624 | if(pdata.out) { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
625 | dav_session_set_progresscallback(sn, download_progress, NULL, &pdata); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
626 | } |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
627 | } |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
628 | |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
629 | char *update = cmd_getoption(a, "update"); |
135
664aeaec8d25
replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
630 | time_t t = -1; |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
631 | if(update) { |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
632 | 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
|
633 | 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
|
634 | 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
|
635 | "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
|
636 | " 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
|
637 | " 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
|
638 | 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
|
639 | } |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
640 | } |
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
641 | |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
642 | 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
|
643 | 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
|
644 | |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
645 | if(recursive && version) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
646 | 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
|
647 | return -1; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
648 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
649 | |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
650 | DavResource *res; |
30
9a5a7a513a96
added update option for list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
651 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
652 | int depth = recursive ? -1 : 1; |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
653 | res = dav_query( |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
654 | sn, |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
655 | "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
|
656 | path, |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
657 | depth, |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
658 | t); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
659 | if(!res) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
660 | 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
|
661 | return -1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
662 | } |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
663 | if(!recursive && res->iscollection) { |
235
0468df02e18f
fixed dav get with -u option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
230
diff
changeset
|
664 | 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
|
665 | 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
|
666 | return -1; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
667 | } |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
668 | |
476
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
669 | if(version) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
670 | 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
|
671 | if(!vres) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
672 | 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
|
673 | return -1; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
674 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
675 | 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
|
676 | res = vres; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
677 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
678 | |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
679 | /* |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
680 | * determine the output file |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
681 | * 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
|
682 | */ |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
683 | char *outfile = cmd_getoption(a, "output"); |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
684 | char *basepath = outfile; |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
685 | if(!outfile) { |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
686 | if(res->iscollection) { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
687 | basepath = ""; |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
688 | } else { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
689 | basepath = res->name; |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
690 | } |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
691 | if(export) { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
692 | outfile = "-"; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
693 | } |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
694 | } else if(export) { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
695 | basepath = ""; |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
696 | } else if(res->iscollection && !strcmp(outfile, "-")) { |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
697 | fprintf( |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
698 | stderr, |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
699 | "Cannot write output to stdout " |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
700 | "if the requested resource is a collection.\n"); |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
701 | return -1; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
702 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
703 | |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
704 | // get list of resources |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
705 | CxList *reslist = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
706 | cxDefineDestructor(reslist, free_getres); |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
707 | uint64_t totalsize = 0; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
708 | uint64_t rescount = 0; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
709 | |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
710 | GetResource *getres = malloc(sizeof(GetResource)); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
711 | getres->res = res; |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
712 | getres->path = strdup(basepath); |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
713 | |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
714 | char *structure = cmd_getoption(a, "structure"); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
715 | |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
716 | // iterate over resource tree |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
717 | CxList *stack = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
718 | cxListInsert(stack, 0, getres); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
719 | while(cxListSize(stack) > 0) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
720 | GetResource *g = cxListAt(stack, 0); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
721 | cxListRemove(stack, 0); |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
722 | |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
723 | if(g->res->iscollection) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
724 | DavResource *child = g->res->children; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
725 | while(child) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
726 | // add resource to stack |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
727 | size_t pathlen = strlen(g->path); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
728 | GetResource *newres = malloc(sizeof(GetResource)); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
729 | newres->res = child; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
730 | newres->path = pathlen > 0 ? |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
731 | 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
|
732 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
733 | cxListInsert(stack, 0, newres); |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
734 | |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
735 | child = child->next; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
736 | } |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
737 | } else { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
738 | if(structure) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
739 | // download only directory structure |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
740 | // 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
|
741 | continue; // skip non-collection resource |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
742 | } |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
743 | totalsize += g->res->contentlength; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
744 | rescount++; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
745 | } |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
746 | |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
747 | if(strlen(g->path) == 0) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
748 | free_getres(g); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
749 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
750 | cxListAdd(reslist, g); |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
751 | } |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
752 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
753 | cxListDestroy(stack); |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
754 | |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
755 | // download resources |
355
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
756 | pdata.total = totalsize; |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
757 | |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
758 | int ret; |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
759 | getfunc get; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
760 | 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
|
761 | if(export) { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
762 | get = (getfunc)resource2tar; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
763 | FILE *tarfile = strcmp(outfile, "-") ? fopen(outfile, "wb") : stdout; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
764 | if(!tarfile) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
765 | perror("Cannot open tar output file"); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
766 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
767 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
768 | tout = tar_open(tarfile); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
769 | } else { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
770 | get = get_resource; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
771 | } |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
772 | CxIterator iter = cxListIterator(reslist); |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
773 | cx_foreach(GetResource *, res_item, iter) { |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
774 | ret = get(repo, res_item, a, tout); |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
775 | if(ret) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
776 | break; |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
777 | } |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
778 | } |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
779 | if(export) { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
780 | // close tar stream |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
781 | if(tar_close(tout)) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
782 | fprintf(stderr, "tar stream broken\n"); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
783 | ret = -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
784 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
785 | } |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
786 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
787 | cxListDestroy(reslist); |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
788 | free(path); |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
789 | |
355
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
790 | if(pdata.out && !pdata.isstdout) { |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
791 | fclose(pdata.out); |
5da2cf15eb44
adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
354
diff
changeset
|
792 | } |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
793 | return ret; |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
794 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
795 | |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
796 | 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
|
797 | int ret = fseek(f, offset, origin); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
798 | 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
|
799 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
800 | |
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
|
801 | 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
|
802 | // 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
|
803 | 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
|
804 | 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
|
805 | 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
|
806 | 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
|
807 | 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
|
808 | } 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
|
809 | 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
|
810 | 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
|
811 | } |
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
|
812 | |
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
|
813 | /* |
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
|
814 | * 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
|
815 | * 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
|
816 | * 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
|
817 | */ |
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
|
818 | 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
|
819 | 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
|
820 | "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
|
821 | "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
|
822 | " - 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
|
823 | " - 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
|
824 | " - 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
|
825 | "(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
|
826 | 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
|
827 | } |
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
|
828 | } |
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
|
829 | |
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
|
830 | // 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
|
831 | 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
|
832 | 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
|
833 | "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
|
834 | "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
|
835 | 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
|
836 | } |
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
|
837 | |
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
|
838 | 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
|
839 | } |
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
|
840 | |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
841 | int cmd_edit(CmdArgs *a) { |
715
f4da6141e233
removes win32 support for dav edit
Mike Becker <universe@uap-core.de>
parents:
712
diff
changeset
|
842 | #ifdef _WIN32 |
f4da6141e233
removes win32 support for dav edit
Mike Becker <universe@uap-core.de>
parents:
712
diff
changeset
|
843 | 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
|
844 | return -1; |
f4da6141e233
removes win32 support for dav edit
Mike Becker <universe@uap-core.de>
parents:
712
diff
changeset
|
845 | #else |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
846 | if(a->argc != 1) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
847 | 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
|
848 | 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
|
849 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
850 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
851 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
852 | char *url = a->argv[0]; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
853 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
854 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
855 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
856 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
857 | if(set_session_config(sn, a)) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
858 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
859 | } |
720
2b8a65ed6f4c
adds support for -L option in dav edit
Mike Becker <universe@uap-core.de>
parents:
719
diff
changeset
|
860 | 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
|
861 | |
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
|
862 | 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
|
863 | 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
|
864 | } |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
865 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
866 | char *version = cmd_getoption(a, "version"); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
867 | DavResource *res; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
868 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
869 | res = dav_resource_new(sn, path); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
870 | int fresh_resource = !dav_exists(res); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
871 | if(fresh_resource) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
872 | // 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
|
873 | // 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
|
874 | if(dav_create(res)) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
875 | 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
|
876 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
877 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
878 | } else { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
879 | if(!res) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
880 | print_resource_error(sn, path); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
881 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
882 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
883 | if(res->iscollection) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
884 | fprintf(stderr, "Resource %s is a collection " |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
885 | "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
|
886 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
887 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
888 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
889 | if(version) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
890 | DavResource *vres = find_version(res, version); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
891 | if(!vres) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
892 | 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
|
893 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
894 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
895 | dav_resource_free_all(res); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
896 | res = vres; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
897 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
898 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
899 | |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
900 | // get temp dir |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
901 | char* envtmp = getenv("TMPDIR"); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
902 | char* outfile; |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
903 | if(envtmp) { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
904 | size_t len = strlen(envtmp); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
905 | outfile = malloc(len+24); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
906 | memcpy(outfile, envtmp, len+1); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
907 | if(outfile[len-1] != '/') { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
908 | outfile[len] = '/'; |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
909 | outfile[len+1] = 0; |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
910 | } |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
911 | } else { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
912 | outfile = malloc(24); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
913 | strncpy(outfile, "/tmp/", 24); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
914 | } |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
915 | |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
916 | // 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
|
917 | if(access(outfile, W_OK)) { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
918 | char* home = getenv("HOME"); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
919 | if(home) { |
718
e71ffa69d3fe
cmd_edit. fixes wrong variable in second strlen() call
Mike Becker <universe@uap-core.de>
parents:
717
diff
changeset
|
920 | size_t len = strlen(home); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
921 | outfile = malloc(len+24); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
922 | memcpy(outfile, home, len+1); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
923 | if(outfile[len-1] != '/') { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
924 | outfile[len] = '/'; |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
925 | outfile[len+1] = 0; |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
926 | } |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
927 | } else { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
928 | // 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
|
929 | perror("Cannot write to temporary location"); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
930 | free(outfile); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
931 | return -1; |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
932 | } |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
933 | } |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
934 | |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
935 | // create temp file and open it |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
936 | 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
|
937 | int tmp_fd = mkstemp(outfile); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
938 | if(tmp_fd < 0) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
939 | perror("Cannot open temporary file"); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
940 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
941 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
942 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
943 | // get resource |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
944 | if(!fresh_resource) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
945 | FILE* tmp_stream = sys_fopen(outfile, "wb"); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
946 | if(!tmp_stream) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
947 | perror("Cannot open temporary file"); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
948 | free(outfile); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
949 | close(tmp_fd); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
950 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
951 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
952 | 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
|
953 | print_resource_error(sn, path); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
954 | free(outfile); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
955 | 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
|
956 | sys_unlink(outfile); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
957 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
958 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
959 | fclose(tmp_stream); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
960 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
961 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
962 | // 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
|
963 | SYS_STAT tmp_stat; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
964 | if(sys_stat(outfile, &tmp_stat)) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
965 | perror("Cannot stat temporary file"); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
966 | free(outfile); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
967 | 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
|
968 | sys_unlink(outfile); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
969 | return -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
970 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
971 | 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
|
972 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
973 | // open in editor |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
974 | char* default_editor = "vi"; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
975 | char* editor = getenv("EDITOR"); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
976 | if(!editor) editor = default_editor; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
977 | char* viargs[3] = {editor, outfile, NULL}; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
978 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
979 | int ret = 0; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
980 | pid_t pid = fork(); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
981 | if(pid < 0) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
982 | 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
|
983 | ret = -1; |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
984 | } else if(pid == 0) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
985 | if(execvp(viargs[0], viargs)) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
986 | perror("Opening the editor failed"); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
987 | return -1; |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
988 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
989 | } else { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
990 | int status = -1; |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
991 | ret = waitpid(pid, &status, 0); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
992 | if(ret < 0) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
993 | perror("Error waiting for editor"); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
994 | } else if(WEXITSTATUS(status)) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
995 | fprintf(stderr, |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
996 | "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
|
997 | ret = -1; |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
998 | } else { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
999 | // check if the file has changed |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1000 | 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
|
1001 | // 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
|
1002 | perror("Cannot stat temporary file"); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1003 | ret = -1; |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1004 | } 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
|
1005 | // upload changed file |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1006 | FILE* tmp_stream = sys_fopen(outfile, "rb"); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1007 | if(!tmp_stream) { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1008 | perror("Cannot open temporary file"); |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1009 | ret = -1; |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1010 | } else { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1011 | dav_set_content(res, tmp_stream, |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1012 | (dav_read_func)fread, |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1013 | (dav_seek_func)file_seek); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1014 | 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
|
1015 | ret = dav_store(res); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1016 | fclose(tmp_stream); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1017 | if(ret) { |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1018 | print_resource_error(sn, path); |
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1019 | } |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1020 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1021 | } else { |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1022 | 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
|
1023 | ret = 0; |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1024 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1025 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1026 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1027 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1028 | 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
|
1029 | 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
|
1030 | // 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
|
1031 | 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
|
1032 | } 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
|
1033 | 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
|
1034 | } |
717
764e9fac530d
look up temp location + coherent return codes
Mike Becker <universe@uap-core.de>
parents:
716
diff
changeset
|
1035 | free(outfile); |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1036 | free(path); |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1037 | |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1038 | return ret; |
715
f4da6141e233
removes win32 support for dav edit
Mike Becker <universe@uap-core.de>
parents:
712
diff
changeset
|
1039 | #endif |
709
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1040 | } |
857330e1e3f4
first draft for dav edit command
Mike Becker <universe@uap-core.de>
parents:
703
diff
changeset
|
1041 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1042 | int get_resource(DavCfgRepository *repo, GetResource *getres, CmdArgs *a, void *unused) { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1043 | DavResource *res = getres->res; |
350
5fc457fb2cb1
fixes wrong output path in dav get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
1044 | char *out = getres->path; |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1045 | |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1046 | 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
|
1047 | 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
|
1048 | |
412
dc74f736aea1
adds more fs abstraction
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
410
diff
changeset
|
1049 | int ret = sys_mkdir(out); |
333
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1050 | if(ret != 0 && errno != EEXIST) { |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1051 | fprintf(stderr, "Cannot create directory '%s': ", out); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1052 | perror(""); |
000cdd124115
refactores cmd_get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
332
diff
changeset
|
1053 | return 1; |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1054 | } |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1055 | |
309
8a474d2ad209
adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
1056 | return 0; |
8a474d2ad209
adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
1057 | } |
8a474d2ad209
adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
1058 | |
330
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1059 | int isstdout = !strcmp(out, "-"); |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1060 | if(cmd_getoption(a, "keep") && !isstdout) { |
410
0b9bea2d7283
adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
398
diff
changeset
|
1061 | SYS_STAT s; |
0b9bea2d7283
adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
398
diff
changeset
|
1062 | 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
|
1063 | if(errno != ENOENT) { |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1064 | perror("stat"); |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1065 | } |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1066 | } else { |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1067 | if(cmd_getoption(a, "recursive")) { |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1068 | 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
|
1069 | } |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1070 | return 0; |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1071 | } |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1072 | } |
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1073 | |
309
8a474d2ad209
adds option to dav get for downloading only the directory structure
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
305
diff
changeset
|
1074 | // 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
|
1075 | 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
|
1076 | printf("get: %s\n", res->path); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1077 | } |
330
54819e984a19
adds dav get option to keep existing files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
329
diff
changeset
|
1078 | |
410
0b9bea2d7283
adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
398
diff
changeset
|
1079 | FILE *fout = isstdout ? stdout : sys_fopen(out, "wb"); |
18
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1080 | if(!fout) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1081 | 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
|
1082 | return -1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1083 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1084 | |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
1085 | 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
|
1086 | fclose(fout); |
651989681053
recursive list and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
1087 | if(ret && strcmp(out, "-")) { |
207
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
204
diff
changeset
|
1088 | print_resource_error(res->session, res->path); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
204
diff
changeset
|
1089 | //if(strcmp(out, "-")) { |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
204
diff
changeset
|
1090 | // unlink(out); |
de23f8881e9f
fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
204
diff
changeset
|
1091 | //} |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1092 | } |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1093 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1094 | return 0; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1095 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1096 | |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1097 | #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
|
1098 | #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
|
1099 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1100 | int resource2tar(DavCfgRepository *repo, GetResource *res, CmdArgs *a, TarOutputStream *tar) { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1101 | DavResource *d = res->res; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1102 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1103 | if(d->iscollection) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1104 | fprintf(stderr, "add d: %s\n", res->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1105 | 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
|
1106 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1107 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1108 | fprintf(stderr, "add f: %s\n", res->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1109 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1110 | // add tar file header |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1111 | 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
|
1112 | 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
|
1113 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1114 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1115 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1116 | 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
|
1117 | print_resource_error(d->session, d->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1118 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1119 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1120 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1121 | // download content |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1122 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1123 | return tar_end_file(tar); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1124 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1125 | |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
1126 | 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
|
1127 | if(a->argc < 2) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1128 | 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
|
1129 | fprintf(stderr, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1130 | "Usage: dav %s\n", |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1131 | find_usage_str(import ? "import" : "put")); |
4 | 1132 | return -1; |
3
323689ada09d
disabled ssl cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
1133 | } |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1134 | DavBool use_stdin = FALSE; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1135 | 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
|
1136 | 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
|
1137 | if(use_stdin) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1138 | 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
|
1139 | return -1; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1140 | } else { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1141 | use_stdin = TRUE; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1142 | } |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1143 | } |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1144 | } |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1145 | |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
1146 | if(import) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
1147 | cxMapPut(a->options, cx_hash_key_str("resursive"), ""); |
376
222997d48ae1
moving tar option from get/put to new export/import commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
1148 | } |
3
323689ada09d
disabled ssl cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
1149 | |
11 | 1150 | 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
|
1151 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1152 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
1153 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
1154 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
1155 | if(set_session_config(sn, a)) { |
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
1156 | return -1; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
1157 | } |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
1158 | set_session_lock(sn, a); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
1159 | |
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
|
1160 | 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
|
1161 | // 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
|
1162 | 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
|
1163 | } |
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
|
1164 | |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1165 | DavBool printfile = FALSE; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1166 | DavBool ignoredirerr = FALSE; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1167 | if(a->argc > 2) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1168 | printfile = TRUE; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1169 | ignoredirerr = TRUE; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
1170 | } else if(cmd_getoption(a, "recursive")) { |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1171 | printfile = TRUE; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1172 | } |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1173 | |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1174 | 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
|
1175 | uint32_t finfo = 0; |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1176 | if(finfo_str) { |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
1177 | 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
|
1178 | } |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1179 | |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1180 | int ret; |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1181 | 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
|
1182 | 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
|
1183 | if(!import) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1184 | if(!strcmp(file, "-")) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1185 | FILE *in = stdin; |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1186 | 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
|
1187 | } else { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1188 | ret = put_entry( |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1189 | repo, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1190 | a, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1191 | sn, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1192 | path, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1193 | file, |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1194 | finfo, |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1195 | TRUE, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1196 | printfile, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1197 | ignoredirerr); |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1198 | } |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1199 | } else { |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1200 | ret = put_tar(repo, a, sn, file, path); |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1201 | } |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1202 | if(ret) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1203 | break; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1204 | } |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1205 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1206 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
1207 | free(path); |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1208 | dav_session_destroy(sn); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1209 | return ret; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1210 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1211 | |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1212 | #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG) |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1213 | #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1214 | #endif |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1215 | |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1216 | #ifdef _WIN32 |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1217 | #ifndef S_ISDIR |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1218 | #define S_ISDIR(mode) ((mode) & _S_IFMT) == _S_IFDIR |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1219 | #define S_ISREG(mode) ((mode) & _S_IFMT) == _S_IFREG |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1220 | #endif |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1221 | #endif |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1222 | |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1223 | |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1224 | int put_entry( |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1225 | DavCfgRepository *repo, |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1226 | CmdArgs *a, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1227 | DavSession *sn, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1228 | char *path, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1229 | char *file, |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1230 | uint32_t finfo, |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1231 | DavBool root, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1232 | DavBool printfile, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1233 | DavBool ignoredirerr) |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1234 | { |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1235 | int recursive = cmd_getoption(a, "recursive") ? 1 : 0; |
739
bba6a6e221b4
use sys_* io functions in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
1236 | SYS_STAT s; |
bba6a6e221b4
use sys_* io functions in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
1237 | if(sys_stat(file, &s)) { |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1238 | perror("stat"); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1239 | 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
|
1240 | return -1; |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
1241 | } |
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
1242 | |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1243 | int ret = 0; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1244 | if(S_ISDIR(s.st_mode)) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1245 | if(!recursive) { |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1246 | if(ignoredirerr) { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1247 | 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
|
1248 | } else { |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1249 | fprintf( |
241
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1250 | 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
|
1251 | "%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
|
1252 | file); |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1253 | return 1; |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1254 | } |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1255 | } |
271
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1256 | |
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1257 | if(!root) { |
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1258 | printf("mkcol: %s\n", file); |
744
f0d7178043c1
force mkcol for every directory in the dav put command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1259 | DavResource *res = dav_resource_new(sn, path); |
f0d7178043c1
force mkcol for every directory in the dav put command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1260 | res->iscollection = TRUE; |
f0d7178043c1
force mkcol for every directory in the dav put command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1261 | if(!dav_exists(res)) { |
f0d7178043c1
force mkcol for every directory in the dav put command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1262 | if(dav_create(res)) { |
f0d7178043c1
force mkcol for every directory in the dav put command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1263 | fprintf(stderr, "Cannot create collection %s\n", path); |
f0d7178043c1
force mkcol for every directory in the dav put command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1264 | print_resource_error(sn, res->path); |
f0d7178043c1
force mkcol for every directory in the dav put command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1265 | dav_resource_free(res); |
f0d7178043c1
force mkcol for every directory in the dav put command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1266 | return 1; |
f0d7178043c1
force mkcol for every directory in the dav put command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1267 | } |
f0d7178043c1
force mkcol for every directory in the dav put command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1268 | } |
f0d7178043c1
force mkcol for every directory in the dav put command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1269 | dav_resource_free(res); |
271
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1270 | } |
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1271 | |
739
bba6a6e221b4
use sys_* io functions in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
1272 | SYS_DIR dir = sys_opendir(file); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1273 | if(!dir) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1274 | // error |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1275 | } |
739
bba6a6e221b4
use sys_* io functions in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
1276 | SysDirEnt *entry; |
241
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1277 | int nument = 0; |
739
bba6a6e221b4
use sys_* io functions in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
1278 | while((entry = sys_readdir(dir)) != NULL) { |
bba6a6e221b4
use sys_* io functions in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
1279 | if(!strcmp(entry->name, ".") || !strcmp(entry->name, "..")) { |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1280 | continue; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1281 | } |
241
da7ace67deab
improved dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
236
diff
changeset
|
1282 | nument++; |
739
bba6a6e221b4
use sys_* io functions in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
1283 | char *entry_file = util_concat_path(file, entry->name); |
bba6a6e221b4
use sys_* io functions in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
1284 | char *entry_path = util_concat_path(path, entry->name); |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1285 | int r = put_entry( |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1286 | repo, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1287 | a, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1288 | sn, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1289 | entry_path, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1290 | entry_file, |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1291 | finfo, |
500
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1292 | FALSE, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1293 | printfile, |
0fe1514667e6
adds support for multiple file arguments for dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
498
diff
changeset
|
1294 | ignoredirerr); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1295 | free(entry_path); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1296 | free(entry_file); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1297 | if(r) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1298 | ret = 1; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1299 | break; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1300 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1301 | } |
739
bba6a6e221b4
use sys_* io functions in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
1302 | sys_closedir(dir); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1303 | } 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
|
1304 | if(printfile) { |
271
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1305 | printf("put: %s\n", file); |
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1306 | } |
7b1ca53f3897
fixes dav put output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
1307 | |
739
bba6a6e221b4
use sys_* io functions in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
1308 | FILE *in = sys_fopen(file, "rb"); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1309 | if(!in) { |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1310 | fprintf(stderr, "cannot open input file\n"); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1311 | return -1; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1312 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
1313 | const char *filename = util_resource_name(file); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1314 | //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
|
1315 | 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
|
1316 | //free(path); |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1317 | fclose(in); |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1318 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1319 | |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1320 | return ret; |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1321 | } |
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1322 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1323 | int put_tar(DavCfgRepository *repo, CmdArgs *a, DavSession *sn, char *tarfile, char *path) { |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1324 | int isstdin = !strcmp(tarfile, "-"); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1325 | FILE *in = isstdin ? stdin : fopen(tarfile, "rb"); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1326 | if(!in) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1327 | perror("Cannot open tar file"); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1328 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1329 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1330 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
1331 | 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
|
1332 | if(!col) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1333 | if(sn->error == DAV_NOT_FOUND) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1334 | col = dav_resource_new(sn, path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1335 | col->iscollection = TRUE; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1336 | if(dav_create(col)) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1337 | print_resource_error(sn, path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1338 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1339 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1340 | } else { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1341 | print_resource_error(sn, path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1342 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1343 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1344 | } else if(!col->iscollection) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1345 | 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
|
1346 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1347 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1348 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1349 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1350 | int ret = 0; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1351 | TarInputStream *tar = tar_inputstream_open(in); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1352 | TarEntry *e = NULL; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1353 | while((e = tar_read_entry(tar)) != NULL) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1354 | char *newpath = util_concat_path(path, e->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1355 | if(e->type == TAR_TYPE_FILE) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1356 | fprintf(stderr, "put: %s\n", e->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1357 | DavResource *res = dav_resource_new(sn, newpath); |
478
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
476
diff
changeset
|
1358 | 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
|
1359 | dav_set_content_length(res, (size_t)e->size); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1360 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1361 | if(dav_store(res)) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1362 | print_resource_error(sn, res->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1363 | fprintf(stderr, "Cannot upload file.\n"); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1364 | if(sn->errorstr) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1365 | fprintf(stderr, "%s\n", sn->errorstr); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1366 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1367 | return -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1368 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1369 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1370 | } else if(e->type == TAR_TYPE_DIRECTORY) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1371 | printf("mkcol: %s\n", e->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1372 | DavResource *res = dav_resource_new(sn, newpath); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1373 | res->iscollection = TRUE; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1374 | if(!dav_exists(res)) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1375 | if(dav_create(res)) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1376 | fprintf(stderr, "Cannot create collection %s\n", newpath); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1377 | print_resource_error(sn, res->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1378 | ret = 1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1379 | free(newpath); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1380 | break; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1381 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1382 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1383 | } else { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1384 | fprintf(stderr, "skip: %s\n", e->path); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1385 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1386 | free(newpath); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1387 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1388 | if(tar->error != TAR_OK) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1389 | ret = -1; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1390 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1391 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1392 | if(!isstdin) { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1393 | fclose(in); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1394 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1395 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1396 | return ret; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1397 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
333
diff
changeset
|
1398 | |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1399 | int put_file( |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1400 | DavCfgRepository *repo, |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1401 | CmdArgs *a, |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1402 | DavSession *sn, |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
1403 | const char *path, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
1404 | const char *name, |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1405 | uint32_t finfo, |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1406 | const char *fpath, |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1407 | FILE *in, |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1408 | off_t len) |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1409 | { |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
1410 | 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
|
1411 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1412 | if(!res) { |
24
a317202ae787
implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
1413 | if(sn->error == DAV_NOT_FOUND) { |
21 | 1414 | 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
|
1415 | if(dav_create(res)) { |
a317202ae787
implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
1416 | fprintf(stderr, "Cannot create resource.\n"); |
a317202ae787
implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
1417 | return -1; |
a317202ae787
implemented dav_create for non-collection resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
1418 | } |
21 | 1419 | } else { |
198
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
197
diff
changeset
|
1420 | print_resource_error(sn, path); |
21 | 1421 | return -1; |
1422 | } | |
1423 | } else if(res->iscollection) { | |
1424 | // TODO: free res | |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1425 | 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
|
1426 | |
e554f3d72d9e
fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents:
352
diff
changeset
|
1427 | 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
|
1428 | // 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
|
1429 | 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
|
1430 | "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
|
1431 | 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
|
1432 | 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
|
1433 | } |
e554f3d72d9e
fixes infinite loop when trying to overwrite a collection with a regular file
Mike Becker <universe@uap-core.de>
parents:
352
diff
changeset
|
1434 | |
21 | 1435 | path = newpath; |
1436 | 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
|
1437 | 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
|
1438 | // TODO: free res |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
1439 | free(newpath); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
1440 | return ret; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1441 | } |
517
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1442 | |
8531b63accae
adds option to store a file info property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
512
diff
changeset
|
1443 | 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
|
1444 | 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
|
1445 | } |
539
8deb52292c99
fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
1446 | if((finfo & FINFO_XATTR) == FINFO_XATTR) { |
618
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1447 | 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
|
1448 | if(xattr) { |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
1449 | resource_set_xattr(res, xattr); |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
1450 | } |
da2b0cc44e4f
adds xml attribute support and xattr property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
517
diff
changeset
|
1451 | } |
12
493128ef1b12
added some options to put and get
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
1452 | |
478
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
476
diff
changeset
|
1453 | 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
|
1454 | if(len > 0 && len < 0x7d000000) { |
179
802b48ae791d
enable sharepoint put fix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
178
diff
changeset
|
1455 | 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
|
1456 | } |
4 | 1457 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1458 | if(dav_store(res)) { |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1459 | print_resource_error(sn, res->path); |
13
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
1460 | fprintf(stderr, "Cannot upload file.\n"); |
22
e593f7e41be0
added more error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
1461 | if(sn->errorstr) { |
e593f7e41be0
added more error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
1462 | fprintf(stderr, "%s\n", sn->errorstr); |
e593f7e41be0
added more error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
1463 | } |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1464 | return -1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1465 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
1466 | return 0; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1467 | } |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1468 | |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1469 | 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
|
1470 | res->iscollection = 1; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1471 | return dav_create(res); |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1472 | } |
28
4e46c65711ef
added recursive put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
1473 | |
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
|
1474 | 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
|
1475 | 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
|
1476 | 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
|
1477 | 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
|
1478 | 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
|
1479 | 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
|
1480 | 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
|
1481 | 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
|
1482 | 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
|
1483 | } |
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
|
1484 | } |
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
|
1485 | |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1486 | 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
|
1487 | int(*operation)(DavResource*), |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1488 | const char* command, |
683
53bcb5e47220
fix -c option for dav rm command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
1489 | const char* message, |
53bcb5e47220
fix -c option for dav rm command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
1490 | DavBool check_key) |
53bcb5e47220
fix -c option for dav rm command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
1491 | { |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1492 | if(a->argc < 1) { |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1493 | 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
|
1494 | 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
|
1495 | return -1; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1496 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1497 | |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1498 | char *url = a->argv[0]; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1499 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1500 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
1501 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1502 | |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1503 | int exit_code = -1; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1504 | assert(!!path && !!sn); |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1505 | |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
1506 | 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
|
1507 | goto cmd_oponres_exit; |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
1508 | } |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1509 | |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
1510 | set_session_lock(sn, a); |
45
e3839719b079
added crypt command line option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
1511 | |
683
53bcb5e47220
fix -c option for dav rm command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
1512 | 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
|
1513 | goto cmd_oponres_exit; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1514 | } |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1515 | |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1516 | 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
|
1517 | assert(!!res); |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1518 | res->iscollection = 1; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1519 | |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1520 | if(a->argc == 1) { |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1521 | 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
|
1522 | print_cannoterr(sn, message); |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1523 | 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
|
1524 | goto cmd_oponres_exit; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1525 | } |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1526 | } else { |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1527 | 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
|
1528 | 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
|
1529 | assert(!!child); |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1530 | child->iscollection = 1; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1531 | 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
|
1532 | print_cannoterr(sn, message); |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1533 | 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
|
1534 | goto cmd_oponres_exit; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1535 | } |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1536 | } |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1537 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1538 | |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1539 | exit_code = 0; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1540 | cmd_oponres_exit: |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
1541 | free(path); |
540
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1542 | dav_session_destroy(sn); |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1543 | return exit_code; |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1544 | } |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1545 | |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1546 | int cmd_remove(CmdArgs *a) { |
d18f92483945
adds multiple file support for mkdir and remove
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
1547 | 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
|
1548 | "remove", "delete resource", FALSE); |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
1549 | } |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
1550 | |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
1551 | 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
|
1552 | 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
|
1553 | "mkdir", "create collection", TRUE); |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
1554 | } |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1555 | |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1556 | 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
|
1557 | const char* actionstr = cp ? "copy" : "move"; |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1558 | |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1559 | if(a->argc != 2) { |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1560 | // 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
|
1561 | 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
|
1562 | 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
|
1563 | return -1; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1564 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1565 | |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1566 | char *srcurl = a->argv[0]; |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1567 | char *srcpath = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1568 | DavCfgRepository *srcrepo = dav_config_url2repo(get_config(), srcurl, &srcpath); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1569 | |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
1570 | DavSession *srcsn = connect_to_repo(ctx, srcrepo, srcpath, request_auth, a); |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1571 | if(set_session_config(srcsn, a)) { |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1572 | return -1; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1573 | } |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1574 | set_session_lock(srcsn, a); |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
1575 | |
182
ca07f14f7bfe
added override option for copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
181
diff
changeset
|
1576 | 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
|
1577 | |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1578 | char *desturl = a->argv[1]; |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1579 | char *destpath = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1580 | DavCfgRepository *destrepo = dav_config_url2repo(get_config(), desturl, &destpath); |
382
1ce7211a1021
fixes memory leak in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
380
diff
changeset
|
1581 | |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1582 | if(srcrepo == destrepo) { |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1583 | DavResource *res = dav_resource_new(srcsn, srcpath); |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1584 | 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
|
1585 | : dav_move_o(res, destpath, override); |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1586 | if(err) { |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1587 | print_resource_error(srcsn, res->path); |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1588 | 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
|
1589 | return -1; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1590 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1591 | } else { |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1592 | char *srchost = util_url_base(srcrepo->url.value.ptr); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1593 | char *desthost = util_url_base(destrepo->url.value.ptr); |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1594 | if(!strcmp(srchost, desthost)) { |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
1595 | DavSession *destsn = connect_to_repo(ctx, destrepo, destpath, request_auth, a); |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1596 | if(set_session_config(destsn, a)) { |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1597 | return -1; |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1598 | } |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1599 | DavResource *dest = dav_resource_new(destsn, destpath); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1600 | char *desthref = dav_resource_get_href(dest); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
1601 | desturl = util_get_url(destsn, desthref); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1602 | |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1603 | DavResource *res = dav_resource_new(srcsn, srcpath); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1604 | int err = cp ? dav_copyto(res, desturl, override) |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1605 | : dav_moveto(res, desturl, override); |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1606 | |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1607 | free(desturl); |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1608 | dav_session_destroy(destsn); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1609 | |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1610 | if(err) { |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1611 | print_resource_error(srcsn, res->path); |
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1612 | fprintf(stderr, "Cannot %s resource.\n", actionstr); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1613 | return -1; |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1614 | } |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1615 | } else { |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1616 | fprintf(stderr, "Cannot %s between different hosts.\n", actionstr); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1617 | return -1; |
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1618 | } |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1619 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1620 | |
383
bc215bdaf9bc
improves variable names in cmd_move()
Mike Becker <universe@uap-core.de>
parents:
382
diff
changeset
|
1621 | dav_session_destroy(srcsn); |
186
05d11fbcaeb3
improved copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1622 | |
181
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1623 | return 0; |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1624 | } |
a8f8cdbf85df
implemented webdav copy and move method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
1625 | |
498
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1626 | int cmd_rename(CmdArgs *a) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1627 | if(a->argc != 2) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1628 | // TODO: change, when creation of multiple dirs is supported |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1629 | 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
|
1630 | fprintf(stderr, "Usage: dav %s\n", find_usage_str("rename")); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1631 | return -1; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1632 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1633 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1634 | char *name = a->argv[1]; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1635 | size_t namelen = strlen(name); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1636 | for(size_t i=0;i<namelen;i++) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1637 | char c = name[i]; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1638 | if(c == '/') { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1639 | fprintf(stderr, "Illegal character in name: '/'\n"); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1640 | return 1; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1641 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1642 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1643 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1644 | char *url = a->argv[0]; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1645 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1646 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
1647 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
498
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1648 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1649 | if(set_session_config(sn, a)) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1650 | return -1; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1651 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1652 | set_session_lock(sn, a); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1653 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1654 | int ret = 0; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1655 | DavResource *res = dav_get(sn, path, NULL); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1656 | if(res) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1657 | 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
|
1658 | 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
|
1659 | if(cryptoname && cryptokey) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1660 | // encrypted resource with an encrypted name |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1661 | // renaming is done by simply setting the crypto-name property |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1662 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1663 | DavKey *key = dav_context_get_key(ctx, cryptokey); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1664 | if(key) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1665 | // check if a resource with this name already exists |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1666 | char *parent = util_parent_path(res->path); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1667 | char *newpath = util_concat_path(parent, name); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1668 | DavResource *testres = dav_resource_new(sn, newpath); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1669 | if(dav_exists(testres)) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1670 | 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
|
1671 | ret = 1; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1672 | } else { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1673 | char *crname = aes_encrypt(name, namelen, key); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1674 | 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
|
1675 | free(crname); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1676 | if(dav_store(res)) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1677 | print_resource_error(sn, res->path); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1678 | fprintf(stderr, "Cannot store crypto-name property.\n"); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1679 | ret = 1; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1680 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1681 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1682 | free(parent); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1683 | free(newpath); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1684 | } else { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1685 | fprintf(stderr, "Key %s not found.\n", cryptokey); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1686 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1687 | } else { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1688 | // rename the resource by changing the url mapping with MOVE |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1689 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1690 | char *parent = util_parent_path(res->href); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1691 | char *new_href = util_concat_path(parent, name); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1692 | char *dest = util_get_url(sn, new_href); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1693 | free(parent); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1694 | free(new_href); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1695 | if(dav_moveto(res, dest, false)) { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1696 | print_resource_error(sn, path); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1697 | fprintf(stderr, "Cannot rename resource.\n"); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1698 | ret = 1; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1699 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1700 | free(dest); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1701 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1702 | } else { |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1703 | print_resource_error(sn, path); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1704 | fprintf(stderr, "Cannot rename resource.\n"); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1705 | ret = 1; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1706 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1707 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1708 | |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1709 | dav_session_destroy(sn); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1710 | free(path); |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1711 | return ret; |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1712 | } |
37af2eac3e6a
adds rename command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
494
diff
changeset
|
1713 | |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1714 | |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1715 | 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
|
1716 | char **date_str = (char**)data; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1717 | |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1718 | //printf("header: %.*s\n", s*n, header); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
1719 | cxstring h = cx_strn(header, s*n); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
1720 | if(cx_strprefix(h, CX_STR("Date:"))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
1721 | cxstring v = cx_strsubs(h, 5); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
1722 | *date_str = cx_strdup(cx_strtrim(v)).ptr; |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1723 | } |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1724 | return s*n; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1725 | } |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1726 | |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1727 | int cmd_date(CmdArgs *a) { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1728 | if(a->argc < 1) { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1729 | time_t now = time(NULL); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1730 | struct tm *date = gmtime(&now); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1731 | char str[32]; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1732 | putenv("LC_TIME=C"); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1733 | 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
|
1734 | fwrite(str, 1, len, stdout); |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
1735 | } else if (a->argc == 1) { |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1736 | char *url = a->argv[0]; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1737 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1738 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
1739 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1740 | |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1741 | DavResource *res = dav_resource_new(sn, path); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1742 | char *date = NULL; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1743 | 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
|
1744 | curl_easy_setopt(sn->handle, CURLOPT_WRITEHEADER, &date); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1745 | if(dav_exists(res) && date) { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1746 | printf("%s\n", date); |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1747 | } else { |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1748 | return -1; |
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1749 | } |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
1750 | free(path); |
35
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
1751 | return 0; |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
1752 | } else { |
ad0c9dacd7e3
errors on too many arguments
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
1753 | 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
|
1754 | 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
|
1755 | return -1; |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1756 | } |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
1757 | return 0; |
29
938957a4eea7
added date command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
1758 | } |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1759 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1760 | int cmd_get_property(CmdArgs *a) { |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1761 | if(a->argc < 2) { |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1762 | 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
|
1763 | 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
|
1764 | return -1; |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1765 | } |
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1766 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1767 | char *url = a->argv[0]; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1768 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1769 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
1770 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1771 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1772 | if(set_session_config(sn, a)) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1773 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1774 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1775 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1776 | char *namespace = cmd_getoption(a, "namespace"); |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1777 | char *property = a->argv[1]; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1778 | |
476
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1779 | 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
|
1780 | |
298
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
1781 | DavPropName propname; |
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
1782 | if(namespace) { |
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
1783 | propname.ns = namespace; |
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
1784 | propname.name = property; |
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
1785 | } else { |
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
1786 | 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
|
1787 | if(!propname.ns || !propname.name) { |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
316
diff
changeset
|
1788 | fprintf(stderr, "Error: unknown namespace prefix\n"); |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
316
diff
changeset
|
1789 | return -1; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
316
diff
changeset
|
1790 | } |
298
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
1791 | } |
755b8198b071
dav get-property shouldn't send an allprop propfind request
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
1792 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1793 | 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
|
1794 | if(version) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1795 | 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
|
1796 | if(!vres) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1797 | 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
|
1798 | return -1; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1799 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1800 | 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
|
1801 | res = vres; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1802 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
1803 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
1804 | if(dav_load_prop(res, &propname, 1)) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
1805 | print_resource_error(sn, res->path); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
1806 | return -1; |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1807 | } |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
1808 | free(path); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1809 | |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
1810 | 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
|
1811 | if(!x) { |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1812 | 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
|
1813 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1814 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1815 | |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
1816 | if(cmd_getoption(a, "xml")) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
1817 | // 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
|
1818 | 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
|
1819 | } else { |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
1820 | // 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
|
1821 | // 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
|
1822 | if(dav_xml_isstring(x)) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
1823 | 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
|
1824 | } else { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
1825 | char *str = xml2str(x); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
1826 | fprintf(stderr, "%s", str); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
1827 | free(str); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
1828 | } |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1829 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1830 | |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
1831 | return 0; |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1832 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1833 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1834 | int cmd_set_property(CmdArgs *a) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1835 | if(a->argc < 2) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1836 | 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
|
1837 | 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
|
1838 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1839 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1840 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1841 | char *url = a->argv[0]; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1842 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1843 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
1844 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1845 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1846 | if(set_session_config(sn, a)) { |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1847 | return -1; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1848 | } |
210
1d19e0ff18d9
added lock support to some dav commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
1849 | set_session_lock(sn, a); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1850 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1851 | 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
|
1852 | if(!dav_exists(res)) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
1853 | print_resource_error(sn, res->path); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
1854 | return -1; |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1855 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1856 | |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1857 | 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
|
1858 | 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
|
1859 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1860 | char *property = a->argv[1]; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1861 | 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
|
1862 | |
371
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1863 | int ret = 0; |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1864 | if(xml) { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1865 | 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
|
1866 | if(xmlvalue) { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1867 | if(namespace) { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1868 | 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
|
1869 | } else { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1870 | 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
|
1871 | } |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1872 | } else { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1873 | 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
|
1874 | ret = 1; |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1875 | } |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1876 | } else { |
371
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1877 | if(namespace) { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1878 | 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
|
1879 | } else { |
822
f9e40f5c6daf
fix dav_set_string_property crash if an unknown namespace prefix was specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
816
diff
changeset
|
1880 | if(dav_set_string_property(res, property, value)) { |
f9e40f5c6daf
fix dav_set_string_property crash if an unknown namespace prefix was specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
816
diff
changeset
|
1881 | fprintf(stderr, "%s\n", res->session->errorstr); |
f9e40f5c6daf
fix dav_set_string_property crash if an unknown namespace prefix was specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
816
diff
changeset
|
1882 | } |
371
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1883 | } |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1884 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1885 | |
371
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1886 | if(ret == 0) { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1887 | if(dav_store(res)) { |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1888 | 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
|
1889 | 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
|
1890 | ret = -1; |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1891 | } |
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1892 | } else |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1893 | |
74
da079dc0724c
fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
73
diff
changeset
|
1894 | free(path); |
371
604e7e335b3b
adds support for xml properties in set-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
1895 | 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
|
1896 | return ret; |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
1897 | } |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1898 | |
304
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1899 | int cmd_remove_property(CmdArgs *a) { |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1900 | if(a->argc < 2) { |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1901 | 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
|
1902 | 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
|
1903 | return -1; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1904 | } |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1905 | |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1906 | char *url = a->argv[0]; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1907 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1908 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
1909 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
304
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1910 | |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1911 | if(set_session_config(sn, a)) { |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1912 | return -1; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1913 | } |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1914 | |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1915 | char *namespace = cmd_getoption(a, "namespace"); |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1916 | char *property = a->argv[1]; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1917 | |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1918 | DavPropName propname; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1919 | if(namespace) { |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1920 | propname.ns = namespace; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1921 | propname.name = property; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1922 | } else { |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1923 | 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
|
1924 | } |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1925 | |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1926 | int ret = 0; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1927 | DavResource *res = dav_resource_new(sn, path); |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1928 | 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
|
1929 | |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
1930 | if(dav_store(res)) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
1931 | print_resource_error(sn, res->path); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
1932 | fprintf(stderr, "Cannot set property.\n"); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
1933 | ret = -1; |
304
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1934 | } |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1935 | |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1936 | free(path); |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1937 | return ret; |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1938 | } |
a4d3ff32d49c
adds dav remove-property command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1939 | |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1940 | int cmd_lock(CmdArgs *a) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1941 | if(a->argc != 1) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1942 | 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
|
1943 | 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
|
1944 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1945 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1946 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1947 | char *url = a->argv[0]; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1948 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
1949 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
1950 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
775 | 1951 | cxMempoolRegister(sn->mp, path, free); |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1952 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1953 | if(set_session_config(sn, a)) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1954 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1955 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1956 | |
315
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
1957 | time_t timeout = 0; |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
1958 | char *timeoutstr = cmd_getoption(a, "timeout"); |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
1959 | if(timeoutstr) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
1960 | if(!cx_strcasecmp(cx_str(timeoutstr), CX_STR("infinite"))) { |
315
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
1961 | timeout = -1; |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
1962 | } else { |
509
0576dd6409f3
fixed TODO: use strtol
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
508
diff
changeset
|
1963 | uint64_t i; |
512
3320a015a3bc
fixes signed vs unsigned inaccuracy for the -T option
Mike Becker <universe@uap-core.de>
parents:
511
diff
changeset
|
1964 | if(util_strtouint(timeoutstr, &i)) { |
509
0576dd6409f3
fixed TODO: use strtol
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
508
diff
changeset
|
1965 | timeout = (time_t)i; |
0576dd6409f3
fixed TODO: use strtol
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
508
diff
changeset
|
1966 | } else { |
0576dd6409f3
fixed TODO: use strtol
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
508
diff
changeset
|
1967 | fprintf(stderr, "Error: -T option has invalid value\n"); |
0576dd6409f3
fixed TODO: use strtol
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
508
diff
changeset
|
1968 | return -1; |
0576dd6409f3
fixed TODO: use strtol
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
508
diff
changeset
|
1969 | } |
315
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
1970 | } |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
1971 | } |
7db4dbf4e6f9
adds lock timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
1972 | |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1973 | 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
|
1974 | 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
|
1975 | 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
|
1976 | return -1; |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1977 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1978 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1979 | 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
|
1980 | if(!lock) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1981 | // this should really not happen |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1982 | // do some damage control |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1983 | dav_unlock(res); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1984 | 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
|
1985 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1986 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1987 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1988 | printf("%s\n", lock->token); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1989 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1990 | dav_session_destroy(sn); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1991 | return 0; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1992 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1993 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1994 | static char* read_line() { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
1995 | CxBuffer buf; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
1996 | cxBufferInit(&buf, NULL, 128, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1997 | int c; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1998 | while((c = getchar()) != EOF) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
1999 | if(c == '\n') { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2000 | break; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2001 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2002 | cxBufferPut(&buf, c); |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2003 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2004 | char *str = NULL; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2005 | cxstring line = cx_strtrim(cx_strn(buf.space, buf.size)); |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2006 | if(line.length != 0) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2007 | str = cx_strdup(line).ptr; |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2008 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2009 | cxBufferDestroy(&buf); |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2010 | return str; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2011 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2012 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2013 | int cmd_unlock(CmdArgs *a) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2014 | if(a->argc != 1) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2015 | 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
|
2016 | 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
|
2017 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2018 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2019 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2020 | char *url = a->argv[0]; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2021 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2022 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
2023 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
775 | 2024 | cxMempoolRegister(sn->mp, path, free); |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2025 | if(set_session_config(sn, a)) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2026 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2027 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2028 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2029 | char *locktoken = cmd_getoption(a, "lock"); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2030 | if(locktoken) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2031 | 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
|
2032 | dav_add_collection_lock(sn, "/", lock); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2033 | } else { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2034 | locktoken = read_line(); |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2035 | if(!locktoken) { |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2036 | 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
|
2037 | return -1; |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2038 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2039 | 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
|
2040 | 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
|
2041 | free(locktoken); |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2042 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2043 | |
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
|
2044 | int ret = 0; |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2045 | 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
|
2046 | 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
|
2047 | 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
|
2048 | ret = -1; |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2049 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2050 | |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2051 | 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
|
2052 | return ret; |
209
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2053 | } |
d24761f1e07c
added lock and unlock commands to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
207
diff
changeset
|
2054 | |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2055 | static int count_children(DavResource *res) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2056 | DavResource *child = res->children; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2057 | int count = 0; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2058 | while(child) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2059 | count++; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2060 | child = child->next; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2061 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2062 | return count; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2063 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2064 | |
373
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2065 | void print_xml_infostr(DavXmlNode *xml) { |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2066 | if(xml->children) { |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2067 | printf("<%s>...</%s>", xml->name, xml->name); |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2068 | } else { |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2069 | printf("<%s/>", xml->name); |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2070 | } |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2071 | } |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2072 | |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2073 | int cmd_info(CmdArgs *a) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2074 | if(a->argc < 1) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2075 | 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
|
2076 | 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
|
2077 | return -1; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2078 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2079 | |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2080 | char *url = a->argv[0]; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2081 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2082 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
2083 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2084 | |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2085 | if(set_session_config(sn, a)) { |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2086 | return -1; |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2087 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2088 | |
476
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2089 | 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
|
2090 | |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2091 | 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
|
2092 | if(version) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2093 | 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
|
2094 | if(!vres) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2095 | 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
|
2096 | return -1; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2097 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2098 | 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
|
2099 | res = vres; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2100 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2101 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2102 | if(!dav_load(res)) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2103 | printf("name: %s\n", res->name); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2104 | printf("path: %s\n", res->path); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2105 | |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2106 | char *server = util_url_base(sn->base_url); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
2107 | url = util_concat_path(server, res->href); |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2108 | printf("url: %s\n", url); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2109 | free(url); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2110 | 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
|
2111 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2112 | if(res->iscollection) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2113 | printf("type: collection\n"); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2114 | printf("size: %d\n", count_children(res)); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2115 | } else { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2116 | printf("type: resource\n"); |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
720
diff
changeset
|
2117 | char *len = util_size_str(res->iscollection, res->contentlength); |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2118 | printf("size: %s\n", len); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2119 | free(len); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2120 | } |
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
|
2121 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2122 | size_t count = 0; |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2123 | 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
|
2124 | |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2125 | char *last_ns = NULL; |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2126 | for(int i=0;i<count;i++) { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2127 | DavPropName p = properties[i]; |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2128 | 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
|
2129 | printf("\nnamespace: %s\n", p.ns); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2130 | 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
|
2131 | } |
571b62700df6
adds auth prompt to dav get-property, set-property, lock, unlock and info
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
2132 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2133 | 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
|
2134 | if(dav_xml_isstring(xval)) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2135 | cxstring value = cx_str(dav_xml_getstring(xval)); |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2136 | 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
|
2137 | } else { |
373
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2138 | // find some xml elements |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2139 | printf(" %s: ", p.name); |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2140 | DavXmlNode *x = xval->type == DAV_XML_ELEMENT ? xval : dav_xml_nextelm(xval); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
2141 | for(int j=0;j<3;j++) { |
373
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2142 | if(x) { |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
2143 | if(j == 2) { |
373
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2144 | printf(" ..."); |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2145 | break; |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2146 | } else { |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2147 | print_xml_infostr(x); |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2148 | } |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2149 | } else { |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2150 | break; |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2151 | } |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2152 | x = dav_xml_nextelm(x); |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2153 | } |
dcc03142eb5f
dav info prints simplified xml values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
2154 | printf("\n"); |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2155 | } |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2156 | } |
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
|
2157 | |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2158 | dav_session_free(sn, properties); |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2159 | return 0; |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2160 | } else { |
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2161 | print_resource_error(sn, res->path); |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2162 | } |
354
067ea2315a8a
moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
353
diff
changeset
|
2163 | |
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
|
2164 | return -1; |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2165 | } |
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2166 | |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2167 | int cmd_checkout(CmdArgs *a) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2168 | if(a->argc < 1) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2169 | fprintf(stderr, "Too few arguments\n"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2170 | fprintf(stderr, "Usage: dav %s\n", "checkout [-pc] <url>"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2171 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2172 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2173 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2174 | char *url = a->argv[0]; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2175 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2176 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
2177 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2178 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2179 | if(set_session_config(sn, a)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2180 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2181 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2182 | set_session_lock(sn, a); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2183 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2184 | int ret = 0; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2185 | DavResource *res = dav_resource_new(sn, path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2186 | if(dav_checkout(res)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2187 | print_resource_error(sn, res->path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2188 | ret = 1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2189 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2190 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2191 | return ret; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2192 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2193 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2194 | int cmd_checkin(CmdArgs *a) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2195 | if(a->argc < 1) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2196 | fprintf(stderr, "Too few arguments\n"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2197 | fprintf(stderr, "Usage: dav %s\n", "checkin [-pc] <url>"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2198 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2199 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2200 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2201 | char *url = a->argv[0]; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2202 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2203 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
2204 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2205 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2206 | if(set_session_config(sn, a)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2207 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2208 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2209 | set_session_lock(sn, a); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2210 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2211 | int ret = 0; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2212 | DavResource *res = dav_resource_new(sn, path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2213 | if(dav_checkin(res)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2214 | print_resource_error(sn, res->path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2215 | ret = 1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2216 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2217 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2218 | return ret; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2219 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2220 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2221 | int cmd_uncheckout(CmdArgs *a) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2222 | if(a->argc < 1) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2223 | fprintf(stderr, "Too few arguments\n"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2224 | fprintf(stderr, "Usage: dav %s\n", "uncheckout [-pc] <url>"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2225 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2226 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2227 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2228 | char *url = a->argv[0]; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2229 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2230 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
2231 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2232 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2233 | if(set_session_config(sn, a)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2234 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2235 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2236 | set_session_lock(sn, a); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2237 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2238 | int ret = 0; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2239 | DavResource *res = dav_resource_new(sn, path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2240 | if(dav_uncheckout(res)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2241 | print_resource_error(sn, res->path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2242 | ret = 1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2243 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2244 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2245 | return ret; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2246 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2247 | int cmd_versioncontrol(CmdArgs *a) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2248 | if(a->argc < 1) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2249 | fprintf(stderr, "Too few arguments\n"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2250 | fprintf(stderr, "Usage: dav %s\n", "versioncontrol [-pc] <url>"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2251 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2252 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2253 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2254 | char *url = a->argv[0]; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2255 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2256 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
2257 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2258 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2259 | if(set_session_config(sn, a)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2260 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2261 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2262 | set_session_lock(sn, a); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2263 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2264 | int ret = 0; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2265 | DavResource *res = dav_resource_new(sn, path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2266 | if(dav_versioncontrol(res)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2267 | print_resource_error(sn, res->path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2268 | ret = 1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2269 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2270 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2271 | return ret; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2272 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2273 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2274 | int cmd_list_versions(CmdArgs *a) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2275 | if(a->argc < 1) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2276 | fprintf(stderr, "Too few arguments\n"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2277 | 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
|
2278 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2279 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2280 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2281 | char *url = a->argv[0]; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2282 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2283 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
2284 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
475
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2285 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2286 | if(set_session_config(sn, a)) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2287 | return -1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2288 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2289 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2290 | DavResource *res = dav_resource_new(sn, path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2291 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2292 | int ret = 0; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2293 | DavResource *list = dav_versiontree(res, NULL); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2294 | if(list) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2295 | char* longlist = cmd_getoption(a, "list"); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2296 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2297 | DavResource *v = list; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2298 | int addnl = 0; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2299 | while(v) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2300 | 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
|
2301 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2302 | if(longlist) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2303 | if(addnl) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2304 | putchar('\n'); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2305 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2306 | printf("name: %s\n", vname); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2307 | printf("href: %s\n", v->href); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2308 | addnl = 1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2309 | } else { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2310 | printf("%s\n", vname); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2311 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2312 | v = v->next; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2313 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2314 | } else if(sn->error != DAV_OK) { |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2315 | print_resource_error(sn, path); |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2316 | ret = 1; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2317 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2318 | |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2319 | return ret; |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2320 | } |
52e4171d42ce
adds minimal deltav implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
2321 | |
476
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2322 | 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
|
2323 | 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
|
2324 | DavResource *ret = NULL; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2325 | while(list) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2326 | 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
|
2327 | if(!ret) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2328 | 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
|
2329 | 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
|
2330 | ret = list; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2331 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2332 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2333 | if(list != ret) { |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2334 | 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
|
2335 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2336 | list = next; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2337 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2338 | return ret; |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2339 | } |
b4e3453e2b49
adds -V option to get, get-property and info commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
475
diff
changeset
|
2340 | |
84
7fca3788261d
added info command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
2341 | |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2342 | char* stdin2str() { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2343 | CxBuffer buf; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2344 | cxBufferInit(&buf, NULL, 1024, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2345 | size_t size = cx_stream_copy(stdin, &buf, (cx_read_func)fread, (cx_write_func)cxBufferWrite); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2346 | if(size == 0) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2347 | cxBufferDestroy(&buf); |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2348 | return NULL; |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2349 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2350 | cxBufferPut(&buf, '\0'); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2351 | return buf.space; |
62
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2352 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2353 | } |
3b813c57c106
added property-set and property-get command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2354 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2355 | static void xml2str_i(DavXmlNode *node, CxBuffer *buf, int indent) { |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2356 | while(node) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2357 | if(node->type == DAV_XML_ELEMENT) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2358 | if(node->children) { |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2359 | if(dav_xml_isstring(node->children)) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2360 | cxstring s = cx_strtrim(cx_str(dav_xml_getstring(node->children))); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2361 | cx_bprintf( |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2362 | buf, |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2363 | "%*s<%s>%.*s</%s>\n", |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2364 | indent, |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2365 | "", |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2366 | node->name, |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2367 | (int)s.length, |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2368 | s.ptr, |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2369 | node->name); |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2370 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2371 | cx_bprintf(buf, "%*s<%s>\n", indent, "", node->name); |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2372 | xml2str_i(node->children, buf, indent+2); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2373 | cx_bprintf(buf, "%*s</%s>\n", indent, "", node->name); |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2374 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2375 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2376 | cx_bprintf(buf, "%*s<%s />", indent, "", node->name); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2377 | cxBufferPut(buf, '\n'); |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2378 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2379 | } else if(node->type == DAV_XML_TEXT) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2380 | cxstring val = cx_strtrim(cx_strn(node->content, node->contentlength)); |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2381 | if(val.length > 0) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2382 | cx_bprintf(buf, "%*.*s", indent, (int)val.length, val.ptr); |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2383 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2384 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2385 | |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2386 | node = node->next; |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2387 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2388 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2389 | |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2390 | char* xml2str(DavXmlNode *node) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2391 | CxBuffer buf; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2392 | cxBufferInit(&buf, NULL, 256, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2393 | xml2str_i(node, &buf, 0); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2394 | cxBufferPut(&buf, 0); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2395 | return buf.space; |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2396 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2397 | |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2398 | void printxmldoc(FILE *out, char *root, char *rootns, DavXmlNode *content) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2399 | CxMap *nsmap = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
2400 | cxDefineDestructor(nsmap, free); |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2401 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2402 | cxMapPut(nsmap, cx_hash_key_str(rootns), "x0"); |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2403 | 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
|
2404 | 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
|
2405 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2406 | dav_print_node(out, (cx_write_func)fwrite, nsmap, content); |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2407 | |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2408 | fprintf(out, "</x0:%s>\n", root); |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
355
diff
changeset
|
2409 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
355
diff
changeset
|
2410 | // cleanup namespace map |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2411 | cxMapRemove(nsmap, cx_hash_key_str(rootns)); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2412 | cxMapDestroy(nsmap); |
338
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2413 | } |
c7f3fe4abdb2
dav get-property supports xml property output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
2414 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2415 | |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2416 | /* ---------- config commands ---------- */ |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2417 | |
195
4b7823a58199
fixed add-repository function name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
194
diff
changeset
|
2418 | int cmd_add_repository(CmdArgs *args) { |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2419 | 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
|
2420 | char *name = assistant_getcfg("name"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2421 | if(!name) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2422 | fprintf(stderr, "Abort\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2423 | return -1; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2424 | } |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
2425 | if(dav_config_get_repository(get_config(), cx_str(name))) { |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
2426 | 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
|
2427 | return -1; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2428 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2429 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2430 | printf("\nSpecify the repository base url.\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2431 | char *url = assistant_getcfg("url"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2432 | if(!url) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2433 | fprintf(stderr, "Abort\n"); |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2434 | return -1; |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2435 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2436 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2437 | printf("\nUser for HTTP authentication.\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2438 | char *user = assistant_getoptcfg("user"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2439 | |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2440 | char *password = NULL; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2441 | if(user) { |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2442 | password = assistant_gethiddenoptcfg("password"); |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2443 | } |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2444 | printf("\n"); |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2445 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2446 | DavConfig *config = get_config(); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2447 | const CxAllocator *a = config->mp->allocator; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2448 | DavCfgRepository *repo = dav_repository_new(config); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2449 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2450 | repo->name.value = cx_strdup_a(a, cx_str(name)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2451 | repo->url.value = cx_strdup_a(a, cx_str(url)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2452 | dav_repository_set_auth(config, repo, cx_str(user), cx_str(password)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2453 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2454 | dav_config_add_repository(config, repo); |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2455 | |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2456 | int ret = 0; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2457 | if(store_config()) { |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2458 | fprintf(stderr, "Cannot write config.xml\n"); |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2459 | ret = -1; |
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2460 | } else { |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
2461 | 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
|
2462 | } |
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2463 | |
197
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2464 | free(name); |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2465 | free(url); |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2466 | if(user) { |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2467 | free(user); |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2468 | } |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2469 | if(password) { |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2470 | free(password); |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2471 | } |
79a866256be4
added cleanup code in cmd_add_repository
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
2472 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2473 | return ret; |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
2474 | } |
398
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2475 | |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2476 | int cmd_remove_repository(CmdArgs *args) { |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2477 | if(args->argc < 1) { |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2478 | fprintf(stderr, "Too few arguments\n"); |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2479 | fprintf(stderr, "Usage: dav remove-repository <name...>\n"); |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2480 | return -1; |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2481 | } |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2482 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2483 | DavConfig *config = get_config(); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2484 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2485 | DavBool store = FALSE; |
398
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2486 | for(int i = 0 ; i < args->argc ; i++) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2487 | cxstring reponame = cx_str(args->argv[i]); |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2488 | DavCfgRepository* repo = dav_config_get_repository(config, reponame); |
398
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2489 | if(repo) { |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2490 | dav_repository_remove_and_free(config, repo); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2491 | store = TRUE; |
398
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2492 | } else { |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2493 | fprintf(stderr, "Repository %s does not exist - skipped.\n", |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2494 | reponame.ptr); |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2495 | return -1; |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2496 | } |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2497 | } |
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2498 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2499 | if(store) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2500 | return store_config(); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2501 | } else { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2502 | return -1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2503 | } |
398
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
384
diff
changeset
|
2504 | } |
419
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2505 | |
798
d7f5067a27ce
remove list_repositories() config.c function in favor of a cmd_list_repositories() function in main.c
Mike Becker <universe@uap-core.de>
parents:
796
diff
changeset
|
2506 | int cmd_list_repositories(void) { |
d7f5067a27ce
remove list_repositories() config.c function in favor of a cmd_list_repositories() function in main.c
Mike Becker <universe@uap-core.de>
parents:
796
diff
changeset
|
2507 | DavConfig *config = get_config(); |
d7f5067a27ce
remove list_repositories() config.c function in favor of a cmd_list_repositories() function in main.c
Mike Becker <universe@uap-core.de>
parents:
796
diff
changeset
|
2508 | if(!config) { |
d7f5067a27ce
remove list_repositories() config.c function in favor of a cmd_list_repositories() function in main.c
Mike Becker <universe@uap-core.de>
parents:
796
diff
changeset
|
2509 | return 1; |
d7f5067a27ce
remove list_repositories() config.c function in favor of a cmd_list_repositories() function in main.c
Mike Becker <universe@uap-core.de>
parents:
796
diff
changeset
|
2510 | } |
d7f5067a27ce
remove list_repositories() config.c function in favor of a cmd_list_repositories() function in main.c
Mike Becker <universe@uap-core.de>
parents:
796
diff
changeset
|
2511 | for(DavCfgRepository *repo=config->repositories;repo;repo=repo->next) { |
d7f5067a27ce
remove list_repositories() config.c function in favor of a cmd_list_repositories() function in main.c
Mike Becker <universe@uap-core.de>
parents:
796
diff
changeset
|
2512 | printf("%.*s\n", (int)repo->name.value.length, repo->name.value.ptr); |
d7f5067a27ce
remove list_repositories() config.c function in favor of a cmd_list_repositories() function in main.c
Mike Becker <universe@uap-core.de>
parents:
796
diff
changeset
|
2513 | } |
d7f5067a27ce
remove list_repositories() config.c function in favor of a cmd_list_repositories() function in main.c
Mike Becker <universe@uap-core.de>
parents:
796
diff
changeset
|
2514 | return 0; |
d7f5067a27ce
remove list_repositories() config.c function in favor of a cmd_list_repositories() function in main.c
Mike Becker <universe@uap-core.de>
parents:
796
diff
changeset
|
2515 | } |
d7f5067a27ce
remove list_repositories() config.c function in favor of a cmd_list_repositories() function in main.c
Mike Becker <universe@uap-core.de>
parents:
796
diff
changeset
|
2516 | |
419
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2517 | int cmd_repository_url(CmdArgs *args) { |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2518 | if(args->argc != 1) { |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2519 | 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
|
2520 | 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
|
2521 | return -1; |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2522 | } |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2523 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2524 | cxstring reponame = cx_str(args->argv[0]); |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2525 | DavCfgRepository* repo = dav_config_get_repository(get_config(), reponame); |
419
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2526 | if(repo) { |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2527 | cxstring url = cx_strcast(repo->url.value); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2528 | if(repo->user.value.ptr && !cmd_getoption(args, "plain")) { |
421
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2529 | int hostindex = 0; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2530 | if(cx_strprefix(url, CX_STR("https://"))) { |
421
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2531 | printf("https://"); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2532 | hostindex = 8; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2533 | } else if(cx_strprefix(url, CX_STR("http://"))) { |
421
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2534 | printf("http://"); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2535 | hostindex = 7; |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2536 | } |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2537 | printf("%.*s", (int)repo->user.value.length, repo->user.value.ptr); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2538 | if(repo->password.value.ptr) { |
811
9385330bdd38
fix dav repo-url command containing the password base64 encoded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
806
diff
changeset
|
2539 | cxmutstr pw_decoded = dav_repository_get_decodedpassword(repo); |
421
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2540 | CURL *curl = curl_easy_init(); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2541 | char *pw = curl_easy_escape( |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2542 | curl, |
811
9385330bdd38
fix dav repo-url command containing the password base64 encoded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
806
diff
changeset
|
2543 | pw_decoded.ptr, |
9385330bdd38
fix dav repo-url command containing the password base64 encoded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
806
diff
changeset
|
2544 | pw_decoded.length); |
421
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2545 | printf(":%s", pw); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2546 | curl_free(pw); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2547 | curl_easy_cleanup(curl); |
811
9385330bdd38
fix dav repo-url command containing the password base64 encoded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
806
diff
changeset
|
2548 | free(pw_decoded.ptr); |
421
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2549 | } |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2550 | putchar('@'); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2551 | 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
|
2552 | } else { |
421
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2553 | printf("%s", url.ptr); |
419
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2554 | } |
421
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2555 | if(url.ptr[url.length-1] != '/') { |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2556 | putchar('/'); |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2557 | } |
178dc32c8c9a
adds user+pw to repo-url output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
2558 | putchar('\n'); |
419
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2559 | } else { |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2560 | 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
|
2561 | return -1; |
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2562 | } |
488
29b979ca8750
adds dav_pw2key commoncrypto implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
478
diff
changeset
|
2563 | return 0; |
419
0b48f935f8a6
adds repository-url command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2564 | } |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
2565 | |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2566 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2567 | 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
|
2568 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2569 | static int secretstore_after_decrypt( |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2570 | CmdArgs *args, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2571 | PwdStore *secrets, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2572 | sscmd_func cb, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2573 | void *userdata); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2574 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2575 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2576 | /* |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2577 | * 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
|
2578 | * decryption |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2579 | * Aborts if a callback returns 1 |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2580 | */ |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2581 | static int secretstore_cmd( |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2582 | CmdArgs *args, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2583 | DavBool create, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2584 | sscmd_func beforedecrypt, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2585 | sscmd_func afterdecrypt, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2586 | void *userdata) |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2587 | { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2588 | PwdStore *secrets = get_pwdstore(); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2589 | if(!secrets) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2590 | if(create) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2591 | secrets = pwdstore_new(); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2592 | } else { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2593 | return 1; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2594 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2595 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2596 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2597 | int ret = 0; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2598 | if(beforedecrypt) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2599 | ret = beforedecrypt(args, secrets, userdata); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2600 | if(ret) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2601 | afterdecrypt = NULL; // exit |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2602 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2603 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2604 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2605 | if(afterdecrypt) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2606 | 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
|
2607 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2608 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2609 | pwdstore_free(secrets); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2610 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2611 | return ret; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2612 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2613 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2614 | static int secretstore_after_decrypt( |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2615 | CmdArgs *args, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2616 | PwdStore *secrets, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2617 | sscmd_func cb, |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2618 | void *userdata) |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2619 | { |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2620 | char *master_pw = util_password_input("Master password: "); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2621 | if(!master_pw) { |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2622 | 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
|
2623 | return 1; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2624 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2625 | |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2626 | 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
|
2627 | free(master_pw); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2628 | if(err) { |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2629 | 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
|
2630 | return 1; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2631 | } |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2632 | |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2633 | if(pwdstore_decrypt(secrets)) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2634 | 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
|
2635 | return 1; |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2636 | } |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2637 | |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2638 | return cb(args, secrets, userdata); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2639 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2640 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2641 | 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
|
2642 | 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
|
2643 | if(!id) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2644 | fprintf(stderr, "Identifier required.\n"); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2645 | return 1; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2646 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2647 | if(pwdstore_get(secrets, id)) { |
653
f503c272bd70
update secret store format description
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
652
diff
changeset
|
2648 | 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
|
2649 | return 1; |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2650 | } |
472
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
2651 | |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2652 | // get user name and password (required) |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
2653 | char *user = assistant_getcfg("User"); |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
2654 | 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
|
2655 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2656 | // optionally, get one or more locations |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2657 | char *location = NULL; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2658 | CxList *locations = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
2659 | cxDefineDestructor(locations, free); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2660 | while((location = assistant_getoptcfg("Location"))) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2661 | cxListAdd(locations, location); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2662 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2663 | |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2664 | int ret = 1; |
732
b0eb645cd26e
fix error in dav add-user, if .dav dir doesn't exists
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
731
diff
changeset
|
2665 | if(user && password) { |
489
fb69eae42ef0
credentials can have multiple locations now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
488
diff
changeset
|
2666 | pwdstore_put_index(secrets, id, locations); |
474
017a4f09e6fa
improves secret store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
473
diff
changeset
|
2667 | 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
|
2668 | ret = pwdstore_save(secrets); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2669 | if(ret) { |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2670 | fprintf(stderr, "Error: saving srcrets store failed.\n"); |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
2671 | } |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
2672 | } |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2673 | |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2674 | if(id) free(id); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2675 | if(user) free(user); |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2676 | if(password) free(password); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2677 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2678 | cxListDestroy(locations); |
473
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2679 | |
6740adb5fccd
adds support for location credentials
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
472
diff
changeset
|
2680 | return ret; |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
2681 | } |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
458
diff
changeset
|
2682 | |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2683 | int cmd_add_user(CmdArgs *args) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2684 | 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
|
2685 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2686 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2687 | /* |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2688 | * 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
|
2689 | */ |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2690 | static int cmd_ss_list_users_bc(CmdArgs *Args, PwdStore *secrets, int *ret) { |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
2691 | if(cxMapSize(secrets->index) == 0) { |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2692 | 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
|
2693 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2694 | // 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
|
2695 | *ret = 1; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2696 | return 0; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2697 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2698 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2699 | /* |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2700 | * 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
|
2701 | */ |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2702 | 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
|
2703 | *ret = 0; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2704 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2705 | CxList *list = secrets->locations; |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2706 | for(int i=0;i<2;i++) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2707 | if(list) { |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
2708 | CxIterator iter = cxListIterator(list); |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
2709 | cx_foreach(PwdIndexEntry*, index, iter) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2710 | PwdEntry *e = cxMapGet(secrets->ids, cx_hash_key_str(index->id)); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2711 | if(e) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2712 | printf("Id: %s\n", e->id); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2713 | printf("User: %s\n", e->user); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2714 | if(index->locations) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2715 | CxIterator loc_iter = cxListIterator(index->locations); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2716 | cx_foreach(char *, location, loc_iter) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2717 | printf("Location: %s\n", location); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2718 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2719 | printf("\n"); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2720 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2721 | } else { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2722 | // broken index |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2723 | fprintf(stderr, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2724 | "Warning: id '%s' not in secret store.\n", |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2725 | index->id); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2726 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2727 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2728 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2729 | list = secrets->noloc; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2730 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2731 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2732 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2733 | return 0; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2734 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2735 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2736 | int cmd_list_users(CmdArgs *args) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2737 | int ret = 0; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2738 | 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
|
2739 | return ret; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2740 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2741 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2742 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2743 | 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
|
2744 | char *id = assistant_getcfg("Credentials identifier"); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2745 | if(!id) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2746 | fprintf(stderr, "Identifier required.\n"); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2747 | return 1; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2748 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2749 | if(!pwdstore_get(secrets, id)) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2750 | 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
|
2751 | free(id); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2752 | return 1; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2753 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2754 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2755 | pwdstore_remove_entry(secrets, id); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2756 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2757 | int ret = pwdstore_save(secrets); |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2758 | if(ret) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2759 | 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
|
2760 | } |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2761 | free(id); |
654
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2762 | return ret; |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2763 | } |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2764 | |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2765 | int cmd_remove_user(CmdArgs *args) { |
8f2b8f2a5cde
add remove-user and list-users commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
653
diff
changeset
|
2766 | 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
|
2767 | } |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
2768 | |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2769 | 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
|
2770 | PwdEntry *entry = pwdstore_get(secrets, id); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2771 | if(!entry) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2772 | return; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2773 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2774 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2775 | PwdIndexEntry *index = cxMapGet(secrets->index, cx_hash_key_str(id)); |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2776 | if(!index) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2777 | return; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2778 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2779 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2780 | printf("Id: %s\n", entry->id); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2781 | printf("User: %s\n", entry->user); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2782 | if(index->locations) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2783 | CxIterator loc_iter = cxListIterator(index->locations); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2784 | cx_foreach(char *, location, loc_iter) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2785 | printf("Location: %s\n", location); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2786 | } |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2787 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2788 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2789 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2790 | static void secrets_remove_location(PwdIndexEntry *index) { |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
2791 | if(!index->locations || cxListSize(index->locations) == 0) { |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2792 | printf("no locations\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2793 | return; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2794 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2795 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2796 | printf("0: abort\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2797 | int i = 1; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2798 | CxIterator loc_iter = cxListIterator(index->locations); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2799 | cx_foreach(char *, location, loc_iter) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2800 | printf("%d: %s\n", i, location); |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2801 | i++; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2802 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2803 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2804 | char *input = assistant_getcfg("Choose location"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2805 | if(!input) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2806 | return; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2807 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2808 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2809 | int64_t ln = 0; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2810 | if(util_strtoint(input, &ln) && (ln >= 0 && ln < i)) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2811 | if(ln == 0) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2812 | return; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2813 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2814 | char *location = cxListAt(index->locations, ln - 1); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2815 | if(location) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2816 | free(location); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2817 | cxListRemove(index->locations, ln - 1); |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2818 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2819 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2820 | } else { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2821 | printf("illegal input, choose 0 - %d\n", i-1); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2822 | secrets_remove_location(index); // try again |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2823 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2824 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2825 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2826 | 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
|
2827 | char *id = assistant_getcfg("Credentials identifier"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2828 | if(!id) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2829 | fprintf(stderr, "Identifier required.\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2830 | return 1; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2831 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2832 | PwdEntry *entry = pwdstore_get(secrets, id); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2833 | PwdIndexEntry *index = cxMapGet(secrets->index, cx_hash_key_str(id)); |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2834 | if(!entry || !index) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2835 | 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
|
2836 | return 1; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2837 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2838 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2839 | secrets_print_user_info(secrets, id); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2840 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2841 | int save = 0; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2842 | int loop = 1; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2843 | while(loop) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2844 | printf("\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2845 | printf("0: change user name\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2846 | printf("1: change password\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2847 | printf("2: add location\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2848 | printf("3: remove location\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2849 | printf("4: list locations\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2850 | printf("5: save and exit\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2851 | printf("6: exit without saving\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2852 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2853 | char *opt = assistant_getcfg("Choose action"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2854 | if(!opt) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2855 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2856 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2857 | int64_t mnu = 0; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2858 | if(util_strtoint(opt, &mnu) && (mnu >= 0 && mnu <= 6)) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2859 | printf("\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2860 | switch(mnu) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2861 | case 0: { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2862 | // change user name |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2863 | char *user = assistant_getcfg("User"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2864 | if(user) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2865 | if(entry->user) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2866 | free(entry->user); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2867 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2868 | entry->user = user; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2869 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2870 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2871 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2872 | case 1: { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2873 | // change password |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2874 | char *password = util_password_input("Password: "); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2875 | if(password) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2876 | if(entry->password) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2877 | free(entry->password); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2878 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2879 | entry->password = password; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2880 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2881 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2882 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2883 | case 2: { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2884 | // add location |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2885 | char *location = assistant_getoptcfg("Location"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2886 | if(location) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2887 | cxListAdd(index->locations, location); |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2888 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2889 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2890 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2891 | case 3: { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2892 | // remove location |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2893 | secrets_remove_location(index); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2894 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2895 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2896 | case 4: { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2897 | // list locations |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
811
diff
changeset
|
2898 | if(!index->locations || cxListSize(index->locations)) { |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2899 | printf("no locations\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2900 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2901 | CxIterator i = cxListIterator(index->locations); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2902 | cx_foreach(char *, location, i) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2903 | printf("Location: %s\n", location); |
655
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2904 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2905 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2906 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2907 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2908 | case 5: { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2909 | // save and exit |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2910 | loop = 0; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2911 | save = 1; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2912 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2913 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2914 | case 6: { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2915 | // exit without saving |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2916 | loop = 0; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2917 | break; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2918 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2919 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2920 | } else { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2921 | printf("illegal input, choose 0 - 5\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2922 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2923 | free(opt); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2924 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2925 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2926 | int ret = 0; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2927 | if(save) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2928 | ret = pwdstore_save(secrets); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2929 | if(ret) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2930 | fprintf(stderr, "Error: saving srcrets store failed.\n"); |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2931 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2932 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2933 | return ret; |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2934 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2935 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2936 | int cmd_edit_user(CmdArgs *args) { |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2937 | 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
|
2938 | } |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2939 | |
4d33b672c33a
add edit-user command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
654
diff
changeset
|
2940 | |
733
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2941 | static int cmd_ss_set_master_pw(CmdArgs *args, PwdStore *secrets, void *ud) { |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2942 | char *new_master_pw = util_password_input("New master password: "); |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2943 | int ret = pwdstore_setpassword(secrets, new_master_pw); |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2944 | if(ret) { |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2945 | fprintf(stderr, "Error: failed to set new master password\n"); |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2946 | } |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2947 | |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2948 | ret = pwdstore_save(secrets); |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2949 | if(ret) { |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2950 | fprintf(stderr, "Error: saving srcrets store failed.\n"); |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2951 | } |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2952 | return ret; |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2953 | } |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2954 | |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2955 | int cmd_set_master_password(CmdArgs *args) { |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2956 | return secretstore_cmd(args, FALSE, NULL, cmd_ss_set_master_pw, NULL); |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2957 | } |
a7883961b5f4
add set-master-password command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
2958 | |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2959 | static char** read_args_from_stdin(int *argc) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2960 | // read stdin into buffer |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2961 | CxBuffer *in = cxBufferCreate(NULL, 1024, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2962 | cx_stream_copy(stdin, in, (cx_read_func)fread, (cx_write_func)cxBufferWrite); |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2963 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2964 | // split input into lines |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2965 | ssize_t count = 0; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2966 | cxmutstr *lines; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2967 | count = cx_strsplit_ma(cxDefaultAllocator, cx_mutstrn(in->space, in->pos), CX_STR("\n"), INT_MAX, &lines); |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2968 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2969 | char **args = NULL; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2970 | if(count > 0) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2971 | args = calloc(count, sizeof(char*)); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2972 | for(int i=0;i<count;i++) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2973 | args[i] = lines[i].ptr; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2974 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2975 | free(lines); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2976 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2977 | *argc = count; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2978 | } else { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2979 | *argc = 0; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2980 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2981 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2982 | // cleanup |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
2983 | cxBufferFree(in); |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2984 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2985 | return args; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2986 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2987 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2988 | int cmd_complete(CmdArgs *args) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2989 | if(args->argc != 1) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2990 | return 1; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2991 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2992 | char *index_str = args->argv[0]; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2993 | int64_t index = 0; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2994 | if(!util_strtoint(index_str, &index)) { |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
2995 | return 1; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
2996 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
2997 | |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2998 | // The completion bash script passes the input words to stdin |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
2999 | int comp_argc; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3000 | char **comp_argv = read_args_from_stdin(&comp_argc); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3001 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3002 | // Try to parse the args |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3003 | char *cmd = NULL; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3004 | if(comp_argc > 1) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3005 | cmd = comp_argv[1]; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3006 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3007 | 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
|
3008 | if(comp_args) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3009 | // check whether the arglist contains options |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3010 | if(comp_args->argc + 2 != comp_argc) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3011 | // 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
|
3012 | // know the index for this item in comp_args->argv |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3013 | // 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
|
3014 | // difference between the two lists |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3015 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3016 | // adjust index to comp_args->argv |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3017 | int j = 0; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3018 | for(int i=0;i<comp_argc-2;i++) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3019 | if(index == i-2) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3020 | break; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3021 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3022 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3023 | if(strcmp(comp_argv[i+2], comp_args->argv[j])) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3024 | index--; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3025 | } else { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3026 | j++; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3027 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3028 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3029 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3030 | } else { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3031 | comp_args = NULL; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3032 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3033 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3034 | // generate output for shell completion |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3035 | int ret = 1; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3036 | if(comp_args) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3037 | ret = shell_completion(cmd, comp_args, index); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3038 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3039 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3040 | // cleanup |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3041 | cmd_args_free(comp_args); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3042 | free(comp_argv); |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3043 | return ret; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3044 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3045 | } |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3046 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3047 | 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
|
3048 | if(index == 1) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3049 | cxstring prefix = { NULL, 0 }; |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3050 | if(cmd) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3051 | prefix = cx_str(cmd); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3052 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3053 | for(int i=0;;i++) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3054 | char *str = cmdusageinfo[i]; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3055 | if(!str) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3056 | break; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3057 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3058 | int len = (int)strlen(str); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3059 | int maxlen = len; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3060 | for(int w=0;w<len;w++) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3061 | if(str[w] == ' ') { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3062 | maxlen = w; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3063 | break; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3064 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3065 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3066 | if(prefix.ptr) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3067 | if(!cx_strprefix(cx_strn(str, maxlen), prefix)) { |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3068 | continue; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3069 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3070 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3071 | printf("%.*s\n", (int)maxlen, str); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3072 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3073 | return 0; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3074 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3075 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3076 | if(!strcmp(cmd, "date")) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3077 | return 0; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3078 | } |
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
|
3079 | |
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
|
3080 | // 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
|
3081 | 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
|
3082 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3083 | //printf("index: {%s}\n", args->argv[0]); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3084 | //printf("dav: {%s}\n", args->argv[1]); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3085 | //printf("cmd: {%s}\n", cmd); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3086 | //printf("url: {%s}\n", url); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3087 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3088 | if(index == 2) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3089 | // url completion |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3090 | return url_completion(args, url); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3091 | } else if (index == 3) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3092 | if(!strcmp(cmd, "put") || !strcmp(cmd, "import")) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3093 | // file completion |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3094 | return 12; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3095 | } 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
|
3096 | // url completion |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3097 | return url_completion(args, url); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3098 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3099 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3100 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3101 | return 0; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3102 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3103 | |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3104 | int url_completion(CmdArgs *args, char *u) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3105 | cxstring url; |
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
|
3106 | 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
|
3107 | url.length = u ? strlen(u) : 0; |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3108 | |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3109 | // 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
|
3110 | // 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
|
3111 | char quote = '\0'; |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3112 | 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
|
3113 | quote = url.ptr[0]; |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3114 | |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3115 | // 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
|
3116 | url.ptr++; |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3117 | url.length--; |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3118 | |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3119 | // 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
|
3120 | 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
|
3121 | url.length--; |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3122 | } |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3123 | } |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3124 | |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3125 | // repo completion |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3126 | int repocomp = 1; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3127 | for(int i=0;i<url.length;i++) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3128 | if(url.ptr[i] == '/') { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3129 | repocomp = 0; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3130 | break; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3131 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3132 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3133 | if(repocomp) { |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
3134 | DavConfig *config = get_config(); |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
3135 | for(DavCfgRepository *repo=config->repositories; repo; repo=repo->next) { |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
3136 | if(cx_strprefix(cx_strcast(repo->name.value), url)) { |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3137 | if(quote == '\0') { |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
3138 | printf("%s/\n", repo->name.value.ptr); |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3139 | } else { |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
3140 | printf("%c%s/%c\n", quote, repo->name.value.ptr, quote); |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3141 | } |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3142 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3143 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3144 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3145 | } else { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3146 | // url completion |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3147 | cxMapPut(args->options, cx_hash_key_str("noinput"), ""); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3148 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3149 | char *path = NULL; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
3150 | DavCfgRepository *repo = dav_config_url2repo(get_config(), url.ptr, &path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
733
diff
changeset
|
3151 | DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, args); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3152 | if(!sn) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3153 | return 0; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3154 | } |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3155 | if(set_session_config(sn, args)) { |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3156 | return 0; |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
683
diff
changeset
|
3157 | } |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3158 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3159 | size_t plen = strlen(path); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3160 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3161 | cxstring filter; |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3162 | char *lspath = NULL; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3163 | if(path[plen-1] == '/') { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3164 | lspath = strdup(path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3165 | filter = CX_STR(""); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3166 | } else { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3167 | lspath = util_parent_path(path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3168 | filter = cx_str(util_resource_name(path)); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3169 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3170 | |
433
7096666628ca
fixes url completion output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
432
diff
changeset
|
3171 | 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
|
3172 | DavResource *elm = ls ? ls->children : NULL; |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3173 | while(elm) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3174 | cxstring name = cx_str(elm->name); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3175 | if(cx_strprefix(name, filter)) { |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3176 | int space = 0; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3177 | for(int i=0;i<name.length;i++) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3178 | if(name.ptr[i] == ' ') { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3179 | space = 1; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3180 | break; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3181 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3182 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3183 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3184 | CxBuffer *out = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
3185 | cxBufferWrite(repo->name.value.ptr, repo->name.value.length, 1, out); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3186 | if(space) { |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3187 | size_t l = strlen(elm->path); |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3188 | for(int i=0;i<l;i++) { |
726
8f6ad495f538
adds more characters to escape for shell completion
Mike Becker <universe@uap-core.de>
parents:
723
diff
changeset
|
3189 | // only if we do not quote, we have to escape |
8f6ad495f538
adds more characters to escape for shell completion
Mike Becker <universe@uap-core.de>
parents:
723
diff
changeset
|
3190 | char nextc = elm->path[i]; |
8f6ad495f538
adds more characters to escape for shell completion
Mike Becker <universe@uap-core.de>
parents:
723
diff
changeset
|
3191 | if(quote == '\0' && NULL != strchr( |
8f6ad495f538
adds more characters to escape for shell completion
Mike Becker <universe@uap-core.de>
parents:
723
diff
changeset
|
3192 | "!\"#$&'()*,;<>?[\\]^`{|}~ ", nextc)) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3193 | cxBufferPut(out, '\\'); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3194 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3195 | cxBufferPut(out, nextc); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3196 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3197 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3198 | cxBufferPutString(out, elm->path); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3199 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3200 | if(elm->iscollection) { |
433
7096666628ca
fixes url completion output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
432
diff
changeset
|
3201 | if(out->space[out->pos-1] != '/') { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3202 | cxBufferPut(out, '/'); |
433
7096666628ca
fixes url completion output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
432
diff
changeset
|
3203 | } |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3204 | } |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3205 | if (quote == '\0') { |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3206 | 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
|
3207 | } else { |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3208 | printf("%c%.*s%c\n", |
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
655
diff
changeset
|
3209 | 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
|
3210 | } |
432
a213ecaf3f4a
adjusts completion index, if options are specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
431
diff
changeset
|
3211 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
744
diff
changeset
|
3212 | cxBufferFree(out); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3213 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3214 | elm = elm->next; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3215 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3216 | |
432
a213ecaf3f4a
adjusts completion index, if options are specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
431
diff
changeset
|
3217 | free(lspath); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3218 | |
432
a213ecaf3f4a
adjusts completion index, if options are specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
431
diff
changeset
|
3219 | dav_session_destroy(sn); |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3220 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3221 | |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3222 | return 10; |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
3223 | } |