/apps/app_dumpchan.c

https://github.com/yclee/astlite · C · 176 lines · 124 code · 24 blank · 28 comment · 4 complexity · 16192ee9b50e4ae6bd4336176e82cbc5 MD5 · raw file

  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2004 - 2005, Anthony Minessale II.
  5. *
  6. * Anthony Minessale <anthmct@yahoo.com>
  7. *
  8. * A license has been granted to Digium (via disclaimer) for the use of
  9. * this code.
  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. * This program is free software, distributed under the terms of
  18. * the GNU General Public License Version 2. See the LICENSE file
  19. * at the top of the source tree.
  20. */
  21. /*! \file
  22. *
  23. * \brief Application to dump channel variables
  24. *
  25. * \author Anthony Minessale <anthmct@yahoo.com>
  26. *
  27. * \ingroup applications
  28. */
  29. #include "asterisk.h"
  30. ASTERISK_FILE_VERSION(__FILE__, "$Revision: 40722 $")
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33. #include <string.h>
  34. #include <unistd.h>
  35. #include "asterisk/file.h"
  36. #include "asterisk/logger.h"
  37. #include "asterisk/channel.h"
  38. #include "asterisk/pbx.h"
  39. #include "asterisk/module.h"
  40. #include "asterisk/options.h"
  41. #include "asterisk/utils.h"
  42. #include "asterisk/lock.h"
  43. #include "asterisk/utils.h"
  44. static char *app = "DumpChan";
  45. static char *synopsis = "Dump Info About The Calling Channel";
  46. static char *desc =
  47. " DumpChan([<min_verbose_level>])\n"
  48. "Displays information on channel and listing of all channel\n"
  49. "variables. If min_verbose_level is specified, output is only\n"
  50. "displayed when the verbose level is currently set to that number\n"
  51. "or greater. \n";
  52. static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
  53. {
  54. struct timeval now;
  55. long elapsed_seconds = 0;
  56. int hour = 0, min = 0, sec = 0;
  57. char cgrp[BUFSIZ/2];
  58. char pgrp[BUFSIZ/2];
  59. char formatbuf[BUFSIZ/2];
  60. now = ast_tvnow();
  61. memset(buf, 0, size);
  62. if (!c)
  63. return 0;
  64. if (c->cdr) {
  65. elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
  66. hour = elapsed_seconds / 3600;
  67. min = (elapsed_seconds % 3600) / 60;
  68. sec = elapsed_seconds % 60;
  69. }
  70. snprintf(buf,size,
  71. "Name= %s\n"
  72. "Type= %s\n"
  73. "UniqueID= %s\n"
  74. "CallerID= %s\n"
  75. "CallerIDName= %s\n"
  76. "DNIDDigits= %s\n"
  77. "RDNIS= %s\n"
  78. "State= %s (%d)\n"
  79. "Rings= %d\n"
  80. "NativeFormat= %s\n"
  81. "WriteFormat= %s\n"
  82. "ReadFormat= %s\n"
  83. "1stFileDescriptor= %d\n"
  84. "Framesin= %d %s\n"
  85. "Framesout= %d %s\n"
  86. "TimetoHangup= %ld\n"
  87. "ElapsedTime= %dh%dm%ds\n"
  88. "Context= %s\n"
  89. "Extension= %s\n"
  90. "Priority= %d\n"
  91. "CallGroup= %s\n"
  92. "PickupGroup= %s\n"
  93. "Application= %s\n"
  94. "Data= %s\n"
  95. "Blocking_in= %s\n",
  96. c->name,
  97. c->tech->type,
  98. c->uniqueid,
  99. S_OR(c->cid.cid_num, "(N/A)"),
  100. S_OR(c->cid.cid_name, "(N/A)"),
  101. S_OR(c->cid.cid_dnid, "(N/A)"),
  102. S_OR(c->cid.cid_rdnis, "(N/A)"),
  103. ast_state2str(c->_state),
  104. c->_state,
  105. c->rings,
  106. ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->nativeformats),
  107. ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->writeformat),
  108. ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->readformat),
  109. c->fds[0], c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
  110. c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "", (long)c->whentohangup,
  111. hour,
  112. min,
  113. sec,
  114. c->context,
  115. c->exten,
  116. c->priority,
  117. ast_print_group(cgrp, sizeof(cgrp), c->callgroup),
  118. ast_print_group(pgrp, sizeof(pgrp), c->pickupgroup),
  119. ( c->appl ? c->appl : "(N/A)" ),
  120. ( c-> data ? S_OR(c->data, "(Empty)") : "(None)"),
  121. (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
  122. return 0;
  123. }
  124. static int dumpchan_exec(struct ast_channel *chan, void *data)
  125. {
  126. struct ast_module_user *u;
  127. char vars[BUFSIZ * 4];
  128. char info[1024];
  129. int level = 0;
  130. static char *line = "================================================================================";
  131. u = ast_module_user_add(chan);
  132. if (!ast_strlen_zero(data))
  133. level = atoi(data);
  134. pbx_builtin_serialize_variables(chan, vars, sizeof(vars));
  135. serialize_showchan(chan, info, sizeof(info));
  136. if (option_verbose >= level)
  137. ast_verbose("\nDumping Info For Channel: %s:\n%s\nInfo:\n%s\nVariables:\n%s%s\n", chan->name, line, info, vars, line);
  138. ast_module_user_remove(u);
  139. return 0;
  140. }
  141. static int unload_module(void)
  142. {
  143. int res;
  144. res = ast_unregister_application(app);
  145. ast_module_user_hangup_all();
  146. return res;
  147. }
  148. static int load_module(void)
  149. {
  150. return ast_register_application(app, dumpchan_exec, synopsis, desc);
  151. }
  152. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel");