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; }