# HG changeset patch # User Olaf Wintermann # Date 1401980033 -7200 # Node ID e3839719b0794b9da4d0abb02b62542fcafd1ea8 # Parent e4e23a88d4de7a8c2794cb0b3c3261989e3a7c9f added crypt command line option diff -r e4e23a88d4de -r e3839719b079 dav/main.c --- a/dav/main.c Thu Jun 05 15:39:51 2014 +0200 +++ b/dav/main.c Thu Jun 05 16:53:53 2014 +0200 @@ -59,7 +59,7 @@ initGenericErrorDefaultFunc(&fnc); ctx = dav_context_new(); load_config(ctx); - dav_add_namespace(ctx, "U", "http://www.uap-core.de/"); + //dav_add_namespace(ctx, "U", "http://www.uap-core.de/"); //test(); @@ -107,19 +107,20 @@ void print_usage(char *cmd) { fprintf(stderr, "Usage: %s command [options] arguments...\n\n", cmd); fprintf(stderr, "Commands:\n"); - fprintf(stderr, " list [-altR] [-u ] \n"); + fprintf(stderr, " list [-altpcR] [-u ] \n"); fprintf( stderr, - " get [-pR] [-o ] [-u ] \n"); - fprintf(stderr, " put [-pR] [-k ] \n"); - fprintf(stderr, " mkdir [-p] [-k ] \n"); - fprintf(stderr, " remove \n"); + " get [-pcR] [-o ] [-u ] \n"); + fprintf(stderr, " put [-pcR] [-k ] \n"); + fprintf(stderr, " mkdir [-pc] [-k ] \n"); + fprintf(stderr, " remove [-pc] \n"); fprintf(stderr, " date [url]\n"); fprintf(stderr, "\n"); fprintf(stderr, "Options:\n"); fprintf(stderr, " -k Key to use for encryption or decryption\n"); fprintf(stderr, " -p Don't encrypt or decrypt files\n"); + fprintf(stderr, " -c Enable full encryption\n"); fprintf(stderr, " -R " "Recursively do the operation for all children\n"); @@ -248,6 +249,25 @@ free(res_url); } +int set_session_config(DavSession *sn, CmdArgs *a) { + char *plain = cmd_getoption(a, "plain"); + char *crypt = cmd_getoption(a, "crypt"); + + if(plain && crypt) { + fprintf(stderr, "Error: -p and -c option set\n"); + return 1; + } + + if(plain) { + int flags = sn->flags; + dav_session_set_flags(sn, 0); + } else if(crypt) { + dav_session_set_flags(sn, DAV_SESSION_FULL_ENCRYPTION); + } + + return 0; +} + int cmd_list(CmdArgs *a) { if(a->argc != 1) { @@ -264,6 +284,10 @@ dav_session_set_flags(sn, get_repository_flags(repo)); sn->key = dav_context_get_key(ctx, repo->default_key); + if(set_session_config(sn, a)) { + return -1; + } + char *update = cmd_getoption(a, "update"); time_t t = 0; if(update) { @@ -276,7 +300,7 @@ while(ret != 0) { ls = dav_query( sn, - "get - from %s where lastmodified > %t with depth %d", + "get idav:crypto-name,idav:crypto-key from %s where lastmodified > %t with depth %d", path, t, depth); @@ -483,6 +507,10 @@ dav_session_set_flags(sn, get_repository_flags(repo)); sn->key = dav_context_get_key(ctx, repo->default_key); + if(set_session_config(sn, a)) { + return -1; + } + char *update = cmd_getoption(a, "update"); time_t t = 0; if(update) { @@ -512,13 +540,6 @@ return -1; } - // disable file decryption, if the -p option is specified - char *plain = cmd_getoption(a, "plain"); - if(plain) { - int flags = sn->flags; - dav_session_set_flags(sn, flags ^ DAV_SESSION_DECRYPT_CONTENT); - } - /* * determine the output file * use stdout if the output file is - @@ -609,12 +630,8 @@ dav_session_set_flags(sn, get_repository_flags(repo)); sn->key = dav_context_get_key(ctx, repo->default_key); - // disable file encryption if the -p option is specified - char *plain = cmd_getoption(a, "plain"); - if(plain) { - int flags = sn->flags; - dav_session_set_flags(sn, flags ^ DAV_SESSION_ENCRYPT_CONTENT); - dav_session_set_flags(sn, flags ^ DAV_SESSION_ENCRYPT_NAME); + if(set_session_config(sn, a)) { + return -1; } // override the session key if the -k option is specified @@ -754,6 +771,10 @@ dav_session_set_flags(sn, get_repository_flags(repo)); sn->key = dav_context_get_key(ctx, repo->default_key); + if(set_session_config(sn, a)) { + return -1; + } + DavResource *res = dav_resource_new(sn, path); if(!res) { fprintf(stderr, "error\n"); @@ -783,12 +804,8 @@ dav_session_set_flags(sn, get_repository_flags(repo)); sn->key = dav_context_get_key(ctx, repo->default_key); - // disable file encryption if the -p option is specified - char *plain = cmd_getoption(a, "plain"); - if(plain) { - int flags = sn->flags; - dav_session_set_flags(sn, flags ^ DAV_SESSION_ENCRYPT_CONTENT); - dav_session_set_flags(sn, flags ^ DAV_SESSION_ENCRYPT_NAME); + if(set_session_config(sn, a)) { + return -1; } // override the session key if the -k option is specified diff -r e4e23a88d4de -r e3839719b079 dav/optparser.c --- a/dav/optparser.c Thu Jun 05 15:39:51 2014 +0200 +++ b/dav/optparser.c Thu Jun 05 16:53:53 2014 +0200 @@ -74,6 +74,10 @@ ucx_map_cstr_put(a->options, "plain", ""); break; } + case 'c': { + ucx_map_cstr_put(a->options, "crypt", ""); + break; + } case 'a': { ucx_map_cstr_put(a->options, "all", ""); break; diff -r e4e23a88d4de -r e3839719b079 libidav/webdav.c --- a/libidav/webdav.c Thu Jun 05 15:39:51 2014 +0200 +++ b/libidav/webdav.c Thu Jun 05 16:53:53 2014 +0200 @@ -77,7 +77,7 @@ return NULL; } idavns->prefix = "idav"; - davns->name = DAV_NS; + idavns->name = DAV_NS; if(ucx_map_cstr_put(context->namespaces, "idav", idavns)) { free(davns); free(idavns); @@ -300,9 +300,8 @@ nsname.length--; DavProperty *dp = malloc(sizeof(DavProperty)); - sstr_t pre = sstrdup(sstrtrim(nspre)); - dp->ns = dav_get_namespace(context, pre.ptr); - free(pre.ptr); + sstr_t pre = sstrtrim(nspre); + dp->ns = dav_get_namespace_s(context, pre); dp->name = sstrdup(nsname).ptr; if(dp->ns && dp->name) { proplist = ucx_list_append(proplist, dp);