diff options
Diffstat (limited to 'Sluift')
| -rw-r--r-- | Sluift/ElementConvertors/StatusShowConvertor.cpp | 14 | ||||
| -rw-r--r-- | Sluift/Helpers.cpp | 35 | ||||
| -rw-r--r-- | Sluift/Helpers.h | 1 | ||||
| -rw-r--r-- | Sluift/SluiftComponent.cpp | 2 | ||||
| -rw-r--r-- | Sluift/SluiftComponent.h | 1 |
5 files changed, 27 insertions, 26 deletions
diff --git a/Sluift/ElementConvertors/StatusShowConvertor.cpp b/Sluift/ElementConvertors/StatusShowConvertor.cpp index d8e24ab..27876ff 100644 --- a/Sluift/ElementConvertors/StatusShowConvertor.cpp +++ b/Sluift/ElementConvertors/StatusShowConvertor.cpp @@ -1,74 +1,74 @@ /* * Copyright (c) 2014 Remko Tronçon * Licensed under the GNU General Public License. * See the COPYING file for more information. */ #include <Sluift/ElementConvertors/StatusShowConvertor.h> #include <lua.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <boost/numeric/conversion/cast.hpp> #include <Sluift/Lua/Check.h> #include <Sluift/Lua/Exception.h> using namespace Swift; StatusShowConvertor::StatusShowConvertor() : GenericLuaElementConvertor<StatusShow>("show") { } StatusShowConvertor::~StatusShowConvertor() { } boost::shared_ptr<StatusShow> StatusShowConvertor::doConvertFromLua(lua_State* L) { boost::shared_ptr<StatusShow> result = boost::make_shared<StatusShow>(); lua_getfield(L, -1, "type"); if (lua_isstring(L, -1)) { result->setType(convertStatusShowTypeFromString(lua_tostring(L, -1))); } lua_pop(L, 1); return result; } void StatusShowConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<StatusShow> payload) { lua_createtable(L, 0, 0); - const std::string show = convertStatusShowTypeToString(payload->getType()); + const std::string show = convertStatusShowTypeToString(payload->getType()); if (!show.empty()) { lua_pushstring(L, show.c_str()); lua_setfield(L, -2, "type"); } } std::string StatusShowConvertor::convertStatusShowTypeToString(const StatusShow::Type &show) { switch (show) { - case StatusShow::Online: return "online"; break; - case StatusShow::FFC: return "ffc"; break; - case StatusShow::Away: return "away"; break; - case StatusShow::XA: return "xa"; break; - case StatusShow::DND: return "dnd"; break; - case StatusShow::None: return ""; break; + case StatusShow::Online: return "online"; + case StatusShow::FFC: return "ffc"; + case StatusShow::Away: return "away"; + case StatusShow::XA: return "xa"; + case StatusShow::DND: return "dnd"; + case StatusShow::None: return ""; } assert(false); return ""; } StatusShow::Type StatusShowConvertor::convertStatusShowTypeFromString(const std::string& show) { if (show == "online") { return StatusShow::Online; } else if (show == "ffc") { return StatusShow::FFC; } else if (show == "away") { return StatusShow::Away; } else if (show == "xa") { return StatusShow::XA; } else if (show == "dnd") { return StatusShow::DND; } else { throw Lua::Exception("Illegal status show: '" + show + "'"); } } diff --git a/Sluift/Helpers.cpp b/Sluift/Helpers.cpp index 29e2b04..756ae59 100644 --- a/Sluift/Helpers.cpp +++ b/Sluift/Helpers.cpp @@ -1,62 +1,65 @@ /* * Copyright (c) 2013-2014 Kevin Smith and Remko Tronçon * Licensed under the GNU General Public License. * See the COPYING file for more information. */ #include <Sluift/Helpers.h> #include <Swiften/Client/ClientError.h> #include <Swiften/Component/ComponentError.h> using namespace Swift; -template<class T> std::string Swift::getCommonErrorString(T& error) { - std::string reason = "Disconnected: "; - switch(error.getType()) { - case T::UnknownError: reason += "Unknown Error"; break; - case T::ConnectionError: reason += "Error connecting to server"; break; - case T::ConnectionReadError: reason += "Error while receiving server data"; break; - case T::ConnectionWriteError: reason += "Error while sending data to the server"; break; - case T::XMLError: reason += "Error parsing server data"; break; - case T::AuthenticationFailedError: reason += "Login/password invalid"; break; - case T::UnexpectedElementError: reason += "Unexpected response"; break; - } - return reason; -} - std::string Swift::getErrorString(const ClientError& error) { - std::string reason = getCommonErrorString(error); + std::string reason = "Disconnected: "; switch(error.getType()) { + case ClientError::UnknownError: reason += "Unknown Error"; break; + case ClientError::ConnectionError: reason += "Error connecting to server"; break; + case ClientError::ConnectionReadError: reason += "Error while receiving server data"; break; + case ClientError::ConnectionWriteError: reason += "Error while sending data to the server"; break; + case ClientError::XMLError: reason += "Error parsing server data"; break; + case ClientError::AuthenticationFailedError: reason += "Login/password invalid"; break; + case ClientError::UnexpectedElementError: reason += "Unexpected response"; break; case ClientError::DomainNameResolveError: reason += "Unable to find server"; break; case ClientError::CompressionFailedError: reason += "Error while compressing stream"; break; case ClientError::ServerVerificationFailedError: reason += "Server verification failed"; break; case ClientError::NoSupportedAuthMechanismsError: reason += "Authentication mechanisms not supported"; break; case ClientError::ResourceBindError: reason += "Error binding resource"; break; case ClientError::RevokedError: reason += "Certificate got revoked"; break; case ClientError::RevocationCheckFailedError: reason += "Failed to do revokation check"; break; case ClientError::SessionStartError: reason += "Error starting session"; break; case ClientError::StreamError: reason += "Stream error"; break; case ClientError::TLSError: reason += "Encryption error"; break; case ClientError::ClientCertificateLoadError: reason += "Error loading certificate (Invalid password?)"; break; case ClientError::ClientCertificateError: reason += "Certificate not authorized"; break; case ClientError::UnknownCertificateError: reason += "Unknown certificate"; break; case ClientError::CertificateCardRemoved: reason += "Certificate card removed"; break; case ClientError::CertificateExpiredError: reason += "Certificate has expired"; break; case ClientError::CertificateNotYetValidError: reason += "Certificate is not yet valid"; break; case ClientError::CertificateSelfSignedError: reason += "Certificate is self-signed"; break; case ClientError::CertificateRejectedError: reason += "Certificate has been rejected"; break; case ClientError::CertificateUntrustedError: reason += "Certificate is not trusted"; break; case ClientError::InvalidCertificatePurposeError: reason += "Certificate cannot be used for encrypting your connection"; break; case ClientError::CertificatePathLengthExceededError: reason += "Certificate path length constraint exceeded"; break; case ClientError::InvalidCertificateSignatureError: reason += "Invalid certificate signature"; break; case ClientError::InvalidCAError: reason += "Invalid Certificate Authority"; break; case ClientError::InvalidServerIdentityError: reason += "Certificate does not match the host identity"; break; } return reason; } std::string Swift::getErrorString(const ComponentError& error) { - return getCommonErrorString(error); + std::string reason = "Disconnected: "; + switch(error.getType()) { + case ComponentError::UnknownError: reason += "Unknown Error"; break; + case ComponentError::ConnectionError: reason += "Error connecting to server"; break; + case ComponentError::ConnectionReadError: reason += "Error while receiving server data"; break; + case ComponentError::ConnectionWriteError: reason += "Error while sending data to the server"; break; + case ComponentError::XMLError: reason += "Error parsing server data"; break; + case ComponentError::AuthenticationFailedError: reason += "Login/password invalid"; break; + case ComponentError::UnexpectedElementError: reason += "Unexpected response"; break; + } + return reason; } diff --git a/Sluift/Helpers.h b/Sluift/Helpers.h index d04a610..157e116 100644 --- a/Sluift/Helpers.h +++ b/Sluift/Helpers.h @@ -1,21 +1,20 @@ /* * Copyright (c) 2013-2014 Kevin Smith and Remko Tronçon * Licensed under the GNU General Public License. * See the COPYING file for more information. */ #pragma once #include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> #include <string> namespace Swift { class ClientError; class ComponentError; - template<typename T> std::string getCommonErrorString(T& error); std::string getErrorString(const ClientError& error); std::string getErrorString(const ComponentError& error); } diff --git a/Sluift/SluiftComponent.cpp b/Sluift/SluiftComponent.cpp index c08a103..c8a17a7 100644 --- a/Sluift/SluiftComponent.cpp +++ b/Sluift/SluiftComponent.cpp @@ -47,71 +47,71 @@ void SluiftComponent::connect(const std::string& host, int port) { void SluiftComponent::setTraceEnabled(bool b) { if (b && !tracer) { tracer = new ComponentXMLTracer(component); } else if (!b && tracer) { delete tracer; tracer = NULL; } } void SluiftComponent::waitConnected(int timeout) { Watchdog watchdog(timeout, networkFactories->getTimerFactory()); while (!watchdog.getTimedOut() && !disconnectedError && !component->isAvailable()) { eventLoop->runUntilEvents(); } if (watchdog.getTimedOut()) { component->disconnect(); throw Lua::Exception("Timeout while connecting"); } if (disconnectedError) { throw Lua::Exception(getErrorString(*disconnectedError)); } } bool SluiftComponent::isConnected() const { return component->isAvailable(); } void SluiftComponent::disconnect() { component->disconnect(); while (component->isAvailable()) { eventLoop->runUntilEvents(); } } -void SluiftComponent::setSoftwareVersion(const std::string& name, const std::string& version, const std::string& os) { +void SluiftComponent::setSoftwareVersion(const std::string& name, const std::string& version, const std::string& /* os */) { component->setSoftwareVersion(name, version); } boost::optional<SluiftComponent::Event> SluiftComponent::getNextEvent( int timeout, boost::function<bool (const Event&)> condition) { Watchdog watchdog(timeout, networkFactories->getTimerFactory()); size_t currentIndex = 0; while (true) { // Look for pending events in the queue while (currentIndex < pendingEvents.size()) { Event event = pendingEvents[currentIndex]; if (!condition || condition(event)) { pendingEvents.erase( pendingEvents.begin() + boost::numeric_cast<int>(currentIndex)); return event; } ++currentIndex; } // Wait for new events while (!watchdog.getTimedOut() && currentIndex >= pendingEvents.size() && component->isAvailable()) { eventLoop->runUntilEvents(); } // Finish if we're disconnected or timed out if (watchdog.getTimedOut() || !component->isAvailable()) { return boost::optional<Event>(); } } } void SluiftComponent::handleIncomingMessage(boost::shared_ptr<Message> stanza) { pendingEvents.push_back(Event(stanza)); } diff --git a/Sluift/SluiftComponent.h b/Sluift/SluiftComponent.h index 3d5792b..ba848e1 100644 --- a/Sluift/SluiftComponent.h +++ b/Sluift/SluiftComponent.h @@ -66,43 +66,42 @@ namespace Swift { bool isConnected() const; void setTraceEnabled(bool b); template<typename REQUEST_TYPE> Sluift::Response sendRequest(REQUEST_TYPE request, int timeout) { boost::signals::scoped_connection c = request->onResponse.connect( boost::bind(&SluiftComponent::handleRequestResponse, this, _1, _2)); return doSendRequest(request, timeout); } template<typename REQUEST_TYPE> Sluift::Response sendVoidRequest(REQUEST_TYPE request, int timeout) { boost::signals::scoped_connection c = request->onResponse.connect( boost::bind(&SluiftComponent::handleRequestResponse, this, boost::shared_ptr<Payload>(), _1)); return doSendRequest(request, timeout); } void disconnect(); void setSoftwareVersion(const std::string& name, const std::string& version, const std::string& os); boost::optional<SluiftComponent::Event> getNextEvent(int timeout, boost::function<bool (const Event&)> condition = 0); private: Sluift::Response doSendRequest(boost::shared_ptr<Request> request, int timeout); void handleIncomingMessage(boost::shared_ptr<Message> stanza); void handleIncomingPresence(boost::shared_ptr<Presence> stanza); void handleRequestResponse(boost::shared_ptr<Payload> response, boost::shared_ptr<ErrorPayload> error); void handleError(const boost::optional<ComponentError>& error); private: NetworkFactories* networkFactories; SimpleEventLoop* eventLoop; Component* component; ComponentXMLTracer* tracer; - bool rosterReceived; std::deque<Event> pendingEvents; boost::optional<ComponentError> disconnectedError; bool requestResponseReceived; boost::shared_ptr<Payload> requestResponse; boost::shared_ptr<ErrorPayload> requestError; }; } |
Swift