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__)
31 #include <winapifamily.h>
34 #include <cryptuiapi.h>
37 #include "../vcard/vcard.h"
38 #include "../actmgr/frmActivityMgr.h"
39 #include "../common/sslcertstructs.h"
42 unsigned int DataFlag:2;
46 struct ContactListData{
48 std::map<wxString,FileSyncData> ListData;
51 struct UploadDataStruc{
57 /*struct CertificateData{
58 std::multimap<wxString,wxString> CertificateData;
63 struct CertificateCollection{
64 std::map<int,CertificateData> Certificates;
65 std::map<int,int> ParentCerticiate;
67 std::map<int,int> CertErrors;
70 //size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, FILE *userdata);
72 size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *userdata);
73 int ProgressFunc(void *clientdata, double TTDown, double NDown, double TTUp, double NUp);
74 size_t UploadReadFunc(void *ptr, size_t size, size_t nmemb, void *userdata);
81 bool SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL);
82 bool SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL, wxString SvrPrefix, wxString SvrAccount);
87 bool HasValidResponse();
89 wxString GetResponseData();
90 void AllowSelfSignTest(bool AllowSelfSignIn);
94 void SetupData(wxString Method, wxString FilenameLocation, wxString UploadData);
95 void ProcessDataThread();
96 void SetUploadMode(bool IncMode);
98 bool SetupResultBools(bool *SvrResult, bool *SvrMonitor);
99 int ProgressFuncProc(void *clientdata, double TTUp, double NUp, double TTDown, double NDown);
100 void SetupVariables(std::map<int, int> *actlist, int actindex);
101 wxString GetETagData();
102 void GetServerETagValue();
103 void GetServerETagValueThread();
104 void GetServerContactData();
105 wxString GetPageData();
106 void SetEditMode(bool EditModeInc);
107 ContactListData GetContactList(wxString SyncTokenInc);
108 void SetServerFilename(wxString Filename);
110 static int GetHTTPCode();
111 wxString GetErrorBuffer();
112 wxString GetDefaultAddressBookURL();
113 void GetSSLResults();
114 SSLCertCollection GetCertificateData();
115 static SSLCertCollection BuildSSLCollection(CURL *conn);
116 wxString ETagValueResult();
117 wxString GetErrorMessage();
118 static size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *stream);
119 #if defined(__APPLE__) || defined(__WIN32__)
120 static CURL* GetConnectionObject();
121 static void SetConnectionObject(CURL *ConnectionObject);
124 #if defined(__APPLE__)
125 SecTrustRef GetTrustObject();
126 #elif defined(__WIN32__)
127 PCCERT_CONTEXT GetCertificateContextPointer();
128 CERT_CONTEXT GetCertificateContext();
131 // SSL Verification tests when connecting.
133 static CURLcode SSLVerifyTest();
134 static SSLCertCollection GetSSLVerifyResults();
136 //size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, FILE *userdata);
138 #if defined(__APPLE__) || defined(__WIN32__)
139 static CURL* ConnectionObject;
141 #if defined(__APPLE__)
142 static SSLContext *SSLContextPointer;
143 static SecTrustRef SecTrustObject;
144 #elif defined(__WIN32__)
145 static PCCERT_CONTEXT CertificateData;
147 static wxString ServerAddress;
148 static int ServerPort;
149 static wxString ServerUser;
150 static wxString ServerPass;
151 static wxString ServerPrefix;
152 static wxString ServerAccount;
153 static bool ServerSSL;
154 static bool *ServerResult;
155 static bool *ServerMonitor;
156 static bool SSLStatus;
157 static bool SSLVerified;
158 static bool ValidResponse;
159 static bool AuthPassed;
160 static bool HasCalDAVSupport;
161 static bool AbortConnection;
162 static wxString ServerResponse;
163 static wxString ServerMethod;
164 static wxString ServerFilenameLocation;
165 static wxString ServerUploadData;
166 static wxString ETagData;
167 static wxString ETagResult;
168 static bool UploadMode;
169 static bool EditMode;
170 static long ItemIndex;
171 static std::map<int, int> *ActivityListPtr;
172 //frmActivityMgr *ActMgrPtr;
173 static char curlerrbuffer[CURL_ERROR_SIZE];
174 static SSLCertCollection SSLCertCol;
175 static wxString ErrorMessage;
176 static wxString ErrorBufferMessage;
177 static bool AllowSelfSign;
179 static int SSLErrorCode;
180 static int ConnectionErrorCode;
181 static wxString PageHeader;
182 static wxString PageData;
183 static CURLcode claconncode;
184 static int HTTPErrorCode;
185 static SSLCertCollection VerifyCertCollection;