[Freeswitch-svn] [commit] r3318 - in freeswitch/branches/knhor/trunk: . src src/include src/mod/applications/mod_conference
Freeswitch SVN
knhor at freeswitch.org
Sat Nov 11 18:22:18 EST 2006
Author: knhor
Date: Sat Nov 11 18:22:17 2006
New Revision: 3318
Modified:
freeswitch/branches/knhor/trunk/ (props changed)
freeswitch/branches/knhor/trunk/src/include/switch_ivr.h
freeswitch/branches/knhor/trunk/src/include/switch_types.h
freeswitch/branches/knhor/trunk/src/mod/applications/mod_conference/mod_conference.c
freeswitch/branches/knhor/trunk/src/switch_ivr.c
Log:
add empty functions for handling dtmf digit string event mapping.
change mod_conference to use the new dtmf digit string functions
Modified: freeswitch/branches/knhor/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/branches/knhor/trunk/src/include/switch_ivr.h (original)
+++ freeswitch/branches/knhor/trunk/src/include/switch_ivr.h Sat Nov 11 18:22:17 2006
@@ -402,6 +402,42 @@
*/
SWITCH_DECLARE(switch_status_t) switch_ivr_transfer_variable(switch_core_session_t *sessa, switch_core_session_t *sessb, char *var);
+
+struct switch_ivr_digit_stream_parser {
+};
+typedef struct switch_ivr_digit_stream_parser switch_ivr_digit_stream_parser_t;
+/*!
+ \brief Create a digit stream parser object
+ \param parser a pointer to the object pointer
+ \return SWITCH_STATUS_SUCCESS if all is well
+*/
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_new(switch_ivr_digit_stream_parser_t **parser);
+
+/*!
+ \brief Set a digit string to action mapping
+ \param parser a pointer to the parser object created by switch_ivr_digit_stream_parser_new
+ \param digits a string of digits to associate with an action
+ \param action the action to signal when the digit string is matched
+ \return SWITCH_STATUS_SUCCESS if all is well
+*/
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_event(switch_ivr_digit_stream_parser_t *parser, char *digits, int action);
+
+/*!
+ \brief Delete a string to action mapping
+ \param parser a pointer to the parser object created by switch_ivr_digit_stream_parser_new
+ \param digits the digit string to be removed from the map
+ \return SWITCH_STATUS_SUCCESS if all is well
+*/
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_del_event(switch_ivr_digit_stream_parser_t *parser, char *digits);
+
+/*!
+ \brief Create a digit stream parser object
+ \param parser a pointer to the parser object created by switch_ivr_digit_stream_parser_new
+ \param digit a digit to collect and test against the map of digit strings
+ \return 0 if no match found or non-zero action that was associated with a given digit string when matched
+*/
+SWITCH_DECLARE(int) switch_ivr_digit_stream_parser_feed(switch_ivr_digit_stream_parser_t *parser, char digit);
+
/** @} */
SWITCH_END_EXTERN_C
Modified: freeswitch/branches/knhor/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/branches/knhor/trunk/src/include/switch_types.h (original)
+++ freeswitch/branches/knhor/trunk/src/include/switch_types.h Sat Nov 11 18:22:17 2006
@@ -905,6 +905,8 @@
struct switch_core_session;
/*! \brief An audio bug */
struct switch_media_bug;
+/*! \brief A digit stream parser object */
+struct switch_ivr_digit_stream_parser;
SWITCH_END_EXTERN_C
Modified: freeswitch/branches/knhor/trunk/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/branches/knhor/trunk/src/mod/applications/mod_conference/mod_conference.c (original)
+++ freeswitch/branches/knhor/trunk/src/mod/applications/mod_conference/mod_conference.c Sat Nov 11 18:22:17 2006
@@ -56,6 +56,22 @@
FILE_STOP_ALL
} file_stop_t;
+typedef enum {
+ CALLER_CONTROL_NOEVENT,
+ CALLER_CONTROL_MUTE,
+ CALLER_CONTROL_DEAF_MUTE,
+ CALLER_CONTROL_ENERGY_UP,
+ CALLER_CONTROL_ENERGY_EQU_CONFERENCE,
+ CALLER_CONTROL_ENERGEY_DN,
+ CALLER_CONTROL_VOL_TALK_UP,
+ CALLER_CONTROL_VOL_TALK_ZERO,
+ CALLER_CONTROL_VOL_TALK_DN,
+ CALLER_CONTROL_VOL_LISTEN_UP,
+ CALLER_CONTROL_VOL_LISTEN_ZERO,
+ CALLER_CONTROL_VOL_LISTEN_DN,
+ CALLER_CONTROL_HANGUP,
+} caller_control_t;
+
/* Global Values */
static struct {
switch_memory_pool_t *conference_pool;
@@ -130,7 +146,7 @@
char *kicked_sound;
char *caller_id_name;
char *caller_id_number;
- char *caller_dtmf_control;
+ switch_ivr_digit_stream_parser_t *dtmf_parser;
char *pin;
char *pin_sound;
char *bad_pin_sound;
@@ -997,56 +1013,50 @@
}
if (switch_channel_has_dtmf(channel)) {
- char *pcontroldigit;
-
switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
- for (digit = dtmf; *digit; digit++) {
- // The position of the dialed digit in the control string
- // determines the operation that is being requested
- // To disable the function for the user, make the control
- // string digit something that can't be dialed... ie. a space
- // The control string MUST have 12 characters in it
- pcontroldigit = strchr(member->conference->caller_dtmf_control,*digit);
-
- if(pcontroldigit != NULL) {
- switch(pcontroldigit-member->conference->caller_dtmf_control) {
- case 0:
- conference_loop_fn_mute_toggle(member);
+ if(member->conference->dtmf_parser != NULL) {
+ for (digit = dtmf; *digit; digit++) {
+ switch(switch_ivr_digit_stream_parser_feed(member->conference->dtmf_parser, *digit)) {
+ case CALLER_CONTROL_NOEVENT:
+ // the digit string collected so far has not been recognized
+ break;
+ case CALLER_CONTROL_MUTE:
+ conference_loop_fn_mute_toggle(member);
+ break;
+ case CALLER_CONTROL_DEAF_MUTE:
+ conference_loop_fn_deafmute_toggle(member);
+ break;
+ case CALLER_CONTROL_ENERGY_UP:
+ conference_loop_fn_energy_up(member);
+ break;
+ case CALLER_CONTROL_ENERGY_EQU_CONFERENCE:
+ conference_loop_fn_energy_equ_conference(member);
+ break;
+ case CALLER_CONTROL_ENERGEY_DN:
+ conference_loop_fn_energy_dn(member);
+ break;
+ case CALLER_CONTROL_VOL_TALK_UP:
+ conference_loop_fn_volume_talk_up(member);
+ break;
+ case CALLER_CONTROL_VOL_TALK_ZERO:
+ conference_loop_fn_volume_talk_zero(member);
+ break;
+ case CALLER_CONTROL_VOL_TALK_DN:
+ conference_loop_fn_volume_talk_dn(member);
+ break;
+ case CALLER_CONTROL_VOL_LISTEN_UP:
+ conference_loop_fn_volume_listen_up(member);
+ break;
+ case CALLER_CONTROL_VOL_LISTEN_ZERO:
+ conference_loop_fn_volume_listen_zero(member);
+ break;
+ case CALLER_CONTROL_VOL_LISTEN_DN:
+ conference_loop_fn_volume_listen_dn(member);
+ break;
+ case CALLER_CONTROL_HANGUP:
+ conference_loop_fn_hangup(member);
break;
- case 1:
- conference_loop_fn_deafmute_toggle(member);
- break;
- case 2:
- conference_loop_fn_energy_up(member);
- break;
- case 3:
- conference_loop_fn_energy_equ_conference(member);
- break;
- case 4:
- conference_loop_fn_energy_dn(member);
- break;
- case 5:
- conference_loop_fn_volume_talk_up(member);
- break;
- case 6:
- conference_loop_fn_volume_talk_zero(member);
- break;
- case 7:
- conference_loop_fn_volume_talk_dn(member);
- break;
- case 8:
- conference_loop_fn_volume_listen_up(member);
- break;
- case 9:
- conference_loop_fn_volume_listen_zero(member);
- break;
- case 10:
- conference_loop_fn_volume_listen_dn(member);
- break;
- case 11:
- conference_loop_fn_hangup(member);
- break;
}
}
}
@@ -3222,7 +3232,7 @@
static conference_obj_t *conference_new(char *name, switch_xml_t profile, switch_memory_pool_t *pool)
{
conference_obj_t *conference;
- switch_xml_t param;
+ switch_xml_t xml_kvp;
char *rate_name = NULL;
char *interval_name = NULL;
char *timer_name = NULL;
@@ -3244,7 +3254,6 @@
char *energy_level = NULL;
char *caller_id_name = NULL;
char *caller_id_number = NULL;
- char *caller_dtmf_control = "0*987321654#";
uint32_t rate = 8000, interval = 20;
switch_status_t status;
@@ -3254,10 +3263,10 @@
return NULL;
}
- // parse the profile tree for config values
- for (param = switch_xml_child(profile, "param"); param; param = param->next) {
- char *var = (char *) switch_xml_attr_soft(param, "name");
- char *val = (char *) switch_xml_attr_soft(param, "value");
+ // parse the profile tree for param values
+ for (xml_kvp = switch_xml_child(profile, "param"); xml_kvp; xml_kvp = xml_kvp->next) {
+ char *var = (char *) switch_xml_attr_soft(xml_kvp, "name");
+ char *val = (char *) switch_xml_attr_soft(xml_kvp, "value");
char buf[128] = "";
char *p;
@@ -3313,8 +3322,6 @@
caller_id_name = val;
} else if (!strcasecmp(var, "caller-id-number")) {
caller_id_number = val;
- } else if (!strcasecmp(var, "caller-dtmf-control")) {
- caller_dtmf_control = val;
}
}
@@ -3376,23 +3383,6 @@
conference->caller_id_name = switch_core_strdup(conference->pool, caller_id_name);
conference->caller_id_number = switch_core_strdup(conference->pool, caller_id_number);
- // The position of the dialed digit in the control string
- // determines the operation that is being requested
- // To disable the function for the user, make the control
- // string digit something that can't be dialed... ie. a space
- // The control string MUST have 12 characters in it
- if(strlen(caller_dtmf_control) < 12) {
- char dbuf[13];
-
- memset(dbuf,' ',sizeof(dbuf));
- dbuf[12] = '\0';
- memcpy(dbuf,caller_dtmf_control,MIN(sizeof(dbuf)-1,strlen(caller_dtmf_control)));
-
- conference->caller_dtmf_control = switch_core_strdup(conference->pool, dbuf);
- } else {
- conference->caller_dtmf_control = switch_core_strdup(conference->pool, caller_dtmf_control);
- }
-
if (!switch_strlen_zero(enter_sound)) {
conference->enter_sound = switch_core_strdup(conference->pool, enter_sound);
}
@@ -3454,6 +3444,55 @@
conference->rate = rate;
conference->interval = interval;
+ if(switch_ivr_digit_stream_parser_new(&conference->dtmf_parser) == SWITCH_STATUS_SUCCESS) {
+ int i;
+ struct _ccds {
+ char *key;
+ char *digits;
+ caller_control_t action;
+ } ccds[] = {
+ {"mute", "0", CALLER_CONTROL_MUTE},
+ {"deaf mute", "*", CALLER_CONTROL_DEAF_MUTE},
+ {"energy up", "9", CALLER_CONTROL_ENERGY_UP},
+ {"energy equ", "8", CALLER_CONTROL_ENERGY_EQU_CONFERENCE},
+ {"energy dn", "7", CALLER_CONTROL_ENERGEY_DN},
+ {"vol talk up", "3", CALLER_CONTROL_VOL_TALK_UP},
+ {"vol talk zero", "2", CALLER_CONTROL_VOL_TALK_ZERO},
+ {"vol talk dn", "1", CALLER_CONTROL_VOL_TALK_DN},
+ {"vol listen up", "6", CALLER_CONTROL_VOL_LISTEN_UP},
+ {"vol listen zero", "5", CALLER_CONTROL_VOL_LISTEN_ZERO},
+ {"vol listen dn", "4", CALLER_CONTROL_VOL_LISTEN_DN},
+ {"hangup", "#", CALLER_CONTROL_HANGUP},
+ };
+ int ccds_qty = sizeof(ccds)/sizeof(ccds[0]);
+
+ // set the default control handler strings
+ for(i=0; status == SWITCH_STATUS_SUCCESS && i<ccds_qty; i++) {
+ status = switch_ivr_digit_stream_parser_set_event(conference->dtmf_parser,ccds[i].key,ccds[i].action);
+ }
+
+ // parse the profile tree for caller control digit strings
+ for (xml_kvp = switch_xml_child(profile, "control"); xml_kvp; xml_kvp = xml_kvp->next) {
+ char *key = (char *) switch_xml_attr_soft(xml_kvp, "action");
+ char *val = (char *) switch_xml_attr_soft(xml_kvp, "digits");
+
+ if(key != NULL && val != NULL) {
+ // scan through all of the valid actions, and if found,
+ // set the new caller control action digit string, then
+ // stop scanning the table, and go to the next xml kvp.
+ for(i=0,status=SWITCH_STATUS_NOOP; i<ccds_qty && status == SWITCH_STATUS_NOOP; i++) {
+ if(strcasecmp(ccds[i].key,key) == 0) {
+ status = switch_ivr_digit_stream_parser_set_event(conference->dtmf_parser,ccds[i].key,ccds[i].action);
+ }
+ }
+ if(status == SWITCH_STATUS_NOOP) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid caller control action name '%'.\n",key);
+ }
+ }
+ }
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to allocate caller control digit parser.\n");
+ }
/* Activate the conference mutex for exclusivity */
switch_mutex_init(&conference->mutex, SWITCH_MUTEX_NESTED, conference->pool);
Modified: freeswitch/branches/knhor/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/branches/knhor/trunk/src/switch_ivr.c (original)
+++ freeswitch/branches/knhor/trunk/src/switch_ivr.c Sat Nov 11 18:22:17 2006
@@ -3235,3 +3235,30 @@
return SWITCH_STATUS_SUCCESS;
}
+
+struct switch_ivr_digit_stream_parser {
+};
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_new(switch_ivr_digit_stream_parser_t **parser)
+{ switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+ return status;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_event(switch_ivr_digit_stream_parser_t *parser, char *digits, int action)
+{ switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+ return status;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_del_event(switch_ivr_digit_stream_parser_t *parser, char *digits)
+{ switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+ return status;
+}
+
+SWITCH_DECLARE(int) switch_ivr_digit_stream_parser_feed(switch_ivr_digit_stream_parser_t *parser, char digit)
+{ int result = 0;
+
+ return result;
+}
More information about the Freeswitch-svn
mailing list