initial
This commit is contained in:
69
ChildProt.cpp
Normal file
69
ChildProt.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <sqlite3.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
15
Database.cpp
Normal file
15
Database.cpp
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
21
Database.hpp
Normal file
21
Database.hpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef DATABASE_HPP_
|
||||||
|
#define DATABASE_HPP_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <sqlite3.h>
|
||||||
|
|
||||||
|
|
||||||
|
class DatabaseError {};
|
||||||
|
|
||||||
|
// resource management class
|
||||||
|
class DatabaseHandle {
|
||||||
|
public:
|
||||||
|
DatabaseHandle(const std::string& filename);
|
||||||
|
~DatabaseHandle();
|
||||||
|
sqlite3 *getHandle() { return dbh; }
|
||||||
|
private:
|
||||||
|
sqlite3 *dbh;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* DATABASE_HPP_ */
|
Reference in New Issue
Block a user