Thu Apr 28 2011 17:15:22

Asterisk developer's documentation


func_module.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2006, Digium, Inc.
00005  *
00006  * See http://www.asterisk.org for more information about
00007  * the Asterisk project. Please do not directly contact
00008  * any of the maintainers of this project for assistance;
00009  * the project provides a web site, mailing lists and IRC
00010  * channels for your use.
00011  *
00012  * This program is free software, distributed under the terms of
00013  * the GNU General Public License Version 2. See the LICENSE file
00014  * at the top of the source tree.
00015  */
00016 
00017 /*! \file
00018  *
00019  * \brief Simple module check function
00020  * \author Olle E. Johansson, Edvina.net
00021  *
00022  * \ingroup functions
00023  */
00024 #include "asterisk.h"
00025 
00026 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 153365 $")
00027 
00028 #include "asterisk/module.h"
00029 #include "asterisk/pbx.h"
00030 
00031 /*** DOCUMENTATION
00032    <function name="IFMODULE" language="en_US">
00033       <synopsis>
00034          Checks if an Asterisk module is loaded in memory.
00035       </synopsis>
00036       <syntax>
00037          <parameter name="modulename.so" required="true">
00038             <para>Module name complete with <literal>.so</literal></para>
00039          </parameter>
00040       </syntax>
00041       <description>
00042          <para>Checks if a module is loaded. Use the full module name
00043          as shown by the list in <literal>module list</literal>.
00044          Returns <literal>1</literal> if module exists in memory, otherwise <literal>0</literal></para>
00045       </description>
00046    </function>
00047  ***/
00048 
00049 static int ifmodule_read(struct ast_channel *chan, const char *cmd, char *data,
00050           char *buf, size_t len)
00051 {
00052    char *ret = "0";
00053 
00054    *buf = '\0';
00055 
00056    if (data)
00057       if (ast_module_check(data))
00058          ret = "1";
00059 
00060    ast_copy_string(buf, ret, len);
00061 
00062    return 0;
00063 }
00064 
00065 static struct ast_custom_function ifmodule_function = {
00066    .name = "IFMODULE",
00067    .read = ifmodule_read,
00068 };
00069 
00070 
00071 static int unload_module(void)
00072 {
00073    return ast_custom_function_unregister(&ifmodule_function);
00074 }
00075 
00076 static int load_module(void)
00077 {
00078    return ast_custom_function_register(&ifmodule_function);
00079 }
00080 
00081 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Checks if Asterisk module is loaded in memory");