Beispiel #1
0
        /// <summary>
        /// Retries the next candidate to send to.
        /// </summary>
        /// <param name="branch">The branch.</param>
        private void RetryNextCandidate(ProxyBranch branch)
        {
            if ((RemoteCandidates == null) || (RemoteCandidates.Count == 0))
            {
                Debug.Assert(false, String.Format("No more DNS resolved address to try"));
            }
            SIPURI target = RemoteCandidates.First();

            RemoteCandidates.RemoveAt(0);
            branch.Request.First("Via").Attributes["branch"] += "A";
            branch.Transaction = Transaction.CreateClient(Stack, this, branch.Request, Stack.Transport,
                                                          target.Host + ":" + target.Port);
        }
Beispiel #2
0
        /// <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);
            }
        }