added noinput option to dav

Tue, 15 Mar 2016 16:47:22 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 15 Mar 2016 16:47:22 +0100
changeset 212
01e80c7cfe96
parent 211
3d12817414e9
child 213
cd870d5f8659

added noinput option to dav

the option disables authentication and key input

dav/main.c file | annotate | diff | comparison | revisions
dav/main.h file | annotate | diff | comparison | revisions
dav/optparser.c file | annotate | diff | comparison | revisions
--- a/dav/main.c	Tue Mar 15 11:21:30 2016 +0100
+++ b/dav/main.c	Tue Mar 15 16:47:22 2016 +0100
@@ -69,7 +69,6 @@
     xmlGenericErrorFunc fnc = xmlerrorfnc;
     initGenericErrorDefaultFunc(&fnc);
     ctx = dav_context_new();
-    ctx->key_input = util_key_input;
     load_config(ctx);
     printxmlerror = 0;
 #ifdef DO_THE_TEST
@@ -94,6 +93,12 @@
         return -1;
     }
     
+    if(cmd_getoption(args, "noinput")) {
+        ctx->key_input = NULL;
+    } else {
+        ctx->key_input = util_key_input;
+    }
+    
     int ret = -1;
     if(!strcasecmp(cmd, "list") || !strcasecmp(cmd, "ls")) {
         ret = cmd_list(args);
@@ -204,7 +209,11 @@
     fprintf(stderr, "\n");
 }
 
-int request_auth(Repository *repo, DavSession *sn) {
+int request_auth(Repository *repo, DavSession *sn, CmdArgs *a) {
+    if(cmd_getoption(a, "noinput")) {
+        return 0;
+    }
+    
     static int login = 0;
     if(login) {
         return 0;
@@ -366,7 +375,7 @@
         
         if(!ls) {
             if(sn->error == DAV_UNAUTHORIZED) {
-                if(request_auth(repo, sn)) {
+                if(request_auth(repo, sn, a)) {
                     continue;
                 }
             }
@@ -601,7 +610,7 @@
                 depth,
                 t);
         if(!res && sn->error == DAV_UNAUTHORIZED) {
-            if(request_auth(repo, sn)) {
+            if(request_auth(repo, sn, a)) {
                 continue;
             }
         }
@@ -803,7 +812,7 @@
     for(int i=0;i<2;i++) {
         res = dav_query(sn, "select - from %s", path);
         if(!res && sn->error == DAV_UNAUTHORIZED) {
-            if(request_auth(repo, sn)) {
+            if(request_auth(repo, sn, a)) {
                 continue;
             }
         }
@@ -875,7 +884,7 @@
     int err = 0;
     for(int i=0;i<2;i++) {
         err = dav_delete(res);
-        if(err && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn)) {
+        if(err && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn, a)) {
             continue;
         } else {
             break;
@@ -932,7 +941,7 @@
     int err = 0;
     for(int i=0;i<2;i++) {
         err = dav_create(res);
-        if(err && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn)) {
+        if(err && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn, a)) {
             continue;
         } else {
             break;
--- a/dav/main.h	Tue Mar 15 11:21:30 2016 +0100
+++ b/dav/main.h	Tue Mar 15 16:47:22 2016 +0100
@@ -41,7 +41,7 @@
 
 void print_usage(char *cmd);
 char* password_input(char *prompt);
-int request_auth(Repository *repo, DavSession *sn);
+int request_auth(Repository *repo, DavSession *sn, CmdArgs *args);
 
 int cmd_list(CmdArgs *args);
 void ls_print_list_elm(DavResource *res, CmdArgs *args);
--- a/dav/optparser.c	Tue Mar 15 11:21:30 2016 +0100
+++ b/dav/optparser.c	Tue Mar 15 16:47:22 2016 +0100
@@ -109,6 +109,10 @@
                         ucx_map_cstr_put(a->options, "insecure", NOARG);
                         break;
                     }
+                    case 'x': {
+                        ucx_map_cstr_put(a->options, "noinput", NOARG);
+                        break;
+                    }
                     case 'o': {
                         if(!option) {
                             option = "output";

mercurial