vcard.h
Go to the documentation of this file.
/*
* vcard.h
*
* Class to represent and parse a vCard as per RFC2426
*
* Portable Windows Library
*
* Copyright (c) 2010 Vox Lucida Pty Ltd
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Tools Library.
*
* The Initial Developer of the Original Code is Vox Lucida Pty Ltd
*
* Contributor(s): ______________________________________.
*
* $Revision: 26015 $
* $Author: rjongbloed $
* $Date: 2011-06-14 02:31:10 -0500 (Tue, 14 Jun 2011) $
*/
#ifndef PTLIB_VCARD_H
#define PTLIB_VCARD_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <ptclib/url.h>
class PvCard : public PObject
{
PCLASSINFO(PvCard, PObject);
public:
PvCard();
bool IsValid() const;
virtual void PrintOn(
ostream & strm
) const;
virtual void ReadFrom(
istream & strm
);
bool Parse(
const PString & str
);
enum Format {
e_Standard,
e_XML_XMPP,
e_XML_RDF,
e_XML_RFC
};
PString AsString(
Format fmt = e_Standard
);
class Token : public PCaselessString
{
public:
Token(const char * str = NULL) : PCaselessString(str) { Validate(); }
Token(const PString & str) : PCaselessString(str) { Validate(); }
Token & operator=(const char * str) { PCaselessString::operator=(str); Validate(); return *this; }
Token & operator=(const PString & str) { PCaselessString::operator=(str); Validate(); return *this; }
virtual void PrintOn(ostream & strm) const;
virtual void ReadFrom(istream & strm);
private:
void Validate();
};
class Separator : public PObject
{
public:
Separator(char c = '\0') : m_separator(c) { }
virtual void PrintOn(ostream & strm) const;
virtual void ReadFrom(istream & strm);
bool operator==(char c) const { return m_separator == c; }
bool operator!=(char c) const { return m_separator != c; }
char m_separator;
};
class ParamValue : public PString
{
public:
ParamValue(const char * str = NULL) : PString(str) { }
ParamValue(const PString & str) : PString(str) { }
virtual void PrintOn(ostream & strm) const;
virtual void ReadFrom(istream & strm);
};
class ParamValues : public PArray<ParamValue>
{
public:
virtual void PrintOn(ostream & strm) const;
virtual void ReadFrom(istream & strm);
};
typedef std::map<Token, ParamValues> ParamMap;
class TypeValues : public ParamValues
{
public:
TypeValues() { }
TypeValues(const ParamValues & values) : ParamValues(values) { }
virtual void PrintOn(ostream & strm) const;
};
class TextValue : public PString
{
public:
TextValue(const char * str = NULL) : PString(str) { }
TextValue(const PString & str) : PString(str) { }
virtual void PrintOn(ostream & strm) const;
virtual void ReadFrom(istream & strm);
};
class TextValues : public PArray<TextValue>
{
public:
virtual void PrintOn(ostream & strm) const;
virtual void ReadFrom(istream & strm);
};
class URIValue : public PURL
{
public:
URIValue(const char * str = NULL) : PURL(str) { }
URIValue(const PString & str) : PURL(str) { }
virtual void PrintOn(ostream & strm) const;
virtual void ReadFrom(istream & strm);
};
class InlineValue : public URIValue
{
public:
InlineValue(const char * str = NULL) : URIValue(str), m_params(NULL) { }
InlineValue(const PString & str) : URIValue(str), m_params(NULL) { }
virtual void PrintOn(ostream & strm) const;
virtual void ReadFrom(istream & strm);
InlineValue & ReadFromParam(const ParamMap & params);
private:
const ParamMap * m_params;
};
Token m_group;
TextValue m_fullName; // Mandatory
TextValue m_version; // Mandatory
TextValue m_familyName;
TextValue m_givenName;
TextValues m_additionalNames;
TextValue m_honorificPrefixes;
TextValue m_honorificSuffixes;
TextValues m_nickNames;
TextValue m_sortString; // Form of name for sorting, e.g. family name;
PTime m_birthday;
URIValue m_url;
InlineValue m_photo; // Possibly embedded via data: scheme
InlineValue m_sound; // Possibly embedded via data: scheme
TextValue m_timeZone;
double m_latitude;
double m_longitude;
TextValue m_title;
TextValue m_role;
InlineValue m_logo; // Possibly embedded via data: scheme
TextValue m_agent;
TextValue m_organisationName;
TextValue m_organisationUnit;
TextValue m_mailer;
TextValues m_categories;
TextValue m_note;
TextValue m_productId;
TextValue m_guid;
TextValue m_revision;
TextValue m_class;
TextValue m_publicKey;
struct MultiValue : public PObject {
MultiValue() { }
MultiValue(const PString & type) { m_types.Append(new ParamValue(type)); }
TypeValues m_types; // e.g. "home", "work", "pref" etc
void SetTypes(const ParamMap & params);
};
struct Address : public MultiValue {
Address(bool label = false) : m_label(label) { }
virtual void PrintOn(ostream & strm) const;
virtual void ReadFrom(istream & strm);
bool m_label;
TextValue m_postOfficeBox;
TextValue m_extendedAddress;
TextValue m_street; // Including number "123 Main Street"
TextValue m_locality; // Suburb/city
TextValue m_region; // State/province
TextValue m_postCode;
TextValue m_country;
};
PArray<Address> m_addresses;
PArray<Address> m_labels;
struct Telephone : public MultiValue {
Telephone() { }
Telephone(const PString & number, const PString & type = PString::Empty())
: MultiValue(type)
, m_number(number)
{ }
virtual void PrintOn(ostream & strm) const;
TextValue m_number;
};
PArray<Telephone> m_telephoneNumbers;
struct EMail : public MultiValue {
EMail() { }
EMail(const PString & address, const PString & type = PString::Empty())
: MultiValue(type)
, m_address(address)
{ }
virtual void PrintOn(ostream & strm) const;
TextValue m_address;
};
PArray<EMail> m_emailAddresses;
struct ExtendedType {
ParamMap m_parameters;
TextValue m_value;
};
typedef std::map<Token, ExtendedType> ExtendedTypeMap;
ExtendedTypeMap m_extensions;
};
#endif // PTLIB_VCARD_H
// End of File ///////////////////////////////////////////////////////////////
PvCard::Separator::operator!=
bool operator!=(char c) const
Definition: vcard.h:101
PvCard::m_version
TextValue m_version
Definition: vcard.h:174
PvCard::ParamValue::ParamValue
ParamValue(const PString &str)
Definition: vcard.h:110
PvCard::Token::operator=
Token & operator=(const PString &str)
Definition: vcard.h:87
PvCard::m_class
TextValue m_class
Definition: vcard.h:206
PvCard::EMail::EMail
EMail()
Definition: vcard.h:247
PvCard
Class to represent a vCard as per RFC2426.
Definition: vcard.h:44
PvCard::Telephone::m_number
TextValue m_number
Definition: vcard.h:242
PvCard::ExtendedType
Definition: vcard.h:257
PvCard::m_revision
TextValue m_revision
Definition: vcard.h:205
PvCard::TypeValues
Definition: vcard.h:124
PvCard::m_telephoneNumbers
PArray< Telephone > m_telephoneNumbers
Definition: vcard.h:244
PvCard::m_logo
InlineValue m_logo
Definition: vcard.h:194
PvCard::Separator
Definition: vcard.h:94
PvCard::ParamValues
Comma separated list of param-value&#39;s.
Definition: vcard.h:115
PvCard::m_addresses
PArray< Address > m_addresses
Definition: vcard.h:231
PvCard::m_guid
TextValue m_guid
Definition: vcard.h:204
PvCard::m_photo
InlineValue m_photo
Definition: vcard.h:186
PvCard::m_emailAddresses
PArray< EMail > m_emailAddresses
Definition: vcard.h:255
PvCard::EMail::EMail
EMail(const PString &address, const PString &type=PString::Empty())
Definition: vcard.h:248
PvCard::Format
Format
Output string formats.
Definition: vcard.h:70
PvCard::m_fullName
TextValue m_fullName
Definition: vcard.h:173
PvCard::m_url
URIValue m_url
Definition: vcard.h:185
PTime
This class defines an absolute time and date.
Definition: ptime.h:53
PvCard::m_honorificPrefixes
TextValue m_honorificPrefixes
Definition: vcard.h:179
PvCard::ReadFrom
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
PvCard::MultiValue::m_types
TypeValues m_types
Definition: vcard.h:213
PvCard::Address::m_region
TextValue m_region
Definition: vcard.h:227
PvCard::MultiValue::MultiValue
MultiValue(const PString &type)
Definition: vcard.h:211
PvCard::Address
Definition: vcard.h:217
PCaselessString::operator=
PCaselessString & operator=(const PString &str)
Assign the string to the current object.
PvCard::Separator::operator==
bool operator==(char c) const
Definition: vcard.h:100
PvCard::m_extensions
ExtendedTypeMap m_extensions
Definition: vcard.h:263
PCaselessString
This class is a variation of a string that ignores case.
Definition: pstring.h:1708
PvCard::TextValue::TextValue
TextValue(const PString &str)
Definition: vcard.h:137
PvCard::e_XML_RFC
Draft RFC.
Definition: vcard.h:74
PvCard::m_productId
TextValue m_productId
Definition: vcard.h:203
PvCard::Address::Address
Address(bool label=false)
Definition: vcard.h:218
PvCard::Address::m_locality
TextValue m_locality
Definition: vcard.h:226
PvCard::InlineValue::InlineValue
InlineValue(const char *str=NULL)
Definition: vcard.h:163
PvCard::ParamValue::ParamValue
ParamValue(const char *str=NULL)
Definition: vcard.h:109
PvCard::m_labels
PArray< Address > m_labels
Definition: vcard.h:232
PvCard::m_note
TextValue m_note
Definition: vcard.h:201
PvCard::TypeValues::TypeValues
TypeValues()
Definition: vcard.h:127
PvCard::PrintOn
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
PvCard::TypeValues::TypeValues
TypeValues(const ParamValues &values)
Definition: vcard.h:128
PvCard::m_organisationName
TextValue m_organisationName
Definition: vcard.h:196
PvCard::ExtendedType::m_value
TextValue m_value
Definition: vcard.h:259
PvCard::IsValid
bool IsValid() const
PvCard::e_Standard
As per RFC2425.
Definition: vcard.h:71
PvCard::m_categories
TextValues m_categories
Definition: vcard.h:200
PvCard::m_title
TextValue m_title
Definition: vcard.h:192
PvCard::EMail
Definition: vcard.h:246
PvCard::InlineValue
Representation of EBNF img-inline-value/snd-inline-value.
Definition: vcard.h:160
PvCard::m_birthday
PTime m_birthday
Definition: vcard.h:184
PvCard::Telephone
Definition: vcard.h:234
PvCard::m_mailer
TextValue m_mailer
Definition: vcard.h:199
PvCard::ParamValue
Representation of EBNF param-value.
Definition: vcard.h:106
PvCard::Address::m_label
bool m_label
Definition: vcard.h:222
PvCard::Address::m_postOfficeBox
TextValue m_postOfficeBox
Definition: vcard.h:223
PvCard::Separator::Separator
Separator(char c='\0')
Definition: vcard.h:97
PvCard::URIValue::URIValue
URIValue(const PString &str)
Definition: vcard.h:154
PvCard::URIValue
Definition: vcard.h:150
PvCard::Token::Token
Token(const char *str=NULL)
Definition: vcard.h:84
PvCard::TextValue
Representation of EBNF text-value.
Definition: vcard.h:133
PvCard::m_timeZone
TextValue m_timeZone
Definition: vcard.h:188
PvCard::m_sortString
TextValue m_sortString
Definition: vcard.h:182
PString
The character string class.
Definition: pstring.h:108
PvCard::m_longitude
double m_longitude
Definition: vcard.h:190
PvCard::Address::m_postCode
TextValue m_postCode
Definition: vcard.h:228
PvCard::URIValue::URIValue
URIValue(const char *str=NULL)
Definition: vcard.h:153
PString::Empty
static PString Empty()
Return an empty string.
PvCard::m_group
Token m_group
Definition: vcard.h:172
PvCard::m_latitude
double m_latitude
Definition: vcard.h:189
PvCard::m_agent
TextValue m_agent
Definition: vcard.h:195
PvCard::MultiValue::MultiValue
MultiValue()
Definition: vcard.h:210
PvCard::Address::m_street
TextValue m_street
Definition: vcard.h:225
PvCard::Address::m_extendedAddress
TextValue m_extendedAddress
Definition: vcard.h:224
PvCard::m_organisationUnit
TextValue m_organisationUnit
Definition: vcard.h:197
PvCard::m_additionalNames
TextValues m_additionalNames
Definition: vcard.h:178
PvCard::m_givenName
TextValue m_givenName
Definition: vcard.h:177
PvCard::MultiValue
Definition: vcard.h:209
PvCard::Parse
bool Parse(const PString &str)
PvCard::Telephone::Telephone
Telephone()
Definition: vcard.h:235
PvCard::ExtendedType::m_parameters
ParamMap m_parameters
Definition: vcard.h:258
PvCard::ParamMap
std::map< Token, ParamValues > ParamMap
Definition: vcard.h:122
PvCard::TextValue::TextValue
TextValue(const char *str=NULL)
Definition: vcard.h:136
PvCard::e_XML_RDF
W3C version.
Definition: vcard.h:73
PvCard::m_sound
InlineValue m_sound
Definition: vcard.h:187
PvCard::ExtendedTypeMap
std::map< Token, ExtendedType > ExtendedTypeMap
Definition: vcard.h:262
PArray
This template class maps the PArrayObjects to a specific object type.
Definition: array.h:1024
PvCard::AsString
PString AsString(Format fmt=e_Standard)
PvCard::Separator::m_separator
char m_separator
Definition: vcard.h:102
PvCard::InlineValue::InlineValue
InlineValue(const PString &str)
Definition: vcard.h:164
PvCard::Address::m_country
TextValue m_country
Definition: vcard.h:229
PvCard::TextValues
Comma separated list of text-value&#39;s.
Definition: vcard.h:143
PvCard::m_nickNames
TextValues m_nickNames
Definition: vcard.h:181
PvCard::PvCard
PvCard()
PvCard::m_honorificSuffixes
TextValue m_honorificSuffixes
Definition: vcard.h:180
url.h
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PvCard::Token
Representation of token (EBNF group, name, iana-token or x-name)
Definition: vcard.h:81
PURL
This class describes a Universal Resource Locator.
Definition: url.h:54
PvCard::m_role
TextValue m_role
Definition: vcard.h:193
PvCard::Token::Token
Token(const PString &str)
Definition: vcard.h:85
PvCard::e_XML_XMPP
Jabber XML.
Definition: vcard.h:72
PvCard::EMail::m_address
TextValue m_address
Definition: vcard.h:253
PvCard::m_familyName
TextValue m_familyName
Definition: vcard.h:176
PvCard::Token::operator=
Token & operator=(const char *str)
Definition: vcard.h:86
PvCard::Token::PrintOn
virtual void PrintOn(ostream &strm) const
Output the string to the specified stream.
PvCard::Telephone::Telephone
Telephone(const PString &number, const PString &type=PString::Empty())
Definition: vcard.h:236
PvCard::m_publicKey
TextValue m_publicKey
Definition: vcard.h:207
PvCard::Token::ReadFrom
virtual void ReadFrom(istream &strm)
Input the string from the specified stream.