Doxygenation of SSDP library.

This commit is contained in:
Marcelo Roberto Jimenez 2010-12-19 13:30:32 -02:00
parent 6d7b3e65f8
commit d6f1b5de59
8 changed files with 1500 additions and 1982 deletions

View File

@ -1,3 +1,6 @@
#ifndef UPNP_H
#define UPNP_H
/*******************************************************************************
*
* Copyright (c) 2000-2003 Intel Corporation
@ -29,11 +32,6 @@
*
******************************************************************************/
#ifndef UPNP_H
#define UPNP_H
/*!
* \file
*
@ -42,13 +40,11 @@
* @{
*/
#include "ixml.h"
#include "upnpconfig.h"
#include "UpnpGlobal.h"
#include "UpnpInet.h"
/*
* \todo Document the exact reason of these include files and solve this
* include mess in an include file like UpnpTime.h
@ -61,14 +57,12 @@
/* Other systems ??? */
#endif
#ifdef WIN32
/* Do not #include <sys/param.h> */
#else
#include <sys/param.h>
#endif
#define LINE_SIZE 180
#define NAME_SIZE 256
#define MNFT_NAME_SIZE 64
@ -79,7 +73,6 @@
#define UPNP_USING_CHUNKED -3
#define UPNP_UNTIL_CLOSE -4
/*!
* \name Error codes
*
@ -421,7 +414,6 @@
#include "StateVarRequest.h"
#include "SubscriptionRequest.h"
/*!
* \name Constants and Types
*

View File

@ -60,7 +60,6 @@
#define fseeko fseek
#else
#include <arpa/inet.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
@ -84,78 +83,17 @@ const int CHUNK_TAIL_SIZE = 10;
/* in seconds */
#define DEFAULT_TCP_CONNECT_TIMEOUT 5
/************************************************************************
* Function : Make_Socket_NoBlocking
/*!
* \brief Checks socket connection and wait if it is not connected.
* It should be called just after connect.
*
* Parameters:
* IN int sock: socket
*
* Description:
* This function makes socket non-blocking.
*
* Returns: int
* 0 if successful else -1
***************************************************************************/
static int Make_Socket_NoBlocking(SOCKET sock)
{
#ifdef WIN32
u_long val = 1;
return ioctlsocket(sock, FIONBIO, &val);
#else
int val;
val = fcntl(sock, F_GETFL, 0);
if (fcntl(sock, F_SETFL, val | O_NONBLOCK) == -1) {
return -1;
}
#endif
return 0;
}
/************************************************************************
* Function : Make_Socket_Blocking
*
* Parameters:
* IN int sock: socket
*
* Description:
* This function makes socket blocking.
*
* Returns: int
* 0 if successful else -1
***************************************************************************/
static int Make_Socket_Blocking(int sock)
{
#ifdef WIN32
u_long val = 0;
return ioctlsocket(sock, FIONBIO, &val);
#else
int val;
val = fcntl(sock, F_GETFL, 0);
if (fcntl(sock, F_SETFL, val & ~O_NONBLOCK) == -1) {
return -1;
}
#endif
return 0;
}
/************************************************************************
* Function : Check_Connect_And_Wait_Connection
*
* Parameters:
* IN int sock: socket
* IN int connect_res: result of connect
*
* Description:
* This function checks socket connection and wait if it is not connected
* It should be called just after connect
*
* Returns: int
* 0 if successful else -1
***************************************************************************/
static int Check_Connect_And_Wait_Connection(int sock, int connect_res)
* \return 0 if successful, else -1.
*/
static int Check_Connect_And_Wait_Connection(
/*! [in] socket. */
SOCKET sock,
/*! [in] result of connect. */
int connect_res)
{
struct timeval tmvTimeout = {DEFAULT_TCP_CONNECT_TIMEOUT, 0};
int result;
@ -210,12 +148,12 @@ static int private_connect(
socklen_t addrlen)
{
#ifndef UPNP_ENABLE_BLOCKING_TCP_CONNECTIONS
int ret = Make_Socket_NoBlocking(sockfd);
int ret = sock_make_no_blocking(sockfd);
if (ret != - 1) {
ret = connect(sockfd, serv_addr, addrlen);
ret = Check_Connect_And_Wait_Connection(sockfd, ret);
if (ret != - 1) {
ret = Make_Socket_Blocking(sockfd);
ret = sock_make_blocking(sockfd);
}
}

View File

@ -39,11 +39,12 @@
#include "sock.h"
#include "unixutil.h" /* for socklen_t, EAFNOSUPPORT */
#include "unixutil.h" /* for socklen_t, EAFNOSUPPORT */
#include "upnp.h"
#include <assert.h>
#include <errno.h>
#include <fcntl.h> /* for F_GETFL, F_SETFL, O_NONBLOCK */
#include <time.h>
#include <string.h>
@ -205,3 +206,35 @@ int sock_write(IN SOCKINFO *info, IN const char *buffer, IN int bufsize,
return sock_read_write(info, (char *)buffer, bufsize, timeoutSecs, FALSE);
}
int sock_make_blocking(SOCKET sock)
{
#ifdef WIN32
u_long val = 0;
return ioctlsocket(sock, FIONBIO, &val);
#else
int val;
val = fcntl(sock, F_GETFL, 0);
if (fcntl(sock, F_SETFL, val & ~O_NONBLOCK) == -1) {
return -1;
}
#endif
return 0;
}
int sock_make_no_blocking(SOCKET sock)
{
#ifdef WIN32
u_long val = 1;
return ioctlsocket(sock, FIONBIO, &val);
#else /* WIN32 */
int val;
val = fcntl(sock, F_GETFL, 0);
if (fcntl(sock, F_SETFL, val | O_NONBLOCK) == -1) {
return -1;
}
#endif /* WIN32 */
return 0;
}

View File

@ -34,6 +34,10 @@
/*!
* \file
*
* \defgroup Sock Network Socket Library
*
* @{
*/
#include "upnputil.h"
@ -64,6 +68,23 @@ typedef struct
#extern "C" {
#endif
/*!
* \brief Closes the socket if it is different from -1.
*
* \return -1 if an error occurred or if the socket is -1.
*/
static UPNP_INLINE int sock_close(
/*! Socket descriptor. */
SOCKET sock)
{
int ret = -1;
if (sock != -1)
ret = UpnpCloseSocket(sock);
return ret;
}
/*!
* \brief Assign the passed in socket descriptor to socket descriptor in the
* SOCKINFO structure.
@ -96,6 +117,23 @@ int sock_init_with_ip(
/*! Remote socket address. */
IN struct sockaddr *foreign_sockaddr);
/*!
* \brief Shutsdown the socket using the ShutdownMethod to indicate whether
* sends and receives on the socket will be dis-allowed.
*
* After shutting down the socket, closesocket is called to release system
* resources used by the socket calls.
*
* \return Integer:
* \li \c UPNP_E_SOCKET_ERROR on failure.
* \li \c UPNP_E_SUCCESS on success.
*/
int sock_destroy(
/*! Socket Information Object. */
INOUT SOCKINFO* info,
/*! How to shutdown the socket. Used by sockets's shutdown(). */
int ShutdownMethod);
/*!
* \brief Reads data on socket in sockinfo.
*
@ -133,42 +171,27 @@ int sock_write(
INOUT int *timeoutSecs);
/*!
* \brief Shutsdown the socket using the ShutdownMethod to indicate whether
* sends and receives on the socket will be dis-allowed.
*
* After shutting down the socket, closesocket is called to release system
* resources used by the socket calls.
*
* \return Integer:
* \li \c UPNP_E_SOCKET_ERROR on failure.
* \li \c UPNP_E_SUCCESS on success.
* \brief Make socket blocking.
*
* \return 0 if successful, -1 otherwise.
*/
int sock_destroy(
/*! Socket Information Object. */
INOUT SOCKINFO* info,
/*! How to shutdown the socket. Used by sockets's shutdown(). */
int ShutdownMethod);
int sock_make_blocking(
/* [in] socket. */
SOCKET sock);
/*!
* \brief Closes the socket if it is different from -1.
*
* \return -1 if an error occurred or if the socket is -1.
* \brief Make socket non-blocking.
*
* \return 0 if successful, -1 otherwise.
*/
static UPNP_INLINE int sock_close(
/*! Socket descriptor. */
SOCKET sock)
{
int ret = -1;
if (sock != -1) {
ret = UpnpCloseSocket(sock);
}
return ret;
}
int sock_make_no_blocking(
/* [in] socket. */
SOCKET sock);
#ifdef __cplusplus
} /* #extern "C" */
#endif
/* @} Sock Network Socket Library */
#endif /* GENLIB_NET_SOCK_H */

View File

@ -33,6 +33,10 @@
**************************************************************************/
/*!
* \defgroup SSDPlib SSDP Library
*
* @{
*
* \file
*/
@ -44,7 +48,6 @@
#include <sys/types.h>
#include <signal.h>
#include <setjmp.h>
#include <fcntl.h>
#include <errno.h>
#ifdef WIN32
@ -176,48 +179,33 @@ typedef struct
typedef int (*ParserFun)(char *, Event *);
/*!
* \brief Make ssdp socket non-blocking.
*
* \return 0 if successful, -1 otherwise.
* \name SSDP Server Functions
*
* @{
*/
int Make_Socket_NoBlocking(
/* [in] socket. */
SOCKET sock);
/*!
* \brief Handles the search request. It does the sanity checks of the
* request and then schedules a thread to send a random time reply
* (random within maximum time given by the control point to reply).
* \brief Sends SSDP advertisements, replies and shutdown messages.
*
* \return UPNP_E_SUCCESS if successful else appropriate error.
*/
#ifdef INCLUDE_DEVICE_APIS
void ssdp_handle_device_request(
/* [in] . */
http_message_t *hmsg,
/* [in] . */
struct sockaddr_storage *dest_addr);
#else
static inline void ssdp_handle_device_request(
/* [in] . */
http_message_t *hmsg,
/* [in] . */
struct sockaddr_storage *dest_addr) {}
#endif
/*!
* \brief This function handles the ssdp messages from the devices. These
* messages includes the search replies, advertisement of device coming alive
* and bye byes.
*/
void ssdp_handle_ctrlpt_msg(
/* [in] SSDP message from the device. */
http_message_t *hmsg,
/* [in] Address of the device. */
struct sockaddr_storage *dest_addr,
/* [in] timeout kept by the control point while sending search message. */
int timeout,
/* [in] Cookie stored by the control point application. This cookie will
* be returned to the control point in the callback. */
void *cookie);
int AdvertiseAndReply(
/* [in] -1 = Send shutdown, 0 = send reply, 1 = Send Advertisement. */
int AdFlag,
/* [in] Device handle. */
UpnpDevice_Handle Hnd,
/* [in] Search type for sending replies. */
enum SsdpSearchType SearchType,
/* [in] Destination address. */
struct sockaddr *DestAddr,
/* [in] Device type. */
char *DeviceType,
/* [in] Device UDN. */
char *DeviceUDN,
/* [in] Service type. */
char *ServiceType,
/* [in] Advertisement age. */
int Exp);
/*!
* \brief Fills the fields of the event structure like DeviceType, Device UDN
@ -232,24 +220,6 @@ int unique_service_name(
* function. */
SsdpEvent *Evt);
/*!
* \brief Creates the ssdp sockets. It set their option to listen for
* multicast traffic.
*
* \return UPNP_E_SUCCESS if successful else returns appropriate error.
*/
int get_ssdp_sockets(
/* [out] Array of SSDP sockets. */
MiniServerSockArray *out);
/*!
* \brief This function reads the data from the ssdp socket.
*/
void readFromSSDPSocket(
/* [in] SSDP socket. */
SOCKET socket);
/*!
* \brief This function figures out the type of the SSDP search in the in the
* request.
@ -261,7 +231,6 @@ enum SsdpSearchType ssdp_request_type1(
/* [in] command came in the ssdp request. */
char *cmd);
/*!
* \brief Starts filling the SSDP event structure based upon the
* request received.
@ -274,9 +243,64 @@ int ssdp_request_type(
/* [out] The event structure partially filled by this function. */
SsdpEvent *Evt);
/*!
* \brief This function reads the data from the ssdp socket.
*/
void readFromSSDPSocket(
/* [in] SSDP socket. */
SOCKET socket);
/*!
* \brief Creates the IPv4 and IPv6 ssdp sockets required by the
* control point and device operation.
*
* \return UPNP_E_SUCCESS if successful else returns appropriate error.
*/
int get_ssdp_sockets(
/* [out] Array of SSDP sockets. */
MiniServerSockArray *out);
/* @} SSDP Server Functions */
/*!
* \name SSDP Control Point Functions
*
* @{
*/
/*!
* \brief This function handles the ssdp messages from the devices. These
* messages includes the search replies, advertisement of device coming alive
* and bye byes.
*/
void ssdp_handle_ctrlpt_msg(
/* [in] SSDP message from the device. */
http_message_t *hmsg,
/* [in] Address of the device. */
struct sockaddr_storage *dest_addr,
/* [in] timeout kept by the control point while sending search message.
* Only in search reply. */
int timeout,
/* [in] Cookie stored by the control point application. This cookie will
* be returned to the control point in the callback.
* Only in search reply. */
void *cookie);
/*!
* \brief Creates and send the search request for a specific URL.
*
* This function implements the search request of the discovery phase.
* A M-SEARCH request is sent on the SSDP channel for both IPv4 and
* IPv6 addresses. The search target(ST) is required and must be one of
* the following:
* \li "ssdp:all" : Search for all devices and services.
* \li "ssdp:rootdevice" : Search for root devices only.
* \li "uuid:<device-uuid>" : Search for a particular device.
* \li "urn:schemas-upnp-org:device:<deviceType:v>"
* \li "urn:schemas-upnp-org:service:<serviceType:v>"
* \li "urn:<domain-name>:device:<deviceType:v>"
* \li "urn:<domain-name>:service:<serviceType:v>"
*
* \return 1 if successful else appropriate error.
*/
int SearchByTarget(
@ -288,6 +312,43 @@ int SearchByTarget(
* be returned to application in the callback. */
void *Cookie);
/* @} SSDP Control Point Functions */
/*!
* \name SSDP Device Functions
*
* @{
*/
/*!
* \brief Wrapper function to reply the search request coming from the
* control point.
*
* \return always return NULL
*/
void *advertiseAndReplyThread(
/* [in] Structure containing the search request. */
void *data);
/*!
* \brief Handles the search request. It does the sanity checks of the
* request and then schedules a thread to send a random time reply
* (random within maximum time given by the control point to reply).
*/
#ifdef INCLUDE_DEVICE_APIS
void ssdp_handle_device_request(
/* [in] . */
http_message_t *hmsg,
/* [in] . */
struct sockaddr_storage *dest_addr);
#else /* INCLUDE_DEVICE_APIS */
static inline void ssdp_handle_device_request(
/* [in] . */
http_message_t *hmsg,
/* [in] . */
struct sockaddr_storage *dest_addr) {}
#endif /* INCLUDE_DEVICE_APIS */
/*!
* \brief Creates the device advertisement request based on the input
* parameter, and send it to the multicast channel.
@ -308,48 +369,6 @@ int DeviceAdvertisement(
/* [in] Device address family. */
int AddressFamily);
/*!
* \brief Creates a HTTP device shutdown request packet and send it to the
* multicast channel through RequestHandler.
*
* \return UPNP_E_SUCCESS if successful else appropriate error.
*/
int DeviceShutdown(
/* [in] Device Type. */
char *DevType,
/* [in] 1 means root device. */
int RootDev,
/* [in] Device UDN. */
char *Udn,
/* [in] . */
char *_Server,
/* [in] Location URL. */
char *Location,
/* [in] Device duration in sec. */
int Duration,
/* [in] Device address family. */
int AddressFamily);
/*!
* \brief Creates the reply packet based on the input parameter, and send it
* to the client address given in its input parameter DestAddr.
*
* \return UPNP_E_SUCCESS if successful else appropriate error.
*/
int DeviceReply(
/* [in] destination IP address. */
struct sockaddr *DestAddr,
/* [in] Device type. */
char *DevType,
/* [in] 1 means root device 0 means embedded device. */
int RootDev,
/* [in] Device UDN. */
char *Udn,
/* [in] Location of Device description document. */
char *Location,
/* [in] Life time of this device. */
int Duration);
/*!
* \brief Creates the reply packet based on the input parameter, and send it
* to the client addesss given in its input parameter DestAddr.
@ -372,6 +391,26 @@ int SendReply(
/* [in] . */
int ByType );
/*!
* \brief Creates the reply packet based on the input parameter, and send it
* to the client address given in its input parameter DestAddr.
*
* \return UPNP_E_SUCCESS if successful else appropriate error.
*/
int DeviceReply(
/* [in] destination IP address. */
struct sockaddr *DestAddr,
/* [in] Device type. */
char *DevType,
/* [in] 1 means root device 0 means embedded device. */
int RootDev,
/* [in] Device UDN. */
char *Udn,
/* [in] Location of Device description document. */
char *Location,
/* [in] Life time of this device. */
int Duration);
/*!
* \brief Creates the advertisement packet based on the input parameter,
* and send it to the multicast channel.
@ -427,36 +466,29 @@ int ServiceShutdown(
int AddressFamily);
/*!
* \brief Wrapper function to reply the search request coming from the
* control point.
*
* \return always return NULL
*/
void *advertiseAndReplyThread(
/* [in] Structure containing the search request. */
void *data);
/*!
* \brief Sends SSDP advertisements, replies and shutdown messages.
* \brief Creates a HTTP device shutdown request packet and send it to the
* multicast channel through RequestHandler.
*
* \return UPNP_E_SUCCESS if successful else appropriate error.
*/
int AdvertiseAndReply(
/* [in] -1 = Send shutdown, 0 = send reply, 1 = Send Advertisement. */
int AdFlag,
/* [in] Device handle. */
UpnpDevice_Handle Hnd,
/* [in] Search type for sending replies. */
enum SsdpSearchType SearchType,
/* [in] Destination address. */
struct sockaddr *DestAddr,
/* [in] Device type. */
char *DeviceType,
int DeviceShutdown(
/* [in] Device Type. */
char *DevType,
/* [in] 1 means root device. */
int RootDev,
/* [in] Device UDN. */
char *DeviceUDN,
/* [in] Service type. */
char *ServiceType,
/* [in] Advertisement age. */
int Exp);
char *Udn,
/* [in] . */
char *_Server,
/* [in] Location URL. */
char *Location,
/* [in] Device duration in sec. */
int Duration,
/* [in] Device address family. */
int AddressFamily);
/* @} SSDP Device Functions */
/* @} SSDPlib SSDP Library */
#endif /* SSDPLIB_H */

View File

@ -29,6 +29,14 @@
*
**************************************************************************/
/*!
* \addtogroup SSDPlib
*
* @{
*
* \file
*/
#include "config.h"
#include "upnputil.h"
@ -49,23 +57,16 @@
#include <stdio.h>
#ifdef WIN32
#include <string.h>
#include <string.h>
#endif /* WIN32 */
/************************************************************************
* Function: send_search_result
*
* Parameters:
* IN void *data: Search reply from the device
*
* Description:
* This function sends a callback to the control point application with
* a SEARCH result
*
* Returns: void
*
***************************************************************************/
void send_search_result(IN void *data)
/*!
* \brief Sends a callback to the control point application with a SEARCH
* result.
*/
static void send_search_result(
/* [in] Search reply from the device. */
IN void *data)
{
SSDPResultData *temp = (SSDPResultData *)data;
@ -73,37 +74,8 @@ void send_search_result(IN void *data)
SSDPResultData_delete(temp);
}
/************************************************************************
* Function: ssdp_handle_ctrlpt_msg
*
* Parameters:
* IN http_message_t *hmsg:
* SSDP message from the device
* IN struct sockaddr *dest_addr:
* Address of the device
* IN int timeout:
* timeout kept by the control point while
* sending search message
* IN void* cookie:
* Cookie stored by the control point application.
* This cookie will be returned to the control point
* in the callback
*
* Description:
* This function handles the ssdp messages from the devices. These
* messages includes the search replies, advertisement of device coming
* alive and bye byes.
*
* Returns: void
*
***************************************************************************/
void ssdp_handle_ctrlpt_msg(
IN http_message_t *hmsg,
IN struct sockaddr_storage *dest_addr,
/* only in search reply */
IN int timeout,
/* only in search reply */
IN void *cookie)
void ssdp_handle_ctrlpt_msg(http_message_t *hmsg, struct sockaddr_storage *dest_addr,
int timeout, void *cookie)
{
int handle;
struct Handle_Info *ctrlpt_info = NULL;
@ -279,23 +251,27 @@ void ssdp_handle_ctrlpt_msg(
break;
case SSDP_DEVICEUDN:
matched = !strncmp(searchArg->searchTarget,
hdr_value.buf, hdr_value.length);
hdr_value.buf,
hdr_value.length);
break;
case SSDP_DEVICETYPE:{
size_t m = min(hdr_value.length,
strlen(searchArg->
searchTarget));
matched = !strncmp(searchArg->searchTarget,
hdr_value.buf, m);
break;
}
size_t m = min(hdr_value.length,
strlen
(searchArg->searchTarget));
matched =
!strncmp(searchArg->searchTarget,
hdr_value.buf, m);
break;
}
case SSDP_SERVICE:{
size_t m = min(hdr_value.length,
strlen(searchArg->searchTarget));
matched = !(strncmp(searchArg->searchTarget,
hdr_value.buf, m));
break;
}
size_t m = min(hdr_value.length,
strlen
(searchArg->searchTarget));
matched =
!strncmp(searchArg->searchTarget,
hdr_value.buf, m);
break;
}
default:
matched = 0;
break;
@ -311,8 +287,7 @@ void ssdp_handle_ctrlpt_msg(
cookie);
SSDPResultData_set_CtrlptCallback
(threadData, ctrlpt_callback);
TPJobInit(&job,
(start_routine)
TPJobInit(&job, (start_routine)
send_search_result,
threadData);
TPJobSetPriority(&job, MED_PRIORITY);
@ -334,60 +309,57 @@ end_ssdp_handle_ctrlpt_msg:
UpnpDiscovery_delete(param);
}
/************************************************************************
* Function : CreateClientRequestPacket
*
* Parameters:
* IN char * RqstBuf:Output string in HTTP format.
* IN char *SearchTarget:Search Target
* IN int Mx dest_addr: Number of seconds to wait to
* collect all the responses
* IN int AddressFamily: search address family
*
* Description:
* This function creates a HTTP search request packet
* depending on the input parameter.
*
* Returns: void
*
***************************************************************************/
static void
CreateClientRequestPacket( IN char *RqstBuf,
IN int Mx,
IN char *SearchTarget,
IN int AddressFamily )
/*!
* \brief Creates a HTTP search request packet depending on the input
* parameter.
*/
static void CreateClientRequestPacket(
/*! [in] Output string in HTTP format. */
IN char *RqstBuf,
/*! [in] Search Target. */
IN int Mx,
/*! [in] Number of seconds to wait to collect all the responses. */
IN char *SearchTarget,
/*! [in] search address family. */
IN int AddressFamily)
{
char TempBuf[COMMAND_LEN];
char TempBuf[COMMAND_LEN];
strcpy( RqstBuf, "M-SEARCH * HTTP/1.1\r\n" );
strcpy(RqstBuf, "M-SEARCH * HTTP/1.1\r\n");
if (AddressFamily == AF_INET) {
sprintf( TempBuf, "HOST: %s:%d\r\n", SSDP_IP, SSDP_PORT );
} else if (AddressFamily == AF_INET6) {
sprintf( TempBuf, "HOST: [%s]:%d\r\n", SSDP_IPV6_LINKLOCAL, SSDP_PORT );
}
strcat( RqstBuf, TempBuf );
strcat( RqstBuf, "MAN: \"ssdp:discover\"\r\n" );
if (AddressFamily == AF_INET) {
sprintf(TempBuf, "HOST: %s:%d\r\n", SSDP_IP, SSDP_PORT);
} else if (AddressFamily == AF_INET6) {
sprintf(TempBuf, "HOST: [%s]:%d\r\n", SSDP_IPV6_LINKLOCAL,
SSDP_PORT);
}
strcat(RqstBuf, TempBuf);
strcat(RqstBuf, "MAN: \"ssdp:discover\"\r\n");
if( Mx > 0 ) {
sprintf( TempBuf, "MX: %d\r\n", Mx );
strcat( RqstBuf, TempBuf );
}
if (Mx > 0) {
sprintf(TempBuf, "MX: %d\r\n", Mx);
strcat(RqstBuf, TempBuf);
}
if( SearchTarget != NULL ) {
sprintf( TempBuf, "ST: %s\r\n", SearchTarget );
strcat( RqstBuf, TempBuf );
}
strcat( RqstBuf, "\r\n" );
if (SearchTarget != NULL) {
sprintf(TempBuf, "ST: %s\r\n", SearchTarget);
strcat(RqstBuf, TempBuf);
}
strcat(RqstBuf, "\r\n");
}
/*!
* \brief
*/
static void CreateClientRequestPacketUlaGua(
IN char *RqstBuf,
IN int Mx,
IN char *SearchTarget,
IN int AddressFamily)
/*! [in] . */
char *RqstBuf,
/*! [in] . */
int Mx,
/*! [in] . */
char *SearchTarget,
/*! [in] . */
int AddressFamily)
{
char TempBuf[COMMAND_LEN];
@ -395,7 +367,8 @@ static void CreateClientRequestPacketUlaGua(
if (AddressFamily == AF_INET) {
sprintf(TempBuf, "HOST: %s:%d\r\n", SSDP_IP, SSDP_PORT);
} else if (AddressFamily == AF_INET6) {
sprintf(TempBuf, "HOST: [%s]:%d\r\n", SSDP_IPV6_SITELOCAL, SSDP_PORT);
sprintf(TempBuf, "HOST: [%s]:%d\r\n", SSDP_IPV6_SITELOCAL,
SSDP_PORT);
}
strcat(RqstBuf, TempBuf);
strcat(RqstBuf, "MAN: \"ssdp:discover\"\r\n");
@ -410,94 +383,58 @@ static void CreateClientRequestPacketUlaGua(
strcat(RqstBuf, "\r\n");
}
/************************************************************************
* Function : searchExpired
*
* Parameters:
* IN void * arg:
*
* Description:
* This function
*
* Returns: void
*
***************************************************************************/
void searchExpired(void *arg)
/*!
* \brief
*/
static void searchExpired(
/* [in] . */
void *arg)
{
int *id = (int *)arg;
int handle = -1;
struct Handle_Info *ctrlpt_info = NULL;
int *id = (int *)arg;
int handle = -1;
struct Handle_Info *ctrlpt_info = NULL;
/* remove search Target from list and call client back */
ListNode *node = NULL;
SsdpSearchArg *item;
Upnp_FunPtr ctrlpt_callback;
void *cookie = NULL;
int found = 0;
/* remove search Target from list and call client back */
ListNode *node = NULL;
SsdpSearchArg *item;
Upnp_FunPtr ctrlpt_callback;
void *cookie = NULL;
int found = 0;
HandleLock();
HandleLock();
/* remove search target from search list */
if( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) {
free( id );
HandleUnlock();
return;
}
ctrlpt_callback = ctrlpt_info->Callback;
node = ListHead( &ctrlpt_info->SsdpSearchList );
while( node != NULL ) {
item = ( SsdpSearchArg * ) node->item;
if( item->timeoutEventId == ( *id ) ) {
free( item->searchTarget );
cookie = item->cookie;
found = 1;
item->searchTarget = NULL;
free( item );
ListDelNode( &ctrlpt_info->SsdpSearchList, node, 0 );
break;
}
node = ListNext( &ctrlpt_info->SsdpSearchList, node );
}
HandleUnlock();
/* remove search target from search list */
if (GetClientHandleInfo(&handle, &ctrlpt_info) != HND_CLIENT) {
free(id);
HandleUnlock();
return;
}
ctrlpt_callback = ctrlpt_info->Callback;
node = ListHead(&ctrlpt_info->SsdpSearchList);
while (node != NULL) {
item = (SsdpSearchArg *) node->item;
if (item->timeoutEventId == (*id)) {
free(item->searchTarget);
cookie = item->cookie;
found = 1;
item->searchTarget = NULL;
free(item);
ListDelNode(&ctrlpt_info->SsdpSearchList, node, 0);
break;
}
node = ListNext(&ctrlpt_info->SsdpSearchList, node);
}
HandleUnlock();
if( found ) {
ctrlpt_callback( UPNP_DISCOVERY_SEARCH_TIMEOUT, NULL, cookie );
}
if (found) {
ctrlpt_callback(UPNP_DISCOVERY_SEARCH_TIMEOUT, NULL, cookie);
}
free( id );
free(id);
}
/************************************************************************
* Function : SearchByTarget
*
* Parameters:
* IN int Mx:Number of seconds to wait, to collect all the responses.
* IN char *St: Search target.
* IN void *Cookie: cookie provided by control point application.
* This cokie will be returned to application in the callback.
*
* Description:
* This function implements the search request of the discovery phase.
* A M-SEARCH request is sent on the SSDP channel for both IPv4 and
* IPv6 addresses. The search target(ST) is required and must be one of
* the following:
* - "ssdp:all" : Search for all devices and services.
* - "ssdp:rootdevice" : Search for root devices only.
* - "uuid:<device-uuid>" : Search for a particular device.
* - "urn:schemas-upnp-org:device:<deviceType:v>"
* - "urn:schemas-upnp-org:service:<serviceType:v>"
* - "urn:<domain-name>:device:<deviceType:v>"
* - "urn:<domain-name>:service:<serviceType:v>"
*
* Returns: int
* 1 if successful else appropriate error
***************************************************************************/
int SearchByTarget(
IN int Mx,
IN char *St,
IN void *Cookie)
int SearchByTarget(int Mx, char *St, void *Cookie)
{
char errorBuffer[ERROR_BUFFER_LEN];
int *id = NULL;
@ -507,8 +444,8 @@ int SearchByTarget(
char ReqBufv6UlaGua[BUFSIZE];
struct sockaddr_storage __ss_v4;
struct sockaddr_storage __ss_v6;
struct sockaddr_in* destAddr4 = (struct sockaddr_in*)&__ss_v4;
struct sockaddr_in6* destAddr6 = (struct sockaddr_in6*)&__ss_v6;
struct sockaddr_in *destAddr4 = (struct sockaddr_in *)&__ss_v4;
struct sockaddr_in6 *destAddr6 = (struct sockaddr_in6 *)&__ss_v6;
fd_set wrSet;
SsdpSearchArg *newArg = NULL;
int timeTillRead = 0;
@ -518,7 +455,7 @@ int SearchByTarget(
unsigned long addrv4 = inet_addr(gIF_IPV4);
int max_fd = 0;
/*ThreadData *ThData;*/
/*ThreadData *ThData; */
ThreadPoolJob job;
requestType = ssdp_request_type1(St);
@ -526,7 +463,8 @@ int SearchByTarget(
return UPNP_E_INVALID_PARAM;
}
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__, "Inside SearchByTarget\n");
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
"Inside SearchByTarget\n");
timeTillRead = Mx;
if (timeTillRead < MIN_SEARCH_TIME) {
@ -537,7 +475,8 @@ int SearchByTarget(
CreateClientRequestPacket(ReqBufv4, timeTillRead, St, AF_INET);
CreateClientRequestPacket(ReqBufv6, timeTillRead, St, AF_INET6);
CreateClientRequestPacketUlaGua(ReqBufv6UlaGua, timeTillRead, St, AF_INET6);
CreateClientRequestPacketUlaGua(ReqBufv6UlaGua, timeTillRead, St,
AF_INET6);
memset(&__ss_v4, 0, sizeof(__ss_v4));
destAddr4->sin_family = AF_INET;
@ -558,19 +497,19 @@ int SearchByTarget(
return UPNP_E_INTERNAL_ERROR;
}
newArg = (SsdpSearchArg *)malloc(sizeof(SsdpSearchArg));
newArg = (SsdpSearchArg *) malloc(sizeof(SsdpSearchArg));
newArg->searchTarget = strdup(St);
newArg->cookie = Cookie;
newArg->requestType = requestType;
id = (int *)malloc(sizeof(int));
TPJobInit(&job, (start_routine)searchExpired, id);
TPJobInit(&job, (start_routine) searchExpired, id);
TPJobSetPriority(&job, MED_PRIORITY);
TPJobSetFreeFunction(&job, (free_routine)free);
TPJobSetFreeFunction(&job, (free_routine) free);
/* Schedule a timeout event to remove search Arg */
TimerThreadSchedule(&gTimerThread, timeTillRead,
REL_SEC, &job, SHORT_TERM, id);
REL_SEC, &job, SHORT_TERM, id);
newArg->timeoutEventId = *id;
ListAddTail(&ctrlpt_info->SsdpSearchList, newArg);
@ -580,14 +519,14 @@ int SearchByTarget(
FD_ZERO(&wrSet);
if (gSsdpReqSocket4 != INVALID_SOCKET) {
setsockopt(gSsdpReqSocket4, IPPROTO_IP, IP_MULTICAST_IF,
(char *)&addrv4, sizeof (addrv4));
(char *)&addrv4, sizeof(addrv4));
FD_SET(gSsdpReqSocket4, &wrSet);
max_fd = max(max_fd, gSsdpReqSocket4);
}
#ifdef UPNP_ENABLE_IPV6
if (gSsdpReqSocket6 != INVALID_SOCKET) {
setsockopt(gSsdpReqSocket6, IPPROTO_IPV6, IPV6_MULTICAST_IF,
(char *)&gIF_INDEX, sizeof (gIF_INDEX));
(char *)&gIF_INDEX, sizeof(gIF_INDEX));
FD_SET(gSsdpReqSocket6, &wrSet);
max_fd = max(max_fd, gSsdpReqSocket6);
}
@ -597,8 +536,7 @@ int SearchByTarget(
if (ret == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
"SSDP_LIB: Error in select(): %s\n",
errorBuffer);
"SSDP_LIB: Error in select(): %s\n", errorBuffer);
shutdown(gSsdpReqSocket4, SD_BOTH);
UpnpCloseSocket(gSsdpReqSocket4);
#ifdef UPNP_ENABLE_IPV6
@ -608,53 +546,53 @@ int SearchByTarget(
return UPNP_E_INTERNAL_ERROR;
}
#ifdef UPNP_ENABLE_IPV6
if (gSsdpReqSocket6 != INVALID_SOCKET &&
if (gSsdpReqSocket6 != INVALID_SOCKET &&
FD_ISSET(gSsdpReqSocket6, &wrSet)) {
int NumCopy = 0;
while (NumCopy < NUM_SSDP_COPY) {
sendto(gSsdpReqSocket6,
ReqBufv6UlaGua, strlen(ReqBufv6UlaGua), 0,
(struct sockaddr *)&__ss_v6,
sizeof(struct sockaddr_in));
ReqBufv6UlaGua, strlen(ReqBufv6UlaGua), 0,
(struct sockaddr *)&__ss_v6,
sizeof(struct sockaddr_in));
NumCopy++;
imillisleep(SSDP_PAUSE);
}
NumCopy = 0;
inet_pton(AF_INET6, SSDP_IPV6_LINKLOCAL, &destAddr6->sin6_addr);
while (NumCopy < NUM_SSDP_COPY) {
UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__,
">>> SSDP SEND M-SEARCH >>>\n%s\n",
ReqBufv6);
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
">>> SSDP SEND M-SEARCH >>>\n%s\n",
ReqBufv6);
sendto(gSsdpReqSocket6,
ReqBufv6, strlen(ReqBufv6), 0,
(struct sockaddr *)&__ss_v6,
sizeof(struct sockaddr_in6));
ReqBufv6, strlen(ReqBufv6), 0,
(struct sockaddr *)&__ss_v6,
sizeof(struct sockaddr_in6));
NumCopy++;
imillisleep(SSDP_PAUSE);
}
}
#endif /* IPv6 */
#endif /* IPv6 */
if (gSsdpReqSocket4 != INVALID_SOCKET &&
if (gSsdpReqSocket4 != INVALID_SOCKET &&
FD_ISSET(gSsdpReqSocket4, &wrSet)) {
int NumCopy = 0;
while (NumCopy < NUM_SSDP_COPY) {
UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__,
">>> SSDP SEND M-SEARCH >>>\n%s\n",
ReqBufv4);
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
">>> SSDP SEND M-SEARCH >>>\n%s\n",
ReqBufv4);
sendto(gSsdpReqSocket4,
ReqBufv4, strlen(ReqBufv4), 0,
(struct sockaddr *)&__ss_v4,
sizeof(struct sockaddr_in));
ReqBufv4, strlen(ReqBufv4), 0,
(struct sockaddr *)&__ss_v4,
sizeof(struct sockaddr_in));
NumCopy++;
imillisleep(SSDP_PAUSE);
}
}
}
return 1;
}
#endif /* EXCLUDE_SSDP */
#endif /* INCLUDE_CLIENT_APIS */
/* @} SSDPlib */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff