White spaces.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@240 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
@@ -42,12 +42,12 @@
|
|||||||
#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"
|
||||||
|
|
||||||
@@ -91,13 +91,12 @@ 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 )
|
||||||
@@ -109,13 +108,12 @@ 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 :
|
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
void
|
void
|
||||||
SetSoapCallback( MiniServerCallback callback )
|
SetSoapCallback( MiniServerCallback callback )
|
||||||
@@ -127,13 +125,12 @@ SetSoapCallback( MiniServerCallback callback )
|
|||||||
* 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 )
|
||||||
@@ -145,17 +142,15 @@ 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,
|
||||||
@@ -203,17 +198,15 @@ dispatch_request( IN SOCKINFO * info,
|
|||||||
* Function: handle_error
|
* Function: handle_error
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
|
* IN SOCKINFO *info - Socket Inforamtion Object
|
||||||
|
* int http_error_code - HTTP Error Code
|
||||||
|
* int major - Major Version Number
|
||||||
|
* int minor - Minor Version Number
|
||||||
*
|
*
|
||||||
* IN SOCKINFO *info ; Socket Inforamtion Object
|
* Description:
|
||||||
* int http_error_code ; HTTP Error Code
|
* Send Error Message
|
||||||
* int major ; Major Version Number
|
|
||||||
* int minor ; Minor Version Number
|
|
||||||
*
|
*
|
||||||
* Description : 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,
|
||||||
@@ -230,12 +223,11 @@ handle_error( IN SOCKINFO * info,
|
|||||||
* 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 )
|
||||||
@@ -251,13 +243,12 @@ 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 )
|
||||||
@@ -322,16 +313,14 @@ 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:
|
||||||
|
* Initilize the thread pool to handle a request.
|
||||||
* Sets priority for the job and adds the job to the thread pool
|
* 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,
|
||||||
@@ -374,29 +363,26 @@ 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:
|
||||||
|
* Function runs the miniserver. The MiniServer accepts a
|
||||||
* new request and schedules a thread to handle the new request.
|
* new request and schedules a thread to handle the new request.
|
||||||
* Checks for socket state and invokes appropriate read and shutdown
|
* Checks for socket state and invokes appropriate read and shutdown
|
||||||
* actions for the Miniserver and SSDP sockets
|
* 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 miniServSock;
|
||||||
connectHnd;
|
SOCKET connectHnd;
|
||||||
SOCKET miniServStopSock;
|
SOCKET miniServStopSock;
|
||||||
SOCKET ssdpSock;
|
SOCKET ssdpSock;
|
||||||
|
CLIENTONLY( SOCKET ssdpReqSock; )
|
||||||
CLIENTONLY( SOCKET ssdpReqSock;
|
|
||||||
)
|
|
||||||
|
|
||||||
fd_set expSet;
|
fd_set expSet;
|
||||||
fd_set rdSet;
|
fd_set rdSet;
|
||||||
@@ -406,27 +392,21 @@ RunMiniServer( MiniServerSockArray * miniSock )
|
|||||||
|
|
||||||
miniServSock = miniSock->miniServerSock;
|
miniServSock = miniSock->miniServerSock;
|
||||||
miniServStopSock = miniSock->miniServerStopSock;
|
miniServStopSock = miniSock->miniServerStopSock;
|
||||||
|
|
||||||
ssdpSock = miniSock->ssdpSock;
|
ssdpSock = miniSock->ssdpSock;
|
||||||
|
CLIENTONLY( ssdpReqSock = miniSock->ssdpReqSock; );
|
||||||
CLIENTONLY( ssdpReqSock = miniSock->ssdpReqSock;
|
|
||||||
);
|
|
||||||
|
|
||||||
gMServState = MSERV_RUNNING;
|
gMServState = MSERV_RUNNING;
|
||||||
maxMiniSock = max( miniServSock, miniServStopSock );
|
maxMiniSock = max( miniServSock, miniServStopSock );
|
||||||
maxMiniSock = max( maxMiniSock, ( SOCKET ) ( ssdpSock ) );
|
maxMiniSock = max( maxMiniSock, ( SOCKET ) ( ssdpSock ) );
|
||||||
|
|
||||||
CLIENTONLY( maxMiniSock =
|
CLIENTONLY( maxMiniSock =
|
||||||
max( maxMiniSock, ( SOCKET ) ( ssdpReqSock ) ) );
|
max( maxMiniSock, ( SOCKET ) ( ssdpReqSock ) ) );
|
||||||
|
|
||||||
++maxMiniSock;
|
++maxMiniSock;
|
||||||
|
|
||||||
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 );
|
||||||
@@ -438,7 +418,6 @@ RunMiniServer( MiniServerSockArray * miniSock )
|
|||||||
"Error in select call !!!\n" );
|
"Error in select call !!!\n" );
|
||||||
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,
|
||||||
@@ -453,17 +432,15 @@ RunMiniServer( MiniServerSockArray * miniSock )
|
|||||||
schedule_request_job( connectHnd, &clientAddr );
|
schedule_request_job( connectHnd, &clientAddr );
|
||||||
}
|
}
|
||||||
//ssdp
|
//ssdp
|
||||||
CLIENTONLY( if( FD_ISSET( ssdpReqSock, &rdSet ) ) {
|
CLIENTONLY(
|
||||||
|
if( FD_ISSET( ssdpReqSock, &rdSet ) ) {
|
||||||
readFromSSDPSocket( ssdpReqSock );}
|
readFromSSDPSocket( ssdpReqSock );
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
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 +456,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;
|
||||||
}
|
}
|
||||||
@@ -502,22 +478,20 @@ RunMiniServer( MiniServerSockArray * 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,
|
* Return: int
|
||||||
* -1 on error; check errno
|
* -1 on error; check errno
|
||||||
* > 0 means port number
|
* > 0 means port number
|
||||||
*
|
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static int
|
static int
|
||||||
get_port( int sockfd )
|
get_port( int sockfd )
|
||||||
@@ -544,24 +518,24 @@ 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 listens for
|
||||||
|
* incoming connecttions. Returns the actual port which the sockets
|
||||||
|
* sub-system returned.
|
||||||
*
|
*
|
||||||
* Description : Creates a STREAM socket, binds to INADDR_ANY and
|
|
||||||
* listens for incoming connecttions. Returns the actual port which
|
|
||||||
* the sockets sub-system returned.
|
|
||||||
* Also creates a DGRAM socket, binds to the loop back address and
|
* Also creates a DGRAM socket, binds to the loop back address and
|
||||||
* returns the port allocated by the socket sub-system.
|
* returns the port allocated by the socket sub-system.
|
||||||
*
|
*
|
||||||
* Return : int :
|
* Return: int
|
||||||
* UPNP_E_OUTOF_SOCKET - Failed to create a socket
|
* UPNP_E_OUTOF_SOCKET - Failed to create a socket
|
||||||
* UPNP_E_SOCKET_BIND - Bind() failed
|
* UPNP_E_SOCKET_BIND - Bind() failed
|
||||||
* UPNP_E_LISTEN - Listen() failed
|
* UPNP_E_LISTEN - Listen() failed
|
||||||
* UPNP_E_INTERNAL_ERROR - Port returned by the socket layer is < 0
|
* UPNP_E_INTERNAL_ERROR - Port returned by the socket layer is < 0
|
||||||
* UPNP_E_SUCCESS - Success
|
* UPNP_E_SUCCESS - Success
|
||||||
*
|
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int
|
int
|
||||||
get_miniserver_sockets( MiniServerSockArray * out,
|
get_miniserver_sockets( MiniServerSockArray * out,
|
||||||
@@ -711,10 +685,11 @@ 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:
|
||||||
|
* 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
|
||||||
@@ -722,10 +697,9 @@ get_miniserver_sockets( MiniServerSockArray * out,
|
|||||||
* 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
|
int
|
||||||
StartMiniServer( unsigned short listen_port )
|
StartMiniServer( unsigned short listen_port )
|
||||||
@@ -817,15 +791,14 @@ 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
|
||||||
*
|
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int
|
int
|
||||||
StopMiniServer( void )
|
StopMiniServer( void )
|
||||||
@@ -864,3 +837,4 @@ StopMiniServer( void )
|
|||||||
UpnpCloseSocket( sock );
|
UpnpCloseSocket( sock );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user