Ejemplo n.º 1
0
		public void GenerateForwardedRequest(SipMessageWriter writer, SipMessageReader reader, ArraySegment<byte> content, ConnectionAddresses fromConnectionAddress, int serverTransactionId)
		{
			Tracer.WriteInformation("LocalProxie.GenerateForwardedRequest");

			recordRouteIndex = reader.Count.RecordRouteCount;

			writer.WriteRequestLine(reader.Method, binding.AddrSpec);

			//var msReceivedCid = fromConnectionAddress.ToLowerHexChars(serverTransactionId);
			//writer.WriteVia(binding.ConnectionAddresses.Transport, binding.ConnectionAddresses.LocalEndPoint, TransactionId, msReceivedCid);
			//writer.WriteRecordRoute(binding.ConnectionAddresses.Transport, binding.ConnectionAddresses.LocalEndPoint, msReceivedCid);

			writer.WriteVia(binding.ConnectionAddresses.Transport, binding.ConnectionAddresses.LocalEndPoint, TransactionId);
			writer.WriteRecordRoute(binding.ConnectionAddresses.Transport, binding.ConnectionAddresses.LocalEndPoint);

			bool writeContact = true;

			for (int i = 0; i < reader.Count.HeaderCount; i++)
			{
				switch (reader.Headers[i].HeaderName)
				{
					case HeaderNames.MaxForwards:
						{
							int maxForwards = (reader.MaxForwards == int.MinValue) ? 70 : reader.MaxForwards;
							writer.WriteMaxForwards(maxForwards - 1);
						}
						break;

					case HeaderNames.Authorization:
					case HeaderNames.ProxyAuthorization:
						// remove exact authorization header
						break;

					case HeaderNames.To:
						writer.WriteToHeader(reader, i, binding.Epid);
						break;

					case HeaderNames.Contact:
						if (writeContact)
						{
							writer.WriteContact(reader.Contact[0].AddrSpec.User, binding.ConnectionAddresses.LocalEndPoint, binding.ConnectionAddresses.Transport, reader.Contact[0].SipInstance);
							writeContact = false;
						}
						break;

					default:
						writer.WriteHeader(reader, i);
						break;
				}
			}

			if (reader.ContentLength == int.MinValue)
				writer.WriteContentLength(content.Count);

			writer.WriteCustomHeaders();
			writer.WriteCRLF();

			writer.Write(content);
		}
Ejemplo n.º 2
0
		public IncomingMessage(ConnectionAddresses connectionAddresses, Connection connection)
		{
			ConnectionAddresses = connectionAddresses;

			Reader = connection.Reader;
			Header = connection.Header;
			Content = connection.Content;
		}
Ejemplo n.º 3
0
		public IncomingMessage(Transports transport, IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, int connectionId, SipMessageReader reader, ArraySegment<byte> readerData, ArraySegment<byte> contentData)
		{
			ConnectionAddresses = new ConnectionAddresses(transport, localEndPoint, remoteEndPoint, connectionId);

			Reader = reader;
			Header = readerData;
			Content = contentData;
		}
Ejemplo n.º 4
0
        public IncomingMessage(ConnectionAddresses connectionAddresses, Connection connection)
        {
            ConnectionAddresses = connectionAddresses;

            Reader  = connection.Reader;
            Header  = connection.Header;
            Content = connection.Content;
        }
Ejemplo n.º 5
0
        public IncomingMessage(Transports transport, IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, int connectionId, SipMessageReader reader, ArraySegment <byte> readerData, ArraySegment <byte> contentData)
        {
            ConnectionAddresses = new ConnectionAddresses(transport, localEndPoint, remoteEndPoint, connectionId);

            Reader  = reader;
            Header  = readerData;
            Content = contentData;
        }
Ejemplo n.º 6
0
		public Dialog Create(SipMessageReader message, int localTag, ConnectionAddresses connectionAddresses)
		{
			var dialog = new Dialog(message, localTag, connectionAddresses);

			dictionary.Add(dialog.Id, dialog);

			return dialog;
		}
Ejemplo n.º 7
0
        public Dialog Create(SipMessageReader message, int localTag, ConnectionAddresses connectionAddresses)
        {
            var dialog = new Dialog(message, localTag, connectionAddresses);

            dictionary.Add(dialog.Id, dialog);

            return(dialog);
        }
Ejemplo n.º 8
0
		public IncomingMessage(Connection connection)
		{
			ConnectionAddresses = new ConnectionAddresses(GetTransport(connection), connection.LocalEndPoint,
				new IPEndPoint(connection.RemoteEndPoint.Address, connection.RemoteEndPoint.Port), connection.Id);

			Reader = connection.Reader;
			Header = connection.Header;
			Content = connection.Content;
		}
Ejemplo n.º 9
0
        public IncomingMessage(Connection connection)
        {
            ConnectionAddresses = new ConnectionAddresses(GetTransport(connection), connection.LocalEndPoint,
                                                          new IPEndPoint(connection.RemoteEndPoint.Address, connection.RemoteEndPoint.Port), connection.Id);

            Reader  = connection.Reader;
            Header  = connection.Header;
            Content = connection.Content;
        }
Ejemplo n.º 10
0
		/// <summary>
		/// DEPRECATED!!! Не удобно читать код, не видно откуда CallLegTransactionDoesNotExist
		/// </summary>
		public Dialog GetOrCreate(SipMessageReader reader, ConnectionAddresses connectionAddresses, out StatusCodes statusCode)
		{
			var dialog = GetOrCreate(reader, connectionAddresses);

			statusCode = (dialog == null) ?
				StatusCodes.CallLegTransactionDoesNotExist : StatusCodes.OK;

			return dialog;
		}
Ejemplo n.º 11
0
        /// <summary>
        /// DEPRECATED!!! Не удобно читать код, не видно откуда CallLegTransactionDoesNotExist
        /// </summary>
        public Dialog GetOrCreate(SipMessageReader reader, ConnectionAddresses connectionAddresses, out StatusCodes statusCode)
        {
            var dialog = GetOrCreate(reader, connectionAddresses);

            statusCode = (dialog == null) ?
                         StatusCodes.CallLegTransactionDoesNotExist : StatusCodes.OK;

            return(dialog);
        }
Ejemplo n.º 12
0
		public void GenerateForwardedRequest(SipMessageWriter writer, SipMessageReader reader, ArraySegment<byte> content, ConnectionAddresses fromConnectionAddress, int serverTransactionId)
		{
			dialog2 = new Dialog(reader, tag, fromConnectionAddress);
			//trunk.AddDialog2(tag, dialog2);

			/////////////////////////////////////////////////////////////////////////////////

			writer.WriteRequestLine(reader.Method, dialog1.RemoteUri);

			//var msReceivedCid = fromConnectionAddress.ToLowerHexChars(serverTransactionId);
			//writer.WriteVia(dialog1.Transport, dialog1.LocalEndPoint, TransactionId, msReceivedCid);
			writer.WriteVia(dialog1.Transport, dialog1.LocalEndPoint, TransactionId);

			for (int i = 0; i < reader.Count.HeaderCount; i++)
			{
				switch (reader.Headers[i].HeaderName)
				{
					case HeaderNames.MaxForwards:
						writer.WriteMaxForwards((reader.MaxForwards == int.MinValue) ? 69 : reader.MaxForwards - 1);
						break;

					case HeaderNames.Contact:
						writer.WriteContact(dialog1.LocalEndPoint, dialog1.Transport);
						break;

					case HeaderNames.To:
						writer.WriteTo(dialog1.RemoteUri, dialog1.RemoteTag);
						break;

					case HeaderNames.From:
						writer.WriteFrom(reader.From.AddrSpec.Value, tag);
						break;

					case HeaderNames.Authorization:
						break;

					default:
						writer.WriteHeader(reader, i);
						break;

					case HeaderNames.Via:
						via = reader.Headers[i].Value.DeepCopy();
						break;
				}
			}

			if (reader.ContentLength == int.MinValue)
				writer.WriteContentLength(content.Count);

			writer.WriteCustomHeaders();
			writer.WriteCRLF();

			writer.Write(content);
		}
Ejemplo n.º 13
0
		public Dialog GetOrCreate(SipMessageReader reader, ConnectionAddresses connectionAddresses)
		{
			Dialog dialog = null;

			if (reader.To.Tag.IsInvalid)
				dialog = Create(reader, NewLocalTag(), connectionAddresses);
			else
				dialog = Get(reader);

			return dialog;
		}
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
		public IncomingMessage(ServerAsyncEventArgs e, SipMessageReader reader, ArraySegment<byte> content)
		{
			if (e.LocalEndPoint.Protocol != ServerProtocol.Udp)
				throw new ArgumentException();

			ConnectionAddresses = new ConnectionAddresses(Transports.Udp, e.LocalEndPoint,
				new IPEndPoint(e.RemoteEndPoint.Address, e.RemoteEndPoint.Port), ServerAsyncEventArgs.AnyNewConnectionId);

			Reader = reader;
			Content = content;
			Header = new ArraySegment<byte>(e.Buffer, e.Offset, e.BytesTransferred - content.Count);
		}
Ejemplo n.º 17
0
        public IncomingMessage(ServerAsyncEventArgs e, SipMessageReader reader, ArraySegment <byte> content)
        {
            if (e.LocalEndPoint.Protocol != ServerProtocol.Udp)
            {
                throw new ArgumentException();
            }

            ConnectionAddresses = new ConnectionAddresses(Transports.Udp, e.LocalEndPoint,
                                                          new IPEndPoint(e.RemoteEndPoint.Address, e.RemoteEndPoint.Port), ServerAsyncEventArgs.AnyNewConnectionId);

            Reader  = reader;
            Content = content;
            Header  = new ArraySegment <byte>(e.Buffer, e.Offset, e.BytesTransferred - content.Count);
        }
Ejemplo n.º 18
0
        public Dialog GetOrCreate(SipMessageReader reader, ConnectionAddresses connectionAddresses)
        {
            Dialog dialog = null;

            if (reader.To.Tag.IsInvalid)
            {
                dialog = Create(reader, NewLocalTag(), connectionAddresses);
            }
            else
            {
                dialog = Get(reader);
            }

            return(dialog);
        }
Ejemplo n.º 19
0
		public LocalTrunkProxieTest()
		{
			trunk = new Trunk("Display Name", "trunk.domain", "user", Transports.Udp,
				new IPEndPoint(IPAddress.Parse("1.2.3.4"), 1234), "server.url", "username", "password", "*****@*****.**", 0)
			{
				//Nonce = new ByteArrayPart("NONCEVALUE"),
				//Opaque = new ByteArrayPart("OPAQUEVALUE"),
				AuthHeader = HeaderNames.Authorization,
			};
			trunk.UpdateChallenge(new ByteArrayPart("NONCEVALUE"), new ByteArrayPart("OPAQUEVALUE"), new ByteArrayPart("auth"));

			proxie = new LocalTrunkProxie(0x12345678, trunk);

			destAddr = new ConnectionAddresses(Transports.Udp, new IPEndPoint(IPAddress.Parse("1.2.3.4"), 1234), new IPEndPoint(IPAddress.Parse("9.0.0.0"), 9000), 99);
			srcAddr = new ConnectionAddresses(Transports.Tcp, new IPEndPoint(IPAddress.Parse("5.6.7.8"), 5678), new IPEndPoint(IPAddress.Parse("8.0.0.0"), 8000), 88);

			request = CreateForwardedRequest(
				"INVITE sip:[email protected] SIP/2.0\r\n" +
				"Via: SIP/2.0/TCP 127.0.0.1:11371\r\n" +
				"Max-Forwards: 70\r\n" +
				"From: <sip:[email protected]>;tag=123;epid=456\r\n" +
				"To: <sip:[email protected]>\r\n" +
				"Call-ID: 403d20dd4ff84d178cd187b5710cb9a8\r\n" +
				"CSeq: 25 INVITE\r\n" +
				"Contact: <sip:[email protected]:11371;maddr=127.0.0.1;transport=tcp>;proxy=replace;+sip.instance=\"<urn:uuid:6984F470-4B9A-5F59-90C1-C9CA88CF214A>\"\r\n" +
				"Authorization: Digest username=\"jdoe2\", realm=\"officesip.local\", qop=auth, algorithm=MD5, uri=\"sip:[email protected]\", nonce=\"c01ba269fbd8eb84d29a52bd8ba7ba7e\", nc=6, cnonce=\"85550150622448769693330628644602\", opaque=\"00000001\", response=\"feed390d2fcaa5e65f0ce57eaa64756c\"\r\n" +
				"Content-Type: application/sdp\r\n" +
				"Content-Length: 135\r\n" +
				"\r\n",
				content);

			response = CreateForwardedResponse(
				"SIP/2.0 200 OK\r\n" +
				"Via: SIP/2.0/UDP 1.2.3.4:1234;branch=z9hG4bK12345678\r\n" +
				"Record-Route: <sip:1.2.3.4:1234;lr>\r\n" +
				"Via: SIP/2.0/TCP 127.0.0.1:11371\r\n" +
				"Max-Forwards: 69\r\n" +
				"From: \"Display Name\" <sip:[email protected]>;tag=123;epid=456\r\n" +
				"To: <sip:[email protected]>;tag=321\r\n" +
				"Call-ID: callid\r\n" +
				"CSeq: 1 INVITE\r\n" +
				"Contact: <sip:55.55.55.55:5555;transport=udp>;+sip.instance=\"<urn:uuid:123>\"\r\n" +
				"Content-Type: application/sdp\r\n" +
				"WWW-Authenticate: Digest realm=\"xxx\",nonce=\"0d0f70e6aa82aac734235c10f150271f\",qop=\"auth\",algorithm=MD5,stale=false,opaque=\"00000001\"\r\n" +
				"Content-Length: 135\r\n",
				content);
		}
Ejemplo n.º 20
0
			public Binding(SipMessageReader reader, int contactIndex, int expires1, ConnectionAddresses connectionAddresses)
			{
				ConnectionAddresses = connectionAddresses;

				int length =
					reader.Contact[contactIndex].AddrSpec.Value.Length +
					reader.Contact[contactIndex].SipInstance.Length +
					reader.From.Epid.Length +
					reader.CallId.Length;

				bytes = new byte[length + 8 - length % 8];

				marker1 = bytes.CopyFrom(reader.Contact[contactIndex].AddrSpec.Value, 0);
				marker2 = bytes.CopyFrom(reader.Contact[contactIndex].SipInstance, marker1);
				marker3 = bytes.CopyFrom(reader.From.Epid, marker2);
				marker4 = bytes.CopyFrom(reader.CallId, marker3);

				Update(reader.CSeq.Value, expires1);
			}
Ejemplo n.º 21
0
            public Binding(SipMessageReader reader, int contactIndex, int expires1, ConnectionAddresses connectionAddresses)
            {
                ConnectionAddresses = connectionAddresses;

                int length =
                    reader.Contact[contactIndex].AddrSpec.Value.Length +
                    reader.Contact[contactIndex].SipInstance.Length +
                    reader.From.Epid.Length +
                    reader.CallId.Length;

                bytes = new byte[length + 8 - length % 8];

                marker1 = bytes.CopyFrom(reader.Contact[contactIndex].AddrSpec.Value, 0);
                marker2 = bytes.CopyFrom(reader.Contact[contactIndex].SipInstance, marker1);
                marker3 = bytes.CopyFrom(reader.From.Epid, marker2);
                marker4 = bytes.CopyFrom(reader.CallId, marker3);

                Update(reader.CSeq.Value, expires1);
            }
Ejemplo n.º 22
0
        private void SendResponse(ConnectionAddresses connectionAddresses, int transactionKId, SipMessageWriter writer)
        {
            var e = CreateOutgoingMessage(connectionAddresses, writer, transactionKId);

            int action;

            switch (Transaction.GetTransactionBasicKind(transactionKId))
            {
            case Transaction.Kind.InviteServer:
                action = inviteServerTransactions.ProccessTransactionUser(transactionKId, e, writer.StatusCode);
                break;

            case Transaction.Kind.NonInviteServer:
                action = nonInviteServerTransactions.ProccessTransactionUser(transactionKId, e, writer.StatusCode);
                break;

            default:
                throw new NotImplementedException();
            }

            DoWork(e, transactionKId, action);
        }
Ejemplo n.º 23
0
		public Dialog(SipMessageReader response, ConnectionAddresses connectionAddresses)
		{
			this.transport = connectionAddresses.Transport;
			this.localEndPoint = connectionAddresses.LocalEndPoint;
			this.remoteEndPoint = connectionAddresses.RemoteEndPoint;

			localCseq = response.CSeq.Value;
			remoteCseq = 0;

			int length = Calculate(response, out routeCount) + response.To.Tag.Length;

			bytes = new byte[length];

			marker1 = bytes.CopyFrom(response.CallId, 0);
			marker2 = bytes.CopyFrom(response.From.Tag, marker1);
			marker3 = bytes.CopyFrom(response.To.Tag, marker2);
			marker4 = bytes.CopyFrom(response.From.AddrSpec.Value, marker3);
			marker5 = bytes.CopyFrom(response.To.AddrSpec.Value, marker4);
			marker6 = bytes.CopyFrom(response.From.Epid, marker5);
			markerN = bytes.CopyFrom(response.Contact[0].AddrSpec.Value, marker6);

			CopyRecordRoute(response);
		}
Ejemplo n.º 24
0
        private static ServerAsyncEventArgs CreateOutgoingMessage(ConnectionAddresses ca, SipMessageWriter writer, int transactionKId)
        {
            try
            {
                var e = EventArgsManager.Get();

                e.LocalEndPoint       = new ServerEndPoint(ca.Transport.ToServerProtocol(), ca.LocalEndPoint);
                e.RemoteEndPoint      = ca.RemoteEndPoint;
                e.ConnectionId        = ca.ConnectionId;
                e.UserTokenForSending = transactionKId;

                e.OffsetOffset = 128;
                e.Count        = writer.Count;
                e.AllocateBuffer();
                Buffer.BlockCopy(writer.Buffer, writer.Offset, e.Buffer, e.Offset, e.Count);

                return(e);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 25
0
        public Dialog(SipMessageReader response, ConnectionAddresses connectionAddresses)
        {
            this.transport      = connectionAddresses.Transport;
            this.localEndPoint  = connectionAddresses.LocalEndPoint;
            this.remoteEndPoint = connectionAddresses.RemoteEndPoint;

            localCseq  = response.CSeq.Value;
            remoteCseq = 0;

            int length = Calculate(response, out routeCount) + response.To.Tag.Length;

            bytes = new byte[length];

            marker1 = bytes.CopyFrom(response.CallId, 0);
            marker2 = bytes.CopyFrom(response.From.Tag, marker1);
            marker3 = bytes.CopyFrom(response.To.Tag, marker2);
            marker4 = bytes.CopyFrom(response.From.AddrSpec.Value, marker3);
            marker5 = bytes.CopyFrom(response.To.AddrSpec.Value, marker4);
            marker6 = bytes.CopyFrom(response.From.Epid, marker5);
            markerN = bytes.CopyFrom(response.Contact[0].AddrSpec.Value, marker6);

            CopyRecordRoute(response);
        }
Ejemplo n.º 26
0
        private readonly int remoteCseq;         // why readonly ?!

        public Dialog(SipMessageReader request, int localTag, ConnectionAddresses connectionAddresses)
        {
            this.transport      = connectionAddresses.Transport;
            this.localEndPoint  = connectionAddresses.LocalEndPoint;
            this.remoteEndPoint = connectionAddresses.RemoteEndPoint;

            localCseq  = 0;
            remoteCseq = request.CSeq.Value;

            int length = Calculate(request, out routeCount) + 8;

            bytes = new byte[length];

            marker1 = bytes.CopyFrom(request.CallId, 0);
            HexEncoding.GetLowerHexChars(localTag, bytes, marker1);
            marker2 = marker1 + 8;
            marker3 = bytes.CopyFrom(request.From.Tag, marker2);
            marker4 = bytes.CopyFrom(request.To.AddrSpec.Value, marker3);
            marker5 = bytes.CopyFrom(request.From.AddrSpec.Value, marker4);
            marker6 = bytes.CopyFrom(request.From.Epid, marker5);
            markerN = bytes.CopyFrom(request.Contact[0].AddrSpec.Value, marker6);

            CopyRecordRoute(request);
        }
Ejemplo n.º 27
0
		private readonly int remoteCseq; // why readonly ?!

		public Dialog(SipMessageReader request, int localTag, ConnectionAddresses connectionAddresses)
		{
			this.transport = connectionAddresses.Transport;
			this.localEndPoint = connectionAddresses.LocalEndPoint;
			this.remoteEndPoint = connectionAddresses.RemoteEndPoint;

			localCseq = 0;
			remoteCseq = request.CSeq.Value;

			int length = Calculate(request, out routeCount) + 8;

			bytes = new byte[length];

			marker1 = bytes.CopyFrom(request.CallId, 0);
			HexEncoding.GetLowerHexChars(localTag, bytes, marker1);
			marker2 = marker1 + 8;
			marker3 = bytes.CopyFrom(request.From.Tag, marker2);
			marker4 = bytes.CopyFrom(request.To.AddrSpec.Value, marker3);
			marker5 = bytes.CopyFrom(request.From.AddrSpec.Value, marker4);
			marker6 = bytes.CopyFrom(request.From.Epid, marker5);
			markerN = bytes.CopyFrom(request.Contact[0].AddrSpec.Value, marker6);

			CopyRecordRoute(request);
		}
Ejemplo n.º 28
0
        private void SendRequest(int router, ConnectionAddresses connectionAddresses, int transactionKId, SipMessageWriter writer, int userData)
        {
            bool isAck = writer.Method == Methods.Ackm;
            var  e     = CreateOutgoingMessage(connectionAddresses, writer, transactionKId);

            int action;

            //switch (Transaction.GetKindForOutgoing(writer.Method, writer.IsRequest))
            switch (Transaction.GetTransactionBasicKind(transactionKId))
            {
            case Transaction.Kind.InviteClient:
                action = inviteClientTransactions.ProccessTransactionUser(transactionKId, router, userData, isAck, e);
                break;

            case Transaction.Kind.NonInviteClient:
                action = nonInviteClientTransactions.ProccessTransactionUser(transactionKId, router, userData, isAck, e);
                break;

            default:
                throw new NotImplementedException();
            }

            DoWork(e, transactionKId, action);
        }
Ejemplo n.º 29
0
		public void GenerateForwardedResponse(SipMessageWriter writer, SipMessageReader reader, ArraySegment<byte> content, ConnectionAddresses ca)
		{
			writer.WriteStatusLine(reader.StatusCode);

			int recordRouteCount = reader.Count.RecordRouteCount;

			bool writeContact = true;

			for (int i = 1; i < reader.Count.ViaCount; i++)
				writer.WriteHeader(HeaderNames.Via, reader.Via[i].Value);

			for (int i = 0; i < reader.Count.HeaderCount; i++)
			{
				switch (reader.Headers[i].HeaderName)
				{
					case HeaderNames.Via:
						break;

					case HeaderNames.Authorization:
					case HeaderNames.ProxyAuthorization:
						// remove exact authorization header
						break;

					case HeaderNames.Contact:
						if (writeContact)
						{
							writer.WriteContact(reader.Contact[0].AddrSpec.User, ca.LocalEndPoint, ca.Transport, reader.Contact[0].SipInstance);
							writeContact = false;
						}
						break;


					case HeaderNames.RecordRoute:
						{
							recordRouteCount--;
							if (recordRouteCount != recordRouteIndex)
								goto default;

							writer.WriteRecordRoute(ca.Transport, ca.LocalEndPoint);
						}
						break;

					default:
						writer.WriteHeader(reader, i);
						break;
				}
			}

			if (reader.ContentLength == int.MinValue)
				writer.WriteContentLength(content.Count);

			writer.WriteCustomHeaders();
			writer.WriteCRLF();
			writer.Write(content);
		}
Ejemplo n.º 30
0
		public void GenerateForwardedRequest(SipMessageWriter writer, SipMessageReader reader, ArraySegment<byte> content, ConnectionAddresses fromConnectionAddress, int serverTransactionId)
		{
			//int? tag = HexEncoding.ParseHex8(reader.To.Tag);
			//var dialog2 = trunk.GetExternalDialog(tag);

			//if (dialog2 != null)
			//{
			//    this.tag = tag.Value;
			//    //this.dialog1 = dialog1;
			//    this.dialog2 = dialog2;
			//}

			Dialog dialog2 = null;
			if (HexEncoding.TryParseHex8(reader.To.Tag, out tag))
				dialog2 = trunk.GetDialog2(tag);
			else
				tag = DialogManager.NewLocalTag();

			dialog1 = new Dialog(reader, tag, fromConnectionAddress);
			trunk.AddDialog1(tag, dialog1);


			writer.WriteRequestLine(reader.Method, trunk.Transport.ToScheme(), reader.To.AddrSpec.User, trunk.Domain);

			//var msReceivedCid = fromConnectionAddress.ToLowerHexChars(serverTransactionId);
			//writer.WriteVia(trunk.ConnectionAddresses.Transport, trunk.ConnectionAddresses.LocalEndPoint, TransactionId, msReceivedCid);
			writer.WriteVia(trunk.ConnectionAddresses.Transport, trunk.ConnectionAddresses.LocalEndPoint, TransactionId);

			for (int i = 0; i < reader.Count.HeaderCount; i++)
			{
				switch (reader.Headers[i].HeaderName)
				{
					case HeaderNames.MaxForwards:
						writer.WriteMaxForwards((reader.MaxForwards == int.MinValue) ? 69 : reader.MaxForwards - 1);
						break;

					case HeaderNames.Contact:
						writer.WriteContact(trunk.LocalEndPoint, trunk.Transport, reader.Contact[0].SipInstance);
						break;

					case HeaderNames.Via:
						via = reader.Headers[i].Value.DeepCopy();
						break;

					case HeaderNames.To:
						writer.WriteTo2(reader.To.AddrSpec.User, trunk.Domain, (dialog2 != null) ? dialog2.RemoteTag : ByteArrayPart.Invalid);
						break;

					case HeaderNames.From:
						writer.WriteFrom(trunk.Uri, tag);
						break;

					case HeaderNames.CSeq:
						writer.WriteCseq(trunk.GetCSeq(reader.CSeq.Method, reader.CallId, reader.CSeq.Value), reader.CSeq.Method);
						break;

					case HeaderNames.Authorization:
					case HeaderNames.ContentLength:
					case HeaderNames.Extension:
						break;

					default:
						writer.WriteHeader(reader, i);
						break;
				}
			}

			WriteAuthorization(writer, reader.Method, content);

			if (reader.Method == Methods.Invitem && reader.ContentType.Subtype.Equals(sdp)) // temp
				content = Sip.Sdp.Helpers.CutCandidates(content);

			writer.WriteContentLength(content.Count);
			writer.WriteCRLF();

			writer.Write(content);
		}
Ejemplo n.º 31
0
		public void SendRequest(ConnectionAddresses connectionAddresses, SipMessageWriter writer, int transactionId)
		{
			TransactionUser.SendRequest(Index, connectionAddresses, transactionId, writer, 0);
		}
Ejemplo n.º 32
0
		private void SendRequest(int router, ConnectionAddresses connectionAddresses, int transactionKId, SipMessageWriter writer, int userData)
		{
			sendRequestes.Add(new Request() { ConnectionAddresses = connectionAddresses, TransactionKId = transactionKId, Writer = writer, });
			sendRequestCount[(int)writer.Method]++;
		}
Ejemplo n.º 33
0
        public void GenerateForwardedRequest(SipMessageWriter writer, SipMessageReader reader, ArraySegment <byte> content, ConnectionAddresses fromConnectionAddress, int serverTransactionId)
        {
            //int? tag = HexEncoding.ParseHex8(reader.To.Tag);
            //var dialog2 = trunk.GetExternalDialog(tag);

            //if (dialog2 != null)
            //{
            //    this.tag = tag.Value;
            //    //this.dialog1 = dialog1;
            //    this.dialog2 = dialog2;
            //}

            Dialog dialog2 = null;

            if (HexEncoding.TryParseHex8(reader.To.Tag, out tag))
            {
                dialog2 = trunk.GetDialog2(tag);
            }
            else
            {
                tag = DialogManager.NewLocalTag();
            }

            dialog1 = new Dialog(reader, tag, fromConnectionAddress);
            trunk.AddDialog1(tag, dialog1);


            writer.WriteRequestLine(reader.Method, trunk.Transport.ToScheme(), reader.To.AddrSpec.User, trunk.Domain);

            //var msReceivedCid = fromConnectionAddress.ToLowerHexChars(serverTransactionId);
            //writer.WriteVia(trunk.ConnectionAddresses.Transport, trunk.ConnectionAddresses.LocalEndPoint, TransactionId, msReceivedCid);
            writer.WriteVia(trunk.ConnectionAddresses.Transport, trunk.ConnectionAddresses.LocalEndPoint, TransactionId);

            for (int i = 0; i < reader.Count.HeaderCount; i++)
            {
                switch (reader.Headers[i].HeaderName)
                {
                case HeaderNames.MaxForwards:
                    writer.WriteMaxForwards((reader.MaxForwards == int.MinValue) ? 69 : reader.MaxForwards - 1);
                    break;

                case HeaderNames.Contact:
                    writer.WriteContact(trunk.LocalEndPoint, trunk.Transport, reader.Contact[0].SipInstance);
                    break;

                case HeaderNames.Via:
                    via = reader.Headers[i].Value.DeepCopy();
                    break;

                case HeaderNames.To:
                    writer.WriteTo2(reader.To.AddrSpec.User, trunk.Domain, (dialog2 != null) ? dialog2.RemoteTag : ByteArrayPart.Invalid);
                    break;

                case HeaderNames.From:
                    writer.WriteFrom(trunk.Uri, tag);
                    break;

                case HeaderNames.CSeq:
                    writer.WriteCseq(trunk.GetCSeq(reader.CSeq.Method, reader.CallId, reader.CSeq.Value), reader.CSeq.Method);
                    break;

                case HeaderNames.Authorization:
                case HeaderNames.ContentLength:
                case HeaderNames.Extension:
                    break;

                default:
                    writer.WriteHeader(reader, i);
                    break;
                }
            }

            WriteAuthorization(writer, reader.Method, content);

            if (reader.Method == Methods.Invitem && reader.ContentType.Subtype.Equals(sdp))             // temp
            {
                content = Sip.Sdp.Helpers.CutCandidates(content);
            }

            writer.WriteContentLength(content.Count);
            writer.WriteCRLF();

            writer.Write(content);
        }
Ejemplo n.º 34
0
		protected void SendAck(ConnectionAddresses connectionAddresses, SipMessageWriter writer)
		{
			SendNonTransactionMessage(connectionAddresses.Transport, connectionAddresses.LocalEndPoint,
				connectionAddresses.RemoteEndPoint, connectionAddresses.ConnectionId, writer);
		}
Ejemplo n.º 35
0
 protected void SendAck(ConnectionAddresses connectionAddresses, SipMessageWriter writer)
 {
     SendNonTransactionMessage(connectionAddresses.Transport, connectionAddresses.LocalEndPoint,
                               connectionAddresses.RemoteEndPoint, connectionAddresses.ConnectionId, writer);
 }
Ejemplo n.º 36
0
 public void SendResponse(ConnectionAddresses connectionAddresses, int transactionId, SipMessageWriter writer)
 {
     SendResponseExternal(connectionAddresses, transactionId, writer);
 }
Ejemplo n.º 37
0
 public void SendRequest(ConnectionAddresses connectionAddresses, SipMessageWriter writer, int transactionId)
 {
     TransactionUser.SendRequest(Index, connectionAddresses, transactionId, writer, 0);
 }
Ejemplo n.º 38
0
		public void GenerateForwardedResponse(SipMessageWriter writer, SipMessageReader response, ArraySegment<byte> content, ConnectionAddresses ca)
		{
			//if (response.StatusCode.Is2xx && response.To.Tag.IsValid)
			//    trunk.AddDialogs(tag, new Dialog(response, ca), dialog2);


			if (response.CSeq.Method == Methods.Byem)
			{
				trunk.RemoveDialog1(tag);
				trunk.RemoveDialog2(tag);
			}
			else
			{
				if (response.StatusCode.Is2xx && response.To.Tag.IsValid)
					trunk.AddDialog1(tag, new Dialog(response, binding.ConnectionAddresses)); //ca));
				if (response.StatusCode.Is2xx == false && response.StatusCode.Is1xx == false)
					trunk.RemoveDialog2(tag);
			}


			writer.WriteStatusLine(response.StatusCode);

			for (int i = 0; i < response.Count.HeaderCount; i++)
			{
				switch (response.Headers[i].HeaderName)
				{
					case HeaderNames.Via:
						writer.Write(SipMessageWriter.C.Via, SipMessageWriter.C.HCOLON, via);
						writer.WriteCRLF();
						break;

					case HeaderNames.WwwAuthenticate:
					case HeaderNames.ProxyAuthenticate:
						break;

					case HeaderNames.To:
						writer.WriteTo(dialog2.LocalUri, dialog2.LocalTag);
						break;

					case HeaderNames.From:
						writer.WriteFrom(dialog2.RemoteUri, dialog2.RemoteTag);
						break;

					case HeaderNames.CSeq:
						writer.WriteCseq(dialog2.RemoteCseq, response.CSeq.Method);
						break;

					case HeaderNames.Contact:
						writer.WriteContact(ca.LocalEndPoint, ca.Transport);
						break;

					default:
						writer.WriteHeader(response, i);
						break;
				}
			}

			if (response.ContentLength == int.MinValue)
				writer.WriteContentLength(content.Count);

			writer.WriteCustomHeaders();
			writer.WriteCRLF();
			writer.Write(content);
		}
Ejemplo n.º 39
0
		public void SendResponse(ConnectionAddresses connectionAddresses, int transactionId, SipMessageWriter writer)
		{
			SendResponseExternal(connectionAddresses, transactionId, writer);
		}
Ejemplo n.º 40
0
        public void GenerateForwardedResponse(SipMessageWriter writer, SipMessageReader response, ArraySegment <byte> content, ConnectionAddresses ca)
        {
            //if (dialog2 == null && response.StatusCode.Is2xx && response.To.Tag.IsValid)
            //    trunk.AddDialogs(tag, dialog1, new Dialog(response, ca));

            if (response.CSeq.Method == Methods.Byem)
            {
                trunk.RemoveDialog1(tag);
                trunk.RemoveDialog2(tag);
            }
            else
            {
                if (response.StatusCode.Is2xx && response.To.Tag.IsValid)
                {
                    trunk.AddDialog2(tag, new Dialog(response, ca));
                }
                if (response.StatusCode.Is2xx == false && response.StatusCode.Is1xx == false)
                {
                    trunk.RemoveDialog1(tag);
                }
            }

            writer.WriteStatusLine(response.StatusCode);

            for (int i = 0; i < response.Count.HeaderCount; i++)
            {
                switch (response.Headers[i].HeaderName)
                {
                case HeaderNames.Via:
                    writer.Write(SipMessageWriter.C.Via, SipMessageWriter.C.HCOLON, via);
                    writer.WriteCRLF();
                    break;

                case HeaderNames.WwwAuthenticate:
                case HeaderNames.ProxyAuthenticate:
                    break;

                case HeaderNames.To:
                    writer.WriteTo(dialog1.LocalUri, dialog1.LocalTag);
                    break;

                case HeaderNames.From:
                    writer.WriteFrom(dialog1.RemoteUri, dialog1.RemoteTag);
                    break;

                case HeaderNames.CSeq:
                    writer.WriteCseq(dialog1.RemoteCseq, response.CSeq.Method);
                    break;

                case HeaderNames.Contact:
                    writer.WriteContact(response.To.AddrSpec.User, ca.LocalEndPoint, ca.Transport, ByteArrayPart.Invalid);
                    break;

                default:
                    writer.WriteHeader(response, i);
                    break;
                }
            }

            if (response.ContentLength == int.MinValue)
            {
                writer.WriteContentLength(content.Count);
            }

            writer.WriteCustomHeaders();
            writer.WriteCRLF();
            writer.Write(content);
        }
Ejemplo n.º 41
0
 private void SendNonTransactionMessage(ConnectionAddresses connectionAddresses, SipMessageWriter writer)
 {
     SendAsync(CreateOutgoingMessage(connectionAddresses, writer, Transaction.InvalidKId));
 }
Ejemplo n.º 42
0
		private void SendResponse(ConnectionAddresses connectionAddresses, int transactionKId, SipMessageWriter writer)
		{
			sentResponses.Add(writer);
		}
Ejemplo n.º 43
0
        public void GenerateForwardedRequest(SipMessageWriter writer, SipMessageReader reader, ArraySegment <byte> content, ConnectionAddresses fromConnectionAddress, int serverTransactionId)
        {
            //dialog2 = new Dialog(reader, fromTag, fromConnectionAddress);

            Dialog dialog1 = null;

            if (HexEncoding.TryParseHex8(reader.To.Tag, out tag))
            {
                dialog1 = trunk.GetDialog1(tag);
            }
            else
            {
                tag = DialogManager.NewLocalTag();
            }

            dialog2 = new Dialog(reader, tag, fromConnectionAddress);
            trunk.AddDialog2(tag, dialog2);

            /////////////////////////////////////////////////////////////////////////////////

            writer.WriteRequestLine(reader.Method, binding.AddrSpec);

            //var msReceivedCid = fromConnectionAddress.ToLowerHexChars(serverTransactionId);
            //writer.WriteVia(binding.ConnectionAddresses.Transport, binding.ConnectionAddresses.LocalEndPoint, TransactionId, msReceivedCid);
            writer.WriteVia(binding.ConnectionAddresses.Transport, binding.ConnectionAddresses.LocalEndPoint, TransactionId);

            for (int i = 0; i < reader.Count.HeaderCount; i++)
            {
                switch (reader.Headers[i].HeaderName)
                {
                case HeaderNames.MaxForwards:
                    writer.WriteMaxForwards((reader.MaxForwards == int.MinValue) ? 69 : reader.MaxForwards - 1);
                    break;

                case HeaderNames.Contact:
                    writer.WriteContact(binding.ConnectionAddresses.LocalEndPoint, binding.ConnectionAddresses.Transport);
                    break;

                case HeaderNames.To:
                    writer.WriteTo(trunk.ForwardCallToUri, (dialog1 != null) ? dialog1.RemoteTag : ByteArrayPart.Invalid);
                    break;

                case HeaderNames.From:
                    writer.WriteFrom(reader.From.AddrSpec.Value, tag);
                    break;

                case HeaderNames.Authorization:
                    break;

                default:
                    writer.WriteHeader(reader, i);
                    break;

                case HeaderNames.Via:
                    via = reader.Headers[i].Value.DeepCopy();
                    break;
                }
            }

            if (reader.ContentLength == int.MinValue)
            {
                writer.WriteContentLength(content.Count);
            }

            writer.WriteCustomHeaders();
            writer.WriteCRLF();

            writer.Write(content);
        }
Ejemplo n.º 44
0
        public void GenerateForwardedRequest(SipMessageWriter writer, SipMessageReader reader, ArraySegment <byte> content, ConnectionAddresses fromConnectionAddress, int serverTransactionId)
        {
            dialog2 = new Dialog(reader, tag, fromConnectionAddress);
            //trunk.AddDialog2(tag, dialog2);

            /////////////////////////////////////////////////////////////////////////////////

            writer.WriteRequestLine(reader.Method, dialog1.RemoteUri);

            //var msReceivedCid = fromConnectionAddress.ToLowerHexChars(serverTransactionId);
            //writer.WriteVia(dialog1.Transport, dialog1.LocalEndPoint, TransactionId, msReceivedCid);
            writer.WriteVia(dialog1.Transport, dialog1.LocalEndPoint, TransactionId);

            for (int i = 0; i < reader.Count.HeaderCount; i++)
            {
                switch (reader.Headers[i].HeaderName)
                {
                case HeaderNames.MaxForwards:
                    writer.WriteMaxForwards((reader.MaxForwards == int.MinValue) ? 69 : reader.MaxForwards - 1);
                    break;

                case HeaderNames.Contact:
                    writer.WriteContact(dialog1.LocalEndPoint, dialog1.Transport);
                    break;

                case HeaderNames.To:
                    writer.WriteTo(dialog1.RemoteUri, dialog1.RemoteTag);
                    break;

                case HeaderNames.From:
                    writer.WriteFrom(reader.From.AddrSpec.Value, tag);
                    break;

                case HeaderNames.Authorization:
                    break;

                default:
                    writer.WriteHeader(reader, i);
                    break;

                case HeaderNames.Via:
                    via = reader.Headers[i].Value.DeepCopy();
                    break;
                }
            }

            if (reader.ContentLength == int.MinValue)
            {
                writer.WriteContentLength(content.Count);
            }

            writer.WriteCustomHeaders();
            writer.WriteCRLF();

            writer.Write(content);
        }
Ejemplo n.º 45
0
        public void GenerateForwardedResponse(SipMessageWriter writer, SipMessageReader reader, ArraySegment <byte> content, ConnectionAddresses ca)
        {
            writer.WriteStatusLine(reader.StatusCode);

            int recordRouteCount = reader.Count.RecordRouteCount;

            bool writeContact = true;

            for (int i = 1; i < reader.Count.ViaCount; i++)
            {
                writer.WriteHeader(HeaderNames.Via, reader.Via[i].Value);
            }

            for (int i = 0; i < reader.Count.HeaderCount; i++)
            {
                switch (reader.Headers[i].HeaderName)
                {
                case HeaderNames.Via:
                    break;

                case HeaderNames.Authorization:
                case HeaderNames.ProxyAuthorization:
                    // remove exact authorization header
                    break;

                case HeaderNames.Contact:
                    if (writeContact)
                    {
                        writer.WriteContact(reader.Contact[0].AddrSpec.User, ca.LocalEndPoint, ca.Transport, reader.Contact[0].SipInstance);
                        writeContact = false;
                    }
                    break;


                case HeaderNames.RecordRoute:
                {
                    recordRouteCount--;
                    if (recordRouteCount != recordRouteIndex)
                    {
                        goto default;
                    }

                    writer.WriteRecordRoute(ca.Transport, ca.LocalEndPoint);
                }
                break;

                default:
                    writer.WriteHeader(reader, i);
                    break;
                }
            }

            if (reader.ContentLength == int.MinValue)
            {
                writer.WriteContentLength(content.Count);
            }

            writer.WriteCustomHeaders();
            writer.WriteCRLF();
            writer.Write(content);
        }
Ejemplo n.º 46
0
		public void GenerateForwardedRequest(SipMessageWriter writer, SipMessageReader reader, ArraySegment<byte> content, ConnectionAddresses fromConnectionAddress, int serverTransactionId)
		{
			//dialog2 = new Dialog(reader, fromTag, fromConnectionAddress);

			Dialog dialog1 = null;
			if (HexEncoding.TryParseHex8(reader.To.Tag, out tag))
				dialog1 = trunk.GetDialog1(tag);
			else
				tag = DialogManager.NewLocalTag();

			dialog2 = new Dialog(reader, tag, fromConnectionAddress);
			trunk.AddDialog2(tag, dialog2);

			/////////////////////////////////////////////////////////////////////////////////

			writer.WriteRequestLine(reader.Method, binding.AddrSpec);

			//var msReceivedCid = fromConnectionAddress.ToLowerHexChars(serverTransactionId);
			//writer.WriteVia(binding.ConnectionAddresses.Transport, binding.ConnectionAddresses.LocalEndPoint, TransactionId, msReceivedCid);
			writer.WriteVia(binding.ConnectionAddresses.Transport, binding.ConnectionAddresses.LocalEndPoint, TransactionId);

			for (int i = 0; i < reader.Count.HeaderCount; i++)
			{
				switch (reader.Headers[i].HeaderName)
				{
					case HeaderNames.MaxForwards:
						writer.WriteMaxForwards((reader.MaxForwards == int.MinValue) ? 69 : reader.MaxForwards - 1);
						break;

					case HeaderNames.Contact:
						writer.WriteContact(binding.ConnectionAddresses.LocalEndPoint, binding.ConnectionAddresses.Transport);
						break;

					case HeaderNames.To:
						writer.WriteTo(trunk.ForwardCallToUri, (dialog1 != null) ? dialog1.RemoteTag : ByteArrayPart.Invalid);
						break;

					case HeaderNames.From:
						writer.WriteFrom(reader.From.AddrSpec.Value, tag);
						break;

					case HeaderNames.Authorization:
						break;

					default:
						writer.WriteHeader(reader, i);
						break;

					case HeaderNames.Via:
						via = reader.Headers[i].Value.DeepCopy();
						break;
				}
			}

			if (reader.ContentLength == int.MinValue)
				writer.WriteContentLength(content.Count);

			writer.WriteCustomHeaders();
			writer.WriteCRLF();

			writer.Write(content);
		}
Ejemplo n.º 47
0
        public void GenerateForwardedRequest(SipMessageWriter writer, SipMessageReader reader, ArraySegment <byte> content, ConnectionAddresses fromConnectionAddress, int serverTransactionId)
        {
            Tracer.WriteInformation("LocalProxie.GenerateForwardedRequest");

            recordRouteIndex = reader.Count.RecordRouteCount;

            writer.WriteRequestLine(reader.Method, binding.AddrSpec);

            //var msReceivedCid = fromConnectionAddress.ToLowerHexChars(serverTransactionId);
            //writer.WriteVia(binding.ConnectionAddresses.Transport, binding.ConnectionAddresses.LocalEndPoint, TransactionId, msReceivedCid);
            //writer.WriteRecordRoute(binding.ConnectionAddresses.Transport, binding.ConnectionAddresses.LocalEndPoint, msReceivedCid);

            writer.WriteVia(binding.ConnectionAddresses.Transport, binding.ConnectionAddresses.LocalEndPoint, TransactionId);
            writer.WriteRecordRoute(binding.ConnectionAddresses.Transport, binding.ConnectionAddresses.LocalEndPoint);

            bool writeContact = true;

            for (int i = 0; i < reader.Count.HeaderCount; i++)
            {
                switch (reader.Headers[i].HeaderName)
                {
                case HeaderNames.MaxForwards:
                {
                    int maxForwards = (reader.MaxForwards == int.MinValue) ? 70 : reader.MaxForwards;
                    writer.WriteMaxForwards(maxForwards - 1);
                }
                break;

                case HeaderNames.Authorization:
                case HeaderNames.ProxyAuthorization:
                    // remove exact authorization header
                    break;

                case HeaderNames.To:
                    writer.WriteToHeader(reader, i, binding.Epid);
                    break;

                case HeaderNames.Contact:
                    if (writeContact)
                    {
                        writer.WriteContact(reader.Contact[0].AddrSpec.User, binding.ConnectionAddresses.LocalEndPoint, binding.ConnectionAddresses.Transport, reader.Contact[0].SipInstance);
                        writeContact = false;
                    }
                    break;

                default:
                    writer.WriteHeader(reader, i);
                    break;
                }
            }

            if (reader.ContentLength == int.MinValue)
            {
                writer.WriteContentLength(content.Count);
            }

            writer.WriteCustomHeaders();
            writer.WriteCRLF();

            writer.Write(content);
        }