added update option for list and get

Thu, 22 Aug 2013 14:09:26 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 22 Aug 2013 14:09:26 +0200
changeset 30
9a5a7a513a96
parent 29
938957a4eea7
child 31
59cdf7b7316f

added update option for list and get

dav/davql.c file | annotate | diff | comparison | revisions
dav/main.c file | annotate | diff | comparison | revisions
dav/optparser.c file | annotate | diff | comparison | revisions
--- a/dav/davql.c	Thu Aug 22 12:45:12 2013 +0200
+++ b/dav/davql.c	Thu Aug 22 14:09:26 2013 +0200
@@ -454,7 +454,7 @@
                     }
                     int pos = stackpos-1;
                     if(stack[pos].type == DAVQOP_INTEGER) {
-                        printf("not %" PRId64 "\n", stack[pos].intval);
+                        //printf("not %" PRId64 "\n", stack[pos].intval);
                         stack[pos].intval = !stack[pos].intval;
                     } else {
                         // error
@@ -490,9 +490,9 @@
             case DAVQOP_INTEGER:
             case DAVQOP_TIME: {
                 if(op.type == DAVQOP_STRING) {
-                    printf("put on stack: '%s'\n", op.val);
+                    //printf("put on stack: '%s'\n", op.val);
                 } else {
-                    printf("put on stack[%d]: %" PRId64 "\n", stackpos, op.intval);
+                    //printf("put on stack[%d]: %" PRId64 "\n", stackpos, op.intval);
                 }
                 stack[stackpos++] = op;
                 break;
@@ -505,11 +505,11 @@
                 DavQOp value;
                 value.type = DAVQOP_STRING;
                 if(property_value) {
-                    printf("put on stack: \"%s\"\n", property_value);
+                    //printf("put on stack: \"%s\"\n", property_value);
                     value.val = property_value;
                     value.intval = strlen(property_value);
                 } else {
-                    printf("put on stack: null string\n");
+                    //printf("put on stack: null string\n");
                     value.val = NULL;
                     value.intval = 0;
                 }
@@ -522,10 +522,10 @@
                 value.type = DAVQOP_INTEGER;
                 value.val = NULL;
                 if(!sstrcmp(name, S("contentlength"))) {
-                    printf("put contentlength\n");
+                    //printf("put contentlength\n");
                     value.intval = res->contentlength;
                 } else if(!sstrcmp(name, S("lastmodified"))) {
-                    printf("put getlastmodified\n");
+                    //printf("put getlastmodified\n");
                     value.intval = res->lastmodified;
                 } else if(!sstrcmp(name, S("creationdate"))) {
                     value.intval = res->creationdate;
@@ -551,7 +551,7 @@
         return 0;
     }
     DavQOp result = stack[0];
-    printf("result: %" PRId64 "\n", result.intval);
+    //printf("result: %" PRId64 "\n", result.intval);
     return (int)result.intval;
 }
 
@@ -563,55 +563,55 @@
     switch(op) {
         case 5: {
             // <
-            printf("compare: %" PRId64 " < %" PRId64 "\n", v1, v2);
+            //printf("compare: %" PRId64 " < %" PRId64 "\n", v1, v2);
             res.intval = v1 < v2;
             break;
         }
         case 6: {
             // >
-            printf("compare: %" PRId64 " > %" PRId64 "\n", v1, v2);
+            //printf("compare: %" PRId64 " > %" PRId64 "\n", v1, v2);
             res.intval = v1 > v2;
             break;
         }
         case 7: {
             // ==
-            printf("compare: %" PRId64 " == %" PRId64 "\n", v1, v2);
+            //printf("compare: %" PRId64 " == %" PRId64 "\n", v1, v2);
             res.intval = v1 == v2;
             break;
         }
         case 8: {
             // !=
-            printf("compare: %" PRId64 " != %" PRId64 "\n", v1, v2);
+            //printf("compare: %" PRId64 " != %" PRId64 "\n", v1, v2);
             res.intval = v1 != v2;
             break;
         }
         case 9: {
             // <=
-            printf("compare: %" PRId64 " <= %" PRId64 "\n", v1, v2);
+            //printf("compare: %" PRId64 " <= %" PRId64 "\n", v1, v2);
             res.intval = v1 <= v2;
             break;
         }
         case 10: {
             // >=
-            printf("compare: %" PRId64 " >= %" PRId64 "\n", v1, v2);
+            //printf("compare: %" PRId64 " >= %" PRId64 "\n", v1, v2);
             res.intval = v1 >= v2;
             break;
         }
         case 11: {
             // and
-            printf("compare: %" PRId64 " and %" PRId64 "\n", v1, v2);
+            //printf("compare: %" PRId64 " and %" PRId64 "\n", v1, v2);
             res.intval = v1 && v2;
             break;
         }
         case 12: {
             // or
-            printf("compare: %" PRId64 " or %" PRId64 "\n", v1, v2);
+            //printf("compare: %" PRId64 " or %" PRId64 "\n", v1, v2);
             res.intval = v1 || v2;
             break;
         }
         case 13: {
             // xor
-            printf("compare: %" PRId64 " xor %" PRId64 "\n", v1, v2);
+            //printf("compare: %" PRId64 " xor %" PRId64 "\n", v1, v2);
             res.intval = v1 ^ v2;
             break;
         }
@@ -637,55 +637,55 @@
     switch(op) {
         case 5: {
             // <
-            printf("str compare: %.*s < %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
+            //printf("str compare: %.*s < %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
             res.intval = s1.length < s2.length;
             break;
         }
         case 6: {
             // >
-            printf("str compare: %.*s > %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
+            //printf("str compare: %.*s > %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
             res.intval = s1.length > s2.length;
             break;
         }
         case 7: {
             // ==
-            printf("str compare: %.*s == %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
+            //printf("str compare: %.*s == %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
             res.intval = sstrcmp(s1, s2) == 0;
             break;
         }
         case 8: {
             // !=
-            printf("str compare: %.*s != %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
+            //printf("str compare: %.*s != %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
             res.intval = sstrcmp(s1, s2) != 0;
             break;
         }
         case 9: {
             // <=
-            printf("str compare: %.*s <= %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
+            //printf("str compare: %.*s <= %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
             res.intval = s1.length <= s2.length;
             break;
         }
         case 10: {
             // >=
-            printf("str compare: %.*s >= %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
+            //printf("str compare: %.*s >= %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
             res.intval = s1.length >= s2.length;
             break;
         }
         case 11: {
             // and
-            printf("str compare: %.*s and %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
+            //printf("str compare: %.*s and %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
             res.intval = s1.ptr && s2.ptr;
             break;
         }
         case 12: {
             // or
-            printf("str compare: %.*s or %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
+            //printf("str compare: %.*s or %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
             res.intval = s1.ptr || s2.ptr;
             break;
         }
         case 13: {
             // xor
-            printf("str compare: %.*s xor %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
+            //printf("str compare: %.*s xor %.*s\n", s1.length, s1.ptr, s2.length, s2.ptr);
             res.intval = (intptr_t)s1.ptr ^ (intptr_t)s2.ptr;
             break;
         }
--- a/dav/main.c	Thu Aug 22 12:45:12 2013 +0200
+++ b/dav/main.c	Thu Aug 22 14:09:26 2013 +0200
@@ -101,8 +101,10 @@
 void print_usage(char *cmd) {
     fprintf(stderr, "Usage: %s command [options] arguments...\n\n", cmd);
     fprintf(stderr, "Commands:\n");
-    fprintf(stderr, "        list [-altR] <url>\n");
-    fprintf(stderr, "        get [-pR] [-k <key>] [-o <file>] <url>\n");
+    fprintf(stderr, "list [-altR] [-u <date>] <url>\n");
+    fprintf(
+            stderr,
+            "        get [-pR] [-k <key>] [-o <file>] [-u <date>] <url>\n");
     fprintf(stderr, "        put [-p] [-k <key>] <url> <file>\n");
     fprintf(stderr, "        mkdir <url>\n");
     fprintf(stderr, "        remove <url>\n");
@@ -116,6 +118,10 @@
             "        -R         "
             "Recursively do the operation for all children\n");
     fprintf(stderr, "        -o <file>  Write output to file\n");
+    fprintf(
+            stderr,
+            "        -u <date>  "
+            "Get resources which are modified since the specified date\n");
     fprintf(stderr, "        -a         show all files\n");
     fprintf(stderr, "        -l         print resources in long list format\n");
     fprintf(stderr, "        -t         print content type\n");
@@ -214,12 +220,31 @@
         sn = dav_session_new(ctx, base);
     }
     
+    char *update = cmd_getoption(a, "update");
+    time_t t = 0;
+    if(update) {
+        t = util_parse_lastmodified(update);
+    }
+    
     DavResource *ls;
     if(cmd_getoption(a, "recursive")) {
         printf("base: %s\n", base);
-        ls = dav_query(sn, "get U:crypto-key from /*");
+        if(update) {
+            ls = dav_query(
+                    sn,
+                    "get U:crypto-key from /* where lastmodified > %t",
+                    t);
+        } else {
+            ls = dav_query(sn, "get U:crypto-key from /*");
+        }
     } else {
-        ls = dav_query(sn, "get U:crypto-key from /");
+        if(update) {
+            ls = dav_query(
+                    sn,
+                    "get U:crypto-key from / where lastmodified > %t", t);
+        } else {
+            ls = dav_query(sn, "get U:crypto-key from /");
+        }
     }
     if(!ls) {
         print_resource_error(sn, path);
@@ -418,12 +443,35 @@
         sn = dav_session_new(ctx, root);
     }
     
+    char *update = cmd_getoption(a, "update");
+    time_t t = 0;
+    if(update) {
+        t = util_parse_lastmodified(update);
+    }
+    
     int recursive = cmd_getoption(a, "recursive") ? 1 : 0;
     DavResource *res;
+    
     if(recursive) {
-        res = dav_query(sn, "get U:crypto-key from %s*", path);
+        if(update) {
+            res = dav_query(
+                    sn,
+                    "get U:crypto-key from %s* where lastmodified > %t",
+                    path,
+                    t);
+        } else {
+            res = dav_query(sn, "get U:crypto-key from %s*", path);
+        }
     } else {
-        res = dav_query(sn, "get U:crypto-key from %s", path);
+        if(update) {
+            res = dav_query(
+                    sn,
+                    "get U:crypto-key from %s where lastmodified > %t",
+                    path,
+                    t);
+        } else {
+            res = dav_query(sn, "get U:crypto-key from %s", path);
+        }
     }
     if(!res) {
         print_resource_error(sn, path);
--- a/dav/optparser.c	Thu Aug 22 12:45:12 2013 +0200
+++ b/dav/optparser.c	Thu Aug 22 14:09:26 2013 +0200
@@ -104,6 +104,20 @@
                         }
                         break;
                     }
+                    case 'u': {
+                        if(!option) {
+                            option = "update";
+                            optchar = 'u';
+                        } else {
+                            fprintf(
+                                    stderr,
+                                    "Missing argument for option -%c\n",
+                                    optchar);
+                            cmd_args_free(a);
+                            return NULL;
+                        }
+                        break;
+                    }
                 }
             }
         } else if(option) {

mercurial