publish.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJSIP_SIMPLE_PUBLISH_H__
  20. #define __PJSIP_SIMPLE_PUBLISH_H__
  21. /**
  22. * @file publish.h
  23. * @brief SIP Extension for Event State Publication (PUBLISH, RFC 3903)
  24. */
  25. #include <pjsip/sip_util.h>
  26. #include <pjsip/sip_auth.h>
  27. PJ_BEGIN_DECL
  28. /**
  29. @defgroup PJSIP_SIMPLE_PUBLISH SIP Event State Publication (PUBLISH, RFC 3903)
  30. @ingroup PJSIP_SIMPLE
  31. @brief Support for SIP Event State Publication (PUBLISH, RFC 3903)
  32. @{
  33. This module contains the implementation of Session Initiation Protocol (SIP)
  34. Extension for Event State Publication (PUBLISH) as defined by RFC 3903.
  35. */
  36. /**
  37. * The SIP PUBLISH method constant.
  38. */
  39. extern const pjsip_method pjsip_publish_method;
  40. /**
  41. * @defgroup PJSIP_SIMPLE_PUBLISH_CLIENT SIP Event State Publication Client
  42. * @ingroup PJSIP_SIMPLE
  43. * @brief Event State Publication Clien
  44. * @{
  45. */
  46. /** Expiration not specified. */
  47. #define PJSIP_PUBC_EXPIRATION_NOT_SPECIFIED ((pj_uint32_t)0xFFFFFFFFUL)
  48. /**
  49. * Opaque declaration for client side event publication session.
  50. */
  51. typedef struct pjsip_publishc pjsip_publishc;
  52. /**
  53. * Client publication options. Application should initialize this structure
  54. * with its default values by calling #pjsip_publishc_opt_default()
  55. */
  56. typedef struct pjsip_publishc_opt
  57. {
  58. /**
  59. * Specify whether the client publication session should queue the
  60. * PUBLISH request should there be another PUBLISH transaction still
  61. * pending. If this is set to false, the client will return error
  62. * on the PUBLISH request if there is another PUBLISH transaction still
  63. * in progress.
  64. *
  65. * Default: PJSIP_PUBLISHC_QUEUE_REQUEST
  66. */
  67. pj_bool_t queue_request;
  68. } pjsip_publishc_opt;
  69. /** Structure to hold parameters when calling application's callback.
  70. * The application's callback is called when the client publication process
  71. * has finished.
  72. */
  73. struct pjsip_publishc_cbparam
  74. {
  75. pjsip_publishc *pubc; /**< Client publication structure. */
  76. void *token; /**< Arbitrary token. */
  77. pj_status_t status; /**< Error status. */
  78. int code; /**< SIP status code received. */
  79. pj_str_t reason; /**< SIP reason phrase received. */
  80. pjsip_rx_data *rdata; /**< The complete received response. */
  81. unsigned expiration;/**< Next expiration interval. If the
  82. value is
  83. PJSIP_PUBC_EXPIRATION_NOT_SPECIFIED,
  84. it means the session will not renew
  85. itself. */
  86. };
  87. /** Type declaration for callback to receive publication result. */
  88. typedef void pjsip_publishc_cb(struct pjsip_publishc_cbparam *param);
  89. /**
  90. * Initialize client publication session option with default values.
  91. *
  92. * @param opt The option.
  93. */
  94. PJ_DECL(void) pjsip_publishc_opt_default(pjsip_publishc_opt *opt);
  95. /**
  96. * Initialize client publication module.
  97. *
  98. * @param endpt SIP endpoint.
  99. *
  100. * @return PJ_SUCCESS on success.
  101. */
  102. PJ_DECL(pj_status_t) pjsip_publishc_init_module(pjsip_endpoint *endpt);
  103. /**
  104. * Create client publication structure.
  105. *
  106. * @param endpt Endpoint, used to allocate pool from.
  107. * @param opt Options, or NULL to specify default options.
  108. * @param token Opaque data to be associated with the client publication.
  109. * @param cb Pointer to callback function to receive publication status.
  110. * @param p_pubc Pointer to receive client publication structure.
  111. *
  112. * @return PJ_SUCCESS on success.
  113. */
  114. PJ_DECL(pj_status_t) pjsip_publishc_create( pjsip_endpoint *endpt,
  115. const pjsip_publishc_opt *opt,
  116. void *token,
  117. pjsip_publishc_cb *cb,
  118. pjsip_publishc **p_pubc);
  119. /**
  120. * Destroy client publication structure. If a publication transaction is
  121. * in progress, then the structure will be deleted only after a final response
  122. * has been received, and in this case, the callback won't be called.
  123. *
  124. * @param pubc The client publication structure.
  125. *
  126. * @return PJ_SUCCESS on success.
  127. */
  128. PJ_DECL(pj_status_t) pjsip_publishc_destroy(pjsip_publishc *pubc);
  129. /**
  130. * Get the memory pool associated with a publication client session.
  131. *
  132. * @param pubc The client publication structure.
  133. * @return pool handle.
  134. */
  135. PJ_DECL(pj_pool_t*) pjsip_publishc_get_pool(pjsip_publishc *pubc);
  136. /**
  137. * Initialize client publication structure with various information needed to
  138. * perform the publication.
  139. *
  140. * @param pubc The client publication structure.
  141. * @param event The Event identification (e.g. "presence").
  142. * @param target_uri The URI of the presentity which the which the status
  143. * is being published.
  144. * @param from_uri The URI of the endpoint who sends the event
  145. * publication. Normally the value would be the same as
  146. * target_uri.
  147. * @param to_uri The URI to be put in To header. Normally the value
  148. * would be the same as target_uri.
  149. * @param expires The default expiration of the event publication.
  150. * If the value PJSIP_PUBC_EXPIRATION_NOT_SPECIFIED is
  151. * given, then no default expiration will be applied.
  152. *
  153. * @return PJ_SUCCESS on success.
  154. */
  155. PJ_DECL(pj_status_t) pjsip_publishc_init(pjsip_publishc *pubc,
  156. const pj_str_t *event,
  157. const pj_str_t *target_uri,
  158. const pj_str_t *from_uri,
  159. const pj_str_t *to_uri,
  160. pj_uint32_t expires);
  161. /**
  162. * Set authentication credentials to use by this publication.
  163. *
  164. * @param pubc The publication structure.
  165. * @param count Number of credentials in the array.
  166. * @param c Array of credentials.
  167. *
  168. * @return PJ_SUCCESS on success.
  169. */
  170. PJ_DECL(pj_status_t) pjsip_publishc_set_credentials(pjsip_publishc *pubc,
  171. int count,
  172. const pjsip_cred_info c[]);
  173. /**
  174. * Set route set to be used for outgoing requests.
  175. *
  176. * @param pubc The client publication structure.
  177. * @param rs List containing Route headers.
  178. *
  179. * @return PJ_SUCCESS on success.
  180. */
  181. PJ_DECL(pj_status_t) pjsip_publishc_set_route_set(pjsip_publishc *pubc,
  182. const pjsip_route_hdr *rs);
  183. /**
  184. * Set list of headers to be added to each PUBLISH request generated by
  185. * the client publication session. Note that application can also add
  186. * the headers to the request after calling #pjsip_publishc_publish()
  187. * or #pjsip_publishc_unpublish(), but the benefit of this function is
  188. * the headers will also be added to requests generated internally by
  189. * the session, such as during session renewal/refresh.
  190. *
  191. * Note that calling this function will clear the previously added list
  192. * of headers.
  193. *
  194. * @param pubc The client publication structure.
  195. * @param hdr_list The list of headers.
  196. *
  197. * @return PJ_SUCCESS on success.
  198. */
  199. PJ_DECL(pj_status_t) pjsip_publishc_set_headers(pjsip_publishc *pubc,
  200. const pjsip_hdr *hdr_list);
  201. /**
  202. * Set the "sent-by" field of the Via header for outgoing requests.
  203. *
  204. * @param pubc The client publication structure.
  205. * @param via_addr Set via_addr to use for the Via header or NULL to use
  206. * the transport's published name.
  207. * @param via_tp via_addr will only be used if we are using via_tp
  208. * transport.
  209. *
  210. * @return PJ_SUCCESS on success.
  211. */
  212. PJ_DECL(pj_status_t) pjsip_publishc_set_via_sent_by(pjsip_publishc *pubc,
  213. pjsip_host_port *via_addr,
  214. pjsip_transport *via_tp);
  215. /**
  216. * Create PUBLISH request for the specified client publication structure.
  217. * Application can use this function to both create initial publication
  218. * or to modify existing publication.
  219. *
  220. * After the PUBLISH request is created, application MUST fill in the
  221. * body part of the request with the appropriate content for the Event
  222. * being published.
  223. *
  224. * Note that publication refresh are handled automatically by the session
  225. * (as long as auto_refresh argument below is non-zero), and application
  226. * should not use this function to perform publication refresh.
  227. *
  228. * @param pubc The client publication session.
  229. * @param auto_refresh If non zero, the library will automatically
  230. * refresh the next publication until application
  231. * unpublish.
  232. * @param p_tdata Pointer to receive the PUBLISH request. Note that
  233. * the request DOES NOT have a message body.
  234. *
  235. * @return PJ_SUCCESS on success.
  236. */
  237. PJ_DECL(pj_status_t) pjsip_publishc_publish(pjsip_publishc *pubc,
  238. pj_bool_t auto_refresh,
  239. pjsip_tx_data **p_tdata);
  240. /**
  241. * Create PUBLISH request to unpublish the current client publication.
  242. *
  243. * @param pubc The client publication structure.
  244. * @param p_tdata Pointer to receive the PUBLISH request.
  245. *
  246. * @return PJ_SUCCESS on success.
  247. */
  248. PJ_DECL(pj_status_t) pjsip_publishc_unpublish(pjsip_publishc *pubc,
  249. pjsip_tx_data **p_tdata);
  250. /**
  251. * Update the client publication expiration value. Note that this DOES NOT
  252. * automatically send outgoing PUBLISH request to update the publication
  253. * session. If application wants to do this, then it must construct a
  254. * PUBLISH request and send it to the server.
  255. *
  256. * @param pubc The client publication structure.
  257. * @param expires The new expires value.
  258. *
  259. * @return PU_SUCCESS on successfull.
  260. */
  261. PJ_DECL(pj_status_t) pjsip_publishc_update_expires(pjsip_publishc *pubc,
  262. pj_uint32_t expires );
  263. /**
  264. * Sends outgoing PUBLISH request. The process will complete asynchronously,
  265. * and application will be notified via the callback when the process
  266. * completes.
  267. *
  268. * If the session has another PUBLISH request outstanding, the behavior
  269. * depends on whether request queueing is enabled in the session (this was
  270. * set by setting \a queue_request field of #pjsip_publishc_opt to true
  271. * when calling #pjsip_publishc_create(). Default is true). If request
  272. * queueing is enabled, the request will be queued and the function will
  273. * return PJ_EPENDING. One the outstanding request is complete, the queued
  274. * request will be sent automatically. If request queueing is disabled, the
  275. * function will reject the request and return PJ_EBUSY.
  276. *
  277. * @param pubc The client publication structure.
  278. * @param tdata Transmit data.
  279. *
  280. * @return - PJ_SUCCESS on success, or
  281. * - PJ_EPENDING if request is queued, or
  282. * - PJ_EBUSY if request is rejected because another PUBLISH
  283. * request is in progress, or
  284. * - other status code to indicate the error.
  285. */
  286. PJ_DECL(pj_status_t) pjsip_publishc_send(pjsip_publishc *pubc,
  287. pjsip_tx_data *tdata);
  288. /**
  289. * @}
  290. */
  291. /**
  292. * @}
  293. */
  294. PJ_END_DECL
  295. #endif /* __PJSIP_SIMPLE_PUBLISH_H__ */