Doxygenation of SSDP library.
This commit is contained in:
parent
704dca3df1
commit
04d64a893b
@ -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
|
||||
*
|
||||
@ -423,7 +416,6 @@
|
||||
#include "SubscriptionRequest.h"
|
||||
#endif /* UPNP_VERSION >= 10800 */
|
||||
|
||||
|
||||
/*!
|
||||
* \name Constants and Types
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h> /* for F_GETFL, F_SETFL, O_NONBLOCK */
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -207,3 +208,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;
|
||||
}
|
||||
|
@ -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.
|
||||
* \brief Make socket blocking.
|
||||
*
|
||||
* 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.
|
||||
* \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.
|
||||
* \brief Make socket non-blocking.
|
||||
*
|
||||
* \return -1 if an error occurred or if the socket is -1.
|
||||
* \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 */
|
||||
|
@ -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
|
||||
@ -184,48 +187,33 @@ typedef struct
|
||||
typedef int (*ParserFun)(char *, Event *);
|
||||
|
||||
/*!
|
||||
* \brief Make ssdp socket non-blocking.
|
||||
* \name SSDP Server Functions
|
||||
*
|
||||
* \return 0 if successful, -1 otherwise.
|
||||
* @{
|
||||
*/
|
||||
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 *dest_addr);
|
||||
#else
|
||||
static inline void ssdp_handle_device_request(
|
||||
/* [in] . */
|
||||
http_message_t *hmsg,
|
||||
/* [in] . */
|
||||
struct sockaddr* 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 *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
|
||||
@ -240,24 +228,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.
|
||||
@ -269,7 +239,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.
|
||||
@ -282,9 +251,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 *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(
|
||||
@ -296,6 +320,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 *dest_addr);
|
||||
#else /* INCLUDE_DEVICE_APIS */
|
||||
static inline void ssdp_handle_device_request(
|
||||
/* [in] . */
|
||||
http_message_t *hmsg,
|
||||
/* [in] . */
|
||||
struct sockaddr* dest_addr) {}
|
||||
#endif /* INCLUDE_DEVICE_APIS */
|
||||
|
||||
/*!
|
||||
* \brief Creates the device advertisement request based on the input
|
||||
* parameter, and send it to the multicast channel.
|
||||
@ -316,48 +377,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.
|
||||
@ -380,6 +399,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.
|
||||
@ -435,36 +474,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 */
|
||||
|
@ -29,6 +29,14 @@
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
/*!
|
||||
* \addtogroup SSDPlib
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "upnputil.h"
|
||||
@ -52,58 +60,23 @@
|
||||
#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)
|
||||
{
|
||||
ResultData *temp = (ResultData *) data;
|
||||
|
||||
temp->ctrlpt_callback(UPNP_DISCOVERY_SEARCH_RESULT, &temp->param, temp->cookie);
|
||||
temp->ctrlpt_callback(UPNP_DISCOVERY_SEARCH_RESULT, &temp->param,
|
||||
temp->cookie);
|
||||
free(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 *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 *dest_addr,
|
||||
int timeout, void *cookie)
|
||||
{
|
||||
int handle;
|
||||
struct Handle_Info *ctrlpt_info = NULL;
|
||||
@ -277,17 +250,19 @@ void ssdp_handle_ctrlpt_msg(
|
||||
break;
|
||||
case SSDP_DEVICETYPE:{
|
||||
size_t m = min(hdr_value.length,
|
||||
strlen(searchArg->
|
||||
searchTarget));
|
||||
matched = !strncmp(searchArg->searchTarget,
|
||||
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,
|
||||
strlen
|
||||
(searchArg->searchTarget));
|
||||
matched =
|
||||
!strncmp(searchArg->searchTarget,
|
||||
hdr_value.buf, m);
|
||||
break;
|
||||
}
|
||||
@ -304,8 +279,7 @@ void ssdp_handle_ctrlpt_msg(
|
||||
threadData->cookie = searchArg->cookie;
|
||||
threadData->ctrlpt_callback =
|
||||
ctrlpt_callback;
|
||||
TPJobInit(&job,
|
||||
(start_routine)
|
||||
TPJobInit(&job, (start_routine)
|
||||
send_search_result,
|
||||
threadData);
|
||||
TPJobSetPriority(&job, MED_PRIORITY);
|
||||
@ -324,28 +298,18 @@ void ssdp_handle_ctrlpt_msg(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* 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,
|
||||
/*!
|
||||
* \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];
|
||||
@ -355,7 +319,8 @@ CreateClientRequestPacket( IN char *RqstBuf,
|
||||
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 );
|
||||
sprintf(TempBuf, "HOST: [%s]:%d\r\n", SSDP_IPV6_LINKLOCAL,
|
||||
SSDP_PORT);
|
||||
}
|
||||
strcat(RqstBuf, TempBuf);
|
||||
strcat(RqstBuf, "MAN: \"ssdp:discover\"\r\n");
|
||||
@ -372,12 +337,18 @@ CreateClientRequestPacket( IN char *RqstBuf,
|
||||
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];
|
||||
|
||||
@ -385,7 +356,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");
|
||||
@ -400,20 +372,12 @@ 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;
|
||||
@ -459,35 +423,7 @@ void searchExpired(void *arg)
|
||||
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;
|
||||
@ -516,7 +452,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) {
|
||||
@ -527,7 +464,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;
|
||||
@ -587,8 +525,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
|
||||
@ -644,7 +581,7 @@ int SearchByTarget(
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* EXCLUDE_SSDP */
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
|
||||
/* @} SSDPlib */
|
||||
|
@ -29,14 +29,19 @@
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
/*!
|
||||
* \addtogroup SSDPlib
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
#ifdef INCLUDE_DEVICE_APIS
|
||||
#if EXCLUDE_SSDP == 0
|
||||
|
||||
|
||||
#include "httpparser.h"
|
||||
#include "httpreadwrite.h"
|
||||
#include "ssdplib.h"
|
||||
@ -46,32 +51,15 @@
|
||||
#include "upnpapi.h"
|
||||
#include "UpnpInet.h"
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define MSGTYPE_SHUTDOWN 0
|
||||
#define MSGTYPE_ADVERTISEMENT 1
|
||||
#define MSGTYPE_REPLY 2
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* Function : advertiseAndReplyThread
|
||||
*
|
||||
* Parameters:
|
||||
* IN void *data: Structure containing the search request
|
||||
*
|
||||
* Description:
|
||||
* This function is a wrapper function to reply the search request
|
||||
* coming from the control point.
|
||||
*
|
||||
* Returns: void *
|
||||
* always return NULL
|
||||
***************************************************************************/
|
||||
void *
|
||||
advertiseAndReplyThread( IN void *data )
|
||||
void *advertiseAndReplyThread(void *data)
|
||||
{
|
||||
SsdpSearchReply *arg = (SsdpSearchReply *) data;
|
||||
|
||||
@ -79,35 +67,16 @@ advertiseAndReplyThread( IN void *data )
|
||||
arg->event.RequestType,
|
||||
(struct sockaddr *)&arg->dest_addr,
|
||||
arg->event.DeviceType,
|
||||
arg->event.UDN,
|
||||
arg->event.ServiceType, arg->MaxAge );
|
||||
arg->event.UDN, arg->event.ServiceType, arg->MaxAge);
|
||||
free(arg);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : ssdp_handle_device_request
|
||||
*
|
||||
* Parameters:
|
||||
* IN http_message_t *hmsg: SSDP search request from the control point
|
||||
* IN struct sockaddr *dest_addr: The address info of control point
|
||||
*
|
||||
* Description:
|
||||
* This function handles the search request. It do the sanity checks of
|
||||
* the request and then schedules a thread to send a random time reply (
|
||||
* random within maximum time given by the control point to reply).
|
||||
*
|
||||
* Returns: void *
|
||||
* 1 if successful else appropriate error
|
||||
***************************************************************************/
|
||||
#ifdef INCLUDE_DEVICE_APIS
|
||||
void ssdp_handle_device_request(
|
||||
IN http_message_t *hmsg,
|
||||
IN struct sockaddr *dest_addr)
|
||||
void ssdp_handle_device_request(http_message_t *hmsg, struct sockaddr *dest_addr)
|
||||
{
|
||||
#define MX_FUDGE_FACTOR 10
|
||||
|
||||
int handle;
|
||||
struct Handle_Info *dev_info = NULL;
|
||||
memptr hdr_value;
|
||||
@ -122,28 +91,24 @@ void ssdp_handle_device_request(
|
||||
|
||||
/* check man hdr. */
|
||||
if (httpmsg_find_hdr(hmsg, HDR_MAN, &hdr_value) == NULL ||
|
||||
memptr_cmp( &hdr_value, "\"ssdp:discover\"" ) != 0 ) {
|
||||
memptr_cmp(&hdr_value, "\"ssdp:discover\"") != 0)
|
||||
/* bad or missing hdr. */
|
||||
return;
|
||||
}
|
||||
/* MX header. */
|
||||
if (httpmsg_find_hdr(hmsg, HDR_MX, &hdr_value) == NULL ||
|
||||
( mx = raw_to_int( &hdr_value, 10 ) ) < 0 ) {
|
||||
(mx = raw_to_int(&hdr_value, 10)) < 0)
|
||||
return;
|
||||
}
|
||||
/* ST header. */
|
||||
if( httpmsg_find_hdr( hmsg, HDR_ST, &hdr_value ) == NULL ) {
|
||||
if (httpmsg_find_hdr(hmsg, HDR_ST, &hdr_value) == NULL)
|
||||
return;
|
||||
}
|
||||
save_char = hdr_value.buf[hdr_value.length];
|
||||
hdr_value.buf[hdr_value.length] = '\0';
|
||||
ret_code = ssdp_request_type(hdr_value.buf, &event);
|
||||
/* restore. */
|
||||
hdr_value.buf[hdr_value.length] = save_char;
|
||||
if( ret_code == -1 ) {
|
||||
if (ret_code == -1)
|
||||
/* bad ST header. */
|
||||
return;
|
||||
}
|
||||
|
||||
HandleLock();
|
||||
/* device info. */
|
||||
@ -169,13 +134,9 @@ void ssdp_handle_device_request(
|
||||
"DeviceUuid = %s\n", event.UDN);
|
||||
UpnpPrintf(UPNP_PACKET, API, __FILE__, __LINE__,
|
||||
"ServiceType = %s\n", event.ServiceType);
|
||||
|
||||
threadArg =
|
||||
( SsdpSearchReply * ) malloc( sizeof( SsdpSearchReply ) );
|
||||
|
||||
if( threadArg == NULL ) {
|
||||
threadArg = (SsdpSearchReply *)malloc(sizeof(SsdpSearchReply));
|
||||
if (threadArg == NULL)
|
||||
return;
|
||||
}
|
||||
threadArg->handle = handle;
|
||||
memcpy(&threadArg->dest_addr, dest_addr, sizeof(threadArg->dest_addr));
|
||||
threadArg->event = event;
|
||||
@ -187,38 +148,29 @@ void ssdp_handle_device_request(
|
||||
/* Subtract a percentage from the mx to allow for network and processing
|
||||
* delays (i.e. if search is for 30 seconds, respond
|
||||
* within 0 - 27 seconds). */
|
||||
if( mx >= 2 ) {
|
||||
if (mx >= 2)
|
||||
mx -= MAXVAL(1, mx / MX_FUDGE_FACTOR);
|
||||
}
|
||||
|
||||
if( mx < 1 ) {
|
||||
if (mx < 1)
|
||||
mx = 1;
|
||||
}
|
||||
|
||||
replyTime = rand() % mx;
|
||||
|
||||
TimerThreadSchedule(&gTimerThread, replyTime, REL_SEC, &job,
|
||||
SHORT_TERM, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
/************************************************************************
|
||||
* Function : NewRequestHandler
|
||||
/*!
|
||||
* \brief Works as a request handler which passes the HTTP request string
|
||||
* to multicast channel.
|
||||
*
|
||||
* Parameters:
|
||||
* IN struct sockaddr *DestAddr: Ip address, to send the reply.
|
||||
* IN int NumPacket: Number of packet to be sent.
|
||||
* IN char **RqPacket:Number of packet to be sent.
|
||||
*
|
||||
* Description:
|
||||
* This function works as a request handler which passes the HTTP
|
||||
* request string to multicast channel then
|
||||
*
|
||||
* Returns: void *
|
||||
* 1 if successful else appropriate error
|
||||
***************************************************************************/
|
||||
static int NewRequestHandler(IN struct sockaddr *DestAddr, IN int NumPacket,
|
||||
IN char **RqPacket)
|
||||
* \return 1 if successful else appropriate error.
|
||||
*/
|
||||
static int NewRequestHandler(
|
||||
/*! [in] Ip address, to send the reply. */
|
||||
struct sockaddr *DestAddr,
|
||||
/*! [in] Number of packet to be sent. */
|
||||
int NumPacket,
|
||||
/*! [in] . */
|
||||
char **RqPacket)
|
||||
{
|
||||
char errorBuffer[ERROR_BUFFER_LEN];
|
||||
SOCKET ReplySock;
|
||||
@ -288,10 +240,12 @@ static int NewRequestHandler(IN struct sockaddr *DestAddr, IN int NumPacket,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* return 1 if an inet6 @ has been found
|
||||
/*!
|
||||
* \brief
|
||||
*
|
||||
* \return 1 if an inet6 @ has been found.
|
||||
*/
|
||||
int extractIPv6address(char *url, char *address)
|
||||
static int extractIPv6address(char *url, char *address)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
@ -324,12 +278,12 @@ exit_function:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return 1 if the Url contains an ULA or GUA IPv6 address
|
||||
* 0 otherwise
|
||||
/*!
|
||||
* \brief
|
||||
*
|
||||
* \return 1 if the Url contains an ULA or GUA IPv6 address, 0 otherwise.
|
||||
*/
|
||||
int isUrlV6UlaGua(char *descdocUrl)
|
||||
static int isUrlV6UlaGua(char *descdocUrl)
|
||||
{
|
||||
char address[INET6_ADDRSTRLEN];
|
||||
struct in6_addr v6_addr;
|
||||
@ -342,36 +296,27 @@ int isUrlV6UlaGua(char *descdocUrl)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* Function : CreateServiceRequestPacket
|
||||
*
|
||||
* Parameters:
|
||||
* IN int msg_type : type of the message ( Search Reply, Advertisement
|
||||
* or Shutdown )
|
||||
* IN char * nt : ssdp type
|
||||
* IN char * usn : unique service name ( go in the HTTP Header)
|
||||
* IN char * location :Location URL.
|
||||
* IN int duration :Service duration in sec.
|
||||
* OUT char** packet :Output buffer filled with HTTP statement.
|
||||
* IN int AddressFamily: Address family of the HTTP request.
|
||||
*
|
||||
* Description:
|
||||
* This function creates a HTTP request packet. Depending
|
||||
* on the input parameter it either creates a service advertisement
|
||||
* request or service shutdown request etc.
|
||||
*
|
||||
* Returns: void
|
||||
*
|
||||
***************************************************************************/
|
||||
/*!
|
||||
* \brief Creates a HTTP request packet. Depending on the input parameter,
|
||||
* it either creates a service advertisement request or service shutdown
|
||||
* request etc.
|
||||
*/
|
||||
static void CreateServicePacket(
|
||||
IN int msg_type,
|
||||
const IN char *nt,
|
||||
IN char *usn,
|
||||
IN char *location,
|
||||
IN int duration,
|
||||
OUT char **packet,
|
||||
IN int AddressFamily)
|
||||
/*! [in] type of the message (Search Reply, Advertisement
|
||||
* or Shutdown). */
|
||||
int msg_type,
|
||||
/*! [in] ssdp type. */
|
||||
const char *nt,
|
||||
/*! [in] unique service name ( go in the HTTP Header). */
|
||||
char *usn,
|
||||
/*! [in] Location URL. */
|
||||
char *location,
|
||||
/*! [in] Service duration in sec. */
|
||||
int duration,
|
||||
/*! [out] Output buffer filled with HTTP statement. */
|
||||
char **packet,
|
||||
/*! [in] Address family of the HTTP request. */
|
||||
int AddressFamily)
|
||||
{
|
||||
int ret_code;
|
||||
const char *nts;
|
||||
@ -383,20 +328,17 @@ static void CreateServicePacket(
|
||||
membuffer_init(&buf);
|
||||
buf.size_inc = 30;
|
||||
*packet = NULL;
|
||||
|
||||
if (msg_type == MSGTYPE_REPLY) {
|
||||
ret_code = http_MakeMessage(
|
||||
&buf, 1, 1,
|
||||
"R" "sdc" "D" "sc" "ssc" "ssc" "ssc" "S" "Xc" "ssc" "sscc",
|
||||
HTTP_OK,
|
||||
ret_code = http_MakeMessage(&buf, 1, 1,
|
||||
"R" "sdc" "D" "sc" "ssc" "ssc" "ssc"
|
||||
"S" "Xc" "ssc" "sscc", HTTP_OK,
|
||||
"CACHE-CONTROL: max-age=", duration,
|
||||
"EXT:",
|
||||
"LOCATION: ", location,
|
||||
"OPT: ", "\"http://schemas.upnp.org/upnp/1/0/\"; ns=01",
|
||||
"EXT:", "LOCATION: ", location,
|
||||
"OPT: ",
|
||||
"\"http://schemas.upnp.org/upnp/1/0/\"; ns=01",
|
||||
"01-NLS: ", gUpnpSdkNLSuuid,
|
||||
X_USER_AGENT,
|
||||
"ST: ", nt,
|
||||
"USN: ", usn);
|
||||
X_USER_AGENT, "ST: ", nt, "USN: ",
|
||||
usn);
|
||||
if (ret_code != 0) {
|
||||
return;
|
||||
}
|
||||
@ -419,19 +361,16 @@ static void CreateServicePacket(
|
||||
else
|
||||
host = "[" SSDP_IPV6_LINKLOCAL "]";
|
||||
}
|
||||
ret_code = http_MakeMessage(
|
||||
&buf, 1, 1,
|
||||
"Q" "sssdc" "sdc" "ssc" "ssc" "ssc" "ssc" "ssc" "S" "Xc" "sscc",
|
||||
ret_code = http_MakeMessage(&buf, 1, 1,
|
||||
"Q" "sssdc" "sdc" "ssc" "ssc" "ssc"
|
||||
"ssc" "ssc" "S" "Xc" "sscc",
|
||||
HTTPMETHOD_NOTIFY, "*", (size_t) 1,
|
||||
"HOST: ", host,
|
||||
":", SSDP_PORT,
|
||||
"HOST: ", host, ":", SSDP_PORT,
|
||||
"CACHE-CONTROL: max-age=", duration,
|
||||
"LOCATION: ", location,
|
||||
"OPT: ", "\"http://schemas.upnp.org/upnp/1/0/\"; ns=01",
|
||||
"01-NLS: ", gUpnpSdkNLSuuid,
|
||||
"NT: ", nt,
|
||||
"NTS: ", nts,
|
||||
X_USER_AGENT,
|
||||
"LOCATION: ", location, "OPT: ",
|
||||
"\"http://schemas.upnp.org/upnp/1/0/\"; ns=01",
|
||||
"01-NLS: ", gUpnpSdkNLSuuid, "NT: ",
|
||||
nt, "NTS: ", nts, X_USER_AGENT,
|
||||
"USN: ", usn);
|
||||
if (ret_code)
|
||||
return;
|
||||
@ -445,37 +384,12 @@ static void CreateServicePacket(
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* Function : DeviceAdvertisement
|
||||
*
|
||||
* Parameters:
|
||||
* IN char * DevType : type of the device
|
||||
* IN int RootDev: flag to indicate if the device is root device
|
||||
* IN char * nt : ssdp type
|
||||
* IN char * usn : unique service name
|
||||
* IN char * location :Location URL.
|
||||
* IN int duration :Service duration in sec.
|
||||
*
|
||||
* Description:
|
||||
* This function creates the device advertisement request based on
|
||||
* the input parameter, and send it to the multicast channel.
|
||||
*
|
||||
* Returns: int
|
||||
* UPNP_E_SUCCESS if successful else appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
DeviceAdvertisement( IN char *DevType,
|
||||
int RootDev,
|
||||
char *Udn,
|
||||
IN char *Location,
|
||||
IN int Duration,
|
||||
IN int AddressFamily)
|
||||
int DeviceAdvertisement(char *DevType, int RootDev, char *Udn, char *Location,
|
||||
int Duration, int AddressFamily)
|
||||
{
|
||||
struct sockaddr_storage __ss;
|
||||
struct sockaddr_in *DestAddr4 = (struct sockaddr_in *)&__ss;
|
||||
struct sockaddr_in6 *DestAddr6 = (struct sockaddr_in6 *)&__ss;
|
||||
|
||||
/* char Mil_Nt[LINE_SIZE] */
|
||||
char Mil_Usn[LINE_SIZE];
|
||||
char *msgs[3];
|
||||
@ -483,7 +397,6 @@ DeviceAdvertisement( IN char *DevType,
|
||||
|
||||
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
|
||||
"In function DeviceAdvertisement\n");
|
||||
|
||||
memset(&__ss, 0, sizeof(__ss));
|
||||
if (AddressFamily == AF_INET) {
|
||||
DestAddr4->sin_family = AF_INET;
|
||||
@ -492,25 +405,24 @@ DeviceAdvertisement( IN char *DevType,
|
||||
} else if (AddressFamily == AF_INET6) {
|
||||
DestAddr6->sin6_family = AF_INET6;
|
||||
inet_pton(AF_INET6,
|
||||
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : SSDP_IPV6_LINKLOCAL,
|
||||
&DestAddr6->sin6_addr );
|
||||
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL :
|
||||
SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr);
|
||||
DestAddr6->sin6_port = htons(SSDP_PORT);
|
||||
DestAddr6->sin6_scope_id = gIF_INDEX;
|
||||
} else {
|
||||
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
|
||||
"Invalid device address family.\n");
|
||||
}
|
||||
|
||||
msgs[0] = NULL;
|
||||
msgs[1] = NULL;
|
||||
msgs[2] = NULL;
|
||||
|
||||
/* If deviceis a root device , here we need to send 3 advertisement
|
||||
* or reply */
|
||||
if (RootDev) {
|
||||
sprintf(Mil_Usn, "%s::upnp:rootdevice", Udn);
|
||||
CreateServicePacket(MSGTYPE_ADVERTISEMENT, "upnp:rootdevice",
|
||||
Mil_Usn, Location, Duration, &msgs[0], AddressFamily );
|
||||
Mil_Usn, Location, Duration, &msgs[0],
|
||||
AddressFamily);
|
||||
}
|
||||
/* both root and sub-devices need to send these two messages */
|
||||
CreateServicePacket(MSGTYPE_ADVERTISEMENT, Udn, Udn,
|
||||
@ -519,8 +431,7 @@ DeviceAdvertisement( IN char *DevType,
|
||||
CreateServicePacket(MSGTYPE_ADVERTISEMENT, DevType, Mil_Usn,
|
||||
Location, Duration, &msgs[2], AddressFamily);
|
||||
/* check error */
|
||||
if( ( RootDev && msgs[0] == NULL ) ||
|
||||
msgs[1] == NULL || msgs[2] == NULL ) {
|
||||
if ((RootDev && msgs[0] == NULL) || msgs[1] == NULL || msgs[2] == NULL) {
|
||||
free(msgs[0]);
|
||||
free(msgs[1]);
|
||||
free(msgs[2]);
|
||||
@ -529,13 +440,14 @@ DeviceAdvertisement( IN char *DevType,
|
||||
/* send packets */
|
||||
if (RootDev) {
|
||||
/* send 3 msg types */
|
||||
ret_code = NewRequestHandler( (struct sockaddr*)&__ss, 3, &msgs[0] );
|
||||
} else /* sub-device */
|
||||
{
|
||||
/* send 2 msg types */
|
||||
ret_code = NewRequestHandler( (struct sockaddr*)&__ss, 2, &msgs[1] );
|
||||
}
|
||||
ret_code =
|
||||
NewRequestHandler((struct sockaddr *)&__ss, 3, &msgs[0]);
|
||||
} else { /* sub-device */
|
||||
|
||||
/* send 2 msg types */
|
||||
ret_code =
|
||||
NewRequestHandler((struct sockaddr *)&__ss, 2, &msgs[1]);
|
||||
}
|
||||
/* free msgs */
|
||||
free(msgs[0]);
|
||||
free(msgs[1]);
|
||||
@ -544,33 +456,8 @@ DeviceAdvertisement( IN char *DevType,
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : SendReply
|
||||
*
|
||||
* Parameters:
|
||||
* IN struct sockaddr * DestAddr:destination IP address.
|
||||
* IN char *DevType: Device type
|
||||
* IN int RootDev: 1 means root device 0 means embedded device.
|
||||
* IN char * Udn: Device UDN
|
||||
* IN char * Location: Location of Device description document.
|
||||
* IN int Duration :Life time of this device.
|
||||
* IN int ByType:
|
||||
*
|
||||
* Description:
|
||||
* This function creates the reply packet based on the input parameter,
|
||||
* and send it to the client addesss given in its input parameter DestAddr.
|
||||
*
|
||||
* Returns: int
|
||||
* UPNP_E_SUCCESS if successful else appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
SendReply( IN struct sockaddr *DestAddr,
|
||||
IN char *DevType,
|
||||
IN int RootDev,
|
||||
IN char *Udn,
|
||||
IN char *Location,
|
||||
IN int Duration,
|
||||
IN int ByType )
|
||||
int SendReply(struct sockaddr *DestAddr, char *DevType, int RootDev,
|
||||
char *Udn, char *Location, int Duration, int ByType)
|
||||
{
|
||||
int ret_code;
|
||||
char *msgs[2];
|
||||
@ -580,14 +467,14 @@ SendReply( IN struct sockaddr *DestAddr,
|
||||
|
||||
msgs[0] = NULL;
|
||||
msgs[1] = NULL;
|
||||
|
||||
if (RootDev) {
|
||||
/* one msg for root device */
|
||||
num_msgs = 1;
|
||||
|
||||
sprintf(Mil_Usn, "%s::upnp:rootdevice", Udn);
|
||||
CreateServicePacket(MSGTYPE_REPLY, "upnp:rootdevice",
|
||||
Mil_Usn, Location, Duration, &msgs[0], DestAddr->sa_family );
|
||||
Mil_Usn, Location, Duration, &msgs[0],
|
||||
DestAddr->sa_family);
|
||||
} else {
|
||||
/* two msgs for embedded devices */
|
||||
num_msgs = 1;
|
||||
@ -595,14 +482,15 @@ SendReply( IN struct sockaddr *DestAddr,
|
||||
/*NK: FIX for extra response when someone searches by udn */
|
||||
if (!ByType) {
|
||||
CreateServicePacket(MSGTYPE_REPLY, Udn, Udn, Location,
|
||||
Duration, &msgs[0], DestAddr->sa_family );
|
||||
Duration, &msgs[0],
|
||||
DestAddr->sa_family);
|
||||
} else {
|
||||
sprintf(Mil_Usn, "%s::%s", Udn, DevType);
|
||||
CreateServicePacket(MSGTYPE_REPLY, DevType, Mil_Usn,
|
||||
Location, Duration, &msgs[0], DestAddr->sa_family );
|
||||
Location, Duration, &msgs[0],
|
||||
DestAddr->sa_family);
|
||||
}
|
||||
}
|
||||
|
||||
/* check error */
|
||||
for (i = 0; i < num_msgs; i++) {
|
||||
if (msgs[i] == NULL) {
|
||||
@ -610,7 +498,6 @@ SendReply( IN struct sockaddr *DestAddr,
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
/* send msgs */
|
||||
ret_code = NewRequestHandler(DestAddr, num_msgs, msgs);
|
||||
for (i = 0; i < num_msgs; i++) {
|
||||
@ -621,47 +508,23 @@ SendReply( IN struct sockaddr *DestAddr,
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : DeviceReply
|
||||
*
|
||||
* Parameters:
|
||||
* IN struct sockaddr *DestAddr:destination IP address.
|
||||
* IN char *DevType: Device type
|
||||
* IN int RootDev: 1 means root device 0 means embedded device.
|
||||
* IN char * Udn: Device UDN
|
||||
* IN char * Location: Location of Device description document.
|
||||
* IN int Duration :Life time of this device.
|
||||
* Description:
|
||||
* This function creates the reply packet based on the input parameter,
|
||||
* and send it to the client address given in its input parameter DestAddr.
|
||||
*
|
||||
* Returns: int
|
||||
* UPNP_E_SUCCESS if successful else appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
DeviceReply( IN struct sockaddr *DestAddr,
|
||||
IN char *DevType,
|
||||
IN int RootDev,
|
||||
IN char *Udn,
|
||||
IN char *Location,
|
||||
IN int Duration)
|
||||
int DeviceReply(struct sockaddr *DestAddr, char *DevType, int RootDev,
|
||||
char *Udn, char *Location, int Duration)
|
||||
{
|
||||
char *szReq[3],
|
||||
Mil_Nt[LINE_SIZE],
|
||||
Mil_Usn[LINE_SIZE];
|
||||
char *szReq[3], Mil_Nt[LINE_SIZE], Mil_Usn[LINE_SIZE];
|
||||
int RetVal;
|
||||
|
||||
szReq[0] = NULL;
|
||||
szReq[1] = NULL;
|
||||
szReq[2] = NULL;
|
||||
|
||||
/* create 2 or 3 msgs */
|
||||
if (RootDev) {
|
||||
/* 3 replies for root device */
|
||||
strcpy(Mil_Nt, "upnp:rootdevice");
|
||||
sprintf(Mil_Usn, "%s::upnp:rootdevice", Udn);
|
||||
CreateServicePacket(MSGTYPE_REPLY, Mil_Nt, Mil_Usn,
|
||||
Location, Duration, &szReq[0], DestAddr->sa_family );
|
||||
Location, Duration, &szReq[0],
|
||||
DestAddr->sa_family);
|
||||
}
|
||||
sprintf(Mil_Nt, "%s", Udn);
|
||||
sprintf(Mil_Usn, "%s", Udn);
|
||||
@ -693,28 +556,8 @@ DeviceReply( IN struct sockaddr *DestAddr,
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : ServiceAdvertisement
|
||||
*
|
||||
* Parameters:
|
||||
* IN char * Udn: Device UDN
|
||||
* IN char *ServType: Service Type.
|
||||
* IN char * Location: Location of Device description document.
|
||||
* IN int Duration :Life time of this device.
|
||||
* IN int AddressFamily: Device address family
|
||||
* Description:
|
||||
* This function creates the advertisement packet based
|
||||
* on the input parameter, and send it to the multicast channel.
|
||||
*
|
||||
* Returns: int
|
||||
* UPNP_E_SUCCESS if successful else appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
ServiceAdvertisement( IN char *Udn,
|
||||
IN char *ServType,
|
||||
IN char *Location,
|
||||
IN int Duration,
|
||||
IN int AddressFamily)
|
||||
int ServiceAdvertisement(char *Udn, char *ServType, char *Location,
|
||||
int Duration, int AddressFamily)
|
||||
{
|
||||
char Mil_Usn[LINE_SIZE];
|
||||
char *szReq[1];
|
||||
@ -731,17 +574,15 @@ ServiceAdvertisement( IN char *Udn,
|
||||
} else if (AddressFamily == AF_INET6) {
|
||||
DestAddr6->sin6_family = AF_INET6;
|
||||
inet_pton(AF_INET6,
|
||||
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : SSDP_IPV6_LINKLOCAL,
|
||||
&DestAddr6->sin6_addr );
|
||||
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL :
|
||||
SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr);
|
||||
DestAddr6->sin6_port = htons(SSDP_PORT);
|
||||
DestAddr6->sin6_scope_id = gIF_INDEX;
|
||||
} else {
|
||||
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
|
||||
"Invalid device address family.\n");
|
||||
}
|
||||
|
||||
sprintf(Mil_Usn, "%s::%s", Udn, ServType);
|
||||
|
||||
/* CreateServiceRequestPacket(1,szReq[0],Mil_Nt,Mil_Usn,
|
||||
* Server,Location,Duration); */
|
||||
CreateServicePacket(MSGTYPE_ADVERTISEMENT, ServType, Mil_Usn,
|
||||
@ -749,78 +590,33 @@ ServiceAdvertisement( IN char *Udn,
|
||||
if (szReq[0] == NULL) {
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
|
||||
RetVal = NewRequestHandler((struct sockaddr *)&__ss, 1, szReq);
|
||||
|
||||
free(szReq[0]);
|
||||
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : ServiceReply
|
||||
*
|
||||
* Parameters:
|
||||
* IN struct sockaddr *DestAddr:
|
||||
* IN char * Udn: Device UDN
|
||||
* IN char *ServType: Service Type.
|
||||
* IN char * Location: Location of Device description document.
|
||||
* IN int Duration :Life time of this device.
|
||||
* Description:
|
||||
* This function creates the advertisement packet based
|
||||
* on the input parameter, and send it to the multicast channel.
|
||||
*
|
||||
* Returns: int
|
||||
* UPNP_E_SUCCESS if successful else appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
ServiceReply( IN struct sockaddr *DestAddr,
|
||||
IN char *ServType,
|
||||
IN char *Udn,
|
||||
IN char *Location,
|
||||
IN int Duration )
|
||||
int ServiceReply(struct sockaddr *DestAddr, char *ServType, char *Udn,
|
||||
char *Location, int Duration)
|
||||
{
|
||||
char Mil_Usn[LINE_SIZE];
|
||||
char *szReq[1];
|
||||
int RetVal;
|
||||
|
||||
szReq[0] = NULL;
|
||||
|
||||
sprintf(Mil_Usn, "%s::%s", Udn, ServType);
|
||||
|
||||
CreateServicePacket(MSGTYPE_REPLY, ServType, Mil_Usn,
|
||||
Location, Duration, &szReq[0], DestAddr->sa_family);
|
||||
if( szReq[0] == NULL ) {
|
||||
if (szReq[0] == NULL)
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
|
||||
RetVal = NewRequestHandler(DestAddr, 1, szReq);
|
||||
|
||||
free(szReq[0]);
|
||||
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : ServiceShutdown
|
||||
*
|
||||
* Parameters:
|
||||
* IN char * Udn: Device UDN
|
||||
* IN char *ServType: Service Type.
|
||||
* IN char * Location: Location of Device description document.
|
||||
* IN int Duration :Service duration in sec.
|
||||
* IN int AddressFamily: Device address family
|
||||
* Description:
|
||||
* This function creates a HTTP service shutdown request packet
|
||||
* and sent it to the multicast channel through RequestHandler.
|
||||
*
|
||||
* Returns: int
|
||||
* UPNP_E_SUCCESS if successful else appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
ServiceShutdown( IN char *Udn,
|
||||
IN char *ServType,
|
||||
IN char *Location,
|
||||
IN int Duration,
|
||||
IN int AddressFamily)
|
||||
int ServiceShutdown(char *Udn, char *ServType, char *Location, int Duration,
|
||||
int AddressFamily)
|
||||
{
|
||||
char Mil_Usn[LINE_SIZE];
|
||||
char *szReq[1];
|
||||
@ -837,56 +633,30 @@ ServiceShutdown( IN char *Udn,
|
||||
} else if (AddressFamily == AF_INET6) {
|
||||
DestAddr6->sin6_family = AF_INET6;
|
||||
inet_pton(AF_INET6,
|
||||
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : SSDP_IPV6_LINKLOCAL,
|
||||
&DestAddr6->sin6_addr );
|
||||
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL :
|
||||
SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr);
|
||||
DestAddr6->sin6_port = htons(SSDP_PORT);
|
||||
DestAddr6->sin6_scope_id = gIF_INDEX;
|
||||
} else {
|
||||
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
|
||||
"Invalid device address family.\n");
|
||||
}
|
||||
|
||||
/* sprintf(Mil_Nt,"%s",ServType); */
|
||||
sprintf(Mil_Usn, "%s::%s", Udn, ServType);
|
||||
/* CreateServiceRequestPacket(0,szReq[0],Mil_Nt,Mil_Usn,
|
||||
* Server,Location,Duration); */
|
||||
CreateServicePacket(MSGTYPE_SHUTDOWN, ServType, Mil_Usn,
|
||||
Location, Duration, &szReq[0], AddressFamily);
|
||||
if( szReq[0] == NULL ) {
|
||||
if (szReq[0] == NULL)
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
RetVal = NewRequestHandler((struct sockaddr *)&__ss, 1, szReq);
|
||||
|
||||
free(szReq[0]);
|
||||
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : DeviceShutdown
|
||||
*
|
||||
* Parameters:
|
||||
* IN char *DevType: Device Type.
|
||||
* IN int RootDev:1 means root device.
|
||||
* IN char * Udn: Device UDN
|
||||
* IN char * Location: Location URL
|
||||
* IN int Duration :Device duration in sec.
|
||||
* IN int AddressFamily: Device address family.
|
||||
*
|
||||
* Description:
|
||||
* This function creates a HTTP device shutdown request packet
|
||||
* and sent it to the multicast channel through RequestHandler.
|
||||
*
|
||||
* Returns: int
|
||||
* UPNP_E_SUCCESS if successful else appropriate error
|
||||
***************************************************************************/
|
||||
int
|
||||
DeviceShutdown( IN char *DevType,
|
||||
IN int RootDev,
|
||||
IN char *Udn,
|
||||
IN char *_Server,
|
||||
IN char *Location,
|
||||
IN int Duration,
|
||||
IN int AddressFamily)
|
||||
int DeviceShutdown(char *DevType, int RootDev, char *Udn, char *_Server,
|
||||
char *Location, int Duration, int AddressFamily)
|
||||
{
|
||||
struct sockaddr_storage __ss;
|
||||
struct sockaddr_in *DestAddr4 = (struct sockaddr_in *)&__ss;
|
||||
@ -898,7 +668,6 @@ DeviceShutdown( IN char *DevType,
|
||||
msgs[0] = NULL;
|
||||
msgs[1] = NULL;
|
||||
msgs[2] = NULL;
|
||||
|
||||
memset(&__ss, 0, sizeof(__ss));
|
||||
if (AddressFamily == AF_INET) {
|
||||
DestAddr4->sin_family = AF_INET;
|
||||
@ -907,8 +676,8 @@ DeviceShutdown( IN char *DevType,
|
||||
} else if (AddressFamily == AF_INET6) {
|
||||
DestAddr6->sin6_family = AF_INET6;
|
||||
inet_pton(AF_INET6,
|
||||
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : SSDP_IPV6_LINKLOCAL,
|
||||
&DestAddr6->sin6_addr );
|
||||
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL :
|
||||
SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr);
|
||||
DestAddr6->sin6_port = htons(SSDP_PORT);
|
||||
DestAddr6->sin6_scope_id = gIF_INDEX;
|
||||
} else {
|
||||
@ -919,7 +688,8 @@ DeviceShutdown( IN char *DevType,
|
||||
if (RootDev) {
|
||||
sprintf(Mil_Usn, "%s::upnp:rootdevice", Udn);
|
||||
CreateServicePacket(MSGTYPE_SHUTDOWN, "upnp:rootdevice",
|
||||
Mil_Usn, Location, Duration, &msgs[0], AddressFamily );
|
||||
Mil_Usn, Location, Duration, &msgs[0],
|
||||
AddressFamily);
|
||||
}
|
||||
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
|
||||
"In function DeviceShutdown\n");
|
||||
@ -930,8 +700,7 @@ DeviceShutdown( IN char *DevType,
|
||||
CreateServicePacket(MSGTYPE_SHUTDOWN, DevType, Mil_Usn,
|
||||
Location, Duration, &msgs[2], AddressFamily);
|
||||
/* check error */
|
||||
if( ( RootDev && msgs[0] == NULL ) ||
|
||||
msgs[1] == NULL || msgs[2] == NULL ) {
|
||||
if ((RootDev && msgs[0] == NULL) || msgs[1] == NULL || msgs[2] == NULL) {
|
||||
free(msgs[0]);
|
||||
free(msgs[1]);
|
||||
free(msgs[2]);
|
||||
@ -940,11 +709,13 @@ DeviceShutdown( IN char *DevType,
|
||||
/* send packets */
|
||||
if (RootDev) {
|
||||
/* send 3 msg types */
|
||||
ret_code = NewRequestHandler( (struct sockaddr*)&__ss, 3, &msgs[0] );
|
||||
ret_code =
|
||||
NewRequestHandler((struct sockaddr *)&__ss, 3, &msgs[0]);
|
||||
} else {
|
||||
/* sub-device */
|
||||
/* send 2 msg types */
|
||||
ret_code = NewRequestHandler( (struct sockaddr*)&__ss, 2, &msgs[1] );
|
||||
ret_code =
|
||||
NewRequestHandler((struct sockaddr *)&__ss, 2, &msgs[1]);
|
||||
}
|
||||
/* free msgs */
|
||||
free(msgs[0]);
|
||||
@ -954,7 +725,7 @@ DeviceShutdown( IN char *DevType,
|
||||
return ret_code;
|
||||
_Server = _Server;
|
||||
}
|
||||
|
||||
#endif /* EXCLUDE_SSDP */
|
||||
#endif /* INCLUDE_DEVICE_APIS */
|
||||
|
||||
/* @} SSDPlib */
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user