func_callcompletion.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2010, Digium, Inc.
  5. *
  6. * Mark Michelson <mmichelson@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 Call Completion Supplementary Services implementation
  20. * \author Mark Michelson <mmichelson@digium.com>
  21. */
  22. /*** MODULEINFO
  23. <support_level>core</support_level>
  24. ***/
  25. #include "asterisk.h"
  26. #include "asterisk/module.h"
  27. #include "asterisk/channel.h"
  28. #include "asterisk/ccss.h"
  29. #include "asterisk/pbx.h"
  30. /*** DOCUMENTATION
  31. <function name="CALLCOMPLETION" language="en_US">
  32. <synopsis>
  33. Get or set a call completion configuration parameter for a channel.
  34. </synopsis>
  35. <syntax>
  36. <parameter name="option" required="true">
  37. <para>The allowable options are:</para>
  38. <enumlist>
  39. <enum name="cc_agent_policy" />
  40. <enum name="cc_monitor_policy" />
  41. <enum name="cc_offer_timer" />
  42. <enum name="ccnr_available_timer" />
  43. <enum name="ccbs_available_timer" />
  44. <enum name="cc_recall_timer" />
  45. <enum name="cc_max_agents" />
  46. <enum name="cc_max_monitors" />
  47. <enum name="cc_agent_dialstring" />
  48. </enumlist>
  49. </parameter>
  50. </syntax>
  51. <description>
  52. <para>The CALLCOMPLETION function can be used to get or set a call
  53. completion configuration parameter for a channel. Note that setting
  54. a configuration parameter will only change the parameter for the
  55. duration of the call.
  56. For more information see <filename>doc/AST.pdf</filename>.
  57. For more information on call completion parameters, see <filename>configs/ccss.conf.sample</filename>.</para>
  58. </description>
  59. </function>
  60. ***/
  61. static int acf_cc_read(struct ast_channel *chan, const char *name, char *data,
  62. char *buf, size_t buf_len)
  63. {
  64. struct ast_cc_config_params *cc_params;
  65. int res;
  66. if (!chan) {
  67. ast_log(LOG_WARNING, "No channel was provided to %s function.\n", name);
  68. return -1;
  69. }
  70. ast_channel_lock(chan);
  71. if (!(cc_params = ast_channel_get_cc_config_params(chan))) {
  72. ast_channel_unlock(chan);
  73. return -1;
  74. }
  75. res = ast_cc_get_param(cc_params, data, buf, buf_len);
  76. ast_channel_unlock(chan);
  77. return res;
  78. }
  79. static int acf_cc_write(struct ast_channel *chan, const char *cmd, char *data,
  80. const char *value)
  81. {
  82. struct ast_cc_config_params *cc_params;
  83. int res;
  84. if (!chan) {
  85. ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
  86. return -1;
  87. }
  88. ast_channel_lock(chan);
  89. if (!(cc_params = ast_channel_get_cc_config_params(chan))) {
  90. ast_channel_unlock(chan);
  91. return -1;
  92. }
  93. res = ast_cc_set_param(cc_params, data, value);
  94. ast_channel_unlock(chan);
  95. return res;
  96. }
  97. static struct ast_custom_function cc_function = {
  98. .name = "CALLCOMPLETION",
  99. .read = acf_cc_read,
  100. .write = acf_cc_write,
  101. };
  102. static int unload_module(void)
  103. {
  104. return ast_custom_function_unregister(&cc_function);
  105. }
  106. static int load_module(void)
  107. {
  108. return ast_custom_function_register(&cc_function) == 0 ? AST_MODULE_LOAD_SUCCESS : AST_MODULE_LOAD_DECLINE;
  109. }
  110. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Call Control Configuration Function",
  111. .support_level = AST_MODULE_SUPPORT_CORE,
  112. .load = load_module,
  113. .unload = unload_module,
  114. .requires = "ccss",
  115. );