Merge of trunk into branch 1.6.x.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@263 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
20
ChangeLog
20
ChangeLog
@@ -2,15 +2,23 @@
|
|||||||
Version 1.6.2
|
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>
|
2007-11-09 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||||
* Added a isleep() call to the error handler of select() in
|
* Added a isleep() call to the error handler of select() in
|
||||||
RunMiniServer(), so that it does not take 100% cpu in case select()
|
RunMiniServer(), so that it does not take 100% cpu in case select()
|
||||||
fails repeatedly.
|
fails repeatedly.
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
Version 1.6.1
|
Version 1.6.1
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
@@ -129,6 +137,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
|
||||||
|
2
THANKS
2
THANKS
@@ -16,6 +16,8 @@ exempt of errors.
|
|||||||
- Erik Johansson
|
- Erik Johansson
|
||||||
- Eric Tanguy
|
- Eric Tanguy
|
||||||
- Erwan Velu
|
- Erwan Velu
|
||||||
|
- Eugene Christensen
|
||||||
|
- Fabrice Fontaine
|
||||||
- Fredrik Svensson
|
- Fredrik Svensson
|
||||||
- Glen Masgai
|
- Glen Masgai
|
||||||
- Jiri Zouhar
|
- Jiri Zouhar
|
||||||
|
@@ -92,11 +92,9 @@ CLIENTONLY( ithread_mutex_t GlobalClientSubscribeMutex; )
|
|||||||
|
|
||||||
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;
|
||||||
@@ -415,8 +413,9 @@ UpnpFinish()
|
|||||||
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
||||||
"UpnpFinish : UpnpSdkInit is ONE\n" );
|
"UpnpFinish : UpnpSdkInit is ONE\n" );
|
||||||
}
|
}
|
||||||
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool");
|
|
||||||
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__, "Send Thread Pool");
|
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__, "Send Thread Pool");
|
||||||
|
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool");
|
||||||
|
PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__, "MiniServer Thread Pool");
|
||||||
|
|
||||||
#ifdef INCLUDE_DEVICE_APIS
|
#ifdef INCLUDE_DEVICE_APIS
|
||||||
if( GetDeviceHandleInfo( &device_handle, &temp ) == HND_DEVICE )
|
if( GetDeviceHandleInfo( &device_handle, &temp ) == HND_DEVICE )
|
||||||
@@ -435,11 +434,13 @@ UpnpFinish()
|
|||||||
web_server_destroy();
|
web_server_destroy();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ThreadPoolShutdown(&gSendThreadPool);
|
ThreadPoolShutdown(&gMiniServerThreadPool);
|
||||||
ThreadPoolShutdown(&gRecvThreadPool);
|
ThreadPoolShutdown(&gRecvThreadPool);
|
||||||
|
ThreadPoolShutdown(&gSendThreadPool);
|
||||||
|
|
||||||
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool");
|
|
||||||
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__, "Send Thread Pool");
|
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__, "Send Thread Pool");
|
||||||
|
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool");
|
||||||
|
PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__, "MiniServer Thread Pool");
|
||||||
|
|
||||||
#ifdef INCLUDE_CLIENT_APIS
|
#ifdef INCLUDE_CLIENT_APIS
|
||||||
ithread_mutex_destroy(&GlobalClientSubscribeMutex);
|
ithread_mutex_destroy(&GlobalClientSubscribeMutex);
|
||||||
|
@@ -115,11 +115,13 @@ SetHTTPGetCallback( MiniServerCallback callback )
|
|||||||
*
|
*
|
||||||
* Return: void
|
* Return: void
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
#ifdef INCLUDE_DEVICE_APIS
|
||||||
void
|
void
|
||||||
SetSoapCallback( MiniServerCallback callback )
|
SetSoapCallback( MiniServerCallback callback )
|
||||||
{
|
{
|
||||||
gSoapCallback = callback;
|
gSoapCallback = callback;
|
||||||
}
|
}
|
||||||
|
#endif /* INCLUDE_DEVICE_APIS */
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: SetGenaCallback
|
* Function: SetGenaCallback
|
||||||
|
@@ -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 )
|
||||||
{
|
{
|
||||||
@@ -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,18 +862,18 @@ 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,
|
||||||
@@ -924,23 +923,23 @@ GetNextRange( char **SrcRangeStr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* 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,
|
||||||
@@ -1036,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,
|
||||||
@@ -1167,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,
|
||||||
@@ -1495,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,
|
||||||
@@ -1659,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,
|
||||||
@@ -1764,3 +1763,4 @@ web_server_callback( IN http_parser_t * parser,
|
|||||||
membuffer_destroy( &headers );
|
membuffer_destroy( &headers );
|
||||||
membuffer_destroy( &filename );
|
membuffer_destroy( &filename );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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 */
|
||||||
|
|
||||||
|
@@ -43,56 +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:
|
* IN int AdFlag:
|
||||||
* -1 = Send shutdown,
|
* -1 = Send shutdown,
|
||||||
* 0 = send reply,
|
* 0 = send reply,
|
||||||
* 1 = Send Advertisement
|
* 1 = Send Advertisement
|
||||||
* IN UpnpDevice_Handle Hnd: Device handle
|
* IN UpnpDevice_Handle Hnd: Device handle
|
||||||
* IN enum SsdpSearchType SearchType:Search type for sending replies
|
* IN enum SsdpSearchType SearchType:Search type for sending replies
|
||||||
* IN struct sockaddr_in *DestAddr:Destination address
|
* IN struct sockaddr_in *DestAddr:Destination address
|
||||||
* IN char *DeviceType:Device type
|
* IN char *DeviceType:Device type
|
||||||
* IN char *DeviceUDN:Device UDN
|
* IN char *DeviceUDN:Device UDN
|
||||||
* IN char *ServiceType:Service type
|
* IN char *ServiceType:Service type
|
||||||
* IN int Exp:Advertisement age
|
* IN int Exp:Advertisement age
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function sends SSDP advertisements, replies and shutdown messages.
|
* This function sends SSDP advertisements, replies and shutdown messages.
|
||||||
*
|
*
|
||||||
* Returns: int
|
* Returns: int
|
||||||
* UPNP_E_SUCCESS if successful else appropriate error
|
* 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,
|
||||||
@@ -129,7 +127,6 @@ int AdvertiseAndReply( IN int AdFlag,
|
|||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
defaultExp = SInfo->MaxAge;
|
defaultExp = SInfo->MaxAge;
|
||||||
nodeList = NULL;
|
|
||||||
|
|
||||||
//get server info
|
//get server info
|
||||||
|
|
||||||
@@ -398,21 +395,21 @@ int AdvertiseAndReply( IN int AdFlag,
|
|||||||
|
|
||||||
} /****************** 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 )
|
||||||
{
|
{
|
||||||
@@ -431,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 )
|
||||||
@@ -526,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 )
|
||||||
{
|
{
|
||||||
@@ -562,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 )
|
||||||
@@ -593,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 )
|
||||||
{
|
{
|
||||||
@@ -620,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 )
|
||||||
{
|
{
|
||||||
@@ -661,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 )
|
||||||
{
|
{
|
||||||
@@ -713,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 )
|
||||||
{
|
{
|
||||||
@@ -737,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 );
|
||||||
}
|
}
|
||||||
@@ -748,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 )
|
||||||
{
|
{
|
||||||
@@ -845,32 +841,31 @@ 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 ) ) == UPNP_INVALID_SOCKET ) {
|
if( ( ssdpReqSock = socket( AF_INET, SOCK_DGRAM, 0 ) ) == UPNP_INVALID_SOCKET ) {
|
||||||
UpnpPrintf( UPNP_CRITICAL,
|
UpnpPrintf( UPNP_CRITICAL,
|
||||||
SSDP, __FILE__, __LINE__,
|
SSDP, __FILE__, __LINE__,
|
||||||
@@ -880,15 +875,15 @@ CLIENTONLY(
|
|||||||
setsockopt( ssdpReqSock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof( ttl ) );
|
setsockopt( ssdpReqSock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof( ttl ) );
|
||||||
// just do it, regardless if fails or not.
|
// just do it, regardless if fails or not.
|
||||||
Make_Socket_NoBlocking( ssdpReqSock );
|
Make_Socket_NoBlocking( ssdpReqSock );
|
||||||
gSsdpReqSocket = ssdpReqSock; )
|
gSsdpReqSocket = ssdpReqSock;
|
||||||
// END CLIENTONLY
|
#endif /* INCLUDE_CLIENT_APIS */
|
||||||
|
|
||||||
if( ( ssdpSock = socket( AF_INET, SOCK_DGRAM, 0 ) ) == UPNP_INVALID_SOCKET ) {
|
if( ( ssdpSock = socket( AF_INET, SOCK_DGRAM, 0 ) ) == 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" );
|
||||||
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
|
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ); )
|
||||||
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
|
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ); )
|
||||||
return UPNP_E_OUTOF_SOCKET;
|
return UPNP_E_OUTOF_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -898,26 +893,26 @@ CLIENTONLY(
|
|||||||
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__
|
#ifdef __FreeBSD__
|
||||||
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;
|
||||||
@@ -931,8 +926,8 @@ CLIENTONLY(
|
|||||||
"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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -945,9 +940,9 @@ CLIENTONLY(
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -961,7 +956,7 @@ CLIENTONLY(
|
|||||||
/* 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,
|
||||||
@@ -970,16 +965,16 @@ CLIENTONLY(
|
|||||||
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 */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user