50 xmlGenericErrorFunc fnc = xmlerrorfnc; |
50 xmlGenericErrorFunc fnc = xmlerrorfnc; |
51 initGenericErrorDefaultFunc(&fnc); |
51 initGenericErrorDefaultFunc(&fnc); |
52 load_config(); |
52 load_config(); |
53 |
53 |
54 if(argc < 2) { |
54 if(argc < 2) { |
55 print_usage(); |
55 fprintf(stderr, "Missing command\n"); |
56 return -1; |
56 print_usage(argv[0]); |
57 } |
57 return -1; |
58 |
58 } |
59 if(!strcmp(argv[1], "list") || !strcmp(argv[1], "ls")) { |
59 |
60 return cmd_list(argc - 2, argv + 2); |
60 char *cmd = argv[1]; |
61 } else if(!strcmp(argv[1], "get")) { |
61 CmdArgs *args = cmd_parse_args(argc - 2, argv + 2); |
62 return cmd_get(argc - 2, argv + 2); |
62 if(!args) { |
63 } else if(!strcmp(argv[1], "put")) { |
63 print_usage(argv[0]); |
64 return cmd_put(argc - 2, argv + 2); |
64 return -1; |
65 } |
65 } |
66 |
66 |
67 print_usage(); |
67 if(!strcmp(cmd, "list") || !strcmp(cmd, "ls")) { |
|
68 return cmd_list(args); |
|
69 } else if(!strcmp(cmd, "get")) { |
|
70 return cmd_get(args); |
|
71 } else if(!strcmp(cmd, "put")) { |
|
72 return cmd_put(args); |
|
73 } |
|
74 |
|
75 print_usage(argv[0]); |
68 return -1; |
76 return -1; |
69 } |
77 } |
70 |
78 |
71 void print_usage() { |
79 void print_usage(char *cmd) { |
72 |
80 fprintf(stderr, "Usage: %s command [options] arguments...\n\n", cmd); |
|
81 fprintf(stderr, "Commands:\n"); |
|
82 fprintf(stderr, " list [-al] <url>\n"); |
|
83 fprintf(stderr, " get [-p] [-k <key>] [-o <file>] <url>\n"); |
|
84 fprintf(stderr, " put [-p] [-k <key>] <url> <file>\n"); |
|
85 fprintf(stderr, "\n"); |
|
86 fprintf(stderr, "Options:\n"); |
|
87 fprintf(stderr, |
|
88 " -k <key> Key to use for encryption or decryption\n"); |
|
89 fprintf(stderr, " -p Don't encrypt or decrypt files\n"); |
|
90 fprintf(stderr, " -o <file> Write output to file\n"); |
|
91 fprintf(stderr, "\n"); |
|
92 fprintf(stderr, |
|
93 "Instead of an url you can pass a repository name " |
|
94 "with an optional path:\n"); |
|
95 fprintf(stderr, " <repository>/path/\n"); |
|
96 fprintf(stderr, "\n"); |
73 } |
97 } |
74 |
98 |
75 void url_get_parts(char *url, char **root, char **path) { |
99 void url_get_parts(char *url, char **root, char **path) { |
76 size_t ulen = strlen(url); |
100 size_t ulen = strlen(url); |
77 *root = NULL; |
101 *root = NULL; |
78 *path = NULL; |
102 *path = NULL; |
79 |
103 |
80 int s; |
104 int s; |
81 if(ulen > 7 && !strncmp(url, "http://", 7)) { |
105 if(ulen > 7 && !strncasecmp(url, "http://", 7)) { |
82 s = 7; |
106 s = 7; |
83 } else if(ulen > 8 && !strncmp(url, "https://", 8)) { |
107 } else if(ulen > 8 && !strncasecmp(url, "https://", 8)) { |
84 s = 8; |
108 s = 8; |
85 } else { |
109 } else { |
86 s = 1; |
110 s = 1; |
87 } |
111 } |
88 |
112 |
103 *root = strdup(url); |
127 *root = strdup(url); |
104 *path = strdup("/"); |
128 *path = strdup("/"); |
105 } |
129 } |
106 |
130 |
107 |
131 |
108 int cmd_list(int argc, char **argv) { |
132 int cmd_list(CmdArgs *a) { |
109 if(argc == 0) { |
133 if(a->argc == 0) { |
110 return -1; |
134 return -1; |
111 } |
135 } |
112 |
136 |
113 |
137 |
114 DavContext *ctx = dav_context_new(); |
138 DavContext *ctx = dav_context_new(); |
115 DavSession *sn = NULL; |
139 DavSession *sn = NULL; |
116 char *url = argv[0]; |
140 char *url = a->argv[0]; |
117 char *root = NULL; |
141 char *root = NULL; |
118 char *path = NULL; |
142 char *path = NULL; |
119 url_get_parts(url, &root, &path); |
143 url_get_parts(url, &root, &path); |
120 |
144 |
121 Repository *repo = get_repository(root); |
145 Repository *repo = get_repository(root); |
139 } |
163 } |
140 |
164 |
141 return 0; |
165 return 0; |
142 } |
166 } |
143 |
167 |
144 int cmd_get(int argc, char **argv) { |
168 int cmd_get(CmdArgs *a) { |
145 if(argc == 0) { |
169 if(a->argc == 0) { |
146 return -1; |
170 return -1; |
147 } |
171 } |
148 |
172 |
149 DavContext *ctx = dav_context_new(); |
173 DavContext *ctx = dav_context_new(); |
150 dav_add_namespace(ctx, "U", "http://www.uap-core.de/"); |
174 dav_add_namespace(ctx, "U", "http://www.uap-core.de/"); |
151 DavSession *sn = NULL; |
175 DavSession *sn = NULL; |
152 char *url = argv[0]; |
176 char *url = a->argv[0]; |
153 char *root = NULL; |
177 char *root = NULL; |
154 char *path = NULL; |
178 char *path = NULL; |
155 url_get_parts(url, &root, &path); |
179 url_get_parts(url, &root, &path); |
156 |
180 |
157 Repository *repo = get_repository(root); |
181 Repository *repo = get_repository(root); |
196 } |
220 } |
197 |
221 |
198 return 0; |
222 return 0; |
199 } |
223 } |
200 |
224 |
201 int cmd_put(int argc, char **argv) { |
225 int cmd_put(CmdArgs *a) { |
202 if(argc < 2) { |
226 if(a->argc < 2) { |
203 return -1; |
227 return -1; |
204 } |
228 } |
205 |
229 |
206 DavContext *ctx = dav_context_new(); |
230 DavContext *ctx = dav_context_new(); |
207 DavSession *sn = NULL; |
231 DavSession *sn = NULL; |
208 char *url = argv[0]; |
232 char *url = a->argv[0]; |
209 char *file = argv[1]; |
233 char *file = a->argv[1]; |
210 char *root = NULL; |
234 char *root = NULL; |
211 char *path = NULL; |
235 char *path = NULL; |
212 url_get_parts(url, &root, &path); |
236 url_get_parts(url, &root, &path); |
213 |
237 |
214 Repository *repo = get_repository(root); |
238 Repository *repo = get_repository(root); |