ami_testhooks.c automatically registers hook
[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 #include "asterisk.h"
26
27 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
28
29 #include "asterisk/module.h"
30 #include "asterisk/channel.h"
31 #include "asterisk/pbx.h"
32 #include "asterisk/utils.h"
33 #include "asterisk/app.h"
34 #include "asterisk/ast_version.h"
35 #include "asterisk/build.h"
36
37 /*** DOCUMENTATION
38         <function name="VERSION" language="en_US">
39                 <synopsis>
40                         Return the Version info for this Asterisk.
41                 </synopsis>
42                 <syntax>
43                         <parameter name="info">
44                                 <para>The possible values are:</para>
45                                 <enumlist>
46                                         <enum name="ASTERISK_VERSION_NUM">
47                                                 <para>A string of digits is returned (right now fixed at 999999).</para>
48                                         </enum>
49                                         <enum name="BUILD_USER">
50                                                 <para>The string representing the user's name whose account
51                                                 was used to configure Asterisk, is returned.</para>
52                                         </enum>
53                                         <enum name="BUILD_HOSTNAME">
54                                                 <para>The string representing the name of the host on which Asterisk was configured, is returned.</para>
55                                         </enum>
56                                         <enum name="BUILD_MACHINE">
57                                                 <para>The string representing the type of machine on which Asterisk was configured, is returned.</para>
58                                         </enum>
59                                         <enum name="BUILD_OS">
60                                                 <para>The string representing the OS of the machine on which Asterisk was configured, is returned.</para>
61                                         </enum>
62                                         <enum name="BUILD_DATE">
63                                                 <para>The string representing the date on which Asterisk was configured, is returned.</para>
64                                         </enum>
65                                         <enum name="BUILD_KERNEL">
66                                                 <para>The string representing the kernel version of the machine on which Asterisk
67                                                 was configured, is returned.</para>
68                                         </enum>
69                                 </enumlist>
70                         </parameter>
71                 </syntax>
72                 <description>
73                         <para>If there are no arguments, return the version of Asterisk in this format: SVN-branch-1.4-r44830M</para>
74                         <para>Example:  Set(junky=${VERSION()};</para>
75                         <para>Sets junky to the string <literal>SVN-branch-1.6-r74830M</literal>, or possibly, <literal>SVN-trunk-r45126M</literal>.</para>
76                 </description>
77         </function>
78  ***/
79
80 static int acf_version_exec(struct ast_channel *chan, const char *cmd,
81                          char *parse, char *buffer, size_t buflen)
82 {
83         const char *response_char = ast_get_version();
84         AST_DECLARE_APP_ARGS(args,
85                 AST_APP_ARG(info);
86         );
87
88         AST_STANDARD_APP_ARGS(args, parse);
89
90         if (!ast_strlen_zero(args.info) ) {
91                 if (!strcasecmp(args.info,"ASTERISK_VERSION_NUM"))
92                         response_char = ast_get_version_num();
93                 else if (!strcasecmp(args.info,"BUILD_USER"))
94                         response_char = BUILD_USER;
95                 else if (!strcasecmp(args.info,"BUILD_HOSTNAME"))
96                         response_char = BUILD_HOSTNAME;
97                 else if (!strcasecmp(args.info,"BUILD_MACHINE"))
98                         response_char = BUILD_MACHINE;
99                 else if (!strcasecmp(args.info,"BUILD_KERNEL"))
100                         response_char = BUILD_KERNEL;
101                 else if (!strcasecmp(args.info,"BUILD_OS"))
102                         response_char = BUILD_OS;
103                 else if (!strcasecmp(args.info,"BUILD_DATE"))
104                         response_char = BUILD_DATE;
105         }
106
107         ast_debug(1, "VERSION returns %s result, given %s argument\n", response_char, args.info);
108
109         ast_copy_string(buffer, response_char, buflen);
110
111         return 0;
112 }
113
114 static struct ast_custom_function acf_version = {
115         .name = "VERSION",
116         .read = acf_version_exec,
117 };
118
119 static int unload_module(void)
120 {
121         ast_custom_function_unregister(&acf_version);
122
123         return 0;
124 }
125
126 static int load_module(void)
127 {
128         return ast_custom_function_register(&acf_version);
129 }
130
131 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get Asterisk Version/Build Info");