//+--------------------------------------------------------------------------- // // Microsoft Windows // Copyright (C) Microsoft Corporation, 1992 - 1995. // // File: cache.c // // Contents: // // Functions to cache SessionIds and keys for PCT // // Classes: // // Functions: // // History: 8-13-95 TerenceS Created // //---------------------------------------------------------------------------- #include "pctsspi.h" SessCacheItem *ServerCache; DWORD ServerCacheLen = 0; CRITICAL_SECTION CacheCritSec; BOOL PctCacheLockedAndLoaded() { return (ServerCacheLen != 0); } BOOL PctInitSessionCache(DWORD CacheSize) { DWORD i; #if DBG DebugLog((DEB_TRACE, "Attempting to init cache to %d items:\n", CacheSize)); #endif if ((ServerCache = (SessCacheItem *)PctExternalAlloc(CacheSize * sizeof(SessCacheItem))) == NULL) { #if DBG DebugLog((DEB_TRACE, " FAILED\n")); #endif return FALSE; } InitializeCriticalSection(&CacheCritSec); ServerCacheLen = CacheSize; for(i=0;ibSessionId, ServerCache[i].Session.bSessionId, PCT_SESSION_ID_SIZE)) { CopyMemory(RetItem, &(ServerCache[i]), sizeof(SessCacheItem)); ServerCache[i].Time = GetTickCount(); // drop cache lock LeaveCriticalSection(&CacheCritSec); #if DBG DebugLog((DEB_TRACE, " FOUND IT\n")); #endif return TRUE; } } } #if DBG DebugLog((DEB_TRACE, " FAILED\n")); #endif return FALSE; } BOOL PctFindTargetInCache(UCHAR *Target, SessCacheItem *RetItem) { DWORD i; #if DBG DebugLog((DEB_TRACE, "Looking for %s in cache:\n", Target)); #endif // acquire cache lock EnterCriticalSection(&CacheCritSec); for(i=0;i