Ejemplo n.º 1
0
        private void ProccessService(AcceptedRequest tu, IncomingMessageEx request)
        {
            var account = accounts.GetAccount(request.Reader.RequestUri.Hostport.Host);

            var writer = GetWriter();

            if (account != null)
            {
                var outContent = serviceSoap.ProcessRequest <IAccount>(request.Content, Search, account);

                writer.WriteStatusLine(StatusCodes.OK);
                writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, StatusCodes.OK);
                writer.WriteContentType(type, subtype);
                writer.WriteCustomHeaders();
                writer.WriteContentLength();
                writer.WriteCRLF();

                writer.Write(outContent.GenerateToByteArray());
                writer.RewriteContentLength();
            }
            else
            {
                writer.WriteStatusLine(StatusCodes.NotFound);
                writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, StatusCodes.NotFound);
                writer.WriteContentLength(0);
                writer.WriteCRLF();
            }

            tu.SendResponse(request, writer);
        }
Ejemplo n.º 2
0
		private void ProccessService(AcceptedRequest tu, IncomingMessageEx request)
		{
			var writer = GetWriter();

			try
			{
				var outContent = mras.ProcessRequest(request.Content);

				writer.WriteStatusLine(StatusCodes.OK);
				writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, StatusCodes.OK);
				writer.WriteContentType(type, subtype);
				writer.WriteCustomHeaders();
				writer.WriteContentLength();
				writer.WriteCRLF();

				writer.Write(outContent.GenerateToByteArray());
				writer.RewriteContentLength();
			}
			catch (MrasException)
			{
				writer.WriteResponse(request.Reader, StatusCodes.BadRequest);
			}

			tu.SendResponse(request, writer);
		}
Ejemplo n.º 3
0
			public RequestProxyFactory(ProxyServerTU parent, IncomingMessageEx request)
			{
				this.parent = parent;
				this.request = request;

				this.requestProxy = null;
			}
Ejemplo n.º 4
0
		private void ProccessService(AcceptedRequest tu, IncomingMessageEx request)
		{
			var account = accounts.GetAccount(request.Reader.RequestUri.Hostport.Host);

			var writer = GetWriter();

			if (account != null)
			{
				var outContent = serviceSoap.ProcessRequest<IAccount>(request.Content, Search, account);

				writer.WriteStatusLine(StatusCodes.OK);
				writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, StatusCodes.OK);
				writer.WriteContentType(type, subtype);
				writer.WriteCustomHeaders();
				writer.WriteContentLength();
				writer.WriteCRLF();

				writer.Write(outContent.GenerateToByteArray());
				writer.RewriteContentLength();
			}
			else
			{
				writer.WriteStatusLine(StatusCodes.NotFound);
				writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, StatusCodes.NotFound);
				writer.WriteContentLength(0);
				writer.WriteCRLF();
			}

			tu.SendResponse(request, writer);
		}
Ejemplo n.º 5
0
        private void ProccessService(AcceptedRequest tu, IncomingMessageEx request)
        {
            var writer = GetWriter();

            try
            {
                var outContent = mras.ProcessRequest(request.Content);

                writer.WriteStatusLine(StatusCodes.OK);
                writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, StatusCodes.OK);
                writer.WriteContentType(type, subtype);
                writer.WriteCustomHeaders();
                writer.WriteContentLength();
                writer.WriteCRLF();

                writer.Write(outContent.GenerateToByteArray());
                writer.RewriteContentLength();
            }
            catch (MrasException)
            {
                writer.WriteResponse(request.Reader, StatusCodes.BadRequest);
            }

            tu.SendResponse(request, writer);
        }
Ejemplo n.º 6
0
            public RequestProxyFactory(ProxyServerTU parent, IncomingMessageEx request)
            {
                this.parent  = parent;
                this.request = request;

                this.requestProxy = null;
            }
Ejemplo n.º 7
0
		private void ProccessSubscribe(AcceptedRequest tu, IncomingMessageEx request)
		{
			var statusCode = StatusCodes.OK;
			var dialog = dialogManager.GetOrCreate(request.Reader, request.ConnectionAddresses, out statusCode);

			var writer = GetWriter();

			int expires = 0;
			if (statusCode == StatusCodes.OK)
			{
				expires = request.Reader.GetExpires(600, int.MaxValue);

				writer.WriteStatusLine(statusCode);
				writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, statusCode, dialog.LocalTag);
				writer.WriteDate(DateTime.UtcNow);
				writer.WriteExpires(expires);
				writer.WriteContentLength(0);
				writer.WriteCRLF();
			}
			else
			{
				writer.WriteResponse(request.Reader, statusCode);
			}

			tu.SendResponse(request, writer);

			if (statusCode == StatusCodes.OK)
				SendNotify(dialog, expires);
		}
Ejemplo n.º 8
0
        private void ProccessSubscribe(AcceptedRequest tu, IncomingMessageEx request)
        {
            var statusCode = StatusCodes.OK;
            var dialog     = dialogManager.GetOrCreate(request.Reader, request.ConnectionAddresses, out statusCode);

            var writer = GetWriter();

            int expires = 0;

            if (statusCode == StatusCodes.OK)
            {
                expires = request.Reader.GetExpires(600, int.MaxValue);

                writer.WriteStatusLine(statusCode);
                writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, statusCode, dialog.LocalTag);
                writer.WriteDate(DateTime.UtcNow);
                writer.WriteExpires(expires);
                writer.WriteContentLength(0);
                writer.WriteCRLF();
            }
            else
            {
                writer.WriteResponse(request.Reader, statusCode);
            }

            tu.SendResponse(request, writer);

            if (statusCode == StatusCodes.OK)
            {
                SendNotify(dialog, expires);
            }
        }
Ejemplo n.º 9
0
            public bool TryUpdate(IncomingMessageEx request, int defaultExpires, out bool isNewData, Action <Bindings, Binding, SipMessageReader> onAddBinding, Action <Bindings, Binding> onRemoveBinding)
            {
                isNewData = false;

                lock (sync)
                {
                    if (isStale)
                    {
                        return(false);
                    }

                    isNewData = IsNewData(request.Reader.CallId, request.Reader.CSeq.Value);

                    if (isNewData)
                    {
                        var reader = request.Reader;

                        for (int i = 0; i < reader.Count.ContactCount; i++)
                        {
                            int index   = FindBindingByAddrSpec(reader.Contact[i].AddrSpec.Value);
                            int expires = GetExpires(reader, i, defaultExpires);

                            if (expires > 0)
                            {
                                if (index >= 0 && bindings[index].IsChanged(reader, i) == false)
                                {
                                    bindings[index].Update(reader.CSeq.Value, expires);
                                }
                                else
                                {
                                    if (index < 0 && reader.Contact[i].SipInstance.IsValid)
                                    {
                                        index = FindBindingBySipInstance(reader.Contact[i].SipInstance);
                                    }

                                    if (index >= 0)
                                    {
                                        RemoveBinding(index, onRemoveBinding);
                                    }

                                    AddBinding(new Binding(reader, i, expires, request.ConnectionAddresses), onAddBinding, reader);
                                }
                            }
                            else
                            {
                                if (index >= 0)
                                {
                                    RemoveBinding(index, onRemoveBinding);
                                }
                            }
                        }
                    }

                    UpdateStale();
                    return(true);
                }
            }
Ejemplo n.º 10
0
		private void ProccessOptions(AcceptedRequest tu, IncomingMessageEx request)
		{
			var writer = GetWriter();

			writer.WriteStatusLine(StatusCodes.OK);
			writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, StatusCodes.OK); // statusCode есть во writer'е!!!!!!
			writer.WriteAllow(AllowMethods);
			writer.WriteCRLF();

			tu.SendResponse(request, writer);
		}
Ejemplo n.º 11
0
        private void ProccessRequest(AcceptedRequest tu, IncomingMessageEx request)
        {
            var writer = GetWriter();

            writer.WriteStatusLine(StatusCodes.NotImplemented);
            writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, StatusCodes.NotImplemented);
            writer.WriteContentLength(0);
            writer.WriteCRLF();

            tu.SendResponse(request, writer);
        }
Ejemplo n.º 12
0
		private void ProccessRequest(AcceptedRequest tu, IncomingMessageEx request)
		{
			var writer = GetWriter();

			writer.WriteStatusLine(StatusCodes.NotImplemented);
			writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, StatusCodes.NotImplemented);
			writer.WriteContentLength(0);
			writer.WriteCRLF();

			tu.SendResponse(request, writer);
		}
Ejemplo n.º 13
0
        private void ProccessOptions(AcceptedRequest tu, IncomingMessageEx request)
        {
            var writer = GetWriter();

            writer.WriteStatusLine(StatusCodes.OK);
            writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, StatusCodes.OK);             // statusCode есть во writer'е!!!!!!
            writer.WriteAllow(AllowMethods);
            writer.WriteCRLF();

            tu.SendResponse(request, writer);
        }
Ejemplo n.º 14
0
        public RequestProxy(IncomingMessageEx request)
        {
            this.proxies = new List <IProxie>(1);
            this.bestResponseStatusCode = int.MaxValue;

            this.ServerTransactionId = request.TransactionId;
            this.ConnectionAddresses = request.ConnectionAddresses;

            this.Headers      = request.Headers;
            this.Content      = request.Content;
            this.bufferHandle = request.DetachBuffers();
        }
Ejemplo n.º 15
0
		public RequestProxy(IncomingMessageEx request)
		{
			this.proxies = new List<IProxie>(1);
			this.bestResponseStatusCode = int.MaxValue;

			this.ServerTransactionId = request.TransactionId;
			this.ConnectionAddresses = request.ConnectionAddresses;

			this.Headers = request.Headers;
			this.Content = request.Content;
			this.bufferHandle = request.DetachBuffers();
		}
Ejemplo n.º 16
0
        private void ProccessPublish(AcceptedRequest tu, IncomingMessageEx request)
        {
            StatusCodes statusCode = StatusCodes.OK;

            int expires = request.Reader.GetExpires(600, 900);

            if (request.Reader.IsExpiresTooBrief(60))
            {
                statusCode = StatusCodes.IntervalTooBrief;
            }

            int sipIfMatch = simpleModule.InvalidEtag;

            if (statusCode == StatusCodes.OK)
            {
                if (request.Reader.SipIfMatch.Length == 8)
                {
                    if (HexEncoding.TryParseHex8(request.Reader.SipIfMatch.Bytes, request.Reader.SipIfMatch.Begin, out sipIfMatch) == false)
                    {
                        statusCode = StatusCodes.CallLegTransactionDoesNotExist;
                    }
                }
            }

            if (statusCode == StatusCodes.OK)
            {
                var fromUser = request.Reader.From.AddrSpec.User.ToString();
                var fromHost = request.Reader.From.AddrSpec.Hostport.Host.ToString();
                if (simpleModule.Publish(fromUser + "@" + fromHost, ref sipIfMatch, expires, request.Content) == false)
                {
                    statusCode = StatusCodes.BadRequest;
                }
            }

            var writer = GetWriter();

            if (statusCode == StatusCodes.OK)
            {
                writer.WriteStatusLine(statusCode);
                writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, statusCode);
                writer.WriteExpires(expires);
                writer.WriteSipEtag(sipIfMatch);
                writer.WriteCRLF();
            }
            else
            {
                writer.WriteResponse(request.Reader, statusCode);
            }

            SendResponse(request, writer);
        }
Ejemplo n.º 17
0
        private void ProccessService(AcceptedRequest tu, IncomingMessageEx request)
        {
            var         writer     = GetWriter();
            StatusCodes statusCode = StatusCodes.OK;

            string endpointId = null;

            if (request.Reader.Count.ContactCount == 0)
            {
                statusCode = StatusCodes.BadRequest;
            }
            else
            {
                endpointId = (request.Reader.Contact[0].SipInstance.IsValid == true ?
                              request.Reader.Contact[0].SipInstance : request.Reader.Contact[0].AddrSpec1.Value).ToString();
            }

            if (statusCode == StatusCodes.OK)
            {
                try
                {
                    var categories = enhancedPresence.ParsePublication(request.Content);

                    var content = enhancedPresence.ProcessPublication(
                        request.Reader.From.AddrSpec.Value.ToString(), categories, endpointId);

                    writer.WriteStatusLine(statusCode);
                    writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, statusCode);
                    writer.WriteContentType(new ByteArrayPart(categories.OutContentType), new ByteArrayPart(categories.OutContentSubtype));
                    // нужен ли контакт
                    writer.WriteCustomHeaders();
                    writer.WriteContentLength();
                    writer.WriteCRLF();

                    int endOfHeaders = writer.Count;
                    writer.Write(content.GenerateToByteArray());
                    writer.RewriteContentLength(writer.Count - endOfHeaders);
                }
                catch (EnhancedPresenceException)
                {
                    statusCode = StatusCodes.BadRequest;
                }
            }

            if (statusCode != StatusCodes.OK)
            {
                writer.WriteResponse(request.Reader, statusCode);
            }

            tu.SendResponse(request, writer);
        }
Ejemplo n.º 18
0
        public bool UpdateBindings(ByteArrayPart user, ByteArrayPart domain, IncomingMessageEx request, int defaultExpires)
        {
            bool     isNewData;
            Bindings bindings;

            do
            {
                bindings = GetOrAddBindings(GetAor(user, domain));
            } while (bindings.TryUpdate(request, defaultExpires, out isNewData, ContactAddedHandler, ContactRemovedHandler) == false);

            RemoveStaleBindings(bindings);

            return(isNewData);
        }
Ejemplo n.º 19
0
		public bool UpdateBindings(ByteArrayPart user, ByteArrayPart domain, IncomingMessageEx request, int defaultExpires)
		{
			bool isNewData;
			Bindings bindings;

			do
			{
				bindings = GetOrAddBindings(GetAor(user, domain));

			} while (bindings.TryUpdate(request, defaultExpires, out isNewData, ContactAddedHandler, ContactRemovedHandler) == false);

			RemoveStaleBindings(bindings);

			return isNewData;
		}
Ejemplo n.º 20
0
        private void ProccessUnsubscribe(AcceptedRequest tu, IncomingMessageEx request)
        {
            var writer = GetWriter();

            var dialog = dialogManager.Get(request.Reader);

            if (dialog != null)
            {
                writer.WriteResponse(request.Reader, StatusCodes.OK, dialog.LocalTag);
                dialogManager.Remove(dialog.Id);
            }
            else
            {
                writer.WriteResponse(request.Reader, StatusCodes.OK);
            }

            tu.SendResponse(request, writer);
        }
Ejemplo n.º 21
0
        private void ProccessCancelRequest(AcceptedRequest tu, IncomingMessageEx request)
        {
            var statusCode = StatusCodes.CallLegTransactionDoesNotExist;

            int inviteTransactionKId = Transaction.GetRelaytedInviteServerKId(request.TransactionId);

            if (inviteTransactionKId != Transaction.InvalidKId)
            {
                var requestProxy = requestProxyes.TryGetValue(inviteTransactionKId);

                if (requestProxy != null)
                {
                    CancelClients(requestProxy, request.Reader);
                    statusCode = StatusCodes.OK;
                }
            }

            SendResponse(request, statusCode);
        }
Ejemplo n.º 22
0
		private void ProccessPublish(AcceptedRequest tu, IncomingMessageEx request)
		{
			StatusCodes statusCode = StatusCodes.OK;

			int expires = request.Reader.GetExpires(600, 900);

			if (request.Reader.IsExpiresTooBrief(60))
				statusCode = StatusCodes.IntervalTooBrief;

			int sipIfMatch = simpleModule.InvalidEtag;

			if (statusCode == StatusCodes.OK)
			{
				if (request.Reader.SipIfMatch.Length == 8)
					if (HexEncoding.TryParseHex8(request.Reader.SipIfMatch.Bytes, request.Reader.SipIfMatch.Begin, out sipIfMatch) == false)
						statusCode = StatusCodes.CallLegTransactionDoesNotExist;
			}

			if (statusCode == StatusCodes.OK)
			{
				var fromUser = request.Reader.From.AddrSpec.User.ToString();
				var fromHost = request.Reader.From.AddrSpec.Hostport.Host.ToString();
				if (simpleModule.Publish(fromUser + "@" + fromHost, ref sipIfMatch, expires, request.Content) == false)
					statusCode = StatusCodes.BadRequest;
			}

			var writer = GetWriter();

			if (statusCode == StatusCodes.OK)
			{
				writer.WriteStatusLine(statusCode);
				writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, statusCode);
				writer.WriteExpires(expires);
				writer.WriteSipEtag(sipIfMatch);
				writer.WriteCRLF();
			}
			else
			{
				writer.WriteResponse(request.Reader, statusCode);
			}

			SendResponse(request, writer);
		}
Ejemplo n.º 23
0
        private void ProduceAck(IncomingMessageEx response)
        {
            var requestProxy = GetRequestProxy(response.TransactionId);

            if (requestProxy != null)
            {
                lock (requestProxy)
                {
                    int clientTransactionId = response.TransactionId;
                    var proxie = requestProxy.GetProxie(clientTransactionId);

                    if (proxie != null)
                    {
                        var writer = GetWriter();
                        proxie.GenerateAck(writer, response.Reader);

                        SendAck(proxie.ToConnectionAddresses, writer);
                    }
                }
            }
        }
Ejemplo n.º 24
0
        private void ProccessSubscribe(AcceptedRequest tu, IncomingMessageEx request)
        {
            var dialog = dialogManager.GetOrCreate(request.Reader, request.ConnectionAddresses);

            if (dialog == null)
            {
                SendResponse(request, StatusCodes.CallLegTransactionDoesNotExist);
            }
            else if (request.Reader.IsExpiresTooBrief(60))
            {
                SendResponse(request, StatusCodes.IntervalTooBrief);
            }
            else
            {
                int expires = request.Reader.GetExpires(600, 900);


                var dialogId = dialog.Id.ToString();
                var toUser   = request.Reader.To.AddrSpec.User.ToString();
                var toHost   = request.Reader.To.AddrSpec.Hostport.Host.ToString();
                var document = simpleModule.Subscribe(dialogId, toUser + "@" + toHost, expires);


                var statusCode = StatusCodes.OK;
                var writer     = GetWriter();

                writer.WriteStatusLine(statusCode);
                writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, statusCode, dialog.LocalTag);
                writer.WriteExpires(expires);
                writer.WriteCRLF();

                SendResponse(request, writer);


                if (document != null)
                {
                    SendNotify(dialog, expires, document);
                }
            }
        }
Ejemplo n.º 25
0
        public void OnIncomingRequest(AcceptedRequest router, IncomingMessageEx message)
        {
            bool repeat;
            var  mode = router.AuthorizationMode;

            do
            {
                repeat = mode == AuthorizationMode.Custom;

                switch (mode)
                {
                case AuthorizationMode.Custom:
                {
                    mode = OnCustomAuthorization(message);
                }
                break;

                case AuthorizationMode.Disabled:
                {
                    router.OnIncomingRequest(message);
                }
                break;

                case AuthorizationMode.Enabled:
                {
                    SipMessageWriter writer;
                    if (Authentication.IsAuthorized(message.Reader, message.Content, out writer))
                    {
                        router.OnIncomingRequest(message);
                    }
                    else if (writer != null)
                    {
                        SendResponse(message, writer);
                    }
                }
                break;
                }
            }while (repeat);
        }
Ejemplo n.º 26
0
		public void OnIncomingRequest(AcceptedRequest router, IncomingMessageEx message)
		{
			bool repeat;
			var mode = router.AuthorizationMode;

			do
			{
				repeat = mode == AuthorizationMode.Custom;

				switch (mode)
				{
					case AuthorizationMode.Custom:
						{
							mode = OnCustomAuthorization(message);
						}
						break;

					case AuthorizationMode.Disabled:
						{
							router.OnIncomingRequest(message);
						}
						break;

					case AuthorizationMode.Enabled:
						{
							SipMessageWriter writer;
							if (Authentication.IsAuthorized(message.Reader, message.Content, out writer))
								router.OnIncomingRequest(message);
							else if (writer != null)
								SendResponse(message, writer);
						}
						break;
				}
			}
			while (repeat);
		}
Ejemplo n.º 27
0
 public void OnIncomingResponse(ProducedRequest router, IncomingMessageEx message)
 {
     router.OnIncomingResponse(message);
 }
Ejemplo n.º 28
0
		/// <summary>
		/// !!! DEPRECATED !!!
		/// </summary>
		public void SendResponse(IncomingMessageEx to, SipMessageWriter writer)
		{
			TransactionUser.SendResponse(to.ConnectionAddresses, to.TransactionId, writer);
		}
Ejemplo n.º 29
0
		private void ProccessRegister(AcceptedRequest tu, IncomingMessageEx request)
		{
			StatusCodes statusCode = StatusCodes.OK;

			bool isStar = HasStarContact(request.Reader);
			var user = request.Reader.To.AddrSpec.User;
			var domain = request.Reader.RequestUri.Hostport.Host;

			if (isStar)
			{
				if (request.Reader.Count.ContactCount > 1 && request.Reader.Expires != 0)
					statusCode = StatusCodes.BadRequest;
			}
			else
			{
				if (IsExpiresValid(request.Reader) == false)
					statusCode = StatusCodes.IntervalTooBrief;
			}

			if (statusCode == StatusCodes.OK)
			{
				if (isStar)
					locationService.RemoveAllBindings(user, domain);
				else
					if (locationService.UpdateBindings(user, domain, request, defaultExpires) == false)
						statusCode = StatusCodes.Gone;
			}

			var writer = GetWriter();

			if (statusCode == StatusCodes.OK)
			{
				writer.WriteStatusLine(StatusCodes.OK);
				writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, StatusCodes.OK);

				int maxExpires = 0;

				foreach (var binding in locationService.GetEnumerableBindings(user, domain))
				{
					writer.WriteContact(binding.AddrSpec, binding.SipInstance, binding.Expires);

					if (maxExpires < binding.Expires)
						maxExpires = binding.Expires;
				}

				writer.WriteExpires(maxExpires);
				writer.WriteCustomHeaders();
				writer.WriteContentLength(0);
				writer.WriteCRLF();
			}
			else
			{
				writer.WriteStatusLine(statusCode);
				writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, statusCode);
				if (statusCode == StatusCodes.IntervalTooBrief)
					writer.WriteMinExpires(minExpires);
				writer.WriteContentLength(0);
				writer.WriteCRLF();
			}

			tu.SendResponse(request, writer);
		}
Ejemplo n.º 30
0
        private void ProccessResponse(IncomingMessageEx response)
        {
            var requestProxy = GetRequestProxy(response.TransactionId);

            if (requestProxy != null)
            {
                lock (requestProxy)
                {
                    if (requestProxy.IsAllResponsesReceived == false)
                    {
                        int statusCode          = response.Reader.StatusCode.Value;
                        int clientTransactionId = response.TransactionId;
                        var proxie = requestProxy.GetProxie(clientTransactionId);

                        if (proxie != null)
                        {
                            if (statusCode > 199)
                            {
                                proxie.IsFinalReceived = true;
                            }

                            if (statusCode >= 100 && statusCode <= 299)
                            {
                                Tracer.WriteInformation("Forward response " + statusCode);

                                var writer = GetWriter();
                                proxie.GenerateForwardedResponse(writer, response.Reader, response.Content, requestProxy.ConnectionAddresses);

                                SendResponse(requestProxy.ConnectionAddresses, requestProxy.ServerTransactionId, writer);

                                if (statusCode >= 100 && statusCode <= 199)
                                {
                                    if (proxie.TimerC != timerC.InvalidTimerIndex)
                                    {
                                        proxie.TimerC = timerC.Change(proxie.TimerC, new ServerClientId(requestProxy.ServerTransactionId, clientTransactionId));
                                    }
                                }

                                if (statusCode >= 200 && statusCode <= 299)
                                {
                                    CancelClients(requestProxy, response.Reader);

                                    if (requestProxy.BestResponseStatusCode > statusCode)
                                    {
                                        requestProxy.SetBestResponseStatusCode(statusCode);
                                    }
                                }
                            }
                            else
                            {
                                if (proxie.CanFork(response.Reader))
                                {
                                    var proxie2 = proxie.Fork(GetTransactionId(response.Reader.CSeq.Method));
                                    ForwardRequest(proxie2, requestProxy, ParseHeaders(requestProxy));
                                }
                                else
                                {
                                    if (requestProxy.BestResponseStatusCode > statusCode)
                                    {
                                        var writer = GetWriter();
                                        proxie.GenerateForwardedResponse(writer, response.Reader, response.Content, requestProxy.ConnectionAddresses);

                                        requestProxy.SetBestResponse(writer);
                                    }

                                    SendBestIfAllFinalRecived(requestProxy);
                                }
                            }
                        }
                    }
                }

                RemoveIfFinished(requestProxy);
            }
            else
            {
                // stateless forward
                Tracer.WriteInformation("requestProxy not found for " + response.TransactionId.ToString());
            }
        }
Ejemplo n.º 31
0
		public void PassRequest(string message)
		{
			SipMessageReader reader;
			ArraySegment<byte> headers;
			ArraySegment<byte> content = new ArraySegment<byte>();
			GetReader(message, out reader, out headers);

			var im1 = new IncomingMessage(Transports.Tcp, GetIPEndPoint(), GetIPEndPoint(), 44444, reader, headers, content);

			var im2 = new IncomingMessageEx(im1, message.StartsWith("CANCEL") ? serverCancelTransactionId-- : serverTransactionId--);

			bool found = false;
			foreach (var accepted in acceptedRequests)
			{
				if (accepted.Method == im2.Reader.Method)
					if (accepted.IsAcceptedRequest(im2.Reader))
					{
						proxy.OnIncomingRequest(accepted, im2);
						found = true;
					}
			}

			if (found == false)
				throw new InvalidProgramException("Accepted request not found for: " + message);

			//var caBytes = im2.ConnectionAddresses.ToLowerHexChars(im2.TransactionId);

			//return Encoding.UTF8.GetString(caBytes.Array, caBytes.Offset, caBytes.Count);
		}
Ejemplo n.º 32
0
		protected void SendResponse(IncomingMessageEx request, StatusCodes statusCode)
		{
			SendResponseExternal(request.ConnectionAddresses, request.TransactionId,
				GenerateResponse(request.Reader, statusCode));
		}
Ejemplo n.º 33
0
 public void OnIncomingRequest(IncomingMessageEx message)
 {
     IncomingRequest(this, message);
 }
Ejemplo n.º 34
0
		private static void None(IncomingMessageEx message) { }
Ejemplo n.º 35
0
		public void PassResponse(int router, string message, int transactionId)
		{
			SipMessageReader reader;
			ArraySegment<byte> headers;
			ArraySegment<byte> content = new ArraySegment<byte>();
			GetReader(message, out reader, out headers);

			var im1 = new IncomingMessage(Transports.Tcp, new IPEndPoint(IPAddress.None, 22222),
				new IPEndPoint(IPAddress.None, 33333), 111111,
				reader, headers, content);

			var im2 = new IncomingMessageEx(im1, transactionId);

			proxy.OnIncomingResponse(producedRequests[router], im2);
		}
Ejemplo n.º 36
0
		public void OnIncomingResponse(IncomingMessageEx message)
		{
			IncomingResponse(message);
		}
Ejemplo n.º 37
0
        private void ProccessSubscribe(AcceptedRequest tu, IncomingMessageEx request)
        {
            StatusCodes statusCode = StatusCodes.OK;
            string      endpointId = string.Empty;

            int expires = request.Reader.GetExpires(600, 900);

            if (request.Reader.IsExpiresTooBrief(60))
            {
                statusCode = StatusCodes.IntervalTooBrief;
            }

            if (statusCode == StatusCodes.OK)
            {
                if (request.Reader.Count.ContactCount == 0)
                {
                    statusCode = StatusCodes.BadRequest;
                }
                else
                {
                    endpointId = (request.Reader.Contact[0].SipInstance.IsValid == true ?
                                  request.Reader.Contact[0].SipInstance : request.Reader.Contact[0].AddrSpec1.Value).ToString();
                }
            }

            Dialog dialog = null;

            if (statusCode == StatusCodes.OK)
            {
                dialog = dialogManager.GetOrCreate(request.Reader, request.ConnectionAddresses, out statusCode);
            }

            var writer = GetWriter();

            if (statusCode == StatusCodes.OK)
            {
                try
                {
                    var batchSubscribe = enhancedPresence.ParseSubscribe(request.Content);

                    var contents = enhancedPresence.ProcessSubscription(
                        request.Reader.From.AddrSpec.Value.ToString(),
                        dialog.Id.ToString(),
                        batchSubscribe,
                        (uint)expires,
                        endpointId,
                        dialog);

                    writer.WriteStatusLine(statusCode);
                    writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, statusCode, dialog.LocalTag);
                    writer.WriteContact(dialog.LocalEndPoint, dialog.Transport);
                    writer.WriteExpires(expires);
                    writer.WriteEventPresence();
                    writer.WriteSupportedMsBenotify();
                    writer.WriteContentTypeMultipart(contentType);
                    writer.WriteCustomHeaders();
                    writer.WriteContentLength();
                    writer.WriteCRLF();

                    WriteResponseContent(writer, contents);
                }
                catch (EnhancedPresenceException)
                {
                    // TODO: add error info in response
                    statusCode = StatusCodes.BadRequest;
                }
            }

            if (statusCode != StatusCodes.OK)
            {
                writer.WriteResponse(request.Reader, statusCode);
            }

            tu.SendResponse(request, writer);
        }
Ejemplo n.º 38
0
 public override AuthorizationMode OnCustomAuthorization(IncomingMessageEx message)
 {
     return((IsFromLocal(message.Reader) && message.Reader.Method != Methods.Ackm) ?
            AuthorizationMode.Enabled : AuthorizationMode.Disabled);
 }
Ejemplo n.º 39
0
 protected void SendResponse(IncomingMessageEx request, StatusCodes statusCode)
 {
     SendResponseExternal(request.ConnectionAddresses, request.TransactionId,
                          GenerateResponse(request.Reader, statusCode));
 }
Ejemplo n.º 40
0
		private void ProccessResponse(IncomingMessageEx response)
		{
			int trunkId;
			var tag = response.Reader.From.Tag;

			if (tag.Length == 8 && HexEncoding.TryParseHex8(tag.Bytes, tag.Begin, out trunkId))
			{
				var trunk = trunkManager.GetTrunkById(trunkId);
				if (trunk != null)
				{
					switch (response.Reader.StatusCode.Value)
					{
						case 401:
						case 407:
							if ((trunk.State == Trunk.States.Waiting200or401 || trunk.State == Trunk.States.Connected) &&
								(response.Reader.Count.WwwAuthenticateCount > 0 || response.Reader.Count.ProxyAuthenticateCount > 0))
							{
								Challenge challenge;
								if (response.Reader.Count.WwwAuthenticateCount > 0)
								{
									challenge = response.Reader.WwwAuthenticate[0];
									trunk.AuthHeader = HeaderNames.Authorization;
								}
								else
								{
									challenge = response.Reader.ProxyAuthenticate[0];
									trunk.AuthHeader = HeaderNames.ProxyAuthorization;
								}

								if (challenge.AuthScheme == AuthSchemes.Digest)
								{
									trunk.State = Trunk.States.Waiting200;
									trunk.UpdateChallenge(challenge);
									SendRegister(trunk, trunk.RegisterDuration);
								}
								else
								{
									trunk.ErrorMessage = @"Unsupport Auth Scheme";
								}
							}
							else
							{
								trunk.ErrorMessage = @"Proxy response: " + response.Reader.StatusCode.Value.ToString();
							}
							break;

						case 200:
							if (trunk.State == Trunk.States.Disconnecting)
								trunk.State = Trunk.States.Disconnected;
							else
							{
								trunk.State = Trunk.States.Connected;
								int repeat = response.Reader.GetExpires(0) - 10;
								repeat = (repeat <= 0) ? 1 : repeat;
								registerTimer.Add(repeat * 1000, trunk.Id);
							}
							break;

						default:
							trunk.ErrorMessage = @"Proxy response: " + response.Reader.StatusCode.Value.ToString();
							break;
					}
				}
			}
		}
Ejemplo n.º 41
0
		public virtual AuthorizationMode OnCustomAuthorization(IncomingMessageEx message)
		{
			return AuthorizationMode.Disabled;
		}
Ejemplo n.º 42
0
        private void ProccessRegister(AcceptedRequest tu, IncomingMessageEx request)
        {
            StatusCodes statusCode = StatusCodes.OK;

            bool isStar = HasStarContact(request.Reader);
            var  user   = request.Reader.To.AddrSpec.User;
            var  domain = request.Reader.RequestUri.Hostport.Host;

            if (isStar)
            {
                if (request.Reader.Count.ContactCount > 1 && request.Reader.Expires != 0)
                {
                    statusCode = StatusCodes.BadRequest;
                }
            }
            else
            {
                if (IsExpiresValid(request.Reader) == false)
                {
                    statusCode = StatusCodes.IntervalTooBrief;
                }
            }

            if (statusCode == StatusCodes.OK)
            {
                if (isStar)
                {
                    locationService.RemoveAllBindings(user, domain);
                }
                else
                if (locationService.UpdateBindings(user, domain, request, defaultExpires) == false)
                {
                    statusCode = StatusCodes.Gone;
                }
            }

            var writer = GetWriter();

            if (statusCode == StatusCodes.OK)
            {
                writer.WriteStatusLine(StatusCodes.OK);
                writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, StatusCodes.OK);

                int maxExpires = 0;

                foreach (var binding in locationService.GetEnumerableBindings(user, domain))
                {
                    writer.WriteContact(binding.AddrSpec, binding.SipInstance, binding.Expires);

                    if (maxExpires < binding.Expires)
                    {
                        maxExpires = binding.Expires;
                    }
                }

                writer.WriteExpires(maxExpires);
                writer.WriteCustomHeaders();
                writer.WriteContentLength(0);
                writer.WriteCRLF();
            }
            else
            {
                writer.WriteStatusLine(statusCode);
                writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, statusCode);
                if (statusCode == StatusCodes.IntervalTooBrief)
                {
                    writer.WriteMinExpires(minExpires);
                }
                writer.WriteContentLength(0);
                writer.WriteCRLF();
            }

            tu.SendResponse(request, writer);
        }
Ejemplo n.º 43
0
		public void OnIncomingResponse(ProducedRequest router, IncomingMessageEx message)
		{
			router.OnIncomingResponse(message);
		}
Ejemplo n.º 44
0
		private void ProccessSubscribe(AcceptedRequest tu, IncomingMessageEx request)
		{
			StatusCodes statusCode = StatusCodes.OK;
			string endpointId = string.Empty;

			int expires = request.Reader.GetExpires(600, 900);

			if (request.Reader.IsExpiresTooBrief(60))
				statusCode = StatusCodes.IntervalTooBrief;

			if (statusCode == StatusCodes.OK)
			{
				if (request.Reader.Count.ContactCount == 0)
					statusCode = StatusCodes.BadRequest;
				else
					endpointId = (request.Reader.Contact[0].SipInstance.IsValid == true ?
						request.Reader.Contact[0].SipInstance : request.Reader.Contact[0].AddrSpec1.Value).ToString();
			}

			Dialog dialog = null;
			if (statusCode == StatusCodes.OK)
				dialog = dialogManager.GetOrCreate(request.Reader, request.ConnectionAddresses, out statusCode);

			var writer = GetWriter();

			if (statusCode == StatusCodes.OK)
			{
                try
                {
                    var batchSubscribe = enhancedPresence.ParseSubscribe(request.Content);

                    var contents = enhancedPresence.ProcessSubscription(
                        request.Reader.From.AddrSpec.Value.ToString(),
                        dialog.Id.ToString(),
                        batchSubscribe,
                        (uint)expires,
                        endpointId,
                        dialog);

                    writer.WriteStatusLine(statusCode);
                    writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, statusCode, dialog.LocalTag);
                    writer.WriteContact(dialog.LocalEndPoint, dialog.Transport);
                    writer.WriteExpires(expires);
                    writer.WriteEventPresence();
                    writer.WriteSupportedMsBenotify();
                    writer.WriteContentTypeMultipart(contentType);
                    writer.WriteCustomHeaders();
                    writer.WriteContentLength();
                    writer.WriteCRLF();

                    WriteResponseContent(writer, contents);
                }
                catch (EnhancedPresenceException)
                {
                    // TODO: add error info in response
                    statusCode = StatusCodes.BadRequest;
                }
			}

            if (statusCode != StatusCodes.OK)
            {
				writer.WriteResponse(request.Reader, statusCode);
			}

			tu.SendResponse(request, writer);
		}
Ejemplo n.º 45
0
		protected void SendResponse(IncomingMessageEx to, SipMessageWriter writer)
		{
			SendResponseExternal(to.ConnectionAddresses, to.TransactionId, writer);
		}
Ejemplo n.º 46
0
        private void ProccessResponse(IncomingMessageEx response)
        {
            int trunkId;
            var tag = response.Reader.From.Tag;

            if (tag.Length == 8 && HexEncoding.TryParseHex8(tag.Bytes, tag.Begin, out trunkId))
            {
                var trunk = trunkManager.GetTrunkById(trunkId);
                if (trunk != null)
                {
                    switch (response.Reader.StatusCode.Value)
                    {
                    case 401:
                    case 407:
                        if ((trunk.State == Trunk.States.Waiting200or401 || trunk.State == Trunk.States.Connected) &&
                            (response.Reader.Count.WwwAuthenticateCount > 0 || response.Reader.Count.ProxyAuthenticateCount > 0))
                        {
                            Challenge challenge;
                            if (response.Reader.Count.WwwAuthenticateCount > 0)
                            {
                                challenge        = response.Reader.WwwAuthenticate[0];
                                trunk.AuthHeader = HeaderNames.Authorization;
                            }
                            else
                            {
                                challenge        = response.Reader.ProxyAuthenticate[0];
                                trunk.AuthHeader = HeaderNames.ProxyAuthorization;
                            }

                            if (challenge.AuthScheme == AuthSchemes.Digest)
                            {
                                trunk.State = Trunk.States.Waiting200;
                                trunk.UpdateChallenge(challenge);
                                SendRegister(trunk, trunk.RegisterDuration);
                            }
                            else
                            {
                                trunk.ErrorMessage = @"Unsupport Auth Scheme";
                            }
                        }
                        else
                        {
                            trunk.ErrorMessage = @"Proxy response: " + response.Reader.StatusCode.Value.ToString();
                        }
                        break;

                    case 200:
                        if (trunk.State == Trunk.States.Disconnecting)
                        {
                            trunk.State = Trunk.States.Disconnected;
                        }
                        else
                        {
                            trunk.State = Trunk.States.Connected;
                            int repeat = response.Reader.GetExpires(0) - 10;
                            repeat = (repeat <= 0) ? 1 : repeat;
                            registerTimer.Add(repeat * 1000, trunk.Id);
                        }
                        break;

                    default:
                        trunk.ErrorMessage = @"Proxy response: " + response.Reader.StatusCode.Value.ToString();
                        break;
                    }
                }
            }
        }
Ejemplo n.º 47
0
 public void OnIncomingResponse(IncomingMessageEx message)
 {
     IncomingResponse(message);
 }
Ejemplo n.º 48
0
        //private void ProccessRequest(AcceptedRequest tu, IncomingMessageEx request)
        //{
        //    var statusCode = Validate(request.Reader);

        //    if (statusCode == StatusCodes.OK)
        //    {
        //        RequestProxyFactory requestProxy = new RequestProxyFactory(this, tu, request);

        //        try
        //        {
        //            //ByteArrayPart domain, user = request.Reader.RequestUri.User;
        //            //...or from To

        //            var user = request.Reader.To.AddrSpec.User;
        //            var domain = request.Reader.To.AddrSpec.Hostport.Host;

        //            foreach (var binding in locationService.GetEnumerableBindings(user, domain))
        //            {
        //                requestProxy.Forward(binding);
        //            }

        //            if (requestProxy.WasForwarded == false)
        //            {
        //                if (IsFromLocal(request.Reader))
        //                {
        //                    var trunk = trunkManager.GetTrunkByDomain(request.Reader.To.AddrSpec.Hostport.Host);
        //                    if (trunk != null)
        //                        requestProxy.Forward(trunk);
        //                }
        //                else
        //                {
        //                    var trunk = trunkManager.GetTrunkByDomain(request.Reader.From.AddrSpec.Hostport.Host);

        //                    if (trunk != null)
        //                    {
        //                        if (request.Reader.To.Tag.IsValid)
        //                        {
        //                            int tag;
        //                            Dialog dialog1 = null;
        //                            if (HexEncoding.TryParseHex8(request.Reader.To.Tag, out tag))
        //                                dialog1 = trunk.GetDialog1(tag);

        //                            if (dialog1 != null)
        //                                requestProxy.Forward(trunk, tag, dialog1);
        //                        }
        //                        else
        //                        {
        //                            foreach (var binding in locationService.GetEnumerableBindings(trunk.ForwardCallToUri))
        //                            {
        //                                requestProxy.Forward(trunk, binding);
        //                            }
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //        finally
        //        {
        //            if (requestProxy.WasForwarded)
        //            {
        //                requestProxy.RequestProxy.Close();

        //                Monitor.Exit(requestProxy.RequestProxy);
        //                RemoveIfFinished(requestProxy.RequestProxy);
        //            }
        //        }

        //        if (requestProxy.WasForwarded == false)
        //            statusCode = StatusCodes.TemporarilyUnavailable;
        //    }

        //    if (statusCode != StatusCodes.OK)
        //    {
        //        var writer = GetWriter();
        //        writer.WriteResponse(request.Reader, statusCode);
        //        tu.SendResponse(request, writer);
        //    }
        //}

        //private void ProccessRequest(AcceptedRequest tu, IncomingMessageEx request)
        //{
        //    var statusCode = Validate(request.Reader);

        //    if (statusCode == StatusCodes.OK)
        //    {
        //        RequestProxy requestProxy = null;

        //        try
        //        {
        //            //ByteArrayPart domain, user = request.Reader.RequestUri.User;
        //            //...or from To

        //            var user = request.Reader.To.AddrSpec.User;
        //            var domain = request.Reader.To.AddrSpec.Hostport.Host;

        //            foreach (var binding in locationService.GetEnumerableBindings(user, domain))
        //            {
        //                CreateLockedRequestProxy(tu, request, ref requestProxy);
        //                var proxie = new LocalProxie(binding, requestProducer.GetTransactionId(request.Reader.Method));
        //                ForwardRequest(requestProxy, proxie, request.Reader, request.Content);
        //            }

        //            if (requestProxy == null)
        //            {
        //                if (IsFromLocal(request.Reader))
        //                {
        //                    var trunk = trunkManager.GetTrunkByDomain(request.Reader.To.AddrSpec.Hostport.Host);
        //                    if (trunk != null)
        //                    {
        //                        var proxie = new LocalTrunkProxie(requestProducer.GetTransactionId(request.Reader.Method), trunk);
        //                        CreateLockedRequestProxy(tu, request, ref requestProxy);
        //                        ForwardRequest(requestProxy, proxie, request.Reader, request.Content);
        //                    }
        //                }
        //                else
        //                {
        //                    var trunk = trunkManager.GetTrunkByDomain(request.Reader.From.AddrSpec.Hostport.Host);

        //                    if (trunk != null)
        //                    {
        //                        if (request.Reader.To.Tag.IsValid)
        //                        {
        //                            int tag;
        //                            Dialog dialog1 = null;
        //                            if (HexEncoding.TryParseHex8(request.Reader.To.Tag, out tag))
        //                                dialog1 = trunk.GetDialog1(tag);

        //                            if (dialog1 != null)
        //                            {
        //                                var proxie = new TrunkDialogProxie(requestProducer.GetTransactionId(request.Reader.Method), trunk, tag, dialog1);
        //                                CreateLockedRequestProxy(tu, request, ref requestProxy);
        //                                ForwardRequest(requestProxy, proxie, request.Reader, request.Content);
        //                            }
        //                        }
        //                        else
        //                        {
        //                            foreach (var binding in locationService.GetEnumerableBindings(trunk.ForwardCallToUri))
        //                            {
        //                                var proxie = new TrunkLocalProxie(requestProducer.GetTransactionId(request.Reader.Method), trunk, binding);
        //                                CreateLockedRequestProxy(tu, request, ref requestProxy);
        //                                ForwardRequest(requestProxy, proxie, request.Reader, request.Content);
        //                            }
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //        finally
        //        {
        //            if (requestProxy != null)
        //            {
        //                requestProxy.Close();

        //                Monitor.Exit(requestProxy);
        //                RemoveIfFinished(requestProxy);
        //            }
        //        }

        //        if (requestProxy == null)
        //            statusCode = StatusCodes.TemporarilyUnavailable;
        //    }

        //    if (statusCode != StatusCodes.OK)
        //    {
        //        var writer = GetWriter();
        //        writer.WriteResponse(request.Reader, statusCode);
        //        tu.SendResponse(request, writer);
        //    }
        //}

        //private void CreateLockedRequestProxy(AcceptedRequest tu, IncomingMessageEx request, ref RequestProxy requestProxy)
        //{
        //    if (requestProxy == null)
        //    {
        //        requestProxy = new RequestProxy(request);
        //        Monitor.Enter(requestProxy);

        //        ////-----------
        //        if (request.Reader.Method != Methods.Ackm)
        //            requestProxyes.Add(requestProxy.ServerTransactionId, requestProxy);
        //        ////-----------

        //        if (request.Reader.Method == Methods.Invitem)
        //        {
        //            var writer = GetWriter();
        //            writer.WriteResponse(request.Reader, StatusCodes.Trying);
        //            tu.SendResponse(request, writer);
        //        }
        //    }
        //}

        //private void ForwardRequest(RequestProxy requestProxy, IProxie proxie, SipMessageReader reader, ArraySegment<byte> content)
        //{
        //    clientTransactionIds.Add(proxie.TransactionId, requestProxy.ServerTransactionId);

        //    ////-----------
        //    if (reader.Method == Methods.Ackm)
        //        proxie.IsFinalReceived = true;
        //    ////-----------

        //    requestProxy.AddProxie(proxie);

        //    var message = GetWriter();
        //    proxie.GenerateForwardedRequest(Authentication, message, reader, content,
        //        requestProxy.ConnectionAddresses, requestProxy.ServerTransactionId);

        //    requestProducer.SendRequest(proxie.ToConnectionAddresses, message, proxie.TransactionId, requestProxy.ServerTransactionId);

        //    proxie.TimerC = (reader.CSeq.Method == Methods.Invitem) ?
        //        timerC.Add(new ServerClientId(requestProxy.ServerTransactionId, proxie.TransactionId)) : timerC.InvalidTimerIndex;
        //}

        private void ProccessRequest(AcceptedRequest tu, IncomingMessageEx request)
        {
            var statusCode = Validate(request.Reader);

            if (statusCode == StatusCodes.OK)
            {
                statusCode = Filter(request.Reader);
            }

            if (statusCode == StatusCodes.OK)
            {
                RequestProxyFactory requestProxy = new RequestProxyFactory(this, request);

                try
                {
                    //ByteArrayPart domain, user = request.Reader.RequestUri.User;
                    //...or from To

                    var method = request.Reader.Method;

                    var user   = request.Reader.To.AddrSpec.User;
                    var domain = request.Reader.To.AddrSpec.Hostport.Host;

                    foreach (var binding in locationService.GetEnumerableBindings(user, domain))
                    {
                        requestProxy.Forward(
                            ProxieFactory.Create(GetTransactionId(method), binding));
                    }

                    if (requestProxy.HasValue == false)
                    {
                        if (IsFromLocal(request.Reader))
                        {
                            var trunk = trunkManager.GetTrunkByDomain(request.Reader.To.AddrSpec.Hostport.Host);
                            if (trunk != null)
                            {
                                requestProxy.Forward(
                                    ProxieFactory.Create(GetTransactionId(method), trunk));
                            }
                        }
                        else
                        {
                            var trunk = trunkManager.GetTrunkByDomain(request.Reader.From.AddrSpec.Hostport.Host);

                            if (trunk != null)
                            {
                                if (request.Reader.To.Tag.IsValid)
                                {
                                    requestProxy.Forward(
                                        ProxieFactory.Create(GetTransactionId(method), trunk, request.Reader.To.Tag));
                                }
                                else
                                {
                                    foreach (var binding in locationService.GetEnumerableBindings(trunk.ForwardCallToUri))
                                    {
                                        requestProxy.Forward(
                                            ProxieFactory.Create(GetTransactionId(method), trunk, binding));
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    requestProxy.SetAllRequestsSent();
                    SendBestIfAllFinalRecived(requestProxy.Value);

                    requestProxy.Release();

                    RemoveIfFinished(requestProxy.Value);

                    if (requestProxy.HasValue == false)
                    {
                        statusCode = StatusCodes.TemporarilyUnavailable;
                    }
                }
            }

            if (statusCode != StatusCodes.OK)
            {
                SendResponse(request, statusCode);
            }
        }
Ejemplo n.º 49
0
		private void ProccessService(AcceptedRequest tu, IncomingMessageEx request)
		{
			var writer = GetWriter();
			StatusCodes statusCode = StatusCodes.OK;

			string endpointId = null;
			if (request.Reader.Count.ContactCount == 0)
				statusCode = StatusCodes.BadRequest;
			else
				endpointId = (request.Reader.Contact[0].SipInstance.IsValid == true ?
					request.Reader.Contact[0].SipInstance : request.Reader.Contact[0].AddrSpec1.Value).ToString();

			if (statusCode == StatusCodes.OK)
			{
				try
				{
					var categories = enhancedPresence.ParsePublication(request.Content);

					var content = enhancedPresence.ProcessPublication(
						request.Reader.From.AddrSpec.Value.ToString(), categories, endpointId);

					writer.WriteStatusLine(statusCode);
					writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, statusCode);
					writer.WriteContentType(new ByteArrayPart(categories.OutContentType), new ByteArrayPart(categories.OutContentSubtype));
					// нужен ли контакт
					writer.WriteCustomHeaders();
					writer.WriteContentLength();
					writer.WriteCRLF();

					int endOfHeaders = writer.Count;
					writer.Write(content.GenerateToByteArray());
					writer.RewriteContentLength(writer.Count - endOfHeaders);
				}
				catch (EnhancedPresenceException)
				{
					statusCode = StatusCodes.BadRequest;
				}
			}

			if (statusCode != StatusCodes.OK)
			{
				writer.WriteResponse(request.Reader, statusCode);
			}

			tu.SendResponse(request, writer);
		}
Ejemplo n.º 50
0
 private static void None(IncomingMessageEx message)
 {
 }
Ejemplo n.º 51
0
		private void ProccessUnsubscribe(AcceptedRequest tu, IncomingMessageEx request)
		{
			var writer = GetWriter();

			var dialog = dialogManager.Get(request.Reader);

			if (dialog != null)
			{
				writer.WriteResponse(request.Reader, StatusCodes.OK, dialog.LocalTag);
				dialogManager.Remove(dialog.Id);
			}
			else
			{
				writer.WriteResponse(request.Reader, StatusCodes.OK);
			}

			tu.SendResponse(request, writer);
		}
Ejemplo n.º 52
0
 protected void SendResponse(IncomingMessageEx to, SipMessageWriter writer)
 {
     SendResponseExternal(to.ConnectionAddresses, to.TransactionId, writer);
 }
Ejemplo n.º 53
0
		private void ProccessSubscribe(AcceptedRequest tu, IncomingMessageEx request)
		{
			var dialog = dialogManager.GetOrCreate(request.Reader, request.ConnectionAddresses);

			if (dialog == null)
				SendResponse(request, StatusCodes.CallLegTransactionDoesNotExist);
			else if (request.Reader.IsExpiresTooBrief(60))
				SendResponse(request, StatusCodes.IntervalTooBrief);
			else
			{
				int expires = request.Reader.GetExpires(600, 900);


				var dialogId = dialog.Id.ToString();
				var toUser = request.Reader.To.AddrSpec.User.ToString();
				var toHost = request.Reader.To.AddrSpec.Hostport.Host.ToString();
				var document = simpleModule.Subscribe(dialogId, toUser + "@" + toHost, expires);


				var statusCode = StatusCodes.OK;
				var writer = GetWriter();

				writer.WriteStatusLine(statusCode);
				writer.CopyViaToFromCallIdRecordRouteCSeq(request.Reader, statusCode, dialog.LocalTag);
				writer.WriteExpires(expires);
				writer.WriteCRLF();

				SendResponse(request, writer);


				if (document != null)
					SendNotify(dialog, expires, document);
			}
		}
Ejemplo n.º 54
0
 public virtual AuthorizationMode OnCustomAuthorization(IncomingMessageEx message)
 {
     return(AuthorizationMode.Disabled);
 }
Ejemplo n.º 55
0
 /// <summary>
 /// !!! DEPRECATED !!!
 /// </summary>
 public void SendResponse(IncomingMessageEx to, SipMessageWriter writer)
 {
     TransactionUser.SendResponse(to.ConnectionAddresses, to.TransactionId, writer);
 }
Ejemplo n.º 56
0
		public void OnIncomingRequest(IncomingMessageEx message)
		{
			IncomingRequest(this, message);
		}