dav/main.c

changeset 74
da079dc0724c
parent 73
41e88442ad4e
child 75
56962faf2b42
equal deleted inserted replaced
73:41e88442ad4e 74:da079dc0724c
59 xmlGenericErrorFunc fnc = xmlerrorfnc; 59 xmlGenericErrorFunc fnc = xmlerrorfnc;
60 initGenericErrorDefaultFunc(&fnc); 60 initGenericErrorDefaultFunc(&fnc);
61 ctx = dav_context_new(); 61 ctx = dav_context_new();
62 load_config(ctx); 62 load_config(ctx);
63 //dav_add_namespace(ctx, "U", "http://www.uap-core.de/"); 63 //dav_add_namespace(ctx, "U", "http://www.uap-core.de/");
64
65 //test(); 64 //test();
66 65
67 memcpy(ctx->http_proxy, get_http_proxy(), sizeof(Proxy)); 66 memcpy(ctx->http_proxy, get_http_proxy(), sizeof(Proxy));
68 memcpy(ctx->https_proxy, get_https_proxy(), sizeof(Proxy)); 67 memcpy(ctx->https_proxy, get_https_proxy(), sizeof(Proxy));
69 68
75 74
76 char *cmd = argv[1]; 75 char *cmd = argv[1];
77 CmdArgs *args = cmd_parse_args(argc - 2, argv + 2); 76 CmdArgs *args = cmd_parse_args(argc - 2, argv + 2);
78 if(!args) { 77 if(!args) {
79 print_usage(argv[0]); 78 print_usage(argv[0]);
79 cmd_args_free(args);
80 return -1; 80 return -1;
81 } 81 }
82 82
83 int ret = -1; 83 int ret = -1;
84 if(!strcasecmp(cmd, "list") || !strcasecmp(cmd, "ls")) { 84 if(!strcasecmp(cmd, "list") || !strcasecmp(cmd, "ls")) {
102 } else if(!strcasecmp(cmd, "get-property")) { 102 } else if(!strcasecmp(cmd, "get-property")) {
103 ret = cmd_get_property(args); 103 ret = cmd_get_property(args);
104 } else { 104 } else {
105 print_usage(argv[0]); 105 print_usage(argv[0]);
106 } 106 }
107
107 dav_context_destroy(ctx); 108 dav_context_destroy(ctx);
109 cmd_args_free(args);
110 free_config();
111 xmlCleanupParser();
112 curl_global_cleanup();
108 113
109 return ret; 114 return ret;
110 } 115 }
111 116
112 void print_usage(char *cmd) { 117 void print_usage(char *cmd) {
362 } 367 }
363 368
364 free(path); 369 free(path);
365 //free(base); 370 //free(base);
366 371
372 dav_session_destroy(sn);
373
367 return ret; 374 return ret;
368 } 375 }
369 376
370 static char* ls_date_str(time_t tm) { 377 static char* ls_date_str(time_t tm) {
371 struct tm t; 378 struct tm t;
583 return -1; 590 return -1;
584 } 591 }
585 592
586 int ret = get_resource(repo, res, a, outfile); 593 int ret = get_resource(repo, res, a, outfile);
587 594
595 free(path);
588 return ret; 596 return ret;
589 } 597 }
590 598
591 int get_resource(Repository *repo, DavResource *res, CmdArgs *a, char *out) { 599 int get_resource(Repository *repo, DavResource *res, CmdArgs *a, char *out) {
592 size_t outlen = strlen(out); 600 size_t outlen = strlen(out);
675 ret = put_file(repo, a, sn, path, "stdin", in); 683 ret = put_file(repo, a, sn, path, "stdin", in);
676 } else { 684 } else {
677 ret = put_entry(repo, a, sn, path, file); 685 ret = put_entry(repo, a, sn, path, file);
678 } 686 }
679 687
688 free(path);
680 return ret; 689 return ret;
681 } 690 }
682 691
683 int put_entry(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *file) { 692 int put_entry(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *file) {
684 int recursive = cmd_getoption(a, "recursive") ? 1 : 0; 693 int recursive = cmd_getoption(a, "recursive") ? 1 : 0;
754 return -1; 763 return -1;
755 } 764 }
756 } else if(res->iscollection) { 765 } else if(res->iscollection) {
757 // TODO: free res 766 // TODO: free res
758 char *newpath = util_concat_path(path, name); 767 char *newpath = util_concat_path(path, name);
759 free(path);
760 path = newpath; 768 path = newpath;
761 res = dav_resource_new(sn, path); 769 res = dav_resource_new(sn, path);
770 free(newpath);
762 int ret = put_file(repo, a, sn, res->path, NULL, in); 771 int ret = put_file(repo, a, sn, res->path, NULL, in);
763 // TODO: free res 772 // TODO: free res
764 return ret; 773 return ret;
765 } 774 }
766 775
803 print_resource_error(sn, res->path); 812 print_resource_error(sn, res->path);
804 fprintf(stderr, "Cannot delete resource.\n"); 813 fprintf(stderr, "Cannot delete resource.\n");
805 return -1; 814 return -1;
806 } 815 }
807 816
817 free(path);
808 return 0; 818 return 0;
809 } 819 }
810 820
811 int cmd_mkdir(CmdArgs *a) { 821 int cmd_mkdir(CmdArgs *a) {
812 if(a->argc != 1) { 822 if(a->argc != 1) {
847 print_resource_error(sn, res->path); 857 print_resource_error(sn, res->path);
848 fprintf(stderr, "Cannot create collection.\n"); 858 fprintf(stderr, "Cannot create collection.\n");
849 return -1; 859 return -1;
850 } 860 }
851 861
862 free(path);
852 return 0; 863 return 0;
853 } 864 }
854 865
855 866
856 static size_t get_date_header_cb(void *header, int s, int n, void *data) { 867 static size_t get_date_header_cb(void *header, int s, int n, void *data) {
886 if(dav_exists(res) && date) { 897 if(dav_exists(res) && date) {
887 printf("%s\n", date); 898 printf("%s\n", date);
888 } else { 899 } else {
889 return -1; 900 return -1;
890 } 901 }
902 free(path);
891 return 0; 903 return 0;
892 } else { 904 } else {
893 fprintf(stderr, "Too many arguments\n"); 905 fprintf(stderr, "Too many arguments\n");
894 return -1; 906 return -1;
895 } 907 }
934 // TODO: correct error message 946 // TODO: correct error message
935 fprintf(stderr, "Error: property not found.\n"); 947 fprintf(stderr, "Error: property not found.\n");
936 ret = -1; 948 ret = -1;
937 } 949 }
938 950
951 free(path);
939 return ret; 952 return ret;
940 } 953 }
941 954
942 int cmd_set_property(CmdArgs *a) { 955 int cmd_set_property(CmdArgs *a) {
943 if(a->argc < 2) { 956 if(a->argc < 2) {
973 print_resource_error(sn, res->path); 986 print_resource_error(sn, res->path);
974 fprintf(stderr, "Cannot set property.\n"); 987 fprintf(stderr, "Cannot set property.\n");
975 return -1; 988 return -1;
976 } 989 }
977 990
991 free(path);
978 return 0; 992 return 0;
979 } 993 }
980 994
981 char* stdin2str() { 995 char* stdin2str() {
982 UcxBuffer *buf = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND); 996 UcxBuffer *buf = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND);

mercurial