Wed Jan 8 2020 09:49:47

Asterisk developer's documentation


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 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
32 
33 #include "asterisk/module.h"
34 #include "asterisk/pbx.h"
35 
36 /*** DOCUMENTATION
37  <function name="IFMODULE" language="en_US">
38  <synopsis>
39  Checks if an Asterisk module is loaded in memory.
40  </synopsis>
41  <syntax>
42  <parameter name="modulename.so" required="true">
43  <para>Module name complete with <literal>.so</literal></para>
44  </parameter>
45  </syntax>
46  <description>
47  <para>Checks if a module is loaded. Use the full module name
48  as shown by the list in <literal>module list</literal>.
49  Returns <literal>1</literal> if module exists in memory, otherwise <literal>0</literal></para>
50  </description>
51  </function>
52  ***/
53 
54 static int ifmodule_read(struct ast_channel *chan, const char *cmd, char *data,
55  char *buf, size_t len)
56 {
57  char *ret = "0";
58 
59  *buf = '\0';
60 
61  if (data)
62  if (ast_module_check(data))
63  ret = "1";
64 
65  ast_copy_string(buf, ret, len);
66 
67  return 0;
68 }
69 
71  .name = "IFMODULE",
72  .read = ifmodule_read,
73  .read_max = 2,
74 };
75 
76 
77 static int unload_module(void)
78 {
79  return ast_custom_function_unregister(&ifmodule_function);
80 }
81 
82 static int load_module(void)
83 {
84  return ast_custom_function_register(&ifmodule_function);
85 }
86 
87 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Checks if Asterisk module is loaded in memory");
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk main include file. File version handling, generic pbx functions.
static int ifmodule_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_module.c:54
static int unload_module(void)
Definition: func_module.c:77
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
int ast_module_check(const char *name)
Check if module with the name given is loaded.
Definition: loader.c:1255
Data structure associated with a custom dialplan function.
Definition: pbx.h:95
Core PBX routines and definitions.
static int load_module(void)
Definition: func_module.c:82
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:70
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
const char * name
Definition: pbx.h:96
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180