libnpupnp 4.1.0
An almost compatible successor for the Portable UPnP reference library
upnp.h
Go to the documentation of this file.
1#ifndef UPNP_H
2#define UPNP_H
3
4/*******************************************************************************
5 *
6 * Copyright (c) 2000-2003 Intel Corporation
7 * Copyright (C) 2011-2012 France Telecom All rights reserved.
8 * Copyright (C) 2020 J.F. Dockes <jf@dockes.org>
9 * All rights reserved.
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
40#include <cstdint>
41#include <ctime>
42#include <map>
43#include <string>
44#include <unordered_map>
45#include <utility>
46#include <vector>
47
48#include "upnpconfig.h"
49#ifdef _WIN32
50#include <winsock2.h>
51#else
52#include <sys/socket.h>
53#endif
54#include "UpnpGlobal.h"
55
57#define LINE_SIZE size_t(180)
59#define NAME_SIZE size_t(256)
61#define UPNP_INFINITE -1
66#define UPNP_USING_CHUNKED -3
68#define UPNP_UNTIL_CLOSE -4
69
74#define UPNP_MAX_SEARCH_TIME 80
75
80#define UPNP_MIN_SEARCH_TIME 2
81
82
96#define UPNP_E_SUCCESS 0
97
99#define UPNP_E_INVALID_HANDLE -100
100
102#define UPNP_E_INVALID_PARAM -101
103
105#define UPNP_E_OUTOF_HANDLE -102
106
108#define UPNP_E_OUTOF_CONTEXT -103
109
111#define UPNP_E_OUTOF_MEMORY -104
112
114#define UPNP_E_INIT -105
115
117#define UPNP_E_BUFFER_TOO_SMALL -106
118
121#define UPNP_E_INVALID_DESC -107
122
124#define UPNP_E_INVALID_URL -108
125
127#define UPNP_E_INVALID_SID -109
128
130#define UPNP_E_INVALID_DEVICE -110
131
133#define UPNP_E_INVALID_SERVICE -111
134
137#define UPNP_E_BAD_RESPONSE -113
138
140#define UPNP_E_BAD_REQUEST -114
141
145#define UPNP_E_INVALID_ACTION -115
146
151#define UPNP_E_FINISH -116
152
155#define UPNP_E_INIT_FAILED -117
156
159#define UPNP_E_URL_TOO_BIG -118
160
169#define UPNP_E_BAD_HTTPMSG -119
170
177#define UPNP_E_ALREADY_REGISTERED -120
178
181#define UPNP_E_INVALID_INTERFACE -121
182
190#define UPNP_E_NETWORK_ERROR -200
191
200#define UPNP_E_SOCKET_WRITE -201
201
210#define UPNP_E_SOCKET_READ -202
211
220#define UPNP_E_SOCKET_BIND -203
221
230#define UPNP_E_SOCKET_CONNECT -204
231
240#define UPNP_E_OUTOF_SOCKET -205
241
244#define UPNP_E_LISTEN -206
245
252#define UPNP_E_TIMEDOUT -207
253
260#define UPNP_E_SOCKET_ERROR -208
261
263#define UPNP_E_FILE_WRITE_ERROR -209
264
266#define UPNP_E_CANCELED -210
267
269#define UPNP_E_EVENT_PROTOCOL -300
270
272#define UPNP_E_SUBSCRIBE_UNACCEPTED -301
273
275#define UPNP_E_UNSUBSCRIBE_UNACCEPTED -302
276
278#define UPNP_E_NOTIFY_UNACCEPTED -303
279
281#define UPNP_E_INVALID_ARGUMENT -501
282
285#define UPNP_E_FILE_NOT_FOUND -502
286
288#define UPNP_E_FILE_READ_ERROR -503
289
292#define UPNP_E_EXT_NOT_XML -504
293
295#define UPNP_E_NO_WEB_SERVER -505
296
298#define UPNP_E_OUTOF_BOUNDS -506
299
301#define UPNP_E_NOT_FOUND -507
302
305#define UPNP_E_INTERNAL_ERROR -911
306
307/* SOAP-related error codes */
308#define UPNP_SOAP_E_INVALID_ACTION 401
309#define UPNP_SOAP_E_INVALID_ARGS 402
310#define UPNP_SOAP_E_OUT_OF_SYNC 403
311#define UPNP_SOAP_E_INVALID_VAR 404
312#define UPNP_SOAP_E_ACTION_FAILED 501
313
314/* @} ErrorCodes */
315
316
317enum UpnpOpenFileMode
318{
319 UPNP_READ,
320 UPNP_WRITE
321};
322
326
330
411
412
413
415typedef std::string Upnp_SID;
416
431
445
462
470
471 /* Old comment said socket number ?? Not set, kept for ABI */
472 int unused1;
473
476
479
482
485
487 std::vector<std::pair<std::string, std::string> > args;
488
490 std::vector<std::pair<std::string, std::string> > resdata;
491
493 struct sockaddr_storage CtrlPtIPAddr;
494
496 std::string Os;
497
501 std::string xmlAction;
502
507 std::string xmlResponse;
508};
509
510/* compat code for libupnp-1.8 */
512#define UpnpActionRequest_get_ErrCode(x) ((x)->ErrCode)
513#define UpnpActionRequest_set_ErrCode(x, v) ((x)->ErrCode = (v))
514#define UpnpActionRequest_get_Socket(x) ((x)->Socket)
515#define UpnpActionRequest_get_ErrStr_cstr(x) ((x)->ErrStr)
516#define UpnpActionRequest_set_ErrStr(x, v) (strncpy((x)->ErrStr, v, LINE_SIZE))
517#define UpnpActionRequest_strcpy_ErrStr(x, v) (strncpy((x)->ErrStr, v, LINE_SIZE))
518#define UpnpActionRequest_get_ActionName_cstr(x) ((x)->ActionName)
519#define UpnpActionRequest_get_DevUDN_cstr(x) ((x)->DevUDN)
520#define UpnpActionRequest_get_ServiceID_cstr(x) ((x)->ServiceID)
521#define UpnpActionRequest_get_xmlAction(x) ((x)->xmlAction)
522#define UpnpActionRequest_get_xmlResponse(x) ((x)->xmlResponse)
523#define UpnpActionRequest_set_xmlResponse(x, v) ((x)->xmlResponse = (v))
524#define UpnpActionRequest_get_CtrlPtIPAddr(x) (&((x)->CtrlPtIPAddr))
525#define UpnpActionRequest_get_Os_cstr(x) ((x)->Os.c_str())
526
531
534
537 std::unordered_map<std::string, std::string> ChangedVariables;
538};
539
540/* compat code for libupnp-1.8 */
541typedef struct Upnp_Event UpnpEvent;
542#define UpnpEvent_get_SID_cstr(x) ((x)->Sid.c_str())
543#define UpnpEvent_get_EventKey(x) ((x)->EventKey)
544#define UpnpEvent_get_ChangedVariables(x) ((x)->ChangedVariables)
545
550
553
556
559
562
565
568
570 char Os[LINE_SIZE];
571
574
577
579 struct sockaddr_storage DestAddr;
580};
581
582/* compat code for libupnp-1.8 */
583typedef struct Upnp_Discovery UpnpDiscovery;
584#define UpnpDiscovery_get_ErrCode(x) ((x)->ErrCode)
585#define UpnpDiscovery_get_Expires(x) ((x)->Expires)
586#define UpnpDiscovery_get_DeviceID_cstr(x) ((x)->DeviceId)
587#define UpnpDiscovery_get_DeviceType_cstr(x) ((x)->DeviceType)
588#define UpnpDiscovery_get_ServiceType_cstr(x) ((x)->ServiceType)
589#define UpnpDiscovery_get_ServiceVer_cstr(x) ((x)->ServiceVer)
590#define UpnpDiscovery_get_Location_cstr(x) ((x)->Location)
591#define UpnpDiscovery_get_Os_cstr(x) ((x)->Os)
592#define UpnpDiscovery_get_Date_cstr(x) ((x)->Date)
593#define UpnpDiscovery_get_Ext_cstr(x) ((x)->Ext)
594#define UpnpDiscovery_get_Os_cstr(x) ((x)->Os)
595#define UpnpDiscovery_get_DestAddr(x) (&((x)->DestAddr))
596
616
617/* compat code for libupnp-1.8 */
619#define UpnpEventSubscribe_get_SID_cstr(x) ((x)->Sid.c_str())
620#define UpnpEventSubscribe_get_ErrCode(x) ((x)->ErrCode)
621#define UpnpEventSubscribe_get_PublisherUrl_cstr(x) ((x)->PublisherUrl)
622#define UpnpEventSubscribe_get_TimeOut(x) ((x)->TimeOut)
623
627 const char *ServiceId;
628
630 const char *UDN;
631
634};
635
636/* compat code for libupnp-1.8 */
638#define UpnpSubscriptionRequest_get_ServiceId_cstr(x) ((x)->ServiceId)
639#define UpnpSubscriptionRequest_get_UDN_cstr(x) ((x)->UDN)
640#define UpnpSubscriptionRequest_get_SID_cstr(x) ((x)->Sid.c_str())
641
643struct File_Info {
647 int64_t file_length{0};
648
651 time_t last_modified{0};
652
656
660
662 std::string content_type;
663
665 struct sockaddr_storage CtrlPtIPAddr;
666
668 std::string Os;
669
672 std::map<std::string, std::string> request_headers;
673
678 std::vector<std::pair<std::string, std::string>> response_headers;
679};
680
681/* Compat code for libupnp-1.8 */
682typedef struct File_Info UpnpFileInfo;
683#define UpnpFileInfo_get_FileLength(x) ((x)->file_length)
684#define UpnpFileInfo_set_FileLength(x, v) ((x)->file_length = (v))
685#define UpnpFileInfo_get_LastModified(x) ((x)->last_modified)
686#define UpnpFileInfo_set_LastModified(x, v) ((x)->last_modified = (v))
687#define UpnpFileInfo_get_IsDirectory(x) ((x)->is_directory)
688#define UpnpFileInfo_set_IsDirectory(x, v) ((x)->is_directory = (v))
689#define UpnpFileInfo_get_IsReadable(x) ((x)->is_readable)
690#define UpnpFileInfo_set_IsReadable(x, v) ((x)->is_readable = (v))
691#define UpnpFileInfo_get_ContentType(x) ((x)->content_type)
692#define UpnpFileInfo_set_ContentType(x, v) ((x)->content_type = (v))
693#define UpnpFileInfo_get_CtrlPtIPAddr(x) (&((x)->CtrlPtIPAddr))
694#define UpnpFileInfo_get_Os_cstr(x) ((x)->Os.c_str())
695
717typedef int (*Upnp_FunPtr)(
718 Upnp_EventType EventType, const void *Event, void *Cookie);
719
720
759EXPORT_SPEC int UpnpInit(
762 const char *HostIP,
767 unsigned short DestPort);
768
808EXPORT_SPEC int UpnpInit2(
809 const char *IfName, unsigned short DestPort);
810
848EXPORT_SPEC int UpnpInit2(
849 const std::vector<std::string>& ifnames, unsigned short DestPort);
850
890EXPORT_SPEC int UpnpInitWithOptions(
891 const char *IfNames,
892 unsigned short DestPort,
894 unsigned int flags,
895 ...
896 );
897
898
918EXPORT_SPEC int UpnpFinish(void);
919
931EXPORT_SPEC unsigned short UpnpGetServerPort(void);
932
933#ifdef UPNP_ENABLE_IPV6
944EXPORT_SPEC unsigned short UpnpGetServerPort6(void);
945
957EXPORT_SPEC unsigned short UpnpGetServerUlaGuaPort6(void);
958#endif
959
971EXPORT_SPEC const char *UpnpGetServerIpAddress(void);
972
973#ifdef UPNP_ENABLE_IPV6
986EXPORT_SPEC const char *UpnpGetServerIp6Address(void);
987
989EXPORT_SPEC const char *UpnpGetServerUlaGuaIp6Address(void);
990#endif
991
1010 size_t contentLength);
1011
1058 const char *DescUrl,
1060 Upnp_FunPtr Fun,
1062 const void *Cookie,
1064 UpnpDevice_Handle *Hnd);
1065
1116 Upnp_DescType descriptionType,
1119 const char* description,
1122 size_t bufferLen,
1124 int ignored,
1126 Upnp_FunPtr Fun,
1128 const void* Cookie,
1130 UpnpDevice_Handle* Hnd);
1131
1171 const char *DescUrl,
1173 Upnp_FunPtr Fun,
1175 const void *Cookie,
1177 UpnpDevice_Handle *Hnd,
1179 int,
1182 const char *LowerDescUrl);
1183
1192EXPORT_SPEC int UpnpDeviceSetProduct(
1196 const char *product,
1198 const char *version);
1199
1216 UpnpDevice_Handle Hnd);
1217
1239 int PowerState,
1241 int SleepPeriod,
1243 int RegistrationState);
1244
1269EXPORT_SPEC int UpnpRegisterClient(
1271 Upnp_FunPtr Fun,
1273 const void *Cookie,
1275 UpnpClient_Handle *Hnd);
1276
1281EXPORT_SPEC void UpnpClientSetProduct(
1285 const char *product,
1287 const char *version);
1288
1306EXPORT_SPEC int UpnpUnRegisterClient(
1308 UpnpClient_Handle Hnd);
1309
1313/******************************************************************************
1314 * *
1315 * D I S C O V E R Y *
1316 * *
1317 ******************************************************************************/
1339EXPORT_SPEC int UpnpSearchAsync(
1346 int Mx,
1349 const char *Target,
1351 const void *cookie);
1352
1379 const std::string& url,
1381 const char *Target,
1383 void *cookie);
1384
1414 int Exp);
1415
1442 int Exp,
1444 int PowerState,
1446 int SleepPeriod,
1448 int RegistrationState);
1449
1456/******************************************************************************
1457 * *
1458 * C O N T R O L *
1459 * *
1460 ******************************************************************************/
1497EXPORT_SPEC int UpnpSendAction(
1499 const std::string& headerString,
1500 const std::string& actionURL,
1501 const std::string& serviceType,
1502 const std::string& actionName,
1503 const std::vector<std::pair<std::string, std::string>>& actionParams,
1504 std::vector<std::pair<std::string, std::string>>& responseData,
1505 int* errcodep,
1506 std::string& errdesc);
1507
1510/******************************************************************************
1511 * *
1512 * E V E N T I N G *
1513 * *
1514 ******************************************************************************/
1515
1549 const char *DevID,
1551 const char *ServName,
1553 const char **VarName,
1555 const char **NewVal,
1557 int cVariables,
1559 const Upnp_SID& SubsId);
1560
1565 const char *DevID,
1567 const char *ServName,
1569 const std::string& propertyset,
1571 const Upnp_SID& SubsId);
1572
1594EXPORT_SPEC int UpnpNotify(
1598 const char *DevID,
1600 const char *ServName,
1602 const char **VarName,
1604 const char **NewVal,
1606 int cVariables);
1607
1608EXPORT_SPEC int UpnpNotifyXML(
1612 const char *DevID,
1614 const char *ServName,
1616 const std::string& propset);
1617
1636 int MaxSubscriptions);
1637
1673EXPORT_SPEC int UpnpSubscribe(
1677 const char *EvtUrl,
1681 int *TimeOut,
1683 Upnp_SID& SubsId);
1684
1720 int *TimeOut,
1722 const Upnp_SID& SubsId);
1723
1753EXPORT_SPEC int UpnpUnSubscribe(
1757 const Upnp_SID& SubsId);
1758
1779 int MaxSubscriptionTimeOut);
1780
1795EXPORT_SPEC int UpnpSubsOpsTimeoutMs(
1799 int TimeOutMS);
1800
1834EXPORT_SPEC int UpnpDownloadUrlItem(
1836 const char *url,
1839 char **outBuf,
1842 char *contentType);
1843
1849EXPORT_SPEC int UpnpDownloadUrlItem(
1851 const std::string& url,
1853 std::string& data,
1855 std::string& ct);
1856
1860/******************************************************************************
1861 * *
1862 * W E B S E R V E R A P I *
1863 * *
1864 ******************************************************************************/
1865
1879EXPORT_SPEC int UpnpEnableWebserver(
1881 int enable);
1882
1890EXPORT_SPEC int UpnpIsWebserverEnabled(void);
1891
1906 const char *rootDir);
1907
1921EXPORT_SPEC std::string UpnpGetUrlHostPortForClient(const struct sockaddr_storage*);
1922
1923/*
1924 * @brief Callback for validating HTTP requests HOST header values.
1925 *
1926 * This is called when a GET/POST/HEAD request to the Web server contains a host
1927 * name (instead of a numeric address) in the HOST header. The client code can chose
1928 * to authorize the request. Else it will be either redirected to a numeric
1929 * address or rejected depending on the UPNP_FLAG_REJECT_HOSTNAMES
1930 * option. Specific UPnP (SOAP/SUBSCRIBE...) requests are always checked to
1931 * contain a numeric address and will not trigger the callback.
1932 *
1933 * @param hostname the value in the request HOST header.
1934 * @return An integer representing one of the following:
1935 * \li \c UPNP_E_SUCCESS: a request with the HOST header set to hostname should be processed.
1936 * \li \c UPNP_E_BAD_HTTPMSG the request should be redirected or rejected.
1937 */
1938typedef int (*WebCallback_HostValidate)(const char *hostname, void *cookie);
1939
1940EXPORT_SPEC int UpnpSetWebRequestHostValidateCallback(
1941 WebCallback_HostValidate callback, void *cookie);
1942
1945 WebCallback_HostValidate callback, void *cookie);
1946
1960 const char *corsString);
1961
1962
1964typedef void *UpnpWebFileHandle;
1965
1970typedef int (*VDCallback_GetInfo)(
1972 const char *filename,
1974 struct File_Info *info,
1975 const void *cookie,
1976 const void **request_cookiep
1977 );
1978
1988
1992 const char *filename,
1995 enum UpnpOpenFileMode Mode,
1996 const void *cookie,
1997 const void *request_cookie
1998 );
1999
2009
2011typedef int (*VDCallback_Read)(
2013 UpnpWebFileHandle fileHnd,
2015 char *buf,
2017 size_t buflen,
2018 const void *cookie,
2019 const void *request_cookie
2020 );
2021
2031
2033typedef int (*VDCallback_Write)(
2035 UpnpWebFileHandle fileHnd,
2037 char *buf,
2039 size_t buflen,
2040 const void *cookie,
2041 const void *request_cookie
2042 );
2043
2053
2055typedef int (*VDCallback_Seek) (
2057 UpnpWebFileHandle fileHnd,
2061 int64_t offset,
2066 int origin,
2067 const void *cookie,
2068 const void *request_cookie
2069 );
2070
2080
2082typedef int (*VDCallback_Close)(
2084 UpnpWebFileHandle fileHnd,
2085 const void *cookie,
2086 const void *request_cookie
2087 );
2088
2098
2120
2130 struct UpnpVirtualDirCallbacks *callbacks );
2131
2151EXPORT_SPEC int UpnpAddVirtualDir(
2152 const char *dirName, const void *cookie, const void **oldcookie);
2153
2161EXPORT_SPEC int UpnpRemoveVirtualDir(
2163 const char *dirName);
2164
2168EXPORT_SPEC void UpnpRemoveAllVirtualDirs(void);
2169
2170/* @} Web Server API */
2171
2172#endif /* UPNP_H */
Definition upnp.h:643
int64_t file_length
The length of the file. A length less than 0 indicates the size is unknown, and data will be sent unt...
Definition upnp.h:647
std::map< std::string, std::string > request_headers
Headers received with the HTTP request. Set by the library before calling VDCallback_GetInfo.
Definition upnp.h:672
std::string Os
Client user-agent string.
Definition upnp.h:668
int is_directory
If the file is a directory, contains a non-zero value. For a regular file, it should be 0.
Definition upnp.h:655
int is_readable
If the file or directory is readable, this contains a non-zero value. If unreadable,...
Definition upnp.h:659
std::string content_type
The content type of the file.
Definition upnp.h:662
time_t last_modified
The time at which the contents of the file was modified; The time system is always local (not GMT).
Definition upnp.h:651
struct sockaddr_storage CtrlPtIPAddr
IP address of the control point requesting this action.
Definition upnp.h:665
std::vector< std::pair< std::string, std::string > > response_headers
Additional headers which should be set in the response. Set by the client inside the VDCallback_GetIn...
Definition upnp.h:678
Definition upnp.h:2106
VDCallback_Open open
VDCallback_Open callback
Definition upnp.h:2110
VDCallback_Seek seek
VDCallback_Seek callback
Definition upnp.h:2116
VDCallback_Read read
VDCallback_Read callback
Definition upnp.h:2112
VDCallback_GetInfo get_info
VDCallback_GetInfo callback
Definition upnp.h:2108
VDCallback_Write write
VDCallback_Write callback
Definition upnp.h:2114
VDCallback_Close close
VDCallback_Close callback
Definition upnp.h:2118
Definition upnp.h:467
std::string xmlResponse
[output] Alternative data return: return an XML document instead of using the resdata vector....
Definition upnp.h:507
std::vector< std::pair< std::string, std::string > > resdata
[output] The action results.
Definition upnp.h:490
std::string Os
[input] Client user-agent string
Definition upnp.h:496
char ActionName[NAME_SIZE]
[input] The Action Name.
Definition upnp.h:478
char ErrStr[LINE_SIZE]
[output] The error string in case of error.
Definition upnp.h:475
std::vector< std::pair< std::string, std::string > > args
[input] The action arguments
Definition upnp.h:487
int ErrCode
[output] The result of the operation.
Definition upnp.h:469
std::string xmlAction
[input] The XML request document in case the callback has something else to get from there....
Definition upnp.h:501
char DevUDN[NAME_SIZE]
[input] The unique device ID.
Definition upnp.h:481
char ServiceID[NAME_SIZE]
[input] The service ID.
Definition upnp.h:484
struct sockaddr_storage CtrlPtIPAddr
[input] IP address of the control point requesting this action.
Definition upnp.h:493
Definition upnp.h:547
char ServiceType[LINE_SIZE]
The service type.
Definition upnp.h:561
char Ext[LINE_SIZE]
Confirmation that the MAN header was understood by the device.
Definition upnp.h:576
struct sockaddr_storage DestAddr
The host address of the device responding to the search.
Definition upnp.h:579
char DeviceType[LINE_SIZE]
The device type.
Definition upnp.h:558
char Date[LINE_SIZE]
Date when the response was generated.
Definition upnp.h:573
int ErrCode
The result code of the UpnpSearchAsync call.
Definition upnp.h:549
char DeviceId[LINE_SIZE]
The unique device identifier.
Definition upnp.h:555
char Os[LINE_SIZE]
The operating system the device is running.
Definition upnp.h:570
char Location[LINE_SIZE]
The URL to the UPnP description document for the device.
Definition upnp.h:567
char ServiceVer[LINE_SIZE]
The service version.
Definition upnp.h:564
int Expires
The expiration time of the advertisement.
Definition upnp.h:552
Definition upnp.h:598
char PublisherUrl[NAME_SIZE]
The event URL being subscribed to or removed from.
Definition upnp.h:611
int ErrCode
The result of the operation.
Definition upnp.h:608
int TimeOut
The actual subscription time (for subscriptions only).
Definition upnp.h:614
Upnp_SID Sid
The SID for this subscription. For subscriptions, this only contains a valid SID if the ErrCode field...
Definition upnp.h:605
Definition upnp.h:528
std::unordered_map< std::string, std::string > ChangedVariables
The changes generating the event. std::map would have been a better choice, but too late to change....
Definition upnp.h:537
int EventKey
The event sequence number.
Definition upnp.h:533
Upnp_SID Sid
The subscription ID for this subscription.
Definition upnp.h:530
Definition upnp.h:625
const char * ServiceId
The identifier for the service being subscribed to.
Definition upnp.h:627
const char * UDN
Unique Device Name.
Definition upnp.h:630
Upnp_SID Sid
The assigned subscription ID for this subscription.
Definition upnp.h:633
EXPORT_SPEC int UpnpVirtualDir_set_CloseCallback(VDCallback_Close callback)
Sets the close callback function to be used to access a virtual directory.
EXPORT_SPEC int UpnpSetWebServerRootDir(const char *rootDir)
Sets the document root directory for the internal WEB server.
EXPORT_SPEC int UpnpRegisterRootDevice2(Upnp_DescType descriptionType, const char *description, size_t bufferLen, int ignored, Upnp_FunPtr Fun, const void *Cookie, UpnpDevice_Handle *Hnd)
Registers a device application with the UPnP Library. Similar to UpnpRegisterRootDevice,...
int(* VDCallback_Close)(UpnpWebFileHandle fileHnd, const void *cookie, const void *request_cookie)
Virtual directory close callback function prototype.
Definition upnp.h:2082
EXPORT_SPEC int UpnpRegisterRootDevice(const char *DescUrl, Upnp_FunPtr Fun, const void *Cookie, UpnpDevice_Handle *Hnd)
Registers a device application with the UPnP Library.
EXPORT_SPEC int UpnpSetHostValidateCallback(WebCallback_HostValidate callback, void *cookie)
EXPORT_SPEC int UpnpNotifyXML(UpnpDevice_Handle, const char *DevID, const char *ServName, const std::string &propset)
enum Upnp_EventType_e Upnp_EventType
EXPORT_SPEC int UpnpAcceptSubscription(UpnpDevice_Handle Hnd, const char *DevID, const char *ServName, const char **VarName, const char **NewVal, int cVariables, const Upnp_SID &SubsId)
Accepts a subscription request and sends out the current state of the eventable variables for a servi...
Upnp_DescType_e
Specifies the type of description passed to UpnpRegisterRootDevice2.
Definition upnp.h:419
@ UPNPREG_FILENAME_DESC
The description is a file name on the local file system containing the description of the device.
Definition upnp.h:425
@ UPNPREG_BUF_DESC
The description is a pointer to a character array containing the XML description document.
Definition upnp.h:429
@ UPNPREG_URL_DESC
The description is the URL to the description document.
Definition upnp.h:421
Upnp_InitOption
Definition upnp.h:448
@ UPNP_OPTION_NEXTBOOTID
NEXTBOOTID value to be sent in SSDP messages, int arg follows. Currently ignored.
Definition upnp.h:458
@ UPNP_OPTION_NETWORK_WAIT
Max wait seconds for an IP address to be found, int arg follows.
Definition upnp.h:452
@ UPNP_OPTION_SEARCHPORT
SEARCHPORT value to be sent in SSDP messages, int arg follows. Currently ignored.
Definition upnp.h:460
@ UPNP_OPTION_BOOTID
BOOTID value to be sent in SSDP messages, int arg follows.
Definition upnp.h:454
@ UPNP_OPTION_END
Terminate the VARARGs list.
Definition upnp.h:450
@ UPNP_OPTION_CONFIGID
CONFIGID value to be sent in SSDP messages, int arg follows.
Definition upnp.h:456
EXPORT_SPEC int UpnpDeviceSetProduct(UpnpDevice_Handle Hnd, const char *product, const char *version)
Set the product information part of the SERVER header sent with some network requests.
EXPORT_SPEC int UpnpSetMaxSubscriptionTimeOut(UpnpDevice_Handle Hnd, int MaxSubscriptionTimeOut)
Sets the maximum time-out accepted for a subscription request or renewal.
EXPORT_SPEC void UpnpRemoveAllVirtualDirs(void)
Removes all virtual directory mappings.
EXPORT_SPEC int UpnpInit(const char *HostIP, unsigned short DestPort)
Initializes the UPnP SDK for exclusive IP V4 operation on a single interface.
EXPORT_SPEC int UpnpSendAction(UpnpClient_Handle Hnd, const std::string &headerString, const std::string &actionURL, const std::string &serviceType, const std::string &actionName, const std::vector< std::pair< std::string, std::string > > &actionParams, std::vector< std::pair< std::string, std::string > > &responseData, int *errcodep, std::string &errdesc)
Sends a message to change a state variable in a service.
EXPORT_SPEC int UpnpSendAdvertisementLowPower(UpnpDevice_Handle Hnd, int Exp, int PowerState, int SleepPeriod, int RegistrationState)
Sends out the discovery announcements for all devices and services for a device.
EXPORT_SPEC int UpnpSetVirtualDirCallbacks(struct UpnpVirtualDirCallbacks *callbacks)
Sets the callback functions to be used to access a virtual directory.
EXPORT_SPEC int UpnpVirtualDir_set_ReadCallback(VDCallback_Read callback)
Sets the read callback function to be used to access a virtual directory.
EXPORT_SPEC int UpnpVirtualDir_set_GetInfoCallback(VDCallback_GetInfo callback)
Sets the get_info callback function to be used to access a virtual directory.
void * UpnpWebFileHandle
Definition upnp.h:1964
EXPORT_SPEC int UpnpVirtualDir_set_SeekCallback(VDCallback_Seek callback)
Sets the seek callback function to be used to access a virtual directory.
EXPORT_SPEC int UpnpSearchAsyncUnicast(UpnpClient_Handle Hnd, const std::string &url, const char *Target, void *cookie)
Unicast search.
EXPORT_SPEC int UpnpUnSubscribe(UpnpClient_Handle Hnd, const Upnp_SID &SubsId)
Removes the subscription of a control point from a service previously subscribed to using UpnpSubscri...
EXPORT_SPEC int UpnpUnRegisterRootDeviceLowPower(UpnpDevice_Handle Hnd, int PowerState, int SleepPeriod, int RegistrationState)
Unregisters a root device.
EXPORT_SPEC int UpnpInitWithOptions(const char *IfNames, unsigned short DestPort, unsigned int flags,...)
Initializes the library, passing the interface spec as a string.
EXPORT_SPEC int UpnpRegisterClient(Upnp_FunPtr Fun, const void *Cookie, UpnpClient_Handle *Hnd)
Registers a control point application with the UPnP Library.
int(* VDCallback_GetInfo)(const char *filename, struct File_Info *info, const void *cookie, const void **request_cookiep)
Virtual Directory function prototype for the "get file information" callback. This is guaranteed to ...
Definition upnp.h:1970
EXPORT_SPEC int UpnpSetMaxContentLength(size_t contentLength)
Sets the maximum content-length that the SDK will process on an incoming SOAP requests or responses.
EXPORT_SPEC unsigned short UpnpGetServerPort(void)
Returns the internal server IPv4 UPnP listening port.
Upnp_EventType_e
Definition upnp.h:335
@ UPNP_EVENT_RENEWAL_COMPLETE
Definition upnp.h:391
@ UPNP_EVENT_AUTORENEWAL_FAILED
Definition upnp.h:403
@ UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE
Definition upnp.h:362
@ UPNP_CONTROL_GET_VAR_REQUEST
Definition upnp.h:346
@ UPNP_EVENT_SUBSCRIPTION_REQUEST
Definition upnp.h:383
@ UPNP_DISCOVERY_ADVERTISEMENT_ALIVE
Definition upnp.h:357
@ UPNP_CONTROL_ACTION_COMPLETE
Definition upnp.h:344
@ UPNP_EVENT_SUBSCRIPTION_EXPIRED
Definition upnp.h:409
@ UPNP_DISCOVERY_SEARCH_RESULT
Definition upnp.h:368
@ UPNP_EVENT_SUBSCRIBE_COMPLETE
Definition upnp.h:394
@ UPNP_CONTROL_GET_VAR_COMPLETE
Definition upnp.h:349
@ UPNP_EVENT_UNSUBSCRIBE_COMPLETE
Definition upnp.h:397
@ UPNP_DISCOVERY_SEARCH_TIMEOUT
Definition upnp.h:373
@ UPNP_EVENT_RECEIVED
Definition upnp.h:388
@ UPNP_CONTROL_ACTION_REQUEST
Definition upnp.h:341
#define NAME_SIZE
Definition upnp.h:59
int UpnpClient_Handle
Definition upnp.h:325
EXPORT_SPEC std::string UpnpGetUrlHostPortForClient(const struct sockaddr_storage *)
return an URL host:port string suitable for the passed-in client address.
EXPORT_SPEC int UpnpSendAdvertisement(UpnpDevice_Handle Hnd, int Exp)
Sends out the discovery announcements for all devices and services for a device.
EXPORT_SPEC const char * UpnpGetServerIpAddress(void)
Returns a local IPv4 listening ip address.
EXPORT_SPEC int UpnpIsWebserverEnabled(void)
Returns TRUE if the webserver is enabled, or FALSE if it is not.
EXPORT_SPEC int UpnpUnRegisterClient(UpnpClient_Handle Hnd)
Unregisters a control point application, unsubscribing all active subscriptions.
EXPORT_SPEC int UpnpVirtualDir_set_WriteCallback(VDCallback_Write callback)
Sets the write callback function to be used to access a virtual directory.
EXPORT_SPEC int UpnpSubsOpsTimeoutMs(UpnpClient_Handle Hnd, int TimeOutMS)
Sets the HTTP timeout for subscription operations.
int UpnpDevice_Handle
Definition upnp.h:329
EXPORT_SPEC int UpnpFinish(void)
Terminate and clean up the library.
EXPORT_SPEC int UpnpSetWebServerCorsString(const char *corsString)
Assign the Access-Control-Allow-Origin specfied by the input const char* cors_string parameterto the ...
#define LINE_SIZE
Definition upnp.h:57
EXPORT_SPEC int UpnpSubscribe(UpnpClient_Handle Hnd, const char *EvtUrl, int *TimeOut, Upnp_SID &SubsId)
Registers a control point to receive event notifications from another device.
EXPORT_SPEC void UpnpClientSetProduct(UpnpClient_Handle Hnd, const char *product, const char *version)
Set the product information part of the User-Agent header sent with some network requests.
EXPORT_SPEC int UpnpRegisterRootDevice4(const char *DescUrl, Upnp_FunPtr Fun, const void *Cookie, UpnpDevice_Handle *Hnd, int, const char *LowerDescUrl)
Registers a device application with the UPnP library. This function can also be used to specify a ded...
std::string Upnp_SID
Holds a service subscription unique identifier.
Definition upnp.h:415
EXPORT_SPEC int UpnpAddVirtualDir(const char *dirName, const void *cookie, const void **oldcookie)
Adds a virtual directory mapping.
EXPORT_SPEC int UpnpNotify(UpnpDevice_Handle, const char *DevID, const char *ServName, const char **VarName, const char **NewVal, int cVariables)
Sends out an event change notification to all control points subscribed to a particular service.
int(* Upnp_FunPtr)(Upnp_EventType EventType, const void *Event, void *Cookie)
Definition upnp.h:717
EXPORT_SPEC int UpnpSetMaxSubscriptions(UpnpDevice_Handle Hnd, int MaxSubscriptions)
Sets the maximum number of subscriptions accepted per service.
EXPORT_SPEC int UpnpRenewSubscription(UpnpClient_Handle Hnd, int *TimeOut, const Upnp_SID &SubsId)
Renews a subscription that is about to expire.
EXPORT_SPEC int UpnpUnRegisterRootDevice(UpnpDevice_Handle Hnd)
Unregisters a root device.
int(* VDCallback_Write)(UpnpWebFileHandle fileHnd, char *buf, size_t buflen, const void *cookie, const void *request_cookie)
Virtual Directory Write callback function prototype.
Definition upnp.h:2033
EXPORT_SPEC int UpnpSearchAsync(UpnpClient_Handle Hnd, int Mx, const char *Target, const void *cookie)
Searches for devices matching the given search target.
int(* VDCallback_Read)(UpnpWebFileHandle fileHnd, char *buf, size_t buflen, const void *cookie, const void *request_cookie)
Virtual Directory Read callback function prototype.
Definition upnp.h:2011
UpnpWebFileHandle(* VDCallback_Open)(const char *filename, enum UpnpOpenFileMode Mode, const void *cookie, const void *request_cookie)
Virtual Directory Open callback function prototype.
Definition upnp.h:1990
enum Upnp_DescType_e Upnp_DescType
Specifies the type of description passed to UpnpRegisterRootDevice2.
EXPORT_SPEC int UpnpDownloadUrlItem(const char *url, char **outBuf, char *contentType)
Downloads a text file specified in a URL.
EXPORT_SPEC int UpnpAcceptSubscriptionXML(UpnpDevice_Handle Hnd, const char *DevID, const char *ServName, const std::string &propertyset, const Upnp_SID &SubsId)
EXPORT_SPEC int UpnpRemoveVirtualDir(const char *dirName)
Removes a virtual directory mapping made with UpnpAddVirtualDir.
EXPORT_SPEC int UpnpVirtualDir_set_OpenCallback(VDCallback_Open callback)
Sets the open callback function to be used to access a virtual directory.
EXPORT_SPEC int UpnpEnableWebserver(int enable)
Enables or disables the WEB server file service. The WEB server is automatically enabled by UpnpInit2...
Upnp_InitFlag
Definition upnp.h:433
@ UPNP_FLAG_NO_HOST_VALIDATE
Definition upnp.h:440
@ UPNP_FLAG_IPV6_REQUIRED
Definition upnp.h:438
@ UPNP_FLAG_REJECT_HOSTNAMES
Definition upnp.h:443
@ UPNP_FLAG_IPV6
Definition upnp.h:436
int(* VDCallback_Seek)(UpnpWebFileHandle fileHnd, int64_t offset, int origin, const void *cookie, const void *request_cookie)
Virtual Directory Seek callback function prototype.
Definition upnp.h:2055
EXPORT_SPEC int UpnpInit2(const char *IfName, unsigned short DestPort)
Initializes the library, passing the interface spec as a single string.