app_verbose.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * Verbose application
  5. *
  6. * Copyright (c) 2004 Tilghman Lesher. All rights reserved.
  7. *
  8. * Tilghman Lesher <app_verbose_v001@the-tilghman.com>
  9. *
  10. * This code is released by the author with no restrictions on usage.
  11. *
  12. */
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <unistd.h>
  16. #include <string.h>
  17. #include <asterisk/options.h>
  18. #include <asterisk/logger.h>
  19. #include <asterisk/channel.h>
  20. #include <asterisk/pbx.h>
  21. #include <asterisk/module.h>
  22. static char *tdesc = "Send verbose output";
  23. static char *app_verbose = "Verbose";
  24. static char *verbose_synopsis = "Send arbitrary text to verbose output";
  25. static char *verbose_descrip =
  26. "Verbose([<level>|]<message>)\n"
  27. " level must be an integer value. If not specified, defaults to 0."
  28. " Always returns 0.\n";
  29. STANDARD_LOCAL_USER;
  30. LOCAL_USER_DECL;
  31. static int verbose_exec(struct ast_channel *chan, void *data)
  32. {
  33. char *vtext;
  34. int vsize;
  35. if (data) {
  36. vtext = ast_strdupa((char *)data);
  37. if (vtext) {
  38. char *tmp = strsep(&vtext, "|,");
  39. if (vtext) {
  40. if (sscanf(tmp, "%d", &vsize) != 1) {
  41. vsize = 0;
  42. ast_log(LOG_WARNING, "'%s' is not a verboser number\n", vtext);
  43. }
  44. } else {
  45. vtext = tmp;
  46. vsize = 0;
  47. }
  48. if (option_verbose >= vsize) {
  49. switch (vsize) {
  50. case 0:
  51. ast_verbose("%s\n", vtext);
  52. break;
  53. case 1:
  54. ast_verbose(VERBOSE_PREFIX_1 "%s\n", vtext);
  55. break;
  56. case 2:
  57. ast_verbose(VERBOSE_PREFIX_2 "%s\n", vtext);
  58. break;
  59. case 3:
  60. ast_verbose(VERBOSE_PREFIX_3 "%s\n", vtext);
  61. break;
  62. default:
  63. ast_verbose(VERBOSE_PREFIX_4 "%s\n", vtext);
  64. }
  65. }
  66. } else {
  67. ast_log(LOG_ERROR, "Out of memory\n");
  68. }
  69. }
  70. return 0;
  71. }
  72. int unload_module(void)
  73. {
  74. STANDARD_HANGUP_LOCALUSERS;
  75. return ast_unregister_application(app_verbose);
  76. }
  77. int load_module(void)
  78. {
  79. return ast_register_application(app_verbose, verbose_exec, verbose_synopsis, verbose_descrip);
  80. }
  81. char *description(void)
  82. {
  83. return tdesc;
  84. }
  85. int usecount(void)
  86. {
  87. int res;
  88. STANDARD_USECOUNT(res);
  89. return res;
  90. }
  91. char *key()
  92. {
  93. return ASTERISK_GPL_KEY;
  94. }