Here is a patch to include the "Folders" database. I hacked it up for
debugging the Messages header stuff, but it is a good starting place for
someone who wants to write a BB desktop for linux.
The parent directory information is kept in field codes 0x0d and 0x0e. I
didn't format them for printing.
-edge
Index: tools/btool.cc
===================================================================
RCS file: /cvsroot/barry/barry/tools/btool.cc,v
retrieving revision 1.19
diff -u -r1.19 btool.cc
--- tools/btool.cc 8 Jun 2007 18:54:22 -0000 1.19
+++ tools/btool.cc 24 Jun 2007 16:39:17 -0000
@@ -239,6 +239,11 @@
new RecordParser<SavedMessage, Store<SavedMessage> > (
new Store<SavedMessage>(filename, false)));
}
+ else if( name == "Folders" ) {
+ return auto_ptr<Parser>(
+ new RecordParser<Folder, Store<Folder> > (
+ new Store<Folder>(filename, false)));
+ }
else {
// unknown database, use null parser
return auto_ptr<Parser>( new DataDumpParser );
Index: src/record.h
===================================================================
RCS file: /cvsroot/barry/barry/src/record.h,v
retrieving revision 1.27
diff -u -r1.27 record.h
--- src/record.h 8 Jun 2007 19:25:15 -0000 1.27
+++ src/record.h 24 Jun 2007 16:39:17 -0000
@@ -208,6 +208,7 @@
#include "r_task.h"
#include "r_pin_message.h"
#include "r_saved_message.h"
+#include "r_folder.h"
#endif
Index: src/Makefile.am
===================================================================
RCS file: /cvsroot/barry/barry/src/Makefile.am,v
retrieving revision 1.19
diff -u -r1.19 Makefile.am
--- src/Makefile.am 8 Jun 2007 18:56:01 -0000 1.19
+++ src/Makefile.am 24 Jun 2007 16:39:17 -0000
@@ -70,6 +70,7 @@
r_saved_message.h \
r_servicebook.h \
r_task.h \
+ r_folder.h \
socket.h \
time.h \
usbwrap.h \
@@ -97,6 +98,7 @@
r_saved_message.cc \
r_servicebook.cc \
r_task.cc \
+ r_folder.cc \
packet.cc packet.h \
controller.cc \
version.cc \
Index: src/s11n-boost.h
===================================================================
RCS file: /cvsroot/barry/barry/src/s11n-boost.h,v
retrieving revision 1.9
diff -u -r1.9 s11n-boost.h
--- src/s11n-boost.h 8 Jun 2007 18:54:22 -0000 1.9
+++ src/s11n-boost.h 24 Jun 2007 16:39:17 -0000
@@ -252,6 +252,15 @@
}
}
+template <class ArchiveT>
+void serialize(ArchiveT &ar, Barry::Folder &f, const unsigned int ver)
+{
+ ar & make_nvp("FolderName", f.FolderName);
+ if( ver < BARRY_POD_MAP_VERSION ) {
+ ar & make_nvp( "Unknowns", f.Unknowns);
+ }
+}
+
}} // namespace boost::serialization
#endif
Index: src/r_folder.h
===================================================================
RCS file: src/r_folder.h
diff -N src/r_folder.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/r_folder.h 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,96 @@
+///
+/// \file r_folder.h
+/// Record parsing class for the Folder database.
+///
+
+/*
+ Copyright (C) 2005-2007, Net Direct Inc. (http://www.netdirect.ca/)
+ Copyright (C) 2007, Brian Edginton
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ See the GNU General Public License in the COPYING file at the
+ root directory of this project for more details.
+*/
+
+#ifndef __BARRY_RECORD_FOLDER_H__
+#define __BARRY_RECORD_FOLDER_H__
+
+#include "record.h"
+#include <vector>
+#include <string>
+#include <stdint.h>
+
+namespace Barry {
+
+class Folder
+{
+public:
+ typedef std::vector<UnknownField> UnknownsType;
+ uint8_t RecType;
+ uint32_t RecordId;
+
+ std::string FolderName;
+ uint16_t FolderNumber; // Not unique, used for ordering of subfolders - NOT level
+ uint16_t FolderLevel; // From parent
+
+ enum FolderTypeEnum {
+ FolderSubtree = 0,
+ FolderDeleted,
+ FolderInbox,
+ FolderOutbox,
+ FolderSent,
+ FolderOther,
+ FolderDraft = 0x0a
+ };
+ FolderTypeEnum FolderType;
+
+ enum FolderStatusType {
+ FolderOrphan = 0x50,
+ FolderUnfiled,
+ FolderFiled,
+ };
+
+ UnknownsType Unknowns;
+
+public:
+ Folder();
+ ~Folder();
+
+ const unsigned char* ParseField(const unsigned char *begin,
+ const unsigned char *end);
+ uint8_t GetRecType() const { return RecType; }
+ uint32_t GetUniqueId() const { return RecordId; }
+ void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
+ void ParseHeader(const Data &data, size_t &offset);
+ void ParseFields(const Data &data, size_t &offset);
+ void BuildHeader(Data &data, size_t &offset) const;
+
+ void Clear();
+
+ void Dump(std::ostream &os) const;
+ bool operator<(const Folder &other) const { return FolderName < other.FolderName; }
+
+ // database name
+ static const char * GetDBName() { return "Folders"; }
+ static uint8_t GetDefaultRecType() { return 0; }
+
+};
+
+inline std::ostream& operator<<(std::ostream &os, const Folder &msg) {
+ msg.Dump(os);
+ return os;
+}
+
+} // namespace Barry
+
+#endif // __BARRY_RECORD_FOLDER_H__
+
+
Index: src/r_folder.cc
===================================================================
RCS file: src/r_folder.cc
diff -N src/r_folder.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/r_folder.cc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,180 @@
+///
+/// \file r_folder.cc
+/// Record parsing class for the folders database.
+///
+
+/*
+ Copyright (C) 2005-2007, Net Direct Inc. (http://www.netdirect.ca/)
+ Copyright (C) 2007, Brian Edginton
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ See the GNU General Public License in the COPYING file at the
+ root directory of this project for more details.
+*/
+
+#include "r_folder.h"
+#include "record-internal.h"
+#include "protostructs.h"
+#include "data.h"
+#include "time.h"
+#include "debug.h"
+#include <ostream>
+#include <iomanip>
+
+using namespace std;
+using namespace Barry::Protocol;
+
+namespace Barry {
+
+///////////////////////////////////////////////////////////////////////////////
+// Folder Class
+
+// Folder Field Codes
+
+#define FFC_NUMBER 0x0a
+#define FFC_LEVEL 0x0b
+#define FFC_NAME 0x0c
+#define FFC_ADDRESS1 0x0d
+#define FFC_ADDRESS2 0x0e
+#define FFC_TYPE 0x0f
+#define FFC_END 0xffff
+
+// Folder Types
+#define SUBTREE 0x00
+#define DELETED 0x01
+#define INBOX 0x02
+#define OUTBOX 0x03
+#define SENT 0x04
+#define OTHER 0x05
+#define DRAFT 0x0a
+
+// Folder Status
+#define ORPHAN 0x50
+#define UNFILED 0x51
+#define FILED 0x52
+
+#define INVALID -1
+
+#define SEPARATOR 0x2f
+#define ROOT_SEPARATOR 0x3a
+
+FieldLink<Folder> FolderFieldLinks[] = {
+ { FFC_NAME, "FolderName", 0, 0, &Folder::FolderName, 0, 0 },
+ { FFC_END, "End of List", 0, 0, 0, 0, 0 },
+};
+
+Folder::Folder()
+{
+ Clear();
+}
+
+
+Folder::~Folder()
+{
+}
+
+const unsigned char* Folder::ParseField(const unsigned char *begin,
+ const unsigned char *end)
+{
+ const CommonField *field = (const CommonField *) begin;
+
+ // advance and check size
+ begin += COMMON_FIELD_HEADER_SIZE + btohs(field->size);
+ if( begin > end ) // if begin==end, we are ok
+ return begin;
+
+ if( !btohs(field->size) ) // if field has no size, something's up
+ return begin;
+
+ // cycle through the type table
+ for( FieldLink<Folder> *b = FolderFieldLinks;
+ b->type != FFC_END;
+ b++ )
+ {
+ if( b->type == field->type ) {
+ if( b->strMember ) {
+ std::string &s = this->*(b->strMember);
+ s.assign((const char *)field->u.raw, btohs(field->size)-1);
+ return begin; // done!
+ }
+ else if( b->timeMember && btohs(field->size) == 4 ) {
+ time_t &t = this->*(b->timeMember);
+ t = min2time(field->u.min1900);
+ return begin;
+ }
+ }
+ }
+ // handle special cases
+ switch( field->type )
+ {
+ case FFC_TYPE:
+ FolderType = (FolderTypeEnum)field->u.raw[0];
+ return begin;
+ case FFC_NUMBER:
+ FolderNumber = field->u.raw[0]; // two's complement
+ return begin;
+ case FFC_LEVEL:
+ FolderLevel = field->u.raw[0];
+ return begin;
+ }
+
+ // if still not handled, add to the Unknowns list
+ UnknownField uf;
+ uf.type = field->type;
+ uf.data.assign((const char*)field->u.raw, btohs(field->size));
+ Unknowns.push_back(uf);
+
+ // return new pointer for next field
+ return begin;
+}
+
+void Folder::ParseHeader(const Data &data, size_t &offset)
+{
+ // no header in Folder records
+}
+
+void Folder::ParseFields(const Data &data, size_t &offset)
+{
+ const unsigned char *finish = ParseCommonFields(*this,
+ data.GetData() + offset, data.GetData() + data.GetSize());
+ offset += finish - (data.GetData() + offset);
+}
+
+void Folder::Clear()
+{
+ FolderName.clear();
+ Unknowns.clear();
+ FolderType = (FolderTypeEnum)0;
+}
+
+void Folder::Dump(std::ostream &os) const
+{
+ static const char *FolderTypeString[] = { "Subtree", "Deleted", "Inbox", "Outbox", "Sent", "Other"};
+ static const char *FolderStatusString[] = { "Orphan", "Unfiled", "Filed" };
+
+ os << "Folder Records\n\n";
+ os << "Folder Name: " << FolderName << "\n";
+ os << "Folder Type: ";
+ if( FolderType < FolderDraft )
+ os << FolderTypeString[FolderType] << "\n";
+ else if( FolderType == FolderDraft )
+ os << "Draft\n";
+ else
+ os << "Unknown (" << std::hex << FolderType << ")\n";
+ os << "Folder Number: " << std::dec << FolderNumber << "\n";
+ os << "Folder Level: " << std::dec << FolderLevel << "\n";
+ os << "\n";
+ os << Unknowns;
+ os << "\n\n";
+}
+
+} // namespace Barry
+
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Barry-devel mailing list
Barry-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/barry-devel