public void test_codec_registration() { var userName = "******"; DeleteExisting(userName); // Add new var sipMessage = new KamailioRegistrationMessage() { Ip = GetRandomLocationIpAddress(), Port = 5060, UnixTimeStamp = GetUnixTimeStamp(DateTime.Now), Sip = new SipUri(userName), UserAgent = "ProntoNet LC v6.8.1", Username = userName, ToDisplayName = "Test", Expires = 60 }; // Assert var result = _sipMessageManager.RegisterSip(sipMessage); Assert.AreEqual(KamailioMessageChangeStatus.CodecAdded, result.ChangeStatus); // Update only timestamp. Should return nothing changed. // Act sipMessage.UnixTimeStamp = GetUnixTimeStamp(DateTime.Now.AddSeconds(1)); // Assert result = _sipMessageManager.RegisterSip(sipMessage); Assert.AreEqual(KamailioMessageChangeStatus.NothingChanged, result.ChangeStatus); // Update location. Should return status updated. // Act sipMessage.Ip = GetRandomLocationIpAddress(); // Assert result = _sipMessageManager.RegisterSip(sipMessage); Assert.AreEqual(KamailioMessageChangeStatus.CodecUpdated, result.ChangeStatus); // Only timestamp sipMessage.UnixTimeStamp = GetUnixTimeStamp(DateTime.Now.AddSeconds(2)); result = _sipMessageManager.RegisterSip(sipMessage); Assert.AreEqual(KamailioMessageChangeStatus.NothingChanged, result.ChangeStatus); // Update display name. Should return status updated. // Act sipMessage.ToDisplayName = "New display name"; // Assert result = _sipMessageManager.RegisterSip(sipMessage); Assert.AreEqual(KamailioMessageChangeStatus.CodecUpdated, result.ChangeStatus); // Update user agent sipMessage.UserAgent = "Quantum/3.4.3"; result = _sipMessageManager.RegisterSip(sipMessage); Assert.AreEqual(KamailioMessageChangeStatus.CodecUpdated, result.ChangeStatus); // Only timestamp sipMessage.UnixTimeStamp = GetUnixTimeStamp(DateTime.Now.AddSeconds(3)); result = _sipMessageManager.RegisterSip(sipMessage); Assert.AreEqual(KamailioMessageChangeStatus.NothingChanged, result.ChangeStatus); }
public KamailioMessageHandlerResult RegisterSip(KamailioRegistrationMessage sipMessage) { var sip = new RegisteredSip { IP = sipMessage.Ip, Port = sipMessage.Port, ServerTimeStamp = sipMessage.UnixTimeStamp, SIP = sipMessage.Sip.UserAtHost, UserAgentHead = sipMessage.UserAgent, Username = sipMessage.Username, DisplayName = sipMessage.ToDisplayName, Expires = sipMessage.Expires }; return(_sipRepository.UpdateRegisteredSip(sip)); }
private KamailioRegistrationMessage ParseRegistration(KamailioData kamailioData) { var registration = new KamailioRegistrationMessage() { Ip = kamailioData.GetField("si"), Port = ParseInt(kamailioData.GetField("sp")), UnixTimeStamp = ParseLong(kamailioData.GetField("TS")), Sip = new SipUri(kamailioData.GetField("fu")), UserAgent = kamailioData.GetField("ua"), Username = kamailioData.GetField("Au"), ToDisplayName = ParseDisplayName(kamailioData.GetField("tn")), Expires = ParseInt(kamailioData.GetField("Expires"), DefaultExpireValue), // Används inte ToUsername = kamailioData.GetField("rU"), RequestedSip = new SipUri(kamailioData.GetField("ru")), ReceivedIp = kamailioData.GetField("Ri"), ReceivedPort = ParseInt(kamailioData.GetField("Rp")), FromDisplayName = ParseDisplayName(kamailioData.GetField("fn")), CallId = kamailioData.GetField("ci"), }; return(registration); }