func_version.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "asterisk.h"
00025
00026 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 45724 $")
00027
00028 #include <stdlib.h>
00029 #include <string.h>
00030 #include <stdio.h>
00031 #include <sys/types.h>
00032
00033 #include "asterisk/module.h"
00034 #include "asterisk/channel.h"
00035 #include "asterisk/pbx.h"
00036 #include "asterisk/logger.h"
00037 #include "asterisk/utils.h"
00038 #include "asterisk/app.h"
00039 #include "asterisk/options.h"
00040 #include "asterisk/version.h"
00041 #include "asterisk/build.h"
00042
00043 #define STRING_IT(vernum) STRING_IT2(vernum)
00044 #define STRING_IT2(vernum) #vernum
00045
00046 static int acf_version_exec(struct ast_channel *chan, char *cmd,
00047 char *parse, char *buffer, size_t buflen)
00048 {
00049 struct ast_module_user *u;
00050 char *response_char = ASTERISK_VERSION;
00051 AST_DECLARE_APP_ARGS(args,
00052 AST_APP_ARG(info);
00053 );
00054
00055 u = ast_module_user_add(chan);
00056
00057 AST_STANDARD_APP_ARGS(args, parse);
00058
00059 if (!ast_strlen_zero(args.info) ) {
00060 if (strcasecmp(args.info,"ASTERISK_VERSION_NUM") == 0)
00061 response_char = STRING_IT(ASTERISK_VERSION_NUM);
00062 else if (strcasecmp(args.info,"BUILD_USER") == 0)
00063 response_char = BUILD_USER;
00064 else if (strcasecmp(args.info,"BUILD_HOSTNAME") == 0)
00065 response_char = BUILD_HOSTNAME;
00066 else if (strcasecmp(args.info,"BUILD_MACHINE") == 0)
00067 response_char = BUILD_MACHINE;
00068 else if (strcasecmp(args.info,"BUILD_KERNEL") == 0)
00069 response_char = BUILD_KERNEL;
00070 else if (strcasecmp(args.info,"BUILD_OS") == 0)
00071 response_char = BUILD_OS;
00072 else if (strcasecmp(args.info,"BUILD_DATE") == 0)
00073 response_char = BUILD_DATE;
00074
00075 }
00076
00077
00078 if (option_debug)
00079 ast_log(LOG_DEBUG, "VERSION returns %s result, given %s argument\n",
00080 response_char, args.info);
00081 snprintf(buffer, buflen, "%s", response_char);
00082
00083 ast_module_user_remove(u);
00084
00085 return 0;
00086 }
00087
00088 static struct ast_custom_function acf_version = {
00089 .name = "VERSION",
00090 .synopsis = "Return the Version info for this Asterisk",
00091 .syntax = "VERSION([info])",
00092 .desc =
00093 "If there are no arguments, return the version of Asterisk in this format: SVN-branch-1.4-r44830M\n"
00094 "If the argument is 'ASTERISK_VERSION_NUM', a string of digits is returned (right now fixed at 999999).\n"
00095 "If the argument is 'BUILD_USER', the string representing the user's name whose account was used to configure Asterisk, is returned.\n"
00096 "If the argument is 'BUILD_HOSTNAME', the string representing the name of the host on which Asterisk was configured, is returned.\n"
00097 "If the argument is 'BUILD_MACHINE', the string representing the type of machine on which Asterisk was configured, is returned.\n"
00098 "If the argument is 'BUILD_OS', the string representing the OS of the machine on which Asterisk was configured, is returned.\n"
00099 "If the argument is 'BUILD_DATE', the string representing the date on which Asterisk was configured, is returned.\n"
00100 "If the argument is 'BUILD_KERNEL', the string representing the kernel version of the machine on which Asterisk was configured, is returned .\n"
00101 " Example: Set(junky=${VERSION()}; \n"
00102 " Sets junky to the string 'SVN-branch-1.6-r74830M', or possibly, 'SVN-trunk-r45126M'.\n",
00103 .read = acf_version_exec,
00104 };
00105
00106 static int unload_module(void)
00107 {
00108 ast_custom_function_unregister(&acf_version);
00109
00110 return 0;
00111 }
00112
00113 static int load_module(void)
00114 {
00115 return ast_custom_function_register(&acf_version);
00116 }
00117
00118 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get Asterisk Version/Build Info");