dav/main.c

changeset 33
0bbbb0341606
parent 32
c9d37bb97ea8
child 34
1b87b3b1921e
equal deleted inserted replaced
32:c9d37bb97ea8 33:0bbbb0341606
36 #include <sys/types.h> 36 #include <sys/types.h>
37 #include <ucx/string.h> 37 #include <ucx/string.h>
38 #include <dirent.h> 38 #include <dirent.h>
39 39
40 40
41 #include "utils.h" 41 #include <libidav/utils.h>
42 #include "config.h" 42 #include "config.h"
43 #include "crypto.h" 43 #include "crypto.h"
44 #include "main.h" 44 #include "main.h"
45 45
46 #include "davql.h"
47
48 static DavContext *ctx; 46 static DavContext *ctx;
49 47
50 void xmlerrorfnc(void * c, const char * msg, ... ) { 48 void xmlerrorfnc(void * c, const char * msg, ... ) {
51 // nothing 49 // nothing
52 } 50 }
53 51
54 int main(int argc, char **argv) { 52 int main(int argc, char **argv) {
53
54 char *xargv[4];
55 xargv[0] = "dav";
56 xargv[1] = "put";
57 xargv[2] = "sunfire";
58 xargv[3] = "config.xml";
59 int xargc = 4;
60
55 xmlGenericErrorFunc fnc = xmlerrorfnc; 61 xmlGenericErrorFunc fnc = xmlerrorfnc;
56 initGenericErrorDefaultFunc(&fnc); 62 initGenericErrorDefaultFunc(&fnc);
57 load_config(); 63 load_config();
58 ctx = dav_context_new(); 64 ctx = dav_context_new();
59 dav_add_namespace(ctx, "U", "http://www.uap-core.de/"); 65 dav_add_namespace(ctx, "U", "http://www.uap-core.de/");
60 66
61 if(argc < 2) { 67 if(xargc < 2) {
62 fprintf(stderr, "Missing command\n"); 68 fprintf(stderr, "Missing command\n");
63 print_usage(argv[0]); 69 print_usage(argv[0]);
64 return -1; 70 return -1;
65 } 71 }
66 72
67 char *cmd = argv[1]; 73 char *cmd = xargv[1];
68 CmdArgs *args = cmd_parse_args(argc - 2, argv + 2); 74 CmdArgs *args = cmd_parse_args(xargc - 2, xargv + 2);
69 if(!args) { 75 if(!args) {
70 print_usage(argv[0]); 76 print_usage(argv[0]);
71 return -1; 77 return -1;
72 } 78 }
73 79
75 if(!strcasecmp(cmd, "list") || !strcasecmp(cmd, "ls")) { 81 if(!strcasecmp(cmd, "list") || !strcasecmp(cmd, "ls")) {
76 ret = cmd_list(args); 82 ret = cmd_list(args);
77 } else if(!strcasecmp(cmd, "get")) { 83 } else if(!strcasecmp(cmd, "get")) {
78 ret = cmd_get(args); 84 ret = cmd_get(args);
79 } else if(!strcasecmp(cmd, "put")) { 85 } else if(!strcasecmp(cmd, "put")) {
86 printf("put\n");
80 ret = cmd_put(args); 87 ret = cmd_put(args);
81 } else if( 88 } else if(
82 !strcasecmp(cmd, "remove") || 89 !strcasecmp(cmd, "remove") ||
83 !strcasecmp(cmd, "rm") || 90 !strcasecmp(cmd, "rm") ||
84 !strcasecmp(cmd, "delete")) 91 !strcasecmp(cmd, "delete"))
97 } 104 }
98 105
99 void print_usage(char *cmd) { 106 void print_usage(char *cmd) {
100 fprintf(stderr, "Usage: %s command [options] arguments...\n\n", cmd); 107 fprintf(stderr, "Usage: %s command [options] arguments...\n\n", cmd);
101 fprintf(stderr, "Commands:\n"); 108 fprintf(stderr, "Commands:\n");
102 fprintf(stderr, "list [-altR] [-u <date>] <url>\n"); 109 fprintf(stderr, " list [-altR] [-u <date>] <url>\n");
103 fprintf( 110 fprintf(
104 stderr, 111 stderr,
105 " get [-pR] [-k <key>] [-o <file>] [-u <date>] <url>\n"); 112 " get [-pR] [-k <key>] [-o <file>] [-u <date>] <url>\n");
106 fprintf(stderr, " put [-p] [-k <key>] <url> <file>\n"); 113 fprintf(stderr, " put [-pR] [-k <key>] <url> <file>\n");
107 fprintf(stderr, " mkdir <url>\n"); 114 fprintf(stderr, " mkdir <url>\n");
108 fprintf(stderr, " remove <url>\n"); 115 fprintf(stderr, " remove <url>\n");
109 fprintf(stderr, " date [url]\n"); 116 fprintf(stderr, " date [url]\n");
110 fprintf(stderr, "\n"); 117 fprintf(stderr, "\n");
111 fprintf(stderr, "Options:\n"); 118 fprintf(stderr, "Options:\n");
641 int ret; 648 int ret;
642 if(!strcmp(file, "-")) { 649 if(!strcmp(file, "-")) {
643 FILE *in = stdin; 650 FILE *in = stdin;
644 ret = put_file(repo, a, sn, path, "stdin", in); 651 ret = put_file(repo, a, sn, path, "stdin", in);
645 } else { 652 } else {
646 ret = put_entry(repo, a, sn, path, file); 653 ret = put_entry(repo, a, sn, path, file);
647 } 654 }
648 655
649 return ret; 656 return ret;
650 } 657 }
651 658
696 return -1; 703 return -1;
697 } 704 }
698 char *filename = util_resource_name(file); 705 char *filename = util_resource_name(file);
699 //path = util_concat_path(path, filename); 706 //path = util_concat_path(path, filename);
700 ret = put_file(repo, a, sn, path, filename, in); 707 ret = put_file(repo, a, sn, path, filename, in);
701 free(path); 708 //free(path);
702 fclose(in); 709 fclose(in);
703 } 710 }
704 711
705 return ret; 712 return ret;
706 } 713 }
886 return -1; 893 return -1;
887 } 894 }
888 } 895 }
889 return 0; 896 return 0;
890 } 897 }
898
899 int cmd_sync(CmdArgs *a) {
900 if(a->argc < 2) {
901 fprintf(stderr, "Too few arguments\n");
902 return -1;
903 }
904
905 return 0;
906 }

mercurial