libUPnP  1.8.4
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"); \
125  ithread_mutex_lock(&GlobalClientSubscribeMutex); \
126  UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \
127  "Subscribe Lock");
128 
129 
133 #define SubscribeUnlock() \
134  UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \
135  "Trying Subscribe UnLock"); \
136  ithread_mutex_unlock(&GlobalClientSubscribeMutex); \
137  UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \
138  "Subscribe UnLock");
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  time_t ctime;
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(
245  UpnpDevice_Handle device_handle);
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(
282  UpnpDevice_Handle device_handle,
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(
307  UpnpDevice_Handle device_handle,
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(
328  UpnpDevice_Handle device_handle,
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(
357  UpnpDevice_Handle device_handle,
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 
int genaRenewSubscription(UpnpClient_Handle client_handle, const UpnpString *in_sid, int *TimeOut)
Renews a SID.
Definition: gena_ctrlpt.c:598
int UpnpClient_Handle
Returned when a control point application registers with UpnpRegisterClient.
Definition: upnp.h:426
Definition: gena.h:144
void error_respond(SOCKINFO *info, int error_code, http_message_t *hmsg)
Sends an error message to the control point in the case of incorrect GENA requests.
int genaSubscribe(UpnpClient_Handle client_handle, const UpnpString *PublisherURL, int *TimeOut, UpnpString *out_sid)
This function subscribes to a PublisherURL (also mentioned as EventURL in some places).
Definition: gena_ctrlpt.c:509
Definition: httpparser.h:179
struct NOTIFY_THREAD_STRUCT notify_thread_struct
int genaUnSubscribe(UpnpClient_Handle client_handle, const UpnpString *in_sid)
Unsubscribes a SID.
Definition: gena_ctrlpt.c:457
int genaInitNotify(UpnpDevice_Handle device_handle, char *UDN, char *servId, char **VarNames, char **VarValues, int var_count, const Upnp_SID sid)
Sends the intial state table dump to newly subscribed control point.
Definition: gena_device.c:624
UpnpString object declaration.
int genaUnregisterClient(UpnpClient_Handle client_handle)
Unsubcribes all the outstanding subscriptions and cleans the subscription list.
Definition: gena_ctrlpt.c:411
void genaCallback(http_parser_t *parser, http_message_t *request, SOCKINFO *info)
This is the callback function called by the miniserver to handle incoming GENA requests.
Definition: sock.h:59
int UpnpDevice_Handle
Returned when a device application registers with UpnpRegisterRootDevice, UpnpRegisterRootDevice2, UpnpRegisterRootDevice3 or UpnpRegisterRootDevice4.
Definition: upnp.h:436
int genaInitNotifyExt(UpnpDevice_Handle device_handle, char *UDN, char *servId, IXML_Document *PropSet, const Upnp_SID sid)
Similar to the genaInitNofity. The only difference is that it takes the xml document for the state ta...
Definition: gena_device.c:666
ithread_mutex_t GlobalClientSubscribeMutex
Definition: upnpapi.c:105
#define DOMString
The type of DOM strings.
Definition: ixml.h:59
int genaNotifyAll(UpnpDevice_Handle device_handle, char *UDN, char *servId, char **VarNames, char **VarValues, int var_count)
Sends a notification to all the subscribed control points.
Definition: gena_device.c:927
int genaUnregisterDevice(UpnpDevice_Handle device_handle)
Cleans the service table of the device.
Definition: gena_device.c:66
Definition: httpparser.h:213
Data structure representing the DOM Document.
Definition: ixml.h:197
struct s_UpnpString UpnpString
Type of the string objects inside libupnp.
Definition: UpnpString.h:38
char Upnp_SID[44]
Holds the subscription identifier for a subscription between a client and a device.
Definition: upnp.h:445
int genaNotifyAllExt(UpnpDevice_Handle device_handle, char *UDN, char *servId, IXML_Document *PropSet)
Sends a notification to all the subscribed control points.
Definition: gena_device.c:891