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
 
@@ -42,6 +42,7 @@
 
#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)
 
@@ -178,6 +179,8 @@ class NetworkPluginServer : Swift::XMPPParserClient {
 
#endif
 
		void handleStreamEnd() {}
 

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

	
 
		UserManager *m_userManager;
 
		VCardResponder *m_vcardResponder;
 
		RosterResponder *m_rosterResponder;
libtransport/NetworkPluginServer.cpp
Show inline comments
 
@@ -46,8 +46,10 @@
 
#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"
 

	
 
@@ -686,6 +688,8 @@ void NetworkPluginServer::handleConvMessagePayload(const std::string &data, bool
 
		msg->setBody(payload.message());
 
	}
 

	
 
    wrapIncomingImage(msg.get(), payload);
 

	
 
	if (payload.headline()) {
 
		msg->setType(Swift::Message::Headline);
 
	}
 
@@ -1789,6 +1793,32 @@ void NetworkPluginServer::handleBuddyRemoved(Buddy *b) {
 
	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();
 

	
0 comments (0 inline, 0 general)