ASR_BASE

Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/package/kernel/realtek-wl/src/Users/mini_upnp/minixml.c b/package/kernel/realtek-wl/src/Users/mini_upnp/minixml.c
new file mode 100644
index 0000000..97ed879
--- /dev/null
+++ b/package/kernel/realtek-wl/src/Users/mini_upnp/minixml.c
@@ -0,0 +1,160 @@
+

+#include "minixml.h"

+

+/* parseatt : used to parse the argument list

+ * return 0 (false) in case of success and -1 (true) if the end

+ * of the xmlbuffer is reached. */

+int parseatt(struct xmlparser * p)

+{

+	const char * attname;

+	int attnamelen;

+	const char * attvalue;

+	int attvaluelen;

+	while(p->xml < p->xmlend)

+	{

+		if(*p->xml=='/' || *p->xml=='>')

+			return 0;

+		if( !IS_WHITE_SPACE(*p->xml) )

+		{

+			char sep;

+			attname = p->xml;

+			attnamelen = 0;

+			while(*p->xml!='=' && !IS_WHITE_SPACE(*p->xml) )

+			{

+				attnamelen++; p->xml++;

+				if(p->xml >= p->xmlend)

+					return -1;

+			}

+			while(*(p->xml++) != '=')

+			{

+				if(p->xml >= p->xmlend)

+					return -1;

+			}

+			while(IS_WHITE_SPACE(*p->xml))

+			{

+				p->xml++;

+				if(p->xml >= p->xmlend)

+					return -1;

+			}

+			sep = *p->xml;

+			if(sep=='\'' || sep=='\"')

+			{

+				p->xml++;

+				if(p->xml >= p->xmlend)

+					return -1;

+				attvalue = p->xml;

+				attvaluelen = 0;

+				while(*p->xml != sep)

+				{

+					attvaluelen++; p->xml++;

+					if(p->xml >= p->xmlend)

+						return -1;

+				}

+			}

+			else

+			{

+				attvalue = p->xml;

+				attvaluelen = 0;

+				while(   !IS_WHITE_SPACE(*p->xml)

+					  && *p->xml != '>' && *p->xml != '/')

+				{

+					attvaluelen++; p->xml++;

+					if(p->xml >= p->xmlend)

+						return -1;

+				}

+			}

+			/*printf("%.*s='%.*s'\n",

+			       attnamelen, attname, attvaluelen, attvalue);*/

+			if(p->attfunc)

+				p->attfunc(p->data, attname, attnamelen, attvalue, attvaluelen);

+		}

+		p->xml++;

+	}

+	return -1;

+}

+

+/* parseelt parse the xml stream and

+ * call the callback functions when needed... */

+void parseelt(struct xmlparser * p)

+{

+	int i;

+	const char * elementname;

+	while(p->xml < (p->xmlend - 1))

+	{

+		if((p->xml)[0]=='<' && (p->xml)[1]!='?')

+		{

+			i = 0; elementname = ++p->xml;

+			while( !IS_WHITE_SPACE(*p->xml)

+				  && (*p->xml!='>') && (*p->xml!='/')

+				 )

+			{

+				i++; p->xml++;

+				if (p->xml >= p->xmlend)

+					return;

+				/* to ignore namespace : */

+				if(*p->xml==':')

+				{

+					i = 0;

+					elementname = ++p->xml;

+				}

+			}

+			if(i>0)

+			{

+				if(p->starteltfunc)

+					p->starteltfunc(p->data, elementname, i);

+				if(parseatt(p))

+					return;

+				if(*p->xml!='/')

+				{

+					const char * data;

+					i = 0; data = ++p->xml;

+					if (p->xml >= p->xmlend)

+						return;

+					while( IS_WHITE_SPACE(*p->xml) )

+					{

+						i++; p->xml++; // support HNAP1

+						if (p->xml >= p->xmlend)

+							return;

+					}

+					while(*p->xml!='<')

+					{

+						i++; p->xml++;

+						if (p->xml >= p->xmlend)

+							return;

+					}

+					if(i>0 && p->datafunc)

+						p->datafunc(p->data, data, i);

+				}

+			}

+			else if(*p->xml == '/')

+			{

+				i = 0; elementname = ++p->xml;

+				if (p->xml >= p->xmlend)

+					return;

+				while((*p->xml != '>'))

+				{

+					i++; p->xml++;

+					if (p->xml >= p->xmlend)

+						return;

+				}

+				if(p->endeltfunc)

+					p->endeltfunc(p->data, elementname, i);

+				p->xml++;

+			}

+		}

+		else

+		{

+			p->xml++;

+		}

+	}

+}

+

+/* the parser must be initialized before calling this function */

+void parsexml(struct xmlparser * parser)

+{

+	parser->xml = parser->xmlstart;

+	parser->xmlend = parser->xmlstart + parser->xmlsize;

+	parseelt(parser);

+}

+

+