320 } |
320 } |
321 ucx_list_free(res_tags); |
321 ucx_list_free(res_tags); |
322 return ret; |
322 return ret; |
323 } |
323 } |
324 |
324 |
325 static DavSession* create_session(DavContext *ctx, Repository *repo, char *url) { |
325 static DavSession* create_session(DavContext *ctx, Repository *repo, char *collection) { |
|
326 int flags = get_repository_flags(repo); |
|
327 char *url = repo->url; |
|
328 DavBool find_collection = TRUE; |
|
329 if((flags & DAV_SESSION_DECRYPT_NAME) != DAV_SESSION_DECRYPT_NAME) { |
|
330 url = util_concat_path(repo->url, collection); |
|
331 find_collection = FALSE; |
|
332 } |
326 DavSession *sn = dav_session_new_auth( |
333 DavSession *sn = dav_session_new_auth( |
327 ctx, |
334 ctx, |
328 url, |
335 url, |
329 repo->user, |
336 repo->user, |
330 repo->password); |
337 repo->password); |
331 sn->flags = get_repository_flags(repo); |
338 if(url != repo->url) { |
|
339 free(url); |
|
340 } |
|
341 sn->flags = flags; |
332 sn->key = dav_context_get_key(ctx, repo->default_key); |
342 sn->key = dav_context_get_key(ctx, repo->default_key); |
333 curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods); |
343 curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods); |
334 curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version); |
344 curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version); |
335 if(repo->cert) { |
345 if(repo->cert) { |
336 curl_easy_setopt(sn->handle, CURLOPT_CAPATH, repo->cert); |
346 curl_easy_setopt(sn->handle, CURLOPT_CAPATH, repo->cert); |
337 } |
347 } |
338 if(!repo->verification) { |
348 if(!repo->verification) { |
339 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYPEER, 0); |
349 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYPEER, 0); |
340 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0); |
350 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0); |
341 } |
351 } |
|
352 |
|
353 if(find_collection) { |
|
354 DavResource *col = dav_resource_new(sn, collection); |
|
355 dav_exists(col); // exec this to get the href |
|
356 // we actually don't care what the result is |
|
357 // if it doesn't exists, an error will occur later |
|
358 // and we can't handle it here |
|
359 char *newurl = util_concat_path(repo->url, util_resource_name(col->href)); |
|
360 dav_session_set_baseurl(sn, newurl); |
|
361 free(newurl); |
|
362 } |
|
363 |
342 return sn; |
364 return sn; |
343 } |
365 } |
344 |
366 |
345 static void print_allowed_cmds(SyncDirectory *dir) { |
367 static void print_allowed_cmds(SyncDirectory *dir) { |
346 fprintf(stderr, "Allowed commands: "); |
368 fprintf(stderr, "Allowed commands: "); |
425 fprintf(stderr, "Cannot load database file: %s\n", dir->database); |
447 fprintf(stderr, "Cannot load database file: %s\n", dir->database); |
426 return -1; |
448 return -1; |
427 } |
449 } |
428 remove_deleted_conflicts(dir, db); |
450 remove_deleted_conflicts(dir, db); |
429 |
451 |
430 char *new_url = NULL; |
452 DavSession *sn = create_session(ctx, repo, dir->collection); |
431 if(dir->collection) { |
|
432 new_url = util_concat_path(repo->url, dir->collection); |
|
433 } |
|
434 DavSession *sn = create_session(ctx, repo, new_url ? new_url : repo->url); |
|
435 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); |
453 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); |
436 if(new_url) { |
|
437 free(new_url); |
|
438 } |
|
439 if (cmd_getoption(a, "verbose")) { |
454 if (cmd_getoption(a, "verbose")) { |
440 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
455 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
441 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
456 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
442 } |
457 } |
443 |
458 |
1017 fprintf(stderr, "Cannot load database file: %s\n", dir->database); |
1032 fprintf(stderr, "Cannot load database file: %s\n", dir->database); |
1018 return -1; |
1033 return -1; |
1019 } |
1034 } |
1020 remove_deleted_conflicts(dir, db); |
1035 remove_deleted_conflicts(dir, db); |
1021 |
1036 |
1022 char *new_url = NULL; |
1037 DavSession *sn = create_session(ctx, repo, dir->collection); |
1023 if(dir->collection) { |
|
1024 new_url = util_concat_path(repo->url, dir->collection); |
|
1025 } |
|
1026 DavSession *sn = create_session(ctx, repo, new_url ? new_url : repo->url); |
|
1027 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); |
1038 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); |
1028 if(new_url) { |
|
1029 free(new_url); |
|
1030 } |
|
1031 if (cmd_getoption(a, "verbose")) { |
1039 if (cmd_getoption(a, "verbose")) { |
1032 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
1040 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
1033 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
1041 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
1034 } |
1042 } |
1035 |
1043 |
1362 Repository *repo = get_repository(sstr(dir->repository)); |
1370 Repository *repo = get_repository(sstr(dir->repository)); |
1363 if(!repo) { |
1371 if(!repo) { |
1364 fprintf(stderr, "Unkown repository %s\n", dir->name); |
1372 fprintf(stderr, "Unkown repository %s\n", dir->name); |
1365 return -1; |
1373 return -1; |
1366 } |
1374 } |
1367 char *new_url = NULL; |
1375 DavSession *sn = create_session(ctx, repo, dir->collection); |
1368 if(dir->collection) { |
|
1369 new_url = util_concat_path(repo->url, dir->collection); |
|
1370 } |
|
1371 DavSession *sn = create_session(ctx, repo, new_url ? new_url : repo->url); |
|
1372 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); |
1376 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); |
1373 if(new_url) { |
|
1374 free(new_url); |
|
1375 } |
|
1376 if (cmd_getoption(a, "verbose")) { |
1377 if (cmd_getoption(a, "verbose")) { |
1377 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
1378 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
1378 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
1379 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
1379 } |
1380 } |
1380 |
1381 |