dav/main.c

changeset 212
01e80c7cfe96
parent 211
3d12817414e9
child 213
cd870d5f8659
equal deleted inserted replaced
211:3d12817414e9 212:01e80c7cfe96
67 67
68 int main(int argc, char **argv) { 68 int main(int argc, char **argv) {
69 xmlGenericErrorFunc fnc = xmlerrorfnc; 69 xmlGenericErrorFunc fnc = xmlerrorfnc;
70 initGenericErrorDefaultFunc(&fnc); 70 initGenericErrorDefaultFunc(&fnc);
71 ctx = dav_context_new(); 71 ctx = dav_context_new();
72 ctx->key_input = util_key_input;
73 load_config(ctx); 72 load_config(ctx);
74 printxmlerror = 0; 73 printxmlerror = 0;
75 #ifdef DO_THE_TEST 74 #ifdef DO_THE_TEST
76 test(); 75 test();
77 return 0; 76 return 0;
90 CmdArgs *args = cmd_parse_args(argc - 2, argv + 2); 89 CmdArgs *args = cmd_parse_args(argc - 2, argv + 2);
91 if(!args) { 90 if(!args) {
92 print_usage(argv[0]); 91 print_usage(argv[0]);
93 cmd_args_free(args); 92 cmd_args_free(args);
94 return -1; 93 return -1;
94 }
95
96 if(cmd_getoption(args, "noinput")) {
97 ctx->key_input = NULL;
98 } else {
99 ctx->key_input = util_key_input;
95 } 100 }
96 101
97 int ret = -1; 102 int ret = -1;
98 if(!strcasecmp(cmd, "list") || !strcasecmp(cmd, "ls")) { 103 if(!strcasecmp(cmd, "list") || !strcasecmp(cmd, "ls")) {
99 ret = cmd_list(args); 104 ret = cmd_list(args);
202 "with an optional path:\n"); 207 "with an optional path:\n");
203 fprintf(stderr, " <repository>/path/\n"); 208 fprintf(stderr, " <repository>/path/\n");
204 fprintf(stderr, "\n"); 209 fprintf(stderr, "\n");
205 } 210 }
206 211
207 int request_auth(Repository *repo, DavSession *sn) { 212 int request_auth(Repository *repo, DavSession *sn, CmdArgs *a) {
213 if(cmd_getoption(a, "noinput")) {
214 return 0;
215 }
216
208 static int login = 0; 217 static int login = 0;
209 if(login) { 218 if(login) {
210 return 0; 219 return 0;
211 } 220 }
212 221
364 depth, 373 depth,
365 t); 374 t);
366 375
367 if(!ls) { 376 if(!ls) {
368 if(sn->error == DAV_UNAUTHORIZED) { 377 if(sn->error == DAV_UNAUTHORIZED) {
369 if(request_auth(repo, sn)) { 378 if(request_auth(repo, sn, a)) {
370 continue; 379 continue;
371 } 380 }
372 } 381 }
373 print_resource_error(sn, path); 382 print_resource_error(sn, path);
374 break; 383 break;
599 "select - from %s with depth = %d where lastmodified > %t", 608 "select - from %s with depth = %d where lastmodified > %t",
600 path, 609 path,
601 depth, 610 depth,
602 t); 611 t);
603 if(!res && sn->error == DAV_UNAUTHORIZED) { 612 if(!res && sn->error == DAV_UNAUTHORIZED) {
604 if(request_auth(repo, sn)) { 613 if(request_auth(repo, sn, a)) {
605 continue; 614 continue;
606 } 615 }
607 } 616 }
608 break; 617 break;
609 } 618 }
801 int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len) { 810 int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len) {
802 DavResource *res = NULL; 811 DavResource *res = NULL;
803 for(int i=0;i<2;i++) { 812 for(int i=0;i<2;i++) {
804 res = dav_query(sn, "select - from %s", path); 813 res = dav_query(sn, "select - from %s", path);
805 if(!res && sn->error == DAV_UNAUTHORIZED) { 814 if(!res && sn->error == DAV_UNAUTHORIZED) {
806 if(request_auth(repo, sn)) { 815 if(request_auth(repo, sn, a)) {
807 continue; 816 continue;
808 } 817 }
809 } 818 }
810 break; 819 break;
811 } 820 }
873 } 882 }
874 883
875 int err = 0; 884 int err = 0;
876 for(int i=0;i<2;i++) { 885 for(int i=0;i<2;i++) {
877 err = dav_delete(res); 886 err = dav_delete(res);
878 if(err && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn)) { 887 if(err && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn, a)) {
879 continue; 888 continue;
880 } else { 889 } else {
881 break; 890 break;
882 } 891 }
883 } 892 }
930 res->iscollection = 1; 939 res->iscollection = 1;
931 940
932 int err = 0; 941 int err = 0;
933 for(int i=0;i<2;i++) { 942 for(int i=0;i<2;i++) {
934 err = dav_create(res); 943 err = dav_create(res);
935 if(err && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn)) { 944 if(err && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn, a)) {
936 continue; 945 continue;
937 } else { 946 } else {
938 break; 947 break;
939 } 948 }
940 } 949 }

mercurial