1 // ConnectionObject.h - ConnectionObject interface 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 __CONNOBJECT_CONNECTIONOBJECT_H__
20 #define __CONNOBJECT_CONNECTIONOBJECT_H__
25 #include "../common/sslcertstructs.h"
27 #if defined (__APPLE__)
28 #import <Foundation/Foundation.h>
29 #import <SecurityInterface/SFCertificateTrustPanel.h>
32 #if defined (__WIN32__)
35 #include <winapifamily.h>
38 #include <cryptuiapi.h>
42 enum COConnectResult {
43 COCONNECT_UNITTESTFAIL = -1,
49 COCONNECT_NOCONNECTION,
52 enum CORequestResult {
53 COREQUEST_UNITTESTFAIL = -1,
55 COREQUEST_ERROR_NOTCONNECTED,
56 COREQUEST_ERROR_SERVER,
57 COREQUEST_NOCONNECTION,
61 COSSL_UNITTESTFAIL = -1,
69 enum COContactStatus {
75 struct COServerResponse {
76 CORequestResult RequestResult = COREQUEST_NOCONNECTION;
77 std::string EntityTag = "";
80 std::string ResultMessage = "";
83 struct COContactData {
84 std::string Location = "";
85 std::string Data = "";
86 COContactStatus Status = COCS_UNKNOWN;
89 struct COContactList {
90 COServerResponse ServerResponse;
91 std::vector<COContactData> ListData;
92 std::string SyncToken;
95 class ConnectionObject{
98 //ConnectionObject(std::string ServerAddress, int ServerPort, std::string ServerUser, std::string ServerPass, bool ServerSSL);
99 //ConnectionObject(std::string ServerAddress, int ServerPort, std::string ServerUser, std::string ServerPass, bool ServerSSL, std::string ServerPrefix, std::string ServerAccount);
101 // Virtual functions to be setup by the inheriting classes.
103 virtual void SetupConnectionObject() {};
105 virtual bool IsTaskCompleted() { return false; };
107 virtual COConnectResult Connect(bool DoAuthentication) { COConnectResult x; return x; };
108 virtual void BypassSSLVerification(bool EnableBypass) {};
110 virtual COServerResponse GetDefaultPrefix(std::string *ServerPrefix) { COServerResponse x; return x; };
111 virtual COServerResponse AddContact(std::string Location, std::string Data) { COServerResponse x; return x; };
112 virtual COServerResponse EditContact(std::string Location, std::string Data) { COServerResponse x; return x; };
113 virtual COServerResponse DeleteContact(std::string Location) { COServerResponse x; return x; };
114 virtual COServerResponse GetServerEntityTagValue(std::string Location) { COServerResponse x; return x; };
115 virtual COServerResponse GetContact(std::string Location, std::string *PageData) { COServerResponse x; return x; };
116 virtual COContactList GetContactList(std::string SyncToken) { COContactList x; return x; };
118 virtual bool CanDoProcessing() { return false; };
119 virtual bool CanDoSSL() { return false; };
120 virtual COSSLVerified SSLVerify() { COSSLVerified x; return x; };
121 virtual bool AbleToLogin() { return false; };
122 virtual bool HasValidResponse() { return false; };
123 virtual bool IsSelfSigned() { return false; };
124 virtual std::string GetErrorMessage() { return ""; };
126 // OS specific functions.
128 #if defined(__APPLE__)
130 virtual SecTrustRef BuildSSLCollection() { return nullptr; };
132 #elif defined(__WIN32__)
134 virtual PCCERT_CONTEXT BuildSSLCollection() { return nullptr; };
137 virtual SSLCertCollectionString BuildSSLCollection() {};
144 bool TestMode = false;
148 std::string ServerAddress = "";
149 unsigned int ServerPort = 8080;
150 std::string ServerUser = "";
151 std::string ServerPass = "";
152 std::string ServerPrefix = "";
153 std::string ServerAccount = "";
154 bool ServerSSL = true;
155 std::string ErrorMessage = "";
159 bool SSLStatus = false;
160 COSSLVerified SSLVerified = COSSL_NORESULT;
161 bool ValidResponse = false;
162 bool AuthPassed = false;
163 bool CanProcess = false;
164 bool SSLSelfSigned = false;
165 bool TaskCompleted = false;