2 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4 * Copyright (c) 2006, Thomas Bernard
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
33 #include "upnpreplyparse.h"
37 NameValueParserStartElt(void * d
, const char * name
, int l
)
39 struct NameValueParserData
* data
= (struct NameValueParserData
*)d
;
42 memcpy(data
->curelt
, name
, l
);
43 data
->curelt
[l
] = '\0';
45 /* store root element */
46 if(!data
->head
.lh_first
)
48 struct NameValue
* nv
;
49 nv
= malloc(sizeof(struct NameValue
)+l
+1);
50 strcpy(nv
->name
, "rootElement");
51 memcpy(nv
->value
, name
, l
);
53 LIST_INSERT_HEAD(&(data
->head
), nv
, entries
);
58 NameValueParserGetData(void * d
, const char * datas
, int l
)
60 struct NameValueParserData
* data
= (struct NameValueParserData
*)d
;
61 struct NameValue
* nv
;
64 nv
= malloc(sizeof(struct NameValue
)+l
+1);
65 strncpy(nv
->name
, data
->curelt
, 64);
67 memcpy(nv
->value
, datas
, l
);
69 LIST_INSERT_HEAD(&(data
->head
), nv
, entries
);
73 ParseNameValue(const char * buffer
, int bufsize
,
74 struct NameValueParserData
* data
, uint32_t flags
)
76 struct xmlparser parser
;
77 LIST_INIT(&(data
->head
));
78 /* init xmlparser object */
79 parser
.xmlstart
= buffer
;
80 parser
.xmlsize
= bufsize
;
82 parser
.starteltfunc
= NameValueParserStartElt
;
83 parser
.endeltfunc
= 0;
84 parser
.datafunc
= NameValueParserGetData
;
91 ClearNameValueList(struct NameValueParserData
* pdata
)
93 struct NameValue
* nv
;
94 while((nv
= pdata
->head
.lh_first
) != NULL
)
96 LIST_REMOVE(nv
, entries
);
102 GetValueFromNameValueList(struct NameValueParserData
* pdata
,
105 struct NameValue
* nv
;
107 for(nv
= pdata
->head
.lh_first
;
108 (nv
!= NULL
) && (p
== NULL
);
109 nv
= nv
->entries
.le_next
)
111 if(strcmp(nv
->name
, Name
) == 0)
117 /* debug all-in-one function
118 * do parsing then display to stdout */
121 DisplayNameValueList(char * buffer
, int bufsize
)
123 struct NameValueParserData pdata
;
124 struct NameValue
* nv
;
125 ParseNameValue(buffer
, bufsize
, &pdata
, XML_STORE_EMPTY_FL
);
126 for(nv
= pdata
.head
.lh_first
;
128 nv
= nv
->entries
.le_next
)
130 printf("%s = %s\n", nv
->name
, nv
->value
);
132 ClearNameValueList(&pdata
);