|
53 | 53 | import android.javax.sip.address.Address; |
54 | 54 | import android.javax.sip.address.AddressFactory; |
55 | 55 | import android.javax.sip.header.CSeqHeader; |
| 56 | +import android.javax.sip.header.CallIdHeader; |
56 | 57 | import android.javax.sip.header.ContactHeader; |
57 | 58 | import android.javax.sip.header.ContentTypeHeader; |
58 | 59 | import android.javax.sip.header.HeaderFactory; |
@@ -91,6 +92,8 @@ enum CallDirection { |
91 | 92 | private HashMap<String,String> customHeaders; |
92 | 93 | private ClientTransaction currentClientTransaction = null; |
93 | 94 | private ServerTransaction currentServerTransaction; |
| 95 | + private static final int MAX_REGISTER_ATTEMPTS = 3; |
| 96 | + HashMap<String, Integer> registerAuthenticationMap = new HashMap<>(); |
94 | 97 | public int ackCount = 0; |
95 | 98 | DigestServerAuthenticationHelper dsam; |
96 | 99 | // Is it an outgoing call or incoming call. We're using this so that when we hit |
@@ -501,10 +504,21 @@ public void processResponse(ResponseEvent arg0) { |
501 | 504 | sipProfile.getRemoteIp(), sipProfile |
502 | 505 | .getSipPassword()), headerFactory); |
503 | 506 | try { |
504 | | - ClientTransaction inviteTid = authenticationHelper |
505 | | - .handleChallenge(response, tid, sipProvider, 5, true); |
506 | | - currentClientTransaction = inviteTid; |
507 | | - inviteTid.sendRequest(); |
| 507 | + CallIdHeader callId = (CallIdHeader)response.getHeader("Call-ID"); //responseDialog.getCallId(); |
| 508 | + int attempts = 0; |
| 509 | + if (registerAuthenticationMap.containsKey(callId.toString())) { |
| 510 | + attempts = registerAuthenticationMap.get(callId.toString()).intValue(); |
| 511 | + } |
| 512 | + |
| 513 | + // we 're subtracting one since the first attempt has already taken place |
| 514 | + // (that way we are enforcing MAX_REGISTER_ATTEMPTS at most) |
| 515 | + if (attempts < MAX_REGISTER_ATTEMPTS - 1) { |
| 516 | + ClientTransaction inviteTid = authenticationHelper |
| 517 | + .handleChallenge(response, tid, sipProvider, 5, true); |
| 518 | + currentClientTransaction = inviteTid; |
| 519 | + inviteTid.sendRequest(); |
| 520 | + registerAuthenticationMap.put(callId.toString(), attempts + 1); |
| 521 | + } |
508 | 522 | } catch (NullPointerException e) { |
509 | 523 | e.printStackTrace(); |
510 | 524 | } catch (SipException e) { |
@@ -544,7 +558,12 @@ public void processResponse(ResponseEvent arg0) { |
544 | 558 | e.printStackTrace(); |
545 | 559 | } |
546 | 560 |
|
547 | | - } else if (cseq.getMethod().equals(Request.CANCEL)) { |
| 561 | + } |
| 562 | + else if (cseq.getMethod().equals(Request.REGISTER)) { |
| 563 | + // we got 200 OK to register request, clear the map |
| 564 | + registerAuthenticationMap.clear(); |
| 565 | + } |
| 566 | + else if (cseq.getMethod().equals(Request.CANCEL)) { |
548 | 567 | if (dialog.getState() == DialogState.CONFIRMED) { |
549 | 568 | // oops cancel went in too late. Need to hang up the |
550 | 569 | // dialog. |
|
0 commit comments