247 } else if(!strcmp(cmd, "list-dirs") |
247 } else if(!strcmp(cmd, "list-dirs") |
248 || !strcmp(cmd, "list-directories")) { |
248 || !strcmp(cmd, "list-directories")) { |
249 ret = cmd_list_dirs(); |
249 ret = cmd_list_dirs(); |
250 } else if(!strcmp(cmd, "check-repos") |
250 } else if(!strcmp(cmd, "check-repos") |
251 || !strcmp(cmd, "check-repositories")) { |
251 || !strcmp(cmd, "check-repositories")) { |
252 ret = cmd_check_repositories(); |
252 ret = cmd_check_repositories(args); |
253 } else { |
253 } else { |
254 print_usage(argv[0]); |
254 print_usage(argv[0]); |
255 } |
255 } |
256 } |
256 } |
257 |
257 |
445 } |
445 } |
446 ucx_list_free(res_tags); |
446 ucx_list_free(res_tags); |
447 return ret; |
447 return ret; |
448 } |
448 } |
449 |
449 |
450 static DavSession* create_session(DavContext *ctx, Repository *repo, char *collection) { |
450 static DavSession* create_session(CmdArgs *a, DavContext *ctx, Repository *repo, char *collection) { |
451 int flags = get_repository_flags(repo); |
451 int flags = get_repository_flags(repo); |
452 char *url = repo->url; |
|
453 DavBool find_collection = TRUE; |
452 DavBool find_collection = TRUE; |
454 if((flags & DAV_SESSION_DECRYPT_NAME) != DAV_SESSION_DECRYPT_NAME) { |
453 if((flags & DAV_SESSION_DECRYPT_NAME) != DAV_SESSION_DECRYPT_NAME) { |
455 url = util_concat_path(repo->url, collection); |
454 char *url = util_concat_path(repo->url, collection); |
|
455 free(repo->url); |
|
456 repo->url = url; |
|
457 collection = NULL; |
456 find_collection = FALSE; |
458 find_collection = FALSE; |
457 } |
459 } |
458 if(!collection || (collection[0] == '/' && strlen(collection) == 1)) { |
460 if(!collection || (collection[0] == '/' && strlen(collection) == 1)) { |
459 // collection is NULL or "/" |
461 // collection is NULL or "/" |
460 // we don't need to find any collection because the repo url is |
462 // we don't need to find any collection because the repo url is |
461 // the base url |
463 // the base url |
462 find_collection = FALSE; |
464 find_collection = FALSE; |
463 } |
465 } |
464 DavSession *sn = dav_session_new_auth( |
466 |
465 ctx, |
467 DavSession *sn = connect_to_repo(ctx, repo, collection, request_auth, a); |
466 url, |
468 |
467 repo->user, |
|
468 repo->password); |
|
469 if(url != repo->url) { |
|
470 free(url); |
|
471 } |
|
472 sn->flags = flags; |
469 sn->flags = flags; |
473 sn->key = dav_context_get_key(ctx, repo->default_key); |
470 sn->key = dav_context_get_key(ctx, repo->default_key); |
474 curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods); |
471 curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods); |
475 curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version); |
472 curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version); |
476 if(repo->cert) { |
473 if(repo->cert) { |
489 // and we can't handle it here |
486 // and we can't handle it here |
490 char *newurl = util_concat_path(repo->url, util_resource_name(col->href)); |
487 char *newurl = util_concat_path(repo->url, util_resource_name(col->href)); |
491 dav_session_set_baseurl(sn, newurl); |
488 dav_session_set_baseurl(sn, newurl); |
492 free(newurl); |
489 free(newurl); |
493 } |
490 } |
494 |
491 |
495 return sn; |
492 return sn; |
496 } |
493 } |
497 |
494 |
498 static void print_allowed_cmds(SyncDirectory *dir) { |
495 static void print_allowed_cmds(SyncDirectory *dir) { |
499 fprintf(stderr, "Allowed commands: "); |
496 fprintf(stderr, "Allowed commands: "); |
594 UcxMap *hashes = NULL; |
591 UcxMap *hashes = NULL; |
595 if(SYNC_HASHING(dir)) { |
592 if(SYNC_HASHING(dir)) { |
596 hashes = create_hash_index(db); |
593 hashes = create_hash_index(db); |
597 } |
594 } |
598 |
595 |
599 DavSession *sn = create_session(ctx, repo, dir->collection); |
596 DavSession *sn = create_session(a, ctx, repo, dir->collection); |
600 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); |
597 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); |
601 if (cmd_getoption(a, "verbose")) { |
598 if (cmd_getoption(a, "verbose")) { |
602 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
599 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
603 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
600 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
604 } |
601 } |
1931 fprintf(stderr, "Cannot load database file: %s\n", dir->database); |
1928 fprintf(stderr, "Cannot load database file: %s\n", dir->database); |
1932 return -1; |
1929 return -1; |
1933 } |
1930 } |
1934 remove_deleted_conflicts(dir, db); |
1931 remove_deleted_conflicts(dir, db); |
1935 |
1932 |
1936 DavSession *sn = create_session(ctx, repo, dir->collection); |
1933 DavSession *sn = create_session(a, ctx, repo, dir->collection); |
1937 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); |
1934 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); |
1938 if (cmd_getoption(a, "verbose")) { |
1935 if (cmd_getoption(a, "verbose")) { |
1939 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
1936 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
1940 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
1937 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
1941 } |
1938 } |
2590 Repository *repo = get_repository(sstr(dir->repository)); |
2587 Repository *repo = get_repository(sstr(dir->repository)); |
2591 if(!repo) { |
2588 if(!repo) { |
2592 fprintf(stderr, "Unkown repository %s\n", dir->name); |
2589 fprintf(stderr, "Unkown repository %s\n", dir->name); |
2593 return -1; |
2590 return -1; |
2594 } |
2591 } |
2595 DavSession *sn = create_session(ctx, repo, dir->collection); |
2592 DavSession *sn = create_session(a, ctx, repo, dir->collection); |
2596 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); |
2593 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); |
2597 if (cmd_getoption(a, "verbose")) { |
2594 if (cmd_getoption(a, "verbose")) { |
2598 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
2595 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
2599 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
2596 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
2600 } |
2597 } |
5042 fprintf(stderr, "Cannot load database file: %s\n", dir->database); |
5039 fprintf(stderr, "Cannot load database file: %s\n", dir->database); |
5043 return -1; |
5040 return -1; |
5044 } |
5041 } |
5045 remove_deleted_conflicts(dir, db); |
5042 remove_deleted_conflicts(dir, db); |
5046 |
5043 |
5047 DavSession *sn = create_session(ctx, repo, dir->collection); |
5044 DavSession *sn = create_session(a, ctx, repo, dir->collection); |
5048 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); |
5045 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); |
5049 if (cmd_getoption(a, "verbose")) { |
5046 if (cmd_getoption(a, "verbose")) { |
5050 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
5047 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
5051 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
5048 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
5052 } |
5049 } |
5601 printf("%s\n", dir->name); |
5598 printf("%s\n", dir->name); |
5602 } |
5599 } |
5603 return 0; |
5600 return 0; |
5604 } |
5601 } |
5605 |
5602 |
5606 int cmd_check_repositories() { |
5603 int cmd_check_repositories(CmdArgs *a) { |
5607 int ret = EXIT_SUCCESS; |
5604 int ret = EXIT_SUCCESS; |
5608 |
5605 |
5609 UcxList *reponames = NULL; |
5606 UcxList *reponames = NULL; |
5610 { |
5607 { |
5611 UcxMapIterator iter = scfg_directory_iterator(); |
5608 UcxMapIterator iter = scfg_directory_iterator(); |
5621 Repository* repo = get_repository(sstr(reponame)); |
5618 Repository* repo = get_repository(sstr(reponame)); |
5622 if (!repo) { |
5619 if (!repo) { |
5623 printf(" not found in config.xml!\n"); |
5620 printf(" not found in config.xml!\n"); |
5624 ret = EXIT_FAILURE; |
5621 ret = EXIT_FAILURE; |
5625 } else { |
5622 } else { |
5626 DavSession *sn = create_session(ctx, repo, repo->url); |
5623 DavSession *sn = create_session(a, ctx, repo, repo->url); |
5627 if (sn) { |
5624 if (sn) { |
5628 DavResource *res = dav_query(sn, |
5625 DavResource *res = dav_query(sn, |
5629 "select - from / with depth = 0"); |
5626 "select - from / with depth = 0"); |
5630 if (res) { |
5627 if (res) { |
5631 printf("OK.\n"); |
5628 printf("OK.\n"); |