Commit 10eea7ab authored by dexterlb's avatar dexterlb Committed by vitalyster

wrap incoming images in x:oob tag

parent 07ee87c6
......@@ -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;
......
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment