1 // ConnectionObject.h - ConnectionObject interface header file.
3 // (c) 2012-2016 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{
99 // Virtual functions to be setup by the inheriting classes.
101 virtual void SetupConnectionObject() {};
103 virtual bool IsTaskCompleted() { return false; };
105 virtual COConnectResult Connect(bool DoAuthentication) { COConnectResult x; return x; };
106 virtual void BypassSSLVerification(bool EnableBypass) {};
108 virtual COServerResponse GetDefaultPrefix(std::string *ServerPrefix) { COServerResponse x; return x; };
109 virtual COServerResponse AddContact(std::string Location, std::string Data) { COServerResponse x; return x; };
110 virtual COServerResponse EditContact(std::string Location, std::string Data) { COServerResponse x; return x; };
111 virtual COServerResponse DeleteContact(std::string Location) { COServerResponse x; return x; };
112 virtual COServerResponse GetServerEntityTagValue(std::string Location) { COServerResponse x; return x; };
113 virtual COServerResponse GetContact(std::string Location, std::string *PageData) { COServerResponse x; return x; };
114 virtual COContactList GetContactList(std::string SyncToken) { COContactList x; return x; };
116 virtual bool CanDoProcessing() { return false; };
117 virtual bool CanDoSSL() { return false; };
118 virtual COSSLVerified SSLVerify() { COSSLVerified x; return x; };
119 virtual bool AbleToLogin() { return false; };
120 virtual bool HasValidResponse() { return false; };
121 virtual bool IsSelfSigned() { return false; };
122 virtual std::string GetErrorMessage() { return ""; };
124 // OS specific functions.
126 #if defined(__APPLE__)
128 virtual SecTrustRef BuildSSLCollection() { return nullptr; };
130 #elif defined(__WIN32__)
132 virtual PCCERT_CONTEXT BuildSSLCollection() { return nullptr; };
135 virtual SSLCertCollectionString BuildSSLCollection() {};
142 bool TestMode = false;
146 std::string ServerAddress = "";
147 unsigned int ServerPort = 8080;
148 std::string ServerUser = "";
149 std::string ServerPass = "";
150 std::string ServerPrefix = "";
151 std::string ServerAccount = "";
152 bool ServerSSL = true;
153 std::string ErrorMessage = "";
157 bool SSLStatus = false;
158 COSSLVerified SSLVerified = COSSL_NORESULT;
159 bool ValidResponse = false;
160 bool AuthPassed = false;
161 bool CanProcess = false;
162 bool SSLSelfSigned = false;
163 bool TaskCompleted = false;