Beispiel #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);
		}
Beispiel #2
0
		public void Dispose()
		{
			bufferHandle.Free();

			if (bestResponse != null)
			{
				bestResponse.Dispose();
				bestResponse = null;
			}
		}
		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);
		}
		private void AreEqual(string expected, PresenceDocument doc)
		{
			var writer = new SipMessageWriter();

			expected = expected.Replace('\'', '"');

			//byte[] actualBytes = null;
			//int copied = doc.CopyTo(
			//    (length) => { return new ArraySegment<byte>(actualBytes = new byte[length], 0, length); });
			doc.WriteContent(writer);

			//string actual = Encoding.UTF8.GetString(actualBytes);

			var actual = Encoding.UTF8.GetString(writer.Buffer, writer.Offset, writer.Count);

			Assert.AreEqual(openPresence + expected + closePresence, actual);
		}
Beispiel #5
0
		public void GenerateCancel(SipMessageWriter writer, SipMessageReader reader)
		{
			GenerateRequest(writer, reader, Methods.Cancelm);
		}
		private void SendResponse(ConnectionAddresses connectionAddresses, int transactionKId, SipMessageWriter writer)
		{
			sentResponses.Add(writer);
		}
Beispiel #7
0
		public void SendRequest(Transports transport, IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, int connectionId, SipMessageWriter writer, int transactionId)
		{
			TransactionUser.SendRequest(Index,
				new ConnectionAddresses(transport, localEndPoint, remoteEndPoint, connectionId), transactionId, writer, 0);
		}
		public void GenerateAck(SipMessageWriter writer, SipMessageReader reader)
		{
			GenerateRequest(writer, reader, Methods.Ackm);
		}
		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);
		}
		protected void SendResponse(IncomingMessageEx to, SipMessageWriter writer)
		{
			SendResponseExternal(to.ConnectionAddresses, to.TransactionId, writer);
		}
Beispiel #11
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);
		}
		private string CreateForwardedRequest(string message, string content)
		{
			var reader = Parse(message);
			var contentBytes = Encoding.UTF8.GetBytes(content);

			using (var writer = new SipMessageWriter())
			{
				proxie.GenerateForwardedRequest(writer, reader, new ArraySegment<byte>(contentBytes), destAddr, 0x1000);
				return Encoding.UTF8.GetString(writer.Buffer, writer.Offset, writer.Count);
			}
		}
		public bool IsAuthorized(SipMessageReader reader, ArraySegment<byte> content, ByteArrayPart realm, int param, out SipMessageWriter writer)
		{
			writer = null;
			return true;
		}
Beispiel #14
0
		public void WriteLenghtAndContent(SipMessageWriter writer)
		{
			lock (tuples)
			{
				int length = CountLength();

				writer.WriteContentLength(length);
				writer.WriteCRLF();

				WriteContent(writer, length);
			}
		}
Beispiel #15
0
		public void SetBestResponse(SipMessageWriter response)
		{
			if (bestResponse != response)
			{
				if (bestResponse != null)
				{
					bestResponse.Dispose();
					bestResponse = null;
				}

				bestResponse = response;
				bestResponseStatusCode = response.StatusCode;
			}
		}
		public void WriteSignature(SipMessageWriter writer)
		{
		}
Beispiel #17
0
		public SipMessageWriter DetachBestResponse()
		{
			var response = bestResponse;
			bestResponse = null;
			return response;
		}
Beispiel #18
0
		public void SetBestResponseStatusCode(int statusCode)
		{
			bestResponseStatusCode = statusCode;

			if (bestResponse != null)
			{
				bestResponse.Dispose();
				bestResponse = null;
			}
		}
		private string CreateForwardedResponse(string message, string content)
		{
			var reader = Parse(message);

			using (var writer = new SipMessageWriter())
			{
				proxie.GenerateForwardedResponse(writer, reader, new ArraySegment<byte>(Encoding.UTF8.GetBytes(content)), srcAddr);
				return Encoding.UTF8.GetString(writer.Buffer, writer.Offset, writer.Count);
			}
		}
Beispiel #20
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);
		}
		protected void SendAck(ConnectionAddresses connectionAddresses, SipMessageWriter writer)
		{
			SendNonTransactionMessage(connectionAddresses.Transport, connectionAddresses.LocalEndPoint,
				connectionAddresses.RemoteEndPoint, connectionAddresses.ConnectionId, writer);
		}
Beispiel #22
0
		/// Что с этой функцией делать?! Как отсюда убрать? Убрать в Helpers?
		private void WriteAuthorization(SipMessageWriter writer, Methods method, ArraySegment<byte> content)
		{
			if (trunk.Nonce.IsValid)
			{
				int nc = trunk.GetNextNonceCount();
				int cnonce = Environment.TickCount;

				var response = SipDigestAuthentication.GetResponseHexChars(trunk.AuthenticationId, trunk.Realm, AuthAlgorithms.Md5, trunk.Nonce,
					cnonce, nc, trunk.Password, trunk.Qop, trunk.Uri, method.ToByteArrayPart(), content);

				writer.WriteDigestAuthorization(trunk.AuthHeader, trunk.AuthenticationId, trunk.Realm, trunk.Qop, AuthAlgorithms.Md5, trunk.Uri,
					trunk.Nonce, nc, cnonce, trunk.Opaque, response);
			}
		}
		public void SendResponse(ConnectionAddresses connectionAddresses, int transactionId, SipMessageWriter writer)
		{
			SendResponseExternal(connectionAddresses, transactionId, writer);
		}
Beispiel #24
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);
		}
Beispiel #25
0
		public void GenerateCancel(SipMessageWriter writer, SipMessageReader reader)
		{
			trunk.RemoveDialog1(tag);
			trunk.RemoveDialog2(tag);

			GenerateRequest(writer, reader, Methods.Cancelm);
		}
Beispiel #26
0
		/// <summary>
		/// !!! DEPRECATED !!!
		/// </summary>
		public void SendResponse(IncomingMessageEx to, SipMessageWriter writer)
		{
			TransactionUser.SendResponse(to.ConnectionAddresses, to.TransactionId, writer);
		}
Beispiel #27
0
		private void GenerateRequest(SipMessageWriter writer, SipMessageReader reader, Methods method)
		{
			writer.WriteRequestLine(method, trunk.ForwardCallToUri);

			writer.WriteVia(ToConnectionAddresses.Transport, ToConnectionAddresses.LocalEndPoint, TransactionId);

			for (int i = 0; i < reader.Count.HeaderCount; i++)
			{
				switch (reader.Headers[i].HeaderName)
				{
					case HeaderNames.From:
					case HeaderNames.To:
					case HeaderNames.CallId:
						writer.WriteHeader(reader, i);
						break;
				}
			}

			writer.WriteMaxForwards(70);
			writer.WriteCseq(reader.CSeq.Value, method);
			writer.WriteContentLength(0);

			writer.WriteCustomHeaders();
			writer.WriteCRLF();
		}
Beispiel #28
0
		public void SendRequest(ConnectionAddresses connectionAddresses, SipMessageWriter writer, int transactionId)
		{
			TransactionUser.SendRequest(Index, connectionAddresses, transactionId, writer, 0);
		}
Beispiel #29
0
		private void SendNotify(Dialog dialog, int expires, PresenceDocument document)
		{
			int transactionId = GetTransactionId(Methods.Notifym);

			var writer = new SipMessageWriter();

			writer.WriteRequestLine(Methods.Notifym, dialog.RemoteUri);
			writer.WriteVia(dialog.Transport, dialog.LocalEndPoint, transactionId);
			writer.WriteFrom(dialog.LocalUri, dialog.LocalTag);
			writer.WriteTo(dialog.RemoteUri, dialog.RemoteTag);
			writer.WriteCallId(dialog.CallId);
			writer.WriteEventPresence();
			writer.WriteSubscriptionState(expires);
			writer.WriteMaxForwards(70);
			writer.WriteCseq(dialog.GetNextLocalCseq(), Methods.Notifym);
			writer.WriteContact(dialog.LocalEndPoint, dialog.Transport);

			if (document != null)
			{
				writer.WriteContentType(application, pidfXml);
				//writer.WriteContentLength();
				//writer.WriteCRLF();

				//writer.RewriteContentLength(
				//    document.CopyTo((length) => writer.GetBytesForCustomWrite(length)));

				document.WriteLenghtAndContent(writer);
			}
			else
			{
				writer.WriteContentLength(0);
				writer.WriteCRLF();
			}

			notifyProducer.SendRequest(dialog.Transport, dialog.LocalEndPoint,
				dialog.RemoteEndPoint, ServerAsyncEventArgs.AnyConnectionId, writer, transactionId);
		}
		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]++;
		}