libUPnP 22.2.2
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
289 /* [in] Client handle. */
290 int handle,
291 /* [in] timeoutEventId of the search, or -1 for every callback of the
292 * handle. */
293 int searchId);
294
313 /* [in] The handle of the client performing the search. */
314 int Hnd,
315 /* [in] Number of seconds to wait, to collect all the responses. */
316 int Mx,
317 /* [in] Search target. */
318 char *St,
319 /* [in] Cookie provided by control point application. This cokie will
320 * be returned to application in the callback. */
321 void *Cookie);
322
323/* @} SSDP Control Point Functions */
324
330
336 /* [in] Structure containing the search request. */
337 void *data);
338
344#ifdef INCLUDE_DEVICE_APIS
346 /* [in] . */
347 http_message_t *hmsg,
348 /* [in] . */
349 struct sockaddr_storage *dest_addr);
350#else /* INCLUDE_DEVICE_APIS */
352 /* [in] . */
353 http_message_t *hmsg,
354 /* [in] . */
355 struct sockaddr_storage *dest_addr)
356{
357}
358#endif /* INCLUDE_DEVICE_APIS */
359
367 /* [in] type of the device. */
368 char *DevType,
369 /* [in] flag to indicate if the device is root device. */
370 int RootDev,
371 /* [in] UDN. */
372 char *Udn,
373 /* [in] Location URL. */
374 char *Location,
375 /* [in] Service duration in sec. */
376 int Duration,
377 /* [in] Device address family. */
378 int AddressFamily,
379 /* [in] PowerState as defined by UPnP Low Power. */
380 int PowerState,
381 /* [in] SleepPeriod as defined by UPnP Low Power. */
382 int SleepPeriod,
383 /* [in] RegistrationState as defined by UPnP Low Power. */
384 int RegistrationState);
385
392int SendReply(
393 /* [in] destination IP address. */
394 struct sockaddr *DestAddr,
395 /* [in] Device type. */
396 char *DevType,
397 /* [in] 1 means root device 0 means embedded device. */
398 int RootDev,
399 /* [in] Device UDN. */
400 char *Udn,
401 /* [in] Location of Device description document. */
402 char *Location,
403 /* [in] Life time of this device. */
404 int Duration,
405 /* [in] . */
406 int ByType,
407 /* [in] PowerState as defined by UPnP Low Power. */
408 int PowerState,
409 /* [in] SleepPeriod as defined by UPnP Low Power. */
410 int SleepPeriod,
411 /* [in] RegistrationState as defined by UPnP Low Power. */
412 int RegistrationState);
413
420int DeviceReply(
421 /* [in] destination IP address. */
422 struct sockaddr *DestAddr,
423 /* [in] Device type. */
424 char *DevType,
425 /* [in] 1 means root device 0 means embedded device. */
426 int RootDev,
427 /* [in] Device UDN. */
428 char *Udn,
429 /* [in] Location of Device description document. */
430 char *Location,
431 /* [in] Life time of this device. */
432 int Duration,
433 /* [in] PowerState as defined by UPnP Low Power. */
434 int PowerState,
435 /* [in] SleepPeriod as defined by UPnP Low Power. */
436 int SleepPeriod,
437 /* [in] RegistrationState as defined by UPnP Low Power. */
438 int RegistrationState);
439
447 /* [in] Device UDN. */
448 char *Udn,
449 /* [in] Service Type. */
450 char *ServType,
451 /* [in] Location of Device description document. */
452 char *Location,
453 /* [in] Life time of this device. */
454 int Duration,
455 /* [in] Device address family. */
456 int AddressFamily,
457 /* [in] PowerState as defined by UPnP Low Power. */
458 int PowerState,
459 /* [in] SleepPeriod as defined by UPnP Low Power. */
460 int SleepPeriod,
461 /* [in] RegistrationState as defined by UPnP Low Power. */
462 int RegistrationState);
463
470int ServiceReply(
471 /* [in] . */
472 struct sockaddr *DestAddr,
473 /* [in] Service Type. */
474 char *ServType,
475 /* [in] Device UDN. */
476 char *Udn,
477 /* [in] Location of Device description document. */
478 char *Location,
479 /* [in] Life time of this device. */
480 int Duration,
481 /* [in] PowerState as defined by UPnP Low Power. */
482 int PowerState,
483 /* [in] SleepPeriod as defined by UPnP Low Power. */
484 int SleepPeriod,
485 /* [in] RegistrationState as defined by UPnP Low Power. */
486 int RegistrationState);
487
495 /* [in] Device UDN. */
496 char *Udn,
497 /* [in] Service Type. */
498 char *ServType,
499 /* [in] Location of Device description document. */
500 char *Location,
501 /* [in] Service duration in sec. */
502 int Duration,
503 /* [in] Device address family. */
504 int AddressFamily,
505 /* [in] PowerState as defined by UPnP Low Power. */
506 int PowerState,
507 /* [in] SleepPeriod as defined by UPnP Low Power. */
508 int SleepPeriod,
509 /* [in] RegistrationState as defined by UPnP Low Power. */
510 int RegistrationState);
511
519 /* [in] Device Type. */
520 char *DevType,
521 /* [in] 1 means root device. */
522 int RootDev,
523 /* [in] Device UDN. */
524 char *Udn,
525 /* [in] Location URL. */
526 char *Location,
527 /* [in] Device duration in sec. */
528 int Duration,
529 /* [in] Device address family. */
530 int AddressFamily,
531 /* [in] PowerState as defined by UPnP Low Power. */
532 int PowerState,
533 /* [in] SleepPeriod as defined by UPnP Low Power. */
534 int SleepPeriod,
535 /* [in] RegistrationState as defined by UPnP Low Power. */
536 int RegistrationState);
537
538/* @} SSDP Device Functions */
539
540/* @} SSDPlib SSDP Library */
541
542#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:705
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_wait_ctrlpt_callbacks(int handle, int searchId)
Waits until no discovery callback of the given client is running: search results of the given search,...
Definition ssdp_ctrlpt.c:178
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
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:204
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