3 /// Blackberry database record classes. Help translate data
4 /// from data packets to useful structurs, and back.
8 Copyright (C) 2005-2006, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #ifndef __BARRY_RECORD_H__
24 #define __BARRY_RECORD_H__
31 // forward declarations
37 // NOTE: All classes here must be container-safe! Perhaps add sorting
38 // operators in the future.
52 typedef std::vector
<Command
> CommandArrayType
;
54 CommandArrayType Commands
;
57 const unsigned char* ParseField(const unsigned char *begin
,
58 const unsigned char *end
);
63 void Parse(const Data
&data
, size_t offset
);
66 // returns 0 if unable to find command name, which is safe, since
67 // 0 is a special command that shouldn't be in the table anyway
68 unsigned int GetCommand(const std::string
&name
) const;
70 void Dump(std::ostream
&os
) const;
73 inline std::ostream
& operator<< (std::ostream
&os
, const CommandTable
&command
) {
80 class DatabaseDatabase
86 unsigned int RecordCount
;
90 typedef std::vector
<Database
> DatabaseArrayType
;
92 DatabaseArrayType Databases
;
95 template <class RecordType
, class FieldType
>
96 void ParseRec(const RecordType
&rec
, const unsigned char *end
);
98 template <class FieldType
>
99 const unsigned char* ParseField(const unsigned char *begin
,
100 const unsigned char *end
);
106 void Parse(const Data
&data
);
109 // returns true on success, and fills target
110 bool GetDBNumber(const std::string
&name
, unsigned int &number
) const;
111 bool GetDBName(unsigned int number
, std::string
&name
) const;
113 void Dump(std::ostream
&os
) const;
116 inline std::ostream
& operator<<(std::ostream
&os
, const DatabaseDatabase
&dbdb
) {
128 std::ostream
& operator<< (std::ostream
&os
, const std::vector
<UnknownField
> &unknowns
);
131 /// \addtogroup RecordParserClasses
132 /// Parser and data storage classes. These classes take a
133 /// Database Database record and convert them into C++ objects.
134 /// Each of these classes are safe to be used in standard
135 /// containers, and are meant to be used in conjunction with the
136 /// RecordParser<> template when calling Controller::LoadDatabase().
147 GroupLink() : Link(0), Unknown(0) {}
148 GroupLink(uint32_t link
, uint16_t unknown
)
149 : Link(link
), Unknown(unknown
)
153 typedef std::vector
<GroupLink
> GroupLinksType
;
154 typedef std::vector
<UnknownField
> UnknownsType
;
156 // contact specific data
170 DefaultCommunicationsMethod
,
182 GroupLinksType GroupLinks
;
183 UnknownsType Unknowns
;
188 const unsigned char* ParseField(const unsigned char *begin
,
189 const unsigned char *end
);
195 uint64_t GetID() const { return RecordId
; }
196 std::string
GetPostalAddress() const;
198 void Parse(const Data
&data
, size_t offset
, unsigned int operation
);
199 void Build(Data
&data
, size_t offset
) const;
200 void Clear(); // erase everything
202 void Dump(std::ostream
&os
) const;
203 void DumpLdif(std::ostream
&os
, const std::string
&baseDN
) const;
205 // sorting - put group links at the end
206 bool operator<(const Contact
&other
) const {
207 return GroupLinks
.size() == 0 && other
.GroupLinks
.size() > 0;
208 // // testing - put group links at the top
209 // return GroupLinks.size() > 0 && other.GroupLinks.size() == 0;
212 // protocol record sizes
213 static size_t GetOldProtocolRecordSize();
214 static size_t GetProtocolRecordSize();
217 static const char * GetDBName() { return "Address Book"; }
220 inline std::ostream
& operator<< (std::ostream
&os
, const Contact
&contact
) {
240 std::vector
<UnknownField
> Unknowns
;
246 const unsigned char* ParseField(const unsigned char *begin
,
247 const unsigned char *end
);
248 void Parse(const Data
&data
, size_t offset
, unsigned int operation
);
251 void Dump(std::ostream
&os
) const;
254 bool operator<(const Message
&other
) const { return Subject
< other
.Subject
; }
256 // protocol record sizes
257 static size_t GetOldProtocolRecordSize();
258 static size_t GetProtocolRecordSize();
261 static const char * GetDBName() { return "Messages"; }
264 inline std::ostream
& operator<<(std::ostream
&os
, const Message
&msg
) {
269 std::ostream
& operator<<(std::ostream
&os
, const Message::Address
&msga
);
275 typedef std::vector
<UnknownField
> UnknownsType
;
282 std::string Location
;
283 time_t NotificationTime
;
286 UnknownsType Unknowns
;
292 const unsigned char* ParseField(const unsigned char *begin
,
293 const unsigned char *end
);
294 void Parse(const Data
&data
, size_t offset
, unsigned int operation
);
295 void Build(Data
&data
, size_t offset
) const;
298 void Dump(std::ostream
&os
) const;
301 bool operator<(const Calendar
&other
) const { return StartTime
< other
.StartTime
; }
303 // protocol record sizes
304 static size_t GetOldProtocolRecordSize();
305 static size_t GetProtocolRecordSize();
308 static const char * GetDBName() { return "Calendar"; }
311 inline std::ostream
& operator<<(std::ostream
&os
, const Calendar
&msg
) {