PTLib Version 2.12.9

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vcard.h
Go to the documentation of this file.
1 /*
2 * vcard.h
3 *
4 * Class to represent and parse a vCard as per RFC2426
5 *
6 * Portable Windows Library
7 *
8 * Copyright (c) 2010 Vox Lucida Pty Ltd
9 *
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
14 *
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * The Original Code is Portable Tools Library.
21 *
22 * The Initial Developer of the Original Code is Vox Lucida Pty Ltd
23 *
24 * Contributor(s): ______________________________________.
25 *
26 * $Revision: 28207 $
27 * $Author: rjongbloed $
28 * $Date: 2012-08-17 10:09:54 +1000 (Fri, 17 Aug 2012) $
29 */
30
31 #ifndef PTLIB_VCARD_H
32 #define PTLIB_VCARD_H
33
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37
38 #if P_VCARD
39
40 #include <ptclib/url.h>
41
42
45 class PvCard : public PObject
46 {
47 PCLASSINFO(PvCard, PObject);
48
49 public:
50 PvCard();
51
52 bool IsValid() const;
53
54 virtual void PrintOn(
55 ostream & strm
56 ) const;
57 virtual void ReadFrom(
58 istream & strm
59 );
60 bool Parse(
61 const PString & str
62 );
63
71 enum Format {
72 e_Standard,
73 e_XML_XMPP,
74 e_XML_RDF,
75 e_XML_RFC
76 };
77 PString AsString(
78 Format fmt = e_Standard
79 );
80
82 class Token : public PCaselessString
83 {
84 public:
85 Token(const char * str = NULL) : PCaselessString(str) { Validate(); }
86 Token(const PString & str) : PCaselessString(str) { Validate(); }
87 Token & operator=(const char * str) { PCaselessString::operator=(str); Validate(); return *this; }
88 Token & operator=(const PString & str) { PCaselessString::operator=(str); Validate(); return *this; }
89 virtual void PrintOn(ostream & strm) const;
90 virtual void ReadFrom(istream & strm);
91 private:
92 void Validate();
93 };
94
95 class Separator : public PObject
96 {
97 public:
98 Separator(char c = '\0') : m_separator(c) { }
99 virtual void PrintOn(ostream & strm) const;
100 virtual void ReadFrom(istream & strm);
101 bool operator==(char c) const { return m_separator == c; }
102 bool operator!=(char c) const { return m_separator != c; }
103 char m_separator;
104 };
105
107 class ParamValue : public PString
108 {
109 public:
110 ParamValue(const char * str = NULL) : PString(str) { }
111 ParamValue(const PString & str) : PString(str) { }
112 virtual void PrintOn(ostream & strm) const;
113 virtual void ReadFrom(istream & strm);
114 };
116 class ParamValues : public PArray<ParamValue>
117 {
118 public:
119 virtual void PrintOn(ostream & strm) const;
120 virtual void ReadFrom(istream & strm);
121 };
122
123 typedef std::map<Token, ParamValues> ParamMap;
124
125 class TypeValues : public ParamValues
126 {
127 public:
128 TypeValues() { }
129 TypeValues(const ParamValues & values) : ParamValues(values) { }
130 virtual void PrintOn(ostream & strm) const;
131 };
132
134 class TextValue : public PString
135 {
136 public:
137 TextValue(const char * str = NULL) : PString(str) { }
138 TextValue(const PString & str) : PString(str) { }
139 virtual void PrintOn(ostream & strm) const;
140 virtual void ReadFrom(istream & strm);
141 };
142
144 class TextValues : public PArray<TextValue>
145 {
146 public:
147 virtual void PrintOn(ostream & strm) const;
148 virtual void ReadFrom(istream & strm);
149 };
150
151 class URIValue : public PURL
152 {
153 public:
154 URIValue(const char * str = NULL) : PURL(str) { }
155 URIValue(const PString & str) : PURL(str) { }
156 virtual void PrintOn(ostream & strm) const;
157 virtual void ReadFrom(istream & strm);
158 };
159
161 class InlineValue : public URIValue
162 {
163 public:
164 InlineValue(const char * str = NULL) : URIValue(str), m_params(NULL) { }
165 InlineValue(const PString & str) : URIValue(str), m_params(NULL) { }
166 virtual void PrintOn(ostream & strm) const;
167 virtual void ReadFrom(istream & strm);
168 InlineValue & ReadFromParam(const ParamMap & params);
169 private:
170 const ParamMap * m_params;
171 };
172
173 Token m_group;
174 TextValue m_fullName; // Mandatory
175 TextValue m_version; // Mandatory
176
177 TextValue m_familyName;
178 TextValue m_givenName;
179 TextValues m_additionalNames;
180 TextValue m_honorificPrefixes;
181 TextValue m_honorificSuffixes;
182 TextValues m_nickNames;
183 TextValue m_sortString; // Form of name for sorting, e.g. family name;
184
185 PTime m_birthday;
186 URIValue m_url;
187 InlineValue m_photo; // Possibly embedded via data: scheme
188 InlineValue m_sound; // Possibly embedded via data: scheme
189 TextValue m_timeZone;
190 double m_latitude;
191 double m_longitude;
192
193 TextValue m_title;
194 TextValue m_role;
195 InlineValue m_logo; // Possibly embedded via data: scheme
196 TextValue m_agent;
197 TextValue m_organisationName;
198 TextValue m_organisationUnit;
199
200 TextValue m_mailer;
201 TextValues m_categories;
202 TextValue m_note;
203
204 TextValue m_productId;
205 TextValue m_guid;
206 TextValue m_revision;
207 TextValue m_class;
208 TextValue m_publicKey;
209
210 struct MultiValue : public PObject {
211 MultiValue() { }
212 MultiValue(const PString & type) { m_types.Append(new ParamValue(type)); }
213
214 TypeValues m_types; // e.g. "home", "work", "pref" etc
215 void SetTypes(const ParamMap & params);
216 };
217
218 struct Address : public MultiValue {
219 Address(bool label = false) : m_label(label) { }
220 virtual void PrintOn(ostream & strm) const;
221 virtual void ReadFrom(istream & strm);
222
223 bool m_label;
224 TextValue m_postOfficeBox;
225 TextValue m_extendedAddress;
226 TextValue m_street; // Including number "123 Main Street"
227 TextValue m_locality; // Suburb/city
228 TextValue m_region; // State/province
229 TextValue m_postCode;
230 TextValue m_country;
231 };
232 PArray<Address> m_addresses;
233 PArray<Address> m_labels;
234
235 struct Telephone : public MultiValue {
236 Telephone() { }
237 Telephone(const PString & number, const PString & type = PString::Empty())
238 : MultiValue(type)
239 , m_number(number)
240 { }
241 virtual void PrintOn(ostream & strm) const;
242
243 TextValue m_number;
244 };
245 PArray<Telephone> m_telephoneNumbers;
246
247 struct EMail : public MultiValue {
248 EMail() { }
249 EMail(const PString & address, const PString & type = PString::Empty())
250 : MultiValue(type)
251 , m_address(address)
252 { }
253 virtual void PrintOn(ostream & strm) const;
254 TextValue m_address;
255 };
256 PArray<EMail> m_emailAddresses;
257
258 struct ExtendedType {
259 ParamMap m_parameters;
260 TextValue m_value;
261 };
262
263 typedef std::map<Token, ExtendedType> ExtendedTypeMap;
264 ExtendedTypeMap m_extensions;
265 };
266
267
268 #endif // P_VCARD
269
270 #endif // PTLIB_VCARD_H
271
272
273 // End of File ///////////////////////////////////////////////////////////////