Doxygen update
[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 <stdlib.h>
30 #include <string.h>
31 #include <stdio.h>
32 #include <sys/types.h>
33
34 #include "asterisk/module.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/pbx.h"
37 #include "asterisk/logger.h"
38 #include "asterisk/utils.h"
39 #include "asterisk/app.h"
40 #include "asterisk/options.h"
41 #include "asterisk/version.h"
42 #include "asterisk/build.h"
43
44 #define STRING_IT(vernum) STRING_IT2(vernum)
45 #define STRING_IT2(vernum) #vernum
46
47 static int acf_version_exec(struct ast_channel *chan, const char *cmd,
48                          char *parse, char *buffer, size_t buflen)
49 {
50         struct ast_module_user *u;
51         char *response_char = ASTERISK_VERSION;
52         AST_DECLARE_APP_ARGS(args,
53                              AST_APP_ARG(info);
54         );
55
56         u = ast_module_user_add(chan);
57
58         AST_STANDARD_APP_ARGS(args, parse);
59
60         if (!ast_strlen_zero(args.info) ) {
61                 if (strcasecmp(args.info,"ASTERISK_VERSION_NUM") == 0)
62                         response_char = STRING_IT(ASTERISK_VERSION_NUM);
63                 else if (strcasecmp(args.info,"BUILD_USER") == 0)
64                         response_char = BUILD_USER;
65                 else if (strcasecmp(args.info,"BUILD_HOSTNAME") == 0)
66                         response_char = BUILD_HOSTNAME;
67                 else if (strcasecmp(args.info,"BUILD_MACHINE") == 0)
68                         response_char = BUILD_MACHINE;
69                 else if (strcasecmp(args.info,"BUILD_KERNEL") == 0)
70                         response_char = BUILD_KERNEL;
71                 else if (strcasecmp(args.info,"BUILD_OS") == 0)
72                         response_char = BUILD_OS;
73                 else if (strcasecmp(args.info,"BUILD_DATE") == 0)
74                         response_char = BUILD_DATE;
75
76         }
77
78
79         if (option_debug)
80                 ast_log(LOG_DEBUG, "VERSION returns %s result, given %s argument\n",
81                         response_char, args.info);
82         snprintf(buffer, buflen, "%s", response_char);
83
84         ast_module_user_remove(u);
85
86         return 0;
87 }
88
89 static struct ast_custom_function acf_version = {
90         .name = "VERSION",
91         .synopsis = "Return the Version info for this Asterisk",
92         .syntax = "VERSION([info])",
93         .desc =
94                 "If there are no arguments, return the version of Asterisk in this format: SVN-branch-1.4-r44830M\n"
95                 "If the argument is 'ASTERISK_VERSION_NUM', a string of digits is returned (right now fixed at 999999).\n"
96                 "If the argument is 'BUILD_USER', the string representing the user's name whose account was used to configure Asterisk, is returned.\n"
97                 "If the argument is 'BUILD_HOSTNAME', the string representing the name of the host on which Asterisk was configured, is returned.\n"
98                 "If the argument is 'BUILD_MACHINE', the string representing the type of machine on which Asterisk was configured, is returned.\n"
99                 "If the argument is 'BUILD_OS', the string representing the OS of the machine on which Asterisk was configured, is returned.\n"
100                 "If the argument is 'BUILD_DATE', the string representing the date on which Asterisk was configured, is returned.\n"
101                 "If the argument is 'BUILD_KERNEL', the string representing the kernel version of the machine on which Asterisk was configured, is returned .\n"
102                 "  Example:  Set(junky=${VERSION()}; \n"
103                 "  Sets junky to the string 'SVN-branch-1.6-r74830M', or possibly, 'SVN-trunk-r45126M'.\n",
104         .read = acf_version_exec,
105 };
106
107 static int unload_module(void)
108 {
109         ast_custom_function_unregister(&acf_version);
110
111         return 0;
112 }
113
114 static int load_module(void)
115 {
116         return ast_custom_function_register(&acf_version);
117 }
118
119 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get Asterisk Version/Build Info");