From 8f3c87eaa3c152aa2a0755718c297a43714f2385 Mon Sep 17 00:00:00 2001 From: "relyea%netscape.com" Date: Sat, 16 Feb 2002 00:29:37 +0000 Subject: [PATCH] Use timers to determine whether or not to do the smart card present checks or not. bob --- security/nss/lib/dev/devt.h | 3 ++- security/nss/lib/dev/devtoken.c | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/security/nss/lib/dev/devt.h b/security/nss/lib/dev/devt.h index 88acc7cfc936..b2f5fec59db7 100644 --- a/security/nss/lib/dev/devt.h +++ b/security/nss/lib/dev/devt.h @@ -35,7 +35,7 @@ #define DEVT_H #ifdef DEBUG -static const char DEVT_CVS_ID[] = "@(#) $RCSfile: devt.h,v $ $Revision: 1.9 $ $Date: 2002/02/01 17:25:11 $ $Name: $"; +static const char DEVT_CVS_ID[] = "@(#) $RCSfile: devt.h,v $ $Revision: 1.10 $ $Date: 2002/02/16 00:29:37 $ $Name: $"; #endif /* DEBUG */ /* @@ -131,6 +131,7 @@ struct NSSTokenStr void *epv; nssSession *defaultSession; NSSTrustDomain *trustDomain; + PRIntervalTime lastTime; #ifdef NSS_3_4_CODE PK11SlotInfo *pk11slot; nssList *certList; /* local cache of certs for slow tokens */ diff --git a/security/nss/lib/dev/devtoken.c b/security/nss/lib/dev/devtoken.c index ce95822c0391..c7f4f5e11288 100644 --- a/security/nss/lib/dev/devtoken.c +++ b/security/nss/lib/dev/devtoken.c @@ -32,7 +32,7 @@ */ #ifdef DEBUG -static const char CVS_ID[] = "@(#) $RCSfile: devtoken.c,v $ $Revision: 1.6 $ $Date: 2002/02/04 21:57:03 $ $Name: $"; +static const char CVS_ID[] = "@(#) $RCSfile: devtoken.c,v $ $Revision: 1.7 $ $Date: 2002/02/16 00:29:37 $ $Name: $"; #endif /* DEBUG */ #ifndef DEV_H @@ -207,11 +207,25 @@ nssToken_IsPresent nssSession *session; CK_SLOT_INFO slotInfo; NSSSlot *slot = token->slot; + PRIntervalTime time,lastTime; + static PRIntervalTime delayTime = 0; + session = token->defaultSession; /* permanent slots are always present */ if (nssSlot_IsPermanent(slot) && session != CK_INVALID_SESSION) { return PR_TRUE; } + + if (delayTime == 0) { + delayTime = PR_SecondsToInterval(10); + } + + time = PR_IntervalNow(); + lastTime = token->lastTime; + if ((time > lastTime) && ((time - lastTime) < delayTime)) { + return (PRBool) ((slot->ckFlags & CKF_TOKEN_PRESENT) != 0); + } + token->lastTime = time; nssSession_EnterMonitor(session); /* First obtain the slot info */ ckrv = CKAPI(slot)->C_GetSlotInfo(slot->slotID, &slotInfo);