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 /*** MODULEINFO
00026    <support_level>core</support_level>
00027  ***/
00028 
00029 #include "asterisk.h"
00030 
00031 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 389251 $")
00032 
00033 #include "asterisk/module.h"
00034 #include "asterisk/channel.h"
00035 #include "asterisk/pbx.h"
00036 #include "asterisk/utils.h"
00037 #include "asterisk/app.h"
00038 #include "asterisk/ast_version.h"
00039 #include "asterisk/build.h"
00040 
00041 /*** DOCUMENTATION
00042    <function name="VERSION" language="en_US">
00043       <synopsis>
00044          Return the Version info for this Asterisk.
00045       </synopsis>
00046       <syntax>
00047          <parameter name="info">
00048             <para>The possible values are:</para>
00049             <enumlist>
00050                <enum name="ASTERISK_VERSION_NUM">
00051                   <para>A string of digits is returned, e.g. 10602 for 1.6.2 or 100300 for 10.3.0,
00052                   or 999999 when using an SVN build.</para>
00053                </enum>
00054                <enum name="BUILD_USER">
00055                   <para>The string representing the user's name whose account
00056                   was used to configure Asterisk, is returned.</para>
00057                </enum>
00058                <enum name="BUILD_HOSTNAME">
00059                   <para>The string representing the name of the host on which Asterisk was configured, is returned.</para>
00060                </enum>
00061                <enum name="BUILD_MACHINE">
00062                   <para>The string representing the type of machine on which Asterisk was configured, is returned.</para>
00063                </enum>
00064                <enum name="BUILD_OS">
00065                   <para>The string representing the OS of the machine on which Asterisk was configured, is returned.</para>
00066                </enum>
00067                <enum name="BUILD_DATE">
00068                   <para>The string representing the date on which Asterisk was configured, is returned.</para>
00069                </enum>
00070                <enum name="BUILD_KERNEL">
00071                   <para>The string representing the kernel version of the machine on which Asterisk
00072                   was configured, is returned.</para>
00073                </enum>
00074             </enumlist>
00075          </parameter>
00076       </syntax>
00077       <description>
00078          <para>If there are no arguments, return the version of Asterisk in this format: SVN-branch-1.4-r44830M</para>
00079          <para>Example:  Set(junky=${VERSION()};</para>
00080          <para>Sets junky to the string <literal>SVN-branch-1.6-r74830M</literal>, or possibly, <literal>SVN-trunk-r45126M</literal>.</para>
00081       </description>
00082    </function>
00083  ***/
00084 
00085 static int acf_version_exec(struct ast_channel *chan, const char *cmd,
00086           char *parse, char *buffer, size_t buflen)
00087 {
00088    const char *response_char = ast_get_version();
00089    AST_DECLARE_APP_ARGS(args,
00090       AST_APP_ARG(info);
00091    );
00092 
00093    AST_STANDARD_APP_ARGS(args, parse);
00094 
00095    if (!ast_strlen_zero(args.info) ) {
00096       if (!strcasecmp(args.info,"ASTERISK_VERSION_NUM"))
00097          response_char = ast_get_version_num();
00098       else if (!strcasecmp(args.info,"BUILD_USER"))
00099          response_char = BUILD_USER;
00100       else if (!strcasecmp(args.info,"BUILD_HOSTNAME"))
00101          response_char = BUILD_HOSTNAME;
00102       else if (!strcasecmp(args.info,"BUILD_MACHINE"))
00103          response_char = BUILD_MACHINE;
00104       else if (!strcasecmp(args.info,"BUILD_KERNEL"))
00105          response_char = BUILD_KERNEL;
00106       else if (!strcasecmp(args.info,"BUILD_OS"))
00107          response_char = BUILD_OS;
00108       else if (!strcasecmp(args.info,"BUILD_DATE"))
00109          response_char = BUILD_DATE;
00110    }
00111 
00112    ast_debug(1, "VERSION returns %s result, given %s argument\n", response_char, args.info);
00113 
00114    ast_copy_string(buffer, response_char, buflen);
00115 
00116    return 0;
00117 }
00118 
00119 static struct ast_custom_function acf_version = {
00120    .name = "VERSION",
00121    .read = acf_version_exec,
00122 };
00123 
00124 static int unload_module(void)
00125 {
00126    ast_custom_function_unregister(&acf_version);
00127 
00128    return 0;
00129 }
00130 
00131 static int load_module(void)
00132 {
00133    return ast_custom_function_register(&acf_version);
00134 }
00135 
00136 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get Asterisk Version/Build Info");

Generated on Thu Apr 16 06:27:36 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6