func_module.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2006, Digium, Inc.
  5. *
  6. * See http://www.asterisk.org for more information about
  7. * the Asterisk project. Please do not directly contact
  8. * any of the maintainers of this project for assistance;
  9. * the project provides a web site, mailing lists and IRC
  10. * channels for your use.
  11. *
  12. * This program is free software, distributed under the terms of
  13. * the GNU General Public License Version 2. See the LICENSE file
  14. * at the top of the source tree.
  15. */
  16. /*! \file
  17. *
  18. * \brief Simple module check function
  19. * \author Olle E. Johansson, Edvina.net
  20. *
  21. * \ingroup functions
  22. */
  23. /*** MODULEINFO
  24. <support_level>core</support_level>
  25. ***/
  26. #include "asterisk.h"
  27. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  28. #include "asterisk/module.h"
  29. #include "asterisk/pbx.h"
  30. /*** DOCUMENTATION
  31. <function name="IFMODULE" language="en_US">
  32. <synopsis>
  33. Checks if an Asterisk module is loaded in memory.
  34. </synopsis>
  35. <syntax>
  36. <parameter name="modulename.so" required="true">
  37. <para>Module name complete with <literal>.so</literal></para>
  38. </parameter>
  39. </syntax>
  40. <description>
  41. <para>Checks if a module is loaded. Use the full module name
  42. as shown by the list in <literal>module list</literal>.
  43. Returns <literal>1</literal> if module exists in memory, otherwise <literal>0</literal></para>
  44. </description>
  45. </function>
  46. ***/
  47. static int ifmodule_read(struct ast_channel *chan, const char *cmd, char *data,
  48. char *buf, size_t len)
  49. {
  50. char *ret = "0";
  51. *buf = '\0';
  52. if (data)
  53. if (ast_module_check(data))
  54. ret = "1";
  55. ast_copy_string(buf, ret, len);
  56. return 0;
  57. }
  58. static struct ast_custom_function ifmodule_function = {
  59. .name = "IFMODULE",
  60. .read = ifmodule_read,
  61. .read_max = 2,
  62. };
  63. static int unload_module(void)
  64. {
  65. return ast_custom_function_unregister(&ifmodule_function);
  66. }
  67. static int load_module(void)
  68. {
  69. return ast_custom_function_register(&ifmodule_function);
  70. }
  71. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Checks if Asterisk module is loaded in memory");