Add ssl certificate crt and key to config
This commit is contained in:
@ -37,7 +37,7 @@ namespace Utilities {
|
||||
}
|
||||
|
||||
std::string trimFromDelimiter(std::string stringToTrim, char delimiter) {
|
||||
int position = stringToTrim.find(delimiter);
|
||||
std::size_t position = stringToTrim.find(delimiter);
|
||||
if (position != std::string::npos)
|
||||
return stringToTrim.substr(0, position);
|
||||
return stringToTrim;
|
||||
@ -54,16 +54,22 @@ namespace Utilities {
|
||||
std::string emailServerAddress;
|
||||
int emailServerPort = 587;
|
||||
std::string emailAddressDisplay = "Cavecomm Automated Management System";
|
||||
std::string sslCrtPath;
|
||||
std::string sslKeyPath;
|
||||
|
||||
/*
|
||||
* validates existence of mandatory variables in config
|
||||
* returns 0 if successful else 1
|
||||
*/
|
||||
int checkMandatoryVariables() const {
|
||||
if (emailAddress.compare("") == 0
|
||||
|| emailPassword.compare("") == 0
|
||||
|| emailServerAddress.compare("") == 0
|
||||
|| databaseConnectionString.compare("") == 0)
|
||||
if (
|
||||
emailAddress.empty()
|
||||
|| emailPassword.empty()
|
||||
|| emailServerAddress.empty()
|
||||
|| databaseConnectionString.empty()
|
||||
|| sslCrtPath.empty()
|
||||
|| sslCrtPath.empty()
|
||||
)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
@ -113,30 +119,38 @@ namespace Utilities {
|
||||
|
||||
if (lineVector.size() == 2) {
|
||||
std::cout << lineVector.at(0) << " - " << lineVector.at(1) << std::endl;
|
||||
if (lineVector.at(0).compare("emailAddress") == 0) {
|
||||
if (lineVector.at(0) == "emailAddress") {
|
||||
emailAddress = trimFromDelimiter(lineVector.at(1), ';');
|
||||
continue;
|
||||
}
|
||||
if (lineVector.at(0).compare("emailPassword") == 0) {
|
||||
if (lineVector.at(0) == "emailPassword") {
|
||||
emailPassword = trimFromDelimiter(lineVector.at(1), ';');
|
||||
continue;
|
||||
}
|
||||
if (lineVector.at(0).compare("emailServerAddress") == 0) {
|
||||
if (lineVector.at(0) == "emailServerAddress") {
|
||||
emailServerAddress = trimFromDelimiter(lineVector.at(1), ';');
|
||||
continue;
|
||||
}
|
||||
if (lineVector.at(0).compare("emailServerPort") == 0) {
|
||||
if (lineVector.at(0) == "emailServerPort") {
|
||||
emailServerPort = std::stoi(trimFromDelimiter(lineVector.at(1), ';'));
|
||||
continue;
|
||||
}
|
||||
if (lineVector.at(0).compare("emailAddressDisplay") == 0) {
|
||||
if (lineVector.at(0) == "emailAddressDisplay") {
|
||||
emailAddressDisplay = trimFromDelimiter(lineVector.at(1), ';');
|
||||
continue;
|
||||
}
|
||||
if (lineVector.at(0).compare("databaseConnectionString") == 0) {
|
||||
if (lineVector.at(0) == "databaseConnectionString") {
|
||||
databaseConnectionString = trimFromDelimiter(lineVector.at(1), ';');
|
||||
continue;
|
||||
}
|
||||
if (lineVector.at(0) == "sslCrtPath") {
|
||||
sslCrtPath = trimFromDelimiter(lineVector.at(1), ';');
|
||||
continue;
|
||||
}
|
||||
if (lineVector.at(0) == "sslKeyPath") {
|
||||
sslKeyPath = trimFromDelimiter(lineVector.at(1), ';');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -163,7 +177,7 @@ namespace Utilities {
|
||||
* replaces a string with another string within a string
|
||||
*/
|
||||
void replaceString(std::string &stringToProcess, const std::string& from, const std::string& to) {
|
||||
int stringPosition = stringToProcess.find(from);
|
||||
std::size_t stringPosition = stringToProcess.find(from);
|
||||
while (stringPosition != std::string::npos) {
|
||||
stringToProcess.replace(stringToProcess.find(from), std::string(from).size(), to);
|
||||
stringPosition = stringToProcess.find(from);
|
||||
@ -200,7 +214,7 @@ namespace Utilities {
|
||||
int err_no = client.sendMail(msg);
|
||||
if (err_no != 0) {
|
||||
std::cerr << client.getCommunicationLog() << '\n';
|
||||
std::string errorMessage = client.getErrorMessage(err_no);
|
||||
std::string errorMessage = OpportunisticSecureSMTPClient::getErrorMessage(err_no);
|
||||
std::cerr << "An error occurred: " << errorMessage
|
||||
<< " (error no: " << err_no << ")" << '\n';
|
||||
return 1;
|
||||
|
Reference in New Issue
Block a user