upnpapi.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*******************************************************************************
  2. *
  3. * Copyright (c) 2000-2003 Intel Corporation
  4. * All rights reserved.
  5. * Copyright (C) 2011-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 UPNPAPI_H
  33. #define UPNPAPI_H
  34. /*!
  35. * \file
  36. */
  37. #include "client_table.h"
  38. #include "upnp.h"
  39. #include "VirtualDir.h" /* for struct VirtualDirCallbacks */
  40. #define MAX_INTERFACES 256
  41. #define DEFAULT_INTERFACE 1
  42. #define DEV_LIMIT 200
  43. #define DEFAULT_MX 5
  44. #define DEFAULT_MAXAGE 1800
  45. #define DEFAULT_SOAP_CONTENT_LENGTH 16000
  46. #define MAX_SOAP_CONTENT_LENGTH (size_t)32000
  47. extern size_t g_maxContentLength;
  48. extern int g_UpnpSdkEQMaxLen;
  49. extern int g_UpnpSdkEQMaxAge;
  50. /* 30-second timeout */
  51. #define UPNP_TIMEOUT 30
  52. typedef enum {HND_INVALID=-1,HND_CLIENT,HND_DEVICE} Upnp_Handle_Type;
  53. /* Data to be stored in handle table for */
  54. struct Handle_Info
  55. {
  56. /*! . */
  57. Upnp_Handle_Type HType;
  58. /*! Callback function pointer. */
  59. Upnp_FunPtr Callback;
  60. /*! . */
  61. char *Cookie;
  62. /*! 0 = not installed; otherwise installed. */
  63. int aliasInstalled;
  64. /* Device Only */
  65. #ifdef INCLUDE_DEVICE_APIS
  66. /*! URL for the use of SSDP. */
  67. char DescURL[LINE_SIZE];
  68. /*! URL for the use of SSDP when answering to legacy CPs (CP searching
  69. * for a v1 when the device is v2). */
  70. char LowerDescURL[LINE_SIZE];
  71. /*! XML file path for device description. */
  72. char DescXML[LINE_SIZE];
  73. /* Advertisement timeout */
  74. int MaxAge;
  75. /* Power State as defined by UPnP Low Power. */
  76. int PowerState;
  77. /* Sleep Period as defined by UPnP Low Power. */
  78. int SleepPeriod;
  79. /* Registration State as defined by UPnP Low Power. */
  80. int RegistrationState;
  81. /*! Description parsed in terms of DOM document. */
  82. IXML_Document *DescDocument;
  83. /*! List of devices in the description document. */
  84. IXML_NodeList *DeviceList;
  85. /*! List of services in the description document. */
  86. IXML_NodeList *ServiceList;
  87. /*! Table holding subscriptions and URL information. */
  88. service_table ServiceTable;
  89. /*! . */
  90. int MaxSubscriptions;
  91. /*! . */
  92. int MaxSubscriptionTimeOut;
  93. /*! Address family: AF_INET or AF_INET6. */
  94. int DeviceAf;
  95. #endif
  96. /* Client only */
  97. #ifdef INCLUDE_CLIENT_APIS
  98. /*! Client subscription list. */
  99. ClientSubscription *ClientSubList;
  100. /*! Active SSDP searches. */
  101. LinkedList SsdpSearchList;
  102. #endif
  103. };
  104. extern ithread_rwlock_t GlobalHndRWLock;
  105. /*!
  106. * \brief Get handle information.
  107. *
  108. * \return HND_DEVICE, UPNP_E_INVALID_HANDLE
  109. */
  110. Upnp_Handle_Type GetHandleInfo(
  111. /*! handle pointer (key for the client handle structure). */
  112. int Hnd,
  113. /*! handle structure passed by this function. */
  114. struct Handle_Info **HndInfo);
  115. #define HandleLock() HandleWriteLock()
  116. #define HandleWriteLock() \
  117. UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying a write lock"); \
  118. ithread_rwlock_wrlock(&GlobalHndRWLock); \
  119. UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Write lock acquired");
  120. #define HandleReadLock() \
  121. UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Trying a read lock"); \
  122. ithread_rwlock_rdlock(&GlobalHndRWLock); \
  123. UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Read lock acquired");
  124. #define HandleUnlock() \
  125. UpnpPrintf(UPNP_INFO, API,__FILE__, __LINE__, "Trying Unlock"); \
  126. ithread_rwlock_unlock(&GlobalHndRWLock); \
  127. UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Unlocked rwlock");
  128. /*!
  129. * \brief Get client handle info.
  130. *
  131. * \note The logic around the use of this function should be revised.
  132. *
  133. * \return HND_CLIENT, HND_INVALID
  134. */
  135. Upnp_Handle_Type GetClientHandleInfo(
  136. /*! [in] client handle pointer (key for the client handle structure). */
  137. int *client_handle_out,
  138. /*! [out] Client handle structure passed by this function. */
  139. struct Handle_Info **HndInfo);
  140. /*!
  141. * \brief Retrieves the device handle and information of the first device of
  142. * the address family spcified.
  143. *
  144. * \return HND_DEVICE or HND_INVALID
  145. */
  146. Upnp_Handle_Type GetDeviceHandleInfo(
  147. /*! [in] Address family. */
  148. int AddressFamily,
  149. /*! [out] Device handle pointer. */
  150. int *device_handle_out,
  151. /*! [out] Device handle structure passed by this function. */
  152. struct Handle_Info **HndInfo);
  153. extern char gIF_NAME[LINE_SIZE];
  154. extern char gIF_IPV4[INET_ADDRSTRLEN];
  155. extern char gIF_IPV6[INET6_ADDRSTRLEN];
  156. extern char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN];
  157. extern unsigned gIF_INDEX;
  158. extern unsigned short LOCAL_PORT_V4;
  159. extern unsigned short LOCAL_PORT_V6;
  160. /*! NLS uuid. */
  161. extern Upnp_SID gUpnpSdkNLSuuid;
  162. extern TimerThread gTimerThread;
  163. extern ThreadPool gRecvThreadPool;
  164. extern ThreadPool gSendThreadPool;
  165. extern ThreadPool gMiniServerThreadPool;
  166. typedef enum {
  167. SUBSCRIBE,
  168. UNSUBSCRIBE,
  169. DK_NOTIFY,
  170. QUERY,
  171. ACTION,
  172. STATUS,
  173. DEVDESCRIPTION,
  174. SERVDESCRIPTION,
  175. MINI,
  176. RENEW
  177. } UpnpFunName;
  178. struct UpnpNonblockParam
  179. {
  180. UpnpFunName FunName;
  181. int Handle;
  182. int TimeOut;
  183. char VarName[NAME_SIZE];
  184. char NewVal[NAME_SIZE];
  185. char DevType[NAME_SIZE];
  186. char DevId[NAME_SIZE];
  187. char ServiceType[NAME_SIZE];
  188. char ServiceVer[NAME_SIZE];
  189. char Url[NAME_SIZE];
  190. Upnp_SID SubsId;
  191. char *Cookie;
  192. Upnp_FunPtr Fun;
  193. IXML_Document *Header;
  194. IXML_Document *Act;
  195. struct DevDesc *Devdesc;
  196. };
  197. extern virtualDirList *pVirtualDirList;
  198. extern struct VirtualDirCallbacks virtualDirCallback;
  199. typedef enum {
  200. WEB_SERVER_DISABLED,
  201. WEB_SERVER_ENABLED
  202. } WebServerState;
  203. #define E_HTTP_SYNTAX -6
  204. /*!
  205. * \brief Retrieve interface information and keep it in global variables.
  206. * If NULL, we'll find the first suitable interface for operation.
  207. *
  208. * The interface must fulfill these requirements:
  209. * \li Be UP.
  210. * \li Not be LOOPBACK.
  211. * \li Support MULTICAST.
  212. * \li Have a valid IPv4 or IPv6 address.
  213. *
  214. * We'll retrieve the following information from the interface:
  215. * \li gIF_NAME -> Interface name (by input or found).
  216. * \li gIF_IPV4 -> IPv4 address (if any).
  217. * \li gIF_IPV6 -> IPv6 address (if any).
  218. * \li gIF_IPV6_ULA_GUA -> ULA or GUA IPv6 address (if any)
  219. * \li gIF_INDEX -> Interface index number.
  220. *
  221. * \return UPNP_E_SUCCESS on success.
  222. */
  223. int UpnpGetIfInfo(
  224. /*! [in] Interface name (can be NULL). */
  225. const char *IfName);
  226. void UpnpThreadDistribution(struct UpnpNonblockParam * Param);
  227. /*!
  228. * \brief This function is a timer thread scheduled by UpnpSendAdvertisement
  229. * to the send advetisement again.
  230. */
  231. void AutoAdvertise(
  232. /*! [in] Information provided to the thread. */
  233. void *input);
  234. /*!
  235. * \brief Get local IP address.
  236. *
  237. * Gets the ip address for the DEFAULT_INTERFACE interface which is up and not
  238. * a loopback. Assumes at most MAX_INTERFACES interfaces
  239. *
  240. * \return UPNP_E_SUCCESS if successful or UPNP_E_INIT.
  241. */
  242. int getlocalhostname(
  243. /*! [out] IP address of the interface. */
  244. char *out,
  245. /*! [in] Length of the output buffer. */
  246. size_t out_len);
  247. /*!
  248. * \brief Print handle info.
  249. *
  250. * \return UPNP_E_SUCCESS if successful, otherwise returns appropriate error.
  251. */
  252. int PrintHandleInfo(
  253. /*! [in] Handle index. */
  254. UpnpClient_Handle Hnd);
  255. extern WebServerState bWebServerState;
  256. #endif /* UPNPAPI_H */