util_xml.c revision b0fb330a8581c8bfab5e523084f9f39264a52b12
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*/
/*
** DAV extension module for Apache 2.0.*
** - XML parser for the body of a request
*/
/* James Clark's Expat parser */
#include <xmlparse.h>
#include "httpd.h"
#include "http_protocol.h"
#include "http_log.h"
#include "mod_dav.h"
/* errors related to namespace processing */
#define DAV_NS_ERROR_UNKNOWN_PREFIX (DAV_NS_ERROR_BASE)
/* test for a namespace prefix that begins with [Xx][Mm][Ll] */
#define DAV_NS_IS_RESERVED(name) \
/* content for parsing */
typedef struct dav_xml_ctx {
ap_pool *p; /* the pool we allocate from */
int error; /* an error has occurred */
/* errors may be DAV_NS_ERROR_* or other errors defined here (none yet) */
} dav_xml_ctx;
/* struct for scoping namespace declarations */
typedef struct dav_xml_ns_scope {
const char *prefix; /* prefix used for this ns */
int ns; /* index into namespace table */
int emptyURI; /* the namespace URI is the empty string */
/* ### need a similar mechanism for xml:lang values */
/* return namespace table index for a given prefix */
{
/*
** Walk up the tree, looking for a namespace scope that defines this
** prefix.
*/
/*
** It is possible to set the default namespace to an
** empty URI string; this resets the default namespace
** to mean "no namespace." We just found the prefix
** refers to an empty URI, so return "no namespace."
*/
return DAV_NS_NONE;
}
}
}
}
/*
* If the prefix is empty (""), this means that a prefix was not
* just above did not locate a default namespace URI (which is stored
* has "no namespace". We have a reserved value for this.
*/
if (*prefix == '\0') {
return DAV_NS_NONE;
}
/* not found */
return DAV_NS_ERROR_UNKNOWN_PREFIX;
}
{
char *colon;
const char *quoted;
/* punt once we find an error */
return;
/* prep the element */
/* fill in the attributes (note: ends up in reverse order) */
while (*attrs) {
}
/* hook the element into the tree */
/* no current element; this also becomes the root */
}
else {
/* this element appeared within the current elem */
/* no first child either */
}
else {
/* hook onto the end of the parent's children */
}
/* this element is now the current element */
}
/* scan the attributes for namespace declarations */
attr;
/* test for xmlns:foo= form and xmlns= form */
if (*prefix == ':')
++prefix;
else if (*prefix != '\0') {
/* advance "prev" since "attr" is still present */
continue;
}
/* quote the URI before we ever start working with it */
/* build and insert the new scope */
/* remove this attribute from the element */
else
/* Note: prev will not be advanced since we just removed "attr" */
}
/* save away the language (in quoted form) */
/* remove this attribute from the element */
else
/* Note: prev will not be advanced since we just removed "attr" */
}
else {
/* advance "prev" since "attr" is still present */
}
}
/*
** If an xml:lang attribute didn't exist (lang==NULL), then copy the
** language from the parent element (if present).
**
** NOTE: dav_elem_size() *depends* upon this pointer equality.
*/
/* adjust the element's namespace */
/*
* The element is using the default namespace, which will always
* be found. Either it will be "no namespace", or a default
* namespace URI has been specified at some point.
*/
}
}
else {
*colon = '\0';
return;
}
}
/* adjust all remaining attributes' namespaces */
/*
* Attributes do NOT use the default namespace. Therefore,
* we place them into the "no namespace" category.
*/
}
}
else {
*colon = '\0';
return;
}
}
}
}
{
/* punt once we find an error */
return;
/* pop up one level */
}
{
const char *s;
/* punt once we find an error */
return;
/* no children yet. this cdata follows the start tag */
}
else {
/* child elements exist. this cdata follows the last child. */
}
}
{
int result;
{0};
return result;
if (r->remaining == 0) {
return OK;
}
/* ### we should get the encoding from Content-Encoding */
/* ### anything better to do? */
exit(1);
}
if (ap_should_client_block(r)) {
long len;
char *buffer;
char end;
int rv;
size_t total_read = 0;
/* allocate our working buffer */
/* read the body, stuffing it into the parser */
total_read += len;
"XML request body is larger than the configured "
"limit of %lu", (unsigned long)limit_xml_body);
goto read_error;
}
if (rv == 0)
goto parser_error;
}
if (len == -1) {
/* ap_get_client_block() has logged an error */
goto read_error;
}
/* tell the parser that we're done */
if (rv == 0)
goto parser_error;
}
"An undefined namespace prefix was used.");
break;
default:
"There was an error within the XML request body.");
break;
}
/* Apache will supply a default error, plus the error log above. */
return HTTP_BAD_REQUEST;
}
/* ### assert: ctx.cur_elem == NULL */
return OK;
{
/* ### fix this error message (default vs special) */
"XML parser error code: %s (%d).",
/* Apache will supply a default error, plus the error log above. */
return HTTP_BAD_REQUEST;
}
/* Apache will supply a default error, plus whatever was logged. */
return HTTP_BAD_REQUEST;
}