func_module.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #include "asterisk/module.h"
  28. #include "asterisk/pbx.h"
  29. /*** DOCUMENTATION
  30. <function name="IFMODULE" language="en_US">
  31. <synopsis>
  32. Checks if an Asterisk module is loaded in memory.
  33. </synopsis>
  34. <syntax>
  35. <parameter name="modulename.so" required="true">
  36. <para>Module name complete with <literal>.so</literal></para>
  37. </parameter>
  38. </syntax>
  39. <description>
  40. <para>Checks if a module is loaded. Use the full module name
  41. as shown by the list in <literal>module list</literal>.
  42. Returns <literal>1</literal> if module exists in memory, otherwise <literal>0</literal></para>
  43. </description>
  44. </function>
  45. ***/
  46. static int ifmodule_read(struct ast_channel *chan, const char *cmd, char *data,
  47. char *buf, size_t len)
  48. {
  49. char *ret = "0";
  50. *buf = '\0';
  51. if (data)
  52. if (ast_module_check(data))
  53. ret = "1";
  54. ast_copy_string(buf, ret, len);
  55. return 0;
  56. }
  57. static struct ast_custom_function ifmodule_function = {
  58. .name = "IFMODULE",
  59. .read = ifmodule_read,
  60. .read_max = 2,
  61. };
  62. static int unload_module(void)
  63. {
  64. return ast_custom_function_unregister(&ifmodule_function);
  65. }
  66. static int load_module(void)
  67. {
  68. return ast_custom_function_register(&ifmodule_function);
  69. }
  70. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Checks if Asterisk module is loaded in memory");