[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit
Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/app/cwmp/netcwmp/libxmlet/src/Makefile.am b/ap/app/cwmp/netcwmp/libxmlet/src/Makefile.am
new file mode 100755
index 0000000..30adc20
--- /dev/null
+++ b/ap/app/cwmp/netcwmp/libxmlet/src/Makefile.am
@@ -0,0 +1,9 @@
+lib_LIBRARIES = libxmlet.a
+libxmlet_a_SOURCES = attr.c document.c namemap.c list.c xmlet.c \
+ element.c node.c buffer.c parser.c
+
+
+AM_CPPFLAGS = -DUSE_CWMP_MEMORY_POOL -I$(top_srcdir)/libxmlet/src/inc -I$(top_srcdir)/libxmlet/include -I$(top_srcdir)/libpool/include
+
+
+
diff --git a/ap/app/cwmp/netcwmp/libxmlet/src/Makefile.in b/ap/app/cwmp/netcwmp/libxmlet/src/Makefile.in
new file mode 100755
index 0000000..18ffc03
--- /dev/null
+++ b/ap/app/cwmp/netcwmp/libxmlet/src/Makefile.in
@@ -0,0 +1,537 @@
+# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = libxmlet/src
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.in
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(SHELL) $(top_srcdir)/build/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+ if (++n[$$2] == $(am__install_max)) \
+ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+ END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(libdir)"
+LIBRARIES = $(lib_LIBRARIES)
+ARFLAGS = cru
+libxmlet_a_AR = $(AR) $(ARFLAGS)
+libxmlet_a_LIBADD =
+am_libxmlet_a_OBJECTS = attr.$(OBJEXT) document.$(OBJEXT) \
+ namemap.$(OBJEXT) list.$(OBJEXT) xmlet.$(OBJEXT) \
+ element.$(OBJEXT) node.$(OBJEXT) buffer.$(OBJEXT) \
+ parser.$(OBJEXT)
+libxmlet_a_OBJECTS = $(am_libxmlet_a_OBJECTS)
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/build/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+ $(LDFLAGS) -o $@
+SOURCES = $(libxmlet_a_SOURCES)
+DIST_SOURCES = $(libxmlet_a_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ALLOCA = @ALLOCA@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BUILD_CPU = @BUILD_CPU@
+BUILD_OS = @BUILD_OS@
+BUILD_VENDOR = @BUILD_VENDOR@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DSYMUTIL = @DSYMUTIL@
+ECHO = @ECHO@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+F77 = @F77@
+FFLAGS = @FFLAGS@
+GREP = @GREP@
+HOST_CPU = @HOST_CPU@
+HOST_OS = @HOST_OS@
+HOST_VENDOR = @HOST_VENDOR@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NMEDIT = @NMEDIT@
+OBJEXT = @OBJEXT@
+OPENSSL_DIR = @OPENSSL_DIR@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_F77 = @ac_ct_F77@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+lib_LIBRARIES = libxmlet.a
+libxmlet_a_SOURCES = attr.c document.c namemap.c list.c xmlet.c \
+ element.c node.c buffer.c parser.c
+
+AM_CPPFLAGS = -DUSE_CWMP_MEMORY_POOL -I$(top_srcdir)/libxmlet/src/inc -I$(top_srcdir)/libxmlet/include -I$(top_srcdir)/libpool/include
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libxmlet/src/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign libxmlet/src/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-libLIBRARIES: $(lib_LIBRARIES)
+ @$(NORMAL_INSTALL)
+ test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
+ @list='$(lib_LIBRARIES)'; test -n "$(libdir)" || list=; \
+ list2=; for p in $$list; do \
+ if test -f $$p; then \
+ list2="$$list2 $$p"; \
+ else :; fi; \
+ done; \
+ test -z "$$list2" || { \
+ echo " $(INSTALL_DATA) $$list2 '$(DESTDIR)$(libdir)'"; \
+ $(INSTALL_DATA) $$list2 "$(DESTDIR)$(libdir)" || exit $$?; }
+ @$(POST_INSTALL)
+ @list='$(lib_LIBRARIES)'; test -n "$(libdir)" || list=; \
+ for p in $$list; do \
+ if test -f $$p; then \
+ $(am__strip_dir) \
+ echo " ( cd '$(DESTDIR)$(libdir)' && $(RANLIB) $$f )"; \
+ ( cd "$(DESTDIR)$(libdir)" && $(RANLIB) $$f ) || exit $$?; \
+ else :; fi; \
+ done
+
+uninstall-libLIBRARIES:
+ @$(NORMAL_UNINSTALL)
+ @list='$(lib_LIBRARIES)'; test -n "$(libdir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ test -n "$$files" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(libdir)' && rm -f "$$files" )"; \
+ cd "$(DESTDIR)$(libdir)" && rm -f $$files
+
+clean-libLIBRARIES:
+ -test -z "$(lib_LIBRARIES)" || rm -f $(lib_LIBRARIES)
+libxmlet.a: $(libxmlet_a_OBJECTS) $(libxmlet_a_DEPENDENCIES)
+ -rm -f libxmlet.a
+ $(libxmlet_a_AR) libxmlet.a $(libxmlet_a_OBJECTS) $(libxmlet_a_LIBADD)
+ $(RANLIB) libxmlet.a
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/attr.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buffer.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/document.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/element.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/namemap.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/node.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parser.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlet.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ set x; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LIBRARIES)
+installdirs:
+ for dir in "$(DESTDIR)$(libdir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libLIBRARIES clean-libtool \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-libLIBRARIES
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-libLIBRARIES
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+ clean-libLIBRARIES clean-libtool ctags distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am \
+ install-libLIBRARIES install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags uninstall uninstall-am uninstall-libLIBRARIES
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/ap/app/cwmp/netcwmp/libxmlet/src/attr.c b/ap/app/cwmp/netcwmp/libxmlet/src/attr.c
new file mode 100755
index 0000000..96ea2c1
--- /dev/null
+++ b/ap/app/cwmp/netcwmp/libxmlet/src/attr.c
@@ -0,0 +1,71 @@
+///////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2003 Intel Corporation
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+// * Neither name of Intel Corporation nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////
+
+#include "xmlparser.h"
+
+/*================================================================
+* Function: XmlAttrInit
+* Initializes an attribute node
+* External function.
+*
+*=================================================================*/
+void
+XmlAttrInit( XmlAttribute * attr )
+{
+ if ( attr != NULL )
+ {
+ memset( attr, 0, sizeof( XmlAttribute ) );
+ }
+}
+
+
+/*================================================================
+* Function: XmlAttrFree
+* Frees an attribute node.
+* external function.
+*
+*=================================================================*/
+void
+XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ XmlAttribute * attr )
+{
+ if ( attr != NULL )
+ {
+ XmlNodeFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ ( XmlNode * ) attr );
+ }
+}
diff --git a/ap/app/cwmp/netcwmp/libxmlet/src/buffer.c b/ap/app/cwmp/netcwmp/libxmlet/src/buffer.c
new file mode 100755
index 0000000..1069f94
--- /dev/null
+++ b/ap/app/cwmp/netcwmp/libxmlet/src/buffer.c
@@ -0,0 +1,305 @@
+///////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2003 Intel Corporation
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+// * Neither name of Intel Corporation nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include "xmlbuffer.h"
+#include "cwmp/xmlet.h"
+
+//#include "xmlparser.h"
+/*================================================================
+* XmlBufferSetSize
+*
+* Increases or decreases buffer cap so that at least
+* 'new_length' bytes can be stored
+*
+* On error, m's fields do not change.
+*
+* returns:
+* UPNP_E_SUCCESS
+* UPNP_E_OUTOF_MEMORY
+*
+*=================================================================*/
+static int
+XmlBufferSetSize(
+ Pool * pool,
+ XmlBuffer * m,
+ IN size_t new_length )
+{
+ size_t diff;
+ size_t alloc_len;
+ char *temp_buf;
+
+ if ( new_length > m->length ) // increase length
+ {
+ // need more mem?
+ if ( new_length < m->capacity )
+ {
+ return 0; // have enough mem; done
+ }
+
+ if (m->length == 0)
+ {
+ alloc_len = new_length + 1;
+ temp_buf = PMALLOC(alloc_len);
+ if ( temp_buf == NULL )
+ return XML_INSUFFICIENT_MEMORY;
+ m->buf = temp_buf;
+ m->capacity = alloc_len;
+ return 0;
+ }
+
+ diff = new_length - m->length + 1;
+ alloc_len = MAXVAL( m->size_inc, diff ) + m->capacity;
+ }
+ else // decrease length
+ {
+ assert( new_length <= m->length );
+ return 0;
+ /* // if diff is 0..m->size_inc, don't PFREE
+ if( ( m->capacity - new_length ) <= m->size_inc ) {
+ return 0;
+ }
+
+ alloc_len = new_length + m->size_inc;
+ */
+ }
+
+ assert( alloc_len > new_length );
+
+ temp_buf = PREALLOC( m->buf, m->length, alloc_len );
+ if ( temp_buf == NULL )
+ {
+ // try smaller size
+ alloc_len = new_length + 1;
+ temp_buf = PREALLOC( m->buf, m->length, alloc_len);
+
+ if ( temp_buf == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+ // save
+ m->buf = temp_buf;
+ m->capacity = alloc_len;
+ return 0;
+}
+
+/*================================================================
+* memcwmp_buffer_init
+*
+*
+*=================================================================*/
+void
+XmlBufferInit( XmlBuffer * m )
+{
+ assert( m != NULL );
+
+ m->size_inc = MEMBUF_DEF_SIZE_INC;
+ m->buf = NULL;
+ m->length = 0;
+ m->capacity = 0;
+}
+
+/*================================================================
+* memcwmp_buffer_destroy
+*
+*
+*=================================================================*/
+void
+XmlBufferDestroy(
+ Pool * pool,
+ XmlBuffer * m )
+{
+ if ( m == NULL )
+ {
+ return;
+ }
+
+ if (m->buf) //laoyou fixed
+ PFREE( m->buf );
+ XmlBufferInit( m );
+}
+
+/*================================================================
+* XmlBufferAssign
+*
+*
+*=================================================================*/
+int
+XmlBufferAssign(
+ Pool * pool,
+
+ XmlBuffer * m,
+ IN const void *buf,
+ IN size_t buf_len )
+{
+ int return_code;
+
+ assert( m != NULL );
+
+ // set value to null
+ if ( buf == NULL )
+ {
+ XmlBufferDestroy(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ m );
+ return XML_OK;
+ }
+ // alloc mem
+ return_code = XmlBufferSetSize(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ m, buf_len );
+ if ( return_code != 0 )
+ {
+ return return_code;
+ }
+ // copy
+ memcpy( m->buf, buf, buf_len );
+ m->buf[buf_len] = 0; // null-terminate
+
+ m->length = buf_len;
+
+ return XML_OK;
+
+}
+
+/*================================================================
+* XmlBufferAssignString
+*
+*
+*=================================================================*/
+int
+XmlBufferAssignString(
+ Pool * pool,
+ XmlBuffer * m,
+ IN const char *c_str )
+{
+ return XmlBufferAssign(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ m, c_str, strlen( c_str ) );
+}
+
+/*================================================================
+* XmlBufferAppend
+*
+*
+*=================================================================*/
+int
+XmlBufferAppend(
+ Pool * pool,
+
+ XmlBuffer * m,
+ IN const void *buf )
+{
+ assert( m != NULL );
+
+ return XmlBufferInsert(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ m, buf, 1, m->length );
+}
+
+/*================================================================
+* XmlBufferAppendString
+*
+*
+*=================================================================*/
+int
+XmlBufferAppendString(
+ Pool * pool,
+
+ XmlBuffer * m,
+ IN const char *c_str )
+{
+ return XmlBufferInsert(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ m, c_str, strlen( c_str ), m->length );
+}
+
+/*================================================================
+* XmlBufferInsert
+*
+*
+*=================================================================*/
+int
+XmlBufferInsert(
+ Pool * pool,
+
+ XmlBuffer * m,
+ IN const void *buf,
+ IN size_t buf_len,
+ int index )
+{
+ int return_code;
+
+ assert( m != NULL );
+
+ if ( index < 0 || index > ( int )m->length )
+ return XML_INDEX_SIZE_ERR;
+
+ if ( buf == NULL || buf_len == 0 )
+ {
+ return 0;
+ }
+ // alloc mem
+ return_code = XmlBufferSetSize(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ m, m->length + buf_len );
+ if ( return_code != 0 )
+ {
+ return return_code;
+ }
+ // insert data
+ // move data to right of insertion point
+ memmove( m->buf + index + buf_len, m->buf + index, m->length - index );
+ memcpy( m->buf + index, buf, buf_len );
+ m->length += buf_len;
+ m->buf[m->length] = 0; // null-terminate
+
+ return 0;
+}
diff --git a/ap/app/cwmp/netcwmp/libxmlet/src/document.c b/ap/app/cwmp/netcwmp/libxmlet/src/document.c
new file mode 100755
index 0000000..c0aeff5
--- /dev/null
+++ b/ap/app/cwmp/netcwmp/libxmlet/src/document.c
@@ -0,0 +1,1033 @@
+///////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2003 Intel Corporation
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+// * Neither name of Intel Corporation nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "xmlparser.h"
+
+/*================================================================
+* XmlDocumentInit
+* It initialize the document structure.
+* External function.
+*
+*=================================================================*/
+void
+XmlDocumentInit( XmlDocument * doc )
+{
+ memset( doc, 0, sizeof( XmlDocument ) );
+}
+
+/*================================================================
+* XmlDocumentFree
+* It XFREEs the whole document tree.
+* External function.
+*
+*=================================================================*/
+void
+XmlDocumentFree(
+ Pool * pool,
+ XmlDocument * doc )
+{
+ if ( doc != NULL )
+ {
+ XmlNodeFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ ( XmlNode * ) doc );
+ }
+
+}
+
+/*================================================================
+* XmlDocSetOwnerDocument
+*
+* When this function is called first time, nodeptr is the root
+* of the subtree, so it is not necessay to do two steps
+* recursion.
+*
+* Internal function called by XmlDocImportNode
+*
+*=================================================================*/
+void
+XmlDocSetOwnerDocument( XmlDocument * doc,
+ XmlNode * nodeptr )
+{
+ if ( nodeptr != NULL )
+ {
+ nodeptr->ownerDocument = doc;
+ XmlDocSetOwnerDocument( doc,
+ XmlNodeGetFirstChild( nodeptr ) );
+ XmlDocSetOwnerDocument( doc,
+ XmlNodeGetNextSibling
+ ( nodeptr ) );
+ }
+}
+
+/*================================================================
+* XmlDocImportNode
+* Imports a node from another document to this document. The
+* returned node has no parent; (parentNode is null). The source
+* node is not altered or removed from the original document;
+* this method creates a new copy of the source node.
+
+* For all nodes, importing a node creates a node object owned
+* by the importing document, with attribute values identical to
+* the source node's nodeName and nodeType, plus the attributes
+* related to namespaces (prefix, localName, and namespaceURI).
+* As in the cloneNode operation on a node, the source node is
+* not altered.
+*
+* External function.
+*
+*=================================================================*/
+int
+XmlDocImportNode(
+ Pool * pool,
+
+ XmlDocument * doc,
+ XmlNode * importNode,
+ IN BOOL deep,
+ OUT XmlNode ** rtNode )
+{
+ unsigned short nodeType;
+ XmlNode * newNode;
+
+ *rtNode = NULL;
+
+ if ( ( doc == NULL ) || ( importNode == NULL ) )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+
+ nodeType = XmlNodeGetNodeType( importNode );
+ if ( nodeType == XML_DOCUMENT_NODE )
+ {
+ return XML_NOT_SUPPORTED_ERR;
+ }
+
+ newNode = XmlNodeCloneNode(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ importNode, deep );
+ if ( newNode == NULL )
+ {
+ return XML_FAILED;
+ }
+
+ XmlDocSetOwnerDocument( doc, newNode );
+ *rtNode = newNode;
+
+ return XML_OK;
+}
+
+/*================================================================
+* XmlDocCreateElementEx
+* Creates an element of the type specified.
+* External function.
+* Parameters:
+* doc: pointer to document
+* tagName: The name of the element, it is case-sensitive.
+* Return Value:
+* XML_OK
+* XML_INVALID_PARAMETER: if either doc or tagName is NULL
+* XML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
+*
+*=================================================================*/
+int
+#ifdef USE_CWMP_MEMORY_POOL
+XmlDocCreateElementEx(Pool * pool, XmlDocument * doc,
+#else
+XmlDocCreateElementEx( XmlDocument * doc,
+#endif
+
+ IN char * tagName,
+ OUT XmlElement ** rtElement )
+{
+
+ int errCode = XML_OK;
+ XmlElement *newElement = NULL;
+
+ if ( ( doc == NULL ) || ( tagName == NULL ) )
+ {
+ errCode = XML_INVALID_PARAMETER;
+ goto ErrorHandler;
+ }
+
+ newElement = ( XmlElement * ) PMALLOC( sizeof( XmlElement ) );
+ if ( newElement == NULL )
+ {
+ errCode = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+
+ XmlElementInit( newElement );
+ newElement->tagName = PSTRDUP( tagName );
+ if ( newElement->tagName == NULL )
+ {
+ XmlElementFree(
+#ifdef USE_CWMP_MEMORY_POOL
+
+ pool ,
+#endif
+ newElement );
+ newElement = NULL;
+ errCode = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+ // set the node fields
+ newElement->node.nodeType = XML_ELEMENT_NODE;
+ newElement->node.nodeName = PSTRDUP( tagName );
+ if ( newElement->node.nodeName == NULL )
+ {
+ XmlElementFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newElement );
+ newElement = NULL;
+ errCode = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+
+ newElement->node.ownerDocument = doc;
+
+ErrorHandler:
+ *rtElement = newElement;
+ return errCode;
+
+}
+
+/*================================================================
+* XmlDocCreateElement
+* Creates an element of the type specified.
+* External function.
+* Parameters:
+* doc: pointer to document
+* tagName: The name of the element, it is case-sensitive.
+* Return Value:
+* A new element object with the nodeName set to tagName, and
+* localName, prefix and namespaceURI set to null.
+*
+*=================================================================*/
+XmlElement *
+
+XmlDocCreateElement(
+ Pool * pool,
+ XmlDocument * doc,
+ IN char * tagName )
+{
+ XmlElement *newElement = NULL;
+
+ XmlDocCreateElementEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ doc, tagName, &newElement );
+ return newElement;
+
+}
+
+/*================================================================
+* XmlDocCreateDocumentEx
+* Creates an document object
+* Internal function.
+* Parameters:
+* rtDoc: the document created or NULL on failure
+* Return Value:
+* XML_OK
+* XML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
+*
+*=================================================================*/
+int
+XmlDocCreateDocumentEx(
+ Pool * pool,
+ OUT XmlDocument ** rtDoc )
+{
+ XmlDocument *doc;
+ int errCode = XML_OK;
+
+ doc = NULL;
+ doc = ( XmlDocument * ) PMALLOC( sizeof( XmlDocument ) );
+ if ( doc == NULL )
+ {
+ errCode = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+
+ XmlDocumentInit( doc );
+
+ doc->node.nodeName = PSTRDUP( DOCUMENTNODENAME );
+ if ( doc->node.nodeName == NULL )
+ {
+ XmlDocumentFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ doc );
+ doc = NULL;
+ errCode = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+
+ doc->node.nodeType = XML_DOCUMENT_NODE;
+ doc->node.ownerDocument = doc;
+
+ErrorHandler:
+ *rtDoc = doc;
+ return errCode;
+}
+
+/*================================================================
+* XmlDocCreateDocument
+* Creates an document object
+* Internal function.
+* Parameters:
+* none
+* Return Value:
+* A new document object with the nodeName set to "#document".
+*
+*=================================================================*/
+XmlDocument *
+XmlDocCreateDocument(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool
+#endif
+)
+{
+ XmlDocument *doc = NULL;
+
+ XmlDocCreateDocumentEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ &doc );
+
+ return doc;
+
+}
+
+/*================================================================
+* XmlDocCreateTextNodeEx
+* Creates an text node.
+* External function.
+* Parameters:
+* data: text data for the text node. It is stored in nodeValue field.
+* Return Value:
+* XML_OK
+* XML_INVALID_PARAMETER: if either doc or data is NULL
+* XML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
+*
+*=================================================================*/
+int
+#ifdef USE_CWMP_MEMORY_POOL
+XmlDocCreateTextNodeEx(Pool * pool, XmlDocument * doc,
+#else
+XmlDocCreateTextNodeEx( XmlDocument * doc,
+#endif
+ IN char *data,
+ OUT XmlNode ** textNode )
+{
+ XmlNode * returnNode;
+ int rc = XML_OK;
+
+ returnNode = NULL;
+ if ( ( doc == NULL ) || ( data == NULL ) )
+ {
+ rc = XML_INVALID_PARAMETER;
+ goto ErrorHandler;
+ }
+
+ returnNode = ( XmlNode * ) PMALLOC( sizeof( XmlNode ) );
+ if ( returnNode == NULL )
+ {
+ rc = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+ // initialize the node
+ XmlNodeInit( returnNode );
+
+ returnNode->nodeName = PSTRDUP( TEXTNODENAME );
+ if ( returnNode->nodeName == NULL )
+ {
+ XmlNodeFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ returnNode );
+ returnNode = NULL;
+ rc = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+ // add in node value
+// if ( data != NULL ) // kw 3
+ {
+ returnNode->nodeValue = XmlStrduptrim(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ data );
+ if ( returnNode->nodeValue == NULL )
+ {
+ XmlNodeFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ returnNode );
+ returnNode = NULL;
+ rc = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+ }
+
+ returnNode->nodeType = XML_TEXT_NODE;
+ returnNode->ownerDocument = doc;
+
+ErrorHandler:
+ *textNode = returnNode;
+ return rc;
+
+}
+
+/*================================================================
+* XmlDocCreateTextNode
+* Creates an text node.
+* External function.
+* Parameters:
+* data: text data for the text node. It is stored in nodeValue field.
+* Return Value:
+* The new text node.
+*
+*=================================================================*/
+XmlNode *
+XmlDocCreateTextNode(
+ Pool * pool,
+
+ XmlDocument * doc,
+ IN char *data )
+{
+ XmlNode * returnNode = NULL;
+
+ XmlDocCreateTextNodeEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ doc, data, &returnNode );
+
+ return returnNode;
+}
+
+/*================================================================
+* XmlDocCreateAttributeEx
+* Creates an attribute of the given name.
+* External function.
+* Parameters:
+* name: The name of the Attribute node.
+* Return Value:
+* XML_OK
+* XML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
+*
+================================================================*/
+int
+#ifdef USE_CWMP_MEMORY_POOL
+XmlDocCreateAttributeEx(Pool * pool, XmlDocument * doc,
+#else
+XmlDocCreateAttributeEx( XmlDocument * doc,
+#endif
+
+ const char *name,
+ XmlAttribute ** rtAttr )
+{
+ XmlAttribute *attrNode = NULL;
+ int errCode = XML_OK;
+
+ attrNode = ( XmlAttribute * ) PMALLOC( sizeof( XmlAttribute ) );
+ if ( attrNode == NULL )
+ {
+ errCode = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+
+ if ( ( doc == NULL ) || ( name == NULL ) )
+ {
+ XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ attrNode );
+ attrNode = NULL;
+ errCode = XML_INVALID_PARAMETER;
+ goto ErrorHandler;
+ }
+
+ XmlAttrInit( attrNode );
+
+ attrNode->node.nodeType = XML_ATTRIBUTE_NODE;
+
+ // set the node fields
+ attrNode->node.nodeName = PSTRDUP( name );
+ if ( attrNode->node.nodeName == NULL )
+ {
+ XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ attrNode );
+ attrNode = NULL;
+ errCode = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+
+ attrNode->node.ownerDocument = doc;
+
+ErrorHandler:
+ *rtAttr = attrNode;
+ return errCode;
+
+}
+
+/*================================================================
+* XmlDocCreateAttribute
+* Creates an attribute of the given name.
+* External function.
+* Parameters:
+* name: The name of the Attribute node.
+* Return Value:
+* A new attr object with the nodeName attribute set to the
+* given name, and the localName, prefix and namespaceURI set to NULL.
+* The value of the attribute is the empty string.
+*
+================================================================*/
+XmlAttribute *
+XmlDocCreateAttribute(
+ Pool * pool,
+ XmlDocument * doc,
+ IN char *name )
+{
+ XmlAttribute *attrNode = NULL;
+
+ XmlDocCreateAttributeEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ doc, name, &attrNode );
+ return attrNode;
+
+}
+
+/*================================================================
+* XmlDocCreateAttributeNSEx
+* Creates an attrbute of the given name and namespace URI
+* External function.
+* Parameters:
+* namespaceURI: the namespace fo the attribute to create
+* qualifiedName: qualifiedName of the attribute to instantiate
+* Return Value:
+* XML_OK
+* XML_INVALID_PARAMETER: if either doc,namespaceURI or qualifiedName is NULL
+* XML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
+*
+*=================================================================*/
+int
+XmlDocCreateAttributeNSEx(
+ Pool * pool,
+
+ XmlDocument * doc,
+ const char * namespaceURI,
+ const char * qualifiedName,
+ OUT XmlAttribute ** rtAttr )
+{
+ XmlAttribute *attrNode = NULL;
+ int errCode = XML_OK;
+
+ if ( ( doc == NULL ) || ( namespaceURI == NULL )
+ || ( qualifiedName == NULL ) )
+ {
+ errCode = XML_INVALID_PARAMETER;
+ goto ErrorHandler;
+ }
+
+ errCode =
+ XmlDocCreateAttributeEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ doc, qualifiedName, &attrNode );
+ if ( errCode != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+ // set the namespaceURI field
+ attrNode->node.namespaceURI = PSTRDUP( namespaceURI );
+ if ( attrNode->node.namespaceURI == NULL )
+ {
+ XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ attrNode );
+ attrNode = NULL;
+ errCode = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+ // set the localName and prefix
+ errCode =
+ XmlNodeSetNodeName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ ( XmlNode * ) attrNode, qualifiedName );
+ if ( errCode != XML_OK )
+ {
+ XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ attrNode );
+ attrNode = NULL;
+ goto ErrorHandler;
+ }
+
+ErrorHandler:
+ *rtAttr = attrNode;
+ return errCode;
+
+}
+
+/*================================================================
+* XmlDocCreateAttributeNS
+* Creates an attrbute of the given name and namespace URI
+* External function.
+* Parameters:
+* namespaceURI: the namespace fo the attribute to create
+* qualifiedName: qualifiedName of the attribute to instantiate
+* Return Value:
+* Creates an attribute node with the given namespaceURI and
+* qualifiedName. The prefix and localname are extracted from
+* the qualifiedName. The node value is empty.
+*
+*=================================================================*/
+XmlAttribute *
+XmlDocCreateAttributeNS(
+ Pool * pool,
+
+ XmlDocument * doc,
+ IN char * namespaceURI,
+ IN char * qualifiedName )
+{
+ XmlAttribute *attrNode = NULL;
+
+ XmlDocCreateAttributeNSEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ doc, namespaceURI, qualifiedName,
+ &attrNode );
+ return attrNode;
+}
+
+/*================================================================
+* XmlDocCreateCDATASectionEx
+* Creates an CDATASection node whose value is the specified string
+* External function.
+* Parameters:
+* data: the data for the CDATASection contents.
+* Return Value:
+* XML_OK
+* XML_INVALID_PARAMETER: if either doc or data is NULL
+* XML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
+*
+*=================================================================*/
+int
+#ifdef USE_CWMP_MEMORY_POOL
+XmlDocCreateCDATASectionEx(Pool * pool, XmlDocument * doc,
+#else
+XmlDocCreateCDATASectionEx( XmlDocument * doc,
+#endif
+ IN char * data,
+ OUT XmlCDATASection ** rtCD )
+{
+ int errCode = XML_OK;
+ XmlCDATASection *cDSectionNode = NULL;
+
+ if ( ( doc == NULL ) || ( data == NULL ) )
+ {
+ errCode = XML_INVALID_PARAMETER;
+ goto ErrorHandler;
+ }
+
+ cDSectionNode =
+ ( XmlCDATASection * ) PMALLOC( sizeof( XmlCDATASection ) );
+ if ( cDSectionNode == NULL )
+ {
+ errCode = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+
+ XmlCDATASectionInit( cDSectionNode );
+
+ cDSectionNode->node.nodeType = XML_CDATA_SECTION_NODE;
+ cDSectionNode->node.nodeName = PSTRDUP( CDATANODENAME );
+ if ( cDSectionNode->node.nodeName == NULL )
+ {
+ XmlCDATASectionFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ cDSectionNode );
+ cDSectionNode = NULL;
+ errCode = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+
+ cDSectionNode->node.nodeValue = XmlStrduptrim(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ data );
+ if ( cDSectionNode->node.nodeValue == NULL )
+ {
+ XmlCDATASectionFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ cDSectionNode );
+ cDSectionNode = NULL;
+ errCode = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+
+ cDSectionNode->node.ownerDocument = doc;
+
+ErrorHandler:
+ *rtCD = cDSectionNode;
+ return errCode;
+
+}
+
+/*================================================================
+* XmlDocCreateCDATASection
+* Creates an CDATASection node whose value is the specified string
+* External function.
+* Parameters:
+* data: the data for the CDATASection contents.
+* Return Value:
+* The new CDATASection object.
+*
+*=================================================================*/
+XmlCDATASection *
+XmlDocCreateCDATASection(
+ Pool * pool,
+
+ XmlDocument * doc,
+ IN char * data )
+{
+
+ XmlCDATASection *cDSectionNode = NULL;
+
+ XmlDocCreateCDATASectionEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ doc, data, &cDSectionNode );
+ return cDSectionNode;
+}
+
+/*================================================================
+* XmlDocCreateElementNSEx
+* Creates an element of the given qualified name and namespace URI.
+* External function.
+* Parameters:
+* namespaceURI: the namespace URI of the element to create.
+* qualifiedName: the qualified name of the element to instantiate.
+* Return Value:
+* Return Value:
+* XML_OK
+* XML_INVALID_PARAMETER: if either doc,namespaceURI or qualifiedName is NULL
+* XML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
+*
+*=================================================================*/
+int
+XmlDocCreateElementNSEx(
+ Pool * pool,
+
+ XmlDocument * doc,
+ IN char * namespaceURI,
+ IN char * qualifiedName,
+ OUT XmlElement ** rtElement )
+{
+
+ XmlElement *newElement = NULL;
+ int errCode = XML_OK;
+
+ if ( ( doc == NULL ) || ( namespaceURI == NULL )
+ || ( qualifiedName == NULL ) )
+ {
+ errCode = XML_INVALID_PARAMETER;
+ goto ErrorHandler;
+ }
+
+ errCode =
+ XmlDocCreateElementEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ doc, qualifiedName, &newElement );
+ if ( errCode != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+ // set the namespaceURI field
+ newElement->node.namespaceURI = PSTRDUP( namespaceURI );
+ if ( newElement->node.namespaceURI == NULL )
+ {
+ XmlElementFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newElement );
+ newElement = NULL;
+ errCode = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+ // set the localName and prefix
+ errCode =
+ XmlNodeSetNodeName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ ( XmlNode * ) newElement, qualifiedName );
+ if ( errCode != XML_OK )
+ {
+ XmlElementFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newElement );
+ newElement = NULL;
+ errCode = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+
+ newElement->node.nodeValue = NULL;
+
+ErrorHandler:
+ *rtElement = newElement;
+ return errCode;
+
+}
+
+/*================================================================
+* XmlDocCreateElementNS
+* Creates an element of the given qualified name and namespace URI.
+* External function.
+* Parameters:
+* namespaceURI: the namespace URI of the element to create.
+* qualifiedName: the qualified name of the element to instantiate.
+* Return Value:
+* The new element object with tagName qualifiedName, prefix and
+* localName extraced from qualfiedName, nodeName of qualfiedName,
+* namespaceURI of namespaceURI.
+*
+*=================================================================*/
+XmlElement *
+XmlDocCreateElementNS(
+ Pool * pool,
+
+ XmlDocument * doc,
+ IN char * namespaceURI,
+ IN char * qualifiedName )
+{
+ XmlElement *newElement = NULL;
+
+ XmlDocCreateElementNSEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ doc, namespaceURI, qualifiedName,
+ &newElement );
+ return newElement;
+}
+
+/*================================================================
+* XmlDocGetElementsByTagName
+* Returns a nodeList of all the Elements with a given tag name
+* in the order in which they are encountered in a preorder traversal
+* of the document tree.
+* External function.
+* Parameters:
+* tagName: the name of the tag to match on. The special value "*"
+* matches all tags.
+* Return Value:
+* A new nodeList object containing all the matched Elements.
+*
+*=================================================================*/
+XmlNodeList *
+XmlDocGetElementsByTagName(
+ Pool * pool,
+ XmlDocument * doc,
+ IN char *tagName )
+{
+ XmlNodeList *returnNodeList = NULL;
+
+ if ( ( doc == NULL ) || ( tagName == NULL ) )
+ {
+ return NULL;
+ }
+
+ XmlNodeGetElementsByTagName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ ( XmlNode * ) doc, tagName,
+ &returnNodeList );
+ return returnNodeList;
+}
+
+/*================================================================
+* XmlDocGetElementsByTagNameNS
+* Returns a nodeList of all the Elements with a given local name and
+* namespace URI in the order in which they are encountered in a
+* preorder traversal of the document tree.
+* External function.
+* Parameters:
+* namespaceURI: the namespace of the elements to match on. The special
+* value "*" matches all namespaces.
+* localName: the local name of the elements to match on. The special
+* value "*" matches all local names.
+* Return Value:
+* A new nodeList object containing all the matched Elements.
+*
+*=================================================================*/
+XmlNodeList *
+XmlDocGetElementsByTagNameNS(
+ Pool * pool,
+ XmlDocument * doc,
+ IN char * namespaceURI,
+ IN char * localName )
+{
+ XmlNodeList *returnNodeList = NULL;
+
+ if ( ( doc == NULL ) || ( namespaceURI == NULL )
+ || ( localName == NULL ) )
+ {
+ return NULL;
+ }
+
+ XmlNodeGetElementsByTagNameNS(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ ( XmlNode * ) doc, namespaceURI,
+ localName, &returnNodeList );
+ return returnNodeList;
+}
+
+/*================================================================
+* XmlDocGetElementById
+* Returns the element whose ID is given by tagName. If no such
+* element exists, returns null.
+* External function.
+* Parameter:
+* tagName: the tag name for an element.
+* Return Values:
+* The matching element.
+*
+*=================================================================*/
+XmlElement *
+XmlDocGetElementById( XmlDocument * doc,
+ IN char * tagName )
+{
+ XmlElement *rtElement = NULL;
+ XmlNode * nodeptr = ( XmlNode * ) doc;
+ const char *name;
+
+ if ( ( nodeptr == NULL ) || ( tagName == NULL ) )
+ {
+ return rtElement;
+ }
+
+ if ( XmlNodeGetNodeType( nodeptr ) == XML_ELEMENT_NODE )
+ {
+ name = XmlNodeGetNodeName( nodeptr );
+ if ( name == NULL )
+ {
+ return rtElement;
+ }
+
+ if ( strcmp( tagName, name ) == 0 )
+ {
+ rtElement = ( XmlElement * ) nodeptr;
+ return rtElement;
+ }
+ else
+ {
+ rtElement = XmlDocGetElementById( ( XmlDocument * )
+ XmlNodeGetFirstChild
+ ( nodeptr ),
+ tagName );
+ if ( rtElement == NULL )
+ {
+ rtElement = XmlDocGetElementById( ( XmlDocument
+ * )
+ XmlNodeGetNextSibling
+ ( nodeptr ),
+ tagName );
+ }
+ }
+ }
+ else
+ {
+ rtElement = XmlDocGetElementById( ( XmlDocument * )
+ XmlNodeGetFirstChild
+ ( nodeptr ), tagName );
+ if ( rtElement == NULL )
+ {
+ rtElement = XmlDocGetElementById( ( XmlDocument * )
+ XmlNodeGetNextSibling
+ ( nodeptr ),
+ tagName );
+ }
+ }
+
+ return rtElement;
+}
diff --git a/ap/app/cwmp/netcwmp/libxmlet/src/element.c b/ap/app/cwmp/netcwmp/libxmlet/src/element.c
new file mode 100755
index 0000000..ee89df5
--- /dev/null
+++ b/ap/app/cwmp/netcwmp/libxmlet/src/element.c
@@ -0,0 +1,1199 @@
+///////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2003 Intel Corporation
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+// * Neither name of Intel Corporation nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////
+
+#include "xmlparser.h"
+
+
+/*================================================================
+* XmlElement_Init
+* Initializes an element node.
+* External function.
+*
+*=================================================================*/
+void
+XmlElementInit( XmlElement * element )
+{
+ if ( element != NULL )
+ {
+ memset( element, 0, sizeof( XmlElement ) );
+ element->node.nodeType = XML_ELEMENT_NODE;
+ }
+}
+
+/*================================================================
+* XmlElementGetTagName
+* Gets the element node's tagName
+* External function.
+*
+*=================================================================*/
+const char *
+XmlElementGetTagName( XmlElement * element )
+{
+
+ if ( element != NULL )
+ {
+ return element->tagName;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+/*================================================================
+* XmlElementSetTagName
+* Sets the given element's tagName.
+* Parameters:
+* tagName: new tagName for the element.
+*
+*=================================================================*/
+int
+XmlElementSetTagName(
+ Pool * pool,
+ XmlElement * element,
+ const char *tagName )
+{
+ int rc = XML_OK;
+
+// assert( ( element != NULL ) && ( tagName != NULL ) );
+ if ( ( element == NULL ) || ( tagName == NULL ) )
+ {
+ return XML_FAILED;
+ }
+
+ if ( element->tagName != NULL )
+ {
+ PFREE( element->tagName );
+ }
+
+ element->tagName = PSTRDUP( tagName );
+ if ( element->tagName == NULL )
+ {
+ rc = XML_INSUFFICIENT_MEMORY;
+ }
+
+ return rc;
+
+}
+
+/*=========================================================================
+* XmlElementGetAttribute
+* Retrievea an attribute value by name.
+* External function.
+* Parameters:
+* name: the name of the attribute to retrieve.
+* Return Values:
+* attribute value as a string, or the empty string if that attribute
+* does not have a specified value.
+*
+*========================================================================*/
+char *
+XmlElementGetAttribute( XmlElement * element,
+ const char * name )
+{
+ XmlNode * attrNode;
+
+ if ( ( element == NULL ) || ( name == NULL ) )
+ {
+ return NULL;
+ }
+
+ attrNode = element->node.firstAttr;
+ while ( attrNode != NULL )
+ {
+ if ( strcmp( attrNode->nodeName, name ) == 0 ) // found it
+ {
+ return attrNode->nodeValue;
+ }
+ else
+ {
+ attrNode = attrNode->nextSibling;
+ }
+ }
+
+ return NULL;
+}
+
+/*======================================================================
+* XmlElementSetAttribute
+* Adds a new attribute. If an attribute with that name is already
+* present in the element, its value is changed to be that of the value
+* parameter. If not, a new attribute is inserted into the element.
+*
+* External function.
+* Parameters:
+* name: the name of the attribute to create or alter.
+* value: value to set in string form
+* Return Values:
+* XML_OK or failure code.
+*=======================================================================*/
+int
+XmlElementSetAttribute(
+ Pool * pool,
+ XmlElement * element,
+ const char *name,
+ const char *value )
+{
+ XmlNode * attrNode;
+ XmlAttribute *newAttrNode;
+ short errCode = XML_OK;
+
+ if ( ( element == NULL ) || ( name == NULL ) || ( value == NULL ) )
+ {
+ errCode = XML_INVALID_PARAMETER;
+ goto ErrorHandler;
+ }
+
+ if ( XmlParserIsValidXmlName( name ) == FALSE )
+ {
+ errCode = XML_INVALID_CHARACTER_ERR;
+ goto ErrorHandler;
+ }
+
+ attrNode = element->node.firstAttr;
+ while ( attrNode != NULL )
+ {
+ if ( strcmp( attrNode->nodeName, name ) == 0 )
+ {
+ break; //found it
+ }
+ else
+ {
+ attrNode = attrNode->nextSibling;
+ }
+ }
+
+ if ( attrNode == NULL ) // add a new attribute
+ {
+ errCode =
+ XmlDocCreateAttributeEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ ( XmlDocument * ) element->node.
+ ownerDocument, name,
+ &newAttrNode );
+ if ( errCode != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+
+ attrNode = ( XmlNode * ) newAttrNode;
+
+ attrNode->nodeValue = XmlStrduptrim(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ value );
+ if ( attrNode->nodeValue == NULL )
+ {
+ XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newAttrNode );
+ errCode = XML_INSUFFICIENT_MEMORY;
+ goto ErrorHandler;
+ }
+
+ errCode =
+ XmlElementSetAttributeNode( element, newAttrNode, NULL );
+ if ( errCode != XML_OK )
+ {
+ XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newAttrNode );
+ goto ErrorHandler;
+ }
+
+ }
+ else
+ {
+ if ( attrNode->nodeValue != NULL ) // attribute name has a value already
+ {
+ PFREE( attrNode->nodeValue );
+ }
+
+ attrNode->nodeValue = XmlStrduptrim(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ value );
+ if ( attrNode->nodeValue == NULL )
+ {
+ errCode = XML_INSUFFICIENT_MEMORY;
+ }
+ }
+
+ErrorHandler:
+ return errCode;
+}
+
+/*================================================================
+* XmlElementRemoveAttribute
+* Removes an attribute value by name. The attribute node is
+* not removed.
+* External function.
+* Parameters:
+* name: the name of the attribute to remove.
+* Return Values:
+* XML_OK or error code.
+*
+*=================================================================*/
+int
+XmlElementRemoveAttribute(
+ Pool * pool,
+ XmlElement * element,
+ const char *name )
+{
+
+ XmlNode * attrNode;
+
+ if ( ( element == NULL ) || ( name == NULL ) )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+
+ attrNode = element->node.firstAttr;
+ while ( attrNode != NULL )
+ {
+ if ( strcmp( attrNode->nodeName, name ) == 0 )
+ {
+ break; //found it
+ }
+ else
+ {
+ attrNode = attrNode->nextSibling;
+ }
+ }
+
+ if ( attrNode != NULL ) // has the attribute
+ {
+ if ( attrNode->nodeValue != NULL )
+ {
+ PFREE( attrNode->nodeValue );
+ attrNode->nodeValue = NULL;
+ }
+ }
+
+ return XML_OK;
+}
+
+/*================================================================
+* XmlElementGetAttributeNode
+* Retrieve an attribute node by name.
+* External function.
+* Parameters:
+* name: the name(nodeName) of the attribute to retrieve.
+* Return Value:
+* The attr node with the specified name (nodeName) or NULL if
+* there is no such attribute.
+*
+*=================================================================*/
+XmlAttribute *
+XmlElementGetAttributeNode( XmlElement * element,
+ IN char *name )
+{
+
+ XmlNode * attrNode;
+
+ if ( ( element == NULL ) || ( name == NULL ) )
+ {
+ return NULL;
+ }
+
+ attrNode = element->node.firstAttr;
+ while ( attrNode != NULL )
+ {
+ if ( strcmp( attrNode->nodeName, name ) == 0 ) // found it
+ {
+ break;
+ }
+ else
+ {
+ attrNode = attrNode->nextSibling;
+ }
+ }
+
+ return ( XmlAttribute * ) attrNode;
+
+}
+
+/*==========================================================================
+* XmlElementSetAttributeNode
+* Adds a new attribute node. If an attribute with that name(nodeName)
+* is already present in the element, it is replaced by the new one.
+* External function.
+* Parameters:
+* The attr node to add to the attribute list.
+* Return Value:
+* if newAttr replaces an existing attribute, the replaced
+* attr node is returned, otherwise NULL is returned.
+*
+*===========================================================================*/
+int
+XmlElementSetAttributeNode( XmlElement * element,
+ XmlAttribute * newAttr,
+ OUT XmlAttribute ** rtAttr )
+{
+
+ XmlNode * attrNode;
+ XmlNode * node;
+ XmlNode * nextAttr = NULL;
+ XmlNode * prevAttr = NULL;
+ XmlNode * preSib;
+ XmlNode * nextSib;
+
+ if ( ( element == NULL ) || ( newAttr == NULL ) )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+
+ if ( newAttr->node.ownerDocument != element->node.ownerDocument )
+ {
+ return XML_WRONG_DOCUMENT_ERR;
+ }
+
+ if ( newAttr->ownerElement != NULL )
+ {
+ return XML_INUSE_ATTRIBUTE_ERR;
+ }
+
+ newAttr->ownerElement = element;
+ node = ( XmlNode * ) newAttr;
+
+ attrNode = element->node.firstAttr;
+ while ( attrNode != NULL )
+ {
+ if ( strcmp( attrNode->nodeName, node->nodeName ) == 0 )
+ {
+ break; //found it
+ }
+ else
+ {
+ attrNode = attrNode->nextSibling;
+ }
+ }
+
+ if ( attrNode != NULL ) // already present, will replace by newAttr
+ {
+ preSib = attrNode->prevSibling;
+ nextSib = attrNode->nextSibling;
+
+ if ( preSib != NULL )
+ {
+ preSib->nextSibling = node;
+ }
+
+ if ( nextSib != NULL )
+ {
+ nextSib->prevSibling = node;
+ }
+
+ if ( element->node.firstAttr == attrNode )
+ {
+ element->node.firstAttr = node;
+ }
+
+ if ( rtAttr != NULL )
+ {
+ *rtAttr = ( XmlAttribute * ) attrNode;
+ }
+ }
+ else // add this attribute
+ {
+ if ( element->node.firstAttr != NULL )
+ {
+ prevAttr = element->node.firstAttr;
+ nextAttr = prevAttr->nextSibling;
+ while ( nextAttr != NULL )
+ {
+ prevAttr = nextAttr;
+ nextAttr = prevAttr->nextSibling;
+ }
+ prevAttr->nextSibling = node;
+ node->prevSibling = prevAttr;
+ }
+ else // this is the first attribute node
+ {
+ element->node.firstAttr = node;
+ node->prevSibling = NULL;
+ node->nextSibling = NULL;
+ }
+
+ if ( rtAttr != NULL )
+ {
+ *rtAttr = NULL;
+ }
+ }
+
+ return XML_OK;
+}
+
+/*=======================================================================
+* XmlElementFindAttributeNode
+* Find a attribute node whose contents are the same as the oldAttr.
+* Internal only to parser.
+* Parameter:
+* oldAttr: the attribute node to match
+* Return:
+* if found it, the attribute node is returned,
+* otherwise, return NULL.
+*
+*========================================================================*/
+XmlNode *
+XmlElementFindAttributeNode( XmlElement * element,
+ XmlAttribute * oldAttr )
+{
+ XmlNode * attrNode;
+ XmlNode * oldAttrNode = ( XmlNode * ) oldAttr;
+
+ assert( ( element != NULL ) && ( oldAttr != NULL ) );
+
+ attrNode = element->node.firstAttr;
+ while ( attrNode != NULL ) // parentNode, prevSib, nextSib and ownerDocument doesn't matter
+ {
+ if ( XmlNodeCompare( attrNode, oldAttrNode ) == TRUE )
+ {
+ break; //found it
+ }
+ else
+ {
+ attrNode = attrNode->nextSibling;
+ }
+ }
+
+ return attrNode;
+
+}
+
+/*==================================================================
+* XmlElementRemoveAttributeNode
+* Removes the specified attribute node.
+* External function.
+*
+* Parameters:
+* oldAttr: the attr node to remove from the attribute list.
+*
+* Return Value:
+* XML_OK or failure
+*
+*===================================================================*/
+int
+XmlElementRemoveAttributeNode( XmlElement * element,
+ XmlAttribute * oldAttr,
+ OUT XmlAttribute ** rtAttr )
+{
+ XmlNode * attrNode;
+ XmlNode * preSib;
+ XmlNode * nextSib;
+
+ if ( ( element == NULL ) || ( oldAttr == NULL ) )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+
+ attrNode = XmlElementFindAttributeNode( element, oldAttr );
+ if ( attrNode != NULL ) // has the attribute
+ {
+ preSib = attrNode->prevSibling;
+ nextSib = attrNode->nextSibling;
+
+ if ( preSib != NULL )
+ {
+ preSib->nextSibling = nextSib;
+ }
+
+ if ( nextSib != NULL )
+ {
+ nextSib->prevSibling = preSib;
+ }
+
+ if ( element->node.firstAttr == attrNode )
+ {
+ element->node.firstAttr = nextSib;
+ }
+
+ attrNode->parentNode = 0;
+ attrNode->prevSibling = 0 ;
+ attrNode->nextSibling = 0;
+ *rtAttr = ( XmlAttribute * ) attrNode;
+ return XML_OK;
+
+ }
+ else
+ {
+ return XML_NOT_FOUND_ERR;
+ }
+
+}
+
+/*================================================================
+* XmlElementGetElementsByTagName
+* Returns a nodeList of all descendant Elements with a given
+* tag name, in the order in which they are encountered in a preorder
+* traversal of this element tree.
+* External function.
+*
+* Parameters:
+* tagName: the name of the tag to match on. The special value "*"
+* matches all tags.
+*
+* Return Value:
+* a nodeList of matching element nodes.
+*
+*=================================================================*/
+XmlNodeList *
+XmlElementGetElementsByTagName(
+ Pool * pool,
+ XmlElement * element,
+ IN char *tagName )
+{
+ XmlNodeList *returnNodeList = NULL;
+
+ if ( ( element != NULL ) && ( tagName != NULL ) )
+ {
+ XmlNodeGetElementsByTagName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ ( XmlNode * ) element, tagName,
+ &returnNodeList );
+ }
+ return returnNodeList;
+}
+
+/*================================================================
+* XmlElementGetAttributeNS
+* Retrieves an attribute value by local name and namespace URI.
+* External function.
+*
+* Parameters:
+* namespaceURI: the namespace URI of the attribute to retrieve.
+* localName: the local name of the attribute to retrieve.
+*
+* Return Value:
+* the attr value as a string, or NULL if that attribute does
+* not have the specified value.
+*
+*=================================================================*/
+char *
+XmlElementGetAttributeNS( XmlElement * element,
+ const char * namespaceURI,
+ const char * localName )
+{
+ XmlNode * attrNode;
+
+ if ( ( element == NULL ) || ( namespaceURI == NULL )
+ || ( localName == NULL ) )
+ {
+ return NULL;
+ }
+
+ attrNode = element->node.firstAttr;
+ while ( attrNode != NULL )
+ {
+ if ( strcmp( attrNode->localName, localName ) == 0 && strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) // found it
+ {
+ return attrNode->nodeValue;
+ }
+ else
+ {
+ attrNode = attrNode->nextSibling;
+ }
+ }
+
+ return NULL;
+
+}
+
+/*================================================================
+* XmlElementSetAttributeNS
+* Adds a new attribute. If an attribute with the same local name
+* and namespace URI is already present on the element, its prefix
+* is changed to be the prefix part of the qualifiedName, and its
+* value is changed to be the value parameter. This value is a
+* simple string.
+* External function.
+*
+* Parameter:
+* namespaceURI: the namespace of the attribute to create or alter.
+* qualifiedName: the qualified name of the attribute to create or alter.
+* value: the value to set in string form.
+*
+* Return Value:
+* XML_OK or failure
+*
+*=================================================================*/
+int
+XmlElementSetAttributeNS(
+ Pool * pool,
+ XmlElement * element,
+ const char * namespaceURI,
+ const char * qualifiedName,
+ const char * value )
+{
+ XmlNode * attrNode = NULL;
+ XmlNode newAttrNode;
+ XmlAttribute *newAttr;
+ int rc;
+
+ if ( ( element == NULL ) || ( namespaceURI == NULL ) ||
+ ( qualifiedName == NULL ) || ( value == NULL ) )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+
+ if ( XmlParserIsValidXmlName( qualifiedName ) == FALSE )
+ {
+ return XML_INVALID_CHARACTER_ERR;
+ }
+
+ XmlNodeInit( &newAttrNode );
+
+ newAttrNode.nodeName = PSTRDUP( qualifiedName );
+ if ( newAttrNode.nodeName == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ rc = XmlParserSetNodePrefixAndLocalName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ &newAttrNode );
+ if ( rc != XML_OK )
+ {
+ XmlParserFreeNodeContent(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ &newAttrNode );
+ return rc;
+ }
+ // see DOM 2 spec page 59
+ if ( /*( newAttrNode.prefix != NULL && namespaceURI == NULL ) ||*/
+ (newAttrNode.prefix != NULL && strcmp( newAttrNode.prefix, "xml" ) == 0 &&
+ strcmp( namespaceURI,
+ "http://www.w3.org/XML/1998/namespace" ) != 0 )
+ || ( strcmp( qualifiedName, "xmlns" ) == 0
+ && strcmp( namespaceURI,
+ "http://www.w3.org/2000/xmlns/" ) != 0 ) )
+ {
+ XmlParserFreeNodeContent(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ &newAttrNode );
+ return XML_NAMESPACE_ERR;
+ }
+
+ attrNode = element->node.firstAttr;
+ while ( attrNode != NULL )
+ {
+ if ( strcmp( attrNode->localName, newAttrNode.localName ) == 0 &&
+ strcmp( attrNode->namespaceURI, namespaceURI ) == 0 )
+ {
+ break; //found it
+ }
+ else
+ {
+ attrNode = attrNode->nextSibling;
+ }
+ }
+
+ if ( attrNode != NULL )
+ {
+ if ( attrNode->prefix != NULL )
+ {
+ PFREE( attrNode->prefix ); // remove the old prefix
+ }
+ // replace it with the new prefix
+ attrNode->prefix = PSTRDUP( newAttrNode.prefix );
+ if ( attrNode->prefix == NULL )
+ {
+ XmlParserFreeNodeContent(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ &newAttrNode );
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ if ( attrNode->nodeValue != NULL )
+ {
+ PFREE( attrNode->nodeValue );
+ }
+
+ attrNode->nodeValue = XmlStrduptrim(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ value );
+ if ( attrNode->nodeValue == NULL )
+ {
+ PFREE( attrNode->prefix );
+ XmlParserFreeNodeContent(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ &newAttrNode );
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ }
+ else
+ {
+ // add a new attribute
+ rc = XmlDocCreateAttributeNSEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ ( XmlDocument * )
+ element->node.ownerDocument,
+ namespaceURI, qualifiedName,
+ &newAttr );
+ if ( rc != XML_OK )
+ {
+ return rc;
+ }
+
+ newAttr->node.nodeValue = XmlStrduptrim(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ value );
+ if ( newAttr->node.nodeValue == NULL )
+ {
+ XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newAttr );
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ if ( XmlElementSetAttributeNodeNS( element, newAttr, NULL ) !=
+ XML_OK )
+ {
+ XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newAttr );
+ return XML_FAILED;
+ }
+
+ }
+
+ XmlParserFreeNodeContent(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ &newAttrNode );
+ return XML_OK;
+}
+
+/*================================================================
+* XmlElementRemoveAttributeNS
+* Removes an attribute by local name and namespace URI. The replacing
+* attribute has the same namespace URI and local name, as well as
+* the original prefix.
+* External function.
+*
+* Parameters:
+* namespaceURI: the namespace URI of the attribute to remove.
+* localName: the local name of the atribute to remove.
+*
+* Return Value:
+* XML_OK or failure.
+*
+*=================================================================*/
+int
+XmlElementRemoveAttributeNS(
+ Pool * pool,
+ XmlElement * element,
+ const char * namespaceURI,
+ const char * localName )
+{
+ XmlNode * attrNode;
+
+ if ( ( element == NULL ) || ( namespaceURI == NULL )
+ || ( localName == NULL ) )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+
+ attrNode = element->node.firstAttr;
+ while ( attrNode != NULL )
+ {
+ if ( strcmp( attrNode->localName, localName ) == 0 &&
+ strcmp( attrNode->namespaceURI, namespaceURI ) == 0 )
+ {
+ break; //found it
+ }
+ else
+ {
+ attrNode = attrNode->nextSibling;
+ }
+ }
+
+ if ( attrNode != NULL ) // has the attribute
+ {
+ if ( attrNode->nodeValue != NULL )
+ {
+ PFREE( attrNode->nodeValue );
+ attrNode->nodeValue = NULL;
+ }
+ }
+
+ return XML_OK;
+
+}
+
+/*================================================================
+* XmlElementGetAttributeNodeNS
+* Retrieves an attr node by local name and namespace URI.
+* External function.
+*
+* Parameter:
+* namespaceURI: the namespace of the attribute to retrieve.
+* localName: the local name of the attribute to retrieve.
+*
+* Return Value:
+* The attr node with the specified attribute local name and
+* namespace URI or null if there is no such attribute.
+*
+*=================================================================*/
+XmlAttribute *
+XmlElementGetAttributeNodeNS( XmlElement * element,
+ const char * namespaceURI,
+ const char * localName )
+{
+
+ XmlNode * attrNode;
+
+ if ( ( element == NULL ) || ( namespaceURI == NULL )
+ || ( localName == NULL ) )
+ {
+ return NULL;
+ }
+
+ attrNode = element->node.firstAttr;
+ while ( attrNode != NULL )
+ {
+ if ( strcmp( attrNode->localName, localName ) == 0 && strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) // found it
+ {
+ break;
+ }
+ else
+ {
+ attrNode = attrNode->nextSibling;
+ }
+ }
+
+ return ( XmlAttribute * ) attrNode;
+
+}
+
+/*================================================================
+* XmlElementSetAttributeNodeNS
+* Adds a new attribute. If an attribute with that local name and
+* that namespace URI is already present in the element, it is replaced
+* by the new one.
+* External function.
+*
+* Parameter:
+* newAttr: the attr node to add to the attribute list.
+*
+* Return Value:
+* If the newAttr attribute replaces an existing attribute with the
+* same local name and namespace, the replaced attr node is returned,
+* otherwise null is returned.
+*
+*=================================================================*/
+int
+XmlElementSetAttributeNodeNS( XmlElement * element,
+ XmlAttribute * newAttr,
+ OUT XmlAttribute ** rtAttr )
+{
+ XmlNode * attrNode;
+ XmlNode * node;
+ XmlNode * prevAttr = NULL;
+ XmlNode * nextAttr = NULL;
+ XmlNode * preSib;
+ XmlNode * nextSib;
+
+ if ( ( element == NULL ) || ( newAttr == NULL ) )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+
+ if ( newAttr->node.ownerDocument != element->node.ownerDocument )
+ {
+ return XML_WRONG_DOCUMENT_ERR;
+ }
+
+ if ( ( newAttr->ownerElement != NULL )
+ && ( newAttr->ownerElement != element ) )
+ {
+ return XML_INUSE_ATTRIBUTE_ERR;
+ }
+
+ newAttr->ownerElement = element;
+ node = ( XmlNode * ) newAttr;
+
+ attrNode = element->node.firstAttr;
+ while ( attrNode != NULL )
+ {
+ if ( strcmp( attrNode->localName, node->localName ) == 0 &&
+ strcmp( attrNode->namespaceURI, node->namespaceURI ) == 0 )
+ {
+ break; //found it
+ }
+ else
+ {
+ attrNode = attrNode->nextSibling;
+ }
+ }
+
+ if ( attrNode != NULL ) // already present, will replace by newAttr
+ {
+ preSib = attrNode->prevSibling;
+ nextSib = attrNode->nextSibling;
+
+ if ( preSib != NULL )
+ {
+ preSib->nextSibling = node;
+ }
+
+ if ( nextSib != NULL )
+ {
+ nextSib->prevSibling = node;
+ }
+
+ if ( element->node.firstAttr == attrNode )
+ {
+ element->node.firstAttr = node;
+ }
+
+ if ( rtAttr != NULL )
+ {
+ *rtAttr = ( XmlAttribute * ) attrNode;
+ }
+
+ }
+ else // add this attribute
+ {
+ if ( element->node.firstAttr != NULL ) // element has attribute already
+ {
+ prevAttr = element->node.firstAttr;
+ nextAttr = prevAttr->nextSibling;
+ while ( nextAttr != NULL )
+ {
+ prevAttr = nextAttr;
+ nextAttr = prevAttr->nextSibling;
+ }
+ prevAttr->nextSibling = node;
+ }
+ else // this is the first attribute node
+ {
+ element->node.firstAttr = node;
+ node->prevSibling = NULL;
+ node->nextSibling = NULL;
+ }
+
+ if ( rtAttr != NULL )
+ {
+ *rtAttr = NULL;
+ }
+ }
+
+ return XML_OK;
+}
+
+/*================================================================
+* XmlElementGetElementsByTagNameNS
+* Returns a nodeList of all the descendant Elements with a given
+* local name and namespace in the order in which they are encountered
+* in a preorder traversal of the element tree.
+* External function.
+*
+* Parameters:
+* namespaceURI: the namespace URI of the elements to match on. The
+* special value "*" matches all namespaces.
+* localName: the local name of the elements to match on. The special
+* value "*" matches all local names.
+*
+* Return Value:
+* A new nodeList object containing all the matched Elements.
+*
+*=================================================================*/
+XmlNodeList *
+XmlElementGetElementsByTagNameNS(
+ Pool * pool,
+ XmlElement * element,
+ const char * namespaceURI,
+ const char * localName )
+{
+ XmlNode * node = ( XmlNode * ) element;
+ XmlNodeList *nodeList = NULL;
+
+ if ( ( element != NULL ) && ( namespaceURI != NULL )
+ && ( localName != NULL ) )
+ {
+ XmlNodeGetElementsByTagNameNS(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ node, namespaceURI, localName,
+ &nodeList );
+ }
+
+ return nodeList;
+}
+
+/*================================================================
+* XmlElementHasAttribute
+* Returns true when an attribute with a given name is specified on
+* this element, false otherwise.
+* External function.
+*
+* Parameters:
+* name: the name of the attribute to look for.
+*
+* Return Value:
+* ture if an attribute with the given name is specified on this
+* element, false otherwise.
+*
+*=================================================================*/
+BOOL
+XmlElementHasAttribute( XmlElement * element,
+ const char * name )
+{
+
+ XmlNode * attrNode;
+
+ if ( ( element == NULL ) || ( name == NULL ) )
+ {
+ return FALSE;
+ }
+
+ attrNode = element->node.firstAttr;
+ while ( attrNode != NULL )
+ {
+ if ( strcmp( attrNode->nodeName, name ) == 0 )
+ {
+ return TRUE;
+ }
+ else
+ {
+ attrNode = attrNode->nextSibling;
+ }
+ }
+
+ return FALSE;
+}
+
+/*================================================================
+* XmlElementHasAttributeNS
+* Returns true when attribute with a given local name and namespace
+* URI is specified on this element, false otherwise.
+* External function.
+*
+* Parameters:
+* namespaceURI: the namespace URI of the attribute to look for.
+* localName: the local name of the attribute to look for.
+*
+* Return Value:
+* true if an attribute with the given local name and namespace URI
+* is specified, false otherwise.
+*
+*=================================================================*/
+BOOL
+XmlElementHasAttributeNS( XmlElement * element,
+ const char * namespaceURI,
+ const char * localName )
+{
+
+ XmlNode * attrNode;
+
+ if ( ( element == NULL ) || ( namespaceURI == NULL )
+ || ( localName == NULL ) )
+ {
+ return FALSE;
+ }
+
+ attrNode = element->node.firstAttr;
+ while ( attrNode != NULL )
+ {
+ if ( strcmp( attrNode->localName, localName ) == 0 &&
+ strcmp( attrNode->namespaceURI, namespaceURI ) == 0 )
+ {
+ return TRUE;
+ }
+ else
+ {
+ attrNode = attrNode->nextSibling;
+ }
+ }
+
+ return FALSE;
+}
+
+
+/*================================================================
+* XmlElementFree
+* XFREEs a element node.
+* External function.
+*
+*=================================================================*/
+void
+XmlElementFree(
+ Pool * pool,
+ XmlElement * element )
+{
+ if ( element != NULL )
+ {
+ XmlNodeFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ ( XmlNode * ) element );
+ }
+}
diff --git a/ap/app/cwmp/netcwmp/libxmlet/src/inc/xmlbuffer.h b/ap/app/cwmp/netcwmp/libxmlet/src/inc/xmlbuffer.h
new file mode 100755
index 0000000..585005c
--- /dev/null
+++ b/ap/app/cwmp/netcwmp/libxmlet/src/inc/xmlbuffer.h
@@ -0,0 +1,105 @@
+///////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2003 Intel Corporation
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+// * Neither name of Intel Corporation nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. NO EVENT SHALL INTEL OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+// OF LIABILITY, WHETHER CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING ANY WAY OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////
+
+#ifndef CWMP_XML_BUFFER_H
+#define CWMP_XML_BUFFER_H
+
+#include <stdlib.h>
+#include "cwmp/xmlet.h"
+
+#define MINVAL( a, b ) ( (a) < (b) ? (a) : (b) )
+#define MAXVAL( a, b ) ( (a) > (b) ? (a) : (b) )
+
+#define XINLINE inline
+
+#define MEMBUF_DEF_SIZE_INC 1024*4
+
+
+typedef struct // XmlBuffer
+{
+ char *buf;
+
+ size_t length;
+ size_t capacity;
+ size_t size_inc;
+
+} XmlBuffer;
+
+//--------------------------------------------------
+//////////////// functions /////////////////////////
+//--------------------------------------------------
+/*
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+*/
+
+
+void XmlBufferInit(XmlBuffer *m);
+void XmlBufferDestroy(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ XmlBuffer *m);
+
+int XmlBufferAssign(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+
+ XmlBuffer *m, const void *buf,
+ size_t buf_len );
+int XmlBufferAssignString(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+
+ XmlBuffer *m, const char *c_str );
+int XmlBufferAppend(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+
+ XmlBuffer *m, const void *buf);
+int XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ XmlBuffer *m, const char *c_str);
+int XmlBufferInsert(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+
+ XmlBuffer *m, const void* buf,
+ size_t buf_len, int index );
+
+#endif // _CWMP_XML_MEMBUF_H
diff --git a/ap/app/cwmp/netcwmp/libxmlet/src/inc/xmlparser.h b/ap/app/cwmp/netcwmp/libxmlet/src/inc/xmlparser.h
new file mode 100755
index 0000000..5fd73e5
--- /dev/null
+++ b/ap/app/cwmp/netcwmp/libxmlet/src/inc/xmlparser.h
@@ -0,0 +1,202 @@
+///////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2003 Intel Corporation
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+// * Neither name of Intel Corporation nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. NO EVENT SHALL INTEL OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+// OF LIABILITY, WHETHER CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING ANY WAY OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////
+
+#ifndef CWMP_XML_PARSER_H
+#define CWMP_XML_PARSER_H
+
+#include "cwmp/xmlet.h"
+#include "xmlbuffer.h"
+
+// XMLParser definitions
+#define QUOT """
+#define LT "<"
+#define GT ">"
+#define APOS "'"
+#define AMP "&"
+#define ESC_HEX "&#x"
+#define ESC_DEC "&#"
+
+typedef struct XmlNameSpaceURI
+{
+ char *nsURI;
+ char *prefix;
+ struct XmlNameSpaceURI *nextNsURI;
+} XmlNameSpaceURI;
+
+
+typedef struct XmlElementStack
+{
+ char *element;
+ char *prefix;
+ char *namespaceUri;
+ XmlNameSpaceURI *pNsURI;
+ struct XmlElementStack *nextElement;
+} XmlElementStack;
+
+
+typedef enum
+{
+ E_ELEMENT,
+ E_ATTRIBUTE,
+ E_CONTENT,
+} XmlParserState;
+
+typedef struct XmlParser
+{
+ char *dataBuffer; //data buffer
+ char *curPtr; //ptr to the token parsed
+ char *savePtr; //Saves for backup
+ XmlBuffer lastElem;
+ XmlBuffer tokenBuf;
+
+ XmlNode *pNeedPrefixNode;
+ XmlElementStack *pCurElement;
+ XmlNode *currentNodePtr;
+ XmlParserState state;
+
+ BOOL bHasTopLevel;
+
+} XMLParser;
+
+
+
+int XmlParserLoadDocument(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ XmlDocument **retDoc, char * xmlFile, BOOL file);
+BOOL XmlParserIsValidXmlName(const char * name);
+int XmlParserSetNodePrefixAndLocalName(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+
+ XmlNode * node);
+void XmlParserFreeNodeContent(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ XmlNode * node);
+
+void XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+
+ XmlAttribute *attrNode);
+void XmlAttrInit(XmlAttribute *attrNode);
+
+void XmlNamedNodeMapInit(XmlNamedNodeMap *nnMap);
+int XmlNamedNodeMapAddToNamedNodeMap(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+
+ XmlNamedNodeMap **nnMap, XmlNode * add);
+
+void XmlNodeInit(XmlNode * node);
+BOOL XmlNodeCompare(XmlNode * left, XmlNode * right);
+
+void XmlNodeGetElementsByTagName(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ XmlNode * n, char *tagname, XmlNodeList **list);
+void XmlNodeGetElementsByTagNameNS(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ XmlNode * node,const char *namespaceURI,
+ const char *localName, XmlNodeList **list);
+
+int XmlNodeSetNodeProperties(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ XmlNode* node, XmlNode * src);
+
+void XmlNodeListInit(XmlNodeList *nList);
+int XmlNodeListAddToNodeList(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ XmlNodeList **nList, XmlNode * add);
+
+
+
+static char * XmlStrduptrim(Pool * pool, const char * data)
+{
+ char buffer[1024+1] = {0};
+ char * p;
+ char * q;
+
+ int len = 0;
+
+ if (!data)
+ {
+ return NULL;
+ }
+
+ memset(buffer, 0, sizeof(buffer));
+ strncpy(buffer, data, sizeof(buffer)-1);
+ buffer[sizeof(buffer)-1] = '\0';
+
+ len = (strlen(data) < sizeof(buffer)) ? strlen(buffer) : (sizeof(buffer) -1 );
+
+ p = buffer;
+
+ while ((*p <= ' ') && (*p != '\n'))
+ {
+ p ++;
+ }
+
+ // KW 1: use len instead of strlen(data);
+ q = buffer + len;
+ if ((*q == 0) && (q != p))
+ {
+ q --;
+ }
+
+
+ while ((*p <= ' ') && (q != p))
+ {
+ q --;
+ }
+
+ if (q < (buffer + sizeof(buffer) - 1)) //cov
+ *(q+1) = 0;
+
+ return PSTRDUP(p);
+
+}
+
+#endif // _IXMLPARSER_H
+
diff --git a/ap/app/cwmp/netcwmp/libxmlet/src/list.c b/ap/app/cwmp/netcwmp/libxmlet/src/list.c
new file mode 100755
index 0000000..c4ff493
--- /dev/null
+++ b/ap/app/cwmp/netcwmp/libxmlet/src/list.c
@@ -0,0 +1,203 @@
+///////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2003 Intel Corporation
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+// * Neither name of Intel Corporation nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////
+
+#include "xmlparser.h"
+
+/*================================================================
+* XmlNodeListInit
+* initializes a nodelist
+* External function.
+*
+*=================================================================*/
+void
+XmlNodeListInit( XmlNodeList * nList )
+{
+ assert( nList != NULL );
+
+ memset( nList, 0, sizeof( XmlNodeList ) );
+
+}
+
+/*================================================================
+* XmlNodeListItem
+* Returns the indexth item in the collection. If index is greater
+* than or equal to the number of nodes in the list, this returns
+* null.
+* External function.
+*
+*=================================================================*/
+XmlNode *
+XmlNodeListItem( XmlNodeList * nList,
+ unsigned long index )
+{
+ XmlNodeList *next;
+ unsigned int i;
+
+ // if the list ptr is NULL
+ if ( nList == NULL )
+ {
+ return NULL;
+ }
+ // if index is more than list length
+ if ( index > XmlNodeListLength( nList ) - 1 )
+ {
+ return NULL;
+ }
+
+ next = nList;
+ for ( i = 0; i < index && next != NULL; ++i )
+ {
+ next = next->next;
+ }
+
+ if(NULL != next)
+ {
+ return next->nodeItem;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+/*================================================================
+* XmlNodeListAddToNodeList
+* Add a node to nodelist
+* Internal to parser only.
+*
+*=================================================================*/
+int
+
+#ifdef USE_CWMP_MEMORY_POOL
+XmlNodeListAddToNodeList(Pool * pool, XmlNodeList ** nList,
+#else
+XmlNodeListAddToNodeList( XmlNodeList ** nList,
+#endif
+
+ XmlNode * add )
+{
+ XmlNodeList *traverse,
+ *p = NULL;
+ XmlNodeList *newListItem;
+
+// assert( add != NULL );
+
+ if ( add == NULL )
+ {
+ return XML_FAILED;
+ }
+
+ if ( *nList == NULL ) // nodelist is empty
+ {
+ *nList = ( XmlNodeList * ) PMALLOC( sizeof( XmlNodeList ) );
+ if ( *nList == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ XmlNodeListInit( *nList );
+ }
+
+ if ( ( *nList )->nodeItem == NULL )
+ {
+ ( *nList )->nodeItem = add;
+ }
+ else
+ {
+ traverse = *nList;
+ while ( traverse != NULL )
+ {
+ p = traverse;
+ traverse = traverse->next;
+ }
+
+ newListItem =
+ ( XmlNodeList * ) PMALLOC( sizeof( XmlNodeList ) );
+ if ( newListItem == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ p->next = newListItem;
+ newListItem->nodeItem = add;
+ newListItem->next = NULL;
+ }
+
+ return XML_OK;
+}
+
+/*================================================================
+* XmlNodeListLength
+* Returns the number of nodes in the list. The range of valid
+* child node indices is 0 to length-1 inclusive.
+* External function.
+*
+*=================================================================*/
+unsigned long
+XmlNodeListLength( XmlNodeList * nList )
+{
+ XmlNodeList *list;
+ unsigned long length = 0;
+
+ list = nList;
+ while ( list != NULL )
+ {
+ ++length;
+ list = list->next;
+ }
+
+ return length;
+}
+
+/*================================================================
+* XmlNodeListFree
+* XFREEs a nodeList
+* External function
+*
+*=================================================================*/
+void
+XmlNodeListFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ XmlNodeList * nList )
+{
+ XmlNodeList *next;
+
+ while ( nList != NULL )
+ {
+ next = nList->next;
+
+ PFREE( nList );
+ nList = next;
+ }
+
+}
+
diff --git a/ap/app/cwmp/netcwmp/libxmlet/src/namemap.c b/ap/app/cwmp/netcwmp/libxmlet/src/namemap.c
new file mode 100755
index 0000000..94ff513
--- /dev/null
+++ b/ap/app/cwmp/netcwmp/libxmlet/src/namemap.c
@@ -0,0 +1,271 @@
+///////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2003 Intel Corporation
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+// * Neither name of Intel Corporation nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////
+
+#include "xmlparser.h"
+
+/*================================================================
+* NamedNodeMap_getItemNumber
+* return the item number of a item in NamedNodeMap.
+* Internal to parser only.
+* Parameters:
+* name: the name of the item to find
+*
+*=================================================================*/
+unsigned long
+XmlNamedNodeMapGetItemNumber( XmlNamedNodeMap * nnMap,
+ IN char *name )
+{
+ XmlNode * tempNode;
+ unsigned long returnItemNo = 0;
+
+// assert( nnMap != NULL && name != NULL );
+ if ( ( nnMap == NULL ) || ( name == NULL ) )
+ {
+ return XML_INVALID_ITEM_NUMBER;
+ }
+
+ tempNode = nnMap->nodeItem;
+ while ( tempNode != NULL )
+ {
+ if ( strcmp( name, tempNode->nodeName ) == 0 )
+ {
+ return returnItemNo;
+ }
+
+ tempNode = tempNode->nextSibling;
+ returnItemNo++;
+ }
+
+ return XML_INVALID_ITEM_NUMBER;
+}
+
+/*================================================================
+* NamedNodeMap_init
+* Initializes a NamedNodeMap object.
+* External function.
+*
+*=================================================================*/
+void
+XmlNamedNodeMapInit( XmlNamedNodeMap * nnMap )
+{
+ assert( nnMap != NULL );
+ memset( nnMap, 0, sizeof( XmlNamedNodeMap ) );
+}
+
+/*================================================================
+* NamedNodeMap_getNamedItem
+* Retrieves a node specified by name.
+* External function.
+*
+* Parameter:
+* name: type nodeName of a node to retrieve.
+*
+* Return Value:
+* A Node with the specified nodeName, or null if it
+* does not identify any node in this map.
+*
+*=================================================================*/
+XmlNode *
+XmlNamedNodeMapGetNamedItem( XmlNamedNodeMap * nnMap,
+ IN char *name )
+{
+ long index;
+
+ if ( ( nnMap == NULL ) || ( name == NULL ) )
+ {
+ return NULL;
+ }
+
+ index = XmlNamedNodeMapGetItemNumber( nnMap, name );
+ if ( index == XML_INVALID_ITEM_NUMBER )
+ {
+ return NULL;
+ }
+ else
+ {
+ return ( XmlNamedNodeMapItem( nnMap, ( unsigned long )index ) );
+ }
+}
+
+/*================================================================
+* NamedNodeMap_item
+* Returns the indexth item in the map. If index is greater than or
+* equal to the number of nodes in this map, this returns null.
+* External function.
+*
+* Parameter:
+* index: index into this map.
+*
+* Return Value:
+* The node at the indexth position in the map, or null if that is
+* not a valid index.
+*
+*=================================================================*/
+XmlNode *
+XmlNamedNodeMapItem( XmlNamedNodeMap * nnMap,
+ IN unsigned long index )
+{
+ XmlNode * tempNode;
+ unsigned int i;
+
+ if ( nnMap == NULL )
+ {
+ return NULL;
+ }
+
+ if ( index > XmlNamedNodeMapGetLength( nnMap ) - 1 )
+ {
+ return NULL;
+ }
+
+ tempNode = nnMap->nodeItem;
+ for ( i = 0; i < index && tempNode != NULL; ++i )
+ {
+ tempNode = tempNode->nextSibling;
+ }
+
+ return tempNode;
+}
+
+/*================================================================
+* NamedNodeMap_getLength
+* Return the number of Nodes in this map.
+* External function.
+*
+* Parameters:
+*
+*=================================================================*/
+unsigned long
+XmlNamedNodeMapGetLength( XmlNamedNodeMap * nnMap )
+{
+ XmlNode * tempNode;
+ unsigned long length = 0;
+
+ if ( nnMap != NULL )
+ {
+ tempNode = nnMap->nodeItem;
+ for ( length = 0; tempNode != NULL; ++length )
+ {
+ tempNode = tempNode->nextSibling;
+ }
+ }
+ return length;
+}
+
+/*================================================================
+* XmlNamedNodeMapFree
+* XFREEs a NamedNodeMap.
+* External function.
+*
+*=================================================================*/
+void
+XmlNamedNodeMapFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ XmlNamedNodeMap * nnMap )
+{
+ XmlNamedNodeMap *pNext;
+
+ while ( nnMap != NULL )
+ {
+ pNext = nnMap->next;
+ PFREE( nnMap );
+ nnMap = pNext;
+ }
+}
+
+/*================================================================
+* NamedNodeMap_addToNamedNodeMap
+* add a node to a NamedNodeMap.
+* Internal to parser only.
+* Parameters:
+* add: the node to add into NamedNodeMap.
+* Return:
+* XML_OK or failure.
+*
+*=================================================================*/
+int
+XmlNamedNodeMapAddToNamedNodeMap(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ XmlNamedNodeMap ** nnMap,
+ XmlNode * add )
+{
+ XmlNamedNodeMap *traverse = NULL,
+ *p = NULL;
+ XmlNamedNodeMap *newItem = NULL;
+
+ if ( add == NULL )
+ {
+ return XML_OK;
+ }
+
+
+ if ( *nnMap == NULL ) // nodelist is empty
+ {
+ *nnMap =
+ ( XmlNamedNodeMap * ) PMALLOC( sizeof( XmlNamedNodeMap ) );
+ if ( *nnMap == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ XmlNamedNodeMapInit( *nnMap );
+ }
+
+ if ( ( *nnMap )->nodeItem == NULL )
+ {
+ ( *nnMap )->nodeItem = add;
+ }
+ else
+ {
+ traverse = *nnMap;
+ p = traverse;
+ while ( traverse != NULL )
+ {
+ p = traverse;
+ traverse = traverse->next;
+ }
+
+ newItem =
+ ( XmlNamedNodeMap * ) PMALLOC( sizeof( XmlNamedNodeMap ) );
+ if ( newItem == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ p->next = newItem;
+ newItem->nodeItem = add;
+ newItem->next = NULL;
+ }
+
+ return XML_OK;
+}
diff --git a/ap/app/cwmp/netcwmp/libxmlet/src/node.c b/ap/app/cwmp/netcwmp/libxmlet/src/node.c
new file mode 100755
index 0000000..3bb3f8b
--- /dev/null
+++ b/ap/app/cwmp/netcwmp/libxmlet/src/node.c
@@ -0,0 +1,2173 @@
+///////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2003 Intel Corporation
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+// * Neither name of Intel Corporation nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////
+
+#include "xmlparser.h"
+
+/*================================================================
+* XmlNodeInit
+* Intializes a node.
+* External function.
+*
+*=================================================================*/
+void
+XmlNodeInit( XmlNode * nodeptr )
+{
+ assert( nodeptr != NULL );
+ memset( nodeptr, 0, sizeof( XmlNode ) );
+
+}
+
+/*================================================================
+* XmlCDATASectionInit
+* Initializes a CDATASection node.
+* External function.
+*
+*=================================================================*/
+void
+XmlCDATASectionInit( XmlCDATASection * nodeptr )
+{
+ memset( nodeptr, 0, sizeof( XmlCDATASection ) );
+}
+
+/*================================================================
+* XmlCDATASectionFree
+* XFREEs a CDATASection node.
+* External function.
+*
+*=================================================================*/
+void
+XmlCDATASectionFree(
+ Pool * pool,
+ XmlCDATASection * nodeptr )
+{
+ if ( nodeptr != NULL )
+ {
+ XmlNodeFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ ( XmlNode * ) nodeptr );
+ }
+}
+
+/*================================================================
+* XmlNodeFreeSingleNode
+* XFREEs a node content.
+* Internal to parser only.
+*
+*=================================================================*/
+void
+XmlNodeFreeSingleNode(
+ Pool * pool,
+ XmlNode * nodeptr )
+{
+ XmlElement *element = NULL;
+
+ if ( nodeptr != NULL )
+ {
+
+ if ( nodeptr->nodeName != NULL )
+ {
+ PFREE( nodeptr->nodeName );
+ }
+
+ if ( nodeptr->nodeValue != NULL )
+ {
+ PFREE( nodeptr->nodeValue );
+ }
+
+ if ( nodeptr->namespaceURI != NULL )
+ {
+ PFREE( nodeptr->namespaceURI );
+ }
+
+ if ( nodeptr->prefix != NULL )
+ {
+ PFREE( nodeptr->prefix );
+ }
+
+ if ( nodeptr->localName != NULL )
+ {
+ PFREE( nodeptr->localName );
+ }
+
+ if ( nodeptr->nodeType == XML_ELEMENT_NODE )
+ {
+ element = ( XmlElement * ) nodeptr;
+ PFREE( element->tagName );
+ }
+
+ PFREE( nodeptr );
+
+ }
+}
+
+/*================================================================
+* XmlNodeFree
+* Frees all nodes under nodeptr subtree.
+* External function.
+*
+*=================================================================*/
+void
+XmlNodeFree(
+
+
+ Pool * pool,
+ XmlNode * nodeptr )
+{
+ if ( nodeptr != NULL )
+ {
+ XmlNodeFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ nodeptr->firstChild );
+ XmlNodeFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ nodeptr->nextSibling );
+ XmlNodeFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ nodeptr->firstAttr );
+
+ XmlNodeFreeSingleNode(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ nodeptr );
+ }
+}
+
+/*================================================================
+* XmlNodeGetNodeName
+* Returns the nodename(the qualified name)
+* External function.
+*
+*=================================================================*/
+const char *
+XmlNodeGetNodeName( XmlNode * nodeptr )
+{
+
+ if ( nodeptr != NULL )
+ {
+ return ( nodeptr->nodeName );
+ }
+
+ return NULL;
+}
+
+/*================================================================
+* XmlNodeGetLocalName
+* Returns the node local name
+* External function.
+*
+*=================================================================*/
+const char *
+XmlNodeGetLocalName( XmlNode * nodeptr )
+{
+
+ if ( nodeptr != NULL )
+ {
+ return ( nodeptr->localName );
+ }
+
+ return NULL;
+}
+
+/*================================================================
+* XmlNodeSetNamespaceURI
+* sets the namespace URI of the node.
+* Internal function.
+* Return:
+* XML_OK or failure
+*
+*=================================================================*/
+int
+XmlNodeSetNamespaceURI(
+ Pool * pool,
+ XmlNode * nodeptr,
+ IN char *namespaceURI )
+{
+
+ if ( nodeptr == NULL )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+
+ if ( nodeptr->namespaceURI != NULL )
+ {
+ PFREE( nodeptr->namespaceURI );
+ nodeptr->namespaceURI = NULL;
+ }
+
+ if ( namespaceURI != NULL )
+ {
+ nodeptr->namespaceURI = PSTRDUP( namespaceURI );
+ if ( nodeptr->namespaceURI == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+
+ return XML_OK;
+}
+
+/*================================================================
+* XmlNodeSetPrefix
+* set the prefix of the node.
+* Internal to parser only.
+* Returns:
+* XML_OK or failure.
+*
+*=================================================================*/
+int
+XmlNodeSetPrefix(
+ Pool * pool,
+ XmlNode * nodeptr,
+ IN char *prefix )
+{
+
+ if ( nodeptr == NULL )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+
+ if ( nodeptr->prefix != NULL )
+ {
+ PFREE( nodeptr->prefix );
+ nodeptr->prefix = NULL;
+ }
+
+ if ( prefix != NULL )
+ {
+ nodeptr->prefix = PSTRDUP( prefix );
+ if ( nodeptr->prefix == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+
+ return XML_OK;
+
+}
+
+/*================================================================
+* XmlNodeSetLocalName
+* set the localName of the node.
+* Internal to parser only.
+* Returns:
+* XML_OK or failure.
+*
+*=================================================================*/
+int
+XmlNodeSetLocalName(
+ Pool * pool,
+ XmlNode * nodeptr,
+ IN char *localName )
+{
+
+ assert( nodeptr != NULL );
+
+ if ( nodeptr->localName != NULL )
+ {
+ PFREE( nodeptr->localName );
+ nodeptr->localName = NULL;
+ }
+
+ if ( localName != NULL )
+ {
+ nodeptr->localName = PSTRDUP( localName );
+ if ( nodeptr->localName == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+
+ return XML_OK;
+}
+
+/*================================================================
+* XmlNodeGetNodeNamespaceURI
+* Returns the node namespaceURI
+* External function.
+* Returns:
+* the namespaceURI of the node
+*
+*=================================================================*/
+const char *
+XmlNodeGetNamespaceURI( XmlNode * nodeptr )
+{
+ char * retNamespaceURI = NULL;
+
+ if ( nodeptr != NULL )
+ {
+ retNamespaceURI = nodeptr->namespaceURI;
+ }
+
+ return retNamespaceURI;
+}
+
+/*================================================================
+* XmlNodeGetPrefix
+* Returns the node prefix
+* External function.
+* Returns:
+* the prefix of the node.
+*
+*=================================================================*/
+char *
+XmlNodeGetPrefix( XmlNode * nodeptr )
+{
+ char * prefix = NULL;
+
+ if ( nodeptr != NULL )
+ {
+ prefix = nodeptr->prefix;
+ }
+
+ return prefix;
+
+}
+
+/*================================================================
+* XmlNodeGetNodeValue
+* Returns the nodeValue of this node
+* External function.
+* Return:
+* the nodeValue of the node.
+*
+*=================================================================*/
+char *
+XmlNodeGetNodeValue( XmlNode * nodeptr )
+{
+
+ if ( nodeptr != NULL )
+ {
+ return ( nodeptr->nodeValue );
+ }
+
+ return NULL;
+}
+
+/*================================================================
+* XmlNodeSetNodeValue
+* Sets the nodeValue
+* Internal function.
+* Returns:
+* XML_OK or failure
+*
+*=================================================================*/
+int
+XmlNodeSetNodeValue(
+ Pool * pool,
+ XmlNode * nodeptr,
+ const char *newNodeValue )
+{
+ int rc = XML_OK;
+
+ if ( nodeptr == NULL )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+
+ if ( nodeptr->nodeValue != NULL )
+ {
+ PFREE( nodeptr->nodeValue );
+ nodeptr->nodeValue = NULL;
+ }
+
+ if ( newNodeValue != NULL )
+ {
+ nodeptr->nodeValue = XmlStrduptrim(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newNodeValue );
+ if ( nodeptr->nodeValue == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+
+ return rc;
+}
+
+/*================================================================
+* XmlNodeGetNodeType
+* Gets the NodeType of this node
+* External function.
+*
+*=================================================================*/
+int
+XmlNodeGetNodeType( XmlNode * nodeptr )
+{
+ if ( nodeptr != NULL )
+ {
+ return ( nodeptr->nodeType );
+ }
+ else
+ {
+ return ( XML_INVALID_NODE );
+ }
+}
+
+/*================================================================
+* XmlNodeGetParentNode
+* Get the parent node
+* External function.
+* Return:
+*
+*=================================================================*/
+XmlNode *
+XmlNodeGetParentNode( XmlNode * nodeptr )
+{
+
+ if ( nodeptr != NULL )
+ {
+ return nodeptr->parentNode;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+/*================================================================
+* XmlNodeGetFirstChild
+* Returns the first child of nodeptr.
+* External function.
+*
+*=================================================================*/
+XmlNode *
+XmlNodeGetFirstChild( XmlNode * nodeptr )
+{
+ if ( nodeptr != NULL )
+ {
+ return nodeptr->firstChild;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+/*================================================================
+* XmlNodeGetLastChild
+* Returns the last child of nodeptr.
+* External function.
+*
+*=================================================================*/
+XmlNode *
+XmlNodeGetLastChild( XmlNode * nodeptr )
+{
+ XmlNode * prev;
+ XmlNode * next;
+
+ if ( nodeptr != NULL )
+ {
+ prev = nodeptr;
+ next = nodeptr->firstChild;
+
+ while ( next != NULL )
+ {
+ prev = next;
+ next = next->nextSibling;
+ }
+ return prev;
+ }
+ else
+ {
+ return NULL;
+ }
+
+}
+
+/*================================================================
+* XmlNodeGetPreviousSibling
+* returns the previous sibling node of nodeptr.
+* External function.
+*
+*=================================================================*/
+XmlNode *
+XmlNodeGetPreviousSibling( XmlNode * nodeptr )
+{
+ if ( nodeptr != NULL )
+ {
+ return nodeptr->prevSibling;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+/*================================================================
+* XmlNodeGetNextSibling
+* Returns the next sibling node.
+* External function.
+*
+*=================================================================*/
+XmlNode *
+XmlNodeGetNextSibling( XmlNode * nodeptr )
+{
+
+ if ( nodeptr != NULL )
+ {
+ return nodeptr->nextSibling;
+ }
+ else
+ {
+ return NULL;
+ }
+
+}
+
+/*================================================================
+* XmlNodeGetOwnerDocument
+* Returns the owner document node.
+* External function.
+*
+*=================================================================*/
+XmlDocument *
+XmlNodeGetOwnerDocument( XmlNode * nodeptr )
+{
+ if ( nodeptr != NULL )
+ {
+ return ( XmlDocument * ) nodeptr->ownerDocument;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+/*================================================================
+* XmlNodeIsAncestor
+* check if ancestorNode is ancestor of toFind
+* Internal to parser only.
+* Returns:
+* TRUE or FALSE
+*
+*=================================================================*/
+BOOL
+XmlNodeIsAncestor( XmlNode * ancestorNode,
+ XmlNode * toFind )
+{
+
+ BOOL found = FALSE;
+
+ if ( ( ancestorNode != NULL ) && ( toFind != NULL ) )
+ {
+ if ( toFind->parentNode == ancestorNode )
+ {
+ return TRUE;
+ }
+ else
+ {
+ found =
+ XmlNodeIsAncestor( ancestorNode->firstChild, toFind );
+ if ( found == FALSE )
+ {
+ found =
+ XmlNodeIsAncestor( ancestorNode->nextSibling,
+ toFind );
+ }
+ }
+ }
+
+ return found;
+}
+
+/*================================================================
+* XmlNodeIsParent
+* Check whether toFind is a children of nodeptr.
+* Internal to parser only.
+* Return:
+* TRUE or FALSE
+*
+*=================================================================*/
+BOOL
+XmlNodeIsParent( XmlNode * nodeptr,
+ XmlNode * toFind )
+{
+ BOOL found = FALSE;
+
+ assert( nodeptr != NULL && toFind != NULL );
+ if ( toFind->parentNode == nodeptr )
+ {
+ found = TRUE;
+ }
+
+ return found;
+}
+
+/*================================================================
+* XmlNodeAllowChildren
+* Check to see whether nodeptr allows children of type newChild.
+* Internal to parser only.
+* Returns:
+* TRUE, if nodeptr can have newChild as children
+* FALSE,if nodeptr cannot have newChild as children
+*
+*=================================================================*/
+BOOL
+XmlNodeAllowChildren( XmlNode * nodeptr,
+ XmlNode * newChild )
+{
+
+ assert( nodeptr != NULL && newChild != NULL );
+ switch ( nodeptr->nodeType )
+ {
+ case XML_ATTRIBUTE_NODE:
+ case XML_TEXT_NODE:
+ case XML_CDATA_SECTION_NODE:
+ return FALSE;
+ break;
+
+ case XML_ELEMENT_NODE:
+ if ( ( newChild->nodeType == XML_ATTRIBUTE_NODE ) ||
+ ( newChild->nodeType == XML_DOCUMENT_NODE ) )
+ {
+ return FALSE;
+ }
+ break;
+
+ case XML_DOCUMENT_NODE:
+ if ( newChild->nodeType != XML_ELEMENT_NODE )
+ {
+ return FALSE;
+ }
+
+ default:
+ break;
+ }
+
+ return TRUE;
+}
+
+/*================================================================
+* XmlNodeCompare
+* Compare two nodes to see whether they are the same node.
+* Parent, sibling and children node are ignored.
+* Internal to parser only.
+* Returns:
+* TRUE, the two nodes are the same.
+* FALSE, the two nodes are not the same.
+*
+*=================================================================*/
+BOOL
+XmlNodeCompare( XmlNode * srcNode,
+ XmlNode * destNode )
+{
+ assert( srcNode != NULL && destNode != NULL );
+ if ( ( srcNode == destNode ) ||
+ ( strcmp( srcNode->nodeName, destNode->nodeName ) == 0 &&
+ strcmp( srcNode->nodeValue, destNode->nodeValue ) == 0 &&
+ ( srcNode->nodeType == destNode->nodeType ) &&
+ strcmp( srcNode->namespaceURI, destNode->namespaceURI ) == 0 &&
+ strcmp( srcNode->prefix, destNode->prefix ) == 0 &&
+ strcmp( srcNode->localName, destNode->localName ) == 0 ) )
+ {
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+/*================================================================
+* XmlNodeInsertBefore
+* Inserts the node newChild before the existing child node refChild.
+* If refChild is null, insert newChild at the end of the list of
+* children. If the newChild is already in the tree, it is first
+* removed.
+* External function.
+* Parameters:
+* newChild: the node to insert.
+* Returns:
+*
+*=================================================================*/
+int
+XmlNodeInsertBefore( XmlNode * nodeptr,
+ XmlNode * newChild,
+ XmlNode * refChild )
+{
+
+ int ret = XML_OK;
+
+ if ( ( nodeptr == NULL ) || ( newChild == NULL ) )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+ // whether nodeptr allow children of the type of newChild
+ if ( XmlNodeAllowChildren( nodeptr, newChild ) == FALSE )
+ {
+ return XML_HIERARCHY_REQUEST_ERR;
+ }
+ // or if newChild is one of nodeptr's ancestors
+ if ( XmlNodeIsAncestor( newChild, nodeptr ) == TRUE )
+ {
+ return XML_HIERARCHY_REQUEST_ERR;
+ }
+ // if newChild was created from a different document
+ if ( nodeptr->ownerDocument != newChild->ownerDocument )
+ {
+ return XML_WRONG_DOCUMENT_ERR;
+ }
+ // if refChild is not a child of nodeptr
+ if ( XmlNodeIsParent( nodeptr, refChild ) == FALSE )
+ {
+ return XML_NOT_FOUND_ERR;
+ }
+
+ if ( refChild != NULL )
+ {
+ if ( XmlNodeIsParent( nodeptr, newChild ) == TRUE )
+ {
+ XmlNodeRemoveChild( nodeptr, newChild, NULL );
+ newChild->nextSibling = NULL;
+ newChild->prevSibling = NULL;
+ }
+
+ newChild->nextSibling = refChild;
+ if ( refChild->prevSibling != NULL )
+ {
+ ( refChild->prevSibling )->nextSibling = newChild;
+ newChild->prevSibling = refChild->prevSibling;
+ }
+
+ refChild->prevSibling = newChild;
+
+ if ( newChild->prevSibling == NULL )
+ {
+ nodeptr->firstChild = newChild;
+ }
+
+ newChild->parentNode = nodeptr;
+
+ }
+ else
+ {
+ ret = XmlNodeAppendChild( nodeptr, newChild );
+ }
+
+ return ret;
+}
+
+/*================================================================
+* XmlNodeReplaceChild
+* Replaces the child node oldChild with newChild in the list of children,
+* and returns the oldChild node.
+* External function.
+* Parameters:
+* newChild: the new node to put in the child list.
+* oldChild: the node being replaced in the list.
+* returnNode: the node replaced.
+* Return Value:
+* XML_OK
+* XML_INVALID_PARAMETER: if anyone of nodeptr, newChild or oldChild is NULL.
+* XML_HIERARCHY_REQUEST_ERR: if the newChild is ancestor of nodeptr or nodeptr
+* is of a type that does not allow children of the
+* type of the newChild node.
+* XML_WRONG_DOCUMENT_ERR: if newChild was created from a different document than
+* the one that created this node.
+* XML_NOT_FOUND_ERR: if oldChild is not a child of nodeptr.
+*
+*=================================================================*/
+int
+XmlNodeReplaceChild( XmlNode * nodeptr,
+ XmlNode * newChild,
+ XmlNode * oldChild,
+ OUT XmlNode ** returnNode )
+{
+ int ret = XML_OK;
+
+ if ( ( nodeptr == NULL ) || ( newChild == NULL )
+ || ( oldChild == NULL ) )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+ // if nodetype of nodeptr does not allow children of the type of newChild
+ // needs to add later
+
+ // or if newChild is one of nodeptr's ancestors
+ if ( XmlNodeIsAncestor( newChild, nodeptr ) == TRUE )
+ {
+ return XML_HIERARCHY_REQUEST_ERR;
+ }
+
+ if ( XmlNodeAllowChildren( nodeptr, newChild ) == FALSE )
+ {
+ return XML_HIERARCHY_REQUEST_ERR;
+ }
+ // if newChild was created from a different document
+ if ( nodeptr->ownerDocument != newChild->ownerDocument )
+ {
+ return XML_WRONG_DOCUMENT_ERR;
+ }
+ // if refChild is not a child of nodeptr
+ if ( XmlNodeIsParent( nodeptr, oldChild ) != TRUE )
+ {
+ return XML_NOT_FOUND_ERR;
+ }
+
+ ret = XmlNodeInsertBefore( nodeptr, newChild, oldChild );
+ if ( ret != XML_OK )
+ {
+ return ret;
+ }
+
+ ret = XmlNodeRemoveChild( nodeptr, oldChild, returnNode );
+ return ret;
+}
+
+/*================================================================
+* XmlNodeRemoveChild
+* Removes the child node indicated by oldChild from the list of
+* children, and returns it.
+* External function.
+* Parameters:
+* oldChild: the node being removed.
+* returnNode: the node removed.
+* Return Value:
+* XML_OK
+* XML_NOT_FOUND_ERR: if oldChild is not a child of this node.
+* XML_INVALID_PARAMETER: if either oldChild or nodeptr is NULL
+*
+*=================================================================*/
+int
+XmlNodeRemoveChild( XmlNode * nodeptr,
+ XmlNode * oldChild,
+ OUT XmlNode ** returnNode )
+{
+
+ if ( ( nodeptr == NULL ) || ( oldChild == NULL ) )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+
+ if ( XmlNodeIsParent( nodeptr, oldChild ) == FALSE )
+ {
+ return XML_NOT_FOUND_ERR;
+ }
+
+ if ( oldChild->prevSibling != NULL )
+ {
+ ( oldChild->prevSibling )->nextSibling = oldChild->nextSibling;
+ }
+
+ if ( nodeptr->firstChild == oldChild )
+ {
+ nodeptr->firstChild = oldChild->nextSibling;
+ }
+
+ if ( oldChild->nextSibling != NULL )
+ {
+ ( oldChild->nextSibling )->prevSibling = oldChild->prevSibling;
+ }
+
+ oldChild->nextSibling = NULL;
+ oldChild->prevSibling = NULL;
+ oldChild->parentNode = NULL;
+
+ if ( returnNode != NULL )
+ {
+ *returnNode = oldChild;
+ }
+ return XML_OK;
+}
+
+/*========================================================================================
+* XmlNodeAppendChild
+* Adds the node newChild to the end of the list of children of this node.
+* If the newChild is already in the tree, it is first removed.
+* External function.
+* Parameter:
+* newChild: the node to add.
+* Return Value:
+* XML_OK
+* XML_INVALID_PARAMETER: if either nodeptr or newChild is NULL
+* XML_WRONG_DOCUMENT_ERR: if newChild was created from a different document than
+* the one that created nodeptr.
+* XML_HIERARCHY_REQUEST_ERR: if newChild is ancestor of nodeptr or if nodeptr is of
+* a type that does not allow children of the type of the
+* newChild node.
+*
+*========================================================================================*/
+int
+XmlNodeAppendChild( XmlNode * nodeptr,
+ XmlNode * newChild )
+{
+
+ XmlNode * prev = NULL;
+ XmlNode * next = NULL;
+
+
+ if ( ( nodeptr == NULL ) || ( newChild == NULL ) )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+ // if newChild was created from a different document
+ if ( ( newChild->ownerDocument != NULL ) &&
+ ( nodeptr->ownerDocument != newChild->ownerDocument ) )
+ {
+ return XML_WRONG_DOCUMENT_ERR;
+ }
+ // if newChild is an ancestor of nodeptr
+ if ( XmlNodeIsAncestor( newChild, nodeptr ) == TRUE )
+ {
+ return XML_HIERARCHY_REQUEST_ERR;
+ }
+ // if nodeptr does not allow to have newChild as children
+ if ( XmlNodeAllowChildren( nodeptr, newChild ) == FALSE )
+ {
+ return XML_HIERARCHY_REQUEST_ERR;
+ }
+
+ if ( XmlNodeIsParent( nodeptr, newChild ) == TRUE )
+ {
+ XmlNodeRemoveChild( nodeptr, newChild, NULL );
+ }
+ // set the parent node pointer
+ newChild->parentNode = nodeptr;
+ newChild->ownerDocument = nodeptr->ownerDocument;
+
+ //if the first child
+ if ( nodeptr->firstChild == NULL )
+ {
+ nodeptr->firstChild = newChild;
+ }
+ else
+ {
+ prev = nodeptr->firstChild;
+ next = prev->nextSibling;
+ while ( next != NULL )
+ {
+ prev = next;
+ next = prev->nextSibling;
+ }
+ prev->nextSibling = newChild;
+ newChild->prevSibling = prev;
+ }
+
+
+ return XML_OK;
+}
+
+/*================================================================
+* XmlNodeCloneTextNode
+* Returns a clone of nodeptr
+* Internal to parser only.
+*
+*=================================================================*/
+XmlNode *
+#ifdef USE_CWMP_MEMORY_POOL
+XmlNodeCloneTextNode(Pool * pool, XmlNode * nodeptr )
+#else
+XmlNodeCloneTextNode( XmlNode * nodeptr )
+#endif
+
+{
+ XmlNode * newNode = NULL;
+
+ assert( nodeptr != NULL );
+
+ newNode = ( XmlNode * ) PMALLOC( sizeof( XmlNode ) );
+ if ( newNode == NULL )
+ {
+ return NULL;
+ }
+ else
+ {
+ XmlNodeInit( newNode );
+
+ XmlNodeSetNodeName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ newNode, nodeptr->nodeName );
+ XmlNodeSetNodeValue(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newNode, nodeptr->nodeValue );
+ newNode->nodeType = XML_TEXT_NODE;
+ }
+
+ return newNode;
+}
+
+/*================================================================
+* XmlNodeCloneCDATASect
+* Return a clone of CDATASection node.
+* Internal to parser only.
+*
+*=================================================================*/
+XmlCDATASection *
+#ifdef USE_CWMP_MEMORY_POOL
+XmlNodeCloneCDATASect(Pool * pool, XmlCDATASection * nodeptr )
+#else
+XmlNodeCloneCDATASect( XmlCDATASection * nodeptr )
+#endif
+
+{
+ XmlCDATASection *newCDATA = NULL;
+ XmlNode * newNode;
+ XmlNode * srcNode;
+
+ assert( nodeptr != NULL );
+ newCDATA =
+ ( XmlCDATASection * ) PMALLOC( sizeof( XmlCDATASection ) );
+ if ( newCDATA != NULL )
+ {
+ newNode = ( XmlNode * ) newCDATA;
+ XmlNodeInit( newNode );
+
+ srcNode = ( XmlNode * ) nodeptr;
+ XmlNodeSetNodeName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newNode, srcNode->nodeName );
+ XmlNodeSetNodeValue(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newNode, srcNode->nodeValue );
+ newNode->nodeType = XML_CDATA_SECTION_NODE;
+ }
+
+ return newCDATA;
+}
+
+/*================================================================
+* XmlNodeCloneElement
+* returns a clone of element node
+* Internal to parser only.
+*
+*=================================================================*/
+XmlElement *
+#ifdef USE_CWMP_MEMORY_POOL
+XmlNodeCloneElement(Pool * pool, XmlElement * nodeptr )
+#else
+XmlNodeCloneElement( XmlElement * nodeptr )
+#endif
+
+{
+ XmlElement *newElement;
+ XmlNode * elementNode;
+ XmlNode * srcNode;
+ int rc;
+
+ assert( nodeptr != NULL );
+
+ newElement = ( XmlElement * ) PMALLOC( sizeof( XmlElement ) );
+ if ( newElement == NULL )
+ {
+ return NULL;
+ }
+
+ XmlElementInit( newElement );
+ rc = XmlElementSetTagName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newElement, nodeptr->tagName );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandle;
+ }
+
+ elementNode = ( XmlNode * ) newElement;
+ srcNode = ( XmlNode * ) nodeptr;
+ rc = XmlNodeSetNodeName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ elementNode, srcNode->nodeName );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandle;
+ }
+
+ rc = XmlNodeSetNodeValue(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ elementNode, srcNode->nodeValue );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandle;
+ }
+
+ rc = XmlNodeSetNamespaceURI(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ elementNode, srcNode->namespaceURI );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandle;
+ }
+
+ rc = XmlNodeSetPrefix(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ elementNode, srcNode->prefix );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandle;
+ }
+
+ rc = XmlNodeSetLocalName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ elementNode, srcNode->localName );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandle;
+ }
+
+ elementNode->nodeType = XML_ELEMENT_NODE;
+
+ return newElement;
+
+ErrorHandle:
+ XmlElementFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newElement );
+
+ return NULL;
+
+}
+
+/*================================================================
+* XmlNodeCloneDoc
+* Returns a clone of document node
+* Internal to parser only.
+*
+*=================================================================*/
+XmlDocument *
+#ifdef USE_CWMP_MEMORY_POOL
+XmlNodeCloneDoc(Pool * pool, XmlDocument * nodeptr)
+#else
+XmlNodeCloneDoc(XmlDocument * nodeptr)
+#endif
+{
+ XmlDocument *newDoc;
+ XmlNode * docNode;
+ int rc;
+
+ assert( nodeptr != NULL );
+ newDoc = ( XmlDocument * ) PMALLOC( sizeof( XmlDocument ) );
+ if ( newDoc == NULL )
+ {
+ return NULL;
+ }
+
+ XmlDocumentInit( newDoc );
+ docNode = ( XmlNode * ) newDoc;
+
+ rc = XmlNodeSetNodeName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ docNode, DOCUMENTNODENAME );
+ if ( rc != XML_OK )
+ {
+ XmlDocumentFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newDoc );
+ return NULL;
+ }
+
+ newDoc->node.nodeType = XML_DOCUMENT_NODE;
+
+ return newDoc;
+
+}
+
+/*================================================================
+* XmlNodeCloneAttr
+* Returns a clone of attribute node
+* Internal to parser only
+*
+*=================================================================*/
+XmlAttribute *
+#ifdef USE_CWMP_MEMORY_POOL
+XmlNodeCloneAttr(Pool * pool, XmlAttribute * nodeptr )
+#else
+XmlNodeCloneAttr( XmlAttribute * nodeptr )
+#endif
+{
+ XmlAttribute *newAttr;
+ XmlNode * attrNode;
+ XmlNode * srcNode;
+ int rc;
+
+ assert( nodeptr != NULL );
+ newAttr = ( XmlAttribute * ) PMALLOC( sizeof( XmlAttribute ) );
+ if ( newAttr == NULL )
+ {
+ return NULL;
+ }
+
+ XmlAttrInit( newAttr );
+ attrNode = ( XmlNode * ) newAttr;
+ srcNode = ( XmlNode * ) nodeptr;
+
+ rc = XmlNodeSetNodeName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ attrNode, srcNode->nodeName );
+ if ( rc != XML_OK )
+ {
+ XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ newAttr );
+ return NULL;
+ }
+
+ rc = XmlNodeSetNodeValue(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ attrNode, srcNode->nodeValue );
+ if ( rc != XML_OK )
+ {
+ XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newAttr );
+ return NULL;
+ }
+ //check to see whether we need to split prefix and localname for attribute
+ rc = XmlNodeSetNamespaceURI(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ attrNode, srcNode->namespaceURI );
+ if ( rc != XML_OK )
+ {
+ XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newAttr );
+ return NULL;
+ }
+
+ rc = XmlNodeSetPrefix(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ attrNode, srcNode->prefix );
+ if ( rc != XML_OK )
+ {
+ XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newAttr );
+ return NULL;
+ }
+
+ rc = XmlNodeSetLocalName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ attrNode, srcNode->localName );
+ if ( rc != XML_OK )
+ {
+ XmlAttrFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newAttr );
+ return NULL;
+ }
+
+ attrNode->nodeType = XML_ATTRIBUTE_NODE;
+
+ return newAttr;
+}
+
+/*================================================================
+* XmlNodeCloneAttrDirect
+* Return a clone of attribute node, with specified field set
+* to TRUE.
+*
+*=================================================================*/
+XmlAttribute *
+XmlNodeCloneAttrDirect(
+ Pool * pool,
+
+ XmlAttribute * nodeptr )
+{
+
+ XmlAttribute *newAttr;
+
+ assert( nodeptr != NULL );
+
+ newAttr = XmlNodeCloneAttr(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ nodeptr );
+ if ( newAttr != NULL )
+ {
+ newAttr->specified = TRUE;
+ }
+
+ return newAttr;
+}
+
+void
+XmlNodeSetSiblingNodesParent( XmlNode * nodeptr )
+{
+ XmlNode * parentNode = nodeptr->parentNode;
+ XmlNode * nextptr = nodeptr->nextSibling;
+
+ while ( nextptr != NULL )
+ {
+ nextptr->parentNode = parentNode;
+ nextptr = nextptr->nextSibling;
+ }
+}
+
+/*================================================================
+* XmlNodeCloneNodeTreeRecursive
+* recursive functions that clones node tree of nodeptr.
+* Internal to parser only.
+*
+*=================================================================*/
+XmlNode *
+XmlNodeCloneNodeTreeRecursive(
+ Pool * pool,
+
+ XmlNode * nodeptr,
+ IN BOOL deep )
+{
+ XmlNode * newNode = NULL;
+ XmlElement *newElement;
+ XmlAttribute *newAttr = NULL;
+ XmlCDATASection *newCDATA = NULL;
+ XmlDocument *newDoc;
+ XmlNode * nextSib;
+
+ if ( nodeptr != NULL )
+ {
+ switch ( nodeptr->nodeType )
+ {
+ case XML_ELEMENT_NODE:
+ newElement =
+ XmlNodeCloneElement(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ ( XmlElement * ) nodeptr );
+ if(NULL == newElement)
+ {
+ return NULL;
+ }
+
+ newElement->node.firstAttr =
+ XmlNodeCloneNodeTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ nodeptr->firstAttr,
+ deep );
+ if ( deep )
+ {
+ newElement->node.firstChild =
+ XmlNodeCloneNodeTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ nodeptr->
+ firstChild,
+ deep );
+ if ( newElement->node.firstChild != NULL )
+ {
+ ( newElement->node.firstChild )->parentNode =
+ ( XmlNode * ) newElement;
+ XmlNodeSetSiblingNodesParent( newElement->node.
+ firstChild );
+ }
+ nextSib =
+ XmlNodeCloneNodeTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ nodeptr->
+ nextSibling,
+ deep );
+ newElement->node.nextSibling = nextSib;
+ if ( nextSib != NULL )
+ {
+ nextSib->prevSibling = ( XmlNode * ) newElement;
+ }
+ }
+
+ newNode = ( XmlNode * ) newElement;
+ break;
+
+ case XML_ATTRIBUTE_NODE:
+ newAttr = XmlNodeCloneAttr(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ ( XmlAttribute * ) nodeptr );
+ if(NULL == newAttr)
+ {
+ return NULL;
+ }
+
+
+ nextSib =
+ XmlNodeCloneNodeTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ nodeptr->nextSibling,
+ deep );
+ newAttr->node.nextSibling = nextSib;
+
+ if ( nextSib != NULL )
+ {
+ nextSib->prevSibling = ( XmlNode * ) newAttr;
+ }
+ newNode = ( XmlNode * ) newAttr;
+ break;
+
+ case XML_TEXT_NODE:
+ newNode = XmlNodeCloneTextNode(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ nodeptr );
+ break;
+
+ case XML_CDATA_SECTION_NODE:
+ newCDATA =
+ XmlNodeCloneCDATASect(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ ( XmlCDATASection * )
+ nodeptr );
+ newNode = ( XmlNode * ) newCDATA;
+ break;
+
+ case XML_DOCUMENT_NODE:
+ newDoc = XmlNodeCloneDoc(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ ( XmlDocument * ) nodeptr );
+
+ if(NULL == newDoc)
+ {
+ return NULL;
+ }
+
+ newNode = ( XmlNode * ) newDoc;
+ if ( deep )
+ {
+ newNode->firstChild =
+ XmlNodeCloneNodeTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ nodeptr->
+ firstChild,
+ deep );
+ if ( newNode->firstChild != NULL )
+ {
+ newNode->firstChild->parentNode = newNode;
+ }
+ }
+
+ break;
+
+ case XML_INVALID_NODE:
+ case XML_ENTITY_REFERENCE_NODE:
+ case XML_ENTITY_NODE:
+ case XML_PROCESSING_INSTRUCTION_NODE:
+ case XML_COMMENT_NODE:
+ case XML_DOCUMENT_TYPE_NODE:
+ case XML_DOCUMENT_FRAGMENT_NODE:
+ case XML_NOTATION_NODE:
+ break;
+ }
+ }
+
+ return newNode;
+}
+
+/*================================================================
+* XmlNodeCloneNodeTree
+* clones a node tree.
+* Internal to parser only.
+*
+*=================================================================*/
+XmlNode *
+XmlNodeCloneNodeTree(
+ Pool * pool,
+ XmlNode * nodeptr,
+ IN BOOL deep )
+{
+ XmlNode * newNode = NULL;
+ XmlElement *newElement;
+ XmlNode * childNode;
+
+ assert( nodeptr != NULL );
+
+ switch ( nodeptr->nodeType )
+ {
+ case XML_ELEMENT_NODE:
+ newElement =
+ XmlNodeCloneElement(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ ( XmlElement * ) nodeptr );
+
+ if(NULL == newElement)
+ {
+ return NULL;
+ }
+
+ newElement->node.firstAttr =
+ XmlNodeCloneNodeTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ nodeptr->firstAttr,
+ deep );
+ if ( deep )
+ {
+ newElement->node.firstChild =
+ XmlNodeCloneNodeTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ nodeptr->firstChild,
+ deep );
+ childNode = newElement->node.firstChild;
+ while ( childNode != NULL )
+ {
+ childNode->parentNode = ( XmlNode * ) newElement;
+ childNode = childNode->nextSibling;
+ }
+ newElement->node.nextSibling = NULL;
+ }
+
+ newNode = ( XmlNode * ) newElement;
+ break;
+
+ case XML_ATTRIBUTE_NODE:
+ case XML_TEXT_NODE:
+ case XML_CDATA_SECTION_NODE:
+ case XML_DOCUMENT_NODE:
+ newNode = XmlNodeCloneNodeTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ nodeptr, deep );
+ break;
+
+ case XML_INVALID_NODE:
+ case XML_ENTITY_REFERENCE_NODE:
+ case XML_ENTITY_NODE:
+ case XML_PROCESSING_INSTRUCTION_NODE:
+ case XML_COMMENT_NODE:
+ case XML_DOCUMENT_TYPE_NODE:
+ case XML_DOCUMENT_FRAGMENT_NODE:
+ case XML_NOTATION_NODE:
+ break;
+ }
+
+ if(NULL != newNode)
+ {
+ // by spec, the duplicate node has no parent
+ newNode->parentNode = NULL;
+ }
+
+ return newNode;
+}
+
+/*================================================================
+* XmlNodeCloneNode
+* Clones a node, if deep==TRUE, clones subtree under nodeptr.
+* External function.
+* Returns:
+* the cloned node or NULL if error occurs.
+*
+*=================================================================*/
+XmlNode *
+XmlNodeCloneNode(
+ Pool * pool,
+
+ XmlNode * nodeptr,
+ IN BOOL deep )
+{
+
+ XmlNode * newNode;
+ XmlAttribute *newAttrNode;
+
+ if ( nodeptr == NULL )
+ {
+ return NULL;
+ }
+
+ switch ( nodeptr->nodeType )
+ {
+ case XML_ATTRIBUTE_NODE:
+ newAttrNode =
+ XmlNodeCloneAttrDirect(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ ( XmlAttribute * ) nodeptr );
+ return ( XmlNode * ) newAttrNode;
+ break;
+
+ default:
+ newNode = XmlNodeCloneNodeTree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ nodeptr, deep );
+ return newNode;
+ break;
+ }
+
+}
+
+/*================================================================
+* XmlNodeGetChildNodes
+* Returns a XmlNodeList of all the child nodes of nodeptr.
+* External function.
+*
+*=================================================================*/
+XmlNodeList *
+#ifdef USE_CWMP_MEMORY_POOL
+XmlNodeGetChildNodes(Pool * pool, XmlNode * nodeptr )
+#else
+XmlNodeGetChildNodes( XmlNode * nodeptr )
+#endif
+{
+ XmlNode * tempNode;
+ XmlNodeList *newNodeList;
+ int rc;
+
+ if ( nodeptr == NULL )
+ {
+ return NULL;
+ }
+
+ newNodeList = ( XmlNodeList * ) PMALLOC( sizeof( XmlNodeList ) );
+ if ( newNodeList == NULL )
+ {
+ return NULL;
+ }
+
+ XmlNodeListInit( newNodeList );
+
+ tempNode = nodeptr->firstChild;
+ while ( tempNode != NULL )
+ {
+ rc = XmlNodeListAddToNodeList(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ &newNodeList, tempNode );
+ if ( rc != XML_OK )
+ {
+ XmlNodeListFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newNodeList );
+ return NULL;
+ }
+
+ tempNode = tempNode->nextSibling;
+ }
+ return newNodeList;
+}
+
+/*================================================================
+* XmlNodeGetAttributes
+* returns a namedNodeMap of attributes of nodeptr
+* External function.
+* Returns:
+*
+*=================================================================*/
+XmlNamedNodeMap *
+#ifdef USE_CWMP_MEMORY_POOL
+XmlNodeGetAttributes(Pool * pool, XmlNode * nodeptr )
+#else
+XmlNodeGetAttributes( XmlNode * nodeptr )
+#endif
+{
+ XmlNamedNodeMap *returnNamedNodeMap = NULL;
+ XmlNode * tempNode;
+ int rc;
+
+ if ( nodeptr == NULL )
+ {
+ return NULL;
+ }
+
+ if ( nodeptr->nodeType == XML_ELEMENT_NODE )
+ {
+ returnNamedNodeMap =
+ ( XmlNamedNodeMap * ) PMALLOC( sizeof( XmlNamedNodeMap ) );
+ if ( returnNamedNodeMap == NULL )
+ {
+ return NULL;
+ }
+
+ XmlNamedNodeMapInit( returnNamedNodeMap );
+
+ tempNode = nodeptr->firstAttr;
+ while ( tempNode != NULL )
+ {
+ rc = XmlNamedNodeMapAddToNamedNodeMap(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ &returnNamedNodeMap,
+ tempNode );
+ if ( rc != XML_OK )
+ {
+ XmlNamedNodeMapFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ returnNamedNodeMap );
+ return NULL;
+ }
+
+ tempNode = tempNode->nextSibling;
+ }
+ return returnNamedNodeMap;
+ }
+ else // if not an ELEMENT_NODE
+ {
+ return NULL;
+ }
+}
+
+/*================================================================
+* XmlNodeHasChildNodes
+* External function.
+*
+*=================================================================*/
+BOOL
+XmlNodeHasChildNodes( XmlNode * nodeptr )
+{
+ if ( nodeptr == NULL )
+ {
+ return FALSE;
+ }
+
+ return ( nodeptr->firstChild != NULL );
+
+}
+
+/*================================================================
+* XmlNodeHasAttributes
+* External function.
+*
+*=================================================================*/
+BOOL
+XmlNodeHasAttributes( XmlNode * nodeptr )
+{
+ if ( nodeptr != NULL )
+ {
+ if ( ( nodeptr->nodeType == XML_ELEMENT_NODE )
+ && ( nodeptr->firstAttr != NULL ) )
+ {
+ return TRUE;
+ }
+ }
+ return FALSE;
+
+}
+
+/*================================================================
+* XmlNodeGetElementsByTagNameRecursive
+* Recursively traverse the whole tree, search for element
+* with the given tagname.
+* Internal to parser.
+*
+*=================================================================*/
+void
+XmlNodeGetElementsByTagNameRecursive(
+ Pool * pool,
+ XmlNode * n,
+ IN char *tagname,
+ OUT XmlNodeList ** list )
+{
+ const char *name;
+
+ if ( n != NULL )
+ {
+ if ( XmlNodeGetNodeType( n ) == XML_ELEMENT_NODE )
+ {
+ name = XmlNodeGetNodeName( n )? XmlNodeGetNodeName( n ):"";
+ if ( strcmp( tagname, name ) == 0
+ || strcmp( tagname, "*" ) == 0 )
+ {
+ XmlNodeListAddToNodeList(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ list, n );
+ }
+ }
+
+ XmlNodeGetElementsByTagNameRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ XmlNodeGetFirstChild
+ ( n ), tagname, list );
+ XmlNodeGetElementsByTagNameRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ XmlNodeGetNextSibling
+ ( n ), tagname, list );
+ }
+
+}
+
+/*================================================================
+* XmlNodeGetElementsByTagName
+* Returns a nodeList of all descendant Elements with a given
+* tagName, in the order in which they are encountered in a
+* traversal of this element tree.
+* External function.
+*
+*=================================================================*/
+void
+XmlNodeGetElementsByTagName(
+ Pool * pool,
+ XmlNode * n,
+ IN char *tagname,
+ OUT XmlNodeList ** list )
+{
+ const char *name;
+
+ assert( n != NULL && tagname != NULL );
+
+ if ( XmlNodeGetNodeType( n ) == XML_ELEMENT_NODE )
+ {
+ name = XmlNodeGetNodeName( n )?XmlNodeGetNodeName( n ):"";
+ if ( strcmp( tagname, name ) == 0 || strcmp( tagname, "*" ) == 0 )
+ {
+ XmlNodeListAddToNodeList(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ list, n );
+ }
+ }
+
+ XmlNodeGetElementsByTagNameRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ XmlNodeGetFirstChild( n ),
+ tagname, list );
+
+}
+
+/*================================================================
+* XmlNodeGetElementsByTagNameNSRecursive
+* Internal function to parser.
+*
+*
+*=================================================================*/
+void
+XmlNodeGetElementsByTagNameNSRecursive(
+ Pool * pool,
+ XmlNode * n,
+ const char *namespaceURI,
+ const char *localName,
+ OUT XmlNodeList ** list )
+{
+ const char * nsURI;
+ const char * name;
+
+ if ( n != NULL )
+ {
+ if ( XmlNodeGetNodeType( n ) == XML_ELEMENT_NODE )
+ {
+ name = XmlNodeGetLocalName( n );
+ nsURI = XmlNodeGetNamespaceURI( n );
+
+ if ( ( name != NULL ) && ( nsURI != NULL ) &&
+ ( strcmp( namespaceURI, nsURI ) == 0
+ || strcmp( namespaceURI, "*" ) == 0 )
+ && ( strcmp( name, localName ) == 0
+ || strcmp( localName, "*" ) == 0 ) )
+ {
+ XmlNodeListAddToNodeList(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ list, n );
+ }
+ }
+
+ XmlNodeGetElementsByTagNameNSRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ XmlNodeGetFirstChild
+ ( n ), namespaceURI,
+ localName, list );
+ XmlNodeGetElementsByTagNameNSRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ XmlNodeGetNextSibling
+ ( n ), namespaceURI,
+ localName, list );
+ }
+
+}
+
+/*================================================================
+* XmlNodeGetElementsByTagNameNS
+* Returns a nodeList of all the descendant Elements with a given
+* local name and namespace URI in the order in which they are
+* encountered in a preorder traversal of this Elememt tree.
+* External function.
+*
+*=================================================================*/
+void
+XmlNodeGetElementsByTagNameNS(
+ Pool * pool,
+ XmlNode * n,
+ const char *namespaceURI,
+ const char *localName,
+ OUT XmlNodeList ** list )
+{
+ const char * nsURI;
+ const char * name;
+
+ assert( n != NULL && namespaceURI != NULL && localName != NULL );
+
+ if ( XmlNodeGetNodeType( n ) == XML_ELEMENT_NODE )
+ {
+ name = XmlNodeGetLocalName( n );
+ nsURI = XmlNodeGetNamespaceURI( n );
+
+ if ( ( name != NULL ) && ( nsURI != NULL ) &&
+ ( strcmp( namespaceURI, nsURI ) == 0
+ || strcmp( namespaceURI, "*" ) == 0 )
+ && ( strcmp( name, localName ) == 0
+ || strcmp( localName, "*" ) == 0 ) )
+ {
+ XmlNodeListAddToNodeList(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ list, n );
+ }
+ }
+
+ XmlNodeGetElementsByTagNameNSRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ XmlNodeGetFirstChild( n ),
+ namespaceURI, localName,
+ list );
+
+}
+
+/*================================================================
+* XmlNodeSetNodeName
+* Internal to parser only.
+*
+*=================================================================*/
+int
+XmlNodeSetNodeName(
+ Pool * pool,
+
+ XmlNode * node,
+ const char * qualifiedName )
+{
+ int rc = XML_OK;
+
+ assert( node != NULL );
+
+ if ( node->nodeName != NULL )
+ {
+ PFREE( node->nodeName );
+ node->nodeName = NULL;
+ }
+
+ if ( qualifiedName != NULL )
+ {
+ // set the name part
+ node->nodeName = PSTRDUP( qualifiedName );
+ if ( node->nodeName == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ rc = XmlParserSetNodePrefixAndLocalName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ node );
+ if ( rc != XML_OK )
+ {
+ PFREE( node->nodeName );
+ }
+ }
+
+ return rc;
+}
+
+/*================================================================
+* XmlNodeSetNodeProperties
+* Internal to parser only.
+*
+*=================================================================*/
+int
+XmlNodeSetNodeProperties(
+ Pool * pool,
+ XmlNode * destNode,
+ XmlNode * src )
+{
+
+ int rc;
+
+ assert( destNode != NULL || src != NULL );
+
+ rc = XmlNodeSetNodeValue(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ destNode, src->nodeValue );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+
+ rc = XmlNodeSetLocalName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ destNode, src->localName );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+
+ rc = XmlNodeSetPrefix(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ destNode, src->prefix );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+ // set nodetype
+ destNode->nodeType = src->nodeType;
+
+ return XML_OK;
+
+ErrorHandler:
+#ifndef USE_CWMP_MEMORY_POOL
+ if ( destNode->nodeName != NULL )
+ {
+ PFREE( destNode->nodeName );
+ destNode->nodeName = NULL;
+ }
+ if ( destNode->nodeValue != NULL )
+ {
+ PFREE( destNode->nodeValue );
+ destNode->nodeValue = NULL;
+ }
+ if ( destNode->localName != NULL )
+ {
+ PFREE( destNode->localName );
+ destNode->localName = NULL;
+ }
+#endif
+ return XML_INSUFFICIENT_MEMORY;
+}
diff --git a/ap/app/cwmp/netcwmp/libxmlet/src/parser.c b/ap/app/cwmp/netcwmp/libxmlet/src/parser.c
new file mode 100755
index 0000000..8670c05
--- /dev/null
+++ b/ap/app/cwmp/netcwmp/libxmlet/src/parser.c
@@ -0,0 +1,3355 @@
+///////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2003 Intel Corporation
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+// * Neither name of Intel Corporation nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////
+
+#include <string.h>
+#include "xmlparser.h"
+
+static const char LESSTHAN = '<';
+static const char GREATERTHAN = '>';
+static const char SLASH = '/';
+static const char EQUALS = '=';
+static const char QUOTE = '\"';
+static const char SINGLEQUOTE = '\'';
+
+static const char *WHITESPACE = "\n\t\r ";
+static const char *COMPLETETAG = "/>";
+static const char *ENDTAG = "</";
+static const char *XMLDECL = "<?xml ";
+static const char *XMLDECL2 = "<?xml?";
+static const char *BEGIN_COMMENT = "<!--";
+static const char *END_COMMENT = "-->";
+static const char *BEGIN_PI = "<?";
+static const char *END_PI = "?>";
+static const char *BEGIN_DOCTYPE = "<!DOCTYPE";
+static const char *CDSTART = "<![CDATA[";
+static const char *CDEND = "]]>";
+static const char *DEC_NUMBERS = "0123456789";
+static const char *HEX_NUMBERS = "0123456789ABCDEFabcdef";
+
+
+typedef struct XmlCharInfo
+{
+ unsigned short l,
+ h;
+} XmlCharInfo;
+
+typedef char utf8char[8];
+
+/*==============================================================================*
+* Letter table contains all characters in XML 1.0 plus ":", "_" and
+* ideographic.
+*
+* This table contains all the characters that an element name can start with.
+* See XML 1.0 (2nd Edition) for more details.
+*
+*===============================================================================*/
+static XmlCharInfo Letter[] =
+{
+ {0x003A, 0x003A}, // character ":"
+ {0x0041, 0x005A},
+ {0x005F, 0x005F}, // character "_"
+ {0x0061, 0x007A}, {0x00C0, 0x00D6}, {0x00D8, 0x00F6}, {0x00F8, 0x00FF},
+ {0x0100, 0x0131}, {0x0134, 0x013E}, {0x0141, 0x0148}, {0x014A, 0x017E},
+ {0x0180, 0x01C3}, {0x01CD, 0x01F0}, {0x01F4, 0x01F5}, {0x01FA, 0x0217},
+ {0x0250, 0x02A8}, {0x02BB, 0x02C1}, {0x0386, 0x0386}, {0x0388, 0x038A},
+ {0x038C, 0x038C}, {0x038E, 0x03A1}, {0x03A3, 0x03CE}, {0x03D0, 0x03D6},
+ {0x03DA, 0x03DA},
+ {0x03DC, 0x03DC}, {0x03DE, 0x03DE}, {0x03E0, 0x03E0}, {0x03E2, 0x03F3},
+ {0x0401, 0x040C}, {0x040E, 0x044F}, {0x0451, 0x045C}, {0x045E, 0x0481},
+ {0x0490, 0x04C4}, {0x04C7, 0x04C8}, {0x04CB, 0x04CC}, {0x04D0, 0x04EB},
+ {0x04EE, 0x04F5}, {0x04F8, 0x04F9}, {0x0531, 0x0556}, {0x0559, 0x0559},
+ {0x0561, 0x0586}, {0x05D0, 0x05EA}, {0x05F0, 0x05F2}, {0x0621, 0x063A},
+ {0x0641, 0x064A}, {0x0671, 0x06B7}, {0x06BA, 0x06BE}, {0x06C0, 0x06CE},
+ {0x06D0, 0x06D3}, {0x06D5, 0x06D5}, {0x06E5, 0x06E6}, {0x0905, 0x0939},
+ {0x093D, 0x093D}, {0x0958, 0x0961}, {0x0985, 0x098C}, {0x098F, 0x0990},
+ {0x0993, 0x09A8}, {0x09AA, 0x09B0}, {0x09B2, 0x09B2}, {0x09B6, 0x09B9},
+ {0x09DC, 0x09DD}, {0x09DF, 0x09E1}, {0x09F0, 0x09F1}, {0x0A05, 0x0A0A},
+ {0x0A0F, 0x0A10}, {0x0A13, 0x0A28}, {0x0A2A, 0x0A30}, {0x0A32, 0x0A33},
+ {0x0A35, 0x0A36}, {0x0A38, 0x0A39}, {0x0A59, 0x0A5C}, {0x0A5E, 0x0A5E},
+ {0x0A72, 0x0A74}, {0x0A85, 0x0A8B}, {0x0A8D, 0x0A8D}, {0x0A8F, 0x0A91},
+ {0x0A93, 0x0AA8}, {0x0AAA, 0x0AB0}, {0x0AB2, 0x0AB3}, {0x0AB5, 0x0AB9},
+ {0x0ABD, 0x0ABD}, {0x0AE0, 0x0AE0}, {0x0B05, 0x0B0C}, {0x0B0F, 0x0B10},
+ {0x0B13, 0x0B28}, {0x0B2A, 0x0B30}, {0x0B32, 0x0B33}, {0x0B36, 0x0B39},
+ {0x0B3D, 0x0B3D}, {0x0B5C, 0x0B5D}, {0x0B5F, 0x0B61}, {0x0B85, 0x0B8A},
+ {0x0B8E, 0x0B90}, {0x0B92, 0x0B95}, {0x0B99, 0x0B9A}, {0x0B9C, 0x0B9C},
+ {0x0B9E, 0x0B9F}, {0x0BA3, 0x0BA4}, {0x0BA8, 0x0BAA}, {0x0BAE, 0x0BB5},
+ {0x0BB7, 0x0BB9}, {0x0C05, 0x0C0C}, {0x0C0E, 0x0C10}, {0x0C12, 0x0C28},
+ {0x0C2A, 0x0C33}, {0x0C35, 0x0C39}, {0x0C60, 0x0C61}, {0x0C85, 0x0C8C},
+ {0x0C8E, 0x0C90}, {0x0C92, 0x0CA8}, {0x0CAA, 0x0CB3}, {0x0CB5, 0x0CB9},
+ {0x0CDE, 0x0CDE}, {0x0CE0, 0x0CE1}, {0x0D05, 0x0D0C}, {0x0D0E, 0x0D10},
+ {0x0D12, 0x0D28}, {0x0D2A, 0x0D39}, {0x0D60, 0x0D61}, {0x0E01, 0x0E2E},
+ {0x0E30, 0x0E30}, {0x0E32, 0x0E33}, {0x0E40, 0x0E45}, {0x0E81, 0x0E82},
+ {0x0E84, 0x0E84}, {0x0E87, 0x0E88}, {0x0E8A, 0x0E8A}, {0x0E8D, 0x0E8D},
+ {0x0E94, 0x0E97}, {0x0E99, 0x0E9F}, {0x0EA1, 0x0EA3}, {0x0EA5, 0x0EA5},
+ {0x0EA7, 0x0EA7}, {0x0EAA, 0x0EAB}, {0x0EAD, 0x0EAE}, {0x0EB0, 0x0EB0},
+ {0x0EB2, 0x0EB3}, {0x0EBD, 0x0EBD}, {0x0EC0, 0x0EC4}, {0x0F40, 0x0F47},
+ {0x0F49, 0x0F69}, {0x10A0, 0x10C5}, {0x10D0, 0x10F6}, {0x1100, 0x1100},
+ {0x1102, 0x1103}, {0x1105, 0x1107}, {0x1109, 0x1109}, {0x110B, 0x110C},
+ {0x110E, 0x1112}, {0x113C, 0x113C}, {0x113E, 0x113E}, {0x1140, 0x1140},
+ {0x114C, 0x114C}, {0x114E, 0x114E}, {0x1150, 0x1150}, {0x1154, 0x1155},
+ {0x1159, 0x1159}, {0x115F, 0x1161}, {0x1163, 0x1163}, {0x1165, 0x1165},
+ {0x1167, 0x1167}, {0x1169, 0x1169}, {0x116D, 0x116E}, {0x1172, 0x1173},
+ {0x1175, 0x1175}, {0x119E, 0x119E}, {0x11A8, 0x11A8}, {0x11AB, 0x11AB},
+ {0x11AE, 0x11AF}, {0x11B7, 0x11B8}, {0x11BA, 0x11BA}, {0x11BC, 0x11C2},
+ {0x11EB, 0x11EB}, {0x11F0, 0x11F0}, {0x11F9, 0x11F9}, {0x1E00, 0x1E9B},
+ {0x1EA0, 0x1EF9}, {0x1F00, 0x1F15}, {0x1F18, 0x1F1D}, {0x1F20, 0x1F45},
+ {0x1F48, 0x1F4D}, {0x1F50, 0x1F57}, {0x1F59, 0x1F59}, {0x1F5B, 0x1F5B},
+ {0x1F5D, 0x1F5D}, {0x1F5F, 0x1F7D}, {0x1F80, 0x1FB4}, {0x1FB6, 0x1FBC},
+ {0x1FBE, 0x1FBE}, {0x1FC2, 0x1FC4}, {0x1FC6, 0x1FCC}, {0x1FD0, 0x1FD3},
+ {0x1FD6, 0x1FDB}, {0x1FE0, 0x1FEC}, {0x1FF2, 0x1FF4}, {0x1FF6, 0x1FFC},
+ {0x2126, 0x2126}, {0x212A, 0x212B}, {0x212E, 0x212E}, {0x2180, 0x2182},
+ {0x3007, 0x3007}, {0x3021, 0x3029}, // these two are ideographic
+ {0x3041, 0x3094}, {0x30A1, 0x30FA}, {0x3105, 0x312C},
+ {0x4E00, 0x9FA5}, // ideographic
+ {0xAC00, 0xD7A3}
+};
+
+#define LETTERTABLESIZE (sizeof(Letter)/sizeof(Letter[0]))
+
+/*==============================================================================*
+* NameChar table contains
+* CombiningChar, Extender, Digit, '-', '.', less '_', ':'
+* NameChar ::= Digit | '-' | '.' | CombiningChar | Extender
+* See XML 1.0 2nd Edition
+*
+*===============================================================================*/
+static XmlCharInfo NameChar[] =
+{
+ {0x002D, 0x002D}, // character "-"
+ {0x002E, 0x002E}, // character "."
+ {0x0030, 0x0039}, // digit
+ {0x00B7, 0x00B7}, {0x02D0, 0x02D0}, {0x02D1, 0x02D1}, // extended
+ {0x0300, 0x0345}, {0x0360, 0x0361},
+ {0x0387, 0x0387}, // extended
+ {0x0483, 0x0486}, {0x0591, 0x05A1}, {0x05A3, 0x05B9},
+ {0x05BB, 0x05BD}, {0x05BF, 0x05BF}, {0x05C1, 0x05C2}, {0x05C4, 0x05C4},
+ {0x0640, 0x0640}, // extended
+ {0x064B, 0x0652},
+ {0x0660, 0x0669}, // digit
+ {0x0670, 0x0670},
+ {0x06D6, 0x06DC}, {0x06DD, 0x06DF}, {0x06E0, 0x06E4}, {0x06E7, 0x06E8},
+ {0x06EA, 0x06ED},
+ {0x06F0, 0x06F9}, // digit
+ {0x0901, 0x0903}, {0x093C, 0x093C},
+ {0x093E, 0x094C}, {0x094D, 0x094D}, {0x0951, 0x0954}, {0x0962, 0x0963},
+ {0x0966, 0x096F}, // digit
+ {0x0981, 0x0983}, {0x09BC, 0x09BC}, {0x09BE, 0x09BE},
+ {0x09BF, 0x09BF}, {0x09C0, 0x09C4}, {0x09C7, 0x09C8}, {0x09CB, 0x09CD},
+ {0x09D7, 0x09D7}, {0x09E2, 0x09E3},
+ {0x09E6, 0x09EF}, // digit
+ {0x0A02, 0x0A02},
+ {0x0A3C, 0x0A3C}, {0x0A3E, 0x0A3E}, {0x0A3F, 0x0A3F}, {0x0A40, 0x0A42},
+ {0x0A47, 0x0A48}, {0x0A4B, 0x0A4D},
+ {0x0A66, 0x0A6F}, // digit
+ {0x0A70, 0x0A71},
+ {0x0A81, 0x0A83}, {0x0ABC, 0x0ABC}, {0x0ABE, 0x0AC5}, {0x0AC7, 0x0AC9},
+ {0x0ACB, 0x0ACD},
+ {0x0AE6, 0x0AEF}, // digit
+ {0x0B01, 0x0B03}, {0x0B3C, 0x0B3C},
+ {0x0B3E, 0x0B43}, {0x0B47, 0x0B48}, {0x0B4B, 0x0B4D}, {0x0B56, 0x0B57},
+ {0x0B66, 0x0B6F}, // digit
+ {0x0B82, 0x0B83}, {0x0BBE, 0x0BC2}, {0x0BC6, 0x0BC8},
+ {0x0BCA, 0x0BCD}, {0x0BD7, 0x0BD7},
+ {0x0BE7, 0x0BEF}, // digit
+ {0x0C01, 0x0C03},
+ {0x0C3E, 0x0C44}, {0x0C46, 0x0C48}, {0x0C4A, 0x0C4D}, {0x0C55, 0x0C56},
+ {0x0C66, 0x0C6F}, // digit
+ {0x0C82, 0x0C83}, {0x0CBE, 0x0CC4}, {0x0CC6, 0x0CC8},
+ {0x0CCA, 0x0CCD}, {0x0CD5, 0x0CD6},
+ {0x0CE6, 0x0CEF}, // digit
+ {0x0D02, 0x0D03},
+ {0x0D3E, 0x0D43}, {0x0D46, 0x0D48}, {0x0D4A, 0x0D4D}, {0x0D57, 0x0D57},
+ {0x0D66, 0x0D6F}, // digit
+ {0x0E31, 0x0E31}, {0x0E34, 0x0E3A},
+ {0x0E46, 0x0E46}, // extended
+ {0x0E47, 0x0E4E},
+ {0x0E50, 0x0E59}, // digit
+ {0x0EB1, 0x0EB1}, {0x0EB4, 0x0EB9},
+ {0x0EBB, 0x0EBC},
+ {0x0EC6, 0x0EC6}, // extended
+ {0x0EC8, 0x0ECD},
+ {0x0ED0, 0x0ED9}, // digit
+ {0x0F18, 0x0F19},
+ {0x0F20, 0x0F29}, // digit
+ {0x0F35, 0x0F35}, {0x0F37, 0x0F37},
+ {0x0F39, 0x0F39}, {0x0F3E, 0x0F3E}, {0x0F3F, 0x0F3F}, {0x0F71, 0x0F84},
+ {0x0F86, 0x0F8B}, {0x0F90, 0x0F95}, {0x0F97, 0x0F97}, {0x0F99, 0x0FAD},
+ {0x0FB1, 0x0FB7}, {0x0FB9, 0x0FB9}, {0x20D0, 0x20DC}, {0x20E1, 0x20E1},
+ {0x3005, 0x3005}, // extended
+ {0x302A, 0x302F},
+ {0x3031, 0x3035}, // extended
+ {0x3099, 0x3099}, {0x309A, 0x309A}, // combining char
+ {0x309D, 0x309E}, {0x30FC, 0x30FE} // extended
+};
+
+#define NAMECHARTABLESIZE (sizeof(NameChar)/sizeof(NameChar[0]))
+
+static int XMLStrncasecmp(const char * s1, const char * s2, size_t n)
+{
+ if (!s1 || !s2)
+ {
+ return -1;
+ }
+#ifdef WIN32
+
+ if (n == 0)
+ return 0;
+
+ while (n-- != 0 && tolower(*s1) == tolower(*s2))
+ {
+ if (n == 0 || *s1 == '\0' || *s2 == '\0')
+ break;
+ s1++;
+ s2++;
+ }
+
+ return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
+#else
+ return strncasecmp(s1, s2, n);
+#endif
+}
+
+
+
+// functions used in this file
+static void XMLParserFree(
+ Pool * pool,
+ XMLParser * myParser );
+static int XMLParserSkipDocType( char **pstr );
+static int XMLParserSkipProlog( XMLParser * xmlParser );
+static int XMLParserSkipMisc( XMLParser * xmlParser );
+static void XMLParserFreeElementStackItem(
+ Pool * pool,
+ XmlElementStack * pItem );
+static void XMLParserFreeNsURI(
+ Pool * pool,
+ XmlNameSpaceURI * pNsURI );
+
+static int XMLParserGetNextNode(
+ Pool * pool,
+ XMLParser * myParser,
+ XmlNode * newNode,
+ BOOL * isEnd );
+static int XMLParserGetNextToken(
+ Pool * pool,
+ XMLParser * myParser );
+static int XMLParserXmlNamespace(
+ Pool * pool,
+ XMLParser * myParser,
+ XmlNode * newNode );
+static BOOL XMLParserElementPrefixDefined( XMLParser * myParser,
+ XmlNode * newNode,
+ char **nsURI );
+static int XMLParserSetElementNamespace(
+ Pool * pool,
+ XmlElement * newElement,
+ char *nsURI );
+static int XMLParserParseDocument(
+ Pool * pool,
+
+ XmlDocument ** retDoc,
+ XMLParser * domParser );
+static BOOL XMLParserHasDefaultNamespace( XMLParser * xmlParser,
+ XmlNode * newNode,
+ char **nsURI );
+static int XMLParserGetChar( IN char *src,
+ INOUT int *cLen );
+
+/*==============================================================================*
+* XMLParserIsCharInTable
+* will determine whether character c is in the table of tbl
+* (either Letter table or NameChar table)
+*
+*===============================================================================*/
+static BOOL
+XMLParserIsCharInTable( IN int c,
+ IN XmlCharInfo * tbl,
+ IN int sz )
+{
+ int t = 0,
+ b = sz,
+ m;
+
+ while ( t <= b )
+ {
+ m = ( t + b ) / 2;
+ if ( c < tbl[m].l )
+ {
+ b = m - 1;
+ }
+ else if ( c > tbl[m].h )
+ {
+ t = m + 1;
+ }
+ else
+ {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/*==============================================================================*
+* XMLParserIsXmlChar
+* see XML 1.0 (2nd Edition) 2.2.
+* Internal to parser only
+*
+*===============================================================================*/
+static BOOL
+XMLParserIsXmlChar( IN int c )
+{
+ return ( c == 0x9 || c == 0xA || c == 0xD ||
+ ( c >= 0x20 && c <= 0xD7FF ) ||
+ ( c >= 0xE000 && c <= 0xFFFD ) ||
+ ( c >= 0x10000 && c <= 0x10FFFF ) );
+}
+
+/*==============================================================================*
+* XMLParserIsNameChar
+* check whether c (int) is in LetterTable or NameCharTable
+* Internal to parser only.
+*
+*===============================================================================*/
+static BOOL
+XMLParserIsNameChar( IN int c,
+ IN BOOL bNameChar )
+{
+ if ( XMLParserIsCharInTable( c, Letter, LETTERTABLESIZE ) )
+ {
+ return TRUE;
+ }
+
+ if ( bNameChar
+ && XMLParserIsCharInTable( c, NameChar, NAMECHARTABLESIZE ) )
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/*==============================================================================*
+* XmlParserIsValidXmlName
+* Check to see whether name is a valid xml name.
+* External function.
+*
+*===============================================================================*/
+BOOL
+XmlParserIsValidXmlName( const char * name )
+{
+ char *pstr = NULL;
+ int i = 0,
+ nameLen = 0;
+
+ assert( name != NULL );
+
+ nameLen = strlen( name );
+
+ pstr = (char *)name;
+ if ( XMLParserIsNameChar( *pstr, FALSE ) == TRUE )
+ {
+ for ( i = 1; i < nameLen; i++ )
+ {
+ if ( XMLParserIsNameChar( *( pstr + 1 ), TRUE ) == FALSE ) //illegal char
+ {
+ return FALSE;
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+/*==============================================================================*
+* XMLParserIntToUTF8:
+* Encoding a character to its UTF-8 character string, and return its length
+* internal function.
+*
+*===============================================================================*/
+static int
+XMLParserIntToUTF8( IN int c,
+ IN utf8char s )
+{
+ if ( c < 0 )
+ {
+ return 0;
+ }
+
+ if ( c <= 127 )
+ {
+ s[0] = c;
+ s[1] = 0;
+ return 1;
+ }
+ else if ( c <= 0x07FF ) // 0x0080 < c <= 0x07FF
+ {
+ s[0] = 0xC0 | ( c >> 6 );
+ s[1] = 0x80 | ( c & 0x3f );
+ s[2] = 0;
+ return 2;
+ }
+ else if ( c <= 0xFFFF ) // 0x0800 < c <= 0xFFFF
+ {
+ s[0] = 0xE0 | ( c >> 12 );
+ s[1] = 0x80 | ( ( c >> 6 ) & 0x3f );
+ s[2] = 0x80 | ( c & 0x3f );
+ s[3] = 0;
+ return 3;
+ }
+ else if ( c <= 0x1FFFFF ) // 0x10000 < c <= 0x1FFFFF
+ {
+ s[0] = 0xF0 | ( c >> 18 );
+ s[1] = 0x80 | ( ( c >> 12 ) & 0x3f );
+ s[2] = 0x80 | ( ( c >> 6 ) & 0x3f );
+ s[3] = 0x80 | ( c & 0x3f );
+ s[4] = 0;
+ return 4;
+ }
+ else if ( c <= 0x3FFFFFF ) // 0x200000 < c <= 3FFFFFF
+ {
+ s[0] = 0xF8 | ( c >> 24 );
+ s[1] = 0x80 | ( ( c >> 18 ) & 0x3f );
+ s[2] = 0x80 | ( ( c >> 12 ) & 0x3f );
+ s[3] = 0x80 | ( ( c >> 6 ) & 0x3f );
+ s[4] = 0x80 | ( c & 0x3f );
+ s[5] = 0;
+ return 5;
+ }
+#if 1
+ else // 0x4000000 < c <= 7FFFFFFF
+ {
+ s[0] = 0xFC | ( c >> 30 );
+ s[1] = 0x80 | ( ( c >> 24 ) & 0x3f );
+ s[2] = 0x80 | ( ( c >> 18 ) & 0x3f );
+ s[3] = 0x80 | ( ( c >> 12 ) & 0x3f );
+ s[4] = 0x80 | ( ( c >> 6 ) & 0x3f );
+ s[5] = 0x80 | ( c & 0x3f );
+ s[6] = 0;
+ return 6;
+ }
+
+#else
+ else if ( c <= 0x7FFFFFFF ) // 0x4000000 < c <= 7FFFFFFF
+ {
+ s[0] = 0xFC | ( c >> 30 );
+ s[1] = 0x80 | ( ( c >> 24 ) & 0x3f );
+ s[2] = 0x80 | ( ( c >> 18 ) & 0x3f );
+ s[3] = 0x80 | ( ( c >> 12 ) & 0x3f );
+ s[4] = 0x80 | ( ( c >> 6 ) & 0x3f );
+ s[5] = 0x80 | ( c & 0x3f );
+ s[6] = 0;
+ return 6;
+ }
+ else // illegal
+ {
+ return 0;
+ }
+#endif
+}
+
+/*==============================================================================*
+* Parser_UTF8ToInt
+* In UTF-8, characters are encoded using sequences of 1 to 6 octets.
+* This functions will return a UTF-8 character value and its octets number.
+* Internal to parser only.
+* Internal to parser only
+*
+*===============================================================================*/
+static int
+Parser_UTF8ToInt( IN char *ss,
+ OUT int *len )
+{
+
+ unsigned char *s = ( unsigned char * )ss;
+ int c = *s;
+
+ if ( c <= 127 ) // if c<=127, c is just the character.
+ {
+ *len = 1;
+ return c;
+ }
+ else if ( ( c & 0xE0 ) == 0xC0 && ( s[1] & 0xc0 ) == 0x80 ) // a sequence of 110xxxxx and 10xxxxxx?
+ {
+ *len = 2;
+ return ( ( ( c & 0x1f ) << 6 ) | ( s[1] & 0x3f ) );
+ }
+ else if ( ( c & 0xF0 ) == 0xE0 && ( s[1] & 0xc0 ) == 0x80 && ( s[2] & 0xc0 ) == 0x80 ) // a sequence of 1110xxxx,10xxxxxx and 10xxxxxx ?
+ {
+ *len = 3;
+ return ( ( ( c & 0xf ) << 12 ) | ( ( s[1] & 0x3f ) << 6 ) |
+ ( s[2] & 0x3f ) );
+ }
+ else if ( ( c & 0xf8 ) == 0xf0 && ( s[1] & 0xc0 ) == 0x80 && ( s[2] & 0xc0 ) == 0x80 && ( s[3] & 0xc0 ) == 0x80 ) // a sequence of 11110xxx,10xxxxxx,10xxxxxx and 10xxxxxx ?
+ {
+ *len = 4;
+ return ( ( ( c & 0x7 ) << 18 ) | ( ( s[1] & 0x3f ) << 12 ) |
+ ( ( s[2] & 0x3f ) << 6 ) | ( s[3] & 0x3f ) );
+ }
+ else if ( ( c & 0xfc ) == 0xf8 && ( s[1] & 0xc0 ) == 0x80 && ( s[2] & 0xc0 ) == 0x80 && ( s[3] & 0xc0 ) == 0x80 && ( s[4] & 0xc0 ) == 0x80 ) // a sequence of 111110xx,10xxxxxx,10xxxxxx,10xxxxxx,10xxxxxx ?
+ {
+ *len = 5;
+ return ( ( ( c & 0x3 ) << 24 ) | ( ( s[1] & 0x3f ) << 18 ) |
+ ( ( s[2] & 0x3f ) << 12 ) | ( ( s[3] & 0x3f ) << 6 ) |
+ ( s[4] & 0x3f ) );
+ }
+ else if ( ( c & 0xfe ) == 0xfc && ( s[1] & 0xc0 ) == 0x80 && ( s[2] & 0xc0 ) == 0x80 && ( s[3] & 0xc0 ) == 0x80 && ( s[4] & 0xc0 ) == 0x80 && ( s[5] & 0xc0 ) == 0x80 ) // a sequence of 1111110x,10xxxxxx,10xxxxxx,10xxxxxx,10xxxxxx and 10xxxxxx ?
+ {
+ *len = 6;
+ return ( ( ( c & 0x1 ) << 30 ) | ( ( s[1] & 0x3f ) << 24 ) |
+ ( ( s[2] & 0x3f ) << 18 ) | ( ( s[3] & 0x3f ) << 12 ) |
+ ( ( s[4] & 0x3f ) << 6 ) | ( s[5] & 0x3f ) );
+ }
+ else // none of above, error
+ {
+ *len = 0;
+ return -1;
+ }
+}
+
+/*==============================================================================*
+* ParserInit
+* Initializes a xml parser.
+* Internal to parser only
+*
+*===============================================================================*/
+static XMLParser *
+
+
+#ifdef USE_CWMP_MEMORY_POOL
+ParserInit( Pool * pool )
+
+#else
+ParserInit( )
+#endif
+
+{
+ XMLParser *newParser = NULL;
+
+ newParser = ( XMLParser * ) PMALLOC( sizeof( XMLParser ) );
+ if ( newParser == NULL )
+ {
+ return NULL;
+ }
+
+ memset( newParser, 0, sizeof( XMLParser ) );
+
+ XmlBufferInit( &( newParser->tokenBuf ) );
+ XmlBufferInit( &( newParser->lastElem ) );
+
+ return newParser;
+}
+
+/*================================================================
+* XMLParserIsValidEndElement
+* check if a new node->nodeName matches top of element stack.
+* Internal to parser only.
+*
+*=================================================================*/
+static int
+XMLParserIsValidEndElement( XMLParser * xmlParser,
+ XmlNode * newNode )
+{
+ return ( strcmp( xmlParser->pCurElement->element, newNode->nodeName )
+ == 0 );
+}
+
+/*===============================================================
+* Parser_pushElement
+* push a new element onto element stack
+* Internal to parser only.
+*
+*=================================================================*/
+static int
+#ifdef USE_CWMP_MEMORY_POOL
+Parser_pushElement(Pool * pool, XMLParser * xmlParser,
+#else
+Parser_pushElement( XMLParser * xmlParser,
+#endif
+
+
+ XmlNode * newElement )
+{
+
+ XmlElementStack *pCurElement = NULL;
+ XmlElementStack *pNewStackElement = NULL;
+
+// assert( newElement );
+ if ( newElement != NULL )
+ {
+ // push new element
+ pNewStackElement =
+ ( XmlElementStack * ) PMALLOC( sizeof( XmlElementStack ) );
+ if ( pNewStackElement == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ memset( pNewStackElement, 0, sizeof( XmlElementStack ) );
+ // the element member includes both prefix and name
+
+ pNewStackElement->element = PSTRDUP( newElement->nodeName );
+ if ( pNewStackElement->element == NULL )
+ {
+ PFREE( pNewStackElement );
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ if ( newElement->prefix != 0 )
+ {
+ pNewStackElement->prefix = PSTRDUP( newElement->prefix );
+ if ( pNewStackElement->prefix == NULL )
+ {
+ XMLParserFreeElementStackItem(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ pNewStackElement );
+ PFREE( pNewStackElement );
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+
+ if ( newElement->namespaceURI != 0 )
+ {
+ pNewStackElement->namespaceUri =
+ PSTRDUP( newElement->namespaceURI );
+ if ( pNewStackElement->namespaceUri == NULL )
+ {
+ XMLParserFreeElementStackItem(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ pNewStackElement );
+ PFREE( pNewStackElement );
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+
+ pCurElement = xmlParser->pCurElement;
+
+ // insert the new element into the top of the stack
+ pNewStackElement->nextElement = pCurElement;
+ xmlParser->pCurElement = pNewStackElement;
+
+ }
+
+ return XML_OK;
+}
+
+/*================================================================
+* ParserPopElement
+* Remove element from element stack.
+* Internal to parser only.
+*
+*=================================================================*/
+static void
+ParserPopElement(
+ Pool * pool,
+ XMLParser * xmlParser )
+{
+ XmlElementStack *pCur = NULL;
+ XmlNameSpaceURI *pnsUri = NULL,
+ *pNextNS = NULL;
+
+ pCur = xmlParser->pCurElement;
+ if ( pCur != NULL )
+ {
+ xmlParser->pCurElement = pCur->nextElement;
+
+ XMLParserFreeElementStackItem(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ pCur );
+
+ pnsUri = pCur->pNsURI;
+ while ( pnsUri != NULL )
+ {
+ pNextNS = pnsUri->nextNsURI;
+
+ XMLParserFreeNsURI(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ pnsUri );
+ PFREE( pnsUri );
+ pnsUri = pNextNS;
+ }
+
+ PFREE( pCur );
+ }
+
+}
+
+
+
+static char* check_file(char * filepath)
+{
+#if 0
+ char type[6] = {0};
+
+ if(strncmp(filepath,".xml",4) == 0 )
+ {
+ return NULL;
+ }
+
+ strncpy(type,filepath+(strlen(filepath))-4, 4);
+
+// cwmp_log_info("file type is :%s", type);
+
+ if( strncmp(type, ".xml", 4) == 0)
+ {
+ return filepath;
+ }
+
+ return NULL;
+#endif
+
+ if(strncmp(filepath, "./", 2) == 0 || strncmp(filepath, "../", 3) == 0)
+ {
+ return NULL;
+ }
+
+ return filepath;
+}
+
+/*================================================================
+* ParserReadFileOrBuffer
+* read a xml file or buffer contents into xml parser.
+* Internal to parser only.
+*
+*=================================================================*/
+static int
+
+#ifdef USE_CWMP_MEMORY_POOL
+ParserReadFileOrBuffer(Pool * pool, XMLParser * xmlParser,
+#else
+ParserReadFileOrBuffer( XMLParser * xmlParser,
+#endif
+ IN char *xmlFileName,
+ IN BOOL file )
+{
+ int fileSize = 0;
+ int bytesRead = 0;
+ FILE *xmlFilePtr = NULL;
+
+ char *pxmlFileName = NULL;
+
+ if ( file )
+ {
+ pxmlFileName = check_file(xmlFileName);
+ if(NULL == pxmlFileName)
+ {
+// cwmp_log_error("%s not xml file", xmlFileName);
+ return XML_NO_SUCH_FILE;
+ }
+
+ xmlFilePtr = fopen( pxmlFileName, "rb" );
+ if ( xmlFilePtr == NULL )
+ {
+ return XML_NO_SUCH_FILE;
+ }
+ else
+ {
+ fseek( xmlFilePtr, 0, SEEK_END );
+ fileSize = ftell( xmlFilePtr );
+ if ( fileSize <= 0 )
+ {
+ fclose( xmlFilePtr );
+ return XML_SYNTAX_ERR;
+ }
+
+ xmlParser->dataBuffer = ( char * )PMALLOC( fileSize + 1 );
+ if ( xmlParser->dataBuffer == NULL )
+ {
+ fclose( xmlFilePtr );
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ fseek( xmlFilePtr, 0, SEEK_SET );
+ bytesRead =
+ fread( xmlParser->dataBuffer, 1, fileSize, xmlFilePtr );
+ xmlParser->dataBuffer[bytesRead] = '\0'; // append null
+ fclose( xmlFilePtr );
+ }
+ }
+ else
+ {
+ xmlParser->dataBuffer = PSTRDUP( xmlFileName );
+ if ( xmlParser->dataBuffer == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+
+ return XML_OK;
+}
+
+/*================================================================
+* XmlParserLoadDocument
+* parses a xml file and return the DOM tree.
+* Internal to parser only
+*
+*=================================================================*/
+int
+XmlParserLoadDocument(
+ Pool * pool,
+ OUT XmlDocument ** retDoc,
+ IN char *xmlFileName,
+ IN BOOL file )
+{
+ int rc = XML_OK;
+ XMLParser *xmlParser = NULL;
+
+ xmlParser = ParserInit(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool
+#endif
+
+ );
+ if ( xmlParser == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ rc = ParserReadFileOrBuffer(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser, xmlFileName, file );
+ if ( rc != XML_OK )
+ {
+ XMLParserFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser );
+ return rc;
+ }
+
+ xmlParser->curPtr = xmlParser->dataBuffer;
+ rc = XMLParserParseDocument(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ retDoc, xmlParser );
+ return rc;
+
+}
+
+/*================================================================
+* isTopLevelElement
+* decides whether we have top level element already.
+* Internal to parser only.
+*
+*=================================================================*/
+static int
+isTopLevelElement( XMLParser * xmlParser )
+{
+ assert( xmlParser );
+ return ( xmlParser->pCurElement == NULL );
+}
+
+/*================================================================
+* isDuplicateAttribute
+* Decide whether the new attribute is the same as an
+* existing one.
+* Internal to parser only.
+*
+*=================================================================*/
+static int
+isDuplicateAttribute( XMLParser * xmlParser,
+ XmlNode * newAttrNode )
+{
+ XmlNode * elementNode = NULL;
+ XmlNode * attrNode = NULL;
+
+ elementNode = xmlParser->currentNodePtr;
+ attrNode = elementNode->firstAttr;
+ while ( attrNode != NULL )
+ {
+ if ( strcmp( attrNode->nodeName, newAttrNode->nodeName ) == 0 )
+ {
+ return TRUE;
+ }
+
+ attrNode = attrNode->nextSibling;
+ }
+
+ return FALSE;
+}
+
+/*================================================================
+* XMLParserProcessAttributeName
+* processes the attribute name.
+* Internal to parser only.
+*
+*=================================================================*/
+static int
+XMLParserProcessAttributeName(
+ Pool * pool,
+ XmlDocument * rootDoc,
+ XMLParser * xmlParser,
+ XmlNode * newNode )
+{
+ XmlAttribute *attr = NULL;
+ int rc = XML_OK;
+
+ if ( isDuplicateAttribute( xmlParser, newNode ) == TRUE )
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ rc = XmlDocCreateAttributeEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ rootDoc, newNode->nodeName,
+ &attr );
+ if ( rc != XML_OK )
+ {
+ return rc;
+ }
+
+ rc = XmlNodeSetNodeProperties(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ ( XmlNode * ) attr, newNode );
+ if ( rc != XML_OK )
+ {
+ return rc;
+ }
+
+ rc = XmlElementSetAttributeNode(
+
+ ( XmlElement * ) xmlParser->currentNodePtr, attr, NULL );
+ return rc;
+}
+
+/*================================================================
+* ParserProcessElementName
+* Processes element name
+* Internal to parser only.
+*
+*=================================================================*/
+static int
+ParserProcessElementName(
+ Pool * pool,
+
+ XmlDocument * rootDoc,
+ XMLParser * xmlParser,
+ XmlNode * newNode )
+{
+ XmlElement *newElement = NULL;
+ char *nsURI = NULL;
+ int rc = XML_OK;
+
+ if ( xmlParser->bHasTopLevel == TRUE )
+ {
+ if ( isTopLevelElement( xmlParser ) == TRUE )
+ {
+ return XML_SYNTAX_ERR;
+ }
+ }
+ else
+ {
+ xmlParser->bHasTopLevel = TRUE;
+ }
+
+ xmlParser->savePtr = xmlParser->curPtr;
+ rc = XmlDocCreateElementEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ rootDoc, newNode->nodeName,
+ &newElement );
+ if ( rc != XML_OK )
+ {
+ return rc;
+ }
+
+ rc = XmlNodeSetNodeProperties(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ ( XmlNode * ) newElement, newNode );
+ if ( rc != XML_OK )
+ {
+ XmlElementFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newElement );
+ return rc;
+ }
+
+ if ( newNode->prefix != NULL ) // element has namespace prefix
+ {
+ if ( XMLParserElementPrefixDefined( xmlParser, newNode, &nsURI ) !=
+ TRUE )
+ {
+ // read next node to see whether it includes namespace definition
+ xmlParser->pNeedPrefixNode = ( XmlNode * ) newElement;
+ }
+ else // fill in the namespace
+ {
+ XMLParserSetElementNamespace(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newElement, nsURI );
+ }
+ }
+ else // does element has default namespace
+ {
+ // the node may have default namespace definition
+ if ( XMLParserHasDefaultNamespace( xmlParser, newNode, &nsURI ) ==
+ TRUE )
+ {
+ XMLParserSetElementNamespace(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newElement, nsURI );
+ }
+ else if ( xmlParser->state == E_ATTRIBUTE )
+ {
+ // the default namespace maybe defined later
+ xmlParser->pNeedPrefixNode = ( XmlNode * ) newElement;
+ }
+ }
+
+ rc = XmlNodeAppendChild( xmlParser->currentNodePtr,
+ ( XmlNode * ) newElement );
+ if ( rc != XML_OK )
+ {
+ XmlElementFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newElement );
+ return rc;
+ }
+
+ xmlParser->currentNodePtr = ( XmlNode * ) newElement;
+
+ // push element to stack
+ rc = Parser_pushElement(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ xmlParser, ( XmlNode * ) newElement );
+ return rc;
+}
+
+/*================================================================
+* ParserETagVerification
+* Verifies endof element tag is the same as the openning
+* element tag.
+* Internal to parser only.
+*
+*=================================================================*/
+static int
+ParserETagVerification(
+ Pool * pool,
+ XMLParser * xmlParser,
+ XmlNode * newNode )
+{
+
+ assert( newNode->nodeName );
+ assert( xmlParser->currentNodePtr );
+
+ if ( newNode->nodeType == XML_ELEMENT_NODE )
+ {
+ if ( XMLParserIsValidEndElement( xmlParser, newNode ) == TRUE )
+ {
+ ParserPopElement(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser );
+ }
+ else // syntax error
+ {
+ return XML_SYNTAX_ERR;
+ }
+ }
+
+ if ( strcmp( newNode->nodeName, xmlParser->currentNodePtr->nodeName ) ==
+ 0 )
+ {
+ xmlParser->currentNodePtr = xmlParser->currentNodePtr->parentNode;
+ }
+ else
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ return XML_OK;
+
+}
+
+/*================================================================
+* XmlParserFreeNodeContent
+* XFREEs a node contents
+* Internal to parser only.
+*
+*=================================================================*/
+void
+XmlParserFreeNodeContent(
+ Pool * pool,
+ XmlNode * nodeptr )
+{
+
+ if ( nodeptr == NULL )
+ {
+ return;
+ }
+
+ if ( nodeptr->nodeName != NULL )
+ {
+ PFREE( nodeptr->nodeName );
+ }
+
+ if ( nodeptr->nodeValue != NULL )
+ {
+ PFREE( nodeptr->nodeValue );
+ }
+
+ if ( nodeptr->namespaceURI != NULL )
+ {
+ PFREE( nodeptr->namespaceURI );
+ }
+
+ if ( nodeptr->prefix != NULL )
+ {
+ PFREE( nodeptr->prefix );
+ }
+
+ if ( nodeptr->localName != NULL )
+ {
+ PFREE( nodeptr->localName );
+ }
+
+}
+
+/*================================================================
+* XMLParserParseDocument
+* Parses the xml file and returns the DOM document tree.
+* External function.
+*
+*=================================================================*/
+static int
+XMLParserParseDocument(
+ Pool * pool,
+ OUT XmlDocument ** retDoc,
+ XMLParser * xmlParser )
+{
+
+ XmlDocument *gRootDoc = NULL;
+ XmlNode newNode;
+ BOOL bETag = FALSE;
+ XmlNode * tempNode = NULL;
+ int rc = XML_OK;
+ XmlCDATASection *cdataSecNode = NULL;
+
+ XmlNodeInit( &newNode );
+
+ rc = XmlDocCreateDocumentEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ &gRootDoc );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+
+ xmlParser->currentNodePtr = ( XmlNode * ) gRootDoc;
+
+ rc = XMLParserSkipProlog( xmlParser );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+
+ while ( bETag == FALSE )
+ {
+ // clear the newNode contents
+ XmlNodeInit( &newNode );
+
+ if ( XMLParserGetNextNode(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser, &newNode, &bETag ) ==
+ XML_OK )
+ {
+ if ( bETag == FALSE )
+ {
+ switch ( newNode.nodeType )
+ {
+ case XML_ELEMENT_NODE:
+ rc = ParserProcessElementName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ gRootDoc,
+ xmlParser,
+ &newNode );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+ break;
+
+ case XML_TEXT_NODE:
+ rc = XmlDocCreateTextNodeEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ gRootDoc,
+ newNode.
+ nodeValue,
+ &tempNode );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+
+ rc = XmlNodeAppendChild( xmlParser->
+ currentNodePtr,
+ tempNode );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+
+ break;
+
+ case XML_CDATA_SECTION_NODE:
+ rc = XmlDocCreateCDATASectionEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ gRootDoc,
+ newNode.
+ nodeValue,
+ &cdataSecNode );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+
+ rc = XmlNodeAppendChild( xmlParser->
+ currentNodePtr,
+ &( cdataSecNode->node ) );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+ break;
+
+ case XML_ATTRIBUTE_NODE:
+ rc = XMLParserProcessAttributeName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ gRootDoc,
+ xmlParser,
+ &newNode );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ else // ETag==TRUE, endof element tag.
+ {
+ rc = ParserETagVerification(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser, &newNode );
+ if ( rc != XML_OK )
+ {
+ goto ErrorHandler;
+ }
+ xmlParser->state = E_CONTENT;
+ }
+
+ // reset bETag flag
+ bETag = FALSE;
+
+ }
+ else if ( bETag == TRUE ) // file is done
+ {
+ break;
+ }
+ else
+ {
+ rc = XML_FAILED;
+ goto ErrorHandler;
+ }
+ XmlParserFreeNodeContent(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ &newNode );
+
+ }
+
+ if ( xmlParser->pCurElement != NULL )
+ {
+ rc = XML_SYNTAX_ERR;
+ goto ErrorHandler;
+ }
+
+ *retDoc = ( XmlDocument * ) gRootDoc;
+ XMLParserFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser );
+ return rc;
+
+ErrorHandler:
+ XmlParserFreeNodeContent(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ &newNode );
+ XmlDocumentFree(
+
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ gRootDoc );
+ XMLParserFree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser );
+ return rc;
+
+}
+
+/*==============================================================================*
+* XMLParserSetLastElem
+* set the last element to be the given string.
+* Internal to parser only.
+*
+*===============================================================================*/
+static int
+XMLParserSetLastElem(
+ Pool * pool,
+
+ XMLParser * xmlParser,
+ IN const char *s )
+{
+ int rc;
+
+ if ( ( xmlParser == NULL ) || ( s == NULL ) )
+ {
+ return XML_FAILED;
+ }
+
+ rc = XmlBufferAssignString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ &( xmlParser->lastElem ), s );
+ return rc;
+}
+
+/*==============================================================================*
+*
+* ParserClearTokenBuf
+* clear token buffer.
+* Internal to parser only.
+*
+*===============================================================================*/
+static void
+ParserClearTokenBuf(
+ Pool * pool,
+ XMLParser * xmlParser )
+{
+ XmlBufferDestroy(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ &( xmlParser->tokenBuf ) );
+}
+
+/*==============================================================================*
+*
+* ParserAppendTokBufStr
+* Appends string s to token buffer
+* Internal to parser only.
+*
+*===============================================================================*/
+static int
+ParserAppendTokBufStr(
+ Pool * pool,
+
+ XMLParser * xmlParser,
+ IN const char *s )
+{
+ int rc = XML_OK;
+
+ if ( s != NULL )
+ {
+ rc = XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ &( xmlParser->tokenBuf ), s );
+ }
+
+ return rc;
+}
+
+/*==============================================================================*
+*
+* ParserAppendTokBufChar
+* Appends c to token buffer.
+* Internal to parser only.
+*
+*===============================================================================*/
+static int
+ParserAppendTokBufChar(
+ Pool * pool,
+ XMLParser * xmlParser,
+ IN char c )
+{
+ int rc;
+
+ rc = XmlBufferAppend(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ &( xmlParser->tokenBuf ), &c );
+ return rc;
+}
+
+/*==============================================================================*
+*
+* XMLParserSkipWhiteSpaces
+* skip white spaces
+* Internal to parser only
+*
+*===============================================================================*/
+static void
+XMLParserSkipWhiteSpaces( XMLParser * xmlParser )
+{
+ while ( ( *( xmlParser->curPtr ) != 0 ) &&
+ ( strchr( WHITESPACE, *( xmlParser->curPtr ) ) != NULL ) )
+ {
+ xmlParser->curPtr++;
+ }
+
+}
+
+/*==============================================================================*
+* XMLParserGetChar
+* returns next char value and its length
+* Internal to parser only
+*
+*===============================================================================*/
+static int
+XMLParserGetChar( IN char *src,
+ INOUT int *cLen )
+{
+ char *pnum;
+ int sum;
+ char c;
+ int i;
+
+ if ( src == NULL || cLen == NULL )
+ {
+ return -1;
+ }
+
+ *cLen = 0;
+
+ if ( *src != '&' )
+ {
+ if ( *src > 0 && XMLParserIsXmlChar( *src ) )
+ {
+ *cLen = 1;
+ return *src;
+ }
+
+ i = Parser_UTF8ToInt( src, cLen );
+ if ( !XMLParserIsXmlChar( i ) )
+ {
+ return -1;
+ }
+ return i;
+ }
+ else if ( XMLStrncasecmp( src, QUOT, strlen( QUOT ) ) == 0 )
+ {
+ *cLen = strlen( QUOT );
+ return '"';
+ }
+ else if ( XMLStrncasecmp( src, LT, strlen( LT ) ) == 0 )
+ {
+ *cLen = strlen( LT );
+ return '<';
+ }
+ else if ( XMLStrncasecmp( src, GT, strlen( GT ) ) == 0 )
+ {
+ *cLen = strlen( GT );
+ return '>';
+ }
+ else if ( XMLStrncasecmp( src, APOS, strlen( APOS ) ) == 0 )
+ {
+ *cLen = strlen( APOS );
+ return '\'';
+ }
+ else if ( XMLStrncasecmp( src, AMP, strlen( AMP ) ) == 0 )
+ {
+ *cLen = strlen( AMP );
+ return '&';
+ }
+ else if ( XMLStrncasecmp( src, ESC_HEX, strlen( ESC_HEX ) ) == 0 ) // Read in escape characters of type &#xnn where nn is a hexadecimal value
+ {
+ pnum = src + strlen( ESC_HEX );
+ sum = 0;
+ while ( strchr( HEX_NUMBERS, *pnum ) != 0 )
+ {
+ c = *pnum;
+ if ( c <= '9' )
+ {
+ sum = sum * 16 + ( c - '0' );
+ }
+ else if ( c <= 'F' )
+ {
+ sum = sum * 16 + ( c - 'A' + 10 );
+ }
+ else
+ {
+ sum = sum * 16 + ( c - 'a' + 10 );
+ }
+
+ pnum++;
+ }
+
+ if ( ( pnum == src ) || *pnum != ';' || !XMLParserIsXmlChar( sum ) )
+ {
+ return -1;
+ }
+
+ *cLen = pnum - src + 1;
+ return sum;
+
+ }
+ else if ( XMLStrncasecmp( src, ESC_DEC, strlen( ESC_DEC ) ) == 0 )
+ {
+ // Read in escape characters of type &#nn where nn is a decimal value
+ pnum = src + strlen( ESC_DEC );
+ sum = 0;
+ while ( strchr( DEC_NUMBERS, *pnum ) != 0 )
+ {
+ sum = sum * 10 + ( *pnum - '0' );
+ pnum++;
+ }
+
+ if ( ( pnum == src ) || *pnum != ';' || !XMLParserIsXmlChar( sum ) )
+ {
+ return -1;
+ }
+
+ *cLen = pnum - src + 1;
+ return sum;
+ }
+
+ return -1;
+}
+
+/*==============================================================================*
+* XMLParserCopyToken
+* copy string in src into xml parser token buffer
+* Internal to parser only.
+*
+*===============================================================================*/
+static int
+XMLParserCopyToken(
+ Pool * pool,
+
+ XMLParser * xmlParser,
+ IN char *src,
+ IN int len )
+{
+ int i,
+ c,
+ cl;
+ char *psrc,
+ *pend;
+ utf8char uch;
+
+ if ( !src || len <= 0 )
+ {
+ return XML_FAILED;
+ }
+
+ psrc = src;
+ pend = src + len;
+
+ while ( psrc < pend )
+ {
+ if ( ( c = XMLParserGetChar( psrc, &cl ) ) <= 0 )
+ {
+ return XML_FAILED;
+ }
+
+ if ( cl == 1 )
+ {
+ ParserAppendTokBufChar(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ xmlParser, ( char )c );
+ psrc++;
+ }
+ else
+ {
+
+ i = XMLParserIntToUTF8( c, uch );
+ if ( i == 0 )
+ {
+ return XML_FAILED;
+ }
+
+ ParserAppendTokBufStr(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser, uch );
+ psrc += cl;
+ }
+ }
+
+ if ( psrc > pend )
+ {
+ return XML_FAILED;
+ }
+ else
+ {
+ return XML_OK; // success
+ }
+
+}
+
+/*==============================================================================*
+*
+* XMLParserSkipString
+* Skips all characters in the string until it finds the skip key.
+* Then it skips the skip key and returns.
+* Internal to parser only
+*
+*===============================================================================*/
+static int
+XMLParserSkipString( INOUT char **pstrSrc,
+ IN const char *strSkipKey )
+{
+ if ( !( *pstrSrc ) || !strSkipKey )
+ {
+ return XML_FAILED;
+ }
+
+ while ( ( **pstrSrc )
+ && strncmp( *pstrSrc, strSkipKey,
+ strlen( strSkipKey ) ) != 0 )
+ {
+ ( *pstrSrc )++;
+ }
+
+ if ( **pstrSrc == '\0' )
+ {
+ return XML_SYNTAX_ERR;
+ }
+ *pstrSrc = *pstrSrc + strlen( strSkipKey );
+
+ return XML_OK; //success
+}
+
+/*==============================================================================*
+*
+* Function:
+* Returns:
+*
+*
+*===============================================================================*/
+static int
+XMLParserSkipPI( INOUT char **pSrc )
+{
+ char *pEnd = NULL;
+
+// assert( *pSrc );
+ if ( *pSrc == NULL )
+ {
+ return XML_FAILED;
+ }
+
+ if ( ( XMLStrncasecmp( *pSrc, ( char * )XMLDECL, strlen( XMLDECL ) ) == 0 ) || ( XMLStrncasecmp( *pSrc, ( char * )XMLDECL2, strlen( XMLDECL2 ) ) == 0 ) ) // not allowed
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ if ( XMLStrncasecmp( *pSrc, ( char * )BEGIN_PI, strlen( BEGIN_PI ) ) == 0 )
+ {
+ pEnd = strstr( *pSrc, END_PI );
+ if ( ( pEnd != NULL ) && ( pEnd != *pSrc ) )
+ {
+ *pSrc = pEnd + strlen( BEGIN_PI );
+ }
+ else
+ {
+ return XML_SYNTAX_ERR;
+ }
+ }
+
+ return XML_OK;
+}
+
+/*==============================================================================*
+* XMLParserSkipXMLDecl:
+* skips XML declarations.
+* Internal only to parser.
+*
+*===============================================================================*/
+static int
+XMLParserSkipXMLDecl( INOUT XMLParser * xmlParser )
+{
+ int rc = XML_FAILED;
+
+// assert( xmlParser );
+ if ( xmlParser == NULL )
+ {
+ return rc;
+ }
+
+ rc = XMLParserSkipString( &( xmlParser->curPtr ), END_PI );
+ XMLParserSkipWhiteSpaces( xmlParser );
+ return rc;
+
+}
+
+/*==============================================================================*
+* XMLParserSkipProlog
+* skip prolog
+* Internal to parser only.
+*
+*===============================================================================*/
+static int
+XMLParserSkipProlog( INOUT XMLParser * xmlParser )
+{
+ int rc = XML_OK;
+
+// assert( xmlParser != NULL );
+ if ( xmlParser == NULL )
+ {
+ return XML_FAILED;
+ }
+
+ XMLParserSkipWhiteSpaces( xmlParser );
+
+ if ( strncmp( xmlParser->curPtr, ( char * )XMLDECL, strlen( XMLDECL ) ) == 0 ) // <?xml
+ {
+ rc = XMLParserSkipXMLDecl( xmlParser );
+ if ( rc != XML_OK )
+ {
+ return rc;
+ }
+ }
+
+ rc = XMLParserSkipMisc( xmlParser );
+ if ( ( rc == XML_OK ) && strncmp( xmlParser->curPtr, ( char * )BEGIN_DOCTYPE, strlen( BEGIN_DOCTYPE ) ) == 0 ) // <! DOCTYPE
+ {
+ xmlParser->curPtr++;
+ rc = XMLParserSkipDocType( &( xmlParser->curPtr ) );
+ }
+
+ if ( rc == XML_OK )
+ {
+ rc = XMLParserSkipMisc( xmlParser );
+ }
+
+ return rc;
+}
+
+/*==============================================================================*
+*
+* Function:
+* Returns:
+* Skips all characters in the string until it finds the skip key.
+* Then it skips the skip key and returns.
+*
+*===============================================================================*/
+static int
+XMLParserSkipComment( INOUT char **pstrSrc )
+{
+ char *pStrFound = NULL;
+
+// assert( ( *pstrSrc ) != NULL );
+ if ( *pstrSrc == NULL )
+ {
+ return XML_FAILED;
+ }
+
+ pStrFound = strstr( *pstrSrc, END_COMMENT );
+ if ( ( pStrFound != NULL ) && ( pStrFound != *pstrSrc ) &&
+ ( *( pStrFound - 1 ) != '-' ) )
+ {
+ *pstrSrc = pStrFound + strlen( END_COMMENT );
+ }
+ else
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ return XML_OK;
+}
+
+/*==============================================================================*
+* XMLParserSkipDocType
+* skips document type declaration
+*
+*===============================================================================*/
+static int
+XMLParserSkipDocType( INOUT char **pstr )
+{
+ char *pCur = *pstr;
+ char *pNext = NULL; // default there is no nested <
+ int num = 1;
+
+// assert( ( *pstr ) != NULL );
+ if ( *pstr == NULL )
+ {
+ return XML_FAILED;
+ }
+
+ while ( ( pCur != NULL ) && ( num != 0 ) && ( *pCur != 0 ) )
+ {
+ if ( *pCur == '<' )
+ {
+ num++;
+ }
+ else if ( *pCur == '>' )
+ {
+ num--;
+ }
+ else if ( *pCur == '"' )
+ {
+ pNext = strchr( pCur + 1, '"' );
+ if ( pNext == NULL )
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ pCur = pNext;
+ }
+
+ pCur++;
+ }
+
+ if ( num == 0 )
+ {
+ *pstr = pCur;
+ return XML_OK;
+ }
+ else
+ {
+ return XML_SYNTAX_ERR;
+ }
+}
+
+/*==============================================================================*
+*
+* XMLParserSkipMisc:
+* skip comment, PI and white space
+*
+*
+*===============================================================================*/
+static int
+XMLParserSkipMisc( XMLParser * xmlParser )
+{
+ int rc = XML_OK;
+ int done = FALSE;
+
+ while ( ( done == FALSE ) && ( rc == XML_OK ) )
+ {
+ if ( XMLStrncasecmp( xmlParser->curPtr, ( char * )BEGIN_COMMENT, strlen( BEGIN_COMMENT ) ) == 0 ) // <!--
+ {
+ rc = XMLParserSkipComment( &( xmlParser->curPtr ) );
+
+ }
+ else if ( ( XMLStrncasecmp( xmlParser->curPtr, ( char * )XMLDECL, strlen( XMLDECL ) ) == 0 ) || ( XMLStrncasecmp( xmlParser->curPtr, ( char * )XMLDECL2, strlen( XMLDECL2 ) ) == 0 ) ) // <?xml or <?xml?
+ {
+ rc = XML_SYNTAX_ERR;
+ }
+ else if ( XMLStrncasecmp( xmlParser->curPtr, ( char * )BEGIN_PI, strlen( BEGIN_PI ) ) == 0 ) // <?
+ {
+ rc = XMLParserSkipString( &( xmlParser->curPtr ), END_PI );
+ }
+ else
+ {
+ done = TRUE;
+ }
+
+ XMLParserSkipWhiteSpaces( xmlParser );
+ }
+
+ return rc;
+}
+
+/*==============================================================================*
+*
+* XMLParserGetNextToken
+* return the length of next token in tokenBuff
+*
+*
+*===============================================================================*/
+static int
+XMLParserGetNextToken(
+ Pool * pool,
+ XMLParser * xmlParser )
+{
+ int tokenLength = 0;
+ int temp,
+ tlen;
+ int rc;
+
+ ParserClearTokenBuf(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser );
+
+ if ( *( xmlParser->curPtr ) == '\0' )
+ {
+ return 0;
+ }
+ // skip XML instructions
+ rc = XMLParserSkipMisc( xmlParser );
+ if ( rc != XML_OK )
+ {
+ return 0;
+ }
+ // Attribute value logic must come first, since all text untokenized until end-quote
+ if ( *( xmlParser->curPtr ) == QUOTE )
+ {
+ tokenLength = 1;
+ }
+ else if ( *( xmlParser->curPtr ) == SINGLEQUOTE )
+ {
+ tokenLength = 1;
+ }
+ else if ( *( xmlParser->curPtr ) == LESSTHAN ) // Check for start tags
+ {
+ temp = Parser_UTF8ToInt( xmlParser->curPtr + 1, &tlen );
+ if ( temp == '/' )
+ {
+ tokenLength = 2; // token is '</' end tag
+ }
+ else if ( XMLParserIsNameChar( temp, FALSE ) == TRUE )
+ {
+ tokenLength = 1; // '<' found, so return '<' token
+ }
+ else
+ {
+ return 0; //error
+ }
+ }
+ else if ( *( xmlParser->curPtr ) == EQUALS ) // Check for '=' token, return it as a token
+ {
+ tokenLength = 1;
+ }
+ else if ( *( xmlParser->curPtr ) == SLASH )
+ {
+ if ( *( xmlParser->curPtr + 1 ) == GREATERTHAN ) // token '/>' found
+ {
+ tokenLength = 2;
+ xmlParser->savePtr = xmlParser->curPtr; // fix
+ }
+ }
+ else if ( *( xmlParser->curPtr ) == GREATERTHAN ) // > found, so return it as a token
+ {
+ tokenLength = 1;
+ }
+ else if ( XMLParserIsNameChar( Parser_UTF8ToInt( xmlParser->curPtr, &tlen ), FALSE ) ) // Check for name tokens, name found, so find out how long it is
+ {
+ int iIndex = tlen;
+
+ while ( XMLParserIsNameChar
+ ( Parser_UTF8ToInt( xmlParser->curPtr + iIndex, &tlen ),
+ TRUE ) )
+ {
+ iIndex += tlen;
+ }
+ tokenLength = iIndex;
+ }
+ else
+ {
+ return 0;
+ }
+
+ // Copy the token to the return string
+ if ( XMLParserCopyToken(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser, xmlParser->curPtr, tokenLength ) !=
+ XML_OK )
+ {
+ return 0;
+ }
+
+ xmlParser->curPtr += tokenLength;
+ return tokenLength;
+}
+
+/*==============================================================================*
+*
+* XMLParserGetNameSpace
+* return the namespce as defined as prefix.
+* Internal to parser only
+*
+*===============================================================================*/
+static char *
+XMLParserGetNameSpace( XMLParser * xmlParser,
+ IN char *prefix )
+{
+ XmlElementStack *pCur;
+ XmlNameSpaceURI *pNsUri;
+
+ pCur = xmlParser->pCurElement;
+ if ( strcmp( pCur->prefix, prefix ) != 0 )
+ {
+ pNsUri = pCur->pNsURI;
+ while ( pNsUri != NULL )
+ {
+ if ( strcmp( pNsUri->prefix, prefix ) == 0 )
+ {
+ return pNsUri->nsURI;
+ }
+ pNsUri = pNsUri->nextNsURI;
+ }
+ }
+ else
+ {
+ return pCur->namespaceUri;
+ }
+
+ return NULL;
+
+}
+
+/*==============================================================================*
+*
+* ParserAddNamespace
+* Add a namespace definition
+* Internal to parser only
+*
+*===============================================================================*/
+static int
+ParserAddNamespace(
+ Pool * pool,
+ XMLParser * xmlParser )
+{
+ XmlNode * pNode;
+ XmlElementStack *pCur;
+ char *namespaceUri;
+
+ pNode = xmlParser->pNeedPrefixNode;
+ pCur = xmlParser->pCurElement;
+
+ if ( pNode->prefix == NULL ) // element does not have prefix
+ {
+ if ( strcmp( pNode->nodeName, pCur->element ) != 0 )
+ {
+ return XML_FAILED;
+ }
+ if ( pCur->namespaceUri != NULL )
+ {
+ // it would be wrong that pNode->namespace != NULL.
+ assert( pNode->namespaceURI == NULL );
+
+ pNode->namespaceURI = PSTRDUP( pCur->namespaceUri );
+ if ( pNode->namespaceURI == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+
+ xmlParser->pNeedPrefixNode = NULL;
+
+ }
+ else
+ {
+ if ( ( strcmp( pNode->nodeName, pCur->element ) != 0 ) &&
+ ( strcmp( pNode->prefix, pCur->prefix ) != 0 ) )
+ {
+ return XML_FAILED;
+ }
+
+ namespaceUri = XMLParserGetNameSpace( xmlParser, pCur->prefix );
+ if ( namespaceUri != NULL )
+ {
+ pNode->namespaceURI = PSTRDUP( namespaceUri );
+ if ( pNode->namespaceURI == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ xmlParser->pNeedPrefixNode = NULL;
+ }
+ }
+ return XML_OK;
+}
+
+/*==============================================================================*
+*
+* XmlParserSetNodePrefixAndLocalName
+* set the node prefix and localName as defined by the nodeName
+* in the form of ns:name
+* Internal to parser only.
+*
+*===============================================================================*/
+int
+#ifdef USE_CWMP_MEMORY_POOL
+XmlParserSetNodePrefixAndLocalName(Pool * pool, XmlNode * node )
+#else
+XmlParserSetNodePrefixAndLocalName( XmlNode * node )
+#endif
+
+{
+
+ char *pStrPrefix = NULL;
+ char *pLocalName;
+ int nPrefix;
+
+// assert( node != NULL );
+ if ( node == NULL )
+ {
+ return XML_FAILED;
+ }
+
+ pStrPrefix = strchr( node->nodeName, ':' );
+ if ( pStrPrefix == NULL )
+ {
+ node->prefix = NULL;
+ node->localName = PSTRDUP( node->nodeName );
+ if ( node->localName == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ }
+ else // fill in the local name and prefix
+ {
+
+ pLocalName = ( char * )pStrPrefix + 1;
+ nPrefix = pStrPrefix - node->nodeName;
+ node->prefix = PMALLOC( nPrefix + 1 );
+ if ( node->prefix == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ memset( node->prefix, 0, nPrefix + 1 );
+ strncpy( node->prefix, node->nodeName, nPrefix );
+
+ node->localName = PSTRDUP( pLocalName );
+ if ( node->localName == NULL )
+ {
+ PFREE( node->prefix );
+ node->prefix = NULL; //no need to PFREE really, main loop will XFREEs it
+ //when return code is not success
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+
+ return XML_OK;
+}
+
+/*==============================================================================*
+*
+* XMLParserXmlNamespace
+* add namespace definition.
+* internal to parser only.
+*
+*===============================================================================*/
+static int
+#ifdef USE_CWMP_MEMORY_POOL
+XMLParserXmlNamespace(Pool * pool, XMLParser * xmlParser,
+#else
+XMLParserXmlNamespace( XMLParser * xmlParser,
+#endif
+
+ XmlNode * newNode )
+{
+
+
+ XmlElementStack *pCur = NULL;
+ XmlNameSpaceURI *pNewNs = NULL;
+ XmlNameSpaceURI *pNs = NULL;
+ XmlNameSpaceURI *pPrevNs = NULL;
+ int rc;
+
+ // if the newNode contains a namespace definition
+ assert( newNode->nodeName != NULL );
+
+
+ if(NULL == xmlParser)
+ {
+ return XML_FAILED;
+ }
+
+ pCur = xmlParser->pCurElement;
+
+ if ( strcmp( newNode->nodeName, "xmlns" ) == 0 ) // default namespace def.
+ {
+ if(pCur == NULL)
+ {
+ return XML_FAILED;
+ }
+
+ if (pCur->namespaceUri != NULL )
+ {
+ PFREE( pCur->namespaceUri );
+ }
+
+#if 1 /* Jerry Lu Modified@Sep,14,2005 for fix PSTRDUP(NULL) cause Segment Fault */
+ if (newNode->nodeValue==NULL)
+ pCur->namespaceUri = PSTRDUP("");
+ else
+#endif
+ pCur->namespaceUri = XmlStrduptrim(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newNode->nodeValue );
+
+ if ( pCur->namespaceUri == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ }
+ else if ( strncmp( newNode->nodeName, "xmlns:", strlen( "xmlns:" ) ) == 0 ) // namespace definition
+ {
+ rc = XmlParserSetNodePrefixAndLocalName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newNode );
+ if ( rc != XML_OK )
+ {
+ return rc;
+ }
+
+ assert( newNode->localName != NULL );
+
+ if ( pCur == NULL )
+ {
+ return XML_FAILED;
+ }
+
+ if ( ( pCur->prefix != NULL )
+ && ( strcmp( pCur->prefix, newNode->localName ) == 0 ) )
+ {
+ pCur->namespaceUri = XmlStrduptrim(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newNode->nodeValue );
+ if ( pCur->namespaceUri == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+ else
+ {
+
+ pPrevNs = pCur->pNsURI;
+ pNs = pPrevNs;
+ while ( pNs != NULL )
+ {
+ if ( ( pNs->prefix != NULL ) &&
+ ( strcmp( pNs->prefix, newNode->localName ) == 0 ) )
+ {
+ break; // replace namespace definition
+ }
+ else
+ {
+ pPrevNs = pNs;
+ pNs = pNs->nextNsURI;
+ }
+ }
+
+ if ( pNs == NULL ) // a new definition
+ {
+ pNewNs =
+ ( XmlNameSpaceURI * )
+ PMALLOC( sizeof( XmlNameSpaceURI ) );
+ if ( pNewNs == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ memset( pNewNs, 0, sizeof( XmlNameSpaceURI ) );
+
+ pNewNs->prefix = PSTRDUP( newNode->localName );
+ if ( pNewNs->prefix == NULL )
+ {
+ PFREE( pNewNs );
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ pNewNs->nsURI = XmlStrduptrim(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newNode->nodeValue );
+ if ( pNewNs->nsURI == NULL )
+ {
+ XMLParserFreeNsURI(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ pNewNs );
+ PFREE( pNewNs );
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ if ( pCur->pNsURI == NULL )
+ {
+ pCur->pNsURI = pNewNs;
+ }
+ else
+ {
+ pPrevNs->nextNsURI = pNewNs;
+ }
+ }
+ else // udpate the namespace
+ {
+ if ( pNs->nsURI != NULL )
+ {
+ PFREE( pNs->nsURI );
+ }
+
+ pNs->nsURI = XmlStrduptrim(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ newNode->nodeValue );
+ if ( pNs->nsURI == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+ }
+ }
+
+ if ( pCur == NULL )
+ {
+ return XML_FAILED;
+ }
+
+
+ if (xmlParser->pNeedPrefixNode != NULL )
+ {
+ rc = ParserAddNamespace(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser );
+ return rc;
+ }
+ else
+ {
+ return XML_OK;
+ }
+
+}
+
+/*==============================================================================*
+*
+* ParserProcessSTag:
+* Processes the STag as defined by XML spec.
+* Internal to parser only.
+*
+*===============================================================================*/
+static int
+ParserProcessSTag(
+ Pool * pool,
+ XMLParser * xmlParser,
+ XmlNode * node )
+{
+ char *pCurToken = NULL;
+ int rc;
+
+ if ( XMLParserGetNextToken(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser ) == 0 )
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ pCurToken = ( xmlParser->tokenBuf ).buf;
+ if ( pCurToken != NULL )
+ {
+ node->nodeName = PSTRDUP( pCurToken );
+ if ( node->nodeName == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+ else
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ rc = XMLParserSetLastElem(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ xmlParser, node->nodeName );
+ if ( rc != XML_OK ) // no need to PFREE node->nodeName, main loop will PFREE it
+ {
+ return XML_FAILED;
+ }
+
+ rc = XmlParserSetNodePrefixAndLocalName(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ node );
+ if ( rc != XML_OK ) // no need to PFREE node->nodeName, main loop will PFREE it
+ {
+ return XML_FAILED;
+ }
+
+ node->nodeValue = NULL;
+ node->nodeType = XML_ELEMENT_NODE;
+
+ xmlParser->savePtr = xmlParser->curPtr;
+ if ( XMLParserGetNextToken(
+
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser ) == 0 ) // no need to PFREE node->nodeName, main loop will PFREE it
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ pCurToken = ( xmlParser->tokenBuf ).buf;
+ // check to see what is the next token
+ if ( strcmp( pCurToken, "/>" ) == 0 ) // empty element
+ {
+ xmlParser->state = E_ELEMENT;
+ xmlParser->curPtr = xmlParser->savePtr; // backup to />
+ }
+ else if ( strcmp( pCurToken, ">" ) == 0 ) // expecting text node
+ {
+ xmlParser->state = E_CONTENT;
+ }
+ else
+ {
+ xmlParser->state = E_ATTRIBUTE;
+ xmlParser->curPtr = xmlParser->savePtr;
+ }
+
+ return XML_OK;
+}
+
+/*==============================================================================*
+*
+* XMLParserHasDefaultNamespace
+* decide whether the current element has default namespace
+* Internal to parser only.
+*
+*===============================================================================*/
+static BOOL
+XMLParserHasDefaultNamespace( XMLParser * xmlParser,
+ XmlNode * newNode,
+ IN char **nsURI )
+{
+ XmlElementStack *pCur = xmlParser->pCurElement;
+
+ while ( pCur != NULL )
+ {
+ if ( ( pCur->prefix == NULL ) && ( pCur->namespaceUri != NULL ) )
+ {
+ *nsURI = pCur->namespaceUri;
+ return TRUE;
+ }
+ else
+ {
+ pCur = pCur->nextElement;
+ }
+ }
+
+ return FALSE;
+
+}
+
+/*==============================================================================*
+*
+* XMLParserElementPrefixDefined
+* decides whether element's prefix is already defined.
+* Internal to parser only.
+*
+*===============================================================================*/
+static BOOL
+XMLParserElementPrefixDefined( XMLParser * xmlParser,
+ XmlNode * newNode,
+ IN char **nsURI )
+{
+
+ XmlElementStack *pCur = xmlParser->pCurElement;
+ XmlNameSpaceURI *pNsUri;
+
+ while ( pCur != NULL )
+ {
+ if ( ( pCur->prefix != NULL )
+ && ( strcmp( pCur->prefix, newNode->prefix ) == 0 ) )
+ {
+ *nsURI = pCur->namespaceUri;
+ return TRUE;
+ }
+ else
+ {
+ pNsUri = pCur->pNsURI;
+
+ while ( pNsUri != NULL )
+ {
+ if ( strcmp( pNsUri->prefix, newNode->prefix ) == 0 )
+ {
+ *nsURI = pNsUri->nsURI;
+ return TRUE;
+ }
+ else
+ {
+ pNsUri = pNsUri->nextNsURI;
+ }
+ }
+ }
+
+ pCur = pCur->nextElement;
+
+ }
+
+ return FALSE;
+
+}
+
+/*==============================================================================*
+*
+* ParserProcessCDSect
+* Processes CDSection as defined by XML spec.
+* Internal to parser only.
+*
+*===============================================================================*/
+static int
+#ifdef USE_CWMP_MEMORY_POOL
+ParserProcessCDSect(Pool * pool, IN char **pSrc,
+#else
+ParserProcessCDSect( IN char **pSrc,
+#endif
+
+ XmlNode * node )
+{
+
+ char *pEnd;
+ int tokenLength = 0;
+ char *pCDataStart;
+
+ if ( *pSrc == NULL )
+ {
+ return XML_FAILED;
+ }
+
+ pCDataStart = *pSrc + strlen( CDSTART );
+ pEnd = pCDataStart;
+ while ( ( XMLParserIsXmlChar( *pEnd ) == TRUE ) && ( *pEnd != '0' ) )
+ {
+ if ( strncmp( pEnd, CDEND, strlen( CDEND ) ) == 0 )
+ {
+ break;
+ }
+ else
+ {
+ pEnd++;
+ }
+ }
+
+ if ( ( pEnd - pCDataStart > 0 ) && ( *pEnd != '0' ) )
+ {
+ tokenLength = pEnd - pCDataStart;
+ node->nodeValue = ( char * )PMALLOC( tokenLength + 1 );
+ if ( node->nodeValue == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ strncpy( node->nodeValue, pCDataStart, tokenLength );
+ node->nodeValue[tokenLength] = '\0';
+
+ node->nodeName = PSTRDUP( CDATANODENAME );
+ if ( node->nodeName == NULL )
+ {
+ // no need to PFREE node->nodeValue at all, bacause node contents
+ // will be XFREEd by the main loop.
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ node->nodeType = XML_CDATA_SECTION_NODE;
+ *pSrc = pEnd + strlen( CDEND );
+ return XML_OK;
+ }
+ else
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+}
+
+/*==============================================================================*
+*
+* XMLParserSetElementNamespace
+* set element's namespace
+* Internal to parser only.
+*
+*===============================================================================*/
+static int
+XMLParserSetElementNamespace(
+ Pool * pool,
+ XmlElement * newElement,
+ IN char *nsURI )
+{
+ if ( newElement != NULL )
+ {
+ if ( newElement->node.namespaceURI != NULL )
+ {
+ return XML_SYNTAX_ERR;
+ }
+ else
+ {
+ if (nsURI == NULL)
+ {
+ return XML_NAMESPACE_ERR;
+ }
+ ( newElement->node ).namespaceURI = PSTRDUP( nsURI );
+ if ( ( newElement->node ).namespaceURI == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+ }
+
+ return XML_OK;
+}
+
+/*==============================================================================*
+*
+* ParserProcessContent
+* processes the CONTENT as defined in XML spec.
+* Internal to parser only
+*
+*===============================================================================*/
+static int
+ParserProcessContent(
+ Pool * pool,
+ XMLParser * xmlParser,
+ XmlNode * node )
+{
+ char *pEndContent;
+ BOOL bReadContent;
+ int tokenLength;
+ char *notAllowed = "]]>";
+ char *pCurToken = NULL;
+
+ // save pointer for backup
+ xmlParser->savePtr = xmlParser->curPtr;
+ XMLParserSkipWhiteSpaces( xmlParser );
+
+ if ( *( xmlParser->curPtr ) == '\0' ) // end of file is reached
+ {
+ return XML_OK;
+ }
+
+ pEndContent = xmlParser->curPtr;
+ if ( *pEndContent == LESSTHAN )
+ {
+ if ( strncmp( pEndContent, ( char * )CDSTART, strlen( CDSTART ) ) ==
+ 0 )
+ {
+ if ( ParserProcessCDSect(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ &pEndContent, node ) !=
+ XML_OK )
+ {
+ return XML_SYNTAX_ERR;
+ }
+ else
+ {
+ xmlParser->curPtr = pEndContent;
+ }
+ }
+ else
+ if ( strncmp
+ ( pEndContent, ( char * )BEGIN_COMMENT,
+ strlen( BEGIN_COMMENT ) ) == 0 )
+ {
+ if ( XMLParserSkipComment( &pEndContent ) != XML_OK )
+ {
+ return XML_SYNTAX_ERR;
+ }
+ else
+ {
+ xmlParser->curPtr = pEndContent;
+ }
+ }
+ else
+ if ( strncmp
+ ( pEndContent, ( char * )BEGIN_PI,
+ strlen( BEGIN_PI ) ) == 0 )
+ {
+ if ( XMLParserSkipPI( &pEndContent ) != XML_OK )
+ {
+ return XML_SYNTAX_ERR;
+ }
+ else
+ {
+ xmlParser->curPtr = pEndContent;
+ }
+ }
+ else // empty content
+ {
+ xmlParser->state = E_ELEMENT;
+ }
+ }
+ else
+ {
+ // backup
+ xmlParser->curPtr = xmlParser->savePtr;
+ pEndContent = xmlParser->curPtr;
+
+ while ( ( *pEndContent != LESSTHAN ) &&
+ ( strncmp
+ ( pEndContent, ( const char * )notAllowed,
+ strlen( notAllowed ) ) != 0 ) && *pEndContent )
+ {
+ pEndContent++;
+ }
+
+ if ( *pEndContent == '\0' )
+ {
+ bReadContent = FALSE;
+ }
+
+ if ( strncmp
+ ( pEndContent, ( const char * )notAllowed,
+ strlen( notAllowed ) ) == 0 )
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ tokenLength = pEndContent - xmlParser->curPtr;
+ ParserClearTokenBuf(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser );
+
+ if ( XMLParserCopyToken(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser, xmlParser->curPtr, tokenLength )
+ != XML_OK )
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ pCurToken = ( xmlParser->tokenBuf ).buf;
+ if ( pCurToken != NULL )
+ {
+ node->nodeValue = XmlStrduptrim(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ pCurToken );
+ if ( node->nodeValue == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+ else
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ node->nodeName = PSTRDUP( TEXTNODENAME );
+ if ( node->nodeName == NULL )
+ {
+ return XML_SYNTAX_ERR;
+ }
+ node->nodeType = XML_TEXT_NODE;
+
+ // adjust curPtr
+ xmlParser->curPtr += tokenLength;
+
+ }
+
+ return XML_OK;
+}
+
+/*==============================================================================*
+*
+* ParserProcessETag
+* process ETag as defined by XML spec.
+* Internal to parser only.
+*
+*===============================================================================*/
+static int
+ParserProcessETag(
+ Pool * pool,
+ XMLParser * xmlParser,
+ XmlNode * node,
+ OUT BOOL * bETag )
+{
+ char *pCurToken = NULL;
+
+ assert( xmlParser != NULL );
+ if ( XMLParserGetNextToken(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser ) == 0 )
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ pCurToken = ( xmlParser->tokenBuf ).buf;
+ if ( pCurToken == NULL )
+ {
+ return XML_SYNTAX_ERR;
+ }
+ node->nodeName = PSTRDUP( pCurToken );
+ if ( node->nodeName == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+
+ node->nodeValue = NULL;
+ node->nodeType = XML_ELEMENT_NODE;
+
+ XMLParserSkipWhiteSpaces( xmlParser );
+
+ // read the >
+ if ( XMLParserGetNextToken(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser ) == 0 )
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ pCurToken = ( xmlParser->tokenBuf ).buf;
+ if ( pCurToken == NULL ) // no need to PFREE node->nodeName, it is XFREEd by main loop
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ if ( strcmp( pCurToken, ">" ) != 0 )
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ *bETag = TRUE;
+ return XML_OK;
+}
+
+/*==============================================================================*
+*
+* XMLParserFreeElementStackItem
+* XFREEs one ElementStack item.
+* Internal to parser only.
+*
+*===============================================================================*/
+static void
+XMLParserFreeElementStackItem(
+ Pool * pool,
+ XmlElementStack * pItem )
+{
+ assert( pItem != NULL );
+ if ( pItem->element != NULL )
+ {
+ PFREE( pItem->element );
+ pItem->element = NULL;
+ }
+ if ( pItem->namespaceUri != NULL )
+ {
+ PFREE( pItem->namespaceUri );
+ pItem->namespaceUri = NULL;
+ }
+ if ( pItem->prefix != NULL )
+ {
+ PFREE( pItem->prefix );
+ pItem->prefix = NULL;
+ }
+
+}
+
+/*==============================================================================*
+*
+* XMLParserFreeNsURI
+* XFREEs namespaceURI item.
+* Internal to parser only.
+*
+*===============================================================================*/
+static void
+XMLParserFreeNsURI(
+ Pool * pool,
+ XmlNameSpaceURI * pNsURI )
+{
+ assert( pNsURI != NULL );
+ if ( pNsURI->nsURI != NULL )
+ {
+ PFREE( pNsURI->nsURI );
+ }
+ if ( pNsURI->prefix != NULL )
+ {
+ PFREE( pNsURI->prefix );
+ }
+}
+
+/*==============================================================================*
+*
+* XMLParserFree
+* XFREEs all temporary memory allocated by xmlparser.
+* Internal to parser only
+*
+*
+*===============================================================================*/
+static void
+XMLParserFree(
+ Pool * pool,
+ XMLParser * xmlParser )
+{
+ XmlElementStack *pElement,
+ *pNextElement;
+ XmlNameSpaceURI *pNsURI,
+ *pNextNsURI;
+
+ if ( xmlParser == NULL )
+ {
+ return;
+ }
+
+ if ( xmlParser->dataBuffer != NULL )
+ {
+ PFREE( xmlParser->dataBuffer );
+ }
+
+ XmlBufferDestroy(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ &( xmlParser->tokenBuf ) );
+ XmlBufferDestroy(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ &( xmlParser->lastElem ) );
+
+ pElement = xmlParser->pCurElement;
+ while ( pElement != NULL )
+ {
+ XMLParserFreeElementStackItem(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ pElement );
+
+ pNsURI = pElement->pNsURI;
+ while ( pNsURI != NULL )
+ {
+ pNextNsURI = pNsURI->nextNsURI;
+ XMLParserFreeNsURI(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ pNsURI );
+ PFREE( pNsURI );
+ pNsURI = pNextNsURI;
+ }
+
+ pNextElement = pElement->nextElement;
+ PFREE( pElement );
+ pElement = pNextElement;
+ }
+
+ PFREE( xmlParser );
+
+}
+
+/*==============================================================================*
+*
+* XMLParserParseReference
+* return XML_OK or not
+*
+*
+*===============================================================================*/
+static int
+XMLParserParseReference( IN char *pStr )
+{
+ // place holder for future implementation
+ return XML_OK;
+}
+
+/*==============================================================================*
+*
+* XMLParserProcessAttribute
+* processes attribute.
+* Internal to parser only.
+* returns XML_OK or failure
+*
+*
+*===============================================================================*/
+static int
+XMLParserProcessAttribute(
+ Pool * pool,
+
+ XMLParser * xmlParser,
+ XmlNode * node )
+{
+
+ char *strEndQuote = NULL;
+ int tlen = 0;
+ char *pCur = NULL;
+ char *pCurToken = NULL;
+
+// assert( xmlParser );
+ if ( xmlParser == NULL )
+ {
+ return XML_FAILED;
+ }
+
+ pCurToken = ( xmlParser->tokenBuf ).buf;
+ if ( pCurToken == NULL )
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ if ( XMLParserIsNameChar( Parser_UTF8ToInt( pCurToken, &tlen ), FALSE ) ==
+ FALSE )
+ {
+ return XML_SYNTAX_ERR;
+ }
+ // copy in the attribute name
+ node->nodeName = PSTRDUP( pCurToken );
+ if ( node->nodeName == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ // read in the "=" sign
+ if ( XMLParserGetNextToken(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser ) == 0 )
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ pCurToken = ( xmlParser->tokenBuf ).buf;
+ if ( *pCurToken != EQUALS )
+ {
+ return XML_SYNTAX_ERR;
+ }
+ // read in the single quote or double quote
+ if ( XMLParserGetNextToken(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser ) == 0 )
+ {
+ return XML_SYNTAX_ERR;
+ }
+ // pCurToken is either quote or singlequote
+ pCurToken = ( xmlParser->tokenBuf ).buf;
+ if ( ( *pCurToken != QUOTE ) && ( *pCurToken != SINGLEQUOTE ) )
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ strEndQuote = strstr( xmlParser->curPtr, pCurToken );
+ if ( strEndQuote == NULL )
+ {
+ return XML_SYNTAX_ERR;
+ }
+ // check between curPtr and strEndQuote, whether there are illegal chars.
+ pCur = xmlParser->curPtr;
+ while ( pCur < strEndQuote )
+ {
+ if ( *pCur == '<' )
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ if ( *pCur == '&' )
+ {
+ XMLParserParseReference( ++pCur );
+ }
+ pCur++;
+ }
+ //clear token buffer
+ ParserClearTokenBuf(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser );
+ if ( strEndQuote != xmlParser->curPtr )
+ {
+ if ( XMLParserCopyToken(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ xmlParser, xmlParser->curPtr,
+ strEndQuote - xmlParser->curPtr ) !=
+ XML_OK )
+ {
+ return XML_SYNTAX_ERR;
+ }
+ }
+ // skip the ending quote
+ xmlParser->curPtr = strEndQuote + 1;
+
+ pCurToken = ( xmlParser->tokenBuf ).buf;
+ if ( pCurToken != NULL ) // attribute has value, like a="c"
+ {
+ node->nodeValue = XmlStrduptrim(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ pCurToken );
+ if ( node->nodeValue == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ }
+ // if attribute doesn't have value, like a="", fine
+ node->nodeType = XML_ATTRIBUTE_NODE;
+
+ // check whether this is a new namespace definition
+ if ( XMLParserXmlNamespace(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ xmlParser, node ) != XML_OK )
+ {
+ return XML_FAILED;
+ }
+ // read ahead to see whether we have more attributes
+ xmlParser->savePtr = xmlParser->curPtr;
+ if ( XMLParserGetNextToken(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ xmlParser ) == 0 )
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ pCurToken = ( xmlParser->tokenBuf ).buf;
+ if ( strcmp( pCurToken, "<" ) == 0 )
+ {
+ return XML_FAILED;
+ }
+ else if ( strcmp( pCurToken, ">" ) != 0 ) // more attribute?
+ {
+ // backup
+ xmlParser->curPtr = xmlParser->savePtr;
+ }
+ else
+ {
+ xmlParser->state = E_CONTENT;
+ }
+
+ return XML_OK;
+}
+
+/*==============================================================================*
+*
+* XMLParserGetNextNode
+* return next node
+* returns XML_OK or
+*
+*
+*===============================================================================*/
+static int
+XMLParserGetNextNode(
+ Pool * pool,
+ XMLParser * xmlParser,
+ OUT XmlNode * node,
+ OUT BOOL * bETag )
+{
+ char *pCurToken = NULL;
+ char *lastElement = NULL;
+
+ // endof file reached?
+ if (xmlParser == NULL || *( xmlParser->curPtr ) == '\0' )
+ {
+ *bETag = TRUE;
+ return XML_FILE_DONE;
+ }
+
+ if ( xmlParser->state == E_CONTENT )
+ {
+ if ( ParserProcessContent(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ xmlParser, node ) != XML_OK )
+ {
+ return XML_FAILED;
+ }
+ }
+ else
+ {
+ XMLParserSkipWhiteSpaces( xmlParser );
+
+ if ( ( XMLParserGetNextToken(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ xmlParser ) == 0 ) && ( xmlParser->pCurElement == NULL ) && ( *( xmlParser->curPtr ) == '\0' ) ) // comments after the xml doc
+ {
+ return XML_OK;
+ }
+ else if ( ( xmlParser->tokenBuf ).length == 0 )
+ {
+ return XML_SYNTAX_ERR;
+ }
+
+ pCurToken = ( xmlParser->tokenBuf ).buf;
+ if ( *pCurToken == GREATERTHAN )
+ {
+ return XML_OK;
+ }
+ else if ( strcmp( pCurToken, ENDTAG ) == 0 ) // we got </, read next element
+ {
+ return ParserProcessETag(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ xmlParser, node, bETag );
+ }
+ else if ( *pCurToken == LESSTHAN )
+ {
+ return ParserProcessSTag(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser, node );
+ }
+ else if ( strcmp( pCurToken, COMPLETETAG ) == 0 )
+ {
+ lastElement = ( xmlParser->lastElem ).buf;
+ if ( lastElement == NULL )
+ {
+ goto ErrorHandler;
+ }
+
+ node->nodeName = PSTRDUP( lastElement );
+ if ( node->nodeName == NULL )
+ {
+ return XML_INSUFFICIENT_MEMORY;
+ }
+ node->nodeType = XML_ELEMENT_NODE;
+ *bETag = TRUE;
+
+ return XML_OK;
+ }
+ else if ( xmlParser->state == E_ATTRIBUTE )
+ {
+ if ( XMLParserProcessAttribute(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlParser, node ) !=
+ XML_OK )
+ {
+ return XML_SYNTAX_ERR;
+ }
+ }
+ else
+ {
+ return XML_SYNTAX_ERR;
+ }
+ }
+
+ return XML_OK;
+
+ErrorHandler:
+
+ return XML_SYNTAX_ERR;
+
+}
diff --git a/ap/app/cwmp/netcwmp/libxmlet/src/xmlet.c b/ap/app/cwmp/netcwmp/libxmlet/src/xmlet.c
new file mode 100755
index 0000000..c5a8a17
--- /dev/null
+++ b/ap/app/cwmp/netcwmp/libxmlet/src/xmlet.c
@@ -0,0 +1,1129 @@
+///////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2003 Intel Corporation
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+// * Neither name of Intel Corporation nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////
+
+#include "xmlbuffer.h"
+#include "xmlparser.h"
+
+/*================================================================
+* XmlCopyWithEscape
+*
+*
+*=================================================================*/
+void
+XmlCopyWithEscape(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+
+ XmlBuffer * buf,
+ IN char *p )
+{
+ int i;
+ int plen;
+
+ if ( p == NULL )
+ return;
+
+ plen = strlen( p );
+
+ for ( i = 0; i < plen; i++ )
+ {
+ switch ( p[i] )
+ {
+ case '<':
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "<" );
+ break;
+
+ case '>':
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, ">" );
+ break;
+
+ case '&':
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "&" );
+ break;
+
+ case '\'':
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "'" );
+ break;
+
+ case '\"':
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, """ );
+ break;
+
+ default:
+ XmlBufferAppend(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ buf, &p[i] );
+ }
+ }
+}
+
+/*================================================================
+* XmlPrintDomTreeRecursive
+* It is a recursive function to print all the node in a tree.
+* Internal to parser only.
+*
+*=================================================================*/
+void
+XmlPrintDomTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+
+ XmlNode * nodeptr,
+ XmlBuffer * buf )
+{
+ char *nodeName = NULL;
+ char *nodeValue = NULL;
+ XmlNode * child = NULL;
+ XmlNode * sibling = NULL;
+
+ if ( nodeptr != NULL )
+ {
+ nodeName = ( char * )XmlNodeGetNodeName( nodeptr )? ( char * )XmlNodeGetNodeName( nodeptr ):"";
+ nodeValue = XmlNodeGetNodeValue( nodeptr );
+
+ switch ( XmlNodeGetNodeType( nodeptr ) )
+ {
+
+ case XML_TEXT_NODE:
+ XmlCopyWithEscape(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ buf, nodeValue );
+ break;
+
+ case XML_CDATA_SECTION_NODE:
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeValue );
+ break;
+
+ case XML_PROCESSING_INSTRUCTION_NODE:
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "<?" );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeName );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, " " );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeValue );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "?>\n" );
+ break;
+
+ case XML_DOCUMENT_NODE:
+ XmlPrintDomTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ XmlNodeGetFirstChild
+ ( nodeptr ), buf );
+ break;
+
+ case XML_ATTRIBUTE_NODE:
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeName );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "=\"" );
+ if ( nodeValue != NULL )
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeValue );
+ }
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "\"" );
+ if ( nodeptr->nextSibling != NULL )
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, " " );
+ XmlPrintDomTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ nodeptr->nextSibling, buf );
+ }
+ break;
+
+ case XML_ELEMENT_NODE:
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "<" );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeName );
+
+ if ( nodeptr->firstAttr != NULL )
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ buf, " " );
+ XmlPrintDomTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ nodeptr->firstAttr, buf );
+ }
+
+ child = XmlNodeGetFirstChild( nodeptr );
+ if ( ( child != NULL )
+ && ( XmlNodeGetNodeType( child ) ==
+ XML_ELEMENT_NODE ) )
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ buf, ">\n" );
+ // output the children
+ XmlPrintDomTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ XmlNodeGetFirstChild
+ ( nodeptr ), buf );
+
+
+ }
+ else
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ buf, ">" );
+
+
+ if (nodeValue)
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeValue );
+ }
+
+ }
+
+
+ // Done with children. Output the end tag.
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "</" );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeName );
+
+ sibling = XmlNodeGetNextSibling( nodeptr );
+ if ( sibling != NULL
+ && XmlNodeGetNodeType( sibling ) == XML_TEXT_NODE )
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, ">" );
+ }
+ else
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, ">\n" );
+ }
+ XmlPrintDomTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ XmlNodeGetNextSibling
+ ( nodeptr ), buf );
+ break;
+
+ default:
+ break;
+ }
+ }
+}
+
+/*================================================================
+* XmlPrintDomTree
+* Print a DOM tree.
+* Element, and Attribute nodes are handled differently.
+* We don't want to print the Element and Attribute nodes' sibling.
+* External function.
+*
+*=================================================================*/
+void
+XmlPrintDomTree(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+
+ XmlNode * nodeptr,
+ XmlBuffer * buf )
+{
+ char *nodeName = NULL;
+ char *nodeValue = NULL;
+ XmlNode * child = NULL;
+
+ if ( ( nodeptr == NULL ) || ( buf == NULL ) )
+ {
+ return;
+ }
+
+ nodeName = ( char * )XmlNodeGetNodeName( nodeptr )? ( char * )XmlNodeGetNodeName( nodeptr ):"";
+ nodeValue = XmlNodeGetNodeValue( nodeptr );
+
+ switch ( XmlNodeGetNodeType( nodeptr ) )
+ {
+
+ case XML_TEXT_NODE:
+ case XML_CDATA_SECTION_NODE:
+ case XML_PROCESSING_INSTRUCTION_NODE:
+ case XML_DOCUMENT_NODE:
+ XmlPrintDomTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ nodeptr, buf );
+ break;
+
+ case XML_ATTRIBUTE_NODE:
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeName );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "=\"" );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeValue );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "\"" );
+ break;
+
+ case XML_ELEMENT_NODE:
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "<" );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ buf, nodeName );
+
+ if ( nodeptr->firstAttr != NULL )
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, " " );
+ XmlPrintDomTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ nodeptr->firstAttr, buf );
+ }
+
+
+ child = XmlNodeGetFirstChild( nodeptr );
+ if ( ( child != NULL )
+ && ( XmlNodeGetNodeType( child ) == XML_ELEMENT_NODE ) )
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, ">\n" );
+
+
+ // output the children
+ XmlPrintDomTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ XmlNodeGetFirstChild( nodeptr ),
+ buf );
+
+ }
+ else
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, ">" );
+
+
+ if (nodeValue)
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeValue );
+ }
+ }
+
+
+
+ // Done with children. Output the end tag.
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "</" );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeName );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, ">\n" );
+ break;
+
+ default:
+ break;
+ }
+}
+
+/*================================================================
+* XmlPrintDomTreeIdent
+* It is a recursive function to print all the node in a tree.
+* Internal to parser only.
+*
+*=================================================================*/
+void
+XmlPrintDomTreeIdent(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ XmlNode * nodeptr,
+ XmlBuffer * buf )
+{
+ char *nodeName = NULL;
+ char *nodeValue = NULL;
+ XmlNode * child = NULL;
+ XmlNode * sibling = NULL;
+ int i;
+ static int curDeepth = 0;
+
+ if ( nodeptr != NULL )
+ {
+ nodeName = ( char * )XmlNodeGetNodeName( nodeptr )?( char * )XmlNodeGetNodeName( nodeptr ):"";
+ nodeValue = XmlNodeGetNodeValue( nodeptr );
+
+ switch ( XmlNodeGetNodeType( nodeptr ) )
+ {
+
+ case XML_TEXT_NODE:
+ XmlCopyWithEscape(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeValue );
+ break;
+
+ case XML_CDATA_SECTION_NODE:
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeValue );
+ break;
+
+ case XML_PROCESSING_INSTRUCTION_NODE:
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "<?" );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeName );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, " " );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeValue );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "?>\n" );
+ break;
+
+ case XML_DOCUMENT_NODE:
+ XmlPrintDomTreeIdent(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ XmlNodeGetFirstChild
+ ( nodeptr ), buf );
+ break;
+
+ case XML_ATTRIBUTE_NODE:
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeName );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "=\"" );
+ if ( nodeValue != NULL )
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeValue );
+ }
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "\"" );
+ if ( nodeptr->nextSibling != NULL )
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, " " );
+ XmlPrintDomTreeIdent(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ nodeptr->nextSibling, buf );
+ }
+ break;
+
+ case XML_ELEMENT_NODE:
+
+ for (i=0;i<curDeepth;i++)
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, " " );
+
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "<" );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeName );
+
+ if ( nodeptr->firstAttr != NULL )
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, " " );
+ XmlPrintDomTreeIdent(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ nodeptr->firstAttr, buf );
+ }
+
+ child = XmlNodeGetFirstChild( nodeptr );
+ if ( ( child != NULL )
+ && ( XmlNodeGetNodeType( child ) ==
+ XML_ELEMENT_NODE ) )
+ {
+
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, ">\n" );
+
+ curDeepth++;
+
+ }
+ else
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, ">" );
+ }
+
+ // output the children
+ XmlPrintDomTreeIdent(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ XmlNodeGetFirstChild
+ ( nodeptr ), buf );
+
+ if (( child != NULL ) &&
+ XmlNodeGetNodeType( child ) == XML_ELEMENT_NODE)
+ {
+ curDeepth--;
+
+ for (i=0;i<curDeepth;i++)
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, " " );
+ }
+
+ // Done with children. Output the end tag.
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "</" );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeName );
+
+ sibling = XmlNodeGetNextSibling( nodeptr );
+ if ( sibling != NULL
+ && XmlNodeGetNodeType( sibling ) == XML_TEXT_NODE )
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, ">" );
+ }
+ else
+ {
+
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, ">\n" );
+
+ }
+ XmlPrintDomTreeIdent(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ XmlNodeGetNextSibling
+ ( nodeptr ), buf );
+ break;
+
+ default:
+ break;
+ }
+ }
+
+}
+
+/*================================================================
+* XmlDomTreetoString
+* Converts a DOM tree into a text string
+* Element, and Attribute nodes are handled differently.
+* We don't want to print the Element and Attribute nodes' sibling.
+* External function.
+*
+*=================================================================*/
+void
+XmlDomTreetoString(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+
+ XmlNode * nodeptr,
+ XmlBuffer * buf )
+{
+ char *nodeName = NULL;
+ char *nodeValue = NULL;
+ XmlNode * child = NULL;
+
+ if ( ( nodeptr == NULL ) || ( buf == NULL ) )
+ {
+ return;
+ }
+
+ nodeName = ( char * )XmlNodeGetNodeName( nodeptr )?( char * )XmlNodeGetNodeName( nodeptr ):"";
+ nodeValue = XmlNodeGetNodeValue( nodeptr );
+
+ switch ( XmlNodeGetNodeType( nodeptr ) )
+ {
+
+ case XML_TEXT_NODE:
+ case XML_CDATA_SECTION_NODE:
+ case XML_PROCESSING_INSTRUCTION_NODE:
+ case XML_DOCUMENT_NODE:
+ XmlPrintDomTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ nodeptr, buf );
+ break;
+
+ case XML_ATTRIBUTE_NODE:
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeName );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "=\"" );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeValue );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "\"" );
+ break;
+
+ case XML_ELEMENT_NODE:
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "<" );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeName );
+
+ if ( nodeptr->firstAttr != NULL )
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, " " );
+ XmlPrintDomTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ nodeptr->firstAttr, buf );
+ }
+
+ child = XmlNodeGetFirstChild( nodeptr );
+#if 1
+
+#ifdef USE_CWMP_MEMORY_POOL
+ XmlBufferAppendString(pool ,buf, ">" );
+#else
+ XmlBufferAppendString(buf, ">" );
+#endif
+
+
+#else
+ if ( ( child != NULL )
+ && ( XmlNodeGetNodeType( child ) == XML_ELEMENT_NODE ) )
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, ">" );
+
+ }
+ else
+ {
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, ">" );
+ }
+#endif
+
+ // output the children
+ XmlPrintDomTreeRecursive(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ XmlNodeGetFirstChild( nodeptr ),
+ buf );
+
+ // Done with children. Output the end tag.
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, "</" );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, nodeName );
+ XmlBufferAppendString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buf, ">" );
+ break;
+
+ default:
+ break;
+ }
+}
+
+/*================================================================
+* XmlLoadDocumentEx
+* Parses the given file, and returns the DOM tree from it.
+* External function.
+*
+*=================================================================*/
+int
+XmlLoadDocumentEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ IN char *xmlFile,
+ XmlDocument ** doc )
+{
+
+ if ( ( xmlFile == NULL ) || ( doc == NULL ) )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+
+ return XmlParserLoadDocument(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ doc, xmlFile, TRUE );
+}
+
+/*================================================================
+* XmlLoadDocument
+* Parses the given file, and returns the DOM tree from it.
+* External function.
+*
+*=================================================================*/
+XmlDocument *
+XmlLoadDocument(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+
+ IN char *xmlFile )
+{
+
+ XmlDocument *doc = NULL;
+
+ XmlLoadDocumentEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ xmlFile, &doc );
+ return doc;
+}
+
+/*================================================================
+* XmlPrintNode
+* Print DOM tree under node. Puts lots of white spaces
+* External function.
+*
+*=================================================================*/
+char *
+XmlPrintNode(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+
+ XmlNode * node )
+{
+
+ XmlBuffer memBuf;
+ XmlBuffer *buf = &memBuf;
+
+ if ( node == NULL )
+ {
+ return NULL;
+ }
+
+ XmlBufferInit( buf );
+ XmlPrintDomTree(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ node, buf );
+ return buf->buf;
+
+}
+
+/*================================================================
+* XmlPrintNode
+* converts DOM tree under node to text string
+* External function.
+*
+*=================================================================*/
+char *
+XmlNodeToString(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+
+ XmlNode * node )
+{
+
+ XmlBuffer memBuf;
+ XmlBuffer *buf = &memBuf;
+
+ if ( node == NULL )
+ {
+ return NULL;
+ }
+
+ XmlBufferInit( buf );
+ XmlDomTreetoString(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+
+ node, buf );
+ return buf->buf;
+
+}
+
+/*================================================================
+* XmlParseBufferEx
+* Parse xml file stored in buffer.
+* External function.
+*
+*=================================================================*/
+int
+XmlParseBufferEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ IN char *buffer,
+ XmlDocument ** retDoc )
+{
+
+ if ( ( buffer == NULL ) || ( retDoc == NULL ) )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+
+ if ( strlen( buffer ) == 0 )
+ {
+ return XML_INVALID_PARAMETER;
+ }
+
+ return XmlParserLoadDocument(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ retDoc, buffer, FALSE );
+}
+
+
+/*================================================================
+* XmlParseBuffer
+* Parse xml file stored in buffer.
+* External function.
+*
+*=================================================================*/
+XmlDocument *
+XmlParseBuffer(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ IN char *buffer )
+{
+ XmlDocument *doc = NULL;
+
+ XmlParseBufferEx(
+#ifdef USE_CWMP_MEMORY_POOL
+ pool ,
+#endif
+ buffer, &doc );
+ return doc;
+}
+
+/*================================================================
+* XmlCloneDOMString
+* Clones a DOM String.
+* External function.
+*
+*=================================================================*/
+char *
+XmlCloneDOMString(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ const char * src )
+{
+ if ( src == NULL )
+ {
+ return NULL;
+ }
+
+ return ( PSTRDUP( src ) );
+}
+
+/*================================================================
+* XmlFreeDOMString
+* Frees a DOM String.
+* External function.
+*
+*=================================================================*/
+void
+XmlFreeDOMString(
+#ifdef USE_CWMP_MEMORY_POOL
+ Pool * pool,
+#endif
+ IN char * buf )
+{
+ if ( buf != NULL )
+ {
+ PFREE( buf );
+ }
+}
+
+