2016-07-05 10:11:37 -04:00
|
|
|
#pragma once
|
2016-08-08 08:02:01 -04:00
|
|
|
/*
|
|
|
|
* libresapi local socket server
|
|
|
|
* Copyright (C) 2016 Gioacchino Mazzurco <gio@eigenlab.org>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-07-05 10:11:37 -04:00
|
|
|
|
|
|
|
#include <QLocalServer>
|
|
|
|
#include <QString>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QLocalSocket>
|
|
|
|
#include <retroshare/rsinit.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "ApiServer.h"
|
|
|
|
|
|
|
|
namespace resource_api
|
|
|
|
{
|
|
|
|
|
2016-08-08 08:02:01 -04:00
|
|
|
class ApiLocalListener : public QObject
|
2016-07-05 10:11:37 -04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-08-08 08:02:01 -04:00
|
|
|
ApiLocalListener(ApiServer* server, QObject *parent=0);
|
|
|
|
~ApiLocalListener() { mLocalServer.close(); }
|
|
|
|
|
|
|
|
const static QString& serverName()
|
|
|
|
{
|
|
|
|
const static QString sockPath(RsAccounts::AccountDirectory()
|
|
|
|
.append("/libresapi.sock").c_str());
|
|
|
|
return sockPath;
|
|
|
|
}
|
2016-07-05 10:11:37 -04:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void handleConnection();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ApiServer* mApiServer;
|
|
|
|
QLocalServer mLocalServer;
|
2016-08-08 08:02:01 -04:00
|
|
|
};
|
2016-07-05 10:11:37 -04:00
|
|
|
|
2016-08-08 08:02:01 -04:00
|
|
|
class ApiServerLocal : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
ApiServerLocal(ApiServer* server, QObject *parent=0);
|
|
|
|
~ApiServerLocal();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QThread serverThread;
|
|
|
|
ApiLocalListener localListener;
|
2016-07-05 10:11:37 -04:00
|
|
|
};
|
|
|
|
|
2016-08-08 08:02:01 -04:00
|
|
|
class ApiLocalConnectionHandler : public QObject
|
2016-07-05 10:11:37 -04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-08-08 08:02:01 -04:00
|
|
|
ApiLocalConnectionHandler(ApiServer* apiServer, QLocalSocket* sock, QObject *parent = 0);
|
2016-07-05 10:11:37 -04:00
|
|
|
~ApiLocalConnectionHandler();
|
2016-08-08 08:02:01 -04:00
|
|
|
enum State {WAITING_PATH, WAITING_DATA};
|
2016-07-05 10:11:37 -04:00
|
|
|
|
|
|
|
public slots:
|
2016-08-08 08:02:01 -04:00
|
|
|
void handlePendingRequests();
|
2016-07-05 10:11:37 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
ApiServer* mApiServer;
|
|
|
|
QLocalSocket* mLocalSocket;
|
2016-08-08 08:02:01 -04:00
|
|
|
State mState;
|
2016-07-05 10:11:37 -04:00
|
|
|
std::string reqPath;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace resource_api
|