Browse code

sbc: b/f: fix retarget

Raphael Coeffic authored on 29/11/2013 13:54:35
Showing 3 changed files
... ...
@@ -793,7 +793,7 @@ void SBCCallLeg::onInvite(const AmSipRequest& req)
793 793
   }
794 794
   else if(call_profile.reg_caching) {
795 795
     // REG-Cache lookup
796
-    uac_req.r_uri = call_profile.retarget(req.user,*dlg);
796
+    uac_req.r_uri = call_profile.retarget(req.user);
797 797
   }
798 798
 
799 799
   ruri = call_profile.ruri.empty() ? uac_req.r_uri : call_profile.ruri;
... ...
@@ -1207,6 +1207,33 @@ void SBCCallProfile::fix_reg_contact(ParamReplacerCtx& ctx,
1207 1207
   }
1208 1208
 }
1209 1209
 
1210
+string SBCCallProfile::retarget(const string& alias)
1211
+{
1212
+    // REG-Cache lookup
1213
+    AliasEntry alias_entry;
1214
+    if(!RegisterCache::instance()->findAliasEntry(alias, alias_entry)) {
1215
+      throw AmSession::Exception(404,"User not found");
1216
+    }
1217
+    string new_r_uri = alias_entry.contact_uri;
1218
+    DBG("setting from registration cache: r_uri='%s'\n",new_r_uri.c_str());
1219
+
1220
+    // fix NAT
1221
+    string nh = alias_entry.source_ip;
1222
+    if(alias_entry.source_port != 5060)
1223
+      nh += ":" + int2str(alias_entry.source_port);
1224
+
1225
+    DBG("setting from registration cache: next_hop='%s'\n", nh.c_str());
1226
+    next_hop = nh;
1227
+
1228
+    // sticky interface
1229
+    DBG("setting from registration cache: outbound_interface='%s'\n",
1230
+	AmConfig::SIP_Ifs[alias_entry.local_if].name.c_str());
1231
+    outbound_interface = AmConfig::SIP_Ifs[alias_entry.local_if].name;
1232
+    outbound_interface_value = alias_entry.local_if;
1233
+
1234
+    return new_r_uri;
1235
+}
1236
+
1210 1237
 string SBCCallProfile::retarget(const string& alias, AmBasicSipDialog& dlg) const
1211 1238
 {
1212 1239
     // REG-Cache lookup
... ...
@@ -387,10 +387,18 @@ struct SBCCallProfile
387 387
   /**
388 388
    * Reg-cache lookup:
389 389
    * - searches for alias in the reg-cache.
390
-   * - sets next-hop & outbound_interface
390
+   * - sets next-hop & outbound_interface on the given dialog
391 391
    * @return retargeted R-URI
392 392
    */
393 393
   string retarget(const string& alias, AmBasicSipDialog& dlg) const;
394
+
395
+  /**
396
+   * Reg-cache lookup:
397
+   * - searches for alias in the reg-cache.
398
+   * - sets next-hop & outbound_interface in this profile
399
+   * @return retargeted R-URI
400
+   */
401
+  string retarget(const string& alias);
394 402
 };
395 403
 
396 404
 #endif // _SBCCallProfile_h