summaryrefslogtreecommitdiff
path: root/res/res_fax_spandsp.c
diff options
context:
space:
mode:
authorJonathan Rose <jrose@digium.com>2014-07-18 15:49:46 +0000
committerJonathan Rose <jrose@digium.com>2014-07-18 15:49:46 +0000
commit5c988cc4e6c5693f03080f88e3057cb7a5358597 (patch)
tree63fc4304613e087700537d6ca35c5f0b1b495508 /res/res_fax_spandsp.c
parentdd23637195bf83d6b4cee2c88caf3c2ae5dbc8a5 (diff)
res_fax: Provide AMI equivalents for fax CLI commands
Specifically the following equivalents were created: fax show session -> FAXSession fax show sessions -> FAXSessions fax show stats -> FAXStats Review: https://reviewboard.asterisk.org/r/3666/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@418911 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_fax_spandsp.c')
-rw-r--r--res/res_fax_spandsp.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/res/res_fax_spandsp.c b/res/res_fax_spandsp.c
index 015e69704..96fd83d76 100644
--- a/res/res_fax_spandsp.c
+++ b/res/res_fax_spandsp.c
@@ -86,6 +86,8 @@ static void spandsp_v21_tone(void *data, int code, int level, int delay);
static char *spandsp_fax_cli_show_capabilities(int fd);
static char *spandsp_fax_cli_show_session(struct ast_fax_session *s, int fd);
+static void spandsp_manager_fax_session(struct mansession *s,
+ const char *id_text, struct ast_fax_session *session);
static char *spandsp_fax_cli_show_stats(int fd);
static char *spandsp_fax_cli_show_settings(int fd);
@@ -113,6 +115,7 @@ static struct ast_fax_tech spandsp_fax_tech = {
.switch_to_t38 = spandsp_fax_switch_to_t38,
.cli_show_capabilities = spandsp_fax_cli_show_capabilities,
.cli_show_session = spandsp_fax_cli_show_session,
+ .manager_fax_session = spandsp_manager_fax_session,
.cli_show_stats = spandsp_fax_cli_show_stats,
.cli_show_settings = spandsp_fax_cli_show_settings,
};
@@ -1073,6 +1076,97 @@ static char *spandsp_fax_cli_show_session(struct ast_fax_session *s, int fd)
return CLI_SUCCESS;
}
+static void spandsp_manager_fax_session(struct mansession *s,
+ const char *id_text, struct ast_fax_session *session)
+{
+ struct ast_str *message_string;
+ struct spandsp_pvt *span_pvt = session->tech_pvt;
+ int res;
+
+ message_string = ast_str_create(128);
+
+ if (!message_string) {
+ return;
+ }
+
+ ao2_lock(session);
+ res = ast_str_append(&message_string, 0, "SessionNumber: %d\r\n", session->id);
+ res |= ast_str_append(&message_string, 0, "Operation: %s\r\n", ast_fax_session_operation_str(session));
+ res |= ast_str_append(&message_string, 0, "State: %s\r\n", ast_fax_state_to_str(session->state));
+
+ if (session->details->caps & AST_FAX_TECH_GATEWAY) {
+ t38_stats_t stats;
+
+ if (session->state == AST_FAX_STATE_UNINITIALIZED) {
+ goto skip_cap_additions;
+ }
+
+ t38_gateway_get_transfer_statistics(&span_pvt->t38_gw_state, &stats);
+ res |= ast_str_append(&message_string, 0, "ErrorCorrectionMode: %s\r\n",
+ stats.error_correcting_mode ? "yes" : "no");
+ res |= ast_str_append(&message_string, 0, "DataRate: %d\r\n",
+ stats.bit_rate);
+ res |= ast_str_append(&message_string, 0, "PageNumber: %d\r\n",
+ stats.pages_transferred + 1);
+ } else if (!(session->details->caps & AST_FAX_TECH_V21_DETECT)) { /* caps is SEND/RECEIVE */
+ t30_stats_t stats;
+
+ if (session->state == AST_FAX_STATE_UNINITIALIZED) {
+ goto skip_cap_additions;
+ }
+
+ t30_get_transfer_statistics(span_pvt->t30_state, &stats);
+ res |= ast_str_append(&message_string, 0, "ErrorCorrectionMode: %s\r\n",
+ stats.error_correcting_mode ? "Yes" : "No");
+ res |= ast_str_append(&message_string, 0, "DataRate: %d\r\n",
+ stats.bit_rate);
+ res |= ast_str_append(&message_string, 0, "ImageResolution: %dx%d\r\n",
+ stats.x_resolution, stats.y_resolution);
+#if SPANDSP_RELEASE_DATE >= 20090220
+ res |= ast_str_append(&message_string, 0, "PageNumber: %d\r\n",
+ ((session->details->caps & AST_FAX_TECH_RECEIVE) ? stats.pages_rx : stats.pages_tx) + 1);
+#else
+ res |= ast_str_append(&message_string, 0, "PageNumber: %d\r\n",
+ stats.pages_transferred + 1);
+#endif
+ res |= ast_str_append(&message_string, 0, "FileName: %s\r\n",
+ session->details->caps & AST_FAX_TECH_RECEIVE ? span_pvt->t30_state->rx_file :
+ span_pvt->t30_state->tx_file);
+#if SPANDSP_RELEASE_DATE >= 20090220
+ res |= ast_str_append(&message_string, 0, "PagesTransmitted: %d\r\n",
+ stats.pages_tx);
+ res |= ast_str_append(&message_string, 0, "PagesReceived: %d\r\n",
+ stats.pages_rx);
+#else
+ res |= ast_str_append(&message_string, 0, "PagesTransmitted: %d\r\n",
+ (session->details->caps & AST_FAX_TECH_SEND) ? stats.pages_transferred : 0);
+ res |= ast_str_append(&message_string, 0, "PagesReceived: %d\r\n",
+ (session->details->caps & AST_FAX_TECH_RECEIVE) ? stats.pages_transferred : 0);
+#endif
+ res |= ast_str_append(&message_string, 0, "TotalBadLines: %d\r\n",
+ stats.bad_rows);
+ }
+
+skip_cap_additions:
+
+ ao2_unlock(session);
+
+ if (res < 0) {
+ /* One or more of the ast_str_append attempts failed, cancel the message */
+ ast_free(message_string);
+ return;
+ }
+
+ astman_append(s, "Event: FAXSession\r\n"
+ "%s"
+ "%s"
+ "\r\n",
+ id_text,
+ ast_str_buffer(message_string));
+
+ ast_free(message_string);
+}
+
/*! \brief */
static char *spandsp_fax_cli_show_stats(int fd)
{