libUPnP  1.6.17
upnpapi.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2000-2003 Intel Corporation 
00004  * All rights reserved. 
00005  * Copyright (C) 2011-2012 France Telecom All rights reserved. 
00006  *
00007  * Redistribution and use in source and binary forms, with or without 
00008  * modification, are permitted provided that the following conditions are met: 
00009  *
00010  * * Redistributions of source code must retain the above copyright notice, 
00011  * this list of conditions and the following disclaimer. 
00012  * * Redistributions in binary form must reproduce the above copyright notice, 
00013  * this list of conditions and the following disclaimer in the documentation 
00014  * and/or other materials provided with the distribution. 
00015  * * Neither name of Intel Corporation nor the names of its contributors 
00016  * may be used to endorse or promote products derived from this software 
00017  * without specific prior written permission.
00018  * 
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
00022  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 
00023  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00024  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00025  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
00026  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
00027  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00028  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
00029  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  *
00031  ******************************************************************************/
00032 
00033 
00034 #ifndef UPNPAPI_H
00035 #define UPNPAPI_H
00036 
00037 
00043 #include "client_table.h"
00044 #include "upnp.h"
00045 #include "VirtualDir.h"         /* for struct VirtualDirCallbacks */
00046 
00047 
00048 #define MAX_INTERFACES 256
00049 
00050 #define DEFAULT_INTERFACE 1
00051 
00052 #define DEV_LIMIT 200
00053 
00054 #define DEFAULT_MX 5
00055 
00056 #define DEFAULT_MAXAGE 1800
00057 
00058 #define DEFAULT_SOAP_CONTENT_LENGTH 16000
00059 #define MAX_SOAP_CONTENT_LENGTH (size_t)32000
00060 
00061 extern size_t g_maxContentLength;
00062 
00063 /* 30-second timeout */
00064 #define UPNP_TIMEOUT    30
00065 
00066 typedef enum {HND_INVALID=-1,HND_CLIENT,HND_DEVICE} Upnp_Handle_Type;
00067 
00068 /* Data to be stored in handle table for */
00069 struct Handle_Info
00070 {
00072         Upnp_Handle_Type HType;
00074         Upnp_FunPtr  Callback;
00076         char *Cookie;
00078         int   aliasInstalled;
00079 
00080         /* Device Only */
00081 #ifdef INCLUDE_DEVICE_APIS
00082 
00083         char  DescURL[LINE_SIZE];
00086         char  LowerDescURL[LINE_SIZE];
00088         char  DescXML[LINE_SIZE];
00089         /* Advertisement timeout */
00090         int MaxAge;
00091         /* Power State as defined by UPnP Low Power. */
00092         int PowerState;
00093         /* Sleep Period as defined by UPnP Low Power. */
00094         int SleepPeriod;
00095         /* Registration State as defined by UPnP Low Power. */
00096         int RegistrationState;
00098         IXML_Document *DescDocument;
00100         IXML_NodeList *DeviceList;
00102         IXML_NodeList *ServiceList;
00104         service_table ServiceTable;
00106         int MaxSubscriptions;
00108         int MaxSubscriptionTimeOut;
00110         int DeviceAf;
00111 #endif
00112 
00113         /* Client only */
00114 #ifdef INCLUDE_CLIENT_APIS
00115 
00116         ClientSubscription *ClientSubList;
00118         LinkedList SsdpSearchList;
00119 #endif
00120 };
00121 
00122 extern ithread_rwlock_t GlobalHndRWLock;
00123 
00129 Upnp_Handle_Type GetHandleInfo(
00131         int Hnd,
00133         struct Handle_Info **HndInfo); 
00134 
00135 
00136 #define HandleLock() HandleWriteLock()
00137 
00138 
00139 #define HandleWriteLock()  \
00140         UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying a write lock\n"); \
00141         ithread_rwlock_wrlock(&GlobalHndRWLock); \
00142         UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Write lock acquired\n");
00143 
00144 
00145 #define HandleReadLock()  \
00146         UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying a read lock\n"); \
00147         ithread_rwlock_rdlock(&GlobalHndRWLock); \
00148         UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Read lock acquired\n");
00149 
00150 
00151 #define HandleUnlock() \
00152         UpnpPrintf(UPNP_INFO, API,__FILE__, __LINE__, "Trying Unlock\n"); \
00153         ithread_rwlock_unlock(&GlobalHndRWLock); \
00154         UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Unlocked rwlock\n");
00155 
00156 
00164 Upnp_Handle_Type GetClientHandleInfo(
00166         int *client_handle_out, 
00168         struct Handle_Info **HndInfo);
00175 Upnp_Handle_Type GetDeviceHandleInfo(
00177         int AddressFamily,
00179         int *device_handle_out, 
00181         struct Handle_Info **HndInfo);
00182 
00183 
00184 extern char gIF_NAME[LINE_SIZE];
00185 extern char gIF_IPV4[INET_ADDRSTRLEN];
00186 extern char gIF_IPV6[INET6_ADDRSTRLEN];
00187 
00188 extern char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN];
00189 
00190 extern unsigned gIF_INDEX;
00191 
00192 
00193 extern unsigned short LOCAL_PORT_V4;
00194 extern unsigned short LOCAL_PORT_V6;
00195 
00196 
00198 extern Upnp_SID gUpnpSdkNLSuuid;
00199 
00200 
00201 extern TimerThread gTimerThread;
00202 extern ThreadPool gRecvThreadPool;
00203 extern ThreadPool gSendThreadPool;
00204 extern ThreadPool gMiniServerThreadPool;
00205 
00206 
00207 typedef enum {
00208         SUBSCRIBE,
00209         UNSUBSCRIBE,
00210         DK_NOTIFY,
00211         QUERY,
00212         ACTION,
00213         STATUS,
00214         DEVDESCRIPTION,
00215         SERVDESCRIPTION,
00216         MINI,
00217         RENEW
00218 } UpnpFunName;
00219 
00220 
00221 struct  UpnpNonblockParam 
00222 {
00223         UpnpFunName FunName;
00224         int Handle;
00225         int TimeOut;
00226         char VarName[NAME_SIZE];
00227         char NewVal[NAME_SIZE];
00228         char DevType[NAME_SIZE];
00229         char DevId[NAME_SIZE];
00230         char ServiceType[NAME_SIZE];
00231         char ServiceVer[NAME_SIZE];
00232         UpnpString *Url;
00233         Upnp_SID SubsId;
00234         char *Cookie;
00235         Upnp_FunPtr Fun;
00236         IXML_Document *Header;
00237         IXML_Document *Act;
00238         struct DevDesc *Devdesc;
00239 };
00240 
00241 
00242 extern virtualDirList *pVirtualDirList;
00243 extern struct VirtualDirCallbacks virtualDirCallback;
00244 
00245 
00246 typedef enum {
00247         WEB_SERVER_DISABLED,
00248         WEB_SERVER_ENABLED
00249 } WebServerState;
00250 
00251 
00252 #define E_HTTP_SYNTAX -6
00253 
00254 
00274 int UpnpGetIfInfo(
00276         const char *IfName);
00277 
00278 
00279 void UpnpThreadDistribution(struct UpnpNonblockParam * Param);
00280 
00281 
00286 void AutoAdvertise(
00288         void *input); 
00289 
00290 
00299 int getlocalhostname(
00301         char *out,
00303         size_t out_len);
00304 
00305 
00311 int PrintHandleInfo(
00313         UpnpClient_Handle Hnd);
00314 
00315 
00316 extern WebServerState bWebServerState;
00317 
00318 
00319 #endif /* UPNPAPI_H */
00320