initial submission / version 1.4.0

git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@4 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Oxy 2006-06-06 08:51:22 +00:00
parent 517cac71aa
commit fa017dde60
179 changed files with 61331 additions and 0 deletions

0
libupnp/AUTHORS Normal file
View File

0
libupnp/COPYING Normal file
View File

278
libupnp/ChangeLog Normal file
View File

@ -0,0 +1,278 @@
*************************************************************************
Release of version 1.4.0
*************************************************************************
2006-05-26 Oxy <virtual_worlds@gmx.de>
* defines in iasnprintf.h changed to work with GCC-version < 3
2006-05-22 Oxy <virtual_worlds@gmx.de>
* BSD-patch added (not tested yet on an BSD system)
2006-05-19 Oxy <virtual_worlds@gmx.de>
* Patch added for bug: ixml parser colapsed on empty args (arg="")
2006-05-18 Oxy <virtual_worlds@gmx.de>
* DSM-320 patch added (fetched from project MediaTomb)
* httpGet additons atch added, Added proxy support by introducing
UpnpOpenHttpGetProxy. UpnpOpenHttpGet now just calls
UpnpOpenHttpGetProxy with the proxy url set to NULL.
* Bugfix for typo ("\0" / "0") in ixmlparser.c
* Bugfix for M-Search packet
*************************************************************************
FORK FROM DEAD libupnp
*************************************************************************
2006-04-29 Rémi Turboult <r3mi@users.sourceforge.net>
* THANKS: new file with list of contributors
* upnp/src/gena/gena_device.c (respond_ok): add 'Content-Length: 0'
in subscription response. Patch by Chaos (Bug # 1455367).
2006-04-08 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/doc/UPnP_Programming_Guide.pdf: replace this document with
the one in libupnp-doc-1.2.1 because current CVS version
was corrupted.
2006-04-06
* changes applied to several files to work under Sparc Solaris, temporarily
requiring a define SPARC_SOLARIS
2006-04-03 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/Makefile.am: install upnp samples in $(docdir)/examples
2006-03-28 Rémi Turboult <r3mi@users.sourceforge.net>
* configure.ac: add --with-docdir option to choose where documentation
is installed (or -without-docdir to not install the documentation)
2006-03-27 Rémi Turboult <r3mi@users.sourceforge.net>
* ixml/test: add simple test suite for xml parser
2006-03-26 Rémi Turboult <r3mi@users.sourceforge.net>
* ixml/src/ixmlparser.c (Parser_processCDSect): fix bug which prevents
CDATA sections which contain a 0 (zero) to be parsed (instead the
parsing of the whole document is aborted). Patch by Arno Willig
(Patch # 1432124).
* configure.ac, upnp/Makefile.am: add "--disable-samples" configure
option, and move samples compilation from check_PROGRAMS to
noinst_PROGRAMS
2006-03-25 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/src/genlib/miniserver/miniserver.c (get_miniserver_sockets):
fix bug if new socket created has fd 0 (can only occur when stdin
has been closed). Patch by Oskar Liljeblad 2004-07-02 :
http://sourceforge.net/mailarchive/message.php?msg_id=8870528
2006-03-21 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/test/test_init.c: add some version checks and exit if failure
2006-03-05 Rémi Turboult <r3mi@users.sourceforge.net>
* libupnp version 1.3.1
* upnp/inc/upnpconfig.h.in: add new define UPNP_VERSION_PATCH
* upnp/test/test_init.c: add simple test to run during checks
* upnp/inc/upnp.h: include "upnpdebug.h" only if debug enabled
in the library (else header file is not installed)
* upnp/Makefile.am (libupnp_la_LDFLAGS): add inter-library libtool
dependencies between upnp and ixml / threadutil, so that programs
linking against upnp only still work.
2006-03-04 Rémi Turboult <r3mi@users.sourceforge.net>
* libupnp version 1.3.0
2006-03-03 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/src/genlib/net/http/httpreadwrite.c (get_sdk_info): use
package version string from configure to set sdk info
* upnp/Makefile.am: add sample/tvdevice/web/ files in EXTRA_DIST
+ do not distribute generated upnpconfig.h file.
2006-02-28 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/src/inc/config.h, configure.ac: use only new defines
UPNP_HAVE_xx instead of INCLUDE_yyy_APIS and INTERNAL_WEB_SERVER
* upnp/Makefile.am, ixml/Makefile.am: add -export-symbols-regex to
the librarie LDFLAGS in order to export only the symbols defined
in the API
2006-02-27 Rémi Turboult <r3mi@users.sourceforge.net>
* configure.ac: add libtool versions for the 3 libraries
* ixml/src/ixml.c (copy_with_escape): add missing 'static' to function
* threadutil/src/ThreadPool.c (SetSeed): add missing 'static'
2006-02-26 Rémi Turboult <r3mi@users.sourceforge.net>
* threadutil/inc/iasnprintf.h: add gcc __printf__ format attribute
to "iasnprintf"
* upnp/src/api/upnpapi.c: fix invalid UpnpPrintf formats
* upnp/src/gena/gena_device.c: fix invalid UpnpPrintf formats
* upnp/src/inc/config.h: move upnp/inc/config.h to internal
sources (this file is no longer installed with the libraries)
* upnp/inc/upnpdebug.h: new file created from debug definitions
previously in upnp/inc/config.h
* upnp/src/api/config.c: rename to upnp/src/api/upnpdebug.c
* upnp/inc/upnpconfig.h.in: new file to contain information on
the configuration of the installed libraries (generates installed
file <upnp/upnpconfig.h>)
2006-02-22 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/ : add missing include of config.h in some .c files
2006-02-21 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/inc/upnp.h: move some definitions which should not be
exported into "upnp/src/inc/util.h"
* import all modifications below from libupnp in djmount 0.51
into official libupnp
2006-01-17 Rémi Turboult <r3mi@users.sourceforge.net>
* threadutil/Makefile.am (libthreadutil_la_SOURCES): remove extraneous
file
2006-01-15 Rémi Turboult <r3mi@users.sourceforge.net>
* configure.ac: add checks for large-file support
* upnp/inc/config.h: rename to "upnpconfig.h". The new "config.h" file
is the one generated by autoconf.
* m4/type_socklen_t.m4: added new check for socklen_t (fallback to
int if not defined)
* upnp/src/genlib/miniserver/miniserver.c,
upnp/src/ssdp/ssdp_server.c: use socklen_t where appropriate
(instead of int)
* upnp/src/genlib/net/http/httpreadwrite.c (get_sdk_info): remove
XINLINE declaration (unused and too late)
* ixml/src/node.c (ixmlNode_getNodeType): fix compilation warning
on const return type
2006-01-12 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/src/inc/readwrite.h : suppress unused C++ header file
2006-01-11 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/inc/config.h, upnp/src/inc/upnpapi.h,
upnp/src/inc/httpreadwrite.h: remove internal configuration variable
MINIMUM_DELAY (no clear purpose)
2005-12-05 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/inc/upnp.h: re-declare obsolete method UpnpSetContentLength,
for binary compatibility with previous libupnp version.
* upnp/src/api/upnpapi.c: correct type of g_maxContentLength to size_t
2005-11-01 Rémi Turboult <r3mi@users.sourceforge.net>
* autoconfiscate library : replace all makefiles by Makefile.am
for automake support, + preliminary autoconf support
(generated config.h not yet used in source files)
2005-10-18 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/src/makefile: fix location of DEBUG STATIC libupnp library
* upnp/sample/tvctrlpt/linux/Makefile,
upnp/sample/tvdevice/linux/Makefile: fix STATIC library support
2005-10-16 Rémi Turboult <r3mi@users.sourceforge.net>
* threadutil/src/Makefile (clean): remove built library
2005-08-28 Rémi Turboult <r3mi@users.sourceforge.net>
* ixml/src/ixml.h, ixml/src/ixml.c (ixmlRelaxParser) : new function
* ixml/src/ixmlparser.h, ixml/src/ixmlparser.c (Parser_setErrorChar) :
new function
2005-08-02 Rémi Turboult <r3mi@users.sourceforge.net>
* ixml/src/Makefile: correct bug for static library being incorrectly
stripped when building non-debug
2005-06-09 Rémi Turboult <r3mi@users.sourceforge.net>
* ixml/src/element.c (ixmlElement_removeAttributeNode):
remove some compilation warning
* ixml/inc/ixml.h, ixml/src/document.c :
add some missing const's in public API
* upnp/inc/upnptools.h, upnp/src/api/upnptools.c :
add missing const's in public API
2005-05-28 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/inc/config.h: suppress HTTP_READ_BYTES (unused)
and replace by DEFAULT_SOAP_CONTENT_LENGTH (previously in upnpapi.h)
* upnp/inc/upnp.h, upnp/src/api/upnpapi.c : replace
UpnpSetContentLength (which was not using its Handle argument)
by global function UpnpSetMaxContentLength.
Remove "hard" limitation to 32K (not suitable for using in UPnP AV).
* upnp/src/inc/upnpapi.h : removed DEFAULT_SOAP_CONTENT_LENGTH
(moved to config.h) and MAX_SOAP_CONTENT_LENGTH (now unused)
* upnp/src/api/upnptools.c : add more error message strings
* upnp/src/genlib/net/http/httpreadwrite.c : return OUTOF_BOUNDS
instead of BAD_HTTPMSG when allowed Content Length is exceeded.
* upnp/src/genlib/net/http/httpreadwrite.c : corrected an incorrect
sprintf format
2005-05-27 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/makefile, upnp/src/makefile,
ixml/Makefile, ixml/src/Makefile,
threadutil/Makefile, threadutil/src/Makefile :
implement STATIC library support (from patch at
http://sourceforge.net/tracker/?group_id=7189&atid=307189 )
2005-05-26 Rémi Turboult <r3mi@users.sourceforge.net>
* upnp/src/api/upnpapi.c, upnp/src/soap/soap_device.c,
upnp/src/soap/makefile :
corrections for compilation with CLIENT=1 only
* importing "libupnp-1.2.1a" as baseline

0
libupnp/INSTALL Normal file
View File

27
libupnp/LICENSE Normal file
View File

@ -0,0 +1,27 @@
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.

37
libupnp/Makefile.am Normal file
View File

@ -0,0 +1,37 @@
# $Id: Makefile.am,v 1.5 2006/04/29 20:12:50 r3mi Exp $
#
# Top-level "Makefile.am" for libupnp
#
# Copyright (C) 2005 Rémi Turboult <r3mi@users.sourceforge.net>
#
ACLOCAL_AMFLAGS = -I m4
DISTCHECK_CONFIGURE_FLAGS = --enable-debug --enable-samples
SUBDIRS = ixml threadutil upnp
EXTRA_DIST = libupnp.pc.in LICENSE THANKS
# This variable must have 'exec' in its name, in order to be installed
# by 'install-exec' target (instead of default 'install-data')
pkgconfigexecdir = $(libdir)/pkgconfig
pkgconfigexec_DATA = libupnp.pc
$(pkgconfigexec_DATA): config.status
if WITH_DOCDIR
docdir = @DOCDIR@
doc_DATA = LICENSE README NEWS TODO THANKS
endif
CLEANFILES = IUpnpErrFile.txt IUpnpInfoFile.txt

84
libupnp/NEWS Normal file
View File

@ -0,0 +1,84 @@
What is new in libupnp 1.3.1
* fix: "upnp.h" includes "upnpdebug.h" only if debug enabled in the library
(else header file is not installed)
* fix: add inter-library dependencies between upnp and ixml / threadutil,
so that programs linking against upnp only still work.
============================================================================
What is new in libupnp 1.3.0
* major change: autoconfiscate build system. automake + autoconf replace the
previous makefiles. This should allow for easier build and installation on
various distributions.
* change: optional library features are selected with configure options
(such as "./configure --enable-debug --disable-device") : see README file
for the main options, and "./configure --help" to display a complete list.
* new: install a pkgconfig file "libupnp.pc"
* new: a new installed file <upnp/upnpconfig.h> provides macros to know
the installed library version, and the optional features which have
been configured in the library.
* change: the old included file "config.h", which contained internal
definitions needed to compile the library, is no longer installed in <upnp>
* change: the debug definitions previously available in <upnp/config.h>
are now available in <upnp/upnpdebug.h> (only if library configured with
debug enabled).
* change: add libtool versionning for the 3 libraries.
Also hide all library symbols not part of the public API.
* change: remove "hard" limit to 32K in UpnpSetContentLength
(not suitable for UPnP AV clients).
* new: new "UpnpSetMaxContentLength" function to globally set the maximum
incoming content-length that the SDK will process (should be used instead
of UpnpSetContentLength, which does not uses its handle argument)
* change: returns OUTOF_BOUNDS instead of BAD_HTTPMSG when exceed allowed
Content Length
* new: ixml: new function ixmlRelaxParser to make the XML parser more tolerant
to malformed text, if required (default behaviour is unchanged : abort
on error)
* fix: compilation error with gcc4
* fix: add some missing const's in public API
* fix: add check for availability of socklen_t type
* fix: miscellaneous bugs and warnings (see details in ChangeLog)
============================================================================
Changes to the SDK for UPnP Devices version 1.2.1a:
- Changes the NAME_SIZE constant used for URL buffers to 256 bytes to
accomodate longer URLs.
============================================================================
Changes to the SDK for UPnP Devices version 1.2.1:
- Integrates an entirely new XML parser that features DOM2 API support and
a much smaller code size.
- Integrates a new threading utility library that manages all threads in
the library.
- Elimination of C++ and other code optimizations have reduced the binary
size by over 60%.
- The web server now supports application-level callbacks to handle
dynamically generated data.
- The web server now correctly handles chunked encoding.
- A new client HTTP API has been added that allows downloading of items
of unlimited size.
- The SDK supports much better cross-compilation support.
- Numerous memory leaks and bugs have been fixed.

294
libupnp/README Normal file
View File

@ -0,0 +1,294 @@
Linux* SDK for UPnP* Devices (libupnp)
Copyright (c) 2000-2003 Intel Corporation - All Rights Reserved.
Copyright (c) 2005-2006 Rémi Turboult <r3mi@users.sourceforge.net>
See LICENSE for details.
This file contains information about the above product in the following
sections:
1. Release Contents
2. Package Contents
3. System Requirements
4. Build Instructions
5. Install/Uninstall Instructions
6. Product Release Notes
7. New Features
8. Support and Contact Information
1) Release Contents
-------------------------------------------
The Linux SDK for UPnP Devices is an SDK for development of UPnP device
and control point applications for Linux. It consists of the core UPnP
protocols along with a UPnP-specific eXtensible Markup Language (XML) parser
supporting the Document Object Model (DOM) Level 2 API and an optional,
integrated mini web server for serving UPnP related documents.
2) Package Contents
-------------------------------------------
The Linux SDK for UPnP Devices contains the following:
README This file. Contains the installation and build instructions.
LICENSE The licensing terms the SDK is distributed under.
NEWS Changes and new features.
ixml\doc The files for generating the XML parser documentation from
the source code.
ixml\inc The public include files required to use the XML parser.
ixml\src The source code to the XML parser library.
threadutil\inc The public include files required to the threading
utility library.
threadutil\src The source code to the threading utility library.
upnp\doc The files for generating the SDK documentation from the
source code.
upnp\inc The public include files required to use the SDK.
upnp\src The source files comprising the SDK, libupnp.so.
upnp\sample A sample device and control point application, illustrating the
usage of the SDK.
3) System Requirements
-------------------------------------------
The SDK for UPnP Devices is designed to compile and run under the
Linux operating system. It does, however, have dependencies on some
packages that may not be installed by default. All packages that it
requires are listed below. The name of the package and where it can be
found is dependent on the distribution of Linux being used.
libpthread The header and library are installed as part of the glibc-devel
package (or equivalent).
Additionally, the documentation for the SDK can be auto-generated from
the UPNP.H header file using DOC++, a documentation system for C, C++,
IDL, and Java*. DOC++ generates the documentation in HTML or TeX format.
Using some additional tools, the TeX output can be converted into a
PDF file. To generate the documentation these tools are required:
DOC++ The homepage for DOC++ is http://docpp.sourceforge.net/.
The current version as of this release of the SDK is
version 3.4.9. DOC++ is the only requirement for generating
the HTML documentation.
LaTeX/TeX To generate the PDF documentation, LaTeX and TeX tools are
necessary. The tetex and tetex-latex packages provide these
tools.
dvips dvips converts the DVI file produced by LaTeX into a PostScript*
file. The tetex-dvips package provides this tool.
ps2pdf The final step to making the PDF is converting the PostStript
into Portable Document Format. The ghostscript package provides
this tool.
For the UPnP library to function correctly, Linux networking must be configured
properly for multicasting. To do this:
route add -net 239.0.0.0 netmask 255.0.0.0 eth0
where 'eth0' is the network adapter that the UPnP library will use. Without
this addition, device advertisements and control point searches will not
function.
libupnp has been built and tested on the following configurations:
* MandrakeLinux 10.1 (kernel 2.6.8.1-12mdk, gcc 3.4.1, glibc-2.3.3)
* Ubuntu 5.10 "Breezy Badger" (Linux kernel 2.6.12-9-386, gcc 4.0.2 20050808
prerelease, libc6 2.3.5-1ubuntu12)
4) Build Instructions
-------------------------------------------
CORE LIBRARIES
The in the examples below, replace $(LIBUPNP) with "libupnp-x.y.z",
with x, y, and z corresponding to the version of the library that you have.
All pieces of the SDK are configured and built from the $(LIBUPNP) directory.
% cd $(LIBUPNP)
% ./configure
% make
will build a version of the binaries without debug support, and with default
options enabled (see below for options available at configure time).
To build the documentation, assuming all the necessary tools are installed
(see section 3) :
To generate the HTML documentation:
% cd $(LIBUPNP)
% make html
To generate the PDF file:
% cd $(LIBUPNP)
% make pdf
A few options are available at configure time. Use "./configure --help"
to display a complete list of options. Note that these options
may be combined in any order.
After installation, the file <upnp/upnpconfig.h> will provide a summary
of the optional features that have been included in the library.
% cd $(LIBUPNP)
% ./configure --enable-debug
% make
will build a debug version with symbols support.
To build the library with the optional, integrated mini web server (note
that this is the default):
% cd $(LIBUPNP)
% ./configure --enable-webserver
% make
To build without:
% cd $(LIBUPNP)
% ./configure --disable-webserver
% make
The SDK for Linux also contains some additional helper APIs, declared in
inc/tools/upnptools.h. If these additional tools are not required, they can
be compiled out:
% cd $(LIBUPNP)
% ./configure --disable-tools
% make
By default, the tools are included in the library.
To further remove code that is not required, the library can be build with or
with out the control point (client) or device specific code. To remove this
code:
% cd $(LIBUPNP)
% ./configure --disable-client
% make
to remove client only code or:
% cd $(LIBUPNP)
% ./configure --disable-device
% make
to remove device only code.
By default, both client and device code is included in the library. The
integrated web server is automatically removed when configuring with
--disable-device.
To build the library without large-file support (enabled by default) :
% cd $(LIBUPNP)
% ./configure --disable-largefile
% make
To remove all the targets, object files, and built documentation:
% cd $(LIBUPNP)
% make clean
CROSS COMPILATION
To cross compile the SDK, a special "configure" directive is all that is
required:
% cd $(LIBUPNP)
% ./configure --host=arm-linux
% make
This will invoke the "arm-linux-gcc" cross compiler to build the library.
SAMPLES
The SDK contains two samples: a TV device application and a control point
that talks with the TV device. They are found in the $(LIBUPNP)/upnp/sample
directory.
To build the samples (note: this is the default behaviour):
% cd $(LIBUPNP)
% ./configure --enable-samples
% make
will build the sample device "$(LIBUPNP)/upnp/upnp_tv_device" and
sample control point "$(LIBUPNP)/upnp/upnp_tv_ctrlpt".
Note : the sample device won't be built if --disable-device has been
configured, and the sample control point won't be build if --disable-client
has been configured.
To run the sample device, you need the "$(LIBUPNP)/upnp/sample/tvdevice/web"
sub-directory. Example :
% cd $(LIBUPNP)/upnp/sample/tvdevice
% ../../upnp_tv_device
5) Install/Uninstall Instructions
-------------------------------------------
Install
The top-level makefile for the UPnP SDK contains rules to install the
necessary components. To install the SDK, as root:
make install
Uninstall
Likewise, the top-level makefile contains an uninstall rule, reversing
the steps in the install:
make uninstall
6) Product Release Notes
-------------------------------------------
The SDK for UPnP Devices v1.2.1a has these known issues:
- The UPnP library may not work with older versions of gcc and libstdc++,
causing a segmentation fault when the library loads. It is recommended
that gcc version 2.9 or later be used in building library.
- The UPnP library does not work the glibc 2.1.92-14 that ships with
Red Hat 7.0. For the library to function, you must updated the glibc
and glibc-devel packages to 2.1.94-3 or later. There is some issue with
libpthreads that has been resolved in the 2.1.94 version.
7) New Features
-------------------------------------------
See NEWS file.
8) Support and Contact Information
-------------------------------------------
Intel is not providing support for the Linux SDK for UPnP Devices. Two
mailing lists for the SDK are available on http://upnp.sourceforge.net/.
Questions and problems should be addressed on the appropriate mailing list.
If you find this SDK useful, please send an email to upnp@intel.com and let
us know.
* Other brands, names, and trademarks are the property of their respective
owners.

13
libupnp/THANKS Normal file
View File

@ -0,0 +1,13 @@
libupnp was originally written by Intel Corporation.
Many people further contributed to libupnp by reporting problems,
suggesting various improvements or submitting actual code.
Here is a list of these people. Help us keep it complete and
exempt of errors.
Patches: Arno Willig, Oskar Liljeblad, Chaos,
Nektarios K. Papadopoulos, John Dennis, Jiri Zouhar,
Marcelo Jimenez
Solaris Port: Oxy
Hints and useful bugreports: Siva Chandran

29
libupnp/TODO Normal file
View File

@ -0,0 +1,29 @@
To Be Done
==========
- add FreeBSD patches
( http://sf.net/tracker/index.php?func=detail&aid=1332618&group_id=7189&atid=307189 ?)
- non-regression testing
- replace doc++ by Doxygen for documentation generation
- incorporate public patches and fix reported bugs :
http://sourceforge.net/tracker/?group_id=7189&atid=107189 and
http://sourceforge.net/tracker/?group_id=7189&atid=307189
- RPM packaging (a preliminary one here :
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=176617 )
- make API clean for large files and 64 bits
To Be Decided
=============
- IPV6 support ?

19
libupnp/bootstrap Normal file
View File

@ -0,0 +1,19 @@
#!/bin/sh
rm -fr autom4te.cache
# Equivalent to
# aclocal
# autoheader
# automake --add-missing --copy
# autoconf
autoreconf --force --install -Wall -Wno-obsolete $* || exit 1
echo "Now run ./configure and then make."
exit 0

193
libupnp/configure.ac Normal file
View File

@ -0,0 +1,193 @@
# -*- Autoconf -*-
# $Id: configure.ac,v 1.11 2006/04/09 13:59:44 r3mi Exp $
#
# Top-level configure.ac file for libupnp
#
# Process this file with autoconf to produce a configure script.
#
# (C) Copyright 2005-2006 Rémi Turboult <r3mi@users.sourceforge.net>
#
AC_PREREQ(2.59)
AC_INIT([libupnp], [1.4.0], [virtual_worlds@gmx.de])
# *Independently* of the above libupnp package version, the libtool version
# of the 3 libraries need to be updated whenever there is a change released :
# "current:revision:age" (this is NOT the same as the package version), where:
# - library code modified: revision++
# - interfaces changed/added/removed: current++ and revision=0
# - interfaces added: age++
# - interfaces removed: age=0
# *please update only once, before a formal release, not for each change*
AC_SUBST([LT_VERSION_IXML], [2:1:0])
AC_SUBST([LT_VERSION_THREADUTIL], [2:1:0])
AC_SUBST([LT_VERSION_UPNP], [2:1:0])
AC_CONFIG_AUX_DIR(config.aux)
AC_CONFIG_MACRO_DIR(m4)
AC_CONFIG_SRCDIR(upnp/inc/upnp.h)
AM_INIT_AUTOMAKE([1.8 -Wall foreign subdir-objects])
#
# There are 3 configuration files :
# 1) "./autoconfig.h" is auto-generated and used only internally during build
# (usually named "config.h" but conflicts with the file below)
# 2) "./upnp/src/inc/config.h" is static and contains some compile-time
# parameters. This file was previously in "./upnp/inc" but is no longer
# installed (contains internal definitions only).
# 3) "./upnp/inc/upnpconfig.h" is auto-generated and installed with the
# libraries : it contains information on the configuration of the
# installed libraries.
#
AC_CONFIG_HEADERS([autoconfig.h upnp/inc/upnpconfig.h])
AC_REVISION([$Revision: 1.11 $])
upnpmaj=`echo "$PACKAGE_VERSION" | sed 's/\..*//' `
upnpmin=[`echo "$PACKAGE_VERSION" | sed 's/^[^.]\.// ; s/[^0-9].*$//' `]
upnppatch=[`echo "$PACKAGE_VERSION" | sed 's/^[^.]\.[^.]\.// ; s/[^0-9].*$//' `]
AC_DEFINE_UNQUOTED([UPNP_VERSION_STRING], "$PACKAGE_VERSION",
[see upnpconfig.h])
AC_DEFINE_UNQUOTED([UPNP_VERSION_MAJOR], $upnpmaj, [see upnpconfig.h])
AC_DEFINE_UNQUOTED([UPNP_VERSION_MINOR], $upnpmin, [see upnpconfig.h])
AC_DEFINE_UNQUOTED([UPNP_VERSION_PATCH], $upnppatch, [see upnpconfig.h])
#
# Check for DEBUG flag
#
RT_BOOL_ARG_ENABLE([debug], [no], [extra debugging code])
if test "x$enable_debug" = xyes ; then
AC_DEFINE(UPNP_HAVE_DEBUG, 1, [see upnpconfig.h])
AC_DEFINE(DEBUG, 1, [Define to 1 to compile debug code])
else
AC_DEFINE(NO_DEBUG, 1, [Define to 1 to prevent some debug code])
AC_DEFINE(NDEBUG, 1, [Define to 1 to prevent compilation of assert()])
fi
#
# Check for libupnp subsets
#
RT_BOOL_ARG_ENABLE([client], [yes], [control point code (client)])
if test "x$enable_client" = xyes ; then
AC_DEFINE(UPNP_HAVE_CLIENT, 1, [see upnpconfig.h])
fi
RT_BOOL_ARG_ENABLE([device], [yes],
[device specific code (implies --disable-webserver if disabled)])
if test "x$enable_device" = xyes ; then
AC_DEFINE(UPNP_HAVE_DEVICE, 1, [see upnpconfig.h])
fi
if test "x$enable_device" = xno ; then
enable_webserver=no
else
RT_BOOL_ARG_ENABLE([webserver], [yes], [integrated web server])
fi
AM_CONDITIONAL(ENABLE_WEBSERVER, test x"$enable_webserver" = xyes)
if test "x$enable_webserver" = xyes ; then
AC_DEFINE(UPNP_HAVE_WEBSERVER, 1, [see upnpconfig.h])
fi
RT_BOOL_ARG_ENABLE([tools], [yes], [helper APIs in upnptools.h])
if test "x$enable_tools" = xyes ; then
AC_DEFINE(UPNP_HAVE_TOOLS, 1, [see upnpconfig.h])
fi
RT_BOOL_ARG_ENABLE([samples], [yes], [compilation of upnp/sample/ code])
# doc installation
AC_MSG_CHECKING([documentation installation])
AC_ARG_WITH([docdir],
AC_HELP_STRING([--with-docdir=DIR],
[where documentation is installed
@<:@[DATADIR/doc/]AC_PACKAGE_NAME[-]AC_PACKAGE_VERSION@:>@])
AC_HELP_STRING([--without-docdir],
[do not install the documentation]),
[DOCDIR="$with_docdir"],
[DOCDIR="${datadir}/doc/${PACKAGE_NAME}-${PACKAGE_VERSION}"])
AM_CONDITIONAL(WITH_DOCDIR, test x"$with_docdir" != xno)
AC_SUBST(DOCDIR)
AC_MSG_RESULT($DOCDIR)
#
# Checks for programs
#
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_LIBTOOL
AC_PROG_INSTALL
AC_PROG_MAKE_SET
#
# Default compilation flags
#
if test x"$enable_debug" = xyes; then
# AC_PROG_CC already sets CFLAGS to "-g -O2" by default
:
else
# add optimise for size
AX_CFLAGS_GCC_OPTION([-Os])
fi
AX_CFLAGS_WARN_ALL
# Arrange for large-file support (can be disabled with --disable-largefile).
# Define _FILE_OFFSET_BITS and _LARGE_FILES if necessary
AC_SYS_LARGEFILE
#
# Checks for header files
#
AC_HEADER_STDC
# libupnp code doesn't use autoconf variables yet,
# so just abort if a header file is not found.
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h malloc.h netdb.h netinet/in.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h sys/timeb.h syslog.h unistd.h],[],[AC_MSG_ERROR([required header file missing])])
#
# Checks for typedefs, structures, and compiler characteristics
#
AC_C_CONST
AC_TYPE_SIZE_T
TYPE_SOCKLEN_T
#
# Checks for library functions
#
AC_FUNC_VPRINTF
AC_FUNC_FSEEKO
#
# Checks for POSIX Threads
#
ACX_PTHREAD([],[AC_MSG_ERROR([POSIX threads are required to build this program])])
AC_CONFIG_FILES([Makefile
ixml/Makefile
ixml/doc/Makefile
threadutil/Makefile
upnp/Makefile
upnp/doc/Makefile
libupnp.pc
])
AC_OUTPUT

50
libupnp/ixml/Makefile.am Normal file
View File

@ -0,0 +1,50 @@
# $Id: Makefile.am,v 1.4 2006/03/27 21:27:31 r3mi Exp $
#
# "Makefile.am" for "libupnp/ixml"
#
# (C) Copyright 2005 Rémi Turboult <r3mi@users.sourceforge.net>
#
SUBDIRS = doc
AM_CPPFLAGS = -I$(srcdir)/inc -I$(srcdir)/src/inc
AM_CFLAGS =
LDADD = libixml.la
if ENABLE_DEBUG
AM_CPPFLAGS += -DDEBUG
else
AM_CPPFLAGS += -DNDEBUG
endif
lib_LTLIBRARIES = libixml.la
libixml_la_LDFLAGS = -version-info $(LT_VERSION_IXML) \
-export-symbols-regex '^ixml.*'
libixml_la_SOURCES = \
src/ixml.c src/node.c src/ixmlparser.c \
src/ixmlmembuf.c src/nodeList.c \
src/element.c src/attr.c src/document.c \
src/namedNodeMap.c \
src/inc/ixmlmembuf.h src/inc/ixmlparser.h
upnpincludedir = $(includedir)/upnp
upnpinclude_HEADERS = inc/ixml.h
check_PROGRAMS = test_document
TESTS = test/test_document.sh
test_document_SOURCES = test/test_document.c
EXTRA_DIST = test/test_document.sh test/testdata
dist-hook:
rm -rf `find $(distdir)/test/testdata/ -type f \! -name '*ml' -print`
clean-local:
@if [ -d bin ] ; then rm -rf bin ; fi

View File

@ -0,0 +1,53 @@
# $Id: Makefile.am,v 1.1.1.1 2006/02/18 13:47:30 r3mi Exp $
#
# "Makefile.am" for "libunp/ixml/doc"
#
# (C) Copyright 2005 Rémi Turboult <r3mi@users.sourceforge.net>
#
##########################################################################
#
# 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.
#
##########################################################################
EXTRA_DIST= docxx.sty intro.dxx ixml.dxx license.dxx
html-local:
@if [ -d html ]; then rm -rf html; fi
@doc++ -nd -S -w -j -d html $(srcdir)/ixml.dxx
pdf-local:
@doc++ -nd -S -w -j -t --package a4wide -o ixml.tex $(srcdir)/ixml.dxx
@-pdflatex "\scrollmode\input ixml.tex" > pdflatex.log
@-pdflatex "\scrollmode\input ixml.tex" >> pdflatex.log
@-pdflatex "\scrollmode\input ixml.tex" >> pdflatex.log
clean-local:
-rm -rf html
-rm -f ixml.tex pdflatex.log ixml.log ixml.aux

1083
libupnp/ixml/doc/docxx.sty Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
/**@name Introduction
* The Linux DOM2 XML Parser Version 1.2 (IXML) is a lightweight, portable XML
* parser supporting the standard Document Object Model (DOM) Level 2
* interfaces. The parser uses a C-style interface, making it idea for small,
* embedded applications. This document describes the interfaces supported by
* IXML 1.2, referencing the W3C DOM2 recommendations when necessary, and the
* additional utility application programming interfaces (APIs) that it
* supports.
*
* Note that this document assumes that the reader has a copy of the DOM2-Core
* recommendation. Refer to the link below to obtain a copy. Only a brief
* description is included here and the reader is pointed to the DOM2-Core
* recommendation for more details. This document does, however, clarify
* IXML-specific behavior when the recommendation is unclear.
*
* {\bf About DOM}
*
* The Document Object Model (DOM) is a set of interfaces that give a
* programmatic interface to documents. It provides a platform-neutral and
* language-neutral interface for random access and updating elements inside
* XML documents. DOM Level 1 provided the basic interfaces to access
* document elements. DOM Level 2 extended the interfaces to provide proper
* support for XML namespaces.
*
* The latest DOM 2 recommendation is maintained by W3C and is available from
* {\tt http://www.w3.org/TR/DOM-Level-2-Core}.
*/

15
libupnp/ixml/doc/ixml.dxx Normal file
View File

@ -0,0 +1,15 @@
/**@name IXML v1.2
* \begin{center}
* {\bf Linux DOM2 XML Parser Version 1.2}
*
* Copyright (C) 2000-2003 Intel Corporation ALL RIGHTS RESERVED
*
* Revision 1.2.1 (\Date)
* \end{center}
*/
//@{
//@Include: intro.dxx
//@Include: license.dxx
//@Include: ../inc/ixml.h
//@}

View File

@ -0,0 +1,32 @@
/**@name License
*
* \begin{center}
* Copyright (c) 2000-2003 Intel Corporation
* All rights reserved.
* \end{center}
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* \begin{itemize}
* \item Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* \item 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.
* \item 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.
* \end{itemize}
* 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.
*
*/

1905
libupnp/ixml/inc/ixml.h Normal file

File diff suppressed because it is too large Load Diff

60
libupnp/ixml/src/attr.c Normal file
View File

@ -0,0 +1,60 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 "ixmlparser.h"
/*================================================================
* Function: Attr_init
* Initializes an attribute node
* External function.
*
*=================================================================*/
void
ixmlAttr_init( IN IXML_Attr * attr )
{
if( attr != NULL ) {
memset( attr, 0, sizeof( IXML_Attr ) );
}
}
/*================================================================
* Function: Attr_free
* Frees an attribute node.
* external function.
*
*=================================================================*/
void
ixmlAttr_free( IN IXML_Attr * attr )
{
if( attr != NULL ) {
ixmlNode_free( ( IXML_Node * ) attr );
}
}

804
libupnp/ixml/src/document.c Normal file
View File

@ -0,0 +1,804 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 "ixmlparser.h"
/*================================================================
* ixmlDocument_init
* It initialize the document structure.
* External function.
*
*=================================================================*/
void
ixmlDocument_init( IN IXML_Document * doc )
{
memset( doc, 0, sizeof( IXML_Document ) );
}
/*================================================================
* ixmlDocument_free
* It frees the whole document tree.
* External function.
*
*=================================================================*/
void
ixmlDocument_free( IN IXML_Document * doc )
{
if( doc != NULL ) {
ixmlNode_free( ( IXML_Node * ) doc );
}
}
/*================================================================
* ixmlDocument_setOwnerDocument
*
* 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 ixmlDocument_importNode
*
*=================================================================*/
void
ixmlDocument_setOwnerDocument( IN IXML_Document * doc,
IN IXML_Node * nodeptr )
{
if( nodeptr != NULL ) {
nodeptr->ownerDocument = doc;
ixmlDocument_setOwnerDocument( doc,
ixmlNode_getFirstChild( nodeptr ) );
ixmlDocument_setOwnerDocument( doc,
ixmlNode_getNextSibling
( nodeptr ) );
}
}
/*================================================================
* ixmlDocument_importNode
* 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
ixmlDocument_importNode( IN IXML_Document * doc,
IN IXML_Node * importNode,
IN BOOL deep,
OUT IXML_Node ** rtNode )
{
unsigned short nodeType;
IXML_Node *newNode;
*rtNode = NULL;
if( ( doc == NULL ) || ( importNode == NULL ) ) {
return IXML_INVALID_PARAMETER;
}
nodeType = ixmlNode_getNodeType( importNode );
if( nodeType == eDOCUMENT_NODE ) {
return IXML_NOT_SUPPORTED_ERR;
}
newNode = ixmlNode_cloneNode( importNode, deep );
if( newNode == NULL ) {
return IXML_FAILED;
}
ixmlDocument_setOwnerDocument( doc, newNode );
*rtNode = newNode;
return IXML_SUCCESS;
}
/*================================================================
* ixmlDocument_createElementEx
* 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:
* IXML_SUCCESS
* IXML_INVALID_PARAMETER: if either doc or tagName is NULL
* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
*
*=================================================================*/
int
ixmlDocument_createElementEx( IN IXML_Document * doc,
IN const DOMString tagName,
OUT IXML_Element ** rtElement )
{
int errCode = IXML_SUCCESS;
IXML_Element *newElement = NULL;
if( ( doc == NULL ) || ( tagName == NULL ) ) {
errCode = IXML_INVALID_PARAMETER;
goto ErrorHandler;
}
newElement = ( IXML_Element * ) malloc( sizeof( IXML_Element ) );
if( newElement == NULL ) {
errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
ixmlElement_init( newElement );
newElement->tagName = strdup( tagName );
if( newElement->tagName == NULL ) {
ixmlElement_free( newElement );
newElement = NULL;
errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
// set the node fields
newElement->n.nodeType = eELEMENT_NODE;
newElement->n.nodeName = strdup( tagName );
if( newElement->n.nodeName == NULL ) {
ixmlElement_free( newElement );
newElement = NULL;
errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
newElement->n.ownerDocument = doc;
ErrorHandler:
*rtElement = newElement;
return errCode;
}
/*================================================================
* ixmlDocument_createElement
* 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.
*
*=================================================================*/
IXML_Element *
ixmlDocument_createElement( IN IXML_Document * doc,
IN const DOMString tagName )
{
IXML_Element *newElement = NULL;
ixmlDocument_createElementEx( doc, tagName, &newElement );
return newElement;
}
/*================================================================
* ixmlDocument_createDocumentEx
* Creates an document object
* Internal function.
* Parameters:
* rtDoc: the document created or NULL on failure
* Return Value:
* IXML_SUCCESS
* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
*
*=================================================================*/
int
ixmlDocument_createDocumentEx( OUT IXML_Document ** rtDoc )
{
IXML_Document *doc;
int errCode = IXML_SUCCESS;
doc = NULL;
doc = ( IXML_Document * ) malloc( sizeof( IXML_Document ) );
if( doc == NULL ) {
errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
ixmlDocument_init( doc );
doc->n.nodeName = strdup( DOCUMENTNODENAME );
if( doc->n.nodeName == NULL ) {
ixmlDocument_free( doc );
doc = NULL;
errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
doc->n.nodeType = eDOCUMENT_NODE;
doc->n.ownerDocument = doc;
ErrorHandler:
*rtDoc = doc;
return errCode;
}
/*================================================================
* ixmlDocument_createDocument
* Creates an document object
* Internal function.
* Parameters:
* none
* Return Value:
* A new document object with the nodeName set to "#document".
*
*=================================================================*/
IXML_Document *
ixmlDocument_createDocument( )
{
IXML_Document *doc = NULL;
ixmlDocument_createDocumentEx( &doc );
return doc;
}
/*================================================================
* ixmlDocument_createTextNodeEx
* Creates an text node.
* External function.
* Parameters:
* data: text data for the text node. It is stored in nodeValue field.
* Return Value:
* IXML_SUCCESS
* IXML_INVALID_PARAMETER: if either doc or data is NULL
* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
*
*=================================================================*/
int
ixmlDocument_createTextNodeEx( IN IXML_Document * doc,
IN const char *data,
OUT IXML_Node ** textNode )
{
IXML_Node *returnNode;
int rc = IXML_SUCCESS;
returnNode = NULL;
if( ( doc == NULL ) || ( data == NULL ) ) {
rc = IXML_INVALID_PARAMETER;
goto ErrorHandler;
}
returnNode = ( IXML_Node * ) malloc( sizeof( IXML_Node ) );
if( returnNode == NULL ) {
rc = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
// initialize the node
ixmlNode_init( returnNode );
returnNode->nodeName = strdup( TEXTNODENAME );
if( returnNode->nodeName == NULL ) {
ixmlNode_free( returnNode );
returnNode = NULL;
rc = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
// add in node value
if( data != NULL ) {
returnNode->nodeValue = strdup( data );
if( returnNode->nodeValue == NULL ) {
ixmlNode_free( returnNode );
returnNode = NULL;
rc = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
}
returnNode->nodeType = eTEXT_NODE;
returnNode->ownerDocument = doc;
ErrorHandler:
*textNode = returnNode;
return rc;
}
/*================================================================
* ixmlDocument_createTextNode
* 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.
*
*=================================================================*/
IXML_Node *
ixmlDocument_createTextNode( IN IXML_Document * doc,
IN const char *data )
{
IXML_Node *returnNode = NULL;
ixmlDocument_createTextNodeEx( doc, data, &returnNode );
return returnNode;
}
/*================================================================
* ixmlDocument_createAttributeEx
* Creates an attribute of the given name.
* External function.
* Parameters:
* name: The name of the Attribute node.
* Return Value:
* IXML_SUCCESS
* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
*
================================================================*/
int
ixmlDocument_createAttributeEx( IN IXML_Document * doc,
IN char *name,
OUT IXML_Attr ** rtAttr )
{
IXML_Attr *attrNode = NULL;
int errCode = IXML_SUCCESS;
attrNode = ( IXML_Attr * ) malloc( sizeof( IXML_Attr ) );
if( attrNode == NULL ) {
errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
if( ( doc == NULL ) || ( name == NULL ) ) {
ixmlAttr_free( attrNode );
attrNode = NULL;
errCode = IXML_INVALID_PARAMETER;
goto ErrorHandler;
}
ixmlAttr_init( attrNode );
attrNode->n.nodeType = eATTRIBUTE_NODE;
// set the node fields
attrNode->n.nodeName = strdup( name );
if( attrNode->n.nodeName == NULL ) {
ixmlAttr_free( attrNode );
attrNode = NULL;
errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
attrNode->n.ownerDocument = doc;
ErrorHandler:
*rtAttr = attrNode;
return errCode;
}
/*================================================================
* ixmlDocument_createAttribute
* 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.
*
================================================================*/
IXML_Attr *
ixmlDocument_createAttribute( IN IXML_Document * doc,
IN char *name )
{
IXML_Attr *attrNode = NULL;
ixmlDocument_createAttributeEx( doc, name, &attrNode );
return attrNode;
}
/*================================================================
* ixmlDocument_createAttributeNSEx
* 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:
* IXML_SUCCESS
* IXML_INVALID_PARAMETER: if either doc,namespaceURI or qualifiedName is NULL
* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
*
*=================================================================*/
int
ixmlDocument_createAttributeNSEx( IN IXML_Document * doc,
IN DOMString namespaceURI,
IN DOMString qualifiedName,
OUT IXML_Attr ** rtAttr )
{
IXML_Attr *attrNode = NULL;
int errCode = IXML_SUCCESS;
if( ( doc == NULL ) || ( namespaceURI == NULL )
|| ( qualifiedName == NULL ) ) {
errCode = IXML_INVALID_PARAMETER;
goto ErrorHandler;
}
errCode =
ixmlDocument_createAttributeEx( doc, qualifiedName, &attrNode );
if( errCode != IXML_SUCCESS ) {
goto ErrorHandler;
}
// set the namespaceURI field
attrNode->n.namespaceURI = strdup( namespaceURI );
if( attrNode->n.namespaceURI == NULL ) {
ixmlAttr_free( attrNode );
attrNode = NULL;
errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
// set the localName and prefix
errCode =
ixmlNode_setNodeName( ( IXML_Node * ) attrNode, qualifiedName );
if( errCode != IXML_SUCCESS ) {
ixmlAttr_free( attrNode );
attrNode = NULL;
goto ErrorHandler;
}
ErrorHandler:
*rtAttr = attrNode;
return errCode;
}
/*================================================================
* ixmlDocument_createAttributeNS
* 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.
*
*=================================================================*/
IXML_Attr *
ixmlDocument_createAttributeNS( IN IXML_Document * doc,
IN DOMString namespaceURI,
IN DOMString qualifiedName )
{
IXML_Attr *attrNode = NULL;
ixmlDocument_createAttributeNSEx( doc, namespaceURI, qualifiedName,
&attrNode );
return attrNode;
}
/*================================================================
* ixmlDocument_createCDATASectionEx
* Creates an CDATASection node whose value is the specified string
* External function.
* Parameters:
* data: the data for the CDATASection contents.
* Return Value:
* IXML_SUCCESS
* IXML_INVALID_PARAMETER: if either doc or data is NULL
* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
*
*=================================================================*/
int
ixmlDocument_createCDATASectionEx( IN IXML_Document * doc,
IN DOMString data,
OUT IXML_CDATASection ** rtCD )
{
int errCode = IXML_SUCCESS;
IXML_CDATASection *cDSectionNode = NULL;
if( ( doc == NULL ) || ( data == NULL ) ) {
errCode = IXML_INVALID_PARAMETER;
goto ErrorHandler;
}
cDSectionNode =
( IXML_CDATASection * ) malloc( sizeof( IXML_CDATASection ) );
if( cDSectionNode == NULL ) {
errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
ixmlCDATASection_init( cDSectionNode );
cDSectionNode->n.nodeType = eCDATA_SECTION_NODE;
cDSectionNode->n.nodeName = strdup( CDATANODENAME );
if( cDSectionNode->n.nodeName == NULL ) {
ixmlCDATASection_free( cDSectionNode );
cDSectionNode = NULL;
errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
cDSectionNode->n.nodeValue = strdup( data );
if( cDSectionNode->n.nodeValue == NULL ) {
ixmlCDATASection_free( cDSectionNode );
cDSectionNode = NULL;
errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
cDSectionNode->n.ownerDocument = doc;
ErrorHandler:
*rtCD = cDSectionNode;
return errCode;
}
/*================================================================
* ixmlDocument_createCDATASection
* 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.
*
*=================================================================*/
IXML_CDATASection *
ixmlDocument_createCDATASection( IN IXML_Document * doc,
IN DOMString data )
{
IXML_CDATASection *cDSectionNode = NULL;
ixmlDocument_createCDATASectionEx( doc, data, &cDSectionNode );
return cDSectionNode;
}
/*================================================================
* ixmlDocument_createElementNSEx
* 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:
* IXML_SUCCESS
* IXML_INVALID_PARAMETER: if either doc,namespaceURI or qualifiedName is NULL
* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations.
*
*=================================================================*/
int
ixmlDocument_createElementNSEx( IN IXML_Document * doc,
IN DOMString namespaceURI,
IN DOMString qualifiedName,
OUT IXML_Element ** rtElement )
{
IXML_Element *newElement = NULL;
int errCode = IXML_SUCCESS;
if( ( doc == NULL ) || ( namespaceURI == NULL )
|| ( qualifiedName == NULL ) ) {
errCode = IXML_INVALID_PARAMETER;
goto ErrorHandler;
}
errCode =
ixmlDocument_createElementEx( doc, qualifiedName, &newElement );
if( errCode != IXML_SUCCESS ) {
goto ErrorHandler;
}
// set the namespaceURI field
newElement->n.namespaceURI = strdup( namespaceURI );
if( newElement->n.namespaceURI == NULL ) {
ixmlElement_free( newElement );
newElement = NULL;
errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
// set the localName and prefix
errCode =
ixmlNode_setNodeName( ( IXML_Node * ) newElement, qualifiedName );
if( errCode != IXML_SUCCESS ) {
ixmlElement_free( newElement );
newElement = NULL;
errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
newElement->n.nodeValue = NULL;
ErrorHandler:
*rtElement = newElement;
return errCode;
}
/*================================================================
* ixmlDocument_createElementNS
* 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.
*
*=================================================================*/
IXML_Element *
ixmlDocument_createElementNS( IN IXML_Document * doc,
IN DOMString namespaceURI,
IN DOMString qualifiedName )
{
IXML_Element *newElement = NULL;
ixmlDocument_createElementNSEx( doc, namespaceURI, qualifiedName,
&newElement );
return newElement;
}
/*================================================================
* ixmlDocument_getElementsByTagName
* 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.
*
*=================================================================*/
IXML_NodeList *
ixmlDocument_getElementsByTagName( IN IXML_Document * doc,
IN char *tagName )
{
IXML_NodeList *returnNodeList = NULL;
if( ( doc == NULL ) || ( tagName == NULL ) ) {
return NULL;
}
ixmlNode_getElementsByTagName( ( IXML_Node * ) doc, tagName,
&returnNodeList );
return returnNodeList;
}
/*================================================================
* ixmlDocument_getElementsByTagNameNS
* 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.
*
*=================================================================*/
IXML_NodeList *
ixmlDocument_getElementsByTagNameNS( IN IXML_Document * doc,
IN DOMString namespaceURI,
IN DOMString localName )
{
IXML_NodeList *returnNodeList = NULL;
if( ( doc == NULL ) || ( namespaceURI == NULL )
|| ( localName == NULL ) ) {
return NULL;
}
ixmlNode_getElementsByTagNameNS( ( IXML_Node * ) doc, namespaceURI,
localName, &returnNodeList );
return returnNodeList;
}
/*================================================================
* ixmlDocument_getElementById
* 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.
*
*=================================================================*/
IXML_Element *
ixmlDocument_getElementById( IN IXML_Document * doc,
IN DOMString tagName )
{
IXML_Element *rtElement = NULL;
IXML_Node *nodeptr = ( IXML_Node * ) doc;
const char *name;
if( ( nodeptr == NULL ) || ( tagName == NULL ) ) {
return rtElement;
}
if( ixmlNode_getNodeType( nodeptr ) == eELEMENT_NODE ) {
name = ixmlNode_getNodeName( nodeptr );
if( name == NULL ) {
return rtElement;
}
if( strcmp( tagName, name ) == 0 ) {
rtElement = ( IXML_Element * ) nodeptr;
return rtElement;
} else {
rtElement = ixmlDocument_getElementById( ( IXML_Document * )
ixmlNode_getFirstChild
( nodeptr ),
tagName );
if( rtElement == NULL ) {
rtElement = ixmlDocument_getElementById( ( IXML_Document
* )
ixmlNode_getNextSibling
( nodeptr ),
tagName );
}
}
} else {
rtElement = ixmlDocument_getElementById( ( IXML_Document * )
ixmlNode_getFirstChild
( nodeptr ), tagName );
if( rtElement == NULL ) {
rtElement = ixmlDocument_getElementById( ( IXML_Document * )
ixmlNode_getNextSibling
( nodeptr ),
tagName );
}
}
return rtElement;
}

969
libupnp/ixml/src/element.c Normal file
View File

@ -0,0 +1,969 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 "ixmlparser.h"
/*================================================================
* ixmlElement_Init
* Initializes an element node.
* External function.
*
*=================================================================*/
void
ixmlElement_init( IN IXML_Element * element )
{
if( element != NULL ) {
memset( element, 0, sizeof( IXML_Element ) );
}
}
/*================================================================
* ixmlElement_getTagName
* Gets the element node's tagName
* External function.
*
*=================================================================*/
const DOMString
ixmlElement_getTagName( IN IXML_Element * element )
{
if( element != NULL ) {
return element->tagName;
} else {
return NULL;
}
}
/*================================================================
* ixmlElement_setTagName
* Sets the given element's tagName.
* Parameters:
* tagName: new tagName for the element.
*
*=================================================================*/
int
ixmlElement_setTagName( IN IXML_Element * element,
IN char *tagName )
{
int rc = IXML_SUCCESS;
assert( ( element != NULL ) && ( tagName != NULL ) );
if( ( element == NULL ) || ( tagName == NULL ) ) {
return IXML_FAILED;
}
if( element->tagName != NULL ) {
free( element->tagName );
}
element->tagName = strdup( tagName );
if( element->tagName == NULL ) {
rc = IXML_INSUFFICIENT_MEMORY;
}
return rc;
}
/*================================================================
* ixmlElement_getAttribute
* 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.
*
*=================================================================*/
DOMString
ixmlElement_getAttribute( IN IXML_Element * element,
IN DOMString name )
{
IXML_Node *attrNode;
if( ( element == NULL ) || ( name == NULL ) ) {
return NULL;
}
attrNode = element->n.firstAttr;
while( attrNode != NULL ) {
if( strcmp( attrNode->nodeName, name ) == 0 ) { // found it
return attrNode->nodeValue;
} else {
attrNode = attrNode->nextSibling;
}
}
return NULL;
}
/*================================================================
* ixmlElement_setAttribute
* 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:
* IXML_SUCCESS or failure code.
*
*=================================================================*/
int
ixmlElement_setAttribute( IN IXML_Element * element,
IN char *name,
IN char *value )
{
IXML_Node *attrNode;
IXML_Attr *newAttrNode;
short errCode = IXML_SUCCESS;
if( ( element == NULL ) || ( name == NULL ) || ( value == NULL ) ) {
errCode = IXML_INVALID_PARAMETER;
goto ErrorHandler;
}
if( Parser_isValidXmlName( name ) == FALSE ) {
errCode = IXML_INVALID_CHARACTER_ERR;
goto ErrorHandler;
}
attrNode = element->n.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 =
ixmlDocument_createAttributeEx( ( IXML_Document * ) element->n.
ownerDocument, name,
&newAttrNode );
if( errCode != IXML_SUCCESS ) {
goto ErrorHandler;
}
attrNode = ( IXML_Node * ) newAttrNode;
attrNode->nodeValue = strdup( value );
if( attrNode->nodeValue == NULL ) {
ixmlAttr_free( newAttrNode );
errCode = IXML_INSUFFICIENT_MEMORY;
goto ErrorHandler;
}
errCode =
ixmlElement_setAttributeNode( element, newAttrNode, NULL );
if( errCode != IXML_SUCCESS ) {
ixmlAttr_free( newAttrNode );
goto ErrorHandler;
}
} else {
if( attrNode->nodeValue != NULL ) { // attribute name has a value already
free( attrNode->nodeValue );
}
attrNode->nodeValue = strdup( value );
if( attrNode->nodeValue == NULL ) {
errCode = IXML_INSUFFICIENT_MEMORY;
}
}
ErrorHandler:
return errCode;
}
/*================================================================
* ixmlElement_removeAttribute
* 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:
* IXML_SUCCESS or error code.
*
*=================================================================*/
int
ixmlElement_removeAttribute( IN IXML_Element * element,
IN char *name )
{
IXML_Node *attrNode;
if( ( element == NULL ) || ( name == NULL ) ) {
return IXML_INVALID_PARAMETER;
}
attrNode = element->n.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 ) {
free( attrNode->nodeValue );
attrNode->nodeValue = NULL;
}
}
return IXML_SUCCESS;
}
/*================================================================
* ixmlElement_getAttributeNode
* 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.
*
*=================================================================*/
IXML_Attr *
ixmlElement_getAttributeNode( IN IXML_Element * element,
IN char *name )
{
IXML_Node *attrNode;
if( ( element == NULL ) || ( name == NULL ) ) {
return NULL;
}
attrNode = element->n.firstAttr;
while( attrNode != NULL ) {
if( strcmp( attrNode->nodeName, name ) == 0 ) { // found it
break;
} else {
attrNode = attrNode->nextSibling;
}
}
return ( IXML_Attr * ) attrNode;
}
/*================================================================
* ixmlElement_setAttributeNode
* 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
ixmlElement_setAttributeNode( IN IXML_Element * element,
IN IXML_Attr * newAttr,
OUT IXML_Attr ** rtAttr )
{
IXML_Node *attrNode;
IXML_Node *node;
IXML_Node *nextAttr = NULL;
IXML_Node *prevAttr = NULL;
IXML_Node *preSib,
*nextSib;
if( ( element == NULL ) || ( newAttr == NULL ) ) {
return IXML_INVALID_PARAMETER;
}
if( newAttr->n.ownerDocument != element->n.ownerDocument ) {
return IXML_WRONG_DOCUMENT_ERR;
}
if( newAttr->ownerElement != NULL ) {
return IXML_INUSE_ATTRIBUTE_ERR;
}
newAttr->ownerElement = element;
node = ( IXML_Node * ) newAttr;
attrNode = element->n.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->n.firstAttr == attrNode ) {
element->n.firstAttr = node;
}
if( rtAttr != NULL ) {
*rtAttr = ( IXML_Attr * ) attrNode;
}
} else // add this attribute
{
if( element->n.firstAttr != NULL ) {
prevAttr = element->n.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->n.firstAttr = node;
node->prevSibling = NULL;
node->nextSibling = NULL;
}
if( rtAttr != NULL ) {
*rtAttr = NULL;
}
}
return IXML_SUCCESS;
}
/*================================================================
* ixmlElement_findAttributeNode
* 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.
*
*=================================================================*/
IXML_Node *
ixmlElement_findAttributeNode( IN IXML_Element * element,
IN IXML_Attr * oldAttr )
{
IXML_Node *attrNode;
IXML_Node *oldAttrNode = ( IXML_Node * ) oldAttr;
assert( ( element != NULL ) && ( oldAttr != NULL ) );
attrNode = element->n.firstAttr;
while( attrNode != NULL ) { // parentNode, prevSib, nextSib and ownerDocument doesn't matter
if( ixmlNode_compare( attrNode, oldAttrNode ) == TRUE ) {
break; //found it
} else {
attrNode = attrNode->nextSibling;
}
}
return attrNode;
}
/*================================================================
* ixmlElement_removeAttributeNode
* Removes the specified attribute node.
* External function.
*
* Parameters:
* oldAttr: the attr node to remove from the attribute list.
*
* Return Value:
* IXML_SUCCESS or failure
*
*=================================================================*/
int
ixmlElement_removeAttributeNode( IN IXML_Element * element,
IN IXML_Attr * oldAttr,
OUT IXML_Attr ** rtAttr )
{
IXML_Node *attrNode;
IXML_Node *preSib,
*nextSib;
if( ( element == NULL ) || ( oldAttr == NULL ) ) {
return IXML_INVALID_PARAMETER;
}
attrNode = ixmlElement_findAttributeNode( 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->n.firstAttr == attrNode ) {
element->n.firstAttr = nextSib;
}
/* ( IXML_Attr * ) */ attrNode->parentNode = NULL;
/* ( IXML_Attr * ) */ attrNode->prevSibling = NULL;
/* ( IXML_Attr * ) */ attrNode->nextSibling = NULL;
*rtAttr = ( IXML_Attr * ) attrNode;
return IXML_SUCCESS;
} else {
return IXML_NOT_FOUND_ERR;
}
}
/*================================================================
* ixmlElement_getElementsByTagName
* 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.
*
*=================================================================*/
IXML_NodeList *
ixmlElement_getElementsByTagName( IN IXML_Element * element,
IN char *tagName )
{
IXML_NodeList *returnNodeList = NULL;
if( ( element != NULL ) && ( tagName != NULL ) ) {
ixmlNode_getElementsByTagName( ( IXML_Node * ) element, tagName,
&returnNodeList );
}
return returnNodeList;
}
/*================================================================
* ixmlElement_getAttributeNS
* 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.
*
*=================================================================*/
DOMString
ixmlElement_getAttributeNS( IN IXML_Element * element,
IN DOMString namespaceURI,
IN DOMString localName )
{
IXML_Node *attrNode;
if( ( element == NULL ) || ( namespaceURI == NULL )
|| ( localName == NULL ) ) {
return NULL;
}
attrNode = element->n.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;
}
/*================================================================
* ixmlElement_setAttributeNS
* 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:
* IXML_SUCCESS or failure
*
*=================================================================*/
int
ixmlElement_setAttributeNS( IN IXML_Element * element,
IN DOMString namespaceURI,
IN DOMString qualifiedName,
IN DOMString value )
{
IXML_Node *attrNode = NULL;
IXML_Node newAttrNode;
IXML_Attr *newAttr;
int rc;
if( ( element == NULL ) || ( namespaceURI == NULL ) ||
( qualifiedName == NULL ) || ( value == NULL ) ) {
return IXML_INVALID_PARAMETER;
}
if( Parser_isValidXmlName( qualifiedName ) == FALSE ) {
return IXML_INVALID_CHARACTER_ERR;
}
ixmlNode_init( &newAttrNode );
newAttrNode.nodeName = strdup( qualifiedName );
if( newAttrNode.nodeName == NULL ) {
return IXML_INSUFFICIENT_MEMORY;
}
rc = Parser_setNodePrefixAndLocalName( &newAttrNode );
if( rc != IXML_SUCCESS ) {
Parser_freeNodeContent( &newAttrNode );
return rc;
}
// see DOM 2 spec page 59
if( ( newAttrNode.prefix != NULL && namespaceURI == 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 ) ) {
Parser_freeNodeContent( &newAttrNode );
return IXML_NAMESPACE_ERR;
}
attrNode = element->n.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 ) {
free( attrNode->prefix ); // remove the old prefix
}
// replace it with the new prefix
attrNode->prefix = strdup( newAttrNode.prefix );
if( attrNode->prefix == NULL ) {
Parser_freeNodeContent( &newAttrNode );
return IXML_INSUFFICIENT_MEMORY;
}
if( attrNode->nodeValue != NULL ) {
free( attrNode->nodeValue );
}
attrNode->nodeValue = strdup( value );
if( attrNode->nodeValue == NULL ) {
free( attrNode->prefix );
Parser_freeNodeContent( &newAttrNode );
return IXML_INSUFFICIENT_MEMORY;
}
} else {
// add a new attribute
rc = ixmlDocument_createAttributeNSEx( ( IXML_Document * )
element->n.ownerDocument,
namespaceURI, qualifiedName,
&newAttr );
if( rc != IXML_SUCCESS ) {
return rc;
}
newAttr->n.nodeValue = strdup( value );
if( newAttr->n.nodeValue == NULL ) {
ixmlAttr_free( newAttr );
return IXML_INSUFFICIENT_MEMORY;
}
if( ixmlElement_setAttributeNodeNS( element, newAttr, NULL ) !=
IXML_SUCCESS ) {
ixmlAttr_free( newAttr );
return IXML_FAILED;
}
}
Parser_freeNodeContent( &newAttrNode );
return IXML_SUCCESS;
}
/*================================================================
* ixmlElement_removeAttributeNS
* 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:
* IXML_SUCCESS or failure.
*
*=================================================================*/
int
ixmlElement_removeAttributeNS( IN IXML_Element * element,
IN DOMString namespaceURI,
IN DOMString localName )
{
IXML_Node *attrNode;
if( ( element == NULL ) || ( namespaceURI == NULL )
|| ( localName == NULL ) ) {
return IXML_INVALID_PARAMETER;
}
attrNode = element->n.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 ) {
free( attrNode->nodeValue );
attrNode->nodeValue = NULL;
}
}
return IXML_SUCCESS;
}
/*================================================================
* ixmlElement_getAttributeNodeNS
* 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.
*
*=================================================================*/
IXML_Attr *
ixmlElement_getAttributeNodeNS( IN IXML_Element * element,
IN DOMString namespaceURI,
IN DOMString localName )
{
IXML_Node *attrNode;
if( ( element == NULL ) || ( namespaceURI == NULL )
|| ( localName == NULL ) ) {
return NULL;
}
attrNode = element->n.firstAttr;
while( attrNode != NULL ) {
if( strcmp( attrNode->localName, localName ) == 0 && strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) { // found it
break;
} else {
attrNode = attrNode->nextSibling;
}
}
return ( IXML_Attr * ) attrNode;
}
/*================================================================
* ixmlElement_setAttributeNodeNS
* 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
ixmlElement_setAttributeNodeNS( IN IXML_Element * element,
IN IXML_Attr * newAttr,
OUT IXML_Attr ** rtAttr )
{
IXML_Node *attrNode;
IXML_Node *node;
IXML_Node *prevAttr = NULL,
*nextAttr = NULL;
IXML_Node *preSib,
*nextSib;
if( ( element == NULL ) || ( newAttr == NULL ) ) {
return IXML_INVALID_PARAMETER;
}
if( newAttr->n.ownerDocument != element->n.ownerDocument ) {
return IXML_WRONG_DOCUMENT_ERR;
}
if( ( newAttr->ownerElement != NULL )
&& ( newAttr->ownerElement != element ) ) {
return IXML_INUSE_ATTRIBUTE_ERR;
}
newAttr->ownerElement = element;
node = ( IXML_Node * ) newAttr;
attrNode = element->n.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->n.firstAttr == attrNode ) {
element->n.firstAttr = node;
}
*rtAttr = ( IXML_Attr * ) attrNode;
} else // add this attribute
{
if( element->n.firstAttr != NULL ) // element has attribute already
{
prevAttr = element->n.firstAttr;
nextAttr = prevAttr->nextSibling;
while( nextAttr != NULL ) {
prevAttr = nextAttr;
nextAttr = prevAttr->nextSibling;
}
prevAttr->nextSibling = node;
} else // this is the first attribute node
{
element->n.firstAttr = node;
node->prevSibling = NULL;
node->nextSibling = NULL;
}
if( rtAttr != NULL ) {
*rtAttr = NULL;
}
}
return IXML_SUCCESS;
}
/*================================================================
* ixmlElement_getElementsByTagNameNS
* 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.
*
*=================================================================*/
IXML_NodeList *
ixmlElement_getElementsByTagNameNS( IN IXML_Element * element,
IN DOMString namespaceURI,
IN DOMString localName )
{
IXML_Node *node = ( IXML_Node * ) element;
IXML_NodeList *nodeList = NULL;
if( ( element != NULL ) && ( namespaceURI != NULL )
&& ( localName != NULL ) ) {
ixmlNode_getElementsByTagNameNS( node, namespaceURI, localName,
&nodeList );
}
return nodeList;
}
/*================================================================
* ixmlElement_hasAttribute
* 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
ixmlElement_hasAttribute( IN IXML_Element * element,
IN DOMString name )
{
IXML_Node *attrNode;
if( ( element == NULL ) || ( name == NULL ) ) {
return FALSE;
}
attrNode = element->n.firstAttr;
while( attrNode != NULL ) {
if( strcmp( attrNode->nodeName, name ) == 0 ) {
return TRUE;
} else {
attrNode = attrNode->nextSibling;
}
}
return FALSE;
}
/*================================================================
* ixmlElement_hasAttributeNS
* 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
ixmlElement_hasAttributeNS( IN IXML_Element * element,
IN DOMString namespaceURI,
IN DOMString localName )
{
IXML_Node *attrNode;
if( ( element == NULL ) || ( namespaceURI == NULL )
|| ( localName == NULL ) ) {
return FALSE;
}
attrNode = element->n.firstAttr;
while( attrNode != NULL ) {
if( strcmp( attrNode->localName, localName ) == 0 &&
strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) {
return TRUE;
} else {
attrNode = attrNode->nextSibling;
}
}
return FALSE;
}
/*================================================================
* ixmlElement_free
* frees a element node.
* External function.
*
*=================================================================*/
void
ixmlElement_free( IN IXML_Element * element )
{
if( element != NULL ) {
ixmlNode_free( ( IXML_Node * ) element );
}
}

View File

@ -0,0 +1,75 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
//
///////////////////////////////////////////////////////////////////////////
#ifndef _IXML_MEMBUF_H
#define _IXML_MEMBUF_H
#include <stdlib.h>
#include "ixml.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 20
typedef struct // ixml_membuf
{
char *buf;
size_t length;
size_t capacity;
size_t size_inc;
} ixml_membuf;
//--------------------------------------------------
//////////////// functions /////////////////////////
//--------------------------------------------------
/*
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
*/
void ixml_membuf_init(INOUT ixml_membuf *m);
void ixml_membuf_destroy(INOUT ixml_membuf *m);
int ixml_membuf_assign(INOUT ixml_membuf *m, IN const void *buf,
IN size_t buf_len );
int ixml_membuf_assign_str(INOUT ixml_membuf *m, IN const char *c_str );
int ixml_membuf_append(INOUT ixml_membuf *m, IN const void *buf);
int ixml_membuf_append_str(INOUT ixml_membuf *m, IN const char *c_str);
int ixml_membuf_insert(INOUT ixml_membuf *m, IN const void* buf,
IN size_t buf_len, int index );
#endif // _IXML_MEMBUF_H

View File

@ -0,0 +1,120 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
//
///////////////////////////////////////////////////////////////////////////
#ifndef _IXMLPARSER_H
#define _IXMLPARSER_H
#include "ixml.h"
#include "ixmlmembuf.h"
// Parser definitions
#define QUOT "&quot;"
#define LT "&lt;"
#define GT "&gt;"
#define APOS "&apos;"
#define AMP "&amp;"
#define ESC_HEX "&#x"
#define ESC_DEC "&#"
typedef struct _IXML_NamespaceURI
{
char *nsURI;
char *prefix;
struct _IXML_NamespaceURI *nextNsURI;
} IXML_NamespaceURI;
typedef struct _IXML_ElementStack
{
char *element;
char *prefix;
char *namespaceUri;
IXML_NamespaceURI *pNsURI;
struct _IXML_ElementStack *nextElement;
} IXML_ElementStack;
typedef enum
{
eELEMENT,
eATTRIBUTE,
eCONTENT,
} PARSER_STATE;
typedef struct _Parser
{
char *dataBuffer; //data buffer
char *curPtr; //ptr to the token parsed
char *savePtr; //Saves for backup
ixml_membuf lastElem;
ixml_membuf tokenBuf;
IXML_Node *pNeedPrefixNode;
IXML_ElementStack *pCurElement;
IXML_Node *currentNodePtr;
PARSER_STATE state;
BOOL bHasTopLevel;
} Parser;
int Parser_LoadDocument( IXML_Document **retDoc, char * xmlFile, BOOL file);
BOOL Parser_isValidXmlName( DOMString name);
int Parser_setNodePrefixAndLocalName(IXML_Node *newIXML_NodeIXML_Attr);
void Parser_freeNodeContent( IXML_Node *IXML_Nodeptr);
void Parser_setErrorChar( char c );
void ixmlAttr_free(IXML_Attr *attrNode);
void ixmlAttr_init(IXML_Attr *attrNode);
int ixmlElement_setTagName(IXML_Element *element, char *tagName);
void ixmlNamedNodeMap_init(IXML_NamedNodeMap *nnMap);
int ixmlNamedNodeMap_addToNamedNodeMap(IXML_NamedNodeMap **nnMap, IXML_Node *add);
void ixmlNode_init(IXML_Node *IXML_Nodeptr);
BOOL ixmlNode_compare(IXML_Node *srcIXML_Node, IXML_Node *destIXML_Node);
void ixmlNode_getElementsByTagName( IXML_Node *n, char *tagname, IXML_NodeList **list);
void ixmlNode_getElementsByTagNameNS( IXML_Node *IXML_Node, char *namespaceURI,
char *localName, IXML_NodeList **list);
int ixmlNode_setNodeProperties(IXML_Node* node, IXML_Node *src);
int ixmlNode_setNodeName( IXML_Node* node, DOMString qualifiedName);
void ixmlNodeList_init(IXML_NodeList *nList);
int ixmlNodeList_addToNodeList(IXML_NodeList **nList, IXML_Node *add);
#endif // _IXMLPARSER_H

530
libupnp/ixml/src/ixml.c Normal file
View File

@ -0,0 +1,530 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 "ixmlmembuf.h"
#include "ixmlparser.h"
/*================================================================
* copy_with_escape
*
*
*=================================================================*/
static void
copy_with_escape( INOUT ixml_membuf * 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 '<':
ixml_membuf_append_str( buf, "&lt;" );
break;
case '>':
ixml_membuf_append_str( buf, "&gt;" );
break;
case '&':
ixml_membuf_append_str( buf, "&amp;" );
break;
case '\'':
ixml_membuf_append_str( buf, "&apos;" );
break;
case '\"':
ixml_membuf_append_str( buf, "&quot;" );
break;
default:
ixml_membuf_append( buf, &p[i] );
}
}
}
/*================================================================
* ixmlPrintDomTreeRecursive
* It is a recursive function to print all the node in a tree.
* Internal to parser only.
*
*=================================================================*/
void
ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr,
IN ixml_membuf * buf )
{
char *nodeName = NULL;
char *nodeValue = NULL;
IXML_Node *child = NULL,
*sibling = NULL;
if( nodeptr != NULL ) {
nodeName = ( char * )ixmlNode_getNodeName( nodeptr );
nodeValue = ixmlNode_getNodeValue( nodeptr );
switch ( ixmlNode_getNodeType( nodeptr ) ) {
case eTEXT_NODE:
copy_with_escape( buf, nodeValue );
break;
case eCDATA_SECTION_NODE:
ixml_membuf_append_str( buf, nodeValue );
break;
case ePROCESSING_INSTRUCTION_NODE:
ixml_membuf_append_str( buf, "<?" );
ixml_membuf_append_str( buf, nodeName );
ixml_membuf_append_str( buf, " " );
ixml_membuf_append_str( buf, nodeValue );
ixml_membuf_append_str( buf, "?>\n" );
break;
case eDOCUMENT_NODE:
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild
( nodeptr ), buf );
break;
case eATTRIBUTE_NODE:
ixml_membuf_append_str( buf, nodeName );
ixml_membuf_append_str( buf, "=\"" );
if( nodeValue != NULL ) {
ixml_membuf_append_str( buf, nodeValue );
}
ixml_membuf_append_str( buf, "\"" );
if( nodeptr->nextSibling != NULL ) {
ixml_membuf_append_str( buf, " " );
ixmlPrintDomTreeRecursive( nodeptr->nextSibling, buf );
}
break;
case eELEMENT_NODE:
ixml_membuf_append_str( buf, "<" );
ixml_membuf_append_str( buf, nodeName );
if( nodeptr->firstAttr != NULL ) {
ixml_membuf_append_str( buf, " " );
ixmlPrintDomTreeRecursive( nodeptr->firstAttr, buf );
}
child = ixmlNode_getFirstChild( nodeptr );
if( ( child != NULL )
&& ( ixmlNode_getNodeType( child ) ==
eELEMENT_NODE ) ) {
ixml_membuf_append_str( buf, ">\n" );
} else {
ixml_membuf_append_str( buf, ">" );
}
// output the children
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild
( nodeptr ), buf );
// Done with children. Output the end tag.
ixml_membuf_append_str( buf, "</" );
ixml_membuf_append_str( buf, nodeName );
sibling = ixmlNode_getNextSibling( nodeptr );
if( sibling != NULL
&& ixmlNode_getNodeType( sibling ) == eTEXT_NODE ) {
ixml_membuf_append_str( buf, ">" );
} else {
ixml_membuf_append_str( buf, ">\n" );
}
ixmlPrintDomTreeRecursive( ixmlNode_getNextSibling
( nodeptr ), buf );
break;
default:
break;
}
}
}
/*================================================================
* ixmlPrintDomTree
* 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
ixmlPrintDomTree( IN IXML_Node * nodeptr,
IN ixml_membuf * buf )
{
char *nodeName = NULL;
char *nodeValue = NULL;
IXML_Node *child = NULL;
if( ( nodeptr == NULL ) || ( buf == NULL ) ) {
return;
}
nodeName = ( char * )ixmlNode_getNodeName( nodeptr );
nodeValue = ixmlNode_getNodeValue( nodeptr );
switch ( ixmlNode_getNodeType( nodeptr ) ) {
case eTEXT_NODE:
case eCDATA_SECTION_NODE:
case ePROCESSING_INSTRUCTION_NODE:
case eDOCUMENT_NODE:
ixmlPrintDomTreeRecursive( nodeptr, buf );
break;
case eATTRIBUTE_NODE:
ixml_membuf_append_str( buf, nodeName );
ixml_membuf_append_str( buf, "=\"" );
ixml_membuf_append_str( buf, nodeValue );
ixml_membuf_append_str( buf, "\"" );
break;
case eELEMENT_NODE:
ixml_membuf_append_str( buf, "<" );
ixml_membuf_append_str( buf, nodeName );
if( nodeptr->firstAttr != NULL ) {
ixml_membuf_append_str( buf, " " );
ixmlPrintDomTreeRecursive( nodeptr->firstAttr, buf );
}
child = ixmlNode_getFirstChild( nodeptr );
if( ( child != NULL )
&& ( ixmlNode_getNodeType( child ) == eELEMENT_NODE ) ) {
ixml_membuf_append_str( buf, ">\n" );
} else {
ixml_membuf_append_str( buf, ">" );
}
// output the children
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild( nodeptr ),
buf );
// Done with children. Output the end tag.
ixml_membuf_append_str( buf, "</" );
ixml_membuf_append_str( buf, nodeName );
ixml_membuf_append_str( buf, ">\n" );
break;
default:
break;
}
}
/*================================================================
* ixmlDomTreetoString
* 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
ixmlDomTreetoString( IN IXML_Node * nodeptr,
IN ixml_membuf * buf )
{
char *nodeName = NULL;
char *nodeValue = NULL;
IXML_Node *child = NULL;
if( ( nodeptr == NULL ) || ( buf == NULL ) ) {
return;
}
nodeName = ( char * )ixmlNode_getNodeName( nodeptr );
nodeValue = ixmlNode_getNodeValue( nodeptr );
switch ( ixmlNode_getNodeType( nodeptr ) ) {
case eTEXT_NODE:
case eCDATA_SECTION_NODE:
case ePROCESSING_INSTRUCTION_NODE:
case eDOCUMENT_NODE:
ixmlPrintDomTreeRecursive( nodeptr, buf );
break;
case eATTRIBUTE_NODE:
ixml_membuf_append_str( buf, nodeName );
ixml_membuf_append_str( buf, "=\"" );
ixml_membuf_append_str( buf, nodeValue );
ixml_membuf_append_str( buf, "\"" );
break;
case eELEMENT_NODE:
ixml_membuf_append_str( buf, "<" );
ixml_membuf_append_str( buf, nodeName );
if( nodeptr->firstAttr != NULL ) {
ixml_membuf_append_str( buf, " " );
ixmlPrintDomTreeRecursive( nodeptr->firstAttr, buf );
}
child = ixmlNode_getFirstChild( nodeptr );
if( ( child != NULL )
&& ( ixmlNode_getNodeType( child ) == eELEMENT_NODE ) ) {
ixml_membuf_append_str( buf, ">" );
} else {
ixml_membuf_append_str( buf, ">" );
}
// output the children
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild( nodeptr ),
buf );
// Done with children. Output the end tag.
ixml_membuf_append_str( buf, "</" );
ixml_membuf_append_str( buf, nodeName );
ixml_membuf_append_str( buf, ">" );
break;
default:
break;
}
}
/*================================================================
* ixmlLoadDocumentEx
* Parses the given file, and returns the DOM tree from it.
* External function.
*
*=================================================================*/
int
ixmlLoadDocumentEx( IN char *xmlFile,
IXML_Document ** doc )
{
if( ( xmlFile == NULL ) || ( doc == NULL ) ) {
return IXML_INVALID_PARAMETER;
}
return Parser_LoadDocument( doc, xmlFile, TRUE );
}
/*================================================================
* ixmlLoadDocument
* Parses the given file, and returns the DOM tree from it.
* External function.
*
*=================================================================*/
IXML_Document *
ixmlLoadDocument( IN char *xmlFile )
{
IXML_Document *doc = NULL;
ixmlLoadDocumentEx( xmlFile, &doc );
return doc;
}
/*================================================================
* ixmlPrintDocument
* Prints entire document, prepending XML prolog first.
* Puts lots of white spaces.
* External function.
*
*=================================================================*/
DOMString
ixmlPrintDocument(IXML_Document *doc)
{
IXML_Node* rootNode = ( IXML_Node * )doc;
ixml_membuf memBuf;
ixml_membuf *buf = &memBuf;
if( rootNode == NULL ) {
return NULL;
}
ixml_membuf_init( buf );
ixml_membuf_append_str( buf, "<?xml version=\"1.0\"?>\n" );
ixmlPrintDomTree( rootNode, buf );
return buf->buf;
}
/*================================================================
* ixmlPrintNode
* Print DOM tree under node. Puts lots of white spaces
* External function.
*
*=================================================================*/
DOMString
ixmlPrintNode( IN IXML_Node * node )
{
ixml_membuf memBuf;
ixml_membuf *buf = &memBuf;
if( node == NULL ) {
return NULL;
}
ixml_membuf_init( buf );
ixmlPrintDomTree( node, buf );
return buf->buf;
}
/*================================================================
* ixmlDocumenttoString
* converts DOM tree under node to text string,
* prepending XML prolog first.
* External function.
*
*=================================================================*/
DOMString
ixmlDocumenttoString(IXML_Document *doc)
{
IXML_Node* rootNode = ( IXML_Node * )doc;
ixml_membuf memBuf;
ixml_membuf *buf = &memBuf;
if( rootNode == NULL ) {
return NULL;
}
ixml_membuf_init( buf );
ixml_membuf_append_str( buf, "<?xml version=\"1.0\"?>\n" );
ixmlDomTreetoString( rootNode, buf );
return buf->buf;
}
/*================================================================
* ixmlNodetoString
* converts DOM tree under node to text string
* External function.
*
*=================================================================*/
DOMString
ixmlNodetoString( IN IXML_Node * node )
{
ixml_membuf memBuf;
ixml_membuf *buf = &memBuf;
if( node == NULL ) {
return NULL;
}
ixml_membuf_init( buf );
ixmlDomTreetoString( node, buf );
return buf->buf;
}
/*================================================================
* ixmlRelaxParser
* Makes the XML parser more tolerant to malformed text.
* External function.
*
*=================================================================*/
void
ixmlRelaxParser(char errorChar)
{
Parser_setErrorChar( errorChar );
}
/*================================================================
* ixmlParseBufferEx
* Parse xml file stored in buffer.
* External function.
*
*=================================================================*/
int
ixmlParseBufferEx( IN char *buffer,
IXML_Document ** retDoc )
{
if( ( buffer == NULL ) || ( retDoc == NULL ) ) {
return IXML_INVALID_PARAMETER;
}
if( strlen( buffer ) == 0 ) {
return IXML_INVALID_PARAMETER;
}
return Parser_LoadDocument( retDoc, buffer, FALSE );
}
/*================================================================
* ixmlParseBuffer
* Parse xml file stored in buffer.
* External function.
*
*=================================================================*/
IXML_Document *
ixmlParseBuffer( IN char *buffer )
{
IXML_Document *doc = NULL;
ixmlParseBufferEx( buffer, &doc );
return doc;
}
/*================================================================
* ixmlCloneDOMString
* Clones a DOM String.
* External function.
*
*=================================================================*/
DOMString
ixmlCloneDOMString( IN const DOMString src )
{
if( src == NULL ) {
return NULL;
}
return ( strdup( src ) );
}
/*================================================================
* ixmlFreeDOMString
* Frees a DOM String.
* External function.
*
*=================================================================*/
void
ixmlFreeDOMString( IN DOMString buf )
{
if( buf != NULL ) {
free( buf );
}
}

View File

@ -0,0 +1,236 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 "ixmlmembuf.h"
#include "ixml.h"
/*================================================================
* ixml_membuf_set_size
*
* 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
ixml_membuf_set_size( INOUT ixml_membuf * 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
}
diff = new_length - m->length;
alloc_len = MAXVAL( m->size_inc, diff ) + m->capacity;
} else // decrease length
{
assert( new_length <= m->length );
// if diff is 0..m->size_inc, don't free
if( ( m->capacity - new_length ) <= m->size_inc ) {
return 0;
}
alloc_len = new_length + m->size_inc;
}
assert( alloc_len >= new_length );
temp_buf = realloc( m->buf, alloc_len + 1 );
if( temp_buf == NULL ) {
// try smaller size
alloc_len = new_length;
temp_buf = realloc( m->buf, alloc_len + 1 );
if( temp_buf == NULL ) {
return IXML_INSUFFICIENT_MEMORY;
}
}
// save
m->buf = temp_buf;
m->capacity = alloc_len;
return 0;
}
/*================================================================
* membuffer_init
*
*
*=================================================================*/
void
ixml_membuf_init( INOUT ixml_membuf * m )
{
assert( m != NULL );
m->size_inc = MEMBUF_DEF_SIZE_INC;
m->buf = NULL;
m->length = 0;
m->capacity = 0;
}
/*================================================================
* membuffer_destroy
*
*
*=================================================================*/
void
ixml_membuf_destroy( INOUT ixml_membuf * m )
{
if( m == NULL ) {
return;
}
free( m->buf );
ixml_membuf_init( m );
}
/*================================================================
* ixml_membuf_assign
*
*
*=================================================================*/
int
ixml_membuf_assign( INOUT ixml_membuf * m,
IN const void *buf,
IN size_t buf_len )
{
int return_code;
assert( m != NULL );
// set value to null
if( buf == NULL ) {
ixml_membuf_destroy( m );
return IXML_SUCCESS;
}
// alloc mem
return_code = ixml_membuf_set_size( 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 IXML_SUCCESS;
}
/*================================================================
* ixml_membuf_assign_str
*
*
*=================================================================*/
int
ixml_membuf_assign_str( INOUT ixml_membuf * m,
IN const char *c_str )
{
return ixml_membuf_assign( m, c_str, strlen( c_str ) );
}
/*================================================================
* ixml_membuf_append
*
*
*=================================================================*/
int
ixml_membuf_append( INOUT ixml_membuf * m,
IN const void *buf )
{
assert( m != NULL );
return ixml_membuf_insert( m, buf, 1, m->length );
}
/*================================================================
* ixml_membuf_append_str
*
*
*=================================================================*/
int
ixml_membuf_append_str( INOUT ixml_membuf * m,
IN const char *c_str )
{
return ixml_membuf_insert( m, c_str, strlen( c_str ), m->length );
}
/*================================================================
* ixml_membuf_insert
*
*
*=================================================================*/
int
ixml_membuf_insert( INOUT ixml_membuf * 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 IXML_INDEX_SIZE_ERR;
if( buf == NULL || buf_len == 0 ) {
return 0;
}
// alloc mem
return_code = ixml_membuf_set_size( 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;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,242 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 "ixmlparser.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
ixmlNamedNodeMap_getItemNumber( IN IXML_NamedNodeMap * nnMap,
IN char *name )
{
IXML_Node *tempNode;
unsigned long returnItemNo = 0;
assert( nnMap != NULL && name != NULL );
if( ( nnMap == NULL ) || ( name == NULL ) ) {
return IXML_INVALID_ITEM_NUMBER;
}
tempNode = nnMap->nodeItem;
while( tempNode != NULL ) {
if( strcmp( name, tempNode->nodeName ) == 0 ) {
return returnItemNo;
}
tempNode = tempNode->nextSibling;
returnItemNo++;
}
return IXML_INVALID_ITEM_NUMBER;
}
/*================================================================
* NamedNodeMap_init
* Initializes a NamedNodeMap object.
* External function.
*
*=================================================================*/
void
ixmlNamedNodeMap_init( IN IXML_NamedNodeMap * nnMap )
{
assert( nnMap != NULL );
memset( nnMap, 0, sizeof( IXML_NamedNodeMap ) );
}
/*================================================================
* 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.
*
*=================================================================*/
IXML_Node *
ixmlNamedNodeMap_getNamedItem( IN IXML_NamedNodeMap * nnMap,
IN char *name )
{
long index;
if( ( nnMap == NULL ) || ( name == NULL ) ) {
return NULL;
}
index = ixmlNamedNodeMap_getItemNumber( nnMap, name );
if( index == IXML_INVALID_ITEM_NUMBER ) {
return NULL;
} else {
return ( ixmlNamedNodeMap_item( 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.
*
*=================================================================*/
IXML_Node *
ixmlNamedNodeMap_item( IN IXML_NamedNodeMap * nnMap,
IN unsigned long index )
{
IXML_Node *tempNode;
unsigned int i;
if( nnMap == NULL ) {
return NULL;
}
if( index > ixmlNamedNodeMap_getLength( 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
ixmlNamedNodeMap_getLength( IN IXML_NamedNodeMap * nnMap )
{
IXML_Node *tempNode;
unsigned long length = 0;
if( nnMap != NULL ) {
tempNode = nnMap->nodeItem;
for( length = 0; tempNode != NULL; ++length ) {
tempNode = tempNode->nextSibling;
}
}
return length;
}
/*================================================================
* ixmlNamedNodeMap_free
* frees a NamedNodeMap.
* External function.
*
*=================================================================*/
void
ixmlNamedNodeMap_free( IXML_NamedNodeMap * nnMap )
{
IXML_NamedNodeMap *pNext;
while( nnMap != NULL ) {
pNext = nnMap->next;
free( nnMap );
nnMap = pNext;
}
}
/*================================================================
* NamedNodeMap_addToNamedNodeMap
* add a node to a NamedNodeMap.
* Internal to parser only.
* Parameters:
* add: the node to add into NamedNodeMap.
* Return:
* IXML_SUCCESS or failure.
*
*=================================================================*/
int
ixmlNamedNodeMap_addToNamedNodeMap( IN IXML_NamedNodeMap ** nnMap,
IN IXML_Node * add )
{
IXML_NamedNodeMap *traverse = NULL,
*p = NULL;
IXML_NamedNodeMap *newItem = NULL;
if( add == NULL ) {
return IXML_SUCCESS;
}
if( *nnMap == NULL ) // nodelist is empty
{
*nnMap =
( IXML_NamedNodeMap * ) malloc( sizeof( IXML_NamedNodeMap ) );
if( *nnMap == NULL ) {
return IXML_INSUFFICIENT_MEMORY;
}
ixmlNamedNodeMap_init( *nnMap );
}
if( ( *nnMap )->nodeItem == NULL ) {
( *nnMap )->nodeItem = add;
} else {
traverse = *nnMap;
p = traverse;
while( traverse != NULL ) {
p = traverse;
traverse = traverse->next;
}
newItem =
( IXML_NamedNodeMap * ) malloc( sizeof( IXML_NamedNodeMap ) );
if( newItem == NULL ) {
return IXML_INSUFFICIENT_MEMORY;
}
p->next = newItem;
newItem->nodeItem = add;
newItem->next = NULL;
}
return IXML_SUCCESS;
}

1628
libupnp/ixml/src/node.c Normal file

File diff suppressed because it is too large Load Diff

174
libupnp/ixml/src/nodeList.c Normal file
View File

@ -0,0 +1,174 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 "ixmlparser.h"
/*================================================================
* ixmlNodeList_init
* initializes a nodelist
* External function.
*
*=================================================================*/
void
ixmlNodeList_init( IXML_NodeList * nList )
{
assert( nList != NULL );
memset( nList, 0, sizeof( IXML_NodeList ) );
}
/*================================================================
* ixmlNodeList_item
* 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.
*
*=================================================================*/
IXML_Node *
ixmlNodeList_item( IXML_NodeList * nList,
unsigned long index )
{
IXML_NodeList *next;
unsigned int i;
// if the list ptr is NULL
if( nList == NULL ) {
return NULL;
}
// if index is more than list length
if( index > ixmlNodeList_length( nList ) - 1 ) {
return NULL;
}
next = nList;
for( i = 0; i < index && next != NULL; ++i ) {
next = next->next;
}
return next->nodeItem;
}
/*================================================================
* ixmlNodeList_addToNodeList
* Add a node to nodelist
* Internal to parser only.
*
*=================================================================*/
int
ixmlNodeList_addToNodeList( IN IXML_NodeList ** nList,
IN IXML_Node * add )
{
IXML_NodeList *traverse,
*p = NULL;
IXML_NodeList *newListItem;
assert( add != NULL );
if( add == NULL ) {
return IXML_FAILED;
}
if( *nList == NULL ) // nodelist is empty
{
*nList = ( IXML_NodeList * ) malloc( sizeof( IXML_NodeList ) );
if( *nList == NULL ) {
return IXML_INSUFFICIENT_MEMORY;
}
ixmlNodeList_init( *nList );
}
if( ( *nList )->nodeItem == NULL ) {
( *nList )->nodeItem = add;
} else {
traverse = *nList;
while( traverse != NULL ) {
p = traverse;
traverse = traverse->next;
}
newListItem =
( IXML_NodeList * ) malloc( sizeof( IXML_NodeList ) );
if( newListItem == NULL ) {
return IXML_INSUFFICIENT_MEMORY;
}
p->next = newListItem;
newListItem->nodeItem = add;
newListItem->next = NULL;
}
return IXML_SUCCESS;
}
/*================================================================
* ixmlNodeList_length
* 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
ixmlNodeList_length( IN IXML_NodeList * nList )
{
IXML_NodeList *list;
unsigned long length = 0;
list = nList;
while( list != NULL ) {
++length;
list = list->next;
}
return length;
}
/*================================================================
* ixmlNodeList_free
* frees a nodeList
* External function
*
*=================================================================*/
void
ixmlNodeList_free( IN IXML_NodeList * nList )
{
IXML_NodeList *next;
while( nList != NULL ) {
next = nList->next;
free( nList );
nList = next;
}
}

View File

@ -0,0 +1,139 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2006 Rémi Turboult <r3mi@users.sourceforge.net>
// 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 "ixml.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
static const char*
get_ixml_error_string (IXML_ERRORCODE code)
{
#define CASE(CODE) case IXML_ ## CODE: return #CODE
switch (code) {
CASE(INDEX_SIZE_ERR);
CASE(DOMSTRING_SIZE_ERR);
CASE(HIERARCHY_REQUEST_ERR);
CASE(WRONG_DOCUMENT_ERR);
CASE(INVALID_CHARACTER_ERR);
CASE(NO_DATA_ALLOWED_ERR);
CASE(NO_MODIFICATION_ALLOWED_ERR);
CASE(NOT_FOUND_ERR);
CASE(NOT_SUPPORTED_ERR);
CASE(INUSE_ATTRIBUTE_ERR);
CASE(INVALID_STATE_ERR);
CASE(SYNTAX_ERR);
CASE(INVALID_MODIFICATION_ERR);
CASE(NAMESPACE_ERR);
CASE(INVALID_ACCESS_ERR);
CASE(SUCCESS);
CASE(NO_SUCH_FILE);
CASE(INSUFFICIENT_MEMORY);
CASE(FILE_DONE);
CASE(INVALID_PARAMETER);
CASE(FAILED);
CASE(INVALID_ITEM_NUMBER);
}
return "** UNKNOWN EROR CODE !! **";
#undef CASE
}
int
main (int argc, char* argv[])
{
int i;
if (argc < 2) {
fprintf (stderr, "Usage: %s [xml files to load]\n",
argv[0]);
exit (EXIT_FAILURE); // ---------->
}
for (i = 1; i < argc; i++) {
int rc;
IXML_Document* doc = NULL;
DOMString s;
char* p;
printf ("Test \"%s\" \n", argv[i]);
printf (" Loading ... ");
fflush (stdout);
rc = ixmlLoadDocumentEx (argv[i], &doc);
if (rc != IXML_SUCCESS) {
fprintf (stderr,
"** error : can't load document %s : "
"error %d (%s)\n",
argv[i], rc, get_ixml_error_string (rc));
exit (EXIT_FAILURE); // ---------->
}
printf ("OK\n");
printf (" Printing ... ");
fflush (stdout);
s = ixmlPrintDocument (doc);
if (s == NULL || s[0] == '\0') {
fprintf (stderr,
"** error : can't print loaded document %s\n",
argv[i]);
exit (EXIT_FAILURE); // ---------->
}
p = s + strlen(s)-1;
while (isspace(*p) && p > s)
p--;
if (*s != '<' || *p != '>') {
fprintf (stderr,
"** error : malformed printed document '%s' :"
"%s\n", argv[i], s);
exit (EXIT_FAILURE); // ---------->
}
printf ("OK\n");
ixmlFreeDOMString (s);
ixmlDocument_free (doc);
}
exit (EXIT_SUCCESS);
}

View File

@ -0,0 +1,4 @@
#!/bin/sh
./test_document `find $srcdir/test/testdata -name *.xml`

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<test>
<name>Empty XML Attribute</name>
<data attr=""/>
<data attr="">
</data>
</test>

27
libupnp/ixml/test/testdata/p43pass1.xml vendored Normal file
View File

@ -0,0 +1,27 @@
<!DOCTYPE elem
[
<!ELEMENT elem (#PCDATA|elem)*>
<!ENTITY ent "<elem>CharData</elem>">
]>
<elem>
CharData&#32;
<!--comment-->
<![CDATA[
<elem>
CharData&#32;
<!--comment-->
<?pi?>&eacute;&quot;
CharData
</elem>
]]>
<![CDATA[
<elem>
CharData&#32;
<!--comment-->
<?pi?>&eacute;&quot;
CharData
</elem>
]]>
<?pi?>&gt;&quot;
CharData
</elem>

View File

@ -0,0 +1,178 @@
<?xml version="1.0"?>
<scpd xmlns="urn:schemas-upnp-org:service-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<actionList>
<action>
<name>PowerOn</name>
<argumentList>
<argument>
<retval />
<name>Power</name>
<relatedStateVariable>Power</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
<action>
<name>PowerOff</name>
<argumentList>
<argument>
<retval />
<name>Power</name>
<relatedStateVariable>Power</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
<action>
<name>SetChannel</name>
<argumentList>
<argument>
<name>NewChannel</name>
<retval />
<relatedStateVariable>Channel</relatedStateVariable>
<direction>out</direction>
</argument>
<argument>
<name>Channel</name>
<relatedStateVariable>Channel</relatedStateVariable>
<direction>in</direction>
</argument>
</argumentList>
</action>
<action>
<name>IncreaseChannel</name>
<argumentList>
<argument>
<name>Channel</name>
<retval />
<relatedStateVariable>Channel</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
<action>
<name>DecreaseChannel</name>
<argumentList>
<argument>
<name>Channel</name>
<retval />
<relatedStateVariable>Channel</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
<action>
<name>SetVolume</name>
<argumentList>
<argument>
<name>NewVolume</name>
<retval />
<relatedStateVariable>Volume</relatedStateVariable>
<direction>out</direction>
</argument>
<argument>
<name>Volume</name>
<relatedStateVariable>Volume</relatedStateVariable>
<direction>in</direction>
</argument>
</argumentList>
</action>
<action>
<name>IncreaseVolume</name>
<argumentList>
<argument>
<name>Volume</name>
<retval />
<relatedStateVariable>Volume</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
<action>
<name>DecreaseVolume</name>
<argumentList>
<argument>
<name>Volume</name>
<retval />
<relatedStateVariable>Volume</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
</actionList>
<serviceStateTable>
<stateVariable sendEvents="yes">
<name>Power</name>
<dataType>Boolean</dataType>
<defaultValue>0</defaultValue>
</stateVariable>
<stateVariable sendEvents="yes">
<name>Channel</name>
<dataType>i4</dataType>
<allowedValueRange>
<minimum>1</minimum>
<maximum>100</maximum>
<step>1</step>
</allowedValueRange>
<defaultValue>1</defaultValue>
</stateVariable>
<stateVariable sendEvents="yes">
<name>Volume</name>
<dataType>i4</dataType>
<allowedValueRange>
<minimum>0</minimum>
<maximum>10</maximum>
<step>1</step>
</allowedValueRange>
<defaultValue>5</defaultValue>
</stateVariable>
</serviceStateTable>
</scpd>

View File

@ -0,0 +1,37 @@
<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<device>
<deviceType>urn:schemas-upnp-org:device:tvdevice:1</deviceType>
<friendlyName>UPnP Television Emulator</friendlyName>
<manufacturer>TV Manufacturer Name</manufacturer>
<manufacturerURL>http://www.manufacturer.com</manufacturerURL>
<modelDescription>UPnP Television Device Emulator 1.0</modelDescription>
<modelName>TVEmulator</modelName>
<modelNumber>1.0</modelNumber>
<modelURL>http://www.manufacturer.com/TVEmulator/</modelURL>
<serialNumber>123456789001</serialNumber>
<UDN>uuid:Upnp-TVEmulator-1_0-1234567890001</UDN>
<UPC>123456789</UPC>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:tvcontrol:1</serviceType>
<serviceId>urn:upnp-org:serviceId:tvcontrol1</serviceId>
<controlURL>/upnp/control/tvcontrol1</controlURL>
<eventSubURL>/upnp/event/tvcontrol1</eventSubURL>
<SCPDURL>/tvcontrolSCPD.xml</SCPDURL>
</service>
<service>
<serviceType>urn:schemas-upnp-org:service:tvpicture:1</serviceType>
<serviceId>urn:upnp-org:serviceId:tvpicture1</serviceId>
<controlURL>/upnp/control/tvpicture1</controlURL>
<eventSubURL>/upnp/event/tvpicture1</eventSubURL>
<SCPDURL>/tvpictureSCPD.xml</SCPDURL>
</service>
</serviceList>
<presentationURL>/tvdevicepres.html</presentationURL>
</device>
</root>

View File

@ -0,0 +1,251 @@
<?xml version="1.0"?>
<scpd xmlns="urn:schemas-upnp-org:service-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<actionList>
<action>
<name>SetColor</name>
<argumentList>
<argument>
<name>NewColor</name>
<retval />
<relatedStateVariable>Color</relatedStateVariable>
<direction>out</direction>
</argument>
<argument>
<name>Color</name>
<relatedStateVariable>Color</relatedStateVariable>
<direction>in</direction>
</argument>
</argumentList>
</action>
<action>
<name>IncreaseColor</name>
<argumentList>
<argument>
<name>Color</name>
<retval />
<relatedStateVariable>Color</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
<action>
<name>DecreaseColor</name>
<argumentList>
<argument>
<name>Color</name>
<retval />
<relatedStateVariable>Color</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
<action>
<name>SetTint</name>
<argumentList>
<argument>
<name>NewTint</name>
<retval />
<relatedStateVariable>Tint</relatedStateVariable>
<direction>out</direction>
</argument>
<argument>
<name>Tint</name>
<relatedStateVariable>Tint</relatedStateVariable>
<direction>in</direction>
</argument>
</argumentList>
</action>
<action>
<name>IncreaseTint</name>
<argumentList>
<argument>
<name>Tint</name>
<retval />
<relatedStateVariable>Tint</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
<action>
<name>DecreaseTint</name>
<argumentList>
<argument>
<name>Tint</name>
<retval />
<relatedStateVariable>Tint</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
<action>
<name>SetContrast</name>
<argumentList>
<argument>
<name>NewContrast</name>
<retval />
<relatedStateVariable>Contrast</relatedStateVariable>
<direction>out</direction>
</argument>
<argument>
<name>Contrast</name>
<relatedStateVariable>Contrast</relatedStateVariable>
<direction>in</direction>
</argument>
</argumentList>
</action>
<action>
<name>IncreaseContrast</name>
<argumentList>
<argument>
<name>Contrast</name>
<retval />
<relatedStateVariable>Contrast</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
<action>
<name>DecreaseContrast</name>
<argumentList>
<argument>
<name>Contrast</name>
<retval />
<relatedStateVariable>Contrast</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
<action>
<name>SetBrightness</name>
<argumentList>
<argument>
<name>NewBrightness</name>
<retval />
<relatedStateVariable>Brightness</relatedStateVariable>
<direction>out</direction>
</argument>
<argument>
<name>Brightness</name>
<relatedStateVariable>Brightness</relatedStateVariable>
<direction>in</direction>
</argument>
</argumentList>
</action>
<action>
<name>IncreaseBrightness</name>
<argumentList>
<argument>
<name>Brightness</name>
<retval />
<relatedStateVariable>Brightness</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
<action>
<name>DecreaseBrightness</name>
<argumentList>
<argument>
<name>Brightness</name>
<retval />
<relatedStateVariable>Brightness</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
</actionList>
<serviceStateTable>
<stateVariable sendEvents="yes">
<name>Color</name>
<dataType>i4</dataType>
<allowedValueRange>
<minimum>1</minimum>
<maximum>10</maximum>
<step>1</step>
</allowedValueRange>
<defaultValue>5</defaultValue>
</stateVariable>
<stateVariable sendEvents="yes">
<name>Tint</name>
<dataType>i4</dataType>
<allowedValueRange>
<minimum>1</minimum>
<maximum>10</maximum>
<step>1</step>
</allowedValueRange>
<defaultValue>5</defaultValue>
</stateVariable>
<stateVariable sendEvents="yes">
<name>Contrast</name>
<dataType>i4</dataType>
<allowedValueRange>
<minimum>1</minimum>
<maximum>10</maximum>
<step>1</step>
</allowedValueRange>
<defaultValue>5</defaultValue>
</stateVariable>
<stateVariable sendEvents="yes">
<name>Brightness</name>
<dataType>i4</dataType>
<allowedValueRange>
<minimum>1</minimum>
<maximum>10</maximum>
<step>1</step>
</allowedValueRange>
<defaultValue>5</defaultValue>
</stateVariable>
</serviceStateTable>
</scpd>

View File

@ -0,0 +1,85 @@
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/WD-html-in-xml/DTD/xhtml1-transitional.dtd"
>
<html xmlns="http://www.w3.org/Profiles/xhtml1-transitional">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<meta name="GENERATOR" content="Microsoft FrontPage Express
2.0" />
<title>
LEGAL NOTICES
</title>
<style type="text/css">
P.c2 {text-align: center}
H1.c1 {text-align: center}
</style>
</head>
<body bgcolor="#FFFFFF" lang="en">
<h1 class="c1">LEGAL NOTICES</h1>
<p class="c2">Unless otherwise stated, pages hosted on the
website<br />
<em>Chinese XML Now!</em><br />
are copyright (C) 1998 the designated authors and
translators,<br />
and the Computing Center, Academia Sinica.</p>
<p class="c2">Unless otherwise stated, permission is granted to
use, copy, link to,<br />
translate and republish in any form, including for commercial
use,<br />
providing due acknowledgement of the copyright holder<br />
and the <em>Chinese XML Now!</em> website is made.</p>
<p class="c2">If you believe any pages here are subject to
another copyright,<br />
please email us (mailto: <a href=
"mailto:ricko@gate.sinica.edu.tw">
ricko@gate.sinica.edu.tw</a>)<br />
with the appropriate correction.</p>
<hr />
<p class="c2">The "<em>Chinese Numberplate</em>" logos copyright
(C) 1998 Rick Jelliffe and Computing Center, Academia Sinica.</p>
<p class="c2">The logo is provided as a public service for
information,<br />
and does not represent a test result or endorsement.</p>
<p class="c2">For integrity, we do reserve the right to ask
makers who use<br />
an incorrect version of the logo to correct it or to abstain
from using the logo.<br />
</p>
<hr />
<p class="c2">The Chinese XML Test pages do not represent<br />
an exhaustive test of some software's Chinese capability.<br />
The tests merely represent a base-level which may<br />
identify particular important characteristics quickly.</p>
<p class="c2">Permission is granted to copy and use the test
files<br />
as part of any test suite. However, copiers must take<br />
the utmost care to ensure that the test files<br />
are maintained in the encoding given in their<br />
XML encoding header.</p>
<hr />
<p class="c2"><em>Caveat</em><em><strong>:</strong></em>
Information provided about products at this site is<br />
provided as a public service only, and does not imply<br />
an endorsement of any product, any company, or any
technology.</p>
<p class="c2">Information at this site should be treated as an
indication only:<br />
products and capabilities change quickly, so information<br />
may only be correct at the time of publication.<br />
Furthermore, due to the technical complexity and novelty<br />
of XML technology, and the poor state of product
documentation,<br />
it is possible that some information may be incorrect,<br />
despite our best endevours.</p>
<p class="c2">If you believe any information here is
incorrect,<br />
please email us (mailto: <a href=
"mailto:ricko@gate.sinica.edu.tw">
ricko@gate.sinica.edu.tw</a>)<br />
with the appropriate correction.</p>
<hr />
</body>
</html>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test type="io0">
<name>Chinese Test #0: utf-8</name>
<data>This file is the null test. It is a UTF-8 encoded
file with no non-ASCII characters (i.e. it is also an
ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="utf-8"?&gt;.
</data>
</test>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test type="io1">
<name>Chinese Test #1: UTF-8</name>
<data>This file is the null test. It is a UTF-8 encoded
file with no non-ASCII characters (i.e. it is also an
ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
</test>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test type="io10">
<name>Chinese Test #10: UTF-8</name>
<data>This file has 1 Chinese character, directly entered.
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data char="The character is here: [中].">
</data>
</test>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test type="io11">
<name>Chinese Test #11: UTF-8</name>
<data>This file has 1 Chinese character, directly entered.
This tests Native Language Markup (NLM).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data>The character is here: <中 />.</data>
</test>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test type="io12">
<name id="中">Chinese Test #12: UTF-8</name>
<data>This file has two attributes
with Chinese characters, directly entered.
This tests Native Language Markup (NLM).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data refid="中">(In the DOCTYPE test, the
name element has an ID attribute, and this
element has an IDREF attribute.)</data>
</test>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test type="io2">
<name>Chinese Test #2: UTF-8</name>
<data>This file has 1 Chinese character, encoded using
a decimal numeric character reference. It is a UTF-8 encoded
file with no non-ASCII characters (i.e. it is also an
ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data>The character is here: [&#20013;].
It is the Chinese character for middle.
It should look like a box with a vertical
line through its middle.
</data>
</test>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test type="io3">
<name>Chinese Test #3: UTF-8</name>
<data>This file has 1 Chinese character, encoded using
a hexadecimal numeric character reference. It is a UTF-8 encoded
file with no non-ASCII characters (i.e. it is also an
ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data>The character is here: [&#x4E2D;].
It is the Chinese character for middle.
It should look like a box with a vertical
line through its middle.
</data>
</test>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test type="io4">
<name>Chinese Test #4: UTF-8</name>
<data>This file has 1 Chinese character, encoded using
a decimal numeric character reference. It is a UTF-8 encoded
file with no non-ASCII characters (i.e. it is also an
ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data char="The character is here: [&#20013;].">
It is the Chinese character for middle.
It should look like a box with a vertical
line through its middle.
</data>
</test>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test type="io5">
<name>Chinese Test #5: UTF-8</name>
<data>This file has 1 Chinese character, encoded using
a decimal numeric character reference. It is a UTF-8 encoded
file with no non-ASCII characters (i.e. it is also an
ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data char="The character is here: [&#x4E2D;].">
It is the Chinese character for middle.
It should look like a box with a vertical
line through its middle.
</data>
</test>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test type="io6">
<name>Chinese Test #6: UTF-8</name>
<data>This file has CDATA which looks like
a decimal numeric character reference. It is a
file with no non-ASCII characters (i.e. it is also a
UTF-8, ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data><![CDATA[The character is here: [&#20013;].]]>
This is not the Chinese character for middle.
It should not look like a box with a vertical
line through its middle.
</data>
</test>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test type="io7">
<name>Chinese Test #7: UTF-8</name>
<data>This file has CDATA which looks like
a hexadecimal numeric character reference. It is a
file with no non-ASCII characters (i.e. it is also a
UTF-8, ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data><![CDATA[CDATA section is here: [&#x4E2D;].]]>
This is not the Chinese character for middle.
It should not look like a box with a vertical
line through its middle.
</data>
</test>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test type="io8">
<name>Chinese Test #8: UTF-8</name>
<data>This file has 1 Chinese character, directly entered.
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data>The character is here: [中] It is the Chinese character for middle.
It should look like a box with a vertical
line through its middle.
</data>
</test>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test type="io9">
<name>Chinese Test #9: UTF-8</name>
<data>This file has 1 Chinese character, directly entered.
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data>The character is here: [究]. </data>
</test>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test xmlns='http://www.ascc.net/xml/test/schema' type="io0">
<name>Chinese Test #0: utf-8</name>
<data>This file is the null test. It is a UTF-8 encoded
file with no non-ASCII characters (i.e. it is also an
ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="utf-8"?&gt;.
</data>
</test>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test xmlns='http://www.ascc.net/xml/test/schema' type="io1">
<name>Chinese Test #1: UTF-8</name>
<data>This file is the null test. It is a UTF-8 encoded
file with no non-ASCII characters (i.e. it is also an
ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
</test>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test xmlns='http://www.ascc.net/xml/test/schema' type="io10">
<name>Chinese Test #10: UTF-8</name>
<data>This file has 1 Chinese character, directly entered.
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data char="The character is here: [中].">
</data>
</test>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test xmlns='http://www.ascc.net/xml/test/schema' type="io11">
<name>Chinese Test #11: UTF-8</name>
<data>This file has 1 Chinese character, directly entered.
This tests Native Language Markup (NLM).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data>The character is here: <中 />.</data>
</test>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test xmlns='http://www.ascc.net/xml/test/schema' type="io12">
<name id="中">Chinese Test #12: UTF-8</name>
<data>This file has two attributes
with Chinese characters, directly entered.
This tests Native Language Markup (NLM).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data refid="中">(In the DOCTYPE test, the
name element has an ID attribute, and this
element has an IDREF attribute.)</data>
</test>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test xmlns='http://www.ascc.net/xml/test/schema' type="io2">
<name>Chinese Test #2: UTF-8</name>
<data>This file has 1 Chinese character, encoded using
a decimal numeric character reference. It is a UTF-8 encoded
file with no non-ASCII characters (i.e. it is also an
ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data>The character is here: [&#20013;].
It is the Chinese character for middle.
It should look like a box with a vertical
line through its middle.
</data>
</test>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test xmlns='http://www.ascc.net/xml/test/schema' type="io3">
<name>Chinese Test #3: UTF-8</name>
<data>This file has 1 Chinese character, encoded using
a hexadecimal numeric character reference. It is a UTF-8 encoded
file with no non-ASCII characters (i.e. it is also an
ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data>The character is here: [&#x4E2D;].
It is the Chinese character for middle.
It should look like a box with a vertical
line through its middle.
</data>
</test>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test xmlns='http://www.ascc.net/xml/test/schema' type="io4">
<name>Chinese Test #4: UTF-8</name>
<data>This file has 1 Chinese character, encoded using
a decimal numeric character reference. It is a UTF-8 encoded
file with no non-ASCII characters (i.e. it is also an
ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data char="The character is here: [&#20013;].">
It is the Chinese character for middle.
It should look like a box with a vertical
line through its middle.
</data>
</test>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test xmlns='http://www.ascc.net/xml/test/schema' type="io5">
<name>Chinese Test #5: UTF-8</name>
<data>This file has 1 Chinese character, encoded using
a decimal numeric character reference. It is a UTF-8 encoded
file with no non-ASCII characters (i.e. it is also an
ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data char="The character is here: [&#x4E2D;].">
It is the Chinese character for middle.
It should look like a box with a vertical
line through its middle.
</data>
</test>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test xmlns='http://www.ascc.net/xml/test/schema' type="io6">
<name>Chinese Test #6: UTF-8</name>
<data>This file has CDATA which looks like
a decimal numeric character reference. It is a
file with no non-ASCII characters (i.e. it is also a
UTF-8, ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data><![CDATA[The character is here: [&#20013;].]]>
This is not the Chinese character for middle.
It should not look like a box with a vertical
line through its middle.
</data>
</test>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test xmlns='http://www.ascc.net/xml/test/schema' type="io7">
<name>Chinese Test #7: UTF-8</name>
<data>This file has CDATA which looks like
a hexadecimal numeric character reference. It is a
file with no non-ASCII characters (i.e. it is also a
UTF-8, ASCII or iso-8859-n file).
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data><![CDATA[CDATA section is here: [&#x4E2D;].]]>
This is not the Chinese character for middle.
It should not look like a box with a vertical
line through its middle.
</data>
</test>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test xmlns='http://www.ascc.net/xml/test/schema' type="io8">
<name>Chinese Test #8: UTF-8</name>
<data>This file has 1 Chinese character, directly entered.
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data>The character is here: [中] It is the Chinese character for middle.
It should look like a box with a vertical
line through its middle.
</data>
</test>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 1998 Academia Sinica Computing Center -->
<!-- Permission to use and distribute granted under MPL -->
<!-- Email corrections to ricko@gate.sinica.net.tw -->
<test xmlns='http://www.ascc.net/xml/test/schema' type="io9">
<name>Chinese Test #9: UTF-8</name>
<data>This file has 1 Chinese character, directly entered.
</data>
<data>The XML header of this file is
&lt;?xml encoding="UTF-8"?&gt;.
</data>
<data>The character is here: [究]. </data>
</test>

View File

@ -0,0 +1,5 @@
<!DOCTYPE doc [
<!ELEMENT doc (#PCDATA)>
<!ATTLIST doc abcdefghijklmnopqrstuvwxyz CDATA #IMPLIED>
]>
<doc abcdefghijklmnopqrstuvwxyz="v1"></doc>

View File

@ -0,0 +1,5 @@
<!DOCTYPE doc [
<!ELEMENT doc (#PCDATA)>
<!ATTLIST doc a1 CDATA #IMPLIED>
]>
<doc a1="&quot;&lt;&amp;&gt;&apos;"></doc>

View File

@ -0,0 +1,10 @@
<!DOCTYPE doc [
<!ELEMENT doc (e*)>
<!ELEMENT e EMPTY>
<!ATTLIST e a1 CDATA #IMPLIED a2 CDATA #IMPLIED a3 CDATA #IMPLIED>
]>
<doc>
<e a1="v1" a2="v2" a3="v3"/>
<e a1="w1" a2="v2"/>
<e a1="v1" a2="w2" a3="v3"/>
</doc>

View File

@ -0,0 +1,5 @@
<!DOCTYPE doc [
<!ELEMENT doc (#PCDATA)>
<!ATTLIST doc a NMTOKENS #IMPLIED>
]>
<doc a="&#32;x&#32;&#32;y&#32;"></doc>

View File

@ -0,0 +1,38 @@
<!DOCTYPE root [
<!ELEMENT root ANY>
<!ELEMENT empty EMPTY>
<!ELEMENT mixed1 (#PCDATA)>
<!ELEMENT mixed2 (#PCDATA)*>
<!ELEMENT mixed3 (#PCDATA|empty)*>
]>
<root>
<empty/>
<mixed1/>
<mixed1></mixed1>
<mixed2/>
<mixed2></mixed2>
<mixed3/>
<mixed3></mixed3>
<mixed1>allowed</mixed1>
<mixed1><![CDATA[<allowed>]]></mixed1>
<mixed2>also</mixed2>
<mixed2><![CDATA[<% illegal otherwise %>]]></mixed2>
<mixed3>moreover</mixed3>
<mixed1>allowed &amp; stuff</mixed1>
<mixed2>also</mixed2>
<mixed3>moreover <empty></empty> </mixed3>
<mixed3>moreover <empty/> </mixed3>
<mixed3><empty/> </mixed3>
<mixed3><empty/> too</mixed3>
</root>

12
libupnp/libupnp.pc.in Normal file
View File

@ -0,0 +1,12 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libupnp
Description: Linux SDK for UPnP Devices
Version: @VERSION@
Libs: @PTHREAD_LIBS@ -L${libdir} -lupnp -lthreadutil -lixml
Cflags: @PTHREAD_CFLAGS@ -I${includedir}

238
libupnp/m4/acx_pthread.m4 Normal file
View File

@ -0,0 +1,238 @@
dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
dnl
dnl @summary figure out how to build C programs using POSIX threads
dnl
dnl This macro figures out how to build C programs using POSIX threads.
dnl It sets the PTHREAD_LIBS output variable to the threads library and
dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
dnl C compiler flags that are needed. (The user can also force certain
dnl compiler flags/libs to be tested by setting these environment
dnl variables.)
dnl
dnl Also sets PTHREAD_CC to any special C compiler that is needed for
dnl multi-threaded programs (defaults to the value of CC otherwise).
dnl (This is necessary on AIX to use the special cc_r compiler alias.)
dnl
dnl NOTE: You are assumed to not only compile your program with these
dnl flags, but also link it with them as well. e.g. you should link
dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
dnl $LIBS
dnl
dnl If you are only building threads programs, you may wish to use
dnl these variables in your default LIBS, CFLAGS, and CC:
dnl
dnl LIBS="$PTHREAD_LIBS $LIBS"
dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
dnl CC="$PTHREAD_CC"
dnl
dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
dnl
dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
dnl default action will define HAVE_PTHREAD.
dnl
dnl Please let the authors know if this macro fails on any platform, or
dnl if you have any other suggestions or comments. This macro was based
dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
dnl We are also grateful for the helpful feedback of numerous users.
dnl
dnl @category InstalledPackages
dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
dnl @version 2005-06-15
dnl @license GPLWithACException
AC_DEFUN([ACX_PTHREAD], [
AC_REQUIRE([AC_CANONICAL_HOST])
AC_LANG_SAVE
AC_LANG_C
acx_pthread_ok=no
# We used to check for pthread.h first, but this fails if pthread.h
# requires special compiler flags (e.g. on True64 or Sequent).
# It gets checked for in the link test anyway.
# First of all, check if the user has set any of the PTHREAD_LIBS,
# etcetera environment variables, and if threads linking works using
# them:
if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
save_LIBS="$LIBS"
LIBS="$PTHREAD_LIBS $LIBS"
AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
AC_MSG_RESULT($acx_pthread_ok)
if test x"$acx_pthread_ok" = xno; then
PTHREAD_LIBS=""
PTHREAD_CFLAGS=""
fi
LIBS="$save_LIBS"
CFLAGS="$save_CFLAGS"
fi
# We must check for the threads library under a number of different
# names; the ordering is very important because some systems
# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
# libraries is broken (non-POSIX).
# Create a list of thread flags to try. Items starting with a "-" are
# C compiler flags, and other items are library names, except for "none"
# which indicates that we try without any flags at all, and "pthread-config"
# which is a program returning the flags for the Pth emulation library.
acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
# The ordering *is* (sometimes) important. Some notes on the
# individual items follow:
# pthreads: AIX (must check this before -lpthread)
# none: in case threads are in libc; should be tried before -Kthread and
# other compiler flags to prevent continual compiler warnings
# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
# -pthreads: Solaris/gcc
# -mthreads: Mingw32/gcc, Lynx/gcc
# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
# doesn't hurt to check since this sometimes defines pthreads too;
# also defines -D_REENTRANT)
# ... -mt is also the pthreads flag for HP/aCC
# pthread: Linux, etcetera
# --thread-safe: KAI C++
# pthread-config: use pthread-config program (for GNU Pth library)
case "${host_cpu}-${host_os}" in
*solaris*)
# On Solaris (at least, for some versions), libc contains stubbed
# (non-functional) versions of the pthreads routines, so link-based
# tests will erroneously succeed. (We need to link with -pthreads/-mt/
# -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
# a function called by this macro, so we could check for that, but
# who knows whether they'll stub that too in a future libc.) So,
# we'll just look for -pthreads and -lpthread first:
acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
;;
esac
if test x"$acx_pthread_ok" = xno; then
for flag in $acx_pthread_flags; do
case $flag in
none)
AC_MSG_CHECKING([whether pthreads work without any flags])
;;
-*)
AC_MSG_CHECKING([whether pthreads work with $flag])
PTHREAD_CFLAGS="$flag"
;;
pthread-config)
AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
if test x"$acx_pthread_config" = xno; then continue; fi
PTHREAD_CFLAGS="`pthread-config --cflags`"
PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
;;
*)
AC_MSG_CHECKING([for the pthreads library -l$flag])
PTHREAD_LIBS="-l$flag"
;;
esac
save_LIBS="$LIBS"
save_CFLAGS="$CFLAGS"
LIBS="$PTHREAD_LIBS $LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
# Check for various functions. We must include pthread.h,
# since some functions may be macros. (On the Sequent, we
# need a special flag -Kthread to make this header compile.)
# We check for pthread_join because it is in -lpthread on IRIX
# while pthread_create is in libc. We check for pthread_attr_init
# due to DEC craziness with -lpthreads. We check for
# pthread_cleanup_push because it is one of the few pthread
# functions on Solaris that doesn't have a non-functional libc stub.
# We try pthread_create on general principles.
AC_TRY_LINK([#include <pthread.h>],
[pthread_t th; pthread_join(th, 0);
pthread_attr_init(0); pthread_cleanup_push(0, 0);
pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
[acx_pthread_ok=yes])
LIBS="$save_LIBS"
CFLAGS="$save_CFLAGS"
AC_MSG_RESULT($acx_pthread_ok)
if test "x$acx_pthread_ok" = xyes; then
break;
fi
PTHREAD_LIBS=""
PTHREAD_CFLAGS=""
done
fi
# Various other checks:
if test "x$acx_pthread_ok" = xyes; then
save_LIBS="$LIBS"
LIBS="$PTHREAD_LIBS $LIBS"
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
# Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
AC_MSG_CHECKING([for joinable pthread attribute])
attr_name=unknown
for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
[attr_name=$attr; break])
done
AC_MSG_RESULT($attr_name)
if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
[Define to necessary symbol if this constant
uses a non-standard name on your system.])
fi
AC_MSG_CHECKING([if more special flags are required for pthreads])
flag=no
case "${host_cpu}-${host_os}" in
*-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
*solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
esac
AC_MSG_RESULT(${flag})
if test "x$flag" != xno; then
PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
fi
LIBS="$save_LIBS"
CFLAGS="$save_CFLAGS"
# More AIX lossage: must compile with cc_r
AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC})
else
PTHREAD_CC="$CC"
fi
AC_SUBST(PTHREAD_LIBS)
AC_SUBST(PTHREAD_CFLAGS)
AC_SUBST(PTHREAD_CC)
# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
if test x"$acx_pthread_ok" = xyes; then
ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
:
else
acx_pthread_ok=no
$2
fi
AC_LANG_RESTORE
])dnl ACX_PTHREAD

View File

@ -0,0 +1,187 @@
dnl @synopsis AX_CFLAGS_GCC_OPTION (optionflag [,[shellvar][,[A][,[NA]]])
dnl
dnl AX_CFLAGS_GCC_OPTION(-fvomit-frame) would show a message as like
dnl "checking CFLAGS for gcc -fvomit-frame ... yes" and adds the
dnl optionflag to CFLAGS if it is understood. You can override the
dnl shellvar-default of CFLAGS of course. The order of arguments stems
dnl from the explicit macros like AX_CFLAGS_WARN_ALL.
dnl
dnl The cousin AX_CXXFLAGS_GCC_OPTION would check for an option to add
dnl to CXXFLAGS - and it uses the autoconf setup for C++ instead of C
dnl (since it is possible to use different compilers for C and C++).
dnl
dnl The macro is a lot simpler than any special AX_CFLAGS_* macro (or
dnl ac_cxx_rtti.m4 macro) but allows to check for arbitrary options.
dnl However, if you use this macro in a few places, it would be great
dnl if you would make up a new function-macro and submit it to the
dnl ac-archive.
dnl
dnl - $1 option-to-check-for : required ("-option" as non-value)
dnl - $2 shell-variable-to-add-to : CFLAGS (or CXXFLAGS in the other case)
dnl - $3 action-if-found : add value to shellvariable
dnl - $4 action-if-not-found : nothing
dnl
dnl note: in earlier versions, $1-$2 were swapped. We try to detect the
dnl situation and accept a $2=~/-/ as being the old
dnl option-to-check-for.
dnl
dnl also: there are other variants that emerged from the original macro
dnl variant which did just test an option to be possibly added.
dnl However, some compilers accept an option silently, or possibly for
dnl just another option that was not intended. Therefore, we have to do
dnl a generic test for a compiler family. For gcc we check "-pedantic"
dnl being accepted which is also understood by compilers who just want
dnl to be compatible with gcc even when not being made from gcc
dnl sources.
dnl
dnl see also:
dnl
dnl AX_CFLAGS_SUN_OPTION AX_CFLAGS_HPUX_OPTION
dnl AX_CFLAGS_AIX_OPTION AX_CFLAGS_IRIX_OPTION
dnl
dnl @category C
dnl @author Guido Draheim <guidod@gmx.de>
dnl @version 2003-11-04
dnl @license GPLWithACException
AC_DEFUN([AX_CFLAGS_GCC_OPTION_OLD], [dnl
AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_gcc_option_$2])dnl
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)],
VAR,[VAR="no, unknown"
AC_LANG_SAVE
AC_LANG_C
ac_save_[]FLAGS="$[]FLAGS"
for ac_arg dnl
in "-pedantic % m4_ifval($2,$2,-option)" dnl GCC
#
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
AC_TRY_COMPILE([],[return 0;],
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
done
FLAGS="$ac_save_[]FLAGS"
AC_LANG_RESTORE
])
case ".$VAR" in
.ok|.ok,*) m4_ifvaln($3,$3) ;;
.|.no|.no,*) m4_ifvaln($4,$4) ;;
*) m4_ifvaln($3,$3,[
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
fi ]) ;;
esac
AS_VAR_POPDEF([VAR])dnl
AS_VAR_POPDEF([FLAGS])dnl
])
dnl the only difference - the LANG selection... and the default FLAGS
AC_DEFUN([AX_CXXFLAGS_GCC_OPTION_OLD], [dnl
AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_gcc_option_$2])dnl
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)],
VAR,[VAR="no, unknown"
AC_LANG_SAVE
AC_LANG_CXX
ac_save_[]FLAGS="$[]FLAGS"
for ac_arg dnl
in "-pedantic % m4_ifval($2,$2,-option)" dnl GCC
#
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
AC_TRY_COMPILE([],[return 0;],
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
done
FLAGS="$ac_save_[]FLAGS"
AC_LANG_RESTORE
])
case ".$VAR" in
.ok|.ok,*) m4_ifvaln($3,$3) ;;
.|.no|.no,*) m4_ifvaln($4,$4) ;;
*) m4_ifvaln($3,$3,[
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
fi ]) ;;
esac
AS_VAR_POPDEF([VAR])dnl
AS_VAR_POPDEF([FLAGS])dnl
])
dnl -------------------------------------------------------------------------
AC_DEFUN([AX_CFLAGS_GCC_OPTION_NEW], [dnl
AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_gcc_option_$1])dnl
AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)],
VAR,[VAR="no, unknown"
AC_LANG_SAVE
AC_LANG_C
ac_save_[]FLAGS="$[]FLAGS"
for ac_arg dnl
in "-pedantic % m4_ifval($1,$1,-option)" dnl GCC
#
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
AC_TRY_COMPILE([],[return 0;],
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
done
FLAGS="$ac_save_[]FLAGS"
AC_LANG_RESTORE
])
case ".$VAR" in
.ok|.ok,*) m4_ifvaln($3,$3) ;;
.|.no|.no,*) m4_ifvaln($4,$4) ;;
*) m4_ifvaln($3,$3,[
if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $VAR])
else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"])
m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"
fi ]) ;;
esac
AS_VAR_POPDEF([VAR])dnl
AS_VAR_POPDEF([FLAGS])dnl
])
dnl the only difference - the LANG selection... and the default FLAGS
AC_DEFUN([AX_CXXFLAGS_GCC_OPTION_NEW], [dnl
AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_gcc_option_$1])dnl
AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)],
VAR,[VAR="no, unknown"
AC_LANG_SAVE
AC_LANG_CXX
ac_save_[]FLAGS="$[]FLAGS"
for ac_arg dnl
in "-pedantic % m4_ifval($1,$1,-option)" dnl GCC
#
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
AC_TRY_COMPILE([],[return 0;],
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
done
FLAGS="$ac_save_[]FLAGS"
AC_LANG_RESTORE
])
case ".$VAR" in
.ok|.ok,*) m4_ifvaln($3,$3) ;;
.|.no|.no,*) m4_ifvaln($4,$4) ;;
*) m4_ifvaln($3,$3,[
if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $VAR])
else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"])
m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"
fi ]) ;;
esac
AS_VAR_POPDEF([VAR])dnl
AS_VAR_POPDEF([FLAGS])dnl
])
AC_DEFUN([AX_CFLAGS_GCC_OPTION],[ifelse(m4_bregexp([$2],[-]),-1,
[AX_CFLAGS_GCC_OPTION_NEW($@)],[AX_CFLAGS_GCC_OPTION_OLD($@)])])
AC_DEFUN([AX_CXXFLAGS_GCC_OPTION],[ifelse(m4_bregexp([$2],[-]),-1,
[AX_CXXFLAGS_GCC_OPTION_NEW($@)],[AX_CXXFLAGS_GCC_OPTION_OLD($@)])])

View File

@ -0,0 +1,118 @@
dnl @synopsis AX_CFLAGS_WARN_ALL [(shellvar [,default, [A/NA]])]
dnl
dnl Try to find a compiler option that enables most reasonable
dnl warnings. This macro is directly derived from VL_PROG_CC_WARNINGS
dnl which is split up into two AX_CFLAGS_WARN_ALL and
dnl AX_CFLAGS_WARN_ALL_ANSI
dnl
dnl For the GNU CC compiler it will be -Wall (and -ansi -pedantic) The
dnl result is added to the shellvar being CFLAGS by default.
dnl
dnl Currently this macro knows about GCC, Solaris C compiler, Digital
dnl Unix C compiler, C for AIX Compiler, HP-UX C compiler, IRIX C
dnl compiler, NEC SX-5 (Super-UX 10) C compiler, and Cray J90 (Unicos
dnl 10.0.0.8) C compiler.
dnl
dnl - $1 shell-variable-to-add-to : CFLAGS
dnl - $2 add-value-if-not-found : nothing
dnl - $3 action-if-found : add value to shellvariable
dnl - $4 action-if-not-found : nothing
dnl
dnl @category C
dnl @author Guido Draheim <guidod@gmx.de>
dnl @version 2003-01-06
dnl @license GPLWithACException
AC_DEFUN([AX_CFLAGS_WARN_ALL],[dnl
AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_warn_all])dnl
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum warnings],
VAR,[VAR="no, unknown"
AC_LANG_SAVE
AC_LANG_C
ac_save_[]FLAGS="$[]FLAGS"
for ac_arg dnl
in "-pedantic % -Wall" dnl GCC
"-xstrconst % -v" dnl Solaris C
"-std1 % -verbose -w0 -warnprotos" dnl Digital Unix
"-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX
"-ansi -ansiE % -fullwarn" dnl IRIX
"+ESlit % +w1" dnl HP-UX C
"-Xc % -pvctl[,]fullmsg" dnl NEC SX-5 (Super-UX 10)
"-h conform % -h msglevel 2" dnl Cray C (Unicos)
#
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
AC_TRY_COMPILE([],[return 0;],
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
done
FLAGS="$ac_save_[]FLAGS"
AC_LANG_RESTORE
])
case ".$VAR" in
.ok|.ok,*) m4_ifvaln($3,$3) ;;
.|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
*) m4_ifvaln($3,$3,[
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
fi ]) ;;
esac
AS_VAR_POPDEF([VAR])dnl
AS_VAR_POPDEF([FLAGS])dnl
])
dnl the only difference - the LANG selection... and the default FLAGS
AC_DEFUN([AX_CXXFLAGS_WARN_ALL],[dnl
AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_warn_all])dnl
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum warnings],
VAR,[VAR="no, unknown"
AC_LANG_SAVE
AC_LANG_CXX
ac_save_[]FLAGS="$[]FLAGS"
for ac_arg dnl
in "-pedantic % -Wall" dnl GCC
"-xstrconst % -v" dnl Solaris C
"-std1 % -verbose -w0 -warnprotos" dnl Digital Unix
"-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX
"-ansi -ansiE % -fullwarn" dnl IRIX
"+ESlit % +w1" dnl HP-UX C
"-Xc % -pvctl[,]fullmsg" dnl NEC SX-5 (Super-UX 10)
"-h conform % -h msglevel 2" dnl Cray C (Unicos)
#
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
AC_TRY_COMPILE([],[return 0;],
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
done
FLAGS="$ac_save_[]FLAGS"
AC_LANG_RESTORE
])
case ".$VAR" in
.ok|.ok,*) m4_ifvaln($3,$3) ;;
.|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
*) m4_ifvaln($3,$3,[
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
fi ]) ;;
esac
AS_VAR_POPDEF([VAR])dnl
AS_VAR_POPDEF([FLAGS])dnl
])
dnl implementation tactics:
dnl the for-argument contains a list of options. The first part of
dnl these does only exist to detect the compiler - usually it is
dnl a global option to enable -ansi or -extrawarnings. All other
dnl compilers will fail about it. That was needed since a lot of
dnl compilers will give false positives for some option-syntax
dnl like -Woption or -Xoption as they think of it is a pass-through
dnl to later compile stages or something. The "%" is used as a
dnl delimimiter. A non-option comment can be given after "%%" marks.

View File

@ -0,0 +1,118 @@
dnl @synopsis AX_CFLAGS_WARN_ALL_ANSI [(shellvar [,default, [A/NA]])]
dnl
dnl Try to find a compiler option that enables most reasonable
dnl warnings. This macro is directly derived from VL_PROG_CC_WARNINGS
dnl which is split up into two AX_CFLAGS_WARN_ALL and
dnl AX_CFLAGS_WARN_ALL_ANSI
dnl
dnl For the GNU CC compiler it will be -Wall (and -ansi -pedantic) The
dnl result is added to the shellvar being CFLAGS by default.
dnl
dnl Currently this macro knows about GCC, Solaris C compiler, Digital
dnl Unix C compiler, C for AIX Compiler, HP-UX C compiler, IRIX C
dnl compiler, NEC SX-5 (Super-UX 10) C compiler, and Cray J90 (Unicos
dnl 10.0.0.8) C compiler.
dnl
dnl - $1 shell-variable-to-add-to : CFLAGS
dnl - $2 add-value-if-not-found : nothing
dnl - $3 action-if-found : add value to shellvariable
dnl - $4 action-if-not-found : nothing
dnl
dnl @category C
dnl @author Guido Draheim <guidod@gmx.de>
dnl @version 2003-01-06
dnl @license GPLWithACException
AC_DEFUN([AX_CFLAGS_WARN_ALL_ANSI],[dnl
AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_warn_all_ansi])dnl
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum ansi warnings],
VAR,[VAR="no, unknown"
AC_LANG_SAVE
AC_LANG_C
ac_save_[]FLAGS="$[]FLAGS"
# IRIX C compiler:
# -use_readonly_const is the default for IRIX C,
# puts them into .rodata, but they are copied later.
# need to be "-G0 -rdatashared" for strictmode but
# I am not sure what effect that has really. - guidod
for ac_arg dnl
in "-pedantic % -Wall -ansi -pedantic" dnl GCC
"-xstrconst % -v -Xc" dnl Solaris C
"-std1 % -verbose -w0 -warnprotos -std1" dnl Digital Unix
" % -qlanglvl=ansi -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX
" % -ansi -ansiE -fullwarn" dnl IRIX
"+ESlit % +w1 -Aa" dnl HP-UX C
"-Xc % -pvctl[,]fullmsg -Xc" dnl NEC SX-5 (Super-UX 10)
"-h conform % -h msglevel 2 -h conform" dnl Cray C (Unicos)
#
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
AC_TRY_COMPILE([],[return 0;],
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
done
FLAGS="$ac_save_[]FLAGS"
AC_LANG_RESTORE
])
case ".$VAR" in
.ok|.ok,*) m4_ifvaln($3,$3) ;;
.|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
*) m4_ifvaln($3,$3,[
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
fi ]) ;;
esac
AS_VAR_POPDEF([VAR])dnl
AS_VAR_POPDEF([FLAGS])dnl
])
dnl the only difference - the LANG selection... and the default FLAGS
AC_DEFUN([AX_CXXFLAGS_WARN_ALL_ANSI],[dnl
AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_warn_all_ansi])dnl
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum ansi warnings],
VAR,[VAR="no, unknown"
AC_LANG_SAVE
AC_LANG_CXX
ac_save_[]FLAGS="$[]FLAGS"
# IRIX C compiler:
# -use_readonly_const is the default for IRIX C,
# puts them into .rodata, but they are copied later.
# need to be "-G0 -rdatashared" for strictmode but
# I am not sure what effect that has really. - guidod
for ac_arg dnl
in "-pedantic % -Wall -ansi -pedantic" dnl GCC
"-xstrconst % -v -Xc" dnl Solaris C
"-std1 % -verbose -w0 -warnprotos -std1" dnl Digital Unix
" % -qlanglvl=ansi -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX
" % -ansi -ansiE -fullwarn" dnl IRIX
"+ESlit % +w1 -Aa" dnl HP-UX C
"-Xc % -pvctl[,]fullmsg -Xc" dnl NEC SX-5 (Super-UX 10)
"-h conform % -h msglevel 2 -h conform" dnl Cray C (Unicos)
#
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
AC_TRY_COMPILE([],[return 0;],
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
done
FLAGS="$ac_save_[]FLAGS"
AC_LANG_RESTORE
])
case ".$VAR" in
.ok|.ok,*) m4_ifvaln($3,$3) ;;
.|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
*) m4_ifvaln($3,$3,[
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
fi ]) ;;
esac
AS_VAR_POPDEF([VAR])dnl
AS_VAR_POPDEF([FLAGS])dnl
])

View File

@ -0,0 +1,53 @@
dnl @synopsis RT_BOOL_ARG_ENABLE([FLAG],[DEFAULT],[HELP STRING])
dnl
dnl This macro declares a configure option with 'AC_ARG_ENABLE'.
dnl It is a boolean argument (yes or no values only), and
dnl the corresponding shell variable 'enable_arg' is guaranteed to
dnl be one or the other.
dnl A message is also printed.
dnl
dnl Arguments
dnl $1 = flag name e.g. [debug]
dnl $2 = default value, shall be m4 constant, either [yes] or [no]
dnl $3 = help string (default value is appended) e.g. [compile debugging code]
dnl
dnl @version $Id: rt_bool_arg_enable.m4,v 1.2 2006/02/18 14:35:09 r3mi Exp $
dnl @author Rémi Turboult <r3mi@users.sourceforge.net>
dnl @license GPLWithACException
dnl
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
dnl Public License, this file may be distributed as part of a program
dnl that contains a configuration script generated by Autoconf, under
dnl the same distribution terms as the rest of that program.
dnl
AC_DEFUN([RT_BOOL_ARG_ENABLE],[
dnl
m4_pushdef([Name],AS_TR_SH($1))dnl
m4_pushdef([NAME],AS_TR_CPP($1))dnl
dnl
AC_MSG_CHECKING([for --enable-]Name)
dnl
dnl use some m4 sugar to have only one 'AC_ARG_ENABLE' declaration,
dnl else "configure --help" is confused
dnl
AC_ARG_ENABLE(Name,
[m4_case([$2],
[yes],AS_HELP_STRING([--disable-]Name,
[disable $3 @<:@default=enabled@:>@]),
[no],AS_HELP_STRING([--enable-]Name,
[enable $3 @<:@default=disabled@:>@]),
[m4_fatal([incorrect boolean argument '$2'])]
)])
test "x$enable_[$1]" != [x]m4_if([$2],[yes],[no],[yes]) dnl
&& enable_[]Name=[$2]
AC_MSG_RESULT($enable_[]Name)dnl
AM_CONDITIONAL([ENABLE_]NAME, test x"$enable_[]Name" = xyes)
dnl
m4_popdef([NAME])dnl
m4_popdef([Name])dnl
dnl
])dnl

View File

@ -0,0 +1,25 @@
dnl @synopsis TYPE_SOCKLEN_T
dnl
dnl Check whether sys/socket.h defines type socklen_t. Please note that
dnl some systems require sys/types.h to be included before sys/socket.h
dnl can be compiled.
dnl
dnl @category Misc
dnl @author Lars Brinkhoff <lars@nocrew.org>
dnl @version 2005-01-11
dnl @license GPLWithACException
AC_DEFUN([TYPE_SOCKLEN_T],
[AC_CACHE_CHECK([for socklen_t], ac_cv_type_socklen_t,
[
AC_TRY_COMPILE(
[#include <sys/types.h>
#include <sys/socket.h>],
[socklen_t len = 42; return 0;],
ac_cv_type_socklen_t=yes,
ac_cv_type_socklen_t=no)
])
if test $ac_cv_type_socklen_t != yes; then
AC_DEFINE(socklen_t, int, [Substitute for socklen_t])
fi
])

View File

@ -0,0 +1,32 @@
# $Id: Makefile.am,v 1.2 2006/02/27 21:38:56 r3mi Exp $
#
# "Makefile.am" for "libupnp/threadutil"
#
# (C) Copyright 2005 Rémi Turboult <r3mi@users.sourceforge.net>
#
AM_CPPFLAGS = -I$(srcdir)/inc -I$(srcdir)/src/inc
AM_CFLAGS = $(PTHREAD_CFLAGS)
if ENABLE_DEBUG
AM_CPPFLAGS += -DDEBUG -DSTATS
else
AM_CPPFLAGS += -DNO_DEBUG -DNDEBUG
endif
lib_LTLIBRARIES = libthreadutil.la
libthreadutil_la_LDFLAGS = -version-info $(LT_VERSION_THREADUTIL)
libthreadutil_la_SOURCES = \
src/FreeList.c src/LinkedList.c \
src/ThreadPool.c src/TimerThread.c \
src/iasnprintf.c
upnpincludedir = $(includedir)/upnp
upnpinclude_HEADERS = \
inc/FreeList.h inc/LinkedList.h \
inc/ThreadPool.h inc/TimerThread.h \
inc/iasnprintf.h inc/ithread.h

View File

@ -0,0 +1,144 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
//
///////////////////////////////////////////////////////////////////////////
#ifndef FREE_LIST_H
#define FREE_LIST_H
#ifdef __cplusplus
extern "C" {
#endif
//#include <malloc.h>
#include "ithread.h"
#include <errno.h>
/****************************************************************************
* Name: FreeListNode
*
* Description:
* free list node. points to next free item.
* memory for node is borrowed from allocated items.
* Internal Use Only.
*****************************************************************************/
typedef struct FREELISTNODE
{
struct FREELISTNODE*next; //pointer to next free node
} FreeListNode;
/****************************************************************************
* Name: FreeList
*
* Description:
* Stores head and size of free list, as well as mutex for protection.
* Internal Use Only.
*****************************************************************************/
typedef struct FREELIST
{
FreeListNode *head; //head of free list
size_t element_size; //size of elements in free
//list
int maxFreeListLength; //max size of free structures
//to keep
int freeListLength; //current size of free list
}FreeList;
/****************************************************************************
* Function: FreeListInit
*
* Description:
* Initializes Free List. Must be called first.
* And only once for FreeList.
* Parameters:
* free_list - must be valid, non null, pointer to a linked list.
* size_t - size of elements to store in free list
* maxFreeListSize - max size that the free list can grow to
* before returning memory to O.S.
* Returns:
* 0 on success. Nonzero on failure.
* Always returns 0.
*****************************************************************************/
int FreeListInit(FreeList *free_list,
size_t elementSize,
int maxFreeListSize);
/****************************************************************************
* Function: FreeListAlloc
*
* Description:
* Allocates chunk of set size.
* If a free item is available in the list, returnes the stored item.
* Otherwise calls the O.S. to allocate memory.
* Parameters:
* free_list - must be valid, non null, pointer to a linked list.
* Returns:
* Non NULL on success. NULL on failure.
*****************************************************************************/
void * FreeListAlloc (FreeList *free_list);
/****************************************************************************
* Function: FreeListFree
*
* Description:
* Returns an item to the Free List.
* If the free list is smaller than the max size than
* adds the item to the free list.
* Otherwise returns the item to the O.S.
* Parameters:
* free_list - must be valid, non null, pointer to a linked list.
* Returns:
* 0 on success. Nonzero on failure.
* Always returns 0.
*****************************************************************************/
int FreeListFree (FreeList *free_list,void * element);
/****************************************************************************
* Function: FreeListDestroy
*
* Description:
* Releases the resources stored with the free list.
* Parameters:
* free_list - must be valid, non null, pointer to a linked list.
* Returns:
* 0 on success. Nonzero on failure.
* Always returns 0.
*****************************************************************************/
int FreeListDestroy (FreeList *free_list);
#ifdef __cplusplus
}
#endif
#endif // FREE_LIST_H

View File

@ -0,0 +1,330 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
//
///////////////////////////////////////////////////////////////////////////
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
#include "FreeList.h"
#ifdef __cplusplus
extern "C" {
#endif
#define EOUTOFMEM (-7 & 1<<29)
#define FREELISTSIZE 100
#define LIST_SUCCESS 1
#define LIST_FAIL 0
/****************************************************************************
* Name: free_routine
*
* Description:
* Function for freeing list items
*****************************************************************************/
typedef void (*free_function)(void *arg);
/****************************************************************************
* Name: cmp_routine
*
* Description:
* Function for comparing list items
* Returns 1 if itemA==itemB
*****************************************************************************/
typedef int (*cmp_routine)(void *itemA,void *itemB);
/****************************************************************************
* Name: ListNode
*
* Description:
* linked list node. stores generic item and pointers to next and prev.
* Internal Use Only.
*****************************************************************************/
typedef struct LISTNODE
{
struct LISTNODE *prev; //previous node
struct LISTNODE *next; //next node
void *item; //item
} ListNode;
/****************************************************************************
* Name: LinkedList
*
* Description:
* linked list (no protection). Internal Use Only.
* Because this is for internal use, parameters are NOT checked for
* validity.
* The first item of the list is stored at node: head->next
* The last item of the list is stored at node: tail->prev
* If head->next=tail, then list is empty.
* To iterate through the list:
*
* LinkedList g;
* ListNode *temp = NULL;
* for (temp = ListHead(g);temp!=NULL;temp = ListNext(g,temp))
* {
* }
*
*****************************************************************************/
typedef struct LINKEDLIST
{
ListNode head; //head, first item is stored at: head->next
ListNode tail; //tail, last item is stored at: tail->prev
long size; //size of list
FreeList freeNodeList; //free list to use
free_function free_func; //free function to use
cmp_routine cmp_func; //compare function to use
} LinkedList;
/****************************************************************************
* Function: ListInit
*
* Description:
* Initializes LinkedList. Must be called first.
* And only once for List.
* Parameters:
* list - must be valid, non null, pointer to a linked list.
* cmp_func - function used to compare items. (May be NULL)
* free_func - function used to free items. (May be NULL)
* Returns:
* 0 on success, EOUTOFMEM on failure.
*****************************************************************************/
int ListInit(LinkedList *list,cmp_routine cmp_func, free_function free_func);
/****************************************************************************
* Function: ListAddHead
*
* Description:
* Adds a node to the head of the list.
* Node gets immediately after list.head.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* void * item - item to be added
* Returns:
* The pointer to the ListNode on success, NULL on failure.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode *ListAddHead(LinkedList *list, void *item);
/****************************************************************************
* Function: ListAddTail
*
* Description:
* Adds a node to the tail of the list.
* Node gets added immediately before list.tail.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* void * item - item to be added
* Returns:
* The pointer to the ListNode on success, NULL on failure.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode *ListAddTail(LinkedList *list, void *item);
/****************************************************************************
* Function: ListAddAfter
*
* Description:
* Adds a node after the specified node.
* Node gets added immediately after bnode.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* void * item - item to be added
* ListNode * bnode - node to add after
* Returns:
* The pointer to the ListNode on success, NULL on failure.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode *ListAddAfter(LinkedList *list, void *item, ListNode *bnode);
/****************************************************************************
* Function: ListAddBefore
*
* Description:
* Adds a node before the specified node.
* Node gets added immediately before anode.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* ListNode * anode - node to add the in front of.
* void * item - item to be added
* Returns:
* The pointer to the ListNode on success, NULL on failure.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode *ListAddBefore(LinkedList *list,void *item, ListNode *anode);
/****************************************************************************
* Function: ListDelNode
*
* Description:
* Removes a node from the list
* The memory for the node is freed.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* ListNode *dnode - done to delete.
* freeItem - if !0 then item is freed using free function.
* if 0 (or free function is NULL) then item is not freed
* Returns:
* The pointer to the item stored in the node or NULL if the item is freed.
* Precondition:
* The list has been initialized.
*****************************************************************************/
void *ListDelNode(LinkedList *list,ListNode *dnode, int freeItem);
/****************************************************************************
* Function: ListDestroy
*
* Description:
* Removes all memory associated with list nodes.
* Does not free LinkedList *list.
*
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* freeItem - if !0 then items are freed using the free_function.
* if 0 (or free function is NULL) then items are not freed.
* Returns:
* 0 on success. Always returns 0.
* Precondition:
* The list has been initialized.
*****************************************************************************/
int ListDestroy(LinkedList *list, int freeItem);
/****************************************************************************
* Function: ListHead
*
* Description:
* Returns the head of the list.
*
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
*
* Returns:
* The head of the list. NULL if list is empty.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode* ListHead(LinkedList *list);
/****************************************************************************
* Function: ListTail
*
* Description:
* Returns the tail of the list.
*
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
*
* Returns:
* The tail of the list. NULL if list is empty.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode* ListTail(LinkedList *list);
/****************************************************************************
* Function: ListNext
*
* Description:
* Returns the next item in the list.
*
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
*
* Returns:
* The next item in the list. NULL if there are no more items in list.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode* ListNext(LinkedList *list, ListNode * node);
/****************************************************************************
* Function: ListPrev
*
* Description:
* Returns the previous item in the list.
*
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
*
* Returns:
* The previous item in the list. NULL if there are no more items in list.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode* ListPrev(LinkedList *list, ListNode * node);
/****************************************************************************
* Function: ListFind
*
* Description:
* Finds the specified item in the list.
* Uses the compare function specified in ListInit. If compare function
* is NULL then compares items as pointers.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* ListNode *start - the node to start from, NULL if to start from
* beginning.
* void * item - the item to search for.
* Returns:
* The node containing the item. NULL if no node contains the item.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode* ListFind(LinkedList *list, ListNode *start, void * item);
/****************************************************************************
* Function: ListSize
*
* Description:
* Returns the size of the list.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* Returns:
* The number of items in the list.
* Precondition:
* The list has been initialized.
*****************************************************************************/
int ListSize(LinkedList* list);
#ifdef __cplusplus
}
#endif
#endif //LINKED_LIST_H

View File

@ -0,0 +1,539 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
//
///////////////////////////////////////////////////////////////////////////
#ifndef THREADPOOL_H
#define THREADPOOL_H
#ifdef __cplusplus
extern "C" {
#endif
//Size of job free list
#define JOBFREELISTSIZE 100
#define INFINITE_THREADS -1
#define EMAXTHREADS (-8 & 1<<29)
//Invalid Policy
#define INVALID_POLICY (-9 & 1<<29)
//Invalid JOB Id
#define INVALID_JOB_ID (-2 & 1<<29)
typedef enum duration {SHORT_TERM,PERSISTENT} Duration;
typedef enum priority {LOW_PRIORITY,
MED_PRIORITY,
HIGH_PRIORITY} ThreadPriority;
#define DEFAULT_PRIORITY MED_PRIORITY //default priority used by TPJobInit
#define DEFAULT_MIN_THREADS 1 //default minimum used by TPAttrInit
#define DEFAULT_MAX_THREADS 10 //default max used by TPAttrInit
#define DEFAULT_JOBS_PER_THREAD 10 //default jobs per thread used by TPAttrInit
#define DEFAULT_STARVATION_TIME 500 //default starvation time used by TPAttrInit
#define DEFAULT_IDLE_TIME 10 * 1000 //default idle time used by TPAttrInit
#define DEFAULT_FREE_ROUTINE NULL //default free routine used TPJobInit
#define STATS 1 //always include stats because code change is minimal
//Statistics
#ifdef STATS
#define STATSONLY(x) x
#else
#define STATSONLY(x)
#endif
#ifdef _DEBUG
#define DEBUG 1
#endif
//DEBUGGING
#ifdef DEBUG
#define DBGONLY(x) x
#else
#define DBGONLY(x)
#endif
#include "LinkedList.h"
#include <sys/timeb.h>
#include "FreeList.h"
#include "ithread.h"
#include <errno.h>
#include <sys/timeb.h>
#define EXPORT
typedef int PolicyType;
#define DEFAULT_POLICY SCHED_OTHER
#define DEFAULT_SCHED_PARAM 0 //default priority
/****************************************************************************
* Name: free_routine
*
* Description:
* Function for freeing a thread argument
*****************************************************************************/
typedef void (*free_routine)(void *arg);
/****************************************************************************
* Name: ThreadPoolAttr
*
* Description:
* Attributes for thread pool. Used to set and change parameters of
* thread pool
*****************************************************************************/
typedef struct THREADPOOLATTR
{
int minThreads; //minThreads, ThreadPool will always maintain at least
//this many threads
int maxThreads; //maxThreads, ThreadPool will never have more than this
//number of threads
int maxIdleTime; //maxIdleTime (in milliseconds)
// this is the maximum time a thread will remain idle
// before dying
int jobsPerThread; //jobs per thread to maintain
int starvationTime; //the time a low priority or med priority
//job waits before getting bumped
//up a priority (in milliseconds)
PolicyType schedPolicy; //scheduling policy to use
} ThreadPoolAttr;
/****************************************************************************
* Name: ThreadPool
*
* Description:
* Internal ThreadPool Job
*****************************************************************************/
typedef struct THREADPOOLJOB
{
start_routine func; //function
void *arg; //arg
free_routine free_func; //free function
struct timeb requestTime; //time of request
int priority; //priority of request
int jobId; //id
} ThreadPoolJob;
/****************************************************************************
* Name: ThreadPoolStats
*
* Description:
* Structure to hold statistics
*****************************************************************************/
STATSONLY(
typedef struct TPOOLSTATS
{
double totalTimeHQ; //total time spent by all jobs in high priority Q
int totalJobsHQ; //total jobs in HQ run so far
double avgWaitHQ; //average wait in HQ
double totalTimeMQ; //total time spent by all jobs in med priority Q
int totalJobsMQ; //total jobs in MQ run so far
double avgWaitMQ; //average wait in MQ
double totalTimeLQ; //total time spent by all jobs in low priority Q
int totalJobsLQ; //total jobs in LQ run so far
double avgWaitLQ; //average wait in LQ
double totalWorkTime; //total time spent working for all threads
double totalIdleTime; //total time spent idle for all threads
int workerThreads; //number of current workerThreads
int idleThreads; //number of current idle threads
int persistentThreads; //number of persistent threads
int totalThreads; //total number of current threads
int maxThreads; //max threads so far
int currentJobsHQ; // current jobs in Q
int currentJobsLQ; //current jobs in Q
int currentJobsMQ; //current jobs in Q
}ThreadPoolStats;
)
/****************************************************************************
* Name: ThreadPool
*
* Description:
* A thread pool similar to the thread pool in the UPnP SDK.
* Allows jobs to be scheduled for running by threads in a
* thread pool. The thread pool is initialized with a
* minimum and maximum thread number as well as a
* max idle time
* and a jobs per thread ratio. If a worker thread waits the whole
* max idle time without receiving a job and the thread pool
* currently has more threads running than the minimum
* then the worker thread will exit. If when
* scheduling a job the current job to thread ratio
* becomes greater than the set ratio and the thread pool currently has
* less than the maximum threads then a new thread will
* be created.
*
*****************************************************************************/
typedef struct THREADPOOL
{
ithread_mutex_t mutex; //mutex to protect job qs
ithread_cond_t condition; //condition variable to signal Q
ithread_cond_t start_and_shutdown; //condition variable for start
//and stop
int lastJobId; //ids for jobs
int shutdown; //whether or not we are shutting down
int totalThreads; //total number of threads
int persistentThreads; //number of persistent threads
FreeList jobFreeList; //free list of jobs
LinkedList lowJobQ; //low priority job Q
LinkedList medJobQ; //med priority job Q
LinkedList highJobQ; //high priority job Q
ThreadPoolJob *persistentJob; //persistent job
ThreadPoolAttr attr; //thread pool attributes
//statistics
STATSONLY(ThreadPoolStats stats;)
} ThreadPool;
/****************************************************************************
* Function: ThreadPoolInit
*
* Description:
* Initializes and starts ThreadPool. Must be called first.
* And only once for ThreadPool.
* Parameters:
* tp - must be valid, non null, pointer to ThreadPool.
* attr - can be null
*
* if not null then attr contains the following fields:
*
* minWorkerThreads - minimum number of worker threads
* thread pool will never have less than this
* number of threads.
* maxWorkerThreads - maximum number of worker threads
* thread pool will never have more than this
* number of threads.
* maxIdleTime - maximum time that a worker thread will spend
* idle. If a worker is idle longer than this
* time and there are more than the min
* number of workers running, than the
* worker thread exits.
* jobsPerThread - ratio of jobs to thread to try and maintain
* if a job is scheduled and the number of jobs per
* thread is greater than this number,and
* if less than the maximum number of
* workers are running then a new thread is
* started to help out with efficiency.
* schedPolicy - scheduling policy to try and set (OS dependent)
* Returns:
* 0 on success, nonzero on failure.
* EAGAIN if not enough system resources to create minimum threads.
* INVALID_POLICY if schedPolicy can't be set
* EMAXTHREADS if minimum threads is greater than maximum threads
*****************************************************************************/
int ThreadPoolInit(ThreadPool *tp,
ThreadPoolAttr *attr);
/****************************************************************************
* Function: ThreadPoolAddPersistent
*
* Description:
* Adds a persistent job to the thread pool.
* Job will be run as soon as possible.
* Call will block until job is scheduled.
* Parameters:
* tp - valid thread pool pointer
* ThreadPoolJob - valid thread pool job with the following fields:
*
* func - ThreadFunction to run
* arg - argument to function.
* priority - priority of job.
*
* Returns:
* 0 on success, nonzero on failure
* EOUTOFMEM not enough memory to add job.
* EMAXTHREADS not enough threads to add persistent job.
*****************************************************************************/
int ThreadPoolAddPersistent (ThreadPool*tp,
ThreadPoolJob *job,
int *jobId);
/****************************************************************************
* Function: ThreadPoolGetAttr
*
* Description:
* Gets the current set of attributes
* associated with the thread pool.
* Parameters:
* tp - valid thread pool pointer
* out - non null pointer to store attributes
* Returns:
* 0 on success, nonzero on failure
* Always returns 0.
*****************************************************************************/
int ThreadPoolGetAttr(ThreadPool *tp,
ThreadPoolAttr *out);
/****************************************************************************
* Function: ThreadPoolSetAttr
*
* Description:
* Sets the attributes for the thread pool.
* Only affects future calculations.
* Parameters:
* tp - valid thread pool pointer
* attr - pointer to attributes, null sets attributes to default.
* Returns:
* 0 on success, nonzero on failure
* Returns INVALID_POLICY if policy can not be set.
*****************************************************************************/
int ThreadPoolSetAttr(ThreadPool *tp,
ThreadPoolAttr *attr);
/****************************************************************************
* Function: ThreadPoolAdd
*
* Description:
* Adds a job to the thread pool.
* Job will be run as soon as possible.
* Parameters:
* tp - valid thread pool pointer
* func - ThreadFunction to run
* arg - argument to function.
* priority - priority of job.
* poolid - id of job
* free_function - function to use when freeing argument
* Returns:
* 0 on success, nonzero on failure
* EOUTOFMEM if not enough memory to add job.
*****************************************************************************/
int ThreadPoolAdd (ThreadPool*tp,
ThreadPoolJob *job,
int *jobId);
/****************************************************************************
* Function: ThreadPoolRemove
*
* Description:
* Removes a job from the thread pool.
* Can only remove jobs which are not
* currently running.
* Parameters:
* tp - valid thread pool pointer
* jobid - id of job
* out - space for removed job.
* Returns:
* 0 on success, nonzero on failure.
* INVALID_JOB_ID if job not found.
*****************************************************************************/
int ThreadPoolRemove(ThreadPool *tp,
int jobId, ThreadPoolJob *out);
/****************************************************************************
* Function: ThreadPoolShutdown
*
* Description:
* Shuts the thread pool down.
* Waits for all threads to finish.
* May block indefinitely if jobs do not
* exit.
* Parameters:
* tp - must be valid tp
* Returns:
* 0 on success, nonzero on failure
* Always returns 0.
*****************************************************************************/
int ThreadPoolShutdown(ThreadPool *tp);
/****************************************************************************
* Function: TPJobInit
*
* Description:
* Initializes thread pool job.
* Sets the priority to default defined in ThreadPool.h.
* Sets the free_routine to default defined in ThreadPool.h
* Parameters:
* ThreadPoolJob *job - must be valid thread pool attributes.
* start_routine func - function to run, must be valid
* void * arg - argument to pass to function.
* Returns:
* Always returns 0.
*****************************************************************************/
int TPJobInit(ThreadPoolJob *job, start_routine func, void *arg);
/****************************************************************************
* Function: TPJobSetPriority
*
* Description:
* Sets the max threads for the thread pool attributes.
* Parameters:
* attr - must be valid thread pool attributes.
* maxThreads - value to set
* Returns:
* Always returns 0.
*****************************************************************************/
int TPJobSetPriority(ThreadPoolJob *job, ThreadPriority priority);
/****************************************************************************
* Function: TPJobSetFreeFunction
*
* Description:
* Sets the max threads for the thread pool attributes.
* Parameters:
* attr - must be valid thread pool attributes.
* maxThreads - value to set
* Returns:
* Always returns 0.
*****************************************************************************/
int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func);
/****************************************************************************
* Function: TPAttrInit
*
* Description:
* Initializes thread pool attributes.
* Sets values to defaults defined in ThreadPool.h.
* Parameters:
* attr - must be valid thread pool attributes.
* Returns:
* Always returns 0.
*****************************************************************************/
int TPAttrInit(ThreadPoolAttr *attr);
/****************************************************************************
* Function: TPAttrSetMaxThreads
*
* Description:
* Sets the max threads for the thread pool attributes.
* Parameters:
* attr - must be valid thread pool attributes.
* maxThreads - value to set
* Returns:
* Always returns 0.
*****************************************************************************/
int TPAttrSetMaxThreads(ThreadPoolAttr *attr, int maxThreads);
/****************************************************************************
* Function: TPAttrSetMinThreads
*
* Description:
* Sets the min threads for the thread pool attributes.
* Parameters:
* attr - must be valid thread pool attributes.
* minThreads - value to set
* Returns:
* Always returns 0.
*****************************************************************************/
int TPAttrSetMinThreads(ThreadPoolAttr *attr, int minThreads);
/****************************************************************************
* Function: TPAttrSetIdleTime
*
* Description:
* Sets the idle time for the thread pool attributes.
* Parameters:
* attr - must be valid thread pool attributes.
* Returns:
* Always returns 0.
*****************************************************************************/
int TPAttrSetIdleTime(ThreadPoolAttr *attr, int idleTime);
/****************************************************************************
* Function: TPAttrSetJobsPerThread
*
* Description:
* Sets the jobs per thread ratio
* Parameters:
* attr - must be valid thread pool attributes.
* jobsPerThread - number of jobs per thread to maintain
* Returns:
* Always returns 0.
*****************************************************************************/
int TPAttrSetJobsPerThread(ThreadPoolAttr *attr, int jobsPerThread);
/****************************************************************************
* Function: TPAttrSetStarvationTime
*
* Description:
* Sets the starvation time for the thread pool attributes.
* Parameters:
* attr - must be valid thread pool attributes.
* int starvationTime - milliseconds
* Returns:
* Always returns 0.
*****************************************************************************/
int TPAttrSetStarvationTime(ThreadPoolAttr *attr, int starvationTime);
/****************************************************************************
* Function: TPAttrSetSchedPolicy
*
* Description:
* Sets the scheduling policy for the thread pool attributes.
* Parameters:
* attr - must be valid thread pool attributes.
* PolicyType schedPolicy - must be a valid policy type.
* Returns:
* Always returns 0.
*****************************************************************************/
int TPAttrSetSchedPolicy(ThreadPoolAttr *attr, PolicyType schedPolicy);
/****************************************************************************
* Function: ThreadPoolGetStats
*
* Description:
* Returns various statistics about the
* thread pool.
* Only valid if STATS has been defined.
* Parameters:
* ThreadPool *tp - valid initialized threadpool
* ThreadPoolStats *stats - valid stats, out parameter
* Returns:
* Always returns 0.
*****************************************************************************/
STATSONLY( EXPORT int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats););
STATSONLY(EXPORT void ThreadPoolPrintStats(ThreadPoolStats *stats););
#ifdef __cplusplus
}
#endif
#endif //ThreadPool

View File

@ -0,0 +1,191 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
//
///////////////////////////////////////////////////////////////////////////
#ifndef TIMERTHREAD_H
#define TIMERTHREAD_H
#include "ithread.h"
#include "LinkedList.h"
#include "FreeList.h"
#include "ThreadPool.h"
#ifdef __cplusplus
extern "C" {
#endif
#define INVALID_EVENT_ID (-10 & 1<<29)
//Timeout Types
//absolute means in seconds from Jan 1, 1970
//relative means in seconds from current time
typedef enum timeoutType {ABS_SEC,REL_SEC} TimeoutType;
/****************************************************************************
* Name: TimerThread
*
* Description:
* A timer thread similar to the one in the Upnp SDK that allows
* the scheduling of a job to run at a specified time in the future
* Because the timer thread uses the thread pool there is no
* gurantee of timing, only approximate timing.
* Uses ThreadPool, Mutex, Condition, Thread
*
*
*****************************************************************************/
typedef struct TIMERTHREAD
{
ithread_mutex_t mutex; //mutex to protect eventQ
ithread_cond_t condition; //condition variable
int lastEventId; //last event id
LinkedList eventQ; //event q
int shutdown; //whether or not we are shutdown
FreeList freeEvents; //FreeList for events
ThreadPool *tp; //ThreadPool to use
} TimerThread;
/****************************************************************************
* Name: TimerEvent
*
* Description:
*
* Struct to contain information for a timer event.
* Internal to the TimerThread
*
*****************************************************************************/
typedef struct TIMEREVENT
{
ThreadPoolJob job;
time_t eventTime; //absolute time for event in seconds since Jan 1, 1970
Duration persistent; //long term or short term job
int id; //id of job
} TimerEvent;
/************************************************************************
* Function: TimerThreadInit
*
* Description:
* Initializes and starts timer thread.
*
* Parameters:
* timer - valid timer thread pointer.
* tp - valid thread pool to use. Must be
* started. Must be valid for lifetime
* of timer. Timer must be shutdown
* BEFORE thread pool.
* Return:
* 0 on success, nonzero on failure
* Returns error from ThreadPoolAddPersistent on failure.
*
************************************************************************/
int TimerThreadInit(TimerThread *timer,
ThreadPool *tp);
/************************************************************************
* Function: TimerThreadSchedule
*
* Description:
* Schedules an event to run at a specified time.
*
* Parameters:
* timer - valid timer thread pointer.
* time_t - time of event.
* either in absolute seconds,
* or relative seconds in the future.
* timeoutType - either ABS_SEC, or REL_SEC.
* if REL_SEC, then the event
* will be scheduled at the
* current time + REL_SEC.
* job-> valid Thread pool job with following fields
* func - function to schedule
* arg - argument to function
* priority - priority of job.
*
* id - id of timer event. (out, can be null)
* Return:
* 0 on success, nonzero on failure
* EOUTOFMEM if not enough memory to schedule job.
*
************************************************************************/
int TimerThreadSchedule(TimerThread* timer,
time_t time,
TimeoutType type,
ThreadPoolJob *job,
Duration duration,
int *id);
/************************************************************************
* Function: TimerThreadRemove
*
* Description:
* Removes an event from the timer Q.
* Events can only be removed
* before they have been placed in the
* thread pool.
*
* Parameters:
* timer - valid timer thread pointer.
* id - id of event to remove.
* ThreadPoolJob *out - space for thread pool job.
* Return:
* 0 on success,
* INVALID_EVENT_ID on failure
*
************************************************************************/
int TimerThreadRemove(TimerThread *timer,
int id,
ThreadPoolJob *out);
/************************************************************************
* Function: TimerThreadShutdown
*
* Description:
* Shutdown the timer thread
* Events scheduled in the future will NOT be run.
* Timer thread should be shutdown BEFORE it's associated
* thread pool.
* Returns:
* returns 0 if succesfull,
* nonzero otherwise.
* Always returns 0.
***********************************************************************/
int TimerThreadShutdown(TimerThread *timer);
#ifdef __cplusplus
}
#endif
#endif //TIMER_THREAD_H

View File

@ -0,0 +1,66 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 <stdarg.h>
#define EXPORT
#ifdef __cplusplus
extern "C" {
#endif
/**
* Allocates enough memory for the
* Formatted string, up to max
* specified.
* With max set to -1, allocates
* as much size as needed.
* Memory must be freed using free.
*/
EXPORT int iasnprintf(char **ret,
int incr,
int max,
const char * fmt, ...)
#ifndef SPARC_SOLARIS
#if (__GNUC__ >= 3)
__attribute__((format (__printf__, 4, 5)));
#else
;
#endif
EXPORT void iasnprintfFree(char *);
#else
;
#endif
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,536 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
//
///////////////////////////////////////////////////////////////////////////
#ifndef ITHREADH
#define ITHREADH
#ifdef __cplusplus
extern "C" {
#endif
#ifdef DEBUG
#define DEBUG_ONLY(x) x
#else
#define DEBUG_ONLY(x)
#endif
#include <pthread.h>
#include <unistd.h>
#define ITHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_FAST_NP
#define ITHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE_NP
#define ITHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK_NP
#define ITHREAD_CANCELED PTHREAD_CANCELED
/***************************************************************************
* Name: ithread_t
*
* Description:
* Thread handle.
* typedef to pthread_t.
* Internal Use Only.
***************************************************************************/
typedef pthread_t ithread_t;
/****************************************************************************
* Name: ithread_attr_t
*
* Description:
* Thread attribute.
* typedef to pthread_attr_t
* Internal Use Only
***************************************************************************/
typedef pthread_attr_t ithread_attr_t;
/****************************************************************************
* Name: start_routine
*
* Description:
* Thread start routine
* Internal Use Only.
***************************************************************************/
typedef void * (*start_routine) (void *arg);
/****************************************************************************
* Name: ithread_cond_t
*
* Description:
* condition variable.
* typedef to pthread_cond_t
* Internal Use Only.
***************************************************************************/
typedef pthread_cond_t ithread_cond_t;
/****************************************************************************
* Name: ithread_mutexattr_t
*
* Description:
* Mutex attribute.
* typedef to pthread_mutexattr_t
* Internal Use Only
***************************************************************************/
typedef pthread_mutexattr_t ithread_mutexattr_t;
/****************************************************************************
* Name: ithread_mutex_t
*
* Description:
* Mutex.
* typedef to pthread_mutex_t
* Internal Use Only.
***************************************************************************/
typedef pthread_mutex_t ithread_mutex_t;
/****************************************************************************
* Name: ithread_condattr_t
*
* Description:
* Condition attribute.
* typedef to pthread_condattr_t
* NOT USED
* Internal Use Only
***************************************************************************/
typedef pthread_condattr_t ithread_condattr_t;
/****************************************************************************
* Function: ithread_mutexattr_init
*
* Description:
* Initializes a mutex attribute variable.
* Used to set the type of the mutex.
* Parameters:
* ithread_mutexattr_init * attr (must be valid non NULL pointer to
* pthread_mutexattr_t)
* Returns:
* 0 on success, Nonzero on failure.
* Always returns 0.
* See man page for pthread_mutexattr_init
***************************************************************************/
#define ithread_mutexattr_init pthread_mutexattr_init
/****************************************************************************
* Function: ithread_mutexattr_destroy
*
* Description:
* Releases any resources held by the mutex attribute.
* Currently there are no resources associated with the attribute
* Parameters:
* ithread_mutexattr_t * attr (must be valid non NULL pointer to
* pthread_mutexattr_t)
* Returns:
* 0 on success, Nonzero on failure.
* Always returns 0.
* See man page for pthread_mutexattr_destroy
***************************************************************************/
#define ithread_mutexattr_destroy pthread_mutexattr_destroy
/****************************************************************************
* Function: ithread_mutexattr_setkind_np
*
* Description:
* Sets the mutex type in the attribute.
* Valid types are: ITHREAD_MUTEX_FAST_NP
* ITHREAD_MUTEX_RECURSIVE_NP
* ITHREAD_MUTEX_ERRORCHECK_NP
*
* Parameters:
* ithread_mutexattr_t * mutex (must be valid non NULL pointer to
* ithread_mutexattr_t)
* int kind (one of ITHREAD_MUTEX_FAST_NP or ITHREAD_MUTEX_RECURSIVE_NP
* or ITHREAD_MUTEX_ERRORCHECK_NP)
* Returns:
* 0 on success. Nonzero on failure.
* Returns EINVAL if the kind is not supported.
* See man page for pthread_mutexattr_setkind_np
*****************************************************************************/
#define ithread_mutexattr_setkind_np pthread_mutexattr_setkind_np
/****************************************************************************
* Function: ithread_mutexattr_getkind_np
*
* Description:
* Gets the mutex type in the attribute.
* Valid types are: ITHREAD_MUTEX_FAST_NP
* ITHREAD_MUTEX_RECURSIVE_NP
* ITHREAD_MUTEX_ERRORCHECK_NP
*
* Parameters:
* ithread_mutexattr_t * mutex (must be valid non NULL pointer to
* pthread_mutexattr_t)
* int *kind (one of ITHREAD_MUTEX_FAST_NP or ITHREAD_MUTEX_RECURSIVE_NP
* or ITHREAD_MUTEX_ERRORCHECK_NP)
* Returns:
* 0 on success. Nonzero on failure.
* Always returns 0.
* See man page for pthread_mutexattr_getkind_np
*****************************************************************************/
#define ithread_mutexattr_getkind_np pthread_mutexattr_getkind_np
/****************************************************************************
* Function: ithread_mutex_init
*
* Description:
* Initializes mutex.
* Must be called before use.
*
* Parameters:
* ithread_mutex_t * mutex (must be valid non NULL pointer to pthread_mutex_t)
* const ithread_mutexattr_t * mutex_attr
* Returns:
* 0 on success, Nonzero on failure.
* Always returns 0.
* See man page for pthread_mutex_init
*****************************************************************************/
#define ithread_mutex_init pthread_mutex_init
/****************************************************************************
* Function: ithread_mutex_lock
*
* Description:
* Locks mutex.
* Parameters:
* ithread_mutex_t * mutex (must be valid non NULL pointer to pthread_mutex_t)
* mutex must be initialized.
*
* Returns:
* 0 on success, Nonzero on failure.
* Always returns 0.
* See man page for pthread_mutex_lock
*****************************************************************************/
#define ithread_mutex_lock pthread_mutex_lock
/****************************************************************************
* Function: ithread_mutex_unlock
*
* Description:
* Unlocks mutex.
*
* Parameters:
* ithread_mutex_t * mutex (must be valid non NULL pointer to pthread_mutex_t)
* mutex must be initialized.
*
* Returns:
* 0 on success, Nonzero on failure.
* Always returns 0.
* See man page for pthread_mutex_unlock
*****************************************************************************/
#define ithread_mutex_unlock pthread_mutex_unlock
/****************************************************************************
* Function: ithread_mutex_destroy
*
* Description:
* Releases any resources held by the mutex.
* Mutex can no longer be used after this call.
* Mutex is only destroyed when there are no longer any threads waiting on it.
* Mutex cannot be destroyed if it is locked.
* Parameters:
* ithread_mutex_t * mutex (must be valid non NULL pointer to pthread_mutex_t)
* mutex must be initialized.
* Returns:
* 0 on success. Nonzero on failure.
* Always returns 0.
* See man page for pthread_mutex_destroy
*****************************************************************************/
#define ithread_mutex_destroy pthread_mutex_destroy
/****************************************************************************
* Function: ithread_cond_init
*
* Description:
* Initializes condition variable.
* Must be called before use.
* Parameters:
* ithread_cond_t * cond (must be valid non NULL pointer to pthread_cond_t)
* const ithread_condattr_t * cond_attr (ignored)
* Returns:
* 0 on success, Nonzero on failure.
* See man page for pthread_cond_init
*****************************************************************************/
#define ithread_cond_init pthread_cond_init
/****************************************************************************
* Function: ithread_cond_signal
*
* Description:
* Wakes up exactly one thread waiting on condition.
* Associated mutex MUST be locked by thread before entering this call.
* Parameters:
* ithread_cond_t * cond (must be valid non NULL pointer to
* ithread_cond_t)
* cond must be initialized
* Returns:
* 0 on success, Nonzero on failure.
* See man page for pthread_cond_signal
*****************************************************************************/
#define ithread_cond_signal pthread_cond_signal
/****************************************************************************
* Function: ithread_cond_broadcast
*
* Description:
* Wakes up all threads waiting on condition.
* Associated mutex MUST be locked by thread before entering this call.
* Parameters:
* ithread_cond_t * cond (must be valid non NULL pointer to
* ithread_cond_t)
* cond must be initialized
* Returns:
* 0 on success, Nonzero on failure.
* See man page for pthread_cond_broadcast
*****************************************************************************/
#define ithread_cond_broadcast pthread_cond_broadcast
/****************************************************************************
* Function: ithread_cond_wait
*
* Description:
* Atomically releases mutex and waits on condition.
* Associated mutex MUST be locked by thread before entering this call.
* Mutex is reacquired when call returns.
* Parameters:
* ithread_cond_t * cond (must be valid non NULL pointer to
* ithread_cond_t)
* cond must be initialized
* ithread_mutex_t *mutex (must be valid non NULL pointer to
* ithread_mutex_t)
* Mutex must be locked.
* Returns:
* 0 on success, Nonzero on failure.
* See man page for pthread_cond_wait
*****************************************************************************/
#define ithread_cond_wait pthread_cond_wait
/****************************************************************************
* Function: pthread_cond_timedwait
*
* Description:
* Atomically releases the associated mutex and waits on the condition.
* If the condition is not signaled in the specified time
* than the
* call times out and returns.
* Associated mutex MUST be locked by thread before entering
* this call.
* Mutex is reacquired when call returns.
* Parameters:
* ithread_cond_t * cond (must be valid non NULL pointer to
* ithread_cond_t)
* cond must be initialized
* ithread_mutex_t *mutex (must be valid non NULL pointer to
* ithread_mutex_t)
* Mutex must be locked.
* const struct timespec *abstime (absolute time, measured
* from Jan 1, 1970)
* Returns:
* 0 on success. ETIMEDOUT on timeout. Nonzero on failure.
* See man page for pthread_cond_timedwait
***************************************************************************/
#define ithread_cond_timedwait pthread_cond_timedwait
/****************************************************************************
* Function: ithread_cond_destroy
*
* Description:
* Releases any resources held by the condition variable.
* Condition variable can no longer be used after this call.
* Parameters:
* ithread_cond_t * cond (must be valid non NULL pointer to
* ithread_cond_t)
* cond must be initialized.
* Returns:
* 0 on success. Nonzero on failure.
* See man page for pthread_cond_destroy
***************************************************************************/
#define ithread_cond_destroy pthread_cond_destroy
/****************************************************************************
* Function: ithread_create
*
* Description:
* Creates a thread with the given start routine
* and argument.
* Parameters:
* ithread_t * thread (must be valid non NULL pointer to pthread_t)
* ithread_attr_t *attr, IGNORED
* void * (start_routine) (void *arg) (start routine)
* void * arg - argument.
* Returns:
* 0 on success. Nonzero on failure.
* Returns EAGAIN if a new thread can not be created.
* Returns EINVAL if there is a problem with the arguments.
* See man page fore pthread_create
***************************************************************************/
#define ithread_create pthread_create
/****************************************************************************
* Function: ithread_cancel
*
* Description:
* Cancels a thread.
* Parameters:
* ithread_t * thread (must be valid non NULL pointer to ithread_t)
* Returns:
* 0 on success. Nonzero on failure.
* See man page for pthread_cancel
***************************************************************************/
#define ithread_cancel pthread_cancel
/****************************************************************************
* Function: ithread_exit
*
* Description:
* Returns a return code from a thread.
* Implicitly called when the start routine returns.
* Parameters:
* void * return_code return code to return
* See man page for pthread_exit
***************************************************************************/
#define ithread_exit pthread_exit
/****************************************************************************
* Function: ithread_get_current_thread_id
*
* Description:
* Returns the handle of the currently running thread.
* Returns:
* The handle of the currently running thread.
* See man page for pthread_self
***************************************************************************/
#define ithread_get_current_thread_id pthread_self
/****************************************************************************
* Function: ithread_self
*
* Description:
* Returns the handle of the currently running thread.
* Returns:
* The handle of the currently running thread.
* See man page for pthread_self
***************************************************************************/
#define ithread_self pthread_self
/****************************************************************************
* Function: ithread_detach
*
* Description:
* Makes a thread's resources reclaimed immediately
* after it finishes
* execution.
* Returns:
* 0 on success, Nonzero on failure.
* See man page for pthread_detach
***************************************************************************/
#define ithread_detach pthread_detach
/****************************************************************************
* Function: ithread_join
*
* Description:
* Suspends the currently running thread until the
* specified thread
* has finished.
* Returns the return code of the thread, or ITHREAD_CANCELED
* if the thread has been canceled.
* Parameters:
* ithread_t *thread (valid non null thread identifier)
* void ** return (space for return code)
* Returns:
* 0 on success, Nonzero on failure.
* See man page for pthread_join
***************************************************************************/
#define ithread_join pthread_join
/****************************************************************************
* Function: isleep
*
* Description:
* Suspends the currently running thread for the specified number
* of seconds
* Always returns 0.
* Parameters:
* unsigned int seconds - number of seconds to sleep.
* Returns:
* 0 on success, Nonzero on failure.
* See man page for sleep (man 3 sleep)
*****************************************************************************/
#define isleep sleep
/****************************************************************************
* Function: isleep
*
* Description:
* Suspends the currently running thread for the specified number
* of milliseconds
* Always returns 0.
* Parameters:
* unsigned int milliseconds - number of milliseconds to sleep.
* Returns:
* 0 on success, Nonzero on failure.
* See man page for sleep (man 3 sleep)
*****************************************************************************/
#define imillisleep(x) usleep(1000*x)
//NK: Added for satisfying the gcc compiler
int pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind);
#ifdef __cplusplus
}
#endif
#endif //ITHREADH

View File

@ -0,0 +1,177 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 "FreeList.h"
#include <assert.h>
#include <stdlib.h>
/****************************************************************************
* Function: FreeListInit
*
* Description:
* Initializes Free List. Must be called first.
* And only once for FreeList.
* Parameters:
* free_list - must be valid, non null, pointer to a linked list.
* size_t - size of elements to store in free list
* maxFreeListSize - max size that the free list can grow to
* before returning memory to O.S.
* Returns:
* 0 on success. Nonzero on failure.
* Always returns 0.
*****************************************************************************/
int
FreeListInit( FreeList * free_list,
size_t elementSize,
int maxFreeListLength )
{
assert( free_list != NULL );
if( free_list == NULL )
return EINVAL;
free_list->element_size = elementSize;
free_list->maxFreeListLength = maxFreeListLength;
free_list->head = NULL;
free_list->freeListLength = 0;
return 0;
}
/****************************************************************************
* Function: FreeListAlloc
*
* Description:
* Allocates chunk of set size.
* If a free item is available in the list, returnes the stored item.
* Otherwise calls the O.S. to allocate memory.
* Parameters:
* free_list - must be valid, non null, pointer to a linked list.
* Returns:
* Non NULL on success. NULL on failure.
*****************************************************************************/
void *
FreeListAlloc( FreeList * free_list )
{
FreeListNode *ret = NULL;
assert( free_list != NULL );
if( free_list == NULL )
return NULL;
if( free_list->head ) {
ret = free_list->head;
free_list->head = free_list->head->next;
free_list->freeListLength--;
} else {
ret = malloc( free_list->element_size );
}
return ret;
}
/****************************************************************************
* Function: FreeListFree
*
* Description:
* Returns an item to the Free List.
* If the free list is smaller than the max size than
* adds the item to the free list.
* Otherwise returns the item to the O.S.
* Parameters:
* free_list - must be valid, non null, pointer to a free list.
* element - must be a pointer allocated by FreeListAlloc
* Returns:
* 0 on success. Nonzero on failure.
* Always returns 0.
*****************************************************************************/
int
FreeListFree( FreeList * free_list,
void *element )
{
FreeListNode *temp = NULL;
assert( free_list != NULL );
if( free_list == NULL )
return EINVAL;
if( ( element != NULL ) &&
( ( free_list->freeListLength + 1 ) <
free_list->maxFreeListLength ) ) {
free_list->freeListLength++;
temp = ( FreeListNode * ) element;
temp->next = free_list->head;
free_list->head = temp;
} else {
free( element );
}
return 0;
}
/****************************************************************************
* Function: FreeListDestroy
*
* Description:
* Releases the resources stored with the free list.
* Parameters:
* free_list - must be valid, non null, pointer to a linked list.
* Returns:
* 0 on success. Nonzero on failure.
* Always returns 0.
*****************************************************************************/
int
FreeListDestroy( FreeList * free_list )
{
FreeListNode *temp = NULL;
int i = 0;
assert( free_list != NULL );
if( free_list == NULL )
return EINVAL;
while( free_list->head ) {
i++;
temp = free_list->head->next;
free( free_list->head );
free_list->head = temp;
}
free_list->freeListLength = 0;
return 0;
}

View File

@ -0,0 +1,529 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 "LinkedList.h"
#include <malloc.h>
#include <assert.h>
static int
freeListNode( ListNode * node,
LinkedList * list )
{
assert( list != NULL );
return FreeListFree( &list->freeNodeList, node );
}
/****************************************************************************
* Function: CreateListNode
*
* Description:
* Creates a list node. Dynamically.
*
* Parameters:
* void * item - the item to store
* Returns:
* The new node, NULL on failure.
*****************************************************************************/
static ListNode *
CreateListNode( void *item,
LinkedList * list )
{
ListNode *temp = NULL;
assert( list != NULL );
temp = ( ListNode * ) FreeListAlloc( &list->freeNodeList );
if( temp ) {
temp->prev = NULL;
temp->next = NULL;
temp->item = item;
}
return temp;
}
/****************************************************************************
* Function: ListInit
*
* Description:
* Initializes LinkedList. Must be called first.
* And only once for List.
* Parameters:
* list - must be valid, non null, pointer to a linked list.
* cmp_func - function used to compare items. (May be NULL)
* free_func - function used to free items. (May be NULL)
* Returns:
* 0 on success, EOUTOFMEM on failure.
*****************************************************************************/
int
ListInit( LinkedList * list,
cmp_routine cmp_func,
free_function free_func )
{
int retCode = 0;
assert( list != NULL );
if( list == NULL )
return EINVAL;
list->size = 0;
list->cmp_func = cmp_func;
list->free_func = free_func;
retCode =
FreeListInit( &list->freeNodeList, sizeof( ListNode ),
FREELISTSIZE );
assert( retCode == 0 );
list->head.item = NULL;
list->head.next = &list->tail;
list->head.prev = NULL;
list->tail.item = NULL;
list->tail.prev = &list->head;
list->tail.next = NULL;
return 0;
}
/****************************************************************************
* Function: ListAddHead
*
* Description:
* Adds a node to the head of the list.
* Node gets immediately after list.head.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* void * item - item to be added
* Returns:
* The pointer to the ListNode on success, NULL on failure.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode *
ListAddHead( LinkedList * list,
void *item )
{
assert( list != NULL );
if( list == NULL )
return NULL;
return ListAddAfter( list, item, &list->head );
}
/****************************************************************************
* Function: ListAddTail
*
* Description:
* Adds a node to the tail of the list.
* Node gets added immediately before list.tail.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* void * item - item to be added
* Returns:
* The pointer to the ListNode on success, NULL on failure.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode *
ListAddTail( LinkedList * list,
void *item )
{
assert( list != NULL );
if( list == NULL )
return NULL;
return ListAddBefore( list, item, &list->tail );
}
/****************************************************************************
* Function: ListAddAfter
*
* Description:
* Adds a node after the specified node.
* Node gets added immediately after bnode.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* void * item - item to be added
* ListNode * bnode - node to add after
* Returns:
* The pointer to the ListNode on success, NULL on failure.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode *
ListAddAfter( LinkedList * list,
void *item,
ListNode * bnode )
{
ListNode *newNode = NULL;
assert( list != NULL );
if( ( list == NULL ) || ( bnode == NULL ) )
return NULL;
newNode = CreateListNode( item, list );
if( newNode ) {
ListNode *temp = bnode->next;
bnode->next = newNode;
newNode->prev = bnode;
newNode->next = temp;
temp->prev = newNode;
list->size++;
return newNode;
}
return NULL;
}
/****************************************************************************
* Function: ListAddBefore
*
* Description:
* Adds a node before the specified node.
* Node gets added immediately before anode.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* ListNode * anode - node to add the in front of.
* void * item - item to be added
* Returns:
* The pointer to the ListNode on success, NULL on failure.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode *
ListAddBefore( LinkedList * list,
void *item,
ListNode * anode )
{
ListNode *newNode = NULL;
assert( list != NULL );
if( ( list == NULL ) || ( anode == NULL ) )
return NULL;
newNode = CreateListNode( item, list );
if( newNode ) {
ListNode *temp = anode->prev;
anode->prev = newNode;
newNode->next = anode;
newNode->prev = temp;
temp->next = newNode;
list->size++;
return newNode;
}
return NULL;
}
/****************************************************************************
* Function: ListDelNode
*
* Description:
* Removes a node from the list
* The memory for the node is freed but the
* the memory for the items are not.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* ListNode *dnode - done to delete.
* Returns:
* The pointer to the item stored in node on success, NULL on failure.
* Precondition:
* The list has been initialized.
*****************************************************************************/
void *
ListDelNode( LinkedList * list,
ListNode * dnode,
int freeItem )
{
void *temp;
assert( list != NULL );
assert( dnode != &list->head );
assert( dnode != &list->tail );
if( ( list == NULL ) ||
( dnode == &list->head ) ||
( dnode == &list->tail ) || ( dnode == NULL ) ) {
return NULL;
}
temp = dnode->item;
dnode->prev->next = dnode->next;
dnode->next->prev = dnode->prev;
freeListNode( dnode, list );
list->size--;
if( freeItem && list->free_func ) {
list->free_func( temp );
temp = NULL;
}
return temp;
}
/****************************************************************************
* Function: ListDestroy
*
* Description:
* Removes all memory associated with list nodes.
* Does not free LinkedList *list.
* Items stored in the list are not freed, only nodes are.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* Returns:
* 0 on success. Nonzero on failure.
* Always returns 0.
* Precondition:
* The list has been initialized.
*****************************************************************************/
int
ListDestroy( LinkedList * list,
int freeItem )
{
ListNode *dnode = NULL;
ListNode *temp = NULL;
if( list == NULL )
return EINVAL;
for( dnode = list->head.next; dnode != &list->tail; ) {
temp = dnode->next;
ListDelNode( list, dnode, freeItem );
dnode = temp;
}
list->size = 0;
FreeListDestroy( &list->freeNodeList );
return 0;
}
/****************************************************************************
* Function: ListHead
*
* Description:
* Returns the head of the list.
*
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
*
* Returns:
* The head of the list. NULL if list is empty.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode *
ListHead( LinkedList * list )
{
assert( list != NULL );
if( list == NULL )
return NULL;
if( list->size == 0 )
return NULL;
else
return list->head.next;
}
/****************************************************************************
* Function: ListTail
*
* Description:
* Returns the tail of the list.
*
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
*
* Returns:
* The tail of the list. NULL if list is empty.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode *
ListTail( LinkedList * list )
{
assert( list != NULL );
if( list == NULL )
return NULL;
if( list->size == 0 )
return NULL;
else
return list->tail.prev;
}
/****************************************************************************
* Function: ListNext
*
* Description:
* Returns the next item in the list.
*
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
*
* Returns:
* The next item in the list. NULL if there are no more items in list.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode *
ListNext( LinkedList * list,
ListNode * node )
{
assert( list != NULL );
assert( node != NULL );
if( ( list == NULL ) || ( node == NULL ) )
return NULL;
if( node->next == &list->tail )
return NULL;
else
return node->next;
}
/****************************************************************************
* Function: ListPrev
*
* Description:
* Returns the previous item in the list.
*
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
*
* Returns:
* The previous item in the list. NULL if there are no more items in list.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode *
ListPrev( LinkedList * list,
ListNode * node )
{
assert( list != NULL );
assert( node != NULL );
if( ( list == NULL ) || ( node == NULL ) )
return NULL;
if( node->prev == &list->head )
return NULL;
else
return node->prev;
}
/****************************************************************************
* Function: ListFind
*
* Description:
* Finds the specified item in the list.
* Uses the compare function specified in ListInit. If compare function
* is NULL then compares items as pointers.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* ListNode *start - the node to start from, NULL if to start from
* beginning.
* void * item - the item to search for.
* Returns:
* The node containing the item. NULL if no node contains the item.
* Precondition:
* The list has been initialized.
*****************************************************************************/
ListNode *
ListFind( LinkedList * list,
ListNode * start,
void *item )
{
ListNode *finger = NULL;
if( list == NULL )
return NULL;
if( start == NULL )
start = &list->head;
assert( start );
finger = start->next;
assert( finger );
while( finger != &list->tail ) {
if( list->cmp_func ) {
if( list->cmp_func( item, finger->item ) )
return finger;
} else {
if( item == finger->item )
return finger;
}
finger = finger->next;
}
return NULL;
}
/****************************************************************************
* Function: ListSize
*
* Description:
* Returns the size of the list.
* Parameters:
* LinkedList *list - must be valid, non null, pointer to a linked list.
* Returns:
* The number of items in the list.
* Precondition:
* The list has been initialized.
*****************************************************************************/
int
ListSize( LinkedList * list )
{
assert( list != NULL );
if( list == NULL )
return EINVAL;
return list->size;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,519 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 "TimerThread.h"
#include <assert.h>
/****************************************************************************
* Function: FreeTimerEvent
*
* Description:
* Deallocates a dynamically allocated TimerEvent.
* Parameters:
* TimerEvent *event - must be allocated with CreateTimerEvent
*****************************************************************************/
static void
FreeTimerEvent( TimerThread * timer,
TimerEvent * event )
{
assert( timer != NULL );
FreeListFree( &timer->freeEvents, event );
}
/****************************************************************************
* Function: TimerThreadWorker
*
* Description:
* Implements timer thread.
* Waits for next event to occur and schedules
* associated job into threadpool.
* Internal Only.
* Parameters:
* void * arg -> is cast to TimerThread *
*****************************************************************************/
static void *
TimerThreadWorker( void *arg )
{
TimerThread *timer = ( TimerThread * ) arg;
ListNode *head = NULL;
TimerEvent *nextEvent = NULL;
time_t currentTime = 0;
time_t nextEventTime = 0;
struct timespec timeToWait;
int tempId;
assert( timer != NULL );
ithread_mutex_lock( &timer->mutex );
while( 1 )
{
//mutex should always be locked at top of loop
//Check for shutdown
if( timer->shutdown )
{
timer->shutdown = 0;
ithread_cond_signal( &timer->condition );
ithread_mutex_unlock( &timer->mutex );
return NULL;
}
nextEvent = NULL;
//Get the next event if possible
if( timer->eventQ.size > 0 )
{
head = ListHead( &timer->eventQ );
nextEvent = ( TimerEvent * ) head->item;
nextEventTime = nextEvent->eventTime;
}
currentTime = time( NULL );
//If time has elapsed, schedule job
if( ( nextEvent != NULL ) && ( currentTime >= nextEventTime ) )
{
if( nextEvent->persistent ) {
ThreadPoolAddPersistent( timer->tp, &nextEvent->job,
&tempId );
} else {
ThreadPoolAdd( timer->tp, &nextEvent->job, &tempId );
}
ListDelNode( &timer->eventQ, head, 0 );
FreeTimerEvent( timer, nextEvent );
continue;
}
if( nextEvent != NULL ) {
timeToWait.tv_nsec = 0;
timeToWait.tv_sec = nextEvent->eventTime;
ithread_cond_timedwait( &timer->condition, &timer->mutex,
&timeToWait );
} else {
ithread_cond_wait( &timer->condition, &timer->mutex );
}
}
}
/****************************************************************************
* Function: CalculateEventTime
*
* Description:
* Calculates the appropriate timeout in absolute seconds since
* Jan 1, 1970
* Internal Only.
* Parameters:
* time_t *timeout - timeout
*
*****************************************************************************/
static int
CalculateEventTime( time_t * timeout,
TimeoutType type )
{
time_t now;
assert( timeout != NULL );
if( type == ABS_SEC )
return 0;
else if( type == REL_SEC ) {
time( &now );
( *timeout ) += now;
return 0;
}
return -1;
}
/****************************************************************************
* Function: CreateTimerEvent
*
* Description:
* Creates a Timer Event. (Dynamically allocated)
* Internal to timer thread.
* Parameters:
* func - thread function to run.
* arg - argument to function.
* priority - priority of job.
* eventTime - the absoule time of the event
* in seconds from Jan, 1970
* id - id of job
*
* Returns:
* TimerEvent * on success, NULL on failure.
****************************************************************************/
static TimerEvent *
CreateTimerEvent( TimerThread * timer,
ThreadPoolJob * job,
Duration persistent,
time_t eventTime,
int id )
{
TimerEvent *temp = NULL;
assert( timer != NULL );
assert( job != NULL );
temp = ( TimerEvent * ) FreeListAlloc( &timer->freeEvents );
if( temp == NULL )
return temp;
temp->job = ( *job );
temp->persistent = persistent;
temp->eventTime = eventTime;
temp->id = id;
return temp;
}
/************************************************************************
* Function: TimerThreadInit
*
* Description:
* Initializes and starts timer thread.
*
* Parameters:
* timer - valid timer thread pointer.
* tp - valid thread pool to use. Must be
* started. Must be valid for lifetime
* of timer. Timer must be shutdown
* BEFORE thread pool.
* Return:
* 0 on success, nonzero on failure
* Returns error from ThreadPoolAddPersistent if failure.
************************************************************************/
int
TimerThreadInit( TimerThread * timer,
ThreadPool * tp )
{
int rc = 0;
ThreadPoolJob timerThreadWorker;
assert( timer != NULL );
assert( tp != NULL );
if( ( timer == NULL ) || ( tp == NULL ) ) {
return EINVAL;
}
rc += ithread_mutex_init( &timer->mutex, NULL );
assert( rc == 0 );
rc += ithread_mutex_lock( &timer->mutex );
assert( rc == 0 );
rc += ithread_cond_init( &timer->condition, NULL );
assert( rc == 0 );
rc += FreeListInit( &timer->freeEvents, sizeof( TimerEvent ), 100 );
assert( rc == 0 );
timer->shutdown = 0;
timer->tp = tp;
timer->lastEventId = 0;
rc += ListInit( &timer->eventQ, NULL, NULL );
assert( rc == 0 );
if( rc != 0 ) {
rc = EAGAIN;
} else {
TPJobInit( &timerThreadWorker, TimerThreadWorker, timer );
TPJobSetPriority( &timerThreadWorker, HIGH_PRIORITY );
rc = ThreadPoolAddPersistent( tp, &timerThreadWorker, NULL );
}
ithread_mutex_unlock( &timer->mutex );
if( rc != 0 ) {
ithread_cond_destroy( &timer->condition );
ithread_mutex_destroy( &timer->mutex );
FreeListDestroy( &timer->freeEvents );
ListDestroy( &timer->eventQ, 0 );
}
return rc;
}
/************************************************************************
* Function: TimerThreadSchedule
*
* Description:
* Schedules an event to run at a specified time.
*
* Parameters:
* timer - valid timer thread pointer.
* time_t - time of event.
* either in absolute seconds,
* or relative seconds in the future.
* timeoutType - either ABS_SEC, or REL_SEC.
* if REL_SEC, then the event
* will be scheduled at the
* current time + REL_SEC.
*
* func - function to schedule
* arg - argument to function
* priority - priority of job.
* id - id of timer event. (out)
* Return:
* 0 on success, nonzero on failure
* EOUTOFMEM if not enough memory to schedule job
************************************************************************/
int
TimerThreadSchedule( TimerThread * timer,
time_t timeout,
TimeoutType type,
ThreadPoolJob * job,
Duration duration,
int *id )
{
int rc = EOUTOFMEM;
int found = 0;
int tempId = 0;
ListNode *tempNode = NULL;
TimerEvent *temp = NULL;
TimerEvent *newEvent = NULL;
assert( timer != NULL );
assert( job != NULL );
if( ( timer == NULL ) || ( job == NULL ) ) {
return EINVAL;
}
CalculateEventTime( &timeout, type );
ithread_mutex_lock( &timer->mutex );
if( id == NULL )
id = &tempId;
( *id ) = INVALID_EVENT_ID;
newEvent = CreateTimerEvent( timer, job, duration, timeout,
timer->lastEventId );
if( newEvent == NULL ) {
ithread_mutex_unlock( &timer->mutex );
return rc;
}
tempNode = ListHead( &timer->eventQ );
//add job to Q
//Q is ordered by eventTime
//with the head of the Q being the next event
while( tempNode != NULL ) {
temp = ( TimerEvent * ) tempNode->item;
if( temp->eventTime >= timeout )
{
if( ListAddBefore( &timer->eventQ, newEvent, tempNode ) !=
NULL )
rc = 0;
found = 1;
break;
}
tempNode = ListNext( &timer->eventQ, tempNode );
}
//add to the end of Q
if( !found ) {
if( ListAddTail( &timer->eventQ, newEvent ) != NULL )
rc = 0;
}
//signal change in Q
if( rc == 0 ) {
ithread_cond_signal( &timer->condition );
} else {
FreeTimerEvent( timer, newEvent );
}
( *id ) = timer->lastEventId++;
ithread_mutex_unlock( &timer->mutex );
return rc;
}
/************************************************************************
* Function: TimerThreadRemove
*
* Description:
* Removes an event from the timer Q.
* Events can only be removed
* before they have been placed in the
* thread pool.
*
* Parameters:
* timer - valid timer thread pointer.
* id - id of event to remove.
* out - space for returned job (Can be NULL)
* Return:
* 0 on success.
* INVALID_EVENT_ID on error.
*
************************************************************************/
int
TimerThreadRemove( TimerThread * timer,
int id,
ThreadPoolJob * out )
{
int rc = INVALID_EVENT_ID;
ListNode *tempNode = NULL;
TimerEvent *temp = NULL;
assert( timer != NULL );
if( timer == NULL ) {
return EINVAL;
}
ithread_mutex_lock( &timer->mutex );
tempNode = ListHead( &timer->eventQ );
while( tempNode != NULL ) {
temp = ( TimerEvent * ) tempNode->item;
if( temp->id == id )
{
ListDelNode( &timer->eventQ, tempNode, 0 );
if( out != NULL )
( *out ) = temp->job;
FreeTimerEvent( timer, temp );
rc = 0;
break;
}
tempNode = ListNext( &timer->eventQ, tempNode );
}
ithread_mutex_unlock( &timer->mutex );
return rc;
}
/************************************************************************
* Function: TimerThreadShutdown
*
* Description:
* Shutdown the timer thread
* Events scheduled in the future will NOT be run.
* Timer thread should be shutdown BEFORE it's associated
* thread pool.
* Returns:
* returns 0 if succesfull,
* nonzero otherwise.
* Always returns 0.
***********************************************************************/
int
TimerThreadShutdown( TimerThread * timer )
{
ListNode *tempNode2 = NULL;
ListNode *tempNode = NULL;
assert( timer != NULL );
if( timer == NULL ) {
return EINVAL;
}
ithread_mutex_lock( &timer->mutex );
timer->shutdown = 1;
tempNode = ListHead( &timer->eventQ );
//Delete nodes in Q
//call registered free function
//on argument
while( tempNode != NULL ) {
TimerEvent *temp = ( TimerEvent * ) tempNode->item;
tempNode2 = ListNext( &timer->eventQ, tempNode );
ListDelNode( &timer->eventQ, tempNode, 0 );
if( temp->job.free_func ) {
temp->job.free_func( temp->job.arg );
}
FreeTimerEvent( timer, temp );
tempNode = tempNode2;
}
ListDestroy( &timer->eventQ, 0 );
FreeListDestroy( &timer->freeEvents );
ithread_cond_broadcast( &timer->condition );
while( timer->shutdown ) //wait for timer thread to shutdown
{
ithread_cond_wait( &timer->condition, &timer->mutex );
}
ithread_mutex_unlock( &timer->mutex );
//destroy condition
while( ithread_cond_destroy( &timer->condition ) != 0 ) {
}
//destroy mutex
while( ithread_mutex_destroy( &timer->mutex ) != 0 ) {
}
return 0;
}

View File

@ -0,0 +1,142 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 <stdarg.h>
#include <assert.h>
#include <malloc.h>
#include <stdio.h>
#include "iasnprintf.h"
#ifndef NULL
#define NULL 0
#endif
/**
* Allocates enough memory for the
* Formatted string, up to max
* specified.
* With max set to -1, it allocates as
* much size as needed.
* Memory must be freed using free.
*/
int
iasnprintf( char **ret,
int incr,
int max,
const char *fmt,
... )
{
int size = incr;
int retc = 0;
va_list ap;
char *temp = NULL;
assert( ret );
assert( fmt );
( *ret ) = ( char * )malloc( incr );
while( 1 ) {
va_start( ap, fmt );
retc = vsnprintf( ( *ret ), size, fmt, ap );
va_end( ap );
if( retc < 0 ) {
//size not big enough
//and vsnprintf does NOT return the
//necessary number of bytes
if( ( max != -1 ) && ( size == max ) ) //max reached
{
break;
}
incr *= 2; //increase increment
//increase size and try again
if( ( max != -1 ) && ( ( size + incr ) > max ) ) {
incr = ( max - size );
}
temp = ( char * )realloc( ( *ret ), size + incr );
if( temp == NULL ) {
break;
}
size += incr;
( *ret ) = temp;
} else {
if( ( retc + 1 ) > size ) {
//size not big enough
//and vsnprintf
//returns the necessary
//number of bytes
if( ( max != -1 ) && ( retc + 1 > max ) ) {
retc = -1;
break;
}
temp = ( char * )realloc( ( *ret ), retc + 1 );
if( temp == NULL ) {
retc = -1;
break;
}
size = retc + 1;
( *ret ) = temp; //size increased try again
} else if( ( retc + 1 ) < size ) {
//size is bigger than needed
//try and reallocate smaller
temp = ( char * )realloc( ( *ret ), retc + 1 );
if( temp != NULL ) {
( *ret ) = temp;
}
break;
} else //size is just right, exit
{
break;
}
}
}
if( retc < 0 ) {
free( ( *ret ) );
( *ret ) = NULL;
}
return retc;
}
void
iasnprintfFree( char *fChar )
{
free( fChar );
fChar = NULL;
}

27
libupnp/upnp/LICENSE Normal file
View File

@ -0,0 +1,27 @@
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.

161
libupnp/upnp/Makefile.am Normal file
View File

@ -0,0 +1,161 @@
# $Id: Makefile.am,v 1.10 2006/04/08 15:22:22 r3mi Exp $
#
# "Makefile.am" for "libupnp/upnp"
#
# Copyright (C) 2005 Rémi Turboult <r3mi@users.sourceforge.net>
#
SUBDIRS = doc
AM_CPPFLAGS = -I$(srcdir)/inc \
-I$(top_srcdir)/threadutil/inc \
-I$(top_srcdir)/ixml/inc
AM_CFLAGS = $(PTHREAD_CFLAGS)
AM_LDFLAGS = $(PTHREAD_LIBS)
LDADD = libupnp.la \
$(top_builddir)/threadutil/libthreadutil.la \
$(top_builddir)/ixml/libixml.la
upnpincludedir = $(includedir)/upnp
upnpinclude_HEADERS = inc/upnp.h
nodist_upnpinclude_HEADERS = inc/upnpconfig.h
if ENABLE_TOOLS
upnpinclude_HEADERS += inc/upnptools.h
endif
if ENABLE_DEBUG
upnpinclude_HEADERS += inc/upnpdebug.h
endif
lib_LTLIBRARIES = libupnp.la
libupnp_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/src/inc
libupnp_la_LDFLAGS = -version-info $(LT_VERSION_UPNP) \
-export-symbols-regex '^Upnp.*' \
$(top_builddir)/threadutil/libthreadutil.la \
$(top_builddir)/ixml/libixml.la
libupnp_la_SOURCES = \
src/inc/config.h \
src/inc/client_table.h src/inc/global.h \
src/inc/md5.h src/inc/ssdplib.h \
src/inc/unixutil.h src/inc/urlconfig.h \
src/inc/gmtdate.h src/inc/membuffer.h \
src/inc/server.h src/inc/statcodes.h \
src/inc/upnpapi.h src/inc/utilall.h \
src/inc/gena_ctrlpt.h src/inc/http_client.h \
src/inc/miniserver.h src/inc/service_table.h \
src/inc/statuscodes.h src/inc/upnpclosesocket.h \
src/inc/util.h src/inc/gena_device.h \
src/inc/httpparser.h src/inc/netall.h \
src/inc/soaplib.h src/inc/strintmap.h \
src/inc/upnp_timeout.h src/inc/uuid.h \
src/inc/gena.h src/inc/httpreadwrite.h \
src/inc/parsetools.h src/inc/sock.h \
src/inc/sysdep.h src/inc/uri.h \
src/inc/webserver.h
# ssdp
libupnp_la_SOURCES += src/ssdp/ssdp_device.c src/ssdp/ssdp_ctrlpt.c \
src/ssdp/ssdp_server.c
# soap
libupnp_la_SOURCES += src/soap/soap_device.c src/soap/soap_ctrlpt.c \
src/soap/soap_common.c
# genlib
libupnp_la_SOURCES += \
src/genlib/miniserver/miniserver.c \
src/genlib/service_table/service_table.c \
src/genlib/util/membuffer.c \
src/genlib/util/strintmap.c \
src/genlib/util/upnp_timeout.c \
src/genlib/util/util.c \
src/genlib/client_table/client_table.c \
src/genlib/net/sock.c \
src/genlib/net/http/httpparser.c \
src/genlib/net/http/httpreadwrite.c \
src/genlib/net/http/statcodes.c \
src/genlib/net/http/webserver.c \
src/genlib/net/http/parsetools.c \
src/genlib/net/uri/uri.c
# gena
libupnp_la_SOURCES += src/gena/gena_device.c src/gena/gena_ctrlpt.c \
src/gena/gena_callback2.c
# api
libupnp_la_SOURCES += src/api/upnpapi.c
if ENABLE_TOOLS
libupnp_la_SOURCES += src/api/upnptools.c
endif
if ENABLE_DEBUG
libupnp_la_SOURCES += src/api/upnpdebug.c
endif
# uuid
libupnp_la_SOURCES += src/uuid/md5.c src/uuid/sysdep.c src/uuid/uuid.c
# urlconfig
libupnp_la_SOURCES += src/urlconfig/urlconfig.c
# samples
noinst_PROGRAMS =
if ENABLE_SAMPLES
if ENABLE_CLIENT
noinst_PROGRAMS += upnp_tv_ctrlpt
upnp_tv_ctrlpt_CPPFLAGS = $(AM_CPPFLAGS) \
-I$(srcdir)/sample/common/ \
-I$(srcdir)/sample/tvctrlpt
endif
if ENABLE_DEVICE
noinst_PROGRAMS += upnp_tv_device
upnp_tv_device_CPPFLAGS = $(AM_CPPFLAGS) \
-I$(srcdir)/sample/common/ \
-I$(srcdir)/sample/tvdevice
endif
endif
upnp_tv_device_SOURCES = \
sample/common/sample_util.c \
sample/common/sample_util.h \
sample/tvdevice/upnp_tv_device.c \
sample/tvdevice/upnp_tv_device.h \
sample/tvdevice/linux/upnp_tv_device_main.c
upnp_tv_ctrlpt_SOURCES = \
sample/common/sample_util.c \
sample/common/sample_util.h \
sample/tvctrlpt/upnp_tv_ctrlpt.c \
sample/tvctrlpt/upnp_tv_ctrlpt.h \
sample/tvctrlpt/linux/upnp_tv_ctrlpt_main.c
if WITH_DOCDIR
docdir = @DOCDIR@
examplesdir = $(docdir)/examples
examples_DATA = $(upnp_tv_ctrlpt_SOURCES) $(upnp_tv_device_SOURCES)
endif
# check / distcheck tests
check_PROGRAMS = test_init
TESTS = test_init
test_init_SOURCES = test/test_init.c
EXTRA_DIST = LICENSE \
sample/tvdevice/web/tvcontrolSCPD.xml \
sample/tvdevice/web/tvdevicedesc.xml \
sample/tvdevice/web/tvdevicepres.html \
sample/tvdevice/web/tvpictureSCPD.xml
CLEANFILES = IUpnpErrFile.txt IUpnpInfoFile.txt

View File

@ -0,0 +1,65 @@
# $Id: Makefile.am,v 1.2 2006/03/28 21:07:01 r3mi Exp $
#
# "Makefile.am" for "libunp/upnp/doc"
#
# (C) Copyright 2005 Rémi Turboult <r3mi@users.sourceforge.net>
#
##########################################################################
#
# 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.
#
##########################################################################
EXTRA_DIST = UPnP_Programming_Guide.pdf \
callback.dxx docxx.sty intro.dxx \
license.dxx upnpsdk.dxx
if WITH_DOCDIR
docdir = @DOCDIR@
doc_DATA = UPnP_Programming_Guide.pdf
endif
html-local:
@if [ -d html ]; then rm -rf html; fi
@doc++ -nd -S -w -j -d html $(srcdir)/upnpsdk.dxx
pdf-local:
@doc++ -nd -S -w -j -t --package a4wide -o upnpsdk.tex \
$(srcdir)/upnpsdk.dxx
@-pdflatex "\scrollmode\input upnpsdk.tex" > latex.log
@-pdflatex "\scrollmode\input upnpsdk.tex" >> latex.log
@-pdflatex "\scrollmode\input upnpsdk.tex" >> latex.log
clean-local:
-rm -rf html
-rm -f upnpsdk.tex upnpsdk.dvi upnpsdk.ps upnpsdk.log upnpsdk.aux
-rm -f latex.log

Binary file not shown.

View File

@ -0,0 +1,13 @@
/**@name About Callbacks
*
* The Linux SDK for UPnP Devices contains functions that generate
* asynchronous callbacks. To simplify the application callback functions,
* these callbacks are executed on a thread owned by the SDK itself. The
* SDK executes the application's callback function in a thread
* context so the application can allocate memory and preserve the information
* it needs. The application can also use standard thread synchronization
* methods to ensure data integrity. Due to the possibility of deadlock, the
* application cannot call back into the SDK during these callbacks
* unless explicitly noted. There is no restriction in calling into the
* operating system or any other application interfaces.
*/

1082
libupnp/upnp/doc/docxx.sty Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,17 @@
/**@name Introduction
* This document gives a brief description of the Linux SDK for UPnP
* Devices API. Section 1 covers the license under which the SDK is
* distributed. Section 2 talks about the callback functions used
* in many parts of the API. Finally, section 3 details the structures and
* functions that comprise the API.
*
* The Linux SDK for UPnP Devices version 1.2 supports the following
* platforms:
* \begin{itemize}
* \item Linux* running on an Intel Architecture processor
* \item Linux running on an Intel StrongARM or XScale processor
* \end{itemize}
*
* {\bf *} Other brands and names are the property of their respective
* owners.
*/

View File

@ -0,0 +1,32 @@
/**@name License
*
* \begin{center}
* Copyright (c) 2000-2003 Intel Corporation
* All rights reserved.
* \end{center}
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* \begin{itemize}
* \item Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* \item 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.
* \item 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.
* \end{itemize}
* 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.
*
*/

View File

@ -0,0 +1,20 @@
/**@name Linux SDK for UPnP Devices v1.2
*
*\begin{center}
* {\bf Linux SDK for UPnP Devices Version 1.2}
*
* Copyright (C) 2000-2003 Intel Corporation ALL RIGHTS RESERVED
*
* Revision 1.2.1 (\Date)
*\end{center}
*/
//@{
//@Include: intro.dxx
//@Include: license.dxx
//@Include: callback.dxx
//@Include: ../inc/upnp.h
//@Include: ../inc/upnptools.h
//@Include: ../inc/config.h
//@}

2761
libupnp/upnp/inc/upnp.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,96 @@
// -*- C -*-
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2006 Rémi Turboult <r3mi@users.sourceforge.net>
// 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.
//
///////////////////////////////////////////////////////////////////////////
#ifndef UPNP_CONFIG_H
#define UPNP_CONFIG_H
/***************************************************************************
* Library version
***************************************************************************/
/** The library version (string) e.g. "1.3.0" */
#undef UPNP_VERSION_STRING
/** Major version of the library */
#undef UPNP_VERSION_MAJOR
/** Minor version of the library */
#undef UPNP_VERSION_MINOR
/** Patch version of the library */
#undef UPNP_VERSION_PATCH
/** The library version (numeric) e.g. 10300 means version 1.3.0 */
#define UPNP_VERSION \
((UPNP_VERSION_MAJOR*100 + UPNP_VERSION_MINOR)*100 + UPNP_VERSION_PATCH)
/***************************************************************************
* Library optional features
***************************************************************************/
/*
* The following defines can be tested in order to know which
* optional features have been included in the installed library.
*/
/** Defined to 1 if the library has been compiled with DEBUG enabled
* (i.e. configure --enable-debug) : <upnp/upnpdebug.h> file is available */
#undef UPNP_HAVE_DEBUG
/** Defined to 1 if the library has been compiled with client API enabled
* (i.e. configure --enable-client) */
#undef UPNP_HAVE_CLIENT
/** Defined to 1 if the library has been compiled with device API enabled
* (i.e. configure --enable-device) */
#undef UPNP_HAVE_DEVICE
/** Defined to 1 if the library has been compiled with integrated web server
* (i.e. configure --enable-webserver --enable-device) */
#undef UPNP_HAVE_WEBSERVER
/** Defined to 1 if the library has been compiled with helper API
* (i.e. configure --enable-tools) : <upnp/upnptools.h> file is available */
#undef UPNP_HAVE_TOOLS
#endif // UPNP_CONFIG_H

View File

@ -0,0 +1,258 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2003 Intel Corporation
// Copyright (c) 2006 Rémi Turboult <r3mi@users.sourceforge.net>
// 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.
//
///////////////////////////////////////////////////////////////////////////
#ifndef UPNP_DEBUG_H
#define UPNP_DEBUG_H
#include "upnpconfig.h"
// Function declarations only if debug compiled into the library
#if UPNP_HAVE_DEBUG
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @name Other debugging features
The UPnP SDK contains other features to aid in debugging.
*/
//@{
/** @name Upnp_LogLevel
* The user has the option to select 4 different types of debugging levels,
* see {\tt UpnpSetLogLevel}.
* The critical level will show only those messages
* which can halt the normal processing of the library, like memory
* allocation errors. The remaining three levels are just for debugging
* purposes. Packet level will display all the incoming and outgoing
* packets that are flowing between the control point and the device.
* Info Level displays the other important operational information
* regarding the working of the library. If the user selects All,
* then the library displays all the debugging information that it has.
* \begin{itemize}
* \item {\tt UPNP_CRITICAL [0]}
* \item {\tt UPNP_PACKET [1]}
* \item {\tt UPNP_INFO [2]}
* \item {\tt UPNP_ALL [3]}
* \end{itemize}
*/
typedef enum Upnp_Module {SSDP,SOAP,GENA,TPOOL,MSERV,DOM,API, HTTP} Dbg_Module;
//@{
typedef enum Upnp_LogLevel_e {
UPNP_CRITICAL,
UPNP_PACKET,
UPNP_INFO,
UPNP_ALL
} Upnp_LogLevel;
//@}
// for backward compatibility
#define Dbg_Level Upnp_LogLevel
/**
* Default log level : see {\tt Upnp_LogLevel}
*/
#define UPNP_DEFAULT_LOG_LEVEL UPNP_ALL
/***************************************************************************
* Function : UpnpInitLog
*
* Parameters: void
*
* Description:
* This functions initializes the log files
* Returns: int
* -1 : If fails
* UPNP_E_SUCCESS : if success
***************************************************************************/
int UpnpInitLog();
// for backward compatibility
#define InitLog UpnpInitLog
/***************************************************************************
* Function : UpnpSetLogLevel
*
* Parameters: void
*
* Description:
* This functions set the log level (see {\tt Upnp_LogLevel}
* Returns: void
***************************************************************************/
void UpnpSetLogLevel (Upnp_LogLevel);
/***************************************************************************
* Function : UpnpCloseLog
*
* Parameters: void
*
* Description:
* This functions closes the log files
* Returns: void
***************************************************************************/
void UpnpCloseLog();
// for backward compatibility
#define CloseLog UpnpCloseLog
/***************************************************************************
* Function : UpnpSetLogFileNames
*
* Parameters:
* IN const char* ErrFileName: name of the error file
* IN const char *InfoFileName: name of the information file
* IN int size: Size of the buffer
* IN int starLength: This parameter provides the width of the banner
*
* Description:
* This functions takes the buffer and writes the buffer in the file as
* per the requested banner
* Returns: void
***************************************************************************/
void UpnpSetLogFileNames (const char* ErrFileName, const char* InfoFileName);
// for backward compatibility
#define SetLogFileNames UpnpSetLogFileNames
/***************************************************************************
* Function : UpnpGetDebugFile
*
* Parameters:
* IN Dbg_Level DLevel: The level of the debug logging. It will decide
* whether debug statement will go to standard output,
* or any of the log files.
* IN Dbg_Module Module: debug will go in the name of this module
*
* Description:
* This function checks if the module is turned on for debug
* and returns the file descriptor corresponding to the debug level
* Returns: FILE *
* NULL : if the module is turn off for debug
* else returns the right file descriptor
***************************************************************************/
FILE* UpnpGetDebugFile (Upnp_LogLevel level, Dbg_Module module);
// for backward compatibility
#define GetDebugFile UpnpGetDebugFile
/***************************************************************************
* Function : UpnpPrintf
*
* Parameters:
* IN Dbg_Level DLevel: The level of the debug logging. It will decide
* whether debug statement will go to standard output,
* or any of the log files.
* IN Dbg_Module Module: debug will go in the name of this module
* IN char *DbgFileName: Name of the file from where debug statement is
* coming
* IN int DbgLineNo : Line number of the file from where debug statement
* is coming
* IN char * FmtStr, ...: Variable number of arguments that will go
* in the debug statement
*
* Description:
* This functions prints the debug statement either on the startdard
* output or log file along with the information from where this
* debug statement is coming
* Returns: void
***************************************************************************/
void UpnpPrintf (Upnp_LogLevel DLevel, Dbg_Module Module,
const char* DbgFileName, int DbgLineNo,
const char* FmtStr,
...)
#if (__GNUC__ >= 3)
__attribute__((format (__printf__, 5, 6)))
#endif
;
/***************************************************************************
* Function : UpnpDisplayBanner
*
* Parameters:
* IN FILE *fd: file descriptor where the banner will be written
* IN char **lines: The buffer that will be written
* IN int size: Size of the buffer
* IN int starLength: This parameter provides the width of the banner
*
* Description:
* This functions takes the buffer and writes the buffer in the file as
* per the requested banner
* Returns: void
***************************************************************************/
void UpnpDisplayBanner (FILE *fd,
const char** lines, size_t size, int starlength);
/***************************************************************************
* Function : UpnpDisplayFileAndLine
*
* Parameters:
* IN FILE *fd: File descriptor where line number and file name will be
* written
* IN char *DbgFileName: Name of the file
* IN int DbgLineNo : Line number of the file
*
* Description:
* This function writes the file name and file number from where
* debug statement is coming to the log file
* Returns: void
***************************************************************************/
void UpnpDisplayFileAndLine (FILE *fd, const char *DbgFileName, int DbgLineNo);
//@}
#ifdef __cplusplus
}
#endif
#endif // UPNP_HAVE_DEBUG
#endif // UPNP_DEBUG_H

Some files were not shown because too many files have changed in this diff Show More