Added missing string.h header to src/m_javaloader.cc
[barry.git] / src / r_contact.h
blobc3344566d0464ad8c132e9ec38cc00fa5aa30151
1 ///
2 /// \file r_contact.h
3 /// Blackberry database record parser class for contact records.
4 ///
6 /*
7 Copyright (C) 2005-2009, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_RECORD_CONTACT_H__
23 #define __BARRY_RECORD_CONTACT_H__
25 #include "dll.h"
26 #include "record.h"
27 #include <iosfwd>
28 #include <string>
29 #include <vector>
30 #include <map>
31 #include <stdint.h>
33 namespace Barry {
35 // forward declarations
36 class IConverter;
39 // NOTE: All classes here must be container-safe! Perhaps add sorting
40 // operators in the future.
43 struct BXEXPORT ContactGroupLink
45 uint32_t Link;
46 uint16_t Unknown;
48 ContactGroupLink() : Link(0), Unknown(0) {}
49 ContactGroupLink(uint32_t link, uint16_t unknown)
50 : Link(link), Unknown(unknown)
54 typedef std::vector<std::string> CategoryList;
56 /// \addtogroup RecordParserClasses
57 /// @{
60 // Contact record class
62 /// Represents a single record in the Address Book Blackberry database.
63 ///
64 class BXEXPORT Contact
66 public:
67 typedef Barry::CategoryList CategoryList;
68 typedef ContactGroupLink GroupLink;
69 typedef std::vector<GroupLink> GroupLinksType;
70 typedef std::vector<UnknownField> UnknownsType;
71 typedef std::string EmailType;
72 typedef std::vector<EmailType> EmailList;
75 // Record fields
78 // contact specific data
79 uint8_t RecType;
80 uint32_t RecordId;
81 EmailList EmailAddresses;
83 /// This field, Phone, is deprecated. It is possible
84 /// to write to this field to the Blackberry,
85 /// but modern devices won't let you add it
86 /// through their GUIs. This field only seems
87 /// to exist on the 7750. While other devices
88 /// accept the field and display it, it is
89 /// not accessible by default.
90 std::string Phone;
92 std::string
93 Fax,
94 WorkPhone,
95 HomePhone,
96 MobilePhone,
97 Pager,
98 PIN,
99 Radio,
100 WorkPhone2,
101 HomePhone2,
102 OtherPhone,
103 FirstName,
104 LastName,
105 Company,
106 DefaultCommunicationsMethod,
107 JobTitle,
108 PublicKey,
109 URL,
110 Prefix,
111 Notes,
112 UserDefined1,
113 UserDefined2,
114 UserDefined3,
115 UserDefined4,
116 Image;
118 Date Birthday;
119 Date Anniversary;
121 PostalAddress WorkAddress;
122 PostalAddress HomeAddress;
124 // Categories are not allowed to have commas in them.
125 // A category name containing a comma will be split into
126 // two categories, not only by this library, but by the
127 // device itself.
128 CategoryList Categories;
130 GroupLinksType GroupLinks;
131 UnknownsType Unknowns;
133 private:
134 bool m_FirstNameSeen;
136 public:
137 const unsigned char* ParseField(const unsigned char *begin,
138 const unsigned char *end, const IConverter *ic = 0);
140 public:
141 Contact();
142 ~Contact();
144 uint32_t GetID() const { return RecordId; }
145 std::string GetFullName() const;
146 const std::string& GetEmail(unsigned int index = 0) const;
148 // Parser / Builder API (see parser.h / builder.h)
149 uint8_t GetRecType() const { return RecType; }
150 uint32_t GetUniqueId() const { return RecordId; }
151 void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
152 void ParseHeader(const Data &data, size_t &offset);
153 void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
154 void BuildHeader(Data &data, size_t &offset) const;
155 void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
157 void Clear(); // erase everything
159 void Dump(std::ostream &os) const;
161 // sorting - put group links at the end
162 bool operator<(const Contact &other) const {
163 return GroupLinks.size() == 0 && other.GroupLinks.size() > 0;
164 // // testing - put group links at the top
165 // return GroupLinks.size() > 0 && other.GroupLinks.size() == 0;
168 // database name
169 static const char * GetDBName() { return "Address Book"; }
170 static uint8_t GetDefaultRecType() { return 0; }
172 // helpers
173 static void SplitName(const std::string &full, std::string &first, std::string &last);
174 static void CategoryStr2List(const std::string &str, Barry::CategoryList &list);
175 static void CategoryList2Str(const Barry::CategoryList &list, std::string &str);
178 BXEXPORT inline std::ostream& operator<< (std::ostream &os, const Contact &contact) {
179 contact.Dump(os);
180 return os;
183 /// @}
185 } // namespace Barry
187 #endif