// ConnectionObject.h - ConnectionObject interface header file.
//
// (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 __CONNOBJECT_CONNECTIONOBJECT_H__
#define __CONNOBJECT_CONNECTIONOBJECT_H__
#include
#include
#include
#include "../common/sslcertstructs.h"
#if defined (__APPLE__)
#import
#import
#endif
#if defined (__WIN32__)
#include
#include
#include
#include
#include
#include
#include
#endif
enum COConnectResult {
COCONNECT_UNITTESTFAIL = -1,
COCONNECT_OK,
COCONNECT_SSLFAIL,
COCONNECT_INVALID,
COCONNECT_TIMEOUT,
COCONNECT_AUTHFAIL,
COCONNECT_NOCONNECTION,
};
enum CORequestResult {
COREQUEST_UNITTESTFAIL = -1,
COREQUEST_OK,
COREQUEST_ERROR_NOTCONNECTED,
COREQUEST_ERROR_SERVER,
COREQUEST_NOCONNECTION,
};
enum COSSLVerified {
COSSL_UNITTESTFAIL = -1,
COSSL_VERIFIED,
COSSL_VERIFIED_USER,
COSSL_UNABLETOVERIFY,
COSSL_NOTAPPLICABLE,
COSSL_NORESULT
};
enum COContactStatus {
COCS_UNKNOWN,
COCS_UPDATED,
COCS_DELETED
};
struct COServerResponse {
CORequestResult RequestResult = COREQUEST_NOCONNECTION;
std::string EntityTag = "";
int SessionCode = 0;
int ResultCode = 0;
std::string ResultMessage = "";
};
struct COContactData {
std::string Location = "";
std::string Data = "";
COContactStatus Status = COCS_UNKNOWN;
};
struct COContactList {
COServerResponse ServerResponse;
std::vector ListData;
std::string SyncToken;
};
class ConnectionObject{
public:
// Virtual functions to be setup by the inheriting classes.
virtual void SetupConnectionObject() {};
virtual bool IsTaskCompleted() { return false; };
virtual COConnectResult Connect(bool DoAuthentication) { COConnectResult x; return x; };
virtual void BypassSSLVerification(bool EnableBypass) {};
virtual COServerResponse GetDefaultPrefix(std::string *ServerPrefix) { COServerResponse x; return x; };
virtual COServerResponse AddContact(std::string Location, std::string Data) { COServerResponse x; return x; };
virtual COServerResponse EditContact(std::string Location, std::string Data) { COServerResponse x; return x; };
virtual COServerResponse DeleteContact(std::string Location) { COServerResponse x; return x; };
virtual COServerResponse GetServerEntityTagValue(std::string Location) { COServerResponse x; return x; };
virtual COServerResponse GetContact(std::string Location, std::string *PageData) { COServerResponse x; return x; };
virtual COContactList GetContactList(std::string SyncToken) { COContactList x; return x; };
virtual bool CanDoProcessing() { return false; };
virtual bool CanDoSSL() { return false; };
virtual COSSLVerified SSLVerify() { COSSLVerified x; return x; };
virtual bool AbleToLogin() { return false; };
virtual bool HasValidResponse() { return false; };
virtual bool IsSelfSigned() { return false; };
virtual std::string GetErrorMessage() { return ""; };
// OS specific functions.
#if defined(__APPLE__)
virtual SecTrustRef BuildSSLCollection() { return nullptr; };
#elif defined(__WIN32__)
virtual PCCERT_CONTEXT BuildSSLCollection() { return nullptr; };
#else
virtual SSLCertCollectionString BuildSSLCollection() {};
#endif
protected:
// Test Mode.
bool TestMode = false;
// Server variables.
std::string ServerAddress = "";
unsigned int ServerPort = 8080;
std::string ServerUser = "";
std::string ServerPass = "";
std::string ServerPrefix = "";
std::string ServerAccount = "";
bool ServerSSL = true;
std::string ErrorMessage = "";
// Connect results.
bool SSLStatus = false;
COSSLVerified SSLVerified = COSSL_NORESULT;
bool ValidResponse = false;
bool AuthPassed = false;
bool CanProcess = false;
bool SSLSelfSigned = false;
bool TaskCompleted = false;
private:
};
#endif