1 // carddav.h - CardDAV Object header file.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #ifndef CALDAV_CALDAV_H
20 #define CALDAV_CALDAV_H
25 #include <libxml/parser.h>
26 #include <libxml/tree.h>
27 #include <curl/curl.h>
28 #if defined(__WIN32__)
32 #include "../vcard/vcard.h"
33 #include "../actmgr/frmActivityMgr.h"
34 #include "../common/sslcertstructs.h"
37 unsigned int DataFlag:2;
41 struct ContactListData{
43 std::map<wxString,FileSyncData> ListData;
46 struct UploadDataStruc{
52 /*struct CertificateData{
53 std::multimap<wxString,wxString> CertificateData;
58 struct CertificateCollection{
59 std::map<int,CertificateData> Certificates;
60 std::map<int,int> ParentCerticiate;
62 std::map<int,int> CertErrors;
65 //size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, FILE *userdata);
67 size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *userdata);
68 int ProgressFunc(void *clientdata, double TTDown, double NDown, double TTUp, double NUp);
69 size_t UploadReadFunc(void *ptr, size_t size, size_t nmemb, void *userdata);
76 bool SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL);
77 bool SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL, wxString SvrPrefix, wxString SvrAccount);
82 bool HasValidResponse();
84 wxString GetResponseData();
85 void AllowSelfSignTest(bool AllowSelfSignIn);
89 void SetupData(wxString Method, wxString FilenameLocation, wxString UploadData);
90 void ProcessDataThread();
91 void SetUploadMode(bool IncMode);
93 bool SetupResultBools(bool *SvrResult, bool *SvrMonitor);
94 int ProgressFuncProc(void *clientdata, double TTUp, double NUp, double TTDown, double NDown);
95 void SetupVariables(std::map<int, int> *actlist, int actindex);
96 wxString GetETagData();
97 void GetServerETagValue();
98 void GetServerETagValueThread();
99 void GetServerContactData();
100 wxString GetPageData();
101 void SetEditMode(bool EditModeInc);
102 ContactListData GetContactList(wxString SyncTokenInc);
103 void SetServerFilename(wxString Filename);
105 static int GetHTTPCode();
106 wxString GetErrorBuffer();
107 wxString GetDefaultAddressBookURL();
108 void GetSSLResults();
109 SSLCertCollection GetCertificateData();
110 static SSLCertCollection BuildSSLCollection(CURL *conn);
111 wxString ETagValueResult();
112 wxString GetErrorMessage();
113 static size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *stream);
114 #if defined(__APPLE__) || defined(__WIN32__)
115 static CURL* GetConnectionObject();
116 static void SetConnectionObject(CURL *ConnectionObject);
119 #if defined(__APPLE__)
120 SecTrustRef GetTrustObject();
121 #elif defined(__WIN32__)
122 PCCERT_CONTEXT GetCertificateContextPointer();
123 CERT_CONTEXT GetCertificateContext();
126 // SSL Verification tests when connecting.
128 static CURLcode SSLVerifyTest();
129 static SSLCertCollection GetSSLVerifyResults();
131 //size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, FILE *userdata);
133 #if defined(__APPLE__) || defined(__WIN32__)
134 static CURL* ConnectionObject;
136 #if defined(__APPLE__)
137 static SSLContext *SSLContextPointer;
138 static SecTrustRef SecTrustObject;
139 #elif defined(__WIN32__)
140 static PCCERT_CONTEXT CertificateData;
142 static wxString ServerAddress;
143 static int ServerPort;
144 static wxString ServerUser;
145 static wxString ServerPass;
146 static wxString ServerPrefix;
147 static wxString ServerAccount;
148 static bool ServerSSL;
149 static bool *ServerResult;
150 static bool *ServerMonitor;
151 static bool SSLStatus;
152 static bool SSLVerified;
153 static bool ValidResponse;
154 static bool AuthPassed;
155 static bool HasCalDAVSupport;
156 static bool AbortConnection;
157 static wxString ServerResponse;
158 static wxString ServerMethod;
159 static wxString ServerFilenameLocation;
160 static wxString ServerUploadData;
161 static wxString ETagData;
162 static wxString ETagResult;
163 static bool UploadMode;
164 static bool EditMode;
165 static long ItemIndex;
166 static std::map<int, int> *ActivityListPtr;
167 //frmActivityMgr *ActMgrPtr;
168 static char curlerrbuffer[CURL_ERROR_SIZE];
169 static SSLCertCollection SSLCertCol;
170 static wxString ErrorMessage;
171 static wxString ErrorBufferMessage;
172 static bool AllowSelfSign;
174 static int SSLErrorCode;
175 static int ConnectionErrorCode;
176 static wxString PageHeader;
177 static wxString PageData;
178 static CURLcode claconncode;
179 static int HTTPErrorCode;
180 static SSLCertCollection VerifyCertCollection;