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 
317 enum UpnpOpenFileMode
318 {
319  UPNP_READ,
320  UPNP_WRITE
321 };
322 
325 typedef int UpnpClient_Handle;
326 
329 typedef int UpnpDevice_Handle;
330 
335 typedef enum Upnp_EventType_e {
336  /* Control callbacks */
337 
342 
347 
350 
351 
352  /* Discovery callbacks */
353 
358 
363 
369 
374 
375  /* Eventing callbacks */
376 
384 
389 
392 
395 
398 
404 
411 
412 
413 
415 typedef std::string Upnp_SID;
416 
419 typedef enum Upnp_DescType_e {
422 
426 
431 
433 typedef enum {
434  UPNP_FLAG_NONE = 0,
444 } Upnp_InitFlag;
445 
448 typedef enum {
462 
469  int ErrCode;
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 
528 struct Upnp_Event {
531 
533  int EventKey;
534 
537  std::unordered_map<std::string, std::string> ChangedVariables;
538 };
539 
540 /* compat code for libupnp-1.8 */
541 typedef 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 
549  int ErrCode;
550 
552  int Expires;
553 
556 
559 
562 
565 
568 
570  char Os[LINE_SIZE];
571 
573  char Date[LINE_SIZE];
574 
576  char Ext[LINE_SIZE];
577 
579  struct sockaddr_storage DestAddr;
580 };
581 
582 /* compat code for libupnp-1.8 */
583 typedef 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 
599 
606 
608  int ErrCode;
609 
612 
614  int TimeOut;
615 };
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 
643 struct File_Info {
647  int64_t file_length{0};
648 
651  time_t last_modified{0};
652 
655  int is_directory{0};
656 
659  int is_readable{0};
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 */
682 typedef 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 
717 typedef int (*Upnp_FunPtr)(
718  Upnp_EventType EventType, const void *Event, void *Cookie);
719 
720 
759 EXPORT_SPEC int UpnpInit(
762  const char *HostIP,
767  unsigned short DestPort);
768 
808 EXPORT_SPEC int UpnpInit2(
809  const char *IfName, unsigned short DestPort);
810 
848 EXPORT_SPEC int UpnpInit2(
849  const std::vector<std::string>& ifnames, unsigned short DestPort);
850 
893 EXPORT_SPEC int UpnpInitWithOptions(
894  const char *IfName,
895  unsigned short DestPort,
897  unsigned int flags,
898  ...
899  );
900 
901 
921 EXPORT_SPEC int UpnpFinish(void);
922 
934 EXPORT_SPEC unsigned short UpnpGetServerPort(void);
935 
936 #ifdef UPNP_ENABLE_IPV6
947 EXPORT_SPEC unsigned short UpnpGetServerPort6(void);
948 
960 EXPORT_SPEC unsigned short UpnpGetServerUlaGuaPort6(void);
961 #endif
962 
974 EXPORT_SPEC const char *UpnpGetServerIpAddress(void);
975 
976 #ifdef UPNP_ENABLE_IPV6
989 EXPORT_SPEC const char *UpnpGetServerIp6Address(void);
990 
992 EXPORT_SPEC const char *UpnpGetServerUlaGuaIp6Address(void);
993 #endif
994 
1010 EXPORT_SPEC int UpnpSetMaxContentLength(
1013  size_t contentLength);
1014 
1058 EXPORT_SPEC int UpnpRegisterRootDevice(
1061  const char *DescUrl,
1063  Upnp_FunPtr Fun,
1065  const void *Cookie,
1067  UpnpDevice_Handle *Hnd);
1068 
1117 EXPORT_SPEC int UpnpRegisterRootDevice2(
1119  Upnp_DescType descriptionType,
1122  const char* description,
1125  size_t bufferLen,
1127  int ignored,
1129  Upnp_FunPtr Fun,
1131  const void* Cookie,
1133  UpnpDevice_Handle* Hnd);
1134 
1171 EXPORT_SPEC int UpnpRegisterRootDevice4(
1174  const char *DescUrl,
1176  Upnp_FunPtr Fun,
1178  const void *Cookie,
1180  UpnpDevice_Handle *Hnd,
1182  int,
1185  const char *LowerDescUrl);
1186 
1195 EXPORT_SPEC int UpnpDeviceSetProduct(
1197  UpnpDevice_Handle Hnd,
1199  const char *product,
1201  const char *version);
1202 
1219  UpnpDevice_Handle Hnd);
1220 
1240  UpnpDevice_Handle Hnd,
1242  int PowerState,
1244  int SleepPeriod,
1246  int RegistrationState);
1247 
1272 EXPORT_SPEC int UpnpRegisterClient(
1274  Upnp_FunPtr Fun,
1276  const void *Cookie,
1278  UpnpClient_Handle *Hnd);
1279 
1284 EXPORT_SPEC void UpnpClientSetProduct(
1286  UpnpClient_Handle Hnd,
1288  const char *product,
1290  const char *version);
1291 
1309 EXPORT_SPEC int UpnpUnRegisterClient(
1311  UpnpClient_Handle Hnd);
1312 
1316 /******************************************************************************
1317  * *
1318  * D I S C O V E R Y *
1319  * *
1320  ******************************************************************************/
1342 EXPORT_SPEC int UpnpSearchAsync(
1344  UpnpClient_Handle Hnd,
1349  int Mx,
1352  const char *Target,
1354  const void *cookie);
1355 
1377 EXPORT_SPEC int UpnpSearchAsyncUnicast(
1379  UpnpClient_Handle Hnd,
1382  const std::string& url,
1384  const char *Target,
1386  void *cookie);
1387 
1409 EXPORT_SPEC int UpnpSendAdvertisement(
1411  UpnpDevice_Handle Hnd,
1417  int Exp);
1418 
1439  UpnpDevice_Handle Hnd,
1445  int Exp,
1447  int PowerState,
1449  int SleepPeriod,
1451  int RegistrationState);
1452 
1459 /******************************************************************************
1460  * *
1461  * C O N T R O L *
1462  * *
1463  ******************************************************************************/
1500 EXPORT_SPEC int UpnpSendAction(
1501  UpnpClient_Handle Hnd,
1502  const std::string& headerString,
1503  const std::string& actionURL,
1504  const std::string& serviceType,
1505  const std::string& actionName,
1506  const std::vector<std::pair<std::string, std::string>>& actionParams,
1507  std::vector<std::pair<std::string, std::string>>& responseData,
1508  int* errcodep,
1509  std::string& errdesc);
1510 
1513 /******************************************************************************
1514  * *
1515  * E V E N T I N G *
1516  * *
1517  ******************************************************************************/
1518 
1548 EXPORT_SPEC int UpnpAcceptSubscription(
1550  UpnpDevice_Handle Hnd,
1552  const char *DevID,
1554  const char *ServName,
1556  const char **VarName,
1558  const char **NewVal,
1560  int cVariables,
1562  const Upnp_SID& SubsId);
1563 
1566  UpnpDevice_Handle Hnd,
1568  const char *DevID,
1570  const char *ServName,
1572  const std::string& propertyset,
1574  const Upnp_SID& SubsId);
1575 
1597 EXPORT_SPEC int UpnpNotify(
1601  const char *DevID,
1603  const char *ServName,
1605  const char **VarName,
1607  const char **NewVal,
1609  int cVariables);
1610 
1611 EXPORT_SPEC int UpnpNotifyXML(
1615  const char *DevID,
1617  const char *ServName,
1619  const std::string& propset);
1620 
1634 EXPORT_SPEC int UpnpSetMaxSubscriptions(
1637  UpnpDevice_Handle Hnd,
1639  int MaxSubscriptions);
1640 
1676 EXPORT_SPEC int UpnpSubscribe(
1678  UpnpClient_Handle Hnd,
1680  const char *EvtUrl,
1684  int *TimeOut,
1686  Upnp_SID& SubsId);
1687 
1718 EXPORT_SPEC int UpnpRenewSubscription(
1720  UpnpClient_Handle Hnd,
1723  int *TimeOut,
1725  const Upnp_SID& SubsId);
1726 
1756 EXPORT_SPEC int UpnpUnSubscribe(
1758  UpnpClient_Handle Hnd,
1760  const Upnp_SID& SubsId);
1761 
1780  UpnpDevice_Handle Hnd,
1782  int MaxSubscriptionTimeOut);
1783 
1798 EXPORT_SPEC int UpnpSubsOpsTimeoutMs(
1800  UpnpClient_Handle Hnd,
1802  int TimeOutMS);
1803 
1837 EXPORT_SPEC int UpnpDownloadUrlItem(
1839  const char *url,
1842  char **outBuf,
1845  char *contentType);
1846 
1852 EXPORT_SPEC int UpnpDownloadUrlItem(
1854  const std::string& url,
1856  std::string& data,
1858  std::string& ct);
1859 
1863 /******************************************************************************
1864  * *
1865  * W E B S E R V E R A P I *
1866  * *
1867  ******************************************************************************/
1868 
1882 EXPORT_SPEC int UpnpEnableWebserver(
1884  int enable);
1885 
1893 EXPORT_SPEC int UpnpIsWebserverEnabled(void);
1894 
1907 EXPORT_SPEC int UpnpSetWebServerRootDir(
1909  const char *rootDir);
1910 
1924 EXPORT_SPEC std::string UpnpGetUrlHostPortForClient(const struct sockaddr_storage*);
1925 
1926 /*
1927  * @brief Callback for validating HTTP requests HOST header values.
1928  *
1929  * This is called when a GET/POST/HEAD request to the Web server contains a host
1930  * name (instead of a numeric address) in the HOST header. The client code can chose
1931  * to authorize the request. Else it will be either redirected to a numeric
1932  * address or rejected depending on the UPNP_FLAG_REJECT_HOSTNAMES
1933  * option. Specific UPnP (SOAP/SUBSCRIBE...) requests are always checked to
1934  * contain a numeric address and will not trigger the callback.
1935  *
1936  * @param hostname the value in the request HOST header.
1937  * @return An integer representing one of the following:
1938  * \li \c UPNP_E_SUCCESS: a request with the HOST header set to hostname should be processed.
1939  * \li \c UPNP_E_BAD_HTTPMSG the request should be redirected or rejected.
1940  */
1941 typedef int (*WebCallback_HostValidate)(const char *hostname, void *cookie);
1942 
1943 EXPORT_SPEC int UpnpSetWebRequestHostValidateCallback(
1944  WebCallback_HostValidate callback, void *cookie);
1945 
1948  WebCallback_HostValidate callback, void *cookie);
1949 
1950 
1952 typedef void *UpnpWebFileHandle;
1953 
1958 typedef int (*VDCallback_GetInfo)(
1960  const char *filename,
1962  struct File_Info *info,
1963  const void *cookie,
1964  const void **request_cookiep
1965  );
1966 
1976 
1980  const char *filename,
1983  enum UpnpOpenFileMode Mode,
1984  const void *cookie,
1985  const void *request_cookie
1986  );
1987 
1997 
1999 typedef int (*VDCallback_Read)(
2001  UpnpWebFileHandle fileHnd,
2003  char *buf,
2005  size_t buflen,
2006  const void *cookie,
2007  const void *request_cookie
2008  );
2009 
2019 
2021 typedef int (*VDCallback_Write)(
2023  UpnpWebFileHandle fileHnd,
2025  char *buf,
2027  size_t buflen,
2028  const void *cookie,
2029  const void *request_cookie
2030  );
2031 
2041 
2043 typedef int (*VDCallback_Seek) (
2045  UpnpWebFileHandle fileHnd,
2049  int64_t offset,
2054  int origin,
2055  const void *cookie,
2056  const void *request_cookie
2057  );
2058 
2068 
2070 typedef int (*VDCallback_Close)(
2072  UpnpWebFileHandle fileHnd,
2073  const void *cookie,
2074  const void *request_cookie
2075  );
2076 
2086 
2094 {
2107 };
2108 
2118  struct UpnpVirtualDirCallbacks *callbacks );
2119 
2139 EXPORT_SPEC int UpnpAddVirtualDir(
2140  const char *dirName, const void *cookie, const void **oldcookie);
2141 
2149 EXPORT_SPEC int UpnpRemoveVirtualDir(
2151  const char *dirName);
2152 
2156 EXPORT_SPEC void UpnpRemoveAllVirtualDirs(void);
2157 
2158 /* @} Web Server API */
2159 
2160 #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:2094
VDCallback_Open open
VDCallback_Open callback
Definition: upnp.h:2098
VDCallback_Seek seek
VDCallback_Seek callback
Definition: upnp.h:2104
VDCallback_Read read
VDCallback_Read callback
Definition: upnp.h:2100
VDCallback_GetInfo get_info
VDCallback_GetInfo callback
Definition: upnp.h:2096
VDCallback_Write write
VDCallback_Write callback
Definition: upnp.h:2102
VDCallback_Close close
VDCallback_Close callback
Definition: upnp.h:2106
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:2070
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 UpnpInitWithOptions(const char *IfName, unsigned short DestPort, unsigned int flags,...)
Initializes the library, passing the interface spec as a string.
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 const char * UpnpGetServerIpAddress(void)
Returns a local IPv4 listening ip address.
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:1952
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 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:1958
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 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.
#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 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 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:2021
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:1999
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:1978
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:2043
EXPORT_SPEC int UpnpInit2(const char *IfName, unsigned short DestPort)
Initializes the library, passing the interface spec as a single string.