Skip to content

Commit

Permalink
Add IP whitelisting support by Søren Boll Overgaard
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.frubar.net/svn/libmaia/trunk@12 76f3bc84-83be-48bd-939e-545709b08832
  • Loading branch information
wiedi authored and wiedi committed Jul 15, 2010
1 parent f5e6cd4 commit be7c913
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 14 additions & 2 deletions maiaXmlRpcServer.cpp
Expand Up @@ -38,6 +38,12 @@ MaiaXmlRpcServer::MaiaXmlRpcServer(quint16 port, QObject* parent) : QObject(pare
server.listen(QHostAddress::Any, port);
}

MaiaXmlRpcServer::MaiaXmlRpcServer(const QHostAddress &address, quint16 port, QList<QHostAddress> *allowedAddresses, QObject *parent) : QObject(parent) {
this->allowedAddresses = allowedAddresses;
connect(&server, SIGNAL(newConnection()), this, SLOT(newConnection()));
server.listen(address, port);
}

void MaiaXmlRpcServer::addMethod(QString method,
QObject* responseObject, const char* responseSlot) {
objectMap[method] = responseObject;
Expand All @@ -60,9 +66,15 @@ void MaiaXmlRpcServer::getMethod(QString method, QObject **responseObject, const
}

void MaiaXmlRpcServer::newConnection() {
MaiaXmlRpcServerConnection *client = new MaiaXmlRpcServerConnection(server.nextPendingConnection(), this);
connect(client, SIGNAL(getMethod(QString, QObject **, const char**)),
QTcpSocket *connection = server.nextPendingConnection();
if (this->allowedAddresses==0 || this->allowedAddresses->length()<=0 || this->allowedAddresses->contains(connection->peerAddress())) {
MaiaXmlRpcServerConnection *client = new MaiaXmlRpcServerConnection(connection, this);
connect(client, SIGNAL(getMethod(QString, QObject **, const char**)),
this, SLOT(getMethod(QString, QObject **, const char**)));
} else {
qWarning() << "Rejected connection attempt from" << connection->peerAddress().toString();
connection->disconnectFromHost();
}
}

QHostAddress MaiaXmlRpcServer::getServerAddress() {
Expand Down
2 changes: 2 additions & 0 deletions maiaXmlRpcServer.h
Expand Up @@ -40,6 +40,7 @@ class MaiaXmlRpcServer : public QObject {

public:
MaiaXmlRpcServer(const QHostAddress &address = QHostAddress::Any, quint16 port = 8080, QObject* parent = 0);
MaiaXmlRpcServer(const QHostAddress &address = QHostAddress::Any, quint16 port = 8080, QList<QHostAddress> *allowedAddresses = 0, QObject *parent = 0);
MaiaXmlRpcServer(quint16 port = 8080, QObject* parent = 0);
void addMethod(QString method, QObject *responseObject, const char* responseSlot);
void removeMethod(QString method);
Expand All @@ -55,6 +56,7 @@ class MaiaXmlRpcServer : public QObject {
QTcpServer server;
QHash<QString, QObject*> objectMap;
QHash<QString, const char*> slotMap;
QList<QHostAddress> *allowedAddresses;

friend class maiaXmlRpcServerConnection;

Expand Down

0 comments on commit be7c913

Please sign in to comment.