app_dumpchan.c 4.6 KB

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