Dup() public method

Clones this SIPURI and returns a new SIPURI
public Dup ( ) : SIPURI
return SIPURI
コード例 #1
0
        /// <summary>
        /// Sends the SIP request.
        /// </summary>
        /// <param name="request">The request.</param>
        public override void SendRequest(Message request)
        {
            SIPURI target = null;

            if (request.First("Route") == null)
            {
                target = request.Uri;
            }
            else
            {
                var routes = request.Headers["Route"];
                if (routes.Count > 0)
                {
                    try
                    {
                        target = ((Address)routes[0].Value).Uri;
                        string test = target.Parameters["lr"];
                    }
                    catch (Exception)
                    {
                        routes.RemoveAt(0);
                        if (routes.Count > 0)
                        {
                            routes.Add(new Header(request.Uri.ToString(), "Route"));
                        }
                        request.Headers["Route"] = routes;
                        request.Uri = target;
                    }
                }
            }
            Stack.Sending(this, request);
            ProxyBranch branch = new ProxyBranch();

            SIPURI dest = target.Dup();

            if (target.Port <= 0)
            {
                dest.Port = 5060;
            }
            else
            {
                dest.Port = target.Port;
            }

            if (!Helpers.IsIPv4(dest.Host))
            {
                try
                {
                    IPAddress[] addresses = Dns.GetHostAddresses(dest.Host);
                    dest.Host = addresses[0].ToString();
                }
                catch (Exception)
                {
                }
            }
            if (Helpers.IsIPv4(dest.Host))
            {
                branch.RemoteCandidates = new List <SIPURI> {
                    dest
                };
            }
            if (branch.RemoteCandidates == null || branch.RemoteCandidates.Count == 0)
            {
                Error(null, "Cannot resolve DNS target");
                return;
            }
            target = branch.RemoteCandidates.First();
            branch.RemoteCandidates.RemoveAt(0);
            if (!request.Method.ToUpper().Contains("ACK"))
            {
                branch.Transaction = Transaction.CreateClient(Stack, this, request, Stack.Transport, target.HostPort());
                branch.Request     = request;
                _branches.Add(branch);
            }
            else
            {
                Stack.Send(request, target.HostPort());
            }
        }
コード例 #2
0
ファイル: UserAgent.cs プロジェクト: niklsspb/C-Sharp-Sip-Lib
        /// <summary>
        /// Sends a specific SIP request.
        /// </summary>
        /// <param name="request">The request.</param>
        public virtual void SendRequest(Message request)
        {
            if ((Request == null) && (request.Method == "REGISTER"))
            {
                if ((Transaction == null) && (Transaction.State != "completed") && (Transaction.State != "terminated"))
                {
                    //TODO This doesn't make sense....
                    Debug.Assert(false, String.Format("Cannot re-REGISTER since pending registration\n"));
                }
            }
            Request = request;

            if (!request.Headers.ContainsKey("Route"))
            {
                RemoteTarget = request.Uri;
            }
            SIPURI target = RemoteTarget;

            if (request.Headers.ContainsKey("Route"))
            {
                if (request.Headers["Route"].Count > 0)
                {
                    target = ((Address)(request.Headers["Route"][0].Value)).Uri;
                    if ((target == null) || !target.Parameters.ContainsKey("lr"))
                    {
                        request.Headers["Route"].RemoveAt(0);
                        if (request.Headers["Route"].Count > 0)
                        {
                            request.Headers["Route"].Insert(request.Headers["Route"].Count - 1,
                                                            new Header(request.Uri.ToString(), "Route"));
                        }
                        request.Uri = target;
                    }
                }
            }
            // TODO: remove any Route Header in REGISTER request
            Stack.Sending(this, request);
            if (target != null)
            {
                SIPURI dest = target.Dup();
                if (dest.Port == 0)
                {
                    dest.Port = 5060;
                }

                if (Helpers.IsIPv4(dest.Host))
                {
                    RemoteCandidates = new List <SIPURI> {
                        dest
                    };
                }
            }
            if ((RemoteCandidates == null) || (RemoteCandidates.Count == 0))
            {
                Error(null, "Cannot Resolve DNS target");
                return;
            }
            target = RemoteCandidates.First();
            RemoteCandidates.RemoveAt(0);
            if (Request.Method != "ACK")
            {
                Transaction = Transaction.CreateClient(Stack, this, Request, Stack.Transport,
                                                       target.Host + ":" + target.Port);
            }
            else
            {
                Stack.Send(Request, target.Host + ":" + target.Port);
            }
        }