181 fprintf(stderr, " -a show all files\n"); |
181 fprintf(stderr, " -a show all files\n"); |
182 fprintf(stderr, " -l print resources in long list format\n"); |
182 fprintf(stderr, " -l print resources in long list format\n"); |
183 fprintf(stderr, " -t print content type\n"); |
183 fprintf(stderr, " -t print content type\n"); |
184 fprintf(stderr, " -O override resources\n"); |
184 fprintf(stderr, " -O override resources\n"); |
185 fprintf(stderr, " -n <uri> specify namespace uri\n"); |
185 fprintf(stderr, " -n <uri> specify namespace uri\n"); |
186 fprintf(stderr, " -v verbose output\n"); |
186 fprintf(stderr, " -i disable cert verification (all commands)\n"); |
|
187 fprintf(stderr, " -v verbose output (all commands)\n"); |
187 fprintf(stderr, "\n"); |
188 fprintf(stderr, "\n"); |
188 fprintf(stderr, "Config commands:\n"); |
189 fprintf(stderr, "Config commands:\n"); |
189 fprintf(stderr, " add-repository\n"); |
190 fprintf(stderr, " add-repository\n"); |
190 fprintf(stderr, " list-repositories\n"); |
191 fprintf(stderr, " list-repositories\n"); |
191 fprintf(stderr, "\n"); |
192 fprintf(stderr, "\n"); |
297 } |
298 } |
298 |
299 |
299 return 0; |
300 return 0; |
300 } |
301 } |
301 |
302 |
302 static DavSession* connect_to_repo(Repository *repo) { |
303 static DavSession* connect_to_repo(Repository *repo, CmdArgs *a) { |
303 DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); |
304 DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); |
304 sn->flags = get_repository_flags(repo); |
305 sn->flags = get_repository_flags(repo); |
305 sn->key = dav_context_get_key(ctx, repo->default_key); |
306 sn->key = dav_context_get_key(ctx, repo->default_key); |
306 curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods); |
307 curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods); |
307 curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version); |
308 curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version); |
|
309 if(repo->cert) { |
|
310 curl_easy_setopt(sn->handle, CURLOPT_CAINFO, repo->cert); |
|
311 } |
|
312 if(!repo->verification || cmd_getoption(a, "insecure")) { |
|
313 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYPEER, 0); |
|
314 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0); |
|
315 } |
308 return sn; |
316 return sn; |
309 } |
317 } |
310 |
318 |
311 int cmd_list(CmdArgs *a) { |
319 int cmd_list(CmdArgs *a) { |
312 if(a->argc != 1) { |
320 if(a->argc != 1) { |
315 } |
323 } |
316 |
324 |
317 char *url = a->argv[0]; |
325 char *url = a->argv[0]; |
318 char *path = NULL; |
326 char *path = NULL; |
319 Repository *repo = url2repo(url, &path); |
327 Repository *repo = url2repo(url, &path); |
320 DavSession *sn = connect_to_repo(repo); |
328 DavSession *sn = connect_to_repo(repo, a); |
321 |
329 |
322 if(set_session_config(sn, a)) { |
330 if(set_session_config(sn, a)) { |
323 return -1; |
331 return -1; |
324 } |
332 } |
325 |
333 |
548 } |
556 } |
549 |
557 |
550 char *url = a->argv[0]; |
558 char *url = a->argv[0]; |
551 char *path = NULL; |
559 char *path = NULL; |
552 Repository *repo = url2repo(url, &path); |
560 Repository *repo = url2repo(url, &path); |
553 DavSession *sn = connect_to_repo(repo); |
561 DavSession *sn = connect_to_repo(repo, a); |
554 |
562 |
555 if(set_session_config(sn, a)) { |
563 if(set_session_config(sn, a)) { |
556 return -1; |
564 return -1; |
557 } |
565 } |
558 |
566 |
670 |
678 |
671 char *url = a->argv[0]; |
679 char *url = a->argv[0]; |
672 char *file = a->argv[1]; |
680 char *file = a->argv[1]; |
673 char *path = NULL; |
681 char *path = NULL; |
674 Repository *repo = url2repo(url, &path); |
682 Repository *repo = url2repo(url, &path); |
675 DavSession *sn = connect_to_repo(repo); |
683 DavSession *sn = connect_to_repo(repo, a); |
676 |
684 |
677 if(set_session_config(sn, a)) { |
685 if(set_session_config(sn, a)) { |
678 return -1; |
686 return -1; |
679 } |
687 } |
680 |
688 |
889 |
897 |
890 char *url2 = a->argv[1]; |
898 char *url2 = a->argv[1]; |
891 char *path2 = NULL; |
899 char *path2 = NULL; |
892 Repository *repo2 = url2repo(url2, &path2); |
900 Repository *repo2 = url2repo(url2, &path2); |
893 |
901 |
894 DavSession *sn = connect_to_repo(repo1); |
902 DavSession *sn = connect_to_repo(repo1, a); |
895 if(set_session_config(sn, a)) { |
903 if(set_session_config(sn, a)) { |
896 return -1; |
904 return -1; |
897 } |
905 } |
898 |
906 |
899 DavBool override = cmd_getoption(a, "override") ? true : false; |
907 DavBool override = cmd_getoption(a, "override") ? true : false; |
909 } |
917 } |
910 } else { |
918 } else { |
911 char *server1 = util_url_base(repo1->url); |
919 char *server1 = util_url_base(repo1->url); |
912 char *server2 = util_url_base(repo2->url); |
920 char *server2 = util_url_base(repo2->url); |
913 if(!strcmp(server1, server2)) { |
921 if(!strcmp(server1, server2)) { |
914 DavSession *sn2 = connect_to_repo(repo2); |
922 DavSession *sn2 = connect_to_repo(repo2, a); |
915 if(set_session_config(sn2, a)) { |
923 if(set_session_config(sn2, a)) { |
916 return -1; |
924 return -1; |
917 } |
925 } |
918 DavResource *dest = dav_resource_new(sn2, path2); |
926 DavResource *dest = dav_resource_new(sn2, path2); |
919 char *desthref = dav_resource_get_href(dest); |
927 char *desthref = dav_resource_get_href(dest); |
965 size_t len = strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT\n", date); |
973 size_t len = strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT\n", date); |
966 fwrite(str, 1, len, stdout); |
974 fwrite(str, 1, len, stdout); |
967 } else if (a->argc == 1) { |
975 } else if (a->argc == 1) { |
968 char *url = a->argv[0]; |
976 char *url = a->argv[0]; |
969 char *path = NULL; |
977 char *path = NULL; |
970 DavSession *sn = connect_to_repo(url2repo(url, &path)); |
978 DavSession *sn = connect_to_repo(url2repo(url, &path), a); |
971 |
979 |
972 DavResource *res = dav_resource_new(sn, path); |
980 DavResource *res = dav_resource_new(sn, path); |
973 char *date = NULL; |
981 char *date = NULL; |
974 curl_easy_setopt(sn->handle, CURLOPT_HEADERFUNCTION, get_date_header_cb); |
982 curl_easy_setopt(sn->handle, CURLOPT_HEADERFUNCTION, get_date_header_cb); |
975 curl_easy_setopt(sn->handle, CURLOPT_WRITEHEADER, &date); |
983 curl_easy_setopt(sn->handle, CURLOPT_WRITEHEADER, &date); |