app_dumpchan.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. /*** MODULEINFO
  30. <support_level>core</support_level>
  31. ***/
  32. #include "asterisk.h"
  33. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  34. #include "asterisk/pbx.h"
  35. #include "asterisk/module.h"
  36. #include "asterisk/channel.h"
  37. #include "asterisk/app.h"
  38. #include "asterisk/translate.h"
  39. #include "asterisk/bridge.h"
  40. /*** DOCUMENTATION
  41. <application name="DumpChan" language="en_US">
  42. <synopsis>
  43. Dump Info About The Calling Channel.
  44. </synopsis>
  45. <syntax>
  46. <parameter name="level">
  47. <para>Minimum verbose level</para>
  48. </parameter>
  49. </syntax>
  50. <description>
  51. <para>Displays information on channel and listing of all channel
  52. variables. If <replaceable>level</replaceable> is specified, output is only
  53. displayed when the verbose level is currently set to that number
  54. or greater.</para>
  55. </description>
  56. <see-also>
  57. <ref type="application">NoOp</ref>
  58. <ref type="application">Verbose</ref>
  59. </see-also>
  60. </application>
  61. ***/
  62. static const char app[] = "DumpChan";
  63. static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
  64. {
  65. long elapsed_seconds = 0;
  66. int hour = 0, min = 0, sec = 0;
  67. struct ast_str *format_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
  68. char cgrp[256];
  69. char pgrp[256];
  70. struct ast_str *write_transpath = ast_str_alloca(256);
  71. struct ast_str *read_transpath = ast_str_alloca(256);
  72. struct ast_bridge *bridge;
  73. memset(buf, 0, size);
  74. if (!c)
  75. return 0;
  76. elapsed_seconds = ast_channel_get_duration(c);
  77. hour = elapsed_seconds / 3600;
  78. min = (elapsed_seconds % 3600) / 60;
  79. sec = elapsed_seconds % 60;
  80. ast_channel_lock(c);
  81. bridge = ast_channel_get_bridge(c);
  82. snprintf(buf,size,
  83. "Name= %s\n"
  84. "Type= %s\n"
  85. "UniqueID= %s\n"
  86. "LinkedID= %s\n"
  87. "CallerIDNum= %s\n"
  88. "CallerIDName= %s\n"
  89. "ConnectedLineIDNum= %s\n"
  90. "ConnectedLineIDName=%s\n"
  91. "DNIDDigits= %s\n"
  92. "RDNIS= %s\n"
  93. "Parkinglot= %s\n"
  94. "Language= %s\n"
  95. "State= %s (%u)\n"
  96. "Rings= %d\n"
  97. "NativeFormat= %s\n"
  98. "WriteFormat= %s\n"
  99. "ReadFormat= %s\n"
  100. "RawWriteFormat= %s\n"
  101. "RawReadFormat= %s\n"
  102. "WriteTranscode= %s %s\n"
  103. "ReadTranscode= %s %s\n"
  104. "1stFileDescriptor= %d\n"
  105. "Framesin= %u %s\n"
  106. "Framesout= %u %s\n"
  107. "TimetoHangup= %ld\n"
  108. "ElapsedTime= %dh%dm%ds\n"
  109. "BridgeID= %s\n"
  110. "Context= %s\n"
  111. "Extension= %s\n"
  112. "Priority= %d\n"
  113. "CallGroup= %s\n"
  114. "PickupGroup= %s\n"
  115. "Application= %s\n"
  116. "Data= %s\n"
  117. "Blocking_in= %s\n",
  118. ast_channel_name(c),
  119. ast_channel_tech(c)->type,
  120. ast_channel_uniqueid(c),
  121. ast_channel_linkedid(c),
  122. S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, "(N/A)"),
  123. S_COR(ast_channel_caller(c)->id.name.valid, ast_channel_caller(c)->id.name.str, "(N/A)"),
  124. S_COR(ast_channel_connected(c)->id.number.valid, ast_channel_connected(c)->id.number.str, "(N/A)"),
  125. S_COR(ast_channel_connected(c)->id.name.valid, ast_channel_connected(c)->id.name.str, "(N/A)"),
  126. S_OR(ast_channel_dialed(c)->number.str, "(N/A)"),
  127. S_COR(ast_channel_redirecting(c)->from.number.valid, ast_channel_redirecting(c)->from.number.str, "(N/A)"),
  128. ast_channel_parkinglot(c),
  129. ast_channel_language(c),
  130. ast_state2str(ast_channel_state(c)),
  131. ast_channel_state(c),
  132. ast_channel_rings(c),
  133. ast_format_cap_get_names(ast_channel_nativeformats(c), &format_buf),
  134. ast_format_get_name(ast_channel_writeformat(c)),
  135. ast_format_get_name(ast_channel_readformat(c)),
  136. ast_format_get_name(ast_channel_rawwriteformat(c)),
  137. ast_format_get_name(ast_channel_rawreadformat(c)),
  138. ast_channel_writetrans(c) ? "Yes" : "No",
  139. ast_translate_path_to_str(ast_channel_writetrans(c), &write_transpath),
  140. ast_channel_readtrans(c) ? "Yes" : "No",
  141. ast_translate_path_to_str(ast_channel_readtrans(c), &read_transpath),
  142. ast_channel_fd(c, 0),
  143. ast_channel_fin(c) & ~DEBUGCHAN_FLAG, (ast_channel_fin(c) & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
  144. ast_channel_fout(c) & ~DEBUGCHAN_FLAG, (ast_channel_fout(c) & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
  145. (long)ast_channel_whentohangup(c)->tv_sec,
  146. hour,
  147. min,
  148. sec,
  149. bridge ? bridge->uniqueid : "(Not bridged)",
  150. ast_channel_context(c),
  151. ast_channel_exten(c),
  152. ast_channel_priority(c),
  153. ast_print_group(cgrp, sizeof(cgrp), ast_channel_callgroup(c)),
  154. ast_print_group(pgrp, sizeof(pgrp), ast_channel_pickupgroup(c)),
  155. ast_channel_appl(c) ? ast_channel_appl(c) : "(N/A)",
  156. ast_channel_data(c) ? S_OR(ast_channel_data(c), "(Empty)") : "(None)",
  157. (ast_test_flag(ast_channel_flags(c), AST_FLAG_BLOCKING) ? ast_channel_blockproc(c) : "(Not Blocking)"));
  158. ast_channel_unlock(c);
  159. ao2_cleanup(bridge);
  160. return 0;
  161. }
  162. static int dumpchan_exec(struct ast_channel *chan, const char *data)
  163. {
  164. struct ast_str *vars = ast_str_thread_get(&ast_str_thread_global_buf, 16);
  165. char info[2048];
  166. int level = 0;
  167. static char *line = "================================================================================";
  168. if (!ast_strlen_zero(data))
  169. level = atoi(data);
  170. if (VERBOSITY_ATLEAST(level)) {
  171. serialize_showchan(chan, info, sizeof(info));
  172. pbx_builtin_serialize_variables(chan, &vars);
  173. ast_verb(level, "\n"
  174. "Dumping Info For Channel: %s:\n"
  175. "%s\n"
  176. "Info:\n"
  177. "%s\n"
  178. "Variables:\n"
  179. "%s%s\n", ast_channel_name(chan), line, info, ast_str_buffer(vars), line);
  180. }
  181. return 0;
  182. }
  183. static int unload_module(void)
  184. {
  185. return ast_unregister_application(app);
  186. }
  187. static int load_module(void)
  188. {
  189. return ast_register_application_xml(app, dumpchan_exec);
  190. }
  191. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel");