# HG changeset patch # User Mike Becker # Date 1418393978 -3600 # Node ID f6d3db6113d3151ba111717e8c3e8ba7a1f86e80 # Parent 6b0c606596524ef01f535858d1f93812977ae5ce added verbose option + encryption flag fixes diff -r 6b0c60659652 -r f6d3db6113d3 Makefile --- a/Makefile Fri Dec 12 13:57:41 2014 +0100 +++ b/Makefile Fri Dec 12 15:19:38 2014 +0100 @@ -39,11 +39,15 @@ include $(CONF).mk -all: build ucx libidav dav +all: build/tool build/ucx build/libidav ucx libidav dav -build: +build/tool: mkdir -p build/tool + +build/ucx: mkdir -p build/ucx + +build/libidav: mkdir -p build/libidav ucx: FORCE diff -r 6b0c60659652 -r f6d3db6113d3 dav/main.c --- a/dav/main.c Fri Dec 12 13:57:41 2014 +0100 +++ b/dav/main.c Fri Dec 12 15:19:38 2014 +0100 @@ -41,6 +41,7 @@ #include #include +#include #include "config.h" #include "main.h" @@ -50,7 +51,6 @@ // nothing } -#include void test() { } @@ -143,7 +143,8 @@ fprintf(stderr, " -a show all files\n"); fprintf(stderr, " -l print resources in long list format\n"); fprintf(stderr, " -t print content type\n"); - fprintf(stderr, " -n specify namespace uri"); + fprintf(stderr, " -n specify namespace uri\n"); + fprintf(stderr, " -v verbose output\n"); fprintf(stderr, "\n"); fprintf(stderr, "Instead of an url you can pass a repository name " @@ -270,16 +271,27 @@ return 1; } - if(plain) { - int flags = sn->flags; - dav_session_set_flags(sn, 0); + if (plain) { + sn->flags &= ~DAV_SESSION_FULL_ENCRYPTION; } else if(crypt) { - dav_session_set_flags(sn, DAV_SESSION_FULL_ENCRYPTION); + sn->flags |= DAV_SESSION_FULL_ENCRYPTION; + } + + if (cmd_getoption(a, "verbose")) { + curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); } return 0; } +static DavSession* connect_to_repo(Repository *repo) { + DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); + sn->flags = get_repository_flags(repo); + sn->key = dav_context_get_key(ctx, repo->default_key); + + return sn; +} int cmd_list(CmdArgs *a) { if(a->argc != 1) { @@ -289,12 +301,8 @@ char *url = a->argv[0]; char *path = NULL; - //char *base = NULL; Repository *repo = url2repo(url, &path); - //base = util_concat_path(repo->url, path); - DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); - dav_session_set_flags(sn, get_repository_flags(repo)); - sn->key = dav_context_get_key(ctx, repo->default_key); + DavSession *sn = connect_to_repo(repo); if(set_session_config(sn, a)) { return -1; @@ -515,9 +523,7 @@ char *url = a->argv[0]; char *path = NULL; Repository *repo = url2repo(url, &path); - DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); - dav_session_set_flags(sn, get_repository_flags(repo)); - sn->key = dav_context_get_key(ctx, repo->default_key); + DavSession *sn = connect_to_repo(repo); if(set_session_config(sn, a)) { return -1; @@ -638,9 +644,7 @@ char *file = a->argv[1]; char *path = NULL; Repository *repo = url2repo(url, &path); - DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); - dav_session_set_flags(sn, get_repository_flags(repo)); - sn->key = dav_context_get_key(ctx, repo->default_key); + DavSession *sn = connect_to_repo(repo); if(set_session_config(sn, a)) { return -1; @@ -777,10 +781,7 @@ char *url = a->argv[0]; char *path = NULL; - Repository *repo = url2repo(url, &path); - DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); - dav_session_set_flags(sn, get_repository_flags(repo)); - sn->key = dav_context_get_key(ctx, repo->default_key); + DavSession *sn = connect_to_repo(url2repo(url, &path)); if(set_session_config(sn, a)) { return -1; @@ -810,10 +811,7 @@ char *url = a->argv[0]; char *path = NULL; - Repository *repo = url2repo(url, &path); - DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); - dav_session_set_flags(sn, get_repository_flags(repo)); - sn->key = dav_context_get_key(ctx, repo->default_key); + DavSession *sn = connect_to_repo(url2repo(url, &path)); if(set_session_config(sn, a)) { return -1; @@ -873,10 +871,7 @@ } else if (a->argc == 1) { char *url = a->argv[0]; char *path = NULL; - Repository *repo = url2repo(url, &path); - DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); - dav_session_set_flags(sn, get_repository_flags(repo)); - sn->key = dav_context_get_key(ctx, repo->default_key); + DavSession *sn = connect_to_repo(url2repo(url, &path)); DavResource *res = dav_resource_new(sn, path); char *date = NULL; @@ -903,10 +898,7 @@ char *url = a->argv[0]; char *path = NULL; - Repository *repo = url2repo(url, &path); - DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); - dav_session_set_flags(sn, get_repository_flags(repo)); - sn->key = dav_context_get_key(ctx, repo->default_key); + DavSession *sn = connect_to_repo(url2repo(url, &path)); if(set_session_config(sn, a)) { return -1; @@ -949,10 +941,7 @@ char *url = a->argv[0]; char *path = NULL; - Repository *repo = url2repo(url, &path); - DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); - dav_session_set_flags(sn, get_repository_flags(repo)); - sn->key = dav_context_get_key(ctx, repo->default_key); + DavSession *sn = connect_to_repo(url2repo(url, &path)); if(set_session_config(sn, a)) { return -1; diff -r 6b0c60659652 -r f6d3db6113d3 dav/optparser.c --- a/dav/optparser.c Fri Dec 12 13:57:41 2014 +0100 +++ b/dav/optparser.c Fri Dec 12 15:19:38 2014 +0100 @@ -43,6 +43,8 @@ a->argv = calloc(argc, sizeof(char*)); a->argc = 0; + const char *NOARG = ""; + char *option = NULL; char optchar = 0; for(int i=0;ioptions, "verbose", NOARG); + break; + } case 'k': { if(!option) { option = "key"; @@ -71,27 +77,27 @@ break; } case 'p': { - ucx_map_cstr_put(a->options, "plain", ""); + ucx_map_cstr_put(a->options, "plain", NOARG); break; } case 'c': { - ucx_map_cstr_put(a->options, "crypt", ""); + ucx_map_cstr_put(a->options, "crypt", NOARG); break; } case 'a': { - ucx_map_cstr_put(a->options, "all", ""); + ucx_map_cstr_put(a->options, "all", NOARG); break; } case 'l': { - ucx_map_cstr_put(a->options, "list", ""); + ucx_map_cstr_put(a->options, "list", NOARG); break; } case 't': { - ucx_map_cstr_put(a->options, "type", ""); + ucx_map_cstr_put(a->options, "type", NOARG); break; } case 'R': { - ucx_map_cstr_put(a->options, "recursive", ""); + ucx_map_cstr_put(a->options, "recursive", NOARG); break; } case 'o': { diff -r 6b0c60659652 -r f6d3db6113d3 dav/sopt.c --- a/dav/sopt.c Fri Dec 12 13:57:41 2014 +0100 +++ b/dav/sopt.c Fri Dec 12 15:19:38 2014 +0100 @@ -43,6 +43,8 @@ a->argv = calloc(argc, sizeof(char*)); a->argc = 0; + const char *NOARG = ""; + char *option = NULL; char optchar = 0; for(int i=0;ioptions, "conflict", ""); + ucx_map_cstr_put(a->options, "conflict", NOARG); break; } case 'r': { - ucx_map_cstr_put(a->options, "read", ""); + ucx_map_cstr_put(a->options, "read", NOARG); + break; + } + case 'v': { + ucx_map_cstr_put(a->options, "verbose", NOARG); break; } } diff -r 6b0c60659652 -r f6d3db6113d3 dav/sync.c --- a/dav/sync.c Fri Dec 12 13:57:41 2014 +0100 +++ b/dav/sync.c Fri Dec 12 15:19:38 2014 +0100 @@ -161,6 +161,7 @@ if(dir->collection) { new_url = util_concat_path(repo->url, dir->collection); } + // TODO: session creator function DavSession *sn = dav_session_new_auth( ctx, new_url ? new_url : repo->url, @@ -169,8 +170,12 @@ if(new_url) { free(new_url); } - dav_session_set_flags(sn, get_repository_flags(repo)); + sn->flags = get_repository_flags(repo); sn->key = dav_context_get_key(ctx, repo->default_key); + if (cmd_getoption(a, "verbose")) { + curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); + } DavResource *ls = dav_query(sn, "get D:getetag from / where lastmodified > 0 with depth -1"); if(!ls) { @@ -460,6 +465,7 @@ if(dir->collection) { new_url = util_concat_path(repo->url, dir->collection); } + // TODO: session creator function DavSession *sn = dav_session_new_auth( ctx, new_url ? new_url : repo->url, @@ -468,8 +474,12 @@ if(new_url) { free(new_url); } - dav_session_set_flags(sn, get_repository_flags(repo)); + sn->flags = get_repository_flags(repo); sn->key = dav_context_get_key(ctx, repo->default_key); + if (cmd_getoption(a, "verbose")) { + curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); + } // upload all changed files UcxList *resources = cmd_getoption(a, "read") ? diff -r 6b0c60659652 -r f6d3db6113d3 libidav/session.c --- a/libidav/session.c Fri Dec 12 13:57:41 2014 +0100 +++ b/libidav/session.c Fri Dec 12 15:19:38 2014 +0100 @@ -63,10 +63,7 @@ url_str[url.length + 1] = '\0'; sn->base_url = url_str; } - sn->context = context; sn->handle = curl_easy_init(); - //curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); - //curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); curl_easy_setopt(sn->handle, CURLOPT_FOLLOWLOCATION, 1L); // set proxy @@ -94,7 +91,9 @@ // set url curl_easy_setopt(sn->handle, CURLOPT_URL, base_url); + // add to context context->sessions = ucx_list_append(context->sessions, sn); + sn->context = context; return sn; } @@ -125,16 +124,9 @@ } } -void dav_session_set_flags(DavSession *sn, uint32_t flags) { - sn->flags = flags; -} - -uint32_t dav_session_get_flags(DavSession *sn) { - return sn->flags; -} - void dav_session_enable_encryption(DavSession *sn, DavKey *key, int flags) { sn->key = key; + // TODO: review sanity if(flags != 0) { sn->flags |= flags; } else { diff -r 6b0c60659652 -r f6d3db6113d3 libidav/webdav.h --- a/libidav/webdav.h Fri Dec 12 13:57:41 2014 +0100 +++ b/libidav/webdav.h Fri Dec 12 15:19:38 2014 +0100 @@ -72,7 +72,7 @@ #define DAV_SESSION_DECRYPT_CONTENT 0x0004 #define DAV_SESSION_DECRYPT_NAME 0x0008 -#define DAV_SESSION_CONTENT_ENCRYPTION 0x000a +#define DAV_SESSION_CONTENT_ENCRYPTION 0x0005 #define DAV_SESSION_FULL_ENCRYPTION 0x000f @@ -160,8 +160,6 @@ char *user, char *password); void dav_session_set_auth(DavSession *sn, char *user, char *password); -void dav_session_set_flags(DavSession *sn, uint32_t flags); -uint32_t dav_session_get_flags(DavSession *sn); void dav_session_enable_encryption(DavSession *sn, DavKey *key, int flags); void dav_session_destroy(DavSession *sn);