Esempio n. 1
0
		public TrunkDialogProxie(int transactionId, Trunk trunk, int tag, Dialog dialog1)
			: base(transactionId)
		{
			this.trunk = trunk;
			this.tag = tag;
			this.dialog1 = dialog1;
		}
Esempio n. 2
0
		public Dialog Create(SipMessageReader message, int localTag, ConnectionAddresses connectionAddresses)
		{
			var dialog = new Dialog(message, localTag, connectionAddresses);

			dictionary.Add(dialog.Id, dialog);

			return dialog;
		}
Esempio n. 3
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);
		}
Esempio n. 4
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);
		}
Esempio n. 5
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);
		}
Esempio n. 6
0
		public void AddDialog2(int tag, Dialog dialog)
		{
			lock (sync)
			{
				dialogs2.Remove(tag);
				dialogs2.Add(tag, dialog);
			}
		}
Esempio n. 7
0
			public Dialogs(Dialog internal1, Dialog external)
			{
				Internal = internal1;
				External = external;
			}
Esempio n. 8
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);
        }
Esempio n. 9
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);
		}
Esempio n. 10
0
		private void SendNotify(Dialog dialog, int expires)
		{
			int transactionId = GetTransactionId(Methods.Notifym);

			var writer = GetWriter();

			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.WriteDate(DateTime.UtcNow);
			writer.WriteCallId(dialog.CallId);
			writer.WriteCseq(dialog.GetNextLocalCseq(), Methods.Notifym);
			writer.WriteContact(dialog.LocalEndPoint, dialog.Transport);
			//Event: message-summary
			//writer.WriteEvent();
			writer.WriteSubscriptionState(expires);
			writer.WriteMaxForwards(70);
			writer.WriteContentType(contentType);
			writer.WriteContentLength(content.Length);
			writer.WriteCRLF();

			writer.Write(content);

			notifyProducer.SendRequest(dialog.ConnectionAddresses, writer, transactionId);
		}