summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoger Planas <roger.planas@isode.com>2016-02-08 11:36:14 (GMT)
committerKevin Smith <kevin.smith@isode.com>2016-02-10 12:04:05 (GMT)
commitdcfe31ce3055f3af7e3b617752d9c9fd16672569 (patch)
treeafa05b40b63f96a7d3cefd4edd58c7c9f7d0c505
parent59c64a11e0bceca4876ba69ef2f30519629b108c (diff)
downloadswift-dcfe31ce3055f3af7e3b617752d9c9fd16672569.zip
swift-dcfe31ce3055f3af7e3b617752d9c9fd16672569.tar.bz2
Sluift: Ensure that message event body is retrieved correctly
As a result of commit "Change stanza body to boost::optional<std::string> type" (commit 1b9ccc1fef6104eaf951153ddccdc6bb15899e9a), Sluift was not populating the 'body' part of the message event, casting it to a bool instead. By adding get_value_or("") to that body part, the actual body value is retrieved, and the message event ends up containing the right information. Test-Information: Without the patch, Sluift's message event body is 'true'. With the patch, Sluift's message event body contains the actual message. Component messages also tested and event body as expected. Change-Id: I366202aa5bf28a3315a81d909ea08f0933aa06d7
-rw-r--r--Sluift/client.cpp2
-rw-r--r--Sluift/component.cpp2
2 files changed, 2 insertions, 2 deletions
diff --git a/Sluift/client.cpp b/Sluift/client.cpp
index 997fd00..8f6ff3a 100644
--- a/Sluift/client.cpp
+++ b/Sluift/client.cpp
@@ -460,61 +460,61 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
SLUIFT_LUA_FUNCTION_WITH_HELP(
Client, get_options,
"Returns a table with all the connection options of this client.",
"self\n",
""
) {
Sluift::globals.eventLoop.runOnce();
SluiftClient* client = getClient(L);
Lua::Table optionsTable = boost::assign::map_list_of
("host", boost::make_shared<Lua::Value>(client->getOptions().manualHostname))
("port", boost::make_shared<Lua::Value>(client->getOptions().manualPort))
("ack", boost::make_shared<Lua::Value>(client->getOptions().useAcks))
("compress", boost::make_shared<Lua::Value>(client->getOptions().useStreamCompression))
("tls", boost::make_shared<Lua::Value>(client->getOptions().useTLS == ClientOptions::NeverUseTLS ? false : true))
("bosh_url", boost::make_shared<Lua::Value>(client->getOptions().boshURL.toString()))
("allow_plain_without_tls", boost::make_shared<Lua::Value>(client->getOptions().allowPLAINWithoutTLS));
pushValue(L, optionsTable);
Lua::registerTableToString(L, -1);
return 1;
}
static void pushEvent(lua_State* L, const SluiftClient::Event& event) {
switch (event.type) {
case SluiftClient::Event::MessageType: {
Message::ref message = boost::dynamic_pointer_cast<Message>(event.stanza);
Lua::Table result = boost::assign::map_list_of
("type", boost::make_shared<Lua::Value>(std::string("message")))
("from", boost::make_shared<Lua::Value>(message->getFrom().toString()))
- ("body", boost::make_shared<Lua::Value>(message->getBody()))
+ ("body", boost::make_shared<Lua::Value>(message->getBody().get_value_or("")))
("message_type", boost::make_shared<Lua::Value>(MessageConvertor::convertMessageTypeToString(message->getType())));
Lua::pushValue(L, result);
addPayloadsToTable(L, message->getPayloads());
Lua::registerTableToString(L, -1);
break;
}
case SluiftClient::Event::PresenceType: {
Presence::ref presence = boost::dynamic_pointer_cast<Presence>(event.stanza);
Lua::Table result = boost::assign::map_list_of
("type", boost::make_shared<Lua::Value>(std::string("presence")))
("from", boost::make_shared<Lua::Value>(presence->getFrom().toString()))
("status", boost::make_shared<Lua::Value>(presence->getStatus()))
("presence_type", boost::make_shared<Lua::Value>(PresenceConvertor::convertPresenceTypeToString(presence->getType())));
Lua::pushValue(L, result);
addPayloadsToTable(L, presence->getPayloads());
Lua::registerTableToString(L, -1);
break;
}
case SluiftClient::Event::PubSubEventType: {
Sluift::globals.elementConvertor.convertToLua(L, event.pubsubEvent);
lua_pushstring(L, "pubsub");
lua_setfield(L, -2, "type");
lua_pushstring(L, event.from.toString().c_str());
lua_setfield(L, -2, "from");
lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.coreLibIndex);
lua_getfield(L, -1, "process_pubsub_event");
lua_pushvalue(L, -3);
lua_call(L, 1, 0);
lua_pop(L, 1);
diff --git a/Sluift/component.cpp b/Sluift/component.cpp
index e92352e..a9ac2d9 100644
--- a/Sluift/component.cpp
+++ b/Sluift/component.cpp
@@ -335,61 +335,61 @@ SLUIFT_LUA_FUNCTION(Component, get) {
}
SLUIFT_LUA_FUNCTION(Component, set) {
return sendQuery(L, IQ::Set);
}
SLUIFT_LUA_FUNCTION_WITH_HELP(
Component, send,
"Sends a raw string",
"self\n"
"data the string to send\n",
""
) {
Sluift::globals.eventLoop.runOnce();
getComponent(L)->getComponent()->sendData(std::string(Lua::checkString(L, 2)));
lua_pushvalue(L, 1);
return 0;
}
static void pushEvent(lua_State* L, const SluiftComponent::Event& event) {
switch (event.type) {
case SluiftComponent::Event::MessageType: {
Message::ref message = boost::dynamic_pointer_cast<Message>(event.stanza);
Lua::Table result = boost::assign::map_list_of
("type", boost::make_shared<Lua::Value>(std::string("message")))
("from", boost::make_shared<Lua::Value>(message->getFrom().toString()))
("to", boost::make_shared<Lua::Value>(message->getTo().toString()))
- ("body", boost::make_shared<Lua::Value>(message->getBody()))
+ ("body", boost::make_shared<Lua::Value>(message->getBody().get_value_or("")))
("message_type", boost::make_shared<Lua::Value>(MessageConvertor::convertMessageTypeToString(message->getType())));
Lua::pushValue(L, result);
addPayloadsToTable(L, message->getPayloads());
Lua::registerTableToString(L, -1);
break;
}
case SluiftComponent::Event::PresenceType: {
Presence::ref presence = boost::dynamic_pointer_cast<Presence>(event.stanza);
Lua::Table result = boost::assign::map_list_of
("type", boost::make_shared<Lua::Value>(std::string("presence")))
("from", boost::make_shared<Lua::Value>(presence->getFrom().toString()))
("to", boost::make_shared<Lua::Value>(presence->getTo().toString()))
("status", boost::make_shared<Lua::Value>(presence->getStatus()))
("presence_type", boost::make_shared<Lua::Value>(PresenceConvertor::convertPresenceTypeToString(presence->getType())));
Lua::pushValue(L, result);
addPayloadsToTable(L, presence->getPayloads());
Lua::registerTableToString(L, -1);
break;
}
}
}
struct CallUnaryLuaPredicateOnEvent {
CallUnaryLuaPredicateOnEvent(lua_State* L, int index) : L(L), index(index) {
}
bool operator()(const SluiftComponent::Event& event) {
lua_pushvalue(L, index);
pushEvent(L, event);
if (lua_pcall(L, 1, 1, 0) != 0) {