diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 563972f5a4..56a23e8879 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -3122,6 +3122,69 @@ SWITCH_STANDARD_API(oz_function) } } stream->write_function(stream, "+OK gains set to Rx %f and Tx %f\n", rxgain, txgain); + } else if (!strcasecmp(argv[0], "trace")) { + char tracepath[255]; + int i = 0; + uint32_t chan_id = 0; + zap_span_t *span = NULL; + if (argc < 3) { + stream->write_function(stream, "-ERR Usage: oz trace []\n"); + goto end; + } + zap_span_find_by_name(argv[2], &span); + if (!span) { + stream->write_function(stream, "-ERR invalid span\n"); + goto end; + } + if (argc > 3) { + chan_id = atoi(argv[3]); + if (chan_id > span->chan_count) { + stream->write_function(stream, "-ERR invalid chan\n"); + goto end; + } + } + if (chan_id) { + snprintf(tracepath, sizeof(tracepath), "%s-in-c%d", argv[1], chan_id); + zap_channel_command(span->channels[chan_id], ZAP_COMMAND_TRACE_INPUT, tracepath); + snprintf(tracepath, sizeof(tracepath), "%s-out-c%d", argv[1], chan_id); + zap_channel_command(span->channels[chan_id], ZAP_COMMAND_TRACE_OUTPUT, tracepath); + } else { + for (i = 1; i < (int)span->chan_count; i++) { + snprintf(tracepath, sizeof(tracepath), "%s-in-c%d", argv[1], i); + zap_channel_command(span->channels[i], ZAP_COMMAND_TRACE_INPUT, tracepath); + snprintf(tracepath, sizeof(tracepath), "%s-out-c%d", argv[1], i); + zap_channel_command(span->channels[i], ZAP_COMMAND_TRACE_OUTPUT, tracepath); + } + } + stream->write_function(stream, "+OK trace enabled with prefix path %s\n", argv[1]); + } else if (!strcasecmp(argv[0], "notrace")) { + uint32_t i = 0; + uint32_t chan_id = 0; + zap_span_t *span = NULL; + if (argc < 2) { + stream->write_function(stream, "-ERR Usage: oz notrace []\n"); + goto end; + } + zap_span_find_by_name(argv[1], &span); + if (!span) { + stream->write_function(stream, "-ERR invalid span\n"); + goto end; + } + if (argc > 2) { + chan_id = atoi(argv[2]); + if (chan_id > span->chan_count) { + stream->write_function(stream, "-ERR invalid chan\n"); + goto end; + } + } + if (chan_id) { + zap_channel_command(span->channels[chan_id], ZAP_COMMAND_TRACE_END_ALL, NULL); + } else { + for (i = 1; i < (int)span->chan_count; i++) { + zap_channel_command(span->channels[i], ZAP_COMMAND_TRACE_END_ALL, NULL); + } + } + stream->write_function(stream, "+OK trace disabled\n"); } else { char *rply = zap_api_execute(cmd, NULL); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index a97f98abd7..1e9a00502d 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -277,6 +277,7 @@ typedef enum { ZAP_COMMAND_DISABLE_PROGRESS_DETECT, ZAP_COMMAND_TRACE_INPUT, ZAP_COMMAND_TRACE_OUTPUT, + ZAP_COMMAND_TRACE_END_ALL, ZAP_COMMAND_ENABLE_CALLERID_DETECT, ZAP_COMMAND_DISABLE_CALLERID_DETECT, ZAP_COMMAND_ENABLE_ECHOCANCEL, diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index dc747d9429..38166d26d4 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1519,6 +1519,18 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t GOTO_STATUS(done, ZAP_FAIL); } break; + case ZAP_COMMAND_TRACE_END_ALL: + { + if (zchan->fds[0] > 0) { + close(zchan->fds[0]); + zchan->fds[0] = -1; + } + if (zchan->fds[1] > 0) { + close(zchan->fds[1]); + zchan->fds[1] = -1; + } + GOTO_STATUS(done, ZAP_SUCCESS); + } case ZAP_COMMAND_SET_INTERVAL: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL)) {