/// <summary> /// New transaction ACK requests are for 2xx responses, i.e. INVITE accepted and dialogue being created. /// </summary> /// <remarks> /// From RFC 3261 Chapter 17.1.1.3 - ACK for non-2xx final responses /// /// IMPORTANT: /// an ACK for a non-2xx response will also have the same branch ID as the INVITE whose response it acknowledges. /// /// The ACK request constructed by the client transaction MUST contain /// values for the Call-ID, From, and Request-URI that are equal to the /// values of those header fields in the request passed to the transport /// by the client transaction (call this the "original request"). The To /// header field in the ACK MUST equal the To header field in the /// response being acknowledged, and therefore will usually differ from /// the To header field in the original request by the addition of the /// tag parameter. The ACK MUST contain a single Via header field, and /// this MUST be equal to the top Via header field of the original /// request. The CSeq header field in the ACK MUST contain the same /// value for the sequence number as was present in the original request, /// but the method parameter MUST be equal to "ACK". /// /// If the INVITE request whose response is being acknowledged had Route /// header fields, those header fields MUST appear in the ACK. This is /// to ensure that the ACK can be routed properly through any downstream /// stateless proxies. /// /// From RFC 3261 Chapter 13.2.2.4 - ACK for 2xx final responses /// /// IMPORTANT: /// an ACK for a 2xx final response is a new transaction and has a new branch ID. /// /// The UAC core MUST generate an ACK request for each 2xx received from /// the transaction layer. The header fields of the ACK are constructed /// in the same way as for any request sent within a dialog (see Section /// 12) with the exception of the CSeq and the header fields related to /// authentication. The sequence number of the CSeq header field MUST be /// the same as the INVITE being acknowledged, but the CSeq method MUST /// be ACK. The ACK MUST contain the same credentials as the INVITE. If /// the 2xx contains an offer (based on the rules above), the ACK MUST /// carry an answer in its body. If the offer in the 2xx response is not /// acceptable, the UAC core MUST generate a valid answer in the ACK and /// then send a BYE immediately. /// </remarks> private SIPRequest GetNewTransactionACKRequest(SIPResponse sipResponse, SIPURI ackURI, SIPEndPoint localSIPEndPoint) { SIPRequest ackRequest = new SIPRequest(SIPMethodsEnum.ACK, ackURI.ToString()) { LocalSIPEndPoint = localSIPEndPoint }; SIPHeader header = new SIPHeader(TransactionRequest.Header.From, sipResponse.Header.To, sipResponse.Header.CSeq, sipResponse.Header.CallId) { CSeqMethod = SIPMethodsEnum.ACK, AuthenticationHeader = TransactionRequest.Header.AuthenticationHeader, ProxySendFrom = base.TransactionRequest.Header.ProxySendFrom }; // If the UAS supplies a desired Record-Route list use that first. Otherwise fall back to any Route list used in the original transaction. if (sipResponse.Header.RecordRoutes != null) { header.Routes = sipResponse.Header.RecordRoutes.Reversed(); } else if (base.TransactionRequest.Header.Routes != null) { header.Routes = base.TransactionRequest.Header.Routes; } ackRequest.Header = header; SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint, CallProperties.CreateBranchId()); ackRequest.Header.Vias.PushViaHeader(viaHeader); return(ackRequest); }
private SIPRequest GetAuthenticatedRegistrationRequest(SIPRequest registerRequest, SIPResponse sipResponse) { try { SIPAuthorisationDigest authRequest = sipResponse.Header.AuthenticationHeader.SIPDigest; string username = (m_authUsername != null) ? m_authUsername : m_sipAccountAOR.User; authRequest.SetCredentials(username, m_password, registerRequest.URI.ToString(), SIPMethodsEnum.REGISTER.ToString()); SIPRequest regRequest = registerRequest.Copy(); regRequest.LocalSIPEndPoint = registerRequest.LocalSIPEndPoint; regRequest.Header.Vias.TopViaHeader.Branch = CallProperties.CreateBranchId(); regRequest.Header.From.FromTag = CallProperties.CreateNewTag(); regRequest.Header.To.ToTag = null; regRequest.Header.CSeq = ++m_cseq; regRequest.Header.AuthenticationHeader = new SIPAuthenticationHeader(authRequest); regRequest.Header.AuthenticationHeader.SIPDigest.Response = authRequest.Digest; return(regRequest); } catch (Exception excp) { logger.LogError("Exception GetAuthenticatedRegistrationRequest. " + excp.Message); throw excp; } }
private void ByeServerFinalResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentServer, SIPMonitorEventTypesEnum.DialPlan, "Response " + sipResponse.StatusCode + " " + sipResponse.ReasonPhrase + " for " + sipTransaction.TransactionRequest.URI.ToString() + ".", Owner)); SIPNonInviteTransaction byeTransaction = sipTransaction as SIPNonInviteTransaction; byeTransaction.NonInviteTransactionFinalResponseReceived -= ByeServerFinalResponseReceived; if ((sipResponse.Status == SIPResponseStatusCodesEnum.ProxyAuthenticationRequired || sipResponse.Status == SIPResponseStatusCodesEnum.Unauthorised) && SIPAccount != null) { // Resend BYE with credentials. SIPAuthorisationDigest authRequest = sipResponse.Header.AuthenticationHeader.SIPDigest; SIPURI contactUri = sipResponse.Header.Contact.Any() ? sipResponse.Header.Contact[0].ContactURI : sipResponse.Header.From.FromURI; authRequest.SetCredentials(SIPAccount.SIPUsername, SIPAccount.SIPPassword, contactUri.ToString(), SIPMethodsEnum.BYE.ToString()); SIPRequest authByeRequest = byeTransaction.TransactionRequest; authByeRequest.Header.AuthenticationHeader = new SIPAuthenticationHeader(authRequest); authByeRequest.Header.AuthenticationHeader.SIPDigest.Response = authRequest.Digest; authByeRequest.Header.Vias.TopViaHeader.Branch = CallProperties.CreateBranchId(); authByeRequest.Header.CSeq = authByeRequest.Header.CSeq + 1; SIPNonInviteTransaction bTransaction = m_sipTransport.CreateNonInviteTransaction(authByeRequest, null, localSIPEndPoint, null); bTransaction.SendReliableRequest(); } } catch (Exception excp) { Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.Error, "Exception ByServerFinalResponseReceived. " + excp.Message, Owner)); } }
public void ByeVideoReq() { if (_audioChannel == null) { return; } _audioChannel.Stop(); _audioChannel = null; SIPURI localUri = new SIPURI(_account.SIPPassword, LocalEP.ToHost(), ""); SIPURI remoteUri = new SIPURI(_ackRequest.Header.From.FromURI.User, _byeRemoteEP.ToHost(), ""); SIPFromHeader from = new SIPFromHeader(null, localUri, _ackRequest.Header.To.ToTag); SIPToHeader to = new SIPToHeader(null, remoteUri, _ackRequest.Header.From.FromTag); SIPRequest byeReq = new SIPRequest(SIPMethodsEnum.BYE, localUri); SIPHeader header = new SIPHeader(from, to, _ackRequest.Header.CSeq + 1, _ackRequest.Header.CallId); header.CSeqMethod = SIPMethodsEnum.BYE; SIPViaHeader viaHeader = new SIPViaHeader(LocalEP, CallProperties.CreateBranchId()); viaHeader.Branch = CallProperties.CreateBranchId(); viaHeader.Transport = SIPProtocolsEnum.udp; SIPViaSet viaSet = new SIPViaSet(); viaSet.Via = new List <SIPViaHeader>(); viaSet.Via.Add(viaHeader); header.Vias = viaSet; header.UserAgent = SIPConstants.SIP_USERAGENT_STRING; header.Contact = _ackRequest.Header.Contact; byeReq.Header = header; SendRequest(_byeRemoteEP, byeReq); }
private SIPRequest GetCallbackInviteRequest(IPEndPoint localSIPEndPoint, string sdp) { string callBackURI = "sip:[email protected]"; string callBackUserField = "<" + callBackURI + ">"; SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, callBackURI); SIPHeader inviteHeader = new SIPHeader(callBackUserField, callBackUserField, 1, CallProperties.CreateNewCallId()); inviteHeader.CSeqMethod = SIPMethodsEnum.INVITE; inviteHeader.ContentType = "application/sdp"; SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint, CallProperties.CreateBranchId()); inviteHeader.Vias.PushViaHeader(viaHeader); inviteRequest.Header = inviteHeader; if (sdp == null) { sdp = "v=0" + CRLF + "o=- " + Crypto.GetRandomInt(1000, 5000).ToString() + " 2 IN IP4 " + localSIPEndPoint.Address.ToString() + CRLF + "s=session" + CRLF + "c=IN IP4 " + localSIPEndPoint.Address.ToString() + CRLF + "t=0 0" + CRLF + "m=audio " + Crypto.GetRandomInt(10000, 20000).ToString() + " RTP/AVP 0 18 101" + CRLF + "a=rtpmap:0 PCMU/8000" + CRLF + "a=rtpmap:18 G729/8000" + CRLF + "a=rtpmap:101 telephone-event/8000" + CRLF + "a=fmtp:101 0-16" + CRLF + "a=recvonly"; } inviteHeader.ContentLength = sdp.Length; inviteRequest.Body = sdp; return(inviteRequest); }
private Task <SocketError> ByeServerFinalResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { logger.LogDebug("Response " + sipResponse.StatusCode + " " + sipResponse.ReasonPhrase + " for " + sipTransaction.TransactionRequest.URI.ToString() + "."); SIPNonInviteTransaction byeTransaction = sipTransaction as SIPNonInviteTransaction; if ((sipResponse.Status == SIPResponseStatusCodesEnum.ProxyAuthenticationRequired || sipResponse.Status == SIPResponseStatusCodesEnum.Unauthorised) && SIPAccount != null) { // Resend BYE with credentials. SIPAuthorisationDigest authRequest = sipResponse.Header.AuthenticationHeader.SIPDigest; SIPURI contactUri = sipResponse.Header.Contact.Any() ? sipResponse.Header.Contact[0].ContactURI : sipResponse.Header.From.FromURI; authRequest.SetCredentials(SIPAccount.SIPUsername, SIPAccount.SIPPassword, contactUri.ToString(), SIPMethodsEnum.BYE.ToString()); SIPRequest authByeRequest = byeTransaction.TransactionRequest; authByeRequest.Header.AuthenticationHeader = new SIPAuthenticationHeader(authRequest); authByeRequest.Header.AuthenticationHeader.SIPDigest.Response = authRequest.Digest; authByeRequest.Header.Vias.TopViaHeader.Branch = CallProperties.CreateBranchId(); authByeRequest.Header.CSeq = authByeRequest.Header.CSeq + 1; SIPNonInviteTransaction authByeTransaction = new SIPNonInviteTransaction(m_sipTransport, authByeRequest, null); authByeTransaction.SendRequest(); } return(Task.FromResult(SocketError.Success)); } catch (Exception excp) { logger.LogError("Exception ByServerFinalResponseReceived. " + excp.Message); return(Task.FromResult(SocketError.Fault)); } }
private SIPRequest GetDummyINVITERequest(SIPURI dummyURI) { string dummyFrom = "<sip:[email protected]>"; string dummyContact = "sip:127.0.0.1:1234"; SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, dummyURI); SIPHeader inviteHeader = new SIPHeader(SIPFromHeader.ParseFromHeader(dummyFrom), new SIPToHeader(null, dummyURI, null), 1, CallProperties.CreateNewCallId()); inviteHeader.From.FromTag = CallProperties.CreateNewTag(); inviteHeader.Contact = SIPContactHeader.ParseContactHeader(dummyContact); inviteHeader.CSeqMethod = SIPMethodsEnum.INVITE; inviteHeader.UserAgent = "unittest"; inviteRequest.Header = inviteHeader; SIPViaHeader viaHeader = new SIPViaHeader("127.0.0.1", 1234, CallProperties.CreateBranchId(), SIPProtocolsEnum.udp); inviteRequest.Header.Vias.PushViaHeader(viaHeader); inviteRequest.Body = "dummy"; inviteRequest.Header.ContentLength = inviteRequest.Body.Length; inviteRequest.Header.ContentType = "application/sdp"; return(inviteRequest); }
private SIPRequest GetAuthenticatedRequest(SIPRequest originalRequest, SIPResponse sipResponse) { try { SIPAuthorisationDigest digest = sipResponse.Header.AuthenticationHeader.SIPDigest; m_lastServerNonce = digest.Nonce; string username = (m_callDescriptor.AuthUsername != null) ? m_callDescriptor.AuthUsername : m_callDescriptor.Username; digest.SetCredentials(username, m_callDescriptor.Password, originalRequest.URI.ToString(), originalRequest.Method.ToString()); SIPRequest authRequest = originalRequest.Copy(); authRequest.SetSendFromHints(originalRequest.LocalSIPEndPoint); authRequest.Header.Vias.TopViaHeader.Branch = CallProperties.CreateBranchId(); authRequest.Header.From.FromTag = CallProperties.CreateNewTag(); authRequest.Header.To.ToTag = null; authRequest.Header.CallId = CallProperties.CreateNewCallId(); authRequest.Header.CSeq = originalRequest.Header.CSeq + 1; authRequest.Header.AuthenticationHeader = new SIPAuthenticationHeader(digest); authRequest.Header.AuthenticationHeader.SIPDigest.Response = digest.Digest; return(authRequest); } catch (Exception excp) { logger.LogError("Exception SIPNonInviteClientUserAgent GetAuthenticatedRequest. " + excp.Message); throw; } }
[Ignore] // Broken after NEtStandard migration. public void SingleProviderLegUnitTest() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, SIPURI.ParseSIPURI("sip:1234@localhost")); SIPHeader inviteHeader = new SIPHeader(SIPFromHeader.ParseFromHeader("<sip:joe@localhost>"), SIPToHeader.ParseToHeader("<sip:jane@localhost>"), 23, CallProperties.CreateNewCallId()); SIPViaHeader viaHeader = new SIPViaHeader("127.0.0.1", 5060, CallProperties.CreateBranchId()); inviteHeader.Vias.PushViaHeader(viaHeader); inviteRequest.Header = inviteHeader; List <SIPProvider> providers = new List <SIPProvider>(); SIPProvider provider = new SIPProvider(ProviderTypes.SIP, "test", "blueface", "test", "password", SIPURI.ParseSIPURIRelaxed("sip.blueface.ie"), null, null, null, null, 3600, null, null, null, false, false, null, null, null); providers.Add(provider); DialStringParser dialStringParser = new DialStringParser(null, "test", null, providers, delegate { return(null); }, delegate { return(null); }, (host, wildcard) => { return(null); }, null, "test"); Queue <List <SIPCallDescriptor> > callQueue = dialStringParser.ParseDialString(DialPlanContextsEnum.Script, inviteRequest, "blueface", null, null, null, null, null, null, null, null, CustomerServiceLevels.Free); Assert.IsNotNull(callQueue, "The call list should have contained a call."); Assert.IsTrue(callQueue.Count == 1, "The call queue list should have contained one leg."); List <SIPCallDescriptor> firstLeg = callQueue.Dequeue(); Assert.IsNotNull(firstLeg, "The first call leg should exist."); Assert.IsTrue(firstLeg.Count == 1, "The first call leg should have had one switch call."); Assert.IsTrue(firstLeg[0].Username == "test", "The username for the first call leg was not correct."); Assert.IsTrue(firstLeg[0].Uri.ToString() == "sip:[email protected]", "The destination URI for the first call leg was not correct."); Console.WriteLine("---------------------------------"); }
private SIPRequest GetAuthenticatedRegistrationRequest(SIPRequest registerRequest, SIPResponse sipResponse) { SIPAuthorisationDigest authRequest = sipResponse.Header.AuthenticationHeader.SIPDigest; string username = (m_authUsername != null) ? m_authUsername : m_sipAccountAOR.User; authRequest.SetCredentials(username, m_password, registerRequest.URI.ToString(), SIPMethodsEnum.REGISTER.ToString()); if (!this.m_realm.IsNullOrBlank()) { authRequest.Realm = this.m_realm; } SIPRequest regRequest = registerRequest.Copy(); regRequest.SetSendFromHints(registerRequest.LocalSIPEndPoint); regRequest.Header.Vias.TopViaHeader.Branch = CallProperties.CreateBranchId(); regRequest.Header.From.FromTag = CallProperties.CreateNewTag(); regRequest.Header.To.ToTag = null; regRequest.Header.CSeq = ++m_cseq; regRequest.Header.AuthenticationHeader = new SIPAuthenticationHeader(authRequest); regRequest.Header.AuthenticationHeader.SIPDigest.Response = authRequest.Digest; return(regRequest); }
private SIPRequest GetInviteRequest(string callURI, SIPCallDescriptor sipCallDescriptor) { SIPFromHeader fromHeader = sipCallDescriptor.GetFromHeader(); SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, SIPURI.ParseSIPURI(callURI)) { LocalSIPEndPoint = m_blackhole }; SIPHeader inviteHeader = new SIPHeader(fromHeader, new SIPToHeader(null, inviteRequest.URI, null), 1, CallProperties.CreateNewCallId()); inviteHeader.From.FromTag = CallProperties.CreateNewTag(); // For incoming calls forwarded via the dial plan the username needs to go into the Contact header. inviteHeader.Contact = new List <SIPContactHeader>() { new SIPContactHeader(null, new SIPURI(inviteRequest.URI.Scheme, m_blackhole)) }; inviteHeader.CSeqMethod = SIPMethodsEnum.INVITE; inviteRequest.Header = inviteHeader; SIPViaHeader viaHeader = new SIPViaHeader(m_blackhole, CallProperties.CreateBranchId()); inviteRequest.Header.Vias.PushViaHeader(viaHeader); try { if (sipCallDescriptor.CustomHeaders != null && sipCallDescriptor.CustomHeaders.Count > 0) { foreach (string customHeader in sipCallDescriptor.CustomHeaders) { if (customHeader.IsNullOrBlank()) { continue; } else if (customHeader.Trim().StartsWith(SIPHeaders.SIP_HEADER_USERAGENT)) { inviteRequest.Header.UserAgent = customHeader.Substring(customHeader.IndexOf(":") + 1).Trim(); } else { inviteRequest.Header.UnknownHeaders.Add(customHeader); } } } } catch (Exception excp) { logger.Error("Exception Parsing CustomHeader for GetInviteRequest. " + excp.Message + sipCallDescriptor.CustomHeaders); } return(inviteRequest); }
public void Call(SIPCallDescriptor sipCallDescriptor) { try { m_uacCallDescriptor = sipCallDescriptor; SIPRequest uacInviteRequest = GetInviteRequest(m_uacCallDescriptor.Uri, sipCallDescriptor); if (sipCallDescriptor.MangleResponseSDP && sipCallDescriptor.MangleIPAddress != null) { uacInviteRequest.Header.ProxyReceivedFrom = sipCallDescriptor.MangleIPAddress.ToString(); } uacInviteRequest.Body = sipCallDescriptor.Content; uacInviteRequest.Header.ContentType = sipCallDescriptor.ContentType; uacInviteRequest.LocalSIPEndPoint = m_blackhole; uacInviteRequest.RemoteSIPEndPoint = m_blackhole; // Now that we have a destination socket create a new UAC transaction for forwarded leg of the call. m_uacTransaction = m_sipTransport.CreateUACTransaction(uacInviteRequest, m_blackhole, m_blackhole, null); if (m_uacTransaction.CDR != null) { m_uacTransaction.CDR.Owner = m_uacOwner; m_uacTransaction.CDR.AdminMemberId = m_uacAdminMemberId; m_uacTransaction.CDR.DialPlanContextID = (m_uacCallDescriptor != null) ? m_uacCallDescriptor.DialPlanContextID : Guid.Empty; } //uacTransaction.UACInviteTransactionInformationResponseReceived += ServerInformationResponseReceived; //uacTransaction.UACInviteTransactionFinalResponseReceived += ServerFinalResponseReceived; //uacTransaction.UACInviteTransactionTimedOut += ServerTimedOut; //uacTransaction.TransactionTraceMessage += TransactionTraceMessage; m_uacTransaction.SendInviteRequest(m_blackhole, m_uacTransaction.TransactionRequest); SIPRequest uasInviteRequest = uacInviteRequest.Copy(); uasInviteRequest.LocalSIPEndPoint = m_blackhole; uasInviteRequest.RemoteSIPEndPoint = m_blackhole; uasInviteRequest.Header.Vias.TopViaHeader.Branch = CallProperties.CreateBranchId(); m_uasTransaction = m_sipTransport.CreateUASTransaction(uasInviteRequest, m_blackhole, m_blackhole, null); SetOwner(sipCallDescriptor.ToSIPAccount.Owner, sipCallDescriptor.ToSIPAccount.AdminMemberId); //m_uasTransaction.TransactionTraceMessage += TransactionTraceMessage; //m_uasTransaction.UASInviteTransactionTimedOut += ClientTimedOut; //m_uasTransaction.UASInviteTransactionCancelled += (t) => { }; QueueNewCall_External(this); CallTrying.Invoke(this, null); } catch (Exception excp) { logger.Error("Exception SIPB2BUserAgent Call. " + excp.Message); } }
/// <summary> /// Used to send a SIP request received from an external user agent to an internal SIP server agent. /// </summary> /// <param name="receivedFromEP">The SIP end point the proxy received the request from.</param> /// <param name="receivedOnEP">The SIP end point the proxy received the request on.</param> /// <param name="dstSocket">The internal socket to send the request to.</param> /// <param name="sipRequest">The SIP request to send.</param> /// <param name="proxyBranch">The branch to set on the Via header when sending the request. The branch should be calculated /// by the proxy core so that looped requests can be detected.</param> /// <param name="sendFromSocket">The proxy socket to send the request from.</param> public void SendInternal(SIPEndPoint receivedFromEP, SIPEndPoint receivedOnEP, string dstSocket, SIPRequest sipRequest, string proxyBranch, string sendFromSocket) { try { if (!IsDestinationValid(sipRequest, dstSocket)) { logger.Debug("SendInternal failed destination check."); return; } sipRequest.Header.ProxyReceivedFrom = receivedFromEP.ToString(); sipRequest.Header.ProxyReceivedOn = receivedOnEP.ToString(); SIPEndPoint dstSIPEndPoint = SIPEndPoint.ParseSIPEndPoint(dstSocket); SIPEndPoint localSIPEndPoint = SIPEndPoint.ParseSIPEndPoint(sendFromSocket); if (receivedOnEP != localSIPEndPoint) { // The proxy is being requested to send the request on a different socket to the one it was received on. // A second Via header is added to ensure the response can navigate back the same path. The calculated branch // parameter needs to go on the top Via header so that whichever internal socket the request is being sent to can // determine re-transmits. SIPViaHeader via = new SIPViaHeader(receivedOnEP, CallProperties.CreateBranchId()); sipRequest.Header.Vias.PushViaHeader(via); SIPViaHeader topVia = new SIPViaHeader(localSIPEndPoint, proxyBranch); sipRequest.Header.Vias.PushViaHeader(topVia); } else { // Only a single Via header is required as any response to this request will be sent from the same socket it gets received on. SIPViaHeader via = new SIPViaHeader(localSIPEndPoint, proxyBranch); sipRequest.Header.Vias.PushViaHeader(via); } sipRequest.LocalSIPEndPoint = localSIPEndPoint; m_sipTransport.SendRequest(dstSIPEndPoint, sipRequest); } catch (Exception excp) { logger.Error("Exception SIPRequest SendInternal. " + excp.Message); logger.Error(sipRequest.ToString()); throw; } }
public SIPRequest GetAuthenticatedRequest(SIPRequest origRequest, SIPResponse authReqdResponse, string username, string password) { SIPRequest authRequest = origRequest; authRequest.Header.Via.TopViaHeader.Branch = CallProperties.CreateBranchId(); authRequest.Header.From.FromTag = CallProperties.CreateNewTag(); authRequest.Header.CSeq = origRequest.Header.CSeq + 1; AuthorizationRequest authorizationRequest = authReqdResponse.Header.AuthenticationHeader.AuthRequest; authorizationRequest.SetCredentials(username, password, origRequest.URI.ToString(), origRequest.Method.ToString()); authRequest.Header.AuthenticationHeader = new SIPAuthenticationHeader(authorizationRequest); authRequest.Header.AuthenticationHeader.AuthRequest.Response = authorizationRequest.Digest; return(authRequest); }
private SIPRequest CreateDummyRequest(SIPDialogue dialogueToReplace, string callDestination) { SIPRequest dummyInvite = new SIPRequest(SIPMethodsEnum.INVITE, SIPURI.ParseSIPURIRelaxed(callDestination + "@sipsorcery.com")); SIPHeader dummyHeader = new SIPHeader("<sip:[email protected]>", "<sip:[email protected]>", 1, CallProperties.CreateNewCallId()) { CSeqMethod = SIPMethodsEnum.INVITE }; dummyHeader.Vias.PushViaHeader(new SIPViaHeader(new IPEndPoint(SIPTransport.BlackholeAddress, 0), CallProperties.CreateBranchId())); dummyInvite.Header = dummyHeader; dummyInvite.Header.ContentType = "application/sdp"; dummyInvite.Body = dialogueToReplace.SDP; return(dummyInvite); }
public string CreateBranchId() { string routeStr = (Header.Routes != null) ? Header.Routes.ToString() : null; string toTagStr = (Header.To != null) ? Header.To.ToTag : null; string fromTagStr = (Header.From != null) ? Header.From.FromTag : null; string topViaStr = (Header.Vias != null && Header.Vias.TopViaHeader != null) ? Header.Vias.TopViaHeader.ToString() : null; return(CallProperties.CreateBranchId( SIPConstants.SIP_BRANCH_MAGICCOOKIE, toTagStr, fromTagStr, Header.CallId, URI.ToString(), topViaStr, Header.CSeq, routeStr, Header.ProxyRequire, null)); }
private SIPRequest GetByeRequest(SIPEndPoint localSIPEndPoint) { SIPRequest byeRequest = new SIPRequest(SIPMethodsEnum.BYE, m_sipDialogue.RemoteTarget); SIPFromHeader byeFromHeader = SIPFromHeader.ParseFromHeader(m_sipDialogue.LocalUserField.ToString()); SIPToHeader byeToHeader = SIPToHeader.ParseToHeader(m_sipDialogue.RemoteUserField.ToString()); int cseq = m_sipDialogue.CSeq + 1; SIPHeader byeHeader = new SIPHeader(byeFromHeader, byeToHeader, cseq, m_sipDialogue.CallId); byeHeader.CSeqMethod = SIPMethodsEnum.BYE; byeRequest.Header = byeHeader; byeRequest.Header.Routes = m_sipDialogue.RouteSet; byeRequest.Header.ProxySendFrom = m_sipDialogue.ProxySendFrom; SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint, CallProperties.CreateBranchId()); byeRequest.Header.Vias.PushViaHeader(viaHeader); return(byeRequest); }
private SIPRequest GetInviteRequest(SIPDialogue dialogue, SIPEndPoint localSIPEndPoint, string body) { SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, dialogue.RemoteTarget); SIPHeader inviteHeader = new SIPHeader(SIPFromHeader.ParseFromHeader(dialogue.LocalUserField.ToString()), SIPToHeader.ParseToHeader(dialogue.RemoteUserField.ToString()), dialogue.CSeq, dialogue.CallId); SIPURI contactURI = new SIPURI(dialogue.RemoteTarget.Scheme, localSIPEndPoint); inviteHeader.Contact = SIPContactHeader.ParseContactHeader("<" + contactURI.ToString() + ">"); inviteHeader.CSeqMethod = SIPMethodsEnum.INVITE; inviteRequest.Header = inviteHeader; inviteRequest.Header.Routes = dialogue.RouteSet; SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint, CallProperties.CreateBranchId()); inviteRequest.Header.Vias.PushViaHeader(viaHeader); inviteRequest.Body = body; inviteRequest.Header.ContentLength = body.Length; inviteRequest.Header.ContentType = m_sdpContentType; return(inviteRequest); }
/// <summary> /// 向上级平台注册 /// </summary> private void RegisterToPlatform() { string fromTag = CallProperties.CreateNewTag(); string callId = CallProperties.CreateNewCallId(); int cSeq = CallProperties.CreateNewCSeq(); string branch = CallProperties.CreateBranchId(); SIPURI localUri = new SIPURI(LocalSIPId, LocalEndPoint.ToHost(), ""); SIPURI remoteUri = new SIPURI(RemoteSIPId, RemoteEndPoint.ToHost(), ""); SIPRequest registerReq = new SIPRequest(SIPMethodsEnum.REGISTER, remoteUri); SIPViaHeader via = new SIPViaHeader(LocalEndPoint, branch); SIPViaSet viaSet = new SIPViaSet(); viaSet.PushViaHeader(via); SIPFromHeader from = new SIPFromHeader(null, localUri, fromTag); SIPToHeader to = new SIPToHeader(null, localUri, null); SIPHeader header = new SIPHeader(from, to, cSeq, callId); registerReq.Header = header; SIPContactHeader contact = new SIPContactHeader(null, localUri); header.Contact = new List <SIPContactHeader>(); header.Contact.Add(contact); header.Vias = viaSet; header.AuthenticationHeader = _auth; header.Expires = 3600; header.CSeqMethod = SIPMethodsEnum.REGISTER; header.MaxForwards = 70; header.ContentLength = 0; header.UserAgent = SIPConstants.SIP_SERVER_STRING; Transport.SendRequest(RemoteEndPoint, registerReq); }
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); }
/// <summary> /// Used to send a request from an internal server agent to an external SIP user agent. The difference between this method and /// the SendTransparent method is that this one will set Via headers in accordance with RFC3261. /// </summary> /// <param name="receivedOnEP">The proxy SIP end point the request was received on.</param> /// <param name="dstSocket">The SIP end point the request is being sent to.</param> /// <param name="sipRequest">The SIP request to send.</param> /// <param name="proxyBranch">The branch parameter for the top Via header that has been pre-calculated by the proxy core.</param> /// <param name="sendFromSocket">The proxy SIP end point to send this request from. If the SIP request has its ProxySendFrom header /// value set that will overrule this parameter.</param> public void SendExternal(SIPEndPoint receivedOnEP, SIPEndPoint dstSIPEndPoint, SIPRequest sipRequest, string proxyBranch, IPAddress publicIPAddress) { try { if (!IsDestinationValid(sipRequest, dstSIPEndPoint)) { logger.Debug("SendExternal failed destination check."); return; } // Determine the external SIP endpoint that the proxy will use to send this request. SIPEndPoint localSIPEndPoint = m_sipTransport.GetDefaultSIPEndPoint(dstSIPEndPoint); if (!sipRequest.Header.ProxySendFrom.IsNullOrBlank()) { SIPChannel proxyChannel = m_sipTransport.FindSIPChannel(SIPEndPoint.ParseSIPEndPoint(sipRequest.Header.ProxySendFrom)); if (proxyChannel == null) { logger.Warn("No SIP channel could be found for\n" + sipRequest.ToString()); } localSIPEndPoint = (proxyChannel != null) ? proxyChannel.SIPChannelEndPoint : localSIPEndPoint; } if (receivedOnEP != localSIPEndPoint) { // The proxy is being requested to send the request on a different socket to the one it was received on. // A second Via header is added to ensure the response can navigate back the same path. The calculated branch // parameter needs to go on the top Via header so that whichever internal socket the request is being sent to can // determine re-transmits. SIPViaHeader via = new SIPViaHeader(receivedOnEP, CallProperties.CreateBranchId()); sipRequest.Header.Vias.PushViaHeader(via); SIPViaHeader externalVia = new SIPViaHeader(localSIPEndPoint, proxyBranch); sipRequest.Header.Vias.PushViaHeader(externalVia); } else { // Only a single Via header is required as any response to this request will be sent from the same socket it gets received on. SIPViaHeader via = new SIPViaHeader(localSIPEndPoint, proxyBranch); sipRequest.Header.Vias.PushViaHeader(via); } if (sipRequest.Method != SIPMethodsEnum.REGISTER) { AdjustContactHeader(sipRequest.Header, localSIPEndPoint, publicIPAddress); } sipRequest.LocalSIPEndPoint = localSIPEndPoint; // Proxy sepecific headers that don't need to be seen by external UAs. sipRequest.Header.ProxyReceivedOn = null; sipRequest.Header.ProxyReceivedFrom = null; sipRequest.Header.ProxySendFrom = null; m_sipTransport.SendRequest(dstSIPEndPoint, sipRequest); } catch (Exception excp) { logger.Error("Exception SIPRequest SendExternal. " + excp.Message); logger.Error(sipRequest.ToString()); throw; } }
public SIPRequest GetByeRequest(SIPResponse inviteResponse) { SIPRequest byeRequest = new SIPRequest(SIPMethodsEnum.BYE, inviteResponse.Header.Contact[0].ContactURI); SIPHeader byeHeader = new SIPHeader(inviteResponse.Header.From, inviteResponse.Header.To, inviteResponse.Header.CSeq + 1, inviteResponse.Header.CallId); byeHeader.CSeqMethod = SIPMethodsEnum.BYE; IPEndPoint localSIPEndPoint = m_sipTransport.GetIPEndPointsList()[0]; SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint.Address.ToString(), localSIPEndPoint.Port, CallProperties.CreateBranchId()); byeHeader.Via.PushViaHeader(viaHeader); byeRequest.Header = byeHeader; return(byeRequest); }
public SIPRequest GetReferRequest(SIPRequest inviteRequest, SIPResponse inviteResponse, string referToURI) { SIPRequest referRequest = new SIPRequest(SIPMethodsEnum.REFER, inviteRequest.URI); SIPHeader referHeader = new SIPHeader(inviteResponse.Header.From, inviteResponse.Header.To, inviteRequest.Header.CSeq + 1, inviteRequest.Header.CallId); referHeader.Contact = inviteRequest.Header.Contact; referHeader.CSeqMethod = SIPMethodsEnum.REFER; referHeader.ReferTo = referToURI; SIPFromHeader referredBy = new SIPFromHeader(inviteRequest.Header.From.FromName, inviteRequest.Header.From.FromURI, null); referHeader.ReferredBy = referredBy.ToString(); referHeader.AuthenticationHeader = inviteRequest.Header.AuthenticationHeader; IPEndPoint localSIPEndPoint = m_sipTransport.GetIPEndPointsList()[0]; SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint.Address.ToString(), localSIPEndPoint.Port, CallProperties.CreateBranchId()); referHeader.Via.PushViaHeader(viaHeader); referRequest.Header = referHeader; return(referRequest); }
public SIPRequest GetRegisterRequest(string server, string toURIStr, string contactStr) { try { IPEndPoint localSIPEndPoint = m_sipTransport.GetDefaultTransportContact(SIPProtocolsEnum.UDP); SIPRequest registerRequest = new SIPRequest(SIPMethodsEnum.REGISTER, "sip:" + server); SIPHeader registerHeader = new SIPHeader(SIPFromHeader.ParseFromHeader(toURIStr), SIPToHeader.ParseToHeader(toURIStr), 1, CallProperties.CreateNewCallId()); registerHeader.From.FromTag = CallProperties.CreateNewTag(); registerHeader.Contact = SIPContactHeader.ParseContactHeader(contactStr); SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint.Address.ToString(), localSIPEndPoint.Port, CallProperties.CreateBranchId()); registerHeader.Via.PushViaHeader(viaHeader); registerHeader.CSeqMethod = SIPMethodsEnum.REGISTER; registerHeader.Expires = SIPConstants.DEFAULT_REGISTEREXPIRY_SECONDS; registerRequest.Header = registerHeader; return(registerRequest); } catch (Exception excp) { logger.Error("Exception GetRegisterRequest. " + excp.Message); throw new ApplicationException("GetRegisterRequest " + excp.GetType().ToString() + ". " + excp.Message); } }
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.LogError("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.LogError("Exception SIPNonInviteClientUserAgent GetRequest. " + excp.Message); throw excp; } }
public SIPRequest GetSIPRequest(SIPMethodsEnum sipMethod, string requestURIStr, string fromURIStr, int cseq, string callId, string contentType, string body) { SIPURI requestURI = (requestURIStr.StartsWith("sip:")) ? SIPURI.ParseSIPURI(requestURIStr) : SIPURI.ParseSIPURI("sip:" + requestURIStr); SIPURI fromURI = (fromURIStr.StartsWith("sip:")) ? SIPURI.ParseSIPURI(fromURIStr) : SIPURI.ParseSIPURI("sip:" + fromURIStr); SIPFromHeader fromHeader = new SIPFromHeader(null, fromURI, CallProperties.CreateNewTag()); SIPToHeader toHeader = new SIPToHeader(null, requestURI, null); SIPRequest sipRequest = new SIPRequest(sipMethod, requestURI); IPEndPoint localSIPEndPoint = m_sipTransport.GetIPEndPointsList()[0]; SIPHeader sipHeader = new SIPHeader(fromHeader, toHeader, cseq, callId); sipHeader.Contact = SIPContactHeader.ParseContactHeader("sip:" + localSIPEndPoint.ToString()); sipHeader.CSeqMethod = sipMethod; sipRequest.Header = sipHeader; SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint.Address.ToString(), localSIPEndPoint.Port, CallProperties.CreateBranchId()); sipRequest.Header.Via.PushViaHeader(viaHeader); if (body != null && body.Trim().Length > 0) { sipRequest.Body = body; //sipRequest.Body = "Signal=5\r\nDuration=250"; //sipRequest.Body = "<rtcp>blah blah blah</rtcp>"; sipRequest.Header.ContentLength = sipRequest.Body.Length; sipRequest.Header.ContentType = contentType; } return(sipRequest); }
private Task <SocketError> SubscribeTransactionFinalResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { if (sipResponse.Status == SIPResponseStatusCodesEnum.IntervalTooBrief) { // The expiry interval used was too small. Adjust and try again. m_expiry = (sipResponse.Header.MinExpires > 0) ? sipResponse.Header.MinExpires : m_expiry * 2; logger.LogWarning("A subscribe request was rejected with IntervalTooBrief, adjusting expiry to " + m_expiry + " and trying again."); Subscribe(m_resourceURI, m_expiry, m_sipEventPackage, m_subscribeCallID, null); } else if (sipResponse.Status == SIPResponseStatusCodesEnum.Forbidden) { // The subscription is never going to succeed so cancel it. SubscriptionFailed?.Invoke(m_resourceURI, sipResponse.Status, "A Forbidden response was received on a subscribe attempt to " + m_resourceURI.ToString() + " for user " + m_authUsername + "."); m_exit = true; m_waitForSubscribeResponse.Set(); } else if (sipResponse.Status == SIPResponseStatusCodesEnum.BadEvent) { // The subscription is never going to succeed so cancel it. SubscriptionFailed?.Invoke(m_resourceURI, sipResponse.Status, "A BadEvent response was received on a subscribe attempt to " + m_resourceURI.ToString() + " for event package " + m_sipEventPackage.ToString() + "."); m_exit = true; m_waitForSubscribeResponse.Set(); } else if (sipResponse.Status == SIPResponseStatusCodesEnum.CallLegTransactionDoesNotExist) { // The notifier server does not have a record for the existing subscription. SubscriptionFailed?.Invoke(m_resourceURI, sipResponse.Status, "Subscribe failed with response " + sipResponse.StatusCode + " " + sipResponse.ReasonPhrase + "."); m_waitForSubscribeResponse.Set(); } else if (sipResponse.Status == SIPResponseStatusCodesEnum.ProxyAuthenticationRequired || sipResponse.Status == SIPResponseStatusCodesEnum.Unauthorised) { if (m_authUsername.IsNullOrBlank() || m_authPassword.IsNullOrBlank()) { // No point trying to authenticate if there are no credentials to use. SubscriptionFailed?.Invoke(m_resourceURI, sipResponse.Status, "Authentication requested on subscribe request when no credentials available."); m_waitForSubscribeResponse.Set(); } else if (sipResponse.Header.AuthenticationHeader != null) { if (m_attempts >= MAX_SUBSCRIBE_ATTEMPTS) { m_subscribed = false; SubscriptionFailed?.Invoke(m_resourceURI, SIPResponseStatusCodesEnum.InternalServerError, "Subscription reached the maximum number of allowed attempts."); m_waitForSubscribeResponse.Set(); } else { logger.LogDebug("Attempting authentication for subscribe request for event package " + m_sipEventPackage.ToString() + " and " + m_resourceURI.ToString() + "."); m_attempts++; // Resend SUBSCRIBE with credentials. SIPAuthorisationDigest authRequest = sipResponse.Header.AuthenticationHeader.SIPDigest; authRequest.SetCredentials(m_authUsername, m_authPassword, m_resourceURI.ToString(), SIPMethodsEnum.SUBSCRIBE.ToString()); SIPRequest authSubscribeRequest = sipTransaction.TransactionRequest; authSubscribeRequest.Header.AuthenticationHeader = new SIPAuthenticationHeader(authRequest); authSubscribeRequest.Header.AuthenticationHeader.SIPDigest.Response = authRequest.Digest; authSubscribeRequest.Header.Vias.TopViaHeader.Branch = CallProperties.CreateBranchId(); m_localCSeq = sipTransaction.TransactionRequest.Header.CSeq + 1; authSubscribeRequest.Header.CSeq = m_localCSeq; authSubscribeRequest.Header.CallId = m_subscribeCallID; if (!m_filter.IsNullOrBlank()) { authSubscribeRequest.Body = m_filter; authSubscribeRequest.Header.ContentLength = m_filter.Length; authSubscribeRequest.Header.ContentType = m_filterTextType; } // Create a new transaction to establish the authenticated server call. SIPNonInviteTransaction subscribeTransaction = new SIPNonInviteTransaction(m_sipTransport, authSubscribeRequest, m_outboundProxy); subscribeTransaction.NonInviteTransactionFinalResponseReceived += SubscribeTransactionFinalResponseReceived; subscribeTransaction.NonInviteTransactionFailed += SubscribeTransactionFailed; //m_sipTransport.SendTransaction(subscribeTransaction); subscribeTransaction.SendRequest(); } } else { SubscriptionFailed?.Invoke(sipTransaction.TransactionRequestURI, sipResponse.Status, "Subscribe requested authentication but did not provide an authentication header."); m_waitForSubscribeResponse.Set(); } } else if (sipResponse.StatusCode >= 200 && sipResponse.StatusCode <= 299) { logger.LogDebug("Authenticating subscribe request for event package " + m_sipEventPackage.ToString() + " and " + m_resourceURI.ToString() + " was successful."); m_subscribed = true; m_subscriptionToTag = sipResponse.Header.To.ToTag; SubscriptionSuccessful?.Invoke(m_resourceURI); m_waitForSubscribeResponse.Set(); } else { SubscriptionFailed?.Invoke(m_resourceURI, sipResponse.Status, "Subscribe failed with response " + sipResponse.StatusCode + " " + sipResponse.ReasonPhrase + "."); m_waitForSubscribeResponse.Set(); } return(Task.FromResult(SocketError.Success)); } catch (Exception excp) { logger.LogError("Exception SubscribeTransactionFinalResponseReceived. " + excp.Message); SubscriptionFailed?.Invoke(m_resourceURI, SIPResponseStatusCodesEnum.InternalServerError, "Exception processing subscribe response. " + excp.Message); m_waitForSubscribeResponse.Set(); return(Task.FromResult(SocketError.Fault)); } }
/// <summary> /// Builds the REFER request to transfer an established call. /// </summary> /// <param name="sipDialogue">A SIP dialogue object representing the established call.</param> /// <param name="referToUri">The SIP URI to transfer the call to.</param> /// <returns>A SIP REFER request.</returns> private static SIPRequest GetReferRequest(SIPClientUserAgent uac, SIPURI referToUri) { SIPDialogue sipDialogue = uac.SIPDialogue; SIPRequest referRequest = new SIPRequest(SIPMethodsEnum.REFER, sipDialogue.RemoteTarget); SIPFromHeader referFromHeader = SIPFromHeader.ParseFromHeader(sipDialogue.LocalUserField.ToString()); SIPToHeader referToHeader = SIPToHeader.ParseToHeader(sipDialogue.RemoteUserField.ToString()); int cseq = sipDialogue.CSeq + 1; sipDialogue.CSeq++; SIPHeader referHeader = new SIPHeader(referFromHeader, referToHeader, cseq, sipDialogue.CallId); referHeader.CSeqMethod = SIPMethodsEnum.REFER; referRequest.Header = referHeader; referRequest.Header.Routes = sipDialogue.RouteSet; referRequest.Header.ProxySendFrom = sipDialogue.ProxySendFrom; SIPViaHeader viaHeader = new SIPViaHeader(uac.ServerTransaction.LocalSIPEndPoint, CallProperties.CreateBranchId()); referRequest.Header.Vias.PushViaHeader(viaHeader); referRequest.Header.ReferTo = referToUri.ToString(); referRequest.Header.Contact = new List <SIPContactHeader>() { new SIPContactHeader(null, uac.ServerTransaction.TransactionRequest.Header.Contact.First().ContactURI) }; referRequest.RemoteSIPEndPoint = uac.ServerTransaction.RemoteEndPoint; return(referRequest); }
private SIPRequest GetInviteRequest(IPEndPoint localContact, string inviteBody, IPEndPoint dstEndPoint) { SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, SIPURI.ParseSIPURI("sip:" + dstEndPoint)); SIPHeader inviteHeader = new SIPHeader(SIPFromHeader.ParseFromHeader("<sip:" + localContact + ">"), SIPToHeader.ParseToHeader("<sip:" + dstEndPoint + ">"), 1, CallProperties.CreateNewCallId()); inviteHeader.From.FromTag = CallProperties.CreateNewTag(); inviteHeader.Contact = SIPContactHeader.ParseContactHeader("sip:" + localContact); inviteHeader.CSeqMethod = SIPMethodsEnum.INVITE; inviteHeader.UserAgent = "unit test"; inviteRequest.Header = inviteHeader; SIPViaHeader viaHeader = new SIPViaHeader(localContact.Address.ToString(), localContact.Port, CallProperties.CreateBranchId(), SIPProtocolsEnum.udp); inviteRequest.Header.Vias.PushViaHeader(viaHeader); //inviteRequest.Body = inviteBody; //inviteRequest.Header.ContentLength = inviteBody.Length; inviteRequest.Header.ContentType = "application/sdp"; return(inviteRequest); }
public SIPRequest GetInviteRequest(string inviteURIStr, string fromURIStr, string body, int rtpPort) { SIPURI inviteURI = (inviteURIStr.StartsWith("sip:")) ? SIPURI.ParseSIPURI(inviteURIStr) : SIPURI.ParseSIPURI("sip:" + inviteURIStr); SIPFromHeader fromHeader = SIPFromHeader.ParseFromHeader(fromURIStr); // (fromURIStr.StartsWith("sip:")) ? SIPFromHeader.ParseFromHeader(fromURIStr) : SIPFromHeader.ParseFromHeader("sip:" + fromURIStr); SIPToHeader toHeader = new SIPToHeader(null, inviteURI, null); SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, inviteURI); IPEndPoint localSIPEndPoint = m_sipTransport.GetIPEndPointsList()[0]; SIPHeader inviteHeader = new SIPHeader(fromHeader, toHeader, 1, CallProperties.CreateNewCallId()); inviteHeader.From.FromTag = CallProperties.CreateNewTag(); inviteHeader.Contact = SIPContactHeader.ParseContactHeader("sip:" + localSIPEndPoint.ToString()); inviteHeader.CSeqMethod = SIPMethodsEnum.INVITE; //inviteHeader.UnknownHeaders.Add("BlueFace-Test: 12324"); inviteRequest.Header = inviteHeader; SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint.Address.ToString(), localSIPEndPoint.Port, CallProperties.CreateBranchId()); inviteRequest.Header.Via.PushViaHeader(viaHeader); rtpPort = (rtpPort != 0) ? rtpPort : Crypto.GetRandomInt(10000, 20000); string sessionId = Crypto.GetRandomInt(1000, 5000).ToString(); if (body != null && body.Trim().Length > 0) { inviteRequest.Body = body; } else { inviteRequest.Body = "v=0" + CRLF + "o=- " + sessionId + " " + sessionId + " IN IP4 " + localSIPEndPoint.Address.ToString() + CRLF + "s=session" + CRLF + "c=IN IP4 " + localSIPEndPoint.Address.ToString() + CRLF + "t=0 0" + CRLF + "m=audio " + rtpPort + " RTP/AVP 0 101" + CRLF + "a=rtpmap:0 PCMU/8000" + CRLF + "a=rtpmap:101 telephone-event/8000" + CRLF + "a=fmtp:101 0-16" + CRLF + "a=sendrecv"; } inviteRequest.Header.ContentLength = inviteRequest.Body.Length; inviteRequest.Header.ContentType = "application/sdp"; return(inviteRequest); }