Loading...
Searching...
No Matches
apr_xml.h
Go to the documentation of this file.
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APR_XML_H
#define APR_XML_H
#include "apr_pools.h"
#include "apr_tables.h"
#include "apr_file_io.h"
#include "apu.h"
#if APR_CHARSET_EBCDIC
#include "apr_xlate.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* -------------------------------------------------------------------- */
/* ### these will need to move at some point to a more logical spot */
typedef struct apr_text apr_text;
struct apr_text {
const char *text;
struct apr_text *next;
};
typedef struct apr_text_header apr_text_header;
struct apr_text_header {
apr_text *first;
apr_text *last;
};
APU_DECLARE(void) apr_text_append(apr_pool_t *p, apr_text_header *hdr,
const char *text);
/* --------------------------------------------------------------------
**
** XML PARSING
*/
/*
** Qualified namespace values
**
** APR_XML_NS_DAV_ID
** We always insert the "DAV:" namespace URI at the head of the
** namespace array. This means that it will always be at ID==0,
** making it much easier to test for.
**
** APR_XML_NS_NONE
** This special ID is used for two situations:
**
** 1) The namespace prefix begins with "xml" (and we do not know
** what it means). Namespace prefixes with "xml" (any case) as
** their first three characters are reserved by the XML Namespaces
** specification for future use. mod_dav will pass these through
** unchanged. When this identifier is used, the prefix is LEFT in
** the element/attribute name. Downstream processing should not
** prepend another prefix.
**
** 2) The element/attribute does not have a namespace.
**
** a) No prefix was used, and a default namespace has not been
** defined.
** b) No prefix was used, and the default namespace was specified
** to mean "no namespace". This is done with a namespace
** declaration of: xmlns=""
** (this declaration is typically used to override a previous
** specification for the default namespace)
**
** In these cases, we need to record that the elem/attr has no
** namespace so that we will not attempt to prepend a prefix.
** All namespaces that are used will have a prefix assigned to
** them -- mod_dav will never set or use the default namespace
** when generating XML. This means that "no prefix" will always
** mean "no namespace".
**
** In both cases, the XML generation will avoid prepending a prefix.
** For the first case, this means the original prefix/name will be
** inserted into the output stream. For the latter case, it means
** the name will have no prefix, and since we never define a default
** namespace, this means it will have no namespace.
**
** Note: currently, mod_dav understands the "xmlns" prefix and the
** "xml:lang" attribute. These are handled specially (they aren't
** left within the XML tree), so the APR_XML_NS_NONE value won't ever
** really apply to these values.
*/
#define APR_XML_NS_DAV_ID 0
#define APR_XML_NS_NONE -10
#define APR_XML_NS_ERROR_BASE -100
#define APR_XML_NS_IS_ERROR(e) ((e) <= APR_XML_NS_ERROR_BASE)
typedef struct apr_xml_attr apr_xml_attr;
typedef struct apr_xml_elem apr_xml_elem;
typedef struct apr_xml_doc apr_xml_doc;
struct apr_xml_attr {
const char *name;
int ns;
const char *value;
struct apr_xml_attr *next;
};
struct apr_xml_elem {
const char *name;
int ns;
const char *lang;
apr_text_header first_cdata;
apr_text_header following_cdata;
struct apr_xml_elem *parent;
struct apr_xml_elem *next;
struct apr_xml_elem *first_child;
struct apr_xml_attr *attr;
/* used only during parsing */
struct apr_xml_elem *last_child;
struct apr_xml_ns_scope *ns_scope;
/* used by modules during request processing */
void *priv;
};
#define APR_XML_ELEM_IS_EMPTY(e) ((e)->first_child == NULL && \
(e)->first_cdata.first == NULL)
struct apr_xml_doc {
apr_xml_elem *root;
apr_array_header_t *namespaces;
};
typedef struct apr_xml_parser apr_xml_parser;
APU_DECLARE(apr_xml_parser *) apr_xml_parser_create(apr_pool_t *pool);
APU_DECLARE(apr_status_t) apr_xml_parse_file(apr_pool_t *p,
apr_xml_parser **parser,
apr_xml_doc **ppdoc,
apr_file_t *xmlfd,
apr_size_t buffer_length);
APU_DECLARE(apr_status_t) apr_xml_parser_feed(apr_xml_parser *parser,
const char *data,
apr_size_t len);
APU_DECLARE(apr_status_t) apr_xml_parser_done(apr_xml_parser *parser,
apr_xml_doc **pdoc);
APU_DECLARE(char *) apr_xml_parser_geterror(apr_xml_parser *parser,
char *errbuf,
apr_size_t errbufsize);
APU_DECLARE(void) apr_xml_to_text(apr_pool_t *p, const apr_xml_elem *elem,
int style, apr_array_header_t *namespaces,
int *ns_map, const char **pbuf,
apr_size_t *psize);
/* style argument values: */
#define APR_XML_X2T_FULL 0
#define APR_XML_X2T_INNER 1
#define APR_XML_X2T_LANG_INNER 2
#define APR_XML_X2T_FULL_NS_LANG 3
#define APR_XML_X2T_PARSED 4
APU_DECLARE(const char *) apr_xml_empty_elem(apr_pool_t *p,
const apr_xml_elem *elem);
APU_DECLARE(const char *) apr_xml_quote_string(apr_pool_t *p, const char *s,
int quotes);
APU_DECLARE(void) apr_xml_quote_elem(apr_pool_t *p, apr_xml_elem *elem);
/* manage an array of unique URIs: apr_xml_insert_uri() and APR_XML_URI_ITEM() */
APU_DECLARE(int) apr_xml_insert_uri(apr_array_header_t *uri_array,
const char *uri);
#define APR_XML_GET_URI_ITEM(ary, i) (((const char * const *)(ary)->elts)[i])
#if APR_CHARSET_EBCDIC
APU_DECLARE(apr_status_t) apr_xml_parser_convert_doc(apr_pool_t *p,
apr_xml_doc *pdoc,
apr_xlate_t *convset);
#endif
#ifdef __cplusplus
}
#endif
#endif /* APR_XML_H */
apr_xlate.h
APR I18N translation library.
apr_xml_parser_create
apr_xml_parser * apr_xml_parser_create(apr_pool_t *pool)
apr_xml_insert_uri
int apr_xml_insert_uri(apr_array_header_t *uri_array, const char *uri)
apr_xml_to_text
void apr_xml_to_text(apr_pool_t *p, const apr_xml_elem *elem, int style, apr_array_header_t *namespaces, int *ns_map, const char **pbuf, apr_size_t *psize)
apr_xml_parser_done
apr_status_t apr_xml_parser_done(apr_xml_parser *parser, apr_xml_doc **pdoc)
apr_xml_quote_elem
void apr_xml_quote_elem(apr_pool_t *p, apr_xml_elem *elem)
apr_xml_parser_feed
apr_status_t apr_xml_parser_feed(apr_xml_parser *parser, const char *data, apr_size_t len)
apr_xml_quote_string
const char * apr_xml_quote_string(apr_pool_t *p, const char *s, int quotes)
apr_xml_parser_geterror
char * apr_xml_parser_geterror(apr_xml_parser *parser, char *errbuf, apr_size_t errbufsize)
apr_xml_parser
struct apr_xml_parser apr_xml_parser
Definition apr_xml.h:208
apr_xml_empty_elem
const char * apr_xml_empty_elem(apr_pool_t *p, const apr_xml_elem *elem)
apr_xml_parse_file
apr_status_t apr_xml_parse_file(apr_pool_t *p, apr_xml_parser **parser, apr_xml_doc **ppdoc, apr_file_t *xmlfd, apr_size_t buffer_length)
apr_text_append
void apr_text_append(apr_pool_t *p, apr_text_header *hdr, const char *text)
apr_xlate_t
struct apr_xlate_t apr_xlate_t
Definition apr_xlate.h:39
apr_text_header
Definition apr_xml.h:64
apr_text_header::last
apr_text * last
Definition apr_xml.h:68
apr_text_header::first
apr_text * first
Definition apr_xml.h:66
apr_text
Definition apr_xml.h:53
apr_text::text
const char * text
Definition apr_xml.h:55
apr_text::next
struct apr_text * next
Definition apr_xml.h:57
apr_xml_attr
Definition apr_xml.h:148
apr_xml_attr::value
const char * value
Definition apr_xml.h:155
apr_xml_attr::name
const char * name
Definition apr_xml.h:150
apr_xml_attr::next
struct apr_xml_attr * next
Definition apr_xml.h:158
apr_xml_attr::ns
int ns
Definition apr_xml.h:152
apr_xml_doc
Definition apr_xml.h:200
apr_xml_doc::namespaces
apr_array_header_t * namespaces
Definition apr_xml.h:204
apr_xml_doc::root
apr_xml_elem * root
Definition apr_xml.h:202
apr_xml_elem
Definition apr_xml.h:162
apr_xml_elem::priv
void * priv
Definition apr_xml.h:192
apr_xml_elem::parent
struct apr_xml_elem * parent
Definition apr_xml.h:176
apr_xml_elem::name
const char * name
Definition apr_xml.h:164
apr_xml_elem::ns
int ns
Definition apr_xml.h:166
apr_xml_elem::first_child
struct apr_xml_elem * first_child
Definition apr_xml.h:180
apr_xml_elem::first_cdata
apr_text_header first_cdata
Definition apr_xml.h:171
apr_xml_elem::next
struct apr_xml_elem * next
Definition apr_xml.h:178
apr_xml_elem::following_cdata
apr_text_header following_cdata
Definition apr_xml.h:173
apr_xml_elem::lang
const char * lang
Definition apr_xml.h:168
apr_xml_elem::attr
struct apr_xml_attr * attr
Definition apr_xml.h:182
apr_xml_elem::last_child
struct apr_xml_elem * last_child
Definition apr_xml.h:186
apr_xml_elem::ns_scope
struct apr_xml_ns_scope * ns_scope
Definition apr_xml.h:188