commit 52fc17295016d41d364be6144c223f511d4c9be6 Author: Wolfgang Hottgenroth Date: Wed Mar 27 20:07:19 2013 +0100 initial diff --git a/ChildProt.cpp b/ChildProt.cpp new file mode 100644 index 0000000..f10669e --- /dev/null +++ b/ChildProt.cpp @@ -0,0 +1,69 @@ +#include +#include + +#include + +#include "Database.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; + + DatabaseHandle databaseHandle("/etc/postfix/children.sqlite"); + + // SELECT id, delegate FROM child_v WHERE address = '%s' + + + } catch (InvalidAddressTuple& iat) { + cerr << "InvalidAddressTuple" << endl; + result = "OK"; + } catch (DatabaseError &de) { + cerr << "DatabaseError" << endl; + result = "OK"; + } + + cout << "action=" << result << endl << endl; +} diff --git a/Database.cpp b/Database.cpp new file mode 100644 index 0000000..c1ea8c7 --- /dev/null +++ b/Database.cpp @@ -0,0 +1,15 @@ +#include "Database.hpp" + +using namespace std; + +DatabaseHandle::DatabaseHandle(const string& filename) { + if (SQLITE_OK != sqlite3_open(filename.c_str(), &dbh)) + throw DatabaseError(); +} + +DatabaseHandle::~DatabaseHandle() { + sqlite3_close(dbh); +} + + + diff --git a/Database.hpp b/Database.hpp new file mode 100644 index 0000000..c4449cc --- /dev/null +++ b/Database.hpp @@ -0,0 +1,21 @@ +#ifndef DATABASE_HPP_ +#define DATABASE_HPP_ + +#include +#include + + +class DatabaseError {}; + +// resource management class +class DatabaseHandle { +public: + DatabaseHandle(const std::string& filename); + ~DatabaseHandle(); + sqlite3 *getHandle() { return dbh; } +private: + sqlite3 *dbh; +}; + + +#endif /* DATABASE_HPP_ */ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0b89c68 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +CXXFLAGS = -O2 -g -Wall -fmessage-length=0 + +OBJS = Database.o ChildProt.o + +LIBS = -lsqlite3 + +TARGET = ChildProt + +$(TARGET): $(OBJS) + $(CXX) -o $(TARGET) $(OBJS) $(LIBS) + +all: $(TARGET) + +clean: + rm -f $(OBJS) $(TARGET)