Slightly better debug messages and lots of white spaces.

git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@225 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez
2007-10-26 13:21:59 +00:00
parent b29de32110
commit fd80e5a8ff
2 changed files with 106 additions and 105 deletions

View File

@@ -475,11 +475,13 @@ http_SendMessage( IN SOCKINFO * info,
buf_length = ( size_t ) va_arg( argp, size_t ); buf_length = ( size_t ) va_arg( argp, size_t );
if( buf_length > 0 ) { if( buf_length > 0 ) {
num_written = sock_write( info, buf, buf_length, TimeOut ); num_written = sock_write( info, buf, buf_length, TimeOut );
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
">>> (SENT) >>>\n"
"%.*s\nbuf_length=%d, num_written=%d\n"
"------------\n",
(int)buf_length, buf, (int)buf_length, num_written );
if( ( size_t ) num_written != buf_length ) if( ( size_t ) num_written != buf_length )
goto end; goto end;
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
">>> (SENT) >>>\n%.*s\n------------\n",
( int )buf_length, buf );
} }
} }
} }

View File

@@ -72,11 +72,13 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0;
#if EXCLUDE_SSDP == 0 #if EXCLUDE_SSDP == 0
/************************************************************************ /************************************************************************
* Function : AdvertiseAndReply * Function : AdvertiseAndReply
* *
* Parameters: * Parameters:
* IN int AdFlag: -1 = Send shutdown, 0 = send reply, * IN int AdFlag:
* 1 = Send Advertisement * -1 = Send shutdown,
* 0 = send reply,
* 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
@@ -85,7 +87,7 @@ CLIENTONLY( SOCKET gSsdpReqSocket = 0;
* 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
@@ -411,12 +413,12 @@ int AdvertiseAndReply( IN int AdFlag,
#endif #endif
/************************************************************************ /************************************************************************
* Function : Make_Socket_NoBlocking * Function : Make_Socket_NoBlocking
*
* Parameters:
* IN int sock: socket
* *
* Description: * Parameters:
* IN int sock: socket
*
* Description:
* This function makes socket non-blocking. * This function makes socket non-blocking.
* *
* Returns: int * Returns: int
@@ -440,19 +442,19 @@ Make_Socket_NoBlocking( int sock )
} }
/************************************************************************ /************************************************************************
* Function : unique_service_name * Function : unique_service_name
*
* Parameters:
* IN char *cmd: Service Name string
* OUT SsdpEvent *Evt: The SSDP event structure partially filled
* by all the function.
* *
* Description: * Parameters:
* IN char *cmd: Service Name string
* OUT SsdpEvent *Evt: The SSDP event structure partially filled
* by all the function.
*
* Description:
* This function fills the fields of the event structure like DeviceType, * 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,
@@ -535,13 +537,13 @@ 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
@@ -571,16 +573,16 @@ 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
@@ -602,17 +604,17 @@ ssdp_request_type( IN char *cmd,
} }
/************************************************************************ /************************************************************************
* Function : free_ssdp_event_handler_data * Function : free_ssdp_event_handler_data
* *
* Parameters: * Parameters:
* IN void *the_data: ssdp_thread_data structure. This structure contains * IN void *the_data: ssdp_thread_data structure. This structure contains
* SSDP request message. * SSDP request message.
* *
* Description: * Description:
* This function frees the ssdp request * This function frees the ssdp request
* *
* Returns: VOID * Returns: VOID
* *
***************************************************************************/ ***************************************************************************/
static void static void
free_ssdp_event_handler_data( void *the_data ) free_ssdp_event_handler_data( void *the_data )
@@ -629,13 +631,13 @@ 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
@@ -670,14 +672,14 @@ 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
@@ -722,17 +724,17 @@ 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 )
@@ -757,16 +759,16 @@ ssdp_event_handler_thread( void *the_data )
} }
/************************************************************************ /************************************************************************
* Function : readFromSSDPSocket * Function : readFromSSDPSocket
* *
* Parameters: * Parameters:
* IN SOCKET socket: SSDP socket * IN SOCKET socket: SSDP socket
* *
* Description: * Description:
* This function reads the data from the ssdp socket. * This function reads the data from the ssdp socket.
* *
* Returns: void * Returns: void
* *
***************************************************************************/ ***************************************************************************/
void void
readFromSSDPSocket( SOCKET socket ) readFromSSDPSocket( SOCKET socket )
@@ -819,18 +821,20 @@ readFromSSDPSocket( SOCKET socket )
( struct sockaddr * )&clientAddr, &socklen ); ( struct sockaddr * )&clientAddr, &socklen );
if( byteReceived > 0 ) { if( byteReceived > 0 ) {
requestBuf[byteReceived] = '\0'; requestBuf[byteReceived] = '\0';
UpnpPrintf( UPNP_INFO, SSDP, UpnpPrintf( UPNP_INFO, SSDP,
__FILE__, __LINE__, __FILE__, __LINE__,
"Received response !!! " "Start of received response ----------------------------------------------------\n"
"%s From host %s \n", "%s\n"
requestBuf, "End of received response ------------------------------------------------------\n"
inet_ntoa( clientAddr.sin_addr ) ); "From host %s\n",
requestBuf,
inet_ntoa( clientAddr.sin_addr ) );
UpnpPrintf( UPNP_PACKET, SSDP, __FILE__, __LINE__, UpnpPrintf( UPNP_PACKET, SSDP, __FILE__, __LINE__,
"Received multicast packet:" "Start of received multicast packet --------------------------------------------\n"
"\n %s\n", requestBuf ); "%s\n"
"End of received multicast packet ----------------------------------------------\n",
requestBuf );
//add thread pool job to handle request //add thread pool job to handle request
if( data != NULL ) { if( data != NULL ) {
data->parser.msg.msg.length += byteReceived; data->parser.msg.msg.length += byteReceived;
@@ -853,12 +857,12 @@ 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
@@ -869,8 +873,7 @@ get_ssdp_sockets( MiniServerSockArray * out )
{ {
SOCKET ssdpSock; SOCKET ssdpSock;
CLIENTONLY( SOCKET ssdpReqSock; 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;
@@ -878,32 +881,31 @@ get_ssdp_sockets( MiniServerSockArray * out )
int option = 1; int option = 1;
struct in_addr addr; struct in_addr addr;
CLIENTONLY( if( ( ssdpReqSock = socket( AF_INET, SOCK_DGRAM, 0 ) ) CLIENTONLY(
== 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__,
"Error in socket operation !!!\n" ); "Error in socket operation !!!\n" );
return UPNP_E_OUTOF_SOCKET;}
setsockopt( ssdpReqSock,
IPPROTO_IP,
IP_MULTICAST_TTL, &ttl, sizeof( ttl ) );
// just do it, regardless if fails or not.
Make_Socket_NoBlocking( ssdpReqSock ); gSsdpReqSocket = ssdpReqSock; ) //CLIENTONLY
if( ( ssdpSock = socket( AF_INET, SOCK_DGRAM, 0 ) )
== UPNP_INVALID_SOCKET ) {
UpnpPrintf( UPNP_CRITICAL,
SSDP, __FILE__, __LINE__,
"Error in socket operation !!!\n" );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
return UPNP_E_OUTOF_SOCKET; return UPNP_E_OUTOF_SOCKET;
} }
setsockopt( ssdpReqSock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof( ttl ) );
// just do it, regardless if fails or not.
Make_Socket_NoBlocking( ssdpReqSock );
gSsdpReqSocket = ssdpReqSock; )
// END CLIENTONLY
if( ( ssdpSock = socket( AF_INET, SOCK_DGRAM, 0 ) ) == UPNP_INVALID_SOCKET ) {
UpnpPrintf( UPNP_CRITICAL,
SSDP, __FILE__, __LINE__,
"Error in socket operation !!!\n" );
CLIENTONLY( shutdown( ssdpReqSock, SD_BOTH ) );
CLIENTONLY( UpnpCloseSocket( ssdpReqSock ) );
return UPNP_E_OUTOF_SOCKET;
}
onOff = 1; onOff = 1;
if( setsockopt( ssdpSock, SOL_SOCKET, SO_REUSEADDR, if( setsockopt( ssdpSock, SOL_SOCKET, SO_REUSEADDR,
( char * )&onOff, sizeof( onOff ) ) != 0 ) { ( char * )&onOff, sizeof( onOff ) ) != 0 ) {
UpnpPrintf( UPNP_CRITICAL, UpnpPrintf( UPNP_CRITICAL,
SSDP, __FILE__, __LINE__, SSDP, __FILE__, __LINE__,
"Error in set reuse addr !!!\n" ); "Error in set reuse addr !!!\n" );
@@ -916,8 +918,7 @@ get_ssdp_sockets( MiniServerSockArray * out )
#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" );
@@ -934,9 +935,8 @@ get_ssdp_sockets( MiniServerSockArray * out )
// ssdpAddr.sin_addr.s_addr = inet_addr(LOCAL_HOST); // ssdpAddr.sin_addr.s_addr = inet_addr(LOCAL_HOST);
ssdpAddr.sin_addr.s_addr = htonl( INADDR_ANY ); ssdpAddr.sin_addr.s_addr = htonl( INADDR_ANY );
ssdpAddr.sin_port = htons( SSDP_PORT ); ssdpAddr.sin_port = htons( SSDP_PORT );
if( bind if( bind( ssdpSock, ( struct sockaddr * )&ssdpAddr,
( ssdpSock, ( struct sockaddr * )&ssdpAddr, sizeof( ssdpAddr ) ) != 0 ) {
sizeof( ssdpAddr ) ) != 0 ) {
UpnpPrintf( UPNP_CRITICAL, UpnpPrintf( UPNP_CRITICAL,
SSDP, __FILE__, __LINE__, SSDP, __FILE__, __LINE__,
"Error in binding !!!\n" ); "Error in binding !!!\n" );
@@ -951,8 +951,7 @@ get_ssdp_sockets( MiniServerSockArray * out )
ssdpMcastAddr.imr_interface.s_addr = inet_addr( LOCAL_HOST ); ssdpMcastAddr.imr_interface.s_addr = inet_addr( LOCAL_HOST );
ssdpMcastAddr.imr_multiaddr.s_addr = inet_addr( SSDP_IP ); ssdpMcastAddr.imr_multiaddr.s_addr = inet_addr( SSDP_IP );
if( setsockopt( ssdpSock, IPPROTO_IP, IP_ADD_MEMBERSHIP, if( setsockopt( ssdpSock, IPPROTO_IP, IP_ADD_MEMBERSHIP,
( char * )&ssdpMcastAddr, ( char * )&ssdpMcastAddr, sizeof( struct ip_mreq ) ) != 0 ) {
sizeof( struct ip_mreq ) ) != 0 ) {
UpnpPrintf( UPNP_CRITICAL, UpnpPrintf( UPNP_CRITICAL,
SSDP, __FILE__, __LINE__, SSDP, __FILE__, __LINE__,
"Error in joining" " multicast group !!!\n" ); "Error in joining" " multicast group !!!\n" );
@@ -966,8 +965,8 @@ get_ssdp_sockets( MiniServerSockArray * out )
/* Set multicast interface. */ /* Set multicast interface. */
memset( ( void * )&addr, 0, sizeof( struct in_addr )); memset( ( void * )&addr, 0, sizeof( struct in_addr ));
addr.s_addr = inet_addr(LOCAL_HOST); addr.s_addr = inet_addr(LOCAL_HOST);
if (setsockopt(ssdpSock, IPPROTO_IP, IP_MULTICAST_IF, if ( setsockopt(ssdpSock, IPPROTO_IP, IP_MULTICAST_IF,
(char *)&addr, sizeof addr) != 0) { (char *)&addr, sizeof addr) != 0) {
UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__,
"Couldn't set multicast interface.\n" ); "Couldn't set multicast interface.\n" );
/* This is probably not a critical error, so let's continue. */ /* This is probably not a critical error, so let's continue. */
@@ -977,7 +976,7 @@ get_ssdp_sockets( MiniServerSockArray * out )
setsockopt( ssdpSock, IPPROTO_IP, setsockopt( ssdpSock, IPPROTO_IP,
IP_MULTICAST_TTL, &ttl, sizeof( ttl ) ); IP_MULTICAST_TTL, &ttl, sizeof( ttl ) );
if( setsockopt( ssdpSock, SOL_SOCKET, SO_BROADCAST, if( setsockopt( ssdpSock, SOL_SOCKET, SO_BROADCAST,
( char * )&option, sizeof( option ) ) != 0 ) { (char *)&option, sizeof(option) ) != 0) {
UpnpPrintf( UPNP_CRITICAL, UpnpPrintf( UPNP_CRITICAL,
SSDP, __FILE__, __LINE__, SSDP, __FILE__, __LINE__,
"Error in setting broadcast !!!\n" ); "Error in setting broadcast !!!\n" );
@@ -988,10 +987,10 @@ get_ssdp_sockets( MiniServerSockArray * out )
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