summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Sluift/sluift.cpp')
-rw-r--r--Sluift/sluift.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp
index 49cfec4..4f762fa 100644
--- a/Sluift/sluift.cpp
+++ b/Sluift/sluift.cpp
@@ -4,16 +4,15 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-extern "C" {
- #include "sluift.h"
- #include <lauxlib.h>
-}
+#include "sluift.h"
+#include <lauxlib.h>
#include <iostream>
#include <string>
#include <deque>
#include <boost/assign/list_of.hpp>
+#include <Swiften/Base/foreach.h>
#include <Swiften/Swiften.h>
#include "Watchdog.h"
@@ -63,11 +62,20 @@ class SluiftClient {
return client;
}
+ ClientOptions& getOptions() {
+ return options;
+ }
+
void connect() {
rosterReceived = false;
client->connect();
}
+ void connect(const std::string& host) {
+ rosterReceived = false;
+ client->connect(host);
+ }
+
void waitConnected() {
Watchdog watchdog(globalTimeout, networkFactories.getTimerFactory());
while (!watchdog.getTimedOut() && client->isActive() && !client->isAvailable()) {
@@ -179,6 +187,7 @@ class SluiftClient {
private:
Client* client;
+ ClientOptions options;
ClientXMLTracer* tracer;
bool rosterReceived;
std::deque<Stanza::ref> pendingEvents;
@@ -196,7 +205,13 @@ static inline SluiftClient* getClient(lua_State* L) {
static int sluift_client_connect(lua_State *L) {
try {
SluiftClient* client = getClient(L);
- client->connect();
+ std::string host(luaL_checkstring(L, 2));
+ if (host.empty()) {
+ client->connect();
+ }
+ else {
+ client->connect(host);
+ }
client->waitConnected();
return 1;
}
@@ -453,12 +468,12 @@ static int sluift_client_set_options(lua_State* L) {
luaL_checktype(L, 2, LUA_TTABLE);
lua_getfield(L, 2, "compress");
if (!lua_isnil(L, -1)) {
- client->getClient()->setUseStreamCompression(lua_toboolean(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->getClient()->setUseTLS(useTLS ? Client::UseTLSWhenAvailable : Client::NeverUseTLS);
+ client->getOptions().useTLS = (useTLS ? ClientOptions::UseTLSWhenAvailable : ClientOptions::NeverUseTLS);
}
lua_pushvalue(L, 1);
return 0;