libUPnP 1.14.17
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
244 /* [in] SSDP socket. */
245 SOCKET socket);
246
254 /* [out] Array of SSDP sockets. */
256
257/* @} SSDP Server Functions */
258
271 /* [in] SSDP message from the device. */
272 http_message_t *hmsg,
273 /* [in] Address of the device. */
274 struct sockaddr_storage *dest_addr,
275 /* [in] timeout kept by the control point while sending search message.
276 * Only in search reply. */
277 int timeout);
278
297 /* [in] The handle of the client performing the search. */
298 int Hnd,
299 /* [in] Number of seconds to wait, to collect all the responses. */
300 int Mx,
301 /* [in] Search target. */
302 char *St,
303 /* [in] Cookie provided by control point application. This cokie will
304 * be returned to application in the callback. */
305 void *Cookie);
306
307/* @} SSDP Control Point Functions */
308
320 /* [in] Structure containing the search request. */
321 void *data);
322
328#ifdef INCLUDE_DEVICE_APIS
330 /* [in] . */
331 http_message_t *hmsg,
332 /* [in] . */
333 struct sockaddr_storage *dest_addr);
334#else /* INCLUDE_DEVICE_APIS */
336 /* [in] . */
337 http_message_t *hmsg,
338 /* [in] . */
339 struct sockaddr_storage *dest_addr)
340{
341}
342#endif /* INCLUDE_DEVICE_APIS */
343
351 /* [in] type of the device. */
352 char *DevType,
353 /* [in] flag to indicate if the device is root device. */
354 int RootDev,
355 /* [in] UDN. */
356 char *Udn,
357 /* [in] Location URL. */
358 char *Location,
359 /* [in] Service duration in sec. */
360 int Duration,
361 /* [in] Device address family. */
362 int AddressFamily,
363 /* [in] PowerState as defined by UPnP Low Power. */
364 int PowerState,
365 /* [in] SleepPeriod as defined by UPnP Low Power. */
366 int SleepPeriod,
367 /* [in] RegistrationState as defined by UPnP Low Power. */
368 int RegistrationState);
369
376int SendReply(
377 /* [in] destination IP address. */
378 struct sockaddr *DestAddr,
379 /* [in] Device type. */
380 char *DevType,
381 /* [in] 1 means root device 0 means embedded device. */
382 int RootDev,
383 /* [in] Device UDN. */
384 char *Udn,
385 /* [in] Location of Device description document. */
386 char *Location,
387 /* [in] Life time of this device. */
388 int Duration,
389 /* [in] . */
390 int ByType,
391 /* [in] PowerState as defined by UPnP Low Power. */
392 int PowerState,
393 /* [in] SleepPeriod as defined by UPnP Low Power. */
394 int SleepPeriod,
395 /* [in] RegistrationState as defined by UPnP Low Power. */
396 int RegistrationState);
397
404int DeviceReply(
405 /* [in] destination IP address. */
406 struct sockaddr *DestAddr,
407 /* [in] Device type. */
408 char *DevType,
409 /* [in] 1 means root device 0 means embedded device. */
410 int RootDev,
411 /* [in] Device UDN. */
412 char *Udn,
413 /* [in] Location of Device description document. */
414 char *Location,
415 /* [in] Life time of this device. */
416 int Duration,
417 /* [in] PowerState as defined by UPnP Low Power. */
418 int PowerState,
419 /* [in] SleepPeriod as defined by UPnP Low Power. */
420 int SleepPeriod,
421 /* [in] RegistrationState as defined by UPnP Low Power. */
422 int RegistrationState);
423
431 /* [in] Device UDN. */
432 char *Udn,
433 /* [in] Service Type. */
434 char *ServType,
435 /* [in] Location of Device description document. */
436 char *Location,
437 /* [in] Life time of this device. */
438 int Duration,
439 /* [in] Device address family. */
440 int AddressFamily,
441 /* [in] PowerState as defined by UPnP Low Power. */
442 int PowerState,
443 /* [in] SleepPeriod as defined by UPnP Low Power. */
444 int SleepPeriod,
445 /* [in] RegistrationState as defined by UPnP Low Power. */
446 int RegistrationState);
447
454int ServiceReply(
455 /* [in] . */
456 struct sockaddr *DestAddr,
457 /* [in] Service Type. */
458 char *ServType,
459 /* [in] Device UDN. */
460 char *Udn,
461 /* [in] Location of Device description document. */
462 char *Location,
463 /* [in] Life time of this device. */
464 int Duration,
465 /* [in] PowerState as defined by UPnP Low Power. */
466 int PowerState,
467 /* [in] SleepPeriod as defined by UPnP Low Power. */
468 int SleepPeriod,
469 /* [in] RegistrationState as defined by UPnP Low Power. */
470 int RegistrationState);
471
479 /* [in] Device UDN. */
480 char *Udn,
481 /* [in] Service Type. */
482 char *ServType,
483 /* [in] Location of Device description document. */
484 char *Location,
485 /* [in] Service duration in sec. */
486 int Duration,
487 /* [in] Device address family. */
488 int AddressFamily,
489 /* [in] PowerState as defined by UPnP Low Power. */
490 int PowerState,
491 /* [in] SleepPeriod as defined by UPnP Low Power. */
492 int SleepPeriod,
493 /* [in] RegistrationState as defined by UPnP Low Power. */
494 int RegistrationState);
495
503 /* [in] Device Type. */
504 char *DevType,
505 /* [in] 1 means root device. */
506 int RootDev,
507 /* [in] Device UDN. */
508 char *Udn,
509 /* [in] Location URL. */
510 char *Location,
511 /* [in] Device duration in sec. */
512 int Duration,
513 /* [in] Device address family. */
514 int AddressFamily,
515 /* [in] PowerState as defined by UPnP Low Power. */
516 int PowerState,
517 /* [in] SleepPeriod as defined by UPnP Low Power. */
518 int SleepPeriod,
519 /* [in] RegistrationState as defined by UPnP Low Power. */
520 int RegistrationState);
521
522/* @} SSDP Device Functions */
523
524/* @} SSDPlib SSDP Library */
525
526#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:1478
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 readFromSSDPSocket(SOCKET socket)
This function reads the data from the ssdp socket.
Definition: ssdp_server.c:808
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
@ SSDP_SERROR
Definition: ssdplib.h:69
int SOCKET
Definition: UpnpInet.h:49
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