res_curl.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. if (!ast_shutting_down()) {
  54. ast_log(LOG_WARNING, "%s (dependent module) is still loaded. Cannot unload res_curl.so\n", dependents[i]);
  55. }
  56. res = -1;
  57. }
  58. }
  59. if (res)
  60. return -1;
  61. curl_global_cleanup();
  62. return res;
  63. }
  64. static int load_module(void)
  65. {
  66. int res = AST_MODULE_LOAD_SUCCESS;
  67. if (curl_global_init(CURL_GLOBAL_ALL)) {
  68. ast_log(LOG_ERROR, "Unable to initialize the cURL library. Cannot load res_curl.so\n");
  69. return AST_MODULE_LOAD_DECLINE;
  70. }
  71. return res;
  72. }
  73. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "cURL Resource Module",
  74. .support_level = AST_MODULE_SUPPORT_CORE,
  75. .load = load_module,
  76. .unload = unload_module,
  77. .load_pri = AST_MODPRI_REALTIME_DEPEND,
  78. );