summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Sluift/Examples/CollectVersions.lua22
-rw-r--r--Sluift/Examples/Login.lua1
-rw-r--r--Sluift/sluift.cpp28
3 files changed, 50 insertions, 1 deletions
diff --git a/Sluift/Examples/CollectVersions.lua b/Sluift/Examples/CollectVersions.lua
new file mode 100644
index 0000000..c93c8c8
--- /dev/null
+++ b/Sluift/Examples/CollectVersions.lua
@@ -0,0 +1,22 @@
+--
+-- Copyright (c) 2010 Remko Tronçon
+-- Licensed under the GNU General Public License v3.
+-- See Documentation/Licenses/GPLv3.txt for more information.
+--
+
+-- This script logs into an XMPP server, and collects statistics about
+-- the server software of all contacts in your roster
+
+require "sluift"
+
+c = sluift.new_client(os.getenv("SLUIFT_JID"), os.getenv("SLUIFT_PASS"))
+c:connect()
+
+versions = {}
+for jid, _ in pairs(c:get_contacts()) do
+ v = c:get_version(sluift.jid_domain(jid))
+ if v then versions[v["name"]] = (versions[v["name"]] or 0) + 1 end
+end
+for name, count in pairs(versions) do print(name .. ": " .. count) end
+
+c:disconnect()
diff --git a/Sluift/Examples/Login.lua b/Sluift/Examples/Login.lua
index c1f42d2..1733bb9 100644
--- a/Sluift/Examples/Login.lua
+++ b/Sluift/Examples/Login.lua
@@ -10,7 +10,6 @@
--
-- The following environment variables are used:
-- * SLUIFT_JID, SWIFT_PASS: JID and password to log in with
--- * SLUIFT_OPTIONS: Client options to use (e.g. "{compress = false}")
-- * SLUIFT_DEBUG: Sets whether debugging should be turned on
require "sluift"
diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp
index ffadc38..ca7d9ff 100644
--- a/Sluift/sluift.cpp
+++ b/Sluift/sluift.cpp
@@ -631,6 +631,30 @@ static int sluift_new_client(lua_State *L) {
}
}
+static int sluift_jid_to_bare(lua_State *L) {
+ JID jid(std::string(luaL_checkstring(L, 1)));
+ lua_pushstring(L, jid.toBare().toString().c_str());
+ return 1;
+}
+
+static int sluift_jid_node(lua_State *L) {
+ JID jid(std::string(luaL_checkstring(L, 1)));
+ lua_pushstring(L, jid.getNode().c_str());
+ return 1;
+}
+
+static int sluift_jid_domain(lua_State *L) {
+ JID jid(std::string(luaL_checkstring(L, 1)));
+ lua_pushstring(L, jid.getDomain().c_str());
+ return 1;
+}
+
+static int sluift_jid_resource(lua_State *L) {
+ JID jid(std::string(luaL_checkstring(L, 1)));
+ lua_pushstring(L, jid.getResource().c_str());
+ return 1;
+}
+
static int sluift_sleep(lua_State *L) {
try {
eventLoop.runOnce();
@@ -672,6 +696,10 @@ static int sluift_newindex(lua_State *L) {
static const luaL_reg sluift_functions[] = {
{"new_client", sluift_new_client},
+ {"jid_to_bare", sluift_jid_to_bare},
+ {"jid_node", sluift_jid_node},
+ {"jid_domain", sluift_jid_domain},
+ {"jid_resource", sluift_jid_resource},
{"sleep", sluift_sleep},
{NULL, NULL}
};