UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
upnpapi.hpp
Go to the documentation of this file.
1#ifndef COMPA_UPNPAPI_HPP
2#define COMPA_UPNPAPI_HPP
3/*******************************************************************************
4 *
5 * Copyright (c) 2000-2003 Intel Corporation
6 * All rights reserved.
7 * Copyright (C) 2011-2012 France Telecom All rights reserved.
8 * Copyright (C) 2021+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
9 * Redistribution only with this Copyright remark. Last modified: 2025-06-11
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * * Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * * Neither name of Intel Corporation nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
31 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************/
36// Last compare with pupnp original source file on 2023-07-08, ver 1.14.17
43#include <VirtualDir.hpp> /* for struct VirtualDirCallbacks */
44#include <client_table.hpp>
45
47#define MAX_INTERFACES 256
48
50#define DEV_LIMIT 200
51
53#define DEFAULT_MX 5
54
56#define DEFAULT_MAXAGE 1800
57
59#define DEFAULT_SOAP_CONTENT_LENGTH 16000
61#define MAX_SOAP_CONTENT_LENGTH (size_t)32000
62
64constexpr int NUM_HANDLE{200};
65
66extern size_t g_maxContentLength;
67extern int g_UpnpSdkEQMaxLen;
68extern int g_UpnpSdkEQMaxAge;
69
71#define UPNP_TIMEOUT 30
72
76 HND_TABLE_INVALID = -2,
77 HND_INVALID,
78 HND_CLIENT,
79 HND_DEVICE
80};
81
82
123
124extern pthread_rwlock_t GlobalHndRWLock;
125
133 int Hnd,
135 struct Handle_Info** HndInfo);
136
138#define HandleLock() HandleWriteLock()
139
141#define HandleWriteLock() pthread_rwlock_wrlock(&GlobalHndRWLock);
142
144#define HandleReadLock() pthread_rwlock_rdlock(&GlobalHndRWLock);
145
147#define HandleUnlock() pthread_rwlock_unlock(&GlobalHndRWLock);
148
149#if 0
151#define HandleWriteLock() \
152 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying a write lock\n"); \
153 pthread_rwlock_wrlock(&GlobalHndRWLock); \
154 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Write lock acquired\n");
155
157#define HandleReadLock() \
158 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying a read lock\n"); \
159 pthread_rwlock_rdlock(&GlobalHndRWLock); \
160 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Read lock acquired\n");
161
163#define HandleUnlock() \
164 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying Unlock\n"); \
165 pthread_rwlock_unlock(&GlobalHndRWLock); \
166 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Unlocked rwlock\n");
167#endif
168
178 int* client_handle_out,
180 struct Handle_Info** HndInfo);
191 UpnpDevice_Handle start,
193 int AddressFamily,
195 int* device_handle_out,
197 struct Handle_Info** HndInfo);
198
208 const char* path,
210 int AddressFamily,
212 int* device_handle_out,
214 struct Handle_Info** HndInfo,
216 service_info** serv_info);
217
218UPnPsdk_VIS extern char gIF_NAME[LINE_SIZE];
219UPnPsdk_VIS extern char gIF_IPV4[INET_ADDRSTRLEN];
220UPnPsdk_VIS extern char gIF_IPV4_NETMASK[INET_ADDRSTRLEN];
221UPnPsdk_VIS extern char gIF_IPV6[INET6_ADDRSTRLEN];
222UPnPsdk_VIS extern unsigned gIF_IPV6_PREFIX_LENGTH;
223
224UPnPsdk_VIS extern char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN];
226
227UPnPsdk_VIS extern unsigned gIF_INDEX;
228
229UPnPsdk_VIS extern unsigned short LOCAL_PORT_V4;
230UPnPsdk_VIS extern unsigned short LOCAL_PORT_V6;
231UPnPsdk_VIS extern unsigned short LOCAL_PORT_V6_ULA_GUA;
232
235
240
242typedef enum {
243 SUBSCRIBE,
244 UNSUBSCRIBE,
245 DK_NOTIFY,
246 QUERY,
247 ACTION,
248 STATUS,
249 DEVDESCRIPTION,
250 SERVDESCRIPTION,
251 MINI,
252 RENEW
254
277
280
282typedef enum { WEB_SERVER_DISABLED, WEB_SERVER_ENABLED } WebServerState;
283
285#define E_HTTP_SYNTAX -6
286
288void UpnpThreadDistribution(struct UpnpNonblockParam* Param);
289
294void AutoAdvertise(
296 void* input);
297
306
309
312
315
318
319#endif /* COMPA_UPNPAPI_HPP */
int(* Upnp_FunPtr)(Upnp_EventType EventType, const void *Event, void *Cookie)
Definition Callback.hpp:143
char Upnp_SID[44]
Holds the subscription identifier for a subscription between a client and a device.
Definition API.hpp:434
#define NAME_SIZE
Definition API.hpp:46
int UpnpClient_Handle
Returned when a control point application registers with UpnpRegisterClient().
Definition API.hpp:415
int UpnpDevice_Handle
Returned when a device application registers with UpnpRegisterRootDevice(),UpnpRegisterRootDevice2(),...
Definition API.hpp:425
#define LINE_SIZE
Definition API.hpp:45
Genlib Client subscription.
Linked list (no protection).
A thread pool.
A timer thread that allows the scheduling of a job to run at a specified time in the future.
Provide the Virtual Directory Callbacks structure.
Virtual directory list.
Data structure representing a list of nodes.
Definition ixml.hpp:193
Data structure representing the DOM Document.
Definition ixml.hpp:155
int(* WebCallback_HostValidate)(const char *hostname, void *cookie)
Callback for validating HTTP requests HOST header values.
Definition API.hpp:2800
table of services
-brief Service information
IXML_Document * Act
UpnpNonblockParam
Definition upnpapi.hpp:273
Upnp_Handle_Type HType
Handle Type.
Definition upnpapi.hpp:85
Upnp_Handle_Type GetHandleInfo(int Hnd, struct Handle_Info **HndInfo)
Get handle information.
Definition upnpapi.cpp:3342
IXML_Document * Header
UpnpNonblockParam
Definition upnpapi.hpp:272
char * Cookie
UpnpNonblockParam
Definition upnpapi.hpp:270
UPnPsdk_VIS WebCallback_HostValidate gWebCallback_HostValidate
webCallback for HOST validation.
Definition upnpapi.cpp:271
IXML_NodeList * ServiceList
List of services in the description document.
Definition upnpapi.hpp:106
int aliasInstalled
0 = not installed; otherwise installed.
Definition upnpapi.hpp:88
int Handle
UpnpNonblockParam
Definition upnpapi.hpp:260
struct VirtualDirCallbacks virtualDirCallback
This structure is for virtual directory callbacks.
Definition upnpapi.cpp:247
void UpnpThreadDistribution(struct UpnpNonblockParam *Param)
UpnpThreadDistribution.
Definition upnpapi.cpp:3142
ThreadPool gSendThreadPool
Send thread pool.
Definition upnpapi.cpp:259
Upnp_FunPtr Fun
UpnpNonblockParam
Definition upnpapi.hpp:271
Upnp_Handle_Type
Definition upnpapi.hpp:75
ThreadPool gRecvThreadPool
Receive thread pool.
Definition upnpapi.cpp:262
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.cpp:3305
UPnPsdk_VIS char gIF_IPV4_NETMASK[INET_ADDRSTRLEN]
Static buffer to contain interface IPv4 netmask. (extern'ed in upnp.h)
Definition upnpapi.cpp:288
char Url[NAME_SIZE]
UpnpNonblockParam
Definition upnpapi.hpp:268
char DescXML[LINE_SIZE]
XML file path for device description.
Definition upnpapi.hpp:97
GenlibClientSubscription * ClientSubList
Client subscription list.
Definition upnpapi.hpp:118
service_table ServiceTable
Table holding subscriptions and URL information.
Definition upnpapi.hpp:108
int SleepPeriod
Sleep Period as defined by UPnP Low Power.
Definition upnpapi.hpp:100
UPnPsdk_VIS char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN]
Static buffer to contain interface IPv6 unique-local or globally-unique address (ULA or GUA)....
Definition upnpapi.cpp:305
int PrintHandleInfo(UpnpClient_Handle Hnd)
Print handle info.
Definition upnpapi.cpp:3364
UPnPsdk_VIS unsigned short LOCAL_PORT_V4
local IPv4 port for the mini-server
Definition upnpapi.cpp:311
Upnp_SID gUpnpSdkNLSuuid
Global variable used in discovery notifications.
Definition upnpapi.cpp:373
pthread_rwlock_t GlobalHndRWLock
rwlock to synchronize handles (root device or control point handle).
Definition upnpapi.cpp:253
UPnPsdk_VIS char gIF_IPV4[INET_ADDRSTRLEN]
Static buffer to contain interface IPv4 address. (extern'ed in upnp.h)
Definition upnpapi.cpp:284
Upnp_Handle_Type GetClientHandleInfo(int *client_handle_out, struct Handle_Info **HndInfo)
Get client handle info.
Definition upnpapi.cpp:3248
UPnPsdk_VIS unsigned short LOCAL_PORT_V6_ULA_GUA
IPv6 ULA or GUA port for the mini-server.
Definition upnpapi.cpp:317
struct DevDesc * Devdesc
UpnpNonblockParam
Definition upnpapi.hpp:274
size_t g_maxContentLength
Maximum content-length (in bytes) that the SDK will process on an incoming packet.
Definition upnpapi.cpp:327
char LowerDescURL[LINE_SIZE]
URL for the use of SSDP when answering to legacy CPs (CP searching for a v1 when the device is v2).
Definition upnpapi.hpp:94
int RegistrationState
Registration State as defined by UPnP Low Power.
Definition upnpapi.hpp:101
virtualDirList * pVirtualDirList
Pointer to the virtual directory list.
Definition upnpapi.cpp:250
int g_UpnpSdkEQMaxLen
Global variable to determines the maximum number of events.
Definition upnpapi.cpp:335
char DescURL[LINE_SIZE]
URL for the use of SSDP.
Definition upnpapi.hpp:93
char ServiceVer[NAME_SIZE]
UpnpNonblockParam
Definition upnpapi.hpp:267
Upnp_SID SubsId
UpnpNonblockParam
Definition upnpapi.hpp:269
UPnPsdk_VIS unsigned gIF_INDEX
Contains network interface index of the link local address gIF_IPV6 that is used as its scope_id.
Definition upnpapi.cpp:299
UPnPsdk_VIS void * gWebCallback_HostValidateCookie
Cookie to the webCallback for HOST validation.
Definition upnpapi.cpp:274
UPnPsdk_VIS unsigned gIF_IPV6_PREFIX_LENGTH
IPv6 LLA prefix length. (extern'ed in upnp.h)
Definition upnpapi.cpp:295
UPnPsdk_VIS unsigned gIF_IPV6_ULA_GUA_PREFIX_LENGTH
IPv6 ULA or GUA prefix length. (extern'ed in upnp.h)
Definition upnpapi.cpp:308
IXML_Document * DescDocument
Description parsed in terms of DOM document.
Definition upnpapi.hpp:103
UpnpFunName FunName
UpnpNonblockParam
Definition upnpapi.hpp:259
int TimeOut
UpnpNonblockParam
Definition upnpapi.hpp:261
UPnPsdk_VIS char gIF_IPV6[INET6_ADDRSTRLEN]
Static buffer to contain interface IPv6 link-local address (LLA). (extern'ed in upnp....
Definition upnpapi.cpp:292
int PowerState
Power State as defined by UPnP Low Power.
Definition upnpapi.hpp:99
char DevId[NAME_SIZE]
UpnpNonblockParam
Definition upnpapi.hpp:265
WebServerState
Possible status of the internal webserver.
Definition upnpapi.hpp:282
void AutoAdvertise(void *input)
This function is a timer thread scheduled by UpnpSendAdvertisement to the send advetisement again.
Definition upnpapi.cpp:3389
UpnpFunName
UpnpFunName.
Definition upnpapi.hpp:242
UPnPsdk_VIS unsigned short LOCAL_PORT_V6
IPv6 LLA port for the mini-server.
Definition upnpapi.cpp:314
char * Cookie
???
Definition upnpapi.hpp:87
UPnPsdk_VIS int gAllowLiteralHostRedirection
Allow literal host names redirection to numeric host names.
Definition upnpapi.cpp:277
Upnp_FunPtr Callback
Callback function pointer.
Definition upnpapi.hpp:86
constexpr int NUM_HANDLE
Maximal number of available UPnP Unit handles.
Definition upnpapi.hpp:64
int MaxSubscriptionTimeOut
???
Definition upnpapi.hpp:110
char NewVal[NAME_SIZE]
UpnpNonblockParam
Definition upnpapi.hpp:263
int MaxSubscriptions
???
Definition upnpapi.hpp:109
LinkedList SsdpSearchList
Active SSDP searches.
Definition upnpapi.hpp:119
TimerThread gTimerThread
Global timer thread.
Definition upnpapi.cpp:256
IXML_NodeList * DeviceList
List of devices in the description document.
Definition upnpapi.hpp:104
int MaxAge
Advertisement timeout.
Definition upnpapi.hpp:98
ThreadPool gMiniServerThreadPool
Mini server thread pool.
Definition upnpapi.cpp:265
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.cpp:3268
char VarName[NAME_SIZE]
UpnpNonblockParam
Definition upnpapi.hpp:262
int g_UpnpSdkEQMaxAge
Global variable to determine the maximum number of seconds which an event can spend on a subscription...
Definition upnpapi.cpp:346
int DeviceAf
Address family: AF_INET6 or AF_INET.
Definition upnpapi.hpp:111
char ServiceType[NAME_SIZE]
UpnpNonblockParam
Definition upnpapi.hpp:266
WebServerState bWebServerState
Flag to indicate the state of web server.
Definition upnpapi.cpp:268
char DevType[NAME_SIZE]
UpnpNonblockParam
Definition upnpapi.hpp:264
UPnPsdk_VIS char gIF_NAME[LINE_SIZE]
Static buffer to contain interface name. (extern'ed in upnp.h)
Definition upnpapi.cpp:280
Data to be stored in handle table for Handle Info.
Definition upnpapi.hpp:84
UpnpNonblockParam.
Definition upnpapi.hpp:256
#define UPnPsdk_VIS
Prefix to export symbol for external use.