diff --git a/ChildProt b/ChildProt new file mode 100755 index 0000000..eea1a04 Binary files /dev/null and b/ChildProt differ diff --git a/ChildProt.cpp b/ChildProt.cpp index f10669e..4e9a801 100644 --- a/ChildProt.cpp +++ b/ChildProt.cpp @@ -4,55 +4,25 @@ #include #include "Database.hpp" +#include "PostfixPolicyProtocol.hpp" +#include "ChildProt.hpp" + using namespace std; -class InvalidAddressTuple {}; - -class AddressTuple { -public : - AddressTuple(); - const string& getSender() const { return sender; } - const string& getRecipient() const { return recipient; } -private: - string sender; - string recipient; -}; - -AddressTuple::AddressTuple() { - sender = ""; - recipient = ""; - - while (1) { - string buffer; - getline(cin, buffer); - if (0 == buffer.length()) - break; - string::size_type equalsIdx = buffer.find('='); - if (string::npos != equalsIdx) { - string key = buffer.substr(0, equalsIdx); - string value = buffer.substr(equalsIdx+1); - if ("sender" == key) - sender = value; - if ("recipient" ==key) - recipient = value; - } - } - - if ((0 == sender.length()) || (0 == recipient.length())) - throw InvalidAddressTuple(); -} int main() { string result; - try { - AddressTuple addressTuple; - cerr << addressTuple.getSender() << endl; - cerr << addressTuple.getRecipient() << endl; + PostfixPolicyProtocol postfixPolicyProtocol; - DatabaseHandle databaseHandle("/etc/postfix/children.sqlite"); + try { + postfixPolicyProtocol.processInput(); + cerr << postfixPolicyProtocol.getSender() << endl; + cerr << postfixPolicyProtocol.getRecipient() << endl; + + DatabaseHandle databaseHandle(DATABASE_FILE); // SELECT id, delegate FROM child_v WHERE address = '%s' @@ -65,5 +35,5 @@ int main() { result = "OK"; } - cout << "action=" << result << endl << endl; + postfixPolicyProtocol.sendResult(result); } diff --git a/ChildProt.hpp b/ChildProt.hpp new file mode 100644 index 0000000..1c80b21 --- /dev/null +++ b/ChildProt.hpp @@ -0,0 +1,16 @@ +/* + * ChildProt.hpp + * + * Created on: 27.03.2013 + * Author: wn + */ + +#ifndef CHILDPROT_HPP_ +#define CHILDPROT_HPP_ + +#include + +const std::string DATABASE_FILE = "children.sqlite"; + + +#endif /* CHILDPROT_HPP_ */ diff --git a/Makefile b/Makefile index 0b89c68..8d32534 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CXXFLAGS = -O2 -g -Wall -fmessage-length=0 -OBJS = Database.o ChildProt.o +OBJS = Database.o PostfixPolicyProtocol.o ChildProt.o LIBS = -lsqlite3 diff --git a/PostfixPolicyProtocol.cpp b/PostfixPolicyProtocol.cpp new file mode 100644 index 0000000..d67924e --- /dev/null +++ b/PostfixPolicyProtocol.cpp @@ -0,0 +1,46 @@ +/* + * PostfixPolicyProtocol.cpp + * + * Created on: 27.03.2013 + * Author: wn + */ + +#include +#include "PostfixPolicyProtocol.hpp" + +using namespace std; + + +PostfixPolicyProtocol::PostfixPolicyProtocol() { + sender = ""; + recipient = ""; + } + +void PostfixPolicyProtocol::processInput() { + while (1) { + string buffer; + getline(cin, buffer); + if (0 == buffer.length()) + break; + string::size_type equalsIdx = buffer.find('='); + if (string::npos != equalsIdx) { + string key = buffer.substr(0, equalsIdx); + string value = buffer.substr(equalsIdx+1); + if ("sender" == key) + sender = value; + if ("recipient" ==key) + recipient = value; + } + } + + if ((0 == sender.length()) || (0 == recipient.length())) + throw InvalidAddressTuple(); +} + +void PostfixPolicyProtocol::sendResult(string const& result) { + cout << "action=" << result << endl << endl; + +} + + + diff --git a/PostfixPolicyProtocol.hpp b/PostfixPolicyProtocol.hpp new file mode 100644 index 0000000..34d3d96 --- /dev/null +++ b/PostfixPolicyProtocol.hpp @@ -0,0 +1,28 @@ +/* + * PostfixPolicyProtocol.hpp + * + * Created on: 27.03.2013 + * Author: wn + */ + +#ifndef POSTFIX_POLICY_PROTOCOL_HPP_ +#define POSTFIX_POLICY_PROTOCOL_HPP_ + +#include + +class InvalidAddressTuple {}; + +class PostfixPolicyProtocol { +public : + PostfixPolicyProtocol(); + void processInput(); + void sendResult(std::string const& result); + const std::string& getSender() const { return sender; } + const std::string& getRecipient() const { return recipient; } +private: + std::string sender; + std::string recipient; +}; + + +#endif /* POSTFIX_POLICY_PROTOCOL_HPP_ */ diff --git a/children.sqlite b/children.sqlite new file mode 100644 index 0000000..4782cc5 Binary files /dev/null and b/children.sqlite differ