libUPnP 22.2.3
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 DEFAULT_MAX_HEADER_SIZE 16384
56
57#define NUM_HANDLE 200
58
59extern size_t g_maxContentLength;
60extern size_t g_maxHeaderSize;
61extern int g_UpnpSdkEQMaxLen;
62extern int g_UpnpSdkEQMaxAge;
63
64/* 30-second timeout */
65#define UPNP_TIMEOUT 30
66
67typedef enum
68{
69 HND_INVALID = -1,
70 HND_CLIENT,
71 HND_DEVICE
72} Upnp_Handle_Type;
73
74/* Data to be stored in handle table for */
76{
78 Upnp_Handle_Type HType;
82 char *Cookie;
85
86 /* Device Only */
87#ifdef INCLUDE_DEVICE_APIS
89 char DescURL[LINE_SIZE];
92 char LowerDescURL[LINE_SIZE];
94 char DescXML[LINE_SIZE];
95 /* Advertisement timeout */
96 int MaxAge;
97 /* Power State as defined by UPnP Low Power. */
98 int PowerState;
99 /* Sleep Period as defined by UPnP Low Power. */
100 int SleepPeriod;
101 /* Registration State as defined by UPnP Low Power. */
102 int RegistrationState;
110 service_table ServiceTable;
117#endif
118
119 /* Client only */
120#ifdef INCLUDE_CLIENT_APIS
125#endif
126};
127
128extern ithread_rwlock_t GlobalHndRWLock;
129
135static enum Upnp_LogLevel_e debug_handle = UPNP_NEVER;
136#if defined(__GNUC__)
137 #pragma GCC diagnostic push
138 #pragma GCC diagnostic ignored "-Wunused-function"
139#endif
140Upnp_Handle_Type GetHandleInfo(
142 int Hnd,
144 struct Handle_Info **HndInfo);
145
146static void HandleUnlock(const char *file, int line)
147{
148 UpnpPrintf(debug_handle, API, file, line, "Trying Unlock\n");
149 ithread_rwlock_unlock(&GlobalHndRWLock);
150 UpnpPrintf(debug_handle, API, file, line, "Unlocked rwlock\n");
151}
152
153static void HandleReadLock(const char *file, int line)
154{
155 UpnpPrintf(debug_handle, API, file, line, "Trying a read lock\n");
156 ithread_rwlock_rdlock(&GlobalHndRWLock);
157 UpnpPrintf(debug_handle, API, file, line, "Read lock acquired\n");
158}
159
160static void HandleWriteLock(const char *file, int line)
161{
162 UpnpPrintf(debug_handle, API, file, line, "Trying a write lock\n");
163 ithread_rwlock_wrlock(&GlobalHndRWLock);
164 UpnpPrintf(debug_handle, API, file, line, "Write lock acquired\n");
165}
166
167static void HandleLock(const char *file, int line)
168{
169 HandleWriteLock(file, line);
170}
171#if defined(__GNUC__)
172 #pragma GCC diagnostic pop
173#endif
174
182Upnp_Handle_Type GetClientHandleInfo(
184 int *client_handle_out,
186 struct Handle_Info **HndInfo);
187
188#ifdef INCLUDE_CLIENT_APIS
190typedef struct ctrlpt_cb
191{
192 int handle;
195 ithread_t thread;
196 struct ctrlpt_cb *next;
198
206 CtrlptCallback *self,
208 int handle,
210 int searchId);
211
215 CtrlptCallback *self);
216
225 int handle,
228 int searchId,
231 const CtrlptCallback *self);
232#endif /* INCLUDE_CLIENT_APIS */
233
242Upnp_Handle_Type GetDeviceHandleInfo(
244 UpnpDevice_Handle start,
246 int AddressFamily,
248 int *device_handle_out,
250 struct Handle_Info **HndInfo);
251
259Upnp_Handle_Type GetDeviceHandleInfoForPath(
261 const char *path,
263 int AddressFamily,
265 int *device_handle_out,
267 struct Handle_Info **HndInfo,
269 service_info **serv_info);
270
271extern char gIF_NAME[LINE_SIZE];
272extern char gIF_IPV4[INET_ADDRSTRLEN];
273extern char gIF_IPV4_NETMASK[INET_ADDRSTRLEN];
274extern char gIF_IPV6[INET6_ADDRSTRLEN];
275extern unsigned gIF_IPV6_PREFIX_LENGTH;
276
277extern char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN];
278extern unsigned gIF_IPV6_ULA_GUA_PREFIX_LENGTH;
279
280extern unsigned gIF_INDEX;
281
282extern unsigned short LOCAL_PORT_V4;
283extern unsigned short LOCAL_PORT_V6;
284extern unsigned short LOCAL_PORT_V6_ULA_GUA;
285
288
293
294typedef enum
295{
296 SUBSCRIBE,
297 UNSUBSCRIBE,
298 DK_NOTIFY,
299 QUERY,
300 ACTION,
301 STATUS,
302 DEVDESCRIPTION,
303 SERVDESCRIPTION,
304 MINI,
305 RENEW
306} UpnpFunName;
307
309{
310 UpnpFunName FunName;
311 int Handle;
312 int TimeOut;
313 char VarName[NAME_SIZE];
314 char NewVal[NAME_SIZE];
315 char DevType[NAME_SIZE];
316 char DevId[NAME_SIZE];
317 char ServiceType[NAME_SIZE];
318 char ServiceVer[NAME_SIZE];
319 char Url[NAME_SIZE];
320 Upnp_SID SubsId;
321 char *Cookie;
322 Upnp_FunPtr Fun;
323 IXML_Document *Header;
324 IXML_Document *Act;
325 struct DevDesc *Devdesc;
326};
327
328extern virtualDirList *pVirtualDirList;
329extern ithread_mutex_t gWebServerSettingsMutex;
331
332typedef enum
333{
334 WEB_SERVER_DISABLED,
335 WEB_SERVER_ENABLED
336} WebServerState;
337
338#define E_HTTP_SYNTAX -6
339
359int UpnpGetIfInfo(
361 const char *IfName);
362
368void UpnpSetIfAddrStrings(int valid_v4_addr_found,
369 const struct in_addr *v4_addr,
370 const struct in_addr *v4_netmask,
371 char *out_v4,
372 size_t out_v4_len,
373 char *out_v4_netmask,
374 size_t out_v4_netmask_len,
375 int valid_v6_addr_found,
376 const struct in6_addr *v6_addr,
377 char *out_v6,
378 size_t out_v6_len);
379
382 void *input);
383
390 void *input);
391
400
402extern WebServerState bWebServerState;
403
405extern WebCallback_HostValidate gWebCallback_HostValidate;
406
409
412
413#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:165
unsigned gIF_IPV6_ULA_GUA_PREFIX_LENGTH
Definition upnpapi.c:194
char Upnp_SID[44]
Holds the subscription identifier for a subscription between a client and a device.
Definition upnp.h:448
void ctrlpt_callback_enter(CtrlptCallback *self, int handle, int searchId)
Marks a control point callback as running. Called with the handle lock held, so whoever ends the sear...
Definition upnpapi.c:1692
struct VirtualDirCallbacks virtualDirCallback
Definition upnpapi.c:126
ThreadPool gSendThreadPool
Definition upnpapi.c:153
char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN]
Definition upnpapi.c:191
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:3802
void ctrlpt_callback_leave(CtrlptCallback *self)
Marks a control point callback as finished.
Definition upnpapi.c:1703
void UpnpThreadDistribution(void *input)
Schedule async functions in threadpool.
Definition upnpapi.c:4273
ThreadPool gRecvThreadPool
Definition upnpapi.c:156
ithread_mutex_t gWebServerSettingsMutex
Definition upnpapi.c:133
unsigned short LOCAL_PORT_V6_ULA_GUA
Definition upnpapi.c:206
void ctrlpt_wait_callbacks(int handle, int searchId, const CtrlptCallback *self)
Waits until no callback of the given client is running: the callbacks of the given search,...
Definition upnpapi.c:1715
int gAllowLiteralHostRedirection
Definition upnpapi.c:171
int PrintHandleInfo(UpnpClient_Handle Hnd)
Print handle info.
Definition upnpapi.c:4542
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:4453
unsigned gIF_IPV6_PREFIX_LENGTH
Definition upnpapi.c:187
void * gWebCallback_HostValidateCookie
Definition upnpapi.c:168
size_t g_maxContentLength
Definition upnpapi.c:220
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:227
char gIF_NAME[(size_t) 180]
Definition upnpapi.c:174
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:3826
unsigned short LOCAL_PORT_V6
Definition upnpapi.c:203
unsigned short LOCAL_PORT_V4
Definition upnpapi.c:200
ithread_rwlock_t GlobalHndRWLock
Definition upnpapi.c:141
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:4416
char gIF_IPV4[INET_ADDRSTRLEN]
Definition upnpapi.c:177
TimerThread gTimerThread
Definition upnpapi.c:150
unsigned gIF_INDEX
Definition upnpapi.c:197
ThreadPool gMiniServerThreadPool
Definition upnpapi.c:159
char gIF_IPV4_NETMASK[INET_ADDRSTRLEN]
Definition upnpapi.c:180
int g_UpnpSdkEQMaxAge
Definition upnpapi.c:237
char gIF_IPV6[INET6_ADDRSTRLEN]
Definition upnpapi.c:184
Upnp_Handle_Type GetHandleInfo(int Hnd, struct Handle_Info **HndInfo)
Definition upnpapi.c:4499
Upnp_Handle_Type GetClientHandleInfo(int *client_handle_out, struct Handle_Info **HndInfo)
Get client handle info.
Definition upnpapi.c:4396
WebServerState bWebServerState
Definition upnpapi.c:162
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:76
Upnp_Handle_Type HType
Definition upnpapi.h:78
IXML_NodeList * ServiceList
Definition upnpapi.h:108
int aliasInstalled
Definition upnpapi.h:84
GenlibClientSubscription * ClientSubList
Definition upnpapi.h:122
service_table ServiceTable
Definition upnpapi.h:110
char DescURL[(size_t) 180]
Definition upnpapi.h:89
char DescXML[(size_t) 180]
Definition upnpapi.h:94
IXML_Document * DescDocument
Definition upnpapi.h:104
char LowerDescURL[(size_t) 180]
Definition upnpapi.h:92
char * Cookie
Definition upnpapi.h:82
Upnp_FunPtr Callback
Definition upnpapi.h:80
int MaxSubscriptionTimeOut
Definition upnpapi.h:114
int MaxSubscriptions
Definition upnpapi.h:112
LinkedList SsdpSearchList
Definition upnpapi.h:124
IXML_NodeList * DeviceList
Definition upnpapi.h:106
int DeviceAf
Definition upnpapi.h:116
Definition upnpapi.h:309
Definition VirtualDir.h:11
Definition upnpapi.h:191
int searchId
Definition upnpapi.h:194
static enum Upnp_LogLevel_e debug_handle
Get handle information.
Definition upnpapi.h:135
struct ctrlpt_cb CtrlptCallback
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