summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoger Planas <roger.planas@isode.com>2016-02-05 12:45:39 (GMT)
committerKevin Smith <kevin.smith@isode.com>2016-02-10 14:33:37 (GMT)
commitaf6493bf45fcd9174b485f8ae0532e2eb4e6914e (patch)
treecfabe60bd9db93ce05557ee26ba18cc4622e0db0 /Sluift/client.cpp
parentdcfe31ce3055f3af7e3b617752d9c9fd16672569 (diff)
downloadswift-af6493bf45fcd9174b485f8ae0532e2eb4e6914e.zip
swift-af6493bf45fcd9174b485f8ae0532e2eb4e6914e.tar.bz2
Sluift: Add timeout to roster receiving operations
This avoids Sluift indefinitely waiting if the server does not respond Test-Information: Before the patch, a sluift client would wait indefinitely if a buggy XMPP server does not respond. With this patch, sluift clients now timeout and through an exception after SLUIFT_TIMEOUT when the server does not respond. Change-Id: I9d36f53a8f4d5b3d594cef68c42de38fd5a1c296
Diffstat (limited to 'Sluift/client.cpp')
-rw-r--r--Sluift/client.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/Sluift/client.cpp b/Sluift/client.cpp
index 8f6ff3a..6373a20 100644
--- a/Sluift/client.cpp
+++ b/Sluift/client.cpp
@@ -1,32 +1,32 @@
/*
- * Copyright (c) 2013-2015 Isode Limited.
+ * Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* 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 <Swiften/TLS/PKCS12Certificate.h>
#include <Sluift/Lua/FunctionRegistration.h>
@@ -159,61 +159,61 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
SLUIFT_LUA_FUNCTION_WITH_HELP(
Client, set_version,
"Sets the published version of this client.",
"self",
"name the name of the client software\n"
"version the version identifier of this client\n"
"os the OS this client is running on\n"
) {
Sluift::globals.eventLoop.runOnce();
SluiftClient* client = getClient(L);
if (boost::shared_ptr<SoftwareVersion> version = boost::dynamic_pointer_cast<SoftwareVersion>(Sluift::globals.elementConvertor.convertFromLuaUntyped(L, 2, "software_version"))) {
client->setSoftwareVersion(version->getName(), version->getVersion(), version->getOS());
}
return 0;
}
SLUIFT_LUA_FUNCTION_WITH_HELP(
Client, get_contacts,
"Returns a table of all the contacts in the contact list.",
"self\n",
""
) {
Sluift::globals.eventLoop.runOnce();
SluiftClient* client = getClient(L);
Lua::Table contactsTable;
- foreach(const XMPPRosterItem& item, client->getRoster()) {
+ foreach(const XMPPRosterItem& item, client->getRoster(getGlobalTimeout(L))) {
std::string subscription;
switch(item.getSubscription()) {
case RosterItemPayload::None: subscription = "none"; break;
case RosterItemPayload::To: subscription = "to"; break;
case RosterItemPayload::From: subscription = "from"; break;
case RosterItemPayload::Both: subscription = "both"; break;
case RosterItemPayload::Remove: subscription = "remove"; break;
}
Lua::Table itemTable = boost::assign::map_list_of
("jid", boost::make_shared<Lua::Value>(item.getJID().toString()))
("name", boost::make_shared<Lua::Value>(item.getName()))
("subscription", boost::make_shared<Lua::Value>(subscription))
("groups", boost::make_shared<Lua::Value>(std::vector<Lua::Value>(item.getGroups().begin(), item.getGroups().end())));
contactsTable[item.getJID().toString()] = boost::make_shared<Lua::Value>(itemTable);
}
pushValue(L, contactsTable);
Lua::registerTableToString(L, -1);
return 1;
}
SLUIFT_LUA_FUNCTION_WITH_HELP(
Client, send_message,
"Send a message.",
"self\n"
"to the JID to send the message to\n"
"body the body of the message. Can alternatively be specified using the `body` option\n",
"to the JID to send the message to\n"
"body the body of the message\n"
"subject the subject of the MUC room to set\n"
@@ -609,61 +609,61 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
const char* rawJID = lua_tostring(L, -1);
if (rawJID) {
item.setJID(std::string(rawJID));
}
lua_getfield(L, 2, "name");
const char* rawName = lua_tostring(L, -1);
if (rawName) {
item.setName(rawName);
}
lua_getfield(L, 2, "groups");
if (!lua_isnil(L, -1)) {
if (lua_type(L, -1) == LUA_TTABLE) {
for (size_t i = 1; i <= lua_objlen(L, -1); ++i) {
lua_rawgeti(L, -1, boost::numeric_cast<int>(i));
const char* rawGroup = lua_tostring(L, -1);
if (rawGroup) {
item.addGroup(rawGroup);
}
lua_pop(L, 1);
}
}
else {
throw Lua::Exception("Groups should be a table");
}
}
}
else {
item.setJID(Lua::checkString(L, 2));
}
- client->getRoster();
+ client->getRoster(timeout);
if (!client->getClient()->getRoster()->containsJID(item.getJID())) {
RosterPayload::ref roster = boost::make_shared<RosterPayload>();
roster->addItem(item);
Sluift::Response response = client->sendVoidRequest(
SetRosterRequest::create(roster, client->getClient()->getIQRouter()), timeout);
if (response.error) {
return response.convertToLuaResult(L);
}
}
client->getClient()->getSubscriptionManager()->requestSubscription(item.getJID());
lua_pushboolean(L, true);
return 1;
}
SLUIFT_LUA_FUNCTION_WITH_HELP(
Client, remove_contact,
"Remove a contact from the contact list.",
"self\n"
"jid the JID of the contact to remove\n",
""
) {
Sluift::globals.eventLoop.runOnce();
SluiftClient* client = getClient(L);
JID jid(Lua::checkString(L, 2));
int timeout = getGlobalTimeout(L);
RosterPayload::ref roster = boost::make_shared<RosterPayload>();
roster->addItem(RosterItemPayload(JID(Lua::checkString(L, 2)), "", RosterItemPayload::Remove));