PTLib  Version 2.18.8
 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 
27 #ifndef PTLIB_VCARD_H
28 #define PTLIB_VCARD_H
29 
30 #ifdef P_USE_PRAGMA
31 #pragma interface
32 #endif
33 
34 #if P_VCARD
35 
36 #include <ptclib/url.h>
37 
38 
41 class PvCard : public PObject
42 {
43  PCLASSINFO(PvCard, PObject);
44 
45  public:
46  PvCard();
47 
48  bool IsValid() const;
49 
50  virtual void PrintOn(
51  ostream & strm
52  ) const;
53  virtual void ReadFrom(
54  istream & strm
55  );
56  bool Parse(
57  const PString & str
58  );
59 
67  enum Format {
68  e_Standard,
69  e_XML_XMPP,
70  e_XML_RDF,
71  e_XML_RFC
72  };
73  PString AsString(
74  Format fmt = e_Standard
75  );
76 
78  class Token : public PCaselessString
79  {
80  public:
81  Token(const char * str = NULL) : PCaselessString(str) { Validate(); }
82  Token(const PString & str) : PCaselessString(str) { Validate(); }
83  Token & operator=(const char * str) { PCaselessString::operator=(str); Validate(); return *this; }
84  Token & operator=(const PString & str) { PCaselessString::operator=(str); Validate(); return *this; }
85  virtual void PrintOn(ostream & strm) const;
86  virtual void ReadFrom(istream & strm);
87  private:
88  void Validate();
89  };
90 
91  class Separator : public PObject
92  {
93  public:
94  Separator(char c = '\0') : m_separator(c) { }
95  virtual void PrintOn(ostream & strm) const;
96  virtual void ReadFrom(istream & strm);
97  bool operator==(char c) const { return m_separator == c; }
98  bool operator!=(char c) const { return m_separator != c; }
99  char m_separator;
100  };
101 
103  class ParamValue : public PString
104  {
105  public:
106  ParamValue(const char * str = NULL) : PString(str) { }
107  ParamValue(const PString & str) : PString(str) { }
108  virtual void PrintOn(ostream & strm) const;
109  virtual void ReadFrom(istream & strm);
110  };
112  class ParamValues : public PArray<ParamValue>
113  {
114  public:
115  virtual void PrintOn(ostream & strm) const;
116  virtual void ReadFrom(istream & strm);
117  };
118 
119  typedef std::map<Token, ParamValues> ParamMap;
120 
121  class TypeValues : public ParamValues
122  {
123  public:
124  TypeValues() { }
125  TypeValues(const ParamValues & values) : ParamValues(values) { }
126  virtual void PrintOn(ostream & strm) const;
127  };
128 
130  class TextValue : public PString
131  {
132  public:
133  TextValue(const char * str = NULL) : PString(str) { }
134  TextValue(const PString & str) : PString(str) { }
135  virtual void PrintOn(ostream & strm) const;
136  virtual void ReadFrom(istream & strm);
137  };
138 
140  class TextValues : public PArray<TextValue>
141  {
142  public:
143  virtual void PrintOn(ostream & strm) const;
144  virtual void ReadFrom(istream & strm);
145  };
146 
147  class URIValue : public PURL
148  {
149  public:
150  URIValue(const char * str = NULL) : PURL(str) { }
151  URIValue(const PString & str) : PURL(str) { }
152  virtual void PrintOn(ostream & strm) const;
153  virtual void ReadFrom(istream & strm);
154  };
155 
157  class InlineValue : public URIValue
158  {
159  public:
160  InlineValue(const char * str = NULL) : URIValue(str), m_params(NULL) { }
161  InlineValue(const PString & str) : URIValue(str), m_params(NULL) { }
162  virtual void PrintOn(ostream & strm) const;
163  virtual void ReadFrom(istream & strm);
164  InlineValue & ReadFromParam(const ParamMap & params);
165  private:
166  const ParamMap * m_params;
167  };
168 
169  Token m_group;
170  TextValue m_fullName; // Mandatory
171  TextValue m_version; // Mandatory
172 
173  TextValue m_familyName;
174  TextValue m_givenName;
175  TextValues m_additionalNames;
176  TextValue m_honorificPrefixes;
177  TextValue m_honorificSuffixes;
178  TextValues m_nickNames;
179  TextValue m_sortString; // Form of name for sorting, e.g. family name;
180 
181  PTime m_birthday;
182  URIValue m_url;
183  InlineValue m_photo; // Possibly embedded via data: scheme
184  InlineValue m_sound; // Possibly embedded via data: scheme
185  TextValue m_timeZone;
186  double m_latitude;
187  double m_longitude;
188 
189  TextValue m_title;
190  TextValue m_role;
191  InlineValue m_logo; // Possibly embedded via data: scheme
192  TextValue m_agent;
193  TextValue m_organisationName;
194  TextValue m_organisationUnit;
195 
196  TextValue m_mailer;
197  TextValues m_categories;
198  TextValue m_note;
199 
200  TextValue m_productId;
201  TextValue m_guid;
202  TextValue m_revision;
203  TextValue m_class;
204  TextValue m_publicKey;
205 
206  struct MultiValue : public PObject {
207  MultiValue() { }
208  MultiValue(const PString & type) { m_types.Append(new ParamValue(type)); }
209 
210  TypeValues m_types; // e.g. "home", "work", "pref" etc
211  void SetTypes(const ParamMap & params);
212  };
213 
214  struct Address : public MultiValue {
215  Address(bool label = false) : m_label(label) { }
216  virtual void PrintOn(ostream & strm) const;
217  virtual void ReadFrom(istream & strm);
218 
219  bool m_label;
220  TextValue m_postOfficeBox;
221  TextValue m_extendedAddress;
222  TextValue m_street; // Including number "123 Main Street"
223  TextValue m_locality; // Suburb/city
224  TextValue m_region; // State/province
225  TextValue m_postCode;
226  TextValue m_country;
227  };
228  PArray<Address> m_addresses;
229  PArray<Address> m_labels;
230 
231  struct Telephone : public MultiValue {
232  Telephone() { }
233  Telephone(const PString & number, const PString & type = PString::Empty())
234  : MultiValue(type)
235  , m_number(number)
236  { }
237  virtual void PrintOn(ostream & strm) const;
238 
239  TextValue m_number;
240  };
241  PArray<Telephone> m_telephoneNumbers;
242 
243  struct EMail : public MultiValue {
244  EMail() { }
245  EMail(const PString & address, const PString & type = PString::Empty())
246  : MultiValue(type)
247  , m_address(address)
248  { }
249  virtual void PrintOn(ostream & strm) const;
250  TextValue m_address;
251  };
252  PArray<EMail> m_emailAddresses;
253 
254  struct ExtendedType {
255  ParamMap m_parameters;
256  TextValue m_value;
257  };
258 
259  typedef std::map<Token, ExtendedType> ExtendedTypeMap;
260  ExtendedTypeMap m_extensions;
261 };
262 
263 
264 #endif // P_VCARD
265 
266 #endif // PTLIB_VCARD_H
267 
268 
269 // End of File ///////////////////////////////////////////////////////////////
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
This class defines an absolute time and date.
Definition: ptime.h:49
PCaselessString & operator=(const PString &str)
Assign the string to the current object.
This class is a variation of a string that ignores case.
Definition: pstring.h:2012
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
The character string class.
Definition: pstring.h:108
static const PString & Empty()
Return an empty string.
This template class maps the PArrayObjects to a specific object type.
Definition: array.h:925
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
This class describes a Universal Resource Locator.
Definition: url.h:56
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
void PrintOn(ostream &strm) const