ANSC_HANDLE SlapVhoAllocUint32ArrayFromImcpVar ( ANSC_HANDLE hThisObject, PUCHAR imcp_var_data, ULONG imcp_var_length ) { PSLAP_UINT32_ARRAY slap_array = NULL; ULONG var_count = imcp_var_length / sizeof(ULONG); ULONG total_size = 0; char* var_point = (char*)imcp_var_data; ULONG jj = 0; total_size = sizeof(SLAP_VAR_ARRAY) + sizeof(SLAP_UINT32) * var_count; slap_array = (PSLAP_UINT32_ARRAY)AnscAllocateMemory(total_size); if ( slap_array ) { slap_array->Size = total_size; slap_array->VarCount = var_count; slap_array->Syntax = SLAP_VAR_SYNTAX_uint32Array; for ( jj = 0; jj < var_count; jj++ ) { slap_array->Array.arrayUint32[jj] = (SLAP_UINT32)AnscUlongFromNToH(AnscReadUlong(var_point)); var_point += sizeof(ULONG); } } return (ANSC_HANDLE)slap_array; }
static ANSC_HANDLE WebVhoGetOldestGso ( ANSC_HANDLE hThisObject, ULONG ulSessionId, char* identifier, PUCHAR address, PULONG pulSessionCount ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PWEB_VIRTUAL_HOST_OBJECT pMyObject = (PWEB_VIRTUAL_HOST_OBJECT )hThisObject; PWEB_SITE_MANAGER_OBJECT pSiteManager = (PWEB_SITE_MANAGER_OBJECT )pMyObject->hOwnerContext; WEB_SITE_MANAGER_PROPERTY SMProperty; PWEB_VIRTUAL_HOST_PROPERTY pProperty = (PWEB_VIRTUAL_HOST_PROPERTY)&pMyObject->Property; PHTTP_HFP_INTERFACE pHfpIf = (PHTTP_HFP_INTERFACE )pMyObject->hHfpIf; PWEB_LSM_INTERFACE pLsmIf = (PWEB_LSM_INTERFACE )pMyObject->hLsmIf; PWEB_GENERAL_SESSION_OBJECT pSession = NULL; ULONG ulClientAddr = 0; USHORT usClientPort = 0; PSINGLE_LINK_ENTRY pSLinkEntry = NULL; ULONG ulHashIndex = AnscHashUlong(ulSessionId, WEB_VHO_GSO_TABLE_SIZE); ULONG i; ULONG ulCSessCount = 0; PWEB_GENERAL_SESSION_OBJECT pOldSession = NULL; for ( i = 0; i < WEB_VHO_GSO_TABLE_SIZE; i ++ ) { pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->GsoTable[i]); while ( pSLinkEntry ) { pSession = ACCESS_WEB_GENERAL_SESSION_OBJECT(pSLinkEntry); ulClientAddr = *(PULONG)pSession->GetClientAddr((ANSC_HANDLE)pSession); usClientPort = pSession->GetClientPort((ANSC_HANDLE)pSession); pSLinkEntry = AnscSListGetNextEntry(pSLinkEntry); if ( pSession->LsmMaxAge != 0 && ulClientAddr == AnscReadUlong(address) ) { ulCSessCount ++; if ( !pOldSession ) { pOldSession = pSession; } else if ( pSession->LastReqAtInSec <= pOldSession->LastReqAtInSec && pSession->LastRepAtInSec <= pOldSession->LastRepAtInSec ) { pOldSession = pSession; } } } } *pulSessionCount = ulCSessCount; return (ANSC_HANDLE)pSession; }
ANSC_STATUS WebVhoDelGso ( ANSC_HANDLE hThisObject, ULONG ulSessionId, PUCHAR address, USHORT port ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PWEB_VIRTUAL_HOST_OBJECT pMyObject = (PWEB_VIRTUAL_HOST_OBJECT )hThisObject; PWEB_VIRTUAL_HOST_PROPERTY pProperty = (PWEB_VIRTUAL_HOST_PROPERTY)&pMyObject->Property; PHTTP_HFP_INTERFACE pHfpIf = (PHTTP_HFP_INTERFACE )pMyObject->hHfpIf; PWEB_LSM_INTERFACE pLsmIf = (PWEB_LSM_INTERFACE )pMyObject->hLsmIf; PWEB_GENERAL_SESSION_OBJECT pSession = NULL; ULONG ulClientAddr = 0; PSINGLE_LINK_ENTRY pSLinkEntry = NULL; ULONG ulHashIndex = AnscHashUlong(ulSessionId, WEB_VHO_GSO_TABLE_SIZE); AnscAcquireLock(&pMyObject->GsoTableLock); pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->GsoTable[ulHashIndex]); while ( pSLinkEntry ) { pSession = ACCESS_WEB_GENERAL_SESSION_OBJECT(pSLinkEntry); ulClientAddr = *(PULONG)pSession->GetClientAddr((ANSC_HANDLE)pSession); pSLinkEntry = AnscSListGetNextEntry(pSLinkEntry); if ( (pSession->GetSessionId((ANSC_HANDLE)pSession) == ulSessionId ) && (ulClientAddr == AnscReadUlong(address)) ) { AnscSListPopEntryByLink(&pMyObject->GsoTable[ulHashIndex], &pSession->Linkage); pSession->AcquireAccess((ANSC_HANDLE)pSession); returnStatus = pLsmIf->EndSession ( pLsmIf->hOwnerContext, (ANSC_HANDLE)pSession ); pSession->ReleaseAccess((ANSC_HANDLE)pSession); pSession->Cancel ((ANSC_HANDLE)pSession); pSession->Remove ((ANSC_HANDLE)pSession); } } AnscReleaseLock(&pMyObject->GsoTableLock); return ANSC_STATUS_SUCCESS; }
ANSC_HANDLE SlapVhoAllocIntArray ( ANSC_HANDLE hThisObject, PUCHAR var_data, ULONG var_length ) { PSLAP_INT_ARRAY slap_array = NULL; ULONG var_count = var_length / sizeof(SLAP_INT); ULONG total_size = 0; char* var_point = (char*)var_data; ULONG jj = 0; total_size = sizeof(SLAP_VAR_ARRAY) + sizeof(SLAP_INT) * var_count; slap_array = (PSLAP_INT_ARRAY)AnscAllocateMemory(total_size); if ( slap_array ) { slap_array->Size = total_size; slap_array->VarCount = var_count; slap_array->Syntax = SLAP_VAR_SYNTAX_intArray; if ( var_data ) { for ( jj = 0; jj < var_count; jj++ ) { slap_array->Array.arrayInt[jj] = (SLAP_INT)AnscReadUlong(var_point); var_point += sizeof(SLAP_INT); } } } return (ANSC_HANDLE)slap_array; }
ANSC_HANDLE WebVhoGetGso ( ANSC_HANDLE hThisObject, ULONG ulSessionId, char* identifier, PUCHAR address, USHORT port ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PWEB_VIRTUAL_HOST_OBJECT pMyObject = (PWEB_VIRTUAL_HOST_OBJECT )hThisObject; PWEB_SITE_MANAGER_OBJECT pSiteManager = (PWEB_SITE_MANAGER_OBJECT )pMyObject->hOwnerContext; WEB_SITE_MANAGER_PROPERTY SMProperty; PWEB_VIRTUAL_HOST_PROPERTY pProperty = (PWEB_VIRTUAL_HOST_PROPERTY)&pMyObject->Property; PHTTP_HFP_INTERFACE pHfpIf = (PHTTP_HFP_INTERFACE )pMyObject->hHfpIf; PWEB_LSM_INTERFACE pLsmIf = (PWEB_LSM_INTERFACE )pMyObject->hLsmIf; PWEB_GENERAL_SESSION_OBJECT pSession = NULL; ULONG ulClientAddr = 0; USHORT usClientPort = 0; PSINGLE_LINK_ENTRY pSLinkEntry = NULL; ULONG ulHashIndex = AnscHashUlong(ulSessionId, WEB_VHO_GSO_TABLE_SIZE); ULONG i; ULONG ulCSessCount = 0; PWEB_GENERAL_SESSION_OBJECT pOldSession = NULL; AnscAcquireLock(&pMyObject->GsoTableLock); if ( ulSessionId != 0xFFFFFFFF ) { pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->GsoTable[ulHashIndex]); while ( pSLinkEntry ) { pSession = ACCESS_WEB_GENERAL_SESSION_OBJECT(pSLinkEntry); ulClientAddr = *(PULONG)pSession->GetClientAddr((ANSC_HANDLE)pSession); usClientPort = pSession->GetClientPort((ANSC_HANDLE)pSession); pSLinkEntry = AnscSListGetNextEntry(pSLinkEntry); if ( pSession->GetLsmMaxAge((ANSC_HANDLE)pSession) == 0 ) { /* this session is marked to be closed */ continue; } if ( (pSession->GetSessionId((ANSC_HANDLE)pSession) == ulSessionId) && (ulClientAddr == AnscReadUlong(address)) ) { char* pLsmId = pSession->GetLsmIdentifier((ANSC_HANDLE)pSession); if ( !identifier ) { if ( !pLsmId || AnscSizeOfString(pLsmId) == 0 ) { AnscReleaseLock(&pMyObject->GsoTableLock); pSession->AcquireAccess((ANSC_HANDLE)pSession); return (ANSC_HANDLE)pSession; } else { break; } } else if ( AnscEqualString ( pLsmId, identifier, TRUE ) ) { AnscReleaseLock(&pMyObject->GsoTableLock); pSession->AcquireAccess((ANSC_HANDLE)pSession); return (ANSC_HANDLE)pSession; } else { break; } } } } else { for ( i = 0; i < WEB_VHO_GSO_TABLE_SIZE; i ++ ) { pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->GsoTable[i]); while ( pSLinkEntry ) { pSession = ACCESS_WEB_GENERAL_SESSION_OBJECT(pSLinkEntry); ulClientAddr = *(PULONG)pSession->GetClientAddr((ANSC_HANDLE)pSession); usClientPort = pSession->GetClientPort((ANSC_HANDLE)pSession); pSLinkEntry = AnscSListGetNextEntry(pSLinkEntry); if ( (ulClientAddr == AnscReadUlong(address)) && usClientPort == port ) { AnscReleaseLock(&pMyObject->GsoTableLock); /* same connection */ pSession->AcquireAccess((ANSC_HANDLE)pSession); return (ANSC_HANDLE)pSession; } } } } pSiteManager->GetProperty((ANSC_HANDLE)pSiteManager, &SMProperty); pOldSession = (PWEB_GENERAL_SESSION_OBJECT)WebVhoGetOldestGso ( (ANSC_HANDLE)pMyObject, ulSessionId, identifier, address, &ulCSessCount ); if ( pOldSession && SMProperty.MaxSessionCountPerPeer != 0 && ulCSessCount >= SMProperty.MaxSessionCountPerPeer ) { pOldSession->Terminate((ANSC_HANDLE)pOldSession); } AnscReleaseLock(&pMyObject->GsoTableLock); /* * We couldn't find a general session object for this client, we shall create a new one and * let the Logical Session Manager classify the client based on his/her identifier. */ pSession = (PWEB_GENERAL_SESSION_OBJECT)pMyObject->AddGso ( (ANSC_HANDLE)pMyObject, identifier, address, port ); return (ANSC_HANDLE)pSession; }
ANSC_HANDLE WebVhoIdentifyGso ( ANSC_HANDLE hThisObject, ANSC_HANDLE hBmoReq ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PWEB_VIRTUAL_HOST_OBJECT pMyObject = (PWEB_VIRTUAL_HOST_OBJECT )hThisObject; PWEB_VIRTUAL_HOST_PROPERTY pProperty = (PWEB_VIRTUAL_HOST_PROPERTY )&pMyObject->Property; PHTTP_HFP_INTERFACE pHfpIf = (PHTTP_HFP_INTERFACE )pMyObject->hHfpIf; PWEB_LSM_INTERFACE pLsmIf = (PWEB_LSM_INTERFACE )pMyObject->hLsmIf; PHTTP_BMO_REQ_OBJECT pBmoReq = (PHTTP_BMO_REQ_OBJECT )hBmoReq; PHTTP_HFO_COOKIE pHttpHfoCookie = (PHTTP_HFO_COOKIE )NULL; PHTTP_COOKIE_CONTENT pCookieContent = (PHTTP_COOKIE_CONTENT )NULL; PWEB_GENERAL_SESSION_OBJECT pSession = (PWEB_GENERAL_SESSION_OBJECT)NULL; ULONG ulSessionId = (ULONG )0xFFFFFFFF; char* pLsmIdentifier = (char* )NULL; char pEmptyLsmId[] = {0}; BOOL bLsmIdAlloc = (BOOL )FALSE; ULONG ulClientAddr = (ULONG )AnscReadUlong(pBmoReq->GetClientAddr((ANSC_HANDLE)pBmoReq)); USHORT usClientPort = (USHORT )pBmoReq->GetClientPort((ANSC_HANDLE)pBmoReq); BOOL bGotSessionId = (BOOL )FALSE; BOOL bGotLsmId = (BOOL )FALSE; ULONG i = 0; ULONG ulCookieIndex = 0; if ( !pProperty->bEnableSessionTracking ) { return (ANSC_HANDLE)NULL; } pHttpHfoCookie = (PHTTP_HFO_COOKIE)pBmoReq->GetHeaderField2 ( (ANSC_HANDLE)pBmoReq, HTTP_HEADER_ID_COOKIE, ulCookieIndex ++ ); while ( pHttpHfoCookie ) { for ( i = 0; i < pHttpHfoCookie->CookieCount; i++ ) { pCookieContent = &pHttpHfoCookie->CookieArray[i]; if ( !bGotSessionId && AnscEqualString ( pCookieContent->Name, pProperty->VhoCookieName, TRUE ) ) { PUCHAR pCookieValue = pCookieContent->Value; /* Some clients will use double quote in cookie value * although we don't specify in Set-Cookie. */ if ( pCookieValue[0] == '"' ) { pCookieValue ++; } ulSessionId = (ULONG)_ansc_atol(pCookieValue); bGotSessionId = TRUE; } else if ( !bGotLsmId && AnscEqualString ( pCookieContent->Name, pProperty->LsmCookieName, TRUE ) ) { bGotLsmId = TRUE; pLsmIdentifier = pCookieContent->Value; /* Some clients will use double quote in cookie value * although we don't specify in Set-Cookie. This may * cause session match failure, and therefore authentication * may fail. */ if ( pLsmIdentifier ) { ULONG ulLen = (ULONG)AnscSizeOfString(pLsmIdentifier); if ( ulLen == 2 && *pLsmIdentifier == '"' && *(pLsmIdentifier + 1) == '"' ) { pLsmIdentifier = pEmptyLsmId; } else if ( ulLen > 2 && *pLsmIdentifier == '"' && *(pLsmIdentifier + ulLen - 1) == '"' ) { pLsmIdentifier = AnscAllocateMemory(ulLen); AnscCopyMemory(pLsmIdentifier, pCookieContent->Value + 1, ulLen - 2); pLsmIdentifier[ulLen - 2] = 0; bLsmIdAlloc = TRUE; } } } } if ( bGotSessionId && bGotLsmId ) { break; } pHttpHfoCookie = (PHTTP_HFO_COOKIE)pBmoReq->GetHeaderField2 ( (ANSC_HANDLE)pBmoReq, HTTP_HEADER_ID_COOKIE, ulCookieIndex ++ ); } pSession = (PWEB_GENERAL_SESSION_OBJECT)pMyObject->GetGso ( (ANSC_HANDLE)pMyObject, ulSessionId, pLsmIdentifier, (PUCHAR)&ulClientAddr, usClientPort ); if ( bLsmIdAlloc && pLsmIdentifier ) { AnscFreeMemory(pLsmIdentifier); } return (ANSC_HANDLE)pSession; }