private void ConvAddBuddy_MsgRcv(object sender, ConversationArgs e) { SipMessage sipMsg = e.RawPacket; SipResponse rsp = sipMsg as SipResponse; string result = string.Empty; if (rsp != null) { Log.WriteLog(LogFile.Debug, string.Format("addbuddy result:{0}", e.RawPacket)); if (rsp.StatusCode == 200) { XDocument doc = XDocument.Parse(e.Text); if (doc.Element("results").Element("contacts") != null) { var buddies = doc.Element("results").Element("contacts").Element("buddies").Elements("buddy"); foreach (var buddy in buddies) { string localname = buddy.Attribute("local-name").Value; string userid = buddy.Attribute("user-id").Value; string uri = buddy.Attribute("uri").Value; result = uri; } } } if (this.AddBuddyResult != null) { ConversationArgs resultArg = new ConversationArgs(IMType.AddBuddyResult, rsp); resultArg.Text = result; this.AddBuddyResult(this, resultArg); this.convAddBuddy.MsgRcv -= new EventHandler <ConversationArgs>(this.ConvAddBuddy_MsgRcv); } } }
protected override void GivenOverride() { //((SipAbstractServerTransaction) Stx).Initialize(); _non200FinalResponse = CreateFinalResponse(302, "Moved Temporarily"); Stx.SendResponse(_non200FinalResponse); Stx.State.Should().Be(SipInviteServerTransaction.CompletedState); /*required assertion*/ }
private void ConvGetContactInfo_MsgRcv(object sender, ConversationArgs e) { SipResponse rsp = e.RawPacket as SipResponse; if (rsp.StatusCode != 200) { Log.WriteLog(LogFile.Trace, "未能获取该好友详细信息"); return; } XDocument doc = XDocument.Parse(e.Text); if (doc.Element("results").Elements("contact").Count() > 0) { foreach (var c in doc.Element("results").Elements("contact")) { SipUri uri = new SipUri(c.Attribute("uri").Value); string userid = c.Attribute("user-id").Value; string mobile = c.Attribute("mobile-no") != null?c.Attribute("mobile-no").Value : string.Empty; string name = c.Attribute("name").Value; string nickname = c.Attribute("nickname").Value; string impresa = c.Attribute("impresa").Value; Contact contact = new Contact(uri, userid, string.Empty, nickname, ContactType.Buddy); if (!string.IsNullOrEmpty(mobile)) { contact.MobileNo = long.Parse(mobile); } contact.Impresa = impresa; this.user.ContactsManager.Add(contact); } this.convGetContactInfo.MsgRcv -= new EventHandler <ConversationArgs>(this.ConvGetContactInfo_MsgRcv); } }
internal override StateResult HandleResponse(SipInviteClientTransaction ctx, SipResponse response) { var statusCode = response.StatusLine.StatusCode; if (statusCode >= 100 && statusCode < 200) { ctx.ChangeState(SipInviteClientTransaction.ProceedingState); return new StateResult() {InformToUser = true}; } if (statusCode >= 200 && statusCode < 300) { ctx.ChangeState(SipInviteClientTransaction.TerminatedState); return new StateResult() {InformToUser = true, Dispose = true}; } if (statusCode >= 300 && statusCode < 700) { ctx.ChangeState(SipInviteClientTransaction.CompletedState); ctx.SendAck(); return new StateResult() {InformToUser = true}; } return new StateResult() {}; }
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*/ }
internal override StateResult HandleResponse(SipInviteClientTransaction ctx, SipResponse response) { var statusCode = response.StatusLine.StatusCode; if (statusCode >= 300 && statusCode < 700) { ctx.SendAck(); } return new StateResult() {}; }
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(); } }
internal override void HandleSendingResponse(SipNonInviteServerTransaction tx, SipResponse response) { var statusCode = response.StatusLine.StatusCode; if (statusCode >= 100 && statusCode < 200) { tx.SendResponseInternal(response); } else if (statusCode >= 200 && statusCode < 700) { tx.SendResponseInternal(response); tx.ChangeState(SipNonInviteServerTransaction.CompletedState); } }
internal override StateResult HandleResponse(SipNonInviteClientTransaction ctx, SipResponse response) { var statusCode = response.StatusLine.StatusCode; if (statusCode >= 100 && statusCode < 200) { ctx.ChangeState(SipNonInviteClientTransaction.ProceedingState); } else if (statusCode >= 200 && statusCode < 700) { ctx.ChangeState(SipNonInviteClientTransaction.CompletedState); } return new StateResult() { InformToUser = true }; }
/// <summary> /// Initialize new SIP response. /// </summary> /// <param name="sipRequest">SIP request from which SIP response will be created.</param> /// <param name="statusCode">SIP response status code.</param> /// <returns>SIP response message.</returns> public static SipResponse GetResponse(this SipRequest sipRequest, StatusCode statusCode) { StatusLine sl = new StatusLine(statusCode); SipResponse response = new SipResponse(sl); // required response headers response.Headers.From = sipRequest.Headers.From; response.Headers.CallId = sipRequest.Headers.CallId; response.Headers.CSeq = sipRequest.Headers.CSeq; response.Headers.Via = sipRequest.Headers.Via; response.Headers.To = sipRequest.Headers.To; response.Headers.ContentLength = 0; return(response); }
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 SendRinging() { if (_ringingResponse == null) { _ringingResponse = _inviteRequest.CreateResponse(SipResponseCodes.x180_Ringing); _ringingResponse.To.Tag = SipUtil.CreateTag(); var contactUri = AddressFactory.CreateUri("", MainForm.SipProvider.ListeningPoint.ToString()); _ringingResponse.Contacts.Add(HeaderFactory.CreateContactHeader(contactUri)); _inviteTransaction = (SipInviteServerTransaction)SipProvider.CreateServerTransaction(_inviteRequest); _dialog = SipProvider.CreateServerDialog(_inviteTransaction); _inviteTransaction.SendResponse(_ringingResponse); } else { _inviteTransaction.SendResponse(_ringingResponse); } }
private void ConvDeleteBuddy_MsgRcv(object sender, ConversationArgs e) { SipResponse rsp = e.RawPacket as SipResponse; if (rsp != null) { XmlDocument document = new XmlDocument(); document.LoadXml(rsp.Body); XmlNode node = document.SelectSingleNode("results/contacts/buddies/buddy"); if (node != null) { string uri = XmlHelper.ReadXmlAttributeString(node, "uri"); if (!string.IsNullOrEmpty(uri)) { this.user.ContactsManager.Delete(new SipUri(uri)); } } ConversationArgs resultArg = new ConversationArgs(IMType.DeleteBuddyResult, rsp); resultArg.Text = rsp.StatusCode.ToString(); this.DeleteBuddyResult(this, resultArg); this.convDeleteBuddy.MsgRcv -= new EventHandler <ConversationArgs>(this.ConvDeleteBuddy_MsgRcv); } }
internal override StateResult HandleSendingResponse(SipInviteServerTransaction tx, SipResponse response) { var stateResult = new StateResult(); var statusCode = response.StatusLine.StatusCode; if (statusCode >= 100 && statusCode < 200) { tx.SendResponseInternal(response); } else if (statusCode >= 200 && statusCode < 300) { tx.SendResponseInternal(response); stateResult.Dispose = true; } else if (statusCode >= 300 && statusCode < 700) { tx.SendResponseInternal(response); tx.ChangeState(SipInviteServerTransaction.CompletedState); } return stateResult; }
internal override StateResult HandleSendingResponse(SipInviteServerTransaction transaction, SipResponse response) { throw new InvalidOperationException(); }
internal abstract StateResult HandleResponse(SipNonInviteClientTransaction ctx, SipResponse response);
protected void CheckFirstResponse(SipResponse response) { Check.Require(response, "response"); Check.IsTrue(response.CSeq.Command == SipMethods.Invite, "The response can not have a command other then 'INVITE'"); Check.IsTrue(response.StatusLine.StatusCode != 100, "The response can not be 'TRYING'"); //Check.IsTrue(response.StatusLine.StatusCode / 100 == 1, "The response must be provisonal"); /*a phone can immediately send busy here response to an invite request*/ Check.IsTrue(response.From.Tag != null, "From must have a tag"); Check.IsTrue(response.To.Tag != null, "To must have a tag"); Check.IsTrue(response.Contacts.GetTopMost() != null, "The response must have a Contact header."); }
public abstract void SendResponse(SipResponse response);
public void ProcessResponse(SipResponse response) { _state.ProcessResponse(response); }
public override void SetLastResponse(SipResponse response) { if (_logger.IsDebugEnabled) _logger.Debug("ServerDialog[Id={0}]. Reponse[StatusCode:'{1}']", GetId(), response.StatusLine.StatusCode); Check.Require(response, "response"); if (response.StatusLine.StatusCode == 100) { if (_logger.IsDebugEnabled) _logger.Debug("ServerDialog[Id={0}]. StatusCode == 100. Ignoring 'TRYING' response"); return; } bool terminate = false; lock(_lock) { var newResponseState = GetCorrespondingState(response.StatusLine.StatusCode); if (_firstResponse == null) { CheckFirstResponse(response); _firstResponse = response; SetDialogProps(); } if(newResponseState > _state) { if (_logger.IsInfoEnabled) _logger.Info("ServerDialog[Id={0}]: State Transition: '{1}'-->'{2}'", GetId(), _state, newResponseState); _state = newResponseState; if (_state == DialogState.Early) { if (!_dialogTable.TryAdd(GetId(), this)) { throw new SipCoreException("Could not add ServerDialog[Id={0}] to table, because it already exists.", GetId()); } if (_logger.IsDebugEnabled) _logger.Debug("ServerDialog[Id={0}] added to table.", GetId()); } else if (_state == DialogState.Confirmed) { if (_logger.IsDebugEnabled) _logger.Debug("ServerDialog[Id={0}]. RETRANSMIT_OK & WAIT_FOR_ACK timers started.", GetId()); _okResponse = response; /*start timers*/ _retransmitOkTimer.Start(); //_endWaitForAckTimer.Start(); } else if (_state == DialogState.Terminated) { terminate = true; } } } if(terminate) { //terminate outside of lock, to prevent from deadlock !! //(terminate is a public method and uses a lock) Terminate(); } }
private SipMessage ProcessFirstLine(string firstLine) { if (firstLine.EndsWith(SipConstants.SipTwoZeroString)) { var message = new SipRequest(); SipRequestLine requestLine = new SipRequestLineParser().Parse(firstLine); message.RequestLine = requestLine; return message; } else if (firstLine.StartsWith(SipConstants.SipTwoZeroString)) { var message = new SipResponse(); var statusLine = new SipStatusLineParser().Parse(firstLine); message.StatusLine = statusLine; return message; } throw new SipParseException(ExceptionMessage.InvalidFirstLineFormat); }
public override void SendResponse(SipResponse response) { StateResult result; if(LatestResponse == null) { Initialize(); } lock (_lock) { /*thread-safety is assured*/ result = _state.HandleSendingResponse(this, response); } if(result.Dispose) { Dispose(); } if (GetDialog() != null) { GetDialog().SetLastResponse(response); } }
internal override void HandleSendingResponse(SipNonInviteServerTransaction transaction, SipResponse response) { /*Final responses passed by the TU to the server transaction MUST be discarded while in the "Completed" state.*/ }
public abstract void SetLastResponse(SipResponse response);
public abstract void ProcessResponse(SipResponse response);
public override void SendResponse(SipResponse response) { lock(_lock) { /*thread-safety is assured*/ if(_state == null) Initialize(); _state.HandleSendingResponse(this, response); } }
internal override StateResult HandleSendingResponse(SipInviteServerTransaction transaction, SipResponse response) { return new StateResult(); }
internal abstract void HandleSendingResponse(SipNonInviteServerTransaction transaction, SipResponse response);
public override void ProcessResponse(SipResponse response) { _transaction.GoToState(this, new ProceedingState(_transaction)); }
internal override StateResult HandleSendingResponse(SipInviteServerTransaction transaction, SipResponse response) { //in this state the uas is not suposed to sent anymore throw new InvalidOperationException(); }
protected void SendResponseInternal(SipResponse response = null) { if (response != null) { if (LatestResponse != null) { //update the latestresponse only when it is a provisional response if (LatestResponse.StatusLine.StatusCode < 200) LatestResponse = response; } else { LatestResponse = response; } } _messageSender.SendResponse(LatestResponse); }
internal abstract StateResult HandleSendingResponse(SipInviteServerTransaction transaction, SipResponse response);
public override void ProcessResponse(SipResponse response) { throw new NotImplementedException(); }
internal override StateResult HandleResponse(SipInviteClientTransaction ctx, SipResponse response) { //a ringing response is received after, an ok. TODO: add logging. return new StateResult(); }
public override void SetLastResponse(SipResponse response) { if (_logger.IsDebugEnabled) _logger.Debug("ClientDialog[Id={0}]. Reponse[StatusCode:'{1}']", GetId(), response.StatusLine.StatusCode); Check.Require(response, "response"); if (response.StatusLine.StatusCode == 100) { if (_logger.IsDebugEnabled) _logger.Debug("StatusCode == 100. Ignoring 'TRYING' response"); return; } bool terminate = false; lock (_lock) { var newResponseState = GetCorrespondingState(response.StatusLine.StatusCode); if (_firstResponse == null) { CheckFirstResponse(response); _firstResponse = response; SetDialogProps(); } if (newResponseState > _state) { if (_logger.IsInfoEnabled) _logger.Info("ClientDialog[Id={0}]: State Transition: '{1}'-->'{2}'", GetId(), _state, newResponseState); if (_state == DialogState.Null && (newResponseState == DialogState.Early || newResponseState == DialogState.Confirmed)) /*it is possible to receive an 'OK' without first receiving a 'RINGING'.*/ { if (!_dialogTable.TryAdd(GetId(), this)) { throw new SipCoreException("Could not add ClientDialog[Id={0}] to table, because it already exists.", GetId()); } if (_logger.IsDebugEnabled) _logger.Debug("ClientDialog[Id={0}] added to table.", GetId()); } else if (newResponseState == DialogState.Terminated) { terminate = true; } _state = newResponseState; } } if (terminate) { //terminate outside of lock, to prevent from deadlock !! //terminate is public method and uses a lock !! Terminate(); } }
internal override StateResult HandleResponse(SipNonInviteClientTransaction ctx, SipResponse response) { return new StateResult(){ InformToUser = true }; }
private bool IsMatchByDialogId(SipResponse response) { return GetId() == SipProvider.GetDialogId(response, this is SipInviteServerDialog); }