Branch: Tag:

2004-05-13

2004-05-13 14:22:14 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Now uses recurse_move_files().
Fixed bug in parsing of the Overwrite header.

Rev: server/modules/misc/webdav.pike:1.30

1:   // Protocol support for RFC 2518   // - // $Id: webdav.pike,v 1.29 2004/05/13 13:39:39 grubba Exp $ + // $Id: webdav.pike,v 1.30 2004/05/13 14:22:14 grubba Exp $   //   // 2003-09-17 Henrik Grubbström   
9:   #include <module.h>   #include <request_trace.h>    - constant cvs_version = "$Id: webdav.pike,v 1.29 2004/05/13 13:39:39 grubba Exp $"; + constant cvs_version = "$Id: webdav.pike,v 1.30 2004/05/13 14:22:14 grubba Exp $";   constant thread_safe = 1;   constant module_name = "DAV: Protocol support";   constant module_type = MODULE_FIRST;
48:    case "LOCK":    case "UNLOCK":    case "COPY": +  case "MOVE":    case "DELETE":    case "PROPFIND":    case "PROPPATCH":
129:    TRACE_LEAVE("Malformed XML.");    return Roxen.http_status(400, "Malformed XML data.");    } -  if (!(< "LOCK", "UNLOCK", "COPY", "DELETE", +  if (!(< "LOCK", "UNLOCK", "COPY", "MOVE", "DELETE",    "PROPFIND", "PROPPATCH">)[id->method]) {    TRACE_LEAVE("Not implemented.");    return Roxen.http_status(501, "Not implemented.");
295:    return Roxen.http_status(204, "Ok.");       case "COPY": +  case "MOVE":    if (!id->request_headers->destination) { -  TRACE_LEAVE("COPY: No destination header."); -  return Roxen.http_status(400, "COPY: Missing destination header."); +  SIMPLE_TRACE_LEAVE("%s: No destination header.", id->method); +  return Roxen.http_status(400, +  sprintf("%s: Missing destination header.", +  id->method));    }    PropertyBehavior propertybehavior = (<>); // default    if (xml_data) {
314:    SimpleNode prop_behav_node =    xml_data->get_first_element("DAV:propertybehavior", 1);    if (!prop_behav_node) { -  TRACE_LEAVE("COPY: No DAV:propertybehavior."); +  SIMPLE_TRACE_LEAVE("%s: No DAV:propertybehavior.", id->method);    return Roxen.http_status(400, "Missing DAV:propertybehavior.");    }    /* Valid children of <DAV:propertybehavior> are
337:    foreach(n->get_children(), SimpleNode href) {    if (href->get_full_name == "DAV:href") {    if (!multisetp(propertybehavior)) { -  TRACE_LEAVE("COPY: Conflicting DAV:propertybehaviour."); +  SIMPLE_TRACE_LEAVE("%s: Conflicting DAV:propertybehaviour.", +  id->method);    return Roxen.http_status(400,    "Conflicting DAV:propertybehavior.");    }    propertybehavior[href->value_of_node()] = 1;    } else if (href->mNodeType == Parser.XML.Tree.XML_TEXT) {    if (href->get_text() != "*"){ -  TRACE_LEAVE("COPY: Syntax error in DAV:keepalive."); +  SIMPLE_TRACE_LEAVE("%s: Syntax error in DAV:keepalive.", +  id->method);    return Roxen.http_status(400,    "Syntax error in DAV:keepalive.");    }    if (!multisetp(propertybehavior) || sizeof(propertybehavior)) { -  TRACE_LEAVE("COPY: Conflicting DAV:propertybehaviour."); +  SIMPLE_TRACE_LEAVE("%s: Conflicting DAV:propertybehaviour.", +  id->method);    return Roxen.http_status(400,    "Conflicting DAV:propertybehavior.");    }
366:    // included in a COPY or MOVE request then the    // resource [sic] MUST treat the request as if it has    // an overwrite header of value "T". -  !id->request_headers->overwrite || -  id->request_headers->overwrite=="T", +  (!id->request_headers->overwrite || +  id->request_headers->overwrite=="T")? +  DO_OVERWRITE:NEVER_OVERWRITE,    });       recur_func = lambda(string source, string loc, int d, RoxenModule module,
380:    }    // Convert destination to module location relative.    destination = destination[sizeof(loc)..]; -  mapping res = -  module->recurse_copy_files(source, destination, d, +  mapping(string:mixed) res; +  if (id->method == "COPY") { +  res = module->recurse_copy_files(source, destination, d,    behavior, overwrite, id); -  +  } else { +  res = module->recurse_move_files(source, destination, +  behavior, overwrite, id); +  }    if (res && ((res->error == 201) || (res->error == 204))) {    empty_result = res;    return 0;