dav/sync.c

changeset 795
05647e862a17
parent 789
378b5ab86f77
child 799
d479b5e25b6e
equal deleted inserted replaced
794:29d544c3c2b8 795:05647e862a17
596 596
597 static int localres_cmp_path_desc(LocalResource *a, LocalResource *b, void *n) { 597 static int localres_cmp_path_desc(LocalResource *a, LocalResource *b, void *n) {
598 return -strcmp(a->path, b->path); 598 return -strcmp(a->path, b->path);
599 } 599 }
600 600
601 static DavSession* create_session(CmdArgs *a, DavContext *ctx, Repository *repo, char *collection) { 601 static DavSession* create_session(CmdArgs *a, DavContext *ctx, DavCfgRepository *repo, char *collection) {
602 int flags = get_repository_flags(repo); 602 int flags = dav_repository_get_flags(repo);
603 DavBool find_collection = TRUE; 603 DavBool find_collection = TRUE;
604 if((flags & DAV_SESSION_DECRYPT_NAME) != DAV_SESSION_DECRYPT_NAME) { 604 if((flags & DAV_SESSION_DECRYPT_NAME) != DAV_SESSION_DECRYPT_NAME) {
605 char *url = util_concat_path(repo->url, collection); 605 char *url = util_concat_path(repo->url.value.ptr, collection);
606 free(repo->url); 606 dav_repository_set_url(get_config(), repo, cx_str(url));
607 repo->url = url; 607 free(url);
608 collection = NULL; 608 collection = NULL;
609 find_collection = FALSE; 609 find_collection = FALSE;
610 } 610 }
611 if(!collection || (collection[0] == '/' && strlen(collection) == 1)) { 611 if(!collection || (collection[0] == '/' && strlen(collection) == 1)) {
612 // collection is NULL or "/" 612 // collection is NULL or "/"
616 } 616 }
617 617
618 DavSession *sn = connect_to_repo(ctx, repo, collection, request_auth, a); 618 DavSession *sn = connect_to_repo(ctx, repo, collection, request_auth, a);
619 619
620 sn->flags = flags; 620 sn->flags = flags;
621 sn->key = dav_context_get_key(ctx, repo->default_key); 621 sn->key = dav_context_get_key(ctx, repo->default_key.value.ptr);
622 curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods); 622 curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods);
623 curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version); 623 curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version);
624 if(repo->cert) { 624 if(repo->cert.value.ptr) {
625 curl_easy_setopt(sn->handle, CURLOPT_CAPATH, repo->cert); 625 curl_easy_setopt(sn->handle, CURLOPT_CAPATH, repo->cert.value.ptr);
626 } 626 }
627 if(!repo->verification) { 627 if(!repo->verification.value) {
628 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYPEER, 0); 628 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYPEER, 0);
629 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0); 629 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0);
630 } 630 }
631 631
632 if(find_collection) { 632 if(find_collection) {
633 DavResource *col = dav_resource_new(sn, collection); 633 DavResource *col = dav_resource_new(sn, collection);
634 dav_exists(col); // exec this to get the href 634 dav_exists(col); // exec this to get the href
635 // we actually don't care what the result is 635 // we actually don't care what the result is
636 // if it doesn't exists, an error will occur later 636 // if it doesn't exists, an error will occur later
637 // and we can't handle it here 637 // and we can't handle it here
638 char *newurl = util_concat_path(repo->url, util_resource_name(col->href)); 638 char *newurl = util_concat_path(repo->url.value.ptr, util_resource_name(col->href));
639 dav_session_set_baseurl(sn, newurl); 639 dav_session_set_baseurl(sn, newurl);
640 free(newurl); 640 free(newurl);
641 } 641 }
642 642
643 return sn; 643 return sn;
729 fprintf(stderr, "Command 'pull' is not allowed for this sync dir\n"); 729 fprintf(stderr, "Command 'pull' is not allowed for this sync dir\n");
730 print_allowed_cmds(dir); 730 print_allowed_cmds(dir);
731 return -1; 731 return -1;
732 } 732 }
733 733
734 Repository *repo = get_repository(cx_str(dir->repository)); 734 DavCfgRepository *repo = dav_config_get_repository(get_config(), cx_str(dir->repository));
735 if(!repo) { 735 if(!repo) {
736 fprintf(stderr, "Unknown repository %s\n", dir->repository); 736 fprintf(stderr, "Unknown repository %s\n", dir->repository);
737 return -1; 737 return -1;
738 } 738 }
739 739
2074 fprintf(stderr, "Command '%s' is not allowed for this sync dir\n", archive ? "archive" : "push"); 2074 fprintf(stderr, "Command '%s' is not allowed for this sync dir\n", archive ? "archive" : "push");
2075 print_allowed_cmds(dir); 2075 print_allowed_cmds(dir);
2076 return -1; 2076 return -1;
2077 } 2077 }
2078 2078
2079 Repository *repo = get_repository(cx_str(dir->repository)); 2079 DavCfgRepository *repo = dav_config_get_repository(get_config(), cx_str(dir->repository));
2080 if(!repo) { 2080 if(!repo) {
2081 fprintf(stderr, "Unkown repository %s\n", dir->name); 2081 fprintf(stderr, "Unkown repository %s\n", dir->name);
2082 return -1; 2082 return -1;
2083 } 2083 }
2084 2084
2752 } 2752 }
2753 2753
2754 int ret = 0; 2754 int ret = 0;
2755 2755
2756 // create DavSession 2756 // create DavSession
2757 Repository *repo = get_repository(cx_str(dir->repository)); 2757 DavCfgRepository *repo = dav_config_get_repository(get_config(), cx_str(dir->repository));
2758 if(!repo) { 2758 if(!repo) {
2759 log_error("Unkown repository %s\n", dir->name); 2759 log_error("Unkown repository %s\n", dir->name);
2760 return -1; 2760 return -1;
2761 } 2761 }
2762 DavSession *sn = create_session(a, ctx, repo, dir->collection); 2762 DavSession *sn = create_session(a, ctx, repo, dir->collection);
5132 5132
5133 if(!dir->versioning) { 5133 if(!dir->versioning) {
5134 fprintf(stderr, "No versioning configured for syncdir %s\n", dir->name); 5134 fprintf(stderr, "No versioning configured for syncdir %s\n", dir->name);
5135 } 5135 }
5136 5136
5137 Repository *repo = get_repository(cx_str(dir->repository)); 5137 DavCfgRepository *repo = dav_config_get_repository(get_config(), cx_str(dir->repository));
5138 if(!repo) { 5138 if(!repo) {
5139 fprintf(stderr, "Unknown repository %s\n", dir->repository); 5139 fprintf(stderr, "Unknown repository %s\n", dir->repository);
5140 return -1; 5140 return -1;
5141 } 5141 }
5142 5142
5727 } 5727 }
5728 5728
5729 CxIterator iter = cxListIterator(reponames); 5729 CxIterator iter = cxListIterator(reponames);
5730 cx_foreach(char *, reponame, iter) { 5730 cx_foreach(char *, reponame, iter) {
5731 log_printf("Checking %s... ", reponame); 5731 log_printf("Checking %s... ", reponame);
5732 Repository* repo = get_repository(cx_str(reponame)); 5732 DavCfgRepository *repo = dav_config_get_repository(get_config(), cx_str(reponame));
5733 if (!repo) { 5733 if (!repo) {
5734 log_printf(" not found in config.xml!\n"); 5734 log_printf(" not found in config.xml!\n");
5735 ret = EXIT_FAILURE; 5735 ret = EXIT_FAILURE;
5736 } else { 5736 } else {
5737 DavSession *sn = create_session(a, ctx, repo, repo->url); 5737 DavSession *sn = create_session(a, ctx, repo, repo->url.value.ptr);
5738 if (sn) { 5738 if (sn) {
5739 DavResource *res = dav_query(sn, 5739 DavResource *res = dav_query(sn,
5740 "select - from / with depth = 0"); 5740 "select - from / with depth = 0");
5741 if (res) { 5741 if (res) {
5742 log_printf("OK.\n"); 5742 log_printf("OK.\n");

mercurial