Mon Mar 19 11:30:27 2012

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

Generated on Mon Mar 19 11:30:27 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7