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  *
43  * mod_say_en.c -- Say for English
44  *
45  */
46 
47 #include <switch.h>
48 #include <math.h>
49 #include <ctype.h>
50 
51 SWITCH_MODULE_LOAD_FUNCTION(mod_say_en_load);
52 SWITCH_MODULE_DEFINITION(mod_say_en, mod_say_en_load, NULL, NULL);
53 
54 
55 #define say_num(_sh, num, meth) {										\
56 		char tmp[80];													\
57 		switch_status_t tstatus;										\
58 		switch_say_method_t smeth = say_args->method;					\
59 		switch_say_type_t stype = say_args->type;						\
60 		say_args->type = SST_ITEMS; say_args->method = meth;			\
61 		switch_snprintf(tmp, sizeof(tmp), "%u", (unsigned)num);			\
62 		if ((tstatus =													\
63 			 en_say_general_count(_sh, tmp, say_args))					\
64 			!= SWITCH_STATUS_SUCCESS) {									\
65 			return tstatus;												\
66 		}																\
67 		say_args->method = smeth; say_args->type = stype;				\
68 	}																	\
69 
70 
71 
play_group(switch_say_method_t method,int a,int b,int c,char * what,switch_say_file_handle_t * sh)72 static switch_status_t play_group(switch_say_method_t method, int a, int b, int c, char *what, switch_say_file_handle_t *sh)
73 {
74 
75 	if (a) {
76 		switch_say_file(sh, "digits/%d", a);
77 		switch_say_file(sh, "digits/hundred");
78 	}
79 
80 	if (b) {
81 		if (b > 1) {
82 			if ((c == 0) && (method == SSM_COUNTED)) {
83 				switch_say_file(sh, "digits/h-%d0", b);
84 			} else {
85 				switch_say_file(sh, "digits/%d0", b);
86 			}
87 		} else {
88 			switch_say_file(sh, "digits/%d%d", b, c);
89 			c = 0;
90 		}
91 	}
92 
93 	if (c) {
94 		if (method == SSM_COUNTED) {
95 			switch_say_file(sh, "digits/h-%d", c);
96 		} else {
97 			switch_say_file(sh, "digits/%d", c);
98 		}
99 	}
100 
101 	if (what && (a || b || c)) {
102 		switch_say_file(sh, what);
103 	}
104 
105 	return SWITCH_STATUS_SUCCESS;
106 }
107 
en_say_general_count(switch_say_file_handle_t * sh,char * tosay,switch_say_args_t * say_args)108 static switch_status_t en_say_general_count(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args)
109 {
110 	int in;
111 	int x = 0;
112 	int places[9] = { 0 };
113 	char sbuf[128] = "";
114 	switch_status_t status;
115 
116 	if (say_args->method == SSM_ITERATED) {
117 		if ((tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf)-1))) {
118 			char *p;
119 			for (p = tosay; p && *p; p++) {
120 				switch_say_file(sh, "digits/%c", *p);
121 			}
122 		} else {
123 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
124 			return SWITCH_STATUS_GENERR;
125 		}
126 		return SWITCH_STATUS_SUCCESS;
127 	}
128 
129 	if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf)-1)) || strlen(tosay) > 9) {
130 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
131 		return SWITCH_STATUS_GENERR;
132 	}
133 
134 	in = atoi(tosay);
135 
136 	if (in != 0) {
137 		for (x = 8; x >= 0; x--) {
138 			int num = (int) pow(10, x);
139 			if ((places[(uint32_t) x] = in / num)) {
140 				in -= places[(uint32_t) x] * num;
141 			}
142 		}
143 
144 
145 		switch (say_args->method) {
146 		case SSM_PRONOUNCED_YEAR:
147 			{
148 				int num = atoi(tosay);
149 				int a = num / 100;
150 				int b = num % 100;
151 
152 				if (!b || !(a % 10)) {
153 					say_num(sh, num, SSM_PRONOUNCED);
154 					return SWITCH_STATUS_SUCCESS;
155 				}
156 
157 				say_num(sh, a, SSM_PRONOUNCED);
158 				say_num(sh, b, SSM_PRONOUNCED);
159 
160 				return SWITCH_STATUS_SUCCESS;
161 			}
162 			break;
163 		case SSM_COUNTED:
164 		case SSM_PRONOUNCED:
165 			if ((status = play_group(SSM_PRONOUNCED, places[8], places[7], places[6], "digits/million", sh)) != SWITCH_STATUS_SUCCESS) {
166 				return status;
167 			}
168 			if ((status = play_group(SSM_PRONOUNCED, places[5], places[4], places[3], "digits/thousand", sh)) != SWITCH_STATUS_SUCCESS) {
169 				return status;
170 			}
171 			if ((status = play_group(say_args->method, places[2], places[1], places[0], NULL, sh)) != SWITCH_STATUS_SUCCESS) {
172 				return status;
173 			}
174 			break;
175 		default:
176 			break;
177 		}
178 	} else {
179 		switch_say_file(sh, "digits/0");
180 	}
181 
182 	return SWITCH_STATUS_SUCCESS;
183 }
184 
en_say_time(switch_say_file_handle_t * sh,char * tosay,switch_say_args_t * say_args)185 static switch_status_t en_say_time(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args)
186 {
187 	int32_t t = 0;
188 	switch_time_t target = 0, target_now = 0;
189 	switch_time_exp_t tm, tm_now;
190 	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;
191 	const char *tz = NULL;
192 
193 	tz = switch_say_file_handle_get_variable(sh, "timezone");
194 
195 
196 	if (say_args->type == SST_TIME_MEASUREMENT) {
197 		int64_t hours = 0;
198 		int64_t minutes = 0;
199 		int64_t seconds = 0;
200 		int64_t r = 0;
201 
202 		if (strchr(tosay, ':')) {
203 			char *tme = strdup(tosay);
204 			char *p;
205 			switch_assert(tme);
206 			if ((p = strrchr(tme, ':'))) {
207 				*p++ = '\0';
208 				seconds = atoi(p);
209 				if ((p = strchr(tme, ':'))) {
210 					*p++ = '\0';
211 					minutes = atoi(p);
212 					hours = atoi(tme);
213 				} else {
214 					minutes = atoi(tme);
215 				}
216 			}
217 			free(tme);
218 		} else {
219 
220 			if ((seconds = atol(tosay)) <= 0) {
221 				seconds = (int64_t) switch_epoch_time_now(NULL);
222 			}
223 
224 			if (seconds >= 60) {
225 				minutes = seconds / 60;
226 				r = seconds % 60;
227 				seconds = r;
228 			}
229 
230 			if (minutes >= 60) {
231 				hours = minutes / 60;
232 				r = minutes % 60;
233 				minutes = r;
234 			}
235 		}
236 
237 		if (hours) {
238 			say_num(sh, hours, SSM_PRONOUNCED);
239 			if (hours == 1) {
240 				switch_say_file(sh, "time/hour");
241 			} else {
242 				switch_say_file(sh, "time/hours");
243 			}
244 		} else {
245 			switch_say_file(sh, "digits/0");
246 			switch_say_file(sh, "time/hours");
247 		}
248 
249 		if (minutes) {
250 			say_num(sh, minutes, SSM_PRONOUNCED);
251 			if (minutes == 1) {
252 				switch_say_file(sh, "time/minute");
253 			} else {
254 				switch_say_file(sh, "time/minutes");
255 			}
256 		} else {
257 			switch_say_file(sh, "digits/0");
258 			switch_say_file(sh, "time/minutes");
259 		}
260 
261 		if (seconds) {
262 			say_num(sh, seconds, SSM_PRONOUNCED);
263 			if (seconds == 1) {
264 				switch_say_file(sh, "time/second");
265 			} else {
266 				switch_say_file(sh, "time/seconds");
267 			}
268 		} else {
269 			switch_say_file(sh, "digits/0");
270 			switch_say_file(sh, "time/seconds");
271 		}
272 
273 		return SWITCH_STATUS_SUCCESS;
274 	}
275 
276 	if (strchr(tosay, ':')) {
277 		switch_time_t tme  = switch_str_time(tosay);
278 		t = (int32_t) ((tme) / (int64_t) (1000000));
279 
280 		target = switch_time_make(t, 0);
281 		target_now = switch_micro_time_now();
282 	}
283 
284 	if (!t) {
285 		if ((t = atol(tosay)) > 0) {
286 			target = switch_time_make(t, 0);
287 			target_now = switch_micro_time_now();
288 		} else {
289 			target = switch_micro_time_now();
290 			target_now = switch_micro_time_now();
291 		}
292 	}
293 
294 	if (tz) {
295 		int check = atoi(tz);
296 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Timezone is [%s]\n", tz);
297 		if (check) {
298 			switch_time_exp_tz(&tm, target, check);
299 			switch_time_exp_tz(&tm_now, target_now, check);
300 		} else {
301 			switch_time_exp_tz_name(tz, &tm, target);
302 			switch_time_exp_tz_name(tz, &tm_now, target_now);
303 		}
304 	} else {
305 		switch_time_exp_lt(&tm, target);
306 		switch_time_exp_lt(&tm_now, target_now);
307 	}
308 
309 	switch (say_args->type) {
310 	case SST_CURRENT_DATE_TIME:
311 		say_date = say_time = 1;
312 		break;
313 	case SST_CURRENT_DATE:
314 		say_date = 1;
315 		break;
316 	case SST_CURRENT_TIME:
317 		say_time = 1;
318 		break;
319 	case SST_SHORT_DATE_TIME:
320 		say_time = 1;
321 		//Time is in the future
322 		if ((tm.tm_year > tm_now.tm_year) ||
323 		    (tm.tm_year == tm_now.tm_year && tm.tm_mon > tm_now.tm_mon) ||
324 		    (tm.tm_year == tm_now.tm_year && tm.tm_mon == tm_now.tm_mon && tm.tm_mday > tm_now.tm_mday))
325 		{
326 			say_date = 1;
327 			break;
328 		}
329 		//Time is today or earlier
330 		if (tm.tm_year != tm_now.tm_year) {
331 			say_date = 1;
332 			break;
333 		}
334 		if (tm.tm_yday == tm_now.tm_yday) {
335 			say_today = 1;
336 			break;
337 		}
338 		if (tm.tm_yday == tm_now.tm_yday - 1) {
339 			say_yesterday = 1;
340 			break;
341 		}
342 		if (tm.tm_yday >= tm_now.tm_yday - 5) {
343 			say_dow = 1;
344 			break;
345 		}
346 
347 		say_month = say_day = say_dow = 1;
348 
349 		break;
350 	default:
351 		break;
352 	}
353 
354 	if (say_date) {
355 		say_year = say_month = say_day = say_dow = 1;
356 		say_today = say_yesterday = 0;
357 	}
358 
359 	if (say_today) {
360 		switch_say_file(sh, "time/today");
361 	}
362 	if (say_yesterday) {
363 		switch_say_file(sh, "time/yesterday");
364 	}
365 	if (say_dow) {
366 		switch_say_file(sh, "time/day-%d", tm.tm_wday);
367 	}
368 	if (say_month) {
369 		switch_say_file(sh, "time/mon-%d", tm.tm_mon);
370 	}
371 	if (say_day) {
372 		say_num(sh, tm.tm_mday, SSM_COUNTED);
373 	}
374 	if (say_year) {
375 		say_num(sh, tm.tm_year + 1900, SSM_PRONOUNCED_YEAR);
376 	}
377 
378 	if (say_time) {
379 		int32_t hour = tm.tm_hour, mil = 0;
380 
381 		if (say_args->method == SSM_ITERATED) {
382 			mil = 1;
383 		}
384 
385 		if (say_date || say_today || say_yesterday || say_dow) {
386 			switch_say_file(sh, "time/at");
387 		}
388 
389 		if (mil) {
390 
391 			if (hour == 0 && tm.tm_min == 0) {
392 				hour = 24;
393 			}
394 
395 			if (hour < 10) {
396 				say_num(sh, 0, SSM_PRONOUNCED);
397 			}
398 
399 			say_num(sh, hour, SSM_PRONOUNCED);
400 
401 			if (tm.tm_min > 9) {
402 				say_num(sh, tm.tm_min, SSM_PRONOUNCED);
403 			} else if (tm.tm_min) {
404 				say_num(sh, 0, SSM_PRONOUNCED);
405 				say_num(sh, tm.tm_min, SSM_PRONOUNCED);
406 			} else {
407 				switch_say_file(sh, "digits/hundred");
408 			}
409 
410 			switch_say_file(sh, "time/hours");
411 
412 		} else {
413 			switch_bool_t pm = 0;
414 
415 			if (hour >= 12) {
416 				pm = 1;
417 			}
418 
419 			if (hour > 12) {
420 				hour -= 12;
421 			} else if (hour == 0) {
422 				hour = 12;
423 			}
424 
425 			say_num(sh, hour, SSM_PRONOUNCED);
426 
427 			if (tm.tm_min > 9) {
428 				say_num(sh, tm.tm_min, SSM_PRONOUNCED);
429 			} else if (tm.tm_min) {
430 				switch_say_file(sh, "time/oh");
431 				say_num(sh, tm.tm_min, SSM_PRONOUNCED);
432 			} else {
433 				switch_say_file(sh, "time/oclock");
434 			}
435 
436 			switch_say_file(sh, "time/%s", pm ? "p-m" : "a-m");
437 		}
438 	}
439 
440 	return SWITCH_STATUS_SUCCESS;
441 }
442 
443 
en_say_money(switch_say_file_handle_t * sh,char * tosay,switch_say_args_t * say_args)444 static switch_status_t en_say_money(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args)
445 {
446 	char sbuf[16] = "";			/* enough for 999,999,999,999.99 (w/o the commas or leading $) */
447 	char *dollars = NULL;
448 	char *cents = NULL;
449 
450 	if (strlen(tosay) > 15 || !switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)-1)) {
451 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
452 		return SWITCH_STATUS_GENERR;
453 	}
454 
455 	dollars = sbuf;
456 
457 	if ((cents = strchr(sbuf, '.'))) {
458 		*cents++ = '\0';
459 		if (strlen(cents) > 2) {
460 			cents[2] = '\0';
461 		}
462 	}
463 
464 	/* If positive sign - skip over" */
465 	if (sbuf[0] == '+') {
466 		dollars++;
467 	}
468 
469 	/* If negative say "negative" */
470 	if (sbuf[0] == '-') {
471 		switch_say_file(sh, "currency/negative");
472 		dollars++;
473 	}
474 
475 	/* Say dollar amount */
476 	en_say_general_count(sh, dollars, say_args);
477 	if (atoi(dollars) == 1) {
478 		switch_say_file(sh, "currency/dollar");
479 	} else {
480 		switch_say_file(sh, "currency/dollars");
481 	}
482 
483 	/* Say cents */
484 	if (cents) {
485 		/* Say "and" */
486 		switch_say_file(sh, "currency/and");
487 
488 		en_say_general_count(sh, cents, say_args);
489 		if (atoi(cents) == 1) {
490 			switch_say_file(sh, "currency/cent");
491 		} else {
492 			switch_say_file(sh, "currency/cents");
493 		}
494 	}
495 
496 	return SWITCH_STATUS_SUCCESS;
497 }
498 
499 
say_ip(switch_say_file_handle_t * sh,char * tosay,switch_say_args_t * say_args)500 static switch_status_t say_ip(switch_say_file_handle_t *sh,
501 							  char *tosay,
502 							  switch_say_args_t *say_args)
503 
504 {
505 	char *a, *b, *c, *d;
506 	switch_status_t status = SWITCH_STATUS_FALSE;
507 
508 	if (!(a = strdup(tosay))) {
509 		abort();
510 	}
511 
512 	if (!(b = strchr(a, '.'))) {
513 		goto end;
514 	}
515 
516 	*b++ = '\0';
517 
518 	if (!(c = strchr(b, '.'))) {
519 		goto end;
520 	}
521 
522 	*c++ = '\0';
523 
524 	if (!(d = strchr(c, '.'))) {
525 		goto end;
526 	}
527 
528 	*d++ = '\0';
529 
530 	say_num(sh, atoi(a), say_args->method);
531 	switch_say_file(sh, "digits/dot");
532 	say_num(sh, atoi(b), say_args->method);
533 	switch_say_file(sh, "digits/dot");
534 	say_num(sh, atoi(c), say_args->method);
535 	switch_say_file(sh, "digits/dot");
536 	say_num(sh, atoi(d), say_args->method);
537 
538  end:
539 
540 	free(a);
541 
542 	return status;
543 }
544 
545 
say_telephone_number(switch_say_file_handle_t * sh,char * tosay,switch_say_args_t * say_args)546 static switch_status_t say_telephone_number(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args)
547 {
548 	int silence = 0;
549 	char *p;
550 
551 	for (p = tosay; !zstr(p); p++) {
552 		int a = tolower((int) *p);
553 		if (a >= '0' && a <= '9') {
554 			switch_say_file(sh, "digits/%c", a);
555 			silence = 0;
556 		} else if (a == '+' || (a >= 'a' && a <= 'z')) {
557 			switch_say_file(sh, "ascii/%d", a);
558 			silence = 0;
559 		} else if (!silence) {
560 			switch_say_file(sh, "silence_stream://100");
561 			silence = 1;
562 		}
563 	}
564 
565 	return SWITCH_STATUS_SUCCESS;
566 }
567 
568 
say_spell(switch_say_file_handle_t * sh,char * tosay,switch_say_args_t * say_args)569 static switch_status_t say_spell(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args)
570 {
571 	char *p;
572 
573 	for (p = tosay; p && *p; p++) {
574 		int a = tolower((int) *p);
575 		if (a >= '0' && a <= '9') {
576 			switch_say_file(sh, "digits/%c", a);
577 		} else {
578 			if (say_args->type == SST_NAME_SPELLED) {
579 				switch_say_file(sh, "ascii/%d", a);
580 			} else if (say_args->type == SST_NAME_PHONETIC) {
581 				switch_say_file(sh, "phonetic-ascii/%d", a);
582 			}
583 		}
584 	}
585 
586 	return SWITCH_STATUS_SUCCESS;
587 }
588 
589 
choose_callback(switch_say_args_t * say_args)590 static switch_new_say_callback_t choose_callback(switch_say_args_t *say_args)
591 {
592 	switch_new_say_callback_t say_cb = NULL;
593 
594 	switch (say_args->type) {
595 	case SST_NUMBER:
596 	case SST_ITEMS:
597 	case SST_PERSONS:
598 	case SST_MESSAGES:
599 		say_cb = en_say_general_count;
600 		break;
601 	case SST_TIME_MEASUREMENT:
602 	case SST_CURRENT_DATE:
603 	case SST_CURRENT_TIME:
604 	case SST_CURRENT_DATE_TIME:
605 	case SST_SHORT_DATE_TIME:
606 		say_cb = en_say_time;
607 		break;
608 	case SST_IP_ADDRESS:
609 		say_cb = say_ip;
610 		break;
611 	case SST_NAME_SPELLED:
612 	case SST_NAME_PHONETIC:
613 		say_cb = say_spell;
614 		break;
615 	case SST_CURRENCY:
616 		say_cb = en_say_money;
617 		break;
618 	case SST_TELEPHONE_NUMBER:
619 		say_cb = say_telephone_number;
620 		break;
621 	default:
622 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown Say type=[%d]\n", say_args->type);
623 		break;
624 	}
625 
626 	return say_cb;
627 }
628 
629 
run_callback(switch_new_say_callback_t say_cb,char * tosay,switch_say_args_t * say_args,switch_core_session_t * session,char ** rstr)630 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)
631 {
632 	switch_say_file_handle_t *sh;
633 	switch_status_t status = SWITCH_STATUS_FALSE;
634 	switch_event_t *var_event = NULL;
635 
636 	if (session) {
637 		switch_channel_t *channel = switch_core_session_get_channel(session);
638 		switch_channel_get_variables(channel, &var_event);
639 	}
640 
641 	switch_say_file_handle_create(&sh, say_args->ext, &var_event);
642 
643 	status = say_cb(sh, tosay, say_args);
644 
645 	if ((*rstr = switch_say_file_handle_detach_path(sh))) {
646 		status = SWITCH_STATUS_SUCCESS;
647 	}
648 
649 	switch_say_file_handle_destroy(&sh);
650 
651 	return status;
652 }
653 
654 
en_say(switch_core_session_t * session,char * tosay,switch_say_args_t * say_args,switch_input_args_t * args)655 static switch_status_t en_say(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
656 {
657 
658 	switch_new_say_callback_t say_cb = NULL;
659 	char *string = NULL;
660 
661 	switch_status_t status = SWITCH_STATUS_FALSE;
662 
663 	say_cb = choose_callback(say_args);
664 
665 	if (say_cb) {
666 		status = run_callback(say_cb, tosay, say_args, session, &string);
667 		if (session && string) {
668 			status = switch_ivr_play_file(session, NULL, string, args);
669 		}
670 
671 		switch_safe_free(string);
672 	}
673 
674 	return status;
675 }
676 
677 
en_say_string(switch_core_session_t * session,char * tosay,switch_say_args_t * say_args,char ** rstr)678 static switch_status_t en_say_string(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, char **rstr)
679 {
680 
681 	switch_new_say_callback_t say_cb = NULL;
682 	char *string = NULL;
683 
684 	switch_status_t status = SWITCH_STATUS_FALSE;
685 
686 	say_cb = choose_callback(say_args);
687 
688 	if (say_cb) {
689 		status = run_callback(say_cb, tosay, say_args, session, &string);
690 		if (string) {
691 			status = SWITCH_STATUS_SUCCESS;
692 			*rstr = string;
693 		}
694 	}
695 
696 	return status;
697 }
698 
SWITCH_MODULE_LOAD_FUNCTION(mod_say_en_load)699 SWITCH_MODULE_LOAD_FUNCTION(mod_say_en_load)
700 {
701 	switch_say_interface_t *say_interface;
702 	/* connect my internal structure to the blank pointer passed to me */
703 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
704 	say_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_SAY_INTERFACE);
705 	say_interface->interface_name = "en";
706 	say_interface->say_function = en_say;
707 	say_interface->say_string_function = en_say_string;
708 
709 	/* indicate that the module should continue to be loaded */
710 	return SWITCH_STATUS_SUCCESS;
711 }
712 
713 /* For Emacs:
714  * Local Variables:
715  * mode:c
716  * indent-tabs-mode:t
717  * tab-width:4
718  * c-basic-offset:4
719  * End:
720  * For VIM:
721  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
722  */
723