summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swiften/Base/LogSerializers.cpp54
-rw-r--r--Swiften/Base/LogSerializers.h5
-rw-r--r--Swiften/Network/BOSHConnection.h4
3 files changed, 59 insertions, 4 deletions
diff --git a/Swiften/Base/LogSerializers.cpp b/Swiften/Base/LogSerializers.cpp
index 5ac1e15..3f8e9ce 100644
--- a/Swiften/Base/LogSerializers.cpp
+++ b/Swiften/Base/LogSerializers.cpp
@@ -1,78 +1,130 @@
/*
- * Copyright (c) 2016 Isode Limited.
+ * Copyright (c) 2016-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/Base/LogSerializers.h>
#include <Swiften/Elements/Presence.h>
+#include <Swiften/Network/BOSHConnection.h>
namespace Swift {
std::ostream& operator<<(std::ostream& stream, const Presence& presence) {
std::string typeString;
switch (presence.getType()) {
case Presence::Available:
typeString = "Available";
break;
case Presence::Error:
typeString = "Error";
break;
case Presence::Probe:
typeString = "Probe";
break;
case Presence::Subscribe:
typeString = "Subscribe";
break;
case Presence::Subscribed:
typeString = "Subscribed";
break;
case Presence::Unavailable:
typeString = "Unavailable";
break;
case Presence::Unsubscribe:
typeString = "Unsubscribe";
break;
case Presence::Unsubscribed:
typeString = "Unsubscribed";
break;
}
std::string showTypeString;
switch (presence.getShow()) {
case StatusShow::Online:
showTypeString = "Online";
break;
case StatusShow::Away:
showTypeString = "Away";
break;
case StatusShow::FFC:
showTypeString = "FFC";
break;
case StatusShow::DND:
showTypeString = "DND";
break;
case StatusShow::XA:
showTypeString = "XA";
break;
case StatusShow::None:
showTypeString = "None";
break;
}
stream << "Presence(" << "from: " << presence.getFrom() << ", to: " << presence.getTo() << ", type: " << typeString << ", status: " << showTypeString << ", priority: " << presence.getPriority() << ", '" << presence.getStatus() << "'" << " )";
return stream;
}
+std::ostream& operator<<(std::ostream& stream, const BOSHError& boshError) {
+ std::string errorString;
+ switch (boshError.getType()) {
+ case BOSHError::BadRequest:
+ errorString = "BadRequest";
+ break;
+ case BOSHError::HostGone:
+ errorString = "HostGone";
+ break;
+ case BOSHError::HostUnknown:
+ errorString = "HostUnknown";
+ break;
+ case BOSHError::ImproperAddressing:
+ errorString = "ImproperAddressing";
+ break;
+ case BOSHError::InternalServerError:
+ errorString = "InternalServerError";
+ break;
+ case BOSHError::ItemNotFound:
+ errorString = "ItemNotFound";
+ break;
+ case BOSHError::OtherRequest:
+ errorString = "OtherRequest";
+ break;
+ case BOSHError::PolicyViolation:
+ errorString = "PolicyViolation";
+ break;
+ case BOSHError::RemoteConnectionFailed:
+ errorString = "RemoteConnectionFailed";
+ break;
+ case BOSHError::RemoteStreamError:
+ errorString = "RemoteStreamError";
+ break;
+ case BOSHError::SeeOtherURI:
+ errorString = "SeeOtherURI";
+ break;
+ case BOSHError::SystemShutdown:
+ errorString = "SystemShutdown";
+ break;
+ case BOSHError::UndefinedCondition:
+ errorString = "UndefinedCondition";
+ break;
+ case BOSHError::NoError:
+ errorString = "NoError";
+ break;
+ }
+
+ stream << "BOSHError( " << errorString << " )";
+ return stream;
+}
+
};
::std::ostream& operator<<(::std::ostream& os, const boost::optional<std::string>& optStr) {
if (optStr.is_initialized()) {
return os << "boost::optional<std::string>(\"" << optStr.get() << "\")";
}
else {
return os << "boost::optional<std::string>()";
}
}
diff --git a/Swiften/Base/LogSerializers.h b/Swiften/Base/LogSerializers.h
index be992bb..b804808 100644
--- a/Swiften/Base/LogSerializers.h
+++ b/Swiften/Base/LogSerializers.h
@@ -1,52 +1,55 @@
/*
- * Copyright (c) 2016 Isode Limited.
+ * Copyright (c) 2016-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
#include <memory>
#include <ostream>
#include <string>
#include <vector>
#include <boost/optional.hpp>
namespace Swift {
class Presence;
+class BOSHError;
template <typename T>
std::ostream& operator<<(std::ostream& stream, const std::shared_ptr<T>& ptr) {
if (ptr) {
stream << *ptr;
}
else {
stream << "nullptr";
}
return stream;
}
template <typename T>
std::ostream& operator<<(std::ostream& stream, const std::vector<T>& vec) {
stream << "[";
if (!vec.empty()) {
auto it = std::begin(vec);
stream << *it;
++it;
for (auto end = std::end(vec); it != end; ++it) {
stream << ", " << *it;
}
}
stream << "]";
return stream;
}
std::ostream& operator<<(std::ostream& stream, const Presence& presence);
+std::ostream& operator<<(std::ostream& stream, const BOSHError& boshError);
+
};
::std::ostream& operator<<(::std::ostream& os, const boost::optional<std::string>& optStr);
diff --git a/Swiften/Network/BOSHConnection.h b/Swiften/Network/BOSHConnection.h
index b75e51f..1409ae6 100644
--- a/Swiften/Network/BOSHConnection.h
+++ b/Swiften/Network/BOSHConnection.h
@@ -1,83 +1,83 @@
/*
* Copyright (c) 2011 Thilo Cestonaro
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
- * Copyright (c) 2011-2016 Isode Limited.
+ * Copyright (c) 2011-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
#include <memory>
#include <Swiften/Base/API.h>
#include <Swiften/Base/Error.h>
#include <Swiften/Base/String.h>
#include <Swiften/Base/URL.h>
#include <Swiften/Network/Connection.h>
#include <Swiften/Network/Connector.h>
#include <Swiften/Network/HostAddressPort.h>
#include <Swiften/Session/SessionStream.h>
#include <Swiften/TLS/TLSError.h>
namespace boost {
class thread;
namespace system {
class error_code;
}
}
class BOSHConnectionTest;
namespace Swift {
class XMLParserFactory;
class TLSContextFactory;
class TLSLayer;
struct TLSOptions;
class HighLayer;
class SWIFTEN_API BOSHError : public SessionStream::SessionStreamError {
public:
enum Type {
BadRequest, HostGone, HostUnknown, ImproperAddressing,
InternalServerError, ItemNotFound, OtherRequest, PolicyViolation,
RemoteConnectionFailed, RemoteStreamError, SeeOtherURI, SystemShutdown, UndefinedCondition,
NoError};
BOSHError(Type type) : SessionStream::SessionStreamError(SessionStream::SessionStreamError::ConnectionReadError), type(type) {}
- Type getType() {return type;}
+ Type getType() const {return type;}
typedef std::shared_ptr<BOSHError> ref;
private:
Type type;
};
class SWIFTEN_API BOSHConnection : public std::enable_shared_from_this<BOSHConnection> {
public:
typedef std::shared_ptr<BOSHConnection> ref;
static ref create(const URL& boshURL, Connector::ref connector, XMLParserFactory* parserFactory, TLSContextFactory* tlsContextFactory, const TLSOptions& tlsOptions) {
return ref(new BOSHConnection(boshURL, connector, parserFactory, tlsContextFactory, tlsOptions));
}
virtual ~BOSHConnection();
virtual void connect();
virtual void disconnect();
virtual void write(const SafeByteArray& data);
const std::string& getSID();
void setRID(unsigned long long rid);
void setSID(const std::string& sid);
void startStream(const std::string& to, unsigned long long rid);
void terminateStream();
bool isReadyToSend();
void restartStream();
bool setClientCertificate(CertificateWithKey::ref cert);
Certificate::ref getPeerCertificate() const;
std::vector<Certificate::ref> getPeerCertificateChain() const;
CertificateVerificationError::ref getPeerCertificateVerificationError() const;