| 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 | |
| 17 | /*! \file |
| 18 | * |
| 19 | * \brief Simple module check function |
| 20 | * \author Olle E. Johansson, Edvina.net |
| 21 | * |
| 22 | * \ingroup functions |
| 23 | */ |
| 24 | |
| 25 | /*** MODULEINFO |
| 26 | <support_level>core</support_level> |
| 27 | ***/ |
| 28 | |
| 29 | #include "asterisk.h" |
| 30 | |
| 31 | #include "asterisk/module.h" |
| 32 | #include "asterisk/pbx.h" |
| 33 | |
| 34 | /*** DOCUMENTATION |
| 35 | <function name="IFMODULE" language="en_US"> |
| 36 | <since> |
| 37 | <version>1.6.0</version> |
| 38 | </since> |
| 39 | <synopsis> |
| 40 | Checks if an Asterisk module is loaded in memory. |
| 41 | </synopsis> |
| 42 | <syntax> |
| 43 | <parameter name="modulename.so" required="true"> |
| 44 | <para>Module name complete with <literal>.so</literal></para> |
| 45 | </parameter> |
| 46 | </syntax> |
| 47 | <description> |
| 48 | <para>Checks if a module is loaded. Use the full module name |
| 49 | as shown by the list in <literal>module list</literal>. |
| 50 | Returns <literal>1</literal> if module exists in memory, otherwise <literal>0</literal></para> |
| 51 | </description> |
| 52 | </function> |
| 53 | ***/ |
| 54 | |
| 55 | static int ifmodule_read(struct ast_channel *chan, const char *cmd, char *data, |
| 56 | char *buf, size_t len) |
| 57 | { |
| 58 | char *ret = "0"; |
| 59 | |
| 60 | *buf = '\0'; |
| 61 | |
| 62 | if (data) |
| 63 | if (ast_module_check(data)) |
| 64 | ret = "1"; |
| 65 | |
| 66 | ast_copy_string(buf, ret, len); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | static struct ast_custom_function ifmodule_function = { |
| 72 | .name = "IFMODULE", |
| 73 | .read = ifmodule_read, |
| 74 | .read_max = 2, |
| 75 | }; |
| 76 | |
| 77 | |
| 78 | static int unload_module(void) |
| 79 | { |
| 80 | return ast_custom_function_unregister(&ifmodule_function); |
| 81 | } |
| 82 | |
| 83 | static int load_module(void) |
| 84 | { |
| 85 | return ast_custom_function_register(&ifmodule_function); |
| 86 | } |
| 87 | |
| 88 | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Checks if Asterisk module is loaded in memory"); |