diff --git a/conf/freeswitch.conf b/conf/freeswitch.conf index 037943d158..d34551a0f3 100644 --- a/conf/freeswitch.conf +++ b/conf/freeswitch.conf @@ -46,7 +46,7 @@ load => mod_commands ;load => mod_commands ; Dialplan Interfaces -load => mod_dialplan_demo +load => mod_dialplan_flatfile ;load => mod_dialplan_directory load => mod_pcre @@ -96,7 +96,7 @@ level => debug,info,warning-alert debug => 0 ;ip => 1.2.3.4 port => 4569 -dialplan => demo +dialplan => flatfile codec_prefs => PCMU,PCMA,speex,L16 codec_master => us codec_rates=8 @@ -176,7 +176,7 @@ debug=0 [+portaudio.conf] [settings] debug => 2 -dialplan => demo +dialplan => flatfile ; partial string match on something in the name or the device # indev => USB @@ -238,7 +238,7 @@ base => dc=freeswitch,dc=org ;---- BASIC EXTENSIONS ;-------------------------------------------------------------------------------- [+extensions.conf] -[extensions] +[default] 1000 => playback /var/sounds/beep.raw @@ -260,7 +260,7 @@ codec_prefs => PCMU name => google login => myjabberid@myjabberserver.com/talk password => mypass - dialplan => demo + dialplan => flatfile message => Jingle all the way rtp-ip => 0.0.0.0 auto-login => true diff --git a/modules.conf.in b/modules.conf.in index aa4db904db..ea23d936c9 100644 --- a/modules.conf.in +++ b/modules.conf.in @@ -14,7 +14,7 @@ codecs/mod_gsm #codecs/mod_ilbc codecs/mod_l16 #codecs/mod_speex -dialplans/mod_dialplan_demo +dialplans/mod_dialplan_flatfile #dialplans/mod_dialplan_directory dialplans/mod_pcre #directories/mod_ldap diff --git a/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c b/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c index c5453d63ef..798dadcff9 100644 --- a/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c +++ b/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c @@ -116,7 +116,11 @@ static switch_caller_extension_t *directory_dialplan_hunt(switch_core_session_t return NULL; } - sprintf(filter, "exten=%s", caller_profile->destination_number); + snprintf(filter, sizeof(filter), "exten=%s", caller_profile->destination_number); + if (caller_profile->context) { + snprintf(filter + strlen(filter), sizeof(filter) - strlen(filter), "context=%s", caller_profile->context); + } + switch_core_directory_query(&dh, globals.base, filter); while (switch_core_directory_next(&dh) == SWITCH_STATUS_SUCCESS) { diff --git a/src/mod/dialplans/mod_dialplan_demo/mod_dialplan_demo.c b/src/mod/dialplans/mod_dialplan_flatfile/mod_dialplan_flatfile.c similarity index 73% rename from src/mod/dialplans/mod_dialplan_demo/mod_dialplan_demo.c rename to src/mod/dialplans/mod_dialplan_flatfile/mod_dialplan_flatfile.c index 0a5f4ebce7..c4fd6171b1 100644 --- a/src/mod/dialplans/mod_dialplan_demo/mod_dialplan_demo.c +++ b/src/mod/dialplans/mod_dialplan_flatfile/mod_dialplan_flatfile.c @@ -26,7 +26,7 @@ * Anthony Minessale II * * - * mod_dialplan_demo.c -- Example Dialplan Module + * mod_dialplan_flatfile.c -- Example Dialplan Module * */ #include @@ -35,25 +35,31 @@ #include -static const char modname[] = "mod_dialplan_demo"; +static const char modname[] = "mod_dialplan_flatfile"; -static switch_caller_extension_t *demo_dialplan_hunt(switch_core_session_t *session) +static switch_caller_extension_t *flatfile_dialplan_hunt(switch_core_session_t *session) { - switch_caller_profile_t *caller_profile; + switch_caller_profile_t *caller_profile = NULL; switch_caller_extension_t *extension = NULL; switch_channel_t *channel; char *cf = "extensions.conf"; switch_config_t cfg; char *var, *val; char app[1024]; + char *context = NULL; channel = switch_core_session_get_channel(session); - caller_profile = switch_channel_get_caller_profile(channel); - //switch_channel_set_variable(channel, "pleasework", "yay"); + + if ((caller_profile = switch_channel_get_caller_profile(channel))) { + context = caller_profile->context ? caller_profile->context : "default"; + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Obtaining Profile!\n"); + return NULL; + } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Hello %s You Dialed %s!\n", caller_profile->caller_id_name, - caller_profile->destination_number); + caller_profile->destination_number); if (!switch_config_open_file(&cfg, cf)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); @@ -62,7 +68,7 @@ static switch_caller_extension_t *demo_dialplan_hunt(switch_core_session_t *sess } while (switch_config_next_pair(&cfg, &var, &val)) { - if (!strcasecmp(cfg.category, "extensions")) { + if (!strcasecmp(cfg.category, context)) { if (!strcmp(var, caller_profile->destination_number) && val) { char *data; @@ -95,6 +101,7 @@ static switch_caller_extension_t *demo_dialplan_hunt(switch_core_session_t *sess if (extension) { switch_channel_set_state(channel, CS_EXECUTE); } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Cannot locate extension %s in context %s\n", caller_profile->destination_number, context); switch_channel_hangup(channel, SWITCH_CAUSE_MESSAGE_TYPE_NONEXIST); } @@ -102,17 +109,17 @@ static switch_caller_extension_t *demo_dialplan_hunt(switch_core_session_t *sess } -static const switch_dialplan_interface_t demo_dialplan_interface = { - /*.interface_name = */ "demo", - /*.hunt_function = */ demo_dialplan_hunt - /*.next = NULL */ +static const switch_dialplan_interface_t flatfile_dialplan_interface = { + /*.interface_name = */ "flatfile", + /*.hunt_function = */ flatfile_dialplan_hunt + /*.next = NULL */ }; -static const switch_loadable_module_interface_t demo_dialplan_module_interface = { +static const switch_loadable_module_interface_t flatfile_dialplan_module_interface = { /*.module_name = */ modname, /*.endpoint_interface = */ NULL, /*.timer_interface = */ NULL, - /*.dialplan_interface = */ &demo_dialplan_interface, + /*.dialplan_interface = */ &flatfile_dialplan_interface, /*.codec_interface = */ NULL, /*.application_interface = */ NULL }; @@ -121,7 +128,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod { /* connect my internal structure to the blank pointer passed to me */ - *module_interface = &demo_dialplan_module_interface; + *module_interface = &flatfile_dialplan_module_interface; /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; diff --git a/src/mod/dialplans/mod_dialplan_demo/mod_dialplan_demo.vcproj b/src/mod/dialplans/mod_dialplan_flatfile/mod_dialplan_flatfile.vcproj similarity index 89% rename from src/mod/dialplans/mod_dialplan_demo/mod_dialplan_demo.vcproj rename to src/mod/dialplans/mod_dialplan_flatfile/mod_dialplan_flatfile.vcproj index 2a51473a3e..f4d932b71c 100644 --- a/src/mod/dialplans/mod_dialplan_demo/mod_dialplan_demo.vcproj +++ b/src/mod/dialplans/mod_dialplan_flatfile/mod_dialplan_flatfile.vcproj @@ -2,9 +2,9 @@ @@ -63,13 +63,13 @@ />