Branch: Tag:

2018-03-19

2018-03-19 16:08:21 by Henrik Grubbström (Grubba) <grubba@grubba.org>

MultiStatusStatus: Support initialization from result mappings.

Also adds support for custom XML fragments (cf RFC 4918).

Preparation for fixing [WS-221].

5:   #include <config.h>   #include <module.h>   #include <module_constants.h> - constant cvs_version="$Id: prototypes.pike,v 1.288 2012/05/10 16:25:57 grubba Exp $"; + constant cvs_version="$Id$";      #ifdef DAV_DEBUG   #define DAV_WERROR(X...) werror(X)
3316:   }      //! @appears MultiStatusStatus - class MultiStatusStatus (int http_code, void|string message) + class MultiStatusStatus   {    constant is_status = 1;    -  +  int http_code; +  SimpleNode message; +  +  //! @param http_code +  //! HTTP return code. +  //! +  //! @param message +  //! Description of @[http_code]. +  protected void create(int http_code, void|string message) +  { +  this::http_code = http_code; +  if (message) { +  SimpleNode node = SimpleElementNode("DAV:responsedescription", ([])); +  node->add_child(SimpleTextNode(message||"")); +  this::message = node; +  } +  } +  +  //! @param ret +  //! Result mapping to convert into a @[MultiStatusStatus]. +  //! +  //! The mapping has often been generated by @[Roxen.http_xml_status()]. +  protected variant void create(mapping(string:mixed) ret) +  { +  if (ret->xml) { +  message = ret->xml; +  http_code = ret->error; +  return; +  } +  create(ret->error, ret->rettext); +  } +     void build_response (SimpleElementNode response_node)    {    SimpleElementNode node = SimpleElementNode("DAV:status", ([]));
3329:    node->add_child(SimpleTextNode(sprintf("HTTP/1.1 %d ", http_code)));       if (message) { -  node = SimpleElementNode ("DAV:responsedescription", ([])); -  response_node->add_child (node); -  node->add_child (SimpleTextNode (message)); +  response_node->add_child(message);    }    }   
3345:       int __hash()    { -  return http_code + (message && hash (message)); +  return http_code + (message && hash (message->render_xml()));    }       string _sprintf (int flag)
3563:    status_set[href] = MultiStatusStatus (status_code, message);    }    +  variant void add_status(string href, mapping(string:mixed) ret) +  //! Add a status for the specified url. +  //! +  //! @param href +  //! URL the status is for. +  //! +  //! @param ret +  //! Result-mapping for the URL. +  { +  status_set[href] = MultiStatusStatus(ret); +  } +     void add_namespace (string namespace)    //! Add a namespace to the generated @tt{<multistatus>@} element.    //! Useful if several properties share a namespace.