SSDP Library

## Files

file | ssdplib.h
file | ssdp_ctrlpt.c
file | ssdp_device.c
file | ssdp_server.c
file | SSDPResultDataCallback.h
| SSDPResultData object declararion.

## Data Structures

struct | SsdpEventStruct
struct | TData
struct | ssdpsearchreply
struct | ssdpsearcharg
struct | ssdpsearchexparg
struct | ssdp_thread_data
struct | SSDPSockArray

## Macros

#define | BUFSIZE (size_t)2500
#define | SSDP_IP "239.255.255.250"
#define | SSDP_IPV6_LINKLOCAL "FF02::C"
#define | SSDP_IPV6_SITELOCAL "FF05::C"
#define | SSDP_PORT 1900
#define | NUM_TRY 3
#define | THREAD_LIMIT 50
#define | COMMAND_LEN 300
#define | MSGTYPE_SHUTDOWN 0
#define | MSGTYPE_ADVERTISEMENT 1
#define | MSGTYPE_REPLY 2
#define | MAX_TIME_TOREAD 45

## Typedefs

typedef enum SsdpSearchType | SType

## Enumerations

enum | SsdpSearchType { SSDP_SERROR = -1 , SSDP_ALL , SSDP_ROOTDEVICE , SSDP_DEVICEUDN , SSDP_DEVICETYPE , SSDP_SERVICE }
enum | Listener { Idle , Stopping , Running }

## Functions

static void | send_search_result (void *data)
| Sends a callback to the control point application with a SEARCH result.
static int | CreateClientRequestPacket (char *RqstBuf, size_t RqstBufSize, int Mx, char *SearchTarget, int AddressFamily)
| Creates a HTTP search request packet depending on the input parameter.
static void | searchExpired (void *arg)
static int | NewRequestHandler (struct sockaddr *DestAddr, int NumPacket, char **RqPacket)
| Works as a request handler which passes the HTTP request string to multicast channel.
static int | extractIPv6address (char *url, char *address)
static int | isUrlV6UlaGua (char *descdocUrl)
static void | CreateServicePacket (int msg_type, const char *nt, char *usn, char *location, int duration, char **packet, int AddressFamily, int PowerState, int SleepPeriod, int RegistrationState)
| Creates a HTTP request packet. Depending on the input parameter, it either creates a service advertisement request or service shutdown request etc.
void | RequestHandler ()
static void | free_ssdp_event_handler_data (void *the_data)
| Frees the ssdp request.
static UPNP_INLINE int | valid_ssdp_msg (http_message_t *hmsg)
| Does some quick checking of the ssdp msg.
static UPNP_INLINE int | start_event_handler (void *Data)
| Parses the message and dispatches it to a handler which handles the ssdp request msg.
static void | ssdp_event_handler_thread (void *the_data)
| This function is a thread that handles SSDP requests.
static int | create_ssdp_sock_v4 (SOCKET *ssdpSock)
static int | create_ssdp_sock_reqv4 (SOCKET *ssdpReqSock)
| Creates the SSDP IPv4 socket to be used by the control point.
void | SSDPResultData_Callback (const SSDPResultData *p)

## Variables

enum SsdpSearchType | SsdpEventStruct::RequestType
int | SsdpEventStruct::ErrCode
int | SsdpEventStruct::MaxAge
int | SsdpEventStruct::Mx
char | SsdpEventStruct::UDN [LINE_SIZE]
char | SsdpEventStruct::DeviceType [LINE_SIZE]
char | SsdpEventStruct::ServiceType [LINE_SIZE]
char | SsdpEventStruct::Location [LINE_SIZE]
char | SsdpEventStruct::HostAddr [LINE_SIZE]
char | SsdpEventStruct::Os [LINE_SIZE]
char | SsdpEventStruct::Ext [LINE_SIZE]
char | SsdpEventStruct::Date [LINE_SIZE]
struct sockaddr * | SsdpEventStruct::DestAddr
void * | SsdpEventStruct::Cookie
int | TData::Mx
void * | TData::Cookie
char * | TData::Data
struct sockaddr_storage | TData::DestAddr
int | ssdpsearchreply::MaxAge
UpnpDevice_Handle | ssdpsearchreply::handle
struct sockaddr_storage | ssdpsearchreply::dest_addr
SsdpEvent | ssdpsearchreply::event
int | ssdpsearcharg::timeoutEventId
char * | ssdpsearcharg::searchTarget
void * | ssdpsearcharg::cookie
enum SsdpSearchType | ssdpsearcharg::requestType
int | ssdpsearchexparg::handle
int | ssdpsearchexparg::timeoutEventId
http_parser_t | ssdp_thread_data::parser
struct sockaddr_storage | ssdp_thread_data::dest_addr
SOCKET | gSsdpReqSocket4 = INVALID_SOCKET
SOCKET | SSDPSockArray::ssdpSock
int | SSDPSockArray::ssdpReqSock
static const char | SERVICELIST_STR [] = "serviceList"

## X_USER_AGENT

can be overwritten by configure CFLAGS argument. The {\tt X_USER_AGENT} constant specifies the value of the X-User-Agent: HTTP header. The value "redsonic" is needed for the DSM-320. See https://sourceforge.net/forum/message.php?msg_id=3166856 for more information
typedef struct SsdpEventStruct | SsdpEvent
typedef void(* | SsdpFunPtr) (SsdpEvent *)
typedef struct TData | ThreadData
typedef struct ssdpsearchreply | SsdpSearchReply
typedef struct ssdpsearcharg | SsdpSearchArg
typedef struct ssdpsearchexparg | SsdpSearchExpArg
typedef int(* | ParserFun) (char *, SsdpEvent *)
SOCKET | gSsdpReqSocket4
#define | X_USER_AGENT "redsonic"
#define | NO_ERROR_FOUND 0
#define | E_REQUEST_INVALID -3
#define | E_RES_EXPIRED -4
#define | E_MEM_ALLOC -5
#define | E_HTTP_SYNTEX -6
#define | E_SOCKET -7
#define | RQST_TIMEOUT 20

## SSDP Server Functions

int | AdvertiseAndReply (int AdFlag, UpnpDevice_Handle Hnd, enum SsdpSearchType SearchType, struct sockaddr *DestAddr, char *DeviceType, char *DeviceUDN, char *ServiceType, int Exp)
| Sends SSDP advertisements, replies and shutdown messages.
int | unique_service_name (char *cmd, SsdpEvent *Evt)
| Fills the fields of the event structure like DeviceType, Device UDN and Service Type.
enum SsdpSearchType | ssdp_request_type1 (char *cmd)
| This function figures out the type of the SSDP search in the in the request.
int | ssdp_request_type (char *cmd, SsdpEvent *Evt)
| Starts filling the SSDP event structure based upon the request received.
int | readFromSSDPSocket (SOCKET socket)
| This function reads the data from the ssdp socket.
int | get_ssdp_sockets (MiniServerSockArray *out)
| Creates the IPv4 and IPv6 ssdp sockets required by the control point and device operation.

## SSDP Control Point Functions

void | ssdp_handle_ctrlpt_msg (http_message_t *hmsg, struct sockaddr_storage *dest_addr, int timeout)
| This function handles the ssdp messages from the devices. These messages includes the search replies, advertisement of device coming alive and bye byes.
int | SearchByTarget (int Hnd, int Mx, char *St, void *Cookie)
| Creates and send the search request for a specific URL.

## SSDP Device Functions

void | advertiseAndReplyThread (void *data)
| Wrapper function to reply the search request coming from the control point.
void | ssdp_handle_device_request (http_message_t *hmsg, struct sockaddr_storage *dest_addr)
| 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).
int | DeviceAdvertisement (char *DevType, int RootDev, char *Udn, char *Location, int Duration, int AddressFamily, int PowerState, int SleepPeriod, int RegistrationState)
| Creates the device advertisement request based on the input parameter, and send it to the multicast channel.
int | SendReply (struct sockaddr *DestAddr, char *DevType, int RootDev, char *Udn, char *Location, int Duration, int ByType, int PowerState, int SleepPeriod, int RegistrationState)
| Creates the reply packet based on the input parameter, and send it to the client addesss given in its input parameter DestAddr.
int | DeviceReply (struct sockaddr *DestAddr, char *DevType, int RootDev, char *Udn, char *Location, int Duration, int PowerState, int SleepPeriod, int RegistrationState)
| Creates the reply packet based on the input parameter, and send it to the client address given in its input parameter DestAddr.
int | ServiceAdvertisement (char *Udn, char *ServType, char *Location, int Duration, int AddressFamily, int PowerState, int SleepPeriod, int RegistrationState)
| Creates the advertisement packet based on the input parameter, and send it to the multicast channel.
int | ServiceReply (struct sockaddr *DestAddr, char *ServType, char *Udn, char *Location, int Duration, int PowerState, int SleepPeriod, int RegistrationState)
| Creates the advertisement packet based on the input parameter, and send it to the multicast channel.
int | ServiceShutdown (char *Udn, char *ServType, char *Location, int Duration, int AddressFamily, int PowerState, int SleepPeriod, int RegistrationState)
| Creates a HTTP service shutdown request packet and sends it to the multicast channel through RequestHandler.
int | DeviceShutdown (char *DevType, int RootDev, char *Udn, char *Location, int Duration, int AddressFamily, int PowerState, int SleepPeriod, int RegistrationState)
| Creates a HTTP device shutdown request packet and send it to the multicast channel through RequestHandler.

## Detailed Description

## Macro Definition Documentation

## NO_ERROR_FOUND

#define NO_ERROR_FOUND 0

Error codes.

## Typedef Documentation

## SsdpEvent

typedef struct SsdpEventStruct SsdpEvent

Structure to store the SSDP information

## SType

typedef enum SsdpSearchType SType

Enumeration to define all different types of ssdp searches

## Enumeration Type Documentation

## SsdpSearchType

enum SsdpSearchType

Enumeration to define all different types of ssdp searches

Enumerator
SSDP_SERROR | Unknown search command.

## Function Documentation

## AdvertiseAndReply()

int AdvertiseAndReply | ( | int | AdFlag,
|  | UpnpDevice_Handle | Hnd,
|  | enum SsdpSearchType | SearchType,
|  | struct sockaddr * | DestAddr,
|  | char * | DeviceType,
|  | char * | DeviceUDN,
|  | char * | ServiceType,
|  | int | Exp
| ) |  |

Sends SSDP advertisements, replies and shutdown messages.

Returns
  UPNP_E_SUCCESS if successful else appropriate error.

References Handle_Info::DescURL, DeviceAdvertisement(), Handle_Info::DeviceAf, Handle_Info::DeviceList, DeviceReply(), DeviceShutdown(), DOMString, GetHandleInfo(), ixmlElement_getElementsByTagName(), ixmlNode_getFirstChild(), ixmlNode_getNextSibling(), ixmlNode_getNodeName(), ixmlNode_getNodeValue(), ixmlNodeList_free(), ixmlNodeList_item(), Handle_Info::LowerDescURL, SendReply(), ServiceAdvertisement(), ServiceReply(), ServiceShutdown(), UPNP_E_INVALID_HANDLE, UPNP_E_SUCCESS, and UpnpPrintf().

Referenced by advertiseAndReplyThread(), UpnpSendAdvertisementLowPower(), and UpnpUnRegisterRootDeviceLowPower().

## advertiseAndReplyThread()

void advertiseAndReplyThread | ( | void * | data | ) |

Wrapper function to reply the search request coming from the control point.

References AdvertiseAndReply().

Referenced by ssdp_handle_device_request().

## create_ssdp_sock_reqv4()

static int create_ssdp_sock_reqv4 | ( | SOCKET * | ssdpReqSock | ) |

static

Creates the SSDP IPv4 socket to be used by the control point.

Returns
  UPNP_E_SUCCESS on successful socket creation.

Parameters

  [out] | ssdpReqSock | SSDP IPv4 request socket to be created.

References INVALID_SOCKET, sock_make_no_blocking(), UPNP_E_OUTOF_SOCKET, UPNP_E_SUCCESS, and UpnpPrintf().

Referenced by get_ssdp_sockets().

## create_ssdp_sock_v4()

static int create_ssdp_sock_v4 | ( | SOCKET * | ssdpSock | ) |

static

Parameters

  ssdpSock | [] SSDP IPv4 socket to be created.

References gIF_IPV4, INVALID_SOCKET, UPNP_E_NETWORK_ERROR, UPNP_E_OUTOF_SOCKET, UPNP_E_SOCKET_BIND, UPNP_E_SOCKET_ERROR, UPNP_E_SUCCESS, UpnpCloseSocket, and UpnpPrintf().

Referenced by get_ssdp_sockets().

## CreateClientRequestPacket()

static int CreateClientRequestPacket | ( | char * | RqstBuf,
|  | size_t | RqstBufSize,
|  | int | Mx,
|  | char * | SearchTarget,
|  | int | AddressFamily
| ) |  |

static

Creates a HTTP search request packet depending on the input parameter.

Parameters

  [in,out] | RqstBuf | Output string in HTTP format.
  [in] | RqstBufSize | RqstBuf size.
  [in] | Mx | Search Target.
  [in] | SearchTarget | Number of seconds to wait to collect all the responses.
  [in] | AddressFamily | search address family.

References UPNP_E_INTERNAL_ERROR, UPNP_E_INVALID_ARGUMENT, and UPNP_E_SUCCESS.

Referenced by SearchByTarget().

## CreateServicePacket()

static void CreateServicePacket | ( | int | msg_type,
|  | const char * | nt,
|  | char * | usn,
|  | char * | location,
|  | int | duration,
|  | char ** | packet,
|  | int | AddressFamily,
|  | int | PowerState,
|  | int | SleepPeriod,
|  | int | RegistrationState
| ) |  |

static

Creates a HTTP request packet. Depending on the input parameter, it either creates a service advertisement request or service shutdown request etc.

Parameters

  [in] | msg_type | type of the message (Search Reply, Advertisement or Shutdown).
  [in] | nt | ssdp type.
  [in] | usn | unique service name ( go in the HTTP Header).
  [in] | location | Location URL.
  [in] | duration | Service duration in sec.
  [out] | packet | Output buffer filled with HTTP statement.
  [in] | AddressFamily | Address family of the HTTP request.
  [in] | PowerState | PowerState as defined by UPnP Low Power.
  [in] | SleepPeriod | SleepPeriod as defined by UPnP Low Power.
  [in] | RegistrationState | RegistrationState as defined by UPnP Low Power.

References gUpnpSdkNLSuuid, http_MakeMessage(), isUrlV6UlaGua(), and membuffer::size_inc.

Referenced by DeviceAdvertisement(), DeviceReply(), DeviceShutdown(), SendReply(), ServiceAdvertisement(), ServiceReply(), and ServiceShutdown().

## DeviceAdvertisement()

int DeviceAdvertisement | ( | char * | DevType,
|  | int | RootDev,
|  | char * | Udn,
|  | char * | Location,
|  | int | Duration,
|  | int | AddressFamily,
|  | int | PowerState,
|  | int | SleepPeriod,
|  | int | RegistrationState
| ) |  |

Creates the device advertisement request based on the input parameter, and send it to the multicast channel.

Returns
  UPNP_E_SUCCESS if successful else appropriate error.

References CreateServicePacket(), gIF_INDEX, isUrlV6UlaGua(), NewRequestHandler(), UPNP_E_OUTOF_MEMORY, and UpnpPrintf().

Referenced by AdvertiseAndReply().

## DeviceReply()

int DeviceReply | ( | struct sockaddr * | DestAddr,
|  | char * | DevType,
|  | int | RootDev,
|  | char * | Udn,
|  | char * | Location,
|  | int | Duration,
|  | int | PowerState,
|  | int | SleepPeriod,
|  | int | RegistrationState
| ) |  |

Creates the reply packet based on the input parameter, and send it to the client address given in its input parameter DestAddr.

Returns
  UPNP_E_SUCCESS if successful else appropriate error.

References CreateServicePacket(), NewRequestHandler(), and UPNP_E_OUTOF_MEMORY.

Referenced by AdvertiseAndReply().

## DeviceShutdown()

int DeviceShutdown | ( | char * | DevType,
|  | int | RootDev,
|  | char * | Udn,
|  | char * | Location,
|  | int | Duration,
|  | int | AddressFamily,
|  | int | PowerState,
|  | int | SleepPeriod,
|  | int | RegistrationState
| ) |  |

Creates a HTTP device shutdown request packet and send it to the multicast channel through RequestHandler.

Returns
  UPNP_E_SUCCESS if successful else appropriate error.

References CreateServicePacket(), gIF_INDEX, isUrlV6UlaGua(), NewRequestHandler(), UPNP_E_OUTOF_MEMORY, and UpnpPrintf().

Referenced by AdvertiseAndReply().

## extractIPv6address()

static int extractIPv6address | ( | char * | url,
|  | char * | address
| ) |  |

static

Returns
  1 if an inet6 @ has been found.

Referenced by isUrlV6UlaGua().

## free_ssdp_event_handler_data()

static void free_ssdp_event_handler_data | ( | void * | the_data | ) |

static

Frees the ssdp request.

Parameters

  [in] | the_data | ssdp_thread_data structure. This structure contains SSDP request message.

Referenced by readFromSSDPSocket(), ssdp_event_handler_thread(), and start_event_handler().

## get_ssdp_sockets()

int get_ssdp_sockets | ( | MiniServerSockArray * | out | ) |

Creates the IPv4 and IPv6 ssdp sockets required by the control point and device operation.

Returns
  UPNP_E_SUCCESS if successful else returns appropriate error.

References create_ssdp_sock_reqv4(), create_ssdp_sock_v4(), gIF_IPV4, gIF_IPV6, gIF_IPV6_ULA_GUA, INVALID_SOCKET, MServerSockArray::ssdpReqSock4, MServerSockArray::ssdpReqSock6, MServerSockArray::ssdpSock4, MServerSockArray::ssdpSock6, MServerSockArray::ssdpSock6UlaGua, UPNP_E_SUCCESS, and UpnpCloseSocket.

Referenced by StartMiniServer().

## isUrlV6UlaGua()

static int isUrlV6UlaGua | ( | char * | descdocUrl | ) |

static

Returns
  1 if the Url contains an ULA or GUA IPv6 address, 0 otherwise.

References extractIPv6address().

Referenced by CreateServicePacket(), DeviceAdvertisement(), DeviceShutdown(), ServiceAdvertisement(), and ServiceShutdown().

## NewRequestHandler()

static int NewRequestHandler | ( | struct sockaddr * | DestAddr,
|  | int | NumPacket,
|  | char ** | RqPacket
| ) |  |

static

Works as a request handler which passes the HTTP request string to multicast channel.

Returns
  UPNP_E_SUCCESS if successful else appropriate error.

Parameters

  [in] | DestAddr | Ip address, to send the reply.
  [in] | NumPacket | Number of packet to be sent.
  [in] | RqPacket | .

References gIF_INDEX, gIF_IPV4, INVALID_SOCKET, UPNP_E_INVALID_PARAM, UPNP_E_NETWORK_ERROR, UPNP_E_OUTOF_SOCKET, UPNP_E_SOCKET_WRITE, UPNP_E_SUCCESS, UpnpCloseSocket, and UpnpPrintf().

Referenced by DeviceAdvertisement(), DeviceReply(), DeviceShutdown(), SendReply(), ServiceAdvertisement(), ServiceReply(), and ServiceShutdown().

## readFromSSDPSocket()

int readFromSSDPSocket | ( | SOCKET | socket | ) |

This function reads the data from the ssdp socket.

Returns
  0 on success; -1 on error.

References membuffer::buf, free_ssdp_event_handler_data(), gRecvThreadPool, membuffer::length, http_message_t::msg, ssdp_event_handler_thread(), ThreadPoolAdd(), TPJobInit(), TPJobSetFreeFunction(), TPJobSetPriority(), and UpnpPrintf().

## SearchByTarget()

int SearchByTarget | ( | int | Hnd,
|  | int | Mx,
|  | char * | St,
|  | void * | Cookie
| ) |  |

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:

- "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
  1 if successful else appropriate error.

References CreateClientRequestPacket(), GetHandleInfo(), gIF_INDEX, gIF_IPV4, gTimerThread, INVALID_SOCKET, REL_SEC, ssdp_request_type1(), SSDP_SERROR, Handle_Info::SsdpSearchList, TimerThreadSchedule(), TPJobInit(), TPJobSetFreeFunction(), TPJobSetPriority(), UPNP_E_INTERNAL_ERROR, UPNP_E_INVALID_PARAM, UPNP_E_SUCCESS, UpnpCloseSocket, and UpnpPrintf().

Referenced by UpnpSearchAsync().

## send_search_result()

static void send_search_result | ( | void * | data | ) |

static

Sends a callback to the control point application with a SEARCH result.

References SSDPResultData_delete().

Referenced by ssdp_handle_ctrlpt_msg().

## SendReply()

int SendReply | ( | struct sockaddr * | DestAddr,
|  | char * | DevType,
|  | int | RootDev,
|  | char * | Udn,
|  | char * | Location,
|  | int | Duration,
|  | int | ByType,
|  | int | PowerState,
|  | int | SleepPeriod,
|  | int | RegistrationState
| ) |  |

Creates the reply packet based on the input parameter, and send it to the client addesss given in its input parameter DestAddr.

Returns
  UPNP_E_SUCCESS if successful else appropriate error.

References CreateServicePacket(), NewRequestHandler(), and UPNP_E_OUTOF_MEMORY.

Referenced by AdvertiseAndReply().

## ServiceAdvertisement()

int ServiceAdvertisement | ( | char * | Udn,
|  | char * | ServType,
|  | char * | Location,
|  | int | Duration,
|  | int | AddressFamily,
|  | int | PowerState,
|  | int | SleepPeriod,
|  | int | RegistrationState
| ) |  |

Creates the advertisement packet based on the input parameter, and send it to the multicast channel.

Returns
  UPNP_E_SUCCESS if successful else appropriate error.

References CreateServicePacket(), gIF_INDEX, isUrlV6UlaGua(), NewRequestHandler(), UPNP_E_OUTOF_MEMORY, and UpnpPrintf().

Referenced by AdvertiseAndReply().

## ServiceReply()

int ServiceReply | ( | struct sockaddr * | DestAddr,
|  | char * | ServType,
|  | char * | Udn,
|  | char * | Location,
|  | int | Duration,
|  | int | PowerState,
|  | int | SleepPeriod,
|  | int | RegistrationState
| ) |  |

Creates the advertisement packet based on the input parameter, and send it to the multicast channel.

Returns
  UPNP_E_SUCCESS if successful else appropriate error.

References CreateServicePacket(), NewRequestHandler(), and UPNP_E_OUTOF_MEMORY.

Referenced by AdvertiseAndReply().

## ServiceShutdown()

int ServiceShutdown | ( | char * | Udn,
|  | char * | ServType,
|  | char * | Location,
|  | int | Duration,
|  | int | AddressFamily,
|  | int | PowerState,
|  | int | SleepPeriod,
|  | int | RegistrationState
| ) |  |

Creates a HTTP service shutdown request packet and sends it to the multicast channel through RequestHandler.

Returns
  UPNP_E_SUCCESS if successful else appropriate error.

References CreateServicePacket(), gIF_INDEX, isUrlV6UlaGua(), NewRequestHandler(), UPNP_E_OUTOF_MEMORY, and UpnpPrintf().

Referenced by AdvertiseAndReply().

## ssdp_event_handler_thread()

static void ssdp_event_handler_thread | ( | void * | the_data | ) |

static

This function is a thread that handles SSDP requests.

Parameters

  the_data | [] ssdp_thread_data structure. This structure contains SSDP request message.

References free_ssdp_event_handler_data(), http_message_t::method, http_message_t::request_method, ssdp_handle_ctrlpt_msg(), ssdp_handle_device_request(), and start_event_handler().

Referenced by readFromSSDPSocket().

## ssdp_handle_ctrlpt_msg()

void ssdp_handle_ctrlpt_msg | ( | http_message_t * | hmsg,
|  | struct sockaddr_storage * | dest_addr,
|  | int | timeout
| ) |  |

This function handles the ssdp messages from the devices. These messages includes the search replies, advertisement of device coming alive and bye byes.

References memptr::buf, Handle_Info::Callback, Handle_Info::Cookie, GetClientHandleInfo(), GetHandleInfo(), gRecvThreadPool, http_message_t::is_request, memptr::length, PARSE_OK, send_search_result(), ssdp_request_type(), SSDPResultData_delete(), SSDPResultData_new(), SSDPResultData_set_Cookie(), SSDPResultData_set_CtrlptCallback(), SSDPResultData_set_Param(), Handle_Info::SsdpSearchList, http_message_t::status_code, ThreadPoolAdd(), TPJobInit(), TPJobSetFreeFunction(), TPJobSetPriority(), unique_service_name(), UPNP_DISCOVERY_ADVERTISEMENT_ALIVE, UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE, UPNP_DISCOVERY_SEARCH_TIMEOUT, UPNP_E_SUCCESS, UpnpDiscovery_delete(), UpnpDiscovery_get_Expires(), UpnpDiscovery_get_Location(), UpnpDiscovery_new(), UpnpDiscovery_set_DestAddr(), UpnpDiscovery_set_ErrCode(), UpnpDiscovery_set_Expires(), UpnpDiscovery_strcpy_Date(), UpnpDiscovery_strcpy_DeviceID(), UpnpDiscovery_strcpy_DeviceType(), UpnpDiscovery_strcpy_ServiceType(), UpnpDiscovery_strncpy_Ext(), UpnpDiscovery_strncpy_Location(), UpnpDiscovery_strncpy_Os(), and UpnpString_get_Length().

Referenced by ssdp_event_handler_thread().

## ssdp_handle_device_request()

void ssdp_handle_device_request | ( | http_message_t * | hmsg,
|  | struct sockaddr_storage * | dest_addr
| ) |  |

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).

References advertiseAndReplyThread(), memptr::buf, GetDeviceHandleInfo(), gTimerThread, memptr::length, REL_SEC, ssdp_request_type(), TimerThreadSchedule(), TPJobInit(), TPJobSetFreeFunction(), and UpnpPrintf().

Referenced by ssdp_event_handler_thread().

## ssdp_request_type()

int ssdp_request_type | ( | char * | cmd,
|  | SsdpEvent * | Evt
| ) |  |

Starts filling the SSDP event structure based upon the request received.

Returns
  0 on success; -1 on error.

References NO_ERROR_FOUND, ssdp_request_type1(), SSDP_SERROR, and unique_service_name().

Referenced by ssdp_handle_ctrlpt_msg(), and ssdp_handle_device_request().

## ssdp_request_type1()

enum SsdpSearchType ssdp_request_type1 | ( | char * | cmd | ) |

This function figures out the type of the SSDP search in the in the request.

Returns
  enum SsdpSearchType. Returns appropriate search type, else returns SSDP_ERROR

References SSDP_SERROR.

Referenced by SearchByTarget(), and ssdp_request_type().

## start_event_handler()

static UPNP_INLINE int start_event_handler | ( | void * | Data | ) |

static

Parses the message and dispatches it to a handler which handles the ssdp request msg.

Returns
  0 if successful, -1 if error.

Parameters

  [in] | Data | ssdp_thread_data structure. This structure contains SSDP request message.

References free_ssdp_event_handler_data(), http_message_t::method, PARSE_FAILURE, PARSE_SUCCESS, UpnpPrintf(), valid_ssdp_msg(), and http_parser_t::valid_ssdp_notify_hack.

Referenced by ssdp_event_handler_thread().

## unique_service_name()

int unique_service_name | ( | char * | cmd,
|  | SsdpEvent * | Evt
| ) |  |

Fills the fields of the event structure like DeviceType, Device UDN and Service Type.

Returns
  0 if successful else -1.

Referenced by ssdp_handle_ctrlpt_msg(), and ssdp_request_type().

## valid_ssdp_msg()

static UPNP_INLINE int valid_ssdp_msg | ( | http_message_t * | hmsg | ) |

static

Does some quick checking of the ssdp msg.

Returns
  1 if msg is valid, else 0.

Parameters

  [in] | hmsg | ssdp_thread_data structure. This structure contains SSDP request message.

References http_message_t::method, http_message_t::request_method, UpnpPrintf(), and http_message_t::uri.

Referenced by start_event_handler().

## Variable Documentation

## ssdpReqSock

int SSDPSockArray::ssdpReqSock

socket for sending search requests and receiving search replies

## ssdpSock

SOCKET SSDPSockArray::ssdpSock

socket for incoming advertisments and search requests