dav/main.c

Sun, 17 Dec 2023 14:25:34 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 17 Dec 2023 14:25:34 +0100
changeset 797
edbb20b1438d
parent 796
81e0f67386a6
child 798
d7f5067a27ce
permissions
-rw-r--r--

[Makefile] fix missing rules preventing dry-runs

We have to support dry-runs, because many IDEs are using
dry-runs to collect build information.

Some rules have dependencies that expect certain files or
directories to be just present. We added respective build
rules which invoke the test program. This way, the behavior
when running make normally is exactly the same, but dry-runs
are also not failing now.

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

mercurial