Documentation updates: git, tarball, bugs, contact
[barry/pauldeden.git] / opensync-plugin / src / vcard.h
blob3263d2f7cdffbfff9e6176986ffdb514d9fd399d
1 ///
2 /// \file vcard.h
3 /// Conversion routines for vcards
4 ///
6 /*
7 Copyright (C) 2006-2008, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_SYNC_VCARD_H__
23 #define __BARRY_SYNC_VCARD_H__
25 #include <barry/barry.h>
26 #include <stdint.h>
27 #include <string>
28 #include "vbase.h"
29 #include "vformat.h"
31 // forward declarations
32 class BarryEnvironment;
36 // vCard
38 /// Class for converting between RFC 2425/2426 vCard data format,
39 /// and the Barry::Contact class.
40 ///
41 class vCard : public vBase
43 // data to pass to external requests
44 char *m_gCardData; // dynamic memory returned by vformat()... can
45 // be used directly by the plugin, without
46 // overmuch allocation and freeing (see Extract())
47 std::string m_vCardData;// copy of m_gCardData, for C++ use
48 Barry::Contact m_BarryContact;
50 protected:
51 void AddAddress(const char *rfc_type, const Barry::PostalAddress &addr);
52 void AddCategories(const Barry::CategoryList &categories);
53 void AddPhoneCond(const char *rfc_type, const std::string &phone);
55 void ParseAddress(vAttr &adr, Barry::PostalAddress &address);
56 void ParseCategories(vAttr &cat, Barry::CategoryList &cats);
58 public:
59 vCard();
60 ~vCard();
62 const std::string& ToVCard(const Barry::Contact &con);
63 const Barry::Contact& ToBarry(const char *vcal, uint32_t RecordId);
65 const std::string& GetVCard() const { return m_vCardData; }
66 const Barry::Contact& GetBarryContact() const { return m_BarryContact; }
68 char* ExtractVCard();
70 void Clear();
74 class VCardConverter
76 char *m_Data;
77 Barry::Contact m_Contact;
78 uint32_t m_RecordId;
80 public:
81 VCardConverter();
82 explicit VCardConverter(uint32_t newRecordId);
83 ~VCardConverter();
85 // Transfers ownership of m_Data to the caller
86 char* ExtractData();
88 // Parses vevent data
89 bool ParseData(const char *data);
91 // Barry storage operator
92 void operator()(const Barry::Contact &rec);
94 // Barry builder operator
95 bool operator()(Barry::Contact &rec, unsigned int dbId);
97 // Handles calling of the Barry::Controller to fetch a specific
98 // record, indicated by index (into the RecordStateTable).
99 // Returns a g_malloc'd string of data containing the vevent20
100 // data. It is the responsibility of the caller to free it.
101 // This is intended to be passed into the GetChanges() function.
102 static char* GetRecordData(BarryEnvironment *env, unsigned int dbId,
103 Barry::RecordStateTable::IndexType index);
105 // Handles either adding or overwriting a calendar record,
106 // given vevent20 data in data, and the proper environmebnt,
107 // dbId, StateIndex. Set add to true if adding.
108 static bool CommitRecordData(BarryEnvironment *env, unsigned int dbId,
109 Barry::RecordStateTable::IndexType StateIndex, uint32_t recordId,
110 const char *data, bool add, std::string &errmsg);
114 #endif