[Freeswitch-trunk] [commit] r13927 - freeswitch/trunk/src/mod/asr_tts/mod_unimrcp

FreeSWITCH SVN crienzo at freeswitch.org
Tue Jun 23 16:28:10 PDT 2009


Author: crienzo
Date: Tue Jun 23 18:28:09 2009
New Revision: 13927

Log:
use inline: for inline grammars.  local files are now handled like mod_pocketsphinx

Modified:
   freeswitch/trunk/src/mod/asr_tts/mod_unimrcp/mod_unimrcp.c

Modified: freeswitch/trunk/src/mod/asr_tts/mod_unimrcp/mod_unimrcp.c
==============================================================================
--- freeswitch/trunk/src/mod/asr_tts/mod_unimrcp/mod_unimrcp.c	(original)
+++ freeswitch/trunk/src/mod/asr_tts/mod_unimrcp/mod_unimrcp.c	Tue Jun 23 18:28:09 2009
@@ -149,6 +149,7 @@
 #define BUILTIN_ID "builtin:"
 #define SESSION_ID "session:"
 #define HTTP_ID "http://"
+#define INLINE_ID "inline:"
 static int text_starts_with(const char *text, const char *match);
 
 /**
@@ -2449,7 +2450,7 @@
 	switch_size_t grammar_file_size = 0, to_read = 0;
 	grammar_type_t type = GRAMMAR_TYPE_UNKNOWN;
 	const char *lname = switch_strlen_zero(name) ? "grammar" : name;
-
+	char *filename = NULL;
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) grammar = %s, name = %s\n", schannel->name, grammar, name);
 
 	if (switch_strlen_zero(grammar)) {
@@ -2463,45 +2464,48 @@
 		goto done;
 	}
 
-	/* check for local file grammar or URI grammar */
+	/* figure out what type of grammar this is */
 	if (text_starts_with(grammar, HTTP_ID) || text_starts_with(grammar, SESSION_ID) || text_starts_with(grammar, BUILTIN_ID)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) Grammar is URI\n", schannel->name);
 		type = GRAMMAR_TYPE_URI;
 		grammar_data = grammar;
-	} else if (switch_is_file_path(grammar)) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) Grammar is inside file\n", schannel->name);
+	} else if (text_starts_with(grammar, INLINE_ID)) {
+		grammar_data = grammar + strlen(INLINE_ID);
+	} else {
 		/* grammar points to file containing the grammar text.  We assume the MRCP server can't get to this file
 		 * so read the data from the file and cache it */
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) Grammar is inside file\n", schannel->name);
+		if (switch_is_file_path(grammar)) {
+			filename = switch_mprintf("%s.gram", grammar);
+		} else {
+			filename = switch_mprintf("%s%s%s.gram", SWITCH_GLOBAL_dirs.grammar_dir, SWITCH_PATH_SEPARATOR, grammar);
+		}
 		grammar_data = NULL;
-
-		if (switch_file_open(&grammar_file, grammar, SWITCH_FOPEN_READ, 0, schannel->memory_pool) != SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) Could not read grammar file: %s\n", schannel->name, grammar);
+		if (switch_file_open(&grammar_file, filename, SWITCH_FOPEN_READ, 0, schannel->memory_pool) != SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) Could not read grammar file: %s\n", schannel->name, filename);
 			status = SWITCH_STATUS_FALSE;
 			goto done;
 		}
 		grammar_file_size = switch_file_get_size(grammar_file);
 		if (grammar_file_size == 0) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) Grammar file is empty: %s\n", schannel->name, grammar);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) Grammar file is empty: %s\n", schannel->name, filename);
 			status = SWITCH_STATUS_FALSE;
 			goto done;
 		}
 		grammar_file_data = (char *)switch_core_alloc(schannel->memory_pool, grammar_file_size + 1);
 		to_read = grammar_file_size;
 		if (switch_file_read(grammar_file, grammar_file_data, &to_read) != SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) Grammar file read error: %s\n", schannel->name, grammar);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) Grammar file read error: %s\n", schannel->name, filename);
 			status = SWITCH_STATUS_FALSE;
 			goto done;
 		}
 		if (to_read != grammar_file_size) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) Could not read entire grammar file: %s\n", schannel->name, grammar);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) Could not read entire grammar file: %s\n", schannel->name, filename);
 			status = SWITCH_STATUS_FALSE;
 			goto done;
 		}
 		grammar_file_data[to_read] = '\0';
 		grammar_data = grammar_file_data;
-	} else {
-		/* assume inline grammar */
-		grammar_data = grammar;
 	}
 
 	/* determine content type of file grammar or inline grammar */
@@ -2532,6 +2536,7 @@
 
  done:
 
+	switch_safe_free(filename);
 	if (grammar_file) {
 		switch_file_close(grammar_file);
 	}



More information about the Freeswitch-trunk mailing list