res_pjsip_outbound_publish.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2014, Digium, Inc.
  5. *
  6. * Joshua Colp <jcolp@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. #ifndef _RES_PJSIP_OUTBOUND_PUBLISH_H
  19. #define _RES_PJSIP_OUTBOUND_PUBLISH_H
  20. #include "asterisk/linkedlists.h"
  21. /* Forward declarations */
  22. struct ast_datastore;
  23. struct ast_datastore_info;
  24. /*!
  25. * \brief Opaque structure representing outbound publish configuration
  26. */
  27. struct ast_sip_outbound_publish;
  28. /*!
  29. * \brief Opaque structure representing an outbound publish client
  30. */
  31. struct ast_sip_outbound_publish_client;
  32. /*!
  33. * \brief Callbacks that event publisher handlers will define
  34. */
  35. struct ast_sip_event_publisher_handler {
  36. /*! \brief The name of the event this handler deals with */
  37. const char *event_name;
  38. /*!
  39. * \brief Called when a publisher should start publishing.
  40. *
  41. * \param configuration The outbound publish configuration, event-specific configuration
  42. * is accessible using extended sorcery fields
  43. * \param client The publish client that can be used to send PUBLISH messages.
  44. * \retval 0 success
  45. * \retval -1 failure
  46. */
  47. int (*start_publishing)(struct ast_sip_outbound_publish *configuration,
  48. struct ast_sip_outbound_publish_client *client);
  49. /*!
  50. * \brief Called when a publisher should stop publishing.
  51. *
  52. * \param client The publish client that was used to send PUBLISH messages.
  53. * \retval 0 success
  54. * \retval -1 failure
  55. */
  56. int (*stop_publishing)(struct ast_sip_outbound_publish_client *client);
  57. AST_LIST_ENTRY(ast_sip_event_publisher_handler) next;
  58. };
  59. /*!
  60. * \brief Register an event publisher handler
  61. *
  62. * \retval 0 Handler was registered successfully
  63. * \retval non-zero Handler was not registered successfully
  64. */
  65. int ast_sip_register_event_publisher_handler(struct ast_sip_event_publisher_handler *handler);
  66. /*!
  67. * \brief Unregister a publish handler
  68. */
  69. void ast_sip_unregister_event_publisher_handler(struct ast_sip_event_publisher_handler *handler);
  70. /*!
  71. * \brief Find a publish client using its name
  72. *
  73. * \param name The name of the publish client
  74. *
  75. * \retval NULL failure
  76. * \retval non-NULL success
  77. *
  78. * \note The publish client is returned with its reference count increased and must be released using
  79. * ao2_cleanup.
  80. */
  81. struct ast_sip_outbound_publish_client *ast_sip_publish_client_get(const char *name);
  82. /*!
  83. * \brief Alternative for ast_datastore_alloc()
  84. *
  85. * There are two major differences between this and ast_datastore_alloc()
  86. * 1) This allocates a refcounted object
  87. * 2) This will fill in a uid if one is not provided
  88. *
  89. * DO NOT call ast_datastore_free() on a datastore allocated in this
  90. * way since that function will attempt to free the datastore rather
  91. * than play nicely with its refcount.
  92. *
  93. * \param info Callbacks for datastore
  94. * \param uid Identifier for datastore
  95. * \retval NULL Failed to allocate datastore
  96. * \retval non-NULL Newly allocated datastore
  97. */
  98. struct ast_datastore *ast_sip_publish_client_alloc_datastore(const struct ast_datastore_info *info, const char *uid);
  99. /*!
  100. * \brief Add a datastore to a SIP event publisher
  101. *
  102. * Note that SIP uses reference counted datastores. The datastore passed into this function
  103. * must have been allocated using ao2_alloc() or there will be serious problems.
  104. *
  105. * \param client The publication client to add the datastore to
  106. * \param datastore The datastore to be added to the subscription
  107. * \retval 0 Success
  108. * \retval -1 Failure
  109. */
  110. int ast_sip_publish_client_add_datastore(struct ast_sip_outbound_publish_client *client,
  111. struct ast_datastore *datastore);
  112. /*!
  113. * \brief Retrieve an event publisher datastore
  114. *
  115. * The datastore retrieved will have its reference count incremented. When the caller is done
  116. * with the datastore, the reference counted needs to be decremented using ao2_ref().
  117. *
  118. * \param client The publication client from which to retrieve the datastore
  119. * \param name The name of the datastore to retrieve
  120. * \retval NULL Failed to find the specified datastore
  121. * \retval non-NULL The specified datastore
  122. */
  123. struct ast_datastore *ast_sip_publish_client_get_datastore(struct ast_sip_outbound_publish_client *client,
  124. const char *name);
  125. /*!
  126. * \brief Remove a publication datastore from an event publisher
  127. *
  128. * This operation may cause the datastore's free() callback to be called if the reference
  129. * count reaches zero.
  130. *
  131. * \param client The publication client to remove the datastore from
  132. * \param name The name of the datastore to remove
  133. */
  134. void ast_sip_publish_client_remove_datastore(struct ast_sip_outbound_publish_client *client,
  135. const char *name);
  136. /*!
  137. * \brief Send an outgoing PUBLISH message using a client
  138. *
  139. * \param client The publication client to send from
  140. * \param body An optional body to add to the PUBLISH
  141. *
  142. * \retval -1 failure
  143. * \retval 0 success
  144. */
  145. int ast_sip_publish_client_send(struct ast_sip_outbound_publish_client *client,
  146. const struct ast_sip_body *body);
  147. #endif /* RES_PJSIP_OUTBOUND_PUBLISH_H */