Thu Apr 28 2011 17:13:33

Asterisk developer's documentation


func_version.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2006, Digium, Inc.
00005  *
00006  * See http://www.asterisk.org for more information about
00007  * the Asterisk project. Please do not directly contact
00008  * any of the maintainers of this project for assistance;
00009  * the project provides a web site, mailing lists and IRC
00010  * channels for your use.
00011  *
00012  * This program is free software, distributed under the terms of
00013  * the GNU General Public License Version 2. See the LICENSE file
00014  * at the top of the source tree.
00015  */
00016 
00017 /*! \file
00018  *
00019  * \brief Return the current Version strings
00020  * 
00021  * \author Steve Murphy (murf@digium.com)
00022  * \ingroup functions
00023  */
00024 
00025 #include "asterisk.h"
00026 
00027 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 153365 $")
00028 
00029 #include "asterisk/module.h"
00030 #include "asterisk/channel.h"
00031 #include "asterisk/pbx.h"
00032 #include "asterisk/utils.h"
00033 #include "asterisk/app.h"
00034 #include "asterisk/ast_version.h"
00035 #include "asterisk/build.h"
00036 
00037 /*** DOCUMENTATION
00038    <function name="VERSION" language="en_US">
00039       <synopsis>
00040          Return the Version info for this Asterisk.
00041       </synopsis>
00042       <syntax>
00043          <parameter name="info">
00044             <para>The possible values are:</para>
00045             <enumlist>
00046                <enum name="ASTERISK_VERSION_NUM">
00047                   <para>A string of digits is returned (right now fixed at 999999).</para>
00048                </enum>
00049                <enum name="BUILD_USER">
00050                   <para>The string representing the user's name whose account
00051                   was used to configure Asterisk, is returned.</para>
00052                </enum>
00053                <enum name="BUILD_HOSTNAME">
00054                   <para>The string representing the name of the host on which Asterisk was configured, is returned.</para>
00055                </enum>
00056                <enum name="BUILD_MACHINE">
00057                   <para>The string representing the type of machine on which Asterisk was configured, is returned.</para>
00058                </enum>
00059                <enum name="BUILD_OS">
00060                   <para>The string representing the OS of the machine on which Asterisk was configured, is returned.</para>
00061                </enum>
00062                <enum name="BUILD_DATE">
00063                   <para>The string representing the date on which Asterisk was configured, is returned.</para>
00064                </enum>
00065                <enum name="BUILD_KERNEL">
00066                   <para>The string representing the kernel version of the machine on which Asterisk
00067                   was configured, is returned.</para>
00068                </enum>
00069             </enumlist>
00070          </parameter>
00071       </syntax>
00072       <description>
00073          <para>If there are no arguments, return the version of Asterisk in this format: SVN-branch-1.4-r44830M</para>
00074          <para>Example:  Set(junky=${VERSION()};</para>
00075          <para>Sets junky to the string <literal>SVN-branch-1.6-r74830M</literal>, or possibly, <literal>SVN-trunk-r45126M</literal>.</para>
00076       </description>
00077    </function>
00078  ***/
00079 
00080 static int acf_version_exec(struct ast_channel *chan, const char *cmd,
00081           char *parse, char *buffer, size_t buflen)
00082 {
00083    const char *response_char = ast_get_version();
00084    AST_DECLARE_APP_ARGS(args,
00085       AST_APP_ARG(info);
00086    );
00087 
00088    AST_STANDARD_APP_ARGS(args, parse);
00089 
00090    if (!ast_strlen_zero(args.info) ) {
00091       if (!strcasecmp(args.info,"ASTERISK_VERSION_NUM"))
00092          response_char = ast_get_version_num();
00093       else if (!strcasecmp(args.info,"BUILD_USER"))
00094          response_char = BUILD_USER;
00095       else if (!strcasecmp(args.info,"BUILD_HOSTNAME"))
00096          response_char = BUILD_HOSTNAME;
00097       else if (!strcasecmp(args.info,"BUILD_MACHINE"))
00098          response_char = BUILD_MACHINE;
00099       else if (!strcasecmp(args.info,"BUILD_KERNEL"))
00100          response_char = BUILD_KERNEL;
00101       else if (!strcasecmp(args.info,"BUILD_OS"))
00102          response_char = BUILD_OS;
00103       else if (!strcasecmp(args.info,"BUILD_DATE"))
00104          response_char = BUILD_DATE;
00105    }
00106 
00107    ast_debug(1, "VERSION returns %s result, given %s argument\n", response_char, args.info);
00108 
00109    ast_copy_string(buffer, response_char, buflen);
00110 
00111    return 0;
00112 }
00113 
00114 static struct ast_custom_function acf_version = {
00115    .name = "VERSION",
00116    .read = acf_version_exec,
00117 };
00118 
00119 static int unload_module(void)
00120 {
00121    ast_custom_function_unregister(&acf_version);
00122 
00123    return 0;
00124 }
00125 
00126 static int load_module(void)
00127 {
00128    return ast_custom_function_register(&acf_version);
00129 }
00130 
00131 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get Asterisk Version/Build Info");