token->name[0] = 0;
nssToken_IsPresent(  NSSToken *token){    CK_RV ckrv;    PRStatus nssrv;    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);    if (ckrv != CKR_OK) {	nssSession_ExitMonitor(session);	return PR_FALSE;    }    slot->ckFlags = slotInfo.flags;    /* check for the presence of the token */    if ((slot->ckFlags & CKF_TOKEN_PRESENT) == 0) {	/* token is not present */	if (session->handle != CK_INVALID_SESSION) {	    /* session is valid, close and invalidate it */	    CKAPI(slot)->C_CloseSession(session->handle);	    session->handle = CK_INVALID_SESSION;	}	nssSession_ExitMonitor(session);	return PR_FALSE;    }    /* token is present, use the session info to determine if the card     * has been removed and reinserted.     */    if (session != CK_INVALID_SESSION) {	CK_SESSION_INFO sessionInfo;	ckrv = CKAPI(slot)->C_GetSessionInfo(session->handle, &sessionInfo);	if (ckrv != CKR_OK) {	    /* session is screwy, close and invalidate it */	    CKAPI(slot)->C_CloseSession(session->handle);	    session->handle = CK_INVALID_SESSION;	}    }    nssSession_ExitMonitor(session);    /* token not removed, finished */    if (session->handle != CK_INVALID_SESSION) {	return PR_TRUE;    } else {	/* token has been removed, need to refresh with new session */	nssrv = nssSlot_Refresh(slot);	if (nssrv != PR_SUCCESS) {	    return PR_FALSE;	}	return PR_TRUE;    }}