aboutsummaryrefslogtreecommitdiff
path: root/src/nat/miniupnp/minixml.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nat/miniupnp/minixml.c')
-rw-r--r--src/nat/miniupnp/minixml.c200
1 files changed, 0 insertions, 200 deletions
diff --git a/src/nat/miniupnp/minixml.c b/src/nat/miniupnp/minixml.c
deleted file mode 100644
index 094118cfa..000000000
--- a/src/nat/miniupnp/minixml.c
+++ /dev/null
@@ -1,200 +0,0 @@
1/* $Id: minixml.c,v 1.6 2007/05/15 18:14:08 nanard Exp $ */
2/* minixml.c : the minimum size a xml parser can be ! */
3/* Project : miniupnp
4 * webpage: http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
5 * Author : Thomas Bernard
6
7Copyright (c) 2005-2007, Thomas BERNARD
8All rights reserved.
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions are met:
12
13 * Redistributions of source code must retain the above copyright notice,
14 this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
18 * The name of the author may not be used to endorse or promote products
19 derived from this software without specific prior written permission.
20
21THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31POSSIBILITY OF SUCH DAMAGE.
32*/
33#include "minixml.h"
34
35/* parseatt : used to parse the argument list
36 * return 0 (false) in case of success and -1 (true) if the end
37 * of the xmlbuffer is reached. */
38int
39parseatt (struct xmlparser *p)
40{
41 const char *attname;
42 int attnamelen;
43 const char *attvalue;
44 int attvaluelen;
45 while (p->xml < p->xmlend)
46 {
47 if (*p->xml == '/' || *p->xml == '>')
48 return 0;
49 if (!IS_WHITE_SPACE (*p->xml))
50 {
51 char sep;
52 attname = p->xml;
53 attnamelen = 0;
54 while (*p->xml != '=' && !IS_WHITE_SPACE (*p->xml))
55 {
56 attnamelen++;
57 p->xml++;
58 if (p->xml >= p->xmlend)
59 return -1;
60 }
61 while (*(p->xml++) != '=')
62 {
63 if (p->xml >= p->xmlend)
64 return -1;
65 }
66 while (IS_WHITE_SPACE (*p->xml))
67 {
68 p->xml++;
69 if (p->xml >= p->xmlend)
70 return -1;
71 }
72 sep = *p->xml;
73 if (sep == '\'' || sep == '\"')
74 {
75 p->xml++;
76 if (p->xml >= p->xmlend)
77 return -1;
78 attvalue = p->xml;
79 attvaluelen = 0;
80 while (*p->xml != sep)
81 {
82 attvaluelen++;
83 p->xml++;
84 if (p->xml >= p->xmlend)
85 return -1;
86 }
87 }
88 else
89 {
90 attvalue = p->xml;
91 attvaluelen = 0;
92 while (!IS_WHITE_SPACE (*p->xml)
93 && *p->xml != '>' && *p->xml != '/')
94 {
95 attvaluelen++;
96 p->xml++;
97 if (p->xml >= p->xmlend)
98 return -1;
99 }
100 }
101 /*printf("%.*s='%.*s'\n",
102 attnamelen, attname, attvaluelen, attvalue); */
103 if (p->attfunc)
104 p->attfunc (p->data, attname, attnamelen, attvalue, attvaluelen);
105 }
106 p->xml++;
107 }
108 return -1;
109}
110
111/* parseelt parse the xml stream and
112 * call the callback functions when needed... */
113void
114parseelt (struct xmlparser *p)
115{
116 int i;
117 const char *elementname;
118 while (p->xml < (p->xmlend - 1))
119 {
120 if ((p->xml)[0] == '<' && (p->xml)[1] != '?')
121 {
122 i = 0;
123 elementname = ++p->xml;
124 while (!IS_WHITE_SPACE (*p->xml)
125 && (*p->xml != '>') && (*p->xml != '/'))
126 {
127 i++;
128 p->xml++;
129 if (p->xml >= p->xmlend)
130 return;
131 /* to ignore namespace : */
132 if (*p->xml == ':')
133 {
134 i = 0;
135 elementname = ++p->xml;
136 }
137 }
138 if (i > 0)
139 {
140 if (p->starteltfunc)
141 p->starteltfunc (p->data, elementname, i);
142 if (parseatt (p))
143 return;
144 if (*p->xml != '/')
145 {
146 const char *data;
147 i = 0;
148 data = ++p->xml;
149 if (p->xml >= p->xmlend)
150 return;
151 while (IS_WHITE_SPACE (*p->xml))
152 {
153 p->xml++;
154 if (p->xml >= p->xmlend)
155 return;
156 }
157 while (*p->xml != '<')
158 {
159 i++;
160 p->xml++;
161 if (p->xml >= p->xmlend)
162 return;
163 }
164 if (i > 0 && p->datafunc)
165 p->datafunc (p->data, data, i);
166 }
167 }
168 else if (*p->xml == '/')
169 {
170 i = 0;
171 elementname = ++p->xml;
172 if (p->xml >= p->xmlend)
173 return;
174 while ((*p->xml != '>'))
175 {
176 i++;
177 p->xml++;
178 if (p->xml >= p->xmlend)
179 return;
180 }
181 if (p->endeltfunc)
182 p->endeltfunc (p->data, elementname, i);
183 p->xml++;
184 }
185 }
186 else
187 {
188 p->xml++;
189 }
190 }
191}
192
193/* the parser must be initialized before calling this function */
194void
195parsexml (struct xmlparser *parser)
196{
197 parser->xml = parser->xmlstart;
198 parser->xmlend = parser->xmlstart + parser->xmlsize;
199 parseelt (parser);
200}