00001 /* ==================================================================== 00002 * The Apache Software License, Version 1.1 00003 * 00004 * Copyright (c) 2000-2003 The Apache Software Foundation. All rights 00005 * reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * 1. Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 00014 * 2. Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in 00016 * the documentation and/or other materials provided with the 00017 * distribution. 00018 * 00019 * 3. The end-user documentation included with the redistribution, 00020 * if any, must include the following acknowledgment: 00021 * "This product includes software developed by the 00022 * Apache Software Foundation (http://www.apache.org/)." 00023 * Alternately, this acknowledgment may appear in the software itself, 00024 * if and wherever such third-party acknowledgments normally appear. 00025 * 00026 * 4. The names "Apache" and "Apache Software Foundation" must 00027 * not be used to endorse or promote products derived from this 00028 * software without prior written permission. For written 00029 * permission, please contact apache@apache.org. 00030 * 00031 * 5. Products derived from this software may not be called "Apache", 00032 * nor may "Apache" appear in their name, without prior written 00033 * permission of the Apache Software Foundation. 00034 * 00035 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00036 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00037 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00038 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 00039 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00040 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00041 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00042 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00043 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00044 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00045 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00046 * SUCH DAMAGE. 00047 * ==================================================================== 00048 * 00049 * This software consists of voluntary contributions made by many 00050 * individuals on behalf of the Apache Software Foundation. For more 00051 * information on the Apache Software Foundation, please see 00052 * <http://www.apache.org/>. 00053 */ 00058 #ifndef APR_XML_H 00059 #define APR_XML_H 00060 00066 #include "apr_pools.h" 00067 #include "apr_tables.h" 00068 #include "apr_file_io.h" 00069 00070 #include "apu.h" 00071 00072 #ifdef __cplusplus 00073 extern "C" { 00074 #endif 00075 00080 /* -------------------------------------------------------------------- */ 00081 00082 /* ### these will need to move at some point to a more logical spot */ 00083 00085 typedef struct apr_text apr_text; 00086 00088 struct apr_text { 00090 const char *text; 00092 struct apr_text *next; 00093 }; 00094 00096 typedef struct apr_text_header apr_text_header; 00097 00099 struct apr_text_header { 00101 apr_text *first; 00103 apr_text *last; 00104 }; 00105 00112 APU_DECLARE(void) apr_text_append(apr_pool_t *p, apr_text_header *hdr, 00113 const char *text); 00114 00115 00116 /* -------------------------------------------------------------------- 00117 ** 00118 ** XML PARSING 00119 */ 00120 00121 /* 00122 ** Qualified namespace values 00123 ** 00124 ** APR_XML_NS_DAV_ID 00125 ** We always insert the "DAV:" namespace URI at the head of the 00126 ** namespace array. This means that it will always be at ID==0, 00127 ** making it much easier to test for. 00128 ** 00129 ** APR_XML_NS_NONE 00130 ** This special ID is used for two situations: 00131 ** 00132 ** 1) The namespace prefix begins with "xml" (and we do not know 00133 ** what it means). Namespace prefixes with "xml" (any case) as 00134 ** their first three characters are reserved by the XML Namespaces 00135 ** specification for future use. mod_dav will pass these through 00136 ** unchanged. When this identifier is used, the prefix is LEFT in 00137 ** the element/attribute name. Downstream processing should not 00138 ** prepend another prefix. 00139 ** 00140 ** 2) The element/attribute does not have a namespace. 00141 ** 00142 ** a) No prefix was used, and a default namespace has not been 00143 ** defined. 00144 ** b) No prefix was used, and the default namespace was specified 00145 ** to mean "no namespace". This is done with a namespace 00146 ** declaration of: xmlns="" 00147 ** (this declaration is typically used to override a previous 00148 ** specification for the default namespace) 00149 ** 00150 ** In these cases, we need to record that the elem/attr has no 00151 ** namespace so that we will not attempt to prepend a prefix. 00152 ** All namespaces that are used will have a prefix assigned to 00153 ** them -- mod_dav will never set or use the default namespace 00154 ** when generating XML. This means that "no prefix" will always 00155 ** mean "no namespace". 00156 ** 00157 ** In both cases, the XML generation will avoid prepending a prefix. 00158 ** For the first case, this means the original prefix/name will be 00159 ** inserted into the output stream. For the latter case, it means 00160 ** the name will have no prefix, and since we never define a default 00161 ** namespace, this means it will have no namespace. 00162 ** 00163 ** Note: currently, mod_dav understands the "xmlns" prefix and the 00164 ** "xml:lang" attribute. These are handled specially (they aren't 00165 ** left within the XML tree), so the APR_XML_NS_NONE value won't ever 00166 ** really apply to these values. 00167 */ 00168 #define APR_XML_NS_DAV_ID 0 00169 #define APR_XML_NS_NONE -10 00171 #define APR_XML_NS_ERROR_BASE -100 00173 #define APR_XML_NS_IS_ERROR(e) ((e) <= APR_XML_NS_ERROR_BASE) 00174 00176 typedef struct apr_xml_attr apr_xml_attr; 00178 typedef struct apr_xml_elem apr_xml_elem; 00180 typedef struct apr_xml_doc apr_xml_doc; 00181 00183 struct apr_xml_attr { 00185 const char *name; 00187 int ns; 00188 00190 const char *value; 00191 00193 struct apr_xml_attr *next; 00194 }; 00195 00197 struct apr_xml_elem { 00199 const char *name; 00201 int ns; 00203 const char *lang; 00204 00206 apr_text_header first_cdata; 00208 apr_text_header following_cdata; 00209 00211 struct apr_xml_elem *parent; 00213 struct apr_xml_elem *next; 00215 struct apr_xml_elem *first_child; 00217 struct apr_xml_attr *attr; 00218 00219 /* used only during parsing */ 00221 struct apr_xml_elem *last_child; 00223 struct apr_xml_ns_scope *ns_scope; 00224 00225 /* used by modules during request processing */ 00227 void *priv; 00228 }; 00229 00231 #define APR_XML_ELEM_IS_EMPTY(e) ((e)->first_child == NULL && \ 00232 (e)->first_cdata.first == NULL) 00233 00235 struct apr_xml_doc { 00237 apr_xml_elem *root; 00239 apr_array_header_t *namespaces; 00240 }; 00241 00243 typedef struct apr_xml_parser apr_xml_parser; 00244 00250 APU_DECLARE(apr_xml_parser *) apr_xml_parser_create(apr_pool_t *pool); 00251 00262 APU_DECLARE(apr_status_t) apr_xml_parse_file(apr_pool_t *p, 00263 apr_xml_parser **parser, 00264 apr_xml_doc **ppdoc, 00265 apr_file_t *xmlfd, 00266 apr_size_t buffer_length); 00267 00268 00277 APU_DECLARE(apr_status_t) apr_xml_parser_feed(apr_xml_parser *parser, 00278 const char *data, 00279 apr_size_t len); 00280 00289 APU_DECLARE(apr_status_t) apr_xml_parser_done(apr_xml_parser *parser, 00290 apr_xml_doc **pdoc); 00291 00299 APU_DECLARE(char *) apr_xml_parser_geterror(apr_xml_parser *parser, 00300 char *errbuf, 00301 apr_size_t errbufsize); 00302 00303 00320 APU_DECLARE(void) apr_xml_to_text(apr_pool_t *p, const apr_xml_elem *elem, 00321 int style, apr_array_header_t *namespaces, 00322 int *ns_map, const char **pbuf, 00323 apr_size_t *psize); 00324 00325 /* style argument values: */ 00326 #define APR_XML_X2T_FULL 0 00327 #define APR_XML_X2T_INNER 1 00328 #define APR_XML_X2T_LANG_INNER 2 00329 #define APR_XML_X2T_FULL_NS_LANG 3 00337 APU_DECLARE(const char *) apr_xml_empty_elem(apr_pool_t *p, 00338 const apr_xml_elem *elem); 00339 00350 APU_DECLARE(const char *) apr_xml_quote_string(apr_pool_t *p, const char *s, 00351 int quotes); 00352 00358 APU_DECLARE(void) apr_xml_quote_elem(apr_pool_t *p, apr_xml_elem *elem); 00359 00360 /* manage an array of unique URIs: apr_xml_insert_uri() and APR_XML_URI_ITEM() */ 00361 00368 APU_DECLARE(int) apr_xml_insert_uri(apr_array_header_t *uri_array, 00369 const char *uri); 00370 00372 #define APR_XML_GET_URI_ITEM(ary, i) (((const char * const *)(ary)->elts)[i]) 00373 00374 #ifdef __cplusplus 00375 } 00376 #endif 00377 00378 #endif /* APR_XML_H */