21 void VCard::insertField( Tag* vcard,
const char* field,
const std::string& var )
23 if( field && !var.empty() )
24 new Tag( vcard, field, var );
27 void VCard::insertField( Tag* vcard,
const char* field,
bool var )
30 new Tag( vcard, field );
33 void VCard::checkField(
const Tag* vcard,
const char* field, std::string& var )
37 Tag* child = vcard->findChild( field );
45 m_N( false ), m_PHOTO( false ), m_LOGO( false )
52 m_N( false ), m_PHOTO( false ), m_LOGO( false )
59 checkField( vcard,
"FN", m_formattedname );
60 checkField( vcard,
"NICKNAME", m_nickname );
61 checkField( vcard,
"URL", m_url );
62 checkField( vcard,
"BDAY", m_bday );
63 checkField( vcard,
"JABBERID", m_jabberid );
64 checkField( vcard,
"TITLE", m_title );
65 checkField( vcard,
"ROLE", m_role );
66 checkField( vcard,
"NOTE", m_note );
67 checkField( vcard,
"DESC", m_desc );
68 checkField( vcard,
"MAILER", m_mailer );
69 checkField( vcard,
"TZ", m_tz );
70 checkField( vcard,
"PRODID", m_prodid );
71 checkField( vcard,
"REV", m_rev );
72 checkField( vcard,
"SORT-STRING", m_sortstring );
73 checkField( vcard,
"UID", m_uid );
75 TagList::const_iterator it = vcard->
children().begin();
76 for( ; it != vcard->
children().end(); ++it )
79 if( tag.
name() ==
"N" )
85 if( ( child = tag.
findChild(
"GIVEN" ) ) )
87 if( ( child = tag.
findChild(
"MIDDLE" ) ) )
89 if( ( child = tag.
findChild(
"PREFIX" ) ) )
91 if( ( child = tag.
findChild(
"SUFFIX" ) ) )
94 else if( tag.
name() ==
"PHOTO" )
104 std::string::size_type pos = 0;
105 while( ( pos = binval.find(
'\n' ) ) != std::string::npos )
106 binval.erase( pos, 1 );
107 while( ( pos = binval.find(
'\r' ) ) != std::string::npos )
108 binval.erase( pos, 1 );
114 else if( tag.
name() ==
"LOGO" )
124 std::string::size_type pos = 0;
125 while( ( pos = binval.find(
'\n' ) ) != std::string::npos )
126 binval.erase( pos, 1 );
127 while( ( pos = binval.find(
'\r' ) ) != std::string::npos )
128 binval.erase( pos, 1 );
134 else if( tag.
name() ==
"EMAIL" && tag.
hasChild(
"USERID" ) )
143 m_emailList.push_back( item );
145 else if( tag.
name() ==
"ADR" )
148 checkField( &tag,
"POBOX", item.
pobox );
149 checkField( &tag,
"EXTADD", item.
extadd );
150 checkField( &tag,
"STREET", item.
street );
151 checkField( &tag,
"LOCALITY", item.
locality );
152 checkField( &tag,
"REGION", item.
region );
153 checkField( &tag,
"PCODE", item.
pcode );
154 checkField( &tag,
"CTRY", item.
ctry );
162 m_addressList.push_back( item );
164 else if( tag.
name() ==
"LABEL" )
167 TagList::const_iterator it2 = tag.
children().begin();
168 for( ; it2 != tag.
children().end(); ++it2 )
170 if( (*it2)->name() ==
"LINE" )
171 item.
lines.push_back( (*it)->cdata() );
172 item.
postal = (*it2)->name() ==
"POSTAL";
173 item.
parcel = (*it2)->name() ==
"PARCEL";
174 item.
work = (*it2)->name() ==
"WORK";
175 item.
home = (*it2)->name() ==
"HOME";
176 item.
pref = (*it2)->name() ==
"PREF";
177 item.
dom = (*it2)->name() ==
"DOM";
178 item.
intl = !item.
dom && (*it2)->name() ==
"INTL";
180 m_labelList.push_back( item );
182 else if( tag.
name() ==
"TEL" && tag.
hasChild(
"NUMBER" ) )
199 m_telephoneList.push_back( item );
201 else if( tag.
name() ==
"ORG" )
203 TagList::const_iterator ito = tag.
children().begin();
204 for( ; ito != tag.
children().end(); ++ito )
206 if( (*ito)->name() ==
"ORGNAME" )
207 m_org.
name = (*ito)->cdata();
208 else if( (*ito)->name() ==
"ORGUNIT" )
209 m_org.
units.push_back( (*ito)->cdata() );
212 else if( tag.
name() ==
"GEO" )
214 checkField( &tag,
"LON", m_geo.
longitude );
215 checkField( &tag,
"LAT", m_geo.
latitude );
217 else if( tag.
name() ==
"CLASS" )
223 else if( tag.
hasChild(
"CONFIDENTIAL" ) )
232 const std::string& middle,
const std::string& prefix,
233 const std::string& suffix )
236 m_name.
given = given;
245 if( !extval.empty() )
254 if( !type.empty() && !binval.empty() )
271 if( !extval.empty() )
280 if( !type.empty() && !binval.empty() )
308 m_emailList.push_back( item );
312 const std::string& street,
const std::string& locality,
313 const std::string& region,
const std::string& pcode,
314 const std::string& ctry,
int type )
316 if( pobox.empty() && extadd.empty() && street.empty() &&
317 locality.empty() && region.empty() && pcode.empty() && ctry.empty() )
336 m_addressList.push_back( item );
354 m_labelList.push_back( item );
378 m_telephoneList.push_back( item );
383 if( !lat.empty() && !lon.empty() )
392 if( !orgname.empty() )
394 m_org.
name = orgname;
395 m_org.
units = orgunits;
401 static const std::string filter =
"/iq/vCard[@xmlns='" +
XMLNS_VCARD_TEMP +
"']";
407 Tag* v =
new Tag(
"vCard" );
415 insertField( v,
"FN", m_formattedname );
416 insertField( v,
"NICKNAME", m_nickname );
417 insertField( v,
"URL", m_url );
418 insertField( v,
"BDAY", m_bday );
419 insertField( v,
"JABBERID", m_jabberid );
420 insertField( v,
"TITLE", m_title );
421 insertField( v,
"ROLE", m_role );
422 insertField( v,
"NOTE", m_note );
423 insertField( v,
"DESC", m_desc );
424 insertField( v,
"MAILER", m_mailer );
425 insertField( v,
"TZ", m_tz );
426 insertField( v,
"REV", m_rev );
427 insertField( v,
"SORT_STRING", m_sortstring );
428 insertField( v,
"UID", m_uid );
432 Tag* n =
new Tag( v,
"N" );
433 insertField( n,
"FAMILY", m_name.
family );
434 insertField( n,
"GIVEN", m_name.
given );
435 insertField( n,
"MIDDLE", m_name.
middle );
436 insertField( n,
"PREFIX", m_name.
prefix );
437 insertField( n,
"SUFFIX", m_name.
suffix );
442 Tag* p =
new Tag( v,
"PHOTO" );
443 if( !m_photo.
extval.empty() )
447 else if( !m_photo.
type.empty() && !m_photo.
binval.empty() )
449 new Tag( p,
"TYPE", m_photo.
type );
456 Tag* l =
new Tag( v,
"LOGO" );
457 if( !m_logo.
extval.empty() )
461 else if( !m_logo.
type.empty() && !m_logo.
binval.empty() )
463 new Tag( l,
"TYPE", m_logo.
type );
468 EmailList::const_iterator ite = m_emailList.begin();
469 for( ; ite != m_emailList.end(); ++ite )
471 Tag* e =
new Tag( v,
"EMAIL" );
472 insertField( e,
"INTERNET", (*ite).internet );
473 insertField( e,
"WORK", (*ite).work );
474 insertField( e,
"HOME", (*ite).home );
475 insertField( e,
"X400", (*ite).x400 );
476 insertField( e,
"PREF", (*ite).pref );
477 insertField( e,
"USERID", (*ite).userid );
480 AddressList::const_iterator ita = m_addressList.begin();
481 for( ; ita != m_addressList.end(); ++ita )
483 Tag* a =
new Tag( v,
"ADR" );
484 insertField( a,
"POSTAL", (*ita).postal );
485 insertField( a,
"PARCEL", (*ita).parcel );
486 insertField( a,
"HOME", (*ita).home );
487 insertField( a,
"WORK", (*ita).work );
488 insertField( a,
"PREF", (*ita).pref );
489 insertField( a,
"DOM", (*ita).dom );
491 insertField( a,
"INTL", (*ita).intl );
493 insertField( a,
"POBOX", (*ita).pobox );
494 insertField( a,
"EXTADD", (*ita).extadd );
495 insertField( a,
"STREET", (*ita).street );
496 insertField( a,
"LOCALITY", (*ita).locality );
497 insertField( a,
"REGION", (*ita).region );
498 insertField( a,
"PCODE", (*ita).pcode );
499 insertField( a,
"CTRY", (*ita).ctry );
502 TelephoneList::const_iterator itt = m_telephoneList.begin();
503 for( ; itt != m_telephoneList.end(); ++itt )
505 Tag* t =
new Tag( v,
"TEL" );
506 insertField( t,
"NUMBER", (*itt).number );
507 insertField( t,
"HOME", (*itt).home );
508 insertField( t,
"WORK", (*itt).work );
509 insertField( t,
"VOICE", (*itt).voice );
510 insertField( t,
"FAX", (*itt).fax );
511 insertField( t,
"PAGER", (*itt).pager );
512 insertField( t,
"MSG", (*itt).msg );
513 insertField( t,
"CELL", (*itt).cell );
514 insertField( t,
"VIDEO", (*itt).video );
515 insertField( t,
"BBS", (*itt).bbs );
516 insertField( t,
"MODEM", (*itt).modem );
517 insertField( t,
"ISDN", (*itt).isdn );
518 insertField( t,
"PCS", (*itt).pcs );
519 insertField( t,
"PREF", (*itt).pref );
524 Tag* g =
new Tag( v,
"GEO" );
529 if( !m_org.
name.empty() )
531 Tag* o =
new Tag( v,
"ORG" );
532 new Tag( o,
"ORGNAME", m_org.
name );
533 StringList::const_iterator ito = m_org.
units.begin();
534 for( ; ito != m_org.
units.end(); ++ito )
535 new Tag( o,
"ORGUNIT", (*ito) );
540 Tag* c =
new Tag( v,
"CLASS" );
544 new Tag( c,
"PUBLIC" );
547 new Tag( c,
"PRIVATE" );
550 new Tag( c,
"CONFIDENTIAL" );
const TagList & children() const
bool setXmlns(const std::string &xmlns, const std::string &prefix=EmptyString)
std::list< std::string > StringList
void addEmail(const std::string &userid, int type)
void addLabel(const StringList &lines, int type)
const std::string decode64(const std::string &input)
void setPhotoUri(const std::string &extval)
The namespace for the gloox library.
const std::string encode64(const std::string &input)
void setLogo(const std::string &extval)
This class abstracts a stanza extension, which is usually an element in a specific namespace...
const std::string & xmlns() const
const std::string cdata() const
void setOrganization(const std::string &orgname, const StringList &orgunits)
const std::string GLOOX_VERSION
void setName(const std::string &family, const std::string &given, const std::string &middle=EmptyString, const std::string &prefix=EmptyString, const std::string &suffix=EmptyString)
void addTelephone(const std::string &number, int type)
bool addAttribute(Attribute *attr)
virtual const std::string & filterString() const
bool hasChild(const std::string &name, const std::string &attr=EmptyString, const std::string &value=EmptyString) const
const std::string & name() const
void setPhoto(const std::string &type=EmptyString, const std::string &binval=EmptyString)
const std::string XMLNS_VCARD_TEMP
void setGeo(const std::string &lat, const std::string &lon)
Tag * findChild(const std::string &name) const
const std::string EmptyString
void addAddress(const std::string &pobox, const std::string &extadd, const std::string &street, const std::string &locality, const std::string ®ion, const std::string &pcode, const std::string &ctry, int type)
This is an abstraction of an XML element.
virtual Tag * tag() const