- moved some record class variables to public: so they can be
[barry.git] / src / record.h
blobe5fae3860b615f95ecb937bd66ffd8350b3c9ed0
1 ///
2 /// \file record.h
3 /// Blackberry database record classes. Help translate data
4 /// from data packets to useful structurs, and back.
5 ///
7 /*
8 Copyright (C) 2005, 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__
26 #include <iosfwd>
27 #include <string>
28 #include <vector>
29 #include <stdint.h>
31 // forward declarations
32 class Data;
34 namespace Barry {
37 // NOTE: All classes here must be container-safe! Perhaps add sorting
38 // operators in the future.
43 class CommandTable
45 public:
46 struct Command
48 unsigned int Code;
49 std::string Name;
52 typedef std::vector<Command> CommandArrayType;
54 CommandArrayType Commands;
56 private:
57 const unsigned char* ParseField(const unsigned char *begin,
58 const unsigned char *end);
59 public:
60 CommandTable();
61 ~CommandTable();
63 void Parse(const Data &data, int offset);
64 void Clear();
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) {
74 command.Dump(os);
75 return os;
80 class DatabaseDatabase
82 public:
83 struct Database
85 unsigned int Number;
86 unsigned int RecordCount;
87 std::string Name;
90 typedef std::vector<Database> DatabaseArrayType;
92 DatabaseArrayType Databases;
94 private:
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);
102 public:
103 DatabaseDatabase();
104 ~DatabaseDatabase();
106 void Parse(const Data &data);
107 void Clear();
109 // FIXME - returns 0 on error here, but that's a valid DBNumber
110 unsigned int GetDBNumber(const std::string &name) const;
112 void Dump(std::ostream &os) const;
115 inline std::ostream& operator<<(std::ostream &os, const DatabaseDatabase &dbdb) {
116 dbdb.Dump(os);
117 return os;
122 struct UnknownField
124 uint8_t type;
125 std::string data;
127 std::ostream& operator<< (std::ostream &os, const std::vector<UnknownField> &unknowns);
130 /// \addtogroup RecordParserClasses
131 /// Parser and data storage classes. These classes take a
132 /// Database Database record and convert them into C++ objects.
133 /// Each of these classes are safe to be used in standard
134 /// containers, and are meant to be used in conjunction with the
135 /// RecordParser<> template when calling Controller::LoadDatabase().
136 /// @{
138 class Contact
140 public:
141 struct GroupLink
143 uint32_t Link;
144 uint16_t Unknown;
146 GroupLink() : Link(0), Unknown(0) {}
147 GroupLink(uint32_t link, uint16_t unknown)
148 : Link(link), Unknown(unknown)
152 typedef std::vector<GroupLink> GroupLinksType;
153 typedef std::vector<UnknownField> UnknownsType;
155 // contact specific data
156 uint32_t RecordId;
157 std::string
158 Email,
159 Phone,
160 Fax,
161 WorkPhone,
162 HomePhone,
163 MobilePhone,
164 Pager,
165 PIN,
166 FirstName,
167 LastName,
168 Company,
169 DefaultCommunicationsMethod,
170 Address1,
171 Address2,
172 Address3,
173 City,
174 Province,
175 PostalCode,
176 Country,
177 Title,
178 PublicKey,
179 Notes;
181 GroupLinksType GroupLinks;
182 UnknownsType Unknowns;
185 //protected:
186 public:
187 const unsigned char* ParseField(const unsigned char *begin,
188 const unsigned char *end);
190 public:
191 Contact();
192 ~Contact();
194 uint64_t GetID() const { return RecordId; }
195 std::string GetPostalAddress() const;
197 void Parse(const Data &data, unsigned int operation);
198 void Build(Data &data, unsigned int databaseId) const;
199 void Clear(); // erase everything
201 void Dump(std::ostream &os) const;
202 void DumpLdif(std::ostream &os, const std::string &baseDN) const;
204 // protocol record sizes
205 static size_t GetOldProtocolRecordSize();
206 static size_t GetProtocolRecordSize();
209 inline std::ostream& operator<< (std::ostream &os, const Contact &contact) {
210 contact.Dump(os);
211 return os;
214 class Message
216 public:
217 struct Address
219 std::string Name;
220 std::string Email;
224 Address From;
225 Address To;
226 Address Cc;
227 std::string Subject;
228 std::string Body;
229 std::vector<UnknownField> Unknowns;
231 public:
232 Message();
233 ~Message();
235 const unsigned char* ParseField(const unsigned char *begin,
236 const unsigned char *end);
237 void Parse(const Data &data, unsigned int operation);
238 void Clear();
240 void Dump(std::ostream &os) const;
242 // protocol record sizes
243 static size_t GetOldProtocolRecordSize();
244 static size_t GetProtocolRecordSize();
247 inline std::ostream& operator<<(std::ostream &os, const Message &msg) {
248 msg.Dump(os);
249 return os;
252 std::ostream& operator<<(std::ostream &os, const Message::Address &msga);
255 class Calendar
257 public:
258 uint64_t RecordId;
259 std::string Subject;
260 std::string Notes;
261 std::string Location;
262 time_t NotificationTime;
263 time_t StartTime;
264 time_t EndTime;
265 std::vector<UnknownField> Unknowns;
267 public:
268 Calendar();
269 ~Calendar();
271 const unsigned char* ParseField(const unsigned char *begin,
272 const unsigned char *end);
273 void Parse(const Data &data, unsigned int operation);
274 void Clear();
276 void Dump(std::ostream &os) const;
278 // protocol record sizes
279 static size_t GetOldProtocolRecordSize();
280 static size_t GetProtocolRecordSize();
283 inline std::ostream& operator<<(std::ostream &os, const Calendar &msg) {
284 msg.Dump(os);
285 return os;
288 /// @}
290 } // namespace Barry
292 #endif