using content-length header in dav put

Sun, 18 Oct 2015 12:46:56 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 18 Oct 2015 12:46:56 +0200
changeset 178
e137883e620f
parent 177
3c0734eeab33
child 179
802b48ae791d

using content-length header in dav put

dav/main.c file | annotate | diff | comparison | revisions
dav/main.h file | annotate | diff | comparison | revisions
libidav/resource.c file | annotate | diff | comparison | revisions
libidav/webdav.h file | annotate | diff | comparison | revisions
--- a/dav/main.c	Sun Oct 18 12:44:57 2015 +0200
+++ b/dav/main.c	Sun Oct 18 12:46:56 2015 +0200
@@ -735,7 +735,7 @@
     int ret;
     if(!strcmp(file, "-")) {
         FILE *in = stdin;
-        ret = put_file(repo, a, sn, path, "stdin", in);
+        ret = put_file(repo, a, sn, path, "stdin", in, 0);
     } else {
         ret = put_entry(repo, a, sn, path, file); 
     }
@@ -792,7 +792,7 @@
         }
         char *filename = util_resource_name(file);
         //path = util_concat_path(path, filename);
-        ret = put_file(repo, a, sn, path, filename, in);
+        ret = put_file(repo, a, sn, path, filename, in, s.st_size);
         //free(path);
         fclose(in);
     }
@@ -800,7 +800,7 @@
     return ret;
 }
 
-int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in) {
+int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len) {
     DavResource *res = dav_query(sn, "select - from %s", path);
     if(!res) {
         if(sn->error == DAV_NOT_FOUND) {
@@ -823,12 +823,15 @@
         path = newpath;
         res = dav_resource_new(sn, path);
         free(newpath);
-        int ret = put_file(repo, a, sn, res->path, NULL, in);
+        int ret = put_file(repo, a, sn, res->path, NULL, in, len);
         // TODO: free res
         return ret;
     }
     
     dav_set_content(res, in, (dav_read_func)fread);
+    if(len > 0) {
+        //dav_set_content_length(res, (size_t)len);
+    }
     
     if(dav_store(res)) {
         print_resource_error(sn, res->path);
--- a/dav/main.h	Sun Oct 18 12:44:57 2015 +0200
+++ b/dav/main.h	Sun Oct 18 12:46:56 2015 +0200
@@ -50,7 +50,7 @@
 
 int cmd_put(CmdArgs *args);
 int put_entry(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *file);
-int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in);
+int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len);
 
 int cmd_remove(CmdArgs *args);
 int cmd_mkdir(CmdArgs *args);
--- a/libidav/resource.c	Sun Oct 18 12:44:57 2015 +0200
+++ b/libidav/resource.c	Sun Oct 18 12:46:56 2015 +0200
@@ -538,6 +538,11 @@
     data->length = length;
 }
 
+void dav_set_content_length(DavResource *res, size_t length) {
+    DavResourceData *data = res->data;
+    data->length = length;
+}
+
 
 int dav_load(DavResource *res) {
     UcxBuffer *rqbuf = create_allprop_propfind_request();
--- a/libidav/webdav.h	Sun Oct 18 12:44:57 2015 +0200
+++ b/libidav/webdav.h	Sun Oct 18 12:46:56 2015 +0200
@@ -233,6 +233,7 @@
 
 void dav_set_content(DavResource *res, void *stream, dav_read_func read_func);
 void dav_set_content_data(DavResource *res, char *content, size_t length);
+void dav_set_content_length(DavResource *res, size_t length);
 
 int dav_load(DavResource *res);
 int dav_store(DavResource *res);

mercurial