Reduced minimum password retry level from 6 to 3
[barry/pauldeden.git] / src / record.h
blobc697d0c751f689e25b9d9ce06d743abbf0d24de3
1 ///
2 /// \file record.h
3 /// Blackberry database record classes. Help translate data
4 /// from data packets to useful structurs, and back.
5 /// This header provides the common types and classes
6 /// used by the general record parser classes in the
7 /// r_*.h files. Only application-safe API stuff goes in
8 /// here. Internal library types go in record-internal.h
9 ///
12 Copyright (C) 2005-2008, Net Direct Inc. (http://www.netdirect.ca/)
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 See the GNU General Public License in the COPYING file at the
24 root directory of this project for more details.
27 #ifndef __BARRY_RECORD_H__
28 #define __BARRY_RECORD_H__
30 #include "dll.h"
31 #include <iosfwd>
32 #include <string>
33 #include <vector>
34 #include <map>
35 #include <stdint.h>
37 // forward declarations
38 namespace Barry { class Data; }
40 namespace Barry {
43 // NOTE: All classes here must be container-safe! Perhaps add sorting
44 // operators in the future.
49 struct BXEXPORT CommandTableCommand
51 unsigned int Code;
52 std::string Name;
55 class BXEXPORT CommandTable
57 public:
58 typedef CommandTableCommand Command;
59 typedef std::vector<Command> CommandArrayType;
61 CommandArrayType Commands;
63 private:
64 BXLOCAL const unsigned char* ParseField(const unsigned char *begin,
65 const unsigned char *end);
66 public:
67 CommandTable();
68 ~CommandTable();
70 void Parse(const Data &data, size_t offset);
71 void Clear();
73 // returns 0 if unable to find command name, which is safe, since
74 // 0 is a special command that shouldn't be in the table anyway
75 unsigned int GetCommand(const std::string &name) const;
77 void Dump(std::ostream &os) const;
80 BXEXPORT inline std::ostream& operator<< (std::ostream &os, const CommandTable &command) {
81 command.Dump(os);
82 return os;
87 struct BXEXPORT RecordStateTableState
89 unsigned int Index;
90 uint32_t RecordId;
91 bool Dirty;
92 unsigned int RecType;
93 std::string Unknown2;
96 class BXEXPORT RecordStateTable
98 public:
99 typedef RecordStateTableState State;
100 typedef unsigned int IndexType;
101 typedef std::map<IndexType, State> StateMapType;
103 StateMapType StateMap;
105 private:
106 mutable IndexType m_LastNewRecordId;
108 private:
109 BXLOCAL const unsigned char* ParseField(const unsigned char *begin,
110 const unsigned char *end);
112 public:
113 RecordStateTable();
114 ~RecordStateTable();
116 void Parse(const Data &data);
117 void Clear();
119 bool GetIndex(uint32_t RecordId, IndexType *pFoundIndex = 0) const;
120 uint32_t MakeNewRecordId() const;
122 void Dump(std::ostream &os) const;
125 BXEXPORT inline std::ostream& operator<< (std::ostream &os, const RecordStateTable &rst) {
126 rst.Dump(os);
127 return os;
132 struct BXEXPORT DatabaseItem
134 unsigned int Number;
135 unsigned int RecordCount;
136 std::string Name;
139 class BXEXPORT DatabaseDatabase
141 public:
142 typedef DatabaseItem Database;
143 typedef std::vector<Database> DatabaseArrayType;
145 DatabaseArrayType Databases;
147 private:
148 template <class RecordType, class FieldType>
149 void ParseRec(const RecordType &rec, const unsigned char *end);
151 template <class FieldType>
152 const unsigned char* ParseField(const unsigned char *begin,
153 const unsigned char *end);
155 public:
156 DatabaseDatabase();
157 ~DatabaseDatabase();
159 void Parse(const Data &data);
160 void Clear();
162 // returns true on success, and fills target
163 bool GetDBNumber(const std::string &name, unsigned int &number) const;
164 bool GetDBName(unsigned int number, std::string &name) const;
166 void Dump(std::ostream &os) const;
169 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const DatabaseDatabase &dbdb) {
170 dbdb.Dump(os);
171 return os;
174 struct UnknownData
176 std::string raw_data;
178 const std::string::value_type* data() const { return raw_data.data(); }
179 std::string::size_type size() const { return raw_data.size(); }
180 void assign(const std::string::value_type *s, std::string::size_type n)
181 { raw_data.assign(s, n); }
184 struct BXEXPORT UnknownField
186 uint8_t type;
187 UnknownData data;
189 BXEXPORT std::ostream& operator<< (std::ostream &os, const std::vector<UnknownField> &unknowns);
191 struct BXEXPORT EmailAddress
193 std::string Name;
194 std::string Email;
196 void clear()
198 Name.clear();
199 Email.clear();
202 BXEXPORT std::ostream& operator<<(std::ostream &os, const EmailAddress &msga);
204 struct BXEXPORT PostalAddress
206 std::string
207 Address1,
208 Address2,
209 Address3,
210 City,
211 Province,
212 PostalCode,
213 Country;
215 std::string GetLabel() const;
216 void Clear();
218 bool HasData() const { return Address1.size() || Address2.size() ||
219 Address3.size() || City.size() || Province.size() ||
220 PostalCode.size() || Country.size(); }
222 BXEXPORT std::ostream& operator<<(std::ostream &os, const PostalAddress &msga);
225 /// \addtogroup RecordParserClasses
226 /// Parser and data storage classes. These classes take a
227 /// Database Database record and convert them into C++ objects.
228 /// Each of these classes are safe to be used in standard
229 /// containers, and are meant to be used in conjunction with the
230 /// RecordParser<> template when calling Controller::LoadDatabase().
231 /// @{
232 /// @}
234 } // namespace Barry
236 // Include all parser classes, to make it easy for the application to use.
237 #include "r_calendar.h"
238 #include "r_contact.h"
239 #include "r_memo.h"
240 #include "r_message.h"
241 #include "r_servicebook.h"
242 #include "r_task.h"
243 #include "r_pin_message.h"
244 #include "r_saved_message.h"
245 #include "r_folder.h"
246 #include "r_timezone.h"
248 #endif