Changeset - 10eea7ab77a5
[Not reviewed]
0 2 0
dexterlb - 8 years ago 2017-12-26 21:38:25
dexterlb@qtrp.org
wrap incoming images in x:oob tag
2 files changed with 33 insertions and 0 deletions:
0 comments (0 inline, 0 general)
include/transport/NetworkPluginServer.h
Show inline comments
 
@@ -39,12 +39,13 @@
 
#include "Swiften/Parser/XMPPParser.h"
 
#include "Swiften/Parser/XMPPParserClient.h"
 
#include "Swiften/Serializer/XMPPSerializer.h"
 
#include "Swiften/SwiftenCompat.h"
 
#include <Swiften/Version.h>
 
#include <Swiften/FileTransfer/FileTransfer.h>
 
#include "transport/protocol.pb.h"
 
#define HAVE_SWIFTEN_3  (SWIFTEN_VERSION >= 0x030000)
 

	
 
#define NETWORK_PLUGIN_API_VERSION (1)
 

	
 
namespace Transport {
 

	
 
@@ -175,12 +176,14 @@ class NetworkPluginServer : Swift::XMPPParserClient {
 
		void handleElement(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::ToplevelElement> element);
 
#else
 
		void handleElement(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Element> element);
 
#endif
 
		void handleStreamEnd() {}
 

	
 
		void wrapIncomingImage(Swift::Message* msg, const pbnetwork::ConversationMessage& payload);
 

	
 
		UserManager *m_userManager;
 
		VCardResponder *m_vcardResponder;
 
		RosterResponder *m_rosterResponder;
 
		BlockResponder *m_blockResponder;
 
		Config *m_config;
 
		SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::ConnectionServer> m_server;
libtransport/NetworkPluginServer.cpp
Show inline comments
 
@@ -43,14 +43,16 @@
 
#include "Swiften/Elements/XHTMLIMPayload.h"
 
#include "Swiften/Elements/Delay.h"
 
#include "Swiften/Elements/DeliveryReceipt.h"
 
#include "Swiften/Elements/DeliveryReceiptRequest.h"
 
#include "Swiften/Elements/InvisiblePayload.h"
 
#include "Swiften/Elements/SpectrumErrorPayload.h"
 
#include "Swiften/Elements/RawXMLPayload.h"
 

	
 
#include "boost/date_time/posix_time/posix_time.hpp"
 
#include <boost/regex.hpp>
 

	
 
#include "transport/utf8.h"
 

	
 
#include <Swiften/FileTransfer/ReadBytestream.h>
 
#include <Swiften/Elements/StreamInitiationFileInfo.h>
 

	
 
@@ -683,12 +685,14 @@ void NetworkPluginServer::handleConvMessagePayload(const std::string &data, bool
 
		msg->setSubject(payload.message());
 
	}
 
	else {
 
		msg->setBody(payload.message());
 
	}
 

	
 
    wrapIncomingImage(msg.get(), payload);
 

	
 
	if (payload.headline()) {
 
		msg->setType(Swift::Message::Headline);
 
	}
 

	
 
	// Add xhtml-im payload.
 
	if (CONFIG_BOOL(m_config, "service.enable_xhtml") && !payload.xhtml().empty()) {
 
@@ -1786,12 +1790,38 @@ void NetworkPluginServer::handleBuddyRemoved(Buddy *b) {
 
	if (!c) {
 
		return;
 
	}
 
	send(c->connection, message);
 
}
 

	
 
void NetworkPluginServer::wrapIncomingImage(Swift::Message* msg, const pbnetwork::ConversationMessage& payload) {
 
    static boost::regex image_expr{"<img src=[\"']([^\"']+)[\"'].*>"};
 

	
 
    if (payload.xhtml().find("<img") != std::string::npos) {
 
        boost::smatch match;
 

	
 
        if (boost::regex_search(payload.xhtml(), match, image_expr)) {
 
            const std::string& image_url = match[1];
 

	
 
            SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::RawXMLPayload>
 
                oob_payload(new Swift::RawXMLPayload(
 
                    "<x xmlns='jabber:x:oob'><url>"
 
                    + image_url
 
                    + "</url>"
 
                    + "</x>"
 
                ));
 
                // todo: add the payload itself as a caption
 

	
 
            msg->addPayload(oob_payload);
 
            msg->setBody(image_url);
 
        } else {
 
            LOG4CXX_WARN(logger, "xhtml seems to contain an image, but doesn't match: " + payload.xhtml())
 
        }
 
    }
 
}
 

	
 
void NetworkPluginServer::handleBuddyUpdated(Buddy *b, const Swift::RosterItemPayload &item) {
 
	User *user = b->getRosterManager()->getUser();
 

	
 
	dynamic_cast<LocalBuddy *>(b)->setAlias(item.getName());
 
	dynamic_cast<LocalBuddy *>(b)->setGroups(item.getGroups());
 

	
0 comments (0 inline, 0 general)