1 /*
2  * Copyright (c) 2007-2014, Anthony Minessale II
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the original author; nor the names of any contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER
25  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * The Initial Developer of the Original Code is
34  * Anthony Minessale II <anthm@freeswitch.org>
35  * Portions created by the Initial Developer are Copyright (C)
36  * the Initial Developer. All Rights Reserved.
37  *
38  * Contributor(s):
39  *
40  * Anthony Minessale II <anthm@freeswitch.org>
41  * Michael B. Murdock <mike@mmurdock.org>
42  * François Delawarde <fdelawarde@wirelessmundi.com>
43  * Joao Mesquita <jmesquita@freeswitch.org>
44  *
45  * mod_say_es_ar.c -- Say for Spanish (Argentina)
46  *
47  */
48 
49 #include <switch.h>
50 #include <math.h>
51 #include <ctype.h>
52 
53 SWITCH_MODULE_LOAD_FUNCTION(mod_say_es_ar_load);
54 SWITCH_MODULE_DEFINITION(mod_say_es_ar, mod_say_es_ar_load, NULL, NULL);
55 
56 
57 #define say_num(_sh, num, meth) {										\
58 		char tmp[80];													\
59 		switch_status_t tstatus;										\
60 		switch_say_method_t smeth = say_args->method;					\
61 		switch_say_type_t stype = say_args->type;						\
62 		say_args->type = SST_ITEMS; say_args->method = meth;			\
63 		switch_snprintf(tmp, sizeof(tmp), "%u", (unsigned)num);			\
64 		if ((tstatus =													\
65 			 es_say_general_count(_sh, tmp, say_args))					\
66 			!= SWITCH_STATUS_SUCCESS) {									\
67 			return tstatus;												\
68 		}																\
69 		say_args->method = smeth; say_args->type = stype;				\
70 	}																	\
71 
72 
73 
play_group(switch_say_method_t method,switch_say_gender_t gender,int a,int b,int c,char * what,switch_say_file_handle_t * sh)74 static switch_status_t play_group(switch_say_method_t method, switch_say_gender_t gender, int a, int b, int c, char *what, switch_say_file_handle_t *sh)
75 {
76 
77 	if (a) {
78 		if (a == 1 && b == 0 && c == 0) {
79 			switch_say_file(sh, "digits/hundred");
80 		} else {
81 			switch_say_file(sh, "digits/%d00", a);
82 		}
83 	}
84 
85 	if (b) {
86 		if (method == SSM_COUNTED) {
87 			/* Numeros no redondos es masculino siempre. */
88 			if (gender == SSG_FEMININE && c == 0) {
89 				switch_say_file(sh, "digits/h-%d0_a", b);
90 
91 			} else {
92 				switch_say_file(sh, "digits/h-%d0", b);
93 			}
94 		} else {
95 			/* Veinti */
96 			if (b == 2) {
97 				switch_say_file(sh, "digits/%d0_i", b);
98 			} else if(b == 1) {
99 				switch_say_file(sh, "digits/%d%d", b, c);
100 			} else {
101 				switch_say_file(sh, "digits/%d0", b);
102 				if (c > 0) {
103 					switch_say_file(sh, "digits/y");
104 				}
105 			}
106 		}
107 	}
108 
109 	if (c && b != 1) {
110 		if (method == SSM_COUNTED) {
111 			if (gender == SSG_FEMININE) {
112 				switch_say_file(sh, "digits/h-%d_a", c);
113 			} else {
114 				switch_say_file(sh, "digits/h-%d", c);
115 			}
116 		} else {
117 			if (c == 1) {
118 				if (gender == SSG_NEUTER) {
119 					switch_say_file(sh, "digits/%d_n", c);
120 				} else if (gender == SSG_FEMININE) {
121 					switch_say_file(sh, "digits/%d_a", c);
122 				} else {
123 					switch_say_file(sh, "digits/%d", c);
124 				}
125 			} else {
126 				switch_say_file(sh, "digits/%d", c);
127 			}
128 		}
129 	}
130 
131 	if (what && (a || b || c)) {
132 		switch_say_file(sh, what);
133 	}
134 
135 	return SWITCH_STATUS_SUCCESS;
136 }
137 
es_say_general_count(switch_say_file_handle_t * sh,char * tosay,switch_say_args_t * say_args)138 static switch_status_t es_say_general_count(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args)
139 {
140 	int in;
141 	int x = 0;
142 	int places[9] = { 0 };
143 	char sbuf[128] = "";
144 	switch_status_t status;
145 
146 	if (say_args->method == SSM_ITERATED) {
147 		if ((tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf)-1))) {
148 			char *p;
149 			for (p = tosay; p && *p; p++) {
150 				char *n_p = p+1;
151 				switch_say_file(sh, "digits/%c", *p);
152 				if (n_p && *n_p) {
153 					switch_say_file(sh, "silence_stream://100");
154 				}
155 			}
156 		} else {
157 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
158 			return SWITCH_STATUS_GENERR;
159 		}
160 		return SWITCH_STATUS_SUCCESS;
161 	}
162 
163 	if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf)-1)) || strlen(tosay) > 9) {
164 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
165 		return SWITCH_STATUS_GENERR;
166 	}
167 
168 	in = atoi(tosay);
169 
170 	if (in != 0) {
171 		for (x = 8; x >= 0; x--) {
172 			int num = (int) pow(10, x);
173 			if ((places[(uint32_t) x] = in / num)) {
174 				in -= places[(uint32_t) x] * num;
175 			}
176 		}
177 
178 
179 		switch (say_args->method) {
180 		case SSM_PRONOUNCED_YEAR:
181 			{
182 				int num = atoi(tosay);
183 				int a = num / 100;
184 				int b = num % 100;
185 
186 				if (!b || !(a % 10)) {
187 					say_num(sh, num, SSM_PRONOUNCED);
188 					return SWITCH_STATUS_SUCCESS;
189 				}
190 
191 				say_num(sh, a, SSM_PRONOUNCED);
192 				say_num(sh, b, SSM_PRONOUNCED);
193 
194 				return SWITCH_STATUS_SUCCESS;
195 			}
196 			break;
197 		case SSM_COUNTED:
198 		case SSM_PRONOUNCED:
199 			if ((status = play_group(SSM_PRONOUNCED, say_args->gender, places[8], places[7], places[6], "digits/million", sh)) != SWITCH_STATUS_SUCCESS) {
200 				return status;
201 			}
202 			if ((status = play_group(SSM_PRONOUNCED, say_args->gender, places[5], places[4], places[3], "digits/thousand", sh)) != SWITCH_STATUS_SUCCESS) {
203 				return status;
204 			}
205 			if ((status = play_group(say_args->method, say_args->gender, places[2], places[1], places[0], NULL, sh)) != SWITCH_STATUS_SUCCESS) {
206 				return status;
207 			}
208 			break;
209 		default:
210 			break;
211 		}
212 	} else {
213 		switch_say_file(sh, "digits/0");
214 	}
215 
216 	return SWITCH_STATUS_SUCCESS;
217 }
218 
es_say_time(switch_say_file_handle_t * sh,char * tosay,switch_say_args_t * say_args)219 static switch_status_t es_say_time(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args)
220 {
221 	int32_t t;
222 	switch_time_t target = 0, target_now = 0;
223 	switch_time_exp_t tm, tm_now;
224 	uint8_t say_date = 0, say_time = 0, say_year = 0, say_month = 0, say_dow = 0, say_day = 0, say_yesterday = 0, say_today = 0;
225 	const char *tz = NULL;
226 
227 	tz = switch_say_file_handle_get_variable(sh, "timezone");
228 
229 	if (say_args->type == SST_TIME_MEASUREMENT) {
230 		int64_t hours = 0;
231 		int64_t minutes = 0;
232 		int64_t seconds = 0;
233 		int64_t r = 0;
234 
235 		if (strchr(tosay, ':')) {
236 			char *tme = strdup(tosay);
237 			char *p;
238 
239 			if ((p = strrchr(tme, ':'))) {
240 				*p++ = '\0';
241 				seconds = atoi(p);
242 				if ((p = strchr(tme, ':'))) {
243 					*p++ = '\0';
244 					minutes = atoi(p);
245 					hours = atoi(tme);
246 				} else {
247 					minutes = atoi(tme);
248 				}
249 			}
250 			free(tme);
251 		} else {
252 			if ((seconds = atol(tosay)) <= 0) {
253 				seconds = (int64_t) switch_epoch_time_now(NULL);
254 			}
255 
256 			if (seconds >= 60) {
257 				minutes = seconds / 60;
258 				r = seconds % 60;
259 				seconds = r;
260 			}
261 
262 			if (minutes >= 60) {
263 				hours = minutes / 60;
264 				r = minutes % 60;
265 				minutes = r;
266 			}
267 		}
268 
269 		if (hours) {
270 			say_num(sh, hours, SSM_PRONOUNCED);
271 			if (hours == 1) {
272 				switch_say_file(sh, "time/hour");
273 			} else {
274 				switch_say_file(sh, "time/hours");
275 			}
276 		} else {
277 			switch_say_file(sh, "digits/0");
278 			switch_say_file(sh, "time/hours");
279 		}
280 
281 		if (minutes) {
282 			say_num(sh, minutes, SSM_PRONOUNCED);
283 			if (minutes == 1) {
284 				switch_say_file(sh, "time/minute");
285 			} else {
286 				switch_say_file(sh, "time/minutes");
287 			}
288 		} else {
289 			switch_say_file(sh, "digits/0");
290 			switch_say_file(sh, "time/minutes");
291 		}
292 
293 		if (seconds) {
294 			say_num(sh, seconds, SSM_PRONOUNCED);
295 			if (seconds == 1) {
296 				switch_say_file(sh, "time/second");
297 			} else {
298 				switch_say_file(sh, "time/seconds");
299 			}
300 		} else {
301 			switch_say_file(sh, "digits/0");
302 			switch_say_file(sh, "time/seconds");
303 		}
304 
305 		return SWITCH_STATUS_SUCCESS;
306 	}
307 
308 	if ((t = atol(tosay)) > 0) {
309 		target = switch_time_make(t, 0);
310 		target_now = switch_micro_time_now();
311 	} else {
312 		target = switch_micro_time_now();
313 		target_now = switch_micro_time_now();
314 	}
315 
316 	if (tz) {
317 		int check = atoi(tz);
318 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Timezone is [%s]\n", tz);
319 		if (check) {
320 			switch_time_exp_tz(&tm, target, check);
321 			switch_time_exp_tz(&tm_now, target_now, check);
322 		} else {
323 			switch_time_exp_tz_name(tz, &tm, target);
324 			switch_time_exp_tz_name(tz, &tm_now, target_now);
325 		}
326 	} else {
327 		switch_time_exp_lt(&tm, target);
328 		switch_time_exp_lt(&tm_now, target_now);
329 	}
330 
331 	switch (say_args->type) {
332 	case SST_CURRENT_DATE_TIME:
333 		say_date = say_time = 1;
334 		break;
335 	case SST_CURRENT_DATE:
336 		say_date = 1;
337 		break;
338 	case SST_CURRENT_TIME:
339 		say_time = 1;
340 		break;
341 	case SST_SHORT_DATE_TIME:
342 		say_time = 1;
343 		//Time is in the future
344 		if ((tm.tm_year > tm_now.tm_year) ||
345 		    (tm.tm_year == tm_now.tm_year && tm.tm_mon > tm_now.tm_mon) ||
346 		    (tm.tm_year == tm_now.tm_year && tm.tm_mon == tm_now.tm_mon && tm.tm_mday > tm_now.tm_mday))
347 		{
348 			say_date = 1;
349 			break;
350 		}
351 		//Time is today or earlier
352 		if (tm.tm_year != tm_now.tm_year) {
353 			say_date = 1;
354 			break;
355 		}
356 		if (tm.tm_yday == tm_now.tm_yday) {
357 			say_today = 1;
358 			break;
359 		}
360 		if (tm.tm_yday == tm_now.tm_yday - 1) {
361 			say_yesterday = 1;
362 			break;
363 		}
364 		if (tm.tm_yday >= tm_now.tm_yday - 5) {
365 			say_dow = 1;
366 			break;
367 		}
368 		if (tm.tm_mon != tm_now.tm_mon) {
369 			say_month = say_day = say_dow = 1;
370 			break;
371 		}
372 
373 		say_month = say_day = say_dow = 1;
374 
375 		break;
376 	default:
377 		break;
378 	}
379 
380 	if (say_today) {
381 		switch_say_file(sh, "time/today");
382 	}
383 	if (say_yesterday) {
384 		switch_say_file(sh, "time/yesterday");
385 	}
386 	if (say_dow) {
387 		switch_say_file(sh, "time/day-%d", tm.tm_wday);
388 	}
389 
390 	if (say_date) {
391 		say_year = say_month = say_day = say_dow = 1;
392 		say_today = say_yesterday = 0;
393 	}
394 
395 	if (say_day) {
396 		if (tm.tm_mday == 1) {
397 			say_num(sh, tm.tm_mday, SSM_COUNTED);
398 		} else {
399 			say_num(sh, tm.tm_mday, SSM_PRONOUNCED);
400 		}
401 		switch_say_file(sh, "time/de");
402 	}
403 	if (say_month) {
404 		switch_say_file(sh, "time/mon-%d", tm.tm_mon);
405 	}
406 	if (say_year) {
407 		switch_say_file(sh, "time/de");
408 		say_num(sh, tm.tm_year + 1900, SSM_PRONOUNCED_YEAR);
409 	}
410 
411 	if (say_time) {
412 
413 		if (say_date || say_today || say_yesterday || say_dow) {
414 			switch_say_file(sh, "time/at");
415 		}
416 
417 
418 		if (tm.tm_hour == 1) {
419 			switch_say_file(sh, "digits/1");
420 			switch_say_file(sh, "time/hour");
421 		} else {
422 			say_num(sh, tm.tm_hour, SSM_PRONOUNCED);
423 			switch_say_file(sh, "time/hours");
424 		}
425 
426 		if (tm.tm_min == 1) {
427 			switch_say_file(sh, "digits/1_1a");
428 			switch_say_file(sh, "time/minute");
429 		} else {
430 			say_num(sh, tm.tm_min, SSM_PRONOUNCED);
431 			switch_say_file(sh, "time/minutes");
432 		}
433 
434 	}
435 
436 	return SWITCH_STATUS_SUCCESS;
437 }
438 
439 
es_say_money(switch_say_file_handle_t * sh,char * tosay,switch_say_args_t * say_args)440 static switch_status_t es_say_money(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args)
441 {
442 	char sbuf[16] = "";			/* enough for 999,999,999,999.99 (w/o the commas or leading $) */
443 	char *dollars = NULL;
444 	char *cents = NULL;
445 
446 	if (strlen(tosay) > 15 || !switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)-1)) {
447 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
448 		return SWITCH_STATUS_GENERR;
449 	}
450 
451 	dollars = sbuf;
452 
453 	if ((cents = strchr(sbuf, '.'))) {
454 		*cents++ = '\0';
455 		if (strlen(cents) > 2) {
456 			cents[2] = '\0';
457 		}
458 	}
459 
460 	/* If positive sign - skip over" */
461 	if (sbuf[0] == '+') {
462 		dollars++;
463 	}
464 
465 	/* If negative say "negative" */
466 	if (sbuf[0] == '-') {
467 		switch_say_file(sh, "currency/negative");
468 		dollars++;
469 	}
470 
471 	/* Say dollar amount */
472 	es_say_general_count(sh, dollars, say_args);
473 	if (atoi(dollars) == 1) {
474 		switch_say_file(sh, "currency/dollar");
475 	} else {
476 		switch_say_file(sh, "currency/dollars");
477 	}
478 
479 	/* Say cents */
480 	if (cents) {
481 		/* Say "and" */
482 		switch_say_file(sh, "currency/and");
483 
484 		es_say_general_count(sh, cents, say_args);
485 		if (atoi(cents) == 1) {
486 			switch_say_file(sh, "currency/cent");
487 		} else {
488 			switch_say_file(sh, "currency/cents");
489 		}
490 	}
491 
492 	return SWITCH_STATUS_SUCCESS;
493 }
494 
495 
say_ip(switch_say_file_handle_t * sh,char * tosay,switch_say_args_t * say_args)496 static switch_status_t say_ip(switch_say_file_handle_t *sh,
497 							  char *tosay,
498 							  switch_say_args_t *say_args)
499 
500 {
501 	char *a, *b, *c, *d;
502 	switch_status_t status = SWITCH_STATUS_FALSE;
503 
504 	if (!(a = strdup(tosay))) {
505 		abort();
506 	}
507 
508 	if (!(b = strchr(a, '.'))) {
509 		goto end;
510 	}
511 
512 	*b++ = '\0';
513 
514 	if (!(c = strchr(b, '.'))) {
515 		goto end;
516 	}
517 
518 	*c++ = '\0';
519 
520 	if (!(d = strchr(c, '.'))) {
521 		goto end;
522 	}
523 
524 	*d++ = '\0';
525 
526 	say_num(sh, atoi(a), say_args->method);
527 	switch_say_file(sh, "digits/dot");
528 	say_num(sh, atoi(b), say_args->method);
529 	switch_say_file(sh, "digits/dot");
530 	say_num(sh, atoi(c), say_args->method);
531 	switch_say_file(sh, "digits/dot");
532 	say_num(sh, atoi(d), say_args->method);
533 
534  end:
535 
536 	free(a);
537 
538 	return status;
539 }
540 
541 
say_telephone_number(switch_say_file_handle_t * sh,char * tosay,switch_say_args_t * say_args)542 static switch_status_t say_telephone_number(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args)
543 {
544 	int silence = 0;
545 	char *p;
546 
547 	for (p = tosay; !zstr(p); p++) {
548 		int a = tolower((int) *p);
549 		if (a >= '0' && a <= '9') {
550 			switch_say_file(sh, "digits/%c", a);
551 			silence = 0;
552 		} else if (a == '+' || (a >= 'a' && a <= 'z')) {
553 			switch_say_file(sh, "ascii/%d", a);
554 			silence = 0;
555 		} else if (!silence) {
556 			switch_say_file(sh, "silence_stream://100");
557 			silence = 1;
558 		}
559 	}
560 
561 	return SWITCH_STATUS_SUCCESS;
562 }
563 
564 
say_spell(switch_say_file_handle_t * sh,char * tosay,switch_say_args_t * say_args)565 static switch_status_t say_spell(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args)
566 {
567 	char *p;
568 
569 	for (p = tosay; p && *p; p++) {
570 		int a = tolower((int) *p);
571 		if (a >= '0' && a <= '9') {
572 			switch_say_file(sh, "digits/%c", a);
573 		} else {
574 			if (say_args->type == SST_NAME_SPELLED) {
575 				switch_say_file(sh, "ascii/%d", a);
576 			} else if (say_args->type == SST_NAME_PHONETIC) {
577 				switch_say_file(sh, "phonetic-ascii/%d", a);
578 			}
579 		}
580 	}
581 
582 	return SWITCH_STATUS_SUCCESS;
583 }
584 
585 
choose_callback(switch_say_args_t * say_args)586 static switch_new_say_callback_t choose_callback(switch_say_args_t *say_args)
587 {
588 	switch_new_say_callback_t say_cb = NULL;
589 
590 	switch (say_args->type) {
591 	case SST_NUMBER:
592 	case SST_ITEMS:
593 	case SST_PERSONS:
594 	case SST_MESSAGES:
595 		say_cb = es_say_general_count;
596 		break;
597 	case SST_TIME_MEASUREMENT:
598 	case SST_CURRENT_DATE:
599 	case SST_CURRENT_TIME:
600 	case SST_CURRENT_DATE_TIME:
601 	case SST_SHORT_DATE_TIME:
602 		say_cb = es_say_time;
603 		break;
604 	case SST_IP_ADDRESS:
605 		say_cb = say_ip;
606 		break;
607 	case SST_NAME_SPELLED:
608 	case SST_NAME_PHONETIC:
609 		say_cb = say_spell;
610 		break;
611 	case SST_CURRENCY:
612 		say_cb = es_say_money;
613 		break;
614 	case SST_TELEPHONE_NUMBER:
615 		say_cb = say_telephone_number;
616 		break;
617 	default:
618 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown Say type=[%d]\n", say_args->type);
619 		break;
620 	}
621 
622 	return say_cb;
623 }
624 
625 
run_callback(switch_new_say_callback_t say_cb,char * tosay,switch_say_args_t * say_args,switch_core_session_t * session,char ** rstr)626 static switch_status_t run_callback(switch_new_say_callback_t say_cb, char *tosay, switch_say_args_t *say_args, switch_core_session_t *session, char **rstr)
627 {
628 	switch_say_file_handle_t *sh;
629 	switch_status_t status = SWITCH_STATUS_FALSE;
630 	switch_event_t *var_event = NULL;
631 
632 	if (session) {
633 		switch_channel_t *channel = switch_core_session_get_channel(session);
634 		switch_channel_get_variables(channel, &var_event);
635 	}
636 
637 	switch_say_file_handle_create(&sh, say_args->ext, &var_event);
638 
639 	status = say_cb(sh, tosay, say_args);
640 
641 	if ((*rstr = switch_say_file_handle_detach_path(sh))) {
642 		status = SWITCH_STATUS_SUCCESS;
643 	}
644 
645 	switch_say_file_handle_destroy(&sh);
646 
647 	return status;
648 }
649 
650 
es_say(switch_core_session_t * session,char * tosay,switch_say_args_t * say_args,switch_input_args_t * args)651 static switch_status_t es_say(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
652 {
653 
654 	switch_new_say_callback_t say_cb = NULL;
655 	char *string = NULL;
656 
657 	switch_status_t status = SWITCH_STATUS_FALSE;
658 
659 	say_cb = choose_callback(say_args);
660 
661 	if (say_cb) {
662 		status = run_callback(say_cb, tosay, say_args, session, &string);
663 		if (session && string) {
664 			status = switch_ivr_play_file(session, NULL, string, args);
665 		}
666 
667 		switch_safe_free(string);
668 	}
669 
670 	return status;
671 }
672 
673 
es_say_string(switch_core_session_t * session,char * tosay,switch_say_args_t * say_args,char ** rstr)674 static switch_status_t es_say_string(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, char **rstr)
675 {
676 
677 	switch_new_say_callback_t say_cb = NULL;
678 	char *string = NULL;
679 
680 	switch_status_t status = SWITCH_STATUS_FALSE;
681 
682 	say_cb = choose_callback(say_args);
683 
684 	if (say_cb) {
685 		status = run_callback(say_cb, tosay, say_args, session, &string);
686 		if (string) {
687 			status = SWITCH_STATUS_SUCCESS;
688 			*rstr = string;
689 		}
690 	}
691 
692 	return status;
693 }
694 
SWITCH_MODULE_LOAD_FUNCTION(mod_say_es_ar_load)695 SWITCH_MODULE_LOAD_FUNCTION(mod_say_es_ar_load)
696 {
697 	switch_say_interface_t *say_interface;
698 	/* connect my internal structure to the blank pointer passed to me */
699 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
700 	say_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_SAY_INTERFACE);
701 	say_interface->interface_name = "es_ar";
702 	say_interface->say_function = es_say;
703 	say_interface->say_string_function = es_say_string;
704 
705 	/* indicate that the module should continue to be loaded */
706 	return SWITCH_STATUS_SUCCESS;
707 }
708 
709 /* For Emacs:
710  * Local Variables:
711  * mode:c
712  * indent-tabs-mode:t
713  * tab-width:4
714  * c-basic-offset:4
715  * End:
716  * For VIM:
717  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
718  */
719