func_version.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #include "asterisk.h"
  24. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  25. #include "asterisk/module.h"
  26. #include "asterisk/channel.h"
  27. #include "asterisk/pbx.h"
  28. #include "asterisk/utils.h"
  29. #include "asterisk/app.h"
  30. #include "asterisk/ast_version.h"
  31. #include "asterisk/build.h"
  32. static int acf_version_exec(struct ast_channel *chan, const char *cmd,
  33. char *parse, char *buffer, size_t buflen)
  34. {
  35. const char *response_char = ast_get_version();
  36. AST_DECLARE_APP_ARGS(args,
  37. AST_APP_ARG(info);
  38. );
  39. AST_STANDARD_APP_ARGS(args, parse);
  40. if (!ast_strlen_zero(args.info) ) {
  41. if (!strcasecmp(args.info,"ASTERISK_VERSION_NUM"))
  42. response_char = ast_get_version_num();
  43. else if (!strcasecmp(args.info,"BUILD_USER"))
  44. response_char = BUILD_USER;
  45. else if (!strcasecmp(args.info,"BUILD_HOSTNAME"))
  46. response_char = BUILD_HOSTNAME;
  47. else if (!strcasecmp(args.info,"BUILD_MACHINE"))
  48. response_char = BUILD_MACHINE;
  49. else if (!strcasecmp(args.info,"BUILD_KERNEL"))
  50. response_char = BUILD_KERNEL;
  51. else if (!strcasecmp(args.info,"BUILD_OS"))
  52. response_char = BUILD_OS;
  53. else if (!strcasecmp(args.info,"BUILD_DATE"))
  54. response_char = BUILD_DATE;
  55. }
  56. ast_debug(1, "VERSION returns %s result, given %s argument\n", response_char, args.info);
  57. ast_copy_string(buffer, response_char, buflen);
  58. return 0;
  59. }
  60. static struct ast_custom_function acf_version = {
  61. .name = "VERSION",
  62. .synopsis = "Return the Version info for this Asterisk",
  63. .syntax = "VERSION([info])",
  64. .desc =
  65. "If there are no arguments, return the version of Asterisk in this format: SVN-branch-1.4-r44830M\n"
  66. "If the argument is 'ASTERISK_VERSION_NUM', a string of digits is returned (right now fixed at 999999).\n"
  67. "If the argument is 'BUILD_USER', the string representing the user's name whose account was used to configure Asterisk, is returned.\n"
  68. "If the argument is 'BUILD_HOSTNAME', the string representing the name of the host on which Asterisk was configured, is returned.\n"
  69. "If the argument is 'BUILD_MACHINE', the string representing the type of machine on which Asterisk was configured, is returned.\n"
  70. "If the argument is 'BUILD_OS', the string representing the OS of the machine on which Asterisk was configured, is returned.\n"
  71. "If the argument is 'BUILD_DATE', the string representing the date on which Asterisk was configured, is returned.\n"
  72. "If the argument is 'BUILD_KERNEL', the string representing the kernel version of the machine on which Asterisk was configured, is returned .\n"
  73. " Example: Set(junky=${VERSION()}; \n"
  74. " Sets junky to the string 'SVN-branch-1.6-r74830M', or possibly, 'SVN-trunk-r45126M'.\n",
  75. .read = acf_version_exec,
  76. };
  77. static int unload_module(void)
  78. {
  79. ast_custom_function_unregister(&acf_version);
  80. return 0;
  81. }
  82. static int load_module(void)
  83. {
  84. return ast_custom_function_register(&acf_version);
  85. }
  86. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get Asterisk Version/Build Info");