libUPnP  1.8.2
upnpapi.h
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * Copyright (c) 2000-2003 Intel Corporation
4  * All rights reserved.
5  * Copyright (C) 2011-2012 France Telecom All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  * * Neither name of Intel Corporation nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  ******************************************************************************/
32 
33 
34 #ifndef UPNPAPI_H
35 #define UPNPAPI_H
36 
37 
43 #include "client_table.h"
44 #include "upnp.h"
45 #include "VirtualDir.h" /* for struct VirtualDirCallbacks */
46 
47 
48 #define MAX_INTERFACES 256
49 
50 #define DEFAULT_INTERFACE 1
51 
52 #define DEV_LIMIT 200
53 
54 #define DEFAULT_MX 5
55 
56 #define DEFAULT_MAXAGE 1800
57 
58 #define DEFAULT_SOAP_CONTENT_LENGTH 16000
59 #define MAX_SOAP_CONTENT_LENGTH (size_t)32000
60 
61 #define NUM_HANDLE 200
62 
63 extern size_t g_maxContentLength;
64 extern int g_UpnpSdkEQMaxLen;
65 extern int g_UpnpSdkEQMaxAge;
66 
67 /* 30-second timeout */
68 #define UPNP_TIMEOUT 30
69 
70 typedef enum {HND_INVALID=-1,HND_CLIENT,HND_DEVICE} Upnp_Handle_Type;
71 
72 /* Data to be stored in handle table for */
74 {
76  Upnp_Handle_Type HType;
80  char *Cookie;
83 
84  /* Device Only */
85 #ifdef INCLUDE_DEVICE_APIS
86 
87  char DescURL[LINE_SIZE];
90  char LowerDescURL[LINE_SIZE];
92  char DescXML[LINE_SIZE];
93  /* Advertisement timeout */
94  int MaxAge;
95  /* Power State as defined by UPnP Low Power. */
96  int PowerState;
97  /* Sleep Period as defined by UPnP Low Power. */
98  int SleepPeriod;
99  /* Registration State as defined by UPnP Low Power. */
100  int RegistrationState;
114  int DeviceAf;
115 #endif
116 
117  /* Client only */
118 #ifdef INCLUDE_CLIENT_APIS
119 
120  GenlibClientSubscription *ClientSubList;
123 #endif
124 };
125 
126 extern ithread_rwlock_t GlobalHndRWLock;
127 
133 Upnp_Handle_Type GetHandleInfo(
135  int Hnd,
137  struct Handle_Info **HndInfo);
138 
139 
140 #define HandleLock() HandleWriteLock()
141 
142 
143 #define HandleWriteLock() \
144  UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying a write lock\n"); \
145  ithread_rwlock_wrlock(&GlobalHndRWLock); \
146  UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Write lock acquired\n");
147 
148 
149 #define HandleReadLock() \
150  UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying a read lock\n"); \
151  ithread_rwlock_rdlock(&GlobalHndRWLock); \
152  UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Read lock acquired\n");
153 
154 
155 #define HandleUnlock() \
156  UpnpPrintf(UPNP_INFO, API,__FILE__, __LINE__, "Trying Unlock\n"); \
157  ithread_rwlock_unlock(&GlobalHndRWLock); \
158  UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Unlocked rwlock\n");
159 
160 
168 Upnp_Handle_Type GetClientHandleInfo(
170  int *client_handle_out,
172  struct Handle_Info **HndInfo);
179 Upnp_Handle_Type GetDeviceHandleInfo(
181  int AddressFamily,
183  int *device_handle_out,
185  struct Handle_Info **HndInfo);
186 
187 
188 extern char gIF_NAME[LINE_SIZE];
189 extern char gIF_IPV4[INET_ADDRSTRLEN];
190 extern char gIF_IPV6[INET6_ADDRSTRLEN];
191 
192 extern char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN];
193 
194 extern unsigned gIF_INDEX;
195 
196 
197 extern unsigned short LOCAL_PORT_V4;
198 extern unsigned short LOCAL_PORT_V6;
199 
200 
203 
204 
209 
210 
211 typedef enum {
212  SUBSCRIBE,
213  UNSUBSCRIBE,
214  DK_NOTIFY,
215  QUERY,
216  ACTION,
217  STATUS,
218  DEVDESCRIPTION,
219  SERVDESCRIPTION,
220  MINI,
221  RENEW
222 } UpnpFunName;
223 
224 
226 {
227  UpnpFunName FunName;
228  int Handle;
229  int TimeOut;
230  char VarName[NAME_SIZE];
231  char NewVal[NAME_SIZE];
232  char DevType[NAME_SIZE];
233  char DevId[NAME_SIZE];
234  char ServiceType[NAME_SIZE];
235  char ServiceVer[NAME_SIZE];
236  char Url[NAME_SIZE];
237  Upnp_SID SubsId;
238  char *Cookie;
239  Upnp_FunPtr Fun;
240  IXML_Document *Header;
241  IXML_Document *Act;
242  struct DevDesc *Devdesc;
243 };
244 
245 
247 extern struct VirtualDirCallbacks virtualDirCallback;
248 
249 
250 typedef enum {
251  WEB_SERVER_DISABLED,
252  WEB_SERVER_ENABLED
253 } WebServerState;
254 
255 
256 #define E_HTTP_SYNTAX -6
257 
258 
278 int UpnpGetIfInfo(
280  const char *IfName);
281 
282 
283 void UpnpThreadDistribution(struct UpnpNonblockParam * Param);
284 
285 
290 void AutoAdvertise(
292  void *input);
293 
294 
303 int getlocalhostname(
305  char *out,
307  size_t out_len);
308 
309 
315 int PrintHandleInfo(
317  UpnpClient_Handle Hnd);
318 
319 
320 extern WebServerState bWebServerState;
321 
322 
323 #endif /* UPNPAPI_H */
324 
Upnp_FunPtr Callback
Definition: upnpapi.h:78
int UpnpClient_Handle
Returned when a control point application registers with UpnpRegisterClient.
Definition: upnp.h:426
int(* Upnp_FunPtr)(Upnp_EventType EventType, const void *Event, void *Cookie)
Definition: Callback.h:145
IXML_Document * DescDocument
Definition: upnpapi.h:102
size_t g_maxContentLength
Definition: upnpapi.c:163
char DescURL[LINE_SIZE]
Definition: upnpapi.h:87
Definition: TimerThread.h:67
Definition: upnpapi.h:225
IXML_NodeList * DeviceList
Definition: upnpapi.h:104
Upnp_Handle_Type GetHandleInfo(int Hnd, struct Handle_Info **HndInfo)
Get handle information.
Definition: upnpapi.c:3886
int getlocalhostname(char *out, size_t out_len)
Get local IP address.
Definition: upnpapi.c:3939
char LowerDescURL[LINE_SIZE]
Definition: upnpapi.h:90
int g_UpnpSdkEQMaxAge
Definition: upnpapi.c:179
Upnp_Handle_Type HType
Definition: upnpapi.h:76
LinkedList SsdpSearchList
Definition: upnpapi.h:122
Definition: VirtualDir.h:11
ThreadPool gSendThreadPool
Definition: upnpapi.c:122
IXML_NodeList * ServiceList
Definition: upnpapi.h:106
WebServerState bWebServerState
Definition: upnpapi.c:131
GenlibClientSubscription * ClientSubList
Definition: upnpapi.h:120
Upnp_SID gUpnpSdkNLSuuid
int PrintHandleInfo(UpnpClient_Handle Hnd)
Print handle info.
Definition: upnpapi.c:3913
char gIF_IPV6[INET6_ADDRSTRLEN]
Definition: upnpapi.c:140
int MaxSubscriptionTimeOut
Definition: upnpapi.h:112
A thread pool similar to the thread pool in the UPnP SDK.
Definition: ThreadPool.h:212
Upnp_Handle_Type GetDeviceHandleInfo(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...
Definition: upnpapi.c:3854
unsigned short LOCAL_PORT_V6
Definition: upnpapi.c:152
TimerThread gTimerThread
Definition: upnpapi.c:119
int aliasInstalled
Definition: upnpapi.h:82
Definition: service_table.h:86
void AutoAdvertise(void *input)
This function is a timer thread scheduled by UpnpSendAdvertisement to the send advetisement again...
Definition: upnpapi.c:4099
unsigned short LOCAL_PORT_V4
Definition: upnpapi.c:149
void UpnpThreadDistribution(struct UpnpNonblockParam *Param)
Schedule async functions in threadpool.
Definition: upnpapi.c:3718
char gIF_NAME[LINE_SIZE]
Definition: upnpapi.c:134
char gIF_IPV4[INET_ADDRSTRLEN]
Definition: upnpapi.c:137
ithread_rwlock_t GlobalHndRWLock
Definition: upnpapi.c:109
Upnp_Handle_Type GetClientHandleInfo(int *client_handle_out, struct Handle_Info **HndInfo)
Get client handle info.
Definition: upnpapi.c:3832
service_table ServiceTable
Definition: upnpapi.h:108
Data structure representing a list of nodes.
Definition: ixml.h:245
virtualDirList * pVirtualDirList
Definition: upnpapi.c:101
unsigned gIF_INDEX
Definition: upnpapi.c:146
char * Cookie
Definition: upnpapi.h:80
int MaxSubscriptions
Definition: upnpapi.h:110
int DeviceAf
Definition: upnpapi.h:114
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:3330
int g_UpnpSdkEQMaxLen
Definition: upnpapi.c:169
Data structure representing the DOM Document.
Definition: ixml.h:197
ThreadPool gRecvThreadPool
Definition: upnpapi.c:125
Definition: VirtualDir.h:61
char Upnp_SID[44]
Holds the subscription identifier for a subscription between a client and a device.
Definition: upnp.h:445
char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN]
Definition: upnpapi.c:143
ThreadPool gMiniServerThreadPool
Definition: upnpapi.c:128
char DescXML[LINE_SIZE]
Definition: upnpapi.h:92
Definition: upnpapi.h:73
Definition: LinkedList.h:83