Wed Jan 8 2020 09:49:48

Asterisk developer's documentation


func_version.c
Go to the documentation of this file.
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 /*** MODULEINFO
26  <support_level>core</support_level>
27  ***/
28 
29 #include "asterisk.h"
30 
31 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 362729 $")
32 
33 #include "asterisk/module.h"
34 #include "asterisk/channel.h"
35 #include "asterisk/pbx.h"
36 #include "asterisk/utils.h"
37 #include "asterisk/app.h"
38 #include "asterisk/ast_version.h"
39 #include "asterisk/build.h"
40 
41 /*** DOCUMENTATION
42  <function name="VERSION" language="en_US">
43  <synopsis>
44  Return the Version info for this Asterisk.
45  </synopsis>
46  <syntax>
47  <parameter name="info">
48  <para>The possible values are:</para>
49  <enumlist>
50  <enum name="ASTERISK_VERSION_NUM">
51  <para>A string of digits is returned, e.g. 10602 for 1.6.2 or 100300 for 10.3.0,
52  or 999999 when using an SVN build.</para>
53  </enum>
54  <enum name="BUILD_USER">
55  <para>The string representing the user's name whose account
56  was used to configure Asterisk, is returned.</para>
57  </enum>
58  <enum name="BUILD_HOSTNAME">
59  <para>The string representing the name of the host on which Asterisk was configured, is returned.</para>
60  </enum>
61  <enum name="BUILD_MACHINE">
62  <para>The string representing the type of machine on which Asterisk was configured, is returned.</para>
63  </enum>
64  <enum name="BUILD_OS">
65  <para>The string representing the OS of the machine on which Asterisk was configured, is returned.</para>
66  </enum>
67  <enum name="BUILD_DATE">
68  <para>The string representing the date on which Asterisk was configured, is returned.</para>
69  </enum>
70  <enum name="BUILD_KERNEL">
71  <para>The string representing the kernel version of the machine on which Asterisk
72  was configured, is returned.</para>
73  </enum>
74  </enumlist>
75  </parameter>
76  </syntax>
77  <description>
78  <para>If there are no arguments, return the version of Asterisk in this format: SVN-branch-1.4-r44830M</para>
79  <para>Example: Set(junky=${VERSION()};</para>
80  <para>Sets junky to the string <literal>SVN-branch-1.6-r74830M</literal>, or possibly, <literal>SVN-trunk-r45126M</literal>.</para>
81  </description>
82  </function>
83  ***/
84 
85 static int acf_version_exec(struct ast_channel *chan, const char *cmd,
86  char *parse, char *buffer, size_t buflen)
87 {
88  const char *response_char = ast_get_version();
90  AST_APP_ARG(info);
91  );
92 
94 
95  if (!ast_strlen_zero(args.info) ) {
96  if (!strcasecmp(args.info,"ASTERISK_VERSION_NUM"))
97  response_char = ast_get_version_num();
98  else if (!strcasecmp(args.info,"BUILD_USER"))
99  response_char = BUILD_USER;
100  else if (!strcasecmp(args.info,"BUILD_HOSTNAME"))
101  response_char = BUILD_HOSTNAME;
102  else if (!strcasecmp(args.info,"BUILD_MACHINE"))
103  response_char = BUILD_MACHINE;
104  else if (!strcasecmp(args.info,"BUILD_KERNEL"))
105  response_char = BUILD_KERNEL;
106  else if (!strcasecmp(args.info,"BUILD_OS"))
107  response_char = BUILD_OS;
108  else if (!strcasecmp(args.info,"BUILD_DATE"))
109  response_char = BUILD_DATE;
110  }
111 
112  ast_debug(1, "VERSION returns %s result, given %s argument\n", response_char, args.info);
113 
114  ast_copy_string(buffer, response_char, buflen);
115 
116  return 0;
117 }
118 
120  .name = "VERSION",
121  .read = acf_version_exec,
122 };
123 
124 static int unload_module(void)
125 {
126  ast_custom_function_unregister(&acf_version);
127 
128  return 0;
129 }
130 
131 static int load_module(void)
132 {
133  return ast_custom_function_register(&acf_version);
134 }
135 
136 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get Asterisk Version/Build Info");
#define BUILD_KERNEL
Definition: build.h:6
Main Channel structure associated with a channel.
Definition: channel.h:742
#define BUILD_MACHINE
Definition: build.h:7
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk main include file. File version handling, generic pbx functions.
Asterisk version information.
const char * ast_get_version(void)
Retrieve the Asterisk version string.
Definition: version.c:14
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
#define BUILD_USER
Definition: build.h:10
#define BUILD_DATE
Definition: build.h:9
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
Utility functions.
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
General Asterisk PBX channel definitions.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
Data structure associated with a custom dialplan function.
Definition: pbx.h:95
static int acf_version_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
Definition: func_version.c:85
Core PBX routines and definitions.
static int load_module(void)
Definition: func_version.c:131
static struct @350 args
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
static int unload_module(void)
Definition: func_version.c:124
const char * ast_get_version_num(void)
Retrieve the numeric Asterisk version.
Definition: version.c:19
#define BUILD_HOSTNAME
Definition: build.h:5
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define BUILD_OS
Definition: build.h:8
const char * name
Definition: pbx.h:96
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
static struct ast_custom_function acf_version
Definition: func_version.c:119
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180