From 3c4ac74af155758aab430071a554326bf2e31402 Mon Sep 17 00:00:00 2001 From: tariq Date: Sun, 22 Jan 2006 20:34:15 +0000 Subject: [PATCH] changed data type of group and entry list from vector (STL) to QList (Qt) git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@19 b624d157-de02-0410-bad0-e51aec6abb33 --- src/Database.cpp | 10 ++++ src/Database.h | 11 ++-- src/PwManager.cpp | 115 +++++++++++++++++++++++++----------------- src/PwManager.h | 12 ++--- src/lib/GroupView.cpp | 28 +++++----- src/lib/SecString.cpp | 12 ++--- src/lib/SecString.h | 4 +- src/mainwindow.cpp | 1 + 8 files changed, 111 insertions(+), 82 deletions(-) diff --git a/src/Database.cpp b/src/Database.cpp index e85be07..037b7df 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -34,6 +34,16 @@ pBinaryData=NULL; bool CGroup::UI_ExpandByDefault=true; +bool CEntry::operator==(const CEntry& e)const{ +if(sID==e.sID)return true; +else return false; +} + +bool CGroup::operator==(const CGroup& g)const{ +if(ID==g.ID)return true; +else return false; +} + CGroup::CGroup(){ Creation=QDateTime::currentDateTime(); LastAccess=QDateTime::currentDateTime(); diff --git a/src/Database.h b/src/Database.h index 6c62eec..db4f25b 100644 --- a/src/Database.h +++ b/src/Database.h @@ -20,7 +20,7 @@ #ifndef _DATABASE_H_ #define _DATABASE_H_ -#include +#include #include #include "lib/SecString.h" using namespace std; @@ -47,6 +47,7 @@ Q_UINT8 *pBinaryData; Q_UINT32 BinaryDataLength; Q_UINT32 PasswordLength; bool ReadEntryField(Q_UINT16 FieldType, Q_UINT32 FieldSize, Q_UINT8 *pData); +bool operator==(const CEntry&) const; }; @@ -65,6 +66,7 @@ QDateTime Expire; Q_UINT16 Level; Q_UINT32 Flags; bool ReadGroupField(Q_UINT16 FieldType, Q_UINT32 FieldSize, Q_UINT8 *pData); +bool operator==(const CGroup&) const; bool UI_ItemIsExpanded; static bool UI_ExpandByDefault; @@ -72,9 +74,6 @@ static bool UI_ExpandByDefault; }; -typedef vector::iterator EntryItr; -typedef vector::iterator GroupItr; - class Database{ public: @@ -83,8 +82,8 @@ public: QString filename; bool modflag; int SearchGroupID; - vectorGroups; - vectorEntries; + QListGroups; + QListEntries; protected: Q_UINT8 MasterKey[32]; diff --git a/src/PwManager.cpp b/src/PwManager.cpp index 94bb70b..a504b8a 100755 --- a/src/PwManager.cpp +++ b/src/PwManager.cpp @@ -140,16 +140,13 @@ err=trUtf8("Hash-Test fehlgeschlage: der Schlüssl ist falsch oder die Datei ist return false;} -Groups.resize(NumGroups); -Entries.resize(NumEntries); - unsigned long tmp_id=0; unsigned long pos = DB_HEADER_SIZE; Q_UINT16 FieldType; Q_UINT32 FieldSize; char* pField; bool bRet; - +CGroup group; for(unsigned long CurGroup = 0; CurGroup < NumGroups; ) { @@ -165,8 +162,9 @@ bool bRet; if(pos >= (total_size + FieldSize)) { return false;} - bRet = Groups[CurGroup].ReadGroupField(FieldType, FieldSize, (Q_UINT8 *)pField); + bRet = group.ReadGroupField(FieldType, FieldSize, (Q_UINT8 *)pField); if((FieldType == 0xFFFF) && (bRet == true)){ + Groups << group; CurGroup++;} // Now and ONLY now the counter gets increased pField += FieldSize; @@ -174,6 +172,7 @@ bool bRet; if(pos >= total_size) { return false;} } +CEntry entry; for(unsigned long CurEntry = 0; CurEntry < NumEntries;) { @@ -189,9 +188,10 @@ bool bRet; if(pos >= (total_size + FieldSize)) { return false; } - bRet = Entries[CurEntry].ReadEntryField(FieldType,FieldSize,(Q_UINT8*)pField); - if((FieldType == 0xFFFF) && (bRet == true)){ - Entries[CurEntry].sID=tmp_id++; + bRet = entry.ReadEntryField(FieldType,FieldSize,(Q_UINT8*)pField); + if((FieldType == 0xFFFF) && (bRet == true)){ + entry.sID=tmp_id++; + Entries << entry; CurEntry++;} // Now and ONLY now the counter gets increased pField += FieldSize; @@ -203,10 +203,10 @@ bool bRet; unsigned long CurGID, g, e, z, num; delete [] buffer; -for(vector::iterator i=Entries.begin();i!=Entries.end();i++){ -if(IsMetaStream(*i)==true){ +for(int i=0;i::iterator PwDatabase::deleteEntry(vector::iterator iterator){ -return Entries.erase(iterator); -} - -vector::iterator PwDatabase::deleteEntry(CEntry* entry){ -return deleteEntry(getEntryIterator(entry)); +void PwDatabase::deleteEntry(CEntry* entry){ +Entries.removeAt(Entries.indexOf(*entry)); } bool PwDatabase::IsMetaStream(CEntry& p){ @@ -559,6 +554,7 @@ Q_UINT8 FinalRandomSeed[16]; Q_UINT8 ContentsHash[32]; Q_UINT8 EncryptionIV[16]; +/* if(SearchGroupID!=-1){ for(int i=0;i::iterator i=Groups.begin();i!=Groups.end();i++){ -//if((*i).ID==pGroup->ID)return i;} -return Groups.begin()+(pGroup-&Groups[0]); -} - - -EntryItr PwDatabase::getEntryIterator(CEntry* pEntry){ -return Entries.begin()+(pEntry-&Entries[0]); -} CGroup* PwDatabase::addGroup(CGroup* parent){ CGroup group; @@ -833,41 +821,51 @@ group.ImageID=0; group.ID=getNewGroupId(); if(!Groups.size() || !parent){ - Groups.push_back(group); + Groups << group; return &Groups.back(); } -else { GroupItr groupIt; - groupIt=Groups.insert(getGroupIterator(parent)+1,group); - return &(*groupIt);} +else { int i=Groups.indexOf(*parent)+1; + Groups.insert(i,group); + return &Groups[i];} } -GroupItr PwDatabase::deleteGroup(unsigned long id){ +void PwDatabase::deleteGroup(unsigned long id){ for(int i=0;iLevel){ - last=i; - break;} +void PwDatabase::deleteGroup(CGroup* group){ +int GroupIndex=Groups.indexOf(*group); +int NumChilds; + +int i; +for(i=GroupIndex+1; iLevel)break; +} +NumChilds=i-GroupIndex-1; +qDebug("NUMCHILDS=%i\n",NumChilds); +//delete entries +for(i=GroupIndex; i<=GroupIndex+NumChilds; i++){ + for(int j=0; j=0; i--){ + Groups.removeAt(GroupIndex+i); } -return Groups.erase(first,last); } +int PwDatabase::getGroupIndex(CGroup* g){ +return getGroupIndex(g->ID); +} int PwDatabase::getGroupIndex(unsigned long ID){ @@ -959,6 +957,31 @@ for(int i=0; i<64; i+=2){ } } +void PwDatabase::moveGroup(CGroup* group, CGroup* DstGroup){ +/* +int NumSubGroups=0; +int GroupIndex=getGroupIndex(group); +int i; +for(i=GroupIndex+1; iLevel) break; +} +NumSubGroups=i-GroupIndex-1; +int LevelDiff; +if(DstGroup) + LevelDiff=DstGroup->Level - group->Level; +else + LevelDiff=-group->Level; + +if(DstGroup){ + groups.insert(pos, groups[ + + +} +*/ + +} + + void memcpyFromLEnd32(Q_UINT32* dst,char* src){ if(QSysInfo::ByteOrder==QSysInfo::BigEndian){ diff --git a/src/PwManager.h b/src/PwManager.h index d47d5da..3df641b 100755 --- a/src/PwManager.h +++ b/src/PwManager.h @@ -55,10 +55,13 @@ public: bool CalcMasterKeyByFileAndPw(QString filename, QString& password); CGroup* addGroup(CGroup* parent); - GroupItr deleteGroup(CGroup* pGroup); - GroupItr deleteGroup(unsigned long ID); + void deleteGroup(CGroup* pGroup); + void deleteGroup(unsigned long ID); + void moveGroup(CGroup* group, CGroup* DstGroup); + int getGroupIndex(CGroup* group); int getGroupIndex(unsigned long ID); - EntryItr deleteEntry(CEntry* pEntry); + + void deleteEntry(CEntry* pEntry); void moveEntry(CEntry* pEntry,CGroup* pDstGroup); CEntry* addEntry(); void merge(PwDatabase* db2); @@ -69,9 +72,6 @@ public: private: - EntryItr deleteEntry(vector::iterator i); - EntryItr getEntryIterator(CEntry* pEntry); - GroupItr getGroupIterator(CGroup* pGroup); bool IsMetaStream(CEntry& Entry); void transformKey(Q_UINT8* src,Q_UINT8* dst,Q_UINT8* seed,int rounds); bool readHeader(char* raw); diff --git a/src/lib/GroupView.cpp b/src/lib/GroupView.cpp index 0a865c4..a71663f 100644 --- a/src/lib/GroupView.cpp +++ b/src/lib/GroupView.cpp @@ -127,29 +127,29 @@ void KeepassGroupView::mouseMoveEvent(QMouseEvent *event){ void KeepassGroupView::updateItems(){ clear(); Items.clear(); -for(GroupItr i=db->Groups.begin();i!=db->Groups.end();i++){ -if((*i).Level==0){ +for(int i=0; iGroups.size();i++){ +if(db->Groups[i].Level==0){ if(Items.size()) Items.push_back(new GroupViewItem(this,getLastSameLevelItem(0))); else Items.push_back(new GroupViewItem(this)); - Items.back()->setText(0,(*i).Name); - Items.back()->pGroup=&(*i); + Items.back()->setText(0,db->Groups[i].Name); + Items.back()->pGroup=&db->Groups[i]; } else{ - if((*i).Level>(*(i-1)).Level){ - Items.push_back(new GroupViewItem(Items.back(),getLastSameLevelItem((*i).Level))); - Items.back()->setText(0,(*i).Name); - Items.back()->pGroup=&(*i); + if(db->Groups[i].Level>db->Groups[i-1].Level){ + Items.push_back(new GroupViewItem(Items.back(),getLastSameLevelItem(db->Groups[i].Level))); + Items.back()->setText(0,db->Groups[i].Name); + Items.back()->pGroup=&db->Groups[i]; } - if((*i).Level<=(*(i-1)).Level){ + if(db->Groups[i].Level<=db->Groups[i-1].Level){ GroupItemItr j; for(j=Items.end()-1;j!=Items.begin();j--){ - if((*j)->pGroup->Level<(*i).Level)break;} - Items.push_back(new GroupViewItem((*j),getLastSameLevelItem((*i).Level))); - Items.back()->setText(0,(*i).Name); - Items.back()->pGroup=&(*i); + if((*j)->pGroup->LevelGroups[i].Level)break;} + Items.push_back(new GroupViewItem((*j),getLastSameLevelItem(db->Groups[i].Level))); + Items.back()->setText(0,db->Groups[i].Name); + Items.back()->pGroup=&db->Groups[i]; } } -Items.back()->setIcon(0,EntryIcons[(*i).ImageID]); +Items.back()->setIcon(0,EntryIcons[db->Groups[i].ImageID]); } for(int i=0;i #include #include #include "crypto/rijndael.h" @@ -42,9 +43,8 @@ public: private: static Q_UINT8 Key[32]; QString plaintext; - char* data; + QByteArray data; int len; - int cryptlen; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8c5ec22..db041a7 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -412,4 +412,5 @@ Q_ASSERT(GroupView->selectedItems().size()); CGroup *pGroup=static_cast(GroupView->selectedItems()[0])->pGroup; db->deleteGroup(pGroup); GroupView->updateItems(); +setStateFileModified(true); } \ No newline at end of file