Merge "SIP: Fix busy authentication loop." into gingerbread

This commit is contained in:
Hung-ying Tyan
2010-10-06 17:29:28 -07:00
committed by Android (Google) Code Review
2 changed files with 30 additions and 35 deletions

View File

@@ -825,11 +825,13 @@ public final class SipService extends ISipService.Stub {
synchronized (SipService.this) { synchronized (SipService.this) {
if (notCurrentSession(session)) return; if (notCurrentSession(session)) return;
if (errorCode == SipErrorCode.INVALID_CREDENTIALS) { switch (errorCode) {
if (DEBUG) Log.d(TAG, " pause auto-registration"); case SipErrorCode.INVALID_CREDENTIALS:
stop(); case SipErrorCode.SERVER_UNREACHABLE:
} else { if (DEBUG) Log.d(TAG, " pause auto-registration");
onError(); stop();
default:
restartLater();
} }
mErrorCode = errorCode; mErrorCode = errorCode;
@@ -846,11 +848,11 @@ public final class SipService extends ISipService.Stub {
mErrorCode = SipErrorCode.TIME_OUT; mErrorCode = SipErrorCode.TIME_OUT;
mProxy.onRegistrationTimeout(session); mProxy.onRegistrationTimeout(session);
onError(); restartLater();
} }
} }
private void onError() { private void restartLater() {
mRegistered = false; mRegistered = false;
restart(backoffDuration()); restart(backoffDuration());
if (mKeepAliveProcess != null) { if (mKeepAliveProcess != null) {

View File

@@ -96,8 +96,6 @@ class SipSessionGroup implements SipListener {
private SipStack mSipStack; private SipStack mSipStack;
private SipHelper mSipHelper; private SipHelper mSipHelper;
private String mLastNonce;
private int mRPort;
// session that processes INVITE requests // session that processes INVITE requests
private SipSessionImpl mCallReceiverSession; private SipSessionImpl mCallReceiverSession;
@@ -150,7 +148,6 @@ class SipSessionGroup implements SipListener {
Log.d(TAG, " start stack for " + myself.getUriString()); Log.d(TAG, " start stack for " + myself.getUriString());
stack.start(); stack.start();
mLastNonce = null;
mCallReceiverSession = null; mCallReceiverSession = null;
mSessionMap.clear(); mSessionMap.clear();
} }
@@ -366,8 +363,12 @@ class SipSessionGroup implements SipListener {
ClientTransaction mClientTransaction; ClientTransaction mClientTransaction;
String mPeerSessionDescription; String mPeerSessionDescription;
boolean mInCall; boolean mInCall;
boolean mReRegisterFlag = false;
SessionTimer mTimer; SessionTimer mTimer;
int mAuthenticationRetryCount;
// for registration
boolean mReRegisterFlag = false;
int mRPort;
// lightweight timer // lightweight timer
class SessionTimer { class SessionTimer {
@@ -417,6 +418,8 @@ class SipSessionGroup implements SipListener {
mState = SipSession.State.READY_TO_CALL; mState = SipSession.State.READY_TO_CALL;
mInviteReceived = null; mInviteReceived = null;
mPeerSessionDescription = null; mPeerSessionDescription = null;
mRPort = 0;
mAuthenticationRetryCount = 0;
if (mDialog != null) mDialog.delete(); if (mDialog != null) mDialog.delete();
mDialog = null; mDialog = null;
@@ -799,22 +802,10 @@ class SipSessionGroup implements SipListener {
onRegistrationDone((state == SipSession.State.REGISTERING) onRegistrationDone((state == SipSession.State.REGISTERING)
? getExpiryTime(((ResponseEvent) evt).getResponse()) ? getExpiryTime(((ResponseEvent) evt).getResponse())
: -1); : -1);
mLastNonce = null;
mRPort = 0;
return true; return true;
case Response.UNAUTHORIZED: case Response.UNAUTHORIZED:
case Response.PROXY_AUTHENTICATION_REQUIRED: case Response.PROXY_AUTHENTICATION_REQUIRED:
if (!handleAuthentication(event)) { handleAuthentication(event);
if (mLastNonce == null) {
onRegistrationFailed(SipErrorCode.SERVER_ERROR,
"server does not provide challenge");
} else {
Log.v(TAG, "Incorrect username/password");
onRegistrationFailed(
SipErrorCode.INVALID_CREDENTIALS,
"incorrect username or password");
}
}
return true; return true;
default: default:
if (statusCode >= 500) { if (statusCode >= 500) {
@@ -830,16 +821,24 @@ class SipSessionGroup implements SipListener {
throws SipException { throws SipException {
Response response = event.getResponse(); Response response = event.getResponse();
String nonce = getNonceFromResponse(response); String nonce = getNonceFromResponse(response);
if (((nonce != null) && nonce.equals(mLastNonce)) || if (nonce == null) {
(nonce == null)) { onError(SipErrorCode.SERVER_ERROR,
mLastNonce = nonce; "server does not provide challenge");
return false; return false;
} else { } else if (mAuthenticationRetryCount < 2) {
mClientTransaction = mSipHelper.handleChallenge( mClientTransaction = mSipHelper.handleChallenge(
event, getAccountManager()); event, getAccountManager());
mDialog = mClientTransaction.getDialog(); mDialog = mClientTransaction.getDialog();
mLastNonce = nonce; mAuthenticationRetryCount++;
if (isLoggable(this, event)) {
Log.d(TAG, " authentication retry count="
+ mAuthenticationRetryCount);
}
return true; return true;
} else {
onError(SipErrorCode.INVALID_CREDENTIALS,
"incorrect username or password");
return false;
} }
} }
@@ -995,12 +994,6 @@ class SipSessionGroup implements SipListener {
getRealmFromResponse(response)); getRealmFromResponse(response));
} else if (handleAuthentication(event)) { } else if (handleAuthentication(event)) {
addSipSession(this); addSipSession(this);
} else if (mLastNonce == null) {
onError(SipErrorCode.SERVER_ERROR,
"server does not provide challenge");
} else {
onError(SipErrorCode.INVALID_CREDENTIALS,
"incorrect username or password");
} }
return true; return true;
case Response.REQUEST_PENDING: case Response.REQUEST_PENDING: