private SipRequest CreateAckRequest() { if (State != CompletedState) { throw new InvalidOperationException(string.Format("The Tx is unable to create an 'ACK' Request. To be able to create an 'ACK' request, the Tx must be in 'Completed' state. CurrentState:{0}", State.Name)); } Check.Require(LatestResponse, "LatestResponse"); var requestUri = Request.RequestLine.Uri.Clone(); var callIdheader = (SipCallIdHeader)Request.CallId.Clone(); var cseqHeader = _headerFactory.CreateSCeqHeader(SipMethods.Ack, Request.CSeq.Sequence); var fromHeader = (SipFromHeader)Request.From.Clone(); var toHeader = (SipToHeader)LatestResponse.To.Clone(); var viaHeader = (SipViaHeader)Request.Vias.GetTopMost().Clone(); var maxForwardsHeader = _headerFactory.CreateMaxForwardsHeader(); var ackRequest = _messageFactory.CreateRequest( requestUri, SipMethods.Ack, callIdheader, cseqHeader, fromHeader, toHeader, viaHeader, maxForwardsHeader); //TODO: not clear from the rfc if the routes have to be copied from request or response foreach (var route in Request.Routes) { ackRequest.Routes.Add((SipRouteHeader)route.Clone()); } return(ackRequest); }
protected SipRequest CreateCancelRequest(SipRequest request) { var hf = new SipHeaderFactory(); var mf = new SipMessageFactory(); var requestUri = request.RequestLine.Uri.Clone(); var callIdheader = (SipCallIdHeader)request.CallId.Clone(); var cseqHeader = new SipHeaderFactory().CreateSCeqHeader(SipMethods.Cancel, request.CSeq.Sequence); var fromHeader = (SipFromHeader)request.From.Clone(); var toHeader = (SipToHeader)request.To.Clone(); var viaHeader = (SipViaHeader)request.Vias.GetTopMost().Clone(); var maxForwardsHeader = hf.CreateMaxForwardsHeader(); var cancelRequest = mf.CreateRequest( requestUri, SipMethods.Cancel, callIdheader, cseqHeader, fromHeader, toHeader, viaHeader, maxForwardsHeader); foreach (var route in request.Routes) { cancelRequest.Routes.Add((SipRouteHeader)route.Clone()); } return(cancelRequest); }
/// <summary> /// creates a bye. this is to be sent by the testclient UA /// </summary> /// <param name="invite"></param> /// <param name="ringing"></param> /// <returns></returns> protected SipRequest CreateByeRequest(SipRequest invite, SipResponse ringing) { var addressFactory = new SipAddressFactory(); var headerFactory = new SipHeaderFactory(); var messageFactory = new SipMessageFactory(); var localSequenceNr = invite.CSeq.Sequence; /*_remoteSequenceNr remains empty */ var callId = invite.CallId.Value; var localTag = invite.From.Tag; var remoteUri = invite.To.SipUri; var localUri = invite.From.SipUri; var remoteTag = ringing.To.Tag; var remoteTarget = ringing.Contacts.GetTopMost().SipUri; var routeSet = ringing.RecordRoutes.ToList();//refuse looseroutin-less recordroutes routeSet.Reverse(); var cseqHeader = headerFactory.CreateSCeqHeader(SipMethods.Bye, localSequenceNr + 1); var toAddress = addressFactory.CreateAddress(null, remoteUri); var toHeader = headerFactory.CreateToHeader(toAddress, remoteTag); var fromAddress = addressFactory.CreateAddress(null, localUri); var fromHeader = headerFactory.CreateFromHeader(fromAddress, localTag); var callIdheader = headerFactory.CreateCallIdHeader(callId); var viaHeader = new SipViaHeaderBuilder().WithSentBy(_testClientUaEndPoint).Build(); var requestUri = remoteUri.Clone(); var maxForwardsHeader = headerFactory.CreateMaxForwardsHeader(); var request = messageFactory.CreateRequest( requestUri, SipMethods.Bye, callIdheader, cseqHeader, fromHeader, toHeader, viaHeader, maxForwardsHeader); foreach (var route in routeSet) { request.Routes.Add(new SipRouteHeader() { SipUri = route.SipUri, Parameters = route.Parameters }); } return(request); }
public SipRequest CreateRequest(string method, SipViaHeader viaheader = null) { if (State < DialogState.Early) { throw new InvalidOperationException("The dialog is unable to create the request. A dialog in 'NULL' state can not create requests."); } Check.IsTrue(SipMethods.IsMethod(method), "method argument must be a SIP method"); var cseqHeader = _headerFactory.CreateSCeqHeader(method, _localSequenceNr); var toAddress = _addressFactory.CreateAddress(null, _remoteUri); var toHeader = _headerFactory.CreateToHeader(toAddress, _remoteTag); var fromAddress = _addressFactory.CreateAddress(null, _localUri); var fromHeader = _headerFactory.CreateFromHeader(fromAddress, _localTag); var callIdheader = _headerFactory.CreateCallIdHeader(_callId); var viaHeader = viaheader ?? _headerFactory.CreateViaHeader(_listeningPoint, SipConstants.Udp, SipUtil.CreateBranch()); var requestUri = _remoteUri.Clone(); var maxForwardsHeader = _headerFactory.CreateMaxForwardsHeader(); var request = _messageFactory.CreateRequest( requestUri, method, callIdheader, cseqHeader, fromHeader, toHeader, viaHeader, maxForwardsHeader); foreach (var route in _routeSet) { request.Routes.Add(new SipRouteHeader() { SipUri = route.SipUri, Parameters = route.Parameters }); } return(request); }
protected SipRequest CreateRequest(string method) { /*create the 'INVITE' message*/ SipAddressFactory addressFactory = _stack.CreateAddressFactory(); SipHeaderFactory headerFactory = _stack.CreateHeaderFactory(); SipMessageFactory messageFactory = _stack.CreateMessageFactory(); SipUri senderSipUri = addressFactory.CreateUri(string.Empty, new IPEndPoint(_ipAddress, 12345).ToString()); SipAddress senderSipAddress = addressFactory.CreateAddress(string.Empty, senderSipUri); SipUri receiverSipUri = addressFactory.CreateUri(string.Empty, new IPEndPoint(_ipAddress, 23456).ToString()); SipAddress receiverSipAddress = addressFactory.CreateAddress(string.Empty, senderSipUri); SipToHeader toHeader = headerFactory.CreateToHeader(receiverSipAddress); SipFromHeader fromHeader = headerFactory.CreateFromHeader(senderSipAddress, SipUtil.CreateTag()); SipCSeqHeader cseqHeader = headerFactory.CreateSCeqHeader(method, 1); SipCallIdHeader callIdheader = headerFactory.CreateCallIdHeader(SipUtil.CreateCallId()); SipViaHeader viaHeader = headerFactory.CreateViaHeader(_ipAddress, 12345, SipConstants.Udp, SipUtil.CreateBranch()); SipMaxForwardsHeader maxForwardsHeader = headerFactory.CreateMaxForwardsHeader(); SipRequest request = messageFactory.CreateRequest( receiverSipUri, method, callIdheader, cseqHeader, fromHeader, toHeader, viaHeader, maxForwardsHeader); if (method == SipMethods.Invite) { SipContactHeader contactHeader = headerFactory.CreateContactHeader(senderSipUri); request.Contacts.Add(contactHeader); } return(request); }