diff --git a/mod_unimrcp.c b/mod_unimrcp.c index 5fb772f..5faac64 100644 --- a/mod_unimrcp.c +++ b/mod_unimrcp.c @@ -1459,7 +1459,7 @@ static const char *speech_channel_type_to_string(speech_channel_type_t type) static switch_status_t speech_channel_set_param(speech_channel_t *schannel, const char *param, const char *val) { switch_mutex_lock(schannel->mutex); - if (!zstr(param) && val != NULL) { + if (!zstr(param) && val != NULL && schannel->params) { /* check if this is a FreeSWITCH param that needs to be translated to an MRCP param: e.g. voice ==> voice-name */ const char *v; const char *p = switch_core_hash_find(schannel->application->fs_param_map, param); @@ -2428,8 +2428,8 @@ static switch_status_t recog_channel_load_grammar(speech_channel_t *schannel, co } /* Create the grammar and save it */ - if ((status = grammar_create(&g, name, type, data, schannel->memory_pool)) == SWITCH_STATUS_SUCCESS) { - recognizer_data_t *r = (recognizer_data_t *) schannel->data; + recognizer_data_t *r = (recognizer_data_t *) schannel->data; + if (r->grammars && (status = grammar_create(&g, name, type, data, schannel->memory_pool)) == SWITCH_STATUS_SUCCESS) { switch_core_hash_insert(r->grammars, g->name, g); } @@ -2459,8 +2459,12 @@ static switch_status_t recog_channel_unload_grammar(speech_channel_t *schannel, switch_log_printf(SWITCH_CHANNEL_UUID_LOG(schannel->session_uuid), SWITCH_LOG_DEBUG, "(%s) Unloading grammar %s\n", schannel->name, grammar_name); switch_mutex_lock(schannel->mutex); - switch_core_hash_delete(r->enabled_grammars, grammar_name); - switch_core_hash_delete(r->grammars, grammar_name); + if (r->enabled_grammars) { + switch_core_hash_delete(r->enabled_grammars, grammar_name); + } + if (r->grammars) { + switch_core_hash_delete(r->grammars, grammar_name); + } switch_mutex_unlock(schannel->mutex); } @@ -2485,13 +2489,12 @@ static switch_status_t recog_channel_enable_grammar(speech_channel_t *schannel, grammar_t *grammar; switch_mutex_lock(schannel->mutex); - grammar = (grammar_t *) switch_core_hash_find(r->grammars, grammar_name); - if (grammar == NULL) + if (r->grammars && (grammar = (grammar_t *) switch_core_hash_find(r->grammars, grammar_name)) == NULL) { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(schannel->session_uuid), SWITCH_LOG_ERROR, "(%s) Undefined grammar, %s\n", schannel->name, grammar_name); status = SWITCH_STATUS_FALSE; } - else { + else if (r->enabled_grammars) { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(schannel->session_uuid), SWITCH_LOG_DEBUG, "(%s) Enabling grammar %s\n", schannel->name, grammar_name); switch_core_hash_insert(r->enabled_grammars, grammar_name, grammar); } @@ -2519,7 +2522,9 @@ static switch_status_t recog_channel_disable_grammar(speech_channel_t *schannel, switch_log_printf(SWITCH_CHANNEL_UUID_LOG(schannel->session_uuid), SWITCH_LOG_DEBUG, "(%s) Disabling grammar %s\n", schannel->name, grammar_name); switch_mutex_lock(schannel->mutex); - switch_core_hash_delete(r->enabled_grammars, grammar_name); + if (r->enabled_grammars) { + switch_core_hash_delete(r->enabled_grammars, grammar_name); + } switch_mutex_unlock(schannel->mutex); } @@ -2534,14 +2539,17 @@ static switch_status_t recog_channel_disable_grammar(speech_channel_t *schannel, */ static switch_status_t recog_channel_disable_all_grammars(speech_channel_t *schannel) { - switch_status_t status = SWITCH_STATUS_SUCCESS; + switch_status_t status = SWITCH_STATUS_FALSE; recognizer_data_t *r = (recognizer_data_t *) schannel->data; switch_log_printf(SWITCH_CHANNEL_UUID_LOG(schannel->session_uuid), SWITCH_LOG_DEBUG, "(%s) Disabling all grammars\n", schannel->name); switch_mutex_lock(schannel->mutex); - switch_core_hash_destroy(&r->enabled_grammars); - switch_core_hash_init(&r->enabled_grammars); + if (r->enabled_grammars) { + switch_core_hash_destroy(&r->enabled_grammars); + switch_core_hash_init(&r->enabled_grammars); + status = SWITCH_STATUS_SUCCESS; + } switch_mutex_unlock(schannel->mutex); return status;