libUPnP  1.6.17
Defines | Functions | Variables
upnpapi.c File Reference
#include "config.h"
#include "upnpapi.h"
#include "httpreadwrite.h"
#include "membuffer.h"
#include "ssdplib.h"
#include "soaplib.h"
#include "sysdep.h"
#include "ThreadPool.h"
#include "UpnpStdInt.h"
#include "UpnpUniStd.h"
#include "uuid.h"
#include "gena.h"
#include "miniserver.h"
#include "service_table.h"
#include <sys/stat.h>
#include <assert.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/types.h>
Include dependency graph for upnpapi.c:

Defines

#define IN6_IS_ADDR_GLOBAL(a)
#define IN6_IS_ADDR_ULA(a)
#define NUM_HANDLE   200
#define FREEMARK   "FrEe"

Functions

static int WinsockInit (void)
 (Windows Only) Initializes the Windows Winsock library.
static int UpnpInitMutexes (void)
 Initializes the global mutexes used by the UPnP SDK.
static int UpnpInitThreadPools (void)
 Initializes the global threadm pools used by the UPnP SDK.
static int UpnpInitPreamble (void)
 Performs the initial steps in initializing the UPnP SDK.
static int UpnpInitStartServers (unsigned short DestPort)
 Finishes initializing the UPnP SDK.
void PrintThreadPoolStats (ThreadPool *tp, const char *DbgFileName, int DbgLineNo, const char *msg)
 Prints thread pool statistics.
char * UpnpGetServerIp6Address (void)
char * UpnpGetServerUlaGuaIp6Address (void)
static int GetFreeHandle ()
 Get a free handle.
static int FreeHandle (int Upnp_Handle)
 Free handle.
static int GetDescDocumentAndURL (Upnp_DescType descriptionType, char *description, int config_baseURL, int AddressFamily, IXML_Document **xmlDoc, char descURL[LINE_SIZE])
 Fills the sockadr_in with miniserver information.
static void Param_delete (struct UpnpNonblockParam *Param)
 De-allocate a UpnpNonblockParam and its fields.
int UpnpGetIfInfo (const char *IfName)
 Retrieve interface information and keep it in global variables. If NULL, we'll find the first suitable interface for operation.
void UpnpThreadDistribution (struct UpnpNonblockParam *Param)
 Schedule async functions in threadpool.
Upnp_FunPtr GetCallBackFn (UpnpClient_Handle Hnd)
 Get callback function ptr from a handle.
Upnp_Handle_Type GetClientHandleInfo (UpnpClient_Handle *client_handle_out, struct Handle_Info **HndInfo)
 Get client handle info.
Upnp_Handle_Type GetDeviceHandleInfo (int AddressFamily, UpnpDevice_Handle *device_handle_out, struct Handle_Info **HndInfo)
 Retrieves the device handle and information of the first device of the address family spcified.
Upnp_Handle_Type GetHandleInfo (UpnpClient_Handle Hnd, struct Handle_Info **HndInfo)
 Get handle information.
int PrintHandleInfo (UpnpClient_Handle Hnd)
 Print handle info.
int getlocalhostname (char *out, size_t out_len)
 Get local IP address.
void AutoAdvertise (void *input)
 This function is a timer thread scheduled by UpnpSendAdvertisement to the send advetisement again.
Initialization and Registration
int UpnpInit (const char *HostIP, unsigned short DestPort)
 Initializes the Linux SDK for UPnP Devices (IPv4 only).
int UpnpFinish (void)
 Initializes the Linux SDK for UPnP Devices (IPv4 or IPv6).
unsigned short UpnpGetServerPort (void)
 Returns the internal server IPv4 UPnP listening port.
char * UpnpGetServerIpAddress (void)
 Returns the internal server IPv6 UPnP listening port.
int UpnpRegisterRootDevice (const char *DescUrl, Upnp_FunPtr Callback, const void *Cookie, UpnpDevice_Handle *Hnd)
 Returns the local IPv6 listening ip address.
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.
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.
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.
int UpnpUnRegisterRootDevice (UpnpDevice_Handle Hnd)
 Unregisters a root device registered with UpnpRegisterRootDevice, UpnpRegisterRootDevice2, UpnpRegisterRootDevice3 or UpnpRegisterRootDevice4.
int UpnpUnRegisterRootDeviceLowPower (UpnpDevice_Handle Hnd, int PowerState, int SleepPeriod, int RegistrationState)
 Unregisters a root device registered with UpnpRegisterRootDevice, UpnpRegisterRootDevice2, UpnpRegisterRootDevice3 or UpnpRegisterRootDevice4.
int UpnpRegisterClient (Upnp_FunPtr Callback, const void *Cookie, UpnpClient_Handle *Hnd)
 Registers a control point application with the UPnP Library.
int UpnpUnRegisterClient (UpnpClient_Handle Hnd)
 Unregisters a control point application, unsubscribing all active subscriptions.
int UpnpSetContentLength (UpnpClient_Handle Hnd, size_t contentLength)
int UpnpSetMaxContentLength (size_t contentLength)
 Sets the maximum content-length that the SDK will process on an incoming SOAP requests or responses.
Discovery
int UpnpSendAdvertisement (UpnpDevice_Handle Hnd, int Exp)
 Sends out the discovery announcements for all devices and services for a device.
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.
int UpnpSearchAsync (UpnpClient_Handle Hnd, int Mx, const char *TTarget_constarget_const, const void *Cookie_const)
 Searches for devices matching the given search target.
Eventing
int UpnpSetMaxSubscriptions (UpnpDevice_Handle Hnd, int MaxSubscriptions)
 Sets the maximum number of subscriptions accepted per service.
int UpnpSetMaxSubscriptionTimeOut (UpnpDevice_Handle Hnd, int MaxSubscriptionTimeOut)
 Sets the maximum time-out accepted for a subscription request or renewal.
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 callback function when the operation is complete.
int UpnpSubscribe (UpnpClient_Handle Hnd, const char *PublisherUrl, int *TimeOut, Upnp_SID SubsId)
 Registers a control point to receive event notifications from another device.
int UpnpUnSubscribe (UpnpClient_Handle Hnd, const Upnp_SID SubsId)
 Removes the subscription of a control point from a service previously subscribed to using UpnpSubscribe or UpnpSubscribeAsync.
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 or UpnpSubscribeAsync, generating a callback when the operation is complete.
int UpnpRenewSubscription (UpnpClient_Handle Hnd, int *TimeOut, const Upnp_SID SubsId)
 Renews a subscription that is about to expire.
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.
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 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 strings.
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 service.
int UpnpAcceptSubscriptionExt (UpnpDevice_Handle Hnd, const char *DevID, const char *ServID, IXML_Document *PropSet, Upnp_SID SubsId)
 Similar to UpnpAcceptSubscription() except that it takes a DOM document for the variables to event rather than an array of strings.
Control
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.
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.
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 complete.
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 complete.
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.
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.
Control Point HTTP API
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 the server if the connection to the server succeeds.
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 UpnpOpenHttpPost call.
int UpnpCloseHttpPost (void *handle, int *httpStatus, int timeout)
 Sends and receives any pending data, closes the connection with the server, and frees memory allocated during the UpnpOpenHttpPost call.
int UpnpOpenHttpGet (const char *url, void **handle, char **contentType, int *contentLength, int *httpStatus, int timeout)
 Gets a file specified in a URL.
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.
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.
int UpnpCancelHttpGet (void *handle)
 Set the cancel flag of the handle parameter.
int UpnpCloseHttpGet (void *handle)
 Closes the connection and frees memory that was allocated for the handle parameter.
int UpnpReadHttpGet (void *handle, char *buf, size_t *size, int timeout)
 Gets specified number of bytes from a file specified in a URL.
int UpnpHttpGetProgress (void *handle, size_t *length, size_t *total)
 Retrieve progress information of a http-get transfer.
int UpnpDownloadUrlItem (const char *url, char **outBuf, char *contentType)
 Downloads a file specified in a URL.
int UpnpDownloadXmlDoc (const char *url, IXML_Document **xmlDoc)
 Downloads an XML document specified in a URL.
Web Server API
int UpnpAddVirtualDir (const char *dirName)
 Adds a virtual directory mapping.
int UpnpRemoveVirtualDir (const char *dirName)
 Removes a virtual directory mapping made with UpnpAddVirtualDir.
void UpnpRemoveAllVirtualDirs (void)
 Removes all virtual directory mappings.
int UpnpEnableWebserver (int enable)
 Enables or disables the webserver.
int UpnpIsWebserverEnabled (void)
 Returns TRUE if the webserver is enabled, or FALSE if it is not.
int UpnpSetVirtualDirCallbacks (struct UpnpVirtualDirCallbacks *callbacks)
 Sets the callback functions to be used to access a virtual directory.
int UpnpVirtualDir_set_GetInfoCallback (VDCallback_GetInfo callback)
 Sets the get_info callback function to be used to access a virtual directory.
int UpnpVirtualDir_set_OpenCallback (VDCallback_Open callback)
 Sets the open callback function to be used to access a virtual directory.
int UpnpVirtualDir_set_ReadCallback (VDCallback_Read callback)
 Sets the read callback function to be used to access a virtual directory.
int UpnpVirtualDir_set_WriteCallback (VDCallback_Write callback)
 Sets the write callback function to be used to access a virtual directory.
int UpnpVirtualDir_set_SeekCallback (VDCallback_Seek callback)
 Sets the seek callback function to be used to access a virtual directory.
int UpnpVirtualDir_set_CloseCallback (VDCallback_Close callback)
 Sets the close callback function to be used to access a virtual directory.

Variables

struct VirtualDirCallbacks virtualDirCallback
virtualDirListpVirtualDirList
ithread_mutex_t GlobalClientSubscribeMutex
ithread_rwlock_t GlobalHndRWLock
ithread_mutex_t gUUIDMutex
ithread_mutex_t gSDKInitMutex = PTHREAD_MUTEX_INITIALIZER
TimerThread gTimerThread
ThreadPool gSendThreadPool
ThreadPool gRecvThreadPool
ThreadPool gMiniServerThreadPool
WebServerState bWebServerState = WEB_SERVER_DISABLED
char gIF_NAME [LINE_SIZE] = { '\0' }
char gIF_IPV4 [INET_ADDRSTRLEN] = { '\0' }
char gIF_IPV6 [INET6_ADDRSTRLEN] = { '\0' }
char gIF_IPV6_ULA_GUA [INET6_ADDRSTRLEN] = { '\0' }
unsigned gIF_INDEX = (unsigned)-1
unsigned short LOCAL_PORT_V4
unsigned short LOCAL_PORT_V6
static void * HandleTable [200]
membuffer gDocumentRootDir
size_t g_maxContentLength = DEFAULT_SOAP_CONTENT_LENGTH
int UpnpSdkInit = 0
int UpnpSdkClientRegistered = 0
int UpnpSdkDeviceRegisteredV4 = 0
int UpnpSdkDeviceregisteredV6 = 0

Detailed Description