libUPnP 1.14.19
ssdplib.h
Go to the documentation of this file.
1#ifndef SSDPLIB_H
2#define SSDPLIB_H
3
4/**************************************************************************
5 *
6 * Copyright (c) 2000-2003 Intel Corporation
7 * All rights reserved.
8 * Copyright (C) 2011-2012 France Telecom All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 *
13 * - Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * - Neither name of Intel Corporation nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
30 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 **************************************************************************/
35
44#include "UpnpInet.h"
45#include "httpparser.h"
46#include "httpreadwrite.h"
47#include "miniserver.h"
48
49#include <errno.h>
50#include <setjmp.h>
51#include <signal.h>
52#include <sys/types.h>
53
54#ifdef _WIN32
55#else /* _WIN32 */
56 #include <syslog.h>
57 #ifndef __APPLE__
58 #include <netinet/in_systm.h>
59 #include <netinet/ip.h>
60 #include <netinet/ip_icmp.h>
61 #endif /* __APPLE__ */
62 #include <sys/time.h>
63#endif /* _WIN32 */
64
66typedef enum SsdpSearchType
67{
70 SSDP_ALL,
71 SSDP_ROOTDEVICE,
72 SSDP_DEVICEUDN,
73 SSDP_DEVICETYPE,
74 SSDP_SERVICE
76
77#define BUFSIZE (size_t)2500
78#define SSDP_IP "239.255.255.250"
79#define SSDP_IPV6_LINKLOCAL "FF02::C"
80#define SSDP_IPV6_SITELOCAL "FF05::C"
81#define SSDP_PORT 1900
82#define NUM_TRY 3
83#define THREAD_LIMIT 50
84#define COMMAND_LEN 300
85
87#ifndef X_USER_AGENT
94 #define X_USER_AGENT "redsonic"
95#endif
96
98#define NO_ERROR_FOUND 0
99#define E_REQUEST_INVALID -3
100#define E_RES_EXPIRED -4
101#define E_MEM_ALLOC -5
102#define E_HTTP_SYNTEX -6
103#define E_SOCKET -7
104
105#define RQST_TIMEOUT 20
106
108typedef struct SsdpEventStruct
109{
110 enum SsdpSearchType RequestType;
111 int ErrCode;
112 int MaxAge;
113 int Mx;
114 char UDN[LINE_SIZE];
115 char DeviceType[LINE_SIZE];
116 /* NT or ST */
117 char ServiceType[LINE_SIZE];
118 char Location[LINE_SIZE];
119 char HostAddr[LINE_SIZE];
120 char Os[LINE_SIZE];
121 char Ext[LINE_SIZE];
122 char Date[LINE_SIZE];
123 struct sockaddr *DestAddr;
124 void *Cookie;
126
127typedef void (*SsdpFunPtr)(SsdpEvent *);
128
129typedef struct TData
130{
131 int Mx;
132 void *Cookie;
133 char *Data;
134 struct sockaddr_storage DestAddr;
135} ThreadData;
136
137typedef struct ssdpsearchreply
138{
139 int MaxAge;
140 UpnpDevice_Handle handle;
141 struct sockaddr_storage dest_addr;
142 SsdpEvent event;
144
145typedef struct ssdpsearcharg
146{
147 int timeoutEventId;
148 char *searchTarget;
149 void *cookie;
150 enum SsdpSearchType requestType;
152
153typedef struct ssdpsearchexparg
154{
155 int handle;
156 int timeoutEventId;
158
159typedef struct
160{
161 http_parser_t parser;
162 struct sockaddr_storage dest_addr;
164
165/* globals */
166
167#ifdef INCLUDE_CLIENT_APIS
168extern SOCKET gSsdpReqSocket4;
169 #ifdef UPNP_ENABLE_IPV6
170extern SOCKET gSsdpReqSocket6;
171 #endif /* UPNP_ENABLE_IPV6 */
172#endif /* INCLUDE_CLIENT_APIS */
173typedef int (*ParserFun)(char *, SsdpEvent *);
174
187 /* [in] -1 = Send shutdown, 0 = send reply, 1 = Send Advertisement. */
188 int AdFlag,
189 /* [in] Device handle. */
191 /* [in] Search type for sending replies. */
192 enum SsdpSearchType SearchType,
193 /* [in] Destination address. */
194 struct sockaddr *DestAddr,
195 /* [in] Device type. */
196 char *DeviceType,
197 /* [in] Device UDN. */
198 char *DeviceUDN,
199 /* [in] Service type. */
200 char *ServiceType,
201 /* [in] Advertisement age. */
202 int Exp);
203
211 /* [in] Service Name string. */
212 char *cmd,
213 /* [out] The SSDP event structure partially filled by all the
214 * function. */
215 SsdpEvent *Evt);
216
225 /* [in] command came in the ssdp request. */
226 char *cmd);
227
235 /* [in] command came in the ssdp request. */
236 char *cmd,
237 /* [out] The event structure partially filled by this function. */
238 SsdpEvent *Evt);
239
246 /* [in] SSDP socket. */
247 SOCKET socket);
248
256 /* [out] Array of SSDP sockets. */
258
259/* @} SSDP Server Functions */
260
273 /* [in] SSDP message from the device. */
274 http_message_t *hmsg,
275 /* [in] Address of the device. */
276 struct sockaddr_storage *dest_addr,
277 /* [in] timeout kept by the control point while sending search message.
278 * Only in search reply. */
279 int timeout);
280
299 /* [in] The handle of the client performing the search. */
300 int Hnd,
301 /* [in] Number of seconds to wait, to collect all the responses. */
302 int Mx,
303 /* [in] Search target. */
304 char *St,
305 /* [in] Cookie provided by control point application. This cokie will
306 * be returned to application in the callback. */
307 void *Cookie);
308
309/* @} SSDP Control Point Functions */
310
322 /* [in] Structure containing the search request. */
323 void *data);
324
330#ifdef INCLUDE_DEVICE_APIS
332 /* [in] . */
333 http_message_t *hmsg,
334 /* [in] . */
335 struct sockaddr_storage *dest_addr);
336#else /* INCLUDE_DEVICE_APIS */
338 /* [in] . */
339 http_message_t *hmsg,
340 /* [in] . */
341 struct sockaddr_storage *dest_addr)
342{
343}
344#endif /* INCLUDE_DEVICE_APIS */
345
353 /* [in] type of the device. */
354 char *DevType,
355 /* [in] flag to indicate if the device is root device. */
356 int RootDev,
357 /* [in] UDN. */
358 char *Udn,
359 /* [in] Location URL. */
360 char *Location,
361 /* [in] Service duration in sec. */
362 int Duration,
363 /* [in] Device address family. */
364 int AddressFamily,
365 /* [in] PowerState as defined by UPnP Low Power. */
366 int PowerState,
367 /* [in] SleepPeriod as defined by UPnP Low Power. */
368 int SleepPeriod,
369 /* [in] RegistrationState as defined by UPnP Low Power. */
370 int RegistrationState);
371
378int SendReply(
379 /* [in] destination IP address. */
380 struct sockaddr *DestAddr,
381 /* [in] Device type. */
382 char *DevType,
383 /* [in] 1 means root device 0 means embedded device. */
384 int RootDev,
385 /* [in] Device UDN. */
386 char *Udn,
387 /* [in] Location of Device description document. */
388 char *Location,
389 /* [in] Life time of this device. */
390 int Duration,
391 /* [in] . */
392 int ByType,
393 /* [in] PowerState as defined by UPnP Low Power. */
394 int PowerState,
395 /* [in] SleepPeriod as defined by UPnP Low Power. */
396 int SleepPeriod,
397 /* [in] RegistrationState as defined by UPnP Low Power. */
398 int RegistrationState);
399
406int DeviceReply(
407 /* [in] destination IP address. */
408 struct sockaddr *DestAddr,
409 /* [in] Device type. */
410 char *DevType,
411 /* [in] 1 means root device 0 means embedded device. */
412 int RootDev,
413 /* [in] Device UDN. */
414 char *Udn,
415 /* [in] Location of Device description document. */
416 char *Location,
417 /* [in] Life time of this device. */
418 int Duration,
419 /* [in] PowerState as defined by UPnP Low Power. */
420 int PowerState,
421 /* [in] SleepPeriod as defined by UPnP Low Power. */
422 int SleepPeriod,
423 /* [in] RegistrationState as defined by UPnP Low Power. */
424 int RegistrationState);
425
433 /* [in] Device UDN. */
434 char *Udn,
435 /* [in] Service Type. */
436 char *ServType,
437 /* [in] Location of Device description document. */
438 char *Location,
439 /* [in] Life time of this device. */
440 int Duration,
441 /* [in] Device address family. */
442 int AddressFamily,
443 /* [in] PowerState as defined by UPnP Low Power. */
444 int PowerState,
445 /* [in] SleepPeriod as defined by UPnP Low Power. */
446 int SleepPeriod,
447 /* [in] RegistrationState as defined by UPnP Low Power. */
448 int RegistrationState);
449
456int ServiceReply(
457 /* [in] . */
458 struct sockaddr *DestAddr,
459 /* [in] Service Type. */
460 char *ServType,
461 /* [in] Device UDN. */
462 char *Udn,
463 /* [in] Location of Device description document. */
464 char *Location,
465 /* [in] Life time of this device. */
466 int Duration,
467 /* [in] PowerState as defined by UPnP Low Power. */
468 int PowerState,
469 /* [in] SleepPeriod as defined by UPnP Low Power. */
470 int SleepPeriod,
471 /* [in] RegistrationState as defined by UPnP Low Power. */
472 int RegistrationState);
473
481 /* [in] Device UDN. */
482 char *Udn,
483 /* [in] Service Type. */
484 char *ServType,
485 /* [in] Location of Device description document. */
486 char *Location,
487 /* [in] Service duration in sec. */
488 int Duration,
489 /* [in] Device address family. */
490 int AddressFamily,
491 /* [in] PowerState as defined by UPnP Low Power. */
492 int PowerState,
493 /* [in] SleepPeriod as defined by UPnP Low Power. */
494 int SleepPeriod,
495 /* [in] RegistrationState as defined by UPnP Low Power. */
496 int RegistrationState);
497
505 /* [in] Device Type. */
506 char *DevType,
507 /* [in] 1 means root device. */
508 int RootDev,
509 /* [in] Device UDN. */
510 char *Udn,
511 /* [in] Location URL. */
512 char *Location,
513 /* [in] Device duration in sec. */
514 int Duration,
515 /* [in] Device address family. */
516 int AddressFamily,
517 /* [in] PowerState as defined by UPnP Low Power. */
518 int PowerState,
519 /* [in] SleepPeriod as defined by UPnP Low Power. */
520 int SleepPeriod,
521 /* [in] RegistrationState as defined by UPnP Low Power. */
522 int RegistrationState);
523
524/* @} SSDP Device Functions */
525
526/* @} SSDPlib SSDP Library */
527
528#endif /* SSDPLIB_H */
#define UPNP_INLINE
Declares an inline function.
Definition UpnpGlobal.h:112
Provides a platform independent way to include TCP/IP types and functions.
int SearchByTarget(int Hnd, int Mx, char *St, void *Cookie)
Creates and send the search request for a specific URL.
Definition ssdp_ctrlpt.c:573
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...
Definition ssdp_device.c:949
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.
Definition ssdp_server.c:90
int ssdp_request_type(char *cmd, SsdpEvent *Evt)
Starts filling the SSDP event structure based upon the request received.
Definition ssdp_server.c:650
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 c...
Definition ssdp_device.c:739
struct SsdpEventStruct SsdpEvent
int get_ssdp_sockets(MiniServerSockArray *out)
Creates the IPv4 and IPv6 ssdp sockets required by the control point and device operation.
Definition ssdp_server.c:1471
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 RequestHan...
Definition ssdp_device.c:1211
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 s...
Definition ssdp_device.c:81
enum SsdpSearchType SType
enum SsdpSearchType ssdp_request_type1(char *cmd)
This function figures out the type of the SSDP search in the in the request.
Definition ssdp_server.c:635
void advertiseAndReplyThread(void *data)
Wrapper function to reply the search request coming from the control point.
Definition ssdp_device.c:65
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.
Definition ssdp_device.c:1039
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 RequestH...
Definition ssdp_device.c:1144
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,...
Definition ssdp_ctrlpt.c:76
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...
Definition ssdp_device.c:857
int unique_service_name(char *cmd, SsdpEvent *Evt)
Fills the fields of the event structure like DeviceType, Device UDN and Service Type.
Definition ssdp_server.c:543
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.
Definition ssdp_device.c:1106
SsdpSearchType
Definition ssdplib.h:67
int readFromSSDPSocket(SOCKET socket)
This function reads the data from the ssdp socket.
Definition ssdp_server.c:808
@ SSDP_SERROR
Definition ssdplib.h:69
int SOCKET
Definition UpnpInet.h:48
int UpnpDevice_Handle
Returned when a device application registers with UpnpRegisterRootDevice, UpnpRegisterRootDevice2,...
Definition upnp.h:439
Definition miniserver.h:46
Definition ssdplib.h:109
Definition ssdplib.h:130
Definition httpparser.h:182
Definition httpparser.h:217
Definition ssdplib.h:160
Definition ssdplib.h:146
Definition ssdplib.h:154
Definition ssdplib.h:138