SIPSorcery.SIP.App.SIPCallDescriptor.ParseCallOptions C# (CSharp) Method

ParseCallOptions() public method

public ParseCallOptions ( string options ) : void
options string
return void
        public void ParseCallOptions(string options)
        {
            if (!options.IsNullOrBlank())
            {
                options = options.Trim('[', ']');

                // Parse delay time option.
                Match delayCallMatch = Regex.Match(options, DELAY_CALL_OPTION_KEY + @"=(?<delaytime>\d+)");
                if (delayCallMatch.Success)
                {
                    Int32.TryParse(delayCallMatch.Result("${delaytime}"), out DelaySeconds);
                }

                // Parse redirect mode option.
                Match redirectModeMatch = Regex.Match(options, REDIRECT_MODE_OPTION_KEY + @"=(?<redirectmode>\w)");
                if (redirectModeMatch.Success)
                {
                    string redirectMode = redirectModeMatch.Result("${redirectmode}");
                    //if (redirectMode == "a" || redirectMode == "A")
                    //{
                    //    RedirectMode = SIPCallRedirectModesEnum.Add;
                    //}
                    //else if (redirectMode == "r" || redirectMode == "R")
                    //{
                    //    RedirectMode = SIPCallRedirectModesEnum.Replace;
                    //}
                    if (redirectMode == "n" || redirectMode == "N")
                    {
                        RedirectMode = SIPCallRedirectModesEnum.NewDialPlan;
                    }
                    else if (redirectMode == "m" || redirectMode == "M")
                    {
                        RedirectMode = SIPCallRedirectModesEnum.Manual;
                    }
                }

                // Parse call duration limit option.
                Match callDurationMatch = Regex.Match(options, CALL_DURATION_OPTION_KEY + @"=(?<callduration>\d+)");
                if (callDurationMatch.Success)
                {
                    Int32.TryParse(callDurationMatch.Result("${callduration}"), out CallDurationLimit);
                }

                // Parse the mangle option.
                Match mangleMatch = Regex.Match(options, MANGLE_MODE_OPTION_KEY + @"=(?<mangle>\w+)");
                if (mangleMatch.Success)
                {
                    Boolean.TryParse(mangleMatch.Result("${mangle}"), out MangleResponseSDP);
                }

                // Parse the From header display name option.
                Match fromDisplayNameMatch = Regex.Match(options, FROM_DISPLAY_NAME_KEY + @"=(?<displayname>.+?)(,|$)");
                if (fromDisplayNameMatch.Success)
                {
                    FromDisplayName = fromDisplayNameMatch.Result("${displayname}").Trim();
                }

                // Parse the From header URI username option.
                Match fromUsernameNameMatch = Regex.Match(options, FROM_USERNAME_KEY + @"=(?<username>.+?)(,|$)");
                if (fromUsernameNameMatch.Success)
                {
                    FromURIUsername = fromUsernameNameMatch.Result("${username}").Trim();
                }

                // Parse the From header URI host option.
                Match fromURIHostMatch = Regex.Match(options, FROM_HOST_KEY + @"=(?<host>.+?)(,|$)");
                if (fromURIHostMatch.Success)
                {
                    FromURIHost = fromURIHostMatch.Result("${host}").Trim();
                }

                // Parse the Transfer behaviour option.
                Match transferMatch = Regex.Match(options, TRANSFER_MODE_OPTION_KEY + @"=(?<transfermode>.+?)(,|$)");
                if (transferMatch.Success)
                {
                    string transferMode = transferMatch.Result("${transfermode}");
                    if (transferMode == "n" || transferMode == "N")
                    {
                        TransferMode = SIPDialogueTransferModesEnum.NotAllowed;
                    }
                    else if (transferMode == "p" || transferMode == "P")
                    {
                        TransferMode = SIPDialogueTransferModesEnum.PassThru;
                    }
                    else if (transferMode == "c" || transferMode == "C")
                    {
                        TransferMode = SIPDialogueTransferModesEnum.BlindPlaceCall;
                    }
                    /*else if (transferMode == "o" || transferMode == "O")
                    {
                        TransferMode = SIPCallTransferModesEnum.Caller;
                    }
                    else if (transferMode == "d" || transferMode == "D")
                    {
                        TransferMode = SIPCallTransferModesEnum.Callee;
                    }
                    else if (transferMode == "b" || transferMode == "B")
                    {
                        TransferMode = SIPCallTransferModesEnum.Both;
                    }*/
                }

                // Parse the switchboard description value.
                Match switchboardDescriptionMatch = Regex.Match(options, SWITCHBOARD_LINE_NAME_KEY + @"=(?<lineName>.+?)(,|$)");
                if (switchboardDescriptionMatch.Success)
                {
                    SwitchboardHeaders.SwitchboardLineName = switchboardDescriptionMatch.Result("${lineName}").Trim();
                }

                // Parse the switchboard dialogue description value.
                //Match switchboardDialogueDescriptionMatch = Regex.Match(options, SWITCHBOARD_DIALOGUE_DESCRIPTION_KEY + @"=(?<description>.+?)(,|$)");
                //if (switchboardDialogueDescriptionMatch.Success)
                //{
                //    SwitchboardHeaders.SwitchboardDialogueDescription = switchboardDialogueDescriptionMatch.Result("${description}").Trim();
                //}

                // Parse the switchboard CallID value.
                Match switchboardCallIDMatch = Regex.Match(options, SWITCHBOARD_CALLID_KEY + @"=(?<callid>.+?)(,|$)");
                if (switchboardCallIDMatch.Success)
                {
                    SwitchboardHeaders.SwitchboardOriginalCallID = switchboardCallIDMatch.Result("${callid}").Trim();
                }

                // Parse the switchboard owner value.
                Match switchboardOwnerMatch = Regex.Match(options, SWITCHBOARD_OWNER_KEY + @"=(?<owner>.+?)(,|$)");
                if (switchboardOwnerMatch.Success)
                {
                    SwitchboardHeaders.SwitchboardOwner = switchboardOwnerMatch.Result("${owner}").Trim();
                }

                // Parse the request caller details option.
                Match callerDetailsMatch = Regex.Match(options,REQUEST_CALLER_DETAILS + @"=(?<callerdetails>\w+)");
                if (callerDetailsMatch.Success)
                {
                    Boolean.TryParse(callerDetailsMatch.Result("${callerdetails}"), out RequestCallerDetails);
                }

                // Parse the accountcode.
                Match accountCodeMatch = Regex.Match(options, ACCOUNT_CODE_KEY + @"=(?<accountCode>\w+)");
                if (accountCodeMatch.Success)
                {
                    AccountCode = accountCodeMatch.Result("${accountCode}");
                }

                // Parse the rate code.
                Match rateCodeMatch = Regex.Match(options, RATE_CODE_KEY + @"=(?<rateCode>\w+)");
                if (rateCodeMatch.Success)
                {
                    RateCode = rateCodeMatch.Result("${rateCode}");
                }
            }
        }

Usage Example

        /// <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;
            }
        }
All Usage Examples Of SIPSorcery.SIP.App.SIPCallDescriptor::ParseCallOptions