47 #include "upnpconfig.h"
55 #if defined(UPNP_USE_MSVCPP) || defined(UPNP_USE_BCBPP)
56 #include <sys/types.h>
58 #elif (defined(BSD) && BSD >= 199306)
64 #ifdef UPNP_ENABLE_OPEN_SSL
65 #include <openssl/ssl.h>
68 #define LINE_SIZE (size_t)180
69 #define NAME_SIZE (size_t)256
70 #define MNFT_NAME_SIZE 64
71 #define MODL_NAME_SIZE 32
72 #define SERL_NUMR_SIZE 64
73 #define MODL_DESC_SIZE 64
74 #define UPNP_INFINITE -1
75 #define UPNP_USING_CHUNKED -3
76 #define UPNP_UNTIL_CLOSE -4
97 #define UPNP_E_SUCCESS 0
102 #define UPNP_E_INVALID_HANDLE -100
110 #define UPNP_E_INVALID_PARAM -101
117 #define UPNP_E_OUTOF_HANDLE -102
119 #define UPNP_E_OUTOF_CONTEXT -103
127 #define UPNP_E_OUTOF_MEMORY -104
135 #define UPNP_E_INIT -105
137 #define UPNP_E_BUFFER_TOO_SMALL -106
144 #define UPNP_E_INVALID_DESC -107
153 #define UPNP_E_INVALID_URL -108
155 #define UPNP_E_INVALID_SID -109
157 #define UPNP_E_INVALID_DEVICE -110
165 #define UPNP_E_INVALID_SERVICE -111
173 #define UPNP_E_BAD_RESPONSE -113
175 #define UPNP_E_BAD_REQUEST -114
183 #define UPNP_E_INVALID_ACTION -115
191 #define UPNP_E_FINISH -116
198 #define UPNP_E_INIT_FAILED -117
205 #define UPNP_E_URL_TOO_BIG -118
216 #define UPNP_E_BAD_HTTPMSG -119
224 #define UPNP_E_ALREADY_REGISTERED -120
230 #define UPNP_E_INVALID_INTERFACE -121
239 #define UPNP_E_NETWORK_ERROR -200
249 #define UPNP_E_SOCKET_WRITE -201
259 #define UPNP_E_SOCKET_READ -202
269 #define UPNP_E_SOCKET_BIND -203
279 #define UPNP_E_SOCKET_CONNECT -204
289 #define UPNP_E_OUTOF_SOCKET -205
297 #define UPNP_E_LISTEN -206
305 #define UPNP_E_TIMEDOUT -207
313 #define UPNP_E_SOCKET_ERROR -208
315 #define UPNP_E_FILE_WRITE_ERROR -209
322 #define UPNP_E_CANCELED -210
324 #define UPNP_E_EVENT_PROTOCOL -300
329 #define UPNP_E_SUBSCRIBE_UNACCEPTED -301
334 #define UPNP_E_UNSUBSCRIBE_UNACCEPTED -302
339 #define UPNP_E_NOTIFY_UNACCEPTED -303
347 #define UPNP_E_INVALID_ARGUMENT -501
353 #define UPNP_E_FILE_NOT_FOUND -502
358 #define UPNP_E_FILE_READ_ERROR -503
364 #define UPNP_E_EXT_NOT_XML -504
366 #define UPNP_E_NO_WEB_SERVER -505
367 #define UPNP_E_OUTOF_BOUNDS -506
373 #define UPNP_E_NOT_FOUND -507
379 #define UPNP_E_INTERNAL_ERROR -911
382 #define UPNP_SOAP_E_INVALID_ACTION 401
383 #define UPNP_SOAP_E_INVALID_ARGS 402
384 #define UPNP_SOAP_E_OUT_OF_SYNC 403
385 #define UPNP_SOAP_E_INVALID_VAR 404
386 #define UPNP_SOAP_E_ACTION_FAILED 501
416 enum UpnpOpenFileMode
552 unsigned short DestPort);
566 #ifdef UPNP_ENABLE_OPEN_SSL
575 const SSL_METHOD *sslMethod);
796 Upnp_DescType descriptionType,
799 const char *description,
919 const char *LowerDescUrl);
968 int RegistrationState);
1029 size_t contentLength);
1050 size_t contentLength);
1101 const char *TTarget_constarget_const,
1103 const void *Cookie_const);
1162 int RegistrationState);
1209 const char *ActionURL,
1211 const char *VarName,
1238 const char *ActionURL,
1240 const char *VarName,
1246 const void *Cookie);
1275 const char *ActionURL,
1277 const char *ServiceType,
1313 const char *ActionURL,
1315 const char *ServiceType,
1352 const char *ActionURL,
1354 const char *ServiceType,
1364 const void *Cookie);
1391 const char *ActionURL,
1393 const char *ServiceType,
1406 const void *Cookie);
1459 const char **VarName,
1461 const char **NewVal,
1535 const char **VarName,
1537 const char **NewVal,
1674 const void *Cookie);
1694 int MaxSubscriptions);
1715 int MaxSubscriptionTimeOut);
1750 const char *PublisherUrl,
1810 const char *PublisherUrl,
1817 const void *Cookie);
1914 const void *Cookie);
1937 UPNP_HTTPMETHOD_PUT = 0,
1938 UPNP_HTTPMETHOD_DELETE = 1,
1939 UPNP_HTTPMETHOD_GET = 2,
1940 UPNP_HTTPMETHOD_HEAD = 3,
1941 UPNP_HTTPMETHOD_POST = 4
2062 const char *proxy_str,
2235 const char *contentType,
2357 Upnp_HttpMethod method,
2370 const char *contentType,
2597 const char *rootDir);
2609 const char *filename,
2616 const void **request_cookie);
2633 const char *filename,
2636 enum UpnpOpenFileMode Mode,
2640 const void *request_cookie);
2657 UpnpWebFileHandle fileHnd,
2665 const void *request_cookie);
2682 UpnpWebFileHandle fileHnd,
2690 const void *request_cookie);
2707 UpnpWebFileHandle fileHnd,
2720 const void *request_cookie);
2737 UpnpWebFileHandle fileHnd,
2741 const void *request_cookie);
2785 typedef int (*WebCallback_HostValidate)(
const char *hostname,
void *cookie);
2794 WebCallback_HostValidate callback,
void *cookie);
2801 EXPORT_SPEC void UpnpSetAllowLiteralHostRedirection(
int enable);
2819 const char *dirName,
2824 const void **oldcookie);
2835 const char *dirName);
int UpnpDownloadXmlDoc(const char *url, IXML_Document **xmlDoc)
Downloads an XML document specified in a URL.
Definition: upnpapi.c:3480
int UpnpClient_Handle
Returned when a control point application registers with UpnpRegisterClient.
Definition: upnp.h:429
int(* Upnp_FunPtr)(Upnp_EventType EventType, const void *Event, void *Cookie)
Definition: Callback.h:145
int UpnpRegisterRootDevice3(const char *DescUrl, Upnp_FunPtr Callback, const void *Cookie, UpnpDevice_Handle *Hnd, int AddressFamily)
Registers a device application for a specific address family with the UPnP library.
Definition: upnpapi.c:1213
int UpnpRegisterRootDevice2(Upnp_DescType descriptionType, const char *description, size_t bufferLen, int config_baseURL, Upnp_FunPtr Fun, const void *Cookie, UpnpDevice_Handle *Hnd)
Registers a device application with the UPnP Library. Similar to UpnpRegisterRootDevice, except that it also allows the description document to be specified as a file or a memory buffer.
Definition: upnpapi.c:1041
int UpnpRegisterRootDevice(const char *DescUrl, Upnp_FunPtr Callback, const void *Cookie, UpnpDevice_Handle *Hnd)
Registers a device application with the UPnP Library.
Definition: upnpapi.c:848
int UpnpAcceptSubscription(UpnpDevice_Handle Hnd, const char *DevID, const char *ServID, 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...
Definition: upnpapi.c:2627
int UpnpSetWebServerRootDir(const char *rootDir)
Sets the document root directory for the internal web server.
Upnp_DescType_e
Specifies the type of description in UpnpRegisterRootDevice2.
Definition: upnp.h:483
int UpnpOpenHttpPost(const char *url, void **handle, const char *contentType, int contentLength, int timeout)
Makes an HTTP POST request message, opens a connection to the server and sends the POST request to th...
Definition: upnpapi.c:3276
Header file for UpnpActionRequest methods.
int UpnpSendActionExAsync(UpnpClient_Handle Hnd, const char *ActionURL, const char *ServiceType, const char *DevUDN, IXML_Document *Header, IXML_Document *Action, Upnp_FunPtr Fun, const void *Cookie)
Sends a message to change a state variable in a service, generating a callback when the operation is ...
Definition: upnpapi.c:3016
int UpnpVirtualDir_set_GetInfoCallback(VDCallback_GetInfo callback)
Sets the get_info callback function to be used to access a virtual directory.
Definition: upnpapi.c:4425
void UpnpRemoveAllVirtualDirs(void)
Removes all virtual directory mappings.
Definition: upnpapi.c:4353
int UpnpGetServiceVarStatusAsync(UpnpClient_Handle Hnd, const char *ActionURL, const char *VarName, Upnp_FunPtr Fun, const void *Cookie)
Queries the state of a variable of a service, generating a callback when the operation is complete...
Definition: upnpapi.c:3145
int UpnpRenewSubscription(UpnpClient_Handle Hnd, int *TimeOut, const Upnp_SID SubsId)
Renews a subscription that is about to expire.
Definition: upnpapi.c:2398
Header file for UpnpStateVarRequest methods.
int UpnpCloseHttpPost(void *handle, int *httpStatus, int timeout)
Sends and receives any pending data, closes the connection with the server, and frees memory allocate...
Definition: upnpapi.c:3300
UpnpWebFileHandle(* VDCallback_Open)(const char *filename, enum UpnpOpenFileMode Mode, const void *cookie, const void *request_cookie)
Open callback function prototype.
Definition: upnp.h:2631
Upnp_SType_e
Represents the different types of searches that can be performed using the SDK for UPnP Devices API...
Definition: upnp.h:458
int UpnpOpenHttpGetProxy(const char *url, const char *proxy_str, void **handle, char **contentType, int *contentLength, int *httpStatus, int timeout)
Gets a file specified in a URL through the specified proxy.
Definition: upnpapi.c:3342
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.
Definition: upnpapi.c:1858
unsigned short UpnpGetServerPort(void)
Returns the internal server IPv4 UPnP listening port.
Definition: upnpapi.c:717
int UpnpUnSubscribeAsync(UpnpClient_Handle Hnd, Upnp_SID SubsId, Upnp_FunPtr Fun, const void *Cookie)
Removes a subscription of a control point from a service previously subscribed to using UpnpSubscribe...
Definition: upnpapi.c:2323
int UpnpSetMaxSubscriptions(UpnpDevice_Handle Hnd, int MaxSubscriptions)
Sets the maximum number of subscriptions accepted per service.
Definition: upnpapi.c:2037
int UpnpRemoveVirtualDir(const char *dirName)
Removes a virtual directory mapping made with UpnpAddVirtualDir.
Definition: upnpapi.c:4306
int UpnpSubscribe(UpnpClient_Handle Hnd, const char *PublisherUrl, int *TimeOut, Upnp_SID SubsId)
Registers a control point to receive event notifications from another device.
Definition: upnpapi.c:2198
int UpnpUnRegisterRootDeviceLowPower(UpnpDevice_Handle Hnd, int PowerState, int SleepPeriod, int RegistrationState)
Unregisters a root device registered with UpnpRegisterRootDevice, UpnpRegisterRootDevice2, UpnpRegisterRootDevice3 or UpnpRegisterRootDevice4.
Definition: upnpapi.c:1418
int UpnpMakeHttpRequest(Upnp_HttpMethod method, const char *url, void *handle, UpnpString *headers, const char *contentType, int contentLength, int timeout)
Makes a HTTP request using a connection previously created by UpnpOpenHttpConnection.
Definition: upnpapi.c:3412
int UpnpCloseHttpGet(void *handle)
Closes the connection and frees memory that was allocated for the handle parameter.
Definition: upnpapi.c:3395
int UpnpRegisterRootDevice4(const char *DescUrl, Upnp_FunPtr Callback, const void *Cookie, UpnpDevice_Handle *Hnd, int AddressFamily, const char *LowerDescUrl)
Registers a device application for a specific address family with the UPnP library. This function can also be used to specify a dedicated description URL to be returned for legacy CPs.
Definition: upnpapi.c:1230
int UpnpReadHttpGet(void *handle, char *buf, size_t *size, int timeout)
Gets specified number of bytes from a file specified in a URL.
Definition: upnpapi.c:3397
int UpnpUnSubscribe(UpnpClient_Handle Hnd, const Upnp_SID SubsId)
Removes the subscription of a control point from a service previously subscribed to using UpnpSubscri...
Definition: upnpapi.c:2271
int UpnpVirtualDir_set_CloseCallback(VDCallback_Close callback)
Sets the close callback function to be used to access a virtual directory.
Definition: upnpapi.c:4485
unsigned short UpnpGetServerUlaGuaPort6(void)
Returns the internal server IPv6 ULA or GUA UPnP listening port.
Definition: upnpapi.c:737
Header file for UpnpDiscovery methods.
int UpnpSetContentLength(UpnpClient_Handle Hnd, size_t contentLength)
Definition: upnpapi.c:4497
int UpnpVirtualDir_set_OpenCallback(VDCallback_Open callback)
Sets the open callback function to be used to access a virtual directory.
Definition: upnpapi.c:4437
int UpnpOpenHttpGetEx(const char *url, void **handle, char **contentType, int *contentLength, int *httpStatus, int lowRange, int highRange, int timeout)
Gets specified number of bytes from a file specified in the URL.
Definition: upnpapi.c:3374
int(* VDCallback_Close)(UpnpWebFileHandle fileHnd, const void *cookie, const void *request_cookie)
Close callback function prototype.
Definition: upnp.h:2735
Header file for UpnpEventSubscribe methods.
int UpnpInit2(const char *IfName, unsigned short DestPort)
Initializes the Linux SDK for UPnP Devices (IPv4 or IPv6).
Definition: upnpapi.c:497
int UpnpUnRegisterRootDevice(UpnpDevice_Handle Hnd)
Unregisters a root device registered with UpnpRegisterRootDevice, UpnpRegisterRootDevice2, UpnpRegisterRootDevice3 or UpnpRegisterRootDevice4.
Definition: upnpapi.c:1408
Header file for UpnpSubscriptionRequest methods.
int UpnpSendAdvertisement(UpnpDevice_Handle Hnd, int Exp)
Sends out the discovery announcements for all devices and services for a device.
Definition: upnpapi.c:1848
int UpnpEndHttpRequest(void *handle, int timeout)
Indicates the end of a HTTP request previously made by UpnpMakeHttpRequest.
Definition: upnpapi.c:3434
int(* VDCallback_Read)(UpnpWebFileHandle fileHnd, char *buf, size_t buflen, const void *cookie, const void *request_cookie)
Read callback function prototype.
Definition: upnp.h:2655
int UpnpVirtualDir_set_SeekCallback(VDCallback_Seek callback)
Sets the seek callback function to be used to access a virtual directory.
Definition: upnpapi.c:4473
int UpnpIsWebserverEnabled(void)
Returns 1 if the webserver is enabled, or 0 if it is not.
Definition: upnpapi.c:4404
int UpnpVirtualDir_set_ReadCallback(VDCallback_Read callback)
Sets the read callback function to be used to access a virtual directory.
Definition: upnpapi.c:4449
int UpnpSendAction(UpnpClient_Handle Hnd, const char *ActionURL, const char *ServiceType, const char *DevUDN, IXML_Document *Action, IXML_Document **RespNode)
Sends a message to change a state variable in a service.
Definition: upnpapi.c:2802
Provides a platform independent way to include TCP/IP types and functions.
int UpnpAddVirtualDir(const char *dirName, const void *cookie, const void **oldcookie)
Adds a virtual directory mapping.
Definition: upnpapi.c:4237
int UpnpDownloadUrlItem(const char *url, char **outBuf, char *contentType)
Downloads a file specified in a URL.
Definition: upnpapi.c:3464
Header file for UpnpStateVarComplete methods.
int UpnpWriteHttpPost(void *handle, char *buf, size_t *size, int timeout)
Sends a request to a server to copy the contents of a buffer to the URI specified in the UpnpOpenHttp...
Definition: upnpapi.c:3295
int UpnpInitSslContext(int initOpenSslLib, const SSL_METHOD *sslMethod)
Initializes the OpenSSL library, and the OpenSSL context for use with pupnp.
int UpnpCancelHttpGet(void *handle)
Set the cancel flag of the handle parameter.
Definition: upnpapi.c:3393
int(* VDCallback_GetInfo)(const char *filename, UpnpFileInfo *info, const void *cookie, const void **request_cookie)
Get-info callback function prototype.
Definition: upnp.h:2607
int UpnpDevice_Handle
Returned when a device application registers with UpnpRegisterRootDevice, UpnpRegisterRootDevice2, UpnpRegisterRootDevice3 or UpnpRegisterRootDevice4.
Definition: upnp.h:439
int UpnpNotify(UpnpDevice_Handle, const char *DevID, const char *ServID, const char **VarName, const char **NewVal, int cVariables)
Sends out an event change notification to all control points subscribed to a particular service...
int UpnpGetHttpResponse(void *handle, UpnpString *headers, char **contentType, int *contentLength, int *httpStatus, int timeout)
Gets the response from the server using a connection previously created by UpnpOpenHttpConnection.
Definition: upnpapi.c:3439
int UpnpOpenHttpGet(const char *url, void **handle, char **contentType, int *contentLength, int *httpStatus, int timeout)
Gets a file specified in a URL.
Definition: upnpapi.c:3311
int UpnpSetMaxSubscriptionTimeOut(UpnpDevice_Handle Hnd, int MaxSubscriptionTimeOut)
Sets the maximum time-out accepted for a subscription request or renewal.
Definition: upnpapi.c:2077
unsigned short UpnpGetServerPort6(void)
Returns the internal server IPv6 link-local (LLA) UPnP listening port.
Definition: upnpapi.c:725
int UpnpHttpGetProgress(void *handle, size_t *length, size_t *total)
Retrieve progress information of a http-get transfer.
Definition: upnpapi.c:3402
int UpnpSendActionEx(UpnpClient_Handle Hnd, const char *ActionURL, const char *ServiceType, const char *DevUDN, IXML_Document *Header, IXML_Document *Action, IXML_Document **RespNode)
Sends a message to change a state variable in a service.
Definition: upnpapi.c:2859
int UpnpOpenHttpConnection(const char *url, void **handle, int timeout)
Opens a connection to the server.
Definition: upnpapi.c:3407
Header file for UpnpEvent methods.
Definition: UpnpFileInfo.c:18
int UpnpNotifyExt(UpnpDevice_Handle, const char *DevID, const char *ServID, IXML_Document *PropSet)
Similar to UpnpNotify except that it takes a DOM document for the event rather than an array of strin...
int UpnpVirtualDir_set_WriteCallback(VDCallback_Write callback)
Sets the write callback function to be used to access a virtual directory.
Definition: upnpapi.c:4461
int UpnpCloseHttpConnection(void *handle)
Closes the connection created with UpnpOpenHttpConnection and frees any memory associated with the co...
Definition: upnpapi.c:3459
#define DOMString
The type of DOM strings.
Definition: ixml.h:48
char * UpnpGetServerIpAddress(void)
Returns the local IPv4 listening ip address.
Definition: upnpapi.c:749
char * UpnpGetServerIp6Address(void)
Returns the IPv6 link-local listening ip address.
Definition: upnpapi.c:757
void * UpnpWebFileHandle
The type of handle returned by the web server for open requests.
Definition: upnp.h:2602
int UpnpUnRegisterClient(UpnpClient_Handle Hnd)
Unregisters a control point application, unsubscribing all active subscriptions.
Definition: upnpapi.c:1562
Data structure representing the DOM Document.
Definition: ixml.h:159
int UpnpSendActionAsync(UpnpClient_Handle Hnd, const char *ActionURL, const char *ServiceType, const char *DevUDN, IXML_Document *Action, Upnp_FunPtr Fun, const void *Cookie)
Sends a message to change a state variable in a service, generating a callback when the operation is ...
Definition: upnpapi.c:2917
int UpnpSubscribeAsync(UpnpClient_Handle Hnd, const char *PublisherUrl, int TimeOut, Upnp_FunPtr Fun, const void *Cookie)
Performs the same operation as UpnpSubscribe, but returns immediately and calls the registered callba...
Definition: upnpapi.c:2121
Header file for UpnpFileInfo methods.
struct s_UpnpString UpnpString
Type of the string objects inside libupnp.
Definition: UpnpString.h:38
Upnp_HttpMethod_e
Different HTTP methods.
Definition: upnp.h:1935
char Upnp_SID[44]
Holds the subscription identifier for a subscription between a client and a device.
Definition: upnp.h:448
int UpnpFinish(void)
Terminates the Linux SDK for UPnP Devices.
Definition: upnpapi.c:626
int(* VDCallback_Seek)(UpnpWebFileHandle fileHnd, off_t offset, int origin, const void *cookie, const void *request_cookie)
Seek callback function prototype.
Definition: upnp.h:2705
int UpnpRenewSubscriptionAsync(UpnpClient_Handle Hnd, int TimeOut, Upnp_SID SubsId, Upnp_FunPtr Fun, const void *Cookie)
Renews a subscription that is about to expire, generating a callback when the operation is complete...
Definition: upnpapi.c:2459
int(* VDCallback_Write)(UpnpWebFileHandle fileHnd, char *buf, size_t buflen, const void *cookie, const void *request_cookie)
Write callback function prototype.
Definition: upnp.h:2680
int UpnpWriteHttpRequest(void *handle, char *buf, size_t *size, int timeout)
Writes the content of a HTTP request initiated by a UpnpMakeHttpRequest call. The end of the content ...
Definition: upnpapi.c:3429
int UpnpSearchAsync(UpnpClient_Handle Hnd, int Mx, const char *TTarget_constarget_const, const void *Cookie_const)
Searches for devices matching the given search target.
Definition: upnpapi.c:1981
int UpnpAcceptSubscriptionExt(UpnpDevice_Handle Hnd, const char *DevID, const char *ServID, IXML_Document *PropSet, const Upnp_SID SubsId)
Similar to UpnpAcceptSubscription() except that it takes a DOM document for the variables to event ra...
Definition: upnpapi.c:2712
int UpnpReadHttpResponse(void *handle, char *buf, size_t *size, int timeout)
Reads the content of a response using a connection previously created by UpnpOpenHttpConnection.
Definition: upnpapi.c:3454
int UpnpSetMaxContentLength(size_t contentLength)
Sets the maximum content-length that the SDK will process on an incoming SOAP requests or responses...
Definition: upnpapi.c:4528
int UpnpEnableWebserver(int enable)
Enables or disables the webserver.
Definition: upnpapi.c:4374
#define EXPORT_SPEC
Export functions on WIN32 DLLs.
Definition: UpnpGlobal.h:91
Defines constants that for some reason are not defined on some systems.
int UpnpRegisterClient(Upnp_FunPtr Callback, const void *Cookie, UpnpClient_Handle *Hnd)
Registers a control point application with the UPnP Library.
Definition: upnpapi.c:1506
char * UpnpGetServerUlaGuaIp6Address(void)
Returns the IPv6 unique-local or globally-unique listening ip address.
Definition: upnpapi.c:769
int UpnpGetServiceVarStatus(UpnpClient_Handle Hnd, const char *ActionURL, const char *VarName, DOMString *StVarVal)
Queries the state of a state variable of a service on another device.
Definition: upnpapi.c:3217
Header file for UpnpActionComplete methods.