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-07-16
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 source file on 2025-07-16, ver 1.14.21
44#include <TimerThread.hpp>
45#include <VirtualDir.hpp> /* for struct VirtualDirCallbacks */
46#include <service_table.hpp>
47
49#define MAX_INTERFACES 256
50
52#define DEV_LIMIT 200
53
55#define DEFAULT_MX 5
56
58#define DEFAULT_MAXAGE 1800
59
61#define DEFAULT_SOAP_CONTENT_LENGTH 16000
63#define MAX_SOAP_CONTENT_LENGTH (size_t)32000
64
66constexpr int NUM_HANDLE{200};
67
68extern size_t g_maxContentLength;
69extern int g_UpnpSdkEQMaxLen;
70extern int g_UpnpSdkEQMaxAge;
71
73#define UPNP_TIMEOUT 30
74
78 HND_TABLE_INVALID = -2,
79 HND_INVALID,
80 HND_CLIENT,
81 HND_DEVICE
82};
83
84
125
126extern pthread_rwlock_t GlobalHndRWLock;
127
135 int Hnd,
137 struct Handle_Info** HndInfo);
138
140#define HandleLock() HandleWriteLock()
141
143#define HandleWriteLock() pthread_rwlock_wrlock(&GlobalHndRWLock);
144
146#define HandleReadLock() pthread_rwlock_rdlock(&GlobalHndRWLock);
147
149#define HandleUnlock() pthread_rwlock_unlock(&GlobalHndRWLock);
150
151#if 0
153#define HandleWriteLock() \
154 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying a write lock\n"); \
155 pthread_rwlock_wrlock(&GlobalHndRWLock); \
156 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Write lock acquired\n")
157
159#define HandleReadLock() \
160 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying a read lock\n"); \
161 pthread_rwlock_rdlock(&GlobalHndRWLock); \
162 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Read lock acquired\n")
163
165#define HandleUnlock() \
166 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying Unlock\n"); \
167 pthread_rwlock_unlock(&GlobalHndRWLock); \
168 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Unlocked rwlock\n")
169#endif
170
180 int* client_handle_out,
182 struct Handle_Info** HndInfo);
193 UpnpDevice_Handle start,
195 int AddressFamily,
197 int* device_handle_out,
199 struct Handle_Info** HndInfo);
200
210 const char* path,
212 int AddressFamily,
214 int* device_handle_out,
216 struct Handle_Info** HndInfo,
218 service_info** serv_info);
219
220PUPNP_API extern char gIF_NAME[LINE_SIZE];
221PUPNP_API extern char gIF_IPV4[INET_ADDRSTRLEN];
222PUPNP_API extern char gIF_IPV4_NETMASK[INET_ADDRSTRLEN];
223PUPNP_API extern char gIF_IPV6[INET6_ADDRSTRLEN];
224PUPNP_API extern unsigned gIF_IPV6_PREFIX_LENGTH;
225
226PUPNP_API extern char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN];
227PUPNP_API extern unsigned gIF_IPV6_ULA_GUA_PREFIX_LENGTH;
228
229PUPNP_API extern unsigned gIF_INDEX;
230
231PUPNP_API extern unsigned short LOCAL_PORT_V4;
232PUPNP_API extern unsigned short LOCAL_PORT_V6;
233PUPNP_API extern unsigned short LOCAL_PORT_V6_ULA_GUA;
234
237
242
244typedef enum {
245 SUBSCRIBE,
246 UNSUBSCRIBE,
247 DK_NOTIFY,
248 QUERY,
249 ACTION,
250 STATUS,
251 DEVDESCRIPTION,
252 SERVDESCRIPTION,
253 MINI,
254 RENEW
256
279
282
284typedef enum { WEB_SERVER_DISABLED, WEB_SERVER_ENABLED } WebServerState;
285
287#define E_HTTP_SYNTAX -6
288
290void UpnpThreadDistribution(struct UpnpNonblockParam* Param);
291
296void AutoAdvertise(
298 void* input);
299
308
311
314
317
320
321#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:431
#define NAME_SIZE
Definition API.hpp:46
int UpnpClient_Handle
Returned when a control point application registers with UpnpRegisterClient().
Definition API.hpp:412
int UpnpDevice_Handle
Returned when a device application registers with UpnpRegisterRootDevice(),UpnpRegisterRootDevice2(),...
Definition API.hpp:422
#define LINE_SIZE
Definition API.hpp:45
Genlib Client subscription.
Header file for GenlibClientSubscription methods.
Linked list (no protection).
A thread pool.
Manage threads that start at a given time (for internal use only).
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:2782
Manage the UPnP Services of a UPnP Device if available.
table of services
-brief Service information
WebCallback_HostValidate gWebCallback_HostValidate
webCallback for HOST validation.
Definition upnpapi.cpp:123
IXML_Document * Act
UpnpNonblockParam
Definition upnpapi.hpp:275
Upnp_Handle_Type HType
Handle Type.
Definition upnpapi.hpp:87
Upnp_Handle_Type GetHandleInfo(int Hnd, struct Handle_Info **HndInfo)
Get handle information.
Definition upnpapi.cpp:3339
IXML_Document * Header
UpnpNonblockParam
Definition upnpapi.hpp:274
char * Cookie
UpnpNonblockParam
Definition upnpapi.hpp:272
IXML_NodeList * ServiceList
List of services in the description document.
Definition upnpapi.hpp:108
int aliasInstalled
0 = not installed; otherwise installed.
Definition upnpapi.hpp:90
int Handle
UpnpNonblockParam
Definition upnpapi.hpp:262
struct VirtualDirCallbacks virtualDirCallback
This structure is for virtual directory callbacks.
Definition upnpapi.cpp:99
void UpnpThreadDistribution(struct UpnpNonblockParam *Param)
UpnpThreadDistribution.
Definition upnpapi.cpp:3139
ThreadPool gSendThreadPool
Send thread pool.
Definition upnpapi.cpp:111
Upnp_FunPtr Fun
UpnpNonblockParam
Definition upnpapi.hpp:273
Upnp_Handle_Type
Definition upnpapi.hpp:77
ThreadPool gRecvThreadPool
Receive thread pool.
Definition upnpapi.cpp:114
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:3302
char Url[NAME_SIZE]
UpnpNonblockParam
Definition upnpapi.hpp:270
char DescXML[LINE_SIZE]
XML file path for device description.
Definition upnpapi.hpp:99
GenlibClientSubscription * ClientSubList
Client subscription list.
Definition upnpapi.hpp:120
int gAllowLiteralHostRedirection
Allow literal host names redirection to numeric host names.
Definition upnpapi.cpp:129
service_table ServiceTable
Table holding subscriptions and URL information.
Definition upnpapi.hpp:110
PUPNP_API unsigned short LOCAL_PORT_V4
IPv4 local port for the mini-server.
Definition upnpapi.cpp:156
int SleepPeriod
Sleep Period as defined by UPnP Low Power.
Definition upnpapi.hpp:102
int PrintHandleInfo(UpnpClient_Handle Hnd)
Print handle info.
Definition upnpapi.cpp:3361
Upnp_SID gUpnpSdkNLSuuid
Global variable used in discovery notifications.
Definition upnpapi.cpp:212
pthread_rwlock_t GlobalHndRWLock
rwlock to synchronize handles (root device or control point handle).
Definition upnpapi.cpp:105
Upnp_Handle_Type GetClientHandleInfo(int *client_handle_out, struct Handle_Info **HndInfo)
Get client handle info.
Definition upnpapi.cpp:3245
void * gWebCallback_HostValidateCookie
Cookie to the webCallback for HOST validation.
Definition upnpapi.cpp:126
struct DevDesc * Devdesc
UpnpNonblockParam
Definition upnpapi.hpp:276
size_t g_maxContentLength
Maximum content-length (in bytes) that the SDK will process on an incoming packet.
Definition upnpapi.cpp:166
PUPNP_API unsigned gIF_INDEX
Index/scope-id from the used network interface.
Definition upnpapi.cpp:135
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:96
int RegistrationState
Registration State as defined by UPnP Low Power.
Definition upnpapi.hpp:103
PUPNP_API char gIF_IPV4[INET_ADDRSTRLEN]
IPv4 buffer to contain interface address. (extern'ed in upnp.h)
Definition upnpapi.cpp:152
virtualDirList * pVirtualDirList
Pointer to the virtual directory list.
Definition upnpapi.cpp:102
int g_UpnpSdkEQMaxLen
Global variable to determines the maximum number of events.
Definition upnpapi.cpp:174
char DescURL[LINE_SIZE]
URL for the use of SSDP.
Definition upnpapi.hpp:95
char ServiceVer[NAME_SIZE]
UpnpNonblockParam
Definition upnpapi.hpp:269
PUPNP_API char gIF_IPV6[INET6_ADDRSTRLEN]
IPv6 LLA buffer to contain interface address. (extern'ed in upnp.h)
Definition upnpapi.cpp:138
PUPNP_API unsigned gIF_IPV6_ULA_GUA_PREFIX_LENGTH
IPv6 GUA prefix length. (extern'ed in upnp.h)
Definition upnpapi.cpp:147
PUPNP_API unsigned short LOCAL_PORT_V6_ULA_GUA
IPv6 GUA port for the mini-server.
Definition upnpapi.cpp:149
Upnp_SID SubsId
UpnpNonblockParam
Definition upnpapi.hpp:271
IXML_Document * DescDocument
Description parsed in terms of DOM document.
Definition upnpapi.hpp:105
PUPNP_API char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN]
IPv6 GUA buffer to contain interface IPv6 global-unicast address.
Definition upnpapi.cpp:145
UpnpFunName FunName
UpnpNonblockParam
Definition upnpapi.hpp:261
int TimeOut
UpnpNonblockParam
Definition upnpapi.hpp:263
int PowerState
Power State as defined by UPnP Low Power.
Definition upnpapi.hpp:101
char DevId[NAME_SIZE]
UpnpNonblockParam
Definition upnpapi.hpp:267
WebServerState
Possible status of the internal webserver.
Definition upnpapi.hpp:284
void AutoAdvertise(void *input)
This function is a timer thread scheduled by UpnpSendAdvertisement to the send advetisement again.
Definition upnpapi.cpp:3386
PUPNP_API unsigned gIF_IPV6_PREFIX_LENGTH
IPv6 LLA prefix length. (extern'ed in upnp.h)
Definition upnpapi.cpp:140
UpnpFunName
UpnpFunName.
Definition upnpapi.hpp:244
char * Cookie
???
Definition upnpapi.hpp:89
Upnp_FunPtr Callback
Callback function pointer.
Definition upnpapi.hpp:88
constexpr int NUM_HANDLE
Maximal number of available UPnP Unit handles.
Definition upnpapi.hpp:66
int MaxSubscriptionTimeOut
???
Definition upnpapi.hpp:112
char NewVal[NAME_SIZE]
UpnpNonblockParam
Definition upnpapi.hpp:265
int MaxSubscriptions
???
Definition upnpapi.hpp:111
LinkedList SsdpSearchList
Active SSDP searches.
Definition upnpapi.hpp:121
TimerThread gTimerThread
Global timer thread.
Definition upnpapi.cpp:108
IXML_NodeList * DeviceList
List of devices in the description document.
Definition upnpapi.hpp:106
int MaxAge
Advertisement timeout.
Definition upnpapi.hpp:100
PUPNP_API char gIF_NAME[LINE_SIZE]
Buffer to contain used network interface name. (extern'ed in upnp.h)
Definition upnpapi.cpp:133
ThreadPool gMiniServerThreadPool
Mini server thread pool.
Definition upnpapi.cpp:117
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:3265
char VarName[NAME_SIZE]
UpnpNonblockParam
Definition upnpapi.hpp:264
int g_UpnpSdkEQMaxAge
Global variable to determine the maximum number of seconds which an event can spend on a subscription...
Definition upnpapi.cpp:185
int DeviceAf
Address family: AF_INET6 or AF_INET.
Definition upnpapi.hpp:113
PUPNP_API unsigned short LOCAL_PORT_V6
IPv6 LLA port for the mini-server.
Definition upnpapi.cpp:142
char ServiceType[NAME_SIZE]
UpnpNonblockParam
Definition upnpapi.hpp:268
WebServerState bWebServerState
Flag to indicate the state of web server.
Definition upnpapi.cpp:120
char DevType[NAME_SIZE]
UpnpNonblockParam
Definition upnpapi.hpp:266
PUPNP_API char gIF_IPV4_NETMASK[INET_ADDRSTRLEN]
IPv4 buffer to contain interface netmask. (extern'ed in upnp.h)
Definition upnpapi.cpp:154
Data to be stored in handle table for Handle Info.
Definition upnpapi.hpp:86
UpnpNonblockParam.
Definition upnpapi.hpp:258