]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Fix routing behavior of inbound calls from gateways that only match gateway based...
authorMichael Jerris <mike@jerris.com>
Thu, 6 Jan 2011 21:35:12 +0000 (15:35 -0600)
committerBrian West <brian@freeswitch.org>
Thu, 6 Jan 2011 21:35:12 +0000 (15:35 -0600)
we now honor the extension gateway param only if it is explicitly set, but will not route to the username param if extension is not set
also, new special value for extension "auto" that should use the request uri unless it has gw+ and then it will use the to uri

src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c

index df267967fa20053c04e888b6c77554f97ae60bf5..b6ce97dac6993143bdeff9190c8874fed067b5e4 100644 (file)
@@ -403,6 +403,7 @@ struct sofia_gateway {
        char *register_from;
        char *register_contact;
        char *extension;
+       char *real_extension;
        char *register_to;
        char *register_proxy;
        char *register_sticky_proxy;
index 2643ceb17f81d35cb935e2f777e30f12c789812c..381eb5d2d16024adde7c4e75a06c0f359a70e370 100644 (file)
@@ -2056,10 +2056,6 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
                                from_user = username;
                        }
 
-                       if (zstr(extension)) {
-                               extension = username;
-                       }
-
                        if (zstr(proxy)) {
                                proxy = realm;
                        }
@@ -2151,8 +2147,13 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
                                sipip = profile->sipip;
                        }
 
-                       gateway->extension = switch_core_strdup(gateway->pool, extension);
+                       if (zstr(extension)) {
+                               extension = username;
+                       } else {
+                               gateway->real_extension = switch_core_strdup(gateway->pool, extension);
+                       }
 
+                       gateway->extension = switch_core_strdup(gateway->pool, extension);
 
                        if (!strncasecmp(proxy, "sip:", 4)) {
                                gateway->register_proxy = switch_core_strdup(gateway->pool, proxy);
@@ -6222,6 +6223,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
        char acl_token[512] = "";
        sofia_transport_t transport;
        const char *gw_name = NULL;
+       const char *gw_param_name = NULL;
        char *call_info_str = NULL;
        nua_handle_t *bnh = NULL;
        char sip_acl_authed_by[512] = "";
@@ -6854,7 +6856,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
 
 
        if (sip->sip_request->rq_url->url_params) {
-               gw_name = sofia_glue_find_parameter_value(session, sip->sip_request->rq_url->url_params, "gw=");
+               gw_param_name = sofia_glue_find_parameter_value(session, sip->sip_request->rq_url->url_params, "gw=");
        }
 
        if (strstr(destination_number, "gw+")) {
@@ -6869,19 +6871,35 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
                }
        }
 
-       if (gw_name) {
-               sofia_gateway_t *gateway;
-               if (gw_name && (gateway = sofia_reg_find_gateway(gw_name))) {
+       if (gw_name || gw_param_name) {
+               sofia_gateway_t *gateway = NULL;
+               char *extension = NULL;
+
+               if (gw_name && ((gateway = sofia_reg_find_gateway(gw_name)))) {
+                       gw_param_name = NULL;
+                       extension = gateway->extension;
+               }
+
+               if (!gateway && gw_param_name) {
+                       gateway = sofia_reg_find_gateway(gw_param_name);
+                       extension = gateway->real_extension;
+               }
+
+               if (gateway) {
                        context = switch_core_session_strdup(session, gateway->register_context);
                        switch_channel_set_variable(channel, "sip_gateway", gateway->name);
 
-                       if (gateway->extension) {
-                               if (!strcasecmp(gateway->extension, "auto_to_user")) {
+                       if (!zstr(extension)) {
+                               if (!strcasecmp(extension, "auto_to_user")) {
                                        destination_number = sip->sip_to->a_url->url_user;
+                               } else if (!strcasecmp(extension, "auto")) {
+                                       if (gw_name) {
+                                               destination_number = sip->sip_to->a_url->url_user;
+                                       }
                                } else {
-                                       destination_number = switch_core_session_strdup(session, gateway->extension);
+                                       destination_number = switch_core_session_strdup(session, extension);
                                }
-                       } else {
+                       } else if (!gw_param_name) {
                                destination_number = sip->sip_to->a_url->url_user;
                        }