public static bool AreEqual(SIPURI uri1, SIPURI uri2) { return(uri1 == uri2); }
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 SIPURI ParseSIPURI(string uri) { try { SIPURI sipURI = new SIPURI(); if (uri == null || uri.Trim().Length == 0) { throw new SIPValidationException(SIPValidationFieldsEnum.URI, "A SIP URI cannot be parsed from an empty string."); } else { if (uri == m_sipRegisterRemoveAll) { sipURI.Host = m_sipRegisterRemoveAll; } else { int colonPosn = uri.IndexOf(SCHEME_ADDR_SEPARATOR); if (colonPosn == -1) { throw new SIPValidationException(SIPValidationFieldsEnum.URI, "SIP URI did not contain compulsory colon"); } else { try { sipURI.Scheme = SIPSchemesType.GetSchemeType(uri.Substring(0, colonPosn)); } catch { throw new SIPValidationException(SIPValidationFieldsEnum.URI, SIPResponseStatusCodesEnum.UnsupportedURIScheme, "SIP scheme " + uri.Substring(0, colonPosn) + " was not understood"); } string uriHostPortion = uri.Substring(colonPosn + 1); int ampPosn = uriHostPortion.IndexOf(USER_HOST_SEPARATOR); int paramHeaderPosn = -1; if (ampPosn != -1) { paramHeaderPosn = uriHostPortion.IndexOfAny(new char[] { PARAM_TAG_DELIMITER, HEADER_START_DELIMITER }, ampPosn); } else { // Host only SIP URI. paramHeaderPosn = uriHostPortion.IndexOfAny(new char[] { PARAM_TAG_DELIMITER, HEADER_START_DELIMITER }); } if (ampPosn != -1 && paramHeaderPosn != -1) { sipURI.User = uriHostPortion.Substring(0, ampPosn); sipURI.Host = uriHostPortion.Substring(ampPosn + 1, paramHeaderPosn - ampPosn - 1); string paramsAndHeaders = uriHostPortion.Substring(paramHeaderPosn); sipURI.ParseParamsAndHeaders(paramsAndHeaders); } else if (ampPosn == -1 && paramHeaderPosn == 0) { throw new SIPValidationException(SIPValidationFieldsEnum.URI, "No Host portion in SIP URI"); } else if (ampPosn == -1 && paramHeaderPosn != -1) { sipURI.Host = uriHostPortion.Substring(0, paramHeaderPosn); string paramsAndHeaders = uriHostPortion.Substring(paramHeaderPosn); sipURI.ParseParamsAndHeaders(paramsAndHeaders); } else if (ampPosn != -1) { sipURI.User = uriHostPortion.Substring(0, ampPosn); sipURI.Host = uriHostPortion.Substring(ampPosn + 1, uriHostPortion.Length - ampPosn - 1); } else { sipURI.Host = uriHostPortion; } if (sipURI.Host.IndexOfAny(m_invalidSIPHostChars) != -1) { throw new SIPValidationException(SIPValidationFieldsEnum.URI, "The SIP URI host portion contained an invalid character."); } } } return(sipURI); } } catch (SIPValidationException) { throw; } catch (Exception excp) { logger.Error("Exception ParseSIPURI (URI=" + uri + "). " + excp.Message); throw new SIPValidationException(SIPValidationFieldsEnum.URI, "Unknown error parsing SIP URI."); } }
public SIPEventDialogInfo(int version, SIPEventDialogInfoStateEnum state, SIPURI entity) { Version = version; State = state; Entity = entity.CopyOf(); }
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("-----------------------------------------"); }
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 SIPEventPresence(SIPURI entity) { Entity = entity.CopyOf(); }
public static SIPDNSLookupResult Resolve(SIPURI sipURI, bool async) { // This assumes the input SIP URI has an IP address as the host! return(new SIPDNSLookupResult(sipURI, new SIPEndPoint(IPSocket.ParseSocketString(sipURI.Host)))); }
private SIPProtocolsEnum GetRemoteTargetProtocol() { SIPURI dstURI = (RouteSet == null) ? RemoteTarget : RouteSet.TopRoute.URI; return(dstURI.Protocol); }
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 bool Pending; // If an aysnc lookup request is made this will be set to true if no immediate result is available. public SIPDNSLookupResult(SIPURI uri) { URI = uri; }
public SIPDNSLookupResult(SIPURI uri, string lookupError) { URI = uri; LookupError = lookupError; }