Apache Portable Runtime Utility Library
apr_xml.h
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#ifndef APR_XML_H
21#define APR_XML_H
22
28#include "apr_pools.h"
29#include "apr_tables.h"
30#include "apr_file_io.h"
31
32#include "apu.h"
33#if APR_CHARSET_EBCDIC
34#include "apr_xlate.h"
35#endif
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
45/* -------------------------------------------------------------------- */
46
47/* ### these will need to move at some point to a more logical spot */
48
50typedef struct apr_text apr_text;
51
53struct apr_text {
55 const char *text;
57 struct apr_text *next;
58};
59
62
69};
70
77APU_DECLARE(void) apr_text_append(apr_pool_t *p, apr_text_header *hdr,
78 const char *text);
79
80
81/* --------------------------------------------------------------------
82**
83** XML PARSING
84*/
85
86/*
87** Qualified namespace values
88**
89** APR_XML_NS_DAV_ID
90** We always insert the "DAV:" namespace URI at the head of the
91** namespace array. This means that it will always be at ID==0,
92** making it much easier to test for.
93**
94** APR_XML_NS_NONE
95** This special ID is used for two situations:
96**
97** 1) The namespace prefix begins with "xml" (and we do not know
98** what it means). Namespace prefixes with "xml" (any case) as
99** their first three characters are reserved by the XML Namespaces
100** specification for future use. mod_dav will pass these through
101** unchanged. When this identifier is used, the prefix is LEFT in
102** the element/attribute name. Downstream processing should not
103** prepend another prefix.
104**
105** 2) The element/attribute does not have a namespace.
106**
107** a) No prefix was used, and a default namespace has not been
108** defined.
109** b) No prefix was used, and the default namespace was specified
110** to mean "no namespace". This is done with a namespace
111** declaration of: xmlns=""
112** (this declaration is typically used to override a previous
113** specification for the default namespace)
114**
115** In these cases, we need to record that the elem/attr has no
116** namespace so that we will not attempt to prepend a prefix.
117** All namespaces that are used will have a prefix assigned to
118** them -- mod_dav will never set or use the default namespace
119** when generating XML. This means that "no prefix" will always
120** mean "no namespace".
121**
122** In both cases, the XML generation will avoid prepending a prefix.
123** For the first case, this means the original prefix/name will be
124** inserted into the output stream. For the latter case, it means
125** the name will have no prefix, and since we never define a default
126** namespace, this means it will have no namespace.
127**
128** Note: currently, mod_dav understands the "xmlns" prefix and the
129** "xml:lang" attribute. These are handled specially (they aren't
130** left within the XML tree), so the APR_XML_NS_NONE value won't ever
131** really apply to these values.
132*/
133#define APR_XML_NS_DAV_ID 0
134#define APR_XML_NS_NONE -10
136#define APR_XML_NS_ERROR_BASE -100
138#define APR_XML_NS_IS_ERROR(e) ((e) <= APR_XML_NS_ERROR_BASE)
139
146
150 const char *name;
152 int ns;
153
155 const char *value;
156
159};
160
164 const char *name;
166 int ns;
168 const char *lang;
169
174
183
184 /* used only during parsing */
188 struct apr_xml_ns_scope *ns_scope;
189
190 /* used by modules during request processing */
192 void *priv;
193};
194
196#define APR_XML_ELEM_IS_EMPTY(e) ((e)->first_child == NULL && \
197 (e)->first_cdata.first == NULL)
198
204 apr_array_header_t *namespaces;
205};
206
209
215APU_DECLARE(apr_xml_parser *) apr_xml_parser_create(apr_pool_t *pool);
216
227APU_DECLARE(apr_status_t) apr_xml_parse_file(apr_pool_t *p,
228 apr_xml_parser **parser,
229 apr_xml_doc **ppdoc,
230 apr_file_t *xmlfd,
231 apr_size_t buffer_length);
232
233
242APU_DECLARE(apr_status_t) apr_xml_parser_feed(apr_xml_parser *parser,
243 const char *data,
244 apr_size_t len);
245
254APU_DECLARE(apr_status_t) apr_xml_parser_done(apr_xml_parser *parser,
255 apr_xml_doc **pdoc);
256
264APU_DECLARE(char *) apr_xml_parser_geterror(apr_xml_parser *parser,
265 char *errbuf,
266 apr_size_t errbufsize);
267
268
286APU_DECLARE(void) apr_xml_to_text(apr_pool_t *p, const apr_xml_elem *elem,
287 int style, apr_array_header_t *namespaces,
288 int *ns_map, const char **pbuf,
289 apr_size_t *psize);
290
291/* style argument values: */
292#define APR_XML_X2T_FULL 0
293#define APR_XML_X2T_INNER 1
294#define APR_XML_X2T_LANG_INNER 2
295#define APR_XML_X2T_FULL_NS_LANG 3
296#define APR_XML_X2T_PARSED 4
304APU_DECLARE(const char *) apr_xml_empty_elem(apr_pool_t *p,
305 const apr_xml_elem *elem);
306
317APU_DECLARE(const char *) apr_xml_quote_string(apr_pool_t *p, const char *s,
318 int quotes);
319
325APU_DECLARE(void) apr_xml_quote_elem(apr_pool_t *p, apr_xml_elem *elem);
326
327/* manage an array of unique URIs: apr_xml_insert_uri() and APR_XML_URI_ITEM() */
328
335APU_DECLARE(int) apr_xml_insert_uri(apr_array_header_t *uri_array,
336 const char *uri);
337
339#define APR_XML_GET_URI_ITEM(ary, i) (((const char * const *)(ary)->elts)[i])
340
341#if APR_CHARSET_EBCDIC
349APU_DECLARE(apr_status_t) apr_xml_parser_convert_doc(apr_pool_t *p,
350 apr_xml_doc *pdoc,
351 apr_xlate_t *convset);
352#endif
353
354#ifdef __cplusplus
355}
356#endif
358#endif /* APR_XML_H */
APR I18N translation library.
apr_xml_parser * apr_xml_parser_create(apr_pool_t *pool)
int apr_xml_insert_uri(apr_array_header_t *uri_array, const char *uri)
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_status_t apr_xml_parser_done(apr_xml_parser *parser, apr_xml_doc **pdoc)
void apr_xml_quote_elem(apr_pool_t *p, apr_xml_elem *elem)
apr_status_t apr_xml_parser_feed(apr_xml_parser *parser, const char *data, apr_size_t len)
const char * apr_xml_quote_string(apr_pool_t *p, const char *s, int quotes)
char * apr_xml_parser_geterror(apr_xml_parser *parser, char *errbuf, apr_size_t errbufsize)
struct apr_xml_parser apr_xml_parser
Definition: apr_xml.h:208
const char * apr_xml_empty_elem(apr_pool_t *p, const apr_xml_elem *elem)
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)
void apr_text_append(apr_pool_t *p, apr_text_header *hdr, const char *text)
struct apr_xlate_t apr_xlate_t
Definition: apr_xlate.h:39
Definition: apr_xml.h:64
apr_text * last
Definition: apr_xml.h:68
apr_text * first
Definition: apr_xml.h:66
Definition: apr_xml.h:53
const char * text
Definition: apr_xml.h:55
struct apr_text * next
Definition: apr_xml.h:57
Definition: apr_xml.h:148
const char * value
Definition: apr_xml.h:155
const char * name
Definition: apr_xml.h:150
struct apr_xml_attr * next
Definition: apr_xml.h:158
int ns
Definition: apr_xml.h:152
Definition: apr_xml.h:200
apr_array_header_t * namespaces
Definition: apr_xml.h:204
apr_xml_elem * root
Definition: apr_xml.h:202
Definition: apr_xml.h:162
void * priv
Definition: apr_xml.h:192
struct apr_xml_elem * parent
Definition: apr_xml.h:176
const char * name
Definition: apr_xml.h:164
int ns
Definition: apr_xml.h:166
struct apr_xml_elem * first_child
Definition: apr_xml.h:180
apr_text_header first_cdata
Definition: apr_xml.h:171
struct apr_xml_elem * next
Definition: apr_xml.h:178
apr_text_header following_cdata
Definition: apr_xml.h:173
const char * lang
Definition: apr_xml.h:168
struct apr_xml_attr * attr
Definition: apr_xml.h:182
struct apr_xml_elem * last_child
Definition: apr_xml.h:186
struct apr_xml_ns_scope * ns_scope
Definition: apr_xml.h:188