private void Initialise(List<SIPContactHeader> contact, SIPFromHeader from, SIPToHeader to, int cseq, string callId) { if (from == null) { throw new ApplicationException("The From header cannot be empty when creating a new SIP header."); } if (to == null) { throw new ApplicationException("The To header cannot be empty when creating a new SIP header."); } if (callId == null || callId.Trim().Length == 0) { throw new ApplicationException("The CallId header cannot be empty when creating a new SIP header."); } From = from; To = to; Contact = contact; CallId = callId; if (cseq > 0 && cseq < Int32.MaxValue) { CSeq = cseq; } else { CSeq = DEFAULT_CSEQ; } }
public static SIPToHeader ParseToHeader(string toHeaderStr) { try { SIPToHeader toHeader = new SIPToHeader(); toHeader.m_userField = SIPUserField.ParseSIPUserField(toHeaderStr); return toHeader; } catch (ArgumentException argExcp) { throw new SIPValidationException(SIPValidationFieldsEnum.ToHeader, argExcp.Message); } catch { throw new SIPValidationException(SIPValidationFieldsEnum.ToHeader, "The SIP To header was invalid."); } }
public SIPHeader(SIPContactHeader contact, SIPFromHeader from, SIPToHeader to, int cseq, string callId) { List<SIPContactHeader> contactList = new List<SIPContactHeader>(); if (contact != null) { contactList.Add(contact); } Initialise(contactList, from, to, cseq, callId); }
public SIPHeader(List<SIPContactHeader> contactList, SIPFromHeader from, SIPToHeader to, int cseq, string callId) { Initialise(contactList, from, to, cseq, callId); }
/// <summary> /// Used to create a SIP response when it was not possible to parse the incoming SIP request. /// </summary> public SIPResponse GetResponse(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPResponseStatusCodesEnum responseCode, string reasonPhrase) { try { if (localSIPEndPoint == null) { localSIPEndPoint = GetDefaultSIPEndPoint(); } SIPResponse response = new SIPResponse(responseCode, reasonPhrase, localSIPEndPoint); SIPSchemesEnum sipScheme = (localSIPEndPoint.Protocol == SIPProtocolsEnum.tls) ? SIPSchemesEnum.sips : SIPSchemesEnum.sip; SIPFromHeader from = new SIPFromHeader(null, new SIPURI(sipScheme, localSIPEndPoint), null); SIPToHeader to = new SIPToHeader(null, new SIPURI(sipScheme, localSIPEndPoint), null); int cSeq = 1; string callId = CallProperties.CreateNewCallId(); response.Header = new SIPHeader(from, to, cSeq, callId); response.Header.CSeqMethod = SIPMethodsEnum.NONE; response.Header.Vias.PushViaHeader(new SIPViaHeader(new SIPEndPoint(localSIPEndPoint.Protocol, remoteEndPoint.GetIPEndPoint()), CallProperties.CreateBranchId())); response.Header.MaxForwards = Int32.MinValue; response.Header.Allow = ALLOWED_SIP_METHODS; return response; } catch (Exception excp) { logger.Error("Exception SIPTransport GetResponse. " + excp.Message); throw; } }
public SIPHeader(SIPFromHeader from, SIPToHeader to, int cseq, string callId) { Initialise(null, from, to, cseq, callId); }
public SIPRequest GetRequest(SIPMethodsEnum method, SIPURI uri, SIPToHeader to, SIPEndPoint localSIPEndPoint) { if (localSIPEndPoint == null) { localSIPEndPoint = GetDefaultSIPEndPoint(); } SIPRequest request = new SIPRequest(method, uri); request.LocalSIPEndPoint = localSIPEndPoint; SIPContactHeader contactHeader = new SIPContactHeader(null, new SIPURI(SIPSchemesEnum.sip, localSIPEndPoint)); SIPFromHeader fromHeader = new SIPFromHeader(null, contactHeader.ContactURI, CallProperties.CreateNewTag()); SIPHeader header = new SIPHeader(contactHeader, fromHeader, to, 1, CallProperties.CreateNewCallId()); request.Header = header; header.CSeqMethod = method; header.Allow = ALLOWED_SIP_METHODS; SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint, CallProperties.CreateBranchId()); header.Vias.PushViaHeader(viaHeader); return request; }
private SIPRequest GetRequest(SIPMethodsEnum method) { try { SIPURI uri = SIPURI.ParseSIPURIRelaxed(m_callDescriptor.Uri); SIPRequest request = new SIPRequest(method, uri); SIPFromHeader fromHeader = m_callDescriptor.GetFromHeader(); fromHeader.FromTag = CallProperties.CreateNewTag(); SIPToHeader toHeader = new SIPToHeader(null, uri, null); int cseq = Crypto.GetRandomInt(10000, 20000); SIPHeader header = new SIPHeader(fromHeader, toHeader, cseq, CallProperties.CreateNewCallId()); header.CSeqMethod = method; header.UserAgent = m_userAgent; request.Header = header; SIPViaHeader viaHeader = new SIPViaHeader(m_sipTransport.GetDefaultSIPEndPoint(), CallProperties.CreateBranchId()); request.Header.Vias.PushViaHeader(viaHeader); try { if (m_callDescriptor.CustomHeaders != null && m_callDescriptor.CustomHeaders.Count > 0) { foreach (string customHeader in m_callDescriptor.CustomHeaders) { if (customHeader.IsNullOrBlank()) { continue; } else if (customHeader.Trim().StartsWith(SIPHeaders.SIP_HEADER_USERAGENT)) { request.Header.UserAgent = customHeader.Substring(customHeader.IndexOf(":") + 1).Trim(); } else { request.Header.UnknownHeaders.Add(customHeader); } } } } catch (Exception excp) { logger.Error("Exception Parsing CustomHeader for SIPNonInviteClientUserAgent GetRequest. " + excp.Message + m_callDescriptor.CustomHeaders); } if (!m_callDescriptor.Content.IsNullOrBlank()) { request.Body = m_callDescriptor.Content; request.Header.ContentType = m_callDescriptor.ContentType; request.Header.ContentLength = request.Body.Length; } return request; } catch (Exception excp) { logger.Error("Exception SIPNonInviteClientUserAgent GetRequest. " + excp.Message); throw excp; } }
private SIPRequest GetOptionsRequest(SIPURI serverURI, int cseq, IPEndPoint contact) { SIPRequest optionsRequest = new SIPRequest(SIPMethodsEnum.OPTIONS, serverURI); SIPFromHeader fromHeader = new SIPFromHeader(null, SIPURI.ParseSIPURI("sip:" + contact.ToString()), null); SIPToHeader toHeader = new SIPToHeader(null, serverURI, null); string callId = CallProperties.CreateNewCallId(); string branchId = CallProperties.CreateBranchId(); SIPHeader header = new SIPHeader(fromHeader, toHeader, cseq, callId); header.CSeqMethod = SIPMethodsEnum.OPTIONS; header.MaxForwards = 0; SIPViaHeader viaHeader = new SIPViaHeader(contact.Address.ToString(), contact.Port, branchId); header.Vias.PushViaHeader(viaHeader); optionsRequest.Header = header; return optionsRequest; }
private SIPRequest GetRegistrationRequest(SIPProvider sipProvider, SIPProviderBinding binding, SIPEndPoint localSIPEndPoint, int expiry, SIPEndPoint registrarEndPoint) { try { if (!binding.BindingSIPURI.Parameters.Has(m_regAgentContactId)) { binding.BindingSIPURI.Parameters.Set(m_regAgentContactId, Crypto.GetRandomString(6)); } string realm = binding.RegistrarRealm; SIPURI registerURI = SIPURI.ParseSIPURIRelaxed(realm); SIPURI regUserURI = SIPURI.ParseSIPURIRelaxed(sipProvider.ProviderUsername + "@" + realm); SIPFromHeader fromHeader = new SIPFromHeader(null, regUserURI, CallProperties.CreateNewTag()); SIPToHeader toHeader = new SIPToHeader(null, regUserURI, null); SIPContactHeader contactHeader = new SIPContactHeader(null, binding.BindingSIPURI); //contactHeader.Expires = binding.BindingExpiry; string callId = binding.Id.ToString(); int cseq = ++binding.CSeq; SIPRequest registerRequest = new SIPRequest(SIPMethodsEnum.REGISTER, registerURI); registerRequest.LocalSIPEndPoint = localSIPEndPoint; SIPHeader header = new SIPHeader(contactHeader, fromHeader, toHeader, cseq, callId); header.CSeqMethod = SIPMethodsEnum.REGISTER; header.UserAgent = m_userAgentString; header.Expires = binding.BindingExpiry; SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint, CallProperties.CreateBranchId()); header.Vias.PushViaHeader(viaHeader); SIPRoute registrarRoute = new SIPRoute(new SIPURI(binding.RegistrarServer.Scheme, registrarEndPoint), true); header.Routes.PushRoute(registrarRoute); if (sipProvider != null && !sipProvider.CustomHeaders.IsNullOrBlank()) { string[] customerHeadersList = sipProvider.CustomHeaders.Split(SIPProvider.CUSTOM_HEADERS_SEPARATOR); if (customerHeadersList != null && customerHeadersList.Length > 0) { foreach (string customHeader in customerHeadersList) { if (customHeader.IndexOf(':') == -1) { logger.Debug("Skipping custom header due to missing colon, " + customHeader + "."); continue; } else { string headerName = customHeader.Substring(0, customHeader.IndexOf(':')); if (headerName != null && Regex.Match(headerName.Trim(), "(Via|From|To|Contact|CSeq|Call-ID|Max-Forwards|Content)", RegexOptions.IgnoreCase).Success) { logger.Debug("Skipping custom header due to an non-permitted string in header name, " + customHeader + "."); continue; } else { if (headerName == SIPConstants.SIP_USERAGENT_STRING) { header.UserAgent = customHeader.Substring(customHeader.IndexOf(':') + 1); } else { header.UnknownHeaders.Add(customHeader.Trim()); } } } } } } registerRequest.Header = header; return registerRequest; } catch (Exception excp) { logger.Error("Exception GetRegistrationRequest. " + excp.Message); throw excp; } }
public SIPRequest GetRequest(SIPMethodsEnum method, SIPURI uri, SIPToHeader to, SIPEndPoint localSIPEndPoint) { if (localSIPEndPoint == null) { localSIPEndPoint = GetDefaultSIPEndPoint(); } SIPRequest request = new SIPRequest(method, uri); request.LocalSIPEndPoint = localSIPEndPoint; SIPContactHeader contactHeader = new SIPContactHeader(null, new SIPURI(SIPSchemesEnum.sip, localSIPEndPoint)); if (!String.IsNullOrWhiteSpace(m_contactGruu)) { contactHeader.ContactURI.Parameters.Set("gr", m_contactGruu); } SIPFromHeader fromHeader = new SIPFromHeader(null, contactHeader.ContactURI, CallProperties.CreateNewTag()); SIPHeader header = new SIPHeader(contactHeader, fromHeader, to, 1, CallProperties.CreateNewCallId()); request.Header = header; header.CSeqMethod = method; header.Allow = ALLOWED_SIP_METHODS; if (m_serviceRoute != null) header.Routes.AddBottomRoute(m_serviceRoute); SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint, CallProperties.CreateBranchId()); header.Vias.PushViaHeader(viaHeader); return request; }