Asterisk - The Open Source Telephony Project  18.5.0
func_module.c
Go to the documentation of this file.
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  <synopsis>
37  Checks if an Asterisk module is loaded in memory.
38  </synopsis>
39  <syntax>
40  <parameter name="modulename.so" required="true">
41  <para>Module name complete with <literal>.so</literal></para>
42  </parameter>
43  </syntax>
44  <description>
45  <para>Checks if a module is loaded. Use the full module name
46  as shown by the list in <literal>module list</literal>.
47  Returns <literal>1</literal> if module exists in memory, otherwise <literal>0</literal></para>
48  </description>
49  </function>
50  ***/
51 
52 static int ifmodule_read(struct ast_channel *chan, const char *cmd, char *data,
53  char *buf, size_t len)
54 {
55  char *ret = "0";
56 
57  *buf = '\0';
58 
59  if (data)
60  if (ast_module_check(data))
61  ret = "1";
62 
63  ast_copy_string(buf, ret, len);
64 
65  return 0;
66 }
67 
69  .name = "IFMODULE",
70  .read = ifmodule_read,
71  .read_max = 2,
72 };
73 
74 
75 static int unload_module(void)
76 {
77  return ast_custom_function_unregister(&ifmodule_function);
78 }
79 
80 static int load_module(void)
81 {
82  return ast_custom_function_register(&ifmodule_function);
83 }
84 
85 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Checks if Asterisk module is loaded in memory");
const char * name
Definition: pbx.h:119
Main Channel structure associated with a channel.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:567
Asterisk main include file. File version handling, generic pbx functions.
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int ifmodule_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_module.c:52
static int unload_module(void)
Definition: func_module.c:75
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
int ast_module_check(const char *name)
Check if module with the name given is loaded.
Definition: loader.c:2653
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
Core PBX routines and definitions.
static int load_module(void)
Definition: func_module.c:80
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static struct ast_custom_function ifmodule_function
Definition: func_module.c:68
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1508