00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef PTLIB_VCARD_H
00032 #define PTLIB_VCARD_H
00033
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037
00038
00039 #include <ptclib/url.h>
00040
00041
00044 class PvCard : public PObject
00045 {
00046 PCLASSINFO(PvCard, PObject);
00047
00048 public:
00049 PvCard();
00050
00051 bool IsValid() const;
00052
00053 virtual void PrintOn(
00054 ostream & strm
00055 ) const;
00056 virtual void ReadFrom(
00057 istream & strm
00058 );
00059 bool Parse(
00060 const PString & str
00061 );
00062
00070 enum Format {
00071 e_Standard,
00072 e_XML_XMPP,
00073 e_XML_RDF,
00074 e_XML_RFC
00075 };
00076 PString AsString(
00077 Format fmt = e_Standard
00078 );
00079
00081 class Token : public PCaselessString
00082 {
00083 public:
00084 Token(const char * str = NULL) : PCaselessString(str) { Validate(); }
00085 Token(const PString & str) : PCaselessString(str) { Validate(); }
00086 Token & operator=(const char * str) { PCaselessString::operator=(str); Validate(); return *this; }
00087 Token & operator=(const PString & str) { PCaselessString::operator=(str); Validate(); return *this; }
00088 virtual void PrintOn(ostream & strm) const;
00089 virtual void ReadFrom(istream & strm);
00090 private:
00091 void Validate();
00092 };
00093
00094 class Separator : public PObject
00095 {
00096 public:
00097 Separator(char c = '\0') : m_separator(c) { }
00098 virtual void PrintOn(ostream & strm) const;
00099 virtual void ReadFrom(istream & strm);
00100 bool operator==(char c) const { return m_separator == c; }
00101 bool operator!=(char c) const { return m_separator != c; }
00102 char m_separator;
00103 };
00104
00106 class ParamValue : public PString
00107 {
00108 public:
00109 ParamValue(const char * str = NULL) : PString(str) { }
00110 ParamValue(const PString & str) : PString(str) { }
00111 virtual void PrintOn(ostream & strm) const;
00112 virtual void ReadFrom(istream & strm);
00113 };
00115 class ParamValues : public PArray<ParamValue>
00116 {
00117 public:
00118 virtual void PrintOn(ostream & strm) const;
00119 virtual void ReadFrom(istream & strm);
00120 };
00121
00122 typedef std::map<Token, ParamValues> ParamMap;
00123
00124 class TypeValues : public ParamValues
00125 {
00126 public:
00127 TypeValues() { }
00128 TypeValues(const ParamValues & values) : ParamValues(values) { }
00129 virtual void PrintOn(ostream & strm) const;
00130 };
00131
00133 class TextValue : public PString
00134 {
00135 public:
00136 TextValue(const char * str = NULL) : PString(str) { }
00137 TextValue(const PString & str) : PString(str) { }
00138 virtual void PrintOn(ostream & strm) const;
00139 virtual void ReadFrom(istream & strm);
00140 };
00141
00143 class TextValues : public PArray<TextValue>
00144 {
00145 public:
00146 virtual void PrintOn(ostream & strm) const;
00147 virtual void ReadFrom(istream & strm);
00148 };
00149
00150 class URIValue : public PURL
00151 {
00152 public:
00153 URIValue(const char * str = NULL) : PURL(str) { }
00154 URIValue(const PString & str) : PURL(str) { }
00155 virtual void PrintOn(ostream & strm) const;
00156 virtual void ReadFrom(istream & strm);
00157 };
00158
00160 class InlineValue : public URIValue
00161 {
00162 public:
00163 InlineValue(const char * str = NULL) : URIValue(str), m_params(NULL) { }
00164 InlineValue(const PString & str) : URIValue(str), m_params(NULL) { }
00165 virtual void PrintOn(ostream & strm) const;
00166 virtual void ReadFrom(istream & strm);
00167 InlineValue & ReadFromParam(const ParamMap & params);
00168 private:
00169 const ParamMap * m_params;
00170 };
00171
00172 Token m_group;
00173 TextValue m_fullName;
00174 TextValue m_version;
00175
00176 TextValue m_familyName;
00177 TextValue m_givenName;
00178 TextValues m_additionalNames;
00179 TextValue m_honorificPrefixes;
00180 TextValue m_honorificSuffixes;
00181 TextValues m_nickNames;
00182 TextValue m_sortString;
00183
00184 PTime m_birthday;
00185 URIValue m_url;
00186 InlineValue m_photo;
00187 InlineValue m_sound;
00188 TextValue m_timeZone;
00189 double m_latitude;
00190 double m_longitude;
00191
00192 TextValue m_title;
00193 TextValue m_role;
00194 InlineValue m_logo;
00195 TextValue m_agent;
00196 TextValue m_organisationName;
00197 TextValue m_organisationUnit;
00198
00199 TextValue m_mailer;
00200 TextValues m_categories;
00201 TextValue m_note;
00202
00203 TextValue m_productId;
00204 TextValue m_guid;
00205 TextValue m_revision;
00206 TextValue m_class;
00207 TextValue m_publicKey;
00208
00209 struct MultiValue : public PObject {
00210 MultiValue() { }
00211 MultiValue(const PString & type) { m_types.Append(new ParamValue(type)); }
00212
00213 TypeValues m_types;
00214 void SetTypes(const ParamMap & params);
00215 };
00216
00217 struct Address : public MultiValue {
00218 Address(bool label = false) : m_label(label) { }
00219 virtual void PrintOn(ostream & strm) const;
00220 virtual void ReadFrom(istream & strm);
00221
00222 bool m_label;
00223 TextValue m_postOfficeBox;
00224 TextValue m_extendedAddress;
00225 TextValue m_street;
00226 TextValue m_locality;
00227 TextValue m_region;
00228 TextValue m_postCode;
00229 TextValue m_country;
00230 };
00231 PArray<Address> m_addresses;
00232 PArray<Address> m_labels;
00233
00234 struct Telephone : public MultiValue {
00235 Telephone() { }
00236 Telephone(const PString & number, const PString & type = PString::Empty())
00237 : MultiValue(type)
00238 , m_number(number)
00239 { }
00240 virtual void PrintOn(ostream & strm) const;
00241
00242 TextValue m_number;
00243 };
00244 PArray<Telephone> m_telephoneNumbers;
00245
00246 struct EMail : public MultiValue {
00247 EMail() { }
00248 EMail(const PString & address, const PString & type = PString::Empty())
00249 : MultiValue(type)
00250 , m_address(address)
00251 { }
00252 virtual void PrintOn(ostream & strm) const;
00253 TextValue m_address;
00254 };
00255 PArray<EMail> m_emailAddresses;
00256
00257 struct ExtendedType {
00258 ParamMap m_parameters;
00259 TextValue m_value;
00260 };
00261
00262 typedef std::map<Token, ExtendedType> ExtendedTypeMap;
00263 ExtendedTypeMap m_extensions;
00264 };
00265
00266
00267 #endif // PTLIB_VCARD_H
00268
00269
00270