1 /* 2 belcard.hpp 3 Copyright (C) 2015 Belledonne Communications SARL 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef belcard_hpp 20 #define belcard_hpp 21 22 #include "belcard_utils.hpp" 23 #include "belcard_generic.hpp" 24 #include "belcard_params.hpp" 25 #include "belcard_property.hpp" 26 #include "belcard_general.hpp" 27 #include "belcard_identification.hpp" 28 #include "belcard_addressing.hpp" 29 #include "belcard_communication.hpp" 30 #include "belcard_geographical.hpp" 31 #include "belcard_organizational.hpp" 32 #include "belcard_explanatory.hpp" 33 #include "belcard_security.hpp" 34 #include "belcard_calendar.hpp" 35 #include "belcard_rfc6474.hpp" 36 37 #include "bctoolbox/logging.h" 38 39 #include <string> 40 #include <list> 41 42 namespace belcard { 43 44 class BelCard : public BelCardGeneric { 45 private: 46 std::string _folded_string; 47 bool _skipFieldValidation = false; 48 49 std::shared_ptr<BelCardKind> _kind; 50 std::shared_ptr<BelCardFullName> _fn; 51 std::shared_ptr<BelCardName> _n; 52 std::shared_ptr<BelCardBirthday> _bday; 53 std::shared_ptr<BelCardAnniversary> _anniversary; 54 std::shared_ptr<BelCardGender> _gender; 55 std::shared_ptr<BelCardProductId> _pid; 56 std::shared_ptr<BelCardRevision> _rev; 57 std::shared_ptr<BelCardUniqueId> _uid; 58 std::shared_ptr<BelCardBirthPlace> _bplace; 59 std::shared_ptr<BelCardDeathPlace> _dplace; 60 std::shared_ptr<BelCardDeathDate> _ddate; 61 std::list<std::shared_ptr<BelCardNickname>> _nicknames; 62 std::list<std::shared_ptr<BelCardPhoto>> _photos; 63 std::list<std::shared_ptr<BelCardAddress>> _addr; 64 std::list<std::shared_ptr<BelCardPhoneNumber>> _tel; 65 std::list<std::shared_ptr<BelCardEmail>> _emails; 66 std::list<std::shared_ptr<BelCardImpp>> _impp; 67 std::list<std::shared_ptr<BelCardLang>> _langs; 68 std::list<std::shared_ptr<BelCardSource>> _sources; 69 std::list<std::shared_ptr<BelCardXML>> _xml; 70 std::list<std::shared_ptr<BelCardTimezone>> _timezones; 71 std::list<std::shared_ptr<BelCardGeo>> _geos; 72 std::list<std::shared_ptr<BelCardTitle>> _titles; 73 std::list<std::shared_ptr<BelCardRole>> _roles; 74 std::list<std::shared_ptr<BelCardLogo>> _logos; 75 std::list<std::shared_ptr<BelCardOrganization>> _organizations; 76 std::list<std::shared_ptr<BelCardMember>> _members; 77 std::list<std::shared_ptr<BelCardRelated>> _related; 78 std::list<std::shared_ptr<BelCardCategories>> _categories; 79 std::list<std::shared_ptr<BelCardNote>> _notes; 80 std::list<std::shared_ptr<BelCardSound>> _sounds; 81 std::list<std::shared_ptr<BelCardClientProductIdMap>> _clientpidmaps; 82 std::list<std::shared_ptr<BelCardURL>> _urls; 83 std::list<std::shared_ptr<BelCardKey>> _keys; 84 std::list<std::shared_ptr<BelCardFBURL>> _fburls; 85 std::list<std::shared_ptr<BelCardCALADRURI>> _caladruris; 86 std::list<std::shared_ptr<BelCardCALURI>> _caluris; 87 std::list<std::shared_ptr<BelCardProperty>> _extended_properties; 88 std::list<std::shared_ptr<BelCardProperty>> _properties; 89 90 template<typename T> 91 void set(std::shared_ptr<T> &p, const std::shared_ptr<T> &property); 92 93 template<typename T> 94 void add(std::list<std::shared_ptr<T>> &property_list, const std::shared_ptr<T> &property); 95 96 template<typename T> 97 void remove(std::list<std::shared_ptr<T>> &property_list, const std::shared_ptr<T> &property); 98 99 // The following are for belcard use only, they don't do any check on the value 100 void _setKind(const std::shared_ptr<BelCardKind> &kind); 101 void _setFullName(const std::shared_ptr<BelCardFullName> &fn); 102 void _setName(const std::shared_ptr<BelCardName> &n); 103 void _setBirthday(const std::shared_ptr<BelCardBirthday> &bday); 104 void _setAnniversary(const std::shared_ptr<BelCardAnniversary> &anniversary); 105 void _setGender(const std::shared_ptr<BelCardGender> &gender); 106 void _setProductId(const std::shared_ptr<BelCardProductId> &pid); 107 void _setRevision(const std::shared_ptr<BelCardRevision> &rev); 108 void _setUniqueId(const std::shared_ptr<BelCardUniqueId> &uid); 109 void _setBirthPlace(const std::shared_ptr<BelCardBirthPlace> &place); 110 void _setDeathPlace(const std::shared_ptr<BelCardDeathPlace> &place); 111 void _setDeathDate(const std::shared_ptr<BelCardDeathDate> &date); 112 void _addNickname(const std::shared_ptr<BelCardNickname> &nickname); 113 void _addPhoto(const std::shared_ptr<BelCardPhoto> &photo); 114 void _addAddress(const std::shared_ptr<BelCardAddress> &addr); 115 void _addPhoneNumber(const std::shared_ptr<BelCardPhoneNumber> &tel); 116 void _addEmail(const std::shared_ptr<BelCardEmail> &email); 117 void _addImpp(const std::shared_ptr<BelCardImpp> &impp); 118 void _addLang(const std::shared_ptr<BelCardLang> &lang); 119 void _addSource(const std::shared_ptr<BelCardSource> &source); 120 void _addXML(const std::shared_ptr<BelCardXML> &xml); 121 void _addTimezone(const std::shared_ptr<BelCardTimezone> &tz); 122 void _addGeo(const std::shared_ptr<BelCardGeo> &geo); 123 void _addTitle(const std::shared_ptr<BelCardTitle> &title); 124 void _addRole(const std::shared_ptr<BelCardRole> &role); 125 void _addLogo(const std::shared_ptr<BelCardLogo> &logo); 126 void _addOrganization(const std::shared_ptr<BelCardOrganization> &org); 127 void _addMember(const std::shared_ptr<BelCardMember> &member); 128 void _addRelated(const std::shared_ptr<BelCardRelated> &related); 129 void _addCategories(const std::shared_ptr<BelCardCategories> &categories); 130 void _addNote(const std::shared_ptr<BelCardNote> ¬e); 131 void _addSound(const std::shared_ptr<BelCardSound> &sound); 132 void _addClientProductIdMap(const std::shared_ptr<BelCardClientProductIdMap> &clientpidmap); 133 void _addURL(const std::shared_ptr<BelCardURL> &url); 134 void _addKey(const std::shared_ptr<BelCardKey> &key); 135 void _addFBURL(const std::shared_ptr<BelCardFBURL> &fburl); 136 void _addCALADRURI(const std::shared_ptr<BelCardCALADRURI> &caladruri); 137 void _addCALURI(const std::shared_ptr<BelCardCALURI> &caluri); 138 void _addExtendedProperty(const std::shared_ptr<BelCardProperty> &property); 139 140 public: 141 BELCARD_PUBLIC static void setHandlerAndCollectors(belr::Parser<std::shared_ptr<BelCardGeneric>> *parser); 142 143 BELCARD_PUBLIC BelCard(); 144 BELCARD_PUBLIC void setSkipFieldValidation(bool skip); 145 BELCARD_PUBLIC bool getSkipFieldValidation(); 146 147 BELCARD_PUBLIC bool setKind(const std::shared_ptr<BelCardKind> &kind); 148 BELCARD_PUBLIC const std::shared_ptr<BelCardKind> &getKind() const; 149 150 BELCARD_PUBLIC bool setFullName(const std::shared_ptr<BelCardFullName> &fn); 151 BELCARD_PUBLIC const std::shared_ptr<BelCardFullName> &getFullName() const; 152 153 BELCARD_PUBLIC bool setName(const std::shared_ptr<BelCardName> &n); 154 BELCARD_PUBLIC const std::shared_ptr<BelCardName> &getName() const; 155 156 BELCARD_PUBLIC bool setBirthday(const std::shared_ptr<BelCardBirthday> &bday); 157 BELCARD_PUBLIC const std::shared_ptr<BelCardBirthday> &getBirthday() const; 158 159 BELCARD_PUBLIC bool setAnniversary(const std::shared_ptr<BelCardAnniversary> &anniversary); 160 BELCARD_PUBLIC const std::shared_ptr<BelCardAnniversary> &getAnniversary() const; 161 162 BELCARD_PUBLIC bool setGender(const std::shared_ptr<BelCardGender> &gender); 163 BELCARD_PUBLIC const std::shared_ptr<BelCardGender> &getGender() const; 164 165 BELCARD_PUBLIC bool setProductId(const std::shared_ptr<BelCardProductId> &pid); 166 BELCARD_PUBLIC const std::shared_ptr<BelCardProductId> &getProductId() const; 167 168 BELCARD_PUBLIC bool setRevision(const std::shared_ptr<BelCardRevision> &rev); 169 BELCARD_PUBLIC const std::shared_ptr<BelCardRevision> &getRevision() const; 170 171 BELCARD_PUBLIC bool setUniqueId(const std::shared_ptr<BelCardUniqueId> &uid); 172 BELCARD_PUBLIC const std::shared_ptr<BelCardUniqueId> &getUniqueId() const; 173 174 BELCARD_PUBLIC bool setBirthPlace(const std::shared_ptr<BelCardBirthPlace> &place); 175 BELCARD_PUBLIC const std::shared_ptr<BelCardBirthPlace> &getBirthPlace() const; 176 177 BELCARD_PUBLIC bool setDeathPlace(const std::shared_ptr<BelCardDeathPlace> &place); 178 BELCARD_PUBLIC const std::shared_ptr<BelCardDeathPlace> &getDeathPlace() const; 179 180 BELCARD_PUBLIC bool setDeathDate(const std::shared_ptr<BelCardDeathDate> &date); 181 BELCARD_PUBLIC const std::shared_ptr<BelCardDeathDate> &getDeathDate() const; 182 183 BELCARD_PUBLIC bool addNickname(const std::shared_ptr<BelCardNickname> &nickname); 184 BELCARD_PUBLIC void removeNickname(const std::shared_ptr<BelCardNickname> &nickname); 185 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardNickname>> &getNicknames() const; 186 187 BELCARD_PUBLIC bool addPhoto(const std::shared_ptr<BelCardPhoto> &photo); 188 BELCARD_PUBLIC void removePhoto(const std::shared_ptr<BelCardPhoto> &photo); 189 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardPhoto>> &getPhotos() const; 190 191 BELCARD_PUBLIC bool addAddress(const std::shared_ptr<BelCardAddress> &addr); 192 BELCARD_PUBLIC void removeAddress(const std::shared_ptr<BelCardAddress> &addr); 193 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardAddress>> &getAddresses() const; 194 195 BELCARD_PUBLIC bool addPhoneNumber(const std::shared_ptr<BelCardPhoneNumber> &tel); 196 BELCARD_PUBLIC void removePhoneNumber(const std::shared_ptr<BelCardPhoneNumber> &tel); 197 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardPhoneNumber>> &getPhoneNumbers() const; 198 199 BELCARD_PUBLIC bool addEmail(const std::shared_ptr<BelCardEmail> &email); 200 BELCARD_PUBLIC void removeEmail(const std::shared_ptr<BelCardEmail> &email); 201 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardEmail>> &getEmails() const; 202 203 BELCARD_PUBLIC bool addImpp(const std::shared_ptr<BelCardImpp> &impp); 204 BELCARD_PUBLIC void removeImpp(const std::shared_ptr<BelCardImpp> &impp); 205 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardImpp>> &getImpp() const; 206 207 BELCARD_PUBLIC bool addLang(const std::shared_ptr<BelCardLang> &lang); 208 BELCARD_PUBLIC void removeLang(const std::shared_ptr<BelCardLang> &lang); 209 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardLang>> &getLangs() const; 210 211 BELCARD_PUBLIC bool addSource(const std::shared_ptr<BelCardSource> &source); 212 BELCARD_PUBLIC void removeSource(const std::shared_ptr<BelCardSource> &source); 213 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardSource>> &getSource() const; 214 215 BELCARD_PUBLIC bool addXML(const std::shared_ptr<BelCardXML> &xml); 216 BELCARD_PUBLIC void removeXML(const std::shared_ptr<BelCardXML> &xml); 217 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardXML>> &getXML() const; 218 219 BELCARD_PUBLIC bool addTimezone(const std::shared_ptr<BelCardTimezone> &tz); 220 BELCARD_PUBLIC void removeTimezone(const std::shared_ptr<BelCardTimezone> &tz); 221 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardTimezone>> &getTimezones() const; 222 223 BELCARD_PUBLIC bool addGeo(const std::shared_ptr<BelCardGeo> &geo); 224 BELCARD_PUBLIC void removeGeo(const std::shared_ptr<BelCardGeo> &geo); 225 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardGeo>> &getGeos() const; 226 227 BELCARD_PUBLIC bool addTitle(const std::shared_ptr<BelCardTitle> &title); 228 BELCARD_PUBLIC void removeTitle(const std::shared_ptr<BelCardTitle> &title); 229 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardTitle>> &getTitles() const; 230 231 BELCARD_PUBLIC bool addRole(const std::shared_ptr<BelCardRole> &role); 232 BELCARD_PUBLIC void removeRole(const std::shared_ptr<BelCardRole> &role); 233 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardRole>> &getRoles() const; 234 235 BELCARD_PUBLIC bool addLogo(const std::shared_ptr<BelCardLogo> &logo); 236 BELCARD_PUBLIC void removeLogo(const std::shared_ptr<BelCardLogo> &logo); 237 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardLogo>> &getLogos() const; 238 239 BELCARD_PUBLIC bool addOrganization(const std::shared_ptr<BelCardOrganization> &org); 240 BELCARD_PUBLIC void removeOrganization(const std::shared_ptr<BelCardOrganization> &org); 241 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardOrganization>> &getOrganizations() const; 242 243 BELCARD_PUBLIC bool addMember(const std::shared_ptr<BelCardMember> &member); 244 BELCARD_PUBLIC void removeMember(const std::shared_ptr<BelCardMember> &member); 245 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardMember>> &getMembers() const; 246 247 BELCARD_PUBLIC bool addRelated(const std::shared_ptr<BelCardRelated> &related); 248 BELCARD_PUBLIC void removeRelated(const std::shared_ptr<BelCardRelated> &related); 249 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardRelated>> &getRelated() const; 250 251 BELCARD_PUBLIC bool addCategories(const std::shared_ptr<BelCardCategories> &categories); 252 BELCARD_PUBLIC void removeCategories(const std::shared_ptr<BelCardCategories> &categories); 253 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardCategories>> &getCategories() const; 254 255 BELCARD_PUBLIC bool addNote(const std::shared_ptr<BelCardNote> ¬e); 256 BELCARD_PUBLIC void removeNote(const std::shared_ptr<BelCardNote> ¬e); 257 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardNote>> &getNotes() const; 258 259 BELCARD_PUBLIC bool addSound(const std::shared_ptr<BelCardSound> &sound); 260 BELCARD_PUBLIC void removeSound(const std::shared_ptr<BelCardSound> &sound); 261 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardSound>> &getSounds() const; 262 263 BELCARD_PUBLIC bool addClientProductIdMap(const std::shared_ptr<BelCardClientProductIdMap> &clientpidmap); 264 BELCARD_PUBLIC void removeClientProductIdMap(const std::shared_ptr<BelCardClientProductIdMap> &clientpidmap); 265 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardClientProductIdMap>> &getClientProductIdMaps() const; 266 267 BELCARD_PUBLIC bool addURL(const std::shared_ptr<BelCardURL> &url); 268 BELCARD_PUBLIC void removeURL(const std::shared_ptr<BelCardURL> &url); 269 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardURL>> &getURLs() const; 270 271 BELCARD_PUBLIC bool addKey(const std::shared_ptr<BelCardKey> &key); 272 BELCARD_PUBLIC void removeKey(const std::shared_ptr<BelCardKey> &key); 273 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardKey>> &getKeys() const; 274 275 BELCARD_PUBLIC bool addFBURL(const std::shared_ptr<BelCardFBURL> &fburl); 276 BELCARD_PUBLIC void removeFBURL(const std::shared_ptr<BelCardFBURL> &fburl); 277 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardFBURL>> &getFBURLs() const; 278 279 BELCARD_PUBLIC bool addCALADRURI(const std::shared_ptr<BelCardCALADRURI> &caladruri); 280 BELCARD_PUBLIC void removeCALADRURI(const std::shared_ptr<BelCardCALADRURI> &caladruri); 281 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardCALADRURI>> &getCALADRURIs() const; 282 283 BELCARD_PUBLIC bool addCALURI(const std::shared_ptr<BelCardCALURI> &caluri); 284 BELCARD_PUBLIC void removeCALURI(const std::shared_ptr<BelCardCALURI> &caluri); 285 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardCALURI>> &getCALURIs() const; 286 287 BELCARD_PUBLIC bool addExtendedProperty(const std::shared_ptr<BelCardProperty> &property); 288 BELCARD_PUBLIC void removeExtendedProperty(const std::shared_ptr<BelCardProperty> &property); 289 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardProperty>> &getExtendedProperties() const; 290 291 BELCARD_PUBLIC void addProperty(const std::shared_ptr<BelCardProperty> &property); 292 BELCARD_PUBLIC void removeProperty(const std::shared_ptr<BelCardProperty> &property); 293 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardProperty>> &getProperties() const; 294 295 BELCARD_PUBLIC std::string& toFoldedString(); 296 BELCARD_PUBLIC bool assertRFCCompliance() const; 297 298 BELCARD_PUBLIC virtual void serialize(std::ostream &output) const; 299 }; 300 301 class BelCardList : public BelCardGeneric { 302 private: 303 std::list<std::shared_ptr<BelCard>> _vCards; 304 305 public: 306 BELCARD_PUBLIC static void setHandlerAndCollectors(belr::Parser<std::shared_ptr<BelCardGeneric>> *parser); 307 308 BELCARD_PUBLIC BelCardList(); 309 310 BELCARD_PUBLIC void addCard(const std::shared_ptr<BelCard> &vcard); 311 BELCARD_PUBLIC const std::list<std::shared_ptr<BelCard>> &getCards() const; 312 313 BELCARD_PUBLIC void serialize(std::ostream &output) const; 314 }; 315 } 316 317 #endif 318