app_sayunixtime.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (c) 2003, 2006 Tilghman Lesher. All rights reserved.
  5. * Copyright (c) 2006 Digium, Inc.
  6. *
  7. * Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com>
  8. *
  9. * This code is released by the author with no restrictions on usage.
  10. *
  11. * See http://www.asterisk.org for more information about
  12. * the Asterisk project. Please do not directly contact
  13. * any of the maintainers of this project for assistance;
  14. * the project provides a web site, mailing lists and IRC
  15. * channels for your use.
  16. *
  17. */
  18. /*! \file
  19. *
  20. * \brief SayUnixTime application
  21. *
  22. * \author Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com>
  23. *
  24. * \ingroup applications
  25. */
  26. /*** MODULEINFO
  27. <support_level>core</support_level>
  28. ***/
  29. #include "asterisk.h"
  30. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  31. #include "asterisk/file.h"
  32. #include "asterisk/channel.h"
  33. #include "asterisk/pbx.h"
  34. #include "asterisk/module.h"
  35. #include "asterisk/say.h"
  36. #include "asterisk/app.h"
  37. /*** DOCUMENTATION
  38. <application name="SayUnixTime" language="en_US">
  39. <synopsis>
  40. Says a specified time in a custom format.
  41. </synopsis>
  42. <syntax>
  43. <parameter name="unixtime">
  44. <para>time, in seconds since Jan 1, 1970. May be negative. Defaults to now.</para>
  45. </parameter>
  46. <parameter name="timezone">
  47. <para>timezone, see <directory>/usr/share/zoneinfo</directory> for a list. Defaults to machine default.</para>
  48. </parameter>
  49. <parameter name="format">
  50. <para>a format the time is to be said in. See <filename>voicemail.conf</filename>.
  51. Defaults to <literal>ABdY "digits/at" IMp</literal></para>
  52. </parameter>
  53. </syntax>
  54. <description>
  55. <para>Uses some of the sound files stored in <directory>/var/lib/asterisk/sounds</directory> to construct a phrase
  56. saying the specified date and/or time in the specified format. </para>
  57. </description>
  58. <see-also>
  59. <ref type="function">STRFTIME</ref>
  60. <ref type="function">STRPTIME</ref>
  61. <ref type="function">IFTIME</ref>
  62. </see-also>
  63. </application>
  64. <application name="DateTime" language="en_US">
  65. <synopsis>
  66. Says a specified time in a custom format.
  67. </synopsis>
  68. <syntax>
  69. <parameter name="unixtime">
  70. <para>time, in seconds since Jan 1, 1970. May be negative. Defaults to now.</para>
  71. </parameter>
  72. <parameter name="timezone">
  73. <para>timezone, see <filename>/usr/share/zoneinfo</filename> for a list. Defaults to machine default.</para>
  74. </parameter>
  75. <parameter name="format">
  76. <para>a format the time is to be said in. See <filename>voicemail.conf</filename>.
  77. Defaults to <literal>ABdY "digits/at" IMp</literal></para>
  78. </parameter>
  79. </syntax>
  80. <description>
  81. <para>Say the date and time in a specified format.</para>
  82. </description>
  83. </application>
  84. ***/
  85. static char *app_sayunixtime = "SayUnixTime";
  86. static char *app_datetime = "DateTime";
  87. static int sayunixtime_exec(struct ast_channel *chan, const char *data)
  88. {
  89. AST_DECLARE_APP_ARGS(args,
  90. AST_APP_ARG(timeval);
  91. AST_APP_ARG(timezone);
  92. AST_APP_ARG(format);
  93. );
  94. char *parse;
  95. int res = 0;
  96. time_t unixtime;
  97. if (!data)
  98. return 0;
  99. parse = ast_strdupa(data);
  100. AST_STANDARD_APP_ARGS(args, parse);
  101. ast_get_time_t(args.timeval, &unixtime, time(NULL), NULL);
  102. if (chan->_state != AST_STATE_UP)
  103. res = ast_answer(chan);
  104. if (!res)
  105. res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY,
  106. chan->language, args.format, args.timezone);
  107. return res;
  108. }
  109. static int unload_module(void)
  110. {
  111. int res;
  112. res = ast_unregister_application(app_sayunixtime);
  113. res |= ast_unregister_application(app_datetime);
  114. return res;
  115. }
  116. static int load_module(void)
  117. {
  118. int res;
  119. res = ast_register_application_xml(app_sayunixtime, sayunixtime_exec);
  120. res |= ast_register_application_xml(app_datetime, sayunixtime_exec);
  121. return res;
  122. }
  123. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say time");