diff options
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Base/SafeByteArray.h | 6 | ||||
-rw-r--r-- | Swiften/Base/SafeString.h | 2 | ||||
-rw-r--r-- | Swiften/Client/ClientXMLTracer.cpp | 6 | ||||
-rw-r--r-- | Swiften/Client/ClientXMLTracer.h | 3 | ||||
-rw-r--r-- | Swiften/Client/CoreClient.cpp | 4 | ||||
-rw-r--r-- | Swiften/Client/CoreClient.h | 9 | ||||
-rw-r--r-- | Swiften/Component/ComponentXMLTracer.cpp | 4 | ||||
-rw-r--r-- | Swiften/Component/ComponentXMLTracer.h | 2 | ||||
-rw-r--r-- | Swiften/Component/CoreComponent.cpp | 4 | ||||
-rw-r--r-- | Swiften/Component/CoreComponent.h | 9 | ||||
-rw-r--r-- | Swiften/Session/BasicSessionStream.cpp | 4 | ||||
-rw-r--r-- | Swiften/Session/SessionStream.h | 5 |
12 files changed, 36 insertions, 22 deletions
diff --git a/Swiften/Base/SafeByteArray.h b/Swiften/Base/SafeByteArray.h index 832b116..2f3fbfa 100644 --- a/Swiften/Base/SafeByteArray.h +++ b/Swiften/Base/SafeByteArray.h @@ -39,5 +39,11 @@ namespace Swift { } SafeByteArray createSafeByteArray(const SafeString& s); + + /* WARNING! This breaks the safety of the data in the safe byte array. + * Do not use in modes that require data safety. */ + inline std::string safeByteArrayToString(const SafeByteArray& b) { + return byteArrayToString(ByteArray(b.begin(), b.end())); + } } diff --git a/Swiften/Base/SafeString.h b/Swiften/Base/SafeString.h index bb6d6c7..d549bd1 100644 --- a/Swiften/Base/SafeString.h +++ b/Swiften/Base/SafeString.h @@ -26,6 +26,8 @@ namespace Swift { SafeString(const char*); + SafeString(const char* begin, const char* end) : data(begin, end) { + } std::string toString() const { return data.empty() ? std::string() : std::string(&data[0], data.size()); diff --git a/Swiften/Client/ClientXMLTracer.cpp b/Swiften/Client/ClientXMLTracer.cpp index a26ce66..441da9b 100644 --- a/Swiften/Client/ClientXMLTracer.cpp +++ b/Swiften/Client/ClientXMLTracer.cpp @@ -9,6 +9,8 @@ #include <iostream> #include <boost/bind.hpp> +#include <Swiften/Base/SafeString.h> + namespace Swift { ClientXMLTracer::ClientXMLTracer(CoreClient* client) { @@ -16,9 +18,9 @@ ClientXMLTracer::ClientXMLTracer(CoreClient* client) { client->onDataWritten.connect(boost::bind(&ClientXMLTracer::printData, '>', _1)); } -void ClientXMLTracer::printData(char direction, const std::string& data) { +void ClientXMLTracer::printData(char direction, const SafeByteArray& data) { printLine(direction); - std::cerr << data << std::endl; + std::cerr << byteArrayToString(ByteArray(data.begin(), data.end())) << std::endl; } void ClientXMLTracer::printLine(char c) { diff --git a/Swiften/Client/ClientXMLTracer.h b/Swiften/Client/ClientXMLTracer.h index 617c53f..dd94e0e 100644 --- a/Swiften/Client/ClientXMLTracer.h +++ b/Swiften/Client/ClientXMLTracer.h @@ -7,6 +7,7 @@ #pragma once #include <Swiften/Client/CoreClient.h> +#include <Swiften/Base/SafeByteArray.h> namespace Swift { class ClientXMLTracer { @@ -14,7 +15,7 @@ namespace Swift { ClientXMLTracer(CoreClient* client); private: - static void printData(char direction, const std::string& data); + static void printData(char direction, const SafeByteArray& data); static void printLine(char c); }; } diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp index 9907f5d..9eec7ca 100644 --- a/Swiften/Client/CoreClient.cpp +++ b/Swiften/Client/CoreClient.cpp @@ -260,11 +260,11 @@ void CoreClient::handleNeedCredentials() { } } -void CoreClient::handleDataRead(const std::string& data) { +void CoreClient::handleDataRead(const SafeByteArray& data) { onDataRead(data); } -void CoreClient::handleDataWritten(const std::string& data) { +void CoreClient::handleDataWritten(const SafeByteArray& data) { onDataWritten(data); } diff --git a/Swiften/Client/CoreClient.h b/Swiften/Client/CoreClient.h index 9806d35..841c32c 100644 --- a/Swiften/Client/CoreClient.h +++ b/Swiften/Client/CoreClient.h @@ -15,6 +15,7 @@ #include <Swiften/Client/ClientError.h> #include <Swiften/Client/ClientOptions.h> #include <Swiften/Base/SafeString.h> +#include <Swiften/Base/SafeByteArray.h> namespace Swift { class ChainedConnector; @@ -156,7 +157,7 @@ namespace Swift { * This signal is emitted before the XML data is parsed, * so this data is unformatted. */ - boost::signal<void (const std::string&)> onDataRead; + boost::signal<void (const SafeByteArray&)> onDataRead; /** * Emitted when the client sends data. @@ -164,7 +165,7 @@ namespace Swift { * This signal is emitted after the XML was serialized, and * is unformatted. */ - boost::signal<void (const std::string&)> onDataWritten; + boost::signal<void (const SafeByteArray&)> onDataWritten; /** * Emitted when a message is received. @@ -194,8 +195,8 @@ namespace Swift { void handleStanzaChannelAvailableChanged(bool available); void handleSessionFinished(boost::shared_ptr<Error>); void handleNeedCredentials(); - void handleDataRead(const std::string&); - void handleDataWritten(const std::string&); + void handleDataRead(const SafeByteArray&); + void handleDataWritten(const SafeByteArray&); void handlePresenceReceived(boost::shared_ptr<Presence>); void handleMessageReceived(boost::shared_ptr<Message>); void handleStanzaAcked(boost::shared_ptr<Stanza>); diff --git a/Swiften/Component/ComponentXMLTracer.cpp b/Swiften/Component/ComponentXMLTracer.cpp index b952c29..d77eef7 100644 --- a/Swiften/Component/ComponentXMLTracer.cpp +++ b/Swiften/Component/ComponentXMLTracer.cpp @@ -16,9 +16,9 @@ ComponentXMLTracer::ComponentXMLTracer(CoreComponent* client) { client->onDataWritten.connect(boost::bind(&ComponentXMLTracer::printData, '>', _1)); } -void ComponentXMLTracer::printData(char direction, const std::string& data) { +void ComponentXMLTracer::printData(char direction, const SafeByteArray& data) { printLine(direction); - std::cerr << data << std::endl; + std::cerr << byteArrayToString(ByteArray(data.begin(), data.end())) << std::endl; } void ComponentXMLTracer::printLine(char c) { diff --git a/Swiften/Component/ComponentXMLTracer.h b/Swiften/Component/ComponentXMLTracer.h index 2db690f..c12ec07 100644 --- a/Swiften/Component/ComponentXMLTracer.h +++ b/Swiften/Component/ComponentXMLTracer.h @@ -14,7 +14,7 @@ namespace Swift { ComponentXMLTracer(CoreComponent* component); private: - static void printData(char direction, const std::string& data); + static void printData(char direction, const SafeByteArray& data); static void printLine(char c); }; } diff --git a/Swiften/Component/CoreComponent.cpp b/Swiften/Component/CoreComponent.cpp index 7f02768..7ee1ff5 100644 --- a/Swiften/Component/CoreComponent.cpp +++ b/Swiften/Component/CoreComponent.cpp @@ -139,11 +139,11 @@ void CoreComponent::handleSessionFinished(boost::shared_ptr<Error> error) { } } -void CoreComponent::handleDataRead(const std::string& data) { +void CoreComponent::handleDataRead(const SafeByteArray& data) { onDataRead(data); } -void CoreComponent::handleDataWritten(const std::string& data) { +void CoreComponent::handleDataWritten(const SafeByteArray& data) { onDataWritten(data); } diff --git a/Swiften/Component/CoreComponent.h b/Swiften/Component/CoreComponent.h index 26f0024..e7945d1 100644 --- a/Swiften/Component/CoreComponent.h +++ b/Swiften/Component/CoreComponent.h @@ -22,6 +22,7 @@ #include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> #include <Swiften/Component/ComponentSessionStanzaChannel.h> #include <Swiften/Entity/Entity.h> +#include <Swiften/Base/SafeByteArray.h> namespace Swift { class IQRouter; @@ -72,8 +73,8 @@ namespace Swift { public: boost::signal<void (const ComponentError&)> onError; boost::signal<void ()> onConnected; - boost::signal<void (const std::string&)> onDataRead; - boost::signal<void (const std::string&)> onDataWritten; + boost::signal<void (const SafeByteArray&)> onDataRead; + boost::signal<void (const SafeByteArray&)> onDataWritten; boost::signal<void (boost::shared_ptr<Message>)> onMessageReceived; boost::signal<void (boost::shared_ptr<Presence>) > onPresenceReceived; @@ -82,8 +83,8 @@ namespace Swift { void handleConnectorFinished(boost::shared_ptr<Connection>); void handleStanzaChannelAvailableChanged(bool available); void handleSessionFinished(boost::shared_ptr<Error>); - void handleDataRead(const std::string&); - void handleDataWritten(const std::string&); + void handleDataRead(const SafeByteArray&); + void handleDataWritten(const SafeByteArray&); private: EventLoop* eventLoop; diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp index a1ec907..d08be4f 100644 --- a/Swiften/Session/BasicSessionStream.cpp +++ b/Swiften/Session/BasicSessionStream.cpp @@ -193,11 +193,11 @@ void BasicSessionStream::handleConnectionFinished(const boost::optional<Connecti } void BasicSessionStream::handleDataRead(const SafeByteArray& data) { - onDataRead(byteArrayToString(ByteArray(data.begin(), data.end()))); + onDataRead(data); } void BasicSessionStream::handleDataWritten(const SafeByteArray& data) { - onDataWritten(byteArrayToString(ByteArray(data.begin(), data.end()))); + onDataWritten(data); } }; diff --git a/Swiften/Session/SessionStream.h b/Swiften/Session/SessionStream.h index 38f5d93..e6b9469 100644 --- a/Swiften/Session/SessionStream.h +++ b/Swiften/Session/SessionStream.h @@ -13,6 +13,7 @@ #include <Swiften/Elements/ProtocolHeader.h> #include <Swiften/Elements/Element.h> #include <Swiften/Base/Error.h> +#include <Swiften/Base/SafeByteArray.h> #include <Swiften/TLS/PKCS12Certificate.h> #include <Swiften/TLS/Certificate.h> #include <Swiften/TLS/CertificateVerificationError.h> @@ -71,8 +72,8 @@ namespace Swift { boost::signal<void (boost::shared_ptr<Element>)> onElementReceived; boost::signal<void (boost::shared_ptr<Error>)> onClosed; boost::signal<void ()> onTLSEncrypted; - boost::signal<void (const std::string&)> onDataRead; - boost::signal<void (const std::string&)> onDataWritten; + boost::signal<void (const SafeByteArray&)> onDataRead; + boost::signal<void (const SafeByteArray&)> onDataWritten; protected: const PKCS12Certificate& getTLSCertificate() const { |