]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
update
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 26 May 2006 16:00:08 +0000 (16:00 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 26 May 2006 16:00:08 +0000 (16:00 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1508 d0543943-73ff-0310-b7d9-9358b9ac24b2

12 files changed:
conf/freeswitch.xml
src/include/switch_caller.h
src/mod/applications/mod_bridgecall/mod_bridgecall.c
src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
src/mod/endpoints/mod_dingaling/mod_dingaling.c
src/mod/endpoints/mod_exosip/mod_exosip.c
src/mod/endpoints/mod_iax/mod_iax.c
src/mod/endpoints/mod_portaudio/mod_portaudio.c
src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
src/mod/endpoints/mod_woomera/mod_woomera.c
src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
src/switch_caller.c

index e23614fe8e3a5eb9384a68f0259b8f1e6bcd85b0..8a63a3dee732b9b363061d1cb1bf49d90459d4c0 100644 (file)
           <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 
index fc0c1a50d3db3db7691a7e2b3f339e950d7e8737..d35fa99a5e43ddada68a4ff31015ca6ac31a6d0e 100644 (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
index 65ea85ede4413d89115c2af541d597a2da77e6fc..c08f4af92afcff3adf37fae6cc7f49bd6ac37537 100644 (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,
index 5fb2d3a9bccfe0d9025703a5dcb82a11aec36b2f..15e9997b6e79f44921058c94ac707c7ff8b26ae7 100644 (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;
-                       }
-
-                       assert(re != NULL);
+               proceed = parse_exten(session, xexten, &extension);
 
-                       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;
-                               }
+               //printf("ASS %s %d\n", (char *) switch_xml_attr_soft(xexten, "name"), proceed);
 
-                               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;
        }
 
 
index 0c69d9bbe6491c1a1491108eb6f4737c95dfb9f5..637a0dea26fd8459860e6868914b82616c2e4751 100644 (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,
index 767eaa5232da8a204358cf041393517a417c47c1..2fb18646bab03baebb9bd38591162a631870be58 100644 (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,
index 81e521c92da904799d1de3b5ef2795555b558ef5..47dafa4b5100e00b3eb24b0f22ce440cc6f85be3 100644 (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,
index 7bf50981c53194aeb5e7389d6816389fb755d5a5..f1dd1e62067196781e4d258a9a11fa1bd65018de 100644 (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) {
index 80aac0926cb1bad24c6233df1c16e375ed391452..b7c07f1e530d8c04e93d7800811beadb76d1c256 100644 (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,
index 2b4ac64f82fcd8180e4bae6cad6ae5894bbc4da4..d5c3c62a155d44cd08150e68e17299af5f42c214 100644 (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];
index 896c1b2f6e4a26dafb1d6b4d734682a8d3a2d628..adf949c93a5534881be4ea32c514772fb452d867 100644 (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;
index 141693a01a3e76cc7c9af5497dc0fe3581d23914..20b2c7fdbd489ca355a8fab45ca512042b8eb3fc 100644 (file)
 #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);