app_datetime.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * Time of day - Report the time of day
  5. *
  6. * Copyright (C) 1999, Mark Spencer
  7. *
  8. * Mark Spencer <markster@linux-support.net>
  9. *
  10. * This program is free software, distributed under the terms of
  11. * the GNU General Public License
  12. */
  13. #include <asterisk/lock.h>
  14. #include <asterisk/file.h>
  15. #include <asterisk/logger.h>
  16. #include <asterisk/channel.h>
  17. #include <asterisk/pbx.h>
  18. #include <asterisk/module.h>
  19. #include <asterisk/say.h>
  20. #include <stdlib.h>
  21. #include <unistd.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. static char *tdesc = "Date and Time";
  25. static char *app = "DateTime";
  26. static char *synopsis = "Say the date and time";
  27. static char *descrip =
  28. " DateTime(): Says the current date and time. Returns -1 on hangup or 0\n"
  29. "otherwise.\n";
  30. STANDARD_LOCAL_USER;
  31. LOCAL_USER_DECL;
  32. static int datetime_exec(struct ast_channel *chan, void *data)
  33. {
  34. int res=0;
  35. time_t t;
  36. struct localuser *u;
  37. LOCAL_USER_ADD(u);
  38. time(&t);
  39. if (chan->_state != AST_STATE_UP)
  40. res = ast_answer(chan);
  41. if (!res)
  42. res = ast_say_datetime(chan, t, "", chan->language);
  43. LOCAL_USER_REMOVE(u);
  44. return res;
  45. }
  46. int unload_module(void)
  47. {
  48. STANDARD_HANGUP_LOCALUSERS;
  49. return ast_unregister_application(app);
  50. }
  51. int load_module(void)
  52. {
  53. return ast_register_application(app, datetime_exec, synopsis, descrip);
  54. }
  55. char *description(void)
  56. {
  57. return tdesc;
  58. }
  59. int usecount(void)
  60. {
  61. int res;
  62. STANDARD_USECOUNT(res);
  63. return res;
  64. }
  65. char *key()
  66. {
  67. return ASTERISK_GPL_KEY;
  68. }