public void AckRecognitionUnitTest() { SIPTransport clientTransport = null; SIPTransport serverTransport = null; try { SIPTransactionEngine clientEngine = new SIPTransactionEngine(); // Client side of the INVITE. SIPEndPoint clientEndPoint = new SIPEndPoint(SIPProtocolsEnum.udp, new IPEndPoint(IPAddress.Loopback, 12013)); clientTransport = new SIPTransport(MockSIPDNSManager.Resolve, clientEngine, new SIPUDPChannel(clientEndPoint.GetIPEndPoint()), false); SetTransportTraceEvents(clientTransport); SIPTransactionEngine serverEngine = new SIPTransactionEngine(); // Server side of the INVITE. UASInviteTransaction serverTransaction = null; SIPEndPoint serverEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 12014)); serverTransport = new SIPTransport(MockSIPDNSManager.Resolve, serverEngine, new SIPUDPChannel(serverEndPoint.GetIPEndPoint()), false); SetTransportTraceEvents(serverTransport); serverTransport.SIPTransportRequestReceived += (localEndPoint, remoteEndPoint, sipRequest) => { Console.WriteLine("Server Transport Request In: " + sipRequest.Method + "."); serverTransaction = serverTransport.CreateUASTransaction(sipRequest, remoteEndPoint, localEndPoint, null); SetTransactionTraceEvents(serverTransaction); serverTransaction.GotRequest(localEndPoint, remoteEndPoint, sipRequest); }; SIPURI dummyURI = SIPURI.ParseSIPURI("sip:dummy@" + serverEndPoint); SIPRequest inviteRequest = GetDummyINVITERequest(dummyURI); inviteRequest.LocalSIPEndPoint = clientTransport.GetDefaultTransportContact(SIPProtocolsEnum.udp); // Send the invite to the server side. UACInviteTransaction clientTransaction = new UACInviteTransaction(clientTransport, inviteRequest, serverEndPoint, clientEndPoint, null); SetTransactionTraceEvents(clientTransaction); clientEngine.AddTransaction(clientTransaction); clientTransaction.SendInviteRequest(serverEndPoint, inviteRequest); Thread.Sleep(500); Assert.IsTrue(clientTransaction.TransactionState == SIPTransactionStatesEnum.Completed, "Client transaction in incorrect state."); Assert.IsTrue(serverTransaction.TransactionState == SIPTransactionStatesEnum.Confirmed, "Server transaction in incorrect state."); } finally { if (clientTransport != null) { clientTransport.Shutdown(); } if (serverTransport != null) { serverTransport.Shutdown(); } } }
public void GetAsXMLStringUnitTest() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); SIPEventPresence presence = new SIPEventPresence(SIPURI.ParseSIPURI("sip:[email protected]")); presence.Tuples.Add(new SIPEventPresenceTuple("1234", SIPEventPresenceStateEnum.open, SIPURI.ParseSIPURIRelaxed("*****@*****.**"), 0.8M)); Console.WriteLine(presence.ToXMLText()); Console.WriteLine("-----------------------------------------"); }
public static SIPRequest ParseSIPRequest(SIPMessage sipMessage) { string uriStr = null; try { SIPRequest sipRequest = new SIPRequest(); sipRequest.LocalSIPEndPoint = sipMessage.LocalSIPEndPoint; sipRequest.RemoteSIPEndPoint = sipMessage.RemoteSIPEndPoint; string statusLine = sipMessage.FirstLine; int firstSpacePosn = statusLine.IndexOf(" "); string method = statusLine.Substring(0, firstSpacePosn).Trim(); sipRequest.Method = SIPMethods.GetMethod(method); if (sipRequest.Method == SIPMethodsEnum.UNKNOWN) { sipRequest.UnknownMethod = method; logger.Warn("Unknown SIP method received " + sipRequest.UnknownMethod + "."); } statusLine = statusLine.Substring(firstSpacePosn).Trim(); int secondSpacePosn = statusLine.IndexOf(" "); if (secondSpacePosn != -1) { uriStr = statusLine.Substring(0, secondSpacePosn); sipRequest.URI = SIPURI.ParseSIPURI(uriStr); sipRequest.SIPVersion = statusLine.Substring(secondSpacePosn, statusLine.Length - secondSpacePosn).Trim(); sipRequest.Header = SIPHeader.ParseSIPHeaders(sipMessage.SIPHeaders); sipRequest.Body = sipMessage.Body; return(sipRequest); } else { throw new SIPValidationException(SIPValidationFieldsEnum.Request, "URI was missing on Request."); } } catch (SIPValidationException) { throw; } catch (Exception excp) { logger.Error("Exception parsing SIP Request. " + excp.Message); logger.Error(sipMessage.RawMessage); throw new SIPValidationException(SIPValidationFieldsEnum.Request, "Unknown error parsing SIP Request"); } }
public void DuplicateTransactionUnitTest() { SIPTransactionEngine clientEngine = new SIPTransactionEngine(); SIPURI dummyURI = SIPURI.ParseSIPURI("sip:[email protected]"); SIPRequest inviteRequest = GetDummyINVITERequest(dummyURI); SIPEndPoint dummySIPEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 1234)); UACInviteTransaction clientTransaction = new UACInviteTransaction(new SIPTransport(MockSIPDNSManager.Resolve, null), inviteRequest, dummySIPEndPoint, dummySIPEndPoint, null); clientEngine.AddTransaction(clientTransaction); clientEngine.AddTransaction(clientTransaction); }
public static SIPEventPresenceTuple Parse(XElement tupleElement) { XNamespace ns = m_pidfXMLNS; SIPEventPresenceTuple tuple = new SIPEventPresenceTuple(); tuple.ID = tupleElement.Attribute("id").Value; tuple.Status = (SIPEventPresenceStateEnum)Enum.Parse(typeof(SIPEventPresenceStateEnum), tupleElement.Element(ns + "status").Element(ns + "basic").Value, true); tuple.ContactURI = (tupleElement.Element(ns + "contact") != null) ? SIPURI.ParseSIPURI(tupleElement.Element(ns + "contact").Value) : null; tuple.ContactPriority = (tuple.ContactURI != null && tupleElement.Element(ns + "contact").Attribute("priority") != null) ? Decimal.Parse(tupleElement.Element(ns + "contact").Attribute("priority").Value) : Decimal.Zero; tuple.AvatarURL = (tuple.ContactURI != null && tupleElement.Element(ns + "contact").Attribute("avatarurl") != null) ? tupleElement.Element(ns + "contact").Attribute("avatarurl").Value : null; return tuple; }
public SIPRequest(SIPMethodsEnum method, string uri) { try { Method = method; URI = SIPURI.ParseSIPURI(uri); SIPVersion = m_sipFullVersion; } catch (Exception excp) { logger.Error("Exception SIPRequest ctor. " + excp.Message); throw; } }
public override void Load(string presenceXMLStr) { try { XNamespace ns = m_pidfXMLNS; XDocument presenceDoc = XDocument.Parse(presenceXMLStr); Entity = SIPURI.ParseSIPURI(((XElement)presenceDoc.FirstNode).Attribute("entity").Value); var tupleElements = presenceDoc.Root.Elements(ns + "tuple"); foreach (XElement tupleElement in tupleElements) { Tuples.Add(SIPEventPresenceTuple.Parse(tupleElement)); } } catch (Exception excp) { logger.Error("Exception SIPEventPresence Load. " + excp.Message); throw; } }
public static SIPURI ParseSIPURIRelaxed(string partialURI) { if (partialURI == null || partialURI.Trim().Length == 0) { return(null); } else { string regexSchemePattern = "^(" + SIPSchemesEnum.sip + "|" + SIPSchemesEnum.sips + "):"; if (Regex.Match(partialURI, regexSchemePattern + @"\S+").Success) { // The partial uri is already valid. return(SIPURI.ParseSIPURI(partialURI)); } else { // The partial URI is missing the scheme. return(SIPURI.ParseSIPURI(m_defaultSIPScheme.ToString() + SCHEME_ADDR_SEPARATOR.ToString() + partialURI)); } } }
public override void Load(string dialogInfoXMLStr) { try { XNamespace ns = m_dialogXMLNS; XDocument eventDialogDoc = XDocument.Parse(dialogInfoXMLStr); Version = Convert.ToInt32(((XElement)eventDialogDoc.FirstNode).Attribute("version").Value); State = (SIPEventDialogInfoStateEnum)Enum.Parse(typeof(SIPEventDialogInfoStateEnum), ((XElement)eventDialogDoc.FirstNode).Attribute("state").Value, true); Entity = SIPURI.ParseSIPURI(((XElement)eventDialogDoc.FirstNode).Attribute("entity").Value); var dialogElements = eventDialogDoc.Root.Elements(ns + "dialog"); foreach (XElement dialogElement in dialogElements) { DialogItems.Add(SIPEventDialog.Parse(dialogElement)); } } catch (Exception excp) { logger.Error("Exception SIPEventDialogInfo Ctor. " + excp.Message); throw; } }
public void ParseFromXMLStringDialogWithParticipantsUnitTest() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); string eventDialogInfoStr = "<?xml version='1.0' encoding='utf-16'?>" + "<dialog-info version='1' state='full' entity='sip:[email protected]' xmlns='urn:ietf:params:xml:ns:dialog-info'>" + " <dialog id='as7d900as8' call-id='a84b4c76e66710' local-tag='1928301774' direction='initiator'>" + " <state event='remote-bye' code='486'>terminated</state>" + " <duration>13</duration>" + " <local>" + " <identity>sip:[email protected];user=phone</identity>" + " <cseq>2</cseq>" + " </local>" + " <remote>" + " <identity display-name='Joe Bloggs'>sip:[email protected]</identity>" + " <target uri='sip:[email protected]:5070' />" + " <cseq>1</cseq>" + " </remote>" + " </dialog>" + "</dialog-info>"; SIPEventDialogInfo dialogInfo = SIPEventDialogInfo.Parse(eventDialogInfoStr); Assert.NotNull(dialogInfo.DialogItems[0].LocalParticipant, "The parsed event dialog local participant was not correct."); Assert.NotNull(dialogInfo.DialogItems[0].RemoteParticipant, "The parsed event dialog remote participant was not correct."); Assert.IsTrue(dialogInfo.DialogItems[0].LocalParticipant.URI == SIPURI.ParseSIPURI("sip:[email protected];user=phone"), "The local participant URI was incorrect."); Assert.IsTrue(dialogInfo.DialogItems[0].LocalParticipant.CSeq == 2, "The local participant CSeq was incorrect."); Assert.IsTrue(dialogInfo.DialogItems[0].RemoteParticipant.URI == SIPURI.ParseSIPURI("sip:[email protected]"), "The remote participant URI was incorrect."); Assert.IsTrue(dialogInfo.DialogItems[0].RemoteParticipant.DisplayName == "Joe Bloggs", "The remote participant display name was incorrect."); Assert.IsTrue(dialogInfo.DialogItems[0].RemoteParticipant.TargetURI == SIPURI.ParseSIPURI("sip:[email protected]:5070"), "The remote participant target URI was incorrect."); Assert.IsTrue(dialogInfo.DialogItems[0].RemoteParticipant.CSeq == 1, "The remote participant CSeq was incorrect."); Console.WriteLine(dialogInfo.ToXMLText()); Console.WriteLine("-----------------------------------------"); }
public static SIPUserField ParseSIPUserField(string userFieldStr) { if (userFieldStr.IsNullOrBlank()) { throw new ArgumentException("A SIPUserField cannot be parsed from an empty string."); } SIPUserField userField = new SIPUserField(); string trimUserField = userFieldStr.Trim(); int position = trimUserField.IndexOf('<'); if (position == -1) { // Treat the field as a URI only, except that all parameters are Header parameters and not URI parameters // (RFC3261 section 20.39 which refers to 20.10 for parsing rules). string uriStr = trimUserField; int paramDelimPosn = trimUserField.IndexOf(PARAM_TAG_DELIMITER); if (paramDelimPosn != -1) { string paramStr = trimUserField.Substring(paramDelimPosn + 1).Trim(); userField.Parameters = new SIPParameters(paramStr, PARAM_TAG_DELIMITER); uriStr = trimUserField.Substring(0, paramDelimPosn); } userField.URI = SIPURI.ParseSIPURI(uriStr); } else { if (position > 0) { userField.Name = trimUserField.Substring(0, position).Trim().Trim('"'); trimUserField = trimUserField.Substring(position, trimUserField.Length - position); } int addrSpecLen = trimUserField.Length; position = trimUserField.IndexOf('>'); if (position != -1) { addrSpecLen = trimUserField.Length - 1; if (position != -1) { addrSpecLen = position - 1; string paramStr = trimUserField.Substring(position + 1).Trim(); userField.Parameters = new SIPParameters(paramStr, PARAM_TAG_DELIMITER); } string addrSpec = trimUserField.Substring(1, addrSpecLen); userField.URI = SIPURI.ParseSIPURI(addrSpec); } else { throw new SIPValidationException(SIPValidationFieldsEnum.ContactHeader, "A SIPUserField was missing the right quote, " + userFieldStr + "."); } } return(userField); }
public void GetAsXMLStringUnitTest() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); SIPEventDialogInfo dialogInfo = new SIPEventDialogInfo(0, SIPEventDialogInfoStateEnum.full, SIPURI.ParseSIPURI("sip:[email protected]")); dialogInfo.DialogItems.Add(new SIPEventDialog("abcde", "terminated", 487, SIPEventDialogStateEvent.Cancelled, 2)); Console.WriteLine(dialogInfo.ToXMLText()); Console.WriteLine("-----------------------------------------"); }