libUPnP  1.6.20
service_table.h
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * Copyright (c) 2000-2003 Intel Corporation
4  * All rights reserved.
5  * Copyright (c) 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 #ifndef SERVICE_TABLE_H
34 #define SERVICE_TABLE_H
35 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #include "config.h"
45 #include "uri.h"
46 #include "ixml.h"
47 #include "upnp.h"
48 #include "upnpdebug.h"
49 
50 #include <stdio.h>
51 #include <time.h>
52 
53 #define SID_SIZE (size_t)41
54 
55 #ifdef INCLUDE_DEVICE_APIS
56 
57 typedef struct SUBSCRIPTION {
58  Upnp_SID sid;
59  int eventKey;
60  int ToSendEventKey;
61  time_t expireTime;
62  int active;
63  URL_list DeliveryURLs;
64  struct SUBSCRIPTION *next;
65 } subscription;
66 
67 typedef struct SERVICE_INFO {
68  DOMString serviceType;
69  DOMString serviceId;
70  char *SCPDURL ;
71  char *controlURL;
72  char *eventURL;
73  DOMString UDN;
74  int active;
75  int TotalSubscriptions;
76  subscription *subscriptionList;
77  struct SERVICE_INFO *next;
78 } service_info;
79 
80 typedef struct SERVICE_TABLE {
81  DOMString URLBase;
82  service_info *serviceList;
83  service_info *endServiceList;
85 
86 /* Functions for Subscriptions */
87 
95  subscription *in,
97  subscription *out);
98 
99 /*
100  * \brief Remove the subscription represented by the const Upnp_SID sid parameter
101  * from the service table and update the service table.
102  */
105  Upnp_SID sid,
107  service_info *service);
108 
117  const Upnp_SID sid,
119  service_info *service);
120 
128  service_info *service);
129 
137  service_info *service,
139  subscription *current);
140 
144 void freeSubscription(
146  subscription *sub);
147 
153  subscription * head);
154 
163  service_table *table,
166  const char *serviceId,
169  const char *UDN);
170 
180  service_table *table,
182  char *eventURLPath);
183 
193  service_table *table,
195  const char *controlURLPath);
196 
201 #ifdef DEBUG
202 void printService(
204  service_info *service,
206  Upnp_LogLevel level,
208  Dbg_Module module);
209 #else
210 static UPNP_INLINE void printService(
211  service_info *service,
212  Upnp_LogLevel level,
213  Dbg_Module module)
214 {
215  return;
216  service = service;
217  level = level;
218  module = module;
219 }
220 #endif
221 
226 #ifdef DEBUG
227 void printServiceList(
229  service_info *service,
231  Upnp_LogLevel level,
233  Dbg_Module module);
234 #else
235 static UPNP_INLINE void printServiceList(
236  service_info *service,
237  Upnp_LogLevel level,
238  Dbg_Module module)
239 {
240  return;
241  service = service;
242  level = level;
243  module = module;
244 }
245 #endif
246 
251 #ifdef DEBUG
252 void printServiceTable(
254  service_table *table,
256  Upnp_LogLevel level,
258  Dbg_Module module);
259 #else
260 static UPNP_INLINE void printServiceTable(
261  service_table *table,
262  Upnp_LogLevel level,
263  Dbg_Module module)
264 {
265  return;
266  table = table;
267  level = level;
268  module = module;
269 }
270 #endif
271 
276 void freeService(
278  service_info *in);
279 
284 void freeServiceList(
286  service_info *head);
287 
292 void freeServiceTable(
294  service_table *table);
295 
306  IXML_Node *node,
308  service_table *in);
309 
313 int addServiceTable(
315  IXML_Node *node,
317  service_table *in,
320  const char *DefaultURLBase);
321 
327 int getServiceTable(
329  IXML_Node *node,
331  service_table *out,
333  const char *DefaultURLBase);
334 
335 /* Misc helper functions */
336 
346  IXML_Node *node);
347 
356 int getSubElement(
358  const char *element_name,
360  IXML_Node *node,
362  IXML_Node **out);
363 
364 #endif /* INCLUDE_DEVICE_APIS */
365 
366 #ifdef __cplusplus
367 }
368 #endif
369 
370 #endif /* SERVICE_TABLE */
371 
Definition: service_table.h:57
Definition: service_table.h:67
int copy_subscription(subscription *in, subscription *out)
Makes a copy of the subscription.
Definition: service_table.c:62
subscription * GetFirstSubscription(service_info *service)
Gets pointer to the first subscription node in the service table.
Definition: service_table.c:192
void printServiceList(service_info *service, Upnp_LogLevel level, Dbg_Module module)
For debugging purposes prints information of each service from the service table passed into the func...
Definition: service_table.c:452
void freeSubscriptionList(subscription *head)
Free's memory allocated for all the subscriptions in the service table.
Definition: service_table.c:227
void printService(service_info *service, Upnp_LogLevel level, Dbg_Module module)
For debugging purposes prints information from the service passed into the function.
Definition: service_table.c:395
subscription * GetSubscriptionSID(const Upnp_SID sid, service_info *service)
Return the subscription from the service table that matches const Upnp_SID sid value.
Definition: service_table.c:123
Represents a list of URLs as in the "callback" header of SUBSCRIBE message in GENA. "char *" URLs holds dynamic memory.
Definition: uri.h:149
void printServiceTable(service_table *table, Upnp_LogLevel level, Dbg_Module module)
For debugging purposes prints the URL base of the table and information of each service from the serv...
Definition: service_table.c:511
DOMString getElementValue(IXML_Node *node)
Returns the clone of the element value.
Definition: service_table.c:644
void freeSubscription(subscription *sub)
Free's the memory allocated for storing the URL of the subscription.
Definition: service_table.c:206
service_info * FindServiceControlURLPath(service_table *table, const char *controlURLPath)
Traverses the service table and finds the node whose control URL Path matches a know value...
Definition: service_table.c:347
void freeServiceList(service_info *head)
Free's memory allocated for the various components of each service entry in the service table...
Definition: service_table.c:580
void freeServiceTable(service_table *table)
Free's dynamic memory in table (does not free table, only memory within the structure).
Definition: service_table.c:622
Definition: service_table.h:80
void freeService(service_info *in)
Free's memory allocated for the various components of the service entry in the service table...
Definition: service_table.c:537
Data structure common to all types of nodes.
Definition: ixml.h:165
int addServiceTable(IXML_Node *node, service_table *in, const char *DefaultURLBase)
Add Service to the table.
Definition: service_table.c:991
subscription * GetNextSubscription(service_info *service, subscription *current)
Get current and valid subscription from the service table.
Definition: service_table.c:159
void RemoveSubscriptionSID(Upnp_SID sid, service_info *service)
Definition: service_table.c:98
#define DOMString
The type of DOM strings.
Definition: ixml.h:59
int removeServiceTable(IXML_Node *node, service_table *in)
This function assumes that services for a particular root device are placed linearly in the service t...
Definition: service_table.c:916
int getSubElement(const char *element_name, IXML_Node *node, IXML_Node **out)
Traverses through a list of XML nodes to find the node with the known element name.
Definition: service_table.c:677
int getServiceTable(IXML_Node *node, service_table *out, const char *DefaultURLBase)
Retrieve service from the table.
Definition: service_table.c:1044
service_info * FindServiceId(service_table *table, const char *serviceId, const char *UDN)
Traverses through the service table and returns a pointer to the service node that matches a known se...
Definition: service_table.c:258
char Upnp_SID[44]
Holds the subscription identifier for a subscription between a client and a device.
Definition: upnp.h:555
#define UPNP_INLINE
Declares an inline function.
Definition: UpnpGlobal.h:93
service_info * FindServiceEventURLPath(service_table *table, char *eventURLPath)
Traverses the service table and finds the node whose event URL Path matches a know value...
Definition: service_table.c:295