From 6c160ec7d9c7bd39313ef432516bdf94095f079c Mon Sep 17 00:00:00 2001 From: Jan Kneschke Date: Fri, 19 Aug 2005 14:40:19 +0000 Subject: [PATCH] added PUT, all basic litmus tests passed git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@589 152afb58-edef-0310-8abb-c4023f1b3aa9 --- doc/webdav.txt | 3 ++- src/mod_webdav.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/doc/webdav.txt b/doc/webdav.txt index 04405a19..175f33f4 100644 --- a/doc/webdav.txt +++ b/doc/webdav.txt @@ -30,11 +30,12 @@ So far we have * OPTIONS * MKCOL * DELETE + * PUT and the usual GET, POST, HEAD from HTTP/1.1. So far mounting a webdav resource into Windows XP works and the basic litmus -tests are passed (excluding PUT as it is not implemented). +tests are passed. Options ======= diff --git a/src/mod_webdav.c b/src/mod_webdav.c index ce617583..1ed02f2b 100644 --- a/src/mod_webdav.c +++ b/src/mod_webdav.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "base.h" #include "log.h" @@ -426,7 +427,10 @@ URIHANDLER_FUNC(mod_webdav_subrequest_handler) { return HANDLER_FINISHED; case HTTP_METHOD_MKCOL: - if (p->conf.is_readonly) break; + if (p->conf.is_readonly) { + con->http_status = 403; + return HANDLER_FINISHED; + } if (con->request.content_length != 0) { /* we don't support MKCOL with a body */ @@ -457,8 +461,11 @@ URIHANDLER_FUNC(mod_webdav_subrequest_handler) { return HANDLER_FINISHED; case HTTP_METHOD_DELETE: - if (p->conf.is_readonly) break; - + if (p->conf.is_readonly) { + con->http_status = 403; + return HANDLER_FINISHED; + } + /* stat and unlink afterwards */ if (-1 == stat(con->physical.path->ptr, &st)) { /* don't about it yet, unlink will fail too */ @@ -523,6 +530,36 @@ URIHANDLER_FUNC(mod_webdav_subrequest_handler) { con->http_status = 204; } return HANDLER_FINISHED; + case HTTP_METHOD_PUT: { + int fd; + + if (p->conf.is_readonly) { + con->http_status = 403; + return HANDLER_FINISHED; + } + + /* taken what we have in the request-body and write it to a file */ + if (-1 == (fd = open(con->physical.path->ptr, O_WRONLY|O_CREAT|O_TRUNC, 0600))) { + /* we can't open the file */ + con->http_status = 403; + } else { + con->http_status = 201; /* created */ + + if (-1 == (write(fd, con->request.content->ptr, con->request.content->used - 1))) { + switch(errno) { + case ENOSPC: + con->http_status = 507; + + break; + default: + con->http_status = 403; + break; + } + } + close(fd); + } + return HANDLER_FINISHED; + } default: break; }