libUPnP 22.0.4
upnpapi.h
Go to the documentation of this file.
1/*******************************************************************************
2 *
3 * Copyright (c) 2000-2003 Intel Corporation
4 * All rights reserved.
5 * Copyright (C) 2011-2012 France Telecom All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * * Neither name of Intel Corporation nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 ******************************************************************************/
32
33#ifndef UPNPAPI_H
34#define UPNPAPI_H
35
39
41#include "TimerThread.h"
42#include "VirtualDir.h" /* for struct VirtualDirCallbacks */
43#include "service_table.h"
44
45#define MAX_INTERFACES 256
46
47#define DEV_LIMIT 200
48
49#define DEFAULT_MX 5
50
51#define DEFAULT_MAXAGE 1800
52
53#define DEFAULT_SOAP_CONTENT_LENGTH 64000
54
55#define NUM_HANDLE 200
56
57extern size_t g_maxContentLength;
58extern int g_UpnpSdkEQMaxLen;
59extern int g_UpnpSdkEQMaxAge;
60
61/* 30-second timeout */
62#define UPNP_TIMEOUT 30
63
64typedef enum
65{
66 HND_INVALID = -1,
67 HND_CLIENT,
68 HND_DEVICE
69} Upnp_Handle_Type;
70
71/* Data to be stored in handle table for */
73{
75 Upnp_Handle_Type HType;
79 char *Cookie;
82
83 /* Device Only */
84#ifdef INCLUDE_DEVICE_APIS
86 char DescURL[LINE_SIZE];
89 char LowerDescURL[LINE_SIZE];
91 char DescXML[LINE_SIZE];
92 /* Advertisement timeout */
93 int MaxAge;
94 /* Power State as defined by UPnP Low Power. */
95 int PowerState;
96 /* Sleep Period as defined by UPnP Low Power. */
97 int SleepPeriod;
98 /* Registration State as defined by UPnP Low Power. */
99 int RegistrationState;
107 service_table ServiceTable;
114#endif
115
116 /* Client only */
117#ifdef INCLUDE_CLIENT_APIS
122#endif
123};
124
125extern ithread_rwlock_t GlobalHndRWLock;
126
132static enum Upnp_LogLevel_e debug_handle = UPNP_NEVER;
133#if defined(__GNUC__)
134 #pragma GCC diagnostic push
135 #pragma GCC diagnostic ignored "-Wunused-function"
136#endif
137Upnp_Handle_Type GetHandleInfo(
139 int Hnd,
141 struct Handle_Info **HndInfo);
142
143static void HandleUnlock(const char *file, int line)
144{
145 UpnpPrintf(debug_handle, API, file, line, "Trying Unlock\n");
146 ithread_rwlock_unlock(&GlobalHndRWLock);
147 UpnpPrintf(debug_handle, API, file, line, "Unlocked rwlock\n");
148}
149
150static void HandleReadLock(const char *file, int line)
151{
152 UpnpPrintf(debug_handle, API, file, line, "Trying a read lock\n");
153 ithread_rwlock_rdlock(&GlobalHndRWLock);
154 UpnpPrintf(debug_handle, API, file, line, "Read lock acquired\n");
155}
156
157static void HandleWriteLock(const char *file, int line)
158{
159 UpnpPrintf(debug_handle, API, file, line, "Trying a write lock\n");
160 ithread_rwlock_wrlock(&GlobalHndRWLock);
161 UpnpPrintf(debug_handle, API, file, line, "Write lock acquired\n");
162}
163
164static void HandleLock(const char *file, int line)
165{
166 HandleWriteLock(file, line);
167}
168#if defined(__GNUC__)
169 #pragma GCC diagnostic pop
170#endif
171
179Upnp_Handle_Type GetClientHandleInfo(
181 int *client_handle_out,
183 struct Handle_Info **HndInfo);
192Upnp_Handle_Type GetDeviceHandleInfo(
194 UpnpDevice_Handle start,
196 int AddressFamily,
198 int *device_handle_out,
200 struct Handle_Info **HndInfo);
201
209Upnp_Handle_Type GetDeviceHandleInfoForPath(
211 const char *path,
213 int AddressFamily,
215 int *device_handle_out,
217 struct Handle_Info **HndInfo,
219 service_info **serv_info);
220
221extern char gIF_NAME[LINE_SIZE];
222extern char gIF_IPV4[INET_ADDRSTRLEN];
223extern char gIF_IPV4_NETMASK[INET_ADDRSTRLEN];
224extern char gIF_IPV6[INET6_ADDRSTRLEN];
225extern unsigned gIF_IPV6_PREFIX_LENGTH;
226
227extern char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN];
228extern unsigned gIF_IPV6_ULA_GUA_PREFIX_LENGTH;
229
230extern unsigned gIF_INDEX;
231
232extern unsigned short LOCAL_PORT_V4;
233extern unsigned short LOCAL_PORT_V6;
234extern unsigned short LOCAL_PORT_V6_ULA_GUA;
235
238
243
244typedef enum
245{
246 SUBSCRIBE,
247 UNSUBSCRIBE,
248 DK_NOTIFY,
249 QUERY,
250 ACTION,
251 STATUS,
252 DEVDESCRIPTION,
253 SERVDESCRIPTION,
254 MINI,
255 RENEW
256} UpnpFunName;
257
259{
260 UpnpFunName FunName;
261 int Handle;
262 int TimeOut;
263 char VarName[NAME_SIZE];
264 char NewVal[NAME_SIZE];
265 char DevType[NAME_SIZE];
266 char DevId[NAME_SIZE];
267 char ServiceType[NAME_SIZE];
268 char ServiceVer[NAME_SIZE];
269 char Url[NAME_SIZE];
270 Upnp_SID SubsId;
271 char *Cookie;
272 Upnp_FunPtr Fun;
273 IXML_Document *Header;
274 IXML_Document *Act;
275 struct DevDesc *Devdesc;
276};
277
278extern virtualDirList *pVirtualDirList;
280
281typedef enum
282{
283 WEB_SERVER_DISABLED,
284 WEB_SERVER_ENABLED
285} WebServerState;
286
287#define E_HTTP_SYNTAX -6
288
308int UpnpGetIfInfo(
310 const char *IfName);
311
317void UpnpSetIfAddrStrings(int valid_v4_addr_found,
318 const struct in_addr *v4_addr,
319 const struct in_addr *v4_netmask,
320 char *out_v4,
321 size_t out_v4_len,
322 char *out_v4_netmask,
323 size_t out_v4_netmask_len,
324 int valid_v6_addr_found,
325 const struct in6_addr *v6_addr,
326 char *out_v6,
327 size_t out_v6_len);
328
329void UpnpThreadDistribution(struct UpnpNonblockParam *Param);
330
337 void *input);
338
347
349extern WebServerState bWebServerState;
350
352extern WebCallback_HostValidate gWebCallback_HostValidate;
353
356
359
360#endif /* UPNPAPI_H */
int(* Upnp_FunPtr)(Upnp_EventType EventType, void *Event, void *Cookie)
Definition Callback.h:145
Header file for GenlibClientSubscription methods.
struct s_GenlibClientSubscription GenlibClientSubscription
Definition GenlibClientSubscription.h:27
struct LINKEDLIST LinkedList
struct THREADPOOL ThreadPool
A thread pool similar to the thread pool in the UPnP SDK.
struct TIMERTHREAD TimerThread
WebCallback_HostValidate gWebCallback_HostValidate
Definition upnpapi.c:161
unsigned gIF_IPV6_ULA_GUA_PREFIX_LENGTH
Definition upnpapi.c:190
char Upnp_SID[44]
Holds the subscription identifier for a subscription between a client and a device.
Definition upnp.h:448
struct VirtualDirCallbacks virtualDirCallback
Definition upnpapi.c:126
void UpnpThreadDistribution(struct UpnpNonblockParam *Param)
Schedule async functions in threadpool.
Definition upnpapi.c:4194
ThreadPool gSendThreadPool
Definition upnpapi.c:149
char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN]
Definition upnpapi.c:187
void UpnpSetIfAddrStrings(int valid_v4_addr_found, const struct in_addr *v4_addr, const struct in_addr *v4_netmask, char *out_v4, size_t out_v4_len, char *out_v4_netmask, size_t out_v4_netmask_len, int valid_v6_addr_found, const struct in6_addr *v6_addr, char *out_v6, size_t out_v6_len)
Format the discovered v4/v6 interface addresses into their output string buffers, but only for the ad...
Definition upnpapi.c:3728
ThreadPool gRecvThreadPool
Definition upnpapi.c:152
unsigned short LOCAL_PORT_V6_ULA_GUA
Definition upnpapi.c:202
int gAllowLiteralHostRedirection
Definition upnpapi.c:167
int PrintHandleInfo(UpnpClient_Handle Hnd)
Print handle info.
Definition upnpapi.c:4462
Upnp_Handle_Type GetDeviceHandleInfoForPath(const char *path, int AddressFamily, int *device_handle_out, struct Handle_Info **HndInfo, service_info **serv_info)
Retrieves the device handle and information of the first device of the address family specified,...
Definition upnpapi.c:4373
unsigned gIF_IPV6_PREFIX_LENGTH
Definition upnpapi.c:183
void * gWebCallback_HostValidateCookie
Definition upnpapi.c:164
size_t g_maxContentLength
Definition upnpapi.c:216
int UpnpClient_Handle
Returned when a control point application registers with UpnpRegisterClient.
Definition upnp.h:429
virtualDirList * pVirtualDirList
Definition upnpapi.c:129
int g_UpnpSdkEQMaxLen
Definition upnpapi.c:222
char gIF_NAME[(size_t) 180]
Definition upnpapi.c:170
int UpnpGetIfInfo(const char *IfName)
Retrieve interface information and keep it in global variables. If NULL, we'll find the first suitabl...
Definition upnpapi.c:3752
unsigned short LOCAL_PORT_V6
Definition upnpapi.c:199
unsigned short LOCAL_PORT_V4
Definition upnpapi.c:196
ithread_rwlock_t GlobalHndRWLock
Definition upnpapi.c:137
int UpnpDevice_Handle
Returned when a device application registers with UpnpRegisterRootDevice, UpnpRegisterRootDevice2,...
Definition upnp.h:439
Upnp_Handle_Type GetDeviceHandleInfo(UpnpDevice_Handle start, int AddressFamily, int *device_handle_out, struct Handle_Info **HndInfo)
Retrieves the device handle and information of the first device of the address family specified....
Definition upnpapi.c:4336
char gIF_IPV4[INET_ADDRSTRLEN]
Definition upnpapi.c:173
TimerThread gTimerThread
Definition upnpapi.c:146
unsigned gIF_INDEX
Definition upnpapi.c:193
ThreadPool gMiniServerThreadPool
Definition upnpapi.c:155
char gIF_IPV4_NETMASK[INET_ADDRSTRLEN]
Definition upnpapi.c:176
int g_UpnpSdkEQMaxAge
Definition upnpapi.c:232
char gIF_IPV6[INET6_ADDRSTRLEN]
Definition upnpapi.c:180
Upnp_Handle_Type GetHandleInfo(int Hnd, struct Handle_Info **HndInfo)
Definition upnpapi.c:4419
Upnp_Handle_Type GetClientHandleInfo(int *client_handle_out, struct Handle_Info **HndInfo)
Get client handle info.
Definition upnpapi.c:4316
WebServerState bWebServerState
Definition upnpapi.c:158
struct _IXML_NodeList IXML_NodeList
Data structure representing a list of nodes.
struct _IXML_Document IXML_Document
Data structure representing the DOM Document.
Definition upnpapi.h:73
Upnp_Handle_Type HType
Definition upnpapi.h:75
IXML_NodeList * ServiceList
Definition upnpapi.h:105
int aliasInstalled
Definition upnpapi.h:81
GenlibClientSubscription * ClientSubList
Definition upnpapi.h:119
service_table ServiceTable
Definition upnpapi.h:107
char DescURL[(size_t) 180]
Definition upnpapi.h:86
char DescXML[(size_t) 180]
Definition upnpapi.h:91
IXML_Document * DescDocument
Definition upnpapi.h:101
char LowerDescURL[(size_t) 180]
Definition upnpapi.h:89
char * Cookie
Definition upnpapi.h:79
Upnp_FunPtr Callback
Definition upnpapi.h:77
int MaxSubscriptionTimeOut
Definition upnpapi.h:111
int MaxSubscriptions
Definition upnpapi.h:109
LinkedList SsdpSearchList
Definition upnpapi.h:121
IXML_NodeList * DeviceList
Definition upnpapi.h:103
int DeviceAf
Definition upnpapi.h:113
Definition upnpapi.h:259
Definition VirtualDir.h:11
static enum Upnp_LogLevel_e debug_handle
Get handle information.
Definition upnpapi.h:132
Upnp_SID gUpnpSdkNLSuuid
void AutoAdvertise(void *input)
This function is a timer thread scheduled by UpnpSendAdvertisement to the send advetisement again.
void UpnpPrintf(Upnp_LogLevel DLevel, Dbg_Module Module, const char *DbgFileName, int DbgLineNo, const char *FmtStr,...)
Prints the debug statement either on the standard output or log file along with the information from ...
Definition upnpdebug.c:264