Thu Oct 11 06:33:48 2012

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 
00025 /*** MODULEINFO
00026    <support_level>core</support_level>
00027  ***/
00028 
00029 #include "asterisk.h"
00030 
00031 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328259 $")
00032 
00033 #include "asterisk/module.h"
00034 #include "asterisk/pbx.h"
00035 
00036 /*** DOCUMENTATION
00037    <function name="IFMODULE" language="en_US">
00038       <synopsis>
00039          Checks if an Asterisk module is loaded in memory.
00040       </synopsis>
00041       <syntax>
00042          <parameter name="modulename.so" required="true">
00043             <para>Module name complete with <literal>.so</literal></para>
00044          </parameter>
00045       </syntax>
00046       <description>
00047          <para>Checks if a module is loaded. Use the full module name
00048          as shown by the list in <literal>module list</literal>.
00049          Returns <literal>1</literal> if module exists in memory, otherwise <literal>0</literal></para>
00050       </description>
00051    </function>
00052  ***/
00053 
00054 static int ifmodule_read(struct ast_channel *chan, const char *cmd, char *data,
00055           char *buf, size_t len)
00056 {
00057    char *ret = "0";
00058 
00059    *buf = '\0';
00060 
00061    if (data)
00062       if (ast_module_check(data))
00063          ret = "1";
00064 
00065    ast_copy_string(buf, ret, len);
00066 
00067    return 0;
00068 }
00069 
00070 static struct ast_custom_function ifmodule_function = {
00071    .name = "IFMODULE",
00072    .read = ifmodule_read,
00073    .read_max = 2,
00074 };
00075 
00076 
00077 static int unload_module(void)
00078 {
00079    return ast_custom_function_unregister(&ifmodule_function);
00080 }
00081 
00082 static int load_module(void)
00083 {
00084    return ast_custom_function_register(&ifmodule_function);
00085 }
00086 
00087 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Checks if Asterisk module is loaded in memory");

Generated on Thu Oct 11 06:33:48 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6