422 return -1; |
422 return -1; |
423 } |
423 } |
424 |
424 |
425 char *url = a->argv[0]; |
425 char *url = a->argv[0]; |
426 char *path = NULL; |
426 char *path = NULL; |
427 Repository *repo = url2repo(url, &path); |
427 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
428 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
428 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
429 |
429 |
430 if(set_session_config(sn, a)) { |
430 if(set_session_config(sn, a)) { |
431 return -1; |
431 return -1; |
432 } |
432 } |
601 cxMapPut(a->options, cx_hash_key_str("recursive"), ""); |
601 cxMapPut(a->options, cx_hash_key_str("recursive"), ""); |
602 } |
602 } |
603 |
603 |
604 char *url = a->argv[0]; |
604 char *url = a->argv[0]; |
605 char *path = NULL; |
605 char *path = NULL; |
606 Repository *repo = url2repo(url, &path); |
606 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
607 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
607 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
608 |
608 |
609 if(set_session_config(sn, a)) { |
609 if(set_session_config(sn, a)) { |
610 return -1; |
610 return -1; |
611 } |
611 } |
848 return -1; |
848 return -1; |
849 } |
849 } |
850 |
850 |
851 char *url = a->argv[0]; |
851 char *url = a->argv[0]; |
852 char *path = NULL; |
852 char *path = NULL; |
853 Repository *repo = url2repo(url, &path); |
853 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
854 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
854 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
855 |
855 |
856 if(set_session_config(sn, a)) { |
856 if(set_session_config(sn, a)) { |
857 return -1; |
857 return -1; |
858 } |
858 } |
1036 |
1036 |
1037 return ret; |
1037 return ret; |
1038 #endif |
1038 #endif |
1039 } |
1039 } |
1040 |
1040 |
1041 int get_resource(Repository *repo, GetResource *getres, CmdArgs *a, void *unused) { |
1041 int get_resource(DavCfgRepository *repo, GetResource *getres, CmdArgs *a, void *unused) { |
1042 DavResource *res = getres->res; |
1042 DavResource *res = getres->res; |
1043 char *out = getres->path; |
1043 char *out = getres->path; |
1044 |
1044 |
1045 if(res->iscollection) { |
1045 if(res->iscollection) { |
1046 printf("get: %s\n", res->path); |
1046 printf("get: %s\n", res->path); |
1094 } |
1094 } |
1095 |
1095 |
1096 #define DEFAULT_DIR_MODE T_IRUSR | T_IWUSR | T_IXUSR | T_IRGRP | T_IXGRP | T_IROTH | T_IXOTH |
1096 #define DEFAULT_DIR_MODE T_IRUSR | T_IWUSR | T_IXUSR | T_IRGRP | T_IXGRP | T_IROTH | T_IXOTH |
1097 #define DEFAULT_FILE_MODE T_IRUSR | T_IWUSR | T_IRGRP | T_IROTH |
1097 #define DEFAULT_FILE_MODE T_IRUSR | T_IWUSR | T_IRGRP | T_IROTH |
1098 |
1098 |
1099 int resource2tar(Repository *repo, GetResource *res, CmdArgs *a, TarOutputStream *tar) { |
1099 int resource2tar(DavCfgRepository *repo, GetResource *res, CmdArgs *a, TarOutputStream *tar) { |
1100 DavResource *d = res->res; |
1100 DavResource *d = res->res; |
1101 |
1101 |
1102 if(d->iscollection) { |
1102 if(d->iscollection) { |
1103 fprintf(stderr, "add d: %s\n", res->path); |
1103 fprintf(stderr, "add d: %s\n", res->path); |
1104 return tar_add_dir(tar, res->path, DEFAULT_DIR_MODE, d->lastmodified); |
1104 return tar_add_dir(tar, res->path, DEFAULT_DIR_MODE, d->lastmodified); |
1146 cxMapPut(a->options, cx_hash_key_str("resursive"), ""); |
1146 cxMapPut(a->options, cx_hash_key_str("resursive"), ""); |
1147 } |
1147 } |
1148 |
1148 |
1149 char *url = a->argv[0]; |
1149 char *url = a->argv[0]; |
1150 char *path = NULL; |
1150 char *path = NULL; |
1151 Repository *repo = url2repo(url, &path); |
1151 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
1152 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1152 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1153 |
1153 |
1154 if(set_session_config(sn, a)) { |
1154 if(set_session_config(sn, a)) { |
1155 return -1; |
1155 return -1; |
1156 } |
1156 } |
1317 } |
1317 } |
1318 |
1318 |
1319 return ret; |
1319 return ret; |
1320 } |
1320 } |
1321 |
1321 |
1322 int put_tar(Repository *repo, CmdArgs *a, DavSession *sn, char *tarfile, char *path) { |
1322 int put_tar(DavCfgRepository *repo, CmdArgs *a, DavSession *sn, char *tarfile, char *path) { |
1323 int isstdin = !strcmp(tarfile, "-"); |
1323 int isstdin = !strcmp(tarfile, "-"); |
1324 FILE *in = isstdin ? stdin : fopen(tarfile, "rb"); |
1324 FILE *in = isstdin ? stdin : fopen(tarfile, "rb"); |
1325 if(!in) { |
1325 if(!in) { |
1326 perror("Cannot open tar file"); |
1326 perror("Cannot open tar file"); |
1327 return -1; |
1327 return -1; |
1562 return -1; |
1562 return -1; |
1563 } |
1563 } |
1564 |
1564 |
1565 char *srcurl = a->argv[0]; |
1565 char *srcurl = a->argv[0]; |
1566 char *srcpath = NULL; |
1566 char *srcpath = NULL; |
1567 Repository *srcrepo = url2repo(srcurl, &srcpath); |
1567 DavCfgRepository *srcrepo = dav_config_url2repo(get_config(), srcurl, &srcpath); |
1568 |
1568 |
1569 DavSession *srcsn = connect_to_repo(ctx, srcrepo, srcpath, request_auth, a); |
1569 DavSession *srcsn = connect_to_repo(ctx, srcrepo, srcpath, request_auth, a); |
1570 if(set_session_config(srcsn, a)) { |
1570 if(set_session_config(srcsn, a)) { |
1571 return -1; |
1571 return -1; |
1572 } |
1572 } |
1574 |
1574 |
1575 DavBool override = cmd_getoption(a, "override") ? true : false; |
1575 DavBool override = cmd_getoption(a, "override") ? true : false; |
1576 |
1576 |
1577 char *desturl = a->argv[1]; |
1577 char *desturl = a->argv[1]; |
1578 char *destpath = NULL; |
1578 char *destpath = NULL; |
1579 Repository *destrepo = url2repo(desturl, &destpath); |
1579 DavCfgRepository *destrepo = dav_config_url2repo(get_config(), desturl, &destpath); |
1580 |
1580 |
1581 if(srcrepo == destrepo) { |
1581 if(srcrepo == destrepo) { |
1582 DavResource *res = dav_resource_new(srcsn, srcpath); |
1582 DavResource *res = dav_resource_new(srcsn, srcpath); |
1583 int err = cp ? dav_copy_o(res, destpath, override) |
1583 int err = cp ? dav_copy_o(res, destpath, override) |
1584 : dav_move_o(res, destpath, override); |
1584 : dav_move_o(res, destpath, override); |
1586 print_resource_error(srcsn, res->path); |
1586 print_resource_error(srcsn, res->path); |
1587 fprintf(stderr, "Cannot %s resource.\n", actionstr); |
1587 fprintf(stderr, "Cannot %s resource.\n", actionstr); |
1588 return -1; |
1588 return -1; |
1589 } |
1589 } |
1590 } else { |
1590 } else { |
1591 char *srchost = util_url_base(srcrepo->url); |
1591 char *srchost = util_url_base(srcrepo->url.value.ptr); |
1592 char *desthost = util_url_base(destrepo->url); |
1592 char *desthost = util_url_base(destrepo->url.value.ptr); |
1593 if(!strcmp(srchost, desthost)) { |
1593 if(!strcmp(srchost, desthost)) { |
1594 DavSession *destsn = connect_to_repo(ctx, destrepo, destpath, request_auth, a); |
1594 DavSession *destsn = connect_to_repo(ctx, destrepo, destpath, request_auth, a); |
1595 if(set_session_config(destsn, a)) { |
1595 if(set_session_config(destsn, a)) { |
1596 return -1; |
1596 return -1; |
1597 } |
1597 } |
1640 } |
1640 } |
1641 } |
1641 } |
1642 |
1642 |
1643 char *url = a->argv[0]; |
1643 char *url = a->argv[0]; |
1644 char *path = NULL; |
1644 char *path = NULL; |
1645 Repository *repo = url2repo(url, &path); |
1645 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
1646 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1646 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1647 |
1647 |
1648 if(set_session_config(sn, a)) { |
1648 if(set_session_config(sn, a)) { |
1649 return -1; |
1649 return -1; |
1650 } |
1650 } |
1732 size_t len = strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT\n", date); |
1732 size_t len = strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT\n", date); |
1733 fwrite(str, 1, len, stdout); |
1733 fwrite(str, 1, len, stdout); |
1734 } else if (a->argc == 1) { |
1734 } else if (a->argc == 1) { |
1735 char *url = a->argv[0]; |
1735 char *url = a->argv[0]; |
1736 char *path = NULL; |
1736 char *path = NULL; |
1737 Repository *repo = url2repo(url, &path); |
1737 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
1738 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1738 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1739 |
1739 |
1740 DavResource *res = dav_resource_new(sn, path); |
1740 DavResource *res = dav_resource_new(sn, path); |
1741 char *date = NULL; |
1741 char *date = NULL; |
1742 curl_easy_setopt(sn->handle, CURLOPT_HEADERFUNCTION, get_date_header_cb); |
1742 curl_easy_setopt(sn->handle, CURLOPT_HEADERFUNCTION, get_date_header_cb); |
1763 return -1; |
1763 return -1; |
1764 } |
1764 } |
1765 |
1765 |
1766 char *url = a->argv[0]; |
1766 char *url = a->argv[0]; |
1767 char *path = NULL; |
1767 char *path = NULL; |
1768 Repository *repo = url2repo(url, &path); |
1768 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
1769 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1769 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1770 |
1770 |
1771 if(set_session_config(sn, a)) { |
1771 if(set_session_config(sn, a)) { |
1772 return -1; |
1772 return -1; |
1773 } |
1773 } |
1837 return -1; |
1837 return -1; |
1838 } |
1838 } |
1839 |
1839 |
1840 char *url = a->argv[0]; |
1840 char *url = a->argv[0]; |
1841 char *path = NULL; |
1841 char *path = NULL; |
1842 Repository *repo = url2repo(url, &path); |
1842 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
1843 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1843 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1844 |
1844 |
1845 if(set_session_config(sn, a)) { |
1845 if(set_session_config(sn, a)) { |
1846 return -1; |
1846 return -1; |
1847 } |
1847 } |
1900 return -1; |
1900 return -1; |
1901 } |
1901 } |
1902 |
1902 |
1903 char *url = a->argv[0]; |
1903 char *url = a->argv[0]; |
1904 char *path = NULL; |
1904 char *path = NULL; |
1905 Repository *repo = url2repo(url, &path); |
1905 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
1906 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1906 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1907 |
1907 |
1908 if(set_session_config(sn, a)) { |
1908 if(set_session_config(sn, a)) { |
1909 return -1; |
1909 return -1; |
1910 } |
1910 } |
1941 return -1; |
1941 return -1; |
1942 } |
1942 } |
1943 |
1943 |
1944 char *url = a->argv[0]; |
1944 char *url = a->argv[0]; |
1945 char *path = NULL; |
1945 char *path = NULL; |
1946 Repository *repo = url2repo(url, &path); |
1946 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
1947 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1947 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
1948 cxMempoolRegister(sn->mp, path, free); |
1948 cxMempoolRegister(sn->mp, path, free); |
1949 |
1949 |
1950 if(set_session_config(sn, a)) { |
1950 if(set_session_config(sn, a)) { |
1951 return -1; |
1951 return -1; |
2014 return -1; |
2014 return -1; |
2015 } |
2015 } |
2016 |
2016 |
2017 char *url = a->argv[0]; |
2017 char *url = a->argv[0]; |
2018 char *path = NULL; |
2018 char *path = NULL; |
2019 Repository *repo = url2repo(url, &path); |
2019 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
2020 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
2020 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
2021 cxMempoolRegister(sn->mp, path, free); |
2021 cxMempoolRegister(sn->mp, path, free); |
2022 if(set_session_config(sn, a)) { |
2022 if(set_session_config(sn, a)) { |
2023 return -1; |
2023 return -1; |
2024 } |
2024 } |
2074 return -1; |
2074 return -1; |
2075 } |
2075 } |
2076 |
2076 |
2077 char *url = a->argv[0]; |
2077 char *url = a->argv[0]; |
2078 char *path = NULL; |
2078 char *path = NULL; |
2079 Repository *repo = url2repo(url, &path); |
2079 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
2080 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
2080 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
2081 |
2081 |
2082 if(set_session_config(sn, a)) { |
2082 if(set_session_config(sn, a)) { |
2083 return -1; |
2083 return -1; |
2084 } |
2084 } |
2170 return -1; |
2170 return -1; |
2171 } |
2171 } |
2172 |
2172 |
2173 char *url = a->argv[0]; |
2173 char *url = a->argv[0]; |
2174 char *path = NULL; |
2174 char *path = NULL; |
2175 Repository *repo = url2repo(url, &path); |
2175 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
2176 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
2176 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
2177 |
2177 |
2178 if(set_session_config(sn, a)) { |
2178 if(set_session_config(sn, a)) { |
2179 return -1; |
2179 return -1; |
2180 } |
2180 } |
2197 return -1; |
2197 return -1; |
2198 } |
2198 } |
2199 |
2199 |
2200 char *url = a->argv[0]; |
2200 char *url = a->argv[0]; |
2201 char *path = NULL; |
2201 char *path = NULL; |
2202 Repository *repo = url2repo(url, &path); |
2202 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
2203 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
2203 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
2204 |
2204 |
2205 if(set_session_config(sn, a)) { |
2205 if(set_session_config(sn, a)) { |
2206 return -1; |
2206 return -1; |
2207 } |
2207 } |
2224 return -1; |
2224 return -1; |
2225 } |
2225 } |
2226 |
2226 |
2227 char *url = a->argv[0]; |
2227 char *url = a->argv[0]; |
2228 char *path = NULL; |
2228 char *path = NULL; |
2229 Repository *repo = url2repo(url, &path); |
2229 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
2230 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
2230 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
2231 |
2231 |
2232 if(set_session_config(sn, a)) { |
2232 if(set_session_config(sn, a)) { |
2233 return -1; |
2233 return -1; |
2234 } |
2234 } |
2250 return -1; |
2250 return -1; |
2251 } |
2251 } |
2252 |
2252 |
2253 char *url = a->argv[0]; |
2253 char *url = a->argv[0]; |
2254 char *path = NULL; |
2254 char *path = NULL; |
2255 Repository *repo = url2repo(url, &path); |
2255 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
2256 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
2256 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
2257 |
2257 |
2258 if(set_session_config(sn, a)) { |
2258 if(set_session_config(sn, a)) { |
2259 return -1; |
2259 return -1; |
2260 } |
2260 } |
2277 return -1; |
2277 return -1; |
2278 } |
2278 } |
2279 |
2279 |
2280 char *url = a->argv[0]; |
2280 char *url = a->argv[0]; |
2281 char *path = NULL; |
2281 char *path = NULL; |
2282 Repository *repo = url2repo(url, &path); |
2282 DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); |
2283 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
2283 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, a); |
2284 |
2284 |
2285 if(set_session_config(sn, a)) { |
2285 if(set_session_config(sn, a)) { |
2286 return -1; |
2286 return -1; |
2287 } |
2287 } |
2440 if(user) { |
2440 if(user) { |
2441 password = assistant_gethiddenoptcfg("password"); |
2441 password = assistant_gethiddenoptcfg("password"); |
2442 } |
2442 } |
2443 printf("\n"); |
2443 printf("\n"); |
2444 |
2444 |
2445 Repository repo; |
2445 DavConfig *config = get_config(); |
2446 memset(&repo, 0, sizeof(Repository)); |
2446 const CxAllocator *a = config->mp->allocator; |
2447 repo.name = name; |
2447 DavCfgRepository *repo = dav_repository_new(config); |
2448 repo.url = url; |
2448 |
2449 repo.user = user; |
2449 repo->name.value = cx_strdup_a(a, cx_str(name)); |
2450 repo.password = password; |
2450 repo->url.value = cx_strdup_a(a, cx_str(url)); |
|
2451 dav_repository_set_auth(config, repo, cx_str(user), cx_str(password)); |
|
2452 |
|
2453 dav_config_add_repository(config, repo); |
2451 |
2454 |
2452 int ret = 0; |
2455 int ret = 0; |
2453 if(add_repository(&repo)) { |
2456 if(store_config()) { |
2454 fprintf(stderr, "Cannot write config.xml\n"); |
2457 fprintf(stderr, "Cannot write config.xml\n"); |
2455 ret = -1; |
2458 ret = -1; |
2456 } else { |
2459 } else { |
2457 printf("\nAdded repository: %s (%s)\n", name, url); |
2460 printf("\nAdded repository: %s (%s)\n", name, url); |
2458 } |
2461 } |
2474 fprintf(stderr, "Too few arguments\n"); |
2477 fprintf(stderr, "Too few arguments\n"); |
2475 fprintf(stderr, "Usage: dav remove-repository <name...>\n"); |
2478 fprintf(stderr, "Usage: dav remove-repository <name...>\n"); |
2476 return -1; |
2479 return -1; |
2477 } |
2480 } |
2478 |
2481 |
|
2482 DavConfig *config = get_config(); |
|
2483 |
|
2484 DavBool store = FALSE; |
2479 for(int i = 0 ; i < args->argc ; i++) { |
2485 for(int i = 0 ; i < args->argc ; i++) { |
2480 cxstring reponame = cx_str(args->argv[i]); |
2486 cxstring reponame = cx_str(args->argv[i]); |
2481 Repository* repo = get_repository(reponame); |
2487 DavCfgRepository* repo = dav_config_get_repository(config, reponame); |
2482 if(repo) { |
2488 if(repo) { |
2483 if(remove_repository(repo)) { |
2489 dav_repository_remove_and_free(config, repo); |
2484 fprintf(stderr, "Cannot write config.xml\n"); |
2490 store = TRUE; |
2485 return -1; |
|
2486 } |
|
2487 } else { |
2491 } else { |
2488 fprintf(stderr, "Repository %s does not exist - skipped.\n", |
2492 fprintf(stderr, "Repository %s does not exist - skipped.\n", |
2489 reponame.ptr); |
2493 reponame.ptr); |
2490 return -1; |
2494 return -1; |
2491 } |
2495 } |
2492 } |
2496 } |
2493 |
2497 |
2494 return -1; |
2498 if(store) { |
|
2499 return store_config(); |
|
2500 } else { |
|
2501 return -1; |
|
2502 } |
2495 } |
2503 } |
2496 |
2504 |
2497 int cmd_repository_url(CmdArgs *args) { |
2505 int cmd_repository_url(CmdArgs *args) { |
2498 if(args->argc != 1) { |
2506 if(args->argc != 1) { |
2499 fprintf(stderr, "Too few arguments\n"); |
2507 fprintf(stderr, "Too few arguments\n"); |
2500 fprintf(stderr, "Usage: dav repository-url [-p] <name>\n"); |
2508 fprintf(stderr, "Usage: dav repository-url [-p] <name>\n"); |
2501 return -1; |
2509 return -1; |
2502 } |
2510 } |
2503 |
2511 |
2504 cxstring reponame = cx_str(args->argv[0]); |
2512 cxstring reponame = cx_str(args->argv[0]); |
2505 Repository* repo = get_repository(reponame); |
2513 DavCfgRepository* repo = dav_config_get_repository(get_config(), reponame); |
2506 if(repo) { |
2514 if(repo) { |
2507 cxstring url = cx_str(repo->url); |
2515 cxstring url = cx_strcast(repo->url.value); |
2508 if(repo->user && !cmd_getoption(args, "plain")) { |
2516 if(repo->user.value.ptr && !cmd_getoption(args, "plain")) { |
2509 int hostindex = 0; |
2517 int hostindex = 0; |
2510 if(cx_strprefix(url, CX_STR("https://"))) { |
2518 if(cx_strprefix(url, CX_STR("https://"))) { |
2511 printf("https://"); |
2519 printf("https://"); |
2512 hostindex = 8; |
2520 hostindex = 8; |
2513 } else if(cx_strprefix(url, CX_STR("http://"))) { |
2521 } else if(cx_strprefix(url, CX_STR("http://"))) { |
2514 printf("http://"); |
2522 printf("http://"); |
2515 hostindex = 7; |
2523 hostindex = 7; |
2516 } |
2524 } |
2517 printf("%s", repo->user); |
2525 printf("%.*s", (int)repo->user.value.length, repo->user.value.ptr); |
2518 if(repo->password) { |
2526 if(repo->password.value.ptr) { |
2519 CURL *curl = curl_easy_init(); |
2527 CURL *curl = curl_easy_init(); |
2520 char *pw = curl_easy_escape( |
2528 char *pw = curl_easy_escape( |
2521 curl, |
2529 curl, |
2522 repo->password, |
2530 repo->password.value.ptr, |
2523 strlen(repo->password)); |
2531 repo->password.value.length); |
2524 printf(":%s", pw); |
2532 printf(":%s", pw); |
2525 curl_free(pw); |
2533 curl_free(pw); |
2526 curl_easy_cleanup(curl); |
2534 curl_easy_cleanup(curl); |
2527 } |
2535 } |
2528 putchar('@'); |
2536 putchar('@'); |
3123 } else { |
3131 } else { |
3124 // url completion |
3132 // url completion |
3125 cxMapPut(args->options, cx_hash_key_str("noinput"), ""); |
3133 cxMapPut(args->options, cx_hash_key_str("noinput"), ""); |
3126 |
3134 |
3127 char *path = NULL; |
3135 char *path = NULL; |
3128 Repository *repo = url2repo_s(url, &path); |
3136 DavCfgRepository *repo = dav_config_url2repo(get_config(), url.ptr, &path); |
3129 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, args); |
3137 DavSession *sn = connect_to_repo(ctx, repo, path, request_auth, args); |
3130 if(!sn) { |
3138 if(!sn) { |
3131 return 0; |
3139 return 0; |
3132 } |
3140 } |
3133 if(set_session_config(sn, args)) { |
3141 if(set_session_config(sn, args)) { |
3158 break; |
3166 break; |
3159 } |
3167 } |
3160 } |
3168 } |
3161 |
3169 |
3162 CxBuffer *out = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
3170 CxBuffer *out = cxBufferCreate(NULL, 512, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
3163 cxBufferPutString(out, repo->name); |
3171 cxBufferWrite(repo->name.value.ptr, repo->name.value.length, 1, out); |
3164 if(space) { |
3172 if(space) { |
3165 size_t l = strlen(elm->path); |
3173 size_t l = strlen(elm->path); |
3166 for(int i=0;i<l;i++) { |
3174 for(int i=0;i<l;i++) { |
3167 // only if we do not quote, we have to escape |
3175 // only if we do not quote, we have to escape |
3168 char nextc = elm->path[i]; |
3176 char nextc = elm->path[i]; |