Fri, 12 Dec 2014 15:19:38 +0100
added verbose option + encryption flag fixes
Makefile | file | annotate | diff | comparison | revisions | |
dav/main.c | file | annotate | diff | comparison | revisions | |
dav/optparser.c | file | annotate | diff | comparison | revisions | |
dav/sopt.c | file | annotate | diff | comparison | revisions | |
dav/sync.c | file | annotate | diff | comparison | revisions | |
libidav/session.c | file | annotate | diff | comparison | revisions | |
libidav/webdav.h | file | annotate | diff | comparison | revisions |
--- 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
--- 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 <libidav/utils.h> #include <libidav/crypto.h> +#include <libidav/session.h> #include "config.h" #include "main.h" @@ -50,7 +51,6 @@ // nothing } -#include <libidav/session.h> 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 <uri> specify namespace uri"); + fprintf(stderr, " -n <uri> 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;
--- 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;i<argc;i++) { @@ -56,6 +58,10 @@ cmd_args_free(a); return NULL; } + case 'v': { + ucx_map_cstr_put(a->options, "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': {
--- 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;i<argc;i++) { @@ -73,11 +75,15 @@ } */ case 'c': { - ucx_map_cstr_put(a->options, "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; } }
--- 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") ?
--- 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 {
--- 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);