PTLib  Version 2.10.10
 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: 26015 $
27  * $Author: rjongbloed $
28  * $Date: 2011-06-14 02:31:10 -0500 (Tue, 14 Jun 2011) $
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 
39 #include <ptclib/url.h>
40 
41 
44 class PvCard : public PObject
45 {
46  PCLASSINFO(PvCard, PObject);
47 
48  public:
49  PvCard();
50 
51  bool IsValid() const;
52 
53  virtual void PrintOn(
54  ostream & strm
55  ) const;
56  virtual void ReadFrom(
57  istream & strm
58  );
59  bool Parse(
60  const PString & str
61  );
62 
70  enum Format {
75  };
77  Format fmt = e_Standard
78  );
79 
81  class Token : public PCaselessString
82  {
83  public:
84  Token(const char * str = NULL) : PCaselessString(str) { Validate(); }
85  Token(const PString & str) : PCaselessString(str) { Validate(); }
86  Token & operator=(const char * str) { PCaselessString::operator=(str); Validate(); return *this; }
87  Token & operator=(const PString & str) { PCaselessString::operator=(str); Validate(); return *this; }
88  virtual void PrintOn(ostream & strm) const;
89  virtual void ReadFrom(istream & strm);
90  private:
91  void Validate();
92  };
93 
94  class Separator : public PObject
95  {
96  public:
97  Separator(char c = '\0') : m_separator(c) { }
98  virtual void PrintOn(ostream & strm) const;
99  virtual void ReadFrom(istream & strm);
100  bool operator==(char c) const { return m_separator == c; }
101  bool operator!=(char c) const { return m_separator != c; }
103  };
104 
106  class ParamValue : public PString
107  {
108  public:
109  ParamValue(const char * str = NULL) : PString(str) { }
110  ParamValue(const PString & str) : PString(str) { }
111  virtual void PrintOn(ostream & strm) const;
112  virtual void ReadFrom(istream & strm);
113  };
115  class ParamValues : public PArray<ParamValue>
116  {
117  public:
118  virtual void PrintOn(ostream & strm) const;
119  virtual void ReadFrom(istream & strm);
120  };
121 
122  typedef std::map<Token, ParamValues> ParamMap;
123 
124  class TypeValues : public ParamValues
125  {
126  public:
128  TypeValues(const ParamValues & values) : ParamValues(values) { }
129  virtual void PrintOn(ostream & strm) const;
130  };
131 
133  class TextValue : public PString
134  {
135  public:
136  TextValue(const char * str = NULL) : PString(str) { }
137  TextValue(const PString & str) : PString(str) { }
138  virtual void PrintOn(ostream & strm) const;
139  virtual void ReadFrom(istream & strm);
140  };
141 
143  class TextValues : public PArray<TextValue>
144  {
145  public:
146  virtual void PrintOn(ostream & strm) const;
147  virtual void ReadFrom(istream & strm);
148  };
149 
150  class URIValue : public PURL
151  {
152  public:
153  URIValue(const char * str = NULL) : PURL(str) { }
154  URIValue(const PString & str) : PURL(str) { }
155  virtual void PrintOn(ostream & strm) const;
156  virtual void ReadFrom(istream & strm);
157  };
158 
160  class InlineValue : public URIValue
161  {
162  public:
163  InlineValue(const char * str = NULL) : URIValue(str), m_params(NULL) { }
164  InlineValue(const PString & str) : URIValue(str), m_params(NULL) { }
165  virtual void PrintOn(ostream & strm) const;
166  virtual void ReadFrom(istream & strm);
167  InlineValue & ReadFromParam(const ParamMap & params);
168  private:
169  const ParamMap * m_params;
170  };
171 
173  TextValue m_fullName; // Mandatory
174  TextValue m_version; // Mandatory
175 
182  TextValue m_sortString; // Form of name for sorting, e.g. family name;
183 
186  InlineValue m_photo; // Possibly embedded via data: scheme
187  InlineValue m_sound; // Possibly embedded via data: scheme
189  double m_latitude;
190  double m_longitude;
191 
194  InlineValue m_logo; // Possibly embedded via data: scheme
198 
202 
208 
209  struct MultiValue : public PObject {
211  MultiValue(const PString & type) { m_types.Append(new ParamValue(type)); }
212 
213  TypeValues m_types; // e.g. "home", "work", "pref" etc
214  void SetTypes(const ParamMap & params);
215  };
216 
217  struct Address : public MultiValue {
218  Address(bool label = false) : m_label(label) { }
219  virtual void PrintOn(ostream & strm) const;
220  virtual void ReadFrom(istream & strm);
221 
222  bool m_label;
225  TextValue m_street; // Including number "123 Main Street"
226  TextValue m_locality; // Suburb/city
227  TextValue m_region; // State/province
230  };
233 
234  struct Telephone : public MultiValue {
235  Telephone() { }
236  Telephone(const PString & number, const PString & type = PString::Empty())
237  : MultiValue(type)
238  , m_number(number)
239  { }
240  virtual void PrintOn(ostream & strm) const;
241 
243  };
245 
246  struct EMail : public MultiValue {
247  EMail() { }
248  EMail(const PString & address, const PString & type = PString::Empty())
249  : MultiValue(type)
250  , m_address(address)
251  { }
252  virtual void PrintOn(ostream & strm) const;
254  };
256 
257  struct ExtendedType {
260  };
261 
262  typedef std::map<Token, ExtendedType> ExtendedTypeMap;
264 };
265 
266 
267 #endif // PTLIB_VCARD_H
268 
269 
270 // End of File ///////////////////////////////////////////////////////////////
TextValue m_version
Definition: vcard.h:174
ParamValue(const PString &str)
Definition: vcard.h:110
virtual void ReadFrom(istream &strm)
Input the contents of the URL from the stream.
Token & operator=(const PString &str)
Definition: vcard.h:87
TextValue m_class
Definition: vcard.h:206
EMail()
Definition: vcard.h:247
Class to represent a vCard as per RFC2426.
Definition: vcard.h:44
TextValue m_number
Definition: vcard.h:242
Definition: vcard.h:257
TextValue m_revision
Definition: vcard.h:205
Definition: vcard.h:124
PArray< Telephone > m_telephoneNumbers
Definition: vcard.h:244
InlineValue m_logo
Definition: vcard.h:194
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
Definition: vcard.h:94
Comma separated list of param-value's.
Definition: vcard.h:115
PArray< Address > m_addresses
Definition: vcard.h:231
TextValue m_guid
Definition: vcard.h:204
InlineValue m_photo
Definition: vcard.h:186
PArray< EMail > m_emailAddresses
Definition: vcard.h:255
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
EMail(const PString &address, const PString &type=PString::Empty())
Definition: vcard.h:248
Format
Output string formats.
Definition: vcard.h:70
TextValue m_fullName
Definition: vcard.h:173
URIValue m_url
Definition: vcard.h:185
virtual void PrintOn(ostream &strm) const
Print the collection on the stream.
This class defines an absolute time and date.
Definition: ptime.h:53
TextValue m_honorificPrefixes
Definition: vcard.h:179
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
TypeValues m_types
Definition: vcard.h:213
void SetTypes(const ParamMap &params)
TextValue m_region
Definition: vcard.h:227
MultiValue(const PString &type)
Definition: vcard.h:211
Definition: vcard.h:217
PCaselessString & operator=(const PString &str)
Assign the string to the current object.
virtual void PrintOn(ostream &strm) const
Output the contents of the URL to the stream as a string.
ExtendedTypeMap m_extensions
Definition: vcard.h:263
InlineValue & ReadFromParam(const ParamMap &params)
virtual void ReadFrom(istream &strm)
Input the string from the specified stream.
This class is a variation of a string that ignores case.
Definition: pstring.h:1708
TextValue(const PString &str)
Definition: vcard.h:137
virtual void ReadFrom(istream &strm)
Input the string from the specified stream.
Draft RFC.
Definition: vcard.h:74
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
TextValue m_productId
Definition: vcard.h:203
Address(bool label=false)
Definition: vcard.h:218
TextValue m_locality
Definition: vcard.h:226
InlineValue(const char *str=NULL)
Definition: vcard.h:163
ParamValue(const char *str=NULL)
Definition: vcard.h:109
PArray< Address > m_labels
Definition: vcard.h:232
virtual void PrintOn(ostream &strm) const
Output the string to the specified stream.
TextValue m_note
Definition: vcard.h:201
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
virtual void ReadFrom(istream &strm)
Input the contents of the URL from the stream.
TypeValues()
Definition: vcard.h:127
TypeValues(const ParamValues &values)
Definition: vcard.h:128
TextValue m_organisationName
Definition: vcard.h:196
TextValue m_value
Definition: vcard.h:259
As per RFC2425.
Definition: vcard.h:71
TextValues m_categories
Definition: vcard.h:200
TextValue m_title
Definition: vcard.h:192
Definition: vcard.h:246
Representation of EBNF img-inline-value/snd-inline-value.
Definition: vcard.h:160
PTime m_birthday
Definition: vcard.h:184
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
virtual PINDEX Append(PObject *obj)
Append a new object to the collection.
Definition: vcard.h:234
TextValue m_mailer
Definition: vcard.h:199
Representation of EBNF param-value.
Definition: vcard.h:106
bool m_label
Definition: vcard.h:222
TextValue m_postOfficeBox
Definition: vcard.h:223
URIValue(const PString &str)
Definition: vcard.h:154
Definition: vcard.h:150
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
Token(const char *str=NULL)
Definition: vcard.h:84
Representation of EBNF text-value.
Definition: vcard.h:133
TextValue m_timeZone
Definition: vcard.h:188
TextValue m_sortString
Definition: vcard.h:182
The character string class.
Definition: pstring.h:108
double m_longitude
Definition: vcard.h:190
TextValue m_postCode
Definition: vcard.h:228
URIValue(const char *str=NULL)
Definition: vcard.h:153
bool operator!=(char c) const
Definition: vcard.h:101
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
static PString Empty()
Return an empty string.
Token m_group
Definition: vcard.h:172
double m_latitude
Definition: vcard.h:189
TextValue m_agent
Definition: vcard.h:195
MultiValue()
Definition: vcard.h:210
TextValue m_street
Definition: vcard.h:225
TextValue m_extendedAddress
Definition: vcard.h:224
virtual void PrintOn(ostream &strm) const
Output the string to the specified stream.
TextValue m_organisationUnit
Definition: vcard.h:197
TextValues m_additionalNames
Definition: vcard.h:178
TextValue m_givenName
Definition: vcard.h:177
Definition: vcard.h:209
Separator(char c= '\0')
Definition: vcard.h:97
bool Parse(const PString &str)
Telephone()
Definition: vcard.h:235
ParamMap m_parameters
Definition: vcard.h:258
std::map< Token, ParamValues > ParamMap
Definition: vcard.h:122
TextValue(const char *str=NULL)
Definition: vcard.h:136
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
W3C version.
Definition: vcard.h:73
InlineValue m_sound
Definition: vcard.h:187
std::map< Token, ExtendedType > ExtendedTypeMap
Definition: vcard.h:262
virtual void PrintOn(ostream &strm) const
Print the collection on the stream.
This template class maps the PArrayObjects to a specific object type.
Definition: array.h:1024
PString AsString(Format fmt=e_Standard)
char m_separator
Definition: vcard.h:102
InlineValue(const PString &str)
Definition: vcard.h:164
TextValue m_country
Definition: vcard.h:229
virtual void PrintOn(ostream &strm) const
Output the string to the specified stream.
virtual void PrintOn(ostream &strm) const
Print the collection on the stream.
Comma separated list of text-value's.
Definition: vcard.h:143
TextValues m_nickNames
Definition: vcard.h:181
bool operator==(char c) const
Definition: vcard.h:100
bool IsValid() const
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
virtual void PrintOn(ostream &strm) const
Output the contents of the URL to the stream as a string.
TextValue m_honorificSuffixes
Definition: vcard.h:180
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
Representation of token (EBNF group, name, iana-token or x-name)
Definition: vcard.h:81
This class describes a Universal Resource Locator.
Definition: url.h:54
TextValue m_role
Definition: vcard.h:193
Token(const PString &str)
Definition: vcard.h:85
Jabber XML.
Definition: vcard.h:72
TextValue m_address
Definition: vcard.h:253
TextValue m_familyName
Definition: vcard.h:176
Token & operator=(const char *str)
Definition: vcard.h:86
Telephone(const PString &number, const PString &type=PString::Empty())
Definition: vcard.h:236
TextValue m_publicKey
Definition: vcard.h:207
virtual void ReadFrom(istream &strm)
Input the string from the specified stream.