service_table.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. #ifndef SERVICE_TABLE_H
  33. #define SERVICE_TABLE_H
  34. /*!
  35. * \file
  36. */
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. #include "config.h"
  41. #include "uri.h"
  42. #include "ixml.h"
  43. #include "upnp.h"
  44. #include "upnpdebug.h"
  45. #include <stdio.h>
  46. #include <time.h>
  47. #define SID_SIZE (size_t)41
  48. #ifdef INCLUDE_DEVICE_APIS
  49. typedef struct SUBSCRIPTION {
  50. Upnp_SID sid;
  51. int ToSendEventKey;
  52. time_t expireTime;
  53. int active;
  54. URL_list DeliveryURLs;
  55. /* List of queued events for this subscription. Only one event job
  56. at a time goes into the thread pool. The first element in the
  57. list is a copy of the active job. Others are activated on job
  58. completion. */
  59. LinkedList outgoing;
  60. struct SUBSCRIPTION *next;
  61. } subscription;
  62. extern void freeSubscriptionQueuedEvents(subscription *sub);
  63. typedef struct SERVICE_INFO {
  64. DOMString serviceType;
  65. DOMString serviceId;
  66. char *SCPDURL ;
  67. char *controlURL;
  68. char *eventURL;
  69. DOMString UDN;
  70. int active;
  71. int TotalSubscriptions;
  72. subscription *subscriptionList;
  73. struct SERVICE_INFO *next;
  74. } service_info;
  75. typedef struct SERVICE_TABLE {
  76. DOMString URLBase;
  77. service_info *serviceList;
  78. service_info *endServiceList;
  79. } service_table;
  80. /* Functions for Subscriptions */
  81. /*!
  82. * \brief Makes a copy of the subscription.
  83. *
  84. * \return HTTP_SUCCESS on success.
  85. */
  86. int copy_subscription(
  87. /*! [in] Source subscription. */
  88. subscription *in,
  89. /*! [in] Destination subscription. */
  90. subscription *out);
  91. /*
  92. * \brief Remove the subscription represented by the const Upnp_SID sid parameter
  93. * from the service table and update the service table.
  94. */
  95. void RemoveSubscriptionSID(
  96. /*! [in] Subscription ID. */
  97. Upnp_SID sid,
  98. /*! [in] Service object providing the list of subscriptions. */
  99. service_info *service);
  100. /*!
  101. * \brief Return the subscription from the service table that matches
  102. * const Upnp_SID sid value.
  103. *
  104. * \return Pointer to the matching subscription node.
  105. */
  106. subscription *GetSubscriptionSID(
  107. /*! [in] Subscription ID. */
  108. const Upnp_SID sid,
  109. /*! [in] Service object providing the list of subscriptions. */
  110. service_info *service);
  111. /*!
  112. * \brief Gets pointer to the first subscription node in the service table.
  113. *
  114. * \return Pointer to the first subscription node.
  115. */
  116. subscription *GetFirstSubscription(
  117. /*! [in] Service object providing the list of subscriptions. */
  118. service_info *service);
  119. /*!
  120. * \brief Get current and valid subscription from the service table.
  121. *
  122. * \return Pointer to the next subscription node.
  123. */
  124. subscription *GetNextSubscription(
  125. /*! [in] Service object providing the list of subscriptions. */
  126. service_info *service,
  127. /*! [in] Current subscription object. */
  128. subscription *current);
  129. /*!
  130. * \brief Free's the memory allocated for storing the URL of the subscription.
  131. */
  132. void freeSubscription(
  133. /*! [in] Subscription object to be freed. */
  134. subscription *sub);
  135. /*!
  136. * \brief Free's memory allocated for all the subscriptions in the service table.
  137. */
  138. void freeSubscriptionList(
  139. /*! [in] Head of the subscription list. */
  140. subscription * head);
  141. /*!
  142. * \brief Traverses through the service table and returns a pointer to the
  143. * service node that matches a known service id and a known UDN.
  144. *
  145. * \return Pointer to the matching service_info node.
  146. */
  147. service_info *FindServiceId(
  148. /*! [in] Service table. */
  149. service_table *table,
  150. /*! [in] String representing the service id to be found among those
  151. * in the table. */
  152. const char *serviceId,
  153. /*! [in] String representing the UDN to be found among those in the
  154. * table. */
  155. const char *UDN);
  156. /*!
  157. * \brief Traverses the service table and finds the node whose event URL Path
  158. * matches a know value.
  159. *
  160. * \return Pointer to the service list node from the service table whose event
  161. * URL matches a known event URL.
  162. */
  163. service_info *FindServiceEventURLPath(
  164. /*! [in] Service table. */
  165. service_table *table,
  166. /*! [in] Event URL path used to find a service from the table. */
  167. char *eventURLPath);
  168. /*!
  169. * \brief Traverses the service table and finds the node whose control URL Path
  170. * matches a know value.
  171. *
  172. * \return Pointer to the service list node from the service table whose control
  173. * URL Path matches a known value.
  174. */
  175. service_info * FindServiceControlURLPath(
  176. /*! [in] Service table. */
  177. service_table *table,
  178. /*! [in] Control URL path used to find a service from the table. */
  179. const char *controlURLPath);
  180. /*!
  181. * \brief For debugging purposes prints information from the service passed
  182. * into the function.
  183. */
  184. #ifdef DEBUG
  185. void printService(
  186. /*! [in] Service whose information is to be printed. */
  187. service_info *service,
  188. /*! [in] Debug level specified to the print function. */
  189. Upnp_LogLevel level,
  190. /*! [in] Debug module specified to the print function. */
  191. Dbg_Module module);
  192. #else
  193. static UPNP_INLINE void printService(
  194. service_info *service,
  195. Upnp_LogLevel level,
  196. Dbg_Module module)
  197. {
  198. return;
  199. service = service;
  200. level = level;
  201. module = module;
  202. }
  203. #endif
  204. /*!
  205. * \brief For debugging purposes prints information of each service from the
  206. * service table passed into the function.
  207. */
  208. #ifdef DEBUG
  209. void printServiceList(
  210. /*! [in] Service whose information is to be printed. */
  211. service_info *service,
  212. /*! [in] Debug level specified to the print function. */
  213. Upnp_LogLevel level,
  214. /*! [in] Debug module specified to the print function. */
  215. Dbg_Module module);
  216. #else
  217. static UPNP_INLINE void printServiceList(
  218. service_info *service,
  219. Upnp_LogLevel level,
  220. Dbg_Module module)
  221. {
  222. return;
  223. service = service;
  224. level = level;
  225. module = module;
  226. }
  227. #endif
  228. /*!
  229. * \brief For debugging purposes prints the URL base of the table and information
  230. * of each service from the service table passed into the function.
  231. */
  232. #ifdef DEBUG
  233. void printServiceTable(
  234. /*! [in] Service table to be printed. */
  235. service_table *table,
  236. /*! [in] Debug level specified to the print function. */
  237. Upnp_LogLevel level,
  238. /*! [in] Debug module specified to the print function. */
  239. Dbg_Module module);
  240. #else
  241. static UPNP_INLINE void printServiceTable(
  242. service_table *table,
  243. Upnp_LogLevel level,
  244. Dbg_Module module)
  245. {
  246. return;
  247. table = table;
  248. level = level;
  249. module = module;
  250. }
  251. #endif
  252. /*!
  253. * \brief Free's memory allocated for the various components of the service
  254. * entry in the service table.
  255. */
  256. void freeService(
  257. /*! [in] Service information that is to be freed. */
  258. service_info *in);
  259. /*!
  260. * \brief Free's memory allocated for the various components of each service
  261. * entry in the service table.
  262. */
  263. void freeServiceList(
  264. /*! [in] Head of the service list to be freed. */
  265. service_info *head);
  266. /*!
  267. * \brief Free's dynamic memory in table (does not free table, only memory
  268. * within the structure).
  269. */
  270. void freeServiceTable(
  271. /*! [in] Service table whose internal memory needs to be freed. */
  272. service_table *table);
  273. /*!
  274. * \brief This function assumes that services for a particular root device are
  275. * placed linearly in the service table, and in the order in which they are
  276. * found in the description document all services for this root device are
  277. * removed from the list.
  278. *
  279. * \return An integer.
  280. */
  281. int removeServiceTable(
  282. /*! [in] XML node information. */
  283. IXML_Node *node,
  284. /*! [in] Service table from which services will be removed. */
  285. service_table *in);
  286. /*!
  287. * \brief Add Service to the table.
  288. */
  289. int addServiceTable(
  290. /*! [in] XML node information. */
  291. IXML_Node *node,
  292. /*! [in] Service table that will be initialized with services. */
  293. service_table *in,
  294. /*! [in] Default base URL on which the URL will be returned to the
  295. * service list. */
  296. const char *DefaultURLBase);
  297. /*!
  298. * \brief Retrieve service from the table.
  299. *
  300. * \return An integer
  301. */
  302. int getServiceTable(
  303. /*! [in] XML node information. */
  304. IXML_Node *node,
  305. /*! [in] Output parameter which will contain the service list and URL. */
  306. service_table *out,
  307. /*! [in] Default base URL on which the URL will be returned. */
  308. const char *DefaultURLBase);
  309. /* Misc helper functions */
  310. /*!
  311. * \brief Returns the clone of the element value.
  312. *
  313. * \note Value must be freed with DOMString_free.
  314. *
  315. * \return DOMString
  316. */
  317. DOMString getElementValue(
  318. /*! [in] Input node which provides the list of child nodes. */
  319. IXML_Node *node);
  320. /*!
  321. * \brief Traverses through a list of XML nodes to find the node with the
  322. * known element name.
  323. *
  324. * \return
  325. * \li 1 - On Success
  326. * \li 0 - On Failure
  327. */
  328. int getSubElement(
  329. /*! [in] Sub element name to be searched for. */
  330. const char *element_name,
  331. /*! [in] Input node which provides the list of child nodes. */
  332. IXML_Node *node,
  333. /*! [out] Ouput node to which the matched child node is returned. */
  334. IXML_Node **out);
  335. #endif /* INCLUDE_DEVICE_APIS */
  336. #ifdef __cplusplus
  337. }
  338. #endif
  339. #endif /* SERVICE_TABLE */