WiP
[oweals/gnunet.git] / src / nat / upnp-minixml.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2010 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /*
22  * Code in this file is originally based on the miniupnp library.
23  * Copyright (c) 2005-2008, Thomas BERNARD. All rights reserved.
24  *
25  * Original licence:
26  * 
27  * Redistribution and use in source and binary forms, with or without
28  * modification, are permitted provided that the following conditions are met:
29  * 
30  *   * Redistributions of source code must retain the above copyright notice,
31  *     this list of conditions and the following disclaimer.
32  *   * Redistributions in binary form must reproduce the above copyright notice,
33  *     this list of conditions and the following disclaimer in the documentation
34  *     and/or other materials provided with the distribution.
35  *   * The name of the author may not be used to endorse or promote products
36  *         derived from this software without specific prior written permission.
37  * 
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
39  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
42  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
43  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
44  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
45  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
46  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48  * POSSIBILITY OF SUCH DAMAGE.
49  */
50
51 /**
52  * @file nat/upnp-minixml.h
53  * @brief Simple XML parser used by UPnP
54  *
55  * @author Milan Bouchet-Valat
56  */
57
58 #ifndef MINIXML_H
59 #define MINIXML_H
60
61 #define IS_WHITE_SPACE(c) ((c==' ') || (c=='\t') || (c=='\r') || (c=='\n'))
62
63 /**
64  * Structure describing the contents and methods that should be
65  * used when running parse_xml();
66  *
67  * If a callback function pointer is set to NULL, the function
68  * is not called */
69 struct UPNP_xml_parser_
70 {
71   /**
72    * Pointer to the XML data to parse
73    */
74   const char *xml_start;
75
76   /**
77    * Pointer to the last character to parse (optional)
78    */
79   const char *xml_end;
80
81   /**
82    * Size of the data stored at xml_start
83    */
84   int xml_size;
85
86   /**
87    * Pointer to current character (private)
88    */
89   const char *xml;
90
91   /**
92    * Closure for user-provided callback functions
93    */
94   void *cls;
95
96   /**
97    * User function called when reaching the start of an XML element.
98    */
99   void (*start_elt_func) (void *cls, const char *elt, int elt_len);
100
101   /**
102    * User function called when reaching the end of an XML element.
103    */
104   void (*end_elt_func) (void *cls, const char *elt, int elt_len);
105
106   /**
107    * User function called when an XML element data is found.
108    */
109   void (*data_func) (void *cls, const char *data, int data_len);
110
111   /**
112    * User function called for every XML element attribute.
113    */
114   void (*att_func) (void *cls, const char *att_name, int att_name_len,
115                     const char *att_value, int att_value_len);
116 };
117
118 /**
119  * Parse data provided to the xml_parser structure, using
120  * user-provided functions.
121  *
122  * The xmlparser structure must be initialized before the call;
123  * the following structure members have to be set:
124  * xml_start, xml_size, cls, *func.
125  * The xml member is for internal usage, xml_end is computed
126  * automatically.
127  *
128  * @param parser the structure used for parsing */
129 void UPNP_parse_xml_ (struct UPNP_xml_parser_ *parser);
130
131 #endif