summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Network')
-rw-r--r--Swiften/Network/BOSHConnection.cpp2
-rw-r--r--Swiften/Network/FakeConnection.cpp4
-rw-r--r--Swiften/Network/NATPMPInterface.cpp8
3 files changed, 10 insertions, 4 deletions
diff --git a/Swiften/Network/BOSHConnection.cpp b/Swiften/Network/BOSHConnection.cpp
index bde689e..28e27d5 100644
--- a/Swiften/Network/BOSHConnection.cpp
+++ b/Swiften/Network/BOSHConnection.cpp
@@ -253,48 +253,48 @@ BOSHError::Type BOSHConnection::parseTerminationCondition(const std::string& tex
else if (text == "policy-violation") {
condition = BOSHError::PolicyViolation;
}
else if (text == "remote-connection-failed") {
condition = BOSHError::RemoteConnectionFailed;
}
else if (text == "remote-stream-error") {
condition = BOSHError::RemoteStreamError;
}
else if (text == "see-other-uri") {
condition = BOSHError::SeeOtherURI;
}
else if (text == "system-shutdown") {
condition = BOSHError::SystemShutdown;
}
else if (text == "") {
condition = BOSHError::NoError;
}
return condition;
}
const std::string& BOSHConnection::getSID() {
return sid_;
}
void BOSHConnection::setRID(unsigned long long rid) {
rid_ = rid;
}
void BOSHConnection::setSID(const std::string& sid) {
sid_ = sid;
}
void BOSHConnection::handleDisconnected(const boost::optional<Connection::Error>& error) {
cancelConnector();
- onDisconnected(error);
+ onDisconnected(error ? true : false);
sid_ = "";
connectionReady_ = false;
}
bool BOSHConnection::isReadyToSend() {
/* Without pipelining you need to not send more without first receiving the response */
/* With pipelining you can. Assuming we can't, here */
return connectionReady_ && !pending_ && !waitingForStartResponse_ && !sid_.empty();
}
}
diff --git a/Swiften/Network/FakeConnection.cpp b/Swiften/Network/FakeConnection.cpp
index be5555c..a84c92e 100644
--- a/Swiften/Network/FakeConnection.cpp
+++ b/Swiften/Network/FakeConnection.cpp
@@ -1,64 +1,64 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <Swiften/Network/FakeConnection.h>
#include <boost/bind.hpp>
namespace Swift {
FakeConnection::FakeConnection(EventLoop* eventLoop) : eventLoop(eventLoop), state(Initial), delayConnect(false) {
}
FakeConnection::~FakeConnection() {
}
void FakeConnection::listen() {
assert(false);
}
void FakeConnection::setError(const Error& e) {
error = boost::optional<Error>(e);
state = DisconnectedWithError;
if (connectedTo) {
eventLoop->postEvent(
boost::bind(boost::ref(onDisconnected), error),
shared_from_this());
}
}
void FakeConnection::connect(const HostAddressPort& address) {
if (delayConnect) {
state = Connecting;
}
else {
if (!error) {
connectedTo = address;
state = Connected;
}
else {
state = DisconnectedWithError;
}
eventLoop->postEvent(
- boost::bind(boost::ref(onConnectFinished), error),
+ boost::bind(boost::ref(onConnectFinished), error ? true : false),
shared_from_this());
}
}
void FakeConnection::disconnect() {
if (!error) {
state = Disconnected;
}
else {
state = DisconnectedWithError;
}
connectedTo.reset();
eventLoop->postEvent(
boost::bind(boost::ref(onDisconnected), error),
shared_from_this());
}
}
diff --git a/Swiften/Network/NATPMPInterface.cpp b/Swiften/Network/NATPMPInterface.cpp
index c7a41ff..dcae641 100644
--- a/Swiften/Network/NATPMPInterface.cpp
+++ b/Swiften/Network/NATPMPInterface.cpp
@@ -1,70 +1,76 @@
/*
* Copyright (c) 2011 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+* Copyright (c) 2014 Kevin Smith
+* Licensed under the GNU General Public License v3.
+* See Documentation/Licenses/GPLv3.txt for more information.
+*/
+
#include <Swiften/Network/NATPMPInterface.h>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <Swiften/Base/Log.h>
// This has to be included after the previous headers, because of WIN32 macro
// being defined somewhere.
#include <natpmp.h>
#pragma GCC diagnostic ignored "-Wold-style-cast"
namespace Swift {
struct NATPMPInterface::Private {
natpmp_t natpmp;
};
NATPMPInterface::NATPMPInterface() : p(boost::make_shared<Private>()) {
initnatpmp(&p->natpmp, 0, 0);
}
NATPMPInterface::~NATPMPInterface() {
closenatpmp(&p->natpmp);
}
bool NATPMPInterface::isAvailable() {
- return getPublicIP();
+ return getPublicIP() ? true : false;
}
boost::optional<HostAddress> NATPMPInterface::getPublicIP() {
if (sendpublicaddressrequest(&p->natpmp) < 0) {
SWIFT_LOG(debug) << "Failed to send NAT-PMP public address request!" << std::endl;
return boost::optional<HostAddress>();
}
int r = 0;
natpmpresp_t response;
do {
fd_set fds;
struct timeval timeout;
FD_ZERO(&fds);
FD_SET(p->natpmp.s, &fds);
getnatpmprequesttimeout(&p->natpmp, &timeout);
select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
r = readnatpmpresponseorretry(&p->natpmp, &response);
} while (r == NATPMP_TRYAGAIN);
if (r == 0) {
return boost::optional<HostAddress>(HostAddress(reinterpret_cast<const unsigned char*>(&(response.pnu.publicaddress.addr)), 4));
}
else {
SWIFT_LOG(debug) << "Inavlid NAT-PMP response." << std::endl;
return boost::optional<HostAddress>();
}
}
boost::optional<NATPortMapping> NATPMPInterface::addPortForward(int localPort, int publicPort) {
NATPortMapping mapping(localPort, publicPort, NATPortMapping::TCP);
if (sendnewportmappingrequest(
&p->natpmp,
mapping.getProtocol() == NATPortMapping::TCP ? NATPMP_PROTOCOL_TCP : NATPMP_PROTOCOL_UDP,
boost::numeric_cast<uint16_t>(mapping.getLocalPort()),