git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1508 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-05-26 16:00:08 +00:00
parent 75c0ab62b2
commit ab3f42c9c4
12 changed files with 126 additions and 67 deletions

View File

@ -261,6 +261,12 @@
<action application="bridge" data="exosip/888@66.250.68.194"/>
</condition>
</extension>
<!-- if the destination is an exact match on the extension name
you do not need any regex in the condition -->
<extension name="999">
<condition><action application="bridge" data="exosip/888@66.250.68.194"/></condition>
</extension>
<!-- extensions starting with 4, all the numbers after 4 form a numeric filename
continue=true means keep looking for more extensions to match
*NOTE* The entire dialplan is parsed ONCE when the call starts

View File

@ -60,6 +60,8 @@ BEGIN_EXTERN_C
/*! \brief Call Specific Data
*/
struct switch_caller_profile {
/*! The Call's User Name */
char *username;
/*! The name of the dialplan */
char *dialplan;
/*! Caller ID Name */
@ -161,16 +163,17 @@ SWITCH_DECLARE(char *) switch_caller_get_field_by_name(switch_caller_profile_t *
\return a new profile object allocated from the session's memory pool
*/
SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_new(switch_memory_pool_t *pool,
char *dialplan,
char *caller_id_name,
char *caller_id_number,
char *network_addr,
char *ani,
char *ani2,
char *rdnis,
char *source,
char *context,
char *destination_number);
char *username,
char *dialplan,
char *caller_id_name,
char *caller_id_number,
char *network_addr,
char *ani,
char *ani2,
char *rdnis,
char *source,
char *context,
char *destination_number);
/*!
\brief Clone an existing caller profile object

View File

@ -56,6 +56,7 @@ static void audio_bridge_function(switch_core_session_t *session, char *data)
caller_caller_profile = switch_channel_get_caller_profile(caller_channel);
caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
caller_caller_profile->username,
caller_caller_profile->dialplan,
caller_caller_profile->caller_id_name,
caller_caller_profile->caller_id_number,

View File

@ -122,13 +122,74 @@ static void perform_substitution(pcre *re, int match_count, char *data, char *fi
substituted[y++] = '\0';
}
static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, switch_caller_extension_t **extension)
{
switch_xml_t xcond, xaction;
switch_caller_profile_t *caller_profile;
switch_channel_t *channel;
char *exten_name = (char *) switch_xml_attr_soft(xexten, "name");
int proceed = 0;
channel = switch_core_session_get_channel(session);
caller_profile = switch_channel_get_caller_profile(channel);
for (xcond = switch_xml_child(xexten, "condition"); xcond; xcond = xcond->next) {
char *field = NULL;
char *expression = NULL;
char *field_data = NULL;
pcre *re = NULL;
int ovector[30];
field = (char *) switch_xml_attr(xcond, "field");
expression = (char *) switch_xml_attr_soft(xcond, "expression");
if (field) {
field_data = switch_caller_get_field_by_name(caller_profile, field);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "test conditions %s(%s) =~ /%s/\n", field, field_data, expression);
if (!(proceed = perform_regex(channel, field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Regex mismatch\n");
break;
}
assert(re != NULL);
}
for (xaction = switch_xml_child(xcond, "action"); xaction; xaction = xaction->next) {
char *application = (char*) switch_xml_attr_soft(xaction, "application");
char *data = (char *) switch_xml_attr_soft(xaction, "data");
char substituted[1024] = "";
char *app_data = NULL;
if (field && strchr(expression, '(')) {
perform_substitution(re, proceed, data, field_data, substituted, sizeof(substituted), ovector);
app_data = substituted;
} else {
app_data = data;
}
if (!*extension) {
if ((*extension =
switch_caller_extension_new(session, exten_name, caller_profile->destination_number)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
return 0;
}
}
switch_caller_extension_add_application(session, *extension, application, app_data);
}
cleanre(re);
}
return proceed;
}
static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session)
{
switch_caller_profile_t *caller_profile;
switch_caller_extension_t *extension = NULL;
switch_channel_t *channel;
char *exten_name = NULL;
switch_xml_t cfg, xml, xcontext, xexten, xaction, xcond;
switch_xml_t cfg, xml, xcontext, xexten;
char *context = NULL;
char params[1024];
@ -143,7 +204,7 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Processing %s->%s!\n", caller_profile->caller_id_name,
caller_profile->destination_number);
snprintf(params, sizeof(params), "dest=%s", caller_profile->destination_number);
snprintf(params, sizeof(params), "context=%s&dest=%s", caller_profile->context, caller_profile->destination_number);
if (switch_xml_locate("dialplan", NULL, NULL, NULL, &xml, &cfg, params) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
@ -159,55 +220,23 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session)
}
}
for (xexten = switch_xml_child(xcontext, "extension"); xexten; xexten = xexten->next) {
if (!(xexten = switch_xml_find_child(xcontext, "extension", "name", caller_profile->destination_number))) {
xexten = switch_xml_child(xcontext, "extension");
}
while(xexten) {
int proceed = 0;
char *cont = (char *) switch_xml_attr_soft(xexten, "continue");
for (xcond = switch_xml_child(xexten, "condition"); xcond; xcond = xcond->next) {
char *field = (char *) switch_xml_attr_soft(xcond, "field");
char *expression = (char *) switch_xml_attr_soft(xcond, "expression");
char *field_data = switch_caller_get_field_by_name(caller_profile, field);
pcre *re = NULL;
int ovector[30];
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "test conditions %s(%s) =~ /%s/\n", field, field_data, expression);
if (!(proceed = perform_regex(channel, field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Regex mismatch\n");
break;
}
proceed = parse_exten(session, xexten, &extension);
assert(re != NULL);
//printf("ASS %s %d\n", (char *) switch_xml_attr_soft(xexten, "name"), proceed);
for (xaction = switch_xml_child(xcond, "action"); xaction; xaction = xaction->next) {
char *application = (char*) switch_xml_attr_soft(xaction, "application");
char *data = (char *) switch_xml_attr_soft(xaction, "data");
char substituted[1024] = "";
char *app_data = NULL;
if (strchr(expression, '(')) {
perform_substitution(re, proceed, data, field_data, substituted, sizeof(substituted), ovector);
app_data = substituted;
} else {
app_data = data;
}
if (!extension) {
if ((extension =
switch_caller_extension_new(session, exten_name, caller_profile->destination_number)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
return NULL;
}
}
switch_caller_extension_add_application(session, extension, application, app_data);
}
cleanre(re);
}
if (proceed && !switch_true(cont)) {
break;
}
xexten = xexten->next;
}

View File

@ -1633,6 +1633,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
ldl_session_get_id(dlsession), cid_name, cid_num, exten);
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
profile->login,
profile->dialplan,
cid_name,
cid_num,

View File

@ -1197,6 +1197,7 @@ static switch_status_t exosip_create_call(eXosip_event_t * event)
}
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
username,
globals.dialplan,
displayname,
username,

View File

@ -999,6 +999,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
iaxevent->ies.username,
globals.dialplan,
iaxevent->ies.calling_name,
iaxevent->ies.calling_number,
@ -1007,7 +1008,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
NULL,
NULL,
(char *)modname,
NULL,
iaxevent->ies.called_context,
iaxevent->ies.called_number)) != 0) {
char name[128];
snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number,

View File

@ -823,6 +823,7 @@ static switch_status_t place_call(char *dest, switch_stream_handle_t *stream)
}
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
NULL,
globals.dialplan,
globals.cid_name,
globals.cid_num, NULL, NULL, NULL, NULL, (char *)modname, NULL, dest)) != 0) {

View File

@ -1128,6 +1128,7 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri
}
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
NULL,
globals.dialplan,
"FreeSWITCH",
event->ring.callingnum,

View File

@ -1065,6 +1065,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
ip = woomera_message_header(&wmsg, "Remote-Address");
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
NULL,
tech_pvt->profile->dialplan,
cid_name, cid_num, ip, NULL, NULL, NULL, (char *)modname, NULL, exten)) != 0) {
char name[128];

View File

@ -988,7 +988,7 @@ static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval
char *ani2 = "";
char *rdnis = "";
char *context = "";
char *username = NULL;
*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
if (JS_ValueToObject(cx, argv[0], &session_obj)) {
@ -1025,6 +1025,9 @@ static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval
if (argc > 10) {
rdnis = JS_GetStringBytes(JS_ValueToString(cx, argv[10]));
}
if (argc > 11) {
username = JS_GetStringBytes(JS_ValueToString(cx, argv[11]));
}
if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
@ -1032,7 +1035,7 @@ static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval
return JS_FALSE;
}
caller_profile = switch_caller_profile_new(pool, dialplan, cid_name, cid_num, network_addr, ani, ani2, rdnis, (char *)modname, context, dest);
caller_profile = switch_caller_profile_new(pool, username, dialplan, cid_name, cid_num, network_addr, ani, ani2, rdnis, (char *)modname, context, dest);
if (switch_core_session_outgoing_channel(session, channel_type, caller_profile, &peer_session, pool) == SWITCH_STATUS_SUCCESS) {
jss = switch_core_session_alloc(peer_session, sizeof(*jss));
jss->session = peer_session;

View File

@ -33,16 +33,17 @@
#include <switch_caller.h>
SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_new(switch_memory_pool_t *pool,
char *dialplan,
char *caller_id_name,
char *caller_id_number,
char *network_addr,
char *ani,
char *ani2,
char *rdnis,
char *source,
char *context,
char *destination_number)
char *username,
char *dialplan,
char *caller_id_name,
char *caller_id_number,
char *network_addr,
char *ani,
char *ani2,
char *rdnis,
char *source,
char *context,
char *destination_number)
{
@ -52,6 +53,7 @@ SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_new(switch_memor
if (!context) {
context = "default";
}
profile->username = switch_core_strdup(pool, username);
profile->dialplan = switch_core_strdup(pool, dialplan);
profile->caller_id_name = switch_core_strdup(pool, caller_id_name);
profile->caller_id_number = switch_core_strdup(pool, caller_id_number);
@ -73,6 +75,7 @@ SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_clone(switch_cor
{
switch_caller_profile_t *profile = NULL;
if ((profile = switch_core_session_alloc(session, sizeof(switch_caller_profile_t))) != 0) {
profile->username = switch_core_session_strdup(session, tocopy->username);
profile->dialplan = switch_core_session_strdup(session, tocopy->dialplan);
profile->caller_id_name = switch_core_session_strdup(session, tocopy->caller_id_name);
profile->ani = switch_core_session_strdup(session, tocopy->ani);
@ -95,6 +98,9 @@ SWITCH_DECLARE(char *) switch_caller_get_field_by_name(switch_caller_profile_t *
if (!strcasecmp(name, "dialplan")) {
return caller_profile->dialplan;
}
if (!strcasecmp(name, "username")) {
return caller_profile->username;
}
if (!strcasecmp(name, "caller_id_name")) {
return caller_profile->caller_id_name;
}
@ -136,6 +142,11 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_
{
char header_name[1024];
if (caller_profile->username) {
snprintf(header_name, sizeof(header_name), "%s-Username", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, caller_profile->username);
}
if (caller_profile->dialplan) {
snprintf(header_name, sizeof(header_name), "%s-Dialplan", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, caller_profile->dialplan);