summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Sluift/Examples')
-rw-r--r--Sluift/Examples/AdHocCommands.lua6
-rw-r--r--Sluift/Examples/CollectVersions.lua6
-rw-r--r--Sluift/Examples/Component.lua55
-rw-r--r--Sluift/Examples/ContactsMap.lua6
-rw-r--r--Sluift/Examples/EchoBot.lua6
-rw-r--r--Sluift/Examples/EchoBot_With.lua32
-rw-r--r--Sluift/Examples/Login.lua8
-rw-r--r--Sluift/Examples/MAMRSM.lua23
-rw-r--r--Sluift/Examples/MAMRSMPage.lua36
-rw-r--r--Sluift/Examples/MAMSimple.lua19
-rw-r--r--Sluift/Examples/MAMSupportedFields.lua18
-rw-r--r--Sluift/Examples/MAMUser.lua25
-rw-r--r--Sluift/Examples/PEPListener.lua6
-rw-r--r--Sluift/Examples/RemoveUnreachableContacts.lua6
-rw-r--r--Sluift/Examples/SendReference.lua74
-rw-r--r--Sluift/Examples/Tunes.lua68
-rwxr-xr-xSluift/Examples/Wonderland.lua6
17 files changed, 375 insertions, 25 deletions
diff --git a/Sluift/Examples/AdHocCommands.lua b/Sluift/Examples/AdHocCommands.lua
index 9e83f0c..f2f9cb4 100644
--- a/Sluift/Examples/AdHocCommands.lua
+++ b/Sluift/Examples/AdHocCommands.lua
@@ -1,7 +1,7 @@
--[[
- Copyright (c) 2013 Remko Tronçon
- Licensed under the GNU General Public License v3.
- See Documentation/Licenses/GPLv3.txt for more information.
+ Copyright (c) 2013 Isode Limited.
+ All rights reserved.
+ See the COPYING file for more information.
--]]
--[[
diff --git a/Sluift/Examples/CollectVersions.lua b/Sluift/Examples/CollectVersions.lua
index 38bf6ac..42bcf86 100644
--- a/Sluift/Examples/CollectVersions.lua
+++ b/Sluift/Examples/CollectVersions.lua
@@ -1,8 +1,8 @@
--[[
- Copyright (c) 2010-2013 Remko Tronçon
- Licensed under the GNU General Public License v3.
- See Documentation/Licenses/GPLv3.txt for more information.
+ Copyright (c) 2010-2013 Isode Limited.
+ All rights reserved.
+ See the COPYING file for more information.
This script logs into an XMPP server, and collects statistics about
the server software of all contacts in your roster
diff --git a/Sluift/Examples/Component.lua b/Sluift/Examples/Component.lua
new file mode 100644
index 0000000..b8a71f5
--- /dev/null
+++ b/Sluift/Examples/Component.lua
@@ -0,0 +1,55 @@
+--[[
+ Copyright (c) 2014 Edwin Mons and Isode Limited.
+ All rights reserved.
+ See the COPYING file for more information.
+--]]
+
+--[[
+
+ Component example.
+
+ This script connects to an XMPP server as a component, and listens to
+ messages received.
+
+ The following environment variables are used:
+ * SLUIFT_COMP_DOMAIN: Component domain name
+ * SLUIFT_COMP_SECRET: Component secret
+ * SLUIFT_COMP_HOST: XMPP server host name
+ * SLUIFT_COMP_PORT: XMPP server component port
+ * SLUIFT_JID: Recipient of presence and initial message
+ * SLUIFT_DEBUG: Sets whether debugging should be turned on
+
+--]]
+
+require "sluift"
+
+sluift.debug = os.getenv("SLUIFT_DEBUG") or false
+
+config = {
+ domain = os.getenv('SLUIFT_COMP_DOMAIN'),
+ secret = os.getenv('SLUIFT_COMP_SECRET'),
+ host = os.getenv('SLUIFT_COMP_HOST'),
+ port = os.getenv('SLUIFT_COMP_PORT'),
+ jid = os.getenv('SLUIFT_JID')
+}
+
+-- Create the component, and connect
+comp = sluift.new_component(config.domain, config.secret);
+comp:connect(config)
+
+-- Send initial presence and message
+-- Assumes the remote client already has this component user on his roster
+comp:send_presence{from='root@' .. config.domain, to=config.jid}
+comp:send_message{from='root@' .. config.domain, to=config.jid, body='Component active'}
+
+-- Listen for messages, and reply if one is received
+for message in comp:messages() do
+ print("Received a message from " .. message.from)
+ comp:send_message{to=message.from, from=message.to, body='I received: ' .. message['body']}
+
+ -- Send out a ping to demonstrate we can do more than just send messages
+ comp:get{to=message.from, query='<ping xmlns="urn:xmpp:ping"/>'}
+end
+
+comp:disconnect()
+
diff --git a/Sluift/Examples/ContactsMap.lua b/Sluift/Examples/ContactsMap.lua
index d248dc7..573eb9f 100644
--- a/Sluift/Examples/ContactsMap.lua
+++ b/Sluift/Examples/ContactsMap.lua
@@ -1,7 +1,7 @@
--[[
- Copyright (c) 2013 Remko Tronçon
- Licensed under the GNU General Public License v3.
- See Documentation/Licenses/GPLv3.txt for more information.
+ Copyright (c) 2013 Isode Limited.
+ All rights reserved.
+ See the COPYING file for more information.
--]]
--[[
diff --git a/Sluift/Examples/EchoBot.lua b/Sluift/Examples/EchoBot.lua
index fc495c4..81c2fa3 100644
--- a/Sluift/Examples/EchoBot.lua
+++ b/Sluift/Examples/EchoBot.lua
@@ -1,7 +1,7 @@
--[[
- Copyright (c) 2010-2013 Remko Tronçon
- Licensed under the GNU General Public License v3.
- See Documentation/Licenses/GPLv3.txt for more information.
+ Copyright (c) 2010-2013 Isode Limited.
+ All rights reserved.
+ See the COPYING file for more information.
--]]
--[[
diff --git a/Sluift/Examples/EchoBot_With.lua b/Sluift/Examples/EchoBot_With.lua
new file mode 100644
index 0000000..2260deb
--- /dev/null
+++ b/Sluift/Examples/EchoBot_With.lua
@@ -0,0 +1,32 @@
+--[[
+ Copyright (c) 2010-2013 Isode Limited.
+ All rights reserved.
+ See the COPYING file for more information.
+--]]
+
+--[[
+
+ Alternative version of EchoBot that uses with()
+
+ This script logs into an XMPP server, sends initial presence,
+ and then waits for incoming messages, and echoes them back.
+
+ The following environment variables are used:
+ * SLUIFT_JID, SWIFT_PASS: JID and password to log in with
+ * SLUIFT_DEBUG: Sets whether debugging should be turned on
+
+--]]
+
+require "sluift"
+
+sluift.debug = os.getenv("SLUIFT_DEBUG") or false
+
+client = sluift.new_client(os.getenv("SLUIFT_JID"), os.getenv("SLUIFT_PASS"))
+sluift.with(client, function ()
+ connect()
+ set_version{name = "EchoBot", version = "0.1"}
+ send_presence("Send me a message")
+ for message in messages() do
+ send_message{to = message["from"], body = message["body"]}
+ end
+end)
diff --git a/Sluift/Examples/Login.lua b/Sluift/Examples/Login.lua
index c43b72a..1d70954 100644
--- a/Sluift/Examples/Login.lua
+++ b/Sluift/Examples/Login.lua
@@ -1,7 +1,7 @@
--[[
- Copyright (c) 2010-2013 Remko Tronçon
- Licensed under the GNU General Public License v3.
- See Documentation/Licenses/GPLv3.txt for more information.
+ Copyright (c) 2010-2014 Isode Limited.
+ All rights reserved.
+ See the COPYING file for more information.
--]]
--[[
@@ -21,7 +21,7 @@ sluift.debug = os.getenv("SLUIFT_DEBUG") or false
print("Connecting " .. os.getenv("SLUIFT_JID") .. " ...")
c = sluift.new_client(os.getenv("SLUIFT_JID"), os.getenv("SLUIFT_PASS"))
-c:set_options({compress = false, tls = false})
+c:set_options{compress = false, tls = false}
c:connect()
c:send_presence("")
diff --git a/Sluift/Examples/MAMRSM.lua b/Sluift/Examples/MAMRSM.lua
new file mode 100644
index 0000000..c8a1e85
--- /dev/null
+++ b/Sluift/Examples/MAMRSM.lua
@@ -0,0 +1,23 @@
+-- A query using Result Set Management
+-- Usage: ./sluift MAMRSM.lua <jid> <password> <query_dest> <max_results>
+
+sluift.debug = true
+
+c = sluift.new_client(arg[1], arg[2])
+
+c:connect();
+
+query = {
+ result_set={max_items=arg[4]}
+}
+
+c:set_mam{mam=query, to=arg[3]}
+
+c:for_each_message(function(e)
+ if e.payloads[1].tag == 'fin' then return true end
+ if e.payloads[1]._type == 'mam_result' then
+ print(e.payloads[1].payload.stanza.payloads[1].text)
+ end
+end)
+
+c:disconnect()
diff --git a/Sluift/Examples/MAMRSMPage.lua b/Sluift/Examples/MAMRSMPage.lua
new file mode 100644
index 0000000..cb3307c
--- /dev/null
+++ b/Sluift/Examples/MAMRSMPage.lua
@@ -0,0 +1,36 @@
+-- A page query using Result Set Management
+-- Usage: ./sluift MAMRSMPage.lua <jid> <password> <query_dest> <pages>
+
+sluift.debug = true
+
+c = sluift.new_client(arg[1], arg[2])
+
+c:set_options{compress = false, tls = false}
+
+c:connect();
+
+query = {
+ result_set={max_items=5}
+}
+
+done = false
+page = 0
+while not done and page < tonumber(arg[4]) do
+ page = page + 1
+ c:set_mam{mam=query, to=arg[3]}
+ c:for_each_message(function(e)
+ if e.payloads[1].tag == 'fin' then
+ if e.payloads[2].last_id then
+ query.result_set.after = e.payloads[2].last_id
+ else
+ done = true
+ end
+ return true
+ end
+ if e.payloads[1]._type == 'mam_result' then
+ print(e.payloads[1].payload.stanza.payloads[1].text)
+ end
+ end)
+end
+
+c:disconnect()
diff --git a/Sluift/Examples/MAMSimple.lua b/Sluift/Examples/MAMSimple.lua
new file mode 100644
index 0000000..13ab1a0
--- /dev/null
+++ b/Sluift/Examples/MAMSimple.lua
@@ -0,0 +1,19 @@
+-- Querying the archive for messages
+-- Usage: ./sluift MAMSimple.lua <jid> <password> <query_dest>
+
+sluift.debug = true
+
+c = sluift.new_client(arg[1], arg[2])
+
+c:connect();
+
+c:set_mam{mam={}, to=arg[3]}
+
+c:for_each_message(function(e)
+ if e.payloads[1].tag == 'fin' then return true end
+ if e.payloads[1]._type == 'mam_result' then
+ print(e.payloads[1].payload.stanza.payloads[1].text)
+ end
+end)
+
+c:disconnect()
diff --git a/Sluift/Examples/MAMSupportedFields.lua b/Sluift/Examples/MAMSupportedFields.lua
new file mode 100644
index 0000000..0417924
--- /dev/null
+++ b/Sluift/Examples/MAMSupportedFields.lua
@@ -0,0 +1,18 @@
+-- Retrieving form fields
+-- Usage: ./sluift MAMSupportedFields.lua <jid> <password>
+
+sluift.debug = true
+
+c = sluift.new_client(arg[1], arg[2])
+
+c:connect();
+
+mam_result = c:get_mam{}
+
+for i=1,#mam_result.form.fields do
+ if mam_result.form.fields[i].type ~= "hidden" then
+ print("Server supports: " .. mam_result.form.fields[i].name)
+ end
+end
+
+c:disconnect()
diff --git a/Sluift/Examples/MAMUser.lua b/Sluift/Examples/MAMUser.lua
new file mode 100644
index 0000000..e4a7c28
--- /dev/null
+++ b/Sluift/Examples/MAMUser.lua
@@ -0,0 +1,25 @@
+-- Querying for all messages to/from a particular JID
+-- Usage: ./sluift MAMUser.lua <jid> <password> <query_dest> <query_jid>
+
+sluift.debug = true
+
+c = sluift.new_client(arg[1], arg[2])
+
+c:connect();
+
+fields = {
+ with = arg[4]
+}
+
+query_form = sluift.create_form{fields, form_type="urn:xmpp:mam:0"}
+
+c:set_mam{mam={form=query_form}, to=arg[3]}
+
+c:for_each_message(function(e)
+ if e.payloads[1].tag == 'fin' then return true end
+ if e.payloads[1]._type == 'mam_result' then
+ print(e.payloads[1].payload.stanza.payloads[1].text)
+ end
+end)
+
+c:disconnect()
diff --git a/Sluift/Examples/PEPListener.lua b/Sluift/Examples/PEPListener.lua
index f196f84..416ae52 100644
--- a/Sluift/Examples/PEPListener.lua
+++ b/Sluift/Examples/PEPListener.lua
@@ -1,7 +1,7 @@
--[[
- Copyright (c) 2010-2013 Remko Tronçon
- Licensed under the GNU General Public License v3.
- See Documentation/Licenses/GPLv3.txt for more information.
+ Copyright (c) 2010-2013 Isode Limited.
+ All rights reserved.
+ See the COPYING file for more information.
--]]
--[[
diff --git a/Sluift/Examples/RemoveUnreachableContacts.lua b/Sluift/Examples/RemoveUnreachableContacts.lua
index a202e62..65d64b9 100644
--- a/Sluift/Examples/RemoveUnreachableContacts.lua
+++ b/Sluift/Examples/RemoveUnreachableContacts.lua
@@ -1,7 +1,7 @@
--[[
- Copyright (c) 2010-2013 Remko Tronçon
- Licensed under the GNU General Public License v3.
- See Documentation/Licenses/GPLv3.txt for more information.
+ Copyright (c) 2010-2013 Isode Limited.
+ All rights reserved.
+ See the COPYING file for more information.
--]]
--[[
diff --git a/Sluift/Examples/SendReference.lua b/Sluift/Examples/SendReference.lua
new file mode 100644
index 0000000..2e60182
--- /dev/null
+++ b/Sluift/Examples/SendReference.lua
@@ -0,0 +1,74 @@
+#!/usr/bin/env sluift --
+
+-- This is an example of sending a custom payload, a XEP-0372 reference in this
+-- case.
+--
+-- Running this requires a sluift binary somewhere in the PATH. Alternatively,
+-- you can feed this to sluift, or to a Lua that has sluift.so in its library
+-- path.
+
+require("sluift")
+
+DEFAULT_URI = "http://example.com/kitten.jpg"
+
+function usage(err)
+ print("Usage: SendReference.lua jid [tojid] [datauri]")
+ print()
+ print("This tool will log in as jid, and send a reference to tojid. If no tojid")
+ print("is provided, a message to itself is sent. The datauri defaults to")
+ print(DEFAULT_URI .. ", but can be overridden.")
+
+ if err then
+ print("")
+ print("Error: " .. err)
+ end
+ os.exit(1)
+end
+
+function get_password(prompt)
+ if prompt then
+ io.write(prompt)
+ end
+ local stty_ret = os.execute("stty -echo 2>/dev/null")
+ if stty_ret then
+ io.write("\027[8m")
+ end
+ local ok, pass = pcall(io.read, "*l")
+ if stty_ret then
+ io.write("\027[m")
+ else
+ os.execute("stty echo")
+ end
+ io.write("\n");
+ if ok then
+ return pass
+ end
+end
+
+if #arg < 1 then
+ usage("no jid specified")
+end
+jid = arg[1]
+password = os.getenv("XMPP_PASSWORD") or get_password("Password: ")
+tojid = #arg > 1 and arg[2] or jid
+datauri = #arg > 2 and arg[3] or DEFAULT_URI
+
+sluift.debug = 1
+sluift.with(sluift.new_client(jid, password), function()
+ options = { host=os.getenv("XMPP_HOST"), port=os.getenv("XMPP_PORT") }
+ connect(options)
+ reference = {
+ ['_type'] = 'dom',
+ ['tag'] = 'reference',
+ ['ns'] = 'urn:xmpp:reference:0',
+ ['attributes'] = {
+ { ['name'] = 'type', ['value'] = 'data' },
+ { ['name'] = 'uri', ['value'] = datauri },
+ { ['name'] = 'mimeType', ['value'] = arg[4] },
+ { ['name'] = 'begin', ['value'] = arg[5] },
+ { ['name'] = 'end', ['value'] = arg[6] }
+ },
+ }
+ send_message{to=tojid, body="Check out this data!", payloads={reference}}
+ disconnect()
+end)
diff --git a/Sluift/Examples/Tunes.lua b/Sluift/Examples/Tunes.lua
new file mode 100644
index 0000000..c645583
--- /dev/null
+++ b/Sluift/Examples/Tunes.lua
@@ -0,0 +1,68 @@
+--[[
+ Copyright (c) 2014 Isode Limited.
+ All rights reserved.
+ See the COPYING file for more information.
+--]]
+
+--[[
+
+ Tune Publisher/Listener
+
+ Publishes the currently playing tune in iTunes, and prints
+ the playing tunes of contacts
+
+ The following environment variables are used:
+ - SLUIFT_JID, SWIFT_PASS: JID and password to log in with
+ - SLUIFT_DEBUG: Sets whether debugging should be turned on
+
+--]]
+
+require 'sluift'
+
+sluift.debug = os.getenv('SLUIFT_DEBUG') or false
+
+client = sluift.new_client(os.getenv('SLUIFT_JID'), os.getenv('SLUIFT_PASS'))
+client:connect(function (c)
+ -- Send initial presence (with service discovery information)
+ c:set_caps_node('http://swift.im/Tunes')
+ c:set_disco_info{
+ identities = {{name = 'Tunes'}},
+ features = {
+ sluift.disco.features.DISCO_INFO,
+ sluift.disco.features.USER_TUNE .. '+notify'
+ }}
+ c:send_presence{priority = -1}
+
+ local pubsub = c:pubsub(sluift.jid.to_bare(c:jid()))
+ local tunes_node = pubsub:node(sluift.disco.features.USER_TUNE)
+ local current_track = nil
+ while true do
+ -- Publish currently playing tune
+ if sluift.itunes then
+ local track = sluift.itunes.get_current_track()
+ if track ~= current_track then
+ tunes_node:publish{item = {
+ _type = 'user_tune',
+ title = track.name,
+ artist = track.artist,
+ track = track.track_number,
+ source = track.album,
+ length = track.length,
+ rating = track.rating and track.rating / 10 or nil
+ }}
+ current_track = track
+ end
+ end
+
+ -- Print incoming events for a while
+ for event in c:pubsub_events{timeout = 1000} do
+ if event._type == 'pubsub_event_items'
+ and event.node == sluift.disco.features.USER_TUNE
+ and event.item.title then
+ print(event.from .. ' is playing "'
+ .. (event.item.artist or '<Unknown Artist>') .. ' - '
+ .. event.item.title .. '"')
+ end
+ end
+ end
+end)
diff --git a/Sluift/Examples/Wonderland.lua b/Sluift/Examples/Wonderland.lua
index 426ec07..5104830 100755
--- a/Sluift/Examples/Wonderland.lua
+++ b/Sluift/Examples/Wonderland.lua
@@ -1,7 +1,7 @@
--
--- Copyright (c) 2011 Remko Tronçon
--- Licensed under the GNU General Public License v3.
--- See Documentation/Licenses/GPLv3.txt for more information.
+-- Copyright (c) 2011 Isode Limited.
+-- All rights reserved.
+-- See the COPYING file for more information.
--
-- This script creates the wonderland world example.