From 76e91678d8de80af7e142e090bfbc093cdc57e24 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Sat, 2 Oct 2010 01:47:38 -0400 Subject: [PATCH] lib: added DBName support to parsers and builders For the upcoming libbarrybackup, it makes sense that parsers and builders know what database they are working on, since it is possible they can contain more than one. This commit adds the DBName argument to SetIds(), which means that during a Desktop::LoadDatabase(), the database name will automatically come along with it. It also adds Builder::GetDBName(), which supports it in the other direction. --- gui/src/DeviceIface.cc | 9 ++++++++- gui/src/DeviceIface.h | 4 +++- man/brecsum.1 | 3 +++ src/builder.h | 8 ++++++++ src/m_desktop.cc | 10 ++++++++-- src/packet.cc | 6 ++++-- src/packet.h | 3 ++- src/parser.h | 9 ++++++--- tools/bfuse.cc | 3 ++- tools/brecsum.cc | 6 ++++-- tools/btool.cc | 3 ++- 11 files changed, 50 insertions(+), 14 deletions(-) diff --git a/gui/src/DeviceIface.cc b/gui/src/DeviceIface.cc index 5e8e0647..c7ec8a1c 100644 --- a/gui/src/DeviceIface.cc +++ b/gui/src/DeviceIface.cc @@ -507,7 +507,9 @@ void DeviceInterface::Clear() { } -void DeviceInterface::SetIds(uint8_t RecType, uint32_t UniqueId) +void DeviceInterface::SetIds(const std::string &DbName, + uint8_t RecType, + uint32_t UniqueId) { m_rec_type = RecType; m_unique_id = UniqueId; @@ -601,6 +603,11 @@ bool DeviceInterface::Retrieve(unsigned int dbId) } } +std::string DeviceInterface::GetDBName() const +{ + return m_current_dbname; +} + uint8_t DeviceInterface::GetRecType() const { return m_rec_type; diff --git a/gui/src/DeviceIface.h b/gui/src/DeviceIface.h index 14d76680..55b1ac0d 100644 --- a/gui/src/DeviceIface.h +++ b/gui/src/DeviceIface.h @@ -173,7 +173,8 @@ public: // Barry::Parser overrides virtual void Clear(); - virtual void SetIds(uint8_t RecType, uint32_t UniqueId); + virtual void SetIds(const std::string &DbName, + uint8_t RecType, uint32_t UniqueId); virtual void ParseHeader(const Barry::Data &data, size_t &offset); virtual void ParseFields(const Barry::Data &data, size_t &offset, const Barry::IConverter *ic); @@ -181,6 +182,7 @@ public: // Barry::Builder overrides virtual bool Retrieve(unsigned int dbId); + virtual std::string GetDBName() const; virtual uint8_t GetRecType() const; virtual uint32_t GetUniqueId() const; virtual void BuildHeader(Barry::Data &data, size_t &offset); diff --git a/man/brecsum.1 b/man/brecsum.1 index 73fe66e8..a8000402 100644 --- a/man/brecsum.1 +++ b/man/brecsum.1 @@ -36,6 +36,9 @@ Specify the database to download and sum. This option may be given multiple times to fetch more than one database. See btool's \-t option to retrieve a list of databases on your device. .TP +.B \-i +Include DB Name, Type, and Unique record IDs in the checksums. +.TP .B \-p pin Specify the PIN of the device to talk to. Only needed if there are multiple Blackberries plugged into your system at once. diff --git a/src/builder.h b/src/builder.h index e441853d..9604c15d 100644 --- a/src/builder.h +++ b/src/builder.h @@ -23,6 +23,8 @@ #define __BARRY_BUILDER_H__ #include "dll.h" +#include "data.h" +#include namespace Barry { @@ -49,6 +51,7 @@ public: virtual bool Retrieve(unsigned int databaseId) = 0; /// Called to retrive the unique ID for this record. + virtual std::string GetDBName() const = 0; virtual uint8_t GetRecType() const = 0; virtual uint32_t GetUniqueId() const = 0; @@ -117,6 +120,11 @@ public: return (*m_storage)(m_rec, databaseId); } + virtual std::string GetDBName() const + { + return RecordT::GetDBName(); + } + virtual uint8_t GetRecType() const { return m_rec.GetRecType(); diff --git a/src/m_desktop.cc b/src/m_desktop.cc index eecdc685..c2654436 100644 --- a/src/m_desktop.cc +++ b/src/m_desktop.cc @@ -253,6 +253,9 @@ void Desktop::GetRecord(unsigned int dbId, { dout("Database ID: " << dbId); + std::string dbName; + m_dbdb.GetDBName(dbId, dbName); + Data command, response; DBPacket packet(*this, command, response); packet.GetRecordByIndex(dbId, stateTableIndex); @@ -282,7 +285,7 @@ void Desktop::GetRecord(unsigned int dbId, } // grab that data - packet.Parse(parser, m_ic); + packet.Parse(parser, dbName, m_ic); // flush the command sequence while( packet.Command() != SB_COMMAND_DB_DONE ) @@ -394,6 +397,9 @@ void Desktop::LoadDatabase(unsigned int dbId, Parser &parser) { dout("Database ID: " << dbId); + std::string dbName; + m_dbdb.GetDBName(dbId, dbName); + Data command, response; DBPacket packet(*this, command, response); packet.GetRecords(dbId); @@ -404,7 +410,7 @@ void Desktop::LoadDatabase(unsigned int dbId, Parser &parser) if( packet.Command() == SB_COMMAND_DB_DATA ) { // this size is the old header size, since using // old command above - packet.Parse(parser, m_ic); + packet.Parse(parser, dbName, m_ic); } // advance! diff --git a/src/packet.cc b/src/packet.cc index ed801afc..12ede3fc 100644 --- a/src/packet.cc +++ b/src/packet.cc @@ -490,7 +490,8 @@ unsigned int DBPacket::DBOperation() const /// \returns bool true - packet was recognized and parse was attempted /// false - packet was not recognized /// -bool DBPacket::Parse(Parser &parser, const IConverter *ic) +bool DBPacket::Parse(Parser &parser, const std::string &dbname, + const IConverter *ic) { size_t offset = 0; MAKE_PACKET(rpack, m_receive); @@ -505,7 +506,8 @@ bool DBPacket::Parse(Parser &parser, const IConverter *ic) Protocol::CheckSize(m_receive, offset); // FIXME - this may need adjustment for email records... they // don't seem to have uniqueID's - parser.SetIds(rpack->u.db.u.response.u.tagged.rectype, + parser.SetIds(dbname, + rpack->u.db.u.response.u.tagged.rectype, btohl(rpack->u.db.u.response.u.tagged.uniqueId)); parser.ParseHeader(m_receive, offset); diff --git a/src/packet.h b/src/packet.h index 1a396fc3..e788e5ac 100644 --- a/src/packet.h +++ b/src/packet.h @@ -162,7 +162,8 @@ public: unsigned int ReturnCode() const; // throws FIXME if packet doesn't support it unsigned int DBOperation() const; // throws Error on size trouble - bool Parse(Parser &parser, const IConverter *ic); // switches based on last m_send command + bool Parse(Parser &parser, const std::string &dbname, + const IConverter *ic); // switches based on last m_send command // response parsers }; diff --git a/src/parser.h b/src/parser.h index 929c794c..d3014cc3 100644 --- a/src/parser.h +++ b/src/parser.h @@ -59,7 +59,8 @@ public: virtual void Clear() = 0; /// Stores the IDs - virtual void SetIds(uint8_t RecType, uint32_t UniqueId) = 0; + virtual void SetIds(const std::string &DbName, + uint8_t RecType, uint32_t UniqueId) = 0; /// Called to parse the header portion of the raw data packet. /// data contains the entire packet, and offset contains the @@ -101,7 +102,8 @@ public: virtual void Clear() {} /// Stores the IDs - virtual void SetIds(uint8_t RecType, uint32_t UniqueId) {} + virtual void SetIds(const std::string &DbName, + uint8_t RecType, uint32_t UniqueId) {} /// Called to parse the header portion of the raw data packet. /// data contains the entire packet, and offset contains the @@ -194,7 +196,8 @@ public: m_rec = RecordT(); } - virtual void SetIds(uint8_t RecType, uint32_t UniqueId) + virtual void SetIds(const std::string &DbName, + uint8_t RecType, uint32_t UniqueId) { m_rec.SetIds(RecType, UniqueId); } diff --git a/tools/bfuse.cc b/tools/bfuse.cc index b248ed8f..25714614 100644 --- a/tools/bfuse.cc +++ b/tools/bfuse.cc @@ -121,7 +121,8 @@ public: virtual void Clear() {} - virtual void SetIds(uint8_t RecType, uint32_t UniqueId) + virtual void SetIds(const std::string &DbName, + uint8_t RecType, uint32_t UniqueId) { m_id = UniqueId; } diff --git a/tools/brecsum.cc b/tools/brecsum.cc index a3fc04b4..cd2ab047 100644 --- a/tools/brecsum.cc +++ b/tools/brecsum.cc @@ -44,7 +44,7 @@ void Usage() << " -d db Read database 'db' and sum all its records.\n" << " Can be used multiple times to fetch more than one DB\n" << " -h This help\n" - << " -i Include Type and Unique record IDs in the checksums\n" + << " -i Include DB Name, Type, and Unique record IDs in the checksums\n" << " -p pin PIN of device to talk with\n" << " If only one device is plugged in, this flag is optional\n" << " -P pass Simplistic method to specify device password\n" @@ -67,9 +67,11 @@ public: SHA1_Init(&m_ctx); } - virtual void SetIds(uint8_t RecType, uint32_t UniqueId) + virtual void SetIds(const std::string &DbName, + uint8_t RecType, uint32_t UniqueId) { if( m_IncludeIds ) { + SHA1_Update(&m_ctx, DbName.c_str(), DbName.size()); SHA1_Update(&m_ctx, &RecType, sizeof(RecType)); SHA1_Update(&m_ctx, &UniqueId, sizeof(UniqueId)); } diff --git a/tools/btool.cc b/tools/btool.cc index c74e194f..1c5b1511 100644 --- a/tools/btool.cc +++ b/tools/btool.cc @@ -324,7 +324,8 @@ class DataDumpParser : public Barry::Parser public: virtual void Clear() {} - virtual void SetIds(uint8_t RecType, uint32_t UniqueId) + virtual void SetIds(const std::string &DbName, + uint8_t RecType, uint32_t UniqueId) { m_id = UniqueId; } -- 2.11.4.GIT