From 6a842ab21d1c179a2141e057ef9ab9e751655a16 Mon Sep 17 00:00:00 2001 From: Chris Rienzo Date: Mon, 9 Sep 2013 16:22:49 -0400 Subject: [PATCH] mod_rayo: fix record complete URI when recording to HTTP --- .../mod_rayo/rayo_record_component.c | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/mod/event_handlers/mod_rayo/rayo_record_component.c b/src/mod/event_handlers/mod_rayo/rayo_record_component.c index 601d8cb3aa..f6b4db06aa 100644 --- a/src/mod/event_handlers/mod_rayo/rayo_record_component.c +++ b/src/mod/event_handlers/mod_rayo/rayo_record_component.c @@ -85,22 +85,23 @@ static void complete_record(struct rayo_component *component, const char *reason { switch_core_session_t *session = NULL; const char *uuid = component->parent->id; - char *uri = switch_mprintf("file://%s", RECORD_COMPONENT(component)->local_file_path); + const char *uri = RECORD_COMPONENT(component)->local_file_path; iks *recording; switch_size_t file_size = 0; -/* TODO this doesn't work with HTTP */ + + /* TODO this doesn't work with HTTP, improve core RECORD_STOP event so that file size and duration is reported */ #if 0 switch_file_t *file; - if (switch_file_open(&file, RECORD_COMPONENT(component)->local_file_path, SWITCH_FOPEN_READ, SWITCH_FPROT_UREAD, RAYO_POOL(component)) == SWITCH_STATUS_SUCCESS) { + if (switch_file_open(&file, uri, SWITCH_FOPEN_READ, SWITCH_FPROT_UREAD, RAYO_POOL(component)) == SWITCH_STATUS_SUCCESS) { file_size = switch_file_get_size(file); switch_file_close(file); } else { - switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_INFO, "Failed to open %s.\n", RECORD_COMPONENT(component)->local_file_path); + switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_INFO, "Failed to open %s.\n", uri); } #endif - switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "Recording %s done.\n", RECORD_COMPONENT(component)->local_file_path); + switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "Recording %s done.\n", uri); if (RECORD_COMPONENT(component)->stop_beep && (session = switch_core_session_locate(uuid))) { switch_ivr_displace_session(session, RECORD_BEEP, 0, ""); @@ -110,15 +111,19 @@ static void complete_record(struct rayo_component *component, const char *reason /* send complete event to client */ recording = iks_new("recording"); iks_insert_attrib(recording, "xmlns", RAYO_RECORD_COMPLETE_NS); - iks_insert_attrib(recording, "uri", uri); + if (strlen(uri) > strlen(SWITCH_PATH_SEPARATOR) && !strncmp(uri, SWITCH_PATH_SEPARATOR, strlen(SWITCH_PATH_SEPARATOR))) { + /* convert absolute path to file:// URI */ + iks_insert_attrib_printf(recording, "uri", "file://%s", uri); + } else { + /* is already a URI (hopefully) */ + iks_insert_attrib(recording, "uri", uri); + } iks_insert_attrib_printf(recording, "duration", "%i", RECORD_COMPONENT(component)->duration_ms); iks_insert_attrib_printf(recording, "size", "%"SWITCH_SIZE_T_FMT, file_size); rayo_component_send_complete_with_metadata(component, reason, reason_namespace, recording, 1); iks_delete(recording); RAYO_UNLOCK(component); - - switch_safe_free(uri); } /**