libUPnP 22.2.1
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
43
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 SSDP_PORT_STR "1900"
83#define NUM_TRY 3
84#define THREAD_LIMIT 50
85#define COMMAND_LEN 300
86
88#ifndef X_USER_AGENT
95 #define X_USER_AGENT "redsonic"
96#endif
97
99#define NO_ERROR_FOUND 0
100#define E_REQUEST_INVALID -3
101#define E_RES_EXPIRED -4
102#define E_MEM_ALLOC -5
103#define E_HTTP_SYNTEX -6
104#define E_SOCKET -7
105
106#define RQST_TIMEOUT 20
107
109typedef struct SsdpEventStruct
110{
111 enum SsdpSearchType RequestType;
112 int ErrCode;
113 int MaxAge;
114 int Mx;
115 char UDN[LINE_SIZE];
116 char DeviceType[LINE_SIZE];
117 /* NT or ST */
118 char ServiceType[LINE_SIZE];
119 char Location[LINE_SIZE];
120 char HostAddr[LINE_SIZE];
121 char Os[LINE_SIZE];
122 char Ext[LINE_SIZE];
123 char Date[LINE_SIZE];
124 struct sockaddr *DestAddr;
125 void *Cookie;
127
128typedef void (*SsdpFunPtr)(SsdpEvent *);
129
130typedef struct TData
131{
132 int Mx;
133 void *Cookie;
134 char *Data;
135 struct sockaddr_storage DestAddr;
136} ThreadData;
137
138typedef struct ssdpsearchreply
139{
140 int MaxAge;
141 UpnpDevice_Handle handle;
142 struct sockaddr_storage dest_addr;
143 SsdpEvent event;
144} SsdpSearchReply;
145
146typedef struct ssdpsearcharg
147{
148 int timeoutEventId;
149 char *searchTarget;
150 void *cookie;
151 enum SsdpSearchType requestType;
152} SsdpSearchArg;
153
154typedef struct ssdpsearchexparg
155{
156 int handle;
157 int timeoutEventId;
158} SsdpSearchExpArg;
159
160typedef struct
161{
162 http_parser_t parser;
163 struct sockaddr_storage dest_addr;
165
166/* globals */
167
168#ifdef INCLUDE_CLIENT_APIS
169extern SOCKET gSsdpReqSocket4;
170 #ifdef UPNP_ENABLE_IPV6
171extern SOCKET gSsdpReqSocket6;
172 #endif /* UPNP_ENABLE_IPV6 */
173#endif /* INCLUDE_CLIENT_APIS */
174typedef int (*ParserFun)(char *, SsdpEvent *);
175
181
188 /* [in] -1 = Send shutdown, 0 = send reply, 1 = Send Advertisement. */
189 int AdFlag,
190 /* [in] Device handle. */
192 /* [in] Search type for sending replies. */
193 enum SsdpSearchType SearchType,
194 /* [in] Destination address. */
195 struct sockaddr *DestAddr,
196 /* [in] Device type. */
197 char *DeviceType,
198 /* [in] Device UDN. */
199 char *DeviceUDN,
200 /* [in] Service type. */
201 char *ServiceType,
202 /* [in] Advertisement age. */
203 int Exp);
204
212 /* [in] Service Name string. */
213 char *cmd,
214 /* [out] The SSDP event structure partially filled by all the
215 * function. */
216 SsdpEvent *Evt);
217
226 /* [in] command came in the ssdp request. */
227 char *cmd);
228
236 /* [in] command came in the ssdp request. */
237 char *cmd,
238 /* [out] The event structure partially filled by this function. */
239 SsdpEvent *Evt);
240
247 /* [in] SSDP socket. */
248 SOCKET socket);
249
257 /* [out] Array of SSDP sockets. */
258 MiniServerSockArray *out);
259
260/* @} SSDP Server Functions */
261
267
274 /* [in] SSDP message from the device. */
275 http_message_t *hmsg,
276 /* [in] Address of the device. */
277 struct sockaddr_storage *dest_addr,
278 /* [in] timeout kept by the control point while sending search message.
279 * Only in search reply. */
280 int timeout);
281
288 /* [in] Client handle. */
289 int handle,
290 /* [in] timeoutEventId of the search, or -1 for every search of the
291 * handle. */
292 int searchId);
293
312 /* [in] The handle of the client performing the search. */
313 int Hnd,
314 /* [in] Number of seconds to wait, to collect all the responses. */
315 int Mx,
316 /* [in] Search target. */
317 char *St,
318 /* [in] Cookie provided by control point application. This cokie will
319 * be returned to application in the callback. */
320 void *Cookie);
321
322/* @} SSDP Control Point Functions */
323
329
335 /* [in] Structure containing the search request. */
336 void *data);
337
343#ifdef INCLUDE_DEVICE_APIS
345 /* [in] . */
346 http_message_t *hmsg,
347 /* [in] . */
348 struct sockaddr_storage *dest_addr);
349#else /* INCLUDE_DEVICE_APIS */
351 /* [in] . */
352 http_message_t *hmsg,
353 /* [in] . */
354 struct sockaddr_storage *dest_addr)
355{
356}
357#endif /* INCLUDE_DEVICE_APIS */
358
366 /* [in] type of the device. */
367 char *DevType,
368 /* [in] flag to indicate if the device is root device. */
369 int RootDev,
370 /* [in] UDN. */
371 char *Udn,
372 /* [in] Location URL. */
373 char *Location,
374 /* [in] Service duration in sec. */
375 int Duration,
376 /* [in] Device address family. */
377 int AddressFamily,
378 /* [in] PowerState as defined by UPnP Low Power. */
379 int PowerState,
380 /* [in] SleepPeriod as defined by UPnP Low Power. */
381 int SleepPeriod,
382 /* [in] RegistrationState as defined by UPnP Low Power. */
383 int RegistrationState);
384
391int SendReply(
392 /* [in] destination IP address. */
393 struct sockaddr *DestAddr,
394 /* [in] Device type. */
395 char *DevType,
396 /* [in] 1 means root device 0 means embedded device. */
397 int RootDev,
398 /* [in] Device UDN. */
399 char *Udn,
400 /* [in] Location of Device description document. */
401 char *Location,
402 /* [in] Life time of this device. */
403 int Duration,
404 /* [in] . */
405 int ByType,
406 /* [in] PowerState as defined by UPnP Low Power. */
407 int PowerState,
408 /* [in] SleepPeriod as defined by UPnP Low Power. */
409 int SleepPeriod,
410 /* [in] RegistrationState as defined by UPnP Low Power. */
411 int RegistrationState);
412
419int DeviceReply(
420 /* [in] destination IP address. */
421 struct sockaddr *DestAddr,
422 /* [in] Device type. */
423 char *DevType,
424 /* [in] 1 means root device 0 means embedded device. */
425 int RootDev,
426 /* [in] Device UDN. */
427 char *Udn,
428 /* [in] Location of Device description document. */
429 char *Location,
430 /* [in] Life time of this device. */
431 int Duration,
432 /* [in] PowerState as defined by UPnP Low Power. */
433 int PowerState,
434 /* [in] SleepPeriod as defined by UPnP Low Power. */
435 int SleepPeriod,
436 /* [in] RegistrationState as defined by UPnP Low Power. */
437 int RegistrationState);
438
446 /* [in] Device UDN. */
447 char *Udn,
448 /* [in] Service Type. */
449 char *ServType,
450 /* [in] Location of Device description document. */
451 char *Location,
452 /* [in] Life time of this device. */
453 int Duration,
454 /* [in] Device address family. */
455 int AddressFamily,
456 /* [in] PowerState as defined by UPnP Low Power. */
457 int PowerState,
458 /* [in] SleepPeriod as defined by UPnP Low Power. */
459 int SleepPeriod,
460 /* [in] RegistrationState as defined by UPnP Low Power. */
461 int RegistrationState);
462
469int ServiceReply(
470 /* [in] . */
471 struct sockaddr *DestAddr,
472 /* [in] Service Type. */
473 char *ServType,
474 /* [in] Device UDN. */
475 char *Udn,
476 /* [in] Location of Device description document. */
477 char *Location,
478 /* [in] Life time of this device. */
479 int Duration,
480 /* [in] PowerState as defined by UPnP Low Power. */
481 int PowerState,
482 /* [in] SleepPeriod as defined by UPnP Low Power. */
483 int SleepPeriod,
484 /* [in] RegistrationState as defined by UPnP Low Power. */
485 int RegistrationState);
486
494 /* [in] Device UDN. */
495 char *Udn,
496 /* [in] Service Type. */
497 char *ServType,
498 /* [in] Location of Device description document. */
499 char *Location,
500 /* [in] Service duration in sec. */
501 int Duration,
502 /* [in] Device address family. */
503 int AddressFamily,
504 /* [in] PowerState as defined by UPnP Low Power. */
505 int PowerState,
506 /* [in] SleepPeriod as defined by UPnP Low Power. */
507 int SleepPeriod,
508 /* [in] RegistrationState as defined by UPnP Low Power. */
509 int RegistrationState);
510
518 /* [in] Device Type. */
519 char *DevType,
520 /* [in] 1 means root device. */
521 int RootDev,
522 /* [in] Device UDN. */
523 char *Udn,
524 /* [in] Location URL. */
525 char *Location,
526 /* [in] Device duration in sec. */
527 int Duration,
528 /* [in] Device address family. */
529 int AddressFamily,
530 /* [in] PowerState as defined by UPnP Low Power. */
531 int PowerState,
532 /* [in] SleepPeriod as defined by UPnP Low Power. */
533 int SleepPeriod,
534 /* [in] RegistrationState as defined by UPnP Low Power. */
535 int RegistrationState);
536
537/* @} SSDP Device Functions */
538
539/* @} SSDPlib SSDP Library */
540
541#endif /* SSDPLIB_H */
#define UPNP_INLINE
Declares an inline function.
Definition UpnpGlobal.h:115
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:686
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:1090
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:103
int ssdp_request_type(char *cmd, SsdpEvent *Evt)
Starts filling the SSDP event structure based upon the request received.
Definition ssdp_server.c:663
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:878
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:1489
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:1352
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:89
enum SsdpSearchType SType
void ssdp_wait_search_callbacks(int handle, int searchId)
Waits until no search result callback of the given search is running. Returns at once when called fro...
Definition ssdp_ctrlpt.c:162
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:648
void advertiseAndReplyThread(void *data)
Wrapper function to reply the search request coming from the control point.
Definition ssdp_device.c:73
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:1180
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:1285
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:188
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:998
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:556
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:1247
SsdpSearchType
Definition ssdplib.h:67
int readFromSSDPSocket(SOCKET socket)
This function reads the data from the ssdp socket.
Definition ssdp_server.c:821
@ SSDP_SERROR
Definition ssdplib.h:69
int SOCKET
Definition UpnpInet.h:50
int UpnpDevice_Handle
Returned when a device application registers with UpnpRegisterRootDevice, UpnpRegisterRootDevice2,...
Definition upnp.h:439
Definition ssdplib.h:110
Definition ssdplib.h:131
Definition httpparser.h:181
Definition httpparser.h:216
Definition ssdplib.h:161
Definition ssdplib.h:147
Definition ssdplib.h:155
Definition ssdplib.h:139