log
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
#include "Database.hpp"
|
||||
#include "PostfixPolicyProtocol.hpp"
|
||||
#include "ChildProt.hpp"
|
||||
#include "log.hpp"
|
||||
|
||||
|
||||
using namespace std;
|
||||
@ -13,27 +14,64 @@ using namespace std;
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
clog.rdbuf(new Log("childProt", LOG_MAIL));
|
||||
string msg;
|
||||
|
||||
string result;
|
||||
|
||||
PostfixPolicyProtocol postfixPolicyProtocol;
|
||||
|
||||
try {
|
||||
postfixPolicyProtocol.processInput();
|
||||
cerr << postfixPolicyProtocol.getSender() << endl;
|
||||
cerr << postfixPolicyProtocol.getRecipient() << endl;
|
||||
msg = "sender=" + postfixPolicyProtocol.getSender() + "recipient=" + postfixPolicyProtocol.getRecipient();
|
||||
|
||||
DatabaseHandle databaseHandle(DATABASE_FILE);
|
||||
|
||||
// SELECT id, delegate FROM child_v WHERE address = '%s'
|
||||
string stmtChildTxt = "SELECT id, delegate FROM child_v WHERE address = '" + postfixPolicyProtocol.getRecipient() + "'";
|
||||
PreparedStatement pStmtChild = databaseHandle.prepareStatement(stmtChildTxt);
|
||||
result_t child = pStmtChild.next();
|
||||
|
||||
if (! child.empty()) {
|
||||
string sender = postfixPolicyProtocol.getSender();
|
||||
string::size_type atIdx = sender.find('@');
|
||||
string domain;
|
||||
if (string::npos != atIdx) {
|
||||
domain = sender.substr(atIdx);
|
||||
} else {
|
||||
domain = "UNKNOWN";
|
||||
}
|
||||
|
||||
string stmtWhitelistTxt = "SELECT * FROM whitelist_t WHERE child = '" +
|
||||
child["id"] +
|
||||
"' AND (address = '" +
|
||||
sender +
|
||||
"' OR address = '" +
|
||||
domain +
|
||||
"')";
|
||||
PreparedStatement pStmtWhitelist = databaseHandle.prepareStatement(stmtWhitelistTxt);
|
||||
result_t whitelistEntry = pStmtWhitelist.next();
|
||||
|
||||
if (whitelistEntry.empty()) {
|
||||
msg += ", not found, redirect to " + child["delegate"];
|
||||
result = "REDIRECT " + child["delegate"];
|
||||
} else {
|
||||
msg += ", found, pass by";
|
||||
result = "OK";
|
||||
}
|
||||
} else {
|
||||
msg += ", ignored";
|
||||
result = "OK";
|
||||
}
|
||||
|
||||
} catch (InvalidAddressTuple& iat) {
|
||||
cerr << "InvalidAddressTuple" << endl;
|
||||
msg = "InvalidAddressTuple";
|
||||
result = "OK";
|
||||
} catch (DatabaseError &de) {
|
||||
cerr << "DatabaseError" << endl;
|
||||
msg = "DatabaseError";
|
||||
result = "OK";
|
||||
}
|
||||
|
||||
clog << msg << endl;
|
||||
postfixPolicyProtocol.sendResult(result);
|
||||
}
|
||||
|
Reference in New Issue
Block a user