upnpapi.h
Go to the documentation of this file.
/*******************************************************************************
*
* Copyright (c) 2000-2003 Intel Corporation
* All rights reserved.
* Copyright (C) 2011-2012 France Telecom All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
#ifndef UPNPAPI_H
#define UPNPAPI_H
#include "GenlibClientSubscription.h"
#include "TimerThread.h"
#include "VirtualDir.h" /* for struct VirtualDirCallbacks */
#include "service_table.h"
#define MAX_INTERFACES 256
#define DEV_LIMIT 200
#define DEFAULT_MX 5
#define DEFAULT_MAXAGE 1800
#define DEFAULT_SOAP_CONTENT_LENGTH 16000
#define MAX_SOAP_CONTENT_LENGTH (size_t)32000
#define NUM_HANDLE 200
extern size_t g_maxContentLength;
extern int g_UpnpSdkEQMaxLen;
extern int g_UpnpSdkEQMaxAge;
/* 30-second timeout */
#define UPNP_TIMEOUT 30
typedef enum
{
HND_INVALID = -1,
HND_CLIENT,
HND_DEVICE
} Upnp_Handle_Type;
/* Data to be stored in handle table for */
struct Handle_Info
{
Upnp_Handle_Type HType;
Upnp_FunPtr Callback;
char *Cookie;
int aliasInstalled;
/* Device Only */
#ifdef INCLUDE_DEVICE_APIS
char DescURL[LINE_SIZE];
char LowerDescURL[LINE_SIZE];
char DescXML[LINE_SIZE];
/* Advertisement timeout */
int MaxAge;
/* Power State as defined by UPnP Low Power. */
int PowerState;
/* Sleep Period as defined by UPnP Low Power. */
int SleepPeriod;
/* Registration State as defined by UPnP Low Power. */
int RegistrationState;
IXML_Document *DescDocument;
IXML_NodeList *DeviceList;
IXML_NodeList *ServiceList;
service_table ServiceTable;
int MaxSubscriptions;
int MaxSubscriptionTimeOut;
int DeviceAf;
#endif
/* Client only */
#ifdef INCLUDE_CLIENT_APIS
GenlibClientSubscription *ClientSubList;
LinkedList SsdpSearchList;
#endif
};
extern ithread_rwlock_t GlobalHndRWLock;
static enum Upnp_LogLevel_e debug_handle = UPNP_NEVER;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
Upnp_Handle_Type GetHandleInfo(
int Hnd,
struct Handle_Info **HndInfo);
static void HandleUnlock(const char *file, int line)
{
UpnpPrintf(debug_handle, API, file, line, "Trying Unlock\n");
ithread_rwlock_unlock(&GlobalHndRWLock);
UpnpPrintf(debug_handle, API, file, line, "Unlocked rwlock\n");
}
static void HandleReadLock(const char *file, int line)
{
UpnpPrintf(debug_handle, API, file, line, "Trying a read lock\n");
ithread_rwlock_rdlock(&GlobalHndRWLock);
UpnpPrintf(debug_handle, API, file, line, "Read lock acquired\n");
}
static void HandleWriteLock(const char *file, int line)
{
UpnpPrintf(debug_handle, API, file, line, "Trying a write lock\n");
ithread_rwlock_wrlock(&GlobalHndRWLock);
UpnpPrintf(debug_handle, API, file, line, "Write lock acquired\n");
}
static void HandleLock(const char *file, int line)
{
HandleWriteLock(file, line);
}
#pragma GCC diagnostic pop
Upnp_Handle_Type GetClientHandleInfo(
int *client_handle_out,
struct Handle_Info **HndInfo);
Upnp_Handle_Type GetDeviceHandleInfo(
UpnpDevice_Handle start,
int AddressFamily,
int *device_handle_out,
struct Handle_Info **HndInfo);
Upnp_Handle_Type GetDeviceHandleInfoForPath(
const char *path,
int AddressFamily,
int *device_handle_out,
struct Handle_Info **HndInfo,
service_info **serv_info);
extern char gIF_NAME[LINE_SIZE];
extern char gIF_IPV4[INET_ADDRSTRLEN];
extern char gIF_IPV4_NETMASK[INET_ADDRSTRLEN];
extern char gIF_IPV6[INET6_ADDRSTRLEN];
extern unsigned gIF_IPV6_PREFIX_LENGTH;
extern char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN];
extern unsigned gIF_IPV6_ULA_GUA_PREFIX_LENGTH;
extern unsigned gIF_INDEX;
extern unsigned short LOCAL_PORT_V4;
extern unsigned short LOCAL_PORT_V6;
extern unsigned short LOCAL_PORT_V6_ULA_GUA;
extern Upnp_SID gUpnpSdkNLSuuid;
extern TimerThread gTimerThread;
extern ThreadPool gRecvThreadPool;
extern ThreadPool gSendThreadPool;
extern ThreadPool gMiniServerThreadPool;
typedef enum
{
SUBSCRIBE,
UNSUBSCRIBE,
DK_NOTIFY,
QUERY,
ACTION,
STATUS,
DEVDESCRIPTION,
SERVDESCRIPTION,
MINI,
RENEW
} UpnpFunName;
struct UpnpNonblockParam
{
UpnpFunName FunName;
int Handle;
int TimeOut;
char VarName[NAME_SIZE];
char NewVal[NAME_SIZE];
char DevType[NAME_SIZE];
char DevId[NAME_SIZE];
char ServiceType[NAME_SIZE];
char ServiceVer[NAME_SIZE];
char Url[NAME_SIZE];
Upnp_SID SubsId;
char *Cookie;
Upnp_FunPtr Fun;
IXML_Document *Header;
IXML_Document *Act;
struct DevDesc *Devdesc;
};
extern virtualDirList *pVirtualDirList;
extern struct VirtualDirCallbacks virtualDirCallback;
typedef enum
{
WEB_SERVER_DISABLED,
WEB_SERVER_ENABLED
} WebServerState;
#define E_HTTP_SYNTAX -6
int UpnpGetIfInfo(
const char *IfName);
void UpnpThreadDistribution(struct UpnpNonblockParam *Param);
void AutoAdvertise(
void *input);
int PrintHandleInfo(
UpnpClient_Handle Hnd);
extern WebServerState bWebServerState;
extern WebCallback_HostValidate gWebCallback_HostValidate;
extern void *gWebCallback_HostValidateCookie;
extern int gAllowLiteralHostRedirection;
#endif /* UPNPAPI_H */
Upnp_FunPtr
int(* Upnp_FunPtr)(Upnp_EventType EventType, const void *Event, void *Cookie)
Definition Callback.h:145
GenlibClientSubscription.h
Header file for GenlibClientSubscription methods.
TimerThread.h
gWebCallback_HostValidate
WebCallback_HostValidate gWebCallback_HostValidate
Definition upnpapi.c:143
gIF_IPV6_ULA_GUA_PREFIX_LENGTH
unsigned gIF_IPV6_ULA_GUA_PREFIX_LENGTH
Definition upnpapi.c:172
Upnp_SID
char Upnp_SID[44]
Holds the subscription identifier for a subscription between a client and a device.
Definition upnp.h:448
virtualDirCallback
struct VirtualDirCallbacks virtualDirCallback
Definition upnpapi.c:108
UpnpThreadDistribution
void UpnpThreadDistribution(struct UpnpNonblockParam *Param)
Schedule async functions in threadpool.
Definition upnpapi.c:4016
gSendThreadPool
ThreadPool gSendThreadPool
Definition upnpapi.c:131
gIF_IPV6_ULA_GUA
char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN]
Definition upnpapi.c:169
gRecvThreadPool
ThreadPool gRecvThreadPool
Definition upnpapi.c:134
LOCAL_PORT_V6_ULA_GUA
unsigned short LOCAL_PORT_V6_ULA_GUA
Definition upnpapi.c:184
gAllowLiteralHostRedirection
int gAllowLiteralHostRedirection
Definition upnpapi.c:149
PrintHandleInfo
int PrintHandleInfo(UpnpClient_Handle Hnd)
Print handle info.
Definition upnpapi.c:4276
GetDeviceHandleInfoForPath
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.c:4195
gIF_IPV6_PREFIX_LENGTH
unsigned gIF_IPV6_PREFIX_LENGTH
Definition upnpapi.c:165
gWebCallback_HostValidateCookie
void * gWebCallback_HostValidateCookie
Definition upnpapi.c:146
g_maxContentLength
size_t g_maxContentLength
Definition upnpapi.c:198
UpnpClient_Handle
int UpnpClient_Handle
Returned when a control point application registers with UpnpRegisterClient.
Definition upnp.h:429
pVirtualDirList
virtualDirList * pVirtualDirList
Definition upnpapi.c:111
g_UpnpSdkEQMaxLen
int g_UpnpSdkEQMaxLen
Definition upnpapi.c:204
UpnpGetIfInfo
int UpnpGetIfInfo(const char *IfName)
Retrieve interface information and keep it in global variables. If NULL, we'll find the first suitabl...
Definition upnpapi.c:3654
LOCAL_PORT_V6
unsigned short LOCAL_PORT_V6
Definition upnpapi.c:181
LOCAL_PORT_V4
unsigned short LOCAL_PORT_V4
Definition upnpapi.c:178
GlobalHndRWLock
ithread_rwlock_t GlobalHndRWLock
Definition upnpapi.c:119
UpnpDevice_Handle
int UpnpDevice_Handle
Returned when a device application registers with UpnpRegisterRootDevice, UpnpRegisterRootDevice2,...
Definition upnp.h:439
GetDeviceHandleInfo
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.c:4158
AutoAdvertise
void AutoAdvertise(void *input)
This function is a timer thread scheduled by UpnpSendAdvertisement to the send advetisement again.
Definition upnpapi.c:4315
gIF_IPV4
char gIF_IPV4[INET_ADDRSTRLEN]
Definition upnpapi.c:155
gTimerThread
TimerThread gTimerThread
Definition upnpapi.c:128
gIF_NAME
char gIF_NAME[LINE_SIZE]
Definition upnpapi.c:152
gIF_INDEX
unsigned gIF_INDEX
Definition upnpapi.c:175
gMiniServerThreadPool
ThreadPool gMiniServerThreadPool
Definition upnpapi.c:137
gIF_IPV4_NETMASK
char gIF_IPV4_NETMASK[INET_ADDRSTRLEN]
Definition upnpapi.c:158
g_UpnpSdkEQMaxAge
int g_UpnpSdkEQMaxAge
Definition upnpapi.c:214
gIF_IPV6
char gIF_IPV6[INET6_ADDRSTRLEN]
Definition upnpapi.c:162
GetHandleInfo
Upnp_Handle_Type GetHandleInfo(int Hnd, struct Handle_Info **HndInfo)
Definition upnpapi.c:4235
GetClientHandleInfo
Upnp_Handle_Type GetClientHandleInfo(int *client_handle_out, struct Handle_Info **HndInfo)
Get client handle info.
Definition upnpapi.c:4138
bWebServerState
WebServerState bWebServerState
Definition upnpapi.c:140
service_table.h
Handle_Info
Definition upnpapi.h:74
Handle_Info::HType
Upnp_Handle_Type HType
Definition upnpapi.h:76
Handle_Info::ServiceList
IXML_NodeList * ServiceList
Definition upnpapi.h:106
Handle_Info::aliasInstalled
int aliasInstalled
Definition upnpapi.h:82
Handle_Info::DescXML
char DescXML[LINE_SIZE]
Definition upnpapi.h:92
Handle_Info::ClientSubList
GenlibClientSubscription * ClientSubList
Definition upnpapi.h:120
Handle_Info::ServiceTable
service_table ServiceTable
Definition upnpapi.h:108
Handle_Info::LowerDescURL
char LowerDescURL[LINE_SIZE]
Definition upnpapi.h:90
Handle_Info::DescURL
char DescURL[LINE_SIZE]
Definition upnpapi.h:87
Handle_Info::DescDocument
IXML_Document * DescDocument
Definition upnpapi.h:102
Handle_Info::Cookie
char * Cookie
Definition upnpapi.h:80
Handle_Info::Callback
Upnp_FunPtr Callback
Definition upnpapi.h:78
Handle_Info::MaxSubscriptionTimeOut
int MaxSubscriptionTimeOut
Definition upnpapi.h:112
Handle_Info::MaxSubscriptions
int MaxSubscriptions
Definition upnpapi.h:110
Handle_Info::SsdpSearchList
LinkedList SsdpSearchList
Definition upnpapi.h:122
Handle_Info::DeviceList
IXML_NodeList * DeviceList
Definition upnpapi.h:104
Handle_Info::DeviceAf
int DeviceAf
Definition upnpapi.h:114
LINKEDLIST
Definition LinkedList.h:84
SERVICE_INFO
Definition service_table.h:71
SERVICE_TABLE
Definition service_table.h:89
THREADPOOL
A thread pool similar to the thread pool in the UPnP SDK.
Definition ThreadPool.h:218
TIMERTHREAD
Definition TimerThread.h:69
UpnpNonblockParam
Definition upnpapi.h:256
VirtualDirCallbacks
Definition VirtualDir.h:11
_IXML_Document
Data structure representing the DOM Document.
Definition ixml.h:160
_IXML_NodeList
Data structure representing a list of nodes.
Definition ixml.h:203
s_GenlibClientSubscription
Definition GenlibClientSubscription.c:19
virtual_Dir_List
Definition VirtualDir.h:61
debug_handle
static enum Upnp_LogLevel_e debug_handle
Get handle information.
Definition upnpapi.h:133
gUpnpSdkNLSuuid
Upnp_SID gUpnpSdkNLSuuid
UpnpPrintf
void UpnpPrintf(Upnp_LogLevel DLevel, Dbg_Module Module, const char *DbgFileName, int DbgLineNo, const char *FmtStr,...)
Prints the debug statement either on the standard output or log file along with the information from ...
Definition upnpdebug.c:259