libUPnP 2.0.1
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 16000
54#define MAX_SOAP_CONTENT_LENGTH (size_t)32000
55
56#define NUM_HANDLE 200
57
58extern size_t g_maxContentLength;
59extern int g_UpnpSdkEQMaxLen;
60extern int g_UpnpSdkEQMaxAge;
61
62/* 30-second timeout */
63#define UPNP_TIMEOUT 30
64
65typedef enum
66{
67 HND_INVALID = -1,
68 HND_CLIENT,
69 HND_DEVICE
70} Upnp_Handle_Type;
71
72/* Data to be stored in handle table for */
74{
76 Upnp_Handle_Type HType;
80 char *Cookie;
83
84 /* Device Only */
85#ifdef INCLUDE_DEVICE_APIS
87 char DescURL[LINE_SIZE];
90 char LowerDescURL[LINE_SIZE];
92 char DescXML[LINE_SIZE];
93 /* Advertisement timeout */
94 int MaxAge;
95 /* Power State as defined by UPnP Low Power. */
96 int PowerState;
97 /* Sleep Period as defined by UPnP Low Power. */
98 int SleepPeriod;
99 /* Registration State as defined by UPnP Low Power. */
100 int RegistrationState;
108 service_table ServiceTable;
115#endif
116
117 /* Client only */
118#ifdef INCLUDE_CLIENT_APIS
123#endif
124};
125
126extern ithread_rwlock_t GlobalHndRWLock;
127
133static enum Upnp_LogLevel_e debug_handle = UPNP_NEVER;
134#if defined(__GNUC__)
135 #pragma GCC diagnostic push
136 #pragma GCC diagnostic ignored "-Wunused-function"
137#endif
138Upnp_Handle_Type GetHandleInfo(
140 int Hnd,
142 struct Handle_Info **HndInfo);
143
144static void HandleUnlock(const char *file, int line)
145{
146 UpnpPrintf(debug_handle, API, file, line, "Trying Unlock\n");
147 ithread_rwlock_unlock(&GlobalHndRWLock);
148 UpnpPrintf(debug_handle, API, file, line, "Unlocked rwlock\n");
149}
150
151static void HandleReadLock(const char *file, int line)
152{
153 UpnpPrintf(debug_handle, API, file, line, "Trying a read lock\n");
154 ithread_rwlock_rdlock(&GlobalHndRWLock);
155 UpnpPrintf(debug_handle, API, file, line, "Read lock acquired\n");
156}
157
158static void HandleWriteLock(const char *file, int line)
159{
160 UpnpPrintf(debug_handle, API, file, line, "Trying a write lock\n");
161 ithread_rwlock_wrlock(&GlobalHndRWLock);
162 UpnpPrintf(debug_handle, API, file, line, "Write lock acquired\n");
163}
164
165static void HandleLock(const char *file, int line)
166{
167 HandleWriteLock(file, line);
168}
169#if defined(__GNUC__)
170 #pragma GCC diagnostic pop
171#endif
172
180Upnp_Handle_Type GetClientHandleInfo(
182 int *client_handle_out,
184 struct Handle_Info **HndInfo);
193Upnp_Handle_Type GetDeviceHandleInfo(
195 UpnpDevice_Handle start,
197 int AddressFamily,
199 int *device_handle_out,
201 struct Handle_Info **HndInfo);
202
210Upnp_Handle_Type GetDeviceHandleInfoForPath(
212 const char *path,
214 int AddressFamily,
216 int *device_handle_out,
218 struct Handle_Info **HndInfo,
220 service_info **serv_info);
221
222extern char gIF_NAME[LINE_SIZE];
223extern char gIF_IPV4[INET_ADDRSTRLEN];
224extern char gIF_IPV4_NETMASK[INET_ADDRSTRLEN];
225extern char gIF_IPV6[INET6_ADDRSTRLEN];
226extern unsigned gIF_IPV6_PREFIX_LENGTH;
227
228extern char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN];
229extern unsigned gIF_IPV6_ULA_GUA_PREFIX_LENGTH;
230
231extern unsigned gIF_INDEX;
232
233extern unsigned short LOCAL_PORT_V4;
234extern unsigned short LOCAL_PORT_V6;
235extern unsigned short LOCAL_PORT_V6_ULA_GUA;
236
239
244
245typedef enum
246{
247 SUBSCRIBE,
248 UNSUBSCRIBE,
249 DK_NOTIFY,
250 QUERY,
251 ACTION,
252 STATUS,
253 DEVDESCRIPTION,
254 SERVDESCRIPTION,
255 MINI,
256 RENEW
257} UpnpFunName;
258
260{
261 UpnpFunName FunName;
262 int Handle;
263 int TimeOut;
264 char VarName[NAME_SIZE];
265 char NewVal[NAME_SIZE];
266 char DevType[NAME_SIZE];
267 char DevId[NAME_SIZE];
268 char ServiceType[NAME_SIZE];
269 char ServiceVer[NAME_SIZE];
270 char Url[NAME_SIZE];
271 Upnp_SID SubsId;
272 char *Cookie;
273 Upnp_FunPtr Fun;
274 IXML_Document *Header;
275 IXML_Document *Act;
276 struct DevDesc *Devdesc;
277};
278
279extern virtualDirList *pVirtualDirList;
281
282typedef enum
283{
284 WEB_SERVER_DISABLED,
285 WEB_SERVER_ENABLED
286} WebServerState;
287
288#define E_HTTP_SYNTAX -6
289
309int UpnpGetIfInfo(
311 const char *IfName);
312
313void UpnpThreadDistribution(struct UpnpNonblockParam *Param);
314
321 void *input);
322
331
333extern WebServerState bWebServerState;
334
336extern WebCallback_HostValidate gWebCallback_HostValidate;
337
340
343
344#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:143
unsigned gIF_IPV6_ULA_GUA_PREFIX_LENGTH
Definition upnpapi.c:172
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:108
void UpnpThreadDistribution(struct UpnpNonblockParam *Param)
Schedule async functions in threadpool.
Definition upnpapi.c:4116
ThreadPool gSendThreadPool
Definition upnpapi.c:131
char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN]
Definition upnpapi.c:169
ThreadPool gRecvThreadPool
Definition upnpapi.c:134
unsigned short LOCAL_PORT_V6_ULA_GUA
Definition upnpapi.c:184
int gAllowLiteralHostRedirection
Definition upnpapi.c:149
int PrintHandleInfo(UpnpClient_Handle Hnd)
Print handle info.
Definition upnpapi.c:4382
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:4295
unsigned gIF_IPV6_PREFIX_LENGTH
Definition upnpapi.c:165
void * gWebCallback_HostValidateCookie
Definition upnpapi.c:146
size_t g_maxContentLength
Definition upnpapi.c:198
int UpnpClient_Handle
Returned when a control point application registers with UpnpRegisterClient.
Definition upnp.h:429
virtualDirList * pVirtualDirList
Definition upnpapi.c:111
int g_UpnpSdkEQMaxLen
Definition upnpapi.c:204
char gIF_NAME[(size_t) 180]
Definition upnpapi.c:152
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:3705
unsigned short LOCAL_PORT_V6
Definition upnpapi.c:181
unsigned short LOCAL_PORT_V4
Definition upnpapi.c:178
ithread_rwlock_t GlobalHndRWLock
Definition upnpapi.c:119
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:4258
char gIF_IPV4[INET_ADDRSTRLEN]
Definition upnpapi.c:155
TimerThread gTimerThread
Definition upnpapi.c:128
unsigned gIF_INDEX
Definition upnpapi.c:175
ThreadPool gMiniServerThreadPool
Definition upnpapi.c:137
char gIF_IPV4_NETMASK[INET_ADDRSTRLEN]
Definition upnpapi.c:158
int g_UpnpSdkEQMaxAge
Definition upnpapi.c:214
char gIF_IPV6[INET6_ADDRSTRLEN]
Definition upnpapi.c:162
Upnp_Handle_Type GetHandleInfo(int Hnd, struct Handle_Info **HndInfo)
Definition upnpapi.c:4341
Upnp_Handle_Type GetClientHandleInfo(int *client_handle_out, struct Handle_Info **HndInfo)
Get client handle info.
Definition upnpapi.c:4238
WebServerState bWebServerState
Definition upnpapi.c:140
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:74
Upnp_Handle_Type HType
Definition upnpapi.h:76
IXML_NodeList * ServiceList
Definition upnpapi.h:106
int aliasInstalled
Definition upnpapi.h:82
GenlibClientSubscription * ClientSubList
Definition upnpapi.h:120
service_table ServiceTable
Definition upnpapi.h:108
char DescURL[(size_t) 180]
Definition upnpapi.h:87
char DescXML[(size_t) 180]
Definition upnpapi.h:92
IXML_Document * DescDocument
Definition upnpapi.h:102
char LowerDescURL[(size_t) 180]
Definition upnpapi.h:90
char * Cookie
Definition upnpapi.h:80
Upnp_FunPtr Callback
Definition upnpapi.h:78
int MaxSubscriptionTimeOut
Definition upnpapi.h:112
int MaxSubscriptions
Definition upnpapi.h:110
LinkedList SsdpSearchList
Definition upnpapi.h:122
IXML_NodeList * DeviceList
Definition upnpapi.h:104
int DeviceAf
Definition upnpapi.h:114
Definition upnpapi.h:260
Definition VirtualDir.h:11
static enum Upnp_LogLevel_e debug_handle
Get handle information.
Definition upnpapi.h:133
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:263