app_verbose.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (c) 2004 - 2005 Tilghman Lesher. All rights reserved.
  5. *
  6. * Tilghman Lesher <app_verbose_v001@the-tilghman.com>
  7. *
  8. * This code is released by the author with no restrictions on usage.
  9. *
  10. * See http://www.asterisk.org for more information about
  11. * the Asterisk project. Please do not directly contact
  12. * any of the maintainers of this project for assistance;
  13. * the project provides a web site, mailing lists and IRC
  14. * channels for your use.
  15. *
  16. */
  17. /*! \file
  18. *
  19. * \brief Verbose logging application
  20. *
  21. * \ingroup applications
  22. */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <unistd.h>
  26. #include <string.h>
  27. #include "asterisk.h"
  28. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  29. #include "asterisk/options.h"
  30. #include "asterisk/logger.h"
  31. #include "asterisk/channel.h"
  32. #include "asterisk/pbx.h"
  33. #include "asterisk/module.h"
  34. static char *tdesc = "Send verbose output";
  35. static char *app_verbose = "Verbose";
  36. static char *verbose_synopsis = "Send arbitrary text to verbose output";
  37. static char *verbose_descrip =
  38. "Verbose([<level>|]<message>)\n"
  39. " level must be an integer value. If not specified, defaults to 0.\n";
  40. STANDARD_LOCAL_USER;
  41. LOCAL_USER_DECL;
  42. static int verbose_exec(struct ast_channel *chan, void *data)
  43. {
  44. char *vtext;
  45. int vsize;
  46. struct localuser *u;
  47. LOCAL_USER_ADD(u);
  48. if (data) {
  49. vtext = ast_strdupa((char *)data);
  50. if (vtext) {
  51. char *tmp = strsep(&vtext, "|,");
  52. if (vtext) {
  53. if (sscanf(tmp, "%d", &vsize) != 1) {
  54. vsize = 0;
  55. ast_log(LOG_WARNING, "'%s' is not a verboser number\n", vtext);
  56. }
  57. } else {
  58. vtext = tmp;
  59. vsize = 0;
  60. }
  61. if (option_verbose >= vsize) {
  62. switch (vsize) {
  63. case 0:
  64. ast_verbose("%s\n", vtext);
  65. break;
  66. case 1:
  67. ast_verbose(VERBOSE_PREFIX_1 "%s\n", vtext);
  68. break;
  69. case 2:
  70. ast_verbose(VERBOSE_PREFIX_2 "%s\n", vtext);
  71. break;
  72. case 3:
  73. ast_verbose(VERBOSE_PREFIX_3 "%s\n", vtext);
  74. break;
  75. default:
  76. ast_verbose(VERBOSE_PREFIX_4 "%s\n", vtext);
  77. }
  78. }
  79. } else {
  80. ast_log(LOG_ERROR, "Out of memory\n");
  81. }
  82. }
  83. LOCAL_USER_REMOVE(u);
  84. return 0;
  85. }
  86. int unload_module(void)
  87. {
  88. int res;
  89. res = ast_unregister_application(app_verbose);
  90. STANDARD_HANGUP_LOCALUSERS;
  91. return res;
  92. }
  93. int load_module(void)
  94. {
  95. return ast_register_application(app_verbose, verbose_exec, verbose_synopsis, verbose_descrip);
  96. }
  97. char *description(void)
  98. {
  99. return tdesc;
  100. }
  101. int usecount(void)
  102. {
  103. int res;
  104. STANDARD_USECOUNT(res);
  105. return res;
  106. }
  107. char *key()
  108. {
  109. return ASTERISK_GPL_KEY;
  110. }