Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Win32 Support: Add basic SSL verification.
[xestiaab/.git] / source / carddav / carddav.h
1 // carddav.h - CardDAV Object header file.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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
22 #include <iostream>
23 #include <map>
24 #include <wx/wx.h>
25 #include <libxml/parser.h>
26 #include <libxml/tree.h>
27 #include <curl/curl.h>
28 #if defined(__WIN32__)
29 #include <security.h>
30 #include <schannel.h>
31 #endif
32 #include "../vcard/vcard.h"
33 #include "../actmgr/frmActivityMgr.h"
34 #include "../common/sslcertstructs.h"
36 struct FileSyncData{
37         unsigned int DataFlag:2;
38         wxString ETagData;
39 };
41 struct ContactListData{
42         wxString SyncToken;
43         std::map<wxString,FileSyncData> ListData;
44 };
46 struct UploadDataStruc{
47         wxString *readptr;
48         long sizeleft;
49         int seek = 0;
50 };
52 /*struct CertificateData{
53         std::multimap<wxString,wxString> CertificateData;
54         bool CertValid;
55         int CertError;
56 };
58 struct CertificateCollection{
59         std::map<int,CertificateData> Certificates;
60         std::map<int,int> ParentCerticiate;
61         bool AllCertsValid;
62         std::map<int,int> CertErrors;
63 };*/
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);
71 class CardDAV
72 {
73         public:
74                 CardDAV();
75                 ~CardDAV();
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);
78                 bool CanDoCardDAV();
79                 bool CanDoSSL();
80                 bool SSLVerify();
81                 bool AbleToLogin();
82                 bool HasValidResponse();
83                 bool IsSelfSigned();
84                 wxString GetResponseData();
85                 void AllowSelfSignTest(bool AllowSelfSignIn);           
86                 bool Connect();
87                 bool ConnectThread();
88                 void ProcessData();
89                 void SetupData(wxString Method, wxString FilenameLocation, wxString UploadData);
90                 void ProcessDataThread();
91                 void SetUploadMode(bool IncMode);
92                 void Abort();
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);
104                 int GetResultCode();
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);
117 #endif
119 #if defined(__APPLE__)
120                 SecTrustRef GetTrustObject();
121 #elif defined(__WIN32__)
122                 PCCERT_CONTEXT GetCertificateContextPointer();
123                 CERT_CONTEXT GetCertificateContext();
124 #endif
125     
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);
132         private:
133 #if defined(__APPLE__) || defined(__WIN32__)
134                 static CURL* ConnectionObject;
135 #endif
136 #if defined(__APPLE__)
137                 static SSLContext *SSLContextPointer;
138                 static SecTrustRef SecTrustObject;
139 #elif defined(__WIN32__)
140                 static PCCERT_CONTEXT CertificateData;
141 #endif
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;
173         protected:
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;
181                                 
182 };
184 #endif
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy