protected override void OnTestClientUaReceive(SipContext sipContext) { if (sipContext.Response.StatusLine.ResponseCode == SipResponseCodes.x180_Ringing) { if (_receivedRingingResponse == null) _receivedRingingResponse = sipContext.Response; } }
protected override void GivenOverride() { //((SipAbstractServerTransaction) Stx).Initialize(); _non200FinalResponse = CreateFinalResponse(302, "Moved Temporarily"); Stx.SendResponse(_non200FinalResponse); Stx.State.Should().Be(SipInviteServerTransaction.CompletedState); /*required assertion*/ }
public void SendResponse(SipResponse response) { Check.Require(response, "response"); var result = new SipValidator().ValidateMessage(response); if (!result.IsValid) { ThrowSipException(result); } var sendToEndPoint = SipProvider.DetermineSendTo(response); var bytes = SipFormatter.FormatMessage(response); SendBytes(bytes, sendToEndPoint); if (_logger.IsDebugEnabled) { _logger.Debug("Send response '{0}' --> {1}. # bytes:{2}.", response.StatusLine.StatusCode, sendToEndPoint, bytes.Length); } if (_responseSentObserver != null) { _responseSentObserver.OnNext(response); } }
protected override void GivenOverride() { //((SipAbstractServerTransaction) Stx).Initialize(); _provisionalResponse = CreateProvisionalResponse(); Stx.SendResponse(_provisionalResponse); Stx.State.Should().Be(SipInviteServerTransaction.ProceedingState); /*assertion*/ }
protected override void When() { /*force it to go into early state*/ _ringingResponse = CreateRingingResponse(); ServerDialog.SetLastResponse(_ringingResponse); ServerDialog.State.Should().Be(DialogState.Early); /*required assertion*/ }
internal SipResponse CreateResponse(SipStatusLine statusLine) { var response = new SipResponse() { StatusLine = statusLine }; return(response); }
private static IPEndPoint DetermineSendTo(SipResponse response) { var topMost = response.Vias.GetTopMost(); int port = topMost.Rport != -1 ? topMost.Rport : topMost.SentBy.Port; IPAddress ipAddress = topMost.Received ?? topMost.SentBy.Address; return(new IPEndPoint(ipAddress, port)); }
protected override void GivenOverride() { //((SipAbstractServerTransaction) Stx).Initialize(); _non200FinalResponse = CreateFinalResponse(302, "Moved Temporarily"); Stx.SendResponse(_non200FinalResponse); var ackRequest = new SipRequestBuilder().WithRequestLine( new SipRequestLineBuilder().WithMethod(SipMethods.Ack).Build()).Build(); Stx.ProcessRequest(new SipRequestEventBuilder().WithRequest(ackRequest).Build()); Stx.State.Should().Be(SipInviteServerTransaction.ConfirmedState); /*required assertion*/ }
protected override void OnTestClientUaReceive(SipContext sipContext) { if (sipContext.Response.StatusLine.ResponseCode == SipResponseCodes.x180_Ringing) { _receivedRingingResponse = sipContext.Response; } if (sipContext.Response.StatusLine.ResponseCode == SipResponseCodes.x200_Ok) { _waitingforOkReceived.Set(); } }
protected override void GivenOverride() { /*force it to go into confirmed state*/ _okResponse = CreateOkResponse(); _rer = new SipResponseEventBuilder().WithResponse(CreateRingingResponse()).WithClientTx(InviteCtx.Object).Build(); _reo = new SipResponseEventBuilder().WithResponse(_okResponse).WithClientTx(InviteCtx.Object).Build(); ClientDialog.ProcessResponse(_rer); ClientDialog.ProcessResponse(_reo); ClientDialog.State.Should().Be(DialogState.Confirmed); /*required assertion*/ _ackRequest = ClientDialog.CreateAck(); ClientDialog.SendAck(_ackRequest); /*sent an ack*/ _beforeSentSeqNr = ClientDialog.LocalSequenceNr; }
protected override void OnTestClientUaReceive(SipContext sipContext) { if (sipContext.Response.StatusLine.ResponseCode == SipResponseCodes.x180_Ringing) { _receivedRingingResponse = sipContext.Response; } if (sipContext.Response.StatusLine.ResponseCode == SipResponseCodes.x200_Ok) { _waitingforOkReceived.Set(); } if (sipContext.Response.StatusLine.ResponseCode == SipResponseCodes.x200_Ok && sipContext.Response.CSeq.Command == SipMethods.Bye) { _receivedOkByeResponse = sipContext.Response; _waitForByeReceived.Set(); } }
protected override void OnTestClientUaReceive(SipContext sipContext) { if (sipContext.Response != null && sipContext.Response.StatusLine.ResponseCode == SipResponseCodes.x180_Ringing) { _receivedRingingResponse = sipContext.Response; } if (sipContext.Response != null && sipContext.Response.StatusLine.ResponseCode == SipResponseCodes.x200_Ok) { _waitingforOkReceived.Set(); } if (sipContext.Request != null && sipContext.Request.RequestLine.Method == SipMethods.Bye) { _receivedBye = sipContext.Request; _waitForByeReceived.Set(); } }
private void SendErrorResponse(Exception exception, SipRequestEvent requestEvent) { Check.Require(exception, "exception"); Check.Require(requestEvent, "requestEvent"); Check.Require(requestEvent.Request, "requestEvent.Request"); var request = requestEvent.Request; var sipException = exception as SipException; string responseCode = sipException != null ? sipException.ResponseCode : SipResponseCodes.x500_Server_Internal_Error; SipResponse response = sipException != null?_stack.CreateMessageFactory().CreateResponse(request, responseCode) : _stack.CreateMessageFactory().CreateResponse(request, responseCode + ", " + exception.Message); if (requestEvent.ServerTransaction != null) { requestEvent.ServerTransaction.SendResponse(response); } else if (response.Vias.GetTopMost() != null) { IPEndPoint ipEndPoint = SipProvider.DetermineSendTo(response); try { _contextSource.SendTo(SipFormatter.FormatMessage(response), ipEndPoint); if (_responseSentObserver != null) { _responseSentObserver.OnNext(response); } } catch (SocketException err) { _logger.Error("Failed to send response to " + ipEndPoint.ToString(), err); } } else { _logger.Warn("Response can not be sent. Via TopMost header missing."); } }
public void SendResponse(SipResponse response) { Check.Require(response, "response"); var result = new SipValidator().ValidateMessage(response); if (!result.IsValid) ThrowSipException(result); var sendToEndPoint = SipProvider.DetermineSendTo(response); var bytes = SipFormatter.FormatMessage(response); SendBytes(bytes, sendToEndPoint); if (_logger.IsDebugEnabled) _logger.Debug("Send response '{0}' --> {1}. # bytes:{2}.", response.StatusLine.StatusCode, sendToEndPoint, bytes.Length); if (_responseSentObserver != null) _responseSentObserver.OnNext(response); }
private void AddContactHeader(SipResponse response) { var contactHeader = new SipContactHeaderBuilder().WithSipUri(TestConstants.BobContactUri).Build(); response.Contacts.Add(contactHeader); }
private bool IsResponseToInvite(SipResponse message) { return(message.CSeq.Command == SipMethods.Invite); }
private static IPEndPoint DetermineSendTo(SipResponse response) { var topMost = response.Vias.GetTopMost(); int port = topMost.Rport != -1 ? topMost.Rport : topMost.SentBy.Port; IPAddress ipAddress = topMost.Received ?? topMost.SentBy.Address; return new IPEndPoint(ipAddress, port); }
public void ProcessResponse(SipResponse sipResponse, SipContext context) { lock (_locker) Responses.Add(sipResponse); _onRecievedResponse(sipResponse, context); }
protected override void When() { _busyHereResponse = CreateBusyHereResponse(); ServerDialog.SetLastResponse(_busyHereResponse); }
protected override void When() { _non200FinalResponse = CreateFinalResponse(302, "Moved Temporarily"); Stx.SendResponse(_non200FinalResponse); }
protected override void When() { _provisionalResponse = CreateProvisionalResponse(); Stx.SendResponse(_provisionalResponse); }
protected override void When() { _finalResponse = CreateFinalResponse(); Stx.SendResponse(_finalResponse); }
protected override void When() { _mostRecentResponse = CreateProvisionalResponse(181, "Call Is Being Forwarded"); Stx.SendResponse(_mostRecentResponse); }
protected override void When() { _mostRecentResponse = CreateFinalResponse(202, "accepted"); Stx.SendResponse(_mostRecentResponse); }
public SipResponse CreateResponse(string responseCode) { //Contract.Requires(!string.IsNullOrWhiteSpace(responseCode)); if (this.RequestLine.Method == SipMethods.Ack) { throw new InvalidOperationException(ExceptionMessage.AckRequestCanNotHaveAResponse); } int wsIndex = responseCode.IndexOf(' '); int code = int.Parse(responseCode.Substring(0, wsIndex + 1)); string reason = responseCode.Substring(wsIndex + 1); /* RFC 3261 8.2.6.1. * When a 100 (Trying) response is generated, any Timestamp header field * present in the request MUST be copied into this 100 (Trying) * response. * * RFC 3261 8.2.6.2. * The From field of the response MUST equal the From header field of * the request. The Call-ID header field of the response MUST equal the * Call-ID header field of the request. The CSeq header field of the * response MUST equal the CSeq field of the request. The Via header * field values in the response MUST equal the Via header field values * in the request and MUST maintain the same ordering. * * If a request contained a To tag in the request, the To header field * in the response MUST equal that of the request. However, if the To * header field in the request did not contain a tag, the URI in the To * header field in the response MUST equal the URI in the To header * field; additionally, the UAS MUST add a tag to the To header field in * the response (with the exception of the 100 (Trying) response, in * which a tag MAY be present). This serves to identify the UAS that is * responding, possibly resulting in a component of a dialog ID. The * same tag MUST be used for all responses to that request, both final * and provisional (again excepting the 100 (Trying)). Procedures for * the generation of tags are defined in Section 19.3. * * RFC 3261 12.1.1. * When a UAS responds to a request with a response that establishes a * dialog (such as a 2xx to INVITE), the UAS MUST copy all Record-Route * header field values from the request into the response (including the * URIs, URI parameters, and any Record-Route header field parameters, * whether they are known or unknown to the UAS) and MUST maintain the * order of those values. */ SipResponse response = new SipResponse(); response.StatusLine.StatusCode = code; response.StatusLine.ReasonPhrase = reason; response.StatusLine.Version = SipConstants.SipTwoZeroString; foreach (var viaHeader in this.Vias) { response.Vias.Add(CloneHeader(viaHeader)); } response.From = CloneHeader(this.From); response.To = CloneHeader(this.To); //TODO: write out same tag for all response to this request if (this.To != null && this.To.Tag == null) { response.To.Tag = SipUtil.CreateTag(); } response.CallId = CloneHeader(this.CallId); response.CSeq = CloneHeader(this.CSeq); response.MaxForwards = CloneHeader(this.MaxForwards); //TODO: record route return(response); }
public bool ParseFirstLine() { _reader.Consume('\r', '\n'); if (!_reader.Contains('\n')) throw new ParseException("Invalid firstline."); var firstLine = _reader.ReadFoldedLine(); if (firstLine.EndsWith(SipConstants.SipTwoZeroString)) { SipRequestLine requestLine = new SipRequestLineParser().Parse(firstLine); _listener.OnRequest(requestLine); } else if (firstLine.StartsWith(SipConstants.SipTwoZeroString)) { var message = new SipResponse(); var statusLine = new SipStatusLineParser().Parse(firstLine); _listener.OnResponse(statusLine); } else { throw new ParseException(ExceptionMessage.InvalidFirstLineFormat); } _parserMethod = GetHeaderName; return true; }
protected override void GivenOverride() { _response = CreateProvisionalResponse(); Stx.SendResponse(_response); /*force it to go into state*/ Stx.State.Should().Be(SipNonInviteServerTransaction.ProceedingState); /*required assertion*/ }
private bool IsResponseToInvite(SipResponse message) { return message.CSeq.Command == SipMethods.Invite; }
/// <summary> /// creates a ack. this is to be sent by the testclient UA /// </summary> /// <param name="invite"></param> /// <param name="ringing"></param> /// <returns></returns> protected SipRequest CreateAckRequest(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.Ack, 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 = invite.Vias.GetTopMost(); var requestUri = remoteUri.Clone(); var maxForwardsHeader = headerFactory.CreateMaxForwardsHeader(); var request = messageFactory.CreateRequest( requestUri, SipMethods.Ack, 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 override void When() { _originalResponse = new SipRequestBuilder().Build().CreateResponse(SipResponseCodes.x200_Ok); var bytes = SipFormatter.FormatMessage(_originalResponse); _sipResponse = _parser.Parse(new DatagramPacketBuilder().WithDataBytes(bytes).Build()) as SipResponse; }
private void OnRecievedResponse(SipResponse sipResponse, SipContext sipContext) { }
internal void Update(SipRequestEvent requestEvent) { Response = requestEvent.Response; IsHandled = requestEvent.IsHandled; IsSent = requestEvent.IsSent; }
protected override void When() { _okResponse = CreateOkResponse(); ServerDialog.SetLastResponse(_okResponse); }
protected override void When() { Request = new SipRequestBuilder().Build(); _response = Request.CreateResponse(SipResponseCodes.x200_Ok); }
protected override void When() { _okResponse = CreateBusyHereResponse(); var c = new SipContextBuilder().WithResponse(_okResponse).Build(); ClientDialog.ProcessResponse(new SipResponseEvent(c)); }
internal SipResponse CreateResponse(SipStatusLine statusLine) { var response = new SipResponse() { StatusLine = statusLine }; return response; }