res_curl.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (c) 2008, Digium, Inc.
  5. *
  6. * Tilghman Lesher <res_curl_v1@the-tilghman.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. *
  20. * \brief curl resource engine
  21. *
  22. * \author Tilghman Lesher <res_curl_v1@the-tilghman.com>
  23. *
  24. * Depends on the CURL library - http://curl.haxx.se/
  25. *
  26. */
  27. /*! \li \ref res_curl.c uses the configuration file \ref res_curl.conf
  28. * \addtogroup configuration_file Configuration Files
  29. */
  30. /*!
  31. * \page res_curl.conf res_curl.conf
  32. * \verbinclude res_curl.conf.sample
  33. */
  34. /*** MODULEINFO
  35. <depend>curl</depend>
  36. <support_level>core</support_level>
  37. ***/
  38. #include "asterisk.h"
  39. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  40. #include <curl/curl.h>
  41. #include "asterisk/module.h"
  42. static const char *dependents[] = {
  43. "func_curl.so",
  44. "res_config_curl.so",
  45. };
  46. static int unload_module(void)
  47. {
  48. int res = 0;
  49. size_t i;
  50. /* If the dependent modules are still in memory, forbid unload */
  51. for (i = 0; i < ARRAY_LEN(dependents); i++) {
  52. if (ast_module_check(dependents[i])) {
  53. ast_log(LOG_ERROR, "%s (dependent module) is still loaded. Cannot unload res_curl.so\n", dependents[i]);
  54. res = -1;
  55. }
  56. }
  57. if (res)
  58. return -1;
  59. curl_global_cleanup();
  60. return res;
  61. }
  62. /*!
  63. * \brief Load the module
  64. *
  65. * Module loading including tests for configuration or dependencies.
  66. * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
  67. * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
  68. * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
  69. * configuration file or other non-critical problem return
  70. * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
  71. */
  72. static int load_module(void)
  73. {
  74. int res = 0;
  75. if (curl_global_init(CURL_GLOBAL_ALL)) {
  76. ast_log(LOG_ERROR, "Unable to initialize the cURL library. Cannot load res_curl.so\n");
  77. return AST_MODULE_LOAD_DECLINE;
  78. }
  79. return res;
  80. }
  81. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "cURL Resource Module",
  82. .support_level = AST_MODULE_SUPPORT_CORE,
  83. .load = load_module,
  84. .unload = unload_module,
  85. .load_pri = AST_MODPRI_REALTIME_DEPEND,
  86. );