00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __BARRY_RECORD_CONTACT_H__
00023 #define __BARRY_RECORD_CONTACT_H__
00024
00025 #include "dll.h"
00026 #include "record.h"
00027 #include <iosfwd>
00028 #include <string>
00029 #include <vector>
00030 #include <map>
00031 #include <stdint.h>
00032
00033 namespace Barry {
00034
00035
00036
00037
00038
00039
00040 struct BXEXPORT ContactGroupLink
00041 {
00042 uint32_t Link;
00043 uint16_t Unknown;
00044
00045 ContactGroupLink() : Link(0), Unknown(0) {}
00046 ContactGroupLink(uint32_t link, uint16_t unknown)
00047 : Link(link), Unknown(unknown)
00048 {}
00049 };
00050
00051 typedef std::vector<std::string> CategoryList;
00052
00053
00054
00055
00056 class BXEXPORT Contact
00057 {
00058 public:
00059 typedef Barry::CategoryList CategoryList;
00060 typedef ContactGroupLink GroupLink;
00061 typedef std::vector<GroupLink> GroupLinksType;
00062 typedef std::vector<UnknownField> UnknownsType;
00063 typedef std::string EmailType;
00064 typedef std::vector<EmailType> EmailList;
00065
00066
00067 uint8_t RecType;
00068 uint32_t RecordId;
00069 EmailList EmailAddresses;
00070 std::string
00071 Phone,
00072 Fax,
00073 WorkPhone,
00074 HomePhone,
00075 MobilePhone,
00076 Pager,
00077 PIN,
00078 Radio,
00079 WorkPhone2,
00080 HomePhone2,
00081 OtherPhone,
00082 FirstName,
00083 LastName,
00084 Company,
00085 DefaultCommunicationsMethod,
00086 JobTitle,
00087 PublicKey,
00088 URL,
00089 Prefix,
00090 Notes,
00091 UserDefined1,
00092 UserDefined2,
00093 UserDefined3,
00094 UserDefined4,
00095 Image;
00096
00097 Date Birthday;
00098 Date Anniversary;
00099
00100 PostalAddress WorkAddress;
00101 PostalAddress HomeAddress;
00102
00103
00104
00105
00106
00107 CategoryList Categories;
00108
00109 GroupLinksType GroupLinks;
00110 UnknownsType Unknowns;
00111
00112 private:
00113 bool m_FirstNameSeen;
00114
00115
00116 public:
00117 const unsigned char* ParseField(const unsigned char *begin,
00118 const unsigned char *end);
00119
00120 public:
00121 Contact();
00122 ~Contact();
00123
00124 uint32_t GetID() const { return RecordId; }
00125 std::string GetFullName() const;
00126 const std::string& GetEmail(unsigned int index = 0) const;
00127
00128
00129 uint8_t GetRecType() const { return RecType; }
00130 uint32_t GetUniqueId() const { return RecordId; }
00131 void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
00132 void ParseHeader(const Data &data, size_t &offset);
00133 void ParseFields(const Data &data, size_t &offset);
00134 void BuildHeader(Data &data, size_t &offset) const;
00135 void BuildFields(Data &data, size_t &offset) const;
00136
00137 void Clear();
00138
00139 void Dump(std::ostream &os) const;
00140
00141
00142 bool operator<(const Contact &other) const {
00143 return GroupLinks.size() == 0 && other.GroupLinks.size() > 0;
00144
00145
00146 }
00147
00148
00149 static const char * GetDBName() { return "Address Book"; }
00150 static uint8_t GetDefaultRecType() { return 0; }
00151
00152
00153 static void SplitName(const std::string &full, std::string &first, std::string &last);
00154 static void CategoryStr2List(const std::string &str, Barry::CategoryList &list);
00155 static void CategoryList2Str(const Barry::CategoryList &list, std::string &str);
00156 };
00157
00158 BXEXPORT inline std::ostream& operator<< (std::ostream &os, const Contact &contact) {
00159 contact.Dump(os);
00160 return os;
00161 }
00162
00163
00164
00165 }
00166
00167 #endif
00168