41 static int split_ext(
char *filename,
char **name,
char **ext)
43 *name = *ext = filename;
45 if ((*ext = strrchr(filename,
'.'))) {
50 if (ast_strlen_zero(*name) || ast_strlen_zero(*ext))
66 char *ret = CLI_FAILURE;
71 char *file_in = NULL, *file_out = NULL;
72 char *name_in, *ext_in, *name_out, *ext_out;
78 "Usage: file convert <file_in> <file_out>\n"
79 " Convert from file_in to file_out. If an absolute path\n"
80 " is not given, the default Asterisk sounds directory\n"
83 " file convert tt-weasels.gsm tt-weasels.ulaw\n";
89 if (a->argc != 4 || ast_strlen_zero(a->argv[2]) || ast_strlen_zero(a->argv[3])) {
97 if (
split_ext(file_in, &name_in, &ext_in)) {
98 ast_cli(a->fd,
"'%s' is an invalid filename!\n", a->argv[2]);
101 if (!(fs_in =
ast_readfile(name_in, ext_in, NULL, O_RDONLY, 0, 0))) {
102 ast_cli(a->fd,
"Unable to open input file: %s\n", a->argv[2]);
106 if (
split_ext(file_out, &name_out, &ext_out)) {
107 ast_cli(a->fd,
"'%s' is an invalid filename!\n", a->argv[3]);
110 if (!(fs_out =
ast_writefile(name_out, ext_out, NULL, O_CREAT|O_TRUNC|O_WRONLY, 0, AST_FILE_MODE))) {
111 ast_cli(a->fd,
"Unable to open output file: %s\n", a->argv[3]);
120 ast_cli(a->fd,
"Failed to convert %s.%s to %s.%s!\n", name_in, ext_in, name_out, ext_out);
127 ast_cli(a->fd,
"Converted %s.%s to %s.%s in %dms\n", name_in, ext_in, name_out, ext_out, cost);
133 if (ret != CLI_SUCCESS)
147 static int unload_module(
void)
153 static int load_module(
void)
159 AST_MODULE_INFO_STANDARD(
ASTERISK_GPL_KEY,
"File format conversion CLI command");
Asterisk main include file. File version handling, generic pbx functions.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
descriptor for a cli entry.
static char * handle_cli_file_convert(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Convert a file from one format to another.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int ast_filedelete(const char *filename, const char *fmt)
Deletes a file.
General Asterisk PBX channel definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
struct ast_frame * ast_readframe(struct ast_filestream *s)
Read a frame from a filestream.
struct ast_filestream * ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
Starts writing a file.
int ast_closestream(struct ast_filestream *f)
Closes a stream.
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
Standard Command Line Interface.
int ast_writestream(struct ast_filestream *fs, struct ast_frame *f)
Writes a frame to a stream.
Data structure associated with a single frame of data.
struct ast_filestream * ast_readfile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
Starts reading from a file.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
static int split_ext(char *filename, char **name, char **ext)
Split the filename to basename and extension.