// CardDAV2.h - CardDAV v2 class header // // (c) 2012-2016 Xestia Software Development. // // This file is part of Xestia Address Book. // // Xestia Address Book is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Address Book is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Address Book. If not, see #ifndef __CARDDAV2_CARDDAV2_H__ #define __CARDDAV2_CARDDAV2_H__ #include "../connobject/ConnectionObject.h" #include "../version.h" #include "../common/sslcertstructs.h" #include "../common/dirs.h" #include #include #include #include #include #include #include #include class CardDAV2 : public ConnectionObject { public: CardDAV2(std::string ServerAddress, int ServerPort, std::string ServerUser, std::string ServerPass, bool ServerSSL); CardDAV2(std::string ServerAddress, int ServerPort, std::string ServerUser, std::string ServerPass, bool ServerSSL, std::string ServerPrefix, std::string ServerAccount); // Destructor. ~CardDAV2(); // Functions from the ConnectionObject interface. void SetupConnectionObject(); bool IsTaskCompleted(); COConnectResult Connect(bool DoAuthentication); COServerResponse GetDefaultPrefix(std::string *ServerPrefix); COServerResponse AddContact(std::string Location, std::string Data); COServerResponse EditContact(std::string Location, std::string Data); COServerResponse DeleteContact(std::string Location); COServerResponse GetServerEntityTagValue(std::string Location); COServerResponse GetContact(std::string Location, std::string *ContactData); COContactList GetContactList(std::string SyncToken); bool CanDoProcessing(); bool CanDoSSL(); COSSLVerified SSLVerify(); bool AbleToLogin(); bool HasValidResponse(); bool IsSelfSigned(); std::string GetErrorMessage(); #if defined(__APPLE__) SecTrustRef BuildSSLCollection(); #elif defined(__WIN32__) PCCERT_CONTEXT BuildSSLCollection(); #else SSLCertCollectionString BuildSSLCollection(); #endif void BypassSSLVerification(bool EnableBypass); struct CardDAV2PassObject { CardDAV2 *CardDAV2Object = nullptr; std::string *DataSetting = nullptr; bool ServerUsingSSL = false; CURL *ConnectionSessionObject = nullptr; #if defined(__APPLE__) SecTrustRef SSLContext = nullptr; #elif defined(__WIN32__) PCCERT_CONTEXT SSLContext = nullptr; #endif }; protected: private: // Variables to set for the CardDAV2 class. CURL *ConnectionSession = nullptr; CURLcode SessionResult = CURLE_OK; struct curl_slist *HeaderList = nullptr; void SetupDefaultParametersNonSSL(bool DoAuthentication); void SetupDefaultParametersSSL(bool DoAuthentication); std::string PageData; std::string PageHeader; char SessionErrorBuffer[CURL_ERROR_SIZE]; CardDAV2PassObject PageDataObject; CardDAV2PassObject PageHeaderObject; static size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, void *stream); size_t WritebackFuncImplementation(char *ptr, size_t size, size_t nmemb, void *stream); std::string BuildURL(std::string URI); void ResetResults(); std::vector GetDAVHeader(); std::string GetETagHeader(); std::string GetETagValue(); std::string GetUserPrincipalURI(); std::string GetAddressBookHomeURI(); std::string GetDefaultAddressBookURI(); void ProcessContactData(COContactList *ContactList); #if defined(__APPLE__) SecTrustRef CertificateData = nullptr; #elif defined(__WIN32__) PCCERT_CONTEXT CertificateData = nullptr; #else #endif void SetCertificateData(); bool EnableSSLBypass = false; }; #endif