upnpapi.c File Reference
`#include "config.h"`
`#include <sys/stat.h>`
`#include <assert.h>`
`#include <signal.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <sys/param.h>`
`#include <arpa/inet.h>`
`#include <net/if.h>`
`#include <netinet/in.h>`
`#include <sys/ioctl.h>`
`#include <sys/socket.h>`
`#include <sys/types.h>`
`#include <sys/utsname.h>`
`#include <unistd.h>`
`#include "upnpapi.h"`
`#include "httpreadwrite.h"`
`#include "membuffer.h"`
`#include "ssdplib.h"`
`#include "soaplib.h"`
`#include "ThreadPool.h"`
`#include "sysdep.h"`
`#include "uuid.h"`
`#include "gena.h"`
`#include "miniserver.h"`
`#include "service_table.h"`
Include dependency graph for upnpapi.c:

## Functions

static int | WinsockInit (void)
| (Windows Only) Initializes the Windows Winsock library. More...
static int | UpnpInitMutexes (void)
| Initializes the global mutexes used by the UPnP SDK. More...
static int | UpnpInitThreadPools (void)
| Initializes the global threadm pools used by the UPnP SDK. More...
static int | UpnpInitPreamble (void)
| Performs the initial steps in initializing the UPnP SDK. More...
static int | UpnpInitStartServers (unsigned short DestPort)
| Finishes initializing the UPnP SDK. More...
int | UpnpInit (const char *HostIP, unsigned short DestPort)
| Initializes the Linux SDK for UPnP Devices (IPv4 only). More...
int | UpnpInit2 (const char *IfName, unsigned short DestPort)
| Initializes the Linux SDK for UPnP Devices (IPv4 or IPv6). More...
int | UpnpFinish (void)
| Terminates the Linux SDK for UPnP Devices. More...
unsigned short | UpnpGetServerPort (void)
| Returns the internal server IPv4 UPnP listening port. More...
unsigned short | UpnpGetServerPort6 (void)
| Returns the internal server IPv6 UPnP listening port. More...
const char * | UpnpGetServerIpAddress (void)
| Returns the local IPv4 listening ip address. More...
const char * | UpnpGetServerIp6Address (void)
| Returns the local IPv6 listening ip address. More...
int | UpnpRegisterRootDevice (const char *DescUrl, Upnp_FunPtr Fun, const void *Cookie, UpnpDevice_Handle *Hnd)
| Registers a device application with the UPnP Library. More...
static int | GetDescDocumentAndURL (Upnp_DescType descriptionType, char *description, unsigned int bufferLen, int config_baseURL, int AddressFamily, IXML_Document **xmlDoc, char *descURL)
| Fills the sockadr_in with miniserver information. More...
int | UpnpRegisterRootDevice2 (Upnp_DescType descriptionType, const char *description_const, 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. More...
int | UpnpRegisterRootDevice3 (const char *DescUrl, Upnp_FunPtr Fun, const void *Cookie, UpnpDevice_Handle *Hnd, const int AddressFamily)
| Registers a device application for a specific address family with the UPnP library. More...
int | UpnpUnRegisterRootDevice (UpnpDevice_Handle Hnd)
| Unregisters a root device registered with UpnpRegisterRootDevice or UpnpRegisterRootDevice2. More...
int | UpnpRegisterClient (Upnp_FunPtr Fun, const void *Cookie, UpnpClient_Handle *Hnd)
| Registers a control point application with the UPnP Library. More...
int | UpnpUnRegisterClient (UpnpClient_Handle Hnd)
| Unregisters a control point application, unsubscribing all active subscriptions. More...
int | UpnpSendAdvertisement (UpnpDevice_Handle Hnd, int Exp)
| Sends out the discovery announcements for all devices and services for a device. More...
int | UpnpSearchAsync (UpnpClient_Handle Hnd, int Mx, const char *Target_const, const void *Cookie_const)
| Searches for devices matching the given search target. More...
int | UpnpSetMaxSubscriptions (UpnpDevice_Handle Hnd, int MaxSubscriptions)
| Sets the maximum number of subscriptions accepted per service. More...
int | UpnpSetMaxSubscriptionTimeOut (UpnpDevice_Handle Hnd, int MaxSubscriptionTimeOut)
| Sets the maximum time-out accepted for a subscription request or renewal. More...
int | UpnpSubscribeAsync (UpnpClient_Handle Hnd, const char *EvtUrl_const, int TimeOut, Upnp_FunPtr Fun, const void *Cookie_const)
| Performs the same operation as UpnpSubscribe, but returns immediately and calls the registered callback function when the operation is complete. More...
int | UpnpSubscribe (UpnpClient_Handle Hnd, const char *EvtUrl_const, int *TimeOut, Upnp_SID SubsId)
| Registers a control point to receive event notifications from another device. More...
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. More...
int | UpnpUnSubscribeAsync (UpnpClient_Handle Hnd, Upnp_SID SubsId, Upnp_FunPtr Fun, const void *Cookie_const)
| 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. More...
int | UpnpRenewSubscription (UpnpClient_Handle Hnd, int *TimeOut, const Upnp_SID SubsId)
| Renews a subscription that is about to expire. More...
int | UpnpRenewSubscriptionAsync (UpnpClient_Handle Hnd, int TimeOut, Upnp_SID SubsId, Upnp_FunPtr Fun, const void *Cookie_const)
| Renews a subscription that is about to expire, generating a callback when the operation is complete. More...
int | UpnpNotify (UpnpDevice_Handle Hnd, const char *DevID_const, const char *ServName_const, const char **VarName_const, const char **NewVal_const, int cVariables)
| Sends out an event change notification to all control points subscribed to a particular service. More...
int | UpnpNotifyExt (UpnpDevice_Handle Hnd, const char *DevID_const, const char *ServName_const, IXML_Document *PropSet)
| Similar to UpnpNotify except that it takes a DOM document for the event rather than an array of strings. More...
int | UpnpAcceptSubscription (UpnpDevice_Handle Hnd, const char *DevID_const, const char *ServName_const, const char **VarName_const, const char **NewVal_const, int cVariables, const Upnp_SID SubsId)
| Accepts a subscription request and sends out the current state of the eventable variables for a service. More...
int | UpnpAcceptSubscriptionExt (UpnpDevice_Handle Hnd, const char *DevID_const, const char *ServName_const, IXML_Document *PropSet, const Upnp_SID SubsId)
| Similar to UpnpAcceptSubscription() except that it takes a DOM document for the variables to event rather than an array of strings. More...
int | UpnpSendAction (UpnpClient_Handle Hnd, const char *ActionURL_const, const char *ServiceType_const, const char *DevUDN_const, IXML_Document *Action, IXML_Document **RespNodePtr)
| Sends a message to change a state variable in a service. More...
int | UpnpSendActionEx (UpnpClient_Handle Hnd, const char *ActionURL_const, const char *ServiceType_const, const char *DevUDN_const, IXML_Document *Header, IXML_Document *Action, IXML_Document **RespNodePtr)
| Sends a message to change a state variable in a service. More...
int | UpnpSendActionAsync (UpnpClient_Handle Hnd, const char *ActionURL_const, const char *ServiceType_const, const char *DevUDN_const, IXML_Document *Act, Upnp_FunPtr Fun, const void *Cookie_const)
| Sends a message to change a state variable in a service, generating a callback when the operation is complete. More...
int | UpnpSendActionExAsync (UpnpClient_Handle Hnd, const char *ActionURL_const, const char *ServiceType_const, const char *DevUDN_const, IXML_Document *Header, IXML_Document *Act, Upnp_FunPtr Fun, const void *Cookie_const)
| Sends a message to change a state variable in a service, generating a callback when the operation is complete. More...
int | UpnpGetServiceVarStatusAsync (UpnpClient_Handle Hnd, const char *ActionURL_const, const char *VarName_const, Upnp_FunPtr Fun, const void *Cookie_const)
| Queries the state of a variable of a service, generating a callback when the operation is complete. More...
int | UpnpGetServiceVarStatus (UpnpClient_Handle Hnd, const char *ActionURL_const, const char *VarName_const, DOMString *StVar)
| Queries the state of a state variable of a service on another device. More...
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. More...
int | UpnpWriteHttpPost (void *handle, char *buf, unsigned int *size, int timeout)
| Sends a request to a server to copy the contents of a buffer to the URI specified in the UpnpOpenHttpPost call. More...
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. More...
int | UpnpOpenHttpGet (const char *url_str, void **Handle, char **contentType, int *contentLength, int *httpStatus, int timeout)
| Gets a file specified in a URL. More...
int | UpnpOpenHttpGetProxy (const char *url_str, 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. More...
int | UpnpOpenHttpGetEx (const char *url_str, 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. More...
int | UpnpCancelHttpGet (void *Handle)
| Set the cancel flag of the handle parameter. More...
int | UpnpCloseHttpGet (void *Handle)
| Closes the connection and frees memory that was allocated for the handle parameter. More...
int | UpnpReadHttpGet (void *Handle, char *buf, unsigned int *size, int timeout)
| Gets specified number of bytes from a file specified in a URL. More...
int | UpnpHttpGetProgress (void *Handle, unsigned int *length, unsigned int *total)
| Retrieve progress information of a http-get transfer. More...
int | UpnpDownloadUrlItem (const char *url, char **outBuf, char *contentType)
| Downloads a file specified in a URL. More...
int | UpnpDownloadXmlDoc (const char *url, IXML_Document **xmlDoc)
| Downloads an XML document specified in a URL. More...
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. More...
void | UpnpThreadDistribution (struct UpnpNonblockParam *Param)
| Schedule async functions in threadpool. More...
Upnp_FunPtr | GetCallBackFn (UpnpClient_Handle Hnd)
| Get callback function ptr from a handle. More...
int | GetFreeHandle ()
| Get a free handle. More...
Upnp_Handle_Type | GetClientHandleInfo (UpnpClient_Handle *client_handle_out, struct Handle_Info **HndInfo)
| Get client handle info. More...
Upnp_Handle_Type | GetDeviceHandleInfo (const 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. More...
Upnp_Handle_Type | GetHandleInfo (UpnpClient_Handle Hnd, struct Handle_Info **HndInfo)
| Get handle information. More...
int | FreeHandle (int Upnp_Handle)
| Free handle. More...
int | PrintHandleInfo (UpnpClient_Handle Hnd)
| Print handle info. More...
int | getlocalhostname (char *out, const int out_len)
| Get local IP address. More...
void | AutoAdvertise (void *input)
| This function is a timer thread scheduled by UpnpSendAdvertisement to the send advetisement again. More...
int | UpnpAddVirtualDir (const char *newDirName)
| Adds a virtual directory mapping. More...
int | UpnpRemoveVirtualDir (const char *dirName)
| Removes a virtual directory mapping made with UpnpAddVirtualDir. More...
void | UpnpRemoveAllVirtualDirs (void)
| Removes all virtual directory mappings. More...
int | UpnpEnableWebserver (int enable)
| Enables or disables the webserver. More...
int | UpnpIsWebserverEnabled (void)
| Checks if the webserver is enabled or disabled. More...
int | UpnpVirtualDir_set_GetInfoCallback (VDCallback_GetInfo callback)
| Sets the get_info callback function to be used to access a virtual directory. More...
int | UpnpVirtualDir_set_OpenCallback (VDCallback_Open callback)
| Sets the open callback function to be used to access a virtual directory. More...
int | UpnpVirtualDir_set_ReadCallback (VDCallback_Read callback)
| Sets the read callback function to be used to access a virtual directory. More...
int | UpnpVirtualDir_set_WriteCallback (VDCallback_Write callback)
| Sets the write callback function to be used to access a virtual directory. More...
int | UpnpVirtualDir_set_SeekCallback (VDCallback_Seek callback)
| Sets the seek callback function to be used to access a virtual directory. More...
int | UpnpVirtualDir_set_CloseCallback (VDCallback_Close callback)
| Sets the close callback function to be used to access a virtual directory. More...
int | UpnpSetContentLength (UpnpClient_Handle Hnd, int contentLength)
int | UpnpSetMaxContentLength (size_t contentLength)
| Sets the maximum content-length that the SDK will process on an incoming SOAP requests or responses. More...

## Variables

struct VirtualDirCallbacks | virtualDirCallback
virtualDirList * | pVirtualDirList
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 [22] = { '\0' }
char | gIF_IPV6 [65] = { '\0' }
int | gIF_INDEX = -1
unsigned short | LOCAL_PORT_V4
unsigned short | LOCAL_PORT_V6
void * | HandleTable [NUM_HANDLE]
membuffer | gDocumentRootDir
size_t | g_maxContentLength = DEFAULT_SOAP_CONTENT_LENGTH
int | UpnpSdkInit = 0
int | UpnpSdkClientRegistered = 0
int | UpnpSdkDeviceRegisteredV4 = 0
int | UpnpSdkDeviceregisteredV6 = 0
Upnp_SID | gUpnpSdkNLSuuid

## Function Documentation

void AutoAdvertise | ( | void * | input | ) |

This function is a timer thread scheduled by UpnpSendAdvertisement to the send advetisement again.

Parameters

  [in] | input | Information provided to the thread.

References free_upnp_timeout(), and UpnpSendAdvertisement().

Referenced by UpnpSendAdvertisement().

int FreeHandle | ( | int | Handle | ) |

Free handle.

Returns
  UPNP_E_SUCCESS if successful or UPNP_E_INVALID_HANDLE if not

Parameters

  [in] | Upnp_Handle | Handle index.

References HandleTable, UPNP_E_INVALID_HANDLE, UPNP_E_SUCCESS, and UpnpPrintf().

Referenced by UpnpRegisterRootDevice(), UpnpRegisterRootDevice2(), UpnpRegisterRootDevice3(), UpnpUnRegisterClient(), and UpnpUnRegisterRootDevice().

Upnp_FunPtr GetCallBackFn | ( | UpnpClient_Handle | Hnd | ) |

Get callback function ptr from a handle.

Returns
  Upnp_FunPtr

References HandleTable.

Upnp_Handle_Type GetClientHandleInfo | ( | int * | client_handle_out,
|  | struct Handle_Info ** | HndInfo
| ) |  |

Get client handle info.

Note
  The logic around the use of this function should be revised.

Returns
  HND_CLIENT, HND_INVALID

Parameters

  [in] | client_handle_out | client handle pointer (key for the client handle structure).
  [out] | HndInfo | Client handle structure passed by this function.

References GetHandleInfo().

Referenced by gena_process_notification_event(), and UpnpFinish().

static int GetDescDocumentAndURL | ( | Upnp_DescType | descriptionType,
|  | char * | description,
|  | unsigned int | bufferLen,
|  | int | config_baseURL,
|  | int | AddressFamily,
|  | IXML_Document ** | xmlDoc,
|  | char * | descURL
| ) |  |

static

Fills the sockadr_in with miniserver information.

References UPNP_E_INVALID_PARAM, UPNP_E_SUCCESS, UPNP_E_URL_TOO_BIG, UpnpDownloadXmlDoc(), and UPNPREG_URL_DESC.

Referenced by UpnpRegisterRootDevice2().

Upnp_Handle_Type GetDeviceHandleInfo | ( | const int | AddressFamily,
|  | int * | device_handle_out,
|  | struct Handle_Info ** | HndInfo
| ) |  |

Retrieves the device handle and information of the first device of the address family spcified.

Returns
  HND_DEVICE or HND_INVALID

Parameters

  [in] | AddressFamily | Address family.
  [out] | device_handle_out | Device handle pointer.
  [out] | HndInfo | Device handle structure passed by this function.

References GetHandleInfo(), UpnpSdkDeviceRegisteredV4, and UpnpSdkDeviceregisteredV6.

Referenced by gena_process_subscription_renewal_request(), gena_process_subscription_request(), gena_process_unsubscribe_request(), and UpnpFinish().

int GetFreeHandle | ( |  | ) |

Get a free handle.

Returns
  On success, an integer greater than zero or UPNP_E_OUTOF_HANDLE on failure.

References HandleTable, and UPNP_E_OUTOF_HANDLE.

Referenced by UpnpRegisterClient(), UpnpRegisterRootDevice(), UpnpRegisterRootDevice2(), and UpnpRegisterRootDevice3().

Upnp_Handle_Type GetHandleInfo | ( | int | Hnd,
|  | struct Handle_Info ** | HndInfo
| ) |  |

Get handle information.

Returns
  HND_DEVICE, UPNP_E_INVALID_HANDLE

Parameters

  Hnd | handle pointer (key for the client handle structure).
  HndInfo | handle structure passed by this function.

References HandleTable, UPNP_E_INVALID_HANDLE, and UpnpPrintf().

Referenced by GenaAutoRenewSubscription(), genaInitNotify(), genaInitNotifyExt(), genaNotifyAll(), genaNotifyAllExt(), genaNotifyThread(), genaRenewSubscription(), genaSubscribe(), genaUnregisterClient(), genaUnregisterDevice(), genaUnSubscribe(), GetClientHandleInfo(), GetDeviceHandleInfo(), UpnpAcceptSubscription(), UpnpAcceptSubscriptionExt(), UpnpGetServiceVarStatus(), UpnpGetServiceVarStatusAsync(), UpnpNotify(), UpnpNotifyExt(), UpnpRenewSubscription(), UpnpRenewSubscriptionAsync(), UpnpSearchAsync(), UpnpSendAction(), UpnpSendActionAsync(), UpnpSendActionEx(), UpnpSendActionExAsync(), UpnpSendAdvertisement(), UpnpSetContentLength(), UpnpSetMaxSubscriptions(), UpnpSetMaxSubscriptionTimeOut(), UpnpSubscribe(), UpnpSubscribeAsync(), UpnpUnRegisterClient(), UpnpUnRegisterRootDevice(), UpnpUnSubscribe(), and UpnpUnSubscribeAsync().

int getlocalhostname | ( | char * | out,
|  | const int | out_len
| ) |  |

Get local IP address.

Gets the ip address for the DEFAULT_INTERFACE interface which is up and not a loopback. Assumes at most MAX_INTERFACES interfaces

Returns
  UPNP_E_SUCCESS if successful or UPNP_E_INIT.

Parameters

  [out] | out | IP address of the interface.
  [in] | out_len | Length of the output buffer.

References UPNP_E_INIT, UPNP_E_SUCCESS, and UpnpPrintf().

Referenced by UpnpInit().

int PrintHandleInfo | ( | UpnpClient_Handle | Hnd | ) |

Print handle info.

Returns
  UPNP_E_SUCCESS if successful, otherwise returns appropriate error.

Parameters

  [in] | Hnd | Handle index.

References Handle_Info::DescURL, HandleTable, Handle_Info::HType, UPNP_E_INVALID_HANDLE, UPNP_E_SUCCESS, and UpnpPrintf().

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.

The interface must fulfill these requirements:

- Be UP.
- Not be LOOPBACK.
- Support MULTICAST.
- Have a valid IPv4 or IPv6 address.

We'll retrieve the following information from the interface:

- gIF_NAME -> Interface name (by input or found).
- gIF_IPV4 -> IPv4 address (if any).
- gIF_IPV6 -> IPv6 address (if any).
- gIF_INDEX -> Interface index number.

Returns
  UPNP_E_SUCCESS on success.

Parameters

  [in] | IfName | Interface name (can be NULL).

References gIF_INDEX, gIF_IPV4, gIF_IPV6, gIF_NAME, UPNP_E_INIT, UPNP_E_INVALID_INTERFACE, UPNP_E_OUTOF_MEMORY, UPNP_E_SUCCESS, and UpnpPrintf().

Referenced by UpnpInit2().

static int UpnpInitMutexes | ( | void |  | ) |

static

Initializes the global mutexes used by the UPnP SDK.

Returns
  UPNP_E_SUCCESS on success or UPNP_E_INIT_FAILED if a mutex could not be initialized.

References GlobalClientSubscribeMutex, GlobalHndRWLock, gUUIDMutex, UPNP_E_INIT_FAILED, and UPNP_E_SUCCESS.

Referenced by UpnpInitPreamble().

static int UpnpInitPreamble | ( | void |  | ) |

static

Performs the initial steps in initializing the UPnP SDK.

- Winsock library is initialized for the process (Windows specific).
- The logging (for debug messages) is initialized.
- Mutexes, Handle table and thread pools are allocated and initialized.
- Callback functions for SOAP and GENA are set, if they're enabled.
- The SDK timer thread is initialized.

Returns
  UPNP_E_SUCCESS on success.

References genaCallback(), gUpnpSdkNLSuuid, HandleTable, SetGenaCallback(), SetSoapCallback(), TimerThreadInit(), UPNP_E_INIT_FAILED, UPNP_E_SUCCESS, UpnpFinish(), UpnpInitLog(), UpnpInitMutexes(), UpnpInitThreadPools(), UpnpPrintf(), and WinsockInit().

Referenced by UpnpInit(), and UpnpInit2().

static int UpnpInitStartServers | ( | unsigned short | DestPort | ) |

static

Finishes initializing the UPnP SDK.

- The MiniServer is started, if enabled.
- The WebServer is started, if enabled.

Returns
  UPNP_E_SUCCESS on success or UPNP_E_INIT_FAILED if a mutex could not be initialized.

Parameters

  [in] | DestPort | Local Port to listen for incoming connections.

References LOCAL_PORT_V4, LOCAL_PORT_V6, StartMiniServer(), UPNP_E_SUCCESS, UpnpEnableWebserver(), UpnpFinish(), and UpnpPrintf().

Referenced by UpnpInit(), and UpnpInit2().

static int UpnpInitThreadPools | ( | void |  | ) |

static

Initializes the global threadm pools used by the UPnP SDK.

Returns
  UPNP_E_SUCCESS on success or UPNP_E_INIT_FAILED if a mutex could not be initialized.

References UPNP_E_INIT_FAILED, UPNP_E_SUCCESS, UpnpFinish(), and UpnpSdkInit.

Referenced by UpnpInitPreamble().

void UpnpThreadDistribution | ( | struct UpnpNonblockParam * | Param | ) |

Schedule async functions in threadpool.

References DOMString, genaRenewSubscription(), genaSubscribe(), genaUnSubscribe(), UPNP_CONTROL_ACTION_COMPLETE, UPNP_CONTROL_GET_VAR_COMPLETE, UPNP_EVENT_RENEWAL_COMPLETE, UPNP_EVENT_SUBSCRIBE_COMPLETE, UPNP_EVENT_UNSUBSCRIBE_COMPLETE, UpnpActionComplete_delete(), UpnpActionComplete_new(), UpnpActionComplete_set_ActionRequest(), UpnpActionComplete_set_ActionResult(), UpnpActionComplete_set_ErrCode(), UpnpActionComplete_strcpy_CtrlUrl(), UpnpEventSubscribe_delete(), UpnpEventSubscribe_get_PublisherUrl(), UpnpEventSubscribe_get_SID(), UpnpEventSubscribe_new(), UpnpPrintf(), UpnpStateVarComplete_delete(), and UpnpStateVarComplete_new().

Referenced by UpnpGetServiceVarStatusAsync(), UpnpRenewSubscriptionAsync(), UpnpSendActionAsync(), UpnpSendActionExAsync(), UpnpSubscribeAsync(), and UpnpUnSubscribeAsync().

static int WinsockInit | ( | void |  | ) |

static

(Windows Only) Initializes the Windows Winsock library.

Returns
  UPNP_E_SUCCESS on success, UPNP_E_INIT_FAILED on failure.

References UPNP_E_INIT_FAILED, and UPNP_E_SUCCESS.

Referenced by UpnpInitPreamble().

## Variable Documentation

WebServerState bWebServerState = WEB_SERVER_DISABLED

Flag to indicate the state of web server

Referenced by UpnpEnableWebserver(), and UpnpIsWebserverEnabled().

size_t g_maxContentLength = DEFAULT_SOAP_CONTENT_LENGTH

Maximum content-length (in bytes) that the SDK will process on an incoming packet. Content-Length exceeding this size will be not processed and error 413 (HTTP Error Code) will be returned to the remote end point.

Referenced by UpnpSetContentLength(), and UpnpSetMaxContentLength().

membuffer gDocumentRootDir

a local dir which serves as webserver root

int gIF_INDEX = -1

Contains interface index. (extern'ed in upnp.h)

Referenced by parse_hostport(), and UpnpGetIfInfo().

char gIF_IPV4[22] = { '\0' }

Static buffer to contain interface IPv4 address. (extern'ed in upnp.h)

Referenced by gena_subscribe(), UpnpGetIfInfo(), UpnpGetServerIpAddress(), and UpnpInit().

char gIF_IPV6[65] = { '\0' }

Static buffer to contain interface IPv6 address. (extern'ed in upnp.h)

Referenced by gena_subscribe(), UpnpGetIfInfo(), and UpnpGetServerIp6Address().

char gIF_NAME[LINE_SIZE] = { '\0' }

Static buffer to contain interface name. (extern'ed in upnp.h)

Referenced by UpnpGetIfInfo().

ithread_mutex_t GlobalClientSubscribeMutex

Mutex to synchronize the subscription handling at the client side.

Referenced by UpnpFinish(), and UpnpInitMutexes().

ithread_rwlock_t GlobalHndRWLock

rwlock to synchronize handles (root device or control point handle).

Referenced by UpnpFinish(), and UpnpInitMutexes().

ThreadPool gMiniServerThreadPool

Mini server thread pool.

Referenced by StartMiniServer().

ThreadPool gRecvThreadPool

Receive thread pool.

ithread_mutex_t gSDKInitMutex = PTHREAD_MUTEX_INITIALIZER

Initialization mutex.

Referenced by UpnpInit(), and UpnpInit2().

ThreadPool gSendThreadPool

Send thread pool.

Referenced by genaInitNotify(), genaInitNotifyExt(), genaNotifyAll(), genaNotifyAllExt(), and genaNotifyThread().

TimerThread gTimerThread

Global timer thread.

Referenced by free_client_subscription(), genaRenewSubscription(), and ScheduleGenaAutoRenew().

Upnp_SID gUpnpSdkNLSuuid

Global variable used in discovery notifications.

Referenced by UpnpInitPreamble().

ithread_mutex_t gUUIDMutex

Mutex to synchronize the uuid creation process.

Referenced by UpnpFinish(), and UpnpInitMutexes().

void* HandleTable[NUM_HANDLE]

UPnP device and control point handle table

Referenced by FreeHandle(), GetCallBackFn(), GetFreeHandle(), GetHandleInfo(), PrintHandleInfo(), UpnpInitPreamble(), UpnpRegisterClient(), UpnpRegisterRootDevice(), UpnpRegisterRootDevice2(), and UpnpRegisterRootDevice3().

unsigned short LOCAL_PORT_V4

local IPv4 port for the mini-server

Referenced by gena_subscribe(), UpnpGetServerPort(), UpnpInit(), and UpnpInitStartServers().

unsigned short LOCAL_PORT_V6

local IPv6 port for the mini-server

Referenced by gena_subscribe(), UpnpGetServerPort6(), and UpnpInitStartServers().

virtualDirList* pVirtualDirList

Pointer to the virtual directory list.

Referenced by UpnpAddVirtualDir(), UpnpRemoveAllVirtualDirs(), and UpnpRemoveVirtualDir().

int UpnpSdkClientRegistered = 0

Global variable to denote the state of Upnp SDK client registration. == 0 if unregistered, == 1 if registered.

Referenced by UpnpRegisterClient(), and UpnpUnRegisterClient().

int UpnpSdkDeviceRegisteredV4 = 0

Global variable to denote the state of Upnp SDK IPv4 device registration. == 0 if unregistered, == 1 if registered.

Referenced by GetDeviceHandleInfo(), UpnpRegisterRootDevice(), UpnpRegisterRootDevice2(), UpnpRegisterRootDevice3(), and UpnpUnRegisterRootDevice().

int UpnpSdkDeviceregisteredV6 = 0

Global variable to denote the state of Upnp SDK IPv6 device registration. == 0 if unregistered, == 1 if registered.

Referenced by GetDeviceHandleInfo(), UpnpRegisterRootDevice3(), and UpnpUnRegisterRootDevice().

int UpnpSdkInit = 0

Global variable to denote the state of Upnp SDK == 0 if uninitialized, == 1 if initialized.

Referenced by UpnpAcceptSubscription(), UpnpAcceptSubscriptionExt(), UpnpAddVirtualDir(), UpnpEnableWebserver(), UpnpFinish(), UpnpGetServerIp6Address(), UpnpGetServerIpAddress(), UpnpGetServerPort(), UpnpGetServerPort6(), UpnpGetServiceVarStatus(), UpnpGetServiceVarStatusAsync(), UpnpInit(), UpnpInit2(), UpnpInitThreadPools(), UpnpIsWebserverEnabled(), UpnpNotify(), UpnpNotifyExt(), UpnpRegisterClient(), UpnpRegisterRootDevice(), UpnpRegisterRootDevice2(), UpnpRegisterRootDevice3(), UpnpRemoveAllVirtualDirs(), UpnpRemoveVirtualDir(), UpnpRenewSubscription(), UpnpRenewSubscriptionAsync(), UpnpSearchAsync(), UpnpSendAction(), UpnpSendActionAsync(), UpnpSendActionEx(), UpnpSendActionExAsync(), UpnpSendAdvertisement(), UpnpSetContentLength(), UpnpSetMaxContentLength(), UpnpSetMaxSubscriptions(), UpnpSetMaxSubscriptionTimeOut(), UpnpSubscribe(), UpnpSubscribeAsync(), UpnpUnRegisterClient(), UpnpUnRegisterRootDevice(), UpnpUnSubscribe(), and UpnpUnSubscribeAsync().

struct VirtualDirCallbacks virtualDirCallback

This structure is for virtual directory callbacks

Referenced by UpnpVirtualDir_set_CloseCallback(), UpnpVirtualDir_set_GetInfoCallback(), UpnpVirtualDir_set_OpenCallback(), UpnpVirtualDir_set_ReadCallback(), UpnpVirtualDir_set_SeekCallback(), and UpnpVirtualDir_set_WriteCallback().