Compare commits

..

8 Commits

Author SHA1 Message Date
Marcelo Roberto Jimenez
ba837a528f Creation of the tag for release-1.6.5.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/tags/release-1.6.5@313 119443c7-1b9e-41f8-b6fc-b9c35fce742c
2008-02-03 01:39:33 +00:00
Marcelo Roberto Jimenez
078f3f8faf Merge of trunk into branch 1.6.x.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@312 119443c7-1b9e-41f8-b6fc-b9c35fce742c
2008-02-03 01:36:23 +00:00
Marcelo Roberto Jimenez
1eeaf99b83 Merge of trunk into branch-1.6.x.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@306 119443c7-1b9e-41f8-b6fc-b9c35fce742c
2008-01-27 02:13:08 +00:00
Marcelo Roberto Jimenez
f6dd5062fe Merge of trunk into branch-1.6.x.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@284 119443c7-1b9e-41f8-b6fc-b9c35fce742c
2007-12-27 02:14:02 +00:00
Marcelo Roberto Jimenez
7d4a610b93 Merge of head into branch-1.6.x.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@265 119443c7-1b9e-41f8-b6fc-b9c35fce742c
2007-12-10 23:18:38 +00:00
Marcelo Roberto Jimenez
0a074d1989 Merge of trunk into branch 1.6.x.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@263 119443c7-1b9e-41f8-b6fc-b9c35fce742c
2007-12-10 22:56:56 +00:00
Marcelo Roberto Jimenez
0475a46680 Merge of current trunk to branch 1.6.x.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@251 119443c7-1b9e-41f8-b6fc-b9c35fce742c
2007-11-19 14:15:45 +00:00
Marcelo Roberto Jimenez
2a76749682 Creating branch 1.6.x.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@210 119443c7-1b9e-41f8-b6fc-b9c35fce742c
2007-06-23 14:23:29 +00:00
29 changed files with 3275 additions and 3373 deletions

103
ChangeLog
View File

@@ -1,3 +1,100 @@
*******************************************************************************
Version 1.6.5
*******************************************************************************
2008-02-02 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Peter Hartley's fix for wrong sized variable beeing passed to
http_MakeMessage() on 64 bit architectures.
*******************************************************************************
Version 1.6.4
*******************************************************************************
2008-01-23 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Workaround for a problem with the new automake AM_CONDITIONAL macro
from autotools-1.10. Thanks to Ingo Hofmann for helping with debugging
this one.
2008-01-22 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Added quoting to macros AC_CONFIG_AUX_DIR, AC_CONFIG_MACRO_DIR and
AC_CONFIG_SRCDIR in configure.ac. Also changed the name of the
auxiliary directory in AC_CONFIG_AUX_DIR to build-aux.
2008-01-22 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Fix for setsockopt() in Threadpool.c to allow more than one process
to join the multicast-group on OSX. Thanks to Ingo Hofmann.
2008-01-22 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Using defined(__OSX__) || defined(__APPLE__) instead of just
defined(__OSX__) in the code. Thanks to Ingo Hofmann and Chris
Pickel.
2008-01-21 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Fix for isFileInVirtualDir. Thanks to Peter Hartley for the patch.
2008-01-07 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Putting back a "defined(__OSX__)" that has been removed in the
previous *BSD patch. Thanks to Chris Pickel for pointing it out.
2008-01-07 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* SF Patches Tracker [ 1865812 ] typo in docs comment
Submitted By: Hartmut Holzgraefe - hholzgra
typo in docs comment ACCAPTED instead of ACCEPTED in
@name UPNP_E_UNSUBSCRIBE_UNACCAPTED [-302]
Also, the documentation file name was mispelled and was corrected in
the Makefile.am.
*******************************************************************************
Version 1.6.3
*******************************************************************************
2007-12-25 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Using pthread flags for the whole project, not just at the places
individually indicated by several Makefile.am files spread all over
the directories. That was too much error prone.
2007-12-24 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Added a configure test to check if pthread_rwlock_t is available.
Define _GNU_SOURCE if needed. The fallback behaviou will only be
implemented if _GNU_SOURCE prooves to be insufficient on some
platforms. Thanks to Jonathan Casiot (no_dice) and Robert Gingher
(robsbox).
2007-12-17 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Removed unused iasnprintf.{c,h} files.
2007-12-17 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Removed STATSONLY() macro from ThreadPool.{c,h}.
* Removed time() usage from ThreadPool.c.
* Fixed STATS = 0 compilation.
2007-12-16 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Library was not compiling on FreeBSD 7. Code now no longer uses
ftime(), using gettimeofday() instead. Thanks to Josh Carroll.
*******************************************************************************
Version 1.6.2
*******************************************************************************
2007-12-10 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Fixed a compilation error due to a missing #ifdef in
upnp/src/genlib/miniserver/miniserver.c. Thanks to Eugene Christensen.
2007-11-12 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* "make check" was failing because ixml/test/test_document.sh did not
have the executable flag set. Thanks to Steve Bresson.
2007-11-12 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Fixed a memory leak in upnpapi.c to delete gMiniServerThreadPool in
the call to UpnpFinish(). Thanks to Fabrice Fontaine.
2007-11-09 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Added a isleep() call to the error handler of select() in
RunMiniServer(), so that it does not take 100% cpu in case select()
fails repeatedly.
*******************************************************************************
Version 1.6.1
*******************************************************************************
@@ -116,6 +213,10 @@ Version 1.6.0
an interface change in the library and the minor library version was
bumped. Also, the libtool library numbers were changed accordingly.
*******************************************************************************
Version 1.4.7
*******************************************************************************
2007-05-26 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Added support for the Basic Device
(http://www.upnp.org/standardizeddcps/basic.asp) as suggested by
@@ -333,7 +434,7 @@ Version 1.4.2
2007-01-23 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* SF Tracker [ 1634922 ] Support for large files (>= 2 GiB), part 2
Submitted By: Jonathan - no_dice
Submitted By: Jonathan Casiot - no_dice
Summary: This patch hopefully fixes the remaining types and related
code to enable files >= 2 GiB to be streamed. Jonathan claims to have
tested this with a patched version of ushare-0.9.8 and a D-Link DSM-520.

15
THANKS
View File

@@ -10,30 +10,39 @@ exempt of errors.
- Arno Willig
- Bob Ciora
- Chaos
- Chris Pickel
- Craig Nelson
- David Maass
- Emil Ljungdahl
- Erik Johansson
- Eric Tanguy
- Erwan Velu
- Eugene Christensen
- Fabrice Fontaine
- Fredrik Svensson
- Glen Masgai
- Hartmut Holzgraefe - hholzgra
- Ingo Hofmann
- Jiri Zouhar
- John Dennis
- Jonathan (no_dice)
- Jonathan Casiot (no_dice)
- Josh Carroll
- Keith Brindley
- Leuk_He
- Loigu
- Luke Kim
- Marcelo Roberto Jimenez (mroberto)
- Markus Strobl
- Nektarios K. Papadopoulos
- Nektarios K. Papadopoulos (npapadop)
- Oskar Liljeblad
- Michael (Oxy)
- Michael (oxygenic)
- Paul Vixie
- Peter Hartley
- Rene Hexel
- Robert Gingher (robsbox)
- Siva Chandran
- Stéphane Corthésy
- Steve Bresson
- Timothy Redaelli
- Titus Winters

View File

@@ -9,97 +9,144 @@
AC_PREREQ(2.60)
AC_INIT([libupnp], [1.6.1], [mroberto@users.sourceforge.net])
###############################################################################
# *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*
#
###############################################################################
# Release 1.4.1:
#AC_SUBST([LT_VERSION_IXML], [2:2:0])
#AC_SUBST([LT_VERSION_THREADUTIL], [2:2:0])
#AC_SUBST([LT_VERSION_UPNP], [2:2:0])
#
###############################################################################
# Release 1.4.6:
# "current:revision:age"
#
# - Code has changed in ixml
# revision: 2 -> 3
# - Code has changed in threadutil
# revision: 2 -> 3
# - Interface added in threadutil
# current: 2 -> 3
# revisiion: 3 -> 0
# age: 0 -> 1
# - Code has changed in upnp
# revision: 2 -> 3
#
#AC_SUBST([LT_VERSION_IXML], [2:3:0])
#AC_SUBST([LT_VERSION_THREADUTIL], [3:0:1])
#AC_SUBST([LT_VERSION_UPNP], [2:3:0])
#
###############################################################################
# Release 1.6.0:
# "current:revision:age"
#
# - Code has changed in ixml
# revision: 3 -> 4
# - Code has changed in threadutil
# revision: 0 -> 1
# - Code has changed in upnp
# revision: 3 -> 4
# - Interface changed in upnp
# current: 2 -> 3
# revision: 4 -> 0
# - Interface removed in upnp
# age: 0 -> 0
#
#AC_SUBST([LT_VERSION_IXML], [2:4:0])
#AC_SUBST([LT_VERSION_THREADUTIL], [3:1:1])
#AC_SUBST([LT_VERSION_UPNP], [3:0:0])
#
###############################################################################
# Release 1.6.1:
# "current:revision:age"
#
# - Code has changed in threadutil
# revision: 1 -> 2
# - Interface added in threadutil
# current: 3 -> 4
# revision: 2 -> 0
# - Interface added in threadutil
# age: 1 -> 2
# - Code has changed in upnp
# revision: 0 -> 1
#
#AC_SUBST([LT_VERSION_IXML], [2:4:0])
#AC_SUBST([LT_VERSION_THREADUTIL], [4:0:2])
#AC_SUBST([LT_VERSION_UPNP], [3:1:0])
#
###############################################################################
AC_INIT([libupnp], [1.6.5], [mroberto@users.sourceforge.net])
dnl ############################################################################
dnl # *Independently* of the above libupnp package version, the libtool version
dnl # of the 3 libraries need to be updated whenever there is a change released:
dnl # "current:revision:age" (this is NOT the same as the package version),
dnl # where:
dnl # - library code modified: revision++
dnl # - interfaces changed/added/removed: current++ and revision=0
dnl # - interfaces added: age++
dnl # - interfaces removed: age=0
dnl # *please update only once, before a formal release, not for each change*
dnl #
dnl ############################################################################
dnl # Release 1.4.1:
dnl #AC_SUBST([LT_VERSION_IXML], [2:2:0])
dnl #AC_SUBST([LT_VERSION_THREADUTIL], [2:2:0])
dnl #AC_SUBST([LT_VERSION_UPNP], [2:2:0])
dnl #
dnl ############################################################################
dnl # Release 1.4.6:
dnl # "current:revision:age"
dnl #
dnl # - Code has changed in ixml
dnl # revision: 2 -> 3
dnl # - Code has changed in threadutil
dnl # revision: 2 -> 3
dnl # - Interface added in threadutil
dnl # current: 2 -> 3
dnl # revisiion: 3 -> 0
dnl # age: 0 -> 1
dnl # - Code has changed in upnp
dnl # revision: 2 -> 3
dnl #
dnl #AC_SUBST([LT_VERSION_IXML], [2:3:0])
dnl #AC_SUBST([LT_VERSION_THREADUTIL], [3:0:1])
dnl #AC_SUBST([LT_VERSION_UPNP], [2:3:0])
dnl #
dnl ############################################################################
dnl # Release 1.6.0:
dnl # "current:revision:age"
dnl #
dnl # - Code has changed in ixml
dnl # revision: 3 -> 4
dnl # - Code has changed in threadutil
dnl # revision: 0 -> 1
dnl # - Code has changed in upnp
dnl # revision: 3 -> 4
dnl # - Interface changed in upnp
dnl # current: 2 -> 3
dnl # revision: 4 -> 0
dnl # - Interface removed in upnp
dnl # age: 0 -> 0
dnl #
dnl #AC_SUBST([LT_VERSION_IXML], [2:4:0])
dnl #AC_SUBST([LT_VERSION_THREADUTIL], [3:1:1])
dnl #AC_SUBST([LT_VERSION_UPNP], [3:0:0])
dnl #
dnl ############################################################################
dnl # Release 1.6.1:
dnl # "current:revision:age"
dnl #
dnl # - Code has changed in threadutil
dnl # revision: 1 -> 2
dnl # - Interface added in threadutil
dnl # current: 3 -> 4
dnl # revision: 2 -> 0
dnl # - Interface added in threadutil
dnl # age: 1 -> 2
dnl # - Code has changed in upnp
dnl # revision: 0 -> 1
dnl #
dnl #AC_SUBST([LT_VERSION_IXML], [2:4:0])
dnl #AC_SUBST([LT_VERSION_THREADUTIL], [4:0:2])
dnl #AC_SUBST([LT_VERSION_UPNP], [3:1:0])
dnl #
dnl ############################################################################
dnl # Release 1.6.2:
dnl # "current:revision:age"
dnl #
dnl # - Code has changed in upnp
dnl # revision: 1 -> 2
dnl #
dnl #AC_SUBST([LT_VERSION_IXML], [2:4:0])
dnl #AC_SUBST([LT_VERSION_THREADUTIL], [4:0:2])
dnl #AC_SUBST([LT_VERSION_UPNP], [3:2:0])
dnl #
dnl ############################################################################
dnl # Release 1.6.3:
dnl # "current:revision:age"
dnl #
dnl # - Code has changed in threadutil
dnl # revision: 0 -> 1
dnl #
dnl #AC_SUBST([LT_VERSION_IXML], [2:4:0])
dnl #AC_SUBST([LT_VERSION_THREADUTIL], [4:1:2])
dnl #AC_SUBST([LT_VERSION_UPNP], [3:2:0])
dnl #
dnl ############################################################################
dnl # Release 1.6.4:
dnl # "current:revision:age"
dnl #
dnl # - Code has changed in threadutil
dnl # revision: 1 -> 2
dnl # - Code has changed in upnp
dnl # revision: 2 -> 3
dnl #
dnl #AC_SUBST([LT_VERSION_IXML], [2:4:0])
dnl #AC_SUBST([LT_VERSION_THREADUTIL], [4:2:2])
dnl #AC_SUBST([LT_VERSION_UPNP], [3:3:0])
dnl #
dnl ############################################################################
dnl # Release 1.6.5:
dnl # "current:revision:age"
dnl #
dnl # - Code has changed in upnp
dnl # revision: 3 -> 4
dnl #
dnl #AC_SUBST([LT_VERSION_IXML], [2:4:0])
dnl #AC_SUBST([LT_VERSION_THREADUTIL], [4:2:2])
dnl #AC_SUBST([LT_VERSION_UPNP], [3:4:0])
dnl #
dnl ############################################################################
AC_SUBST([LT_VERSION_IXML], [2:4:0])
AC_SUBST([LT_VERSION_THREADUTIL], [4:0:2])
AC_SUBST([LT_VERSION_UPNP], [3:1:0])
###############################################################################
# Repeating the algorithm so that it is closer to the modificatin place:
# - 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_THREADUTIL], [4:2:2])
AC_SUBST([LT_VERSION_UPNP], [3:4:0])
dnl ############################################################################
dnl # Repeating the algorithm to place it closer to the modificatin place:
dnl # - library code modified: revision++
dnl # - interfaces changed/added/removed: current++ and revision=0
dnl # - interfaces added: age++
dnl # - interfaces removed: age=0
dnl # *please update only once, before a formal release, not for each change*
dnl ############################################################################
AC_CONFIG_AUX_DIR(config.aux)
AC_CONFIG_MACRO_DIR(m4)
AC_CONFIG_SRCDIR(upnp/inc/upnp.h)
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([upnp/inc/upnp.h])
AM_INIT_AUTOMAKE([1.8 -Wall foreign subdir-objects dist-bzip2])
@@ -129,8 +176,7 @@ 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_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])
@@ -152,7 +198,6 @@ 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])
@@ -186,11 +231,13 @@ fi
RT_BOOL_ARG_ENABLE([samples], [yes], [compilation of upnp/sample/ code])
#
# doc installation
# autoconf >= 2.60 already defines ${docdir}, but we will not use its
# default value, which is ${datarootdir}/doc/${PACKAGE_TARNAME}.
# That would give us ${datarootdir}/doc/libupnp, and we want the package
# version on that.
#
docdir="${datadir}/doc/${PACKAGE_NAME}-${PACKAGE_VERSION}"
AC_MSG_CHECKING([for documentation directory])
AC_ARG_WITH(
@@ -205,7 +252,9 @@ AS_HELP_STRING(
[],
[with_documentation=no])
#
# If something has been entered after an equal sign, assume it is the directory
#
if test x"$with_documentation" != xyes -a x"$with_documentation" != xno; then
docdir="$with_documentation"
fi
@@ -291,7 +340,6 @@ AC_CHECK_HEADERS(
# Checks for typedefs, structures, and compiler characteristics
#
AC_C_CONST
AC_TYPE_SIZE_T
TYPE_SOCKLEN_T
@@ -306,9 +354,40 @@ AC_CHECK_FUNCS(ftime,, [AC_CHECK_LIB(compat, ftime)])
#
# Checks for POSIX Threads
#
echo "--------------------------- pthread stuff -------------------------------------"
ACX_PTHREAD(
[],
[AC_MSG_ERROR([POSIX threads are required to build this program])])
#
# Update environment variables for pthreads
#
CC="$PTHREAD_CC"
CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
LIBS="$PTHREAD_LIBS $LIBS"
#
# Determine if pthread_rwlock_t is available
#
echo "----------------------- pthread_rwlock_t stuff --------------------------------"
AC_MSG_CHECKING([if pthread_rwlock_t is available])
AC_LANG([C])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[#include <pthread.h>],
[pthread_rwlock_t *x;])],
[AC_DEFINE([UPNP_USE_RWLOCK], [1], [Use pthread_rwlock_t])
AC_MSG_RESULT([yes, supported without any options])],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[#define _GNU_SOURCE
#include <pthread.h>],
[pthread_rwlock_t *x;])],
[AC_DEFINE([UPNP_USE_RWLOCK], [1], [Use pthread_rwlock_t])
CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
AC_MSG_RESULT([yes, definition of _GNU_SOURCE required])],
[AC_DEFINE([UPNP_USE_RWLOCK], [0], [Do not use pthread_rwlock_t])
AC_MSG_RESULT([no, needs to fallback to pthread_mutex])
AC_MSG_ERROR([pthread_rwlock_t not available])])])
echo "-------------------------------------------------------------------------------"
AC_CONFIG_FILES([

View File

@@ -39,7 +39,7 @@ EXTRA_DIST = \
./html/upnp/UPNP_E_SOCKET_ERROR-208.html \
./html/upnp/UPNP_E_CANCELED-210.html \
./html/upnp/UPNP_E_SUBSCRIBE_UNACCEPTED-301.html \
./html/upnp/UPNP_E_UNSUBSCRIBE_UNACCAPTED-302.html \
./html/upnp/UPNP_E_UNSUBSCRIBE_UNACCEPTED-302.html \
./html/upnp/UPNP_E_NOTIFY_UNACCEPTED-303.html \
./html/upnp/UPNP_E_INVALID_ARGUMENT-501.html \
./html/upnp/UPNP_E_FILE_NOT_FOUND-502.html \
@@ -295,7 +295,7 @@ if WITH_DOCUMENTATION
./html/upnp/UPNP_E_SOCKET_ERROR-208.html \
./html/upnp/UPNP_E_CANCELED-210.html \
./html/upnp/UPNP_E_SUBSCRIBE_UNACCEPTED-301.html \
./html/upnp/UPNP_E_UNSUBSCRIBE_UNACCAPTED-302.html \
./html/upnp/UPNP_E_UNSUBSCRIBE_UNACCEPTED-302.html \
./html/upnp/UPNP_E_NOTIFY_UNACCEPTED-303.html \
./html/upnp/UPNP_E_INVALID_ARGUMENT-501.html \
./html/upnp/UPNP_E_FILE_NOT_FOUND-502.html \

View File

@@ -38,11 +38,7 @@
#define MINVAL( a, b ) ( (a) < (b) ? (a) : (b) )
#define MAXVAL( a, b ) ( (a) > (b) ? (a) : (b) )
#ifndef WIN32
#define UPNP_INLINE inline
#endif
#define MEMBUF_DEF_SIZE_INC 20
#define MEMBUF_DEF_SIZE_INC 20
typedef struct // ixml_membuf

View File

@@ -501,17 +501,22 @@ Parser_init( )
}
/*================================================================
* Parser_isValidEndElement
* check if a new node->nodeName matches top of element stack.
* Internal to parser only.
*
*=================================================================*/
* Parser_isValidEndElement
* check if a new node->nodeName matches top of element stack.
* Internal to parser only.
*=================================================================*/
static int
Parser_isValidEndElement( IN Parser * xmlParser,
IN IXML_Node * newNode )
Parser_isValidEndElement(
IN Parser * xmlParser,
IN IXML_Node * newNode )
{
return ( strcmp( xmlParser->pCurElement->element, newNode->nodeName )
== 0 );
assert( xmlParser );
assert( xmlParser->pCurElement );
assert( xmlParser->pCurElement->element );
assert( newNode );
assert( newNode->nodeName );
return strcmp( xmlParser->pCurElement->element, newNode->nodeName ) == 0;
}
/*===============================================================
@@ -921,6 +926,8 @@ Parser_parseDocument( OUT IXML_Document ** retDoc,
int rc = IXML_SUCCESS;
IXML_CDATASection *cdataSecNode = NULL;
// It is important that the node gets initialized here, otherwise things
// can go wrong on the error handler.
ixmlNode_init( &newNode );
rc = ixmlDocument_createDocumentEx( &gRootDoc );
@@ -936,7 +943,9 @@ Parser_parseDocument( OUT IXML_Document ** retDoc,
}
while( bETag == FALSE ) {
// clear the newNode contents
// clear the newNode contents. Redundant on the first iteration,
// but nonetheless, necessary due to the possible calls to
// ErrorHandler above. Currently, this is just a memset to zero.
ixmlNode_init( &newNode );
if( Parser_getNextNode( xmlParser, &newNode, &bETag ) ==
@@ -1030,7 +1039,7 @@ Parser_parseDocument( OUT IXML_Document ** retDoc,
Parser_free( xmlParser );
return rc;
ErrorHandler:
ErrorHandler:
Parser_freeNodeContent( &newNode );
ixmlDocument_free( gRootDoc );
Parser_free( xmlParser );
@@ -2497,3 +2506,4 @@ Parser_getNextNode( IN Parser * xmlParser,
return IXML_SYNTAX_ERR;
}

0
ixml/test/test_document.sh Normal file → Executable file
View File

View File

@@ -1,4 +1,4 @@
Version: 1.4.2
Version: 1.6.5
Summary: Universal Plug and Play (UPnP) SDK
Name: libupnp
Release: 1%{?dist}
@@ -77,6 +77,12 @@ make install DESTDIR=$RPM_BUILD_ROOT
rm -rf %{buildroot}
%changelog
* Mon Nov 19 2007 Marcelo Jimenez <mroberto@users.sourceforge.net> - 1.6.2-1
- Update to version 1.6.2
* Mon Nov 19 2007 Marcelo Jimenez <mroberto@users.sourceforge.net> - 1.4.7-1
- Update to version 1.4.7
* Fri Feb 02 2007 Eric Tanguy <eric.tanguy@univ-nantes.fr> - 1.4.2-1
- Update to version 1.4.2

View File

@@ -41,7 +41,7 @@ AC_DEFUN([RT_BOOL_ARG_ENABLE],[
)])
test "x$enable_[$1]" != [x]m4_if([$2],[yes],[no],[yes]) dnl
&& enable_[]Name=[$2]
AC_MSG_RESULT($enable_[]Name)dnl
AC_MSG_RESULT($enable_[]Name)
AM_CONDITIONAL([ENABLE_]NAME, test x"$enable_[]Name" = xyes)
dnl
m4_popdef([NAME])dnl

View File

@@ -6,7 +6,6 @@
#
AM_CPPFLAGS = -I$(srcdir)/inc -I$(srcdir)/src/inc
AM_CFLAGS = $(PTHREAD_CFLAGS)
if ENABLE_DEBUG
AM_CPPFLAGS += -DDEBUG -DSTATS
@@ -21,12 +20,11 @@ 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
src/ThreadPool.c src/TimerThread.c
upnpincludedir = $(includedir)/upnp
upnpinclude_HEADERS = \
inc/FreeList.h inc/LinkedList.h \
inc/ThreadPool.h inc/TimerThread.h \
inc/iasnprintf.h inc/ithread.h
inc/ithread.h

View File

@@ -32,6 +32,12 @@
#ifndef THREADPOOL_H
#define THREADPOOL_H
#ifdef UPNP_USE_MSVCPP
#define UPNP_INLINE
#else
#define UPNP_INLINE inline
#endif
#ifdef __cplusplus
extern "C" {
#endif
@@ -64,32 +70,23 @@ typedef enum priority {LOW_PRIORITY,
#define DEFAULT_FREE_ROUTINE NULL /* default free routine used TPJobInit */
#define DEFAULT_MAX_JOBS_TOTAL 100 /* default max jobs used TPAttrInit */
#define STATS 1 /* always include stats because code change is minimal */
/* Statistics */
#ifdef WIN32 /* TODO: check why STATSONLY fails during compilation */
#undef STATS
#endif
#ifdef STATS
#define STATSONLY(x) x
#else
#define STATSONLY(x)
#endif
/* always include stats because code change is minimal */
#define STATS 1
#ifdef _DEBUG
#define DEBUG 1
#endif
#include "LinkedList.h"
#include <sys/timeb.h>
#include <sys/time.h> /* for gettimeofday() */
#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 */
@@ -111,26 +108,28 @@ typedef void (*free_routine)(void *arg);
*****************************************************************************/
typedef struct THREADPOOLATTR
{
int minThreads; /* minThreads, ThreadPool will always maintain at least
this many threads */
/* minThreads, ThreadPool will always maintain at least this many threads */
int minThreads;
int maxThreads; /* maxThreads, ThreadPool will never have more than this
number of threads */
/* maxThreads, ThreadPool will never have more than this number of threads */
int maxThreads;
int maxIdleTime; /* maxIdleTime (in milliseconds)
this is the maximum time a thread will remain idle
before dying */
/* maxIdleTime (in milliseconds) this is the maximum time a thread will
* remain idle before dying */
int maxIdleTime;
int jobsPerThread; /* jobs per thread to maintain */
/* jobs per thread to maintain */
int jobsPerThread;
int maxJobsTotal; /* maximum number of jobs that can be queued totally. */
/* maximum number of jobs that can be queued totally. */
int maxJobsTotal;
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 */
/* the time a low priority or med priority job waits before getting bumped
* up a priority (in milliseconds) */
int starvationTime;
/* scheduling policy to use */
PolicyType schedPolicy;
} ThreadPoolAttr;
/****************************************************************************
@@ -141,12 +140,12 @@ typedef struct THREADPOOLATTR
*****************************************************************************/
typedef struct THREADPOOLJOB
{
start_routine func;
void *arg;
free_routine free_func;
struct timeb requestTime;
int priority;
int jobId;
start_routine func;
void *arg;
free_routine free_func;
struct timeval requestTime;
int priority;
int jobId;
} ThreadPoolJob;
/****************************************************************************
@@ -156,32 +155,28 @@ typedef struct THREADPOOLJOB
* Structure to hold statistics
*****************************************************************************/
#ifdef STATS
typedef struct TPOOLSTATS
{
double totalTimeHQ;
int totalJobsHQ;
double avgWaitHQ;
double totalTimeMQ;
int totalJobsMQ;
double avgWaitMQ;
double totalTimeLQ;
int totalJobsLQ;
double avgWaitLQ;
double totalWorkTime;
double totalIdleTime;
int workerThreads;
int idleThreads;
int persistentThreads;
int totalThreads;
int maxThreads;
int currentJobsHQ;
int currentJobsLQ;
int currentJobsMQ;
}ThreadPoolStats;
#endif
double totalTimeHQ;
int totalJobsHQ;
double avgWaitHQ;
double totalTimeMQ;
int totalJobsMQ;
double avgWaitMQ;
double totalTimeLQ;
int totalJobsLQ;
double avgWaitLQ;
double totalWorkTime;
double totalIdleTime;
int workerThreads;
int idleThreads;
int persistentThreads;
int totalThreads;
int maxThreads;
int currentJobsHQ;
int currentJobsLQ;
int currentJobsMQ;
} ThreadPoolStats;
/****************************************************************************
@@ -206,27 +201,24 @@ typedef struct TPOOLSTATS
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 */
#ifdef STATS
/* statistics */
ThreadPoolStats stats;
#endif
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 */
ThreadPoolStats stats;
} ThreadPool;
@@ -267,8 +259,7 @@ typedef struct THREADPOOL
* INVALID_POLICY if schedPolicy can't be set
* EMAXTHREADS if minimum threads is greater than maximum threads
*****************************************************************************/
int ThreadPoolInit(ThreadPool *tp,
ThreadPoolAttr *attr);
int ThreadPoolInit(ThreadPool *tp, ThreadPoolAttr *attr);
/****************************************************************************
* Function: ThreadPoolAddPersistent
@@ -290,9 +281,7 @@ int ThreadPoolInit(ThreadPool *tp,
* EOUTOFMEM not enough memory to add job.
* EMAXTHREADS not enough threads to add persistent job.
*****************************************************************************/
int ThreadPoolAddPersistent (ThreadPool*tp,
ThreadPoolJob *job,
int *jobId);
int ThreadPoolAddPersistent(ThreadPool*tp, ThreadPoolJob *job, int *jobId);
/****************************************************************************
* Function: ThreadPoolGetAttr
@@ -307,8 +296,7 @@ int ThreadPoolAddPersistent (ThreadPool*tp,
* 0 on success, nonzero on failure
* Always returns 0.
*****************************************************************************/
int ThreadPoolGetAttr(ThreadPool *tp,
ThreadPoolAttr *out);
int ThreadPoolGetAttr(ThreadPool *tp, ThreadPoolAttr *out);
/****************************************************************************
* Function: ThreadPoolSetAttr
*
@@ -322,8 +310,7 @@ int ThreadPoolGetAttr(ThreadPool *tp,
* 0 on success, nonzero on failure
* Returns INVALID_POLICY if policy can not be set.
*****************************************************************************/
int ThreadPoolSetAttr(ThreadPool *tp,
ThreadPoolAttr *attr);
int ThreadPoolSetAttr(ThreadPool *tp, ThreadPoolAttr *attr);
/****************************************************************************
* Function: ThreadPoolAdd
@@ -342,9 +329,7 @@ int ThreadPoolSetAttr(ThreadPool *tp,
* 0 on success, nonzero on failure
* EOUTOFMEM if not enough memory to add job.
*****************************************************************************/
int ThreadPoolAdd (ThreadPool*tp,
ThreadPoolJob *job,
int *jobId);
int ThreadPoolAdd (ThreadPool*tp, ThreadPoolJob *job, int *jobId);
/****************************************************************************
* Function: ThreadPoolRemove
@@ -361,8 +346,7 @@ int ThreadPoolAdd (ThreadPool*tp,
* 0 on success, nonzero on failure.
* INVALID_JOB_ID if job not found.
*****************************************************************************/
int ThreadPoolRemove(ThreadPool *tp,
int jobId, ThreadPoolJob *out);
int ThreadPoolRemove(ThreadPool *tp, int jobId, ThreadPoolJob *out);
@@ -425,7 +409,6 @@ int TPJobSetPriority(ThreadPoolJob *job, ThreadPriority priority);
*****************************************************************************/
int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func);
/****************************************************************************
* Function: TPAttrInit
*

View File

@@ -1,66 +0,0 @@
/*******************************************************************************
*
* 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

@@ -31,7 +31,7 @@
#include "LinkedList.h"
#include <sys/param.h>
#if (defined(BSD) && BSD >= 199306) || defined(__OSX__)
#if (defined(BSD) && BSD >= 199306) || defined(__OSX__) || defined(__APPLE__)
#include <stdlib.h>
#else
#include <malloc.h>

File diff suppressed because it is too large Load Diff

View File

@@ -1,153 +0,0 @@
///////////////////////////////////////////////////////////////////////////
//
// 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 <sys/param.h>
#if (defined(BSD) && BSD >= 199306) || defined(__OSX__)
#include <stdlib.h>
#else
#include <malloc.h>
#endif
#include <stdio.h>
#include "iasnprintf.h"
#ifndef NULL
#define NULL 0
#endif
#ifdef WIN32
#define vsnprintf _vsnprintf
#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 );
if( ( *ret ) == NULL ) return -1;
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;
}

View File

@@ -11,10 +11,6 @@ AM_CPPFLAGS = \
-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 \

View File

@@ -413,7 +413,7 @@
#define UPNP_E_SUBSCRIBE_UNACCEPTED -301
/*! @} */
/** @name UPNP_E_UNSUBSCRIBE_UNACCAPTED [-302]
/** @name UPNP_E_UNSUBSCRIBE_UNACCEPTED [-302]
* {\tt UPNP_E_UNSUBSCRIBE_UNACCEPTED} signifies that an unsubscribe
* request was rejected from the remote side.
*/

View File

@@ -9,10 +9,6 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/threadutil/inc \
-I$(top_srcdir)/ixml/inc
AM_CFLAGS = $(PTHREAD_CFLAGS)
AM_LDFLAGS = $(PTHREAD_LIBS)
LDADD = \
$(top_builddir)/upnp/libupnp.la \
$(top_builddir)/threadutil/libthreadutil.la \

View File

@@ -92,11 +92,9 @@ CLIENTONLY( ithread_mutex_t GlobalClientSubscribeMutex; )
TimerThread gTimerThread;
ThreadPool gRecvThreadPool;
ThreadPool gSendThreadPool;
ThreadPool gMiniServerThreadPool;
ThreadPool gRecvThreadPool;
ThreadPool gMiniServerThreadPool;
//Flag to indicate the state of web server
WebServerState bWebServerState = WEB_SERVER_DISABLED;
@@ -268,7 +266,7 @@ int UpnpInit( IN const char *HostIP,
if( ThreadPoolInit( &gMiniServerThreadPool, &attr ) != UPNP_E_SUCCESS ) {
UpnpSdkInit = 0;
UpnpFinish( );
UpnpFinish();
return UPNP_E_INIT_FAILED;
}
@@ -402,7 +400,7 @@ UpnpFinish()
struct Handle_Info *temp;
#ifdef WIN32
// WSACleanup( );
// WSACleanup();
#endif
if( UpnpSdkInit != 1 ) {
@@ -410,14 +408,15 @@ UpnpFinish()
}
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"Inside UpnpFinish : UpnpSdkInit is :%d:\n",
UpnpSdkInit );
"Inside UpnpFinish : UpnpSdkInit is :%d:\n", UpnpSdkInit );
if( UpnpSdkInit == 1 ) {
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"UpnpFinish : UpnpSdkInit is ONE\n" );
}
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool");
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__, "Send Thread Pool");
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool");
PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__, "MiniServer Thread Pool");
#ifdef INCLUDE_DEVICE_APIS
if( GetDeviceHandleInfo( &device_handle, &temp ) == HND_DEVICE )
UpnpUnRegisterRootDevice( device_handle );
@@ -429,20 +428,19 @@ UpnpFinish()
#endif
TimerThreadShutdown( &gTimerThread );
StopMiniServer();
#if EXCLUDE_WEB_SERVER == 0
web_server_destroy();
#endif
ThreadPoolShutdown(&gSendThreadPool);
ThreadPoolShutdown(&gMiniServerThreadPool);
ThreadPoolShutdown(&gRecvThreadPool);
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"Exiting UpnpFinish : UpnpSdkInit is :%d:\n", UpnpSdkInit);
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool");
ThreadPoolShutdown(&gSendThreadPool);
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__, "Send Thread Pool");
UpnpCloseLog();
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool");
PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__, "MiniServer Thread Pool");
#ifdef INCLUDE_CLIENT_APIS
ithread_mutex_destroy(&GlobalClientSubscribeMutex);
@@ -456,11 +454,14 @@ UpnpFinish()
// allow static linking
#ifdef WIN32
#ifdef PTW32_STATIC_LIB
pthread_win32_thread_detach_np ();
pthread_win32_thread_detach_np();
#endif
#endif
UpnpSdkInit = 0;
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"Exiting UpnpFinish : UpnpSdkInit is :%d:\n", UpnpSdkInit);
UpnpCloseLog();
return UPNP_E_SUCCESS;

View File

@@ -36,18 +36,18 @@
#include "config.h"
#ifndef WIN32
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/time.h>
#else
#include <winsock2.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/time.h>
#else /* WIN32 */
#include <winsock2.h>
typedef int socklen_t;
#define EAFNOSUPPORT 97
#endif
typedef int socklen_t;
#define EAFNOSUPPORT 97
#endif /* WIN32 */
#include "unixutil.h"
#include "ithread.h"
@@ -88,17 +88,16 @@ static MiniServerCallback gGenaCallback = NULL;
static MiniServerState gMServState = MSERV_IDLE;
/************************************************************************
* Function : SetHTTPGetCallback
*
* Parameters :
* MiniServerCallback callback ; - HTTP Callback to be invoked
*
* Description : Set HTTP Get Callback
*
* Return : void
*
* Note :
************************************************************************/
* Function: SetHTTPGetCallback
*
* Parameters :
* MiniServerCallback callback - HTTP Callback to be invoked
*
* Description:
* Set HTTP Get Callback
*
* Return: void
************************************************************************/
void
SetHTTPGetCallback( MiniServerCallback callback )
{
@@ -106,35 +105,35 @@ SetHTTPGetCallback( MiniServerCallback callback )
}
/************************************************************************
* Function : SetSoapCallback
*
* Parameters :
* MiniServerCallback callback ; - SOAP Callback to be invoked
*
* Description : Set SOAP Callback
*
* Return : void
*
* Note :
************************************************************************/
* Function: SetSoapCallback
*
* Parameters:
* MiniServerCallback callback - SOAP Callback to be invoked
*
* Description:
* Set SOAP Callback
*
* Return: void
************************************************************************/
#ifdef INCLUDE_DEVICE_APIS
void
SetSoapCallback( MiniServerCallback callback )
{
gSoapCallback = callback;
}
#endif /* INCLUDE_DEVICE_APIS */
/************************************************************************
* Function : SetGenaCallback
*
* Parameters :
* MiniServerCallback callback ; - GENA Callback to be invoked
*
* Description : Set GENA Callback
*
* Return : void
*
* Note :
************************************************************************/
* Function: SetGenaCallback
*
* Parameters:
* MiniServerCallback callback - GENA Callback to be invoked
*
* Description:
* Set GENA Callback
*
* Return: void
************************************************************************/
void
SetGenaCallback( MiniServerCallback callback )
{
@@ -142,21 +141,19 @@ SetGenaCallback( MiniServerCallback callback )
}
/************************************************************************
* Function : dispatch_request
*
* Parameters :
* IN SOCKINFO *info ; Socket Information object.
* http_parser_t* hparser ; HTTP parser object.
*
* Description : Based on the type pf message, appropriate callback
* is issued
*
* Return : int ;
* 0 - On Success
* HTTP_INTERNAL_SERVER_ERROR - Callback is NULL
*
* Note :
************************************************************************/
* Function : dispatch_request
*
* Parameters :
* IN SOCKINFO *info - Socket Information object.
* http_parser_t* hparser - HTTP parser object.
*
* Description :
* Based on the type pf message, appropriate callback is issued
*
* Return: int
* 0 - On Success
* HTTP_INTERNAL_SERVER_ERROR - Callback is NULL
************************************************************************/
static int
dispatch_request( IN SOCKINFO * info,
http_parser_t * hparser )
@@ -200,21 +197,19 @@ dispatch_request( IN SOCKINFO * info,
}
/************************************************************************
* Function : handle_error
*
* Parameters :
*
* IN SOCKINFO *info ; Socket Inforamtion Object
* int http_error_code ; HTTP Error Code
* int major ; Major Version Number
* int minor ; Minor Version Number
*
* Description : Send Error Message
*
* Return : void;
*
* Note :
************************************************************************/
* Function: handle_error
*
* Parameters:
* IN SOCKINFO *info - Socket Inforamtion Object
* int http_error_code - HTTP Error Code
* int major - Major Version Number
* int minor - Minor Version Number
*
* Description:
* Send Error Message
*
* Return: void
************************************************************************/
static UPNP_INLINE void
handle_error( IN SOCKINFO * info,
int http_error_code,
@@ -225,18 +220,17 @@ handle_error( IN SOCKINFO * info,
}
/************************************************************************
* Function : free_handle_request_arg
*
* Parameters :
* void *args ; Request Message to be freed
*
* Description : Free memory assigned for handling request and unitial-
* -ize socket functionality
*
* Return : void
*
* Note :
************************************************************************/
* Function: free_handle_request_arg
*
* Parameters:
* void *args ; Request Message to be freed
*
* Description:
* Free memory assigned for handling request and unitialize socket
* functionality
*
* Return: void
************************************************************************/
static void
free_handle_request_arg( void *args )
{
@@ -248,17 +242,16 @@ free_handle_request_arg( void *args )
}
/************************************************************************
* Function : handle_request
*
* Parameters :
* void *args ; Request Message to be handled
*
* Description : Receive the request and dispatch it for handling
*
* Return : void
*
* Note :
************************************************************************/
* Function: handle_request
*
* Parameters:
* void *args - Request Message to be handled
*
* Description:
* Receive the request and dispatch it for handling
*
* Return: void
************************************************************************/
static void
handle_request( void *args )
{
@@ -319,20 +312,18 @@ handle_request( void *args )
}
/************************************************************************
* Function : schedule_request_job
*
* Parameters :
* IN int connfd ; Socket Descriptor on which connection is accepted
* IN struct sockaddr_in* clientAddr ; Clients Address information
*
* Description : Initilize the thread pool to handle a request.
* Sets priority for the job and adds the job to the thread pool
*
*
* Return : void
*
* Note :
************************************************************************/
* Function: schedule_request_job
*
* Parameters:
* IN int connfd - Socket Descriptor on which connection is accepted
* IN struct sockaddr_in* clientAddr - Clients Address information
*
* Description:
* Initilize the thread pool to handle a request.
* Sets priority for the job and adds the job to the thread pool
*
* Return: void
************************************************************************/
static UPNP_INLINE void
schedule_request_job( IN int connfd,
IN struct sockaddr_in *clientAddr )
@@ -371,32 +362,31 @@ schedule_request_job( IN int connfd,
}
/************************************************************************
* Function : RunMiniServer
*
* Parameters :
* MiniServerSockArray *miniSock ; Socket Array
*
* Description : Function runs the miniserver. The MiniServer accepts a
* new request and schedules a thread to handle the new request.
* Checks for socket state and invokes appropriate read and shutdown
* actions for the Miniserver and SSDP sockets
*
* Return : void
*
* Note :
************************************************************************/
* Function: RunMiniServer
*
* Parameters:
* MiniServerSockArray *miniSock - Socket Array
*
* Description:
* Function runs the miniserver. The MiniServer accepts a
* new request and schedules a thread to handle the new request.
* Checks for socket state and invokes appropriate read and shutdown
* actions for the Miniserver and SSDP sockets
*
* Return: void
************************************************************************/
static void
RunMiniServer( MiniServerSockArray * miniSock )
{
struct sockaddr_in clientAddr;
socklen_t clientLen;
SOCKET miniServSock,
connectHnd;
SOCKET miniServStopSock;
SOCKET ssdpSock;
CLIENTONLY( SOCKET ssdpReqSock;
)
SOCKET connectHnd;
SOCKET miniServSock = miniSock->miniServerSock;
SOCKET miniServStopSock = miniSock->miniServerStopSock;
SOCKET ssdpSock = miniSock->ssdpSock;
#ifdef INCLUDE_CLIENT_APIS
SOCKET ssdpReqSock = miniSock->ssdpReqSock;
#endif
fd_set expSet;
fd_set rdSet;
@@ -404,66 +394,55 @@ RunMiniServer( MiniServerSockArray * miniSock )
int byteReceived;
char requestBuf[256];
miniServSock = miniSock->miniServerSock;
miniServStopSock = miniSock->miniServerStopSock;
ssdpSock = miniSock->ssdpSock;
CLIENTONLY( ssdpReqSock = miniSock->ssdpReqSock;
);
gMServState = MSERV_RUNNING;
maxMiniSock = max( miniServSock, miniServStopSock );
maxMiniSock = max( maxMiniSock, ( SOCKET ) ( ssdpSock ) );
CLIENTONLY( maxMiniSock =
max( maxMiniSock, ( SOCKET ) ( ssdpReqSock ) ) );
maxMiniSock = max( miniServSock, miniServStopSock) ;
maxMiniSock = max( maxMiniSock, (SOCKET)(ssdpSock) );
#ifdef INCLUDE_CLIENT_APIS
maxMiniSock = max( maxMiniSock, (SOCKET)(ssdpReqSock) );
#endif
++maxMiniSock;
gMServState = MSERV_RUNNING;
while( TRUE ) {
FD_ZERO( &rdSet );
FD_ZERO( &expSet );
FD_SET( miniServStopSock, &expSet );
FD_SET( miniServSock, &rdSet );
FD_SET( miniServStopSock, &rdSet );
FD_SET( ssdpSock, &rdSet );
CLIENTONLY( FD_SET( ssdpReqSock, &rdSet ) );
#ifdef INCLUDE_CLIENT_APIS
FD_SET( ssdpReqSock, &rdSet );
#endif
if( select( maxMiniSock, &rdSet, NULL, &expSet, NULL ) ==
UPNP_SOCKETERROR ) {
UpnpPrintf( UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in select call !!!\n" );
"Error in select call!\n" );
/* Avoid 100% CPU in case of repeated error in select() */
isleep( 1 );
continue;
} else {
if( FD_ISSET( miniServSock, &rdSet ) ) {
clientLen = sizeof( struct sockaddr_in );
connectHnd = accept( miniServSock,
( struct sockaddr * )&clientAddr,
&clientLen );
( struct sockaddr * )&clientAddr, &clientLen );
if( connectHnd == UPNP_INVALID_SOCKET ) {
UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__,
"miniserver: Error"
" in accepting connection\n" );
"miniserver: Error in accepting connection\n" );
continue;
}
schedule_request_job( connectHnd, &clientAddr );
}
//ssdp
CLIENTONLY( if( FD_ISSET( ssdpReqSock, &rdSet ) ) {
readFromSSDPSocket( ssdpReqSock );}
)
if( FD_ISSET( ssdpSock, &rdSet ) ) {
#ifdef INCLUDE_CLIENT_APIS
// ssdp
if( FD_ISSET( ssdpReqSock, &rdSet ) ) {
readFromSSDPSocket( ssdpReqSock );
}
#endif
if( FD_ISSET( ssdpSock, &rdSet ) ) {
readFromSSDPSocket( ssdpSock );
}
}
if( FD_ISSET( miniServStopSock, &rdSet ) ) {
clientLen = sizeof( struct sockaddr_in );
memset( ( char * )&clientAddr, 0,
sizeof( struct sockaddr_in ) );
@@ -479,7 +458,6 @@ RunMiniServer( MiniServerSockArray * miniSock )
UpnpPrintf( UPNP_PACKET, MSERV, __FILE__, __LINE__,
"Received multicast packet: \n %s\n",
requestBuf );
if( NULL != strstr( requestBuf, "ShutDown" ) ) {
break;
}
@@ -494,31 +472,30 @@ RunMiniServer( MiniServerSockArray * miniSock )
UpnpCloseSocket( miniServStopSock );
shutdown( ssdpSock, SD_BOTH );
UpnpCloseSocket( ssdpSock );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
#ifdef INCLUDE_CLIENT_APIS
shutdown( ssdpReqSock, SD_BOTH );
UpnpCloseSocket( ssdpReqSock );
#endif
free( miniSock );
gMServState = MSERV_IDLE;
return;
}
/************************************************************************
* Function : get_port
*
* Parameters :
* int sockfd ; Socket Descriptor
*
* Description : Returns port to which socket, sockfd, is bound.
*
* Return : int,
* -1 on error; check errno
* > 0 means port number
*
* Note :
************************************************************************/
* Function: get_port
*
* Parameters:
* int sockfd - Socket Descriptor
*
* Description:
* Returns port to which socket, sockfd, is bound.
*
* Return: int
* -1 on error; check errno
* > 0 means port number
************************************************************************/
static int
get_port( int sockfd )
{
@@ -541,28 +518,28 @@ get_port( int sockfd )
}
/************************************************************************
* Function : get_miniserver_sockets
*
* Parameters :
* MiniServerSockArray *out ; Socket Array
* unsigned short listen_port ; port on which the server is listening
* for incoming connections
*
* Description : Creates a STREAM socket, binds to INADDR_ANY and
* listens for incoming connecttions. Returns the actual port which
* the sockets sub-system returned.
* Also creates a DGRAM socket, binds to the loop back address and
* returns the port allocated by the socket sub-system.
*
* Return : int :
* UPNP_E_OUTOF_SOCKET - Failed to create a socket
* UPNP_E_SOCKET_BIND - Bind() failed
* UPNP_E_LISTEN - Listen() failed
* UPNP_E_INTERNAL_ERROR - Port returned by the socket layer is < 0
* UPNP_E_SUCCESS - Success
*
* Note :
************************************************************************/
* Function: get_miniserver_sockets
*
* Parameters:
* MiniServerSockArray *out - Socket Array
* unsigned short listen_port - port on which the server is
* listening for incoming connections
*
* Description:
* Creates a STREAM socket, binds to INADDR_ANY and listens for
* incoming connecttions. Returns the actual port which the sockets
* sub-system returned.
*
* Also creates a DGRAM socket, binds to the loop back address and
* returns the port allocated by the socket sub-system.
*
* Return: int
* UPNP_E_OUTOF_SOCKET - Failed to create a socket
* UPNP_E_SOCKET_BIND - Bind() failed
* UPNP_E_LISTEN - Listen() failed
* UPNP_E_INTERNAL_ERROR - Port returned by the socket layer is < 0
* UPNP_E_SUCCESS - Success
************************************************************************/
int
get_miniserver_sockets( MiniServerSockArray * out,
unsigned short listen_port )
@@ -692,8 +669,8 @@ get_miniserver_sockets( MiniServerSockArray * out,
miniStopSockPort = get_port( miniServerStopSock );
if( miniStopSockPort <= 0 ) {
shutdown( miniServerStopSock, SD_BOTH );
shutdown( listenfd, SD_BOTH );
UpnpCloseSocket( miniServerStopSock );
shutdown( listenfd, SD_BOTH );
UpnpCloseSocket( listenfd );
return UPNP_E_INTERNAL_ERROR;
}
@@ -708,31 +685,29 @@ get_miniserver_sockets( MiniServerSockArray * out,
}
/************************************************************************
* Function : StartMiniServer
*
* Parameters :
* unsigned short listen_port ; Port on which the server listens for
* incoming connections
*
* Description : Initialize the sockets functionality for the
* Miniserver. Initialize a thread pool job to run the MiniServer
* and the job to the thread pool. If listen port is 0, port is
* dynamically picked
*
* Use timer mechanism to start the MiniServer, failure to meet the
* allowed delay aborts the attempt to launch the MiniServer.
*
* Return : int ;
* Actual port socket is bound to - On Success:
* A negative number UPNP_E_XXX - On Error
* Note :
************************************************************************/
* Function: StartMiniServer
*
* Parameters :
* unsigned short listen_port - Port on which the server listens for
* incoming connections
*
* Description:
* Initialize the sockets functionality for the
* Miniserver. Initialize a thread pool job to run the MiniServer
* and the job to the thread pool. If listen port is 0, port is
* dynamically picked
*
* Use timer mechanism to start the MiniServer, failure to meet the
* allowed delay aborts the attempt to launch the MiniServer.
*
* Return: int
* Actual port socket is bound to - On Success
* A negative number UPNP_E_XXX - On Error
************************************************************************/
int
StartMiniServer( unsigned short listen_port )
{
int success;
int count;
int max_count = 10000;
@@ -755,12 +730,10 @@ StartMiniServer( unsigned short listen_port )
}
if( ( success = get_ssdp_sockets( miniSocket ) ) != UPNP_E_SUCCESS ) {
shutdown( miniSocket->miniServerSock, SD_BOTH );
UpnpCloseSocket( miniSocket->miniServerSock );
shutdown( miniSocket->miniServerStopSock, SD_BOTH );
UpnpCloseSocket( miniSocket->miniServerStopSock );
free( miniSocket );
return success;
@@ -776,14 +749,15 @@ StartMiniServer( unsigned short listen_port )
if( success < 0 ) {
shutdown( miniSocket->miniServerSock, SD_BOTH );
shutdown( miniSocket->miniServerStopSock, SD_BOTH );
shutdown( miniSocket->ssdpSock, SD_BOTH );
CLIENTONLY( shutdown( miniSocket->ssdpReqSock, SD_BOTH ) );
UpnpCloseSocket( miniSocket->miniServerSock );
shutdown( miniSocket->miniServerStopSock, SD_BOTH );
UpnpCloseSocket( miniSocket->miniServerStopSock );
shutdown( miniSocket->ssdpSock, SD_BOTH );
UpnpCloseSocket( miniSocket->ssdpSock );
CLIENTONLY( UpnpCloseSocket( miniSocket->ssdpReqSock ) );
#ifdef INCLUDE_CLIENT_APIS
shutdown( miniSocket->ssdpReqSock, SD_BOTH );
UpnpCloseSocket( miniSocket->ssdpReqSock );
#endif
return UPNP_E_OUTOF_MEMORY;
}
@@ -796,16 +770,16 @@ StartMiniServer( unsigned short listen_port )
// taking too long to start that thread
if( count >= max_count ) {
shutdown( miniSocket->miniServerSock, SD_BOTH );
shutdown( miniSocket->miniServerStopSock, SD_BOTH );
shutdown( miniSocket->ssdpSock, SD_BOTH );
CLIENTONLY( shutdown( miniSocket->ssdpReqSock, SD_BOTH ) );
UpnpCloseSocket( miniSocket->miniServerSock );
shutdown( miniSocket->miniServerStopSock, SD_BOTH );
UpnpCloseSocket( miniSocket->miniServerStopSock );
shutdown( miniSocket->ssdpSock, SD_BOTH );
UpnpCloseSocket( miniSocket->ssdpSock );
CLIENTONLY( UpnpCloseSocket( miniSocket->ssdpReqSock ) );
#ifdef INCLUDE_CLIENT_APIS
shutdown( miniSocket->ssdpReqSock, SD_BOTH );
UpnpCloseSocket( miniSocket->ssdpReqSock );
#endif
return UPNP_E_INTERNAL_ERROR;
}
@@ -814,33 +788,33 @@ StartMiniServer( unsigned short listen_port )
}
/************************************************************************
* Function : StopMiniServer
*
* Parameters :
* void ;
*
* Description : Stop and Shutdown the MiniServer and free socket
* resources.
*
* Return : int ;
* Always returns 0
*
* Note :
************************************************************************/
* Function: StopMiniServer
*
* Parameters:
* void
*
* Description:
* Stop and Shutdown the MiniServer and free socket
* resources.
*
* Return: int
* Always returns 0
************************************************************************/
int
StopMiniServer( void )
{
int socklen = sizeof( struct sockaddr_in ),
sock;
int socklen = sizeof( struct sockaddr_in );
int sock;
struct sockaddr_in ssdpAddr;
char buf[256] = "ShutDown";
int bufLen = strlen( buf );
if( gMServState == MSERV_RUNNING )
if( gMServState == MSERV_RUNNING ) {
gMServState = MSERV_STOPPING;
else
} else {
return 0;
}
sock = socket( AF_INET, SOCK_DGRAM, 0 );
if( sock == UPNP_INVALID_SOCKET ) {
@@ -864,3 +838,4 @@ StopMiniServer( void )
UpnpCloseSocket( sock );
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -29,10 +29,10 @@
//
///////////////////////////////////////////////////////////////////////////
/************************************************************************
* Purpose: This file defines the Web Server and has functions to carry out
* operations of the Web Server.
************************************************************************/
/******************************************************************************
* Purpose: This file defines the Web Server and has functions to carry out
* operations of the Web Server.
******************************************************************************/
#include "config.h"
#include <assert.h>
@@ -64,8 +64,12 @@
/*
Response Types
*/
enum resp_type { RESP_FILEDOC, RESP_XMLDOC, RESP_HEADERS, RESP_WEBDOC,
RESP_POST };
enum resp_type {
RESP_FILEDOC,
RESP_XMLDOC,
RESP_HEADERS,
RESP_WEBDOC,
RESP_POST };
// mapping of file extension to content-type of document
struct document_type_t {
@@ -95,18 +99,18 @@ static const char *gMediaTypes[] = {
*/
// index into 'gMediaTypes'
#define AUDIO_STR "\1"
#define VIDEO_STR "\2"
#define IMAGE_STR "\3"
#define APPLICATION_STR "\4"
#define TEXT_STR "\5"
#define AUDIO_STR "\1"
#define VIDEO_STR "\2"
#define IMAGE_STR "\3"
#define APPLICATION_STR "\4"
#define TEXT_STR "\5"
// int index
#define APPLICATION_INDEX 4
#define TEXT_INDEX 5
#define APPLICATION_INDEX 4
#define TEXT_INDEX 5
// general
#define NUM_MEDIA_TYPES 69
#define NUM_MEDIA_TYPES 69
#define NUM_HTTP_HEADER_NAMES 33
// sorted by file extension; must have 'NUM_MEDIA_TYPES' extensions
@@ -182,12 +186,9 @@ static const char *gEncodedMediaTypes =
"zip\0" APPLICATION_STR "zip\0" "\0";
// *** end ***
/***********************************************************************/
/*
/************************************************************************
module variables - Globals, static and externs
*/
/***********************************************************************/
************************************************************************/
static struct document_type_t gMediaTypeList[NUM_MEDIA_TYPES];
membuffer gDocumentRootDir; // a local dir which serves as webserver root
static struct xml_alias_t gAliasDoc; // XML document
@@ -195,16 +196,16 @@ static ithread_mutex_t gWebMutex;
extern str_int_entry Http_Header_Names[NUM_HTTP_HEADER_NAMES];
/************************************************************************
* Function: has_xml_content_type
*
* Parameters:
* none
*
* Description: decodes list and stores it in gMediaTypeList
*
* Returns:
* void
************************************************************************/
* Function: has_xml_content_type
*
* Parameters:
* none
*
* Description: decodes list and stores it in gMediaTypeList
*
* Returns:
* void
************************************************************************/
static UPNP_INLINE void
media_list_init( void )
{
@@ -229,20 +230,20 @@ media_list_init( void )
}
/************************************************************************
* Function: has_xml_content_type
*
* Parameters:
* IN const char* extension ;
* OUT const char** con_type,
* OUT const char** con_subtype
*
* Description: Based on the extension, returns the content type and
* content subtype
*
* Returns:
* 0 on success;
* -1 on error
************************************************************************/
* Function: has_xml_content_type
*
* Parameters:
* IN const char* extension ;
* OUT const char** con_type,
* OUT const char** con_subtype
*
* Description: Based on the extension, returns the content type and
* content subtype
*
* Returns:
* 0 on success;
* -1 on error
************************************************************************/
static UPNP_INLINE int
search_extension( IN const char *extension,
OUT const char **con_type,
@@ -276,20 +277,20 @@ search_extension( IN const char *extension,
}
/************************************************************************
* Function: get_content_type
*
* Parameters:
* IN const char* filename,
* OUT DOMString* content_type
*
* Description: Based on the extension, clones an XML string based on
* type and content subtype. If content type and sub type are not
* found, unknown types are used
*
* Returns:
* 0 - On Sucess
* UPNP_E_OUTOF_MEMORY - on memory allocation failures
************************************************************************/
* Function: get_content_type
*
* Parameters:
* IN const char* filename,
* OUT DOMString* content_type
*
* Description: Based on the extension, clones an XML string based on
* type and content subtype. If content type and sub type are not
* found, unknown types are used
*
* Returns:
* 0 - On Sucess
* UPNP_E_OUTOF_MEMORY - on memory allocation failures
************************************************************************/
UPNP_INLINE int
get_content_type( IN const char *filename,
OUT DOMString * content_type )
@@ -337,17 +338,17 @@ get_content_type( IN const char *filename,
}
/************************************************************************
* Function: glob_alias_init
*
* Parameters:
* none
*
* Description: Initialize the global XML document. Allocate buffers
* for the XML document
*
* Returns:
* void
************************************************************************/
* Function: glob_alias_init
*
* Parameters:
* none
*
* Description: Initialize the global XML document. Allocate buffers
* for the XML document
*
* Returns:
* void
************************************************************************/
static UPNP_INLINE void
glob_alias_init( void )
{
@@ -360,16 +361,16 @@ glob_alias_init( void )
}
/************************************************************************
* Function: is_valid_alias
*
* Parameters:
* IN const struct xml_alias_t* alias ; XML alias object
*
* Description: Check for the validity of the XML object buffer
*
* Returns:
* BOOLEAN
************************************************************************/
* Function: is_valid_alias
*
* Parameters:
* IN const struct xml_alias_t* alias ; XML alias object
*
* Description: Check for the validity of the XML object buffer
*
* Returns:
* BOOLEAN
************************************************************************/
static UPNP_INLINE xboolean
is_valid_alias( IN const struct xml_alias_t *alias )
{
@@ -377,17 +378,17 @@ is_valid_alias( IN const struct xml_alias_t *alias )
}
/************************************************************************
* Function: alias_grab
*
* Parameters:
* OUT struct xml_alias_t* alias ; XML alias object
*
* Description: Copy the contents of the global XML document into the
* local OUT parameter
*
* Returns:
* void
************************************************************************/
* Function: alias_grab
*
* Parameters:
* OUT struct xml_alias_t* alias ; XML alias object
*
* Description: Copy the contents of the global XML document into the
* local OUT parameter
*
* Returns:
* void
************************************************************************/
static void
alias_grab( OUT struct xml_alias_t *alias )
{
@@ -402,17 +403,17 @@ alias_grab( OUT struct xml_alias_t *alias )
}
/************************************************************************
* Function: alias_release
*
* Parameters:
* IN struct xml_alias_t* alias ; XML alias object
*
* Description: Release the XML document referred to by the IN parameter
* Free the allocated buffers associated with this object
*
* Returns:
* void
************************************************************************/
* Function: alias_release
*
* Parameters:
* IN struct xml_alias_t* alias ; XML alias object
*
* Description: Release the XML document referred to by the IN parameter
* Free the allocated buffers associated with this object
*
* Returns:
* void
************************************************************************/
static void
alias_release( IN struct xml_alias_t *alias )
{
@@ -436,24 +437,24 @@ alias_release( IN struct xml_alias_t *alias )
}
/************************************************************************
* Function: web_server_set_alias
*
* Parameters:
* alias_name: webserver name of alias; created by caller and freed by
* caller (doesn't even have to be malloc()d .)
* alias_content: the xml doc; this is allocated by the caller; and
* freed by the web server
* alias_content_length: length of alias body in bytes
* last_modified: time when the contents of alias were last
* changed (local time)
*
* Description: Replaces current alias with the given alias. To remove
* the current alias, set alias_name to NULL.
*
* Returns:
* 0 - OK
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
************************************************************************/
* Function: web_server_set_alias
*
* Parameters:
* alias_name: webserver name of alias; created by caller and freed by
* caller (doesn't even have to be malloc()d .)
* alias_content: the xml doc; this is allocated by the caller; and
* freed by the web server
* alias_content_length: length of alias body in bytes
* last_modified: time when the contents of alias were last
* changed (local time)
*
* Description: Replaces current alias with the given alias. To remove
* the current alias, set alias_name to NULL.
*
* Returns:
* 0 - OK
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
************************************************************************/
int
web_server_set_alias( IN const char *alias_name,
IN const char *alias_content,
@@ -516,19 +517,19 @@ web_server_set_alias( IN const char *alias_name,
}
/************************************************************************
* Function: web_server_init
*
* Parameters:
* none
*
* Description: Initilialize the different documents. Initialize the
* memory for root directory for web server. Call to initialize global
* XML document. Sets bWebServerState to WEB_SERVER_ENABLED
*
* Returns:
* 0 - OK
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
************************************************************************/
* Function: web_server_init
*
* Parameters:
* none
*
* Description: Initilialize the different documents. Initialize the
* memory for root directory for web server. Call to initialize global
* XML document. Sets bWebServerState to WEB_SERVER_ENABLED
*
* Returns:
* 0 - OK
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
************************************************************************/
int
web_server_init( void )
{
@@ -552,18 +553,18 @@ web_server_init( void )
}
/************************************************************************
* Function: web_server_destroy
*
* Parameters:
* none
*
* Description: Release memory allocated for the global web server root
* directory and the global XML document
* Resets the flag bWebServerState to WEB_SERVER_DISABLED
*
* Returns:
* void
************************************************************************/
* Function: web_server_destroy
*
* Parameters:
* none
*
* Description: Release memory allocated for the global web server root
* directory and the global XML document
* Resets the flag bWebServerState to WEB_SERVER_DISABLED
*
* Returns:
* void
************************************************************************/
void
web_server_destroy( void )
{
@@ -584,23 +585,22 @@ web_server_destroy( void )
}
/************************************************************************
* Function: get_file_info
*
* Parameters:
* IN const char* filename ; Filename having the description document
* OUT struct File_Info * info ; File information object having file
* attributes such as filelength, when was
* the file last modified, whether a file
* or a directory and whether the file or
* directory is readable.
*
* Description: Release memory allocated for the global web server root
* directory and the global XML document
* Resets the flag bWebServerState to WEB_SERVER_DISABLED
*
* Returns:
* int
************************************************************************/
* Function: get_file_info
*
* Parameters:
* IN const char* filename ; Filename having the description document
* OUT struct File_Info * info ; File information object having file
* attributes such as filelength, when was the file last
* modified, whether a file or a directory and whether the
* file or directory is readable.
*
* Description: Release memory allocated for the global web server root
* directory and the global XML document
* Resets the flag bWebServerState to WEB_SERVER_DISABLED
*
* Returns:
* int
************************************************************************/
static int
get_file_info( IN const char *filename,
OUT struct File_Info *info )
@@ -647,19 +647,19 @@ get_file_info( IN const char *filename,
}
/************************************************************************
* Function: web_server_set_root_dir
*
* Parameters:
* IN const char* root_dir ; String having the root directory for the
* document
*
* Description: Assign the path specfied by the IN const char* root_dir
* parameter to the global Document root directory. Also check for
* path names ending in '/'
*
* Returns:
* int
************************************************************************/
* Function: web_server_set_root_dir
*
* Parameters:
* IN const char* root_dir ; String having the root directory for the
* document
*
* Description: Assign the path specfied by the IN const char* root_dir
* parameter to the global Document root directory. Also check for
* path names ending in '/'
*
* Returns:
* int
************************************************************************/
int
web_server_set_root_dir( IN const char *root_dir )
{
@@ -682,24 +682,23 @@ web_server_set_root_dir( IN const char *root_dir )
}
/************************************************************************
* Function: get_alias
*
* Parameters:
* IN const char* request_file ; request file passed in to be compared with
* OUT struct xml_alias_t* alias ; xml alias object which has a file name
* stored
* OUT struct File_Info * info ; File information object which will be
* filled up if the file comparison
* succeeds
*
* Description: Compare the files names between the one on the XML alias
* the one passed in as the input parameter. If equal extract file
* information
*
* Returns:
* TRUE - On Success
* FALSE if request is not an alias
************************************************************************/
* Function: get_alias
*
* Parameters:
* IN const char* request_file ; request file passed in to be compared with
* OUT struct xml_alias_t* alias ; xml alias object which has a file name
* stored
* OUT struct File_Info * info ; File information object which will be
* filled up if the file comparison succeeds
*
* Description: Compare the files names between the one on the XML alias
* the one passed in as the input parameter. If equal extract file
* information
*
* Returns:
* TRUE - On Success
* FALSE if request is not an alias
************************************************************************/
static UPNP_INLINE xboolean
get_alias( IN const char *request_file,
OUT struct xml_alias_t *alias,
@@ -720,17 +719,17 @@ get_alias( IN const char *request_file,
}
/************************************************************************
* Function: isFileInVirtualDir
*
* Parameters:
* IN char *filePath ; directory path to be tested for virtual directory
*
* Description: Compares filePath with paths from the list of virtual
* directory lists
*
* Returns:
* BOOLEAN
************************************************************************/
* Function: isFileInVirtualDir
*
* Parameters:
* IN char *filePath ; directory path to be tested for virtual directory
*
* Description: Compares filePath with paths from the list of virtual
* directory lists
*
* Returns:
* BOOLEAN
************************************************************************/
int
isFileInVirtualDir( IN char *filePath )
{
@@ -746,7 +745,7 @@ isFileInVirtualDir( IN char *filePath )
return TRUE;
} else {
if( ( strncmp( pCurVirtualDir->dirName, filePath, webDirLen )
== 0 ) && ( filePath[webDirLen] == '/' ) )
== 0 ) && ( filePath[webDirLen] == '/' || filePath[webDirLen] == '\0' || filePath[webDirLen] == '?' ) )
return TRUE;
}
@@ -757,16 +756,16 @@ isFileInVirtualDir( IN char *filePath )
}
/************************************************************************
* Function: ToUpperCase
*
* Parameters:
* INOUT char * Str ; Input string to be converted
*
* Description: Converts input string to upper case
*
* Returns:
* int
************************************************************************/
* Function: ToUpperCase
*
* Parameters:
* INOUT char * Str ; Input string to be converted
*
* Description: Converts input string to upper case
*
* Returns:
* int
************************************************************************/
int
ToUpperCase( char *Str )
{
@@ -779,17 +778,17 @@ ToUpperCase( char *Str )
}
/************************************************************************
* Function: StrStr
*
* Parameters:
* IN char * S1 ; Input string
* IN char * S2 ; Input sub-string
*
* Description: Finds a substring from a string
*
* Returns:
* char * ptr - pointer to the first occurence of S2 in S1
************************************************************************/
* Function: StrStr
*
* Parameters:
* IN char * S1 ; Input string
* IN char * S2 ; Input sub-string
*
* Description: Finds a substring from a string
*
* Returns:
* char * ptr - pointer to the first occurence of S2 in S1
************************************************************************/
char *
StrStr( char *S1,
char *S2 )
@@ -829,17 +828,17 @@ StrStr( char *S1,
}
/************************************************************************
* Function: StrTok
*
* Parameters:
* IN char ** Src ; String containing the token
* IN char * del ; Set of delimiter characters
*
* Description: Finds next token in a string
*
* Returns:
* char * ptr - pointer to the first occurence of S2 in S1
************************************************************************/
* Function: StrTok
*
* Parameters:
* IN char ** Src ; String containing the token
* IN char * del ; Set of delimiter characters
*
* Description: Finds next token in a string
*
* Returns:
* char * ptr - pointer to the first occurence of S2 in S1
************************************************************************/
char *
StrTok( char **Src,
char *Del )
@@ -863,18 +862,18 @@ StrTok( char **Src,
}
/************************************************************************
* Function: GetNextRange
*
* Parameters:
* IN char ** SrcRangeStr ; string containing the token / range
* OUT int * FirstByte ; gets the first byte of the token
* OUT int * LastByte ; gets the last byte of the token
*
* Description: Returns a range of integers from a sring
*
* Returns: int ;
* always returns 1;
************************************************************************/
* Function: GetNextRange
*
* Parameters:
* IN char ** SrcRangeStr ; string containing the token / range
* OUT int * FirstByte ; gets the first byte of the token
* OUT int * LastByte ; gets the last byte of the token
*
* Description: Returns a range of integers from a string
*
* Returns: int ;
* always returns 1;
************************************************************************/
int
GetNextRange( char **SrcRangeStr,
off_t *FirstByte,
@@ -924,23 +923,23 @@ GetNextRange( char **SrcRangeStr,
}
/************************************************************************
* Function: CreateHTTPRangeResponseHeader
*
* Parameters:
* char * ByteRangeSpecifier ; String containing the range
* long FileLength ; Length of the file
* OUT struct SendInstruction * Instr ; SendInstruction object where the
* range operations will be stored
*
* Description: Fills in the Offset, read size and contents to send out
* as an HTTP Range Response
*
* Returns:
* HTTP_BAD_REQUEST
* UPNP_E_OUTOF_MEMORY
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
* HTTP_OK
************************************************************************/
* Function: CreateHTTPRangeResponseHeader
*
* Parameters:
* char * ByteRangeSpecifier ; String containing the range
* long FileLength ; Length of the file
* OUT struct SendInstruction * Instr ; SendInstruction object
* where the range operations will be stored
*
* Description: Fills in the Offset, read size and contents to send out
* as an HTTP Range Response
*
* Returns:
* HTTP_BAD_REQUEST
* UPNP_E_OUTOF_MEMORY
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
* HTTP_OK
************************************************************************/
int
CreateHTTPRangeResponseHeader( char *ByteRangeSpecifier,
off_t FileLength,
@@ -1036,24 +1035,24 @@ CreateHTTPRangeResponseHeader( char *ByteRangeSpecifier,
}
/************************************************************************
* Function: CheckOtherHTTPHeaders
*
* Parameters:
* IN http_message_t * Req ; HTTP Request message
* OUT struct SendInstruction * RespInstr ; Send Instruction object to
* data for the response
* int FileSize ; Size of the file containing the request document
*
* Description: Get header id from the request parameter and take
* appropriate action based on the ids.
* as an HTTP Range Response
*
* Returns:
* HTTP_BAD_REQUEST
* UPNP_E_OUTOF_MEMORY
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
* HTTP_OK
************************************************************************/
* Function: CheckOtherHTTPHeaders
*
* Parameters:
* IN http_message_t * Req ; HTTP Request message
* OUT struct SendInstruction * RespInstr ; Send Instruction object to
* data for the response
* int FileSize ; Size of the file containing the request document
*
* Description: Get header id from the request parameter and take
* appropriate action based on the ids.
* as an HTTP Range Response
*
* Returns:
* HTTP_BAD_REQUEST
* UPNP_E_OUTOF_MEMORY
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
* HTTP_OK
************************************************************************/
int
CheckOtherHTTPHeaders( IN http_message_t * Req,
OUT struct SendInstruction *RespInstr,
@@ -1167,27 +1166,27 @@ CheckOtherHTTPHeaders( IN http_message_t * Req,
}
/************************************************************************
* Function: process_request
*
* Parameters:
* IN http_message_t *req ; HTTP Request message
* OUT enum resp_type *rtype ; Tpye of response
* OUT membuffer *headers ;
* OUT membuffer *filename ; Get filename from request document
* OUT struct xml_alias_t *alias ; Xml alias document from the
* request document,
* OUT struct SendInstruction * RespInstr ; Send Instruction object
* where the response is set up.
*
* Description: Processes the request and returns the result in the OUT
* parameters
*
* Returns:
* HTTP_BAD_REQUEST
* UPNP_E_OUTOF_MEMORY
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
* HTTP_OK
************************************************************************/
* Function: process_request
*
* Parameters:
* IN http_message_t *req ; HTTP Request message
* OUT enum resp_type *rtype ; Tpye of response
* OUT membuffer *headers ;
* OUT membuffer *filename ; Get filename from request document
* OUT struct xml_alias_t *alias ; Xml alias document from the
* request document,
* OUT struct SendInstruction * RespInstr ; Send Instruction object
* where the response is set up.
*
* Description: Processes the request and returns the result in the OUT
* parameters
*
* Returns:
* HTTP_BAD_REQUEST
* UPNP_E_OUTOF_MEMORY
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
* HTTP_OK
************************************************************************/
static int
process_request( IN http_message_t * req,
OUT enum resp_type *rtype,
@@ -1495,23 +1494,23 @@ process_request( IN http_message_t * req,
}
/************************************************************************
* Function: http_RecvPostMessage
*
* Parameters:
* http_parser_t* parser ; HTTP Parser object
* IN SOCKINFO *info ; Socket Information object
* char * filename ; File where received data is copied to
* struct SendInstruction * Instr ; Send Instruction object which gives
* information whether the file is a virtual file or not.
*
* Description: Receives the HTTP post message
*
* Returns:
* HTTP_INTERNAL_SERVER_ERROR
* HTTP_UNAUTHORIZED
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
* HTTP_OK
************************************************************************/
* Function: http_RecvPostMessage
*
* Parameters:
* http_parser_t* parser ; HTTP Parser object
* IN SOCKINFO *info ; Socket Information object
* char * filename ; File where received data is copied to
* struct SendInstruction * Instr ; Send Instruction object which gives
* information whether the file is a virtual file or not.
*
* Description: Receives the HTTP post message
*
* Returns:
* HTTP_INTERNAL_SERVER_ERROR
* HTTP_UNAUTHORIZED
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
* HTTP_OK
************************************************************************/
int
http_RecvPostMessage( http_parser_t * parser,
IN SOCKINFO * info,
@@ -1659,19 +1658,19 @@ http_RecvPostMessage( http_parser_t * parser,
}
/************************************************************************
* Function: web_server_callback
*
* Parameters:
* IN http_parser_t *parser ; HTTP Parser Object
* INOUT http_message_t* req ; HTTP Message request
* IN SOCKINFO *info ; Socket information object
*
* Description: main entry point into web server;
* handles HTTP GET and HEAD requests
*
* Returns:
* void
************************************************************************/
* Function: web_server_callback
*
* Parameters:
* IN http_parser_t *parser ; HTTP Parser Object
* INOUT http_message_t* req ; HTTP Message request
* IN SOCKINFO *info ; Socket information object
*
* Description: main entry point into web server;
* handles HTTP GET and HEAD requests
*
* Returns:
* void
************************************************************************/
void
web_server_callback( IN http_parser_t * parser,
INOUT http_message_t * req,
@@ -1764,3 +1763,4 @@ web_server_callback( IN http_parser_t * parser,
membuffer_destroy( &headers );
membuffer_destroy( &filename );
}

View File

@@ -555,7 +555,7 @@ parse_hostport( const char *in,
int begin_port;
int hostport_size = 0;
int host_size = 0;
#if !defined(WIN32) && !defined(__OSX__)
#if !defined(WIN32) && !(defined(__OSX__) || defined(__APPLE__))
char temp_hostbyname_buff[BUFFER_SIZE];
struct hostent h_buf;
#endif
@@ -642,7 +642,7 @@ parse_hostport( const char *in,
if ( h == NULL ) {
errCode = 1;
}
#elif defined(__OSX__)
#elif defined(__OSX__) || defined(__APPLE__)
h = gethostbyname(temp_host_name);
if ( h == NULL ) {
errCode = 1;

View File

@@ -50,73 +50,78 @@ int
http_CancelHttpGet( IN void *Handle );
/************************************************************************
* Function: http_FixUrl
*
* Parameters:
* IN uri_type* url ; URL to be validated and fixed
* OUT uri_type* fixed_url ; URL after being fixed.
*
* Description: Validates URL
*
* Returns:
* UPNP_E_INVALID_URL
* UPNP_E_SUCCESS
************************************************************************/
* Function: http_FixUrl
*
* Parameters:
* IN uri_type* url; URL to be validated and fixed
* OUT uri_type* fixed_url; URL after being fixed.
*
* Description:
* Validates URL
*
* Returns:
* UPNP_E_INVALID_URL
* UPNP_E_SUCCESS
************************************************************************/
int http_FixUrl( IN uri_type* url, OUT uri_type* fixed_url );
/************************************************************************
* Function: http_FixStrUrl
*
* Parameters:
* IN char* urlstr ; Character string as a URL
* IN int urlstrlen ; Length of the character string
* OUT uri_type* fixed_url ; Fixed and corrected URL
*
* Description: Parses URL and then validates URL
*
* Returns:
* UPNP_E_INVALID_URL
* UPNP_E_SUCCESS
************************************************************************/
* Function: http_FixStrUrl
*
* Parameters:
* IN char* urlstr ; Character string as a URL
* IN int urlstrlen ; Length of the character string
* OUT uri_type* fixed_url ; Fixed and corrected URL
*
* Description:
* Parses URL and then validates URL
*
* Returns:
* UPNP_E_INVALID_URL
* UPNP_E_SUCCESS
************************************************************************/
int http_FixStrUrl( IN char* urlstr, IN int urlstrlen, OUT uri_type* fixed_url );
/************************************************************************
* Function: http_Connect
*
* Parameters:
* IN uri_type* destination_url ; URL containing destination information
* OUT uri_type *url ; Fixed and corrected URL
*
* Description: Gets destination address from URL and then connects to the
* remote end
*
* Returns:
* socket descriptor on sucess
* UPNP_E_OUTOF_SOCKET
* UPNP_E_SOCKET_CONNECT on error
************************************************************************/
* Function: http_Connect
*
* Parameters:
* IN uri_type* destination_url; URL containing destination information
* OUT uri_type *url; Fixed and corrected URL
*
* Description:
* Gets destination address from URL and then connects to the remote end
*
* Returns:
* socket descriptor on sucess
* UPNP_E_OUTOF_SOCKET
* UPNP_E_SOCKET_CONNECT on error
************************************************************************/
int http_Connect( IN uri_type* destination_url, OUT uri_type *url );
/************************************************************************
* Function: http_RecvMessage
*
* Parameters:
* IN SOCKINFO *info ; Socket information object
* OUT http_parser_t* parser, HTTP parser object
* IN http_method_t request_method ; HTTP request method
* IN OUT int* timeout_secs ; time out
* OUT int* http_error_code ; HTTP error code returned
*
* Description: Get the data on the socket and take actions based on the
* read data to modify the parser objects buffer. If an error is reported
* while parsing the data, the error code is passed in the http_errr_code
* parameter
*
* Returns:
* UPNP_E_BAD_HTTPMSG
* UPNP_E_SUCCESS
************************************************************************/
* Function: http_RecvMessage
*
* Parameters:
* IN SOCKINFO *info; Socket information object
* OUT http_parser_t* parser; HTTP parser object
* IN http_method_t request_method; HTTP request method
* IN OUT int* timeout_secs; time out
* OUT int* http_error_code; HTTP error code returned
*
* Description:
* Get the data on the socket and take actions based on the read data
* to modify the parser objects buffer. If an error is reported while
* parsing the data, the error code is passed in the http_errr_code
* parameter
*
* Returns:
* UPNP_E_BAD_HTTPMSG
* UPNP_E_SUCCESS
************************************************************************/
int http_RecvMessage( IN SOCKINFO *info, OUT http_parser_t* parser,
IN http_method_t request_method,
IN OUT int* timeout_secs,
@@ -124,302 +129,311 @@ int http_RecvMessage( IN SOCKINFO *info, OUT http_parser_t* parser,
/************************************************************************
* Function: http_SendMessage
*
* Parameters:
* IN SOCKINFO *info ; Socket information object
* IN OUT int * TimeOut ; time out value
* IN const char* fmt, ... Pattern format to take actions upon
*
* Description: Sends a message to the destination based on the
* IN const char* fmt parameter
* fmt types:
* 'f': arg = const char * file name
* 'm': arg1 = const char * mem_buffer; arg2= size_t buf_length
* E.g.:
* char *buf = "POST /xyz.cgi http/1.1\r\n\r\n";
* char *filename = "foo.dat";
* int status = http_SendMessage( tcpsock, "mf",
* buf, strlen(buf), // args for memory buffer
* filename ); // arg for file
*
* Returns:
* UPNP_E_OUTOF_MEMORY
* UPNP_E_FILE_READ_ERROR
* UPNP_E_SUCCESS
************************************************************************/
int http_SendMessage( IN SOCKINFO *info, IN OUT int* timeout_secs,
IN const char* fmt, ... );
/************************************************************************
* Function: http_RequestAndResponse
*
* Parameters:
* IN uri_type* destination ; Destination URI object which contains
* remote IP address among other elements
* IN const char* request ; Request to be sent
* IN size_t request_length ; Length of the request
* IN http_method_t req_method ; HTTP Request method
* IN int timeout_secs ; time out value
* OUT http_parser_t* response ; Parser object to receive the repsonse
*
* Description: Initiates socket, connects to the destination, sends a
* request and waits for the response from the remote end
*
* Returns:
* UPNP_E_SOCKET_ERROR
* UPNP_E_SOCKET_CONNECT
* Error Codes returned by http_SendMessage
* Error Codes returned by http_RecvMessage
************************************************************************/
int http_RequestAndResponse( IN uri_type* destination,
IN const char* request, IN size_t request_length,
IN http_method_t req_method,
IN int timeout_secs,
OUT http_parser_t* response );
/************************************************************************
* return codes:
* 0 -- success
* UPNP_E_OUTOF_MEMORY
* UPNP_E_TIMEDOUT
* UPNP_E_BAD_REQUEST
* UPNP_E_BAD_RESPONSE
* UPNP_E_INVALID_URL
* UPNP_E_SOCKET_READ
* UPNP_E_SOCKET_WRITE
************************************************************************/
/************************************************************************
* Function : http_Download
*
* Parameters :
* IN const char* url_str : String as a URL
* IN int timeout_secs : time out value
* OUT char** document : buffer to store the document extracted
* from the donloaded message.
* OUT int* doc_length : length of the extracted document
* OUT char* content_type : Type of content
*
* Description : Download the document message and extract the document
* from the message.
*
* Return : int;
* UPNP_E_SUCCESS;
* UPNP_E_INVALID_URL;
*
*
* Note :
************************************************************************/
int http_Download( IN const char* url,
IN int timeout_secs,
OUT char** document, OUT int* doc_length,
OUT char* content_type );
* Function: http_SendMessage
*
* Parameters:
* IN SOCKINFO *info ; Socket information object
* IN OUT int * TimeOut ; time out value
* IN const char* fmt, ... Pattern format to take actions upon
*
* Description:
* Sends a message to the destination based on the
* IN const char* fmt parameter
* fmt types:
* 'f': arg = const char * file name
* 'm': arg1 = const char * mem_buffer; arg2= size_t buf_length
* E.g.:
* char *buf = "POST /xyz.cgi http/1.1\r\n\r\n";
* char *filename = "foo.dat";
* int status = http_SendMessage( tcpsock, "mf",
* buf, strlen(buf), // args for memory buffer
* filename ); // arg for file
*
* Returns:
* UPNP_E_OUTOF_MEMORY
* UPNP_E_FILE_READ_ERROR
* UPNP_E_SUCCESS
************************************************************************/
int http_SendMessage(
IN SOCKINFO *info,
IN OUT int* timeout_secs,
IN const char* fmt, ... );
/************************************************************************
* Function : http_WriteHttpPost
*
* Parameters :
* IN void *Handle : Handle to the http post object
* IN char *buf : Buffer to send to peer, if format used
* is not UPNP_USING_CHUNKED,
* IN unsigned int *size : Size of the data to be sent.
* IN int timeout : time out value
*
* Description : Formats data if format used is UPNP_USING_CHUNKED.
* Writes data on the socket connected to the peer.
*
* Return : int ;
* UPNP_E_SUCCESS - On Success
* UPNP_E_INVALID_PARAM - Invalid Parameter
* -1 - On Socket Error.
*
* Note :
************************************************************************/
* Function: http_RequestAndResponse
*
* Parameters:
* IN uri_type* destination; Destination URI object which contains
* remote IP address among other elements
* IN const char* request; Request to be sent
* IN size_t request_length; Length of the request
* IN http_method_t req_method; HTTP Request method
* IN int timeout_secs; time out value
* OUT http_parser_t* response; Parser object to receive the repsonse
*
* Description:
* Initiates socket, connects to the destination, sends a
* request and waits for the response from the remote end
*
* Returns:
* UPNP_E_SOCKET_ERROR
* UPNP_E_SOCKET_CONNECT
* Error Codes returned by http_SendMessage
* Error Codes returned by http_RecvMessage
************************************************************************/
int http_RequestAndResponse(
IN uri_type* destination,
IN const char* request,
IN size_t request_length,
IN http_method_t req_method,
IN int timeout_secs,
OUT http_parser_t* response );
/************************************************************************
* return codes:
* 0 -- success
* UPNP_E_OUTOF_MEMORY
* UPNP_E_TIMEDOUT
* UPNP_E_BAD_REQUEST
* UPNP_E_BAD_RESPONSE
* UPNP_E_INVALID_URL
* UPNP_E_SOCKET_READ
* UPNP_E_SOCKET_WRITE
************************************************************************/
/************************************************************************
* Function: http_Download
*
* Parameters:
* IN const char* url_str; String as a URL
* IN int timeout_secs; time out value
* OUT char** document; buffer to store the document extracted
* from the donloaded message.
* OUT int* doc_length; length of the extracted document
* OUT char* content_type; Type of content
*
* Description:
* Download the document message and extract the document
* from the message.
*
* Return: int
* UPNP_E_SUCCESS
* UPNP_E_INVALID_URL
************************************************************************/
int http_Download(
IN const char* url,
IN int timeout_secs,
OUT char** document,
OUT int* doc_length,
OUT char* content_type );
/************************************************************************
* Function: http_WriteHttpPost
*
* Parameters:
* IN void *Handle: Handle to the http post object
* IN char *buf: Buffer to send to peer, if format used
* is not UPNP_USING_CHUNKED,
* IN unsigned int *size: Size of the data to be sent.
* IN int timeout: time out value
*
* Description:
* Formats data if format used is UPNP_USING_CHUNKED.
* Writes data on the socket connected to the peer.
*
* Return: int
* UPNP_E_SUCCESS - On Success
* UPNP_E_INVALID_PARAM - Invalid Parameter
* -1 - On Socket Error.
************************************************************************/
int http_WriteHttpPost(IN void *Handle,
IN char *buf,
IN unsigned int *size,
IN int timeout);
/************************************************************************
* Function : http_CloseHttpPost
*
* Parameters :
* IN void *Handle : Handle to the http post object
* IN OUT int *httpStatus : HTTP status returned on receiving a
* response message
* IN int timeout : time out value
*
* Description : Sends remaining data if using UPNP_USING_CHUNKED
* format. Receives any more messages. Destroys socket and any socket
* associated memory. Frees handle associated with the HTTP POST msg.
*
* Return : int ;
* UPNP_E_SUCCESS - On Sucess ;
* UPNP_E_INVALID_PARAM - Invalid Parameter;
*
* Note :
************************************************************************/
* Function: http_CloseHttpPost
*
* Parameters:
* IN void *Handle; Handle to the http post object
* IN OUT int *httpStatus; HTTP status returned on receiving a
* response message
* IN int timeout; time out value
*
* Description:
* Sends remaining data if using UPNP_USING_CHUNKED
* format. Receives any more messages. Destroys socket and any socket
* associated memory. Frees handle associated with the HTTP POST msg.
*
* Return: int
* UPNP_E_SUCCESS - On Sucess
* UPNP_E_INVALID_PARAM - Invalid Parameter
************************************************************************/
int http_CloseHttpPost(IN void *Handle,
IN OUT int *httpStatus,
IN int timeout);
/************************************************************************
* Function : http_OpenHttpPost
*
* Parameters :
* IN const char *url_str : String as a URL
* IN OUT void **Handle : Pointer to buffer to store HTTP
* post handle
* IN const char *contentType : Type of content
* IN int contentLength : length of content
* IN int timeout : time out value
*
* Description : Makes the HTTP POST message, connects to the peer,
* sends the HTTP POST request. Adds the post handle to buffer of
* such handles
*
* Return : int;
* UPNP_E_SUCCESS - On Sucess ;
* UPNP_E_INVALID_PARAM - Invalid Paramter ;
* UPNP_E_OUTOF_MEMORY ;
* UPNP_E_SOCKET_ERROR ;
* UPNP_E_SOCKET_CONNECT ;
*
* Note :
************************************************************************/
* Function: http_OpenHttpPost
*
* Parameters:
* IN const char *url_str; String as a URL
* IN OUT void **Handle; Pointer to buffer to store HTTP
* post handle
* IN const char *contentType; Type of content
* IN int contentLength; length of content
* IN int timeout; time out value
*
* Description:
* Makes the HTTP POST message, connects to the peer,
* sends the HTTP POST request. Adds the post handle to buffer of
* such handles
*
* Return : int;
* UPNP_E_SUCCESS - On Sucess
* UPNP_E_INVALID_PARAM - Invalid Parameter
* UPNP_E_OUTOF_MEMORY
* UPNP_E_SOCKET_ERROR
* UPNP_E_SOCKET_CONNECT
************************************************************************/
int http_OpenHttpPost(IN const char *url_str,
IN OUT void **Handle,
IN const char *contentType,
IN int contentLength,
IN int timeout);
/************************************************************************
* Function : http_ReadHttpGet
*
* Parameters :
* IN void *Handle : Handle to the HTTP get object
* IN OUT char *buf : Buffer to get the read and parsed data
* IN OUT unsigned int *size : Size of tge buffer passed
* IN int timeout : time out value
*
* Description : Parses already existing data, then gets new data.
* Parses and extracts information from the new data.
*
* Return : int ;
* UPNP_E_SUCCESS - On Sucess ;
* UPNP_E_INVALID_PARAM - Invalid Parameter;
* UPNP_E_BAD_RESPONSE ;
* UPNP_E_BAD_HTTPMSG ;
*
* Note :
************************************************************************/
int http_ReadHttpGet(IN void *Handle,
IN OUT char *buf,
IN OUT unsigned int *size,
IN int timeout);
/************************************************************************
* Function : http_HttpGetProgress
*
* Parameters :
* IN void *Handle : Handle to the HTTP get object
* OUT unsigned int *length : Buffer to get the read and parsed data
* OUT unsigned int *total : Size of tge buffer passed
*
* Description : Extracts information from the Handle to the HTTP get
* object.
*
* Return : int ;
* UPNP_E_SUCCESS - On Sucess ;
* UPNP_E_INVALID_PARAM - Invalid Parameter;
*
* Note :
************************************************************************/
int http_HttpGetProgress(IN void *Handle,
OUT unsigned int *length,
OUT unsigned int *total );
* Function: http_ReadHttpGet
*
* Parameters:
* IN void *Handle; Handle to the HTTP get object
* IN OUT char *buf; Buffer to get the read and parsed data
* IN OUT unsigned int *size; Size of the buffer passed
* IN int timeout; time out value
*
* Description:
* Parses already existing data, then gets new data.
* Parses and extracts information from the new data.
*
* Return: int
* UPNP_E_SUCCESS - On Sucess
* UPNP_E_INVALID_PARAM - Invalid Parameter
* UPNP_E_BAD_RESPONSE
* UPNP_E_BAD_HTTPMSG
* UPNP_E_CANCELED
************************************************************************/
int http_ReadHttpGet(
IN void *Handle,
IN OUT char *buf,
IN OUT unsigned int *size,
IN int timeout);
/************************************************************************
* Function : http_CloseHttpGet
*
* Parameters :
* IN void *Handle ; Handle to HTTP get object
*
* Description : Clears the handle allocated for the HTTP GET operation
* Clears socket states and memory allocated for socket operations.
*
* Return : int ;
* UPNP_E_SUCCESS - On Success
* UPNP_E_INVALID_PARAM - Invalid Parameter
*
* Note :
************************************************************************/
* Function: http_HttpGetProgress
*
* Parameters:
* IN void *Handle; Handle to the HTTP get object
* OUT unsigned int *length; Buffer to get the read and parsed data
* OUT unsigned int *total; Size of tge buffer passed
*
* Description:
* Extracts information from the Handle to the HTTP get object.
*
* Return: int
* UPNP_E_SUCCESS - On Sucess
* UPNP_E_INVALID_PARAM - Invalid Parameter
************************************************************************/
int http_HttpGetProgress(
IN void *Handle,
OUT unsigned int *length,
OUT unsigned int *total );
/************************************************************************
* Function: http_CloseHttpGet
*
* Parameters:
* IN void *Handle; Handle to HTTP get object
*
* Description:
* Clears the handle allocated for the HTTP GET operation
* Clears socket states and memory allocated for socket operations.
*
* Return: int
* UPNP_E_SUCCESS - On Success
* UPNP_E_INVALID_PARAM - Invalid Parameter
************************************************************************/
int http_CloseHttpGet(IN void *Handle);
/************************************************************************
* Function : http_OpenHttpGet
*
* Parameters :
* IN const char *url_str : String as a URL
* IN OUT void **Handle : Pointer to buffer to store HTTP
* post handle
* IN OUT char **contentType : Type of content
* OUT int *contentLength : length of content
* OUT int *httpStatus : HTTP status returned on receiving a
* response message
* IN int timeout : time out value
*
* Description : Makes the HTTP GET message, connects to the peer,
* sends the HTTP GET request, gets the response and parses the
* response.
*
* Return : int;
* UPNP_E_SUCCESS - On Success ;
* UPNP_E_INVALID_PARAM - Invalid Paramters ;
* UPNP_E_OUTOF_MEMORY ;
* UPNP_E_SOCKET_ERROR ;
* UPNP_E_BAD_RESPONSE ;
*
* Note :
*
************************************************************************/
int http_OpenHttpGet(IN const char *url_str,
IN OUT void **Handle,
IN OUT char **contentType,
OUT int *contentLength,
OUT int *httpStatus,
IN int timeout);
/************************************************************************
* Function : http_OpenHttpGetProxy
*
* Parameters :
* IN const char *url_str : String as a URL
* IN const char *proxy_str : String as a URL to the proxy
* IN OUT void **Handle : Pointer to buffer to store HTTP
* post handle
* IN OUT char **contentType : Type of content
* OUT int *contentLength : length of content
* OUT int *httpStatus : HTTP status returned on receiving a
* response message
* IN int timeout : time out value
*
* Description : Makes the HTTP GET message, connects to the peer,
* sends the HTTP GET request, gets the response and parses the
* response.
*
* Return : int;
* UPNP_E_SUCCESS - On Success ;
* UPNP_E_INVALID_PARAM - Invalid Paramters ;
* UPNP_E_OUTOF_MEMORY ;
* UPNP_E_SOCKET_ERROR ;
* UPNP_E_BAD_RESPONSE ;
*
* Note :
*
************************************************************************/
* Function: http_OpenHttpGet
*
* Parameters:
* IN const char *url_str: String as a URL
* IN OUT void **Handle: Pointer to buffer to store HTTP
* post handle
* IN OUT char **contentType: Type of content
* OUT int *contentLength: length of content
* OUT int *httpStatus: HTTP status returned on receiving a
* response message
* IN int timeout: time out value
*
* Description:
* Makes the HTTP GET message, connects to the peer,
* sends the HTTP GET request, gets the response and parses the
* response.
*
* Return: int
* UPNP_E_SUCCESS - On Success
* UPNP_E_INVALID_PARAM - Invalid Paramters
* UPNP_E_OUTOF_MEMORY
* UPNP_E_SOCKET_ERROR
* UPNP_E_BAD_RESPONSE
************************************************************************/
int http_OpenHttpGet(
IN const char *url_str,
IN OUT void **Handle,
IN OUT char **contentType,
OUT int *contentLength,
OUT int *httpStatus,
IN int timeout);
/************************************************************************
* Function: http_OpenHttpGetProxy
*
* Parameters:
* IN const char *url_str; String as a URL
* IN const char *proxy_str; String as a URL
* IN OUT void **Handle; Pointer to buffer to store HTTP
* post handle
* IN OUT char **contentType; Type of content
* OUT int *contentLength; length of content
* OUT int *httpStatus; HTTP status returned on receiving a
* response message
* IN int timeout: time out value
*
* Description:
* Makes the HTTP GET message, connects to the peer,
* sends the HTTP GET request, gets the response and parses the response.
* If a proxy URL is defined then the connection is made there.
*
* Return: int
* UPNP_E_SUCCESS - On Success
* UPNP_E_INVALID_PARAM - Invalid Paramters
* UPNP_E_OUTOF_MEMORY
* UPNP_E_SOCKET_ERROR
* UPNP_E_BAD_RESPONSE
************************************************************************/
int http_OpenHttpGetProxy(IN const char *url_str,
IN const char *proxy_str,
IN OUT void **Handle,
@@ -430,126 +444,134 @@ int http_OpenHttpGetProxy(IN const char *url_str,
/************************************************************************
* Function : http_SendStatusResponse
*
* Parameters :
* IN SOCKINFO *info : Socket information object
* IN int http_status_code : error code returned while making
* or sending the response message
* IN int request_major_version : request major version
* IN int request_minor_version : request minor version
*
* Description : Generate a response message for the status query and
* send the status response.
*
* Return : int;
* 0 -- success
* UPNP_E_OUTOF_MEMORY
* UPNP_E_SOCKET_WRITE
* UPNP_E_TIMEDOUT
*
* Note :
************************************************************************/
int http_SendStatusResponse( IN SOCKINFO *info, IN int http_status_code,
IN int request_major_version,
IN int request_minor_version );
* Function: http_SendStatusResponse
*
* Parameters:
* IN SOCKINFO *info; Socket information object
* IN int http_status_code; error code returned while making
* or sending the response message
* IN int request_major_version; request major version
* IN int request_minor_version; request minor version
*
* Description:
* Generate a response message for the status query and send the
* status response.
*
* Return: int
* 0 -- success
* UPNP_E_OUTOF_MEMORY
* UPNP_E_SOCKET_WRITE
* UPNP_E_TIMEDOUT
************************************************************************/
int http_SendStatusResponse(
IN SOCKINFO *info,
IN int http_status_code,
IN int request_major_version,
IN int request_minor_version );
/************************************************************************
* Function : http_MakeMessage
*
* Parameters :
* INOUT membuffer* buf : buffer with the contents of the
* message
* IN int http_major_version : HTTP major version
* IN int http_minor_version : HTTP minor version
* IN const char* fmt : Pattern format
* ... :
*
* Description : Generate an HTTP message based on the format that is
* specified in the input parameters.
*
* fmt types:
* 's': arg = const char* C_string
* 'b': arg1 = const char* buf; arg2 = size_t buf_length
* memory ptr
* 'c': (no args) appends CRLF "\r\n"
* 'd': arg = int number // appends decimal number
* 'h': arg = off_t number // appends off_t number
* 't': arg = time_t * gmt_time // appends time in RFC 1123 fmt
* 'D': (no args) appends HTTP DATE: header
* 'S': (no args) appends HTTP SERVER: header
* 'U': (no args) appends HTTP USER-AGENT: header
* 'C': (no args) appends a HTTP CONNECTION: close header
* depending on major,minor version
* 'N': arg1 = int content_length // content-length header
* 'Q': arg1 = http_method_t; arg2 = char* url;
* arg3 = int url_length // start line of request
* 'R': arg = int status_code // adds a response start line
* 'B': arg = int status_code
* appends content-length, content-type and HTML body for given code
* 'T': arg = char * content_type; format e.g: "text/html";
* content-type header
*
* Return : int;
* 0 - On Success
* UPNP_E_OUTOF_MEMORY
* UPNP_E_INVALID_URL;
*
* Note :
************************************************************************/
int http_MakeMessage( INOUT membuffer* buf,
IN int http_major_version,
IN int http_minor_version,
IN const char* fmt, ... );
* Function: http_MakeMessage
*
* Parameters:
* INOUT membuffer* buf; buffer with the contents of the
* message
* IN int http_major_version; HTTP major version
* IN int http_minor_version; HTTP minor version
* IN const char* fmt; Pattern format
* ...;
*
* Description:
* Generate an HTTP message based on the format that is specified
* in the input parameters.
*
* fmt types:
* 'B': arg = int status_code
* appends content-length, content-type and HTML body
* for given code
* 'b': arg1 = const char* buf;
* arg2 = size_t buf_length memory ptr
* 'C': (no args) appends a HTTP CONNECTION: close header
* depending on major,minor version
* 'c': (no args) appends CRLF "\r\n"
* 'D': (no args) appends HTTP DATE: header
* 'd': arg = int number // appends decimal number
* 'G': arg = range information // add range header
* 'h': arg = off_t number // appends off_t number
* 'K': (no args) // add chunky header
* 'N': arg1 = off_t content_length // content-length header
* 'q': arg1 = http_method_t // request start line and HOST header
* arg2 = (uri_type *)
* 'Q': arg1 = http_method_t; // start line of request
* arg2 = char* url;
* arg3 = size_t url_length
* 'R': arg = int status_code // adds a response start line
* 'S': (no args) appends HTTP SERVER: header
* 's': arg = const char* C_string
* 'T': arg = char * content_type; format
* e.g: "text/html"; content-type header
* 't': arg = time_t * gmt_time // appends time in RFC 1123 fmt
* 'U': (no args) appends HTTP USER-AGENT: header
* 'X': arg = const char useragent; "redsonic" HTTP X-User-Agent: useragent
*
* Return: int
* 0 - On Success
* UPNP_E_OUTOF_MEMORY
* UPNP_E_INVALID_URL
************************************************************************/
int http_MakeMessage(
INOUT membuffer* buf,
IN int http_major_version,
IN int http_minor_version,
IN const char* fmt, ... );
/************************************************************************
* Function : http_CalcResponseVersion
*
* Parameters :
* IN int request_major_vers : Request major version
* IN int request_minor_vers : Request minor version
* OUT int* response_major_vers : Response mojor version
* OUT int* response_minor_vers : Response minor version
*
* Description : Calculate HTTP response versions based on the request
* versions.
*
* Return : void
*
* Note :
************************************************************************/
* Function: http_CalcResponseVersion
*
* Parameters:
* IN int request_major_vers; Request major version
* IN int request_minor_vers; Request minor version
* OUT int* response_major_vers; Response mojor version
* OUT int* response_minor_vers; Response minor version
*
* Description:
* Calculate HTTP response versions based on the request versions.
*
* Return: void
************************************************************************/
void http_CalcResponseVersion(
IN int request_major_vers, IN int request_minor_vers,
OUT int* response_major_vers, OUT int* response_minor_vers );
IN int request_major_vers,
IN int request_minor_vers,
OUT int* response_major_vers,
OUT int* response_minor_vers );
/************************************************************************
* Function : http_OpenHttpGetEx
*
* Parameters :
* IN const char *url_str : String as a URL
* IN OUT void **Handle : Pointer to buffer to store HTTP
* post handle
* IN OUT char **contentType : Type of content
* OUT int *contentLength : length of content
* OUT int *httpStatus : HTTP status returned on receiving a
* response message
* IN int timeout : time out value
*
* Description : Makes the HTTP GET message, connects to the peer,
* sends the HTTP GET request, gets the response and parses the
* response.
*
* Return : int;
* UPNP_E_SUCCESS - On Success ;
* UPNP_E_INVALID_PARAM - Invalid Paramters ;
* UPNP_E_OUTOF_MEMORY ;
* UPNP_E_SOCKET_ERROR ;
* UPNP_E_BAD_RESPONSE ;
*
* Note :
*
************************************************************************/
* Function: http_OpenHttpGetEx
*
* Parameters:
* IN const char *url_str; String as a URL
* IN OUT void **Handle; Pointer to buffer to store HTTP
* post handle
* IN OUT char **contentType; Type of content
* OUT int *contentLength; length of content
* OUT int *httpStatus; HTTP status returned on receiving a
* response message
* IN int timeout; time out value
*
* Description:
* Makes the HTTP GET message, connects to the peer,
* sends the HTTP GET request, gets the response and parses the
* response.
*
* Return: int
* UPNP_E_SUCCESS - On Success
* UPNP_E_INVALID_PARAM - Invalid Paramters
* UPNP_E_OUTOF_MEMORY
* UPNP_E_SOCKET_ERROR
* UPNP_E_BAD_RESPONSE
************************************************************************/
int http_OpenHttpGetEx(IN const char *url_str,
IN OUT void **Handle,
IN OUT char **contentType,
@@ -559,19 +581,19 @@ int http_OpenHttpGetEx(IN const char *url_str,
IN int highRange,
IN int timeout);
/************************************************************************
* Function : get_sdk_info
*
* Parameters :
* OUT char *info ;
*
* Description : Returns the server information for the operating
* system
*
* Return : void ;
*
* Note :
************************************************************************/
* Function: get_sdk_info
*
* Parameters:
* OUT char *info; buffer to store the operating system information
*
* Description:
* Returns the server information for the operating system
*
* Return:
* UPNP_INLINE void
************************************************************************/
void get_sdk_info( OUT char *info );
#ifdef __cplusplus
@@ -580,3 +602,4 @@ void get_sdk_info( OUT char *info );
#endif // GENLIB_NET_HTTP_HTTPREADWRITE_H

View File

@@ -1,154 +1,150 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
//
///////////////////////////////////////////////////////////////////////////
/************************************************************************
*
* 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 MINISERVER_H
#define MINISERVER_H
#include "sock.h"
#include "httpparser.h"
extern SOCKET gMiniServerStopSock;
typedef struct MServerSockArray {
int miniServerSock; //socket for listening for miniserver
//requests
int miniServerStopSock; //socket for stopping miniserver
int ssdpSock; //socket for incoming advertisments and search requests
/* socket for listening for miniserver requests */
int miniServerSock;
/* socket for stopping miniserver */
int miniServerStopSock;
/* socket for incoming advertisments and search requests */
int ssdpSock;
int stopPort;
int miniServerPort;
int stopPort;
int miniServerPort;
CLIENTONLY(int ssdpReqSock;) //socket for sending search
//requests and receiving
// search replies
/* socket for sending search requests and receiving search replies */
CLIENTONLY(int ssdpReqSock;)
} MiniServerSockArray;
//typedef void (*MiniServerCallback) ( const char* document, int sockfd );
typedef void (*MiniServerCallback) ( IN http_parser_t *parser,
IN http_message_t* request,
IN SOCKINFO *info );
typedef void (*MiniServerCallback)(
IN http_parser_t *parser,
IN http_message_t* request,
IN SOCKINFO *info );
#ifdef __cplusplus
extern "C" {
#endif
/************************************************************************
* Function : SetHTTPGetCallback
*
* Parameters :
* MiniServerCallback callback ; - HTTP Callback to be invoked
*
* Description : Set HTTP Get Callback
*
* Return : void
*
* Note :
************************************************************************/
* Function: SetHTTPGetCallback
*
* Parameters:
* MiniServerCallback callback; - HTTP Callback to be invoked
*
* Description: Set HTTP Get Callback
*
* Return: void
************************************************************************/
void SetHTTPGetCallback( MiniServerCallback callback );
/************************************************************************
* Function : SetSoapCallback
*
* Parameters :
* MiniServerCallback callback ; - SOAP Callback to be invoked
*
* Description : Set SOAP Callback
*
* Return : void
*
* Note :
************************************************************************/
* Function: SetSoapCallback
*
* Parameters:
* MiniServerCallback callback; - SOAP Callback to be invoked
*
* Description: Set SOAP Callback
*
* Return: void
************************************************************************/
#ifdef INCLUDE_DEVICE_APIS
void SetSoapCallback( MiniServerCallback callback );
#else
#else /* INCLUDE_DEVICE_APIS */
static inline void SetSoapCallback( MiniServerCallback callback ) {}
#endif
#endif /* INCLUDE_DEVICE_APIS */
/************************************************************************
* Function : SetGenaCallback
*
* Parameters :
* MiniServerCallback callback ; - GENA Callback to be invoked
*
* Description : Set GENA Callback
*
* Return : void
*
* Note :
************************************************************************/
* Function: SetGenaCallback
*
* Parameters:
* MiniServerCallback callback; - GENA Callback to be invoked
*
* D6escription: Set GENA Callback
*
* Return: void
************************************************************************/
void SetGenaCallback( MiniServerCallback callback );
/************************************************************************
* Function : StartMiniServer
*
* Parameters :
* unsigned short listen_port ; Port on which the server listens for
* incoming connections
*
* Description : Initialize the sockets functionality for the
* Miniserver. Initialize a thread pool job to run the MiniServer
* and the job to the thread pool. If listen port is 0, port is
* dynamically picked
*
* Use timer mechanism to start the MiniServer, failure to meet the
* allowed delay aborts the attempt to launch the MiniServer.
*
* Return : int ;
* Actual port socket is bound to - On Success:
* A negative number UPNP_E_XXX - On Error
* Note :
************************************************************************/
* Function: StartMiniServer
*
* Parameters:
* unsigned short listen_port ; Port on which the server listens for
* incoming connections
*
* Description: Initialize the sockets functionality for the
* Miniserver. Initialize a thread pool job to run the MiniServer
* and the job to the thread pool. If listen port is 0, port is
* dynamically picked
*
* Use timer mechanism to start the MiniServer, failure to meet the
* allowed delay aborts the attempt to launch the MiniServer.
*
* Return: int;
* Actual port socket is bound to - On Success:
* A negative number UPNP_E_XXX - On Error
************************************************************************/
int StartMiniServer( unsigned short listen_port );
/************************************************************************
* Function : StopMiniServer
*
* Parameters :
* void ;
*
* Description : Stop and Shutdown the MiniServer and free socket
* resources.
*
* Return : int ;
* Always returns 0
*
* Note :
************************************************************************/
int StopMiniServer( void );
* Function: StopMiniServer
*
* Parameters:
* void;
*
* Description: Stop and Shutdown the MiniServer and free socket resources.
*
* Return : int;
* Always returns 0
************************************************************************/
int StopMiniServer();
#ifdef __cplusplus
} /* extern C */
#endif
#endif /* MINISERVER_H */

View File

@@ -56,88 +56,88 @@ struct SendInstruction
};
/************************************************************************
* Function: web_server_init
*
* Parameters:
* none
*
* Description: Initilialize the different documents. Initialize the
* memory for root directory for web server. Call to initialize global
* XML document. Sets bWebServerState to WEB_SERVER_ENABLED
*
* Returns:
* 0 - OK
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
* Function: web_server_init
*
* Parameters:
* none
*
* Description: Initilialize the different documents. Initialize the
* memory for root directory for web server. Call to initialize global
* XML document. Sets bWebServerState to WEB_SERVER_ENABLED
*
* Returns:
* 0 - OK
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
************************************************************************/
int web_server_init( void );
/************************************************************************
* Function: web_server_destroy
*
* Parameters:
* none
*
* Description: Release memory allocated for the global web server root
* directory and the global XML document
* Resets the flag bWebServerState to WEB_SERVER_DISABLED
*
* Returns:
* void
* Function: web_server_destroy
*
* Parameters:
* none
*
* Description: Release memory allocated for the global web server root
* directory and the global XML document
* Resets the flag bWebServerState to WEB_SERVER_DISABLED
*
* Returns:
* void
************************************************************************/
void web_server_destroy( void );
/************************************************************************
* Function: web_server_set_alias
*
* Parameters:
* alias_name: webserver name of alias; created by caller and freed by
* caller (doesn't even have to be malloc()d .)
* alias_content: the xml doc; this is allocated by the caller; and
* freed by the web server
* alias_content_length: length of alias body in bytes
* last_modified: time when the contents of alias were last
* changed (local time)
*
* Description: Replaces current alias with the given alias. To remove
* the current alias, set alias_name to NULL.
*
* Returns:
* 0 - OK
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
* Function: web_server_set_alias
*
* Parameters:
* alias_name: webserver name of alias; created by caller and freed by
* caller (doesn't even have to be malloc()d .)
* alias_content: the xml doc; this is allocated by the caller; and
* freed by the web server
* alias_content_length: length of alias body in bytes
* last_modified: time when the contents of alias were last
* changed (local time)
*
* Description: Replaces current alias with the given alias. To remove
* the current alias, set alias_name to NULL.
*
* Returns:
* 0 - OK
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
************************************************************************/
int web_server_set_alias( IN const char* alias_name,
IN const char* alias_content, IN size_t alias_content_length,
IN time_t last_modified );
/************************************************************************
* Function: web_server_set_root_dir
*
* Parameters:
* IN const char* root_dir ; String having the root directory for the
* document
*
* Description: Assign the path specfied by the IN const char* root_dir
* parameter to the global Document root directory. Also check for
* path names ending in '/'
*
* Returns:
* int
* Function: web_server_set_root_dir
*
* Parameters:
* IN const char* root_dir ; String having the root directory for the
* document
*
* Description: Assign the path specfied by the IN const char* root_dir
* parameter to the global Document root directory. Also check for
* path names ending in '/'
*
* Returns:
* int
************************************************************************/
int web_server_set_root_dir( IN const char* root_dir );
/************************************************************************
* Function: web_server_callback *
* *
* Parameters: *
* IN http_parser_t *parser, *
* INOUT http_message_t* req, *
* IN SOCKINFO *info *
* *
* Description: main entry point into web server; *
* handles HTTP GET and HEAD requests *
* *
* Returns: *
* void *
* Function: web_server_callback
*
* Parameters:
* IN http_parser_t *parser,
* INOUT http_message_t* req,
* IN SOCKINFO *info
*
* Description: main entry point into web server;
* handles HTTP GET and HEAD requests
*
* Returns:
* void
************************************************************************/
void web_server_callback( IN http_parser_t *parser, IN http_message_t* req, INOUT SOCKINFO *info );
@@ -148,3 +148,4 @@ void web_server_callback( IN http_parser_t *parser, IN http_message_t* req, INOU
#endif // GENLIB_NET_HTTP_WEBSERVER_H

View File

@@ -335,7 +335,7 @@ CreateServicePacket( IN int msg_type,
&buf, 1, 1,
"Q" "sssdc" "sdc" "ssc" "ssc" "ssc" "S" "Xc" "sscc",
HTTPMETHOD_NOTIFY, "*",
1, "HOST: ", SSDP_IP, ":", SSDP_PORT,
(size_t)1, "HOST: ", SSDP_IP, ":", SSDP_PORT,
"CACHE-CONTROL: max-age=", duration,
"LOCATION: ", location,
"NT: ", nt,

View File

@@ -43,56 +43,54 @@
#include "httpreadwrite.h"
#ifdef WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include "unixutil.h"
#include <winsock2.h>
#include <ws2tcpip.h>
#include "unixutil.h"
#endif
#define MAX_TIME_TOREAD 45
CLIENTONLY( SOCKET gSsdpReqSocket = 0;
)
CLIENTONLY( SOCKET gSsdpReqSocket = 0; )
void RequestHandler( );
Event ErrotEvt;
void RequestHandler();
Event ErrotEvt;
enum Listener { Idle, Stopping, Running };
enum Listener { Idle, Stopping, Running };
unsigned short ssdpStopPort;
unsigned short ssdpStopPort;
struct SSDPSockArray {
int ssdpSock; //socket for incoming advertisments and search requests
CLIENTONLY( int ssdpReqSock;
) //socket for sending search
//requests and receiving
// search replies
};
struct SSDPSockArray {
// socket for incoming advertisments and search requests
int ssdpSock;
// socket for sending search requests and receiving search replies
CLIENTONLY( int ssdpReqSock; )
};
#ifdef INCLUDE_DEVICE_APIS
#if EXCLUDE_SSDP == 0
/************************************************************************
* Function : AdvertiseAndReply
*
* Parameters:
* IN int AdFlag:
* -1 = Send shutdown,
* 0 = send reply,
* 1 = Send Advertisement
* IN UpnpDevice_Handle Hnd: Device handle
* IN enum SsdpSearchType SearchType:Search type for sending replies
* IN struct sockaddr_in *DestAddr:Destination address
* IN char *DeviceType:Device type
* IN char *DeviceUDN:Device UDN
* IN char *ServiceType:Service type
* IN int Exp:Advertisement age
*
* Description:
* This function sends SSDP advertisements, replies and shutdown messages.
*
* Returns: int
* UPNP_E_SUCCESS if successful else appropriate error
***************************************************************************/
* Function : AdvertiseAndReply
*
* Parameters:
* IN int AdFlag:
* -1 = Send shutdown,
* 0 = send reply,
* 1 = Send Advertisement
* IN UpnpDevice_Handle Hnd: Device handle
* IN enum SsdpSearchType SearchType:Search type for sending replies
* IN struct sockaddr_in *DestAddr:Destination address
* IN char *DeviceType:Device type
* IN char *DeviceUDN:Device UDN
* IN char *ServiceType:Service type
* IN int Exp:Advertisement age
*
* Description:
* This function sends SSDP advertisements, replies and shutdown messages.
*
* Returns: int
* UPNP_E_SUCCESS if successful else appropriate error
***************************************************************************/
int AdvertiseAndReply( IN int AdFlag,
IN UpnpDevice_Handle Hnd,
IN enum SsdpSearchType SearchType,
@@ -129,7 +127,6 @@ int AdvertiseAndReply( IN int AdFlag,
return UPNP_E_INVALID_HANDLE;
}
defaultExp = SInfo->MaxAge;
nodeList = NULL;
//get server info
@@ -398,21 +395,21 @@ int AdvertiseAndReply( IN int AdFlag,
} /****************** End of AdvertiseAndReply *********************/
#endif
#endif
#endif /* EXCLUDE_SSDP == 0 */
#endif /* INCLUDE_DEVICE_APIS */
/************************************************************************
* Function : Make_Socket_NoBlocking
*
* Parameters:
* IN int sock: socket
*
* Description:
* This function makes socket non-blocking.
*
* Returns: int
* 0 if successful else -1
***************************************************************************/
* Function : Make_Socket_NoBlocking
*
* Parameters:
* IN int sock: socket
*
* Description:
* This function makes socket non-blocking.
*
* Returns: int
* 0 if successful else -1
***************************************************************************/
int
Make_Socket_NoBlocking( int sock )
{
@@ -431,20 +428,20 @@ Make_Socket_NoBlocking( int sock )
}
/************************************************************************
* Function : unique_service_name
*
* Parameters:
* IN char *cmd: Service Name string
* OUT SsdpEvent *Evt: The SSDP event structure partially filled
* by all the function.
*
* Description:
* This function fills the fields of the event structure like DeviceType,
* Device UDN and Service Type
*
* Returns: int
* 0 if successful else -1
***************************************************************************/
* Function : unique_service_name
*
* Parameters:
* IN char *cmd: Service Name string
* OUT SsdpEvent *Evt: The SSDP event structure partially filled
* by all the function.
*
* Description:
* This function fills the fields of the event structure like DeviceType,
* Device UDN and Service Type
*
* Returns: int
* 0 if successful else -1
***************************************************************************/
int
unique_service_name( IN char *cmd,
IN SsdpEvent * Evt )
@@ -526,18 +523,18 @@ unique_service_name( IN char *cmd,
}
/************************************************************************
* Function : ssdp_request_type1
*
* Parameters:
* IN char *cmd: command came in the ssdp request
*
* Description:
* This function figures out the type of the SSDP search in the
* in the request.
*
* Returns: enum SsdpSearchType
* return appropriate search type else returns SSDP_ERROR
***************************************************************************/
* Function : ssdp_request_type1
*
* Parameters:
* IN char *cmd: command came in the ssdp request
*
* Description:
* This function figures out the type of the SSDP search in the
* in the request.
*
* Returns: enum SsdpSearchType
* return appropriate search type else returns SSDP_ERROR
***************************************************************************/
enum SsdpSearchType
ssdp_request_type1( IN char *cmd )
{
@@ -562,20 +559,20 @@ ssdp_request_type1( IN char *cmd )
}
/************************************************************************
* Function : ssdp_request_type
*
* Parameters:
* IN char *cmd: command came in the ssdp request
* OUT SsdpEvent *Evt: The event structure partially filled by
* this function.
*
* Description:
* This function starts filling the SSDP event structure based upon the
* request received.
*
* Returns: int
* 0 on success; -1 on error
***************************************************************************/
* Function : ssdp_request_type
*
* Parameters:
* IN char *cmd: command came in the ssdp request
* OUT SsdpEvent *Evt: The event structure partially filled by
* this function.
*
* Description:
* This function starts filling the SSDP event structure based upon the
* request received.
*
* Returns: int
* 0 on success; -1 on error
***************************************************************************/
int
ssdp_request_type( IN char *cmd,
OUT SsdpEvent * Evt )
@@ -593,18 +590,18 @@ ssdp_request_type( IN char *cmd,
}
/************************************************************************
* Function : free_ssdp_event_handler_data
*
* Parameters:
* IN void *the_data: ssdp_thread_data structure. This structure contains
* SSDP request message.
*
* Description:
* This function frees the ssdp request
*
* Returns: VOID
*
***************************************************************************/
* Function : free_ssdp_event_handler_data
*
* Parameters:
* IN void *the_data: ssdp_thread_data structure. This structure contains
* SSDP request message.
*
* Description:
* This function frees the ssdp request
*
* Returns: VOID
*
***************************************************************************/
static void
free_ssdp_event_handler_data( void *the_data )
{
@@ -620,18 +617,18 @@ free_ssdp_event_handler_data( void *the_data )
}
/************************************************************************
* Function : valid_ssdp_msg
*
* Parameters:
* IN void *the_data: ssdp_thread_data structure. This structure contains
* SSDP request message.
*
* Description:
* This function do some quick checking of the ssdp msg
*
* Returns: xboolean
* returns TRUE if msg is valid else FALSE
***************************************************************************/
* Function : valid_ssdp_msg
*
* Parameters:
* IN void *the_data: ssdp_thread_data structure. This structure contains
* SSDP request message.
*
* Description:
* This function do some quick checking of the ssdp msg
*
* Returns: xboolean
* returns TRUE if msg is valid else FALSE
***************************************************************************/
static UPNP_INLINE xboolean
valid_ssdp_msg( IN http_message_t * hmsg )
{
@@ -661,19 +658,19 @@ valid_ssdp_msg( IN http_message_t * hmsg )
}
/************************************************************************
* Function : start_event_handler
*
* Parameters:
* IN void *the_data: ssdp_thread_data structure. This structure contains
* SSDP request message.
*
* Description:
* This function parses the message and dispatches it to a handler
* which handles the ssdp request msg
*
* Returns: int
* 0 if successful -1 if error
***************************************************************************/
* Function : start_event_handler
*
* Parameters:
* IN void *the_data: ssdp_thread_data structure. This structure contains
* SSDP request message.
*
* Description:
* This function parses the message and dispatches it to a handler
* which handles the ssdp request msg
*
* Returns: int
* 0 if successful -1 if error
***************************************************************************/
static UPNP_INLINE int
start_event_handler( void *Data )
{
@@ -713,18 +710,18 @@ start_event_handler( void *Data )
}
/************************************************************************
* Function : ssdp_event_handler_thread
*
* Parameters:
* IN void *the_data: ssdp_thread_data structure. This structure contains
* SSDP request message.
*
* Description:
* This function is a thread that handles SSDP requests.
*
* Returns: void
*
***************************************************************************/
* Function : ssdp_event_handler_thread
*
* Parameters:
* IN void *the_data: ssdp_thread_data structure. This structure contains
* SSDP request message.
*
* Description:
* This function is a thread that handles SSDP requests.
*
* Returns: void
*
***************************************************************************/
static void
ssdp_event_handler_thread( void *the_data )
{
@@ -737,8 +734,7 @@ ssdp_event_handler_thread( void *the_data )
// send msg to device or ctrlpt
if( ( hmsg->method == HTTPMETHOD_NOTIFY ) ||
( hmsg->request_method == HTTPMETHOD_MSEARCH ) ) {
CLIENTONLY( ssdp_handle_ctrlpt_msg( hmsg, &data->dest_addr,
FALSE, NULL ););
CLIENTONLY( ssdp_handle_ctrlpt_msg( hmsg, &data->dest_addr, FALSE, NULL );)
} else {
ssdp_handle_device_request( hmsg, &data->dest_addr );
}
@@ -748,17 +744,17 @@ ssdp_event_handler_thread( void *the_data )
}
/************************************************************************
* Function : readFromSSDPSocket
*
* Parameters:
* IN SOCKET socket: SSDP socket
*
* Description:
* This function reads the data from the ssdp socket.
*
* Returns: void
*
***************************************************************************/
* Function : readFromSSDPSocket
*
* Parameters:
* IN SOCKET socket: SSDP socket
*
* Description:
* This function reads the data from the ssdp socket.
*
* Returns: void
*
***************************************************************************/
void
readFromSSDPSocket( SOCKET socket )
{
@@ -845,50 +841,51 @@ readFromSSDPSocket( SOCKET socket )
}
/************************************************************************
* Function : get_ssdp_sockets
*
* Parameters:
* OUT MiniServerSockArray *out: Arrays of SSDP sockets
*
* Description:
* This function creates the ssdp sockets. It set their option to listen
* for multicast traffic.
*
* Returns: int
* return UPNP_E_SUCCESS if successful else returns appropriate error
***************************************************************************/
* Function : get_ssdp_sockets
*
* Parameters:
* OUT MiniServerSockArray *out: Arrays of SSDP sockets
*
* Description:
* This function creates the ssdp sockets. It set their option to listen
* for multicast traffic.
*
* Returns: int
* return UPNP_E_SUCCESS if successful else returns appropriate error
***************************************************************************/
int
get_ssdp_sockets( MiniServerSockArray * out )
{
SOCKET ssdpSock;
CLIENTONLY( SOCKET ssdpReqSock; )
int onOff = 1;
u_char ttl = 4;
struct ip_mreq ssdpMcastAddr;
struct sockaddr_in ssdpAddr;
int option = 1;
struct in_addr addr;
SOCKET ssdpSock;
#if INCLUDE_CLIENT_APIS
SOCKET ssdpReqSock;
CLIENTONLY(
if( ( ssdpReqSock = socket( AF_INET, SOCK_DGRAM, 0 ) ) == UPNP_INVALID_SOCKET ) {
UpnpPrintf( UPNP_CRITICAL,
SSDP, __FILE__, __LINE__,
"Error in socket operation !!!\n" );
return UPNP_E_OUTOF_SOCKET;
}
setsockopt( ssdpReqSock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof( ttl ) );
// just do it, regardless if fails or not.
Make_Socket_NoBlocking( ssdpReqSock );
gSsdpReqSocket = ssdpReqSock; )
// END CLIENTONLY
gSsdpReqSocket = ssdpReqSock;
#endif /* INCLUDE_CLIENT_APIS */
if( ( ssdpSock = socket( AF_INET, SOCK_DGRAM, 0 ) ) == UPNP_INVALID_SOCKET ) {
UpnpPrintf( UPNP_CRITICAL,
SSDP, __FILE__, __LINE__,
"Error in socket operation !!!\n" );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ); )
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ); )
return UPNP_E_OUTOF_SOCKET;
}
@@ -898,26 +895,28 @@ CLIENTONLY(
UpnpPrintf( UPNP_CRITICAL,
SSDP, __FILE__, __LINE__,
"Error in set reuse addr !!!\n" );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ); )
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ); )
shutdown( ssdpSock, SD_BOTH );
UpnpCloseSocket( ssdpSock );
return UPNP_E_SOCKET_ERROR;
}
#ifdef __FreeBSD__
#if defined(__FreeBSD__) || defined(__OSX__) || defined(__APPLE__)
if( setsockopt( ssdpSock, SOL_SOCKET, SO_REUSEPORT,
( char * )&onOff, sizeof( onOff ) ) != 0 ) {
UpnpPrintf( UPNP_CRITICAL,
SSDP, __FILE__, __LINE__,
"Error in set reuse port !!!\n" );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ); )
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ); )
shutdown( ssdpSock, SD_BOTH );
UpnpCloseSocket( ssdpSock );
return UPNP_E_SOCKET_ERROR;
}
#endif
#endif /* __FreeBSD__ */
memset( ( void * )&ssdpAddr, 0, sizeof( struct sockaddr_in ) );
ssdpAddr.sin_family = AF_INET;
@@ -931,8 +930,9 @@ CLIENTONLY(
"Error in binding !!!\n" );
shutdown( ssdpSock, SD_BOTH );
UpnpCloseSocket( ssdpSock );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ); )
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ); )
return UPNP_E_SOCKET_BIND;
}
@@ -945,9 +945,10 @@ CLIENTONLY(
SSDP, __FILE__, __LINE__,
"Error in joining" " multicast group !!!\n" );
shutdown( ssdpSock, SD_BOTH );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ); )
UpnpCloseSocket( ssdpSock );
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ); )
return UPNP_E_SOCKET_ERROR;
}
@@ -961,7 +962,7 @@ CLIENTONLY(
/* This is probably not a critical error, so let's continue. */
}
// result is not checked becuase it will fail in WinMe and Win9x.
/* result is not checked becuase it will fail in WinMe and Win9x. */
setsockopt( ssdpSock, IPPROTO_IP,
IP_MULTICAST_TTL, &ttl, sizeof( ttl ) );
if( setsockopt( ssdpSock, SOL_SOCKET, SO_BROADCAST,
@@ -970,16 +971,18 @@ CLIENTONLY(
SSDP, __FILE__, __LINE__,
"Error in setting broadcast !!!\n" );
shutdown( ssdpSock, SD_BOTH );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ); )
UpnpCloseSocket( ssdpSock );
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ); )
return UPNP_E_NETWORK_ERROR;
}
CLIENTONLY( out->ssdpReqSock = ssdpReqSock; );
CLIENTONLY( out->ssdpReqSock = ssdpReqSock; )
out->ssdpSock = ssdpSock;
return UPNP_E_SUCCESS;
}
#endif // EXCLUDE_SSDP
#endif /* EXCLUDE_SSDP */