dav/main.c

changeset 476
b4e3453e2b49
parent 475
52e4171d42ce
child 478
baa63fef5c5c
equal deleted inserted replaced
475:52e4171d42ce 476:b4e3453e2b49
205 return ret; 205 return ret;
206 } 206 }
207 207
208 static char *cmdusageinfo[] = { 208 static char *cmdusageinfo[] = {
209 "list [-altdepcR] [-u <date>] <url>", 209 "list [-altdepcR] [-u <date>] <url>",
210 "get [-pcRK] [-o <file>] [-u <date>] <url>", 210 "get [-pcRK] [-o <file>] [-u <date>] [-V <version>] <url>",
211 "put [-pcR] [-k <key>] [-L <lock>] <url> <file>", 211 "put [-pcR] [-k <key>] [-L <lock>] <url> <file>",
212 "mkdir [-pc] [-k <key>] [-L <lock>] <url>", 212 "mkdir [-pc] [-k <key>] [-L <lock>] <url>",
213 "remove [-pc] [-L <lock>] <url>", 213 "remove [-pc] [-L <lock>] <url>",
214 "copy [-pcO] [-L <lock>] <url> <url>", 214 "copy [-pcO] [-L <lock>] <url> <url>",
215 "move [-pcO] [-L <lock>] <url> <url>", 215 "move [-pcO] [-L <lock>] <url> <url>",
216 "export [-pc] [-o <file>] [-u <date>] <url>", 216 "export [-pc] [-o <file>] [-u <date>] <url>",
217 "import [-pc] [-k <key>] [-L <lock>] <url> <file>", 217 "import [-pc] [-k <key>] [-L <lock>] <url> <file>",
218 "get-property [-pcx] [-n <uri>] <url> <property>", 218 "get-property [-pcx] [-V <version>] [-n <uri>] <url> <property>",
219 "set-property [-pcx] [-L <lock>] [-n <uri>] <url> <property> [value]", 219 "set-property [-pcx] [-L <lock>] [-n <uri>] <url> <property> [value]",
220 "remove-property [-pc] [-n <uri>] <url> <property>", 220 "remove-property [-pc] [-n <uri>] <url> <property>",
221 "lock [-pc] [-T timeout] <url>", 221 "lock [-pc] [-T timeout] <url>",
222 "unlock [-pc] [-L <lock>] <url>", 222 "unlock [-pc] [-L <lock>] <url>",
223 "info [-pc] <url>", 223 "info [-pc] [-V <version>] <url>",
224 "date [url]", 224 "date [url]",
225 NULL 225 NULL
226 }; 226 };
227 227
228 char* find_usage_str(const char *cmd) { 228 char* find_usage_str(const char *cmd) {
908 return -1; 908 return -1;
909 } 909 }
910 } 910 }
911 911
912 int recursive = cmd_getoption(a, "recursive") ? 1 : 0; 912 int recursive = cmd_getoption(a, "recursive") ? 1 : 0;
913 char *version = cmd_getoption(a, "version");
914
915 if(recursive && version) {
916 fprintf(stderr, "-V option can only be used without -R option\n");
917 return -1;
918 }
919
913 DavResource *res; 920 DavResource *res;
914 921
915 int depth = recursive ? -1 : 1; 922 int depth = recursive ? -1 : 1;
916 res = dav_query( 923 res = dav_query(
917 sn, 924 sn,
925 } 932 }
926 if(!recursive && res->iscollection) { 933 if(!recursive && res->iscollection) {
927 fprintf(stderr, "Resource %s is a collection.\n", res->path); 934 fprintf(stderr, "Resource %s is a collection.\n", res->path);
928 fprintf(stderr, "Use the -R option to download collections.\n"); 935 fprintf(stderr, "Use the -R option to download collections.\n");
929 return -1; 936 return -1;
937 }
938
939 if(version) {
940 DavResource *vres = find_version(res, version);
941 if(!vres) {
942 fprintf(stderr, "Cannot find version '%s' for resource.\n", version);
943 return -1;
944 }
945 dav_resource_free_all(res);
946 res = vres;
930 } 947 }
931 948
932 /* 949 /*
933 * determine the output file 950 * determine the output file
934 * use stdout if the output file is - 951 * use stdout if the output file is -
1614 } 1631 }
1615 1632
1616 char *namespace = cmd_getoption(a, "namespace"); 1633 char *namespace = cmd_getoption(a, "namespace");
1617 char *property = a->argv[1]; 1634 char *property = a->argv[1];
1618 1635
1636 char *version = cmd_getoption(a, "version");
1637
1619 DavPropName propname; 1638 DavPropName propname;
1620 if(namespace) { 1639 if(namespace) {
1621 propname.ns = namespace; 1640 propname.ns = namespace;
1622 propname.name = property; 1641 propname.name = property;
1623 } else { 1642 } else {
1627 return -1; 1646 return -1;
1628 } 1647 }
1629 } 1648 }
1630 1649
1631 DavResource *res = dav_resource_new(sn, path); 1650 DavResource *res = dav_resource_new(sn, path);
1651 if(version) {
1652 DavResource *vres = find_version(res, version);
1653 if(!vres) {
1654 fprintf(stderr, "Cannot find version '%s' for resource.\n", version);
1655 return -1;
1656 }
1657 dav_resource_free_all(res);
1658 res = vres;
1659 }
1660
1632 if(dav_load_prop(res, &propname, 1)) { 1661 if(dav_load_prop(res, &propname, 1)) {
1633 print_resource_error(sn, res->path); 1662 print_resource_error(sn, res->path);
1634 return -1; 1663 return -1;
1635 } 1664 }
1636 free(path); 1665 free(path);
1903 1932
1904 if(set_session_config(sn, a)) { 1933 if(set_session_config(sn, a)) {
1905 return -1; 1934 return -1;
1906 } 1935 }
1907 1936
1937 char *version = cmd_getoption(a, "version");
1938
1908 DavResource *res = dav_resource_new(sn, path); 1939 DavResource *res = dav_resource_new(sn, path);
1940 if(version) {
1941 DavResource *vres = find_version(res, version);
1942 if(!vres) {
1943 fprintf(stderr, "Cannot find version '%s' for resource.\n", version);
1944 return -1;
1945 }
1946 dav_resource_free_all(res);
1947 res = vres;
1948 }
1949
1909 if(!dav_load(res)) { 1950 if(!dav_load(res)) {
1910 printf("name: %s\n", res->name); 1951 printf("name: %s\n", res->name);
1911 printf("path: %s\n", res->path); 1952 printf("path: %s\n", res->path);
1912 1953
1913 char *server = util_url_base(sn->base_url); 1954 char *server = util_url_base(sn->base_url);
2123 } else if(sn->error != DAV_OK) { 2164 } else if(sn->error != DAV_OK) {
2124 print_resource_error(sn, path); 2165 print_resource_error(sn, path);
2125 ret = 1; 2166 ret = 1;
2126 } 2167 }
2127 2168
2169 return ret;
2170 }
2171
2172 DavResource* find_version(DavResource *res, char *version) {
2173 DavResource *list = dav_versiontree(res, NULL);
2174 DavResource *ret = NULL;
2175 while(list) {
2176 DavResource *next = list->next;
2177 if(!ret) {
2178 char *vname = dav_get_string_property(list, "D:version-name");
2179 if(vname && !strcmp(vname, version)) {
2180 ret = list;
2181 }
2182 }
2183 if(list != ret) {
2184 dav_resource_free(list);
2185 }
2186 list = next;
2187 }
2128 return ret; 2188 return ret;
2129 } 2189 }
2130 2190
2131 2191
2132 char* stdin2str() { 2192 char* stdin2str() {

mercurial