libUPnP  1.6.17
gena.h
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * Copyright (c) 2000-2003 Intel Corporation
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * - Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * - Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * - Neither name of Intel Corporation nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  ******************************************************************************/
31 
32 
33 #ifndef GENA_H
34 #define GENA_H
35 
36 
42 #include "config.h"
43 
44 
45 #include <string.h>
46 #include <time.h>
47 
48 
49 #include "client_table.h"
50 #include "httpparser.h"
51 #include "miniserver.h"
52 #include "service_table.h"
53 #include "sock.h"
54 #include "ThreadPool.h"
55 #include "upnp.h"
56 #include "UpnpString.h"
57 #include "uri.h"
58 
59 
60 #ifdef __cplusplus
61  #define EXTERN_C extern "C"
62 #else /* __cplusplus */
63  #ifndef EXTERN_C
64  #define EXTERN_C
65  #endif /* EXTERN_C */
66 #endif /* __cplusplus */
67 
68 
73 #define XML_VERSION "<?xml version='1.0' encoding='ISO-8859-1' ?>\n"
74 #define XML_PROPERTYSET_HEADER \
75  "<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">\n"
76 
77 
78 #define UNABLE_MEMORY "HTTP/1.1 500 Internal Server Error\r\n\r\n"
79 #define UNABLE_SERVICE_UNKNOWN "HTTP/1.1 404 Not Found\r\n\r\n"
80 #define UNABLE_SERVICE_NOT_ACCEPT "HTTP/1.1 503 Service Not Available\r\n\r\n"
81 
82 
83 #define NOT_IMPLEMENTED "HTTP/1.1 501 Not Implemented\r\n\r\n"
84 #define BAD_REQUEST "HTTP/1.1 400 Bad Request\r\n\r\n"
85 #define INVALID_NT BAD_CALLBACK
86 #define BAD_CALLBACK "HTTP/1.1 412 Precondition Failed\r\n\r\n"
87 #define HTTP_OK_CRLF "HTTP/1.1 200 OK\r\n\r\n"
88 #define HTTP_OK_STR "HTTP/1.1 200 OK\r\n"
89 #define INVALID_SID BAD_CALLBACK
90 #define MISSING_SID BAD_CALLBACK
91 #define MAX_CONTENT_LENGTH 20
92 #define MAX_SECONDS 10
93 #define MAX_EVENTS 20
94 #define MAX_PORT_SIZE 10
95 
96 
97 #define GENA_E_BAD_RESPONSE UPNP_E_BAD_RESPONSE
98 #define GENA_E_BAD_SERVICE UPNP_E_INVALID_SERVICE
99 #define GENA_E_SUBSCRIPTION_UNACCEPTED UPNP_E_SUBSCRIBE_UNACCEPTED
100 #define GENA_E_BAD_SID UPNP_E_INVALID_SID
101 #define GENA_E_UNSUBSCRIBE_UNACCEPTED UPNP_E_UNSUBSCRIBE_UNACCEPTED
102 #define GENA_E_NOTIFY_UNACCEPTED UPNP_E_NOTIFY_UNACCEPTED
103 #define GENA_E_NOTIFY_UNACCEPTED_REMOVE_SUB -9
104 #define GENA_E_BAD_HANDLE UPNP_E_INVALID_HANDLE
105 
106 
107 #define XML_ERROR -5
108 #define XML_SUCCESS UPNP_E_SUCCESS
109 #define GENA_SUCCESS UPNP_E_SUCCESS
110 
111 
112 #define CALLBACK_SUCCESS 0
113 #define DEFAULT_TIMEOUT 1801
114 
115 
116 extern ithread_mutex_t GlobalClientSubscribeMutex;
117 
118 
122 #define SubscribeLock() \
123  UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \
124  "Trying Subscribe Lock\n"); \
125  ithread_mutex_lock(&GlobalClientSubscribeMutex); \
126  UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \
127  "Subscribe Lock\n");
128 
129 
133 #define SubscribeUnlock() \
134  UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \
135  "Trying Subscribe UnLock\n"); \
136  ithread_mutex_unlock(&GlobalClientSubscribeMutex); \
137  UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \
138  "Subscribe UnLock\n");
139 
140 
144 typedef struct NOTIFY_THREAD_STRUCT {
145  char *headers;
146  DOMString propertySet;
147  char *servId;
148  char *UDN;
149  Upnp_SID sid;
150  int eventKey;
151  int *reference_count;
152  UpnpDevice_Handle device_handle;
154 
155 
162 EXTERN_C void genaCallback(
164  http_parser_t *parser,
166  http_message_t* request,
168  SOCKINFO *info);
169 
170 
181 #ifdef INCLUDE_CLIENT_APIS
182 EXTERN_C int genaSubscribe(
184  UpnpClient_Handle client_handle,
186  const UpnpString *PublisherURL,
191  int *TimeOut,
193  UpnpString *out_sid);
194 #endif /* INCLUDE_CLIENT_APIS */
195 
196 
207 #ifdef INCLUDE_CLIENT_APIS
208 EXTERN_C int genaUnSubscribe(
210  UpnpClient_Handle client_handle,
212  const UpnpString *in_sid);
213 #endif /* INCLUDE_CLIENT_APIS */
214 
215 
225 #ifdef INCLUDE_CLIENT_APIS
226 EXTERN_C int genaUnregisterClient(
228  UpnpClient_Handle client_handle);
229 #endif /* INCLUDE_CLIENT_APIS */
230 
231 
232 /*
233  * DEVICE
234  */
235 
236 
242 #ifdef INCLUDE_DEVICE_APIS
243 EXTERN_C int genaUnregisterDevice(
246 #endif /* INCLUDE_CLIENT_APIS */
247 
248 
259 #ifdef INCLUDE_CLIENT_APIS
260 EXTERN_C int genaRenewSubscription(
262  UpnpClient_Handle client_handle,
264  const UpnpString *in_sid,
267  int *TimeOut);
268 #endif /* INCLUDE_CLIENT_APIS */
269 
270 
279 #ifdef INCLUDE_DEVICE_APIS
280 EXTERN_C int genaNotifyAll(
284  char *UDN,
286  char *servId,
288  char **VarNames,
290  char **VarValues,
292  int var_count);
293 #endif /* INCLUDE_DEVICE_APIS */
294 
295 
304 #ifdef INCLUDE_DEVICE_APIS
305 EXTERN_C int genaNotifyAllExt(
309  char *UDN,
311  char *servId,
313  IXML_Document *PropSet);
314 #endif /* INCLUDE_DEVICE_APIS */
315 
316 
325 #ifdef INCLUDE_DEVICE_APIS
326 EXTERN_C int genaInitNotify(
330  char *UDN,
332  char *servId,
334  char **VarNames,
336  char **VarValues,
338  int var_count,
340  const Upnp_SID sid);
341 #endif /* INCLUDE_DEVICE_APIS */
342 
343 
354 #ifdef INCLUDE_DEVICE_APIS
355 EXTERN_C int genaInitNotifyExt(
359  char *UDN,
361  char *servId,
363  IXML_Document *PropSet,
365  const Upnp_SID sid);
366 #endif /* INCLUDE_DEVICE_APIS */
367 
368 
375 void error_respond(
377  SOCKINFO *info,
379  int error_code,
381  http_message_t* hmsg);
382 
383 
384 #endif /* GENA_H */
385