99 static int sayfile_exec(
struct ast_channel *chan,
const char *cmd,
char *data,
char *buf,
size_t len)
101 char *value, *type, *files;
103 struct ast_str *filenames = NULL;
109 if (ast_strlen_zero(data)) {
110 ast_log(LOG_WARNING,
"SAYFILES requires an argument\n");
117 type = (ast_strlen_zero(args.type) ?
"alpha" : args.type);
118 lang = (chan ? ast_channel_language(chan) :
"en");
120 if (!strcmp(type,
"alpha")) {
122 }
else if (!strcmp(type,
"phonetic")) {
124 }
else if (!strcmp(type,
"digits")) {
126 }
else if (!strcmp(type,
"number")) {
129 ast_log(LOG_WARNING,
"Invalid numeric argument: %s\n", value);
133 }
else if (!strcmp(type,
"ordinal")) {
136 ast_log(LOG_WARNING,
"Invalid numeric argument: %s\n", value);
140 }
else if (!strcmp(type,
"money")) {
143 ast_log(LOG_WARNING,
"Invalid say type specified: %s\n", type);
151 snprintf(buf, len,
"%s", files);
159 .read = sayfile_exec,
162 #ifdef TEST_FRAMEWORK
165 enum ast_test_result_state res = AST_TEST_PASS;
170 info->name =
"test_SAYFILES_function";
171 info->category =
"/funcs/func_sayfiles/";
172 info->summary =
"Test SAYFILES function substitution";
174 "Executes a series of variable substitutions using the SAYFILES function and ensures that the expected results are received.";
175 return AST_TEST_NOT_RUN;
180 ast_test_status_update(
test,
"Testing SAYFILES() substitution ...\n");
183 return AST_TEST_FAIL;
187 return AST_TEST_FAIL;
190 ast_str_set(&expr, 0,
"${SAYFILES(hi Th3re,alpha)}");
192 if (strcmp(
ast_str_buffer(result),
"letters/h&letters/i&letters/space&letters/t&letters/h&digits/3&letters/r&letters/e") != 0) {
193 ast_test_status_update(
test,
"SAYFILES(hi Th3re,alpha) test failed ('%s')\n",
198 ast_str_set(&expr, 0,
"${SAYFILES(phreak,phonetic)}");
200 if (strcmp(
ast_str_buffer(result),
"phonetic/p_p&phonetic/h_p&phonetic/r_p&phonetic/e_p&phonetic/a_p&phonetic/k_p") != 0) {
201 ast_test_status_update(
test,
"SAYFILES(phreak,phonetic) test failed ('%s')\n",
209 ast_test_status_update(
test,
"SAYFILES(35,digits) test failed ('%s')\n",
215 ast_str_set(&expr, 0,
"${SAYFILES(+18005551212,digits)}");
217 if (strcmp(
ast_str_buffer(result),
"digits/1&digits/8&digits/0&digits/0&digits/5&digits/5&digits/5&digits/1&digits/2&digits/1&digits/2") != 0) {
218 ast_test_status_update(
test,
"SAYFILES(+18005551212,digits) test failed ('%s')\n",
226 ast_test_status_update(
test,
"SAYFILES(35,number) test failed ('%s')\n",
233 if (strcmp(
ast_str_buffer(result),
"digits/7&digits/hundred&digits/40&digits/7") != 0) {
234 ast_test_status_update(
test,
"SAYFILES(747,number) test failed ('%s')\n",
241 if (strcmp(
ast_str_buffer(result),
"digits/1&digits/thousand&digits/40&digits/2") != 0) {
242 ast_test_status_update(
test,
"SAYFILES(1042,number) test failed ('%s')\n",
250 ast_test_status_update(
test,
"SAYFILES(0,digits) test failed ('%s')\n",
255 ast_str_set(&expr, 0,
"${SAYFILES(2001000001,number)}");
257 if (strcmp(
ast_str_buffer(result),
"digits/2&digits/billion&digits/1&digits/million&digits/1") != 0) {
258 ast_test_status_update(
test,
"SAYFILES(2001000001,number) test failed ('%s')\n",
266 ast_test_status_update(
test,
"SAYFILES(7,ordinal) test failed ('%s')\n",
273 if (strcmp(
ast_str_buffer(result),
"digits/30&digits/h-5") != 0) {
274 ast_test_status_update(
test,
"SAYFILES(35,ordinal) test failed ('%s')\n",
279 ast_str_set(&expr, 0,
"${SAYFILES(1042,ordinal)}");
281 if (strcmp(
ast_str_buffer(result),
"digits/1&digits/thousand&digits/40&digits/h-2") != 0) {
282 ast_test_status_update(
test,
"SAYFILES(1042,ordinal) test failed ('%s')\n",
287 ast_str_set(&expr, 0,
"${SAYFILES(11042,ordinal)}");
289 if (strcmp(
ast_str_buffer(result),
"digits/11&digits/thousand&digits/40&digits/h-2") != 0) {
290 ast_test_status_update(
test,
"SAYFILES(11042,ordinal) test failed ('%s')\n",
295 ast_str_set(&expr, 0,
"${SAYFILES(40000,ordinal)}");
297 if (strcmp(
ast_str_buffer(result),
"digits/40&digits/h-thousand") != 0) {
298 ast_test_status_update(
test,
"SAYFILES(40000,ordinal) test failed ('%s')\n",
303 ast_str_set(&expr, 0,
"${SAYFILES(43638,ordinal)}");
305 if (strcmp(
ast_str_buffer(result),
"digits/40&digits/3&digits/thousand&digits/6&digits/hundred&digits/30&digits/h-8") != 0) {
306 ast_test_status_update(
test,
"SAYFILES(43638,ordinal) test failed ('%s')\n",
311 ast_str_set(&expr, 0,
"${SAYFILES(1000000,ordinal)}");
313 if (strcmp(
ast_str_buffer(result),
"digits/1&digits/h-million") != 0) {
314 ast_test_status_update(
test,
"SAYFILES(1000000,ordinal) test failed ('%s')\n",
319 ast_str_set(&expr, 0,
"${SAYFILES(1000001,ordinal)}");
321 if (strcmp(
ast_str_buffer(result),
"digits/1&digits/million&digits/h-1") != 0) {
322 ast_test_status_update(
test,
"SAYFILES(1000001,ordinal) test failed ('%s')\n",
327 ast_str_set(&expr, 0,
"${SAYFILES(2001000001,ordinal)}");
329 if (strcmp(
ast_str_buffer(result),
"digits/2&digits/billion&digits/1&digits/million&digits/h-1") != 0) {
330 ast_test_status_update(
test,
"SAYFILES(2001000001,ordinal) test failed ('%s')\n",
338 ast_test_status_update(
test,
"SAYFILES(0,money) test failed ('%s')\n",
346 ast_test_status_update(
test,
"SAYFILES(0.01,money) test failed ('%s')\n",
353 if (strcmp(
ast_str_buffer(result),
"digits/40&digits/2¢s") != 0) {
354 ast_test_status_update(
test,
"SAYFILES(0.42,money) test failed ('%s')\n",
361 if (strcmp(
ast_str_buffer(result),
"digits/40&digits/2¢s") != 0) {
362 ast_test_status_update(
test,
"SAYFILES(.42,money) test failed ('%s')\n",
369 if (strcmp(
ast_str_buffer(result),
"digits/1&letters/dollar") != 0) {
370 ast_test_status_update(
test,
"SAYFILES(1.00,money) test failed ('%s')\n",
377 if (strcmp(
ast_str_buffer(result),
"digits/1&letters/dollar_&and&digits/40&digits/2¢s") != 0) {
378 ast_test_status_update(
test,
"SAYFILES(1.42,money) test failed ('%s')\n",
386 ast_test_status_update(
test,
"SAYFILES(2.00,money) test failed ('%s')\n",
394 ast_test_status_update(
test,
"SAYFILES(2,money) test failed ('%s')\n",
401 if (strcmp(
ast_str_buffer(result),
"digits/2&dollars&and&digits/40&digits/2¢s") != 0) {
402 ast_test_status_update(
test,
"SAYFILES(2.42,money) test failed ('%s')\n",
409 if (strcmp(
ast_str_buffer(result),
"digits/2&dollars&and&digits/5¢s") != 0) {
410 ast_test_status_update(
test,
"SAYFILES(2.05,money) test failed ('%s')\n",
417 if (strcmp(
ast_str_buffer(result),
"digits/2&dollars&and&digits/5¢s") != 0) {
418 ast_test_status_update(
test,
"SAYFILES(2.051,money) test failed ('%s')\n",
427 ast_test_status_update(
test,
"SAYFILES(blah,money) test failed ('%s')\n",
432 ast_str_set(&expr, 0,
"${SAYFILES(2blah.05,money)}");
435 ast_test_status_update(
test,
"SAYFILES(2blah.05,money) test failed ('%s')\n",
443 ast_test_status_update(
test,
"SAYFILES(2.-05,money) test failed ('%s')\n",
451 ast_test_status_update(
test,
"SAYFILES(2. 05,money) test failed ('%s')\n",
459 ast_test_status_update(
test,
"SAYFILES(. 05,money) test failed ('%s')\n",
471 static int unload_module(
void)
473 AST_TEST_UNREGISTER(test_SAYFILES_function);
477 static int load_module(
void)
479 AST_TEST_REGISTER(test_SAYFILES_function);
Main Channel structure associated with a channel.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
struct ast_str * ast_get_ordinal_str(int num, const char *lang)
Returns an ast_str of files for SayOrdinal playback.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
struct ast_str * ast_get_number_str(int num, const char *lang)
Returns an ast_str of files for SayNumber playback.
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
struct ast_str * ast_get_phonetic_str(const char *str, const char *lang)
Returns an ast_str of files for SayPhonetic playback.
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_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
struct ast_str * ast_get_money_str(const char *str, const char *lang)
Returns an ast_str of files for SayMoney playback.
Custom localtime functions for multiple timezones.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
General Asterisk PBX channel definitions.
struct ast_str * ast_get_digit_str(const char *str, const char *lang)
Returns an ast_str of files for SayDigits playback.
Data structure associated with a custom dialplan function.
Conversion utility functions.
Core PBX routines and definitions.
int ast_str_to_int(const char *str, int *res)
Convert the given string to a signed integer.
Support for dynamic strings.
struct ast_str * ast_get_character_str(const char *str, const char *lang, enum ast_say_case_sensitivity sensitivity)
Returns an ast_str of files for SayAlpha playback.
#define AST_TEST_DEFINE(hdr)
Say numbers and dates (maybe words one day too)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_custom_function_register(acf)
Register a custom function.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
#define AST_APP_ARG(name)
Define an application argument.