diff options
author | Matthew Jordan <mjordan@digium.com> | 2014-07-18 21:48:46 +0000 |
---|---|---|
committer | Matthew Jordan <mjordan@digium.com> | 2014-07-18 21:48:46 +0000 |
commit | b299052e203807c9a2111eb2cd919246d7589cb3 (patch) | |
tree | ed02894e1620cc9d0113aa4449b168fa76f01186 /res/stasis_recording | |
parent | eaf1225b40308f643272a7f7715c7b46aa075f83 (diff) |
ari: Add a copy operation for stored recordings
This patch adds a new operation for stored recordings, copy. It takes an
existing stored recording and makes a copy of it in the same directory
or a relative directory under the stored recording directory.
/ari/recordings/stored/{recordingName}/copy?destinationRecordingName={copy_name}
This is particularly useful for voicemail-esque applications, which may need to
copy or move recordings around a directory structure.
Review: https://reviewboard.asterisk.org/r/3768/
ASTERISK-24036 #close
Reported by: Sam Galarneau
Tested by: Sam Galarneau
........
Merged revisions 419021 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419022 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/stasis_recording')
-rw-r--r-- | res/stasis_recording/stored.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/res/stasis_recording/stored.c b/res/stasis_recording/stored.c index 03af06987..6cc60fd28 100644 --- a/res/stasis_recording/stored.c +++ b/res/stasis_recording/stored.c @@ -458,6 +458,56 @@ struct stasis_app_stored_recording *stasis_app_stored_recording_find_by_name( return recording; } +int stasis_app_stored_recording_copy(struct stasis_app_stored_recording *src_recording, const char *dst, + struct stasis_app_stored_recording **dst_recording) +{ + RAII_VAR(char *, full_path, NULL, ast_free); + char *dst_file = ast_strdupa(dst); + char *format; + char *last_slash; + int res; + + /* Drop the extension if specified, core will do this for us */ + format = strrchr(dst_file, '.'); + if (format) { + format = '\0'; + } + + /* See if any intermediary directories need to be made */ + last_slash = strrchr(dst_file, '/'); + if (last_slash) { + RAII_VAR(char *, tmp_path, NULL, ast_free); + + *last_slash = '\0'; + if (ast_asprintf(&tmp_path, "%s/%s", ast_config_AST_RECORDING_DIR, dst_file) < 0) { + return -1; + } + if (ast_safe_mkdir(ast_config_AST_RECORDING_DIR, + tmp_path, 0777) != 0) { + /* errno set by ast_mkdir */ + return -1; + } + *last_slash = '/'; + if (ast_asprintf(&full_path, "%s/%s", ast_config_AST_RECORDING_DIR, dst_file) < 0) { + return -1; + } + } else { + /* There is no directory portion */ + if (ast_asprintf(&full_path, "%s/%s", ast_config_AST_RECORDING_DIR, dst_file) < 0) { + return -1; + } + } + + ast_verb(4, "Copying recording %s to %s (format %s)\n", src_recording->file, + full_path, src_recording->format); + res = ast_filecopy(src_recording->file, full_path, src_recording->format); + if (!res) { + *dst_recording = stasis_app_stored_recording_find_by_name(dst_file); + } + + return res; +} + int stasis_app_stored_recording_delete( struct stasis_app_stored_recording *recording) { |