//----------------------------------------------------------------------------- //! void EventDispatcher::onPointer( int button, EventCondition* cond, Callback call ) { Hash hash; hash = toHash( Event::POINTER_PRESS, button ); _callbacks[hash].add( cond, call ); hash = toHash( Event::POINTER_RELEASE, button ); _callbacks[hash].add( cond, call ); }
//----------------------------------------------------------------------------- //! void EventDispatcher::onKey( int key, EventCondition* cond, Callback call ) { Hash hash; hash = toHash( Event::KEY_PRESS, key ); _callbacks[hash].add( cond, call ); hash = toHash( Event::KEY_RELEASE, key ); _callbacks[hash].add( cond, call ); }
bool CIndex::FileExists(const char* FileName) { char* NormalizedName = new char[strlen(FileName) + 1]; CIndex::NormalizePath(FileName, NormalizedName); if(FlatFile::Exist(NormalizedName)) { delete[] NormalizedName; NormalizedName = NULL; return true; } else { for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i) { CVFSFile::File* RoseFile; if((*i)->FileTable.getHash(toHash(NormalizedName), &RoseFile)) { delete[] NormalizedName; NormalizedName = NULL; return true; } } } delete[] NormalizedName; NormalizedName = NULL; return false; }
BikePtr Bikebase::add(LicenseType license, Mileage mile, BikeType bikeType, StationType station) { Hashcode hashcode = toHash(license); BikePtr bikeptr = new Bike(license, mile, bikeType, station); hash_table[hashcode].push_back(bikeptr); return bikeptr; }
void CIndex::GetFileInfo(const char* FileName, VFileInfo* FileInfo, bool CalcCrc) { char* NormalizedName = new char[strlen(FileName) + 1]; CIndex::NormalizePath(FileName, NormalizedName); for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i) { CVFSFile::File* RoseFile; if((*i)->FileTable.getHash(toHash(NormalizedName), &RoseFile)) { FileInfo->dwVersion = RoseFile->version; if(CalcCrc) { if(!RoseFile->data) { (*i)->VFile->Seek(RoseFile->offset); RoseFile->data = new unsigned char[RoseFile->length]; (*i)->VFile->ReadData(RoseFile->data, RoseFile->length); } FileInfo->dwCRC = (*i)->CalculateCrc32(RoseFile); RoseFile->crc = FileInfo->dwCRC; delete[] NormalizedName; NormalizedName = NULL; return; } else { FileInfo->dwCRC = RoseFile->crc; return; } } } delete[] NormalizedName; NormalizedName = NULL; return; }
CVFSFile::File* CIndex::OpenFile(const char* FileName) { char* NormalizedName = new char[strlen(FileName) + 1]; CIndex::NormalizePath(FileName, NormalizedName); if(FlatFile::Exist(NormalizedName)) { FlatFile* FFile = new FlatFile(NormalizedName, "rb"); if(FFile->IsOpen()) { CVFSFile::File* RoseFile = new CVFSFile::File(); RoseFile->path = NormalizedName; RoseFile->currentPosition = 0; RoseFile->deleted = false; RoseFile->length = FFile->Size(); RoseFile->offset = 0; RoseFile->lEndOff = RoseFile->length; RoseFile->btEncrypted = 0; RoseFile->data = new unsigned char[RoseFile->length]; FFile->ReadData(RoseFile->data, RoseFile->length); RoseFile->crc = 0; RoseFile->hash = 0; RoseFile->version = this->GetCurrentVersion(); RoseFile->vfsIndex = 0; FFile->Close(); delete FFile; FFile = NULL; Root->Files->push_back(RoseFile); return RoseFile; } else { delete[] NormalizedName; NormalizedName = NULL; delete FFile; FFile = NULL; } } else { CVFSFile::File* RoseFile; for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i) { if((*i)->FileTable.getHash(toHash(NormalizedName), &RoseFile)) { RoseFile->data = new unsigned char[RoseFile->length]; (*i)->VFile->Seek(RoseFile->offset); (*i)->VFile->ReadData(RoseFile->data, RoseFile->length); RoseFile->currentPosition = 0; delete[] NormalizedName; NormalizedName = NULL; return RoseFile; } } } delete[] NormalizedName; NormalizedName = NULL; return 0; }
const QString QueryExecutor::generateNewToken(const QString& login,const QString& password) const { QString log=login+password; QByteArray toHash(log.toUtf8()); toHash=QCryptographicHash::hash(log.toUtf8(),QCryptographicHash::Md5); QString result(toHash.toHex()); syslog(LOG_INFO,"TOken = %s",result.toStdString().c_str()); return result; }
QString Session::generateToken(const common::BasicUser &user) { QString token=user.getLogin()+user.getPassword()+user.getEmail()+QDateTime::currentDateTime().toString(); QByteArray toHash(token.toUtf8()); toHash=QCryptographicHash::hash(token.toUtf8(),QCryptographicHash::Md5); QString result(toHash.toHex()); DEBUG() << "Generated token " << result << " for user " << user.getLogin(); return result; }
BikePtr Bikebase::get(LicenseType license) { HNode& hnode = hash_table[toHash(license)]; for (HNode::iterator it = hnode.begin(); it != hnode.end(); it++) { if (*it == NULL) throw NullpointerException(); if ((*it)->license == license) return *it; } throw LicenseNotFoundException(license); }
short CIndex::RemoveFile(const char* FileName) { char* NormalizedName = new char[strlen(FileName) + 1]; CIndex::NormalizePath(FileName, NormalizedName); for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i) { CVFSFile::File* RoseFile; if((*i)->FileTable.getHash(toHash(NormalizedName), &RoseFile)) { RoseFile->deleted = true; (*i)->FileTable.removeHash(toHash(NormalizedName)); (*i)->SetDeleteCount((*i)->GetDeleteCount() + 1); delete[] NormalizedName; NormalizedName = NULL; return 0; // succes } } delete[] NormalizedName; NormalizedName = NULL; return 3; // doesn't exist }
/*! Computes the WebSocket handshake response given the input key */ static QByteArray generateWebSocketChallengeResponse(const QByteArray& key) { SHA1 sha1; Vector<uint8_t, 20> digest; Vector<char> encoded; QByteArray toHash("258EAFA5-E914-47DA-95CA-C5AB0DC85B11"); toHash.prepend(key); sha1.addBytes((uint8_t*)toHash.data(), toHash.size()); sha1.computeHash(digest); base64Encode((char*)digest.data(), digest.size(), encoded); return QByteArray(encoded.data(), encoded.size()); }
//----------------------------------------------------------------------------- //! void EventDispatcher::onPointer( EventCondition* cond, Callback call ) { static const Event::EventType _kPointerEventTypes[] = { Event::POINTER_PRESS, Event::POINTER_RELEASE, Event::POINTER_MOVE, Event::POINTER_SCROLL, Event::POINTER_CANCEL }; Hash hash; for( uint i = 0; i < sizeof(_kPointerEventTypes)/sizeof(_kPointerEventTypes[0]); ++i ) { hash = toHash( _kPointerEventTypes[i] ); _callbacks[hash].add( cond, call ); } }
/** * Add the (name,value) pair to current context (if possible given current context type). * * \note This method is *not* recommended to add a property because plain * QVariant cannot be directly changed and a work-around is used. * If you have a *write* access to current outer context, use it instead! * * \note The properties stack *MUST* not be empty (this should always be the case). */ void RenderingContext::addProperty( const QString& name, const QVariant& value) { Q_ASSERT_X( ! m_propertiesStack.isEmpty(), "RenderingContext::addProperty", "Expecting a context" ); // Cannot change "in place", so we pop here and push back at the end auto context = m_propertiesStack.takeLast(); auto type = QMetaType::Type( context.type() ); switch( type ) { case QMetaType::QVariantHash: { QVariantHash hash( context.toHash() ); hash.insert( name, value ); m_propertiesStack.append( hash ); } break; case QMetaType::QVariantMap: { QVariantMap map( context.toMap() ); map.insert( name, value ); m_propertiesStack.append( map ); } break; case QMetaType::QObjectStar: case QMetaType::User: { QObject* object( context.value<QObject*>() ); if( object != nullptr ) { object->setProperty( qPrintable( name ), value ); m_propertiesStack.append( QVariant::fromValue( object )); } else m_propertiesStack.append( context ); } break; default: m_propertiesStack.append( context ); // Push back the context -- no luck warning( QString( "Property '%1' cannot be added to current context" ).arg( name )); break; } }
int CIndex::GetFileSize(const char* FileName) { CVFSFile::File* RoseFile; char* NormalizedName = new char[strlen(FileName) + 1]; CIndex::NormalizePath(FileName, NormalizedName); for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i) { if((*i)->FileTable.getHash(toHash(NormalizedName), &RoseFile)) { delete[] NormalizedName; NormalizedName = NULL; return RoseFile->length; } } delete[] NormalizedName; NormalizedName = NULL; return 0; }
bool CIndex::SetFileInfo(const char* FileName, VFileInfo* FileInfo) { char* NormalizedName = new char[strlen(FileName) + 1]; CIndex::NormalizePath(FileName, NormalizedName); for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i) { CVFSFile::File* RoseFile; if((*i)->FileTable.getHash(toHash(NormalizedName), &RoseFile)) { RoseFile->crc = FileInfo->dwCRC; RoseFile->version = FileInfo->dwVersion; delete[] NormalizedName; NormalizedName = NULL; return true; } } delete[] NormalizedName; NormalizedName = NULL; return false; }
USING_NAMESPACE /*============================================================================== UNNAMED NAMESPACE ==============================================================================*/ UNNAMESPACE_BEGIN UNNAMESPACE_END /*============================================================================== CLASS EventDispatch ==============================================================================*/ //----------------------------------------------------------------------------- //! void EventDispatcher::onEvent( EventCondition* cond, Callback call ) { Hash hash = toHash( ANY_TYPE ); _callbacks[hash].add( cond, call ); }
short CIndex::AddFile(const char* VfsName, const char* FileName, const char* TargetName, int version, int crc, bool deleted) { string name = VfsName; transform(name.begin(), name.end(), name.begin(), ::toupper); if(!name.compare("ROOT.VFS")) { return 2; // invalid vfs } if(FileExistsInVfs(name.c_str())) { return 4; } bool VfsFound = false; for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i) { if(!name.compare((*i)->GetVFSName())) { VfsFound = true; if(!FlatFile::Exist((char*)FileName)) { return 5; // doesn't exist } FlatFile* srcFile = new FlatFile(FileName, "rb"); if(!srcFile->IsOpen()) { delete srcFile; srcFile = NULL; return 3; // can't open } CVFSFile::File* TargetFile = new CVFSFile::File(); short len = strlen(TargetName) + 1; char* NormalizedTargetName = new char[len]; CIndex::NormalizePath(TargetName, NormalizedTargetName); for(short j = 0; j < (len - 1); j++) { NormalizedTargetName[j] = toupper(NormalizedTargetName[j]); } TargetFile->path = NormalizedTargetName; TargetFile->version = version; TargetFile->crc = crc; TargetFile->vfsIndex = distance(ListVFS->begin(), i); TargetFile->currentPosition = 0; TargetFile->deleted = false; TargetFile->hash = toHash(TargetFile->path); TargetFile->offset = (*i)->VFile->Size(); TargetFile->length = srcFile->Size(); if(TargetFile->length == 0) { delete TargetFile; TargetFile = NULL; return 10; } TargetFile->data = new unsigned char[TargetFile->length]; if(TargetFile->data == NULL || TargetFile->data == (unsigned char*)-1) { delete TargetFile; TargetFile = NULL; return 6; // memalloc fail } if(!srcFile->ReadData(TargetFile->data, TargetFile->length)) { delete TargetFile; TargetFile = NULL; return 6; // memalloc fail (not really but it suits the error the best) } long pos = (*i)->VFile->Position(); (*i)->VFile->Seek((*i)->VFile->Size()); (*i)->VFile->WriteData(TargetFile->data, TargetFile->length); (*i)->VFile->Seek(pos); (*i)->Files->push_back(TargetFile); (*i)->FileTable.addHash(TargetFile->hash, TargetFile); (*i)->SetFileCount((*i)->GetFileCount() + 1); this->changed = true; srcFile->Close(); delete srcFile; srcFile = NULL; delete[] NormalizedTargetName; NormalizedTargetName = NULL; } } if(VfsFound == false) { return 2; // invalid vfs } return 0; }
//----------------------------------------------------------------------------- //! void EventDispatcher::onPointerMove( EventCondition* cond, Callback call ) { Hash hash = toHash( Event::POINTER_MOVE ); _callbacks[hash].add( cond, call ); }
//----------------------------------------------------------------------------- //! void EventDispatcher::onPointerRelease( EventCondition* cond, Callback call ) { Hash hash = toHash( Event::POINTER_RELEASE ); _callbacks[hash].add( cond, call ); }
//----------------------------------------------------------------------------- //! void EventDispatcher::onPointerPress( EventCondition* cond, Callback call ) { Hash hash = toHash( Event::POINTER_PRESS ); _callbacks[hash].add( cond, call ); }
bool CIndex::Open(const char* FileName, const char* Mode) { UNREFERENCED_PARAMETER(Mode); IFile = new FlatFile(); if(!IFile->Open(FileName, "rb")) { return false; } this->name = (char*)FileName; this->baseVersion = IFile->Read<int>(); this->currentVersion = IFile->Read<int>(); this->vfsCount = IFile->Read<int>(); bool HasRoot = false; for(int i = 0; i < vfsCount; i++) { CVFSFile* VfsFile = new CVFSFile(); short len = IFile->Read<short>(); VfsFile->SetVFSName((char*)IFile->ReadBytes(len)); if(!strcmp(VfsFile->GetVFSName(), "ROOT.VFS")) { HasRoot = true; } VfsFile->SetDataOffset(IFile->Read<unsigned int>()); ListVFS->push_back(VfsFile); } if(HasRoot == true) { for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i) { if(i == ListVFS->end()) { break; } if(!strcmp((*i)->GetVFSName(), "ROOT.VFS")) { delete (*i); (*i) = NULL; i = ListVFS->erase(i); vfsCount--; break; } } } for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i) { IFile->Seek((*i)->GetDataOffset()); (*i)->SetFileCount(IFile->Read<unsigned int>()); (*i)->SetDeleteCount(IFile->Read<unsigned int>()); (*i)->SetStartOffset(IFile->Read<unsigned int>()); unsigned int j = 0; while(j < (*i)->GetFileCount()) { CVFSFile::File* RoseFile = new CVFSFile::File(); RoseFile->vfsIndex = distance(ListVFS->begin(), i); RoseFile->data = NULL; short len = IFile->Read<short>(); RoseFile->path = (char*)IFile->ReadBytes(len); RoseFile->offset = IFile->Read<int>(); RoseFile->length = IFile->Read<int>(); int bs = IFile->Read<int>(); RoseFile->deleted = IFile->Read<bool>(); bool ct = IFile->Read<bool>(); RoseFile->btEncrypted = IFile->Read<unsigned char>(); RoseFile->version = IFile->Read<int>(); RoseFile->crc = IFile->Read<int>(); RoseFile->lEndOff = RoseFile->offset + RoseFile->length; RoseFile->hash = toHash(RoseFile->path); (*i)->Files->push_back(RoseFile); // do allow deleted files if(!RoseFile->deleted) // but do not make a hash for them { (*i)->FileTable.addHash(RoseFile->hash, RoseFile); } j++; } } IFile->Close(); for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i) { (*i)->VFile = new FlatFile(); (*i)->VFile->Open((*i)->GetVFSName(), "rb+"); } this->Opened = true; return true; }
//----------------------------------------------------------------------------- //! void EventDispatcher::onPointerScroll( EventCondition* cond, Callback call ) { Hash hash = toHash( Event::POINTER_SCROLL ); _callbacks[hash].add( cond, call ); }
//----------------------------------------------------------------------------- //! bool EventDispatcher::dispatch( const Event& ev ) { Hash hash; switch( ev.type() ) { case Event::POINTER_PRESS : hash = toHash( ev.type(), ev.value() ); break; case Event::POINTER_RELEASE: hash = toHash( ev.type(), ev.value() ); break; case Event::POINTER_MOVE : hash = toHash( ev.type() ); break; case Event::POINTER_ENTER : return false; case Event::POINTER_LEAVE : return false; case Event::POINTER_CHANGE : return false; case Event::POINTER_SCROLL : hash = toHash( ev.type() ); break; case Event::POINTER_DELETE : return false; case Event::POINTER_CANCEL : hash = toHash( ev.type() ); break; case Event::KEY_PRESS : hash = toHash( ev.type(), ev.value() ); break; case Event::KEY_RELEASE : hash = toHash( ev.type(), ev.value() ); break; case Event::CHAR : hash = toHash( ev.type(), ev.value() ); break; case Event::HID_EVENT : hash = toHash( ev.type() ); break; case Event::ACCELERATE : hash = toHash( ev.type() ); break; default: CHECK( false ); return false; } HashTable<Hash, ConditionCallbacks>::Iterator cur; HashTable<Hash, ConditionCallbacks>::Iterator end = _callbacks.end(); cur = _callbacks.find( hash ); if( cur != end ) { if( cur.data().check(ev) ) return true; } // Convert to a generic ID first. Hash hashAnyID = toAnyID( hash ); if( hashAnyID != hash ) { cur = _callbacks.find( hashAnyID ); if( cur != end ) { if( cur.data().check(ev) ) return true; } } // Convert to a generic type and a generic ID. Hash hashAnyAll = toHash( ANY_TYPE, ANY_VALUE ); if( hashAnyAll != hashAnyID ) { cur = _callbacks.find( hashAnyAll ); if( cur != end ) { if( cur.data().check(ev) ) return true; } } return false; }
//----------------------------------------------------------------------------- //! void EventDispatcher::onAccelerate( EventCondition* cond, Callback call ) { Hash hash = toHash( Event::ACCELERATE ); _callbacks[hash].add( cond, call ); }
//----------------------------------------------------------------------------- //! void EventDispatcher::onHID( EventCondition* cond, Callback call ) { Hash hash = toHash( Event::HID_EVENT ); _callbacks[hash].add( cond, call ); }
//----------------------------------------------------------------------------- //! void EventDispatcher::onChar( int theChar, EventCondition* cond, Callback call ) { Hash hash = toHash( Event::CHAR, theChar ); _callbacks[hash].add( cond, call ); }
//----------------------------------------------------------------------------- //! void EventDispatcher::onKeyRelease( EventCondition* cond, Callback call ) { Hash hash = toHash( Event::KEY_RELEASE ); _callbacks[hash].add( cond, call ); }
bool Index::Load(const char *path, std::vector<VFSFILE*> &Entry, CHashTable<VFSFILE*> &Table) { fIndex = new FlatFile(path, "rb"); if(!fIndex->IsOpen()) return false; file = path; fIndex->Read(basever); fIndex->Read(curversion); fIndex->Read(vfscount); vfsname = new String[vfscount]; offset = new unsigned long[vfscount]; for(unsigned long i = 0; i < vfscount; i++) { unsigned short VfsNameLenght; fIndex->Read(VfsNameLenght); char *tempname = new char[VfsNameLenght]; fIndex->ReadData(tempname, VfsNameLenght); vfsname[i] = tempname; fIndex->Read(offset[i]); } vinfo = new VFSINFO*[vfscount]; for(unsigned long i = 0; i < vfscount; i++) { vinfo[i] = new VFSINFO; fIndex->Seek(offset[i]); fIndex->Read(vinfo[i]->filecount); fIndex->Read(vinfo[i]->deletecount); fIndex->Read(vinfo[i]->startoffset); } unsigned long i = 0; while(i < (vfscount)) { fIndex->Seek(offset[i]); fIndex->Skip((12)); // skip vfsinfo to read fileinfo bool isRoot = false; if(!vfsname[i].Compare("ROOT.VFS")) { isRoot = true; } unsigned long j = 0; while(j < vinfo[i]->filecount) { if(isRoot) break; unsigned long thisoffset = fIndex->Position(); unsigned short len; fIndex->Read(len); char *tmp = new char[len]; fIndex->ReadData(tmp, len); fIndex->Skip(12); bool del = false; fIndex->Read(del); fIndex->Skip(10); if(!del) { VFSFILE* vfs = new VFSFILE; fIndex->Seek(thisoffset); vfs->vfs = vfsname[i].Str(); fIndex->Read(vfs->strlen); vfs->path = new char[vfs->strlen]; fIndex->ReadData(vfs->path, vfs->strlen); fIndex->Read(vfs->offset); // 4 fIndex->Read(vfs->size); // 4 fIndex->Read(vfs->blockSize); // 4 fIndex->Read(vfs->deleted); // 1 fIndex->Read(vfs->compressiontype); // 1 fIndex->Read(vfs->encryptiontype); // 1 fIndex->Read(vfs->version); // 4 fIndex->Read(vfs->checksum); // 4 Entry.push_back(vfs); Table.addHash(toHash(vfs->path), vfs); } SAFE_DELETE_ARRAY(tmp); j++; } i++; } return true; }
//----------------------------------------------------------------------------- //! void EventDispatcher::onKeyPress( EventCondition* cond, Callback call ) { Hash hash = toHash( Event::KEY_PRESS ); _callbacks[hash].add( cond, call ); }
//----------------------------------------------------------------------------- //! void EventDispatcher::onPointerCancel( EventCondition* cond, Callback call ) { Hash hash = toHash( Event::POINTER_CANCEL ); _callbacks[hash].add( cond, call ); }