txcap.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou [at) doubango (DOT) org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. /**@file txcap.h
  23. * @brief RFC 4825 (XCAP) implementation.
  24. *
  25. * @author Mamadou Diop <diopmamadou [at) doubango (DOT) org>
  26. *
  27. */
  28. #ifndef TINYXCAP_TXCAP_H
  29. #define TINYXCAP_TXCAP_H
  30. #include "tinyxcap_config.h"
  31. #include "tinyxcap/txcap_auid.h"
  32. #include "tsk_options.h"
  33. #include "tinyhttp.h"
  34. TXCAP_BEGIN_DECLS
  35. typedef enum txcap_stack_option_e {
  36. //! request timeout
  37. TXCAP_STACK_OPTION_TIMEOUT,
  38. //! time to live
  39. TXCAP_STACK_OPTION_TTL,
  40. //! xcap-root
  41. TXCAP_STACK_OPTION_ROOT,
  42. //! user's password
  43. TXCAP_STACK_OPTION_PASSWORD,
  44. //! xcap user indentifier (e.g. sip:bob@example.com)
  45. TXCAP_STACK_OPTION_XUI,
  46. //! local ip address
  47. TXCAP_STACK_OPTION_LOCAL_IP,
  48. //! local port
  49. TXCAP_STACK_OPTION_LOCAL_PORT,
  50. }
  51. txcap_stack_option_t;
  52. typedef enum txcap_stack_param_type_e {
  53. xcapp_null = 0,
  54. xcapp_option,
  55. xcapp_header,
  56. xcapp_userdata,
  57. xcapp_auid,
  58. }
  59. txcap_stack_param_type_t;
  60. /* For systems that support SIP applications, it is
  61. RECOMMENDED that the XUI be equal to the Address-of-Record (AOR) for
  62. the user (i.e., sip:joe@example.com) */
  63. /**@ingroup txcap_stack_group
  64. * @def TXCAP_STACK_SET_OPTION
  65. * Adds or updates an option.
  66. * This is a helper macro for @ref txcap_stack_create() and @ref txcap_stack_set().
  67. * @param ID_ENUM The id of the option to add/update (@ref txcap_stack_option_t).
  68. * @param VALUE_STR The new value of the option (<i>const char*</i>).
  69. *
  70. * @code
  71. int ret = txcap_stack_set(stack,
  72. // stack-level options
  73. TXCAP_STACK_SET_OPTION(TXCAP_STACK_OPTION_TIMEOUT, "6000"),
  74. TXCAP_STACK_SET_NULL());
  75. * @endcode
  76. */
  77. /**@ingroup txcap_stack_group
  78. * @def TXCAP_STACK_SET_PASSWORD
  79. * Sets or updates the user's password.
  80. * @param PASSWORD_STR The new password (<i>const char*</i>).
  81. *
  82. * @code
  83. int ret = txcap_stack_set(stack,
  84. TXCAP_STACK_SET_PASSWORD("mysecret"),
  85. TXCAP_STACK_SET_NULL());
  86. * @endcode
  87. *
  88. * @sa @ref TXCAP_STACK_OPTION_PASSWORD
  89. */
  90. /**@ingroup txcap_stack_group
  91. * @def TXCAP_STACK_SET_ROOT
  92. * Sets or updates the xcap-root Url.
  93. * @param XCAP_ROOT_STR A valid Http Url(<i>const char*</i>).
  94. *
  95. * @code
  96. int ret = txcap_stack_set(stack,
  97. TXCAP_STACK_SET_ROOT("http://192.168.0.10:8080/services"),
  98. TXCAP_STACK_SET_NULL());
  99. * @endcode
  100. *
  101. * @sa @ref TXCAP_STACK_OPTION_ROOT
  102. */
  103. /**@ingroup txcap_stack_group
  104. * @def TXCAP_STACK_SET_XUI
  105. * Sets or updates the user's identifier.
  106. * @param XUI_STR The new identifier (<i>const char*</i>).For systems that support SIP applications, it is
  107. * RECOMMENDED that the XUI be equal to the Address-of-Record (AOR) for the user (i.e., sip:bob@example.com).
  108. *
  109. * @code
  110. int ret = txcap_stack_set(stack,
  111. TXCAP_STACK_SET_XUI("sip:bob@example.com"),
  112. TXCAP_STACK_SET_NULL());
  113. * @endcode
  114. *
  115. * @sa @ref TXCAP_STACK_OPTION_PASSWORD
  116. */
  117. /**@ingroup txcap_stack_group
  118. * @def TXCAP_STACK_SET_LOCAL_IP
  119. */
  120. /**@ingroup txcap_stack_group
  121. * @def TXCAP_STACK_SET_LOCAL_PORT
  122. */
  123. /**@ingroup txcap_stack_group
  124. * @def TXCAP_STACK_SET_HEADER
  125. * Adds new stack-level HTTP header. This header will be added to all outgoing requests.
  126. * If you want that the header only appear in the current outgoing request, then you should use
  127. * @ref TXCAP_ACTION_SET_HEADER().
  128. * @param NAME_STR The name of the header.
  129. * @param VALUE_STR The value of the header. Will be added "as is".
  130. *
  131. * @code
  132. int ret = txcap_stack_set(stack,
  133. TXCAP_STACK_SET_HEADER("User-Agent", "XDM-client/OMA1.1"),
  134. TXCAP_STACK_SET_NULL());
  135. * @endcode
  136. *
  137. * @sa @ref TXCAP_ACTION_SET_HEADER(), @ref TXCAP_STACK_UNSET_HEADER()
  138. */
  139. /**@ingroup txcap_stack_group
  140. * @def TXCAP_STACK_UNSET_HEADER
  141. * Removes a stack-level HTTP header.
  142. * @param NAME_STR The name of the header.
  143. *
  144. * @code
  145. int ret = txcap_stack_set(stack,
  146. TXCAP_STACK_UNSET_HEADER("User-Agent"),
  147. TXCAP_STACK_SET_NULL());
  148. * @endcode
  149. *
  150. * @sa @ref TXCAP_ACTION_UNSET_HEADER(), @ref TXCAP_ACTION_SET_HEADER()
  151. */
  152. /**@ingroup txcap_stack_group
  153. * @def TXCAP_STACK_SET_CONTEXT
  154. * Sets or updates the user's context. The context will be returned to the application layer
  155. * throught the callback function.
  156. * @param CTX_PTR A pointer to the context (<i>const void*</i>).
  157. *
  158. * @code
  159. const struct application_s context;
  160. int ret = txcap_stack_set(stack,
  161. TXCAP_STACK_SET_CONTEXT(&context),
  162. TXCAP_STACK_SET_NULL());
  163. * @endcode
  164. */
  165. /**@ingroup txcap_stack_group
  166. * @def TXCAP_STACK_SET_AUID
  167. * Register or update an AUID.
  168. * @param ID_STR The identifier associated to this aplication usage (e.g. "xcap-caps").
  169. * @param MIME_TYPE_STR The mime-type (e.g. "application/xcap-caps+xml").
  170. * @param NS_STR The namespace (e.g. "urn:ietf:params:xml:ns:xcap-caps").
  171. * @param DOC_NAME_STR The document name (e.g. "index").
  172. * @param IS_GLOBAL_BOOL The scope (@a tsk_true or @a tsk_false).
  173. *
  174. * @code
  175. // the code below shows how to register two new AUIDs
  176. int ret = txcap_stack_set(stack,
  177. TXCAP_STACK_SET_AUID("my-xcap-caps", "application/my-xcap-caps+xml", "urn:ietf:params:xml:ns:my-xcap-caps", "my-document", tsk_true),
  178. TXCAP_STACK_SET_AUID("my-resource-lists", "application/my-resource-lists+xml", "urn:ietf:params:xml:ns:my-resource-lists", "my-document", tsk_false),
  179. TXCAP_STACK_SET_NULL());
  180. * @endcode
  181. */
  182. /**@ingroup txcap_stack_group
  183. * @def TXCAP_STACK_SET_NULL
  184. * Ends the stack parameters. Mandatory and should be the last one.
  185. */
  186. #define TXCAP_STACK_SET_OPTION(ID_ENUM, VALUE_STR) xcapp_option, (txcap_stack_option_t)ID_ENUM, (const char*)VALUE_STR
  187. #define TXCAP_STACK_SET_TIMEOUT(TIMEOUT_STR) TXCAP_STACK_SET_OPTION(TXCAP_STACK_OPTION_TIMEOUT, TIMEOUT_STR)
  188. #define TXCAP_STACK_SET_ROOT(XCAP_ROOT_STR) TXCAP_STACK_SET_OPTION(TXCAP_STACK_OPTION_ROOT, XCAP_ROOT_STR)
  189. #define TXCAP_STACK_SET_PASSWORD(PASSWORD_STR) TXCAP_STACK_SET_OPTION(TXCAP_STACK_OPTION_PASSWORD, PASSWORD_STR)
  190. #define TXCAP_STACK_SET_XUI(XUI_STR) TXCAP_STACK_SET_OPTION(TXCAP_STACK_OPTION_XUI, XUI_STR)
  191. #define TXCAP_STACK_SET_LOCAL_IP(IP_STR) TXCAP_STACK_SET_OPTION(TXCAP_STACK_OPTION_LOCAL_IP, IP_STR)
  192. #define TXCAP_STACK_SET_LOCAL_PORT(PORT_STR) TXCAP_STACK_SET_OPTION(TXCAP_STACK_OPTION_LOCAL_PORT, PORT_STR)
  193. #define TXCAP_STACK_SET_HEADER(NAME_STR, VALUE_STR) xcapp_header, (const char*)NAME_STR, (const char*)VALUE_STR
  194. #define TXCAP_STACK_UNSET_HEADER(NAME_STR) TXCAP_STACK_SET_HEADER(NAME_STR, (const char*)-1)
  195. #define TXCAP_STACK_SET_USERDATA(CTX_PTR) xcapp_userdata, (const void*)CTX_PTR
  196. #define TXCAP_STACK_SET_AUID(ID_STR, MIME_TYPE_STR, NS_STR, DOC_NAME_STR, IS_GLOBAL_BOOL) xcapp_auid, (const char*)ID_STR, (const char*)MIME_TYPE_STR, (const char*)NS_STR, (const char*)DOC_NAME_STR, (tsk_bool_t)IS_GLOBAL_BOOL
  197. #define TXCAP_STACK_SET_NULL() xcapp_null
  198. typedef struct txcap_stack_s {
  199. TSK_DECLARE_OBJECT;
  200. char* xui; /**< user's name as per RFC 4825 subclause 4.Also used to fill @b "X-3GPP-Intended-Identity" header.*/
  201. char* password; /**< user's password used to authenticate to the XDMS . */
  202. char* xcap_root; /**< xcap-root URI as per RFC 4825 subclause 6.1. MUST be a valid HTPP/HTTPS URL and will be used to build all request-uris. */
  203. thttp_session_handle_t* http_session;
  204. thttp_stack_handle_t* http_stack; /**< http/https stack */
  205. tsk_options_L_t *options; /**< list of user options */
  206. const void* context; /**< user's context */
  207. txcap_auids_L_t* auids; /**< user's auids */
  208. TSK_DECLARE_SAFEOBJ;
  209. }
  210. txcap_stack_t;
  211. typedef void txcap_stack_handle_t;/**< Pointer to a XCAP stack. Should be created using @ref txcap_stack_create().*/
  212. TINYXCAP_API txcap_stack_handle_t* txcap_stack_create(thttp_stack_callback_f callback, const char* xui, const char* password, const char* xcap_root, ...);
  213. TINYXCAP_API int txcap_stack_start(txcap_stack_handle_t* self);
  214. TINYXCAP_API int txcap_stack_set(txcap_stack_handle_t* self, ...);
  215. TINYXCAP_API int txcap_stack_stop(txcap_stack_handle_t* self);
  216. TINYXCAP_GEXTERN const tsk_object_def_t *txcap_stack_def_t;
  217. TXCAP_END_DECLS
  218. #endif // TINYXCAP_CONFIG_H