dav/main.c

changeset 199
f448fc8c9191
parent 198
44054c452de1
child 200
cc474cf2c2f5
equal deleted inserted replaced
198:44054c452de1 199:f448fc8c9191
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
807 return -1; 815 return -1;
808 } 816 }
809 817
810 char *url = a->argv[0]; 818 char *url = a->argv[0];
811 char *path = NULL; 819 char *path = NULL;
812 DavSession *sn = connect_to_repo(url2repo(url, &path)); 820 DavSession *sn = connect_to_repo(url2repo(url, &path), a);
813 821
814 if(set_session_config(sn, a)) { 822 if(set_session_config(sn, a)) {
815 return -1; 823 return -1;
816 } 824 }
817 825
838 return -1; 846 return -1;
839 } 847 }
840 848
841 char *url = a->argv[0]; 849 char *url = a->argv[0];
842 char *path = NULL; 850 char *path = NULL;
843 DavSession *sn = connect_to_repo(url2repo(url, &path)); 851 DavSession *sn = connect_to_repo(url2repo(url, &path), a);
844 852
845 if(set_session_config(sn, a)) { 853 if(set_session_config(sn, a)) {
846 return -1; 854 return -1;
847 } 855 }
848 856
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);
993 return -1; 1001 return -1;
994 } 1002 }
995 1003
996 char *url = a->argv[0]; 1004 char *url = a->argv[0];
997 char *path = NULL; 1005 char *path = NULL;
998 DavSession *sn = connect_to_repo(url2repo(url, &path)); 1006 DavSession *sn = connect_to_repo(url2repo(url, &path), a);
999 1007
1000 if(set_session_config(sn, a)) { 1008 if(set_session_config(sn, a)) {
1001 return -1; 1009 return -1;
1002 } 1010 }
1003 1011
1037 return -1; 1045 return -1;
1038 } 1046 }
1039 1047
1040 char *url = a->argv[0]; 1048 char *url = a->argv[0];
1041 char *path = NULL; 1049 char *path = NULL;
1042 DavSession *sn = connect_to_repo(url2repo(url, &path)); 1050 DavSession *sn = connect_to_repo(url2repo(url, &path), a);
1043 1051
1044 if(set_session_config(sn, a)) { 1052 if(set_session_config(sn, a)) {
1045 return -1; 1053 return -1;
1046 } 1054 }
1047 1055
1087 return -1; 1095 return -1;
1088 } 1096 }
1089 1097
1090 char *url = a->argv[0]; 1098 char *url = a->argv[0];
1091 char *path = NULL; 1099 char *path = NULL;
1092 DavSession *sn = connect_to_repo(url2repo(url, &path)); 1100 DavSession *sn = connect_to_repo(url2repo(url, &path), a);
1093 1101
1094 if(set_session_config(sn, a)) { 1102 if(set_session_config(sn, a)) {
1095 return -1; 1103 return -1;
1096 } 1104 }
1097 1105

mercurial