libUPnP  1.14.24
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 #ifndef GENA_H
33 #define GENA_H
34 
39 #include "config.h"
40 
41 #include <time.h>
42 
43 #include "UpnpString.h"
44 #include "httpparser.h"
45 #include "ithread.h"
46 #include "sock.h"
47 #include "upnp.h"
48 
49 #ifdef __cplusplus
50  #define EXTERN_C extern "C"
51 #else /* __cplusplus */
52  #ifndef EXTERN_C
53  #define EXTERN_C
54  #endif /* EXTERN_C */
55 #endif /* __cplusplus */
56 
61 #define XML_VERSION "<?xml version='1.0' encoding='ISO-8859-1' ?>\n"
62 #define XML_PROPERTYSET_HEADER \
63  "<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">\n"
64 
65 #define UNABLE_MEMORY "HTTP/1.1 500 Internal Server Error\r\n\r\n"
66 #define UNABLE_SERVICE_UNKNOWN "HTTP/1.1 404 Not Found\r\n\r\n"
67 #define UNABLE_SERVICE_NOT_ACCEPT "HTTP/1.1 503 Service Not Available\r\n\r\n"
68 
69 #define NOT_IMPLEMENTED "HTTP/1.1 501 Not Implemented\r\n\r\n"
70 #define BAD_REQUEST "HTTP/1.1 400 Bad Request\r\n\r\n"
71 #define INVALID_NT BAD_CALLBACK
72 #define BAD_CALLBACK "HTTP/1.1 412 Precondition Failed\r\n\r\n"
73 #define HTTP_OK_CRLF "HTTP/1.1 200 OK\r\n\r\n"
74 #define HTTP_OK_STR "HTTP/1.1 200 OK\r\n"
75 #define INVALID_SID BAD_CALLBACK
76 #define MISSING_SID BAD_CALLBACK
77 #define MAX_CONTENT_LENGTH 20
78 #define MAX_SECONDS 10
79 #define MAX_EVENTS 20
80 #define MAX_PORT_SIZE 10
81 
82 #define GENA_E_BAD_RESPONSE UPNP_E_BAD_RESPONSE
83 #define GENA_E_BAD_SERVICE UPNP_E_INVALID_SERVICE
84 #define GENA_E_SUBSCRIPTION_UNACCEPTED UPNP_E_SUBSCRIBE_UNACCEPTED
85 #define GENA_E_BAD_SID UPNP_E_INVALID_SID
86 #define GENA_E_UNSUBSCRIBE_UNACCEPTED UPNP_E_UNSUBSCRIBE_UNACCEPTED
87 #define GENA_E_NOTIFY_UNACCEPTED UPNP_E_NOTIFY_UNACCEPTED
88 #define GENA_E_NOTIFY_UNACCEPTED_REMOVE_SUB -9
89 #define GENA_E_BAD_HANDLE UPNP_E_INVALID_HANDLE
90 
91 #define XML_ERROR -5
92 #define XML_SUCCESS UPNP_E_SUCCESS
93 #define GENA_SUCCESS UPNP_E_SUCCESS
94 
95 #define CALLBACK_SUCCESS 0
96 #define DEFAULT_TIMEOUT 1801
97 
98 extern ithread_mutex_t GlobalClientSubscribeMutex;
99 
103 #define SubscribeLock() \
104  UpnpPrintf( \
105  UPNP_INFO, GENA, __FILE__, __LINE__, "Trying Subscribe Lock"); \
106  ithread_mutex_lock(&GlobalClientSubscribeMutex); \
107  UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "Subscribe Lock")
108 
112 #define SubscribeUnlock() \
113  UpnpPrintf(UPNP_INFO, \
114  GENA, \
115  __FILE__, \
116  __LINE__, \
117  "Trying Subscribe UnLock"); \
118  ithread_mutex_unlock(&GlobalClientSubscribeMutex); \
119  UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "Subscribe UnLock")
120 
124 typedef struct NOTIFY_THREAD_STRUCT
125 {
126  char *headers;
127  DOMString propertySet;
128  char *servId;
129  char *UDN;
130  Upnp_SID sid;
131  time_t ctime;
132  int *reference_count;
133  UpnpDevice_Handle device_handle;
135 
142 EXTERN_C void genaCallback(
144  http_parser_t *parser,
146  http_message_t *request,
148  SOCKINFO *info);
149 
160 #ifdef INCLUDE_CLIENT_APIS
161 EXTERN_C int genaSubscribe(
163  UpnpClient_Handle client_handle,
165  const UpnpString *PublisherURL,
170  int *TimeOut,
172  UpnpString *out_sid);
173 #endif /* INCLUDE_CLIENT_APIS */
174 
185 #ifdef INCLUDE_CLIENT_APIS
186 EXTERN_C int genaUnSubscribe(
188  UpnpClient_Handle client_handle,
190  const UpnpString *in_sid);
191 #endif /* INCLUDE_CLIENT_APIS */
192 
202 #ifdef INCLUDE_CLIENT_APIS
203 EXTERN_C int genaUnregisterClient(
205  UpnpClient_Handle client_handle);
206 #endif /* INCLUDE_CLIENT_APIS */
207 
208 /*
209  * DEVICE
210  */
211 
217 #ifdef INCLUDE_DEVICE_APIS
218 EXTERN_C int genaUnregisterDevice(
221 #endif /* INCLUDE_CLIENT_APIS */
222 
233 #ifdef INCLUDE_CLIENT_APIS
234 EXTERN_C int genaRenewSubscription(
236  UpnpClient_Handle client_handle,
238  const UpnpString *in_sid,
241  int *TimeOut);
242 #endif /* INCLUDE_CLIENT_APIS */
243 
252 #ifdef INCLUDE_DEVICE_APIS
253 EXTERN_C int genaNotifyAll(
257  char *UDN,
259  char *servId,
261  char **VarNames,
263  char **VarValues,
265  int var_count);
266 #endif /* INCLUDE_DEVICE_APIS */
267 
276 #ifdef INCLUDE_DEVICE_APIS
277 EXTERN_C int genaNotifyAllExt(
281  char *UDN,
283  char *servId,
285  IXML_Document *PropSet);
286 #endif /* INCLUDE_DEVICE_APIS */
287 
296 #ifdef INCLUDE_DEVICE_APIS
297 EXTERN_C int genaInitNotify(
301  char *UDN,
303  char *servId,
305  char **VarNames,
307  char **VarValues,
309  int var_count,
311  const Upnp_SID sid);
312 #endif /* INCLUDE_DEVICE_APIS */
313 
324 #ifdef INCLUDE_DEVICE_APIS
325 EXTERN_C int genaInitNotifyExt(
329  char *UDN,
331  char *servId,
333  IXML_Document *PropSet,
335  const Upnp_SID sid);
336 #endif /* INCLUDE_DEVICE_APIS */
337 
344 void error_respond(
346  SOCKINFO *info,
348  int error_code,
350  http_message_t *hmsg);
351 
352 #endif /* GENA_H */
int genaRenewSubscription(UpnpClient_Handle client_handle, const UpnpString *in_sid, int *TimeOut)
Renews a SID.
Definition: gena_ctrlpt.c:662
int UpnpClient_Handle
Returned when a control point application registers with UpnpRegisterClient.
Definition: upnp.h:429
Definition: gena.h:124
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.
Definition: gena_callback2.c:58
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:567
Definition: httpparser.h:181
struct NOTIFY_THREAD_STRUCT notify_thread_struct
UpnpDevice_Handle device_handle
Definition: tv_device.c:78
int genaUnSubscribe(UpnpClient_Handle client_handle, const UpnpString *in_sid)
Unsubscribes a SID.
Definition: gena_ctrlpt.c:518
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:659
UpnpString object declaration.
int genaUnregisterClient(UpnpClient_Handle client_handle)
Unsubcribes all the outstanding subscriptions and cleans the subscription list.
Definition: gena_ctrlpt.c:473
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: gena_callback2.c:84
Definition: sock.h:59
int UpnpDevice_Handle
Returned when a device application registers with UpnpRegisterRootDevice, UpnpRegisterRootDevice2, UpnpRegisterRootDevice3 or UpnpRegisterRootDevice4.
Definition: upnp.h:439
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:710
ithread_mutex_t GlobalClientSubscribeMutex
Definition: upnpapi.c:115
#define DOMString
The type of DOM strings.
Definition: ixml.h:48
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:1004
int genaUnregisterDevice(UpnpDevice_Handle device_handle)
Cleans the service table of the device.
Definition: gena_device.c:61
Definition: httpparser.h:216
Data structure representing the DOM Document.
Definition: ixml.h:159
struct s_UpnpString UpnpString
Type of the string objects inside libupnp.
Definition: UpnpString.h:33
char Upnp_SID[44]
Holds the subscription identifier for a subscription between a client and a device.
Definition: upnp.h:448
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:961