1 /* minixml.c : the minimum size a xml parser can be ! */
3 * webpage: http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4 * Author : Thomas Bernard
6 Copyright (c) 2005-2007, Thomas BERNARD
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 * The name of the author may not be used to endorse or promote products
18 derived from this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
33 #include "upnpreplyparse.h"
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. */
38 int parseatt(struct xmlparser
* p
)
42 const char * attvalue
;
44 while(p
->xml
< p
->xmlend
)
46 if(*p
->xml
=='/' || *p
->xml
=='>')
48 if( !IS_WHITE_SPACE(*p
->xml
) )
53 while(*p
->xml
!='=' && !IS_WHITE_SPACE(*p
->xml
) )
55 attnamelen
++; p
->xml
++;
56 if(p
->xml
>= p
->xmlend
)
59 while(*(p
->xml
++) != '=')
61 if(p
->xml
>= p
->xmlend
)
64 while(IS_WHITE_SPACE(*p
->xml
))
67 if(p
->xml
>= p
->xmlend
)
71 if(sep
=='\'' || sep
=='\"')
74 if(p
->xml
>= p
->xmlend
)
80 attvaluelen
++; p
->xml
++;
81 if(p
->xml
>= p
->xmlend
)
89 while( !IS_WHITE_SPACE(*p
->xml
)
90 && *p
->xml
!= '>' && *p
->xml
!= '/')
92 attvaluelen
++; p
->xml
++;
93 if(p
->xml
>= p
->xmlend
)
97 /*printf("%.*s='%.*s'\n",
98 attnamelen, attname, attvaluelen, attvalue);*/
100 p
->attfunc(p
->data
, attname
, attnamelen
, attvalue
, attvaluelen
);
107 /* parseelt parse the xml stream and
108 * call the callback functions when needed... */
109 void parseelt(struct xmlparser
* p
)
112 const char * elementname
;
113 while(p
->xml
< (p
->xmlend
- 1))
115 if((p
->xml
)[0]=='<' && (p
->xml
)[1]!='?')
117 i
= 0; elementname
= ++p
->xml
;
118 while( !IS_WHITE_SPACE(*p
->xml
)
119 && (*p
->xml
!='>') && (*p
->xml
!='/')
123 if (p
->xml
>= p
->xmlend
)
125 /* to ignore namespace : */
129 elementname
= ++p
->xml
;
135 p
->starteltfunc(p
->data
, elementname
, i
);
141 i
= 0; data
= ++p
->xml
;
142 if (p
->xml
>= p
->xmlend
)
144 while( IS_WHITE_SPACE(*p
->xml
) )
147 if (p
->xml
>= p
->xmlend
)
153 if (p
->xml
>= p
->xmlend
)
158 if (i
> 0 || (p
->flags
& XML_STORE_EMPTY_FL
))
159 p
->datafunc(p
->data
, data
, i
);
163 else if(*p
->xml
== '/')
165 i
= 0; elementname
= ++p
->xml
;
166 if (p
->xml
>= p
->xmlend
)
168 while((*p
->xml
!= '>'))
171 if (p
->xml
>= p
->xmlend
)
175 p
->endeltfunc(p
->data
, elementname
, i
);
186 /* the parser must be initialized before calling this function */
187 void parsexml(struct xmlparser
* parser
)
189 parser
->xml
= parser
->xmlstart
;
190 parser
->xmlend
= parser
->xmlstart
+ parser
->xmlsize
;