bridge_roles.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * Jonathan Rose <jrose@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. /*! \file
  19. * \brief Channel Bridging Roles API
  20. * \author Jonathan Rose <jrose@digium.com>
  21. */
  22. #ifndef _ASTERISK_BRIDGING_ROLES_H
  23. #define _ASTERISK_BRIDGING_ROLES_H
  24. #if defined(__cplusplus) || defined(c_plusplus)
  25. extern "C" {
  26. #endif
  27. #include "asterisk/linkedlists.h"
  28. #define AST_ROLE_LEN 32
  29. /*!
  30. * \brief Adds a bridge role to a channel
  31. *
  32. * \param chan Acquirer of the requested role
  33. * \param role_name Name of the role being attached
  34. *
  35. * \retval 0 on success
  36. * \retval -1 on failure
  37. */
  38. int ast_channel_add_bridge_role(struct ast_channel *chan, const char *role_name);
  39. /*!
  40. * \brief Removes a bridge role from a channel
  41. *
  42. * \param chan Channel the role is being removed from
  43. * \param role_name Name of the role being removed
  44. */
  45. void ast_channel_remove_bridge_role(struct ast_channel *chan, const char *role_name);
  46. /*!
  47. * \brief Removes all bridge roles currently on a channel
  48. *
  49. * \param chan Channel the roles are being removed from
  50. */
  51. void ast_channel_clear_bridge_roles(struct ast_channel *chan);
  52. /*!
  53. * \brief Set a role option on a channel
  54. * \param channel Channel receiving the role option
  55. * \param role_name Role the role option is applied to
  56. * \param option Name of the option
  57. * \param value Value of the option
  58. *
  59. * \param 0 on success
  60. * \retval -1 on failure
  61. */
  62. int ast_channel_set_bridge_role_option(struct ast_channel *channel, const char *role_name, const char *option, const char *value);
  63. /*!
  64. * \brief Check if a role exists on a channel
  65. *
  66. * \param channel The channel to check
  67. * \param role_name The name of the role to search for
  68. *
  69. * \retval 0 The requested role does not exist on the channel
  70. * \retval 1 The requested role exists on the channel
  71. *
  72. * This is an alternative to \ref ast_bridge_channel_has_role that is useful if bridge
  73. * roles have not yet been established on a channel's bridge_channel. A possible example of
  74. * when this could be used is in a bridge v_table's push() callback.
  75. */
  76. int ast_channel_has_role(struct ast_channel *channel, const char *role_name);
  77. /*!
  78. * \brief Retrieve the value of a requested role option from a channel
  79. *
  80. * \param channel The channel to retrieve the requested option from
  81. * \param role_name The role to which the option belongs
  82. * \param option The name of the option to retrieve
  83. *
  84. * \retval NULL The option does not exist
  85. * \retval non-NULL The value of the option
  86. *
  87. * This is an alternative to \ref ast_bridge_channel_get_role_option that is useful if bridge
  88. * roles have not yet been esstablished on a channel's bridge_channel. A possible example of
  89. * when this could be used is in a bridge v_table's push() callback.
  90. */
  91. const char *ast_channel_get_role_option(struct ast_channel *channel, const char *role_name, const char *option);
  92. /*!
  93. * \brief Check to see if a bridge channel inherited a specific role from its channel
  94. *
  95. * \param bridge_channel The bridge channel being checked
  96. * \param role_name Name of the role being checked
  97. *
  98. * \retval 0 The bridge channel does not have the requested role
  99. * \retval 1 The bridge channel does have the requested role
  100. *
  101. * \note Before a bridge_channel can effectively check roles against a bridge, ast_bridge_channel_establish_roles
  102. * should be called on the bridge_channel so that roles and their respective role options can be copied from the channel
  103. * datastore into the bridge_channel roles list. Otherwise this function will just return 0 because the list will be NULL.
  104. */
  105. int ast_bridge_channel_has_role(struct ast_bridge_channel *bridge_channel, const char *role_name);
  106. /*!
  107. * \brief Retrieve the value of a requested role option from a bridge channel
  108. *
  109. * \param bridge_channel The bridge channel we are retrieving the option from
  110. * \param role_name Name of the role the option will be retrieved from
  111. * \param option Name of the option we are retrieving the value of
  112. *
  113. * \retval NULL If either the role does not exist on the bridge_channel or the role does exist but the option has not been set
  114. * \retval The value of the option
  115. *
  116. * \note See ast_channel_set_role_option note about the need to call ast_bridge_channel_establish_roles.
  117. *
  118. * \note The returned character pointer is only valid as long as the bridge_channel is guaranteed to be alive and hasn't had
  119. * ast_bridge_channel_clear_roles called against it (as this will free all roles and role options in the bridge
  120. * channel). If you need this value after one of these destruction events occurs, you must make a local copy while it is
  121. * still valid.
  122. */
  123. const char *ast_bridge_channel_get_role_option(struct ast_bridge_channel *bridge_channel, const char *role_name, const char *option);
  124. /*!
  125. * \brief Clone the roles from a bridge_channel's attached ast_channel onto the bridge_channel's role list
  126. *
  127. * \param bridge_channel The bridge channel that we are preparing
  128. *
  129. * \retval 0 on success
  130. * \retval -1 on failure
  131. *
  132. * \details
  133. * This function should always be called when the bridge_channel binds to an ast_channel at some point before the bridge_channel
  134. * joins or is imparted onto a bridge. Failure to do so will result in an empty role list. While the list remains established,
  135. * changes to roles on the ast_channel will not propogate to the bridge channel and roles can not be re-established on the bridge
  136. * channel without first clearing the roles with ast_bridge_roles_bridge_channel_clear_roles.
  137. */
  138. int ast_bridge_channel_establish_roles(struct ast_bridge_channel *bridge_channel);
  139. /*!
  140. * \brief Clear all roles from a bridge_channel's role list
  141. *
  142. * \param bridge_channel the bridge channel that we are scrubbing
  143. *
  144. * \details
  145. * If roles are already established on a bridge channel, ast_bridge_channel_establish_roles will fail unconditionally
  146. * without changing any roles. In order to update a bridge channel's roles, they must first be cleared from the bridge channel using
  147. * this function.
  148. *
  149. * \note
  150. * ast_bridge_channel_clear_roles also serves as the destructor for the role list of a bridge channel.
  151. */
  152. void ast_bridge_channel_clear_roles(struct ast_bridge_channel *bridge_channel);
  153. #if defined(__cplusplus) || defined(c_plusplus)
  154. }
  155. #endif
  156. #endif /* _ASTERISK_BRIDGING_ROLES_H */