belcard.hpp 16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
	belcard.hpp
	Copyright (C) 2015  Belledonne Communications SARL

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

Sylvain Berfini's avatar
Sylvain Berfini committed
19 20 21
#ifndef belcard_hpp
#define belcard_hpp

22
#include "belcard_utils.hpp"
Sylvain Berfini's avatar
Sylvain Berfini committed
23
#include "belcard_generic.hpp"
Sylvain Berfini's avatar
Sylvain Berfini committed
24 25
#include "belcard_params.hpp"
#include "belcard_property.hpp"
26
#include "belcard_general.hpp"
Sylvain Berfini's avatar
Sylvain Berfini committed
27
#include "belcard_identification.hpp"
28
#include "belcard_addressing.hpp"
Sylvain Berfini's avatar
Sylvain Berfini committed
29
#include "belcard_communication.hpp"
30 31 32 33 34
#include "belcard_geographical.hpp"
#include "belcard_organizational.hpp"
#include "belcard_explanatory.hpp"
#include "belcard_security.hpp"
#include "belcard_calendar.hpp"
35
#include "belcard_rfc6474.hpp"
Sylvain Berfini's avatar
Sylvain Berfini committed
36

37 38
#include "bctoolbox/logging.h"

Sylvain Berfini's avatar
Sylvain Berfini committed
39 40 41
#include <string>
#include <list>

42
namespace belcard {
43

Sylvain Berfini's avatar
Sylvain Berfini committed
44 45
	class BelCard : public BelCardGeneric {
	private:
Sylvain Berfini's avatar
Sylvain Berfini committed
46
		std::string _folded_string;
47
		bool _skipFieldValidation = false;
Sylvain Berfini's avatar
Sylvain Berfini committed
48
		
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
		std::shared_ptr<BelCardKind> _kind;
		std::shared_ptr<BelCardFullName> _fn;
		std::shared_ptr<BelCardName> _n;
		std::shared_ptr<BelCardBirthday> _bday;
		std::shared_ptr<BelCardAnniversary> _anniversary;
		std::shared_ptr<BelCardGender> _gender;
		std::shared_ptr<BelCardProductId> _pid;
		std::shared_ptr<BelCardRevision> _rev;
		std::shared_ptr<BelCardUniqueId> _uid;
		std::shared_ptr<BelCardBirthPlace> _bplace;
		std::shared_ptr<BelCardDeathPlace> _dplace;
		std::shared_ptr<BelCardDeathDate> _ddate;
		std::list<std::shared_ptr<BelCardNickname>> _nicknames;
		std::list<std::shared_ptr<BelCardPhoto>> _photos;
		std::list<std::shared_ptr<BelCardAddress>> _addr;
		std::list<std::shared_ptr<BelCardPhoneNumber>> _tel;
		std::list<std::shared_ptr<BelCardEmail>> _emails;
		std::list<std::shared_ptr<BelCardImpp>> _impp;
		std::list<std::shared_ptr<BelCardLang>> _langs;
		std::list<std::shared_ptr<BelCardSource>> _sources;
		std::list<std::shared_ptr<BelCardXML>> _xml;
		std::list<std::shared_ptr<BelCardTimezone>> _timezones;
		std::list<std::shared_ptr<BelCardGeo>> _geos;
		std::list<std::shared_ptr<BelCardTitle>> _titles;
		std::list<std::shared_ptr<BelCardRole>> _roles;
		std::list<std::shared_ptr<BelCardLogo>> _logos;
		std::list<std::shared_ptr<BelCardOrganization>> _organizations;
		std::list<std::shared_ptr<BelCardMember>> _members;
		std::list<std::shared_ptr<BelCardRelated>> _related;
		std::list<std::shared_ptr<BelCardCategories>> _categories;
		std::list<std::shared_ptr<BelCardNote>> _notes;
		std::list<std::shared_ptr<BelCardSound>> _sounds;
		std::list<std::shared_ptr<BelCardClientProductIdMap>> _clientpidmaps;
		std::list<std::shared_ptr<BelCardURL>> _urls;
		std::list<std::shared_ptr<BelCardKey>> _keys;
		std::list<std::shared_ptr<BelCardFBURL>> _fburls;
		std::list<std::shared_ptr<BelCardCALADRURI>> _caladruris;
		std::list<std::shared_ptr<BelCardCALURI>> _caluris;
		std::list<std::shared_ptr<BelCardProperty>> _extended_properties;
		std::list<std::shared_ptr<BelCardProperty>> _properties;
Sylvain Berfini's avatar
Sylvain Berfini committed
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
		void _setKind(const std::shared_ptr<BelCardKind> &kind);
		void _setFullName(const std::shared_ptr<BelCardFullName> &fn);
		void _setName(const std::shared_ptr<BelCardName> &n);
		void _setBirthday(const std::shared_ptr<BelCardBirthday> &bday);
		void _setAnniversary(const std::shared_ptr<BelCardAnniversary> &anniversary);
		void _setGender(const std::shared_ptr<BelCardGender> &gender);
		void _setProductId(const std::shared_ptr<BelCardProductId> &pid);
		void _setRevision(const std::shared_ptr<BelCardRevision> &rev);
		void _setUniqueId(const std::shared_ptr<BelCardUniqueId> &uid);
		void _setBirthPlace(const std::shared_ptr<BelCardBirthPlace> &place);
		void _setDeathPlace(const std::shared_ptr<BelCardDeathPlace> &place);
		void _setDeathDate(const std::shared_ptr<BelCardDeathDate> &date);
		void _addNickname(const std::shared_ptr<BelCardNickname> &nickname);
		void _addPhoto(const std::shared_ptr<BelCardPhoto> &photo);
		void _addAddress(const std::shared_ptr<BelCardAddress> &addr);
		void _addPhoneNumber(const std::shared_ptr<BelCardPhoneNumber> &tel);
		void _addEmail(const std::shared_ptr<BelCardEmail> &email);
		void _addImpp(const std::shared_ptr<BelCardImpp> &impp);
		void _addLang(const std::shared_ptr<BelCardLang> &lang);
		void _addSource(const std::shared_ptr<BelCardSource> &source);
		void _addXML(const std::shared_ptr<BelCardXML> &xml);
		void _addTimezone(const std::shared_ptr<BelCardTimezone> &tz);
		void _addGeo(const std::shared_ptr<BelCardGeo> &geo);
		void _addTitle(const std::shared_ptr<BelCardTitle> &title);
		void _addRole(const std::shared_ptr<BelCardRole> &role);
		void _addLogo(const std::shared_ptr<BelCardLogo> &logo);
		void _addOrganization(const std::shared_ptr<BelCardOrganization> &org);
		void _addMember(const std::shared_ptr<BelCardMember> &member);
		void _addRelated(const std::shared_ptr<BelCardRelated> &related);
		void _addCategories(const std::shared_ptr<BelCardCategories> &categories);
		void _addNote(const std::shared_ptr<BelCardNote> &note);
		void _addSound(const std::shared_ptr<BelCardSound> &sound);
		void _addClientProductIdMap(const std::shared_ptr<BelCardClientProductIdMap> &clientpidmap);
		void _addURL(const std::shared_ptr<BelCardURL> &url);
		void _addKey(const std::shared_ptr<BelCardKey> &key);
		void _addFBURL(const std::shared_ptr<BelCardFBURL> &fburl);
		void _addCALADRURI(const std::shared_ptr<BelCardCALADRURI> &caladruri);
		void _addCALURI(const std::shared_ptr<BelCardCALURI> &caluri);
		void _addExtendedProperty(const std::shared_ptr<BelCardProperty> &property);
139
		 
Sylvain Berfini's avatar
Sylvain Berfini committed
140
	public:
141
		BELCARD_PUBLIC static void setHandlerAndCollectors(belr::Parser<std::shared_ptr<BelCardGeneric>> *parser);
Sylvain Berfini's avatar
Sylvain Berfini committed
142
		
143
		BELCARD_PUBLIC BelCard();
144 145
		BELCARD_PUBLIC void setSkipFieldValidation(bool skip);
		BELCARD_PUBLIC bool getSkipFieldValidation();
146
		
147 148
		BELCARD_PUBLIC bool setKind(const std::shared_ptr<BelCardKind> &kind);
		BELCARD_PUBLIC const std::shared_ptr<BelCardKind> &getKind() const;
Sylvain Berfini's avatar
Sylvain Berfini committed
149
		
150 151
		BELCARD_PUBLIC bool setFullName(const std::shared_ptr<BelCardFullName> &fn);
		BELCARD_PUBLIC const std::shared_ptr<BelCardFullName> &getFullName() const;
152
		
153 154
		BELCARD_PUBLIC bool setName(const std::shared_ptr<BelCardName> &n);
		BELCARD_PUBLIC const std::shared_ptr<BelCardName> &getName() const;
Sylvain Berfini's avatar
Sylvain Berfini committed
155
		
156 157
		BELCARD_PUBLIC bool setBirthday(const std::shared_ptr<BelCardBirthday> &bday);
		BELCARD_PUBLIC const std::shared_ptr<BelCardBirthday> &getBirthday() const;
158
		
159 160
		BELCARD_PUBLIC bool setAnniversary(const std::shared_ptr<BelCardAnniversary> &anniversary);
		BELCARD_PUBLIC const std::shared_ptr<BelCardAnniversary> &getAnniversary() const;
161
		
162 163
		BELCARD_PUBLIC bool setGender(const std::shared_ptr<BelCardGender> &gender);
		BELCARD_PUBLIC const std::shared_ptr<BelCardGender> &getGender() const;
164
		
165 166
		BELCARD_PUBLIC bool setProductId(const std::shared_ptr<BelCardProductId> &pid);
		BELCARD_PUBLIC const std::shared_ptr<BelCardProductId> &getProductId() const;
167
		
168 169
		BELCARD_PUBLIC bool setRevision(const std::shared_ptr<BelCardRevision> &rev);
		BELCARD_PUBLIC const std::shared_ptr<BelCardRevision> &getRevision() const;
170
		
171 172
		BELCARD_PUBLIC bool setUniqueId(const std::shared_ptr<BelCardUniqueId> &uid);
		BELCARD_PUBLIC const std::shared_ptr<BelCardUniqueId> &getUniqueId() const;
173
		
174 175
		BELCARD_PUBLIC bool setBirthPlace(const std::shared_ptr<BelCardBirthPlace> &place);
		BELCARD_PUBLIC const std::shared_ptr<BelCardBirthPlace> &getBirthPlace() const;
176
		
177 178
		BELCARD_PUBLIC bool setDeathPlace(const std::shared_ptr<BelCardDeathPlace> &place);
		BELCARD_PUBLIC const std::shared_ptr<BelCardDeathPlace> &getDeathPlace() const;
179
		
180 181
		BELCARD_PUBLIC bool setDeathDate(const std::shared_ptr<BelCardDeathDate> &date);
		BELCARD_PUBLIC const std::shared_ptr<BelCardDeathDate> &getDeathDate() const;
182
		
183 184 185
		BELCARD_PUBLIC bool addNickname(const std::shared_ptr<BelCardNickname> &nickname);
		BELCARD_PUBLIC void removeNickname(const std::shared_ptr<BelCardNickname> &nickname);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardNickname>> &getNicknames() const;
186
		
187 188 189
		BELCARD_PUBLIC bool addPhoto(const std::shared_ptr<BelCardPhoto> &photo);
		BELCARD_PUBLIC void removePhoto(const std::shared_ptr<BelCardPhoto> &photo);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardPhoto>> &getPhotos() const;
190
		
191 192 193
		BELCARD_PUBLIC bool addAddress(const std::shared_ptr<BelCardAddress> &addr);
		BELCARD_PUBLIC void removeAddress(const std::shared_ptr<BelCardAddress> &addr);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardAddress>> &getAddresses() const;
194
		
195 196 197
		BELCARD_PUBLIC bool addPhoneNumber(const std::shared_ptr<BelCardPhoneNumber> &tel);
		BELCARD_PUBLIC void removePhoneNumber(const std::shared_ptr<BelCardPhoneNumber> &tel);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardPhoneNumber>> &getPhoneNumbers() const;
Sylvain Berfini's avatar
Sylvain Berfini committed
198
		
199 200 201
		BELCARD_PUBLIC bool addEmail(const std::shared_ptr<BelCardEmail> &email);
		BELCARD_PUBLIC void removeEmail(const std::shared_ptr<BelCardEmail> &email);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardEmail>> &getEmails() const;
202
		
203 204 205
		BELCARD_PUBLIC bool addImpp(const std::shared_ptr<BelCardImpp> &impp);
		BELCARD_PUBLIC void removeImpp(const std::shared_ptr<BelCardImpp> &impp);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardImpp>> &getImpp() const;
206
		
207 208 209
		BELCARD_PUBLIC bool addLang(const std::shared_ptr<BelCardLang> &lang);
		BELCARD_PUBLIC void removeLang(const std::shared_ptr<BelCardLang> &lang);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardLang>> &getLangs() const;
210
		
211 212 213
		BELCARD_PUBLIC bool addSource(const std::shared_ptr<BelCardSource> &source);
		BELCARD_PUBLIC void removeSource(const std::shared_ptr<BelCardSource> &source);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardSource>> &getSource() const;
214
		
215 216 217
		BELCARD_PUBLIC bool addXML(const std::shared_ptr<BelCardXML> &xml);
		BELCARD_PUBLIC void removeXML(const std::shared_ptr<BelCardXML> &xml);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardXML>> &getXML() const;
218
	
219 220 221
		BELCARD_PUBLIC bool addTimezone(const std::shared_ptr<BelCardTimezone> &tz);
		BELCARD_PUBLIC void removeTimezone(const std::shared_ptr<BelCardTimezone> &tz);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardTimezone>> &getTimezones() const;
222
		
223 224 225
		BELCARD_PUBLIC bool addGeo(const std::shared_ptr<BelCardGeo> &geo);
		BELCARD_PUBLIC void removeGeo(const std::shared_ptr<BelCardGeo> &geo);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardGeo>> &getGeos() const;
226
		
227 228 229
		BELCARD_PUBLIC bool addTitle(const std::shared_ptr<BelCardTitle> &title);
		BELCARD_PUBLIC void removeTitle(const std::shared_ptr<BelCardTitle> &title);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardTitle>> &getTitles() const;
230
		
231 232 233
		BELCARD_PUBLIC bool addRole(const std::shared_ptr<BelCardRole> &role);
		BELCARD_PUBLIC void removeRole(const std::shared_ptr<BelCardRole> &role);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardRole>> &getRoles() const;
234
		
235 236 237
		BELCARD_PUBLIC bool addLogo(const std::shared_ptr<BelCardLogo> &logo);
		BELCARD_PUBLIC void removeLogo(const std::shared_ptr<BelCardLogo> &logo);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardLogo>> &getLogos() const;
238
		
239 240 241
		BELCARD_PUBLIC bool addOrganization(const std::shared_ptr<BelCardOrganization> &org);
		BELCARD_PUBLIC void removeOrganization(const std::shared_ptr<BelCardOrganization> &org);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardOrganization>> &getOrganizations() const;
242
		
243 244 245
		BELCARD_PUBLIC bool addMember(const std::shared_ptr<BelCardMember> &member);
		BELCARD_PUBLIC void removeMember(const std::shared_ptr<BelCardMember> &member);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardMember>> &getMembers() const;
246
		
247 248 249
		BELCARD_PUBLIC bool addRelated(const std::shared_ptr<BelCardRelated> &related);
		BELCARD_PUBLIC void removeRelated(const std::shared_ptr<BelCardRelated> &related);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardRelated>> &getRelated() const;
250
		
251 252 253
		BELCARD_PUBLIC bool addCategories(const std::shared_ptr<BelCardCategories> &categories);
		BELCARD_PUBLIC void removeCategories(const std::shared_ptr<BelCardCategories> &categories);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardCategories>> &getCategories() const;
254
		
255 256 257
		BELCARD_PUBLIC bool addNote(const std::shared_ptr<BelCardNote> &note);
		BELCARD_PUBLIC void removeNote(const std::shared_ptr<BelCardNote> &note);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardNote>> &getNotes() const;
258
		
259 260 261
		BELCARD_PUBLIC bool addSound(const std::shared_ptr<BelCardSound> &sound);
		BELCARD_PUBLIC void removeSound(const std::shared_ptr<BelCardSound> &sound);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardSound>> &getSounds() const;
262
		
263 264 265
		BELCARD_PUBLIC bool addClientProductIdMap(const std::shared_ptr<BelCardClientProductIdMap> &clientpidmap);
		BELCARD_PUBLIC void removeClientProductIdMap(const std::shared_ptr<BelCardClientProductIdMap> &clientpidmap);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardClientProductIdMap>> &getClientProductIdMaps() const;
266
		
267 268 269
		BELCARD_PUBLIC bool addURL(const std::shared_ptr<BelCardURL> &url);
		BELCARD_PUBLIC void removeURL(const std::shared_ptr<BelCardURL> &url);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardURL>> &getURLs() const;
270
		
271 272 273
		BELCARD_PUBLIC bool addKey(const std::shared_ptr<BelCardKey> &key);
		BELCARD_PUBLIC void removeKey(const std::shared_ptr<BelCardKey> &key);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardKey>> &getKeys() const;
274
		
275 276 277
		BELCARD_PUBLIC bool addFBURL(const std::shared_ptr<BelCardFBURL> &fburl);
		BELCARD_PUBLIC void removeFBURL(const std::shared_ptr<BelCardFBURL> &fburl);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardFBURL>> &getFBURLs() const;
278
		
279 280 281
		BELCARD_PUBLIC bool addCALADRURI(const std::shared_ptr<BelCardCALADRURI> &caladruri);
		BELCARD_PUBLIC void removeCALADRURI(const std::shared_ptr<BelCardCALADRURI> &caladruri);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardCALADRURI>> &getCALADRURIs() const;
282
		
283 284 285
		BELCARD_PUBLIC bool addCALURI(const std::shared_ptr<BelCardCALURI> &caluri);
		BELCARD_PUBLIC void removeCALURI(const std::shared_ptr<BelCardCALURI> &caluri);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardCALURI>> &getCALURIs() const;
286
		
287 288 289
		BELCARD_PUBLIC bool addExtendedProperty(const std::shared_ptr<BelCardProperty> &property);
		BELCARD_PUBLIC void removeExtendedProperty(const std::shared_ptr<BelCardProperty> &property);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCardProperty>> &getExtendedProperties() const;
290
		
291 292 293
		BELCARD_PUBLIC void addProperty(const std::shared_ptr<BelCardProperty> &property);
		BELCARD_PUBLIC void removeProperty(const std::shared_ptr<BelCardProperty> &property);
		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 302
	
	class BelCardList : public BelCardGeneric {
	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 311
		BELCARD_PUBLIC void addCard(const std::shared_ptr<BelCard> &vcard);
		BELCARD_PUBLIC const std::list<std::shared_ptr<BelCard>> &getCards() const;
312
		
313
		BELCARD_PUBLIC void serialize(std::ostream &output) const;
314
	};
Sylvain Berfini's avatar
Sylvain Berfini committed
315 316
}

317
#endif