summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Maudsley <richard.maudsley@isode.com>2014-05-13 14:48:10 (GMT)
committerSwift Review <review@swift.im>2014-05-27 19:53:49 (GMT)
commit058719296f496b14b906fdee3d74d72a78d9f6a2 (patch)
treee15b5e0032b48c924f7f69e20e0b721172a5691d /Sluift/client.cpp
parente5975a6d4809bf05f8c9df724c926bd26fc4a9df (diff)
downloadswift-contrib-058719296f496b14b906fdee3d74d72a78d9f6a2.zip
swift-contrib-058719296f496b14b906fdee3d74d72a78d9f6a2.tar.bz2
Added Sluift MAM examples. send_mam_query becomes set_mam_query.
Change-Id: I5d81e2476c83a16a8e478656d11d91137b009f3a
Diffstat (limited to 'Sluift/client.cpp')
-rw-r--r--Sluift/client.cpp29
1 files changed, 1 insertions, 28 deletions
diff --git a/Sluift/client.cpp b/Sluift/client.cpp
index 8dcd9ae..4b065ab 100644
--- a/Sluift/client.cpp
+++ b/Sluift/client.cpp
@@ -1,37 +1,37 @@
/*
- * Copyright (c) 2013 Remko Tronçon
+ * Copyright (c) 2013-2014 Remko Tronçon
* Licensed under the GNU General Public License.
* See the COPYING file for more information.
*/
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/assign/list_of.hpp>
#include <iostream>
#include <Sluift/SluiftClient.h>
#include <Swiften/JID/JID.h>
#include <Swiften/Elements/SoftwareVersion.h>
#include <Swiften/Elements/Message.h>
#include <Swiften/Elements/Presence.h>
#include <Swiften/Elements/RawXMLPayload.h>
#include <Swiften/Elements/RosterItemPayload.h>
#include <Swiften/Elements/RosterPayload.h>
#include <Swiften/Elements/DiscoInfo.h>
#include <Swiften/Elements/MAMQuery.h>
#include <Swiften/Disco/ClientDiscoManager.h>
#include <Swiften/Queries/GenericRequest.h>
#include <Swiften/Presence/PresenceSender.h>
#include <Swiften/Roster/XMPPRoster.h>
#include <Swiften/Roster/SetRosterRequest.h>
#include <Swiften/Presence/SubscriptionManager.h>
#include <Swiften/Roster/XMPPRosterItem.h>
#include <Swiften/Queries/IQRouter.h>
#include <Swiften/Queries/Requests/GetSoftwareVersionRequest.h>
#include <Sluift/Lua/FunctionRegistration.h>
#include <Swiften/Base/foreach.h>
#include <Swiften/Base/IDGenerator.h>
#include <Sluift/Lua/Check.h>
#include <Sluift/Lua/Value.h>
#include <Sluift/Lua/Exception.h>
#include <Sluift/Lua/LuaUtils.h>
@@ -420,97 +420,70 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
SluiftClient* client = getClient(L);
Lua::checkType(L, 2, LUA_TTABLE);
lua_getfield(L, 2, "host");
if (!lua_isnil(L, -1)) {
client->getOptions().manualHostname = lua_tostring(L, -1);
}
lua_getfield(L, 2, "port");
if (!lua_isnil(L, -1)) {
client->getOptions().manualPort = boost::numeric_cast<int>(lua_tointeger(L, -1));
}
lua_getfield(L, 2, "ack");
if (!lua_isnil(L, -1)) {
client->getOptions().useAcks = lua_toboolean(L, -1);
}
lua_getfield(L, 2, "compress");
if (!lua_isnil(L, -1)) {
client->getOptions().useStreamCompression = lua_toboolean(L, -1);
}
lua_getfield(L, 2, "tls");
if (!lua_isnil(L, -1)) {
bool useTLS = lua_toboolean(L, -1);
client->getOptions().useTLS = (useTLS ? ClientOptions::UseTLSWhenAvailable : ClientOptions::NeverUseTLS);
}
lua_getfield(L, 2, "bosh_url");
if (!lua_isnil(L, -1)) {
client->getOptions().boshURL = URL::fromString(lua_tostring(L, -1));
}
lua_getfield(L, 2, "allow_plain_without_tls");
if (!lua_isnil(L, -1)) {
client->getOptions().allowPLAINWithoutTLS = lua_toboolean(L, -1);
}
lua_pushvalue(L, 1);
return 0;
}
-SLUIFT_LUA_FUNCTION_WITH_HELP(
- Client, send_mam_query,
-
- "Builds and sends a MAM query.\n",
-
- "self\n"
- "mam_query parameters for the query\n"
- "jid optional jid to set in the 'to' field of the IQ stanza",
-
- "See help('MAMQuery') for details."
-) {
- Lua::checkType(L, 2, LUA_TTABLE);
- boost::shared_ptr<MAMQuery> mamQuery = boost::make_shared<MAMQuery>();
- lua_getfield(L, 2, "mam_query");
- if (lua_istable(L, -1)) {
- mamQuery = boost::dynamic_pointer_cast<MAMQuery>(Sluift::globals.elementConvertor.convertFromLuaUntyped(L, -1, "mam_query"));
- }
- JID jid;
- lua_getfield(L, 2, "jid");
- if (!lua_isnil(L, -1)) {
- jid = JID(lua_tostring(L, -1));
- }
- IQRouter *router = getClient(L)->getClient()->getIQRouter();
- router->sendIQ(IQ::createRequest(IQ::Set, jid, IDGenerator().generateID(), mamQuery));
- return 0;
-}
-
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()))
("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");