diff -r ce9790523346 -r 37a512d7b8f6 src/server/webdav/webdav.c --- a/src/server/webdav/webdav.c Sun Jan 13 14:16:45 2013 +0100 +++ b/src/server/webdav/webdav.c Sat Jan 19 20:13:07 2013 +0100 @@ -64,6 +64,7 @@ int webdav_put(pblock *pb, Session *sn, Request *rq) { int length = 0; + char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars); char *ctlen = pblock_findkeyval(pb_key_content_length, rq->headers); if(ctlen) { length = atoi(ctlen); @@ -75,10 +76,15 @@ printf("PUT length: %d\n", length); - int status = 204; - if(length >= 0) { - char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars); - + int status = 201; + FILE *out = fopen(ppath, "w"); + if(out == NULL) { + fprintf(stderr, "fopen(%s, \"w\") failed\n", ppath); + protocol_status(sn, rq, 500, NULL); + return REQ_ABORTED; + } + + if(length > 0) { FILE *out = fopen(ppath, "w"); if(out == NULL) { fprintf(stderr, "fopen(%s, \"w\") failed\n", ppath); @@ -86,13 +92,13 @@ } setvbuf(out, NULL, _IONBF, 0); - size_t l = (length > 4096) ? (4096) : (length); - char *buffer = malloc(l); + size_t len = (length > 4096) ? (4096) : (length); + char *buffer = malloc(len); int r; int r2 = 0; while(r2 < length) { - r = netbuf_getbytes(sn->inbuf, buffer, l); + r = netbuf_getbytes(sn->inbuf, buffer, len); if(r == NETBUF_EOF) { break; } @@ -101,8 +107,11 @@ r2 += r; } - fclose(out); + free(buffer); + } else { + } + fclose(out); protocol_status(sn, rq, status, NULL); pblock_removekey(pb_key_content_type, rq->srvhdrs); @@ -232,7 +241,7 @@ protocol_status(sn, rq, 404, NULL); pblock_removekey(pb_key_content_type, rq->srvhdrs); pblock_nninsert("content-length", 0, rq->srvhdrs); - http_start_response(sn, rq); + //http_start_response(sn, rq); return REQ_ABORTED; } @@ -306,13 +315,13 @@ pblock_nvinsert("content-type", "text/xml", rq->srvhdrs); pblock_nninsert("content-length", davrq->out->length, rq->srvhdrs); - pblock_nvinsert("connection", "close", rq->srvhdrs); + //pblock_nvinsert("connection", "close", rq->srvhdrs); http_start_response(sn, rq); net_write(sn->csd, davrq->out->ptr, davrq->out->length); - + dav_free_propfind(davrq); return REQ_PROCEED; } @@ -408,11 +417,13 @@ pblock_nvinsert("content-type", "text/xml", rq->srvhdrs); pblock_nninsert("content-length", davrq->out->length, rq->srvhdrs); - pblock_nvinsert("connection", "close", rq->srvhdrs); + //pblock_nvinsert("connection", "close", rq->srvhdrs); http_start_response(sn, rq); net_write(sn->csd, davrq->out->ptr, davrq->out->length); + dav_free_proppatch(davrq); + return REQ_PROCEED; } @@ -485,6 +496,7 @@ DavProperty *prop, int error) { + // TODO: different errors davrq->notFoundProps = ucx_dlist_append(davrq->notFoundProps, prop); } @@ -492,14 +504,13 @@ /* WebDAV Default Backend */ +static DAVPropertyBackend dav_file_backend = { + dav_rq_propfind, + dav_rq_proppatch +}; + DAVPropertyBackend* create_property_backend() { - DAVPropertyBackend *pb = malloc(sizeof(DAVPropertyBackend)); - if(pb == NULL) { - // - } - pb->propfind = dav_rq_propfind; - pb->proppatch = dav_rq_proppatch; - return pb; + return &dav_file_backend; } void dav_rq_propfind(DAVPropertyBackend *b, PropfindRequest *rq ,char *path) { @@ -553,18 +564,19 @@ /* XmlNsMap */ -XmlNsMap* xmlnsmap_create() { +XmlNsMap* xmlnsmap_create(pool_handle_t *pool) { XmlNsMap *map = malloc(sizeof(XmlNsMap)); UcxMap *uxm = ucx_map_new(16); if(map == NULL || uxm == NULL) { return NULL; } map->map = uxm; + map->pool = pool; return map; } void xmlnsmap_free(XmlNsMap *map) { - /* TODO: implement */ + ucx_map_free(map->map); } XmlNs* xmlnsmap_put(XmlNsMap *map, char *ns) { @@ -573,7 +585,7 @@ return xmlns; } - xmlns = malloc(sizeof(XmlNs)); + xmlns = pool_malloc(map->pool, sizeof(XmlNs)); if(xmlns == NULL) { return NULL; }