
31 changed files with 959 additions and 51 deletions
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
|
||||
#pragma once |
||||
|
||||
#include "curl/curl.h" |
||||
#include "transport/Logging.h" |
||||
#include "transport/ThreadPool.h" |
||||
#include <iostream> |
||||
#include <sstream> |
||||
#include <string.h> |
||||
#include "rapidjson/document.h" |
||||
|
||||
namespace Transport { |
||||
|
||||
class HTTPRequest; |
||||
|
||||
class HTTPRequestQueue { |
||||
public: |
||||
HTTPRequestQueue(int delayBetweenRequests = 1); |
||||
|
||||
virtual ~HTTPRequestQueue(); |
||||
|
||||
void queueRequest(HTTPRequest *req); |
||||
|
||||
void sendNextRequest(); |
||||
|
||||
private: |
||||
int m_delay; |
||||
std::queue<HTTPRequest *> m_queue; |
||||
bool m_processing; |
||||
}; |
||||
|
||||
} |
||||
|
@ -0,0 +1,133 @@
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
* XMPP - libpurple transport |
||||
* |
||||
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im> |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation; either version 2 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
||||
*/ |
||||
|
||||
#include "SlackAPI.h" |
||||
#include "SlackFrontend.h" |
||||
#include "SlackUser.h" |
||||
#include "SlackRTM.h" |
||||
|
||||
#include "transport/Transport.h" |
||||
#include "transport/HTTPRequest.h" |
||||
#include "transport/Util.h" |
||||
|
||||
#include <boost/foreach.hpp> |
||||
#include <boost/make_shared.hpp> |
||||
#include <map> |
||||
#include <iterator> |
||||
|
||||
namespace Transport { |
||||
|
||||
DEFINE_LOGGER(logger, "SlackAPI"); |
||||
|
||||
SlackAPI::SlackAPI(Component *component, UserInfo uinfo) : m_uinfo(uinfo) { |
||||
m_component = component; |
||||
} |
||||
|
||||
SlackAPI::~SlackAPI() { |
||||
} |
||||
|
||||
void SlackAPI::handleSendMessage(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data) { |
||||
LOG4CXX_INFO(logger, data); |
||||
} |
||||
|
||||
void SlackAPI::sendMessage(const std::string &from, const std::string &to, const std::string &text) { |
||||
std::string url = "https://slack.com/api/chat.postMessage?"; |
||||
url += "&username=" + Util::urlencode(from); |
||||
url += "&channel=" + Util::urlencode(to); |
||||
url += "&text=" + Util::urlencode(text); |
||||
url += "&token=" + Util::urlencode(m_uinfo.encoding); |
||||
|
||||
HTTPRequest *req = new HTTPRequest(THREAD_POOL(m_component), HTTPRequest::Get, url, |
||||
boost::bind(&SlackAPI::handleSendMessage, this, _1, _2, _3, _4)); |
||||
queueRequest(req); |
||||
} |
||||
|
||||
std::string SlackAPI::getChannelId(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data) { |
||||
if (!ok) { |
||||
LOG4CXX_ERROR(logger, req->getError()); |
||||
LOG4CXX_ERROR(logger, data); |
||||
return ""; |
||||
} |
||||
|
||||
rapidjson::Value &channel = resp["channel"]; |
||||
if (!channel.IsObject()) { |
||||
LOG4CXX_ERROR(logger, "No 'channel' object in the reply."); |
||||
LOG4CXX_ERROR(logger, data); |
||||
return ""; |
||||
} |
||||
|
||||
rapidjson::Value &id = channel["id"]; |
||||
if (!id.IsString()) { |
||||
LOG4CXX_ERROR(logger, "No 'id' string in the reply."); |
||||
LOG4CXX_ERROR(logger, data); |
||||
return ""; |
||||
} |
||||
|
||||
return id.GetString(); |
||||
} |
||||
|
||||
void SlackAPI::imOpen(const std::string &uid, HTTPRequest::Callback callback) { |
||||
std::string url = "https://slack.com/api/im.open?user=" + Util::urlencode(uid) + "&token=" + Util::urlencode(m_uinfo.encoding); |
||||
HTTPRequest *req = new HTTPRequest(THREAD_POOL(m_component), HTTPRequest::Get, url, callback); |
||||
queueRequest(req); |
||||
} |
||||
|
||||
std::string SlackAPI::getOwnerId(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data) { |
||||
if (!ok) { |
||||
LOG4CXX_ERROR(logger, req->getError()); |
||||
return ""; |
||||
} |
||||
|
||||
rapidjson::Value &members = resp["members"]; |
||||
if (!members.IsArray()) { |
||||
LOG4CXX_ERROR(logger, "No 'members' object in the reply."); |
||||
return ""; |
||||
} |
||||
|
||||
for (int i = 0; i < members.Size(); i++) { |
||||
if (!members[i].IsObject()) { |
||||
continue; |
||||
} |
||||
|
||||
rapidjson::Value &is_primary_owner = members[i]["is_primary_owner"]; |
||||
if (!is_primary_owner.IsBool()) { |
||||
continue; |
||||
} |
||||
|
||||
if (is_primary_owner.GetBool()) { |
||||
rapidjson::Value &name = members[i]["id"]; |
||||
if (!name.IsString()) { |
||||
LOG4CXX_ERROR(logger, "No 'name' string in the reply."); |
||||
return ""; |
||||
} |
||||
return name.GetString(); |
||||
} |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
void SlackAPI::usersList(HTTPRequest::Callback callback) { |
||||
std::string url = "https://slack.com/api/users.list?presence=0&token=" + Util::urlencode(m_uinfo.encoding); |
||||
HTTPRequest *req = new HTTPRequest(THREAD_POOL(m_component), HTTPRequest::Get, url, callback); |
||||
queueRequest(req); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Spectrum 2 Slack Frontend |
||||
* |
||||
* Copyright (C) 2015, Jan Kaluza <hanzz.k@gmail.com> |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation; either version 2 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include "transport/HTTPRequestQueue.h" |
||||
#include "transport/HTTPRequest.h" |
||||
#include "transport/StorageBackend.h" |
||||
#include "rapidjson/document.h" |
||||
|
||||
#include <string> |
||||
#include <algorithm> |
||||
#include <map> |
||||
|
||||
#include <boost/signal.hpp> |
||||
|
||||
namespace Transport { |
||||
|
||||
class Component; |
||||
class StorageBackend; |
||||
class HTTPRequest; |
||||
class SlackRTM; |
||||
|
||||
class SlackAPI : public HTTPRequestQueue { |
||||
public: |
||||
SlackAPI(Component *component, UserInfo uinfo); |
||||
|
||||
virtual ~SlackAPI(); |
||||
|
||||
void usersList(HTTPRequest::Callback callback); |
||||
std::string getOwnerId(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data); |
||||
|
||||
void imOpen(const std::string &uid, HTTPRequest::Callback callback); |
||||
std::string getChannelId(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data); |
||||
|
||||
void sendMessage(const std::string &from, const std::string &to, const std::string &text); |
||||
|
||||
private: |
||||
void handleSendMessage(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data); |
||||
|
||||
private: |
||||
Component *m_component; |
||||
UserInfo m_uinfo; |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* XMPP - libpurple transport |
||||
* |
||||
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im> |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation; either version 2 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
||||
*/ |
||||
|
||||
#include "SlackInstallation.h" |
||||
#include "SlackFrontend.h" |
||||
#include "SlackUser.h" |
||||
#include "SlackRTM.h" |
||||
#include "SlackAPI.h" |
||||
|
||||
#include "transport/Transport.h" |
||||
#include "transport/HTTPRequest.h" |
||||
#include "transport/Util.h" |
||||
|
||||
#include <boost/foreach.hpp> |
||||
#include <boost/make_shared.hpp> |
||||
#include <map> |
||||
#include <iterator> |
||||
|
||||
namespace Transport { |
||||
|
||||
DEFINE_LOGGER(logger, "SlackInstallation"); |
||||
|
||||
SlackInstallation::SlackInstallation(Component *component, StorageBackend *storageBackend, UserInfo uinfo) : m_uinfo(uinfo) { |
||||
m_component = component; |
||||
m_storageBackend = storageBackend; |
||||
m_api = new SlackAPI(component, uinfo); |
||||
|
||||
|
||||
m_api->usersList(boost::bind(&SlackInstallation::handleUsersList, this, _1, _2, _3, _4)); |
||||
// m_rtm = new SlackRTM(component, storageBackend, uinfo);
|
||||
} |
||||
|
||||
SlackInstallation::~SlackInstallation() { |
||||
// delete m_rtm;
|
||||
delete m_api; |
||||
} |
||||
|
||||
void SlackInstallation::handleImOpen(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data) { |
||||
std::string channel = m_api->getChannelId(req, ok, resp, data); |
||||
LOG4CXX_INFO(logger, "Opened channel with team owner: " << channel); |
||||
|
||||
std::string msg; |
||||
msg = "Hi, It seems you have authorized Spectrum 2 transport for your team. " |
||||
"As a team owner, you should now configure it. You should provide username and " |
||||
"password you want to use to connect your team to legacy network of your choice."; |
||||
m_api->sendMessage("Spectrum 2", channel, msg); |
||||
|
||||
msg = "You can do it by typing \".spectrum2 register <username> <password>\". Password may be optional."; |
||||
m_api->sendMessage("Spectrum 2", channel, msg); |
||||
|
||||
msg = "For example to connect the Freenode IRC network, just type \".spectrum2 register irc.freenode.net\"."; |
||||
m_api->sendMessage("Spectrum 2", channel, msg); |
||||
} |
||||
|
||||
void SlackInstallation::handleUsersList(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data) { |
||||
std::string ownerId = m_api->getOwnerId(req, ok, resp, data); |
||||
LOG4CXX_INFO(logger, "Team owner ID is " << ownerId); |
||||
|
||||
m_api->imOpen(ownerId, boost::bind(&SlackInstallation::handleImOpen, this, _1, _2, _3, _4)); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Spectrum 2 Slack Frontend |
||||
* |
||||
* Copyright (C) 2015, Jan Kaluza <hanzz.k@gmail.com> |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation; either version 2 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include "transport/StorageBackend.h" |
||||
#include "rapidjson/document.h" |
||||
|
||||
#include <string> |
||||
#include <algorithm> |
||||
#include <map> |
||||
|
||||
#include <boost/signal.hpp> |
||||
|
||||
namespace Transport { |
||||
|
||||
class Component; |
||||
class StorageBackend; |
||||
class HTTPRequest; |
||||
class SlackRTM; |
||||
class SlackAPI; |
||||
|
||||
class SlackInstallation { |
||||
public: |
||||
SlackInstallation(Component *component, StorageBackend *storageBackend, UserInfo uinfo); |
||||
|
||||
virtual ~SlackInstallation(); |
||||
|
||||
boost::signal<void (const std::string &user)> onInstallationDone; |
||||
|
||||
private: |
||||
void handleUsersList(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data); |
||||
void handleImOpen(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data); |
||||
|
||||
private: |
||||
Component *m_component; |
||||
StorageBackend *m_storageBackend; |
||||
UserInfo m_uinfo; |
||||
std::string m_ownerName; |
||||
SlackRTM *m_rtm; |
||||
SlackAPI *m_api; |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,120 @@
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* XMPP - libpurple transport |
||||
* |
||||
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im> |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation; either version 2 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
||||
*/ |
||||
|
||||
#include "SlackRTM.h" |
||||
#include "SlackFrontend.h" |
||||
#include "SlackUser.h" |
||||
|
||||
#include "transport/Transport.h" |
||||
#include "transport/HTTPRequest.h" |
||||
#include "transport/Util.h" |
||||
|
||||
#include <boost/foreach.hpp> |
||||
#include <boost/make_shared.hpp> |
||||
#include <map> |
||||
#include <iterator> |
||||
|
||||
namespace Transport { |
||||
|
||||
DEFINE_LOGGER(logger, "SlackRTM"); |
||||
|
||||
SlackRTM::SlackRTM(Component *component, StorageBackend *storageBackend, UserInfo uinfo) : m_uinfo(uinfo) { |
||||
m_component = component; |
||||
m_storageBackend = storageBackend; |
||||
|
||||
Swift::TLSOptions o; |
||||
Swift::PlatformTLSFactories *m_tlsFactory = new Swift::PlatformTLSFactories(); |
||||
m_tlsConnectionFactory = new Swift::TLSConnectionFactory(m_tlsFactory->getTLSContextFactory(), component->getNetworkFactories()->getConnectionFactory(), o); |
||||
|
||||
|
||||
std::string url = "https://slack.com/api/rtm.start?"; |
||||
url += "token=" + Util::urlencode(m_uinfo.encoding); |
||||
|
||||
// HTTPRequest *req = new HTTPRequest();
|
||||
// req->GET(THREAD_POOL(m_component), url,
|
||||
// boost::bind(&SlackRTM::handleRTMStart, this, _1, _2, _3, _4));
|
||||
} |
||||
|
||||
SlackRTM::~SlackRTM() { |
||||
|
||||
} |
||||
|
||||
void SlackRTM::handleRTMStart(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data) { |
||||
if (!ok) { |
||||
LOG4CXX_ERROR(logger, req->getError()); |
||||
LOG4CXX_ERROR(logger, data); |
||||
return; |
||||
} |
||||
|
||||
rapidjson::Value &url = resp["url"]; |
||||
if (!url.IsString()) { |
||||
LOG4CXX_ERROR(logger, "No 'url' object in the reply."); |
||||
LOG4CXX_ERROR(logger, data); |
||||
return; |
||||
} |
||||
|
||||
std::string u = url.GetString(); |
||||
LOG4CXX_INFO(logger, "Started RTM, WebSocket URL is " << u); |
||||
|
||||
u = u.substr(6); |
||||
m_host = u.substr(0, u.find("/")); |
||||
m_path = u.substr(u.find("/")); |
||||
|
||||
LOG4CXX_INFO(logger, "Starting DNS query for " << m_host << " " << m_path); |
||||
m_dnsQuery = m_component->getNetworkFactories()->getDomainNameResolver()->createAddressQuery(m_host); |
||||
m_dnsQuery->onResult.connect(boost::bind(&SlackRTM::handleDNSResult, this, _1, _2)); |
||||
m_dnsQuery->run(); |
||||
} |
||||
|
||||
void SlackRTM::handleDataRead(boost::shared_ptr<Swift::SafeByteArray> data) { |
||||
LOG4CXX_INFO(logger, "data read"); |
||||
std::string d = Swift::safeByteArrayToString(*data); |
||||
LOG4CXX_INFO(logger, d); |
||||
} |
||||
|
||||
void SlackRTM::handleConnected(bool error) { |
||||
if (error) { |
||||
LOG4CXX_ERROR(logger, "Connection to " << m_host << " failed"); |
||||
return; |
||||
} |
||||
|
||||
LOG4CXX_INFO(logger, "Connected to " << m_host); |
||||
|
||||
std::string req = ""; |
||||
req += "GET " + m_path + " HTTP/1.1\r\n"; |
||||
req += "Host: " + m_host + ":443\r\n"; |
||||
req += "Upgrade: websocket\r\n"; |
||||
req += "Connection: Upgrade\r\n"; |
||||
req += "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n"; |
||||
req += "Sec-WebSocket-Version: 13\r\n"; |
||||
req += "\r\n"; |
||||
|
||||
m_conn->write(Swift::createSafeByteArray(req)); |
||||
|
||||
} |
||||
|
||||
void SlackRTM::handleDNSResult(const std::vector<Swift::HostAddress> &addrs, boost::optional<Swift::DomainNameResolveError>) { |
||||
m_conn = m_tlsConnectionFactory->createConnection(); |
||||
m_conn->onDataRead.connect(boost::bind(&SlackRTM::handleDataRead, this, _1)); |
||||
m_conn->onConnectFinished.connect(boost::bind(&SlackRTM::handleConnected, this, _1)); |
||||
m_conn->connect(Swift::HostAddressPort(addrs[0], 443)); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Spectrum 2 Slack Frontend |
||||
* |
||||
* Copyright (C) 2015, Jan Kaluza <hanzz.k@gmail.com> |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation; either version 2 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include "transport/StorageBackend.h" |
||||
#include "rapidjson/document.h" |
||||
|
||||
#include <Swiften/Network/TLSConnectionFactory.h> |
||||
#include <Swiften/Network/HostAddressPort.h> |
||||
#include <Swiften/TLS/PlatformTLSFactories.h> |
||||
#include <Swiften/TLS/TLSOptions.h> |
||||
#include <Swiften/Network/DomainNameResolveError.h> |
||||
#include <Swiften/Network/DomainNameAddressQuery.h> |
||||
#include <Swiften/Network/DomainNameResolver.h> |
||||
#include <Swiften/Network/HostAddress.h> |
||||
#include <Swiften/Base/SafeByteArray.h> |
||||
|
||||
#include <string> |
||||
#include <algorithm> |
||||
#include <map> |
||||
|
||||
#include <boost/signal.hpp> |
||||
|
||||
namespace Transport { |
||||
|
||||
class Component; |
||||
class StorageBackend; |
||||
class HTTPRequest; |
||||
|
||||
class SlackRTM { |
||||
public: |
||||
SlackRTM(Component *component, StorageBackend *storageBackend, UserInfo uinfo); |
||||
|
||||
virtual ~SlackRTM(); |
||||
|
||||
private: |
||||
void handleDNSResult(const std::vector<Swift::HostAddress>&, boost::optional<Swift::DomainNameResolveError>); |
||||
void handleDataRead(boost::shared_ptr<Swift::SafeByteArray> data); |
||||
void handleConnected(bool error); |
||||
void handleRTMStart(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data); |
||||
|
||||
private: |
||||
Component *m_component; |
||||
StorageBackend *m_storageBackend; |
||||
UserInfo m_uinfo; |
||||
boost::shared_ptr<Swift::DomainNameAddressQuery> m_dnsQuery; |
||||
boost::shared_ptr<Swift::Connection> m_conn; |
||||
Swift::TLSConnectionFactory *m_tlsConnectionFactory; |
||||
std::string m_host; |
||||
std::string m_path; |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
#include "transport/HTTPRequestQueue.h" |
||||
#include "transport/HTTPRequest.h" |
||||
|
||||
namespace Transport { |
||||
|
||||
DEFINE_LOGGER(logger, "HTTPRequestQueue") |
||||
|
||||
HTTPRequestQueue::HTTPRequestQueue(int delay) { |
||||
m_delay = delay; |
||||
m_processing = false; |
||||
} |
||||
|
||||
HTTPRequestQueue::~HTTPRequestQueue() { |
||||
|
||||
} |
||||
|
||||
void HTTPRequestQueue::sendNextRequest() { |
||||
if (m_queue.empty()) { |
||||
m_processing = false; |
||||
return; |
||||
} |
||||
|
||||
if (m_processing) { |
||||
return; |
||||
} |
||||
|
||||
HTTPRequest *req = m_queue.front(); |
||||
m_queue.pop(); |
||||
req->onRequestFinished.connect(boost::bind(&HTTPRequestQueue::sendNextRequest, this)); |
||||
req->execute(); |
||||
} |
||||
|
||||
void HTTPRequestQueue::queueRequest(HTTPRequest *req) { |
||||
m_queue.push(req); |
||||
|
||||
if (!m_processing) { |
||||
sendNextRequest(); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |