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
 private void TrunkManager_TrunkAdded(Trunk trunk)
 {
     if (trunk.State != Trunk.States.Error)
     {
         RegisterTrunk(trunk);
     }
 }
Esempio n. 3
0
		public TrunkDialogProxie(int transactionId, Trunk trunk, int tag, Dialog dialog1)
			: base(transactionId)
		{
			this.trunk = trunk;
			this.tag = tag;
			this.dialog1 = dialog1;
		}
Esempio n. 4
0
        private void SendRegister(Trunk trunk, int expires)
        {
            var writer = GetWriter();

            int transationId = GetTransactionId(Methods.Registerm);

            writer.WriteRequestLine(Methods.Registerm, trunk.RequestUri);
            writer.WriteVia(trunk.Transport, trunk.LocalEndPoint, transationId);
            writer.WriteFrom(trunk.Uri, trunk.Id);
            writer.WriteTo(trunk.Uri);
            writer.WriteCallId(trunk.LocalEndPoint.Address, Interlocked.Increment(ref count));
            writer.WriteCseq(trunk.GetCSeq(Methods.Registerm), Methods.Registerm);
            writer.WriteContact(trunk.LocalEndPoint, trunk.Transport);
            writer.WriteEventRegistration();
            writer.WriteExpires(expires);

            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.RequestUri,
                                                                           Methods.Registerm.ToByteArrayPart(), new ArraySegment <byte>());

                writer.WriteDigestAuthorization(trunk.AuthHeader, trunk.AuthenticationId, trunk.Realm, trunk.Qop, AuthAlgorithms.Md5, trunk.RequestUri,
                                                trunk.Nonce, nc, cnonce, trunk.Opaque, response);
            }

            writer.WriteContentLength(0);
            writer.WriteCRLF();

            registerProducer.SendRequest(trunk.ConnectionAddresses, writer, transationId, trunk.Id);
        }
Esempio n. 5
0
		//public TrunkLocalProxie(int transactionId, ByteArrayPart toUri, ByteArrayPart toTag, LocationService.Binding binding, int fromTag, Trunk trunk)
		public TrunkLocalProxie(int transactionId, Trunk trunk, LocationService.Binding binding)
			: base(transactionId)
		{
			//this.toUri = toUri;
			//this.toTag = toTag;
			//this.tag = fromTag;
			this.trunk = trunk;
			this.binding = binding;
		}
Esempio n. 6
0
        private void OnTrunkAdded(Trunk trunk)
        {
            var method = TrunkAdded;

            if (method != null)
            {
                method(trunk);
            }
        }
Esempio n. 7
0
		public static IProxie Create(int transactionId, Trunk trunk, ByteArrayPart toTag)
		{
			int tag;
			Dialog dialog1 = null;
			if (HexEncoding.TryParseHex8(toTag, out tag))
				dialog1 = trunk.GetDialog1(tag);

			return (dialog1 == null) ? null : new TrunkDialogProxie(transactionId, trunk, tag, dialog1);
		}
Esempio n. 8
0
 //public TrunkLocalProxie(int transactionId, ByteArrayPart toUri, ByteArrayPart toTag, LocationService.Binding binding, int fromTag, Trunk trunk)
 public TrunkLocalProxie(int transactionId, Trunk trunk, LocationService.Binding binding)
     : base(transactionId)
 {
     //this.toUri = toUri;
     //this.toTag = toTag;
     //this.tag = fromTag;
     this.trunk   = trunk;
     this.binding = binding;
 }
Esempio n. 9
0
 private void trunkManager_TrunkUpdated(Trunk trunk)
 {
     if (trunk.State == Trunk.States.Error)
     {
         if (trunk.RegisterAfterErrorTimeout > 0)
         {
             registerTimer.Add(trunk.RegisterAfterErrorTimeout * 1000, trunk.Id);
         }
     }
 }
Esempio n. 10
0
        public void Add(Trunk trunk)
        {
            lock (sync)
            {
                trunk.Changed += Trunk_Changed;

                trunks.Add(trunk);
                OnTrunkAdded(trunk);
            }
        }
Esempio n. 11
0
        public void Add(Trunk trunk)
        {
            lock (sync)
            {
                trunk.Changed += Trunk_Changed;

                trunks.Add(trunk);
                OnTrunkAdded(trunk);
            }
        }
Esempio n. 12
0
        public static IProxie Create(int transactionId, Trunk trunk, ByteArrayPart toTag)
        {
            int    tag;
            Dialog dialog1 = null;

            if (HexEncoding.TryParseHex8(toTag, out tag))
            {
                dialog1 = trunk.GetDialog1(tag);
            }

            return((dialog1 == null) ? null : new TrunkDialogProxie(transactionId, trunk, tag, dialog1));
        }
Esempio n. 13
0
 public void TrunkUpdated(Sip.Server.Trunk trunk)
 {
     if (callback != null)
     {
         try
         {
             callback.VoipProviderUpdated(new WcfVoipProvider(trunk));
         }
         catch
         {
             callback = null;
         }
     }
 }
Esempio n. 14
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);
		}
Esempio n. 15
0
 public static IProxie Create(int transactionId, Trunk trunk)
 {
     return(new LocalTrunkProxie(transactionId, trunk));
 }
Esempio n. 16
0
 private void Trunk_Changed(Trunk trunk)
 {
     OnTrunkUpdated(trunk);
 }
Esempio n. 17
0
 private void OnTrunkRemoved(Trunk trunk)
 {
     var method = TrunkRemoved;
     if (method != null)
         method(trunk);
 }
Esempio n. 18
0
        //private Dialog dialog2;

        public LocalTrunkProxie(int transactionId, Trunk trunk)
            : base(transactionId)
        {
            this.trunk = trunk;
        }
Esempio n. 19
0
 public static IProxie Create(int transactionId, Trunk trunk, LocationService.Binding binding)
 {
     return(new TrunkLocalProxie(transactionId, trunk, binding));
 }
Esempio n. 20
0
		private void SendRegister(Trunk trunk, int expires)
		{
			var writer = GetWriter();

			int transationId = GetTransactionId(Methods.Registerm);

			writer.WriteRequestLine(Methods.Registerm, trunk.RequestUri);
			writer.WriteVia(trunk.Transport, trunk.LocalEndPoint, transationId);
			writer.WriteFrom(trunk.Uri, trunk.Id);
			writer.WriteTo(trunk.Uri);
			writer.WriteCallId(trunk.LocalEndPoint.Address, Interlocked.Increment(ref count));
			writer.WriteCseq(trunk.GetCSeq(Methods.Registerm), Methods.Registerm);
			writer.WriteContact(trunk.LocalEndPoint, trunk.Transport);
			writer.WriteEventRegistration();
			writer.WriteExpires(expires);

			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.RequestUri,
					Methods.Registerm.ToByteArrayPart(), new ArraySegment<byte>());

				writer.WriteDigestAuthorization(trunk.AuthHeader, trunk.AuthenticationId, trunk.Realm, trunk.Qop, AuthAlgorithms.Md5, trunk.RequestUri,
					trunk.Nonce, nc, cnonce, trunk.Opaque, response);
			}

			writer.WriteContentLength(0);
			writer.WriteCRLF();

			registerProducer.SendRequest(trunk.ConnectionAddresses, writer, transationId, trunk.Id);
		}
Esempio n. 21
0
		public static IProxie Create(int transactionId, Trunk trunk, LocationService.Binding binding)
		{
			return new TrunkLocalProxie(transactionId, trunk, binding);
		}
Esempio n. 22
0
 private void TrunkManager_TrunkRemoved(Trunk trunk)
 {
     trunk.State = Trunk.States.Disconnecting;
     SendRegister(trunk, 0);
 }
Esempio n. 23
0
		public static IProxie Create(int transactionId, Trunk trunk)
		{
			return new LocalTrunkProxie(transactionId, trunk);
		}
Esempio n. 24
0
 private void Trunk_Changed(Trunk trunk)
 {
     OnTrunkUpdated(trunk);
 }
Esempio n. 25
0
		private void TrunkManager_TrunkAdded(Trunk trunk)
		{
			if (trunk.State != Trunk.States.Error)
				RegisterTrunk(trunk);
		}
Esempio n. 26
0
		private void TrunkManager_TrunkRemoved(Trunk trunk)
		{
			trunk.State = Trunk.States.Disconnecting;
			SendRegister(trunk, 0);
		}
Esempio n. 27
0
		private void trunkManager_TrunkUpdated(Trunk trunk)
		{
			if (trunk.State == Trunk.States.Error)
				if (trunk.RegisterAfterErrorTimeout > 0)
					registerTimer.Add(trunk.RegisterAfterErrorTimeout * 1000, trunk.Id);
		}
Esempio n. 28
0
		private void RegisterTrunk(Trunk trunk)
		{
			trunk.State = Trunk.States.WaitingDns;

			var match = Regex.Match(trunk.OutgoingProxy, "(?<url>[^:]+)(:(?<port>[0-9]*))?");
			if (match.Success == false)
			{
				trunk.ErrorMessage = @"Invalid outgouing proxy URL";
			}
			else
			{
				var hostname = match.Groups["url"].Value;
				int? port = null;
				if (match.Groups["port"].Success)
					port = int.Parse(match.Groups["port"].Value);

				IPAddress address;
				if (IPAddress.TryParse(hostname, out address))
				{
					trunk.SetServerEndPoint(address, port ?? 5060);
					trunk.State = Trunk.States.Waiting200or401;
					SendRegister(trunk, trunk.RegisterDuration);
				}
				else
				{
					try
					{
						var prefixes = new string[] { @"_sip._tcp.", @"_sip._udp." };

						Transports transport = Transports.None;
						SrvRecord record = null;
						foreach (var prefix in prefixes)
						{
							var request = new DnsQueryRequest();
							var response = request.Resolve(prefix + hostname, NsType.SRV, NsClass.INET, ProtocolType.Udp);

							if (response.Answers.Length > 0)
								record = response.Answers[0] as SrvRecord;

							if (record != null)
							{
								if (prefix.Contains(@"tcp"))
									transport = Transports.Tcp;
								if (prefix.Contains(@"udp"))
									transport = Transports.Udp;
								break;
							}
						}

						if (record == null)
							trunk.ErrorMessage = @"Failed to get SRV record";
						else
						{
							var addresses = Dns.GetHostAddresses(record.HostName);
							if (addresses.Length < 0)
								trunk.ErrorMessage = @"Failed to get DNS A record for " + record.HostName;
							else
							{
								trunk.SetServerEndPoint(transport, addresses[0], port ?? record.Port);
								trunk.State = Trunk.States.Waiting200or401;
								SendRegister(trunk, trunk.RegisterDuration);
							}
						}
					}
					catch (Exception ex)
					{
						trunk.ErrorMessage = ex.Message;
					}
				}
			}
		}
Esempio n. 29
0
        private void RegisterTrunk(Trunk trunk)
        {
            trunk.State = Trunk.States.WaitingDns;

            var match = Regex.Match(trunk.OutgoingProxy, "(?<url>[^:]+)(:(?<port>[0-9]*))?");

            if (match.Success == false)
            {
                trunk.ErrorMessage = @"Invalid outgouing proxy URL";
            }
            else
            {
                var hostname = match.Groups["url"].Value;
                int?port     = null;
                if (match.Groups["port"].Success)
                {
                    port = int.Parse(match.Groups["port"].Value);
                }

                IPAddress address;
                if (IPAddress.TryParse(hostname, out address))
                {
                    trunk.SetServerEndPoint(address, port ?? 5060);
                    trunk.State = Trunk.States.Waiting200or401;
                    SendRegister(trunk, trunk.RegisterDuration);
                }
                else
                {
                    try
                    {
                        var prefixes = new string[] { @"_sip._tcp.", @"_sip._udp." };

                        Transports transport = Transports.None;
                        SrvRecord  record    = null;
                        foreach (var prefix in prefixes)
                        {
                            var request  = new DnsQueryRequest();
                            var response = request.Resolve(prefix + hostname, NsType.SRV, NsClass.INET, ProtocolType.Udp);

                            if (response.Answers.Length > 0)
                            {
                                record = response.Answers[0] as SrvRecord;
                            }

                            if (record != null)
                            {
                                if (prefix.Contains(@"tcp"))
                                {
                                    transport = Transports.Tcp;
                                }
                                if (prefix.Contains(@"udp"))
                                {
                                    transport = Transports.Udp;
                                }
                                break;
                            }
                        }

                        if (record == null)
                        {
                            trunk.ErrorMessage = @"Failed to get SRV record";
                        }
                        else
                        {
                            var addresses = Dns.GetHostAddresses(record.HostName);
                            if (addresses.Length < 0)
                            {
                                trunk.ErrorMessage = @"Failed to get DNS A record for " + record.HostName;
                            }
                            else
                            {
                                trunk.SetServerEndPoint(transport, addresses[0], port ?? record.Port);
                                trunk.State = Trunk.States.Waiting200or401;
                                SendRegister(trunk, trunk.RegisterDuration);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        trunk.ErrorMessage = ex.Message;
                    }
                }
            }
        }
Esempio n. 30
0
		//private Dialog dialog2;

		public LocalTrunkProxie(int transactionId, Trunk trunk)
			: base(transactionId)
		{
			this.trunk = trunk;
		}