diff --git a/chan_capi.c b/chan_capi.c index 5c2d014..388384e 100644 --- a/chan_capi.c +++ b/chan_capi.c @@ -3744,7 +3744,7 @@ static int handle_facility_indication_dtmf( } } if (ignore_digit == 0) { - if (pbx_capi_voicecommand_process_digit(i, dtmf) == 0) { + if (pbx_capi_voicecommand_process_digit(i, 0, dtmf) == 0) { fr.frametype = AST_FRAME_DTMF; fr.subclass = dtmf; local_queue_frame(i, &fr); @@ -4839,7 +4839,7 @@ static void capidev_handle_msg(_cmsg *CMSG) static struct capi_pvt* get_active_plci (struct ast_channel *c) { - struct capi_pvt* i = pbx_check_resource_plci (c); + struct capi_pvt* i = pbx_check_resource_plci(c); if (i == NULL) i = CC_CHANNEL_PVT(c); diff --git a/chan_capi_chat.c b/chan_capi_chat.c index 8db45eb..3147063 100644 --- a/chan_capi_chat.c +++ b/chan_capi_chat.c @@ -20,6 +20,7 @@ #include "chan_capi.h" #include "chan_capi_chat.h" #include "chan_capi_utils.h" +#include "chan_capi_command.h" #define CHAT_FLAG_MOH 0x0001 @@ -479,6 +480,8 @@ static void chat_handle_events(struct ast_channel *c, struct capi_pvt *i, /* ignore NULL frame */ cc_verbose(5, 1, VERBOSE_PREFIX_3 "%s: chat: NULL frame, ignoring.\n", i->vname); + } else if ((f->frametype == AST_FRAME_DTMF_END) && (voice_message == 0)) { + pbx_capi_voicecommand_process_digit (i, c, f->subclass); } else { cc_verbose(3, 1, VERBOSE_PREFIX_3 "%s: chat: unhandled frame %d/%d.\n", i->vname, f->frametype, f->subclass); diff --git a/chan_capi_command.c b/chan_capi_command.c index a55de93..8b66e6b 100644 --- a/chan_capi_command.c +++ b/chan_capi_command.c @@ -61,8 +61,8 @@ typedef struct _pbx_capi_voice_command { */ static const char* pbx_capi_voicecommand_digits = "1234567890ABCD*#"; static int pbx_capi_command_nop (struct ast_channel *c, char *param); -static pbx_capi_voice_command_t* pbx_capi_find_command (struct ast_channel *c, const char* name); -static pbx_capi_voice_command_t* pbx_capi_find_command_by_key (struct ast_channel *c, const char* key); +static pbx_capi_voice_command_t* pbx_capi_find_command (struct capi_pvt *i, const char* name); +static pbx_capi_voice_command_t* pbx_capi_find_command_by_key (struct capi_pvt *i, const char* key); static pbx_capi_voice_command_t* pbx_capi_voicecommand_find_digit_command (diva_entity_queue_t* q, const char* digits, int length, int* info); static void pbx_capi_voicecommand_insert_command (diva_entity_queue_t* q, pbx_capi_voice_command_t* cmd); @@ -73,12 +73,22 @@ static void pbx_capi_voicecommand_insert_command (diva_entity_queue_t* q, pbx_ca */ int pbx_capi_voicecommand(struct ast_channel *c, char *param) { - struct capi_pvt *i = CC_CHANNEL_PVT(c); + struct capi_pvt *i; pbx_capi_voice_command_t* cmd; const char* command[2]; const char* key[2]; size_t length; + if (c->tech == &capi_tech) { + i = CC_CHANNEL_PVT(c); + } else { + i = pbx_check_resource_plci(c); + } + if (i == 0) { + return 0; + } + + if ((param == NULL) || (*param == 0)) { /* Remove all voice commands */ cc_mutex_lock(&i->lock); pbx_capi_voicecommand_cleanup(i); @@ -94,7 +104,7 @@ int pbx_capi_voicecommand(struct ast_channel *c, char *param) * Remove command */ cc_mutex_lock(&i->lock); - while ((cmd = pbx_capi_find_command (c, command[0])) != 0) { + while ((cmd = pbx_capi_find_command (i, command[0])) != 0) { cc_verbose(2, 0, VERBOSE_PREFIX_4"%s: voicecommand:%s removed\n", i->vname, cmd->command_name); diva_q_remove (&i->channel_command_q, &cmd->link); free (cmd); @@ -166,7 +176,7 @@ int pbx_capi_voicecommand(struct ast_channel *c, char *param) pbx_capi_voice_command_t* present_cmd; cc_mutex_lock(&i->lock); - if ((present_cmd = pbx_capi_find_command_by_key (c, cmd->command_name)) != 0) { + if ((present_cmd = pbx_capi_find_command_by_key (i, cmd->command_name)) != 0) { diva_q_remove (&i->channel_command_q, &present_cmd->link); } pbx_capi_voicecommand_insert_command (&i->channel_command_q, cmd); @@ -183,7 +193,16 @@ int pbx_capi_voicecommand(struct ast_channel *c, char *param) int pbx_capi_voicecommand_transparency(struct ast_channel *c, char *param) { - struct capi_pvt *i = CC_CHANNEL_PVT(c); + struct capi_pvt *i; + + if (c->tech == &capi_tech) { + i = CC_CHANNEL_PVT(c); + } else { + i = pbx_check_resource_plci(c); + } + if (i == 0) { + return 0; + } if ((param == NULL) || (*param == 0)) { cc_log(LOG_WARNING, "Parameter for voicecommand transparency missing.\n"); @@ -218,9 +237,8 @@ int pbx_capi_voicecommand_cleanup(struct capi_pvt *i) return 0; } -static pbx_capi_voice_command_t* pbx_capi_find_command(struct ast_channel *c, const char* name) +static pbx_capi_voice_command_t* pbx_capi_find_command(struct capi_pvt *i, const char* name) { - struct capi_pvt *i = CC_CHANNEL_PVT(c); diva_entity_link_t* link; for (link = diva_q_get_head (&i->channel_command_q); link != 0; link = diva_q_get_next(link)) { @@ -232,9 +250,8 @@ static pbx_capi_voice_command_t* pbx_capi_find_command(struct ast_channel *c, co return 0; } -static pbx_capi_voice_command_t* pbx_capi_find_command_by_key(struct ast_channel *c, const char* key) +static pbx_capi_voice_command_t* pbx_capi_find_command_by_key(struct capi_pvt *i, const char* key) { - struct capi_pvt *i = CC_CHANNEL_PVT(c); diva_entity_link_t* link; for (link = diva_q_get_head (&i->channel_command_q); link != 0; link = diva_q_get_next(link)) { @@ -252,9 +269,9 @@ static pbx_capi_voice_command_t* pbx_capi_find_command_by_key(struct ast_channel * returs zero if digit should be processed as usually * returns -1 if digit should be discarded */ -int pbx_capi_voicecommand_process_digit(struct capi_pvt *i, char digit) +int pbx_capi_voicecommand_process_digit(struct capi_pvt *i, struct ast_channel *owner, char digit) { - struct ast_channel *c = i->owner; + struct ast_channel *c = (owner == 0) ? i->owner : owner; pbx_capi_voice_command_t* cmd; int info; time_t t; diff --git a/chan_capi_command.h b/chan_capi_command.h index 0e42997..c938b1e 100644 --- a/chan_capi_command.h +++ b/chan_capi_command.h @@ -25,7 +25,7 @@ int pbx_capi_voicecommand (struct ast_channel *c, char *param); int pbx_capi_voicecommand_transparency (struct ast_channel *c, char *param); -int pbx_capi_voicecommand_process_digit (struct capi_pvt *i, char digit); +int pbx_capi_voicecommand_process_digit (struct capi_pvt *i, struct ast_channel *owner, char digit); int pbx_capi_voicecommand_cleanup (struct capi_pvt *i); #endif