本文整理汇总了C#中SIPSorcery.SIP.SIPResponse类的典型用法代码示例。如果您正苦于以下问题:C# SIPResponse类的具体用法?C# SIPResponse怎么用?C# SIPResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SIPResponse类属于SIPSorcery.SIP命名空间,在下文中一共展示了SIPResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsMagicJackRequest
public static bool IsMagicJackRequest(SIPResponse sipResponse) {
if (sipResponse.Header.AuthenticationHeader != null &&
sipResponse.Header.AuthenticationHeader.SIPDigest.Realm == "stratus.com" &&
sipResponse.Header.To != null &&
sipResponse.Header.To.ToURI != null &&
sipResponse.Header.To.ToURI.Host.ToLower() == "talk4free.com") {
return true;
}
return false;
}
示例2: SIPCancelTransaction_TransactionFinalResponseReceived
private void SIPCancelTransaction_TransactionFinalResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse)
{
if (sipResponse.StatusCode < 200)
{
logger.Warn("A SIP CANCEL transaction received an unexpected SIP information response " + sipResponse.ReasonPhrase + ".");
}
else
{
if (CancelTransactionFinalResponseReceived != null)
{
CancelTransactionFinalResponseReceived(localSIPEndPoint, remoteEndPoint, sipTransaction, sipResponse);
}
}
}
示例3: GetAuthenticationHeader
/// <summary>
/// MagicJack apply a custom algorithm when calculating their nonce seemingly in order to
/// prevent other SIP UAs from being able to authenticate. This method attempts to apply the same
/// algorithm to allow the authenticated requests from this stack.
/// </summary>
/// <remarks>
/// MJ is modifying the nonce dynamically. They append an underscore, then 8 characters to the nonce before computing the MD5. The 8 characters come from the call id.
/// Use the first 8 bytes of the nonce as an index into your call id.
/// Assume your callid is:
/// callid: 9876ABC56738DD43...
/// index: 0123456789ABCDEF
/// and your nonce is: 8765abc4_32190
/// Take the first digit of your nonce (which in our example is 8 ), and find the value in the callid at index 8, which is 6.
/// So, append that to the nonce. 8765abc4_32190_6
/// Then move on to the second digit of the nonce, which is 7 in our example. Find the value at index 7 in the callid, which is 5, and append that:
/// 8765abc4_32190_65 continue until you have done 8 digits. Your new nonce would be:
/// 8765abc4_32190_65CB38DA Use this value when computing the MD5, but pass the original nonce to magicJack.
/// </remarks>
/// <param name="authReqdResponse"></param>
/// <returns></returns>
public static SIPAuthenticationHeader GetAuthenticationHeader(SIPResponse authReqdResponse) {
try {
SIPAuthenticationHeader mjAuthHeader = new SIPAuthenticationHeader(authReqdResponse.Header.AuthenticationHeader.SIPDigest);
string origNonce = mjAuthHeader.SIPDigest.Nonce;
string mjNonce = GetNonce(origNonce, authReqdResponse.Header.CallId);
mjAuthHeader.SIPDigest.Nonce = mjNonce;
mjAuthHeader.SIPDigest.Response = mjAuthHeader.SIPDigest.Digest;
mjAuthHeader.SIPDigest.Nonce = origNonce;
return mjAuthHeader;
}
catch (Exception excp) {
logger.Error("Exception SIPProviderMagicJack GetAuthenticationHeader. " + excp.Message);
throw;
}
}
示例4: UACCallAnswered
private void UACCallAnswered(ISIPClientUserAgent answeredUAC, SIPResponse answeredResponse)
{
try
{
// Remove the current call from the pending list.
lock (m_switchCalls)
{
m_switchCalls.Remove(answeredUAC);
}
if (m_switchCallTransactions != null && answeredUAC.ServerTransaction != null)
{
m_switchCallTransactions.Add(answeredUAC.ServerTransaction);
}
if (answeredResponse != null && answeredResponse.StatusCode >= 200 && answeredResponse.StatusCode <= 299)
{
#region 2xx final response.
if (!m_callAnswered && !m_commandCancelled)
{
// This is the first call we've got an answer on.
m_callAnswered = true;
m_answeredUAC = answeredUAC;
AnsweredSIPResponse = answeredResponse;
SIPDialogueTransferModesEnum uasTransferMode = SIPDialogueTransferModesEnum.Default;
if (m_answeredUAC.CallDescriptor.TransferMode == SIPDialogueTransferModesEnum.NotAllowed)
{
answeredUAC.SIPDialogue.TransferMode = SIPDialogueTransferModesEnum.NotAllowed;
uasTransferMode = SIPDialogueTransferModesEnum.NotAllowed;
}
else if (m_answeredUAC.CallDescriptor.TransferMode == SIPDialogueTransferModesEnum.BlindPlaceCall)
{
answeredUAC.SIPDialogue.TransferMode = SIPDialogueTransferModesEnum.BlindPlaceCall;
uasTransferMode = SIPDialogueTransferModesEnum.BlindPlaceCall;
}
else if (m_answeredUAC.CallDescriptor.TransferMode == SIPDialogueTransferModesEnum.PassThru)
{
answeredUAC.SIPDialogue.TransferMode = SIPDialogueTransferModesEnum.PassThru;
uasTransferMode = SIPDialogueTransferModesEnum.PassThru;
}
/*else if (m_answeredUAC.CallDescriptor.TransferMode == SIPCallTransferModesEnum.Caller)
{
answeredUAC.SIPDialogue.TransferMode = SIPDialogueTransferModesEnum.NotAllowed;
uasTransferMode = SIPDialogueTransferModesEnum.Allowed;
}
else if (m_answeredUAC.CallDescriptor.TransferMode == SIPCallTransferModesEnum.Callee)
{
answeredUAC.SIPDialogue.TransferMode = SIPDialogueTransferModesEnum.Allowed;
uasTransferMode = SIPDialogueTransferModesEnum.NotAllowed;
}
else if (m_answeredUAC.CallDescriptor.TransferMode == SIPCallTransferModesEnum.Both)
{
answeredUAC.SIPDialogue.TransferMode = SIPDialogueTransferModesEnum.Allowed;
uasTransferMode = SIPDialogueTransferModesEnum.Allowed;
}*/
if (CallAnswered != null)
{
logger.Debug("Transfer mode=" + m_answeredUAC.CallDescriptor.TransferMode + ".");
CallAnswered(answeredResponse.Status, answeredResponse.ReasonPhrase, null, null, answeredResponse.Header.ContentType, answeredResponse.Body, answeredUAC.SIPDialogue, uasTransferMode);
}
// Cancel/hangup and other calls on this leg that are still around.
CancelNotRequiredCallLegs(CallCancelCause.NormalClearing);
}
else
{
// Call already answered or cancelled, hangup (send BYE).
FireProxyLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Call leg " + answeredUAC.CallDescriptor.Uri + " answered but call was already answered or cancelled, hanging up.", m_username));
SIPDialogue sipDialogue = new SIPDialogue(answeredUAC.ServerTransaction, m_username, m_adminMemberId);
sipDialogue.Hangup(m_sipTransport, m_outboundProxySocket);
}
#endregion
CallLegCompleted();
}
else if (answeredUAC.SIPDialogue != null)
{
// Google Voice calls create the dialogue without using a SIP response.
if (!m_callAnswered && !m_commandCancelled)
{
FireProxyLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Call leg for Google Voice call to " + answeredUAC.CallDescriptor.Uri + " answered.", m_username));
// This is the first call we've got an answer on.
m_callAnswered = true;
m_answeredUAC = answeredUAC;
if (CallAnswered != null)
{
CallAnswered(SIPResponseStatusCodesEnum.Ok, null, null, null, answeredUAC.SIPDialogue.ContentType, answeredUAC.SIPDialogue.RemoteSDP, answeredUAC.SIPDialogue, SIPDialogueTransferModesEnum.NotAllowed);
}
// Cancel/hangup and other calls on this leg that are still around.
CancelNotRequiredCallLegs(CallCancelCause.NormalClearing);
}
else
{
//.........这里部分代码省略.........
示例5: MagicJackAuthUnitTest
public void MagicJackAuthUnitTest()
{
Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
string nonce = "8765abc4_32190";
SIPResponse authReqdResponse = new SIPResponse(SIPResponseStatusCodesEnum.Unauthorised, null, null);
authReqdResponse.Header.CallId = "9876ABC56738DD43";
authReqdResponse.Header.AuthenticationHeader = SIPAuthenticationHeader.ParseSIPAuthenticationHeader(SIPAuthorisationHeadersEnum.WWWAuthenticate, "Digest nonce=\"" + nonce + "\",realm=\"stratus.com\",algorithm=MD5");
authReqdResponse.Header.AuthenticationHeader.SIPDigest.SetCredentials("username", "password", "sip:[email protected]", SIPMethodsEnum.INVITE.ToString());
Assert.IsTrue(SIPProviderMagicJack.IsMagicJackRequest(authReqdResponse), "The SIP Response was not correctly identified as being for a MagicJack request.");
string mjNonce = GetNonce(authReqdResponse.Header.AuthenticationHeader.SIPDigest.Nonce, authReqdResponse.Header.CallId);
SIPAuthenticationHeader mjAuthheader = SIPProviderMagicJack.GetAuthenticationHeader(authReqdResponse);
Assert.IsTrue(mjNonce == "8765abc4_32190_65CB38DA", "The MagicJack nonce was not correctly generated.");
Assert.IsTrue(authReqdResponse.Header.AuthenticationHeader.SIPDigest.Nonce == nonce, "The nonce set in the MagicJack response was not preserved correctly.");
Console.WriteLine("-----------------------------------------");
}
示例6: Dial
/// <summary>
///
/// </summary>
/// <param name="data"></param>
/// <param name="ringTimeout"></param>
/// <param name="answeredCallLimit"></param>
/// <param name="redirectMode"></param>
/// <param name="clientTransaction"></param>
/// <param name="keepScriptAlive">If false will let the dial plan engine know the script has finished and the call is answered. For applications
/// like Callback which need to have two calls answered it will be true.</param>
/// <returns></returns>
private DialPlanAppResult Dial(
string data,
int ringTimeout,
int answeredCallLimit,
SIPRequest clientRequest,
CRMHeaders contact)
{
if (m_dialPlanContext.IsAnswered)
{
Log("The call has already been answered the Dial command was not processed.");
return DialPlanAppResult.AlreadyAnswered;
}
else if (data.IsNullOrBlank())
{
Log("The dial string cannot be empty when calling Dial.");
return DialPlanAppResult.Error;
}
else if (m_callInitialisationCount > MAX_CALLS_ALLOWED)
{
Log("You have exceeded the maximum allowed calls for a dialplan execution.");
return DialPlanAppResult.Error;
}
else
{
Log("Commencing Dial with: " + data + ".");
DialPlanAppResult result = DialPlanAppResult.Unknown;
m_waitForCallCompleted = new ManualResetEvent(false);
SIPResponseStatusCodesEnum answeredStatus = SIPResponseStatusCodesEnum.None;
string answeredReason = null;
string answeredContentType = null;
string answeredBody = null;
SIPDialogue answeredDialogue = null;
SIPDialogueTransferModesEnum uasTransferMode = SIPDialogueTransferModesEnum.Default;
int numberLegs = 0;
QueueNewCallDelegate queueNewCall = (m_callManager != null) ? m_callManager.QueueNewCall : (QueueNewCallDelegate)null;
m_currentCall = new ForkCall(m_sipTransport, FireProxyLogEvent, queueNewCall, m_dialStringParser, Username, m_adminMemberId, m_outboundProxySocket, m_callManager, m_dialPlanContext, out LastDialled);
m_currentCall.CallProgress += m_dialPlanContext.CallProgress;
m_currentCall.CallFailed += (status, reason, headers) =>
{
LastFailureStatus = status;
LastFailureReason = reason;
result = DialPlanAppResult.Failed;
m_waitForCallCompleted.Set();
};
m_currentCall.CallAnswered += (status, reason, toTag, headers, contentType, body, dialogue, transferMode) =>
{
answeredStatus = status;
answeredReason = reason;
answeredContentType = contentType;
answeredBody = body;
answeredDialogue = dialogue;
uasTransferMode = transferMode;
result = DialPlanAppResult.Answered;
m_waitForCallCompleted.Set();
};
try
{
Queue<List<SIPCallDescriptor>> callsQueue = m_dialStringParser.ParseDialString(
DialPlanContextsEnum.Script,
clientRequest,
data,
m_customSIPHeaders,
m_customContentType,
m_customContent,
m_dialPlanContext.CallersNetworkId,
m_customFromName,
m_customFromUser,
m_customFromHost,
contact,
ServiceLevel);
List<SIPCallDescriptor>[] callListArray = callsQueue.ToArray();
callsQueue.ToList().ForEach((list) => numberLegs += list.Count);
if (numberLegs == 0)
{
Log("The dial string did not result in any call legs.");
return DialPlanAppResult.Error;
}
else
{
m_callInitialisationCount += numberLegs;
if (m_callInitialisationCount > MAX_CALLS_ALLOWED)
{
Log("You have exceeded the maximum allowed calls for a dialplan execution.");
//.........这里部分代码省略.........
示例7: SendResponse
public void SendResponse(SIPResponse sipResponse)
{
if (sipResponse.LocalSIPEndPoint != null && sipResponse.LocalSIPEndPoint.Address.Equals(BlackholeAddress))
{
// Ignore packet, it's destined for the blackhole.
return;
}
if (m_sipChannels.Count == 0)
{
throw new ApplicationException("No channels are configured in the SIP transport layer. The response could not be sent.");
}
//SIPChannel sipChannel = GetChannelForSocketId(sipResponse.SocketId);
SIPViaHeader topViaHeader = sipResponse.Header.Vias.TopViaHeader;
if (topViaHeader == null)
{
logger.Warn("There was no top Via header on a SIP response from " + sipResponse.RemoteSIPEndPoint + " when attempting to send it, response dropped.");
//logger.Warn(sipResponse.ToString());
}
else
{
SIPChannel sipChannel = FindSIPChannel(sipResponse.LocalSIPEndPoint);
sipChannel = sipChannel ?? GetDefaultChannel(topViaHeader.Transport);
if (sipChannel != null)
{
SendResponse(sipChannel, sipResponse);
}
else
{
throw new ApplicationException("Could not find a SIP channel to send SIP Response to " + topViaHeader.ReceivedFromAddress + ".");
}
}
}
示例8: GetResponse
/// <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;
}
}
示例9: ServerResponseReceived
/// <summary>
/// The event handler for responses to the initial register request.
/// </summary>
private void ServerResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse)
{
try
{
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.ContactRegisterInProgress, "Server response " + sipResponse.Status + " received for " + m_sipAccountAOR.ToString() + ".", m_owner));
if (sipResponse.Status == SIPResponseStatusCodesEnum.ProxyAuthenticationRequired || sipResponse.Status == SIPResponseStatusCodesEnum.Unauthorised)
{
if (sipResponse.Header.AuthenticationHeader != null)
{
if (m_attempts >= MAX_REGISTER_ATTEMPTS)
{
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.ContactRegisterFailed, "Registration to " + m_sipAccountAOR.ToString() + " reached the maximum number of allowed attempts without a failure condition.", m_owner));
m_isRegistered = false;
if (RegistrationTemporaryFailure != null)
{
RegistrationTemporaryFailure(m_sipAccountAOR, "Registration reached the maximum number of allowed attempts.");
}
m_waitForRegistrationMRE.Set();
}
else
{
m_attempts++;
SIPRequest authenticatedRequest = GetAuthenticatedRegistrationRequest(sipTransaction.TransactionRequest, sipResponse);
SIPNonInviteTransaction regAuthTransaction = m_sipTransport.CreateNonInviteTransaction(authenticatedRequest, sipTransaction.RemoteEndPoint, localSIPEndPoint, m_outboundProxy);
regAuthTransaction.NonInviteTransactionFinalResponseReceived += (lep, rep, tn, rsp) => { ThreadPool.QueueUserWorkItem(delegate { AuthResponseReceived(lep, rep, tn, rsp); }); };
regAuthTransaction.NonInviteTransactionTimedOut += (tn) => { ThreadPool.QueueUserWorkItem(delegate { RegistrationTimedOut(tn); }); };
m_sipTransport.SendSIPReliable(regAuthTransaction);
}
}
else
{
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.ContactRegisterFailed, "Registration failed with " + sipResponse.Status + " but no authentication header was supplied for " + m_sipAccountAOR.ToString() + ".", m_owner));
m_isRegistered = false;
if (RegistrationTemporaryFailure != null)
{
RegistrationTemporaryFailure(m_sipAccountAOR, "Registration failed with " + sipResponse.Status + " but no authentication header was supplied.");
}
m_waitForRegistrationMRE.Set();
}
}
else
{
if (sipResponse.Status == SIPResponseStatusCodesEnum.Ok)
{
if (m_expiry > 0)
{
m_isRegistered = true;
m_expiry = GetUpdatedExpiry(sipResponse);
//if (sipResponse.Header.SwitchboardToken != null && m_lastServerNonce != null)
//{
// SwitchboardToken = Crypto.SymmetricDecrypt(m_password, m_lastServerNonce, sipResponse.Header.SwitchboardToken);
//}
RegistrationSuccessful(m_sipAccountAOR);
}
else
{
m_isRegistered = false;
RegistrationRemoved(m_sipAccountAOR);
}
m_waitForRegistrationMRE.Set();
}
else if (sipResponse.Status == SIPResponseStatusCodesEnum.Forbidden || sipResponse.Status == SIPResponseStatusCodesEnum.NotFound)
{
// SIP account does not appear to exist.
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.ContactRegisterFailed, "Registration failed with " + sipResponse.Status + " for " + m_sipAccountAOR.ToString() + ", no further registration attempts will be made.", m_owner));
string reasonPhrase = (sipResponse.ReasonPhrase.IsNullOrBlank()) ? sipResponse.Status.ToString() : sipResponse.ReasonPhrase;
if (RegistrationFailed != null)
{
RegistrationFailed(m_sipAccountAOR, "Registration failed with " + (int)sipResponse.Status + " " + reasonPhrase + ".");
}
m_exit = true;
m_waitForRegistrationMRE.Set();
}
else if (sipResponse.Status == SIPResponseStatusCodesEnum.IntervalTooBrief && m_expiry != 0)
{
m_expiry = GetUpdatedExpiryForIntervalTooBrief(sipResponse);
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.ContactRegisterInProgress, "Registration for " + m_sipAccountAOR.ToString() + " had a too short expiry, updated to +" + m_expiry + " and trying again.", m_owner));
SendInitialRegister();
}
else
{
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.ContactRegisterFailed, "Registration failed with " + sipResponse.Status + " for " + m_sipAccountAOR.ToString() + ".", m_owner));
m_isRegistered = false;
if (RegistrationTemporaryFailure != null)
{
RegistrationTemporaryFailure(m_sipAccountAOR, "Registration failed with " + sipResponse.Status + ".");
}
m_waitForRegistrationMRE.Set();
}
}
}
catch (Exception excp)
{
logger.Error("Exception SIPRegistrationUserAgent ServerResponseReceived (" + remoteEndPoint + "). " + excp.Message);
}
//.........这里部分代码省略.........
示例10: GetUpdatedExpiryForIntervalTooBrief
private int GetUpdatedExpiryForIntervalTooBrief(SIPResponse sipResponse)
{
int newExpiry = sipResponse.Header.MinExpires;
if (newExpiry != 0 && newExpiry > m_expiry)
{
if(newExpiry > MAX_EXPIRY)
{
return MAX_EXPIRY;
}
else
{
return newExpiry;
}
}
else if(m_expiry < MAX_EXPIRY)
{
return m_expiry * 2;
}
return m_expiry;
}
示例11: GetUpdatedExpiry
private int GetUpdatedExpiry(SIPResponse sipResponse)
{
// Find the contact in the list that matches the one being maintained by this agent in order to determine the expiry value.
int serverExpiry = 0;
int headerExpires = sipResponse.Header.Expires;
int contactExpires = -1;
if (sipResponse.Header.Contact != null && sipResponse.Header.Contact.Count > 0)
{
if (sipResponse.Header.Contact.Count == 1)
{
contactExpires = sipResponse.Header.Contact[0].Expires;
}
else
{
foreach (SIPContactHeader contactHeader in sipResponse.Header.Contact)
{
if (contactHeader.ContactURI == m_contactURI)
{
contactExpires = contactHeader.Expires;
break;
}
}
}
}
if (contactExpires != -1)
{
serverExpiry = contactExpires;
}
else if (headerExpires != -1)
{
serverExpiry = headerExpires;
}
if (serverExpiry < REGISTER_MINIMUM_EXPIRY)
{
// Make sure we don't do a 3CX and send registration floods.
return REGISTER_MINIMUM_EXPIRY;
}
else if (serverExpiry > MAX_EXPIRY)
{
return MAX_EXPIRY;
}
else
{
return serverExpiry;
}
}
示例12: GetAuthenticatedRegistrationRequest
private SIPRequest GetAuthenticatedRegistrationRequest(SIPRequest registerRequest, SIPResponse sipResponse)
{
try
{
SIPAuthorisationDigest authRequest = sipResponse.Header.AuthenticationHeader.SIPDigest;
m_lastServerNonce = authRequest.Nonce;
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;
//if (RequestSwitchboardToken)
//{
// regRequest.Header.SwitchboardTokenRequest = m_expiry;
//}
return regRequest;
}
catch (Exception excp)
{
logger.Error("Exception GetAuthenticatedRegistrationRequest. " + excp.Message);
throw excp;
}
}
示例13: AuthResponseReceived
/// <summary>
/// The event handler for responses to the authenticated register request.
/// </summary>
private void AuthResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse)
{
try
{
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.ContactRegisterInProgress, "Server auth response " + sipResponse.Status + " received for " + m_sipAccountAOR.ToString() + ".", m_owner));
if (sipResponse.Status == SIPResponseStatusCodesEnum.Ok)
{
if (m_expiry > 0)
{
ServiceRoute = sipResponse.Header.ServiceRoute;
m_isRegistered = true;
m_expiry = GetUpdatedExpiry(sipResponse);
//if (sipResponse.Header.SwitchboardToken != null && m_lastServerNonce != null)
//{
// SwitchboardToken = Crypto.SymmetricDecrypt(m_password, m_lastServerNonce, sipResponse.Header.SwitchboardToken);
//}
if (RegistrationSuccessful != null)
{
RegistrationSuccessful(m_sipAccountAOR);
}
}
else
{
m_isRegistered = false;
if (RegistrationRemoved != null)
{
RegistrationRemoved(m_sipAccountAOR);
}
}
m_waitForRegistrationMRE.Set();
}
else if (sipResponse.Status == SIPResponseStatusCodesEnum.IntervalTooBrief && m_expiry != 0)
{
m_expiry = GetUpdatedExpiryForIntervalTooBrief(sipResponse);
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.ContactRegisterInProgress, "Registration for " + m_sipAccountAOR.ToString() + " had a too short expiry, updated to +" + m_expiry + " and trying again.", m_owner));
SendInitialRegister();
}
else if (sipResponse.Status == SIPResponseStatusCodesEnum.Forbidden || sipResponse.Status == SIPResponseStatusCodesEnum.NotFound || sipResponse.Status == SIPResponseStatusCodesEnum.PaymentRequired)
{
// SIP account does not appear to exist.
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.ContactRegisterFailed, "Registration failed with " + sipResponse.Status + " for " + m_sipAccountAOR.ToString() + ", no further registration attempts will be made.", m_owner));
string reasonPhrase = (sipResponse.ReasonPhrase.IsNullOrBlank()) ? sipResponse.Status.ToString() : sipResponse.ReasonPhrase;
if (RegistrationFailed != null)
{
RegistrationFailed(m_sipAccountAOR, "Registration failed with " + (int)sipResponse.Status + " " + reasonPhrase + ".");
}
m_exit = true;
m_waitForRegistrationMRE.Set();
}
else if (sipResponse.Status == SIPResponseStatusCodesEnum.ProxyAuthenticationRequired || sipResponse.Status == SIPResponseStatusCodesEnum.Unauthorised)
{
// SIP account credentials failed.
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.ContactRegisterFailed, "Registration failed with " + sipResponse.Status + " for " + m_sipAccountAOR.ToString() + ", no further registration attempts will be made.", m_owner));
string reasonPhrase = (sipResponse.ReasonPhrase.IsNullOrBlank()) ? sipResponse.Status.ToString() : sipResponse.ReasonPhrase;
if (RegistrationFailed != null)
{
RegistrationFailed(m_sipAccountAOR, "Registration failed with " + (int)sipResponse.Status + " " + reasonPhrase + ".");
}
m_exit = true;
m_waitForRegistrationMRE.Set();
}
else
{
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.ContactRegisterFailed, "Registration failed with " + sipResponse.Status + " for " + m_sipAccountAOR.ToString() + ".", m_owner));
m_isRegistered = false;
if (RegistrationTemporaryFailure != null)
{
RegistrationTemporaryFailure(m_sipAccountAOR, "Registration failed with " + sipResponse.Status + ".");
}
m_waitForRegistrationMRE.Set();
}
}
catch (Exception excp)
{
logger.Error("Exception SIPRegistrationUserAgent AuthResponseReceived. " + excp.Message);
}
}
示例14: ServerResponseReceived
private void ServerResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse)
{
try
{
string reasonPhrase = (sipResponse.ReasonPhrase.IsNullOrBlank()) ? sipResponse.Status.ToString() : sipResponse.ReasonPhrase;
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.DialPlan, "Server response " + sipResponse.StatusCode + " " + reasonPhrase + " received for " + sipTransaction.TransactionRequest.Method +" to " + m_callDescriptor.Uri + ".", m_owner));
if (sipResponse.Status == SIPResponseStatusCodesEnum.ProxyAuthenticationRequired || sipResponse.Status == SIPResponseStatusCodesEnum.Unauthorised)
{
if (sipResponse.Header.AuthenticationHeader != null)
{
if ((m_callDescriptor.Username != null || m_callDescriptor.AuthUsername != null) && m_callDescriptor.Password != null)
{
SIPRequest authenticatedRequest = GetAuthenticatedRequest(sipTransaction.TransactionRequest, sipResponse);
SIPNonInviteTransaction authTransaction = m_sipTransport.CreateNonInviteTransaction(authenticatedRequest, sipTransaction.RemoteEndPoint, localSIPEndPoint, m_outboundProxy);
authTransaction.NonInviteTransactionFinalResponseReceived += AuthResponseReceived;
authTransaction.NonInviteTransactionTimedOut += RequestTimedOut;
m_sipTransport.SendSIPReliable(authTransaction);
}
else
{
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.DialPlan, "Send request received an authentication required response but no credentials were available.", m_owner));
if (ResponseReceived != null)
{
ResponseReceived(sipResponse);
}
}
}
else
{
Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.UserAgentClient, SIPMonitorEventTypesEnum.DialPlan, "Send request failed with " + sipResponse.StatusCode + " but no authentication header was supplied for " + sipTransaction.TransactionRequest.Method + " to " + m_callDescriptor.Uri + ".", m_owner));
if (ResponseReceived != null)
{
ResponseReceived(sipResponse);
}
}
}
else
{
if (ResponseReceived != null)
{
ResponseReceived(sipResponse);
}
}
}
catch (Exception excp)
{
logger.Error("Exception SIPNonInviteClientUserAgent ServerResponseReceived (" + remoteEndPoint + "). " + excp.Message);
}
}
示例15: FireSIPResponseOutTraceEvent
private void FireSIPResponseOutTraceEvent(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPResponse sipResponse)
{
try
{
if (SIPResponseOutTraceEvent != null)
{
SIPResponseOutTraceEvent(localSIPEndPoint, remoteEndPoint, sipResponse);
}
}
catch (Exception excp)
{
logger.Error("Exception FireSIPResponseOutTraceEvent. " + excp.Message);
}
}