upnpapi.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2000-2003 Intel Corporation 
00004  * All rights reserved. 
00005  *
00006  * Redistribution and use in source and binary forms, with or without 
00007  * modification, are permitted provided that the following conditions are met: 
00008  *
00009  * * Redistributions of source code must retain the above copyright notice, 
00010  * this list of conditions and the following disclaimer. 
00011  * * Redistributions in binary form must reproduce the above copyright notice, 
00012  * this list of conditions and the following disclaimer in the documentation 
00013  * and/or other materials provided with the distribution. 
00014  * * Neither name of Intel Corporation nor the names of its contributors 
00015  * may be used to endorse or promote products derived from this software 
00016  * without specific prior written permission.
00017  * 
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00019  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00020  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
00021  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 
00022  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00023  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00024  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
00025  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
00026  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00027  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  ******************************************************************************/
00031 
00032 
00033 #ifndef UPNPAPI_H
00034 #define UPNPAPI_H
00035 
00036 
00042 #include "client_table.h"
00043 #include "upnp.h"
00044 #include "VirtualDir.h"         /* for struct VirtualDirCallbacks */
00045 
00046 
00047 #define MAX_INTERFACES 256
00048 
00049 #define DEFAULT_INTERFACE 1
00050 
00051 #define DEV_LIMIT 200
00052 
00053 #define NUM_HANDLE 200
00054 
00055 #define DEFAULT_MX 5
00056 
00057 #define DEFAULT_MAXAGE 1800
00058 
00059 #define DEFAULT_SOAP_CONTENT_LENGTH 16000
00060 #define MAX_SOAP_CONTENT_LENGTH 32000
00061 
00062 extern size_t g_maxContentLength;
00063 
00064 /* 30-second timeout */
00065 #define UPNP_TIMEOUT    30
00066 
00067 typedef enum {HND_INVALID=-1,HND_CLIENT,HND_DEVICE} Upnp_Handle_Type;
00068 
00069 /* Data to be stored in handle table for */
00070 struct Handle_Info
00071 {
00073         Upnp_Handle_Type HType;
00075         Upnp_FunPtr  Callback;
00077         char *Cookie;
00079         int   aliasInstalled;
00080 
00081         /* Device Only */
00082 #ifdef INCLUDE_DEVICE_APIS
00083 
00084         char  DescURL[LINE_SIZE];
00086         char  DescXML[LINE_SIZE];
00087         /* Advertisement timeout */
00088         int MaxAge;
00090         IXML_Document *DescDocument;
00092         IXML_NodeList *DeviceList;
00094         IXML_NodeList *ServiceList;
00096         service_table ServiceTable;
00098         int MaxSubscriptions;
00100         int MaxSubscriptionTimeOut;
00102         int DeviceAf;
00103 #endif
00104 
00105         /* Client only */
00106 #ifdef INCLUDE_CLIENT_APIS
00107 
00108         ClientSubscription *ClientSubList;
00110         LinkedList SsdpSearchList;
00111 #endif
00112 };
00113 
00114 
00115 extern ithread_rwlock_t GlobalHndRWLock;
00116 
00117 
00123 Upnp_Handle_Type GetHandleInfo(
00125         int Hnd,
00127         struct Handle_Info **HndInfo); 
00128 
00129 
00130 #define HandleLock() HandleWriteLock()
00131 
00132 
00133 #define HandleWriteLock()  \
00134         UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying a write lock\n"); \
00135         ithread_rwlock_wrlock(&GlobalHndRWLock); \
00136         UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Write lock acquired\n");
00137 
00138 
00139 #define HandleReadLock()  \
00140         UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying a read lock\n"); \
00141         ithread_rwlock_rdlock(&GlobalHndRWLock); \
00142         UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Read lock acquired\n");
00143 
00144 
00145 #define HandleUnlock() \
00146         UpnpPrintf(UPNP_INFO, API,__FILE__, __LINE__, "Trying Unlock\n"); \
00147         ithread_rwlock_unlock(&GlobalHndRWLock); \
00148         UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Unlocked rwlock\n");
00149 
00150 
00158 Upnp_Handle_Type GetClientHandleInfo(
00160         int *client_handle_out, 
00162         struct Handle_Info **HndInfo);
00169 Upnp_Handle_Type GetDeviceHandleInfo(
00171         const int AddressFamily,
00173         int *device_handle_out, 
00175         struct Handle_Info **HndInfo);
00176 
00177 
00178 extern char gIF_NAME[LINE_SIZE];
00180 extern char gIF_IPV4[22];
00182 extern char gIF_IPV6[65];
00183 extern int  gIF_INDEX;
00184 
00185 
00186 extern unsigned short LOCAL_PORT_V4;
00187 extern unsigned short LOCAL_PORT_V6;
00188 
00189 
00191 extern Upnp_SID gUpnpSdkNLSuuid;
00192 
00193 
00194 extern TimerThread gTimerThread;
00195 extern ThreadPool gRecvThreadPool;
00196 extern ThreadPool gSendThreadPool;
00197 extern ThreadPool gMiniServerThreadPool;
00198 
00199 
00200 typedef enum {
00201         SUBSCRIBE,
00202         UNSUBSCRIBE,
00203         DK_NOTIFY,
00204         QUERY,
00205         ACTION,
00206         STATUS,
00207         DEVDESCRIPTION,
00208         SERVDESCRIPTION,
00209         MINI,
00210         RENEW
00211 } UpnpFunName;
00212 
00213 
00214 struct  UpnpNonblockParam 
00215 {
00216         UpnpFunName FunName;
00217         int Handle;
00218         int TimeOut;
00219         char VarName[NAME_SIZE];
00220         char NewVal[NAME_SIZE];
00221         char DevType[NAME_SIZE];
00222         char DevId[NAME_SIZE];
00223         char ServiceType[NAME_SIZE];
00224         char ServiceVer[NAME_SIZE];
00225         char Url[NAME_SIZE];
00226         Upnp_SID SubsId;
00227         char *Cookie;
00228         Upnp_FunPtr Fun;
00229         IXML_Document *Header;
00230         IXML_Document *Act;
00231         struct DevDesc *Devdesc;
00232 };
00233 
00234 
00235 extern virtualDirList *pVirtualDirList;
00236 extern struct VirtualDirCallbacks virtualDirCallback;
00237 
00238 
00239 typedef enum {
00240         WEB_SERVER_DISABLED,
00241         WEB_SERVER_ENABLED
00242 } WebServerState;
00243 
00244 
00245 #define E_HTTP_SYNTAX -6
00246 
00247 
00266 int UpnpGetIfInfo(
00268         const char *IfName);
00269 
00270 
00274 void InitHandleList();
00275 
00276 
00283 int GetFreeHandle();
00284 
00285 
00291 int FreeHandle(
00293         int Handle);
00294 
00295 
00296 void UpnpThreadDistribution(struct UpnpNonblockParam * Param);
00297 
00298 
00303 void AutoAdvertise(
00305         void *input); 
00306 
00307 
00316 int getlocalhostname(
00318         char *out,
00320         const int out_len);
00321 
00322 
00328 int PrintHandleInfo(
00330         UpnpClient_Handle Hnd);
00331 
00332 
00333 extern WebServerState bWebServerState;
00334 
00335 
00336 #endif /* UPNPAPI_H */
00337 
Generated on Fri May 21 00:33:58 2010 for libUPnP by  doxygen 1.6.3