res_monitor: Remove deprecated module.
[asterisk/asterisk.git] / funcs / func_version.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 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 Return the current Version strings
20  *
21  * \author Steve Murphy (murf@digium.com)
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/channel.h"
33 #include "asterisk/pbx.h"
34 #include "asterisk/utils.h"
35 #include "asterisk/app.h"
36 #include "asterisk/ast_version.h"
37 #include "asterisk/build.h"
38
39 /*** DOCUMENTATION
40         <function name="VERSION" language="en_US">
41                 <synopsis>
42                         Return the Version info for this Asterisk.
43                 </synopsis>
44                 <syntax>
45                         <parameter name="info">
46                                 <para>The possible values are:</para>
47                                 <enumlist>
48                                         <enum name="ASTERISK_VERSION_NUM">
49                                                 <para>A string of digits is returned, e.g. 10602 for 1.6.2 or 100300 for 10.3.0,
50                                                 or 999999 when using a Git build.</para>
51                                         </enum>
52                                         <enum name="BUILD_USER">
53                                                 <para>The string representing the user's name whose account
54                                                 was used to configure Asterisk, is returned.</para>
55                                         </enum>
56                                         <enum name="BUILD_HOSTNAME">
57                                                 <para>The string representing the name of the host on which Asterisk was configured, is returned.</para>
58                                         </enum>
59                                         <enum name="BUILD_MACHINE">
60                                                 <para>The string representing the type of machine on which Asterisk was configured, is returned.</para>
61                                         </enum>
62                                         <enum name="BUILD_OS">
63                                                 <para>The string representing the OS of the machine on which Asterisk was configured, is returned.</para>
64                                         </enum>
65                                         <enum name="BUILD_DATE">
66                                                 <para>The string representing the date on which Asterisk was configured, is returned.</para>
67                                         </enum>
68                                         <enum name="BUILD_KERNEL">
69                                                 <para>The string representing the kernel version of the machine on which Asterisk
70                                                 was configured, is returned.</para>
71                                         </enum>
72                                 </enumlist>
73                         </parameter>
74                 </syntax>
75                 <description>
76                         <para>If there are no arguments, return the version of Asterisk in this format: 18.12.0</para>
77                         <example title="Get current version">
78                         same => n,Set(junky=${VERSION()} ; sets junky to 18.12.0, or possibly GITMasterxxxxxx
79                         </example>
80                 </description>
81         </function>
82  ***/
83
84 static int acf_version_exec(struct ast_channel *chan, const char *cmd,
85                          char *parse, char *buffer, size_t buflen)
86 {
87         const char *response_char = ast_get_version();
88         AST_DECLARE_APP_ARGS(args,
89                 AST_APP_ARG(info);
90         );
91
92         AST_STANDARD_APP_ARGS(args, parse);
93
94         if (!ast_strlen_zero(args.info) ) {
95                 if (!strcasecmp(args.info,"ASTERISK_VERSION_NUM"))
96                         response_char = ast_get_version_num();
97                 else if (!strcasecmp(args.info,"BUILD_USER"))
98                         response_char = BUILD_USER;
99                 else if (!strcasecmp(args.info,"BUILD_HOSTNAME"))
100                         response_char = BUILD_HOSTNAME;
101                 else if (!strcasecmp(args.info,"BUILD_MACHINE"))
102                         response_char = BUILD_MACHINE;
103                 else if (!strcasecmp(args.info,"BUILD_KERNEL"))
104                         response_char = BUILD_KERNEL;
105                 else if (!strcasecmp(args.info,"BUILD_OS"))
106                         response_char = BUILD_OS;
107                 else if (!strcasecmp(args.info,"BUILD_DATE"))
108                         response_char = BUILD_DATE;
109         }
110
111         ast_debug(1, "VERSION returns %s result, given %s argument\n", response_char, args.info);
112
113         ast_copy_string(buffer, response_char, buflen);
114
115         return 0;
116 }
117
118 static struct ast_custom_function acf_version = {
119         .name = "VERSION",
120         .read = acf_version_exec,
121 };
122
123 static int unload_module(void)
124 {
125         ast_custom_function_unregister(&acf_version);
126
127         return 0;
128 }
129
130 static int load_module(void)
131 {
132         return ast_custom_function_register(&acf_version);
133 }
134
135 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get Asterisk Version/Build Info");