res_curl.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. * \extref Depends on the CURL library - http://curl.haxx.se/
  25. *
  26. */
  27. /*** MODULEINFO
  28. <support_level>core</support_level>
  29. <depend>curl</depend>
  30. ***/
  31. #include "asterisk.h"
  32. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  33. #include <curl/curl.h>
  34. #include "asterisk/module.h"
  35. static int unload_module(void)
  36. {
  37. int res = 0;
  38. /* If the dependent modules are still in memory, forbid unload */
  39. if (ast_module_check("func_curl.so")) {
  40. ast_log(LOG_ERROR, "func_curl.so (dependent module) is still loaded. Cannot unload res_curl.so\n");
  41. return -1;
  42. }
  43. if (ast_module_check("res_config_curl.so")) {
  44. ast_log(LOG_ERROR, "res_config_curl.so (dependent module) is still loaded. Cannot unload res_curl.so\n");
  45. return -1;
  46. }
  47. curl_global_cleanup();
  48. return res;
  49. }
  50. static int load_module(void)
  51. {
  52. int res = 0;
  53. if (curl_global_init(CURL_GLOBAL_ALL)) {
  54. ast_log(LOG_ERROR, "Unable to initialize the CURL library. Cannot load res_curl\n");
  55. return AST_MODULE_LOAD_DECLINE;
  56. }
  57. return res;
  58. }
  59. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "cURL Resource Module",
  60. .load = load_module,
  61. .unload = unload_module,
  62. .load_pri = AST_MODPRI_REALTIME_DEPEND,
  63. );