changes
This commit is contained in:
@ -4,55 +4,25 @@
|
|||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
|
||||||
#include "Database.hpp"
|
#include "Database.hpp"
|
||||||
|
#include "PostfixPolicyProtocol.hpp"
|
||||||
|
#include "ChildProt.hpp"
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
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() {
|
int main() {
|
||||||
string result;
|
string result;
|
||||||
|
|
||||||
try {
|
PostfixPolicyProtocol postfixPolicyProtocol;
|
||||||
AddressTuple addressTuple;
|
|
||||||
cerr << addressTuple.getSender() << endl;
|
|
||||||
cerr << addressTuple.getRecipient() << endl;
|
|
||||||
|
|
||||||
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'
|
// SELECT id, delegate FROM child_v WHERE address = '%s'
|
||||||
|
|
||||||
@ -65,5 +35,5 @@ int main() {
|
|||||||
result = "OK";
|
result = "OK";
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "action=" << result << endl << endl;
|
postfixPolicyProtocol.sendResult(result);
|
||||||
}
|
}
|
||||||
|
16
ChildProt.hpp
Normal file
16
ChildProt.hpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* ChildProt.hpp
|
||||||
|
*
|
||||||
|
* Created on: 27.03.2013
|
||||||
|
* Author: wn
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CHILDPROT_HPP_
|
||||||
|
#define CHILDPROT_HPP_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
const std::string DATABASE_FILE = "children.sqlite";
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* CHILDPROT_HPP_ */
|
2
Makefile
2
Makefile
@ -1,6 +1,6 @@
|
|||||||
CXXFLAGS = -O2 -g -Wall -fmessage-length=0
|
CXXFLAGS = -O2 -g -Wall -fmessage-length=0
|
||||||
|
|
||||||
OBJS = Database.o ChildProt.o
|
OBJS = Database.o PostfixPolicyProtocol.o ChildProt.o
|
||||||
|
|
||||||
LIBS = -lsqlite3
|
LIBS = -lsqlite3
|
||||||
|
|
||||||
|
46
PostfixPolicyProtocol.cpp
Normal file
46
PostfixPolicyProtocol.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* PostfixPolicyProtocol.cpp
|
||||||
|
*
|
||||||
|
* Created on: 27.03.2013
|
||||||
|
* Author: wn
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
28
PostfixPolicyProtocol.hpp
Normal file
28
PostfixPolicyProtocol.hpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* PostfixPolicyProtocol.hpp
|
||||||
|
*
|
||||||
|
* Created on: 27.03.2013
|
||||||
|
* Author: wn
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef POSTFIX_POLICY_PROTOCOL_HPP_
|
||||||
|
#define POSTFIX_POLICY_PROTOCOL_HPP_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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_ */
|
BIN
children.sqlite
Normal file
BIN
children.sqlite
Normal file
Binary file not shown.
Reference in New Issue
Block a user