1 // carddav.cpp - Main CardDAV Object file.
\r
3 // (c) 2012-2015 Xestia Software Development.
\r
5 // This file is part of Xestia Address Book.
\r
7 // Xestia Address Book is free software: you can redistribute it and/or modify
\r
8 // it under the terms of the GNU General Public License as published by the
\r
9 // Free Software Foundation, version 3 of the license.
\r
11 // Xestia Address Book is distributed in the hope that it will be useful,
\r
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 // GNU General Public License for more details.
\r
16 // You should have received a copy of the GNU General Public License along
\r
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
\r
19 #include "carddav.h"
\r
20 #include "../version.h"
\r
22 #include <wx/tokenzr.h>
\r
23 #include <wx/ffile.h>
\r
24 #include <libxml/parser.h>
\r
25 #include <libxml/tree.h>
\r
28 #include "../vcard/vcard.h"
\r
29 #include "../common/dirs.h"
\r
31 size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *stream){
\r
34 Data = wxString::FromUTF8((char *)ptr);
\r
36 stream->Append(Data);
\r
38 return size * nmemb;
\r
42 int ProgressFunc(void *clientdata, double TTDown, double NDown, double TTUp, double NUp){
\r
46 CardDAV *IncCardDAV = static_cast<CardDAV*>(clientdata);
\r
47 ProgressRet = IncCardDAV->ProgressFuncProc(clientdata, TTDown, NDown, TTUp, NUp);
\r
48 if (ProgressRet != 0){
\r
55 wxString CardDAV::ServerAddress;
\r
56 int CardDAV::ServerPort;
\r
57 wxString CardDAV::ServerUser;
\r
58 wxString CardDAV::ServerPass;
\r
59 wxString CardDAV::ServerPrefix;
\r
60 wxString CardDAV::ServerAccount;
\r
61 bool CardDAV::ServerSSL;
\r
62 bool *CardDAV::ServerResult;
\r
63 bool *CardDAV::ServerMonitor;
\r
64 bool CardDAV::SSLStatus;
\r
65 bool CardDAV::SSLVerified;
\r
66 bool CardDAV::ValidResponse;
\r
67 bool CardDAV::AuthPassed;
\r
68 bool CardDAV::HasCalDAVSupport;
\r
69 bool CardDAV::AbortConnection;
\r
70 wxString CardDAV::ServerResponse;
\r
71 wxString CardDAV::ServerMethod;
\r
72 wxString CardDAV::ServerFilenameLocation;
\r
73 wxString CardDAV::ServerUploadData;
\r
74 wxString CardDAV::ETagData;
\r
75 wxString CardDAV::ETagResult;
\r
76 bool CardDAV::UploadMode;
\r
77 bool CardDAV::EditMode;
\r
78 long CardDAV::ItemIndex;
\r
79 std::map<int, int> *CardDAV::ActivityListPtr;
\r
80 char CardDAV::curlerrbuffer[CURL_ERROR_SIZE];
\r
81 SSLCertCollection CardDAV::SSLCertCol;
\r
82 int CardDAV::SSLErrorCode;
\r
83 int CardDAV::ConnectionErrorCode;
\r
84 wxString CardDAV::PageHeader;
\r
85 wxString CardDAV::PageData;
\r
86 CURLcode CardDAV::claconncode;
\r
87 int CardDAV::HTTPErrorCode;
\r
88 wxString CardDAV::ErrorMessage;
\r
89 SSLCertCollection CardDAV::VerifyCertCollection;
\r
90 bool CardDAV::AllowSelfSign;
\r
95 SSLVerified = FALSE;
\r
97 ValidResponse = FALSE;
\r
98 HasCalDAVSupport = FALSE;
\r
99 SSLCertCol.SuccessCode = 0;
\r
100 AllowSelfSign = FALSE;
\r
102 AbortConnection = FALSE;
\r
103 UploadMode = FALSE;
\r
108 CardDAV::~CardDAV(){
\r
112 size_t UploadReadFunc(void *ptr, size_t size, size_t nmemb, void *userdata){
\r
114 struct UploadDataStruc *UploadPtr = (struct UploadDataStruc *)userdata;
\r
116 if (UploadPtr->sizeleft){
\r
118 //MeepMoop->sizeleft--;
\r
121 UploadPtr->sizeleft--;
\r
124 wxSChar = UploadPtr->readptr->Mid(UploadPtr->seek,1);
\r
126 //*(char *)ptr = (char)wxSChar.mb_str();
\r
128 strncpy((char *)ptr, (const char*)wxSChar.mb_str(wxConvUTF8), 1);
\r
140 bool CardDAV::SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL){
\r
142 ServerAddress = SvrAddress;
\r
143 ServerPort = SvrPort;
\r
144 ServerUser = SvrUser;
\r
145 ServerPass = SvrPass;
\r
146 ServerSSL = SvrSSL;
\r
152 bool CardDAV::SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL, wxString SvrPrefix, wxString SvrAccount){
\r
154 ServerAddress = SvrAddress;
\r
155 ServerPort = SvrPort;
\r
156 ServerUser = SvrUser;
\r
157 ServerPass = SvrPass;
\r
158 ServerSSL = SvrSSL;
\r
159 ServerPrefix = SvrPrefix;
\r
160 ServerAccount = SvrAccount;
\r
166 bool CardDAV::SetupResultBools(bool *SvrResult, bool *SvrMonitor){
\r
168 ServerResult = SvrResult;
\r
169 ServerMonitor = SvrMonitor;
\r
175 bool CardDAV::HasValidResponse(){
\r
177 return ValidResponse;
\r
181 bool CardDAV::CanDoCardDAV(){
\r
183 return HasCalDAVSupport;
\r
187 bool CardDAV::CanDoSSL(){
\r
193 bool CardDAV::SSLVerify(){
\r
195 return SSLVerified;
\r
199 bool CardDAV::AbleToLogin(){
\r
205 bool CardDAV::IsSelfSigned(){
\r
207 return AllowSelfSign;
\r
213 size_t CardDAV::WritebackFunc(char *ptr, size_t size, size_t nmemb, FILE *stream){
\r
216 Data = wxString::FromUTF8((char *)ptr);
\r
217 if ((bool)stream == TRUE){
\r
218 PageHeader.Append(Data);
\r
220 PageData.Append(Data);
\r
222 return size * nmemb;
\r
228 int CardDAV::ProgressFuncProc(void *clientdata, double TTUp, double NUp, double TTDown, double NDown){
\r
230 if (AbortConnection == TRUE){
\r
242 void CardDAV::Abort(){
\r
244 AbortConnection = TRUE;
\r
248 SSLCertCollection CardDAV::GetSSLVerifyResults(){
\r
249 return VerifyCertCollection;
\r
252 void CardDAV::AllowSelfSignTest(bool AllowSelfSignIn){
\r
253 AllowSelfSign = AllowSelfSignIn;
\r
256 void CardDAV::GetSSLResults(){
\r
262 void CardDAV::SetServerFilename(wxString Filename){
\r
264 ServerFilenameLocation = Filename;
\r
268 wxString CardDAV::GetPageData()
\r
275 wxString CardDAV::ETagValueResult(){
\r
281 void CardDAV::SetupData(wxString Method, wxString FilenameLocation, wxString UploadData){
\r
283 ServerMethod = Method;
\r
284 ServerFilenameLocation = FilenameLocation;
\r
285 ServerUploadData = UploadData;
\r
287 // Check if ServerFilenameLocation has a / at
\r
288 // the start and if not then append it.
\r
290 if (ServerFilenameLocation.Left(1) != wxT("/")){
\r
292 // Not there so insert.
\r
294 ServerFilenameLocation = wxT("/") + ServerFilenameLocation;
\r
300 void CardDAV::SetupVariables(std::map<int, int> *actlist, int actindex){
\r
302 ActivityListPtr = actlist;
\r
303 ItemIndex = actindex;
\r
307 wxString CardDAV::GetETagData(){
\r
313 void CardDAV::SetUploadMode(bool IncMode){
\r
315 UploadMode = IncMode;
\r
319 void CardDAV::SetEditMode(bool EditModeInc){
\r
321 EditMode = EditModeInc;
\r
325 int CardDAV::GetResultCode(){
\r
327 return (int)claconncode;
\r
331 int CardDAV::GetHTTPCode(){
\r
333 return HTTPErrorCode;
\r
337 wxString CardDAV::GetErrorBuffer(){
\r
339 wxString ErrorBuffer = wxString::FromUTF8(curlerrbuffer);
\r
341 return ErrorBuffer;
\r
345 SSLCertCollection CardDAV::BuildSSLCollection(CURL *conn){
\r
347 SSLCertCollection SSLCertInfo;
\r
349 // Grab the certificate data.
\r
352 struct curl_slist *certdata;
\r
353 struct curl_certinfo *certinfo;
\r
356 certptr.certdata = NULL;
\r
358 curl_easy_getinfo(conn, CURLINFO_CERTINFO, &certptr.certinfo);
\r
360 wxString CertPropName;
\r
361 wxString CertPropValue;
\r
363 for (int i = 0; i < certptr.certinfo->num_of_certs; i++){
\r
365 struct curl_slist *slist;
\r
366 SSLCertData SSLCertDataInc;
\r
368 for (slist = certptr.certinfo->certinfo[i]; slist; slist = slist->next){
\r
370 wxStringTokenizer CertDataInc(wxString::FromUTF8(slist->data), ":");
\r
372 // Get first token as the property name.
\r
374 CertPropName = CertDataInc.GetNextToken();
\r
376 // Get remaining tokens as the property value.
\r
378 while(CertDataInc.HasMoreTokens()){
\r
380 CertPropValue.Append(CertDataInc.GetNextToken());
\r
384 SSLCertDataInc.CertData.insert(std::make_pair(CertPropName, CertPropValue));
\r
385 CertPropName.clear();
\r
386 CertPropValue.clear();
\r
390 SSLCertInfo.SSLCollection.insert(std::make_pair(i, SSLCertDataInc));
\r
394 return SSLCertInfo;
\r
398 SSLCertCollection CardDAV::GetCertificateData(){
\r
400 // Pass on the collected certificate data.
\r
406 wxString CardDAV::GetErrorMessage(){
\r
408 return ErrorMessage;
\r