diff options
Diffstat (limited to 'src/nat/miniupnp/upnpreplyparse.c')
-rw-r--r-- | src/nat/miniupnp/upnpreplyparse.c | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/src/nat/miniupnp/upnpreplyparse.c b/src/nat/miniupnp/upnpreplyparse.c deleted file mode 100644 index 9aa895d1d..000000000 --- a/src/nat/miniupnp/upnpreplyparse.c +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | /* $Id: upnpreplyparse.c,v 1.10 2008/02/21 13:05:27 nanard Exp $ */ | ||
2 | /* MiniUPnP project | ||
3 | * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ | ||
4 | * (c) 2006 Thomas Bernard | ||
5 | * This software is subject to the conditions detailed | ||
6 | * in the LICENCE file provided within the distribution */ | ||
7 | |||
8 | #include <stdlib.h> | ||
9 | #include <string.h> | ||
10 | #include <stdio.h> | ||
11 | |||
12 | #include "upnpreplyparse.h" | ||
13 | #include "minixml.h" | ||
14 | |||
15 | static void | ||
16 | NameValueParserStartElt (void *d, const char *name, int l) | ||
17 | { | ||
18 | struct NameValueParserData *data = (struct NameValueParserData *) d; | ||
19 | if (l > 63) | ||
20 | l = 63; | ||
21 | memcpy (data->curelt, name, l); | ||
22 | data->curelt[l] = '\0'; | ||
23 | } | ||
24 | |||
25 | static void | ||
26 | NameValueParserGetData (void *d, const char *datas, int l) | ||
27 | { | ||
28 | struct NameValueParserData *data = (struct NameValueParserData *) d; | ||
29 | struct NameValue *nv; | ||
30 | nv = malloc (sizeof (struct NameValue)); | ||
31 | if (l > 63) | ||
32 | l = 63; | ||
33 | strncpy (nv->name, data->curelt, 64); | ||
34 | nv->name[63] = '\0'; | ||
35 | memcpy (nv->value, datas, l); | ||
36 | nv->value[l] = '\0'; | ||
37 | LIST_INSERT_HEAD (&(data->head), nv, entries); | ||
38 | } | ||
39 | |||
40 | void | ||
41 | ParseNameValue (const char *buffer, int bufsize, | ||
42 | struct NameValueParserData *data) | ||
43 | { | ||
44 | struct xmlparser parser; | ||
45 | LIST_INIT (&(data->head)); | ||
46 | /* init xmlparser object */ | ||
47 | parser.xmlstart = buffer; | ||
48 | parser.xmlsize = bufsize; | ||
49 | parser.data = data; | ||
50 | parser.starteltfunc = NameValueParserStartElt; | ||
51 | parser.endeltfunc = 0; | ||
52 | parser.datafunc = NameValueParserGetData; | ||
53 | parser.attfunc = 0; | ||
54 | parsexml (&parser); | ||
55 | } | ||
56 | |||
57 | void | ||
58 | ClearNameValueList (struct NameValueParserData *pdata) | ||
59 | { | ||
60 | struct NameValue *nv; | ||
61 | while ((nv = pdata->head.lh_first) != NULL) | ||
62 | { | ||
63 | LIST_REMOVE (nv, entries); | ||
64 | free (nv); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | char * | ||
69 | GetValueFromNameValueList (struct NameValueParserData *pdata, | ||
70 | const char *Name) | ||
71 | { | ||
72 | struct NameValue *nv; | ||
73 | char *p = NULL; | ||
74 | for (nv = pdata->head.lh_first; | ||
75 | (nv != NULL) && (p == NULL); nv = nv->entries.le_next) | ||
76 | { | ||
77 | if (strcmp (nv->name, Name) == 0) | ||
78 | p = nv->value; | ||
79 | } | ||
80 | return p; | ||
81 | } | ||
82 | |||
83 | #if 0 | ||
84 | /* useless now that minixml ignores namespaces by itself */ | ||
85 | char * | ||
86 | GetValueFromNameValueListIgnoreNS (struct NameValueParserData *pdata, | ||
87 | const char *Name) | ||
88 | { | ||
89 | struct NameValue *nv; | ||
90 | char *p = NULL; | ||
91 | char *pname; | ||
92 | for (nv = pdata->head.lh_first; | ||
93 | (nv != NULL) && (p == NULL); nv = nv->entries.le_next) | ||
94 | { | ||
95 | pname = strrchr (nv->name, ':'); | ||
96 | if (pname) | ||
97 | pname++; | ||
98 | else | ||
99 | pname = nv->name; | ||
100 | if (strcmp (pname, Name) == 0) | ||
101 | p = nv->value; | ||
102 | } | ||
103 | return p; | ||
104 | } | ||
105 | #endif | ||
106 | |||
107 | /* debug all-in-one function | ||
108 | * do parsing then display to stdout */ | ||
109 | #ifdef DEBUG | ||
110 | void | ||
111 | DisplayNameValueList (char *buffer, int bufsize) | ||
112 | { | ||
113 | struct NameValueParserData pdata; | ||
114 | struct NameValue *nv; | ||
115 | ParseNameValue (buffer, bufsize, &pdata); | ||
116 | for (nv = pdata.head.lh_first; nv != NULL; nv = nv->entries.le_next) | ||
117 | { | ||
118 | printf ("%s = %s\n", nv->name, nv->value); | ||
119 | } | ||
120 | ClearNameValueList (&pdata); | ||
121 | } | ||
122 | #endif | ||