func_version.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. /*! \file
  17. *
  18. * \brief Return the current Version strings
  19. *
  20. * \author Steve Murphy (murf@digium.com)
  21. * \ingroup functions
  22. */
  23. /*** MODULEINFO
  24. <support_level>core</support_level>
  25. ***/
  26. #include "asterisk.h"
  27. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  28. #include "asterisk/module.h"
  29. #include "asterisk/channel.h"
  30. #include "asterisk/pbx.h"
  31. #include "asterisk/utils.h"
  32. #include "asterisk/app.h"
  33. #include "asterisk/ast_version.h"
  34. #include "asterisk/build.h"
  35. /*** DOCUMENTATION
  36. <function name="VERSION" language="en_US">
  37. <synopsis>
  38. Return the Version info for this Asterisk.
  39. </synopsis>
  40. <syntax>
  41. <parameter name="info">
  42. <para>The possible values are:</para>
  43. <enumlist>
  44. <enum name="ASTERISK_VERSION_NUM">
  45. <para>A string of digits is returned (right now fixed at 999999).</para>
  46. </enum>
  47. <enum name="BUILD_USER">
  48. <para>The string representing the user's name whose account
  49. was used to configure Asterisk, is returned.</para>
  50. </enum>
  51. <enum name="BUILD_HOSTNAME">
  52. <para>The string representing the name of the host on which Asterisk was configured, is returned.</para>
  53. </enum>
  54. <enum name="BUILD_MACHINE">
  55. <para>The string representing the type of machine on which Asterisk was configured, is returned.</para>
  56. </enum>
  57. <enum name="BUILD_OS">
  58. <para>The string representing the OS of the machine on which Asterisk was configured, is returned.</para>
  59. </enum>
  60. <enum name="BUILD_DATE">
  61. <para>The string representing the date on which Asterisk was configured, is returned.</para>
  62. </enum>
  63. <enum name="BUILD_KERNEL">
  64. <para>The string representing the kernel version of the machine on which Asterisk
  65. was configured, is returned.</para>
  66. </enum>
  67. </enumlist>
  68. </parameter>
  69. </syntax>
  70. <description>
  71. <para>If there are no arguments, return the version of Asterisk in this format: SVN-branch-1.4-r44830M</para>
  72. <para>Example: Set(junky=${VERSION()};</para>
  73. <para>Sets junky to the string <literal>SVN-branch-1.6-r74830M</literal>, or possibly, <literal>SVN-trunk-r45126M</literal>.</para>
  74. </description>
  75. </function>
  76. ***/
  77. static int acf_version_exec(struct ast_channel *chan, const char *cmd,
  78. char *parse, char *buffer, size_t buflen)
  79. {
  80. const char *response_char = ast_get_version();
  81. AST_DECLARE_APP_ARGS(args,
  82. AST_APP_ARG(info);
  83. );
  84. AST_STANDARD_APP_ARGS(args, parse);
  85. if (!ast_strlen_zero(args.info) ) {
  86. if (!strcasecmp(args.info,"ASTERISK_VERSION_NUM"))
  87. response_char = ast_get_version_num();
  88. else if (!strcasecmp(args.info,"BUILD_USER"))
  89. response_char = BUILD_USER;
  90. else if (!strcasecmp(args.info,"BUILD_HOSTNAME"))
  91. response_char = BUILD_HOSTNAME;
  92. else if (!strcasecmp(args.info,"BUILD_MACHINE"))
  93. response_char = BUILD_MACHINE;
  94. else if (!strcasecmp(args.info,"BUILD_KERNEL"))
  95. response_char = BUILD_KERNEL;
  96. else if (!strcasecmp(args.info,"BUILD_OS"))
  97. response_char = BUILD_OS;
  98. else if (!strcasecmp(args.info,"BUILD_DATE"))
  99. response_char = BUILD_DATE;
  100. }
  101. ast_debug(1, "VERSION returns %s result, given %s argument\n", response_char, args.info);
  102. ast_copy_string(buffer, response_char, buflen);
  103. return 0;
  104. }
  105. static struct ast_custom_function acf_version = {
  106. .name = "VERSION",
  107. .read = acf_version_exec,
  108. };
  109. static int unload_module(void)
  110. {
  111. ast_custom_function_unregister(&acf_version);
  112. return 0;
  113. }
  114. static int load_module(void)
  115. {
  116. return ast_custom_function_register(&acf_version);
  117. }
  118. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get Asterisk Version/Build Info");