Compare commits
8 Commits
main
...
release-1.
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ba837a528f | ||
![]() |
078f3f8faf | ||
![]() |
1eeaf99b83 | ||
![]() |
f6dd5062fe | ||
![]() |
7d4a610b93 | ||
![]() |
0a074d1989 | ||
![]() |
0475a46680 | ||
![]() |
2a76749682 |
167
ChangeLog
167
ChangeLog
@ -1,3 +1,164 @@
|
|||||||
|
*******************************************************************************
|
||||||
|
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
|
||||||
|
*******************************************************************************
|
||||||
|
|
||||||
|
2007-11-07 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||||
|
* SF Bug Tracker [ 1825278 ] AdvertiseAndReply sleeps with handle lock out
|
||||||
|
Applied patch from Alex (afaucher) to change some write locks to read
|
||||||
|
locks.
|
||||||
|
|
||||||
|
2007-11-06 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||||
|
* Adjusting libtool library numbers to reflect the last changes.
|
||||||
|
|
||||||
|
2007-11-06 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||||
|
* SF Bug Tracker [ 1825278 ] AdvertiseAndReply sleeps with handle lock out
|
||||||
|
GlobalHndMutex, which was a mutex is now GlobalHndRWLock, which is a
|
||||||
|
rwlock. HandleLock() is mapped to HandleWriteLock() while all other
|
||||||
|
instances have not been checked. One instance in AdvertiseAndReply()
|
||||||
|
has been changed to HandleReadLock(). Thanks to Alex (afaucher) for the
|
||||||
|
bug report and suggestions.
|
||||||
|
|
||||||
|
2007-11-06 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||||
|
* Added support for rwlocks.
|
||||||
|
|
||||||
|
2007-11-05 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||||
|
* SF Bug Tracker [ 1825929 ] woker thread still alive after UpnpFinish()
|
||||||
|
Submitted By: Luke Kim - nereusuj
|
||||||
|
Worker thread still alive after calling UpnpFinish() because
|
||||||
|
ThreadPoolShutdown() is in the #ifdef DEBUG block.
|
||||||
|
421
|
||||||
|
422 #ifdef DEBUG
|
||||||
|
423 ThreadPoolShutdown( &gSendThreadPool );
|
||||||
|
424 ThreadPoolShutdown( &gRecvThreadPool );
|
||||||
|
|
||||||
|
2007-08-28 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||||
|
* Changed the calls to virtualDirCallback.open(filename, UPNP_WRITE)
|
||||||
|
to (virtualDirCallback.open)(filename, UPNP_WRITE) (notice the
|
||||||
|
parenthesis) due to a change in glibc that produces compilation
|
||||||
|
errors.
|
||||||
|
|
||||||
|
2007-08-28 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||||
|
* Initialization of the "randomness" struct so that valgrind does not
|
||||||
|
complain.
|
||||||
|
|
||||||
|
2007-08-06 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||||
|
* Merge of patch submitted By Keith Brindley - brindlk
|
||||||
|
SF Bug Tracker [ 1762758 ] Seek not working for large files
|
||||||
|
Problem:
|
||||||
|
Requests from the uPnP client to seek to a position beyond 2GB in a large
|
||||||
|
file are handled as a request to see from the 2GB point.
|
||||||
|
|
||||||
|
Impact:
|
||||||
|
Varies depending on client. The Xbox 360 kills the connection when it
|
||||||
|
realises.
|
||||||
|
|
||||||
|
Solution:
|
||||||
|
GetNextRange function (webserver.c) is updated to handle large file sizes.
|
||||||
|
Fix should also recognise when built on a 32bit platform rather than 64 and
|
||||||
|
handle accordingly.
|
||||||
|
|
||||||
|
2007-08-05 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||||
|
* Merge of Mac OS X patch from Stéphane Corthésy (davelopper),
|
||||||
|
SF Bug Tracker [ 1686420 ] Modifications for MacOSX.
|
||||||
|
Some of the proposed changes were already done by Rene Hexel's patch.
|
||||||
|
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
Version 1.6.0
|
Version 1.6.0
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
@ -52,6 +213,10 @@ Version 1.6.0
|
|||||||
an interface change in the library and the minor library version was
|
an interface change in the library and the minor library version was
|
||||||
bumped. Also, the libtool library numbers were changed accordingly.
|
bumped. Also, the libtool library numbers were changed accordingly.
|
||||||
|
|
||||||
|
*******************************************************************************
|
||||||
|
Version 1.4.7
|
||||||
|
*******************************************************************************
|
||||||
|
|
||||||
2007-05-26 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
2007-05-26 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||||
* Added support for the Basic Device
|
* Added support for the Basic Device
|
||||||
(http://www.upnp.org/standardizeddcps/basic.asp) as suggested by
|
(http://www.upnp.org/standardizeddcps/basic.asp) as suggested by
|
||||||
@ -269,7 +434,7 @@ Version 1.4.2
|
|||||||
2007-01-23 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
2007-01-23 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||||
|
|
||||||
* SF Tracker [ 1634922 ] Support for large files (>= 2 GiB), part 2
|
* 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
|
Summary: This patch hopefully fixes the remaining types and related
|
||||||
code to enable files >= 2 GiB to be streamed. Jonathan claims to have
|
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.
|
tested this with a patched version of ushare-0.9.8 and a D-Link DSM-520.
|
||||||
|
20
THANKS
20
THANKS
@ -6,31 +6,43 @@ suggesting various improvements or submitting actual code.
|
|||||||
Here is a list of these people. Help us keep it complete and
|
Here is a list of these people. Help us keep it complete and
|
||||||
exempt of errors.
|
exempt of errors.
|
||||||
|
|
||||||
|
- Alex (afaucher)
|
||||||
- Arno Willig
|
- Arno Willig
|
||||||
- Bob Ciora
|
- Bob Ciora
|
||||||
- Chaos
|
- Chaos
|
||||||
|
- Chris Pickel
|
||||||
- Craig Nelson
|
- Craig Nelson
|
||||||
- David Maass
|
- David Maass
|
||||||
- Emil Ljungdahl
|
- Emil Ljungdahl
|
||||||
- Erik Johansson
|
- Erik Johansson
|
||||||
- Eric Tanguy
|
- Eric Tanguy
|
||||||
- Erwan Velu
|
- Erwan Velu
|
||||||
|
- Eugene Christensen
|
||||||
|
- Fabrice Fontaine
|
||||||
- Fredrik Svensson
|
- Fredrik Svensson
|
||||||
- Glen Masgai
|
- Glen Masgai
|
||||||
|
- Hartmut Holzgraefe - hholzgra
|
||||||
|
- Ingo Hofmann
|
||||||
- Jiri Zouhar
|
- Jiri Zouhar
|
||||||
- John Dennis
|
- John Dennis
|
||||||
- Jonathan (no_dice)
|
- Jonathan Casiot (no_dice)
|
||||||
|
- Josh Carroll
|
||||||
|
- Keith Brindley
|
||||||
- Leuk_He
|
- Leuk_He
|
||||||
- Loigu
|
- Loigu
|
||||||
- Luke Kim
|
- Luke Kim
|
||||||
- Marcelo Roberto Jimenez
|
- Marcelo Roberto Jimenez (mroberto)
|
||||||
- Markus Strobl
|
- Markus Strobl
|
||||||
- Nektarios K. Papadopoulos
|
- Nektarios K. Papadopoulos (npapadop)
|
||||||
- Oskar Liljeblad
|
- Oskar Liljeblad
|
||||||
- Michael (Oxy)
|
- Michael (oxygenic)
|
||||||
- Paul Vixie
|
- Paul Vixie
|
||||||
|
- Peter Hartley
|
||||||
- Rene Hexel
|
- Rene Hexel
|
||||||
|
- Robert Gingher (robsbox)
|
||||||
- Siva Chandran
|
- Siva Chandran
|
||||||
|
- Stéphane Corthésy
|
||||||
|
- Steve Bresson
|
||||||
- Timothy Redaelli
|
- Timothy Redaelli
|
||||||
- Titus Winters
|
- Titus Winters
|
||||||
|
|
||||||
|
@ -261,18 +261,18 @@
|
|||||||
|
|
||||||
/** @name Other debugging features
|
/** @name Other debugging features
|
||||||
The UPnP SDK contains other features to aid in debugging:
|
The UPnP SDK contains other features to aid in debugging:
|
||||||
see <upnp/upnpdebug.h>
|
see <upnp/inc/upnpdebug.h>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DEBUG_ALL 1
|
#define DEBUG_ALL 1
|
||||||
#define DEBUG_SSDP 0
|
#define DEBUG_SSDP 0
|
||||||
#define DEBUG_SOAP 0
|
#define DEBUG_SOAP 0
|
||||||
#define DEBUG_GENA 0
|
#define DEBUG_GENA 0
|
||||||
#define DEBUG_TPOOL 0
|
#define DEBUG_TPOOL 0
|
||||||
#define DEBUG_MSERV 0
|
#define DEBUG_MSERV 0
|
||||||
#define DEBUG_DOM 0
|
#define DEBUG_DOM 0
|
||||||
#define DEBUG_HTTP 0
|
#define DEBUG_HTTP 0
|
||||||
#define DEBUG_API 0
|
#define DEBUG_API 0
|
||||||
|
|
||||||
//@} // Compile time configuration options
|
//@} // Compile time configuration options
|
||||||
|
|
||||||
|
235
configure.ac
235
configure.ac
@ -4,73 +4,154 @@
|
|||||||
#
|
#
|
||||||
# Process this file with autoconf to produce a configure script.
|
# Process this file with autoconf to produce a configure script.
|
||||||
#
|
#
|
||||||
# (C) Copyright 2005-2006 Rémi Turboult <r3mi@users.sourceforge.net>
|
# (C) Copyright 2005-2007 Rémi Turboult <r3mi@users.sourceforge.net>
|
||||||
#
|
#
|
||||||
|
|
||||||
AC_PREREQ(2.60)
|
AC_PREREQ(2.60)
|
||||||
|
|
||||||
AC_INIT([libupnp], [1.6.0], [mroberto@users.sourceforge.net])
|
AC_INIT([libupnp], [1.6.5], [mroberto@users.sourceforge.net])
|
||||||
# *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 # *Independently* of the above libupnp package version, the libtool version
|
||||||
# "current:revision:age" (this is NOT the same as the package version), where:
|
dnl # of the 3 libraries need to be updated whenever there is a change released:
|
||||||
# - library code modified: revision++
|
dnl # "current:revision:age" (this is NOT the same as the package version),
|
||||||
# - interfaces changed/added/removed: current++ and revision=0
|
dnl # where:
|
||||||
# - interfaces added: age++
|
dnl # - library code modified: revision++
|
||||||
# - interfaces removed: age=0
|
dnl # - interfaces changed/added/removed: current++ and revision=0
|
||||||
# *please update only once, before a formal release, not for each change*
|
dnl # - interfaces added: age++
|
||||||
#
|
dnl # - interfaces removed: age=0
|
||||||
# For release 1.4.1, we had:
|
dnl # *please update only once, before a formal release, not for each change*
|
||||||
#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 # Release 1.4.1:
|
||||||
#
|
dnl #AC_SUBST([LT_VERSION_IXML], [2:2:0])
|
||||||
# "current:revision:age"
|
dnl #AC_SUBST([LT_VERSION_THREADUTIL], [2:2:0])
|
||||||
#
|
dnl #AC_SUBST([LT_VERSION_UPNP], [2:2:0])
|
||||||
# - Code has changed in ixml
|
dnl #
|
||||||
# revision: 2 -> 3
|
dnl ############################################################################
|
||||||
# - Code has changed in threadutil
|
dnl # Release 1.4.6:
|
||||||
# revision: 2 -> 3
|
dnl # "current:revision:age"
|
||||||
# - Interface added in threadutil
|
dnl #
|
||||||
# current: 2 -> 3
|
dnl # - Code has changed in ixml
|
||||||
# revisiion: 3 -> 0
|
dnl # revision: 2 -> 3
|
||||||
# age: 0 -> 1
|
dnl # - Code has changed in threadutil
|
||||||
# - Code has changed in upnp
|
dnl # revision: 2 -> 3
|
||||||
# revision: 2 -> 3
|
dnl # - Interface added in threadutil
|
||||||
#
|
dnl # current: 2 -> 3
|
||||||
# For release 1.4.6, we had:
|
dnl # revisiion: 3 -> 0
|
||||||
#AC_SUBST([LT_VERSION_IXML], [2:3:0])
|
dnl # age: 0 -> 1
|
||||||
#AC_SUBST([LT_VERSION_THREADUTIL], [3:0:1])
|
dnl # - Code has changed in upnp
|
||||||
#AC_SUBST([LT_VERSION_UPNP], [2:3:0])
|
dnl # revision: 2 -> 3
|
||||||
#
|
dnl #
|
||||||
# "current:revision:age"
|
dnl #AC_SUBST([LT_VERSION_IXML], [2:3:0])
|
||||||
#
|
dnl #AC_SUBST([LT_VERSION_THREADUTIL], [3:0:1])
|
||||||
# - Code has changed in ixml
|
dnl #AC_SUBST([LT_VERSION_UPNP], [2:3:0])
|
||||||
# revision: 3 -> 4
|
dnl #
|
||||||
# - Code has changed in threadutil
|
dnl ############################################################################
|
||||||
# revision: 0 -> 1
|
dnl # Release 1.6.0:
|
||||||
# - Code has changed in upnp
|
dnl # "current:revision:age"
|
||||||
# revision: 3 -> 4
|
dnl #
|
||||||
# - Interface changed in upnp
|
dnl # - Code has changed in ixml
|
||||||
# current: 2 -> 3
|
dnl # revision: 3 -> 4
|
||||||
# revision: 4 -> 0
|
dnl # - Code has changed in threadutil
|
||||||
# - Interface removed in upnp
|
dnl # revision: 0 -> 1
|
||||||
# age: 0 -> 0
|
dnl # - Code has changed in upnp
|
||||||
#
|
dnl # revision: 3 -> 4
|
||||||
# For release 1.6.0, we had:
|
dnl # - Interface changed in upnp
|
||||||
#AC_SUBST([LT_VERSION_IXML], [2:4:0])
|
dnl # current: 2 -> 3
|
||||||
#AC_SUBST([LT_VERSION_THREADUTIL], [3:1:1])
|
dnl # revision: 4 -> 0
|
||||||
#AC_SUBST([LT_VERSION_UPNP], [3:0: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_IXML], [2:4:0])
|
||||||
AC_SUBST([LT_VERSION_THREADUTIL], [3:1:1])
|
AC_SUBST([LT_VERSION_THREADUTIL], [4:2:2])
|
||||||
AC_SUBST([LT_VERSION_UPNP], [3:0:0])
|
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_AUX_DIR([build-aux])
|
||||||
AC_CONFIG_MACRO_DIR(m4)
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
AC_CONFIG_SRCDIR(upnp/inc/upnp.h)
|
AC_CONFIG_SRCDIR([upnp/inc/upnp.h])
|
||||||
|
|
||||||
|
|
||||||
AM_INIT_AUTOMAKE([1.8 -Wall foreign subdir-objects dist-bzip2])
|
AM_INIT_AUTOMAKE([1.8 -Wall foreign subdir-objects dist-bzip2])
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Get canonical host names in host and host_os
|
# Get canonical host names in host and host_os
|
||||||
#
|
#
|
||||||
@ -95,8 +176,7 @@ AC_REVISION([$Revision: 1.11 $])
|
|||||||
upnpmaj=`echo "$PACKAGE_VERSION" | sed 's/\..*//' `
|
upnpmaj=`echo "$PACKAGE_VERSION" | sed 's/\..*//' `
|
||||||
upnpmin=[`echo "$PACKAGE_VERSION" | sed 's/^[^.]\.// ; s/[^0-9].*$//' `]
|
upnpmin=[`echo "$PACKAGE_VERSION" | sed 's/^[^.]\.// ; s/[^0-9].*$//' `]
|
||||||
upnppatch=[`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",
|
AC_DEFINE_UNQUOTED([UPNP_VERSION_STRING], "$PACKAGE_VERSION", [see upnpconfig.h])
|
||||||
[see upnpconfig.h])
|
|
||||||
AC_DEFINE_UNQUOTED([UPNP_VERSION_MAJOR], $upnpmaj, [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_MINOR], $upnpmin, [see upnpconfig.h])
|
||||||
AC_DEFINE_UNQUOTED([UPNP_VERSION_PATCH], $upnppatch, [see upnpconfig.h])
|
AC_DEFINE_UNQUOTED([UPNP_VERSION_PATCH], $upnppatch, [see upnpconfig.h])
|
||||||
@ -118,7 +198,6 @@ fi
|
|||||||
#
|
#
|
||||||
# Check for libupnp subsets
|
# Check for libupnp subsets
|
||||||
#
|
#
|
||||||
|
|
||||||
RT_BOOL_ARG_ENABLE([client], [yes], [control point code (client)])
|
RT_BOOL_ARG_ENABLE([client], [yes], [control point code (client)])
|
||||||
if test "x$enable_client" = xyes ; then
|
if test "x$enable_client" = xyes ; then
|
||||||
AC_DEFINE(UPNP_HAVE_CLIENT, 1, [see upnpconfig.h])
|
AC_DEFINE(UPNP_HAVE_CLIENT, 1, [see upnpconfig.h])
|
||||||
@ -152,11 +231,13 @@ fi
|
|||||||
RT_BOOL_ARG_ENABLE([samples], [yes], [compilation of upnp/sample/ code])
|
RT_BOOL_ARG_ENABLE([samples], [yes], [compilation of upnp/sample/ code])
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
# doc installation
|
# doc installation
|
||||||
# autoconf >= 2.60 already defines ${docdir}, but we will not use its
|
# autoconf >= 2.60 already defines ${docdir}, but we will not use its
|
||||||
# default value, which is ${datarootdir}/doc/${PACKAGE_TARNAME}.
|
# default value, which is ${datarootdir}/doc/${PACKAGE_TARNAME}.
|
||||||
# That would give us ${datarootdir}/doc/libupnp, and we want the package
|
# That would give us ${datarootdir}/doc/libupnp, and we want the package
|
||||||
# version on that.
|
# version on that.
|
||||||
|
#
|
||||||
docdir="${datadir}/doc/${PACKAGE_NAME}-${PACKAGE_VERSION}"
|
docdir="${datadir}/doc/${PACKAGE_NAME}-${PACKAGE_VERSION}"
|
||||||
AC_MSG_CHECKING([for documentation directory])
|
AC_MSG_CHECKING([for documentation directory])
|
||||||
AC_ARG_WITH(
|
AC_ARG_WITH(
|
||||||
@ -171,7 +252,9 @@ AS_HELP_STRING(
|
|||||||
[],
|
[],
|
||||||
[with_documentation=no])
|
[with_documentation=no])
|
||||||
|
|
||||||
|
#
|
||||||
# If something has been entered after an equal sign, assume it is the directory
|
# 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
|
if test x"$with_documentation" != xyes -a x"$with_documentation" != xno; then
|
||||||
docdir="$with_documentation"
|
docdir="$with_documentation"
|
||||||
fi
|
fi
|
||||||
@ -257,7 +340,6 @@ AC_CHECK_HEADERS(
|
|||||||
# Checks for typedefs, structures, and compiler characteristics
|
# Checks for typedefs, structures, and compiler characteristics
|
||||||
#
|
#
|
||||||
AC_C_CONST
|
AC_C_CONST
|
||||||
AC_TYPE_SIZE_T
|
|
||||||
TYPE_SOCKLEN_T
|
TYPE_SOCKLEN_T
|
||||||
|
|
||||||
|
|
||||||
@ -272,9 +354,40 @@ AC_CHECK_FUNCS(ftime,, [AC_CHECK_LIB(compat, ftime)])
|
|||||||
#
|
#
|
||||||
# Checks for POSIX Threads
|
# Checks for POSIX Threads
|
||||||
#
|
#
|
||||||
|
echo "--------------------------- pthread stuff -------------------------------------"
|
||||||
ACX_PTHREAD(
|
ACX_PTHREAD(
|
||||||
[],
|
[],
|
||||||
[AC_MSG_ERROR([POSIX threads are required to build this program])])
|
[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([
|
AC_CONFIG_FILES([
|
||||||
|
4
docs/dist/Makefile.am
vendored
4
docs/dist/Makefile.am
vendored
@ -39,7 +39,7 @@ EXTRA_DIST = \
|
|||||||
./html/upnp/UPNP_E_SOCKET_ERROR-208.html \
|
./html/upnp/UPNP_E_SOCKET_ERROR-208.html \
|
||||||
./html/upnp/UPNP_E_CANCELED-210.html \
|
./html/upnp/UPNP_E_CANCELED-210.html \
|
||||||
./html/upnp/UPNP_E_SUBSCRIBE_UNACCEPTED-301.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_NOTIFY_UNACCEPTED-303.html \
|
||||||
./html/upnp/UPNP_E_INVALID_ARGUMENT-501.html \
|
./html/upnp/UPNP_E_INVALID_ARGUMENT-501.html \
|
||||||
./html/upnp/UPNP_E_FILE_NOT_FOUND-502.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_SOCKET_ERROR-208.html \
|
||||||
./html/upnp/UPNP_E_CANCELED-210.html \
|
./html/upnp/UPNP_E_CANCELED-210.html \
|
||||||
./html/upnp/UPNP_E_SUBSCRIBE_UNACCEPTED-301.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_NOTIFY_UNACCEPTED-303.html \
|
||||||
./html/upnp/UPNP_E_INVALID_ARGUMENT-501.html \
|
./html/upnp/UPNP_E_INVALID_ARGUMENT-501.html \
|
||||||
./html/upnp/UPNP_E_FILE_NOT_FOUND-502.html \
|
./html/upnp/UPNP_E_FILE_NOT_FOUND-502.html \
|
||||||
|
@ -38,11 +38,7 @@
|
|||||||
#define MINVAL( a, b ) ( (a) < (b) ? (a) : (b) )
|
#define MINVAL( a, b ) ( (a) < (b) ? (a) : (b) )
|
||||||
#define MAXVAL( a, b ) ( (a) > (b) ? (a) : (b) )
|
#define MAXVAL( a, b ) ( (a) > (b) ? (a) : (b) )
|
||||||
|
|
||||||
#ifndef WIN32
|
#define MEMBUF_DEF_SIZE_INC 20
|
||||||
#define UPNP_INLINE inline
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MEMBUF_DEF_SIZE_INC 20
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct // ixml_membuf
|
typedef struct // ixml_membuf
|
||||||
|
@ -501,17 +501,22 @@ Parser_init( )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*================================================================
|
/*================================================================
|
||||||
* Parser_isValidEndElement
|
* Parser_isValidEndElement
|
||||||
* check if a new node->nodeName matches top of element stack.
|
* check if a new node->nodeName matches top of element stack.
|
||||||
* Internal to parser only.
|
* Internal to parser only.
|
||||||
*
|
*=================================================================*/
|
||||||
*=================================================================*/
|
|
||||||
static int
|
static int
|
||||||
Parser_isValidEndElement( IN Parser * xmlParser,
|
Parser_isValidEndElement(
|
||||||
IN IXML_Node * newNode )
|
IN Parser * xmlParser,
|
||||||
|
IN IXML_Node * newNode )
|
||||||
{
|
{
|
||||||
return ( strcmp( xmlParser->pCurElement->element, newNode->nodeName )
|
assert( xmlParser );
|
||||||
== 0 );
|
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;
|
int rc = IXML_SUCCESS;
|
||||||
IXML_CDATASection *cdataSecNode = NULL;
|
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 );
|
ixmlNode_init( &newNode );
|
||||||
|
|
||||||
rc = ixmlDocument_createDocumentEx( &gRootDoc );
|
rc = ixmlDocument_createDocumentEx( &gRootDoc );
|
||||||
@ -936,7 +943,9 @@ Parser_parseDocument( OUT IXML_Document ** retDoc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
while( bETag == FALSE ) {
|
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 );
|
ixmlNode_init( &newNode );
|
||||||
|
|
||||||
if( Parser_getNextNode( xmlParser, &newNode, &bETag ) ==
|
if( Parser_getNextNode( xmlParser, &newNode, &bETag ) ==
|
||||||
@ -1030,7 +1039,7 @@ Parser_parseDocument( OUT IXML_Document ** retDoc,
|
|||||||
Parser_free( xmlParser );
|
Parser_free( xmlParser );
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
ErrorHandler:
|
ErrorHandler:
|
||||||
Parser_freeNodeContent( &newNode );
|
Parser_freeNodeContent( &newNode );
|
||||||
ixmlDocument_free( gRootDoc );
|
ixmlDocument_free( gRootDoc );
|
||||||
Parser_free( xmlParser );
|
Parser_free( xmlParser );
|
||||||
@ -2497,3 +2506,4 @@ Parser_getNextNode( IN Parser * xmlParser,
|
|||||||
return IXML_SYNTAX_ERR;
|
return IXML_SYNTAX_ERR;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
0
ixml/test/test_document.sh
Normal file → Executable file
0
ixml/test/test_document.sh
Normal file → Executable file
@ -1,4 +1,4 @@
|
|||||||
Version: 1.4.2
|
Version: 1.6.5
|
||||||
Summary: Universal Plug and Play (UPnP) SDK
|
Summary: Universal Plug and Play (UPnP) SDK
|
||||||
Name: libupnp
|
Name: libupnp
|
||||||
Release: 1%{?dist}
|
Release: 1%{?dist}
|
||||||
@ -77,6 +77,12 @@ make install DESTDIR=$RPM_BUILD_ROOT
|
|||||||
rm -rf %{buildroot}
|
rm -rf %{buildroot}
|
||||||
|
|
||||||
%changelog
|
%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
|
* Fri Feb 02 2007 Eric Tanguy <eric.tanguy@univ-nantes.fr> - 1.4.2-1
|
||||||
- Update to version 1.4.2
|
- Update to version 1.4.2
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ AC_DEFUN([RT_BOOL_ARG_ENABLE],[
|
|||||||
)])
|
)])
|
||||||
test "x$enable_[$1]" != [x]m4_if([$2],[yes],[no],[yes]) dnl
|
test "x$enable_[$1]" != [x]m4_if([$2],[yes],[no],[yes]) dnl
|
||||||
&& enable_[]Name=[$2]
|
&& enable_[]Name=[$2]
|
||||||
AC_MSG_RESULT($enable_[]Name)dnl
|
AC_MSG_RESULT($enable_[]Name)
|
||||||
AM_CONDITIONAL([ENABLE_]NAME, test x"$enable_[]Name" = xyes)
|
AM_CONDITIONAL([ENABLE_]NAME, test x"$enable_[]Name" = xyes)
|
||||||
dnl
|
dnl
|
||||||
m4_popdef([NAME])dnl
|
m4_popdef([NAME])dnl
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
AM_CPPFLAGS = -I$(srcdir)/inc -I$(srcdir)/src/inc
|
AM_CPPFLAGS = -I$(srcdir)/inc -I$(srcdir)/src/inc
|
||||||
AM_CFLAGS = $(PTHREAD_CFLAGS)
|
|
||||||
|
|
||||||
if ENABLE_DEBUG
|
if ENABLE_DEBUG
|
||||||
AM_CPPFLAGS += -DDEBUG -DSTATS
|
AM_CPPFLAGS += -DDEBUG -DSTATS
|
||||||
@ -21,12 +20,11 @@ libthreadutil_la_LDFLAGS = -version-info $(LT_VERSION_THREADUTIL)
|
|||||||
|
|
||||||
libthreadutil_la_SOURCES = \
|
libthreadutil_la_SOURCES = \
|
||||||
src/FreeList.c src/LinkedList.c \
|
src/FreeList.c src/LinkedList.c \
|
||||||
src/ThreadPool.c src/TimerThread.c \
|
src/ThreadPool.c src/TimerThread.c
|
||||||
src/iasnprintf.c
|
|
||||||
|
|
||||||
upnpincludedir = $(includedir)/upnp
|
upnpincludedir = $(includedir)/upnp
|
||||||
upnpinclude_HEADERS = \
|
upnpinclude_HEADERS = \
|
||||||
inc/FreeList.h inc/LinkedList.h \
|
inc/FreeList.h inc/LinkedList.h \
|
||||||
inc/ThreadPool.h inc/TimerThread.h \
|
inc/ThreadPool.h inc/TimerThread.h \
|
||||||
inc/iasnprintf.h inc/ithread.h
|
inc/ithread.h
|
||||||
|
|
||||||
|
@ -32,6 +32,12 @@
|
|||||||
#ifndef THREADPOOL_H
|
#ifndef THREADPOOL_H
|
||||||
#define THREADPOOL_H
|
#define THREADPOOL_H
|
||||||
|
|
||||||
|
#ifdef UPNP_USE_MSVCPP
|
||||||
|
#define UPNP_INLINE
|
||||||
|
#else
|
||||||
|
#define UPNP_INLINE inline
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -64,32 +70,23 @@ typedef enum priority {LOW_PRIORITY,
|
|||||||
#define DEFAULT_FREE_ROUTINE NULL /* default free routine used TPJobInit */
|
#define DEFAULT_FREE_ROUTINE NULL /* default free routine used TPJobInit */
|
||||||
#define DEFAULT_MAX_JOBS_TOTAL 100 /* default max jobs used TPAttrInit */
|
#define DEFAULT_MAX_JOBS_TOTAL 100 /* default max jobs used TPAttrInit */
|
||||||
|
|
||||||
#define STATS 1 /* always include stats because code change is minimal */
|
|
||||||
|
|
||||||
|
|
||||||
/* Statistics */
|
/* Statistics */
|
||||||
#ifdef WIN32 /* TODO: check why STATSONLY fails during compilation */
|
/* always include stats because code change is minimal */
|
||||||
#undef STATS
|
#define STATS 1
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef STATS
|
|
||||||
#define STATSONLY(x) x
|
|
||||||
#else
|
|
||||||
#define STATSONLY(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define DEBUG 1
|
#define DEBUG 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "LinkedList.h"
|
#include "LinkedList.h"
|
||||||
#include <sys/timeb.h>
|
#include <sys/time.h> /* for gettimeofday() */
|
||||||
#include "FreeList.h"
|
#include "FreeList.h"
|
||||||
|
|
||||||
#include "ithread.h"
|
#include "ithread.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/timeb.h>
|
|
||||||
#define EXPORT
|
#define EXPORT
|
||||||
|
|
||||||
typedef int PolicyType;
|
typedef int PolicyType;
|
||||||
#define DEFAULT_POLICY SCHED_OTHER
|
#define DEFAULT_POLICY SCHED_OTHER
|
||||||
#define DEFAULT_SCHED_PARAM 0 /* default priority */
|
#define DEFAULT_SCHED_PARAM 0 /* default priority */
|
||||||
@ -111,26 +108,28 @@ typedef void (*free_routine)(void *arg);
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
typedef struct THREADPOOLATTR
|
typedef struct THREADPOOLATTR
|
||||||
{
|
{
|
||||||
int minThreads; /* minThreads, ThreadPool will always maintain at least
|
/* minThreads, ThreadPool will always maintain at least this many threads */
|
||||||
this many threads */
|
int minThreads;
|
||||||
|
|
||||||
int maxThreads; /* maxThreads, ThreadPool will never have more than this
|
/* maxThreads, ThreadPool will never have more than this number of threads */
|
||||||
number of threads */
|
int maxThreads;
|
||||||
|
|
||||||
int maxIdleTime; /* maxIdleTime (in milliseconds)
|
/* maxIdleTime (in milliseconds) this is the maximum time a thread will
|
||||||
this is the maximum time a thread will remain idle
|
* remain idle before dying */
|
||||||
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
|
/* the time a low priority or med priority job waits before getting bumped
|
||||||
job waits before getting bumped
|
* up a priority (in milliseconds) */
|
||||||
up a priority (in milliseconds) */
|
int starvationTime;
|
||||||
|
|
||||||
PolicyType schedPolicy; /* scheduling policy to use */
|
|
||||||
|
|
||||||
|
/* scheduling policy to use */
|
||||||
|
PolicyType schedPolicy;
|
||||||
} ThreadPoolAttr;
|
} ThreadPoolAttr;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -141,12 +140,12 @@ typedef struct THREADPOOLATTR
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
typedef struct THREADPOOLJOB
|
typedef struct THREADPOOLJOB
|
||||||
{
|
{
|
||||||
start_routine func;
|
start_routine func;
|
||||||
void *arg;
|
void *arg;
|
||||||
free_routine free_func;
|
free_routine free_func;
|
||||||
struct timeb requestTime;
|
struct timeval requestTime;
|
||||||
int priority;
|
int priority;
|
||||||
int jobId;
|
int jobId;
|
||||||
} ThreadPoolJob;
|
} ThreadPoolJob;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -156,32 +155,28 @@ typedef struct THREADPOOLJOB
|
|||||||
* Structure to hold statistics
|
* Structure to hold statistics
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#ifdef STATS
|
|
||||||
|
|
||||||
typedef struct TPOOLSTATS
|
typedef struct TPOOLSTATS
|
||||||
{
|
{
|
||||||
double totalTimeHQ;
|
double totalTimeHQ;
|
||||||
int totalJobsHQ;
|
int totalJobsHQ;
|
||||||
double avgWaitHQ;
|
double avgWaitHQ;
|
||||||
double totalTimeMQ;
|
double totalTimeMQ;
|
||||||
int totalJobsMQ;
|
int totalJobsMQ;
|
||||||
double avgWaitMQ;
|
double avgWaitMQ;
|
||||||
double totalTimeLQ;
|
double totalTimeLQ;
|
||||||
int totalJobsLQ;
|
int totalJobsLQ;
|
||||||
double avgWaitLQ;
|
double avgWaitLQ;
|
||||||
double totalWorkTime;
|
double totalWorkTime;
|
||||||
double totalIdleTime;
|
double totalIdleTime;
|
||||||
int workerThreads;
|
int workerThreads;
|
||||||
int idleThreads;
|
int idleThreads;
|
||||||
int persistentThreads;
|
int persistentThreads;
|
||||||
int totalThreads;
|
int totalThreads;
|
||||||
int maxThreads;
|
int maxThreads;
|
||||||
int currentJobsHQ;
|
int currentJobsHQ;
|
||||||
int currentJobsLQ;
|
int currentJobsLQ;
|
||||||
int currentJobsMQ;
|
int currentJobsMQ;
|
||||||
}ThreadPoolStats;
|
} ThreadPoolStats;
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -206,27 +201,24 @@ typedef struct TPOOLSTATS
|
|||||||
|
|
||||||
typedef struct THREADPOOL
|
typedef struct THREADPOOL
|
||||||
{
|
{
|
||||||
ithread_mutex_t mutex; /* mutex to protect job qs */
|
ithread_mutex_t mutex; /* mutex to protect job qs */
|
||||||
ithread_cond_t condition; /* condition variable to signal Q */
|
ithread_cond_t condition; /* condition variable to signal Q */
|
||||||
ithread_cond_t start_and_shutdown; /* condition variable for start
|
ithread_cond_t start_and_shutdown; /* condition variable for start
|
||||||
and stop */
|
and stop */
|
||||||
int lastJobId; /* ids for jobs */
|
int lastJobId; /* ids for jobs */
|
||||||
int shutdown; /* whether or not we are shutting down */
|
int shutdown; /* whether or not we are shutting down */
|
||||||
int totalThreads; /* total number of threads */
|
int totalThreads; /* total number of threads */
|
||||||
int persistentThreads; /* number of persistent threads */
|
int persistentThreads; /* number of persistent threads */
|
||||||
FreeList jobFreeList; /* free list of jobs */
|
FreeList jobFreeList; /* free list of jobs */
|
||||||
LinkedList lowJobQ; /* low priority job Q */
|
LinkedList lowJobQ; /* low priority job Q */
|
||||||
LinkedList medJobQ; /* med priority job Q */
|
LinkedList medJobQ; /* med priority job Q */
|
||||||
LinkedList highJobQ; /* high priority job Q */
|
LinkedList highJobQ; /* high priority job Q */
|
||||||
ThreadPoolJob *persistentJob; /* persistent job */
|
ThreadPoolJob *persistentJob; /* persistent job */
|
||||||
|
|
||||||
ThreadPoolAttr attr; /* thread pool attributes */
|
ThreadPoolAttr attr; /* thread pool attributes */
|
||||||
|
|
||||||
#ifdef STATS
|
/* statistics */
|
||||||
/* statistics */
|
ThreadPoolStats stats;
|
||||||
ThreadPoolStats stats;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} ThreadPool;
|
} ThreadPool;
|
||||||
|
|
||||||
|
|
||||||
@ -267,8 +259,7 @@ typedef struct THREADPOOL
|
|||||||
* INVALID_POLICY if schedPolicy can't be set
|
* INVALID_POLICY if schedPolicy can't be set
|
||||||
* EMAXTHREADS if minimum threads is greater than maximum threads
|
* EMAXTHREADS if minimum threads is greater than maximum threads
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int ThreadPoolInit(ThreadPool *tp,
|
int ThreadPoolInit(ThreadPool *tp, ThreadPoolAttr *attr);
|
||||||
ThreadPoolAttr *attr);
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: ThreadPoolAddPersistent
|
* Function: ThreadPoolAddPersistent
|
||||||
@ -290,9 +281,7 @@ int ThreadPoolInit(ThreadPool *tp,
|
|||||||
* EOUTOFMEM not enough memory to add job.
|
* EOUTOFMEM not enough memory to add job.
|
||||||
* EMAXTHREADS not enough threads to add persistent job.
|
* EMAXTHREADS not enough threads to add persistent job.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int ThreadPoolAddPersistent (ThreadPool*tp,
|
int ThreadPoolAddPersistent(ThreadPool*tp, ThreadPoolJob *job, int *jobId);
|
||||||
ThreadPoolJob *job,
|
|
||||||
int *jobId);
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: ThreadPoolGetAttr
|
* Function: ThreadPoolGetAttr
|
||||||
@ -307,8 +296,7 @@ int ThreadPoolAddPersistent (ThreadPool*tp,
|
|||||||
* 0 on success, nonzero on failure
|
* 0 on success, nonzero on failure
|
||||||
* Always returns 0.
|
* Always returns 0.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int ThreadPoolGetAttr(ThreadPool *tp,
|
int ThreadPoolGetAttr(ThreadPool *tp, ThreadPoolAttr *out);
|
||||||
ThreadPoolAttr *out);
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: ThreadPoolSetAttr
|
* Function: ThreadPoolSetAttr
|
||||||
*
|
*
|
||||||
@ -322,8 +310,7 @@ int ThreadPoolGetAttr(ThreadPool *tp,
|
|||||||
* 0 on success, nonzero on failure
|
* 0 on success, nonzero on failure
|
||||||
* Returns INVALID_POLICY if policy can not be set.
|
* Returns INVALID_POLICY if policy can not be set.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int ThreadPoolSetAttr(ThreadPool *tp,
|
int ThreadPoolSetAttr(ThreadPool *tp, ThreadPoolAttr *attr);
|
||||||
ThreadPoolAttr *attr);
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: ThreadPoolAdd
|
* Function: ThreadPoolAdd
|
||||||
@ -342,9 +329,7 @@ int ThreadPoolSetAttr(ThreadPool *tp,
|
|||||||
* 0 on success, nonzero on failure
|
* 0 on success, nonzero on failure
|
||||||
* EOUTOFMEM if not enough memory to add job.
|
* EOUTOFMEM if not enough memory to add job.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int ThreadPoolAdd (ThreadPool*tp,
|
int ThreadPoolAdd (ThreadPool*tp, ThreadPoolJob *job, int *jobId);
|
||||||
ThreadPoolJob *job,
|
|
||||||
int *jobId);
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: ThreadPoolRemove
|
* Function: ThreadPoolRemove
|
||||||
@ -361,8 +346,7 @@ int ThreadPoolAdd (ThreadPool*tp,
|
|||||||
* 0 on success, nonzero on failure.
|
* 0 on success, nonzero on failure.
|
||||||
* INVALID_JOB_ID if job not found.
|
* INVALID_JOB_ID if job not found.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int ThreadPoolRemove(ThreadPool *tp,
|
int ThreadPoolRemove(ThreadPool *tp, int jobId, ThreadPoolJob *out);
|
||||||
int jobId, ThreadPoolJob *out);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -425,7 +409,6 @@ int TPJobSetPriority(ThreadPoolJob *job, ThreadPriority priority);
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func);
|
int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func);
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: TPAttrInit
|
* Function: TPAttrInit
|
||||||
*
|
*
|
||||||
@ -547,6 +530,10 @@ int TPAttrSetMaxJobsTotal(ThreadPoolAttr *attr, int maxJobsTotal);
|
|||||||
EXPORT int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats);
|
EXPORT int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats);
|
||||||
|
|
||||||
EXPORT void ThreadPoolPrintStats(ThreadPoolStats *stats);
|
EXPORT void ThreadPoolPrintStats(ThreadPoolStats *stats);
|
||||||
|
#else
|
||||||
|
static UPNP_INLINE int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats) {}
|
||||||
|
|
||||||
|
static UPNP_INLINE void ThreadPoolPrintStats(ThreadPoolStats *stats) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -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
|
|
@ -42,131 +42,158 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PTHREAD_MUTEX_RECURSIVE
|
#ifdef PTHREAD_MUTEX_RECURSIVE
|
||||||
/* This system has SuS2-compliant mutex attributes.
|
/* This system has SuS2-compliant mutex attributes.
|
||||||
* E.g. on Cygwin, where we don't have the old nonportable (NP) symbols
|
* E.g. on Cygwin, where we don't have the old nonportable (NP) symbols
|
||||||
*/
|
*/
|
||||||
#define ITHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_NORMAL
|
#define ITHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_NORMAL
|
||||||
#define ITHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
#define ITHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||||
#define ITHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK
|
#define ITHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK
|
||||||
#else
|
#else /* PTHREAD_MUTEX_RECURSIVE */
|
||||||
#define ITHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_FAST_NP
|
#define ITHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_FAST_NP
|
||||||
#define ITHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE_NP
|
#define ITHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE_NP
|
||||||
#define ITHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK_NP
|
#define ITHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK_NP
|
||||||
#endif
|
#endif /* PTHREAD_MUTEX_RECURSIVE */
|
||||||
|
|
||||||
|
|
||||||
|
#define ITHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
|
||||||
|
#define ITHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED
|
||||||
|
|
||||||
|
|
||||||
#define ITHREAD_CANCELED PTHREAD_CANCELED
|
#define ITHREAD_CANCELED PTHREAD_CANCELED
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Name: ithread_t
|
* Name: ithread_t
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Thread handle.
|
* Thread handle.
|
||||||
* typedef to pthread_t.
|
* typedef to pthread_t.
|
||||||
* Internal Use Only.
|
* Internal Use Only.
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
typedef pthread_t ithread_t;
|
typedef pthread_t ithread_t;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ithread_attr_t
|
* Name: ithread_attr_t
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Thread attribute.
|
* Thread attribute.
|
||||||
* typedef to pthread_attr_t
|
* typedef to pthread_attr_t
|
||||||
* Internal Use Only
|
* Internal Use Only
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
typedef pthread_attr_t ithread_attr_t;
|
typedef pthread_attr_t ithread_attr_t;
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: start_routine
|
* Name: start_routine
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Thread start routine
|
* Thread start routine
|
||||||
* Internal Use Only.
|
* Internal Use Only.
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
typedef void * (*start_routine) (void *arg);
|
typedef void * (*start_routine) (void *arg);
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ithread_cond_t
|
* Name: ithread_cond_t
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* condition variable.
|
* condition variable.
|
||||||
* typedef to pthread_cond_t
|
* typedef to pthread_cond_t
|
||||||
* Internal Use Only.
|
* Internal Use Only.
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
typedef pthread_cond_t ithread_cond_t;
|
typedef pthread_cond_t ithread_cond_t;
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ithread_mutexattr_t
|
* Name: ithread_mutexattr_t
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Mutex attribute.
|
* Mutex attribute.
|
||||||
* typedef to pthread_mutexattr_t
|
* typedef to pthread_mutexattr_t
|
||||||
* Internal Use Only
|
* Internal Use Only
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
typedef pthread_mutexattr_t ithread_mutexattr_t;
|
typedef pthread_mutexattr_t ithread_mutexattr_t;
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ithread_mutex_t
|
* Name: ithread_mutex_t
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Mutex.
|
* Mutex.
|
||||||
* typedef to pthread_mutex_t
|
* typedef to pthread_mutex_t
|
||||||
* Internal Use Only.
|
* Internal Use Only.
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
typedef pthread_mutex_t ithread_mutex_t;
|
typedef pthread_mutex_t ithread_mutex_t;
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ithread_condattr_t
|
* Name: ithread_condattr_t
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Condition attribute.
|
* Condition attribute.
|
||||||
* typedef to pthread_condattr_t
|
* typedef to pthread_condattr_t
|
||||||
* NOT USED
|
* NOT USED
|
||||||
* Internal Use Only
|
* Internal Use Only
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
typedef pthread_condattr_t ithread_condattr_t;
|
typedef pthread_condattr_t ithread_condattr_t;
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Function: ithread_mutexattr_init
|
/****************************************************************************
|
||||||
*
|
* Name: ithread_rwlockattr_t
|
||||||
* Description:
|
*
|
||||||
* Initializes a mutex attribute variable.
|
* Description:
|
||||||
* Used to set the type of the mutex.
|
* Mutex attribute.
|
||||||
* Parameters:
|
* typedef to pthread_rwlockattr_t
|
||||||
* ithread_mutexattr_init * attr (must be valid non NULL pointer to
|
* Internal Use Only
|
||||||
* pthread_mutexattr_t)
|
***************************************************************************/
|
||||||
* Returns:
|
typedef pthread_rwlockattr_t ithread_rwlockattr_t;
|
||||||
* 0 on success, Nonzero on failure.
|
|
||||||
* Always returns 0.
|
|
||||||
* See man page for pthread_mutexattr_init
|
/****************************************************************************
|
||||||
***************************************************************************/
|
* Name: ithread_rwlock_t
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Condition attribute.
|
||||||
|
* typedef to pthread_rwlock_t
|
||||||
|
* Internal Use Only
|
||||||
|
***************************************************************************/
|
||||||
|
typedef pthread_rwlock_t ithread_rwlock_t;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: ithread_mutexattr_init
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initializes a mutex attribute variable.
|
||||||
|
* Used to set the type of the mutex.
|
||||||
|
* Parameters:
|
||||||
|
* ithread_mutexattr_init * attr (must be valid non NULL pointer to
|
||||||
|
* pthread_mutexattr_t)
|
||||||
|
* Returns:
|
||||||
|
* 0 on success, Nonzero on failure.
|
||||||
|
* Always returns 0.
|
||||||
|
* See man page for pthread_mutexattr_init
|
||||||
|
***************************************************************************/
|
||||||
#define ithread_mutexattr_init pthread_mutexattr_init
|
#define ithread_mutexattr_init pthread_mutexattr_init
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Function: ithread_mutexattr_destroy
|
/****************************************************************************
|
||||||
*
|
* Function: ithread_mutexattr_destroy
|
||||||
* Description:
|
*
|
||||||
* Releases any resources held by the mutex attribute.
|
* Description:
|
||||||
* Currently there are no resources associated with the attribute
|
* Releases any resources held by the mutex attribute.
|
||||||
* Parameters:
|
* Currently there are no resources associated with the attribute
|
||||||
* ithread_mutexattr_t * attr (must be valid non NULL pointer to
|
* Parameters:
|
||||||
* pthread_mutexattr_t)
|
* ithread_mutexattr_t * attr (must be valid non NULL pointer to
|
||||||
* Returns:
|
* pthread_mutexattr_t)
|
||||||
* 0 on success, Nonzero on failure.
|
* Returns:
|
||||||
* Always returns 0.
|
* 0 on success, Nonzero on failure.
|
||||||
* See man page for pthread_mutexattr_destroy
|
* Always returns 0.
|
||||||
***************************************************************************/
|
* See man page for pthread_mutexattr_destroy
|
||||||
|
***************************************************************************/
|
||||||
#define ithread_mutexattr_destroy pthread_mutexattr_destroy
|
#define ithread_mutexattr_destroy pthread_mutexattr_destroy
|
||||||
|
|
||||||
|
|
||||||
@ -180,7 +207,7 @@ extern "C" {
|
|||||||
* ITHREAD_MUTEX_ERRORCHECK_NP
|
* ITHREAD_MUTEX_ERRORCHECK_NP
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* ithread_mutexattr_t * mutex (must be valid non NULL pointer to
|
* ithread_mutexattr_t * attr (must be valid non NULL pointer to
|
||||||
* ithread_mutexattr_t)
|
* ithread_mutexattr_t)
|
||||||
* int kind (one of ITHREAD_MUTEX_FAST_NP or ITHREAD_MUTEX_RECURSIVE_NP
|
* int kind (one of ITHREAD_MUTEX_FAST_NP or ITHREAD_MUTEX_RECURSIVE_NP
|
||||||
* or ITHREAD_MUTEX_ERRORCHECK_NP)
|
* or ITHREAD_MUTEX_ERRORCHECK_NP)
|
||||||
@ -190,9 +217,9 @@ extern "C" {
|
|||||||
* See man page for pthread_mutexattr_setkind_np
|
* See man page for pthread_mutexattr_setkind_np
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
#ifdef PTHREAD_MUTEX_RECURSIVE
|
#ifdef PTHREAD_MUTEX_RECURSIVE
|
||||||
#define ithread_mutexattr_setkind_np pthread_mutexattr_settype
|
#define ithread_mutexattr_setkind_np pthread_mutexattr_settype
|
||||||
#else
|
#else
|
||||||
#define ithread_mutexattr_setkind_np pthread_mutexattr_setkind_np
|
#define ithread_mutexattr_setkind_np pthread_mutexattr_setkind_np
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -205,7 +232,7 @@ extern "C" {
|
|||||||
* ITHREAD_MUTEX_ERRORCHECK_NP
|
* ITHREAD_MUTEX_ERRORCHECK_NP
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* ithread_mutexattr_t * mutex (must be valid non NULL pointer to
|
* ithread_mutexattr_t * attr (must be valid non NULL pointer to
|
||||||
* pthread_mutexattr_t)
|
* pthread_mutexattr_t)
|
||||||
* int *kind (one of ITHREAD_MUTEX_FAST_NP or ITHREAD_MUTEX_RECURSIVE_NP
|
* int *kind (one of ITHREAD_MUTEX_FAST_NP or ITHREAD_MUTEX_RECURSIVE_NP
|
||||||
* or ITHREAD_MUTEX_ERRORCHECK_NP)
|
* or ITHREAD_MUTEX_ERRORCHECK_NP)
|
||||||
@ -215,9 +242,9 @@ extern "C" {
|
|||||||
* See man page for pthread_mutexattr_getkind_np
|
* See man page for pthread_mutexattr_getkind_np
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
#ifdef PTHREAD_MUTEX_RECURSIVE
|
#ifdef PTHREAD_MUTEX_RECURSIVE
|
||||||
#define ithread_mutexattr_getkind_np pthread_mutexattr_gettype
|
#define ithread_mutexattr_getkind_np pthread_mutexattr_gettype
|
||||||
#else
|
#else
|
||||||
#define ithread_mutexattr_getkind_np pthread_mutexattr_getkind_np
|
#define ithread_mutexattr_getkind_np pthread_mutexattr_getkind_np
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -237,7 +264,8 @@ extern "C" {
|
|||||||
* See man page for pthread_mutex_init
|
* See man page for pthread_mutex_init
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
#define ithread_mutex_init pthread_mutex_init
|
#define ithread_mutex_init pthread_mutex_init
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: ithread_mutex_lock
|
* Function: ithread_mutex_lock
|
||||||
*
|
*
|
||||||
@ -291,7 +319,170 @@ extern "C" {
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
#define ithread_mutex_destroy pthread_mutex_destroy
|
#define ithread_mutex_destroy pthread_mutex_destroy
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: ithread_rwlockattr_init
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initializes a rwlock attribute variable to default values.
|
||||||
|
* Parameters:
|
||||||
|
* const ithread_rwlockattr_init *attr (must be valid non NULL pointer to
|
||||||
|
* pthread_rwlockattr_t)
|
||||||
|
* Returns:
|
||||||
|
* 0 on success, Nonzero on failure.
|
||||||
|
* Always returns 0.
|
||||||
|
* See man page for pthread_rwlockattr_init
|
||||||
|
***************************************************************************/
|
||||||
|
#define ithread_rwlockattr_init pthread_rwlockattr_init
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: ithread_rwlockattr_destroy
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Releases any resources held by the rwlock attribute.
|
||||||
|
* Parameters:
|
||||||
|
* ithread_rwlockattr_t *attr (must be valid non NULL pointer to
|
||||||
|
* pthread_rwlockattr_t)
|
||||||
|
* Returns:
|
||||||
|
* 0 on success, Nonzero on failure.
|
||||||
|
* Always returns 0.
|
||||||
|
* See man page for pthread_rwlockattr_destroy
|
||||||
|
***************************************************************************/
|
||||||
|
#define ithread_rwlockattr_destroy pthread_rwlockattr_destroy
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: ithread_rwlockatttr_setpshared
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Sets the rwlock type in the attribute.
|
||||||
|
* Valid types are: ITHREAD_PROCESS_PRIVATE
|
||||||
|
* ITHREAD_PROCESS_SHARED
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* ithread_rwlockattr_t * attr (must be valid non NULL pointer to
|
||||||
|
* ithread_rwlockattr_t)
|
||||||
|
* int kind (one of ITHREAD_PROCESS_PRIVATE or ITHREAD_PROCESS_SHARED)
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* 0 on success. Nonzero on failure.
|
||||||
|
* Returns EINVAL if the kind is not supported.
|
||||||
|
* See man page for pthread_rwlockattr_setkind_np
|
||||||
|
*****************************************************************************/
|
||||||
|
#define ithread_rwlockatttr_setpshared pthread_rwlockatttr_setpshared
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: ithread_rwlockatttr_getpshared
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Gets the rwlock type in the attribute.
|
||||||
|
* Valid types are: ITHREAD_PROCESS_PRIVATE
|
||||||
|
* ITHREAD_PROCESS_SHARED
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* ithread_rwlockattr_t * attr (must be valid non NULL pointer to
|
||||||
|
* pthread_rwlockattr_t)
|
||||||
|
* int *kind (one of ITHREAD_PROCESS_PRIVATE or ITHREAD_PROCESS_SHARED)
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* 0 on success. Nonzero on failure.
|
||||||
|
* Always returns 0.
|
||||||
|
* See man page for pthread_rwlockatttr_getpshared
|
||||||
|
*****************************************************************************/
|
||||||
|
#define ithread_rwlockatttr_getpshared pthread_rwlockatttr_getpshared
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: ithread_rwlock_init
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initializes rwlock.
|
||||||
|
* Must be called before use.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* ithread_rwlock_t * rwlock (must be valid non NULL pointer to pthread_rwlock_t)
|
||||||
|
* const ithread_rwlockattr_t * rwlock_attr
|
||||||
|
* Returns:
|
||||||
|
* 0 on success, Nonzero on failure.
|
||||||
|
* Always returns 0.
|
||||||
|
* See man page for pthread_rwlock_init
|
||||||
|
*****************************************************************************/
|
||||||
|
#define ithread_rwlock_init pthread_rwlock_init
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: ithread_rwlock_rdlock
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Locks rwlock for reading.
|
||||||
|
* Parameters:
|
||||||
|
* ithread_rwlock_t * rwlock (must be valid non NULL pointer to pthread_rwlock_t)
|
||||||
|
* rwlock must be initialized.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* 0 on success, Nonzero on failure.
|
||||||
|
* Always returns 0.
|
||||||
|
* See man page for pthread_rwlock_rdlock
|
||||||
|
*****************************************************************************/
|
||||||
|
#define ithread_rwlock_rdlock pthread_rwlock_rdlock
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: ithread_rwlock_wrlock
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Locks rwlock for writting.
|
||||||
|
* Parameters:
|
||||||
|
* ithread_rwlock_t * rwlock (must be valid non NULL pointer to pthread_rwlock_t)
|
||||||
|
* rwlock must be initialized.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* 0 on success, Nonzero on failure.
|
||||||
|
* Always returns 0.
|
||||||
|
* See man page for pthread_rwlock_wrlock
|
||||||
|
*****************************************************************************/
|
||||||
|
#define ithread_rwlock_wrlock pthread_rwlock_wrlock
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: ithread_rwlock_unlock
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Unlocks rwlock.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* ithread_rwlock_t * rwlock (must be valid non NULL pointer to pthread_rwlock_t)
|
||||||
|
* rwlock must be initialized.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* 0 on success, Nonzero on failure.
|
||||||
|
* Always returns 0.
|
||||||
|
* See man page for pthread_rwlock_unlock
|
||||||
|
*****************************************************************************/
|
||||||
|
#define ithread_rwlock_unlock pthread_rwlock_unlock
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: ithread_rwlock_destroy
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Releases any resources held by the rwlock.
|
||||||
|
* rwlock can no longer be used after this call.
|
||||||
|
* rwlock is only destroyed when there are no longer any threads waiting on it.
|
||||||
|
* rwlock cannot be destroyed if it is locked.
|
||||||
|
* Parameters:
|
||||||
|
* ithread_rwlock_t * rwlock (must be valid non NULL pointer to pthread_rwlock_t)
|
||||||
|
* rwlock must be initialized.
|
||||||
|
* Returns:
|
||||||
|
* 0 on success. Nonzero on failure.
|
||||||
|
* Always returns 0.
|
||||||
|
* See man page for pthread_rwlock_destroy
|
||||||
|
*****************************************************************************/
|
||||||
|
#define ithread_rwlock_destroy pthread_rwlock_destroy
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: ithread_cond_init
|
* Function: ithread_cond_init
|
||||||
*
|
*
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
#include "LinkedList.h"
|
#include "LinkedList.h"
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#if (defined(BSD) && BSD >= 199306)
|
#if (defined(BSD) && BSD >= 199306) || defined(__OSX__) || defined(__APPLE__)
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#else
|
#else
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -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)
|
|
||||||
#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;
|
|
||||||
}
|
|
@ -11,10 +11,6 @@ AM_CPPFLAGS = \
|
|||||||
-I$(top_srcdir)/threadutil/inc \
|
-I$(top_srcdir)/threadutil/inc \
|
||||||
-I$(top_srcdir)/ixml/inc
|
-I$(top_srcdir)/ixml/inc
|
||||||
|
|
||||||
AM_CFLAGS = $(PTHREAD_CFLAGS)
|
|
||||||
|
|
||||||
AM_LDFLAGS = $(PTHREAD_LIBS)
|
|
||||||
|
|
||||||
LDADD = \
|
LDADD = \
|
||||||
libupnp.la \
|
libupnp.la \
|
||||||
$(top_builddir)/threadutil/libthreadutil.la \
|
$(top_builddir)/threadutil/libthreadutil.la \
|
||||||
|
@ -413,7 +413,7 @@
|
|||||||
#define UPNP_E_SUBSCRIBE_UNACCEPTED -301
|
#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
|
* {\tt UPNP_E_UNSUBSCRIBE_UNACCEPTED} signifies that an unsubscribe
|
||||||
* request was rejected from the remote side.
|
* request was rejected from the remote side.
|
||||||
*/
|
*/
|
||||||
|
@ -258,7 +258,7 @@ void UpnpPrintf(
|
|||||||
__attribute__((format (__printf__, 5, 6)))
|
__attribute__((format (__printf__, 5, 6)))
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
#else
|
#else /* DEBUG */
|
||||||
static UPNP_INLINE void UpnpPrintf(
|
static UPNP_INLINE void UpnpPrintf(
|
||||||
Upnp_LogLevel DLevel,
|
Upnp_LogLevel DLevel,
|
||||||
Dbg_Module Module,
|
Dbg_Module Module,
|
||||||
@ -266,7 +266,7 @@ static UPNP_INLINE void UpnpPrintf(
|
|||||||
int DbgLineNo,
|
int DbgLineNo,
|
||||||
const char* FmtStr,
|
const char* FmtStr,
|
||||||
...) {}
|
...) {}
|
||||||
#endif
|
#endif /* DEBUG */
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
|
@ -9,10 +9,6 @@ AM_CPPFLAGS = \
|
|||||||
-I$(top_srcdir)/threadutil/inc \
|
-I$(top_srcdir)/threadutil/inc \
|
||||||
-I$(top_srcdir)/ixml/inc
|
-I$(top_srcdir)/ixml/inc
|
||||||
|
|
||||||
AM_CFLAGS = $(PTHREAD_CFLAGS)
|
|
||||||
|
|
||||||
AM_LDFLAGS = $(PTHREAD_LIBS)
|
|
||||||
|
|
||||||
LDADD = \
|
LDADD = \
|
||||||
$(top_builddir)/upnp/libupnp.la \
|
$(top_builddir)/upnp/libupnp.la \
|
||||||
$(top_builddir)/threadutil/libthreadutil.la \
|
$(top_builddir)/threadutil/libthreadutil.la \
|
||||||
|
@ -1362,7 +1362,7 @@ TvCtrlPointStart( print_string printFunctionPtr,
|
|||||||
|
|
||||||
ithread_mutex_init( &DeviceListMutex, 0 );
|
ithread_mutex_init( &DeviceListMutex, 0 );
|
||||||
|
|
||||||
SampleUtil_Print( "Intializing UPnP with ipaddress=%s port=%d",
|
SampleUtil_Print( "Initializing UPnP with ipaddress=%s port=%d",
|
||||||
ip_address, port );
|
ip_address, port );
|
||||||
rc = UpnpInit( ip_address, port );
|
rc = UpnpInit( ip_address, port );
|
||||||
if( UPNP_E_SUCCESS != rc ) {
|
if( UPNP_E_SUCCESS != rc ) {
|
||||||
|
@ -84,19 +84,17 @@ virtualDirList *pVirtualDirList;
|
|||||||
// Mutex to synchronize the subscription handling at the client side
|
// Mutex to synchronize the subscription handling at the client side
|
||||||
CLIENTONLY( ithread_mutex_t GlobalClientSubscribeMutex; )
|
CLIENTONLY( ithread_mutex_t GlobalClientSubscribeMutex; )
|
||||||
|
|
||||||
//Mutex to synchronize handles ( root device or control point handle)
|
// rwlock to synchronize handles (root device or control point handle)
|
||||||
ithread_mutex_t GlobalHndMutex;
|
ithread_rwlock_t GlobalHndRWLock;
|
||||||
|
|
||||||
// Mutex to synchronize the uuid creation process
|
// Mutex to synchronize the uuid creation process
|
||||||
ithread_mutex_t gUUIDMutex;
|
ithread_mutex_t gUUIDMutex;
|
||||||
|
|
||||||
TimerThread gTimerThread;
|
TimerThread gTimerThread;
|
||||||
|
|
||||||
ThreadPool gRecvThreadPool;
|
|
||||||
|
|
||||||
ThreadPool gSendThreadPool;
|
ThreadPool gSendThreadPool;
|
||||||
|
ThreadPool gRecvThreadPool;
|
||||||
ThreadPool gMiniServerThreadPool;
|
ThreadPool gMiniServerThreadPool;
|
||||||
|
|
||||||
//Flag to indicate the state of web server
|
//Flag to indicate the state of web server
|
||||||
WebServerState bWebServerState = WEB_SERVER_DISABLED;
|
WebServerState bWebServerState = WEB_SERVER_DISABLED;
|
||||||
@ -213,26 +211,26 @@ int UpnpInit( IN const char *HostIP,
|
|||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
/* On Cygwin, pthread_mutex_init() fails without this memset. */
|
/* On Cygwin, pthread_mutex_init() fails without this memset. */
|
||||||
/* TODO: Fix Cygwin so we don't need this memset(). */
|
/* TODO: Fix Cygwin so we don't need this memset(). */
|
||||||
memset(&GlobalHndMutex, 0, sizeof(GlobalHndMutex));
|
memset(&GlobalHndRWLock, 0, sizeof(GlobalHndRWLock));
|
||||||
#endif
|
#endif
|
||||||
if( ithread_mutex_init( &GlobalHndMutex, NULL ) != 0 ) {
|
if (ithread_rwlock_init(&GlobalHndRWLock, NULL) != 0) {
|
||||||
return UPNP_E_INIT_FAILED;
|
return UPNP_E_INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ithread_mutex_init( &gUUIDMutex, NULL ) != 0 ) {
|
if (ithread_mutex_init(&gUUIDMutex, NULL) != 0) {
|
||||||
return UPNP_E_INIT_FAILED;
|
return UPNP_E_INIT_FAILED;
|
||||||
}
|
}
|
||||||
// initialize subscribe mutex
|
// initialize subscribe mutex
|
||||||
#ifdef INCLUDE_CLIENT_APIS
|
#ifdef INCLUDE_CLIENT_APIS
|
||||||
if ( ithread_mutex_init( &GlobalClientSubscribeMutex, NULL ) != 0 ) {
|
if (ithread_mutex_init(&GlobalClientSubscribeMutex, NULL) != 0) {
|
||||||
return UPNP_E_INIT_FAILED;
|
return UPNP_E_INIT_FAILED;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
HandleLock();
|
HandleLock();
|
||||||
if( HostIP != NULL )
|
if( HostIP != NULL ) {
|
||||||
strcpy( LOCAL_HOST, HostIP );
|
strcpy( LOCAL_HOST, HostIP );
|
||||||
else {
|
} else {
|
||||||
if( getlocalhostname( LOCAL_HOST ) != UPNP_E_SUCCESS ) {
|
if( getlocalhostname( LOCAL_HOST ) != UPNP_E_SUCCESS ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INIT_FAILED;
|
return UPNP_E_INIT_FAILED;
|
||||||
@ -268,7 +266,7 @@ int UpnpInit( IN const char *HostIP,
|
|||||||
|
|
||||||
if( ThreadPoolInit( &gMiniServerThreadPool, &attr ) != UPNP_E_SUCCESS ) {
|
if( ThreadPoolInit( &gMiniServerThreadPool, &attr ) != UPNP_E_SUCCESS ) {
|
||||||
UpnpSdkInit = 0;
|
UpnpSdkInit = 0;
|
||||||
UpnpFinish( );
|
UpnpFinish();
|
||||||
return UPNP_E_INIT_FAILED;
|
return UPNP_E_INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,29 +321,56 @@ int UpnpInit( IN const char *HostIP,
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
static void
|
static void
|
||||||
PrintThreadPoolStats (const char* DbgFileName, int DbgLineNo,
|
PrintThreadPoolStats(
|
||||||
const char* msg, const ThreadPoolStats* const stats)
|
ThreadPool *tp,
|
||||||
|
const char *DbgFileName,
|
||||||
|
int DbgLineNo,
|
||||||
|
const char *msg)
|
||||||
{
|
{
|
||||||
UpnpPrintf (UPNP_INFO, API, DbgFileName, DbgLineNo,
|
ThreadPoolStats stats;
|
||||||
"%s \n High Jobs pending = %d \nMed Jobs Pending = %d\n"
|
ThreadPoolGetStats(tp, &stats);
|
||||||
" Low Jobs Pending = %d \nWorker Threads = %d\n"
|
UpnpPrintf(UPNP_INFO, API, DbgFileName, DbgLineNo,
|
||||||
"Idle Threads = %d\nPersistent Threads = %d\n"
|
"%s \n"
|
||||||
"Average Time spent in High Q = %lf\n"
|
"High Jobs pending: %d\n"
|
||||||
"Average Time spent in Med Q = %lf\n"
|
"Med Jobs Pending: %d\n"
|
||||||
"Average Time spent in Low Q = %lf\n"
|
"Low Jobs Pending: %d\n"
|
||||||
"Max Threads Used: %d\nTotal Work Time= %lf\n"
|
"Average wait in High Q in milliseconds: %lf\n"
|
||||||
"Total Idle Time = %lf\n",
|
"Average wait in Med Q in milliseconds: %lf\n"
|
||||||
msg,
|
"Average wait in Low Q in milliseconds: %lf\n"
|
||||||
stats->currentJobsHQ, stats->currentJobsMQ,
|
"Max Threads Used: %d\n"
|
||||||
stats->currentJobsLQ, stats->workerThreads,
|
"Worker Threads: %d\n"
|
||||||
stats->idleThreads, stats->persistentThreads,
|
"Persistent Threads: %d\n"
|
||||||
stats->avgWaitHQ, stats->avgWaitMQ, stats->avgWaitLQ,
|
"Idle Threads: %d\n"
|
||||||
stats->maxThreads, stats->totalWorkTime,
|
"Total Threads: %d\n"
|
||||||
stats->totalIdleTime );
|
"Total Work Time: %lf\n"
|
||||||
|
"Total Idle Time: %lf\n",
|
||||||
|
msg,
|
||||||
|
stats.currentJobsHQ,
|
||||||
|
stats.currentJobsMQ,
|
||||||
|
stats.currentJobsLQ,
|
||||||
|
stats.avgWaitHQ,
|
||||||
|
stats.avgWaitMQ,
|
||||||
|
stats.avgWaitLQ,
|
||||||
|
stats.maxThreads,
|
||||||
|
stats.workerThreads,
|
||||||
|
stats.persistentThreads,
|
||||||
|
stats.idleThreads,
|
||||||
|
stats.totalThreads,
|
||||||
|
stats.totalWorkTime,
|
||||||
|
stats.totalIdleTime);
|
||||||
}
|
}
|
||||||
#endif
|
#else /* DEBUG */
|
||||||
|
static UPNP_INLINE void
|
||||||
|
PrintThreadPoolStats(
|
||||||
|
ThreadPool *tp,
|
||||||
|
const char *DbgFileName,
|
||||||
|
int DbgLineNo,
|
||||||
|
const char *msg)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif /* DEBUG */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: UpnpFinish
|
* Function: UpnpFinish
|
||||||
*
|
*
|
||||||
@ -374,12 +399,8 @@ UpnpFinish()
|
|||||||
#endif
|
#endif
|
||||||
struct Handle_Info *temp;
|
struct Handle_Info *temp;
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
ThreadPoolStats stats;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// WSACleanup( );
|
// WSACleanup();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( UpnpSdkInit != 1 ) {
|
if( UpnpSdkInit != 1 ) {
|
||||||
@ -387,20 +408,15 @@ UpnpFinish()
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpFinish : UpnpSdkInit is :%d:\n",
|
"Inside UpnpFinish : UpnpSdkInit is :%d:\n", UpnpSdkInit );
|
||||||
UpnpSdkInit );
|
|
||||||
#ifdef DEBUG
|
|
||||||
if( UpnpSdkInit == 1 ) {
|
if( UpnpSdkInit == 1 ) {
|
||||||
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
||||||
"UpnpFinish : UpnpSdkInit is ONE\n" );
|
"UpnpFinish : UpnpSdkInit is ONE\n" );
|
||||||
}
|
}
|
||||||
ThreadPoolGetStats( &gRecvThreadPool, &stats );
|
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__, "Send Thread Pool");
|
||||||
PrintThreadPoolStats (__FILE__, __LINE__,
|
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool");
|
||||||
"Recv Thread Pool", &stats);
|
PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__, "MiniServer Thread Pool");
|
||||||
ThreadPoolGetStats( &gSendThreadPool, &stats );
|
|
||||||
PrintThreadPoolStats (__FILE__, __LINE__,
|
|
||||||
"Send Thread Pool", &stats);
|
|
||||||
#endif
|
|
||||||
#ifdef INCLUDE_DEVICE_APIS
|
#ifdef INCLUDE_DEVICE_APIS
|
||||||
if( GetDeviceHandleInfo( &device_handle, &temp ) == HND_DEVICE )
|
if( GetDeviceHandleInfo( &device_handle, &temp ) == HND_DEVICE )
|
||||||
UpnpUnRegisterRootDevice( device_handle );
|
UpnpUnRegisterRootDevice( device_handle );
|
||||||
@ -412,51 +428,47 @@ UpnpFinish()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
TimerThreadShutdown( &gTimerThread );
|
TimerThreadShutdown( &gTimerThread );
|
||||||
|
|
||||||
StopMiniServer();
|
StopMiniServer();
|
||||||
|
|
||||||
#if EXCLUDE_WEB_SERVER == 0
|
#if EXCLUDE_WEB_SERVER == 0
|
||||||
web_server_destroy();
|
web_server_destroy();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
ThreadPoolShutdown(&gMiniServerThreadPool);
|
||||||
ThreadPoolShutdown( &gSendThreadPool );
|
ThreadPoolShutdown(&gRecvThreadPool);
|
||||||
ThreadPoolShutdown( &gRecvThreadPool );
|
ThreadPoolShutdown(&gSendThreadPool);
|
||||||
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
|
||||||
"Exiting UpnpFinish : UpnpSdkInit is :%d:\n",
|
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__, "Send Thread Pool");
|
||||||
UpnpSdkInit );
|
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool");
|
||||||
ThreadPoolGetStats( &gRecvThreadPool, &stats );
|
PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__, "MiniServer Thread Pool");
|
||||||
PrintThreadPoolStats( __FILE__, __LINE__,
|
|
||||||
"Recv Thread Pool", &stats);
|
|
||||||
ThreadPoolGetStats( &gSendThreadPool, &stats );
|
|
||||||
PrintThreadPoolStats(__FILE__, __LINE__,
|
|
||||||
"Send Thread Pool", &stats);
|
|
||||||
UpnpCloseLog();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef INCLUDE_CLIENT_APIS
|
#ifdef INCLUDE_CLIENT_APIS
|
||||||
ithread_mutex_destroy( &GlobalClientSubscribeMutex );
|
ithread_mutex_destroy(&GlobalClientSubscribeMutex);
|
||||||
#endif
|
#endif
|
||||||
ithread_mutex_destroy( &GlobalHndMutex );
|
ithread_rwlock_destroy(&GlobalHndRWLock);
|
||||||
ithread_mutex_destroy( &gUUIDMutex );
|
ithread_mutex_destroy(&gUUIDMutex);
|
||||||
|
|
||||||
// remove all virtual dirs
|
// remove all virtual dirs
|
||||||
UpnpRemoveAllVirtualDirs();
|
UpnpRemoveAllVirtualDirs();
|
||||||
// leuk_he allow static linking:
|
|
||||||
|
// allow static linking
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#ifdef PTW32_STATIC_LIB
|
#ifdef PTW32_STATIC_LIB
|
||||||
pthread_win32_thread_detach_np ();
|
pthread_win32_thread_detach_np();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
UpnpSdkInit = 0;
|
UpnpSdkInit = 0;
|
||||||
|
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
||||||
|
"Exiting UpnpFinish : UpnpSdkInit is :%d:\n", UpnpSdkInit);
|
||||||
|
UpnpCloseLog();
|
||||||
|
|
||||||
return UPNP_E_SUCCESS;
|
return UPNP_E_SUCCESS;
|
||||||
|
|
||||||
} /********************* End of UpnpFinish *************************/
|
}
|
||||||
|
/*************************** End of UpnpFinish *****************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/******************************************************************************
|
||||||
* Function: UpnpGetServerPort
|
* Function: UpnpGetServerPort
|
||||||
*
|
*
|
||||||
* Parameters: NONE
|
* Parameters: NONE
|
||||||
@ -953,7 +965,7 @@ GetDescDocumentAndURL( IN Upnp_DescType descriptionType,
|
|||||||
char *temp_str = NULL;
|
char *temp_str = NULL;
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
off_t fileLen;
|
off_t fileLen;
|
||||||
unsigned num_read;
|
size_t num_read;
|
||||||
time_t last_modified;
|
time_t last_modified;
|
||||||
struct stat file_info;
|
struct stat file_info;
|
||||||
struct sockaddr_in serverAddr;
|
struct sockaddr_in serverAddr;
|
||||||
@ -1559,7 +1571,7 @@ UpnpSearchAsync( IN UpnpClient_Handle Hnd,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpSearchAsync \n" );
|
"Inside UpnpSearchAsync \n" );
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -1735,7 +1747,7 @@ UpnpSubscribeAsync( IN UpnpClient_Handle Hnd,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpSubscribeAsync \n" );
|
"Inside UpnpSubscribeAsync \n" );
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -1752,15 +1764,13 @@ UpnpSubscribeAsync( IN UpnpClient_Handle Hnd,
|
|||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_PARAM;
|
return UPNP_E_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
HandleUnlock();
|
||||||
|
|
||||||
Param =
|
Param = (struct UpnpNonblockParam *)
|
||||||
( struct UpnpNonblockParam * )
|
malloc(sizeof (struct UpnpNonblockParam));
|
||||||
malloc( sizeof( struct UpnpNonblockParam ) );
|
|
||||||
if( Param == NULL ) {
|
if( Param == NULL ) {
|
||||||
HandleUnlock();
|
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
return UPNP_E_OUTOF_MEMORY;
|
||||||
}
|
}
|
||||||
HandleUnlock();
|
|
||||||
|
|
||||||
Param->FunName = SUBSCRIBE;
|
Param->FunName = SUBSCRIBE;
|
||||||
Param->Handle = Hnd;
|
Param->Handle = Hnd;
|
||||||
@ -1820,7 +1830,7 @@ UpnpSubscribe( IN UpnpClient_Handle Hnd,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpSubscribe \n" );
|
"Inside UpnpSubscribe \n" );
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -1880,7 +1890,7 @@ UpnpUnSubscribe( IN UpnpClient_Handle Hnd,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpUnSubscribe \n" );
|
"Inside UpnpUnSubscribe \n" );
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -1939,7 +1949,7 @@ UpnpUnSubscribeAsync( IN UpnpClient_Handle Hnd,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpUnSubscribeAsync \n" );
|
"Inside UpnpUnSubscribeAsync \n" );
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -2013,7 +2023,7 @@ UpnpRenewSubscription( IN UpnpClient_Handle Hnd,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpRenewSubscription \n" );
|
"Inside UpnpRenewSubscription \n" );
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -2078,7 +2088,7 @@ UpnpRenewSubscriptionAsync( IN UpnpClient_Handle Hnd,
|
|||||||
|
|
||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpRenewSubscriptionAsync \n" );
|
"Inside UpnpRenewSubscriptionAsync \n" );
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -2173,7 +2183,7 @@ UpnpNotify( IN UpnpDevice_Handle Hnd,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpNotify \n" );
|
"Inside UpnpNotify \n" );
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -2244,7 +2254,7 @@ UpnpNotifyExt( IN UpnpDevice_Handle Hnd,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpNotify \n" );
|
"Inside UpnpNotify \n" );
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -2321,7 +2331,7 @@ UpnpAcceptSubscription( IN UpnpDevice_Handle Hnd,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpAcceptSubscription \n" );
|
"Inside UpnpAcceptSubscription \n" );
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -2397,7 +2407,7 @@ UpnpAcceptSubscriptionExt( IN UpnpDevice_Handle Hnd,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpAcceptSubscription \n" );
|
"Inside UpnpAcceptSubscription \n" );
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -2493,7 +2503,7 @@ UpnpSendAction( IN UpnpClient_Handle Hnd,
|
|||||||
}
|
}
|
||||||
DevUDN_const = NULL;
|
DevUDN_const = NULL;
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -2577,7 +2587,7 @@ UpnpSendActionEx( IN UpnpClient_Handle Hnd,
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -2653,7 +2663,7 @@ UpnpSendActionAsync( IN UpnpClient_Handle Hnd,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpSendActionAsync \n" );
|
"Inside UpnpSendActionAsync \n" );
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -2773,7 +2783,7 @@ UpnpSendActionExAsync( IN UpnpClient_Handle Hnd,
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -2887,7 +2897,7 @@ UpnpGetServiceVarStatusAsync( IN UpnpClient_Handle Hnd,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpGetServiceVarStatusAsync \n" );
|
"Inside UpnpGetServiceVarStatusAsync \n" );
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -2967,7 +2977,7 @@ UpnpGetServiceVarStatus( IN UpnpClient_Handle Hnd,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpGetServiceVarStatus \n" );
|
"Inside UpnpGetServiceVarStatus \n" );
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
@ -3300,9 +3310,9 @@ UpnpDownloadXmlDoc( const char *url,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"****************** END OF Parsed XML Doc *****************\n" );
|
"****************** END OF Parsed XML Doc *****************\n" );
|
||||||
ixmlFreeDOMString( xml_buf );
|
ixmlFreeDOMString( xml_buf );
|
||||||
|
#endif
|
||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Exiting UpnpDownloadXmlDoc\n" );
|
"Exiting UpnpDownloadXmlDoc\n" );
|
||||||
#endif
|
|
||||||
return UPNP_E_SUCCESS;
|
return UPNP_E_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3635,7 +3645,6 @@ int PrintHandleInfo( IN UpnpClient_Handle Hnd )
|
|||||||
struct Handle_Info * HndInfo;
|
struct Handle_Info * HndInfo;
|
||||||
if (HandleTable[Hnd] != NULL) {
|
if (HandleTable[Hnd] != NULL) {
|
||||||
HndInfo = HandleTable[Hnd];
|
HndInfo = HandleTable[Hnd];
|
||||||
#ifdef DEBUG
|
|
||||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Printing information for Handle_%d\n", Hnd);
|
"Printing information for Handle_%d\n", Hnd);
|
||||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
@ -3644,7 +3653,6 @@ int PrintHandleInfo( IN UpnpClient_Handle Hnd )
|
|||||||
if(HndInfo->HType != HND_CLIENT)
|
if(HndInfo->HType != HND_CLIENT)
|
||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"DescURL_%s\n", HndInfo->DescURL );
|
"DescURL_%s\n", HndInfo->DescURL );
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#include "uri.h"
|
#include "uri.h"
|
||||||
#define HEADER_LENGTH 2000
|
#define HEADER_LENGTH 2000
|
||||||
|
|
||||||
//Structure to maintain a error code and string associated with the
|
// Structure to maintain a error code and string associated with the
|
||||||
// error code
|
// error code
|
||||||
struct ErrorString {
|
struct ErrorString {
|
||||||
int rc; /* error code */
|
int rc; /* error code */
|
||||||
@ -44,7 +44,7 @@ struct ErrorString {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//Intializing the array of error structures.
|
// Initializing the array of error structures.
|
||||||
struct ErrorString ErrorMessages[] = { {UPNP_E_SUCCESS, "UPNP_E_SUCCESS"},
|
struct ErrorString ErrorMessages[] = { {UPNP_E_SUCCESS, "UPNP_E_SUCCESS"},
|
||||||
{UPNP_E_INVALID_HANDLE, "UPNP_E_INVALID_HANDLE"},
|
{UPNP_E_INVALID_HANDLE, "UPNP_E_INVALID_HANDLE"},
|
||||||
{UPNP_E_INVALID_PARAM, "UPNP_E_INVALID_PARAM"},
|
{UPNP_E_INVALID_PARAM, "UPNP_E_INVALID_PARAM"},
|
||||||
@ -81,13 +81,13 @@ struct ErrorString ErrorMessages[] = { {UPNP_E_SUCCESS, "UPNP_E_SUCCESS"},
|
|||||||
};
|
};
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : UpnpGetErrorMessage
|
* Function : UpnpGetErrorMessage
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN int rc: error code
|
* IN int rc: error code
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This functions returns the error string mapped to the error code
|
* This functions returns the error string mapped to the error code
|
||||||
* Returns: const char *
|
* Returns: const char *
|
||||||
* return either the right string or "Unknown Error"
|
* return either the right string or "Unknown Error"
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
@ -108,14 +108,14 @@ UpnpGetErrorMessage( IN int rc )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : UpnpResolveURL
|
* Function : UpnpResolveURL
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char * BaseURL: Base URL string
|
* IN char * BaseURL: Base URL string
|
||||||
* IN char * RelURL: relative URL string
|
* IN char * RelURL: relative URL string
|
||||||
* OUT char * AbsURL: Absolute URL string
|
* OUT char * AbsURL: Absolute URL string
|
||||||
* Description:
|
* Description:
|
||||||
* This functions concatinates the base URL and relative URL to generate
|
* This functions concatinates the base URL and relative URL to generate
|
||||||
* the absolute URL
|
* the absolute URL
|
||||||
* Returns: int
|
* Returns: int
|
||||||
* return either UPNP_E_SUCCESS or appropriate error
|
* return either UPNP_E_SUCCESS or appropriate error
|
||||||
@ -151,19 +151,19 @@ UpnpResolveURL( IN const char *BaseURL,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : addToAction
|
* Function : addToAction
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN int response: flag to tell if the ActionDoc is for response
|
* IN int response: flag to tell if the ActionDoc is for response
|
||||||
* or request
|
* or request
|
||||||
* INOUT IXML_Document **ActionDoc: request or response document
|
* INOUT IXML_Document **ActionDoc: request or response document
|
||||||
* IN char *ActionName: Name of the action request or response
|
* IN char *ActionName: Name of the action request or response
|
||||||
* IN char *ServType: Service type
|
* IN char *ServType: Service type
|
||||||
* IN char * ArgName: Name of the argument
|
* IN char * ArgName: Name of the argument
|
||||||
* IN char * ArgValue: Value of the argument
|
* IN char * ArgValue: Value of the argument
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function adds the argument in the action request or response.
|
* This function adds the argument in the action request or response.
|
||||||
* This function creates the action request or response if it is a first
|
* This function creates the action request or response if it is a first
|
||||||
* argument else it will add the argument in the document
|
* argument else it will add the argument in the document
|
||||||
*
|
*
|
||||||
@ -230,22 +230,22 @@ addToAction( IN int response,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : makeAction
|
* Function : makeAction
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN int response: flag to tell if the ActionDoc is for response
|
* IN int response: flag to tell if the ActionDoc is for response
|
||||||
* or request
|
* or request
|
||||||
* IN char * ActionName: Name of the action request or response
|
* IN char * ActionName: Name of the action request or response
|
||||||
* IN char * ServType: Service type
|
* IN char * ServType: Service type
|
||||||
* IN int NumArg :Number of arguments in the action request or response
|
* IN int NumArg :Number of arguments in the action request or response
|
||||||
* IN char * Arg : pointer to the first argument
|
* IN char * Arg : pointer to the first argument
|
||||||
* IN va_list ArgList: Argument list
|
* IN va_list ArgList: Argument list
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function creates the action request or response from the argument
|
* This function creates the action request or response from the argument
|
||||||
* list.
|
* list.
|
||||||
* Returns: IXML_Document *
|
* Returns: IXML_Document *
|
||||||
* returns action request or response document if successful
|
* returns action request or response document if successful
|
||||||
* else returns NULL
|
* else returns NULL
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static IXML_Document *
|
static IXML_Document *
|
||||||
@ -326,9 +326,9 @@ makeAction( IN int response,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : UpnpMakeAction
|
* Function : UpnpMakeAction
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char * ActionName: Name of the action request or response
|
* IN char * ActionName: Name of the action request or response
|
||||||
* IN char * ServType: Service type
|
* IN char * ServType: Service type
|
||||||
* IN int NumArg :Number of arguments in the action request or response
|
* IN int NumArg :Number of arguments in the action request or response
|
||||||
@ -336,7 +336,7 @@ makeAction( IN int response,
|
|||||||
* IN ... : variable argument list
|
* IN ... : variable argument list
|
||||||
* IN va_list ArgList: Argument list
|
* IN va_list ArgList: Argument list
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function creates the action request from the argument
|
* This function creates the action request from the argument
|
||||||
* list. Its a wrapper function that calls makeAction function to create
|
* list. Its a wrapper function that calls makeAction function to create
|
||||||
* the action request.
|
* the action request.
|
||||||
@ -363,9 +363,9 @@ UpnpMakeAction( const char *ActionName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : UpnpMakeActionResponse
|
* Function : UpnpMakeActionResponse
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char * ActionName: Name of the action request or response
|
* IN char * ActionName: Name of the action request or response
|
||||||
* IN char * ServType: Service type
|
* IN char * ServType: Service type
|
||||||
* IN int NumArg :Number of arguments in the action request or response
|
* IN int NumArg :Number of arguments in the action request or response
|
||||||
@ -373,13 +373,13 @@ UpnpMakeAction( const char *ActionName,
|
|||||||
* IN ... : variable argument list
|
* IN ... : variable argument list
|
||||||
* IN va_list ArgList: Argument list
|
* IN va_list ArgList: Argument list
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function creates the action response from the argument
|
* This function creates the action response from the argument
|
||||||
* list. Its a wrapper function that calls makeAction function to create
|
* list. Its a wrapper function that calls makeAction function to create
|
||||||
* the action response.
|
* the action response.
|
||||||
*
|
*
|
||||||
* Returns: IXML_Document *
|
* Returns: IXML_Document *
|
||||||
* returns action response document if successful
|
* returns action response document if successful
|
||||||
* else returns NULL
|
* else returns NULL
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
IXML_Document *
|
IXML_Document *
|
||||||
@ -400,22 +400,22 @@ UpnpMakeActionResponse( const char *ActionName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : UpnpAddToActionResponse
|
* Function : UpnpAddToActionResponse
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* INOUT IXML_Document **ActionResponse: action response document
|
* INOUT IXML_Document **ActionResponse: action response document
|
||||||
* IN char * ActionName: Name of the action request or response
|
* IN char * ActionName: Name of the action request or response
|
||||||
* IN char * ServType: Service type
|
* IN char * ServType: Service type
|
||||||
* IN int ArgName :Name of argument to be added in the action response
|
* IN int ArgName :Name of argument to be added in the action response
|
||||||
* IN char * ArgValue : value of the argument
|
* IN char * ArgValue : value of the argument
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function adds the argument in the action response. Its a wrapper
|
* This function adds the argument in the action response. Its a wrapper
|
||||||
* function that calls addToAction function to add the argument in the
|
* function that calls addToAction function to add the argument in the
|
||||||
* action response.
|
* action response.
|
||||||
*
|
*
|
||||||
* Returns: int
|
* Returns: int
|
||||||
* returns UPNP_E_SUCCESS if successful
|
* returns UPNP_E_SUCCESS if successful
|
||||||
* else returns appropriate error
|
* else returns appropriate error
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
int
|
int
|
||||||
@ -430,22 +430,22 @@ UpnpAddToActionResponse( INOUT IXML_Document ** ActionResponse,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : UpnpAddToAction
|
* Function : UpnpAddToAction
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* INOUT IXML_Document **ActionDoc: action request document
|
* INOUT IXML_Document **ActionDoc: action request document
|
||||||
* IN char * ActionName: Name of the action request or response
|
* IN char * ActionName: Name of the action request or response
|
||||||
* IN char * ServType: Service type
|
* IN char * ServType: Service type
|
||||||
* IN int ArgName :Name of argument to be added in the action response
|
* IN int ArgName :Name of argument to be added in the action response
|
||||||
* IN char * ArgValue : value of the argument
|
* IN char * ArgValue : value of the argument
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function adds the argument in the action request. Its a wrapper
|
* This function adds the argument in the action request. Its a wrapper
|
||||||
* function that calls addToAction function to add the argument in the
|
* function that calls addToAction function to add the argument in the
|
||||||
* action request.
|
* action request.
|
||||||
*
|
*
|
||||||
* Returns: int
|
* Returns: int
|
||||||
* returns UPNP_E_SUCCESS if successful
|
* returns UPNP_E_SUCCESS if successful
|
||||||
* else returns appropriate error
|
* else returns appropriate error
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
int
|
int
|
||||||
@ -461,15 +461,15 @@ UpnpAddToAction( IXML_Document ** ActionDoc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : UpnpAddToPropertySet
|
* Function : UpnpAddToPropertySet
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* INOUT IXML_Document **PropSet: propertyset document
|
* INOUT IXML_Document **PropSet: propertyset document
|
||||||
* IN char *ArgName: Name of the argument
|
* IN char *ArgName: Name of the argument
|
||||||
* IN char *ArgValue: value of the argument
|
* IN char *ArgValue: value of the argument
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function adds the argument in the propertyset node
|
* This function adds the argument in the propertyset node
|
||||||
*
|
*
|
||||||
* Returns: int
|
* Returns: int
|
||||||
* returns UPNP_E_SUCCESS if successful else returns appropriate error
|
* returns UPNP_E_SUCCESS if successful else returns appropriate error
|
||||||
@ -516,14 +516,14 @@ UpnpAddToPropertySet( INOUT IXML_Document ** PropSet,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : UpnpCreatePropertySet
|
* Function : UpnpCreatePropertySet
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN int NumArg: Number of argument that will go in the propertyset node
|
* IN int NumArg: Number of argument that will go in the propertyset node
|
||||||
* IN char * Args: argument strings
|
* IN char * Args: argument strings
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function creates a propertyset node and put all the input
|
* This function creates a propertyset node and put all the input
|
||||||
* parameters in the node as elements
|
* parameters in the node as elements
|
||||||
*
|
*
|
||||||
* Returns: IXML_Document *
|
* Returns: IXML_Document *
|
||||||
@ -581,4 +581,5 @@ UpnpCreatePropertySet( IN int NumArg,
|
|||||||
return PropSet;
|
return PropSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif // EXCLUDE_DOM == 0
|
||||||
|
|
||||||
|
@ -45,12 +45,12 @@
|
|||||||
extern ithread_mutex_t GlobalClientSubscribeMutex;
|
extern ithread_mutex_t GlobalClientSubscribeMutex;
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : GenaAutoRenewSubscription
|
* Function : GenaAutoRenewSubscription
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN void *input: Thread data(upnp_timeout *) needed to send the renewal
|
* IN void *input: Thread data(upnp_timeout *) needed to send the renewal
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This is a thread function to send the renewal just before the
|
* This is a thread function to send the renewal just before the
|
||||||
* subscription times out.
|
* subscription times out.
|
||||||
*
|
*
|
||||||
@ -93,7 +93,7 @@ GenaAutoRenewSubscription( IN void *input )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( send_callback ) {
|
if( send_callback ) {
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
if( GetHandleInfo( event->handle, &handle_info ) != HND_CLIENT ) {
|
if( GetHandleInfo( event->handle, &handle_info ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
free_upnp_timeout( event );
|
free_upnp_timeout( event );
|
||||||
@ -113,14 +113,14 @@ GenaAutoRenewSubscription( IN void *input )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : ScheduleGenaAutoRenew
|
* Function : ScheduleGenaAutoRenew
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN int client_handle: Handle that also contains the subscription list
|
* IN int client_handle: Handle that also contains the subscription list
|
||||||
* IN int TimeOut: The time out value of the subscription
|
* IN int TimeOut: The time out value of the subscription
|
||||||
* IN client_subscription * sub: Subscription being renewed
|
* IN client_subscription * sub: Subscription being renewed
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function schedules a job to renew the subscription just before
|
* This function schedules a job to renew the subscription just before
|
||||||
* time out.
|
* time out.
|
||||||
*
|
*
|
||||||
@ -188,14 +188,14 @@ ScheduleGenaAutoRenew( IN int client_handle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : gena_unsubscribe
|
* Function : gena_unsubscribe
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char *url: Event URL of the service
|
* IN char *url: Event URL of the service
|
||||||
* IN char *sid: The subcription ID.
|
* IN char *sid: The subcription ID.
|
||||||
* OUT http_parser_t* response: The UNSUBCRIBE response from the device
|
* OUT http_parser_t* response: The UNSUBCRIBE response from the device
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function sends the UNSUBCRIBE gena request and recieves the
|
* This function sends the UNSUBCRIBE gena request and recieves the
|
||||||
* response from the device and returns it as a parameter
|
* response from the device and returns it as a parameter
|
||||||
*
|
*
|
||||||
@ -251,9 +251,9 @@ gena_unsubscribe( IN char *url,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : gena_subscribe
|
* Function : gena_subscribe
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char *url: url of service to subscribe
|
* IN char *url: url of service to subscribe
|
||||||
* INOUT int* timeout:subscription time desired (in secs)
|
* INOUT int* timeout:subscription time desired (in secs)
|
||||||
* IN char* renewal_sid:for renewal, this contains a currently h
|
* IN char* renewal_sid:for renewal, this contains a currently h
|
||||||
@ -261,7 +261,7 @@ gena_unsubscribe( IN char *url,
|
|||||||
* subscription, this must be NULL
|
* subscription, this must be NULL
|
||||||
* OUT char** sid: SID returned by the subscription or renew msg
|
* OUT char** sid: SID returned by the subscription or renew msg
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function subscribes or renew subscription
|
* This function subscribes or renew subscription
|
||||||
*
|
*
|
||||||
* Returns: int
|
* Returns: int
|
||||||
@ -374,13 +374,13 @@ gena_subscribe( IN char *url,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : genaUnregisterClient
|
* Function : genaUnregisterClient
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN UpnpClient_Handle client_handle: Handle containing all the control
|
* IN UpnpClient_Handle client_handle: Handle containing all the control
|
||||||
* point related information
|
* point related information
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function unsubcribes all the outstanding subscriptions and cleans
|
* This function unsubcribes all the outstanding subscriptions and cleans
|
||||||
* the subscription list. This function is called when control point
|
* the subscription list. This function is called when control point
|
||||||
* unregisters.
|
* unregisters.
|
||||||
@ -435,12 +435,12 @@ genaUnregisterClient( IN UpnpClient_Handle client_handle )
|
|||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : genaUnSubscribe
|
* Function : genaUnSubscribe
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN UpnpClient_Handle client_handle: UPnP client handle
|
* IN UpnpClient_Handle client_handle: UPnP client handle
|
||||||
* IN SID in_sid: The subscription ID
|
* IN SID in_sid: The subscription ID
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function unsubscribes a SID. It first validates the SID and
|
* This function unsubscribes a SID. It first validates the SID and
|
||||||
* client_handle,copies the subscription, sends UNSUBSCRIBE http request
|
* client_handle,copies the subscription, sends UNSUBSCRIBE http request
|
||||||
* to service processes request and finally removes the subscription
|
* to service processes request and finally removes the subscription
|
||||||
@ -506,8 +506,8 @@ genaUnSubscribe( IN UpnpClient_Handle client_handle,
|
|||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : genaSubscribe
|
* Function : genaSubscribe
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN UpnpClient_Handle client_handle:
|
* IN UpnpClient_Handle client_handle:
|
||||||
* IN char * PublisherURL: NULL Terminated, of the form :
|
* IN char * PublisherURL: NULL Terminated, of the form :
|
||||||
* "http://134.134.156.80:4000/RedBulb/Event"
|
* "http://134.134.156.80:4000/RedBulb/Event"
|
||||||
@ -516,7 +516,7 @@ genaUnSubscribe( IN UpnpClient_Handle client_handle,
|
|||||||
* by Service, -1 for infinite
|
* by Service, -1 for infinite
|
||||||
* OUT Upnp_SID out_sid:sid of subscription, memory passed in by caller
|
* OUT Upnp_SID out_sid:sid of subscription, memory passed in by caller
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function subscribes to a PublisherURL ( also mentioned as EventURL
|
* This function subscribes to a PublisherURL ( also mentioned as EventURL
|
||||||
* some places). It sends SUBSCRIBE http request to service processes
|
* some places). It sends SUBSCRIBE http request to service processes
|
||||||
* request. Finally adds a Subscription to
|
* request. Finally adds a Subscription to
|
||||||
@ -543,10 +543,10 @@ genaSubscribe( IN UpnpClient_Handle client_handle,
|
|||||||
|
|
||||||
UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__,
|
||||||
"GENA SUBSCRIBE BEGIN" );
|
"GENA SUBSCRIBE BEGIN" );
|
||||||
HandleLock();
|
|
||||||
|
|
||||||
memset( out_sid, 0, sizeof( Upnp_SID ) );
|
memset( out_sid, 0, sizeof( Upnp_SID ) );
|
||||||
|
|
||||||
|
HandleReadLock();
|
||||||
// validate handle
|
// validate handle
|
||||||
if( GetHandleInfo( client_handle, &handle_info ) != HND_CLIENT ) {
|
if( GetHandleInfo( client_handle, &handle_info ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
@ -616,15 +616,15 @@ genaSubscribe( IN UpnpClient_Handle client_handle,
|
|||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : genaRenewSubscription
|
* Function : genaRenewSubscription
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN UpnpClient_Handle client_handle: Client handle
|
* IN UpnpClient_Handle client_handle: Client handle
|
||||||
* IN const Upnp_SID in_sid: subscription ID
|
* IN const Upnp_SID in_sid: subscription ID
|
||||||
* INOUT int * TimeOut: requested Duration, if -1, then "infinite".
|
* INOUT int * TimeOut: requested Duration, if -1, then "infinite".
|
||||||
* in the OUT case: actual Duration granted
|
* in the OUT case: actual Duration granted
|
||||||
* by Service, -1 for infinite
|
* by Service, -1 for infinite
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function renews a SID. It first validates the SID and
|
* This function renews a SID. It first validates the SID and
|
||||||
* client_handle and copies the subscription. It sends RENEW
|
* client_handle and copies the subscription. It sends RENEW
|
||||||
* (modified SUBSCRIBE) http request to service and processes
|
* (modified SUBSCRIBE) http request to service and processes
|
||||||
@ -724,14 +724,14 @@ genaRenewSubscription( IN UpnpClient_Handle client_handle,
|
|||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : gena_process_notification_event
|
* Function : gena_process_notification_event
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN SOCKINFO *info: Socket structure containing the device socket
|
* IN SOCKINFO *info: Socket structure containing the device socket
|
||||||
* information
|
* information
|
||||||
* IN http_message_t* event: The http message contains the GENA
|
* IN http_message_t* event: The http message contains the GENA
|
||||||
* notification
|
* notification
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function processes NOTIFY events that are sent by devices.
|
* This function processes NOTIFY events that are sent by devices.
|
||||||
* called by genacallback()
|
* called by genacallback()
|
||||||
*
|
*
|
||||||
@ -881,3 +881,4 @@ gena_process_notification_event( IN SOCKINFO * info,
|
|||||||
|
|
||||||
#endif // INCLUDE_CLIENT_APIS
|
#endif // INCLUDE_CLIENT_APIS
|
||||||
#endif // EXCLUDE_GENA
|
#endif // EXCLUDE_GENA
|
||||||
|
|
||||||
|
@ -365,7 +365,7 @@ genaNotifyThread( IN void *input )
|
|||||||
struct Handle_Info *handle_info;
|
struct Handle_Info *handle_info;
|
||||||
ThreadPoolJob job;
|
ThreadPoolJob job;
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
//validate context
|
//validate context
|
||||||
|
|
||||||
if( GetHandleInfo( in->device_handle, &handle_info ) != HND_DEVICE ) {
|
if( GetHandleInfo( in->device_handle, &handle_info ) != HND_DEVICE ) {
|
||||||
|
@ -36,18 +36,18 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#else
|
#else /* WIN32 */
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
|
||||||
typedef int socklen_t;
|
typedef int socklen_t;
|
||||||
#define EAFNOSUPPORT 97
|
#define EAFNOSUPPORT 97
|
||||||
#endif
|
#endif /* WIN32 */
|
||||||
#include "unixutil.h"
|
#include "unixutil.h"
|
||||||
#include "ithread.h"
|
#include "ithread.h"
|
||||||
|
|
||||||
@ -88,17 +88,16 @@ static MiniServerCallback gGenaCallback = NULL;
|
|||||||
static MiniServerState gMServState = MSERV_IDLE;
|
static MiniServerState gMServState = MSERV_IDLE;
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : SetHTTPGetCallback
|
* Function: SetHTTPGetCallback
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters :
|
||||||
* MiniServerCallback callback ; - HTTP Callback to be invoked
|
* MiniServerCallback callback - HTTP Callback to be invoked
|
||||||
*
|
*
|
||||||
* Description : Set HTTP Get Callback
|
* Description:
|
||||||
*
|
* Set HTTP Get Callback
|
||||||
* Return : void
|
*
|
||||||
*
|
* Return: void
|
||||||
* Note :
|
************************************************************************/
|
||||||
************************************************************************/
|
|
||||||
void
|
void
|
||||||
SetHTTPGetCallback( MiniServerCallback callback )
|
SetHTTPGetCallback( MiniServerCallback callback )
|
||||||
{
|
{
|
||||||
@ -106,35 +105,35 @@ SetHTTPGetCallback( MiniServerCallback callback )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : SetSoapCallback
|
* Function: SetSoapCallback
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* MiniServerCallback callback ; - SOAP Callback to be invoked
|
* MiniServerCallback callback - SOAP Callback to be invoked
|
||||||
*
|
*
|
||||||
* Description : Set SOAP Callback
|
* Description:
|
||||||
*
|
* Set SOAP Callback
|
||||||
* Return : void
|
*
|
||||||
*
|
* Return: void
|
||||||
* Note :
|
************************************************************************/
|
||||||
************************************************************************/
|
#ifdef INCLUDE_DEVICE_APIS
|
||||||
void
|
void
|
||||||
SetSoapCallback( MiniServerCallback callback )
|
SetSoapCallback( MiniServerCallback callback )
|
||||||
{
|
{
|
||||||
gSoapCallback = callback;
|
gSoapCallback = callback;
|
||||||
}
|
}
|
||||||
|
#endif /* INCLUDE_DEVICE_APIS */
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : SetGenaCallback
|
* Function: SetGenaCallback
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* MiniServerCallback callback ; - GENA Callback to be invoked
|
* MiniServerCallback callback - GENA Callback to be invoked
|
||||||
*
|
*
|
||||||
* Description : Set GENA Callback
|
* Description:
|
||||||
*
|
* Set GENA Callback
|
||||||
* Return : void
|
*
|
||||||
*
|
* Return: void
|
||||||
* Note :
|
************************************************************************/
|
||||||
************************************************************************/
|
|
||||||
void
|
void
|
||||||
SetGenaCallback( MiniServerCallback callback )
|
SetGenaCallback( MiniServerCallback callback )
|
||||||
{
|
{
|
||||||
@ -142,21 +141,19 @@ SetGenaCallback( MiniServerCallback callback )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : dispatch_request
|
* Function : dispatch_request
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters :
|
||||||
* IN SOCKINFO *info ; Socket Information object.
|
* IN SOCKINFO *info - Socket Information object.
|
||||||
* http_parser_t* hparser ; HTTP parser object.
|
* http_parser_t* hparser - HTTP parser object.
|
||||||
*
|
*
|
||||||
* Description : Based on the type pf message, appropriate callback
|
* Description :
|
||||||
* is issued
|
* Based on the type pf message, appropriate callback is issued
|
||||||
*
|
*
|
||||||
* Return : int ;
|
* Return: int
|
||||||
* 0 - On Success
|
* 0 - On Success
|
||||||
* HTTP_INTERNAL_SERVER_ERROR - Callback is NULL
|
* HTTP_INTERNAL_SERVER_ERROR - Callback is NULL
|
||||||
*
|
************************************************************************/
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
|
||||||
static int
|
static int
|
||||||
dispatch_request( IN SOCKINFO * info,
|
dispatch_request( IN SOCKINFO * info,
|
||||||
http_parser_t * hparser )
|
http_parser_t * hparser )
|
||||||
@ -200,21 +197,19 @@ dispatch_request( IN SOCKINFO * info,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : handle_error
|
* Function: handle_error
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
*
|
* IN SOCKINFO *info - Socket Inforamtion Object
|
||||||
* IN SOCKINFO *info ; Socket Inforamtion Object
|
* int http_error_code - HTTP Error Code
|
||||||
* int http_error_code ; HTTP Error Code
|
* int major - Major Version Number
|
||||||
* int major ; Major Version Number
|
* int minor - Minor Version Number
|
||||||
* int minor ; Minor Version Number
|
*
|
||||||
*
|
* Description:
|
||||||
* Description : Send Error Message
|
* Send Error Message
|
||||||
*
|
*
|
||||||
* Return : void;
|
* Return: void
|
||||||
*
|
************************************************************************/
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
|
||||||
static UPNP_INLINE void
|
static UPNP_INLINE void
|
||||||
handle_error( IN SOCKINFO * info,
|
handle_error( IN SOCKINFO * info,
|
||||||
int http_error_code,
|
int http_error_code,
|
||||||
@ -225,18 +220,17 @@ handle_error( IN SOCKINFO * info,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : free_handle_request_arg
|
* Function: free_handle_request_arg
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* void *args ; Request Message to be freed
|
* void *args ; Request Message to be freed
|
||||||
*
|
*
|
||||||
* Description : Free memory assigned for handling request and unitial-
|
* Description:
|
||||||
* -ize socket functionality
|
* Free memory assigned for handling request and unitialize socket
|
||||||
*
|
* functionality
|
||||||
* Return : void
|
*
|
||||||
*
|
* Return: void
|
||||||
* Note :
|
************************************************************************/
|
||||||
************************************************************************/
|
|
||||||
static void
|
static void
|
||||||
free_handle_request_arg( void *args )
|
free_handle_request_arg( void *args )
|
||||||
{
|
{
|
||||||
@ -248,17 +242,16 @@ free_handle_request_arg( void *args )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : handle_request
|
* Function: handle_request
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* void *args ; Request Message to be handled
|
* void *args - Request Message to be handled
|
||||||
*
|
*
|
||||||
* Description : Receive the request and dispatch it for handling
|
* Description:
|
||||||
*
|
* Receive the request and dispatch it for handling
|
||||||
* Return : void
|
*
|
||||||
*
|
* Return: void
|
||||||
* Note :
|
************************************************************************/
|
||||||
************************************************************************/
|
|
||||||
static void
|
static void
|
||||||
handle_request( void *args )
|
handle_request( void *args )
|
||||||
{
|
{
|
||||||
@ -319,20 +312,18 @@ handle_request( void *args )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : schedule_request_job
|
* Function: schedule_request_job
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* IN int connfd ; Socket Descriptor on which connection is accepted
|
* IN int connfd - Socket Descriptor on which connection is accepted
|
||||||
* IN struct sockaddr_in* clientAddr ; Clients Address information
|
* IN struct sockaddr_in* clientAddr - Clients Address information
|
||||||
*
|
*
|
||||||
* Description : Initilize the thread pool to handle a request.
|
* Description:
|
||||||
* Sets priority for the job and adds the job to the thread pool
|
* Initilize the thread pool to handle a request.
|
||||||
*
|
* Sets priority for the job and adds the job to the thread pool
|
||||||
*
|
*
|
||||||
* Return : void
|
* Return: void
|
||||||
*
|
************************************************************************/
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
|
||||||
static UPNP_INLINE void
|
static UPNP_INLINE void
|
||||||
schedule_request_job( IN int connfd,
|
schedule_request_job( IN int connfd,
|
||||||
IN struct sockaddr_in *clientAddr )
|
IN struct sockaddr_in *clientAddr )
|
||||||
@ -371,32 +362,31 @@ schedule_request_job( IN int connfd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : RunMiniServer
|
* Function: RunMiniServer
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* MiniServerSockArray *miniSock ; Socket Array
|
* MiniServerSockArray *miniSock - Socket Array
|
||||||
*
|
*
|
||||||
* Description : Function runs the miniserver. The MiniServer accepts a
|
* Description:
|
||||||
* new request and schedules a thread to handle the new request.
|
* Function runs the miniserver. The MiniServer accepts a
|
||||||
* Checks for socket state and invokes appropriate read and shutdown
|
* new request and schedules a thread to handle the new request.
|
||||||
* actions for the Miniserver and SSDP sockets
|
* Checks for socket state and invokes appropriate read and shutdown
|
||||||
*
|
* actions for the Miniserver and SSDP sockets
|
||||||
* Return : void
|
*
|
||||||
*
|
* Return: void
|
||||||
* Note :
|
************************************************************************/
|
||||||
************************************************************************/
|
|
||||||
static void
|
static void
|
||||||
RunMiniServer( MiniServerSockArray * miniSock )
|
RunMiniServer( MiniServerSockArray * miniSock )
|
||||||
{
|
{
|
||||||
struct sockaddr_in clientAddr;
|
struct sockaddr_in clientAddr;
|
||||||
socklen_t clientLen;
|
socklen_t clientLen;
|
||||||
SOCKET miniServSock,
|
SOCKET connectHnd;
|
||||||
connectHnd;
|
SOCKET miniServSock = miniSock->miniServerSock;
|
||||||
SOCKET miniServStopSock;
|
SOCKET miniServStopSock = miniSock->miniServerStopSock;
|
||||||
SOCKET ssdpSock;
|
SOCKET ssdpSock = miniSock->ssdpSock;
|
||||||
|
#ifdef INCLUDE_CLIENT_APIS
|
||||||
CLIENTONLY( SOCKET ssdpReqSock;
|
SOCKET ssdpReqSock = miniSock->ssdpReqSock;
|
||||||
)
|
#endif
|
||||||
|
|
||||||
fd_set expSet;
|
fd_set expSet;
|
||||||
fd_set rdSet;
|
fd_set rdSet;
|
||||||
@ -404,66 +394,55 @@ RunMiniServer( MiniServerSockArray * miniSock )
|
|||||||
int byteReceived;
|
int byteReceived;
|
||||||
char requestBuf[256];
|
char requestBuf[256];
|
||||||
|
|
||||||
miniServSock = miniSock->miniServerSock;
|
maxMiniSock = max( miniServSock, miniServStopSock) ;
|
||||||
miniServStopSock = miniSock->miniServerStopSock;
|
maxMiniSock = max( maxMiniSock, (SOCKET)(ssdpSock) );
|
||||||
|
#ifdef INCLUDE_CLIENT_APIS
|
||||||
ssdpSock = miniSock->ssdpSock;
|
maxMiniSock = max( maxMiniSock, (SOCKET)(ssdpReqSock) );
|
||||||
|
#endif
|
||||||
CLIENTONLY( ssdpReqSock = miniSock->ssdpReqSock;
|
|
||||||
);
|
|
||||||
|
|
||||||
gMServState = MSERV_RUNNING;
|
|
||||||
maxMiniSock = max( miniServSock, miniServStopSock );
|
|
||||||
maxMiniSock = max( maxMiniSock, ( SOCKET ) ( ssdpSock ) );
|
|
||||||
|
|
||||||
CLIENTONLY( maxMiniSock =
|
|
||||||
max( maxMiniSock, ( SOCKET ) ( ssdpReqSock ) ) );
|
|
||||||
|
|
||||||
++maxMiniSock;
|
++maxMiniSock;
|
||||||
|
|
||||||
|
gMServState = MSERV_RUNNING;
|
||||||
while( TRUE ) {
|
while( TRUE ) {
|
||||||
FD_ZERO( &rdSet );
|
FD_ZERO( &rdSet );
|
||||||
FD_ZERO( &expSet );
|
FD_ZERO( &expSet );
|
||||||
|
|
||||||
FD_SET( miniServStopSock, &expSet );
|
FD_SET( miniServStopSock, &expSet );
|
||||||
|
|
||||||
FD_SET( miniServSock, &rdSet );
|
FD_SET( miniServSock, &rdSet );
|
||||||
FD_SET( miniServStopSock, &rdSet );
|
FD_SET( miniServStopSock, &rdSet );
|
||||||
FD_SET( ssdpSock, &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 ) ==
|
if( select( maxMiniSock, &rdSet, NULL, &expSet, NULL ) ==
|
||||||
UPNP_SOCKETERROR ) {
|
UPNP_SOCKETERROR ) {
|
||||||
UpnpPrintf( UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
|
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;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if( FD_ISSET( miniServSock, &rdSet ) ) {
|
if( FD_ISSET( miniServSock, &rdSet ) ) {
|
||||||
clientLen = sizeof( struct sockaddr_in );
|
clientLen = sizeof( struct sockaddr_in );
|
||||||
connectHnd = accept( miniServSock,
|
connectHnd = accept( miniServSock,
|
||||||
( struct sockaddr * )&clientAddr,
|
( struct sockaddr * )&clientAddr, &clientLen );
|
||||||
&clientLen );
|
|
||||||
if( connectHnd == UPNP_INVALID_SOCKET ) {
|
if( connectHnd == UPNP_INVALID_SOCKET ) {
|
||||||
UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__,
|
||||||
"miniserver: Error"
|
"miniserver: Error in accepting connection\n" );
|
||||||
" in accepting connection\n" );
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
schedule_request_job( connectHnd, &clientAddr );
|
schedule_request_job( connectHnd, &clientAddr );
|
||||||
}
|
}
|
||||||
//ssdp
|
#ifdef INCLUDE_CLIENT_APIS
|
||||||
CLIENTONLY( if( FD_ISSET( ssdpReqSock, &rdSet ) ) {
|
// ssdp
|
||||||
|
if( FD_ISSET( ssdpReqSock, &rdSet ) ) {
|
||||||
readFromSSDPSocket( ssdpReqSock );}
|
readFromSSDPSocket( ssdpReqSock );
|
||||||
)
|
}
|
||||||
|
#endif
|
||||||
if( FD_ISSET( ssdpSock, &rdSet ) ) {
|
if( FD_ISSET( ssdpSock, &rdSet ) ) {
|
||||||
readFromSSDPSocket( ssdpSock );
|
readFromSSDPSocket( ssdpSock );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( FD_ISSET( miniServStopSock, &rdSet ) ) {
|
if( FD_ISSET( miniServStopSock, &rdSet ) ) {
|
||||||
|
|
||||||
clientLen = sizeof( struct sockaddr_in );
|
clientLen = sizeof( struct sockaddr_in );
|
||||||
memset( ( char * )&clientAddr, 0,
|
memset( ( char * )&clientAddr, 0,
|
||||||
sizeof( struct sockaddr_in ) );
|
sizeof( struct sockaddr_in ) );
|
||||||
@ -479,7 +458,6 @@ RunMiniServer( MiniServerSockArray * miniSock )
|
|||||||
UpnpPrintf( UPNP_PACKET, MSERV, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_PACKET, MSERV, __FILE__, __LINE__,
|
||||||
"Received multicast packet: \n %s\n",
|
"Received multicast packet: \n %s\n",
|
||||||
requestBuf );
|
requestBuf );
|
||||||
|
|
||||||
if( NULL != strstr( requestBuf, "ShutDown" ) ) {
|
if( NULL != strstr( requestBuf, "ShutDown" ) ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -494,31 +472,30 @@ RunMiniServer( MiniServerSockArray * miniSock )
|
|||||||
UpnpCloseSocket( miniServStopSock );
|
UpnpCloseSocket( miniServStopSock );
|
||||||
shutdown( ssdpSock, SD_BOTH );
|
shutdown( ssdpSock, SD_BOTH );
|
||||||
UpnpCloseSocket( ssdpSock );
|
UpnpCloseSocket( ssdpSock );
|
||||||
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
|
#ifdef INCLUDE_CLIENT_APIS
|
||||||
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
|
shutdown( ssdpReqSock, SD_BOTH );
|
||||||
|
UpnpCloseSocket( ssdpReqSock );
|
||||||
|
#endif
|
||||||
|
|
||||||
free( miniSock );
|
free( miniSock );
|
||||||
|
|
||||||
gMServState = MSERV_IDLE;
|
gMServState = MSERV_IDLE;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : get_port
|
* Function: get_port
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* int sockfd ; Socket Descriptor
|
* int sockfd - Socket Descriptor
|
||||||
*
|
*
|
||||||
* Description : Returns port to which socket, sockfd, is bound.
|
* Description:
|
||||||
*
|
* Returns port to which socket, sockfd, is bound.
|
||||||
* Return : int,
|
*
|
||||||
* -1 on error; check errno
|
* Return: int
|
||||||
* > 0 means port number
|
* -1 on error; check errno
|
||||||
*
|
* > 0 means port number
|
||||||
* Note :
|
************************************************************************/
|
||||||
************************************************************************/
|
|
||||||
static int
|
static int
|
||||||
get_port( int sockfd )
|
get_port( int sockfd )
|
||||||
{
|
{
|
||||||
@ -541,28 +518,28 @@ get_port( int sockfd )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : get_miniserver_sockets
|
* Function: get_miniserver_sockets
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* MiniServerSockArray *out ; Socket Array
|
* MiniServerSockArray *out - Socket Array
|
||||||
* unsigned short listen_port ; port on which the server is listening
|
* unsigned short listen_port - port on which the server is
|
||||||
* for incoming connections
|
* listening for incoming connections
|
||||||
*
|
*
|
||||||
* Description : Creates a STREAM socket, binds to INADDR_ANY and
|
* Description:
|
||||||
* listens for incoming connecttions. Returns the actual port which
|
* Creates a STREAM socket, binds to INADDR_ANY and listens for
|
||||||
* the sockets sub-system returned.
|
* incoming connecttions. Returns the actual port which the sockets
|
||||||
* Also creates a DGRAM socket, binds to the loop back address and
|
* sub-system returned.
|
||||||
* returns the port allocated by the socket sub-system.
|
*
|
||||||
*
|
* Also creates a DGRAM socket, binds to the loop back address and
|
||||||
* Return : int :
|
* returns the port allocated by the socket sub-system.
|
||||||
* UPNP_E_OUTOF_SOCKET - Failed to create a socket
|
*
|
||||||
* UPNP_E_SOCKET_BIND - Bind() failed
|
* Return: int
|
||||||
* UPNP_E_LISTEN - Listen() failed
|
* UPNP_E_OUTOF_SOCKET - Failed to create a socket
|
||||||
* UPNP_E_INTERNAL_ERROR - Port returned by the socket layer is < 0
|
* UPNP_E_SOCKET_BIND - Bind() failed
|
||||||
* UPNP_E_SUCCESS - Success
|
* UPNP_E_LISTEN - Listen() failed
|
||||||
*
|
* UPNP_E_INTERNAL_ERROR - Port returned by the socket layer is < 0
|
||||||
* Note :
|
* UPNP_E_SUCCESS - Success
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int
|
int
|
||||||
get_miniserver_sockets( MiniServerSockArray * out,
|
get_miniserver_sockets( MiniServerSockArray * out,
|
||||||
unsigned short listen_port )
|
unsigned short listen_port )
|
||||||
@ -692,8 +669,8 @@ get_miniserver_sockets( MiniServerSockArray * out,
|
|||||||
miniStopSockPort = get_port( miniServerStopSock );
|
miniStopSockPort = get_port( miniServerStopSock );
|
||||||
if( miniStopSockPort <= 0 ) {
|
if( miniStopSockPort <= 0 ) {
|
||||||
shutdown( miniServerStopSock, SD_BOTH );
|
shutdown( miniServerStopSock, SD_BOTH );
|
||||||
shutdown( listenfd, SD_BOTH );
|
|
||||||
UpnpCloseSocket( miniServerStopSock );
|
UpnpCloseSocket( miniServerStopSock );
|
||||||
|
shutdown( listenfd, SD_BOTH );
|
||||||
UpnpCloseSocket( listenfd );
|
UpnpCloseSocket( listenfd );
|
||||||
return UPNP_E_INTERNAL_ERROR;
|
return UPNP_E_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
@ -708,31 +685,29 @@ get_miniserver_sockets( MiniServerSockArray * out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : StartMiniServer
|
* Function: StartMiniServer
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters :
|
||||||
* unsigned short listen_port ; Port on which the server listens for
|
* unsigned short listen_port - Port on which the server listens for
|
||||||
* incoming connections
|
* incoming connections
|
||||||
*
|
*
|
||||||
* Description : Initialize the sockets functionality for the
|
* Description:
|
||||||
* Miniserver. Initialize a thread pool job to run the MiniServer
|
* Initialize the sockets functionality for the
|
||||||
* and the job to the thread pool. If listen port is 0, port is
|
* Miniserver. Initialize a thread pool job to run the MiniServer
|
||||||
* dynamically picked
|
* 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.
|
* 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:
|
* Return: int
|
||||||
* A negative number UPNP_E_XXX - On Error
|
* Actual port socket is bound to - On Success
|
||||||
* Note :
|
* A negative number UPNP_E_XXX - On Error
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int
|
int
|
||||||
StartMiniServer( unsigned short listen_port )
|
StartMiniServer( unsigned short listen_port )
|
||||||
{
|
{
|
||||||
|
|
||||||
int success;
|
int success;
|
||||||
|
|
||||||
int count;
|
int count;
|
||||||
int max_count = 10000;
|
int max_count = 10000;
|
||||||
|
|
||||||
@ -755,12 +730,10 @@ StartMiniServer( unsigned short listen_port )
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( ( success = get_ssdp_sockets( miniSocket ) ) != UPNP_E_SUCCESS ) {
|
if( ( success = get_ssdp_sockets( miniSocket ) ) != UPNP_E_SUCCESS ) {
|
||||||
|
|
||||||
shutdown( miniSocket->miniServerSock, SD_BOTH );
|
shutdown( miniSocket->miniServerSock, SD_BOTH );
|
||||||
UpnpCloseSocket( miniSocket->miniServerSock );
|
UpnpCloseSocket( miniSocket->miniServerSock );
|
||||||
shutdown( miniSocket->miniServerStopSock, SD_BOTH );
|
shutdown( miniSocket->miniServerStopSock, SD_BOTH );
|
||||||
UpnpCloseSocket( miniSocket->miniServerStopSock );
|
UpnpCloseSocket( miniSocket->miniServerStopSock );
|
||||||
|
|
||||||
free( miniSocket );
|
free( miniSocket );
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
@ -776,14 +749,15 @@ StartMiniServer( unsigned short listen_port )
|
|||||||
|
|
||||||
if( success < 0 ) {
|
if( success < 0 ) {
|
||||||
shutdown( miniSocket->miniServerSock, SD_BOTH );
|
shutdown( miniSocket->miniServerSock, SD_BOTH );
|
||||||
shutdown( miniSocket->miniServerStopSock, SD_BOTH );
|
|
||||||
shutdown( miniSocket->ssdpSock, SD_BOTH );
|
|
||||||
CLIENTONLY( shutdown( miniSocket->ssdpReqSock, SD_BOTH ) );
|
|
||||||
UpnpCloseSocket( miniSocket->miniServerSock );
|
UpnpCloseSocket( miniSocket->miniServerSock );
|
||||||
|
shutdown( miniSocket->miniServerStopSock, SD_BOTH );
|
||||||
UpnpCloseSocket( miniSocket->miniServerStopSock );
|
UpnpCloseSocket( miniSocket->miniServerStopSock );
|
||||||
|
shutdown( miniSocket->ssdpSock, SD_BOTH );
|
||||||
UpnpCloseSocket( miniSocket->ssdpSock );
|
UpnpCloseSocket( miniSocket->ssdpSock );
|
||||||
|
#ifdef INCLUDE_CLIENT_APIS
|
||||||
CLIENTONLY( UpnpCloseSocket( miniSocket->ssdpReqSock ) );
|
shutdown( miniSocket->ssdpReqSock, SD_BOTH );
|
||||||
|
UpnpCloseSocket( miniSocket->ssdpReqSock );
|
||||||
|
#endif
|
||||||
|
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
return UPNP_E_OUTOF_MEMORY;
|
||||||
}
|
}
|
||||||
@ -796,16 +770,16 @@ StartMiniServer( unsigned short listen_port )
|
|||||||
|
|
||||||
// taking too long to start that thread
|
// taking too long to start that thread
|
||||||
if( count >= max_count ) {
|
if( count >= max_count ) {
|
||||||
|
|
||||||
shutdown( miniSocket->miniServerSock, SD_BOTH );
|
shutdown( miniSocket->miniServerSock, SD_BOTH );
|
||||||
shutdown( miniSocket->miniServerStopSock, SD_BOTH );
|
|
||||||
shutdown( miniSocket->ssdpSock, SD_BOTH );
|
|
||||||
CLIENTONLY( shutdown( miniSocket->ssdpReqSock, SD_BOTH ) );
|
|
||||||
|
|
||||||
UpnpCloseSocket( miniSocket->miniServerSock );
|
UpnpCloseSocket( miniSocket->miniServerSock );
|
||||||
|
shutdown( miniSocket->miniServerStopSock, SD_BOTH );
|
||||||
UpnpCloseSocket( miniSocket->miniServerStopSock );
|
UpnpCloseSocket( miniSocket->miniServerStopSock );
|
||||||
|
shutdown( miniSocket->ssdpSock, SD_BOTH );
|
||||||
UpnpCloseSocket( miniSocket->ssdpSock );
|
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;
|
return UPNP_E_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
@ -814,33 +788,33 @@ StartMiniServer( unsigned short listen_port )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : StopMiniServer
|
* Function: StopMiniServer
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* void ;
|
* void
|
||||||
*
|
*
|
||||||
* Description : Stop and Shutdown the MiniServer and free socket
|
* Description:
|
||||||
* resources.
|
* Stop and Shutdown the MiniServer and free socket
|
||||||
*
|
* resources.
|
||||||
* Return : int ;
|
*
|
||||||
* Always returns 0
|
* Return: int
|
||||||
*
|
* Always returns 0
|
||||||
* Note :
|
************************************************************************/
|
||||||
************************************************************************/
|
|
||||||
int
|
int
|
||||||
StopMiniServer( void )
|
StopMiniServer( void )
|
||||||
{
|
{
|
||||||
|
|
||||||
int socklen = sizeof( struct sockaddr_in ),
|
int socklen = sizeof( struct sockaddr_in );
|
||||||
sock;
|
int sock;
|
||||||
struct sockaddr_in ssdpAddr;
|
struct sockaddr_in ssdpAddr;
|
||||||
char buf[256] = "ShutDown";
|
char buf[256] = "ShutDown";
|
||||||
int bufLen = strlen( buf );
|
int bufLen = strlen( buf );
|
||||||
|
|
||||||
if( gMServState == MSERV_RUNNING )
|
if( gMServState == MSERV_RUNNING ) {
|
||||||
gMServState = MSERV_STOPPING;
|
gMServState = MSERV_STOPPING;
|
||||||
else
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
sock = socket( AF_INET, SOCK_DGRAM, 0 );
|
sock = socket( AF_INET, SOCK_DGRAM, 0 );
|
||||||
if( sock == UPNP_INVALID_SOCKET ) {
|
if( sock == UPNP_INVALID_SOCKET ) {
|
||||||
@ -864,3 +838,4 @@ StopMiniServer( void )
|
|||||||
UpnpCloseSocket( sock );
|
UpnpCloseSocket( sock );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -29,10 +29,10 @@
|
|||||||
//
|
//
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/************************************************************************
|
/******************************************************************************
|
||||||
* Purpose: This file defines the Web Server and has functions to carry out
|
* Purpose: This file defines the Web Server and has functions to carry out
|
||||||
* operations of the Web Server.
|
* operations of the Web Server.
|
||||||
************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -64,8 +64,12 @@
|
|||||||
/*
|
/*
|
||||||
Response Types
|
Response Types
|
||||||
*/
|
*/
|
||||||
enum resp_type { RESP_FILEDOC, RESP_XMLDOC, RESP_HEADERS, RESP_WEBDOC,
|
enum resp_type {
|
||||||
RESP_POST };
|
RESP_FILEDOC,
|
||||||
|
RESP_XMLDOC,
|
||||||
|
RESP_HEADERS,
|
||||||
|
RESP_WEBDOC,
|
||||||
|
RESP_POST };
|
||||||
|
|
||||||
// mapping of file extension to content-type of document
|
// mapping of file extension to content-type of document
|
||||||
struct document_type_t {
|
struct document_type_t {
|
||||||
@ -95,18 +99,18 @@ static const char *gMediaTypes[] = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// index into 'gMediaTypes'
|
// index into 'gMediaTypes'
|
||||||
#define AUDIO_STR "\1"
|
#define AUDIO_STR "\1"
|
||||||
#define VIDEO_STR "\2"
|
#define VIDEO_STR "\2"
|
||||||
#define IMAGE_STR "\3"
|
#define IMAGE_STR "\3"
|
||||||
#define APPLICATION_STR "\4"
|
#define APPLICATION_STR "\4"
|
||||||
#define TEXT_STR "\5"
|
#define TEXT_STR "\5"
|
||||||
|
|
||||||
// int index
|
// int index
|
||||||
#define APPLICATION_INDEX 4
|
#define APPLICATION_INDEX 4
|
||||||
#define TEXT_INDEX 5
|
#define TEXT_INDEX 5
|
||||||
|
|
||||||
// general
|
// general
|
||||||
#define NUM_MEDIA_TYPES 69
|
#define NUM_MEDIA_TYPES 69
|
||||||
#define NUM_HTTP_HEADER_NAMES 33
|
#define NUM_HTTP_HEADER_NAMES 33
|
||||||
|
|
||||||
// sorted by file extension; must have 'NUM_MEDIA_TYPES' extensions
|
// 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";
|
"zip\0" APPLICATION_STR "zip\0" "\0";
|
||||||
// *** end ***
|
// *** end ***
|
||||||
|
|
||||||
/***********************************************************************/
|
/************************************************************************
|
||||||
/*
|
|
||||||
module variables - Globals, static and externs
|
module variables - Globals, static and externs
|
||||||
*/
|
************************************************************************/
|
||||||
|
|
||||||
/***********************************************************************/
|
|
||||||
static struct document_type_t gMediaTypeList[NUM_MEDIA_TYPES];
|
static struct document_type_t gMediaTypeList[NUM_MEDIA_TYPES];
|
||||||
membuffer gDocumentRootDir; // a local dir which serves as webserver root
|
membuffer gDocumentRootDir; // a local dir which serves as webserver root
|
||||||
static struct xml_alias_t gAliasDoc; // XML document
|
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];
|
extern str_int_entry Http_Header_Names[NUM_HTTP_HEADER_NAMES];
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: has_xml_content_type
|
* Function: has_xml_content_type
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* none
|
* none
|
||||||
*
|
*
|
||||||
* Description: decodes list and stores it in gMediaTypeList
|
* Description: decodes list and stores it in gMediaTypeList
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* void
|
* void
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static UPNP_INLINE void
|
static UPNP_INLINE void
|
||||||
media_list_init( void )
|
media_list_init( void )
|
||||||
{
|
{
|
||||||
@ -229,20 +230,20 @@ media_list_init( void )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: has_xml_content_type
|
* Function: has_xml_content_type
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN const char* extension ;
|
* IN const char* extension ;
|
||||||
* OUT const char** con_type,
|
* OUT const char** con_type,
|
||||||
* OUT const char** con_subtype
|
* OUT const char** con_subtype
|
||||||
*
|
*
|
||||||
* Description: Based on the extension, returns the content type and
|
* Description: Based on the extension, returns the content type and
|
||||||
* content subtype
|
* content subtype
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* 0 on success;
|
* 0 on success;
|
||||||
* -1 on error
|
* -1 on error
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static UPNP_INLINE int
|
static UPNP_INLINE int
|
||||||
search_extension( IN const char *extension,
|
search_extension( IN const char *extension,
|
||||||
OUT const char **con_type,
|
OUT const char **con_type,
|
||||||
@ -276,20 +277,20 @@ search_extension( IN const char *extension,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: get_content_type
|
* Function: get_content_type
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN const char* filename,
|
* IN const char* filename,
|
||||||
* OUT DOMString* content_type
|
* OUT DOMString* content_type
|
||||||
*
|
*
|
||||||
* Description: Based on the extension, clones an XML string based on
|
* Description: Based on the extension, clones an XML string based on
|
||||||
* type and content subtype. If content type and sub type are not
|
* type and content subtype. If content type and sub type are not
|
||||||
* found, unknown types are used
|
* found, unknown types are used
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* 0 - On Sucess
|
* 0 - On Sucess
|
||||||
* UPNP_E_OUTOF_MEMORY - on memory allocation failures
|
* UPNP_E_OUTOF_MEMORY - on memory allocation failures
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
UPNP_INLINE int
|
UPNP_INLINE int
|
||||||
get_content_type( IN const char *filename,
|
get_content_type( IN const char *filename,
|
||||||
OUT DOMString * content_type )
|
OUT DOMString * content_type )
|
||||||
@ -337,17 +338,17 @@ get_content_type( IN const char *filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: glob_alias_init
|
* Function: glob_alias_init
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* none
|
* none
|
||||||
*
|
*
|
||||||
* Description: Initialize the global XML document. Allocate buffers
|
* Description: Initialize the global XML document. Allocate buffers
|
||||||
* for the XML document
|
* for the XML document
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* void
|
* void
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static UPNP_INLINE void
|
static UPNP_INLINE void
|
||||||
glob_alias_init( void )
|
glob_alias_init( void )
|
||||||
{
|
{
|
||||||
@ -360,16 +361,16 @@ glob_alias_init( void )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: is_valid_alias
|
* Function: is_valid_alias
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN const struct xml_alias_t* alias ; XML alias object
|
* IN const struct xml_alias_t* alias ; XML alias object
|
||||||
*
|
*
|
||||||
* Description: Check for the validity of the XML object buffer
|
* Description: Check for the validity of the XML object buffer
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* BOOLEAN
|
* BOOLEAN
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static UPNP_INLINE xboolean
|
static UPNP_INLINE xboolean
|
||||||
is_valid_alias( IN const struct xml_alias_t *alias )
|
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
|
* Function: alias_grab
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* OUT struct xml_alias_t* alias ; XML alias object
|
* OUT struct xml_alias_t* alias ; XML alias object
|
||||||
*
|
*
|
||||||
* Description: Copy the contents of the global XML document into the
|
* Description: Copy the contents of the global XML document into the
|
||||||
* local OUT parameter
|
* local OUT parameter
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* void
|
* void
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static void
|
static void
|
||||||
alias_grab( OUT struct xml_alias_t *alias )
|
alias_grab( OUT struct xml_alias_t *alias )
|
||||||
{
|
{
|
||||||
@ -402,17 +403,17 @@ alias_grab( OUT struct xml_alias_t *alias )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: alias_release
|
* Function: alias_release
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN struct xml_alias_t* alias ; XML alias object
|
* IN struct xml_alias_t* alias ; XML alias object
|
||||||
*
|
*
|
||||||
* Description: Release the XML document referred to by the IN parameter
|
* Description: Release the XML document referred to by the IN parameter
|
||||||
* Free the allocated buffers associated with this object
|
* Free the allocated buffers associated with this object
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* void
|
* void
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static void
|
static void
|
||||||
alias_release( IN struct xml_alias_t *alias )
|
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
|
* Function: web_server_set_alias
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* alias_name: webserver name of alias; created by caller and freed by
|
* alias_name: webserver name of alias; created by caller and freed by
|
||||||
* caller (doesn't even have to be malloc()d .)
|
* caller (doesn't even have to be malloc()d .)
|
||||||
* alias_content: the xml doc; this is allocated by the caller; and
|
* alias_content: the xml doc; this is allocated by the caller; and
|
||||||
* freed by the web server
|
* freed by the web server
|
||||||
* alias_content_length: length of alias body in bytes
|
* alias_content_length: length of alias body in bytes
|
||||||
* last_modified: time when the contents of alias were last
|
* last_modified: time when the contents of alias were last
|
||||||
* changed (local time)
|
* changed (local time)
|
||||||
*
|
*
|
||||||
* Description: Replaces current alias with the given alias. To remove
|
* Description: Replaces current alias with the given alias. To remove
|
||||||
* the current alias, set alias_name to NULL.
|
* the current alias, set alias_name to NULL.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* 0 - OK
|
* 0 - OK
|
||||||
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int
|
int
|
||||||
web_server_set_alias( IN const char *alias_name,
|
web_server_set_alias( IN const char *alias_name,
|
||||||
IN const char *alias_content,
|
IN const char *alias_content,
|
||||||
@ -516,19 +517,19 @@ web_server_set_alias( IN const char *alias_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: web_server_init
|
* Function: web_server_init
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* none
|
* none
|
||||||
*
|
*
|
||||||
* Description: Initilialize the different documents. Initialize the
|
* Description: Initilialize the different documents. Initialize the
|
||||||
* memory for root directory for web server. Call to initialize global
|
* memory for root directory for web server. Call to initialize global
|
||||||
* XML document. Sets bWebServerState to WEB_SERVER_ENABLED
|
* XML document. Sets bWebServerState to WEB_SERVER_ENABLED
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* 0 - OK
|
* 0 - OK
|
||||||
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int
|
int
|
||||||
web_server_init( void )
|
web_server_init( void )
|
||||||
{
|
{
|
||||||
@ -552,18 +553,18 @@ web_server_init( void )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: web_server_destroy
|
* Function: web_server_destroy
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* none
|
* none
|
||||||
*
|
*
|
||||||
* Description: Release memory allocated for the global web server root
|
* Description: Release memory allocated for the global web server root
|
||||||
* directory and the global XML document
|
* directory and the global XML document
|
||||||
* Resets the flag bWebServerState to WEB_SERVER_DISABLED
|
* Resets the flag bWebServerState to WEB_SERVER_DISABLED
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* void
|
* void
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
void
|
void
|
||||||
web_server_destroy( void )
|
web_server_destroy( void )
|
||||||
{
|
{
|
||||||
@ -584,23 +585,22 @@ web_server_destroy( void )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: get_file_info
|
* Function: get_file_info
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN const char* filename ; Filename having the description document
|
* IN const char* filename ; Filename having the description document
|
||||||
* OUT struct File_Info * info ; File information object having file
|
* OUT struct File_Info * info ; File information object having file
|
||||||
* attributes such as filelength, when was
|
* attributes such as filelength, when was the file last
|
||||||
* the file last modified, whether a file
|
* modified, whether a file or a directory and whether the
|
||||||
* or a directory and whether the file or
|
* file or directory is readable.
|
||||||
* directory is readable.
|
*
|
||||||
*
|
* Description: Release memory allocated for the global web server root
|
||||||
* Description: Release memory allocated for the global web server root
|
* directory and the global XML document
|
||||||
* directory and the global XML document
|
* Resets the flag bWebServerState to WEB_SERVER_DISABLED
|
||||||
* Resets the flag bWebServerState to WEB_SERVER_DISABLED
|
*
|
||||||
*
|
* Returns:
|
||||||
* Returns:
|
* int
|
||||||
* int
|
************************************************************************/
|
||||||
************************************************************************/
|
|
||||||
static int
|
static int
|
||||||
get_file_info( IN const char *filename,
|
get_file_info( IN const char *filename,
|
||||||
OUT struct File_Info *info )
|
OUT struct File_Info *info )
|
||||||
@ -647,19 +647,19 @@ get_file_info( IN const char *filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: web_server_set_root_dir
|
* Function: web_server_set_root_dir
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN const char* root_dir ; String having the root directory for the
|
* IN const char* root_dir ; String having the root directory for the
|
||||||
* document
|
* document
|
||||||
*
|
*
|
||||||
* Description: Assign the path specfied by the IN const char* root_dir
|
* Description: Assign the path specfied by the IN const char* root_dir
|
||||||
* parameter to the global Document root directory. Also check for
|
* parameter to the global Document root directory. Also check for
|
||||||
* path names ending in '/'
|
* path names ending in '/'
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* int
|
* int
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int
|
int
|
||||||
web_server_set_root_dir( IN const char *root_dir )
|
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
|
* Function: get_alias
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN const char* request_file ; request file passed in to be compared with
|
* 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
|
* OUT struct xml_alias_t* alias ; xml alias object which has a file name
|
||||||
* stored
|
* stored
|
||||||
* OUT struct File_Info * info ; File information object which will be
|
* OUT struct File_Info * info ; File information object which will be
|
||||||
* filled up if the file comparison
|
* filled up if the file comparison succeeds
|
||||||
* succeeds
|
*
|
||||||
*
|
* Description: Compare the files names between the one on the XML alias
|
||||||
* Description: Compare the files names between the one on the XML alias
|
* the one passed in as the input parameter. If equal extract file
|
||||||
* the one passed in as the input parameter. If equal extract file
|
* information
|
||||||
* information
|
*
|
||||||
*
|
* Returns:
|
||||||
* Returns:
|
* TRUE - On Success
|
||||||
* TRUE - On Success
|
* FALSE if request is not an alias
|
||||||
* FALSE if request is not an alias
|
************************************************************************/
|
||||||
************************************************************************/
|
|
||||||
static UPNP_INLINE xboolean
|
static UPNP_INLINE xboolean
|
||||||
get_alias( IN const char *request_file,
|
get_alias( IN const char *request_file,
|
||||||
OUT struct xml_alias_t *alias,
|
OUT struct xml_alias_t *alias,
|
||||||
@ -720,17 +719,17 @@ get_alias( IN const char *request_file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: isFileInVirtualDir
|
* Function: isFileInVirtualDir
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char *filePath ; directory path to be tested for virtual directory
|
* IN char *filePath ; directory path to be tested for virtual directory
|
||||||
*
|
*
|
||||||
* Description: Compares filePath with paths from the list of virtual
|
* Description: Compares filePath with paths from the list of virtual
|
||||||
* directory lists
|
* directory lists
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* BOOLEAN
|
* BOOLEAN
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int
|
int
|
||||||
isFileInVirtualDir( IN char *filePath )
|
isFileInVirtualDir( IN char *filePath )
|
||||||
{
|
{
|
||||||
@ -746,7 +745,7 @@ isFileInVirtualDir( IN char *filePath )
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
if( ( strncmp( pCurVirtualDir->dirName, filePath, webDirLen )
|
if( ( strncmp( pCurVirtualDir->dirName, filePath, webDirLen )
|
||||||
== 0 ) && ( filePath[webDirLen] == '/' ) )
|
== 0 ) && ( filePath[webDirLen] == '/' || filePath[webDirLen] == '\0' || filePath[webDirLen] == '?' ) )
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -757,16 +756,16 @@ isFileInVirtualDir( IN char *filePath )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: ToUpperCase
|
* Function: ToUpperCase
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* INOUT char * Str ; Input string to be converted
|
* INOUT char * Str ; Input string to be converted
|
||||||
*
|
*
|
||||||
* Description: Converts input string to upper case
|
* Description: Converts input string to upper case
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* int
|
* int
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int
|
int
|
||||||
ToUpperCase( char *Str )
|
ToUpperCase( char *Str )
|
||||||
{
|
{
|
||||||
@ -779,17 +778,17 @@ ToUpperCase( char *Str )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: StrStr
|
* Function: StrStr
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char * S1 ; Input string
|
* IN char * S1 ; Input string
|
||||||
* IN char * S2 ; Input sub-string
|
* IN char * S2 ; Input sub-string
|
||||||
*
|
*
|
||||||
* Description: Finds a substring from a string
|
* Description: Finds a substring from a string
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* char * ptr - pointer to the first occurence of S2 in S1
|
* char * ptr - pointer to the first occurence of S2 in S1
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
char *
|
char *
|
||||||
StrStr( char *S1,
|
StrStr( char *S1,
|
||||||
char *S2 )
|
char *S2 )
|
||||||
@ -829,17 +828,17 @@ StrStr( char *S1,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: StrTok
|
* Function: StrTok
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char ** Src ; String containing the token
|
* IN char ** Src ; String containing the token
|
||||||
* IN char * del ; Set of delimiter characters
|
* IN char * del ; Set of delimiter characters
|
||||||
*
|
*
|
||||||
* Description: Finds next token in a string
|
* Description: Finds next token in a string
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* char * ptr - pointer to the first occurence of S2 in S1
|
* char * ptr - pointer to the first occurence of S2 in S1
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
char *
|
char *
|
||||||
StrTok( char **Src,
|
StrTok( char **Src,
|
||||||
char *Del )
|
char *Del )
|
||||||
@ -863,39 +862,41 @@ StrTok( char **Src,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: GetNextRange
|
* Function: GetNextRange
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char ** SrcRangeStr ; string containing the token / range
|
* IN char ** SrcRangeStr ; string containing the token / range
|
||||||
* OUT int * FirstByte ; gets the first byte of the token
|
* OUT int * FirstByte ; gets the first byte of the token
|
||||||
* OUT int * LastByte ; gets the last byte of the token
|
* OUT int * LastByte ; gets the last byte of the token
|
||||||
*
|
*
|
||||||
* Description: Returns a range of integers from a sring
|
* Description: Returns a range of integers from a string
|
||||||
*
|
*
|
||||||
* Returns: int ;
|
* Returns: int ;
|
||||||
* always returns 1;
|
* always returns 1;
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int
|
int
|
||||||
GetNextRange( char **SrcRangeStr,
|
GetNextRange( char **SrcRangeStr,
|
||||||
off_t *FirstByte,
|
off_t *FirstByte,
|
||||||
off_t *LastByte )
|
off_t *LastByte )
|
||||||
{
|
{
|
||||||
char *Ptr,
|
char *Ptr;
|
||||||
*Tok;
|
char *Tok;
|
||||||
int i,
|
int i;
|
||||||
F = -1,
|
int64_t F = -1;
|
||||||
L = -1;
|
int64_t L = -1;
|
||||||
int Is_Suffix_byte_Range = 1;
|
int Is_Suffix_byte_Range = 1;
|
||||||
|
|
||||||
if( *SrcRangeStr == NULL )
|
if( *SrcRangeStr == NULL ) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
Tok = StrTok( SrcRangeStr, "," );
|
Tok = StrTok( SrcRangeStr, "," );
|
||||||
|
|
||||||
if( ( Ptr = strstr( Tok, "-" ) ) == NULL )
|
if( ( Ptr = strstr( Tok, "-" ) ) == NULL ) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
*Ptr = ' ';
|
*Ptr = ' ';
|
||||||
sscanf( Tok, "%d%d", &F, &L );
|
sscanf( Tok, "%"SCNd64"%"SCNd64, &F, &L );
|
||||||
|
|
||||||
if( F == -1 || L == -1 ) {
|
if( F == -1 || L == -1 ) {
|
||||||
*Ptr = '-';
|
*Ptr = '-';
|
||||||
@ -910,36 +911,35 @@ GetNextRange( char **SrcRangeStr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( Is_Suffix_byte_Range ) {
|
if( Is_Suffix_byte_Range ) {
|
||||||
*FirstByte = L;
|
*FirstByte = (off_t)L;
|
||||||
*LastByte = F;
|
*LastByte = (off_t)F;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*FirstByte = (off_t)F;
|
||||||
|
*LastByte = (off_t)L;
|
||||||
|
|
||||||
*FirstByte = F;
|
|
||||||
*LastByte = L;
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: CreateHTTPRangeResponseHeader
|
* Function: CreateHTTPRangeResponseHeader
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* char * ByteRangeSpecifier ; String containing the range
|
* char * ByteRangeSpecifier ; String containing the range
|
||||||
* long FileLength ; Length of the file
|
* long FileLength ; Length of the file
|
||||||
* OUT struct SendInstruction * Instr ; SendInstruction object where the
|
* OUT struct SendInstruction * Instr ; SendInstruction object
|
||||||
* range operations will be stored
|
* where the range operations will be stored
|
||||||
*
|
*
|
||||||
* Description: Fills in the Offset, read size and contents to send out
|
* Description: Fills in the Offset, read size and contents to send out
|
||||||
* as an HTTP Range Response
|
* as an HTTP Range Response
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* HTTP_BAD_REQUEST
|
* HTTP_BAD_REQUEST
|
||||||
* UPNP_E_OUTOF_MEMORY
|
* UPNP_E_OUTOF_MEMORY
|
||||||
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
|
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
|
||||||
* HTTP_OK
|
* HTTP_OK
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int
|
int
|
||||||
CreateHTTPRangeResponseHeader( char *ByteRangeSpecifier,
|
CreateHTTPRangeResponseHeader( char *ByteRangeSpecifier,
|
||||||
off_t FileLength,
|
off_t FileLength,
|
||||||
@ -1035,24 +1035,24 @@ CreateHTTPRangeResponseHeader( char *ByteRangeSpecifier,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: CheckOtherHTTPHeaders
|
* Function: CheckOtherHTTPHeaders
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN http_message_t * Req ; HTTP Request message
|
* IN http_message_t * Req ; HTTP Request message
|
||||||
* OUT struct SendInstruction * RespInstr ; Send Instruction object to
|
* OUT struct SendInstruction * RespInstr ; Send Instruction object to
|
||||||
* data for the response
|
* data for the response
|
||||||
* int FileSize ; Size of the file containing the request document
|
* int FileSize ; Size of the file containing the request document
|
||||||
*
|
*
|
||||||
* Description: Get header id from the request parameter and take
|
* Description: Get header id from the request parameter and take
|
||||||
* appropriate action based on the ids.
|
* appropriate action based on the ids.
|
||||||
* as an HTTP Range Response
|
* as an HTTP Range Response
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* HTTP_BAD_REQUEST
|
* HTTP_BAD_REQUEST
|
||||||
* UPNP_E_OUTOF_MEMORY
|
* UPNP_E_OUTOF_MEMORY
|
||||||
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
|
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
|
||||||
* HTTP_OK
|
* HTTP_OK
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int
|
int
|
||||||
CheckOtherHTTPHeaders( IN http_message_t * Req,
|
CheckOtherHTTPHeaders( IN http_message_t * Req,
|
||||||
OUT struct SendInstruction *RespInstr,
|
OUT struct SendInstruction *RespInstr,
|
||||||
@ -1166,27 +1166,27 @@ CheckOtherHTTPHeaders( IN http_message_t * Req,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: process_request
|
* Function: process_request
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN http_message_t *req ; HTTP Request message
|
* IN http_message_t *req ; HTTP Request message
|
||||||
* OUT enum resp_type *rtype ; Tpye of response
|
* OUT enum resp_type *rtype ; Tpye of response
|
||||||
* OUT membuffer *headers ;
|
* OUT membuffer *headers ;
|
||||||
* OUT membuffer *filename ; Get filename from request document
|
* OUT membuffer *filename ; Get filename from request document
|
||||||
* OUT struct xml_alias_t *alias ; Xml alias document from the
|
* OUT struct xml_alias_t *alias ; Xml alias document from the
|
||||||
* request document,
|
* request document,
|
||||||
* OUT struct SendInstruction * RespInstr ; Send Instruction object
|
* OUT struct SendInstruction * RespInstr ; Send Instruction object
|
||||||
* where the response is set up.
|
* where the response is set up.
|
||||||
*
|
*
|
||||||
* Description: Processes the request and returns the result in the OUT
|
* Description: Processes the request and returns the result in the OUT
|
||||||
* parameters
|
* parameters
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* HTTP_BAD_REQUEST
|
* HTTP_BAD_REQUEST
|
||||||
* UPNP_E_OUTOF_MEMORY
|
* UPNP_E_OUTOF_MEMORY
|
||||||
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
|
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
|
||||||
* HTTP_OK
|
* HTTP_OK
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static int
|
static int
|
||||||
process_request( IN http_message_t * req,
|
process_request( IN http_message_t * req,
|
||||||
OUT enum resp_type *rtype,
|
OUT enum resp_type *rtype,
|
||||||
@ -1494,23 +1494,23 @@ process_request( IN http_message_t * req,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: http_RecvPostMessage
|
* Function: http_RecvPostMessage
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* http_parser_t* parser ; HTTP Parser object
|
* http_parser_t* parser ; HTTP Parser object
|
||||||
* IN SOCKINFO *info ; Socket Information object
|
* IN SOCKINFO *info ; Socket Information object
|
||||||
* char * filename ; File where received data is copied to
|
* char * filename ; File where received data is copied to
|
||||||
* struct SendInstruction * Instr ; Send Instruction object which gives
|
* struct SendInstruction * Instr ; Send Instruction object which gives
|
||||||
* information whether the file is a virtual file or not.
|
* information whether the file is a virtual file or not.
|
||||||
*
|
*
|
||||||
* Description: Receives the HTTP post message
|
* Description: Receives the HTTP post message
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* HTTP_INTERNAL_SERVER_ERROR
|
* HTTP_INTERNAL_SERVER_ERROR
|
||||||
* HTTP_UNAUTHORIZED
|
* HTTP_UNAUTHORIZED
|
||||||
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
|
* HTTP_REQUEST_RANGE_NOT_SATISFIABLE
|
||||||
* HTTP_OK
|
* HTTP_OK
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int
|
int
|
||||||
http_RecvPostMessage( http_parser_t * parser,
|
http_RecvPostMessage( http_parser_t * parser,
|
||||||
IN SOCKINFO * info,
|
IN SOCKINFO * info,
|
||||||
@ -1531,7 +1531,7 @@ http_RecvPostMessage( http_parser_t * parser,
|
|||||||
|
|
||||||
if( Instr && Instr->IsVirtualFile ) {
|
if( Instr && Instr->IsVirtualFile ) {
|
||||||
|
|
||||||
Fp = virtualDirCallback.open( filename, UPNP_WRITE );
|
Fp = (virtualDirCallback.open)( filename, UPNP_WRITE );
|
||||||
if( Fp == NULL ) {
|
if( Fp == NULL ) {
|
||||||
return HTTP_INTERNAL_SERVER_ERROR;
|
return HTTP_INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
@ -1658,19 +1658,19 @@ http_RecvPostMessage( http_parser_t * parser,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: web_server_callback
|
* Function: web_server_callback
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN http_parser_t *parser ; HTTP Parser Object
|
* IN http_parser_t *parser ; HTTP Parser Object
|
||||||
* INOUT http_message_t* req ; HTTP Message request
|
* INOUT http_message_t* req ; HTTP Message request
|
||||||
* IN SOCKINFO *info ; Socket information object
|
* IN SOCKINFO *info ; Socket information object
|
||||||
*
|
*
|
||||||
* Description: main entry point into web server;
|
* Description: main entry point into web server;
|
||||||
* handles HTTP GET and HEAD requests
|
* handles HTTP GET and HEAD requests
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* void
|
* void
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
void
|
void
|
||||||
web_server_callback( IN http_parser_t * parser,
|
web_server_callback( IN http_parser_t * parser,
|
||||||
INOUT http_message_t * req,
|
INOUT http_message_t * req,
|
||||||
@ -1763,3 +1763,4 @@ web_server_callback( IN http_parser_t * parser,
|
|||||||
membuffer_destroy( &headers );
|
membuffer_destroy( &headers );
|
||||||
membuffer_destroy( &filename );
|
membuffer_destroy( &filename );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -555,7 +555,7 @@ parse_hostport( const char *in,
|
|||||||
int begin_port;
|
int begin_port;
|
||||||
int hostport_size = 0;
|
int hostport_size = 0;
|
||||||
int host_size = 0;
|
int host_size = 0;
|
||||||
#ifndef WIN32
|
#if !defined(WIN32) && !(defined(__OSX__) || defined(__APPLE__))
|
||||||
char temp_hostbyname_buff[BUFFER_SIZE];
|
char temp_hostbyname_buff[BUFFER_SIZE];
|
||||||
struct hostent h_buf;
|
struct hostent h_buf;
|
||||||
#endif
|
#endif
|
||||||
@ -626,54 +626,61 @@ parse_hostport( const char *in,
|
|||||||
// TODO: Use autoconf to discover this rather than the
|
// TODO: Use autoconf to discover this rather than the
|
||||||
// platform-specific stuff below
|
// platform-specific stuff below
|
||||||
#if defined(WIN32) || defined(__CYGWIN__)
|
#if defined(WIN32) || defined(__CYGWIN__)
|
||||||
h=gethostbyname(temp_host_name);
|
h = gethostbyname(temp_host_name);
|
||||||
#elif defined(SPARC_SOLARIS)
|
#elif defined(SPARC_SOLARIS)
|
||||||
errCode = gethostbyname_r( temp_host_name,
|
errCode = gethostbyname_r(
|
||||||
&h,
|
temp_host_name,
|
||||||
temp_hostbyname_buff,
|
&h,
|
||||||
BUFFER_SIZE, &errcode );
|
temp_hostbyname_buff,
|
||||||
|
BUFFER_SIZE, &errcode );
|
||||||
#elif defined(__FreeBSD__) && __FreeBSD_version < 601103
|
#elif defined(__FreeBSD__) && __FreeBSD_version < 601103
|
||||||
h = lwres_gethostbyname_r( temp_host_name,
|
h = lwres_gethostbyname_r(
|
||||||
&h_buf,
|
temp_host_name,
|
||||||
temp_hostbyname_buff,
|
&h_buf,
|
||||||
BUFFER_SIZE, &errcode );
|
temp_hostbyname_buff,
|
||||||
|
BUFFER_SIZE, &errcode );
|
||||||
if ( h == NULL ) {
|
if ( h == NULL ) {
|
||||||
errCode = 1;
|
errCode = 1;
|
||||||
|
}
|
||||||
|
#elif defined(__OSX__) || defined(__APPLE__)
|
||||||
|
h = gethostbyname(temp_host_name);
|
||||||
|
if ( h == NULL ) {
|
||||||
|
errCode = 1;
|
||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
errCode = gethostbyname_r( temp_host_name,
|
errCode = gethostbyname_r(
|
||||||
&h_buf,
|
temp_host_name,
|
||||||
temp_hostbyname_buff,
|
&h_buf,
|
||||||
BUFFER_SIZE, &h, &errcode );
|
temp_hostbyname_buff,
|
||||||
|
BUFFER_SIZE, &h, &errcode );
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
struct addrinfo hints, *res, *res0;
|
struct addrinfo hints, *res, *res0;
|
||||||
|
|
||||||
h = NULL;
|
h = NULL;
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
hints.ai_family = PF_INET;
|
hints.ai_family = PF_INET;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
errCode = getaddrinfo(temp_host_name, "http", &hints, &res0);
|
errCode = getaddrinfo(temp_host_name, "http", &hints, &res0);
|
||||||
|
|
||||||
if (!errCode) {
|
if (!errCode) {
|
||||||
for (res = res0; res; res = res->ai_next) {
|
for (res = res0; res; res = res->ai_next) {
|
||||||
if (res->ai_family == PF_INET &&
|
if (res->ai_family == PF_INET &&
|
||||||
res->ai_addr->sa_family == AF_INET)
|
res->ai_addr->sa_family == AF_INET)
|
||||||
{
|
{
|
||||||
h = &h_buf;
|
h = &h_buf;
|
||||||
h->h_addrtype = res->ai_addr->sa_family;
|
h->h_addrtype = res->ai_addr->sa_family;
|
||||||
h->h_length = 4;
|
h->h_length = 4;
|
||||||
h->h_addr = (void *) temp_hostbyname_buff;
|
h->h_addr = (void *) temp_hostbyname_buff;
|
||||||
*(struct in_addr *)h->h_addr =
|
*(struct in_addr *)h->h_addr =
|
||||||
((struct sockaddr_in *)res->ai_addr)->sin_addr;
|
((struct sockaddr_in *)res->ai_addr)->sin_addr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
freeaddrinfo(res0);
|
freeaddrinfo(res0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( errCode == 0 ) {
|
if( errCode == 0 ) {
|
||||||
if( h ) {
|
if( h ) {
|
||||||
if( ( h->h_addrtype == AF_INET ) && ( h->h_length == 4 ) ) {
|
if( ( h->h_addrtype == AF_INET ) && ( h->h_length == 4 ) ) {
|
||||||
|
@ -261,18 +261,18 @@
|
|||||||
|
|
||||||
/** @name Other debugging features
|
/** @name Other debugging features
|
||||||
The UPnP SDK contains other features to aid in debugging:
|
The UPnP SDK contains other features to aid in debugging:
|
||||||
see <upnp/upnpdebug.h>
|
see <upnp/inc/upnpdebug.h>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DEBUG_ALL 1
|
#define DEBUG_ALL 1
|
||||||
#define DEBUG_SSDP 0
|
#define DEBUG_SSDP 0
|
||||||
#define DEBUG_SOAP 0
|
#define DEBUG_SOAP 0
|
||||||
#define DEBUG_GENA 0
|
#define DEBUG_GENA 0
|
||||||
#define DEBUG_TPOOL 0
|
#define DEBUG_TPOOL 0
|
||||||
#define DEBUG_MSERV 0
|
#define DEBUG_MSERV 0
|
||||||
#define DEBUG_DOM 0
|
#define DEBUG_DOM 0
|
||||||
#define DEBUG_HTTP 0
|
#define DEBUG_HTTP 0
|
||||||
#define DEBUG_API 0
|
#define DEBUG_API 0
|
||||||
|
|
||||||
//@} // Compile time configuration options
|
//@} // Compile time configuration options
|
||||||
|
|
||||||
|
@ -50,73 +50,78 @@ int
|
|||||||
http_CancelHttpGet( IN void *Handle );
|
http_CancelHttpGet( IN void *Handle );
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: http_FixUrl
|
* Function: http_FixUrl
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN uri_type* url ; URL to be validated and fixed
|
* IN uri_type* url; URL to be validated and fixed
|
||||||
* OUT uri_type* fixed_url ; URL after being fixed.
|
* OUT uri_type* fixed_url; URL after being fixed.
|
||||||
*
|
*
|
||||||
* Description: Validates URL
|
* Description:
|
||||||
*
|
* Validates URL
|
||||||
* Returns:
|
*
|
||||||
* UPNP_E_INVALID_URL
|
* Returns:
|
||||||
* UPNP_E_SUCCESS
|
* UPNP_E_INVALID_URL
|
||||||
************************************************************************/
|
* UPNP_E_SUCCESS
|
||||||
|
************************************************************************/
|
||||||
int http_FixUrl( IN uri_type* url, OUT uri_type* fixed_url );
|
int http_FixUrl( IN uri_type* url, OUT uri_type* fixed_url );
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: http_FixStrUrl
|
* Function: http_FixStrUrl
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char* urlstr ; Character string as a URL
|
* IN char* urlstr ; Character string as a URL
|
||||||
* IN int urlstrlen ; Length of the character string
|
* IN int urlstrlen ; Length of the character string
|
||||||
* OUT uri_type* fixed_url ; Fixed and corrected URL
|
* OUT uri_type* fixed_url ; Fixed and corrected URL
|
||||||
*
|
*
|
||||||
* Description: Parses URL and then validates URL
|
* Description:
|
||||||
*
|
* Parses URL and then validates URL
|
||||||
* Returns:
|
*
|
||||||
* UPNP_E_INVALID_URL
|
* Returns:
|
||||||
* UPNP_E_SUCCESS
|
* UPNP_E_INVALID_URL
|
||||||
************************************************************************/
|
* UPNP_E_SUCCESS
|
||||||
|
************************************************************************/
|
||||||
int http_FixStrUrl( IN char* urlstr, IN int urlstrlen, OUT uri_type* fixed_url );
|
int http_FixStrUrl( IN char* urlstr, IN int urlstrlen, OUT uri_type* fixed_url );
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: http_Connect
|
* Function: http_Connect
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN uri_type* destination_url ; URL containing destination information
|
* IN uri_type* destination_url; URL containing destination information
|
||||||
* OUT uri_type *url ; Fixed and corrected URL
|
* OUT uri_type *url; Fixed and corrected URL
|
||||||
*
|
*
|
||||||
* Description: Gets destination address from URL and then connects to the
|
* Description:
|
||||||
* remote end
|
* Gets destination address from URL and then connects to the remote end
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* socket descriptor on sucess
|
* socket descriptor on sucess
|
||||||
* UPNP_E_OUTOF_SOCKET
|
* UPNP_E_OUTOF_SOCKET
|
||||||
* UPNP_E_SOCKET_CONNECT on error
|
* UPNP_E_SOCKET_CONNECT on error
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int http_Connect( IN uri_type* destination_url, OUT uri_type *url );
|
int http_Connect( IN uri_type* destination_url, OUT uri_type *url );
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: http_RecvMessage
|
* Function: http_RecvMessage
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN SOCKINFO *info ; Socket information object
|
* IN SOCKINFO *info; Socket information object
|
||||||
* OUT http_parser_t* parser, HTTP parser object
|
* OUT http_parser_t* parser; HTTP parser object
|
||||||
* IN http_method_t request_method ; HTTP request method
|
* IN http_method_t request_method; HTTP request method
|
||||||
* IN OUT int* timeout_secs ; time out
|
* IN OUT int* timeout_secs; time out
|
||||||
* OUT int* http_error_code ; HTTP error code returned
|
* OUT int* http_error_code; HTTP error code returned
|
||||||
*
|
*
|
||||||
* Description: Get the data on the socket and take actions based on the
|
* Description:
|
||||||
* read data to modify the parser objects buffer. If an error is reported
|
* Get the data on the socket and take actions based on the read data
|
||||||
* while parsing the data, the error code is passed in the http_errr_code
|
* to modify the parser objects buffer. If an error is reported while
|
||||||
* parameter
|
* parsing the data, the error code is passed in the http_errr_code
|
||||||
*
|
* parameter
|
||||||
* Returns:
|
*
|
||||||
* UPNP_E_BAD_HTTPMSG
|
* Returns:
|
||||||
* UPNP_E_SUCCESS
|
* UPNP_E_BAD_HTTPMSG
|
||||||
************************************************************************/
|
* UPNP_E_SUCCESS
|
||||||
|
************************************************************************/
|
||||||
int http_RecvMessage( IN SOCKINFO *info, OUT http_parser_t* parser,
|
int http_RecvMessage( IN SOCKINFO *info, OUT http_parser_t* parser,
|
||||||
IN http_method_t request_method,
|
IN http_method_t request_method,
|
||||||
IN OUT int* timeout_secs,
|
IN OUT int* timeout_secs,
|
||||||
@ -124,302 +129,311 @@ int http_RecvMessage( IN SOCKINFO *info, OUT http_parser_t* parser,
|
|||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: http_SendMessage
|
* Function: http_SendMessage
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN SOCKINFO *info ; Socket information object
|
* IN SOCKINFO *info ; Socket information object
|
||||||
* IN OUT int * TimeOut ; time out value
|
* IN OUT int * TimeOut ; time out value
|
||||||
* IN const char* fmt, ... Pattern format to take actions upon
|
* IN const char* fmt, ... Pattern format to take actions upon
|
||||||
*
|
*
|
||||||
* Description: Sends a message to the destination based on the
|
* Description:
|
||||||
* IN const char* fmt parameter
|
* Sends a message to the destination based on the
|
||||||
* fmt types:
|
* IN const char* fmt parameter
|
||||||
* 'f': arg = const char * file name
|
* fmt types:
|
||||||
* 'm': arg1 = const char * mem_buffer; arg2= size_t buf_length
|
* 'f': arg = const char * file name
|
||||||
* E.g.:
|
* 'm': arg1 = const char * mem_buffer; arg2= size_t buf_length
|
||||||
* char *buf = "POST /xyz.cgi http/1.1\r\n\r\n";
|
* E.g.:
|
||||||
* char *filename = "foo.dat";
|
* char *buf = "POST /xyz.cgi http/1.1\r\n\r\n";
|
||||||
* int status = http_SendMessage( tcpsock, "mf",
|
* char *filename = "foo.dat";
|
||||||
* buf, strlen(buf), // args for memory buffer
|
* int status = http_SendMessage( tcpsock, "mf",
|
||||||
* filename ); // arg for file
|
* buf, strlen(buf), // args for memory buffer
|
||||||
*
|
* filename ); // arg for file
|
||||||
* Returns:
|
*
|
||||||
* UPNP_E_OUTOF_MEMORY
|
* Returns:
|
||||||
* UPNP_E_FILE_READ_ERROR
|
* UPNP_E_OUTOF_MEMORY
|
||||||
* UPNP_E_SUCCESS
|
* UPNP_E_FILE_READ_ERROR
|
||||||
************************************************************************/
|
* UPNP_E_SUCCESS
|
||||||
int http_SendMessage( IN SOCKINFO *info, IN OUT int* timeout_secs,
|
************************************************************************/
|
||||||
IN const char* fmt, ... );
|
int http_SendMessage(
|
||||||
|
IN SOCKINFO *info,
|
||||||
/************************************************************************
|
IN OUT int* timeout_secs,
|
||||||
* Function: http_RequestAndResponse
|
IN const char* fmt, ... );
|
||||||
*
|
|
||||||
* 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_WriteHttpPost
|
* Function: http_RequestAndResponse
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* IN void *Handle : Handle to the http post object
|
* IN uri_type* destination; Destination URI object which contains
|
||||||
* IN char *buf : Buffer to send to peer, if format used
|
* remote IP address among other elements
|
||||||
* is not UPNP_USING_CHUNKED,
|
* IN const char* request; Request to be sent
|
||||||
* IN unsigned int *size : Size of the data to be sent.
|
* IN size_t request_length; Length of the request
|
||||||
* IN int timeout : time out value
|
* IN http_method_t req_method; HTTP Request method
|
||||||
*
|
* IN int timeout_secs; time out value
|
||||||
* Description : Formats data if format used is UPNP_USING_CHUNKED.
|
* OUT http_parser_t* response; Parser object to receive the repsonse
|
||||||
* Writes data on the socket connected to the peer.
|
*
|
||||||
*
|
* Description:
|
||||||
* Return : int ;
|
* Initiates socket, connects to the destination, sends a
|
||||||
* UPNP_E_SUCCESS - On Success
|
* request and waits for the response from the remote end
|
||||||
* UPNP_E_INVALID_PARAM - Invalid Parameter
|
*
|
||||||
* -1 - On Socket Error.
|
* Returns:
|
||||||
*
|
* UPNP_E_SOCKET_ERROR
|
||||||
* Note :
|
* 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,
|
int http_WriteHttpPost(IN void *Handle,
|
||||||
IN char *buf,
|
IN char *buf,
|
||||||
IN unsigned int *size,
|
IN unsigned int *size,
|
||||||
IN int timeout);
|
IN int timeout);
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : http_CloseHttpPost
|
* Function: http_CloseHttpPost
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* IN void *Handle : Handle to the http post object
|
* IN void *Handle; Handle to the http post object
|
||||||
* IN OUT int *httpStatus : HTTP status returned on receiving a
|
* IN OUT int *httpStatus; HTTP status returned on receiving a
|
||||||
* response message
|
* response message
|
||||||
* IN int timeout : time out value
|
* IN int timeout; time out value
|
||||||
*
|
*
|
||||||
* Description : Sends remaining data if using UPNP_USING_CHUNKED
|
* Description:
|
||||||
* format. Receives any more messages. Destroys socket and any socket
|
* Sends remaining data if using UPNP_USING_CHUNKED
|
||||||
* associated memory. Frees handle associated with the HTTP POST msg.
|
* 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 ;
|
* Return: int
|
||||||
* UPNP_E_INVALID_PARAM - Invalid Parameter;
|
* UPNP_E_SUCCESS - On Sucess
|
||||||
*
|
* UPNP_E_INVALID_PARAM - Invalid Parameter
|
||||||
* Note :
|
************************************************************************/
|
||||||
************************************************************************/
|
|
||||||
int http_CloseHttpPost(IN void *Handle,
|
int http_CloseHttpPost(IN void *Handle,
|
||||||
IN OUT int *httpStatus,
|
IN OUT int *httpStatus,
|
||||||
IN int timeout);
|
IN int timeout);
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : http_OpenHttpPost
|
* Function: http_OpenHttpPost
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* IN const char *url_str : String as a URL
|
* IN const char *url_str; String as a URL
|
||||||
* IN OUT void **Handle : Pointer to buffer to store HTTP
|
* IN OUT void **Handle; Pointer to buffer to store HTTP
|
||||||
* post handle
|
* post handle
|
||||||
* IN const char *contentType : Type of content
|
* IN const char *contentType; Type of content
|
||||||
* IN int contentLength : length of content
|
* IN int contentLength; length of content
|
||||||
* IN int timeout : time out value
|
* IN int timeout; time out value
|
||||||
*
|
*
|
||||||
* Description : Makes the HTTP POST message, connects to the peer,
|
* Description:
|
||||||
* sends the HTTP POST request. Adds the post handle to buffer of
|
* Makes the HTTP POST message, connects to the peer,
|
||||||
* such handles
|
* sends the HTTP POST request. Adds the post handle to buffer of
|
||||||
*
|
* such handles
|
||||||
* Return : int;
|
*
|
||||||
* UPNP_E_SUCCESS - On Sucess ;
|
* Return : int;
|
||||||
* UPNP_E_INVALID_PARAM - Invalid Paramter ;
|
* UPNP_E_SUCCESS - On Sucess
|
||||||
* UPNP_E_OUTOF_MEMORY ;
|
* UPNP_E_INVALID_PARAM - Invalid Parameter
|
||||||
* UPNP_E_SOCKET_ERROR ;
|
* UPNP_E_OUTOF_MEMORY
|
||||||
* UPNP_E_SOCKET_CONNECT ;
|
* UPNP_E_SOCKET_ERROR
|
||||||
*
|
* UPNP_E_SOCKET_CONNECT
|
||||||
* Note :
|
************************************************************************/
|
||||||
************************************************************************/
|
|
||||||
int http_OpenHttpPost(IN const char *url_str,
|
int http_OpenHttpPost(IN const char *url_str,
|
||||||
IN OUT void **Handle,
|
IN OUT void **Handle,
|
||||||
IN const char *contentType,
|
IN const char *contentType,
|
||||||
IN int contentLength,
|
IN int contentLength,
|
||||||
IN int timeout);
|
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
|
* Function: http_ReadHttpGet
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* IN void *Handle : Handle to the HTTP get object
|
* IN void *Handle; Handle to the HTTP get object
|
||||||
* OUT unsigned int *length : Buffer to get the read and parsed data
|
* IN OUT char *buf; Buffer to get the read and parsed data
|
||||||
* OUT unsigned int *total : Size of tge buffer passed
|
* IN OUT unsigned int *size; Size of the buffer passed
|
||||||
*
|
* IN int timeout; time out value
|
||||||
* Description : Extracts information from the Handle to the HTTP get
|
*
|
||||||
* object.
|
* Description:
|
||||||
*
|
* Parses already existing data, then gets new data.
|
||||||
* Return : int ;
|
* Parses and extracts information from the new data.
|
||||||
* UPNP_E_SUCCESS - On Sucess ;
|
*
|
||||||
* UPNP_E_INVALID_PARAM - Invalid Parameter;
|
* Return: int
|
||||||
*
|
* UPNP_E_SUCCESS - On Sucess
|
||||||
* Note :
|
* UPNP_E_INVALID_PARAM - Invalid Parameter
|
||||||
************************************************************************/
|
* UPNP_E_BAD_RESPONSE
|
||||||
int http_HttpGetProgress(IN void *Handle,
|
* UPNP_E_BAD_HTTPMSG
|
||||||
OUT unsigned int *length,
|
* UPNP_E_CANCELED
|
||||||
OUT unsigned int *total );
|
************************************************************************/
|
||||||
|
int http_ReadHttpGet(
|
||||||
|
IN void *Handle,
|
||||||
|
IN OUT char *buf,
|
||||||
|
IN OUT unsigned int *size,
|
||||||
|
IN int timeout);
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : http_CloseHttpGet
|
* Function: http_HttpGetProgress
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* IN void *Handle ; Handle to HTTP get object
|
* IN void *Handle; Handle to the HTTP get object
|
||||||
*
|
* OUT unsigned int *length; Buffer to get the read and parsed data
|
||||||
* Description : Clears the handle allocated for the HTTP GET operation
|
* OUT unsigned int *total; Size of tge buffer passed
|
||||||
* Clears socket states and memory allocated for socket operations.
|
*
|
||||||
*
|
* Description:
|
||||||
* Return : int ;
|
* Extracts information from the Handle to the HTTP get object.
|
||||||
* UPNP_E_SUCCESS - On Success
|
*
|
||||||
* UPNP_E_INVALID_PARAM - Invalid Parameter
|
* Return: int
|
||||||
*
|
* UPNP_E_SUCCESS - On Sucess
|
||||||
* Note :
|
* 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);
|
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
|
* Function: http_OpenHttpGet
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* IN const char *url_str : String as a URL
|
* 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
|
||||||
* IN OUT void **Handle : Pointer to buffer to store HTTP
|
* post handle
|
||||||
* post handle
|
* IN OUT char **contentType: Type of content
|
||||||
* IN OUT char **contentType : Type of content
|
* OUT int *contentLength: length of content
|
||||||
* OUT int *contentLength : length of content
|
* OUT int *httpStatus: HTTP status returned on receiving a
|
||||||
* OUT int *httpStatus : HTTP status returned on receiving a
|
* response message
|
||||||
* response message
|
* IN int timeout: time out value
|
||||||
* IN int timeout : time out value
|
*
|
||||||
*
|
* Description:
|
||||||
* Description : Makes the HTTP GET message, connects to the peer,
|
* Makes the HTTP GET message, connects to the peer,
|
||||||
* sends the HTTP GET request, gets the response and parses the
|
* sends the HTTP GET request, gets the response and parses the
|
||||||
* response.
|
* response.
|
||||||
*
|
*
|
||||||
* Return : int;
|
* Return: int
|
||||||
* UPNP_E_SUCCESS - On Success ;
|
* UPNP_E_SUCCESS - On Success
|
||||||
* UPNP_E_INVALID_PARAM - Invalid Paramters ;
|
* UPNP_E_INVALID_PARAM - Invalid Paramters
|
||||||
* UPNP_E_OUTOF_MEMORY ;
|
* UPNP_E_OUTOF_MEMORY
|
||||||
* UPNP_E_SOCKET_ERROR ;
|
* UPNP_E_SOCKET_ERROR
|
||||||
* UPNP_E_BAD_RESPONSE ;
|
* 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
|
||||||
|
* 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,
|
int http_OpenHttpGetProxy(IN const char *url_str,
|
||||||
IN const char *proxy_str,
|
IN const char *proxy_str,
|
||||||
IN OUT void **Handle,
|
IN OUT void **Handle,
|
||||||
@ -430,126 +444,134 @@ int http_OpenHttpGetProxy(IN const char *url_str,
|
|||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : http_SendStatusResponse
|
* Function: http_SendStatusResponse
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* IN SOCKINFO *info : Socket information object
|
* IN SOCKINFO *info; Socket information object
|
||||||
* IN int http_status_code : error code returned while making
|
* IN int http_status_code; error code returned while making
|
||||||
* or sending the response message
|
* or sending the response message
|
||||||
* IN int request_major_version : request major version
|
* IN int request_major_version; request major version
|
||||||
* IN int request_minor_version : request minor version
|
* IN int request_minor_version; request minor version
|
||||||
*
|
*
|
||||||
* Description : Generate a response message for the status query and
|
* Description:
|
||||||
* send the status response.
|
* Generate a response message for the status query and send the
|
||||||
*
|
* status response.
|
||||||
* Return : int;
|
*
|
||||||
* 0 -- success
|
* Return: int
|
||||||
* UPNP_E_OUTOF_MEMORY
|
* 0 -- success
|
||||||
* UPNP_E_SOCKET_WRITE
|
* UPNP_E_OUTOF_MEMORY
|
||||||
* UPNP_E_TIMEDOUT
|
* UPNP_E_SOCKET_WRITE
|
||||||
*
|
* UPNP_E_TIMEDOUT
|
||||||
* Note :
|
************************************************************************/
|
||||||
************************************************************************/
|
int http_SendStatusResponse(
|
||||||
int http_SendStatusResponse( IN SOCKINFO *info, IN int http_status_code,
|
IN SOCKINFO *info,
|
||||||
IN int request_major_version,
|
IN int http_status_code,
|
||||||
IN int request_minor_version );
|
IN int request_major_version,
|
||||||
|
IN int request_minor_version );
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : http_MakeMessage
|
* Function: http_MakeMessage
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* INOUT membuffer* buf : buffer with the contents of the
|
* INOUT membuffer* buf; buffer with the contents of the
|
||||||
* message
|
* message
|
||||||
* IN int http_major_version : HTTP major version
|
* IN int http_major_version; HTTP major version
|
||||||
* IN int http_minor_version : HTTP minor version
|
* IN int http_minor_version; HTTP minor version
|
||||||
* IN const char* fmt : Pattern format
|
* IN const char* fmt; Pattern format
|
||||||
* ... :
|
* ...;
|
||||||
*
|
*
|
||||||
* Description : Generate an HTTP message based on the format that is
|
* Description:
|
||||||
* specified in the input parameters.
|
* Generate an HTTP message based on the format that is specified
|
||||||
*
|
* in the input parameters.
|
||||||
* fmt types:
|
*
|
||||||
* 's': arg = const char* C_string
|
* fmt types:
|
||||||
* 'b': arg1 = const char* buf; arg2 = size_t buf_length
|
* 'B': arg = int status_code
|
||||||
* memory ptr
|
* appends content-length, content-type and HTML body
|
||||||
* 'c': (no args) appends CRLF "\r\n"
|
* for given code
|
||||||
* 'd': arg = int number // appends decimal number
|
* 'b': arg1 = const char* buf;
|
||||||
* 'h': arg = off_t number // appends off_t number
|
* arg2 = size_t buf_length memory ptr
|
||||||
* 't': arg = time_t * gmt_time // appends time in RFC 1123 fmt
|
* 'C': (no args) appends a HTTP CONNECTION: close header
|
||||||
* 'D': (no args) appends HTTP DATE: header
|
* depending on major,minor version
|
||||||
* 'S': (no args) appends HTTP SERVER: header
|
* 'c': (no args) appends CRLF "\r\n"
|
||||||
* 'U': (no args) appends HTTP USER-AGENT: header
|
* 'D': (no args) appends HTTP DATE: header
|
||||||
* 'C': (no args) appends a HTTP CONNECTION: close header
|
* 'd': arg = int number // appends decimal number
|
||||||
* depending on major,minor version
|
* 'G': arg = range information // add range header
|
||||||
* 'N': arg1 = int content_length // content-length header
|
* 'h': arg = off_t number // appends off_t number
|
||||||
* 'Q': arg1 = http_method_t; arg2 = char* url;
|
* 'K': (no args) // add chunky header
|
||||||
* arg3 = int url_length // start line of request
|
* 'N': arg1 = off_t content_length // content-length header
|
||||||
* 'R': arg = int status_code // adds a response start line
|
* 'q': arg1 = http_method_t // request start line and HOST header
|
||||||
* 'B': arg = int status_code
|
* arg2 = (uri_type *)
|
||||||
* appends content-length, content-type and HTML body for given code
|
* 'Q': arg1 = http_method_t; // start line of request
|
||||||
* 'T': arg = char * content_type; format e.g: "text/html";
|
* arg2 = char* url;
|
||||||
* content-type header
|
* arg3 = size_t url_length
|
||||||
*
|
* 'R': arg = int status_code // adds a response start line
|
||||||
* Return : int;
|
* 'S': (no args) appends HTTP SERVER: header
|
||||||
* 0 - On Success
|
* 's': arg = const char* C_string
|
||||||
* UPNP_E_OUTOF_MEMORY
|
* 'T': arg = char * content_type; format
|
||||||
* UPNP_E_INVALID_URL;
|
* e.g: "text/html"; content-type header
|
||||||
*
|
* 't': arg = time_t * gmt_time // appends time in RFC 1123 fmt
|
||||||
* Note :
|
* 'U': (no args) appends HTTP USER-AGENT: header
|
||||||
************************************************************************/
|
* 'X': arg = const char useragent; "redsonic" HTTP X-User-Agent: useragent
|
||||||
int http_MakeMessage( INOUT membuffer* buf,
|
*
|
||||||
IN int http_major_version,
|
* Return: int
|
||||||
IN int http_minor_version,
|
* 0 - On Success
|
||||||
IN const char* fmt, ... );
|
* 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
|
* Function: http_CalcResponseVersion
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* IN int request_major_vers : Request major version
|
* IN int request_major_vers; Request major version
|
||||||
* IN int request_minor_vers : Request minor version
|
* IN int request_minor_vers; Request minor version
|
||||||
* OUT int* response_major_vers : Response mojor version
|
* OUT int* response_major_vers; Response mojor version
|
||||||
* OUT int* response_minor_vers : Response minor version
|
* OUT int* response_minor_vers; Response minor version
|
||||||
*
|
*
|
||||||
* Description : Calculate HTTP response versions based on the request
|
* Description:
|
||||||
* versions.
|
* Calculate HTTP response versions based on the request versions.
|
||||||
*
|
*
|
||||||
* Return : void
|
* Return: void
|
||||||
*
|
************************************************************************/
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
|
||||||
void http_CalcResponseVersion(
|
void http_CalcResponseVersion(
|
||||||
IN int request_major_vers, IN int request_minor_vers,
|
IN int request_major_vers,
|
||||||
OUT int* response_major_vers, OUT int* response_minor_vers );
|
IN int request_minor_vers,
|
||||||
|
OUT int* response_major_vers,
|
||||||
|
OUT int* response_minor_vers );
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : http_OpenHttpGetEx
|
* Function: http_OpenHttpGetEx
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* IN const char *url_str : String as a URL
|
* IN const char *url_str; String as a URL
|
||||||
* IN OUT void **Handle : Pointer to buffer to store HTTP
|
* IN OUT void **Handle; Pointer to buffer to store HTTP
|
||||||
* post handle
|
* post handle
|
||||||
* IN OUT char **contentType : Type of content
|
* IN OUT char **contentType; Type of content
|
||||||
* OUT int *contentLength : length of content
|
* OUT int *contentLength; length of content
|
||||||
* OUT int *httpStatus : HTTP status returned on receiving a
|
* OUT int *httpStatus; HTTP status returned on receiving a
|
||||||
* response message
|
* response message
|
||||||
* IN int timeout : time out value
|
* IN int timeout; time out value
|
||||||
*
|
*
|
||||||
* Description : Makes the HTTP GET message, connects to the peer,
|
* Description:
|
||||||
* sends the HTTP GET request, gets the response and parses the
|
* Makes the HTTP GET message, connects to the peer,
|
||||||
* response.
|
* sends the HTTP GET request, gets the response and parses the
|
||||||
*
|
* response.
|
||||||
* Return : int;
|
*
|
||||||
* UPNP_E_SUCCESS - On Success ;
|
* Return: int
|
||||||
* UPNP_E_INVALID_PARAM - Invalid Paramters ;
|
* UPNP_E_SUCCESS - On Success
|
||||||
* UPNP_E_OUTOF_MEMORY ;
|
* UPNP_E_INVALID_PARAM - Invalid Paramters
|
||||||
* UPNP_E_SOCKET_ERROR ;
|
* UPNP_E_OUTOF_MEMORY
|
||||||
* UPNP_E_BAD_RESPONSE ;
|
* UPNP_E_SOCKET_ERROR
|
||||||
*
|
* UPNP_E_BAD_RESPONSE
|
||||||
* Note :
|
************************************************************************/
|
||||||
*
|
|
||||||
************************************************************************/
|
|
||||||
int http_OpenHttpGetEx(IN const char *url_str,
|
int http_OpenHttpGetEx(IN const char *url_str,
|
||||||
IN OUT void **Handle,
|
IN OUT void **Handle,
|
||||||
IN OUT char **contentType,
|
IN OUT char **contentType,
|
||||||
@ -559,19 +581,19 @@ int http_OpenHttpGetEx(IN const char *url_str,
|
|||||||
IN int highRange,
|
IN int highRange,
|
||||||
IN int timeout);
|
IN int timeout);
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : get_sdk_info
|
* Function: get_sdk_info
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* OUT char *info ;
|
* OUT char *info; buffer to store the operating system information
|
||||||
*
|
*
|
||||||
* Description : Returns the server information for the operating
|
* Description:
|
||||||
* system
|
* Returns the server information for the operating system
|
||||||
*
|
*
|
||||||
* Return : void ;
|
* Return:
|
||||||
*
|
* UPNP_INLINE void
|
||||||
* Note :
|
************************************************************************/
|
||||||
************************************************************************/
|
|
||||||
void get_sdk_info( OUT char *info );
|
void get_sdk_info( OUT char *info );
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -580,3 +602,4 @@ void get_sdk_info( OUT char *info );
|
|||||||
|
|
||||||
|
|
||||||
#endif // GENLIB_NET_HTTP_HTTPREADWRITE_H
|
#endif // GENLIB_NET_HTTP_HTTPREADWRITE_H
|
||||||
|
|
||||||
|
@ -1,154 +1,150 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
/************************************************************************
|
||||||
//
|
*
|
||||||
// Copyright (c) 2000-2003 Intel Corporation
|
* Copyright (c) 2000-2003 Intel Corporation
|
||||||
// All rights reserved.
|
* All rights reserved.
|
||||||
//
|
*
|
||||||
// Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
// modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
//
|
*
|
||||||
// * Redistributions of source code must retain the above copyright notice,
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
// this list of conditions and the following disclaimer.
|
* this list of conditions and the following disclaimer.
|
||||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
// and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
// * Neither name of Intel Corporation nor the names of its contributors
|
* Neither name of Intel Corporation nor the names of its contributors
|
||||||
// may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
// without specific prior written permission.
|
* without specific prior written permission.
|
||||||
//
|
*
|
||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
//
|
*
|
||||||
///////////////////////////////////////////////////////////////////////////
|
************************************************************************/
|
||||||
|
|
||||||
#ifndef MINISERVER_H
|
#ifndef MINISERVER_H
|
||||||
#define MINISERVER_H
|
#define MINISERVER_H
|
||||||
|
|
||||||
|
|
||||||
#include "sock.h"
|
#include "sock.h"
|
||||||
#include "httpparser.h"
|
#include "httpparser.h"
|
||||||
|
|
||||||
|
|
||||||
extern SOCKET gMiniServerStopSock;
|
extern SOCKET gMiniServerStopSock;
|
||||||
|
|
||||||
|
|
||||||
typedef struct MServerSockArray {
|
typedef struct MServerSockArray {
|
||||||
int miniServerSock; //socket for listening for miniserver
|
/* socket for listening for miniserver requests */
|
||||||
//requests
|
int miniServerSock;
|
||||||
int miniServerStopSock; //socket for stopping miniserver
|
/* socket for stopping miniserver */
|
||||||
int ssdpSock; //socket for incoming advertisments and search requests
|
int miniServerStopSock;
|
||||||
|
/* socket for incoming advertisments and search requests */
|
||||||
|
int ssdpSock;
|
||||||
|
|
||||||
int stopPort;
|
int stopPort;
|
||||||
int miniServerPort;
|
int miniServerPort;
|
||||||
|
|
||||||
CLIENTONLY(int ssdpReqSock;) //socket for sending search
|
/* socket for sending search requests and receiving search replies */
|
||||||
//requests and receiving
|
CLIENTONLY(int ssdpReqSock;)
|
||||||
// search replies
|
|
||||||
|
|
||||||
} MiniServerSockArray;
|
} MiniServerSockArray;
|
||||||
|
|
||||||
//typedef void (*MiniServerCallback) ( const char* document, int sockfd );
|
|
||||||
|
|
||||||
typedef void (*MiniServerCallback) ( IN http_parser_t *parser,
|
typedef void (*MiniServerCallback)(
|
||||||
IN http_message_t* request,
|
IN http_parser_t *parser,
|
||||||
IN SOCKINFO *info );
|
IN http_message_t* request,
|
||||||
|
IN SOCKINFO *info );
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : SetHTTPGetCallback
|
* Function: SetHTTPGetCallback
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* MiniServerCallback callback ; - HTTP Callback to be invoked
|
* MiniServerCallback callback; - HTTP Callback to be invoked
|
||||||
*
|
*
|
||||||
* Description : Set HTTP Get Callback
|
* Description: Set HTTP Get Callback
|
||||||
*
|
*
|
||||||
* Return : void
|
* Return: void
|
||||||
*
|
************************************************************************/
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
|
||||||
void SetHTTPGetCallback( MiniServerCallback callback );
|
void SetHTTPGetCallback( MiniServerCallback callback );
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : SetSoapCallback
|
* Function: SetSoapCallback
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* MiniServerCallback callback ; - SOAP Callback to be invoked
|
* MiniServerCallback callback; - SOAP Callback to be invoked
|
||||||
*
|
*
|
||||||
* Description : Set SOAP Callback
|
* Description: Set SOAP Callback
|
||||||
*
|
*
|
||||||
* Return : void
|
* Return: void
|
||||||
*
|
************************************************************************/
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
|
||||||
#ifdef INCLUDE_DEVICE_APIS
|
#ifdef INCLUDE_DEVICE_APIS
|
||||||
void SetSoapCallback( MiniServerCallback callback );
|
void SetSoapCallback( MiniServerCallback callback );
|
||||||
#else
|
#else /* INCLUDE_DEVICE_APIS */
|
||||||
static inline void SetSoapCallback( MiniServerCallback callback ) {}
|
static inline void SetSoapCallback( MiniServerCallback callback ) {}
|
||||||
#endif
|
#endif /* INCLUDE_DEVICE_APIS */
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : SetGenaCallback
|
* Function: SetGenaCallback
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* MiniServerCallback callback ; - GENA Callback to be invoked
|
* MiniServerCallback callback; - GENA Callback to be invoked
|
||||||
*
|
*
|
||||||
* Description : Set GENA Callback
|
* D6escription: Set GENA Callback
|
||||||
*
|
*
|
||||||
* Return : void
|
* Return: void
|
||||||
*
|
************************************************************************/
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
|
||||||
void SetGenaCallback( MiniServerCallback callback );
|
void SetGenaCallback( MiniServerCallback callback );
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : StartMiniServer
|
* Function: StartMiniServer
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* unsigned short listen_port ; Port on which the server listens for
|
* unsigned short listen_port ; Port on which the server listens for
|
||||||
* incoming connections
|
* incoming connections
|
||||||
*
|
*
|
||||||
* Description : Initialize the sockets functionality for the
|
* Description: Initialize the sockets functionality for the
|
||||||
* Miniserver. Initialize a thread pool job to run the MiniServer
|
* Miniserver. Initialize a thread pool job to run the MiniServer
|
||||||
* and the job to the thread pool. If listen port is 0, port is
|
* and the job to the thread pool. If listen port is 0, port is
|
||||||
* dynamically picked
|
* dynamically picked
|
||||||
*
|
*
|
||||||
* Use timer mechanism to start the MiniServer, failure to meet the
|
* Use timer mechanism to start the MiniServer, failure to meet the
|
||||||
* allowed delay aborts the attempt to launch the MiniServer.
|
* allowed delay aborts the attempt to launch the MiniServer.
|
||||||
*
|
*
|
||||||
* Return : int ;
|
* Return: int;
|
||||||
* Actual port socket is bound to - On Success:
|
* Actual port socket is bound to - On Success:
|
||||||
* A negative number UPNP_E_XXX - On Error
|
* A negative number UPNP_E_XXX - On Error
|
||||||
* Note :
|
************************************************************************/
|
||||||
************************************************************************/
|
|
||||||
int StartMiniServer( unsigned short listen_port );
|
int StartMiniServer( unsigned short listen_port );
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : StopMiniServer
|
* Function: StopMiniServer
|
||||||
*
|
*
|
||||||
* Parameters :
|
* Parameters:
|
||||||
* void ;
|
* void;
|
||||||
*
|
*
|
||||||
* Description : Stop and Shutdown the MiniServer and free socket
|
* Description: Stop and Shutdown the MiniServer and free socket resources.
|
||||||
* resources.
|
*
|
||||||
*
|
* Return : int;
|
||||||
* Return : int ;
|
* Always returns 0
|
||||||
* Always returns 0
|
************************************************************************/
|
||||||
*
|
int StopMiniServer();
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
|
||||||
int StopMiniServer( void );
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern C */
|
} /* extern C */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* MINISERVER_H */
|
#endif /* MINISERVER_H */
|
||||||
|
|
||||||
|
@ -98,18 +98,25 @@ struct Handle_Info
|
|||||||
int aliasInstalled; // 0 = not installed; otherwise installed
|
int aliasInstalled; // 0 = not installed; otherwise installed
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ithread_mutex_t GlobalHndMutex;
|
extern ithread_rwlock_t GlobalHndRWLock;
|
||||||
Upnp_Handle_Type GetHandleInfo(int Hnd, struct Handle_Info **HndInfo);
|
Upnp_Handle_Type GetHandleInfo(int Hnd, struct Handle_Info **HndInfo);
|
||||||
|
|
||||||
#define HandleLock() \
|
#define HandleLock() HandleWriteLock()
|
||||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying Lock"); \
|
|
||||||
ithread_mutex_lock(&GlobalHndMutex); \
|
#define HandleWriteLock() \
|
||||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "LOCK");
|
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying a write lock"); \
|
||||||
|
ithread_rwlock_wrlock(&GlobalHndRWLock); \
|
||||||
|
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Write lock acquired");
|
||||||
|
|
||||||
|
#define HandleReadLock() \
|
||||||
|
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying a read lock"); \
|
||||||
|
ithread_rwlock_rdlock(&GlobalHndRWLock); \
|
||||||
|
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Read lock acquired");
|
||||||
|
|
||||||
#define HandleUnlock() \
|
#define HandleUnlock() \
|
||||||
UpnpPrintf(UPNP_INFO, API,__FILE__, __LINE__, "Trying Unlock"); \
|
UpnpPrintf(UPNP_INFO, API,__FILE__, __LINE__, "Trying Unlock"); \
|
||||||
ithread_mutex_unlock(&GlobalHndMutex); \
|
ithread_rwlock_unlock(&GlobalHndRWLock); \
|
||||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Unlock");
|
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Unlocked rwlock");
|
||||||
|
|
||||||
Upnp_Handle_Type GetClientHandleInfo(int *client_handle_out,
|
Upnp_Handle_Type GetClientHandleInfo(int *client_handle_out,
|
||||||
struct Handle_Info **HndInfo);
|
struct Handle_Info **HndInfo);
|
||||||
|
@ -56,88 +56,88 @@ struct SendInstruction
|
|||||||
};
|
};
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: web_server_init
|
* Function: web_server_init
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* none
|
* none
|
||||||
*
|
*
|
||||||
* Description: Initilialize the different documents. Initialize the
|
* Description: Initilialize the different documents. Initialize the
|
||||||
* memory for root directory for web server. Call to initialize global
|
* memory for root directory for web server. Call to initialize global
|
||||||
* XML document. Sets bWebServerState to WEB_SERVER_ENABLED
|
* XML document. Sets bWebServerState to WEB_SERVER_ENABLED
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* 0 - OK
|
* 0 - OK
|
||||||
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int web_server_init( void );
|
int web_server_init( void );
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: web_server_destroy
|
* Function: web_server_destroy
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* none
|
* none
|
||||||
*
|
*
|
||||||
* Description: Release memory allocated for the global web server root
|
* Description: Release memory allocated for the global web server root
|
||||||
* directory and the global XML document
|
* directory and the global XML document
|
||||||
* Resets the flag bWebServerState to WEB_SERVER_DISABLED
|
* Resets the flag bWebServerState to WEB_SERVER_DISABLED
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* void
|
* void
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
void web_server_destroy( void );
|
void web_server_destroy( void );
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: web_server_set_alias
|
* Function: web_server_set_alias
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* alias_name: webserver name of alias; created by caller and freed by
|
* alias_name: webserver name of alias; created by caller and freed by
|
||||||
* caller (doesn't even have to be malloc()d .)
|
* caller (doesn't even have to be malloc()d .)
|
||||||
* alias_content: the xml doc; this is allocated by the caller; and
|
* alias_content: the xml doc; this is allocated by the caller; and
|
||||||
* freed by the web server
|
* freed by the web server
|
||||||
* alias_content_length: length of alias body in bytes
|
* alias_content_length: length of alias body in bytes
|
||||||
* last_modified: time when the contents of alias were last
|
* last_modified: time when the contents of alias were last
|
||||||
* changed (local time)
|
* changed (local time)
|
||||||
*
|
*
|
||||||
* Description: Replaces current alias with the given alias. To remove
|
* Description: Replaces current alias with the given alias. To remove
|
||||||
* the current alias, set alias_name to NULL.
|
* the current alias, set alias_name to NULL.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* 0 - OK
|
* 0 - OK
|
||||||
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int web_server_set_alias( IN const char* alias_name,
|
int web_server_set_alias( IN const char* alias_name,
|
||||||
IN const char* alias_content, IN size_t alias_content_length,
|
IN const char* alias_content, IN size_t alias_content_length,
|
||||||
IN time_t last_modified );
|
IN time_t last_modified );
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: web_server_set_root_dir
|
* Function: web_server_set_root_dir
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN const char* root_dir ; String having the root directory for the
|
* IN const char* root_dir ; String having the root directory for the
|
||||||
* document
|
* document
|
||||||
*
|
*
|
||||||
* Description: Assign the path specfied by the IN const char* root_dir
|
* Description: Assign the path specfied by the IN const char* root_dir
|
||||||
* parameter to the global Document root directory. Also check for
|
* parameter to the global Document root directory. Also check for
|
||||||
* path names ending in '/'
|
* path names ending in '/'
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* int
|
* int
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int web_server_set_root_dir( IN const char* root_dir );
|
int web_server_set_root_dir( IN const char* root_dir );
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: web_server_callback *
|
* Function: web_server_callback
|
||||||
* *
|
*
|
||||||
* Parameters: *
|
* Parameters:
|
||||||
* IN http_parser_t *parser, *
|
* IN http_parser_t *parser,
|
||||||
* INOUT http_message_t* req, *
|
* INOUT http_message_t* req,
|
||||||
* IN SOCKINFO *info *
|
* IN SOCKINFO *info
|
||||||
* *
|
*
|
||||||
* Description: main entry point into web server; *
|
* Description: main entry point into web server;
|
||||||
* handles HTTP GET and HEAD requests *
|
* handles HTTP GET and HEAD requests
|
||||||
* *
|
*
|
||||||
* Returns: *
|
* Returns:
|
||||||
* void *
|
* void
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
void web_server_callback( IN http_parser_t *parser, IN http_message_t* req, INOUT SOCKINFO *info );
|
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
|
#endif // GENLIB_NET_HTTP_WEBSERVER_H
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ ssdp_handle_ctrlpt_msg( IN http_message_t * hmsg,
|
|||||||
|
|
||||||
// we are assuming that there can be only one client supported at a time
|
// we are assuming that there can be only one client supported at a time
|
||||||
|
|
||||||
HandleLock();
|
HandleReadLock();
|
||||||
|
|
||||||
if( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) {
|
if( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
@ -538,8 +538,7 @@ SearchByTarget( IN int Mx,
|
|||||||
if( ReqBuf == NULL )
|
if( ReqBuf == NULL )
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
return UPNP_E_OUTOF_MEMORY;
|
||||||
|
|
||||||
UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__, ">>> SSDP SEND >>>\n");
|
||||||
">>> SSDP SEND >>>\n%s\n", ReqBuf );
|
|
||||||
|
|
||||||
timeTillRead = Mx;
|
timeTillRead = Mx;
|
||||||
|
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// Copyright (c) 2000-2003 Intel Corporation
|
// Copyright (c) 2000-2003 Intel Corporation
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
// modification, are permitted provided that the following conditions are met:
|
// modification, are permitted provided that the following conditions are met:
|
||||||
//
|
//
|
||||||
// * Redistributions of source code must retain the above copyright notice,
|
// * Redistributions of source code must retain the above copyright notice,
|
||||||
// this list of conditions and the following disclaimer.
|
// this list of conditions and the following disclaimer.
|
||||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
// and/or other materials provided with the distribution.
|
// and/or other materials provided with the distribution.
|
||||||
// * Neither name of Intel Corporation nor the names of its contributors
|
// * Neither name of Intel Corporation nor the names of its contributors
|
||||||
// may be used to endorse or promote products derived from this software
|
// may be used to endorse or promote products derived from this software
|
||||||
// without specific prior written permission.
|
// without specific prior written permission.
|
||||||
//
|
//
|
||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
//
|
//
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
@ -83,11 +83,11 @@ advertiseAndReplyThread( IN void *data )
|
|||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : ssdp_handle_device_request
|
* Function : ssdp_handle_device_request
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN http_message_t* hmsg: SSDP search request from the control point
|
* IN http_message_t* hmsg: SSDP search request from the control point
|
||||||
* IN struct sockaddr_in* dest_addr: The address info of control point
|
* IN struct sockaddr_in* dest_addr: The address info of control point
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function handles the search request. It do the sanity checks of
|
* This function handles the search request. It do the sanity checks of
|
||||||
* the request and then schedules a thread to send a random time reply (
|
* the request and then schedules a thread to send a random time reply (
|
||||||
* random within maximum time given by the control point to reply).
|
* random within maximum time given by the control point to reply).
|
||||||
@ -194,15 +194,15 @@ ssdp_handle_device_request( IN http_message_t * hmsg,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : NewRequestHandler
|
* Function : NewRequestHandler
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN struct sockaddr_in * DestAddr: Ip address, to send the reply.
|
* IN struct sockaddr_in * DestAddr: Ip address, to send the reply.
|
||||||
* IN int NumPacket: Number of packet to be sent.
|
* IN int NumPacket: Number of packet to be sent.
|
||||||
* IN char **RqPacket:Number of packet to be sent.
|
* IN char **RqPacket:Number of packet to be sent.
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function works as a request handler which passes the HTTP
|
* This function works as a request handler which passes the HTTP
|
||||||
* request string to multicast channel then
|
* request string to multicast channel then
|
||||||
*
|
*
|
||||||
* Returns: void *
|
* Returns: void *
|
||||||
@ -242,7 +242,7 @@ NewRequestHandler( IN struct sockaddr_in *DestAddr,
|
|||||||
// "If a multicast resource would send a response(s) to any copy of the
|
// "If a multicast resource would send a response(s) to any copy of the
|
||||||
// request, it SHOULD send its response(s) to each copy of the request
|
// request, it SHOULD send its response(s) to each copy of the request
|
||||||
// it receives. It MUST NOT repeat its response(s) per copy of the
|
// it receives. It MUST NOT repeat its response(s) per copy of the
|
||||||
// reuqest."
|
// request."
|
||||||
//
|
//
|
||||||
// http://www.upnp.org/download/draft-goland-http-udp-04.txt
|
// http://www.upnp.org/download/draft-goland-http-udp-04.txt
|
||||||
//
|
//
|
||||||
@ -266,24 +266,24 @@ NewRequestHandler( IN struct sockaddr_in *DestAddr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : CreateServiceRequestPacket
|
* Function : CreateServiceRequestPacket
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN int msg_type : type of the message ( Search Reply, Advertisement
|
* IN int msg_type : type of the message ( Search Reply, Advertisement
|
||||||
* or Shutdown )
|
* or Shutdown )
|
||||||
* IN char * nt : ssdp type
|
* IN char * nt : ssdp type
|
||||||
* IN char * usn : unique service name ( go in the HTTP Header)
|
* IN char * usn : unique service name ( go in the HTTP Header)
|
||||||
* IN char * location :Location URL.
|
* IN char * location :Location URL.
|
||||||
* IN int duration :Service duration in sec.
|
* IN int duration :Service duration in sec.
|
||||||
* OUT char** packet :Output buffer filled with HTTP statement.
|
* OUT char** packet :Output buffer filled with HTTP statement.
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function creates a HTTP request packet. Depending
|
* This function creates a HTTP request packet. Depending
|
||||||
* on the input parameter it either creates a service advertisement
|
* on the input parameter it either creates a service advertisement
|
||||||
* request or service shutdown request etc.
|
* request or service shutdown request etc.
|
||||||
*
|
*
|
||||||
* Returns: void
|
* Returns: void
|
||||||
*
|
*
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
void
|
void
|
||||||
CreateServicePacket( IN int msg_type,
|
CreateServicePacket( IN int msg_type,
|
||||||
@ -335,7 +335,7 @@ CreateServicePacket( IN int msg_type,
|
|||||||
&buf, 1, 1,
|
&buf, 1, 1,
|
||||||
"Q" "sssdc" "sdc" "ssc" "ssc" "ssc" "S" "Xc" "sscc",
|
"Q" "sssdc" "sdc" "ssc" "ssc" "ssc" "S" "Xc" "sscc",
|
||||||
HTTPMETHOD_NOTIFY, "*",
|
HTTPMETHOD_NOTIFY, "*",
|
||||||
1, "HOST: ", SSDP_IP, ":", SSDP_PORT,
|
(size_t)1, "HOST: ", SSDP_IP, ":", SSDP_PORT,
|
||||||
"CACHE-CONTROL: max-age=", duration,
|
"CACHE-CONTROL: max-age=", duration,
|
||||||
"LOCATION: ", location,
|
"LOCATION: ", location,
|
||||||
"NT: ", nt,
|
"NT: ", nt,
|
||||||
@ -358,9 +358,9 @@ CreateServicePacket( IN int msg_type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : DeviceAdvertisement
|
* Function : DeviceAdvertisement
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char * DevType : type of the device
|
* IN char * DevType : type of the device
|
||||||
* IN int RootDev: flag to indicate if the device is root device
|
* IN int RootDev: flag to indicate if the device is root device
|
||||||
* IN char * nt : ssdp type
|
* IN char * nt : ssdp type
|
||||||
@ -368,7 +368,7 @@ CreateServicePacket( IN int msg_type,
|
|||||||
* IN char * location :Location URL.
|
* IN char * location :Location URL.
|
||||||
* IN int duration :Service duration in sec.
|
* IN int duration :Service duration in sec.
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function creates the device advertisement request based on
|
* This function creates the device advertisement request based on
|
||||||
* the input parameter, and send it to the multicast channel.
|
* the input parameter, and send it to the multicast channel.
|
||||||
*
|
*
|
||||||
@ -444,9 +444,9 @@ DeviceAdvertisement( IN char *DevType,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : SendReply
|
* Function : SendReply
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN struct sockaddr_in * DestAddr:destination IP address.
|
* IN struct sockaddr_in * DestAddr:destination IP address.
|
||||||
* IN char *DevType: Device type
|
* IN char *DevType: Device type
|
||||||
* IN int RootDev: 1 means root device 0 means embedded device.
|
* IN int RootDev: 1 means root device 0 means embedded device.
|
||||||
@ -455,7 +455,7 @@ DeviceAdvertisement( IN char *DevType,
|
|||||||
* IN int Duration :Life time of this device.
|
* IN int Duration :Life time of this device.
|
||||||
* IN int ByType:
|
* IN int ByType:
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function creates the reply packet based on the input parameter,
|
* This function creates the reply packet based on the input parameter,
|
||||||
* and send it to the client addesss given in its input parameter DestAddr.
|
* and send it to the client addesss given in its input parameter DestAddr.
|
||||||
*
|
*
|
||||||
@ -521,17 +521,16 @@ SendReply( IN struct sockaddr_in *DestAddr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : DeviceReply
|
* Function : DeviceReply
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN struct sockaddr_in * DestAddr:destination IP address.
|
* IN struct sockaddr_in * DestAddr:destination IP address.
|
||||||
* IN char *DevType: Device type
|
* IN char *DevType: Device type
|
||||||
* IN int RootDev: 1 means root device 0 means embedded device.
|
* IN int RootDev: 1 means root device 0 means embedded device.
|
||||||
* IN char * Udn: Device UDN
|
* IN char * Udn: Device UDN
|
||||||
* IN char * Location: Location of Device description document.
|
* IN char * Location: Location of Device description document.
|
||||||
* IN int Duration :Life time of this device.
|
* IN int Duration :Life time of this device.
|
||||||
|
* Description:
|
||||||
* Description:
|
|
||||||
* This function creates the reply packet based on the input parameter,
|
* This function creates the reply packet based on the input parameter,
|
||||||
* and send it to the client address given in its input parameter DestAddr.
|
* and send it to the client address given in its input parameter DestAddr.
|
||||||
*
|
*
|
||||||
@ -600,18 +599,16 @@ DeviceReply( IN struct sockaddr_in *DestAddr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : ServiceAdvertisement
|
* Function : ServiceAdvertisement
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char * Udn: Device UDN
|
* IN char * Udn: Device UDN
|
||||||
* IN char *ServType: Service Type.
|
* IN char *ServType: Service Type.
|
||||||
* IN char * Location: Location of Device description document.
|
* IN char * Location: Location of Device description document.
|
||||||
* IN int Duration :Life time of this device.
|
* IN int Duration :Life time of this device.
|
||||||
|
* Description:
|
||||||
* Description:
|
* This function creates the advertisement packet based
|
||||||
* This function creates the advertisement packet based
|
|
||||||
* on the input parameter, and send it to the multicast channel.
|
* on the input parameter, and send it to the multicast channel.
|
||||||
|
|
||||||
*
|
*
|
||||||
* Returns: int
|
* Returns: int
|
||||||
* UPNP_E_SUCCESS if successful else appropriate error
|
* UPNP_E_SUCCESS if successful else appropriate error
|
||||||
@ -648,19 +645,17 @@ ServiceAdvertisement( IN char *Udn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : ServiceReply
|
* Function : ServiceReply
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN struct sockaddr_in *DestAddr:
|
* IN struct sockaddr_in *DestAddr:
|
||||||
* IN char * Udn: Device UDN
|
* IN char * Udn: Device UDN
|
||||||
* IN char *ServType: Service Type.
|
* IN char *ServType: Service Type.
|
||||||
* IN char * Location: Location of Device description document.
|
* IN char * Location: Location of Device description document.
|
||||||
* IN int Duration :Life time of this device.
|
* IN int Duration :Life time of this device.
|
||||||
|
* Description:
|
||||||
* Description:
|
|
||||||
* This function creates the advertisement packet based
|
* This function creates the advertisement packet based
|
||||||
* on the input parameter, and send it to the multicast channel.
|
* on the input parameter, and send it to the multicast channel.
|
||||||
|
|
||||||
*
|
*
|
||||||
* Returns: int
|
* Returns: int
|
||||||
* UPNP_E_SUCCESS if successful else appropriate error
|
* UPNP_E_SUCCESS if successful else appropriate error
|
||||||
@ -693,15 +688,14 @@ ServiceReply( IN struct sockaddr_in *DestAddr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : ServiceShutdown
|
* Function : ServiceShutdown
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char * Udn: Device UDN
|
* IN char * Udn: Device UDN
|
||||||
* IN char *ServType: Service Type.
|
* IN char *ServType: Service Type.
|
||||||
* IN char * Location: Location of Device description document.
|
* IN char * Location: Location of Device description document.
|
||||||
* IN int Duration :Service duration in sec.
|
* IN int Duration :Service duration in sec.
|
||||||
|
* Description:
|
||||||
* Description:
|
|
||||||
* This function creates a HTTP service shutdown request packet
|
* This function creates a HTTP service shutdown request packet
|
||||||
* and sent it to the multicast channel through RequestHandler.
|
* and sent it to the multicast channel through RequestHandler.
|
||||||
*
|
*
|
||||||
@ -739,16 +733,16 @@ ServiceShutdown( IN char *Udn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : DeviceShutdown
|
* Function : DeviceShutdown
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char *DevType: Device Type.
|
* IN char *DevType: Device Type.
|
||||||
* IN int RootDev:1 means root device.
|
* IN int RootDev:1 means root device.
|
||||||
* IN char * Udn: Device UDN
|
* IN char * Udn: Device UDN
|
||||||
* IN char * Location: Location URL
|
* IN char * Location: Location URL
|
||||||
* IN int Duration :Device duration in sec.
|
* IN int Duration :Device duration in sec.
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function creates a HTTP device shutdown request packet
|
* This function creates a HTTP device shutdown request packet
|
||||||
* and sent it to the multicast channel through RequestHandler.
|
* and sent it to the multicast channel through RequestHandler.
|
||||||
*
|
*
|
||||||
@ -821,3 +815,4 @@ DeviceShutdown( IN char *DevType,
|
|||||||
|
|
||||||
#endif // EXCLUDE_SSDP
|
#endif // EXCLUDE_SSDP
|
||||||
#endif // INCLUDE_DEVICE_APIS
|
#endif // INCLUDE_DEVICE_APIS
|
||||||
|
|
||||||
|
@ -43,54 +43,54 @@
|
|||||||
#include "httpreadwrite.h"
|
#include "httpreadwrite.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#include "unixutil.h"
|
#include "unixutil.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MAX_TIME_TOREAD 45
|
#define MAX_TIME_TOREAD 45
|
||||||
|
|
||||||
CLIENTONLY( SOCKET gSsdpReqSocket = 0;
|
CLIENTONLY( SOCKET gSsdpReqSocket = 0; )
|
||||||
)
|
|
||||||
|
|
||||||
void RequestHandler( );
|
void RequestHandler();
|
||||||
Event ErrotEvt;
|
Event ErrotEvt;
|
||||||
|
|
||||||
enum Listener { Idle, Stopping, Running };
|
enum Listener { Idle, Stopping, Running };
|
||||||
|
|
||||||
unsigned short ssdpStopPort;
|
unsigned short ssdpStopPort;
|
||||||
|
|
||||||
struct SSDPSockArray {
|
struct SSDPSockArray {
|
||||||
int ssdpSock; //socket for incoming advertisments and search requests
|
// socket for incoming advertisments and search requests
|
||||||
CLIENTONLY( int ssdpReqSock;
|
int ssdpSock;
|
||||||
) //socket for sending search
|
// socket for sending search requests and receiving search replies
|
||||||
//requests and receiving
|
CLIENTONLY( int ssdpReqSock; )
|
||||||
// search replies
|
};
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef INCLUDE_DEVICE_APIS
|
#ifdef INCLUDE_DEVICE_APIS
|
||||||
#if EXCLUDE_SSDP == 0
|
#if EXCLUDE_SSDP == 0
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : AdvertiseAndReply
|
* Function : AdvertiseAndReply
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN int AdFlag: -1 = Send shutdown, 0 = send reply,
|
* IN int AdFlag:
|
||||||
* 1 = Send Advertisement
|
* -1 = Send shutdown,
|
||||||
* IN UpnpDevice_Handle Hnd: Device handle
|
* 0 = send reply,
|
||||||
* IN enum SsdpSearchType SearchType:Search type for sending replies
|
* 1 = Send Advertisement
|
||||||
* IN struct sockaddr_in *DestAddr:Destination address
|
* IN UpnpDevice_Handle Hnd: Device handle
|
||||||
* IN char *DeviceType:Device type
|
* IN enum SsdpSearchType SearchType:Search type for sending replies
|
||||||
* IN char *DeviceUDN:Device UDN
|
* IN struct sockaddr_in *DestAddr:Destination address
|
||||||
* IN char *ServiceType:Service type
|
* IN char *DeviceType:Device type
|
||||||
* IN int Exp:Advertisement age
|
* IN char *DeviceUDN:Device UDN
|
||||||
*
|
* IN char *ServiceType:Service type
|
||||||
* Description:
|
* IN int Exp:Advertisement age
|
||||||
* This function sends SSDP advertisements, replies and shutdown messages.
|
*
|
||||||
*
|
* Description:
|
||||||
* Returns: int
|
* This function sends SSDP advertisements, replies and shutdown messages.
|
||||||
* UPNP_E_SUCCESS if successful else appropriate error
|
*
|
||||||
***************************************************************************/
|
* Returns: int
|
||||||
|
* UPNP_E_SUCCESS if successful else appropriate error
|
||||||
|
***************************************************************************/
|
||||||
int AdvertiseAndReply( IN int AdFlag,
|
int AdvertiseAndReply( IN int AdFlag,
|
||||||
IN UpnpDevice_Handle Hnd,
|
IN UpnpDevice_Handle Hnd,
|
||||||
IN enum SsdpSearchType SearchType,
|
IN enum SsdpSearchType SearchType,
|
||||||
@ -120,18 +120,14 @@ int AdvertiseAndReply( IN int AdFlag,
|
|||||||
"Inside AdvertiseAndReply with AdFlag = %d\n",
|
"Inside AdvertiseAndReply with AdFlag = %d\n",
|
||||||
AdFlag );
|
AdFlag );
|
||||||
|
|
||||||
HandleLock();
|
// Use a read lock
|
||||||
|
HandleReadLock();
|
||||||
if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) {
|
if( GetHandleInfo( Hnd, &SInfo ) != HND_DEVICE ) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
defaultExp = SInfo->MaxAge;
|
defaultExp = SInfo->MaxAge;
|
||||||
|
|
||||||
//Modifed to prevent more than one thread from accessing the
|
|
||||||
//UpnpDocument stored with the handle at the same time
|
|
||||||
// HandleUnlock();
|
|
||||||
nodeList = NULL;
|
|
||||||
|
|
||||||
//get server info
|
//get server info
|
||||||
|
|
||||||
get_sdk_info( SERVER );
|
get_sdk_info( SERVER );
|
||||||
@ -150,15 +146,13 @@ int AdvertiseAndReply( IN int AdFlag,
|
|||||||
}
|
}
|
||||||
|
|
||||||
dbgStr = ixmlNode_getNodeName( tmpNode );
|
dbgStr = ixmlNode_getNodeName( tmpNode );
|
||||||
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
||||||
"Extracting device type once for %s\n",
|
"Extracting device type once for %s\n", dbgStr );
|
||||||
dbgStr );
|
// extract device type
|
||||||
// extract device type
|
ixmlNodeList_free( nodeList );
|
||||||
ixmlNodeList_free( nodeList );
|
|
||||||
nodeList = NULL;
|
nodeList = NULL;
|
||||||
nodeList =
|
nodeList = ixmlElement_getElementsByTagName(
|
||||||
ixmlElement_getElementsByTagName( ( IXML_Element * ) tmpNode,
|
( IXML_Element * ) tmpNode, "deviceType" );
|
||||||
"deviceType" );
|
|
||||||
if( nodeList == NULL ) {
|
if( nodeList == NULL ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -166,7 +160,6 @@ int AdvertiseAndReply( IN int AdFlag,
|
|||||||
dbgStr = ixmlNode_getNodeName( tmpNode );
|
dbgStr = ixmlNode_getNodeName( tmpNode );
|
||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Extracting UDN for %s\n", dbgStr );
|
"Extracting UDN for %s\n", dbgStr );
|
||||||
|
|
||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Extracting device type\n" );
|
"Extracting device type\n" );
|
||||||
|
|
||||||
@ -236,13 +229,12 @@ int AdvertiseAndReply( IN int AdFlag,
|
|||||||
|
|
||||||
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
||||||
"Sending UDNStr = %s \n", UDNstr );
|
"Sending UDNStr = %s \n", UDNstr );
|
||||||
if( AdFlag ) {
|
if( AdFlag ) {
|
||||||
// send the device advertisement
|
// send the device advertisement
|
||||||
if( AdFlag == 1 ) {
|
if( AdFlag == 1 ) {
|
||||||
DeviceAdvertisement( devType, i == 0,
|
DeviceAdvertisement( devType, i == 0,
|
||||||
UDNstr, SInfo->DescURL, Exp );
|
UDNstr, SInfo->DescURL, Exp );
|
||||||
} else // AdFlag == -1
|
} else { // AdFlag == -1
|
||||||
{
|
|
||||||
DeviceShutdown( devType, i == 0, UDNstr,
|
DeviceShutdown( devType, i == 0, UDNstr,
|
||||||
SERVER, SInfo->DescURL, Exp );
|
SERVER, SInfo->DescURL, Exp );
|
||||||
}
|
}
|
||||||
@ -324,8 +316,9 @@ int AdvertiseAndReply( IN int AdFlag,
|
|||||||
}
|
}
|
||||||
for( j = 0;; j++ ) {
|
for( j = 0;; j++ ) {
|
||||||
tmpNode = ixmlNodeList_item( nodeList, j );
|
tmpNode = ixmlNodeList_item( nodeList, j );
|
||||||
if( tmpNode == NULL )
|
if( tmpNode == NULL ) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
ixmlNodeList_free( tmpNodeList );
|
ixmlNodeList_free( tmpNodeList );
|
||||||
tmpNodeList = NULL;
|
tmpNodeList = NULL;
|
||||||
@ -334,7 +327,7 @@ int AdvertiseAndReply( IN int AdFlag,
|
|||||||
if( tmpNodeList == NULL ) {
|
if( tmpNodeList == NULL ) {
|
||||||
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__,
|
||||||
"ServiceType not found \n" );
|
"ServiceType not found \n" );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tmpNode2 = ixmlNodeList_item( tmpNodeList, 0 );
|
tmpNode2 = ixmlNodeList_item( tmpNodeList, 0 );
|
||||||
if( tmpNode2 == NULL ) {
|
if( tmpNode2 == NULL ) {
|
||||||
@ -367,26 +360,21 @@ int AdvertiseAndReply( IN int AdFlag,
|
|||||||
} else {
|
} else {
|
||||||
switch ( SearchType ) {
|
switch ( SearchType ) {
|
||||||
case SSDP_ALL:
|
case SSDP_ALL:
|
||||||
{
|
ServiceReply( DestAddr, servType,
|
||||||
ServiceReply( DestAddr, servType,
|
UDNstr, SInfo->DescURL,
|
||||||
UDNstr, SInfo->DescURL,
|
defaultExp );
|
||||||
defaultExp );
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SSDP_SERVICE:
|
case SSDP_SERVICE:
|
||||||
{
|
if( ServiceType != NULL ) {
|
||||||
if( ServiceType != NULL ) {
|
if( !strncasecmp( ServiceType,
|
||||||
if( !strncasecmp( ServiceType,
|
servType,
|
||||||
servType,
|
strlen( ServiceType ) ) ) {
|
||||||
strlen( ServiceType ) ) )
|
ServiceReply( DestAddr, servType,
|
||||||
{
|
UDNstr, SInfo->DescURL,
|
||||||
ServiceReply( DestAddr, servType,
|
defaultExp );
|
||||||
UDNstr, SInfo->DescURL,
|
|
||||||
defaultExp );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
} // switch(SearchType)
|
} // switch(SearchType)
|
||||||
@ -401,27 +389,27 @@ int AdvertiseAndReply( IN int AdFlag,
|
|||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Exiting AdvertiseAndReply : \n" );
|
"Exiting AdvertiseAndReply : \n" );
|
||||||
|
|
||||||
HandleUnlock( );
|
HandleUnlock();
|
||||||
|
|
||||||
return UPNP_E_SUCCESS;
|
return UPNP_E_SUCCESS;
|
||||||
|
|
||||||
} /****************** End of AdvertiseAndReply *********************/
|
} /****************** End of AdvertiseAndReply *********************/
|
||||||
|
|
||||||
#endif
|
#endif /* EXCLUDE_SSDP == 0 */
|
||||||
#endif
|
#endif /* INCLUDE_DEVICE_APIS */
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : Make_Socket_NoBlocking
|
* Function : Make_Socket_NoBlocking
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN int sock: socket
|
* IN int sock: socket
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function makes socket non-blocking.
|
* This function makes socket non-blocking.
|
||||||
*
|
*
|
||||||
* Returns: int
|
* Returns: int
|
||||||
* 0 if successful else -1
|
* 0 if successful else -1
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
int
|
int
|
||||||
Make_Socket_NoBlocking( int sock )
|
Make_Socket_NoBlocking( int sock )
|
||||||
{
|
{
|
||||||
@ -440,20 +428,20 @@ Make_Socket_NoBlocking( int sock )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : unique_service_name
|
* Function : unique_service_name
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char *cmd: Service Name string
|
* IN char *cmd: Service Name string
|
||||||
* OUT SsdpEvent *Evt: The SSDP event structure partially filled
|
* OUT SsdpEvent *Evt: The SSDP event structure partially filled
|
||||||
* by all the function.
|
* by all the function.
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function fills the fields of the event structure like DeviceType,
|
* This function fills the fields of the event structure like DeviceType,
|
||||||
* Device UDN and Service Type
|
* Device UDN and Service Type
|
||||||
*
|
*
|
||||||
* Returns: int
|
* Returns: int
|
||||||
* 0 if successful else -1
|
* 0 if successful else -1
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
int
|
int
|
||||||
unique_service_name( IN char *cmd,
|
unique_service_name( IN char *cmd,
|
||||||
IN SsdpEvent * Evt )
|
IN SsdpEvent * Evt )
|
||||||
@ -535,18 +523,18 @@ unique_service_name( IN char *cmd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : ssdp_request_type1
|
* Function : ssdp_request_type1
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char *cmd: command came in the ssdp request
|
* IN char *cmd: command came in the ssdp request
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function figures out the type of the SSDP search in the
|
* This function figures out the type of the SSDP search in the
|
||||||
* in the request.
|
* in the request.
|
||||||
*
|
*
|
||||||
* Returns: enum SsdpSearchType
|
* Returns: enum SsdpSearchType
|
||||||
* return appropriate search type else returns SSDP_ERROR
|
* return appropriate search type else returns SSDP_ERROR
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
enum SsdpSearchType
|
enum SsdpSearchType
|
||||||
ssdp_request_type1( IN char *cmd )
|
ssdp_request_type1( IN char *cmd )
|
||||||
{
|
{
|
||||||
@ -571,20 +559,20 @@ ssdp_request_type1( IN char *cmd )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : ssdp_request_type
|
* Function : ssdp_request_type
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char *cmd: command came in the ssdp request
|
* IN char *cmd: command came in the ssdp request
|
||||||
* OUT SsdpEvent *Evt: The event structure partially filled by
|
* OUT SsdpEvent *Evt: The event structure partially filled by
|
||||||
* this function.
|
* this function.
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function starts filling the SSDP event structure based upon the
|
* This function starts filling the SSDP event structure based upon the
|
||||||
* request received.
|
* request received.
|
||||||
*
|
*
|
||||||
* Returns: int
|
* Returns: int
|
||||||
* 0 on success; -1 on error
|
* 0 on success; -1 on error
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
int
|
int
|
||||||
ssdp_request_type( IN char *cmd,
|
ssdp_request_type( IN char *cmd,
|
||||||
OUT SsdpEvent * Evt )
|
OUT SsdpEvent * Evt )
|
||||||
@ -602,18 +590,18 @@ ssdp_request_type( IN char *cmd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : free_ssdp_event_handler_data
|
* Function : free_ssdp_event_handler_data
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN void *the_data: ssdp_thread_data structure. This structure contains
|
* IN void *the_data: ssdp_thread_data structure. This structure contains
|
||||||
* SSDP request message.
|
* SSDP request message.
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function frees the ssdp request
|
* This function frees the ssdp request
|
||||||
*
|
*
|
||||||
* Returns: VOID
|
* Returns: VOID
|
||||||
*
|
*
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static void
|
static void
|
||||||
free_ssdp_event_handler_data( void *the_data )
|
free_ssdp_event_handler_data( void *the_data )
|
||||||
{
|
{
|
||||||
@ -629,18 +617,18 @@ free_ssdp_event_handler_data( void *the_data )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : valid_ssdp_msg
|
* Function : valid_ssdp_msg
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN void *the_data: ssdp_thread_data structure. This structure contains
|
* IN void *the_data: ssdp_thread_data structure. This structure contains
|
||||||
* SSDP request message.
|
* SSDP request message.
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function do some quick checking of the ssdp msg
|
* This function do some quick checking of the ssdp msg
|
||||||
*
|
*
|
||||||
* Returns: xboolean
|
* Returns: xboolean
|
||||||
* returns TRUE if msg is valid else FALSE
|
* returns TRUE if msg is valid else FALSE
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static UPNP_INLINE xboolean
|
static UPNP_INLINE xboolean
|
||||||
valid_ssdp_msg( IN http_message_t * hmsg )
|
valid_ssdp_msg( IN http_message_t * hmsg )
|
||||||
{
|
{
|
||||||
@ -670,19 +658,19 @@ valid_ssdp_msg( IN http_message_t * hmsg )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : start_event_handler
|
* Function : start_event_handler
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN void *the_data: ssdp_thread_data structure. This structure contains
|
* IN void *the_data: ssdp_thread_data structure. This structure contains
|
||||||
* SSDP request message.
|
* SSDP request message.
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function parses the message and dispatches it to a handler
|
* This function parses the message and dispatches it to a handler
|
||||||
* which handles the ssdp request msg
|
* which handles the ssdp request msg
|
||||||
*
|
*
|
||||||
* Returns: int
|
* Returns: int
|
||||||
* 0 if successful -1 if error
|
* 0 if successful -1 if error
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static UPNP_INLINE int
|
static UPNP_INLINE int
|
||||||
start_event_handler( void *Data )
|
start_event_handler( void *Data )
|
||||||
{
|
{
|
||||||
@ -722,18 +710,18 @@ start_event_handler( void *Data )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : ssdp_event_handler_thread
|
* Function : ssdp_event_handler_thread
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN void *the_data: ssdp_thread_data structure. This structure contains
|
* IN void *the_data: ssdp_thread_data structure. This structure contains
|
||||||
* SSDP request message.
|
* SSDP request message.
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function is a thread that handles SSDP requests.
|
* This function is a thread that handles SSDP requests.
|
||||||
*
|
*
|
||||||
* Returns: void
|
* Returns: void
|
||||||
*
|
*
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static void
|
static void
|
||||||
ssdp_event_handler_thread( void *the_data )
|
ssdp_event_handler_thread( void *the_data )
|
||||||
{
|
{
|
||||||
@ -746,8 +734,7 @@ ssdp_event_handler_thread( void *the_data )
|
|||||||
// send msg to device or ctrlpt
|
// send msg to device or ctrlpt
|
||||||
if( ( hmsg->method == HTTPMETHOD_NOTIFY ) ||
|
if( ( hmsg->method == HTTPMETHOD_NOTIFY ) ||
|
||||||
( hmsg->request_method == HTTPMETHOD_MSEARCH ) ) {
|
( hmsg->request_method == HTTPMETHOD_MSEARCH ) ) {
|
||||||
CLIENTONLY( ssdp_handle_ctrlpt_msg( hmsg, &data->dest_addr,
|
CLIENTONLY( ssdp_handle_ctrlpt_msg( hmsg, &data->dest_addr, FALSE, NULL );)
|
||||||
FALSE, NULL ););
|
|
||||||
} else {
|
} else {
|
||||||
ssdp_handle_device_request( hmsg, &data->dest_addr );
|
ssdp_handle_device_request( hmsg, &data->dest_addr );
|
||||||
}
|
}
|
||||||
@ -757,17 +744,17 @@ ssdp_event_handler_thread( void *the_data )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : readFromSSDPSocket
|
* Function : readFromSSDPSocket
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN SOCKET socket: SSDP socket
|
* IN SOCKET socket: SSDP socket
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function reads the data from the ssdp socket.
|
* This function reads the data from the ssdp socket.
|
||||||
*
|
*
|
||||||
* Returns: void
|
* Returns: void
|
||||||
*
|
*
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
void
|
void
|
||||||
readFromSSDPSocket( SOCKET socket )
|
readFromSSDPSocket( SOCKET socket )
|
||||||
{
|
{
|
||||||
@ -819,18 +806,20 @@ readFromSSDPSocket( SOCKET socket )
|
|||||||
( struct sockaddr * )&clientAddr, &socklen );
|
( struct sockaddr * )&clientAddr, &socklen );
|
||||||
|
|
||||||
if( byteReceived > 0 ) {
|
if( byteReceived > 0 ) {
|
||||||
|
|
||||||
requestBuf[byteReceived] = '\0';
|
requestBuf[byteReceived] = '\0';
|
||||||
UpnpPrintf( UPNP_INFO, SSDP,
|
UpnpPrintf( UPNP_INFO, SSDP,
|
||||||
__FILE__, __LINE__,
|
__FILE__, __LINE__,
|
||||||
"Received response !!! "
|
"Start of received response ----------------------------------------------------\n"
|
||||||
"%s From host %s \n",
|
"%s\n"
|
||||||
requestBuf,
|
"End of received response ------------------------------------------------------\n"
|
||||||
inet_ntoa( clientAddr.sin_addr ) );
|
"From host %s\n",
|
||||||
|
requestBuf,
|
||||||
|
inet_ntoa( clientAddr.sin_addr ) );
|
||||||
UpnpPrintf( UPNP_PACKET, SSDP, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_PACKET, SSDP, __FILE__, __LINE__,
|
||||||
"Received multicast packet:"
|
"Start of received multicast packet --------------------------------------------\n"
|
||||||
"\n %s\n", requestBuf );
|
"%s\n"
|
||||||
|
"End of received multicast packet ----------------------------------------------\n",
|
||||||
|
requestBuf );
|
||||||
//add thread pool job to handle request
|
//add thread pool job to handle request
|
||||||
if( data != NULL ) {
|
if( data != NULL ) {
|
||||||
data->parser.msg.msg.length += byteReceived;
|
data->parser.msg.msg.length += byteReceived;
|
||||||
@ -852,98 +841,98 @@ readFromSSDPSocket( SOCKET socket )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function : get_ssdp_sockets
|
* Function : get_ssdp_sockets
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* OUT MiniServerSockArray *out: Arrays of SSDP sockets
|
* OUT MiniServerSockArray *out: Arrays of SSDP sockets
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function creates the ssdp sockets. It set their option to listen
|
* This function creates the ssdp sockets. It set their option to listen
|
||||||
* for multicast traffic.
|
* for multicast traffic.
|
||||||
*
|
*
|
||||||
* Returns: int
|
* Returns: int
|
||||||
* return UPNP_E_SUCCESS if successful else returns appropriate error
|
* return UPNP_E_SUCCESS if successful else returns appropriate error
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
int
|
int
|
||||||
get_ssdp_sockets( MiniServerSockArray * out )
|
get_ssdp_sockets( MiniServerSockArray * out )
|
||||||
{
|
{
|
||||||
SOCKET ssdpSock;
|
|
||||||
|
|
||||||
CLIENTONLY( SOCKET ssdpReqSock;
|
|
||||||
)
|
|
||||||
int onOff = 1;
|
int onOff = 1;
|
||||||
u_char ttl = 4;
|
u_char ttl = 4;
|
||||||
struct ip_mreq ssdpMcastAddr;
|
struct ip_mreq ssdpMcastAddr;
|
||||||
struct sockaddr_in ssdpAddr;
|
struct sockaddr_in ssdpAddr;
|
||||||
int option = 1;
|
int option = 1;
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
|
SOCKET ssdpSock;
|
||||||
|
#if INCLUDE_CLIENT_APIS
|
||||||
|
SOCKET ssdpReqSock;
|
||||||
|
|
||||||
CLIENTONLY( if( ( ssdpReqSock = socket( AF_INET, SOCK_DGRAM, 0 ) )
|
if( ( ssdpReqSock = socket( AF_INET, SOCK_DGRAM, 0 ) ) == UPNP_INVALID_SOCKET ) {
|
||||||
== UPNP_INVALID_SOCKET ) {
|
UpnpPrintf( UPNP_CRITICAL,
|
||||||
UpnpPrintf( UPNP_CRITICAL,
|
SSDP, __FILE__, __LINE__,
|
||||||
SSDP, __FILE__, __LINE__,
|
"Error in socket operation !!!\n" );
|
||||||
"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; ) //CLIENTONLY
|
|
||||||
|
|
||||||
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 ) );
|
|
||||||
return UPNP_E_OUTOF_SOCKET;
|
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;
|
||||||
|
#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 ); )
|
||||||
|
|
||||||
|
return UPNP_E_OUTOF_SOCKET;
|
||||||
|
}
|
||||||
|
|
||||||
onOff = 1;
|
onOff = 1;
|
||||||
if( setsockopt( ssdpSock, SOL_SOCKET, SO_REUSEADDR,
|
if( setsockopt( ssdpSock, SOL_SOCKET, SO_REUSEADDR,
|
||||||
( char * )&onOff, sizeof( onOff ) ) != 0 ) {
|
( char * )&onOff, sizeof( onOff ) ) != 0 ) {
|
||||||
|
|
||||||
UpnpPrintf( UPNP_CRITICAL,
|
UpnpPrintf( UPNP_CRITICAL,
|
||||||
SSDP, __FILE__, __LINE__,
|
SSDP, __FILE__, __LINE__,
|
||||||
"Error in set reuse addr !!!\n" );
|
"Error in set reuse addr !!!\n" );
|
||||||
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
|
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ); )
|
||||||
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
|
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ); )
|
||||||
shutdown( ssdpSock, SD_BOTH );
|
shutdown( ssdpSock, SD_BOTH );
|
||||||
UpnpCloseSocket( ssdpSock );
|
UpnpCloseSocket( ssdpSock );
|
||||||
|
|
||||||
return UPNP_E_SOCKET_ERROR;
|
return UPNP_E_SOCKET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
#if defined(__FreeBSD__) || defined(__OSX__) || defined(__APPLE__)
|
||||||
if( setsockopt( ssdpSock, SOL_SOCKET, SO_REUSEPORT,
|
if( setsockopt( ssdpSock, SOL_SOCKET, SO_REUSEPORT,
|
||||||
( char * )&onOff, sizeof( onOff ) ) != 0 ) {
|
( char * )&onOff, sizeof( onOff ) ) != 0 ) {
|
||||||
|
|
||||||
UpnpPrintf( UPNP_CRITICAL,
|
UpnpPrintf( UPNP_CRITICAL,
|
||||||
SSDP, __FILE__, __LINE__,
|
SSDP, __FILE__, __LINE__,
|
||||||
"Error in set reuse port !!!\n" );
|
"Error in set reuse port !!!\n" );
|
||||||
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
|
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ); )
|
||||||
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
|
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ); )
|
||||||
shutdown( ssdpSock, SD_BOTH );
|
shutdown( ssdpSock, SD_BOTH );
|
||||||
UpnpCloseSocket( ssdpSock );
|
UpnpCloseSocket( ssdpSock );
|
||||||
|
|
||||||
return UPNP_E_SOCKET_ERROR;
|
return UPNP_E_SOCKET_ERROR;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* __FreeBSD__ */
|
||||||
|
|
||||||
memset( ( void * )&ssdpAddr, 0, sizeof( struct sockaddr_in ) );
|
memset( ( void * )&ssdpAddr, 0, sizeof( struct sockaddr_in ) );
|
||||||
ssdpAddr.sin_family = AF_INET;
|
ssdpAddr.sin_family = AF_INET;
|
||||||
// ssdpAddr.sin_addr.s_addr = inet_addr(LOCAL_HOST);
|
// ssdpAddr.sin_addr.s_addr = inet_addr(LOCAL_HOST);
|
||||||
ssdpAddr.sin_addr.s_addr = htonl( INADDR_ANY );
|
ssdpAddr.sin_addr.s_addr = htonl( INADDR_ANY );
|
||||||
ssdpAddr.sin_port = htons( SSDP_PORT );
|
ssdpAddr.sin_port = htons( SSDP_PORT );
|
||||||
if( bind
|
if( bind( ssdpSock, ( struct sockaddr * )&ssdpAddr,
|
||||||
( ssdpSock, ( struct sockaddr * )&ssdpAddr,
|
sizeof( ssdpAddr ) ) != 0 ) {
|
||||||
sizeof( ssdpAddr ) ) != 0 ) {
|
|
||||||
UpnpPrintf( UPNP_CRITICAL,
|
UpnpPrintf( UPNP_CRITICAL,
|
||||||
SSDP, __FILE__, __LINE__,
|
SSDP, __FILE__, __LINE__,
|
||||||
"Error in binding !!!\n" );
|
"Error in binding !!!\n" );
|
||||||
shutdown( ssdpSock, SD_BOTH );
|
shutdown( ssdpSock, SD_BOTH );
|
||||||
UpnpCloseSocket( ssdpSock );
|
UpnpCloseSocket( ssdpSock );
|
||||||
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
|
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ); )
|
||||||
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
|
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ); )
|
||||||
|
|
||||||
return UPNP_E_SOCKET_BIND;
|
return UPNP_E_SOCKET_BIND;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -951,47 +940,49 @@ get_ssdp_sockets( MiniServerSockArray * out )
|
|||||||
ssdpMcastAddr.imr_interface.s_addr = inet_addr( LOCAL_HOST );
|
ssdpMcastAddr.imr_interface.s_addr = inet_addr( LOCAL_HOST );
|
||||||
ssdpMcastAddr.imr_multiaddr.s_addr = inet_addr( SSDP_IP );
|
ssdpMcastAddr.imr_multiaddr.s_addr = inet_addr( SSDP_IP );
|
||||||
if( setsockopt( ssdpSock, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
if( setsockopt( ssdpSock, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
||||||
( char * )&ssdpMcastAddr,
|
( char * )&ssdpMcastAddr, sizeof( struct ip_mreq ) ) != 0 ) {
|
||||||
sizeof( struct ip_mreq ) ) != 0 ) {
|
|
||||||
UpnpPrintf( UPNP_CRITICAL,
|
UpnpPrintf( UPNP_CRITICAL,
|
||||||
SSDP, __FILE__, __LINE__,
|
SSDP, __FILE__, __LINE__,
|
||||||
"Error in joining" " multicast group !!!\n" );
|
"Error in joining" " multicast group !!!\n" );
|
||||||
shutdown( ssdpSock, SD_BOTH );
|
shutdown( ssdpSock, SD_BOTH );
|
||||||
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
|
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ); )
|
||||||
UpnpCloseSocket( ssdpSock );
|
UpnpCloseSocket( ssdpSock );
|
||||||
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
|
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ); )
|
||||||
|
|
||||||
return UPNP_E_SOCKET_ERROR;
|
return UPNP_E_SOCKET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set multicast interface. */
|
/* Set multicast interface. */
|
||||||
memset( ( void * )&addr, 0, sizeof( struct in_addr ));
|
memset( ( void * )&addr, 0, sizeof( struct in_addr ));
|
||||||
addr.s_addr = inet_addr(LOCAL_HOST);
|
addr.s_addr = inet_addr(LOCAL_HOST);
|
||||||
if (setsockopt(ssdpSock, IPPROTO_IP, IP_MULTICAST_IF,
|
if ( setsockopt(ssdpSock, IPPROTO_IP, IP_MULTICAST_IF,
|
||||||
(char *)&addr, sizeof addr) != 0) {
|
(char *)&addr, sizeof addr) != 0) {
|
||||||
UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__,
|
||||||
"Couldn't set multicast interface.\n" );
|
"Couldn't set multicast interface.\n" );
|
||||||
/* This is probably not a critical error, so let's continue. */
|
/* 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,
|
setsockopt( ssdpSock, IPPROTO_IP,
|
||||||
IP_MULTICAST_TTL, &ttl, sizeof( ttl ) );
|
IP_MULTICAST_TTL, &ttl, sizeof( ttl ) );
|
||||||
if( setsockopt( ssdpSock, SOL_SOCKET, SO_BROADCAST,
|
if( setsockopt( ssdpSock, SOL_SOCKET, SO_BROADCAST,
|
||||||
( char * )&option, sizeof( option ) ) != 0 ) {
|
(char *)&option, sizeof(option) ) != 0) {
|
||||||
UpnpPrintf( UPNP_CRITICAL,
|
UpnpPrintf( UPNP_CRITICAL,
|
||||||
SSDP, __FILE__, __LINE__,
|
SSDP, __FILE__, __LINE__,
|
||||||
"Error in setting broadcast !!!\n" );
|
"Error in setting broadcast !!!\n" );
|
||||||
shutdown( ssdpSock, SD_BOTH );
|
shutdown( ssdpSock, SD_BOTH );
|
||||||
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
|
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ); )
|
||||||
UpnpCloseSocket( ssdpSock );
|
UpnpCloseSocket( ssdpSock );
|
||||||
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
|
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ); )
|
||||||
|
|
||||||
return UPNP_E_NETWORK_ERROR;
|
return UPNP_E_NETWORK_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
CLIENTONLY( out->ssdpReqSock = ssdpReqSock;
|
CLIENTONLY( out->ssdpReqSock = ssdpReqSock; )
|
||||||
);
|
|
||||||
out->ssdpSock = ssdpSock;
|
out->ssdpSock = ssdpSock;
|
||||||
|
|
||||||
return UPNP_E_SUCCESS;
|
return UPNP_E_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EXCLUDE_SSDP
|
#endif /* EXCLUDE_SSDP */
|
||||||
|
|
||||||
|
@ -50,22 +50,11 @@
|
|||||||
#define S43 15
|
#define S43 15
|
||||||
#define S44 21
|
#define S44 21
|
||||||
|
|
||||||
static void MD5Transform PROTO_LIST( ( UINT4[4],
|
static void MD5Transform PROTO_LIST((UINT4[4], unsigned char[64]));
|
||||||
unsigned char[64] ) );
|
static void Encode PROTO_LIST((unsigned char *, UINT4 *, unsigned int));
|
||||||
static void Encode PROTO_LIST( ( unsigned char *,
|
static void Decode PROTO_LIST((UINT4 *, unsigned char *, unsigned int));
|
||||||
UINT4 *,
|
static void MD5_memcpy PROTO_LIST((POINTER, POINTER, unsigned int));
|
||||||
unsigned int ) );
|
static void MD5_memset PROTO_LIST((POINTER, int, unsigned int));
|
||||||
|
|
||||||
static void Decode PROTO_LIST( ( UINT4 *,
|
|
||||||
unsigned char *,
|
|
||||||
unsigned int ) );
|
|
||||||
|
|
||||||
static void MD5_memcpy PROTO_LIST( ( POINTER,
|
|
||||||
POINTER,
|
|
||||||
unsigned int ) );
|
|
||||||
static void MD5_memset PROTO_LIST( ( POINTER,
|
|
||||||
int,
|
|
||||||
unsigned int ) );
|
|
||||||
|
|
||||||
static unsigned char PADDING[64] = {
|
static unsigned char PADDING[64] = {
|
||||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
@ -118,14 +107,10 @@ static unsigned char PADDING[64] = {
|
|||||||
MD5 initialization. Begins an MD5 operation, writing a new context.
|
MD5 initialization. Begins an MD5 operation, writing a new context.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MD5Init( context )
|
MD5Init(MD5_CTX * context)
|
||||||
MD5_CTX *context; /* context */
|
|
||||||
{
|
{
|
||||||
context->count[0] = context->count[1] = 0;
|
context->count[0] = context->count[1] = 0;
|
||||||
|
/* Load magic initialization constants. */
|
||||||
/*
|
|
||||||
Load magic initialization constants.
|
|
||||||
*/
|
|
||||||
context->state[0] = 0x67452301;
|
context->state[0] = 0x67452301;
|
||||||
context->state[1] = 0xefcdab89;
|
context->state[1] = 0xefcdab89;
|
||||||
context->state[2] = 0x98badcfe;
|
context->state[2] = 0x98badcfe;
|
||||||
@ -139,114 +124,72 @@ MD5Init( context )
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
MD5Update( context,
|
MD5Update(MD5_CTX *context, unsigned char *input, unsigned int inputLen)
|
||||||
input,
|
|
||||||
inputLen )
|
|
||||||
MD5_CTX *context; /* context */
|
|
||||||
unsigned char *input; /* input block */
|
|
||||||
unsigned int inputLen; /* length of input block */
|
|
||||||
{
|
{
|
||||||
unsigned int i,
|
unsigned int i;
|
||||||
index,
|
unsigned int index;
|
||||||
partLen;
|
unsigned int partLen;
|
||||||
|
|
||||||
/*
|
/* Compute number of bytes mod 64 */
|
||||||
Compute number of bytes mod 64
|
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
|
||||||
*/
|
|
||||||
index = ( unsigned int )( ( context->count[0] >> 3 ) & 0x3F );
|
|
||||||
|
|
||||||
/*
|
/* Update number of bits */
|
||||||
Update number of bits
|
if ((context->count[0] += ((UINT4)inputLen << 3)) < ((UINT4)inputLen << 3)) {
|
||||||
*/
|
context->count[1]++;
|
||||||
if( ( context->count[0] +=
|
}
|
||||||
( ( UINT4 ) inputLen << 3 ) ) < ( ( UINT4 ) inputLen << 3 ) )
|
context->count[1] += ((UINT4)inputLen >> 29);
|
||||||
context->count[1]++;
|
partLen = 64 - index;
|
||||||
|
|
||||||
context->count[1] += ( ( UINT4 ) inputLen >> 29 );
|
/* Transform as many times as possible. */
|
||||||
|
if (inputLen >= partLen) {
|
||||||
partLen = 64 - index;
|
MD5_memcpy((POINTER)&context->buffer[index], (POINTER)input, partLen);
|
||||||
|
MD5Transform(context->state, context->buffer);
|
||||||
/*
|
for (i = partLen; i + 63 < inputLen; i += 64) {
|
||||||
Transform as many times as possible.
|
MD5Transform(context->state, &input[i]);
|
||||||
*/
|
}
|
||||||
if( inputLen >= partLen ) {
|
index = 0;
|
||||||
|
} else {
|
||||||
MD5_memcpy
|
i = 0;
|
||||||
( ( POINTER ) & context->buffer[index], ( POINTER ) input,
|
}
|
||||||
partLen );
|
|
||||||
MD5Transform( context->state, context->buffer );
|
|
||||||
|
|
||||||
for( i = partLen; i + 63 < inputLen; i += 64 )
|
|
||||||
MD5Transform( context->state, &input[i] );
|
|
||||||
|
|
||||||
index = 0;
|
|
||||||
} else
|
|
||||||
i = 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
Buffer remaining input
|
|
||||||
*/
|
|
||||||
MD5_memcpy
|
|
||||||
( ( POINTER ) & context->buffer[index], ( POINTER ) & input[i],
|
|
||||||
inputLen - i );
|
|
||||||
|
|
||||||
|
/* Buffer remaining input */
|
||||||
|
MD5_memcpy((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen - i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MD5 finalization. Ends an MD5 message-digest operation, writing the
|
MD5 finalization. Ends an MD5 message-digest operation, writing the
|
||||||
the message digest and zeroizing the context.
|
the message digest and zeroizing the context.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
MD5Final( digest,
|
MD5Final(unsigned char digest[16], MD5_CTX *context)
|
||||||
context )
|
|
||||||
unsigned char digest[16]; /* message digest */
|
|
||||||
MD5_CTX *context; /* context */
|
|
||||||
{
|
{
|
||||||
|
|
||||||
unsigned char bits[8];
|
unsigned char bits[8];
|
||||||
unsigned int index,
|
unsigned int index;
|
||||||
padLen;
|
unsigned int padLen;
|
||||||
|
|
||||||
/*
|
/* Save number of bits */
|
||||||
Save number of bits
|
Encode(bits, context->count, 8);
|
||||||
*/
|
|
||||||
Encode( bits, context->count, 8 );
|
|
||||||
|
|
||||||
/*
|
/* Pad out to 56 mod 64. */
|
||||||
Pad out to 56 mod 64.
|
index = (unsigned int)((context->count[0] >> 3) & 0x3f);
|
||||||
*/
|
padLen = (index < 56) ? (56 - index) : (120 - index);
|
||||||
index = ( unsigned int )( ( context->count[0] >> 3 ) & 0x3f );
|
MD5Update(context, PADDING, padLen);
|
||||||
|
|
||||||
padLen = ( index < 56 ) ? ( 56 - index ) : ( 120 - index );
|
/* Append length (before padding) */
|
||||||
|
MD5Update(context, bits, 8);
|
||||||
|
|
||||||
MD5Update( context, PADDING, padLen );
|
/* Store state in digest */
|
||||||
|
Encode(digest, context->state, 16);
|
||||||
/*
|
|
||||||
Append length (before padding)
|
|
||||||
*/
|
|
||||||
MD5Update( context, bits, 8 );
|
|
||||||
|
|
||||||
/*
|
|
||||||
Store state in digest
|
|
||||||
*/
|
|
||||||
Encode( digest, context->state, 16 );
|
|
||||||
|
|
||||||
/*
|
|
||||||
Zeroize sensitive information.
|
|
||||||
*/
|
|
||||||
MD5_memset( ( POINTER ) context, 0, sizeof( *context ) );
|
|
||||||
|
|
||||||
|
/* Zeroize sensitive information. */
|
||||||
|
MD5_memset((POINTER)context, 0, sizeof(*context));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MD5 basic transformation. Transforms state based on block.
|
MD5 basic transformation. Transforms state based on block.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
MD5Transform( state,
|
MD5Transform(UINT4 state[4], unsigned char block[64])
|
||||||
block )
|
|
||||||
UINT4 state[4];
|
|
||||||
unsigned char block[64];
|
|
||||||
{
|
{
|
||||||
UINT4 a = state[0],
|
UINT4 a = state[0],
|
||||||
b = state[1],
|
b = state[1],
|
||||||
@ -353,23 +296,16 @@ MD5Transform( state,
|
|||||||
a multiple of 4.
|
a multiple of 4.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
Encode( output,
|
Encode(unsigned char *output, UINT4 *input, unsigned int len)
|
||||||
input,
|
|
||||||
len )
|
|
||||||
unsigned char *output;
|
|
||||||
UINT4 *input;
|
|
||||||
unsigned int len;
|
|
||||||
{
|
{
|
||||||
unsigned int i,
|
unsigned int i;
|
||||||
j;
|
unsigned int j;
|
||||||
|
for (i = 0, j = 0; j < len; ++i, j += 4) {
|
||||||
for( i = 0, j = 0; j < len; i++, j += 4 ) {
|
output[j+0] = (unsigned char)((input[i] >> 0) & 0xff);
|
||||||
output[j] = ( unsigned char )( input[i] & 0xff );
|
output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
|
||||||
output[j + 1] = ( unsigned char )( ( input[i] >> 8 ) & 0xff );
|
output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
|
||||||
output[j + 2] = ( unsigned char )( ( input[i] >> 16 ) & 0xff );
|
output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
|
||||||
output[j + 3] = ( unsigned char )( ( input[i] >> 24 ) & 0xff );
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -378,55 +314,40 @@ Encode( output,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Decode( output,
|
Decode(UINT4 *output, unsigned char *input, unsigned int len)
|
||||||
input,
|
|
||||||
len )
|
|
||||||
UINT4 *output;
|
|
||||||
unsigned char *input;
|
|
||||||
unsigned int len;
|
|
||||||
{
|
{
|
||||||
unsigned int i,
|
unsigned int i;
|
||||||
j;
|
unsigned int j;
|
||||||
|
for (i = 0, j = 0; j < len; ++i, j += 4) {
|
||||||
for( i = 0, j = 0; j < len; i++, j += 4 )
|
output[i] =
|
||||||
output[i] =
|
(((UINT4)input[j+0]) << 0) |
|
||||||
( ( UINT4 ) input[j] ) | ( ( ( UINT4 ) input[j + 1] ) << 8 ) |
|
(((UINT4)input[j+1]) << 8) |
|
||||||
( ( ( UINT4 ) input[j + 2] ) << 16 ) |
|
(((UINT4)input[j+2]) << 16) |
|
||||||
( ( ( UINT4 ) input[j + 3] ) << 24 );
|
(((UINT4)input[j+3]) << 24);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Note: Replace "for loop" with standard memcpy if possible.
|
Note: Replace for loop with standard memcpy if possible.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
MD5_memcpy( output,
|
MD5_memcpy(POINTER output, POINTER input, unsigned int len)
|
||||||
input,
|
|
||||||
len )
|
|
||||||
POINTER output;
|
|
||||||
POINTER input;
|
|
||||||
unsigned int len;
|
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
for (i = 0; i < len; ++i) {
|
||||||
for( i = 0; i < len; i++ )
|
output[i] = input[i];
|
||||||
output[i] = input[i];
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Note: Replace "for loop" with standard memset if possible.
|
Note: Replace for loop with standard memset if possible.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
MD5_memset( output,
|
MD5_memset(POINTER output, int value, unsigned int len)
|
||||||
value,
|
|
||||||
len )
|
|
||||||
POINTER output;
|
|
||||||
int value;
|
|
||||||
unsigned int len;
|
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
for (i = 0; i < len; ++i) {
|
||||||
for( i = 0; i < len; i++ )
|
((char *)output)[i] = (char)value;
|
||||||
( ( char * )output )[i] = ( char )value;
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,17 +33,16 @@
|
|||||||
This sample implementation generates a random node ID
|
This sample implementation generates a random node ID
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
get_ieee_node_identifier( uuid_node_t * node )
|
get_ieee_node_identifier(uuid_node_t *node)
|
||||||
{
|
{
|
||||||
char seed[16];
|
char seed[16];
|
||||||
static int inited = 0;
|
static int inited = 0;
|
||||||
static uuid_node_t saved_node;
|
static uuid_node_t saved_node;
|
||||||
|
|
||||||
if( !inited ) {
|
if (!inited) {
|
||||||
get_random_info( seed );
|
get_random_info(seed);
|
||||||
seed[0] |= 0x80;
|
seed[0] |= 0x80;
|
||||||
memcpy( &saved_node, seed, sizeof( uuid_node_t ) );
|
memcpy(&saved_node, seed, sizeof (uuid_node_t));
|
||||||
|
|
||||||
inited = 1;
|
inited = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -83,52 +82,48 @@ get_system_time( uuid_time_t * uuid_time )
|
|||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
get_random_info( char seed[16] )
|
get_random_info(char seed[16])
|
||||||
{
|
{
|
||||||
MD5_CTX c;
|
MD5_CTX c;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
MEMORYSTATUS m;
|
MEMORYSTATUS m;
|
||||||
SYSTEM_INFO s;
|
SYSTEM_INFO s;
|
||||||
FILETIME t;
|
FILETIME t;
|
||||||
LARGE_INTEGER pc;
|
LARGE_INTEGER pc;
|
||||||
DWORD tc;
|
DWORD tc;
|
||||||
DWORD l;
|
DWORD l;
|
||||||
char hostname[MAX_COMPUTERNAME_LENGTH + 1];
|
char hostname[MAX_COMPUTERNAME_LENGTH + 1];
|
||||||
} randomness;
|
} randomness;
|
||||||
randomness r;
|
randomness r;
|
||||||
|
|
||||||
MD5Init( &c );
|
/* Initialize memory area so that valgrind does not complain */
|
||||||
/*
|
memset(&r, 0, sizeof r);
|
||||||
memory usage stats
|
|
||||||
*/
|
|
||||||
GlobalMemoryStatus( &r.m );
|
|
||||||
/*
|
|
||||||
random system stats
|
|
||||||
*/
|
|
||||||
GetSystemInfo( &r.s );
|
|
||||||
/*
|
|
||||||
100ns resolution (nominally) time of day
|
|
||||||
*/
|
|
||||||
GetSystemTimeAsFileTime( &r.t );
|
|
||||||
/*
|
|
||||||
high resolution performance counter
|
|
||||||
*/
|
|
||||||
QueryPerformanceCounter( &r.pc );
|
|
||||||
/*
|
|
||||||
milliseconds since last boot
|
|
||||||
*/
|
|
||||||
r.tc = GetTickCount( );
|
|
||||||
r.l = MAX_COMPUTERNAME_LENGTH + 1;
|
|
||||||
|
|
||||||
GetComputerName( r.hostname, &r.l );
|
/* memory usage stats */
|
||||||
MD5Update( &c, &r, sizeof( randomness ) );
|
GlobalMemoryStatus( &r.m );
|
||||||
MD5Final( seed, &c );
|
/* random system stats */
|
||||||
|
GetSystemInfo( &r.s );
|
||||||
|
/* 100ns resolution (nominally) time of day */
|
||||||
|
GetSystemTimeAsFileTime( &r.t );
|
||||||
|
/* high resolution performance counter */
|
||||||
|
QueryPerformanceCounter( &r.pc );
|
||||||
|
/* milliseconds since last boot */
|
||||||
|
r.tc = GetTickCount();
|
||||||
|
r.l = MAX_COMPUTERNAME_LENGTH + 1;
|
||||||
|
|
||||||
|
GetComputerName( r.hostname, &r.l );
|
||||||
|
|
||||||
|
/* MD5 it */
|
||||||
|
MD5Init(&c);
|
||||||
|
MD5Update(&c, &r, sizeof r);
|
||||||
|
MD5Final(seed, &c);
|
||||||
};
|
};
|
||||||
#else
|
|
||||||
|
#else /* _WINDOWS_ */
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
get_system_time( uuid_time_t * uuid_time )
|
get_system_time(uuid_time_t *uuid_time)
|
||||||
{
|
{
|
||||||
struct timeval tp;
|
struct timeval tp;
|
||||||
|
|
||||||
@ -145,22 +140,28 @@ get_system_time( uuid_time_t * uuid_time )
|
|||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
get_random_info( char seed[16] )
|
get_random_info(char seed[16])
|
||||||
{
|
{
|
||||||
MD5_CTX c;
|
MD5_CTX c;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// struct sysinfo s;
|
//struct sysinfo s;
|
||||||
struct timeval t;
|
struct timeval t;
|
||||||
char hostname[257];
|
char hostname[257];
|
||||||
} randomness;
|
} randomness;
|
||||||
randomness r;
|
randomness r;
|
||||||
|
|
||||||
MD5Init( &c );
|
/* Initialize memory area so that valgrind does not complain */
|
||||||
|
memset(&r, 0, sizeof r);
|
||||||
|
|
||||||
gettimeofday( &r.t, ( struct timezone * )0 );
|
/* Get some random stuff */
|
||||||
gethostname( r.hostname, 256 );
|
gettimeofday(&r.t, (struct timezone *)0);
|
||||||
MD5Update( &c, &r, sizeof( randomness ) );
|
gethostname(r.hostname, 256 );
|
||||||
MD5Final( seed, &c );
|
|
||||||
|
/* MD5 it */
|
||||||
|
MD5Init(&c);
|
||||||
|
MD5Update(&c, &r, sizeof r);
|
||||||
|
MD5Final(seed, &c);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif /* _WINDOWS_ */
|
||||||
|
|
||||||
|
@ -53,10 +53,10 @@ static unsigned16 true_random( void );
|
|||||||
uuid_create -- generator a UUID
|
uuid_create -- generator a UUID
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
uuid_create( uuid_upnp * uid )
|
uuid_create(uuid_upnp *uid)
|
||||||
{
|
{
|
||||||
uuid_time_t timestamp,
|
uuid_time_t timestamp;
|
||||||
last_time;
|
uuid_time_t last_time;
|
||||||
unsigned16 clockseq;
|
unsigned16 clockseq;
|
||||||
uuid_node_t node;
|
uuid_node_t node;
|
||||||
uuid_node_t last_node;
|
uuid_node_t last_node;
|
||||||
@ -65,61 +65,64 @@ uuid_create( uuid_upnp * uid )
|
|||||||
/*
|
/*
|
||||||
acquire system wide lock so we're alone
|
acquire system wide lock so we're alone
|
||||||
*/
|
*/
|
||||||
UUIDLock( );
|
UUIDLock();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
get current time
|
get current time
|
||||||
*/
|
*/
|
||||||
get_current_time( ×tamp );
|
get_current_time(×tamp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
get node ID
|
get node ID
|
||||||
*/
|
*/
|
||||||
get_ieee_node_identifier( &node );
|
get_ieee_node_identifier(&node);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
get saved state from NV storage
|
get saved state from NV storage
|
||||||
*/
|
*/
|
||||||
f = read_state( &clockseq, &last_time, &last_node );
|
f = read_state(&clockseq, &last_time, &last_node);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if no NV state, or if clock went backwards, or node ID changed
|
if no NV state, or if clock went backwards, or node ID changed
|
||||||
(e.g., net card swap) change clockseq
|
(e.g., net card swap) change clockseq
|
||||||
*/
|
*/
|
||||||
if( !f || memcmp( &node, &last_node, sizeof( uuid_node_t ) ) )
|
if (!f || memcmp(&node, &last_node, sizeof(uuid_node_t))) {
|
||||||
clockseq = true_random( );
|
clockseq = true_random();
|
||||||
else if( timestamp < last_time )
|
} else if (timestamp < last_time) {
|
||||||
clockseq++;
|
clockseq++;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
stuff fields into the UUID
|
stuff fields into the UUID
|
||||||
*/
|
*/
|
||||||
format_uuid_v1( uid, clockseq, timestamp, node );
|
format_uuid_v1(uid, clockseq, timestamp, node);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
save the state for next time
|
save the state for next time
|
||||||
*/
|
*/
|
||||||
write_state( clockseq, timestamp, node );
|
write_state(clockseq, timestamp, node);
|
||||||
|
|
||||||
UUIDUnlock( );
|
UUIDUnlock();
|
||||||
return ( 1 );
|
return 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
uuid_unpack( uuid_upnp * u,
|
uuid_unpack(uuid_upnp *u, char *out)
|
||||||
char *out )
|
|
||||||
{
|
{
|
||||||
|
sprintf(out,
|
||||||
sprintf( out,
|
"%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
|
||||||
"%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
|
(unsigned int)u->time_low,
|
||||||
( unsigned int )u->time_low, u->time_mid,
|
u->time_mid,
|
||||||
u->time_hi_and_version, u->clock_seq_hi_and_reserved,
|
u->time_hi_and_version,
|
||||||
u->clock_seq_low, u->node[0], u->node[1], u->node[2],
|
u->clock_seq_hi_and_reserved,
|
||||||
u->node[3], u->node[4], u->node[5] );
|
u->clock_seq_low,
|
||||||
|
u->node[0],
|
||||||
*( out + 36 ) = '\0';
|
u->node[1],
|
||||||
|
u->node[2],
|
||||||
|
u->node[3],
|
||||||
|
u->node[4],
|
||||||
|
u->node[5]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
@ -137,11 +140,10 @@ format_uuid_v1( uuid_upnp * uid,
|
|||||||
Construct a version 1 uuid with the information we've gathered
|
Construct a version 1 uuid with the information we've gathered
|
||||||
* plus a few constants.
|
* plus a few constants.
|
||||||
*/
|
*/
|
||||||
uid->time_low = ( unsigned long )( timestamp & 0xFFFFFFFF );
|
uid->time_low = (unsigned long)(timestamp & 0xFFFFFFFF);
|
||||||
uid->time_mid = ( unsigned short )( ( timestamp >> 32 ) & 0xFFFF );
|
uid->time_mid = (unsigned short)((timestamp >> 32) & 0xFFFF);
|
||||||
uid->time_hi_and_version = ( unsigned short )( ( timestamp >> 48 ) &
|
uid->time_hi_and_version = (unsigned short)((timestamp >> 48) & 0x0FFF);
|
||||||
0x0FFF );
|
uid->time_hi_and_version |= (1 << 12);
|
||||||
uid->time_hi_and_version |= ( 1 << 12 );
|
|
||||||
uid->clock_seq_low = clock_seq & 0xFF;
|
uid->clock_seq_low = clock_seq & 0xFF;
|
||||||
uid->clock_seq_hi_and_reserved = ( clock_seq & 0x3F00 ) >> 8;
|
uid->clock_seq_hi_and_reserved = ( clock_seq & 0x3F00 ) >> 8;
|
||||||
uid->clock_seq_hi_and_reserved |= 0x80;
|
uid->clock_seq_hi_and_reserved |= 0x80;
|
||||||
@ -227,7 +229,6 @@ get_current_time( uuid_time_t * timestamp )
|
|||||||
static int inited = 0;
|
static int inited = 0;
|
||||||
|
|
||||||
if( !inited ) {
|
if( !inited ) {
|
||||||
get_system_time( &time_now );
|
|
||||||
uuids_this_tick = UUIDS_PER_TICK;
|
uuids_this_tick = UUIDS_PER_TICK;
|
||||||
inited = 1;
|
inited = 1;
|
||||||
};
|
};
|
||||||
|
@ -105,7 +105,7 @@ main (int argc, char* argv[])
|
|||||||
* Test library initialisation
|
* Test library initialisation
|
||||||
*/
|
*/
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
printf ("Intializing UPnP ... \n");
|
printf ("Initializing UPnP ... \n");
|
||||||
rc = UpnpInit (NULL, 0);
|
rc = UpnpInit (NULL, 0);
|
||||||
if ( UPNP_E_SUCCESS == rc ) {
|
if ( UPNP_E_SUCCESS == rc ) {
|
||||||
const char* ip_address = UpnpGetServerIpAddress();
|
const char* ip_address = UpnpGetServerIpAddress();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user