void File::Close () { if_debug (ValidateState()); if (!SharedHandle) { close (FileHandle); FileIsOpen = false; if ((mFileOpenFlags & File::PreserveTimestamps) && Path.IsFile()) { struct utimbuf u; u.actime = AccTime; u.modtime = ModTime; try { throw_sys_sub_if (utime (string (Path).c_str(), &u) == -1, wstring (Path)); } catch (...) // Suppress errors to allow using read-only files { #ifdef DEBUG throw; #endif } } } }
uint64 File::Length () const { if_debug (ValidateState()); // BSD does not support seeking to the end of a device #ifdef TC_BSD if (Path.IsBlockDevice() || Path.IsCharacterDevice()) { # ifdef TC_MACOSX uint32 blockSize; uint64 blockCount; throw_sys_sub_if (ioctl (FileHandle, DKIOCGETBLOCKSIZE, &blockSize) == -1, wstring (Path)); throw_sys_sub_if (ioctl (FileHandle, DKIOCGETBLOCKCOUNT, &blockCount) == -1, wstring (Path)); return blockCount * blockSize; # else uint64 mediaSize; throw_sys_sub_if (ioctl (FileHandle, DIOCGMEDIASIZE, &mediaSize) == -1, wstring (Path)); return mediaSize; # endif } #endif off_t current = lseek (FileHandle, 0, SEEK_CUR); throw_sys_sub_if (current == -1, wstring (Path)); SeekEnd (0); uint64 length = lseek (FileHandle, 0, SEEK_CUR); SeekAt (current); return length; }
void File::WriteAt (const ConstBufferPtr &buffer, uint64 position) const { if_debug (ValidateState()); #ifdef TC_TRACE_FILE_OPERATIONS TraceFileOperation (FileHandle, Path, true, buffer.Size(), position); #endif throw_sys_sub_if (pwrite (FileHandle, buffer, buffer.Size(), position) != (ssize_t) buffer.Size(), wstring (Path)); }
void EncryptionModeLRW::DecryptSectorsCurrentThread (byte *data, uint64 sectorIndex, uint64 sectorCount, size_t sectorSize) const { if_debug (ValidateState ()); if_debug (ValidateParameters (data, sectorCount, sectorSize)); DecryptBuffer (data, sectorCount * sectorSize, SectorToBlockIndex (sectorIndex)); }
uint64 File::ReadAt (const BufferPtr &buffer, uint64 position) const { if_debug (ValidateState()); #ifdef TC_TRACE_FILE_OPERATIONS TraceFileOperation (FileHandle, Path, false, buffer.Size(), position); #endif ssize_t bytesRead = pread (FileHandle, buffer, buffer.Size(), position); throw_sys_sub_if (bytesRead == -1, wstring (Path)); return bytesRead; }
void EncryptionModeXTS::DecryptBuffer (byte *data, uint64 length, uint64 startDataUnitNo) const { if_debug (ValidateState()); CipherList::const_iterator iSecondaryCipher = SecondaryCiphers.end(); for (CipherList::const_reverse_iterator iCipher = Ciphers.rbegin(); iCipher != Ciphers.rend(); ++iCipher) { --iSecondaryCipher; DecryptBufferXTS (**iCipher, **iSecondaryCipher, data, length, startDataUnitNo, 0); } assert (iSecondaryCipher == SecondaryCiphers.begin()); }
void File::SeekEnd (int offset) const { if_debug (ValidateState()); // BSD does not support seeking to the end of a device #ifdef TC_BSD if (Path.IsBlockDevice() || Path.IsCharacterDevice()) { SeekAt (Length() + offset); return; } #endif throw_sys_sub_if (lseek (FileHandle, offset, SEEK_END) == -1, wstring (Path)); }
FilePath File::GetPath () const { if_debug (ValidateState()); return Path; }
/*********************************************************************************** Function Name : DrawTexture Inputs : Outputs : Returns : Description : ************************************************************************************/ static IMG_VOID DrawTexture(GLES1Context *gc, GLfloat fXs, GLfloat fYs, GLfloat fZs, GLfloat fWidth, GLfloat fHeight) { GLESViewport *psViewport; IMG_FLOAT *pfVertexData, fScreenHeight; IMG_UINT32 ui32Unit, ui32VertexDWords, i; IMG_UINT16 *pui16Indices; IMG_UINT32 *pui32Indices; IMG_UINT32 ui32NoClears = 0; IMG_FLOAT fNewWidth, fNewHeight, fNewXs, fNewYs; if ((fWidth<=0.0f) || (fHeight<=0.0f)) { SetError(gc, GL_INVALID_VALUE); return; } /* Nothing to do if the X.Y offset is outside the drawable */ if((fXs >= (IMG_FLOAT)gc->psDrawParams->ui32Width) || (fYs >= (IMG_FLOAT)gc->psDrawParams->ui32Height)) { return; } if(!PrepareToDraw(gc, &ui32NoClears, IMG_TRUE)) { PVR_DPF((PVR_DBG_ERROR,"DrawTexture: Can't prepare to draw")); return; } if(gc->sPrim.eCurrentPrimitiveType!=GLES1_PRIMTYPE_DRAWTEXTURE) { gc->sPrim.eCurrentPrimitiveType = GLES1_PRIMTYPE_DRAWTEXTURE; gc->ui32DirtyMask |= GLES1_DIRTYFLAG_VAO_ATTRIB_STREAM | GLES1_DIRTYFLAG_VP_STATE | GLES1_DIRTYFLAG_VERTEX_PROGRAM; if (gc->ui32RasterEnables & GLES1_RS_POLYOFFSET_ENABLE) { gc->ui32DirtyMask |= GLES1_DIRTYFLAG_RENDERSTATE; } gc->ui32EmitMask |= GLES1_EMITSTATE_MTE_STATE_CONTROL; } else { gc->ui32DirtyMask |= GLES1_DIRTYFLAG_VAO_ATTRIB_POINTER | GLES1_DIRTYFLAG_VP_STATE | GLES1_DIRTYFLAG_VERTEX_PROGRAM; } if(gc->ui32DirtyMask) { ValidateState(gc); } if (!gc->ui32NumImageUnitsActive) { PVR_DPF((PVR_DBG_WARNING,"DrawTexture: No textures enabled")); PVRSRVUnlockMutex(gc->psRenderSurface->hMutex); return; } /* Colour(4) + 4 * (position(4) + each texture layer (4)) */ ui32VertexDWords = 4 + (4 * (4 + (4 * gc->ui32NumImageUnitsActive))); pfVertexData = (IMG_FLOAT *) CBUF_GetBufferSpace(gc->apsBuffers, ui32VertexDWords, CBUF_TYPE_VERTEX_DATA_BUFFER, IMG_FALSE); if(!pfVertexData) { PVR_DPF((PVR_DBG_ERROR,"DrawTexture: Can't get vertex buffer space")); SetError(gc, GL_OUT_OF_MEMORY); PVRSRVUnlockMutex(gc->psRenderSurface->hMutex); return; } pui32Indices = CBUF_GetBufferSpace(gc->apsBuffers, 2, CBUF_TYPE_INDEX_DATA_BUFFER, IMG_FALSE); if(!pui32Indices) { PVR_DPF((PVR_DBG_ERROR,"DrawTexture: Can't get index buffer space")); SetError(gc, GL_OUT_OF_MEMORY); PVRSRVUnlockMutex(gc->psRenderSurface->hMutex); return; } gc->sPrim.pvDrawTextureAddr = pfVertexData; pui16Indices = (IMG_UINT16 *)pui32Indices; /* ** Clamp Z */ psViewport = &gc->sState.sViewport; if (fZs<=0.0f) { fZs = psViewport->fZNear; } else if (fZs>1.0f) { fZs = psViewport->fZFar; } else { fZs = psViewport->fZNear + fZs*(psViewport->fZFar - psViewport->fZNear); } /* ** Current color for all vertices */ pfVertexData[0] = gc->sState.sCurrent.asAttrib[AP_COLOR].fX; pfVertexData[1] = gc->sState.sCurrent.asAttrib[AP_COLOR].fY; pfVertexData[2] = gc->sState.sCurrent.asAttrib[AP_COLOR].fZ; pfVertexData[3] = gc->sState.sCurrent.asAttrib[AP_COLOR].fW; /* ** Calculate the strip's window coordinates ** ** Clip primitive to screen boundary to prevent guard band clamping ** from moving the vertices (but not moving the texcoords) */ fNewXs = fXs; fNewYs = fYs; fNewWidth = fWidth; fNewHeight = fHeight; if(fNewXs < 0.0f) { fNewWidth += fNewXs; fNewXs = 0.0f; } if(fNewYs < 0.0f) { fNewHeight += fNewYs; fNewYs = 0.0f; } fScreenHeight = (IMG_FLOAT)gc->psDrawParams->ui32Height; if((fNewXs + fNewWidth) > (IMG_FLOAT)gc->psDrawParams->ui32Width) { fNewWidth = (IMG_FLOAT)gc->psDrawParams->ui32Width - fNewXs; } if((fNewYs + fNewHeight) > fScreenHeight) { fNewHeight = fScreenHeight - fNewYs; } if(gc->psDrawParams->eRotationAngle!=PVRSRV_FLIP_Y) { pfVertexData[4] = fNewXs; pfVertexData[5] = fScreenHeight - fNewYs; pfVertexData[6] = fZs; pfVertexData[7] = 1.0f; pfVertexData[8] = fNewXs; pfVertexData[9] = fScreenHeight - (fNewYs + fNewHeight); pfVertexData[10] = fZs; pfVertexData[11] = 1.0f; pfVertexData[12] = fNewXs + fNewWidth; pfVertexData[13] = fScreenHeight - fNewYs; pfVertexData[14] = fZs; pfVertexData[15] = 1.0f; pfVertexData[16] = fNewXs + fNewWidth; pfVertexData[17] = fScreenHeight - (fNewYs + fNewHeight); pfVertexData[18] = fZs; pfVertexData[19] = 1.0f; } else { pfVertexData[4] = fNewXs; pfVertexData[5] = fNewYs; pfVertexData[6] = fZs; pfVertexData[7] = 1.0f; pfVertexData[8] = fNewXs; pfVertexData[9] = fNewYs + fNewHeight; pfVertexData[10] = fZs; pfVertexData[11] = 1.0f; pfVertexData[12] = fNewXs + fNewWidth; pfVertexData[13] = fNewYs; pfVertexData[14] = fZs; pfVertexData[15] = 1.0f; pfVertexData[16] = fNewXs + fNewWidth; pfVertexData[17] = fNewYs + fNewHeight; pfVertexData[18] = fZs; pfVertexData[19] = 1.0f; } pfVertexData += 20; /* ** Calculate the strip's texture coordinates */ for (i=0; i<gc->ui32NumImageUnitsActive; i++) { GLESTexture *psTex; GLESTextureParamState *psParamState; IMG_FLOAT fX0, fX1, fY0, fY1, fWt, fHt; ui32Unit = gc->ui32TexImageUnitsEnabled[i]; psTex = gc->sTexture.apsBoundTexture[ui32Unit][gc->sTexture.aui32CurrentTarget[ui32Unit]]; psParamState = &psTex->sState; fWt = (IMG_FLOAT)psTex->psMipLevel[0].ui32Width; fHt = (IMG_FLOAT)psTex->psMipLevel[0].ui32Height; /* ** s = (Ucr + (X - Xs)*(Wcr/Ws)) / Wt ** t = (Vcr + (Y - Ys)*(Hcr/Hs)) / Ht ** r = 0 ** q = 1 */ fX0 = ((IMG_FLOAT)psParamState->i32CropRectU + (fNewXs - fXs) * ((IMG_FLOAT)psParamState->i32CropRectW / fWidth)) / fWt; fX1 = ((IMG_FLOAT)psParamState->i32CropRectU + (fNewXs + fNewWidth - fXs) * ((IMG_FLOAT)psParamState->i32CropRectW / fWidth)) / fWt; fY0 = ((IMG_FLOAT)psParamState->i32CropRectV + (fNewYs - fYs) * ((IMG_FLOAT)psParamState->i32CropRectH / fHeight)) / fHt; fY1 = ((IMG_FLOAT)psParamState->i32CropRectV + (fNewYs + fNewHeight - fYs) * ((IMG_FLOAT)psParamState->i32CropRectH / fHeight)) / fHt; pfVertexData[0] = fX0; pfVertexData[1] = fY0; pfVertexData[2] = 0.0f; pfVertexData[3] = 1.0f; pfVertexData[4] = fX0; pfVertexData[5] = fY1; pfVertexData[6] = 0.0f; pfVertexData[7] = 1.0f; pfVertexData[8] = fX1; pfVertexData[9] = fY0; pfVertexData[10] = 0.0f; pfVertexData[11] = 1.0f; pfVertexData[12] = fX1; pfVertexData[13] = fY1; pfVertexData[14] = 0.0f; pfVertexData[15] = 1.0f; pfVertexData += 16; } /* ** Indices for the strip */ pui16Indices[0] = 0; pui16Indices[1] = 1; pui16Indices[2] = 2; pui16Indices[3] = 3; /* Attach all used resources to the current surface */ AttachAllUsedResourcesToCurrentSurface(gc); /* Emit state */ GLES1EmitState(gc, 4, CBUF_GetBufferDeviceAddress(gc->apsBuffers, pui32Indices, CBUF_TYPE_INDEX_DATA_BUFFER), 0); CBUF_UpdateBufferPos(gc->apsBuffers, ui32VertexDWords, CBUF_TYPE_VERTEX_DATA_BUFFER); GLES1_INC_COUNT(GLES1_TIMER_VERTEX_DATA_COUNT, ui32VertexDWords); CBUF_UpdateBufferPos(gc->apsBuffers, 2, CBUF_TYPE_INDEX_DATA_BUFFER); GLES1_INC_COUNT(GLES1_TIMER_INDEX_DATA_COUNT, 2); /* Update vertex and index buffers committed primitive offset */ CBUF_UpdateVIBufferCommittedPrimOffsets(gc->apsBuffers, &gc->psRenderSurface->bPrimitivesSinceLastTA, (IMG_VOID *)gc, KickLimit_ScheduleTA); PVRSRVUnlockMutex(gc->psRenderSurface->hMutex); }
void File::Flush () const { if_debug (ValidateState()); throw_sys_sub_if (fsync (FileHandle) != 0, wstring (Path)); }
bool DiameterEapServerStateMachine::CheckDER() { DER_Data& der = derData; DEA_Data& dea = deaData; // Auth-Request-Type check. if (der.AuthRequestType() != AUTH_REQUEST_TYPE_AUTHENTICATION_ONLY && der.AuthRequestType() != AUTH_REQUEST_TYPE_AUTHORIZE_AUTHENTICATE) { AAA_LOG((LM_ERROR, "[%N] Invalid auth request type.\n")); return false; } dea.AuthRequestType = der.AuthRequestType; AuthorizeMultiRoundTimeOut(dea.MultiRoundTimeOut); if (!dea.AuthRequestType.IsSet()) { AAA_LOG((LM_ERROR, "[%N] Failed to set auth request type.\n")); return false; } // Class check. for (unsigned i=0; i<dea.Class.size(); i++) { bool found = false; for (unsigned j=0; j<der.Class.size(); j++) { if (dea.Class[i] == der.Class[j]) found = true; } if (!found) { AAA_LOG((LM_ERROR, "[%N] Invalid class\n.")); return false; } } // UserName check if (der.UserName.IsSet()) { if (!ValidateUserName(der.UserName())) { AAA_LOG((LM_DEBUG, "[%N] Failed to validate username.\n")); return false; } dea.UserName = der.UserName; } // State check. if (dea.State.IsSet()) // Non-initial state. { if (!der.State.IsSet() || !ValidateState(der.State(), dea.State())) { AAA_LOG((LM_DEBUG, "[%N] Invalid State AVP.\n")); return false; } else // Try to set initial state { SetState(dea.State); } } return true; }
int OnNetworkCallbackReceive(char* buffer, uint bytes) { __int32 type = *(__int32*)buffer; buffer += sizeof(__int32); if (type == PACKET_TYPE_SUBSCRIBE && HostingGame) { printf(" Found player\n"); AssignUser = true; } else if (type == PACKET_TYPE_ASSIGN_USER && !HostingGame) { START_PACKET connected = *((START_PACKET*)buffer); buffer += sizeof(START_PACKET); Map->applyPacket(connected); Map->extractWallBuffer((__int32*)buffer, connected.walls); Local->id = connected.id; Local->rect.move(connected.x, connected.y); printf(" Connected to host\n"); printf(" I am player : %d\n", Local->id); OnClientInitialize(); } else if (type == PACKET_TYPE_PUSH_UPDATE && HostingGame) { PLAYER_PACKET packet = *((PLAYER_PACKET*)buffer); buffer += sizeof(PLAYER_PACKET); GAME_PACKET state = StatePacket; AddToState(state, packet); for (uint i = 0; i < Connected.length(); i++) { Player* player = Connected[i]; if (player == NULL || player->id == 0) continue; if (player->id == packet.id) player->applyPacket(packet); } PLAYER_PACKET local; Local->createPacket(local); AddToState(state, local); BuildState(state); if (ValidateState(state)) StatePacket = state; #if 1 if (packet.bulletsFired > 0) { for (uint i = 0; i < OtherBullets.length(); i++) { Bullet* bullet = &OtherBullets[i]; if (bullet->id == packet.id || bullet->id == 0) OtherBullets.remove(*bullet); } for (uint i = 0; i < packet.bulletsFired; i++) { BULLET_PACKET bullet = *((BULLET_PACKET*)buffer); buffer += sizeof(BULLET_PACKET); if (bullet.id == 0 || bullet.id == Local->id) continue; Bullet newBullet; newBullet.applyPacket(bullet); OtherBullets.add(newBullet); } } #endif } else if (type == PACKET_TYPE_MASS_UPDATE && !HostingGame) { GAME_PACKET state = *((GAME_PACKET*)buffer); buffer += sizeof(GAME_PACKET); if (ValidateState(state)) { StatePacket = state; PLAYER_PACKET local; GetPlayerFromState(state, Local->id, &local); for (uint i = Connected.length(); i < uint(StatePacket.connected) - 1; i++) Connected.add(new Player); PLAYER_PACKET* players = (PLAYER_PACKET*)&StatePacket.players; uint k = 0; for (uint i = 0; i < uint(StatePacket.connected); i++) { if (k >= Connected.length()) break; PLAYER_PACKET packet = players[i]; if (packet == local) continue; Player* player = Connected[k]; player->applyPacket(packet); k++; } } #if 1 if (state.bullets > 0) { //printf(" RECEIVING BULLETS %d\n", state.bullets); OtherBullets.zero(); for (uint i = 0; i < state.bullets; i++) { BULLET_PACKET bullet = *((BULLET_PACKET*)buffer); buffer += sizeof(BULLET_PACKET); if (bullet.id == 0 || bullet.id == Local->id) continue; Bullet newBullet; newBullet.applyPacket(bullet); OtherBullets.add(newBullet); } } #endif } return 100; }
void EncryptionModeLRW::Encrypt (byte *data, uint64 length) const { ValidateState (); EncryptBuffer (data, length, 1); }
void EncryptionAlgorithm::Encrypt (byte *data, uint64 length) const { if_debug (ValidateState()); Mode->Encrypt (data, length); }
void File::SeekAt (uint64 position) const { if_debug (ValidateState()); throw_sys_sub_if (lseek (FileHandle, position, SEEK_SET) == -1, wstring (Path)); }
void EncryptionAlgorithm::EncryptSectors (byte *data, uint64 sectorIndex, uint64 sectorCount, size_t sectorSize) const { if_debug (ValidateState ()); Mode->EncryptSectors (data, sectorIndex, sectorCount, sectorSize); }
void EncryptionModeLRW::Decrypt (byte *data, uint64 length) const { if_debug (ValidateState ()); DecryptBuffer (data, length, 1); }