/// <summary>
/// Creates a list of calls based on the registered contacts for a user registration.
/// </summary>
/// <param name="user"></param>
/// <param name="domain"></param>
/// <param name="from">The From header that will be set on the forwarded call leg.</param>
/// <returns></returns>
public List<SIPCallDescriptor> GetForwardsForLocalLeg(
SIPRequest sipRequest,
SIPAccount sipAccount,
List<string> customHeaders,
string customContentType,
string customContent,
string options,
string callersNetworkId,
string fromDisplayName,
string fromUsername,
string fromHost,
CRMHeaders contact)
{
List<SIPCallDescriptor> localUserSwitchCalls = new List<SIPCallDescriptor>();
try
{
if (sipAccount == null)
{
throw new ApplicationException("Cannot lookup forwards for a null SIP account.");
}
List<SIPRegistrarBinding> bindings = GetRegistrarBindings_External(b => b.SIPAccountId == sipAccount.Id, null, 0, Int32.MaxValue);
if (bindings != null)
{
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, bindings.Count + " found for " + sipAccount.SIPUsername + "@" + sipAccount.SIPDomain + ".", m_username));
// Build list of registered contacts.
for (int index = 0; index < bindings.Count; index++)
{
SIPRegistrarBinding binding = bindings[index];
SIPURI contactURI = binding.MangledContactSIPURI;
// Determine the content based on a custom request, caller's network id and whether mangling is required.
string contentType = (sipRequest != null) ? sipRequest.Header.ContentType : null;
string content = (sipRequest != null) ? sipRequest.Body : null;
if (!customContentType.IsNullOrBlank())
{
contentType = customContentType;
}
if (!customContent.IsNullOrBlank())
{
content = customContent;
}
IPAddress publicSDPAddress = PublicIPAddress;
if (publicSDPAddress == null && sipRequest != null)
{
publicSDPAddress = SIPPacketMangler.GetRequestIPAddress(sipRequest);
}
string fromHeader = (sipRequest != null) ? sipRequest.Header.From.ToString() : m_anonymousFromURI;
SIPCallDescriptor switchCall = new SIPCallDescriptor(
null,
null,
contactURI.ToString(),
fromHeader,
new SIPToHeader(null, SIPURI.ParseSIPURIRelaxed(sipAccount.SIPUsername + "@" + sipAccount.SIPDomain), null).ToString(),
null,
customHeaders,
null,
SIPCallDirection.In,
contentType,
content,
publicSDPAddress);
switchCall.CRMHeaders = contact;
// If the binding for the call is a switchboard add the custom switchboard headers.
if (!sipRequest.Header.SwitchboardFrom.IsNullOrBlank())
{
switchCall.SwitchboardHeaders.SwitchboardFrom = sipRequest.Header.SwitchboardFrom;
}
// If the binding has a proxy socket defined set the header to ask the upstream proxy to use it.
if (binding.ProxySIPEndPoint != null)
{
switchCall.ProxySendFrom = binding.ProxySIPEndPoint.ToString();
}
switchCall.ParseCallOptions(options);
if (sipAccount != null && !sipAccount.NetworkId.IsNullOrBlank() && sipAccount.NetworkId == callersNetworkId)
{
switchCall.MangleResponseSDP = false;
}
switchCall.SetGeneralFromHeaderFields(fromDisplayName, fromUsername, fromHost);
localUserSwitchCalls.Add(switchCall);
}
}
else
{
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "No current bindings found for local SIP account " + sipAccount.SIPUsername + "@" + sipAccount.SIPDomain + ".", m_username));
}
return localUserSwitchCalls;
}
catch (Exception excp)
{
logger.Error("Exception GetForwardsForLocalLeg. " + excp);
return localUserSwitchCalls;
}
}