summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2018-02-21 09:06:42 (GMT)
committerEdwin Mons <edwin.mons@isode.com>2018-02-21 09:11:26 (GMT)
commitcc1d97fc393c4d6fd3c9ecacd35b3683a10de356 (patch)
tree871de2bb590a670c26ff84db54d6dc1b57decbbf
parent9919bcfde2a166f815d259712af516a2dc3bd896 (diff)
downloadswift-cc1d97fc393c4d6fd3c9ecacd35b3683a10de356.zip
swift-cc1d97fc393c4d6fd3c9ecacd35b3683a10de356.tar.bz2
Add a Sluift example of sending a custom reference payload
The example will send a message with a data reference as an example of creating and sending custom children of a message. Test-Information: Reference received on macOS 10.12 Change-Id: If670db0c2ded426e8502a4d331026cf56f6df8df
-rw-r--r--Sluift/Examples/SendReference.lua70
1 files changed, 70 insertions, 0 deletions
diff --git a/Sluift/Examples/SendReference.lua b/Sluift/Examples/SendReference.lua
new file mode 100644
index 0000000..b705172
--- /dev/null
+++ b/Sluift/Examples/SendReference.lua
@@ -0,0 +1,70 @@
+#!/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 sane")
+ 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()
+ connect(options)
+ reference = {
+ ['_type'] = 'dom',
+ ['tag'] = 'reference',
+ ['ns'] = 'urn:xmpp:reference:0',
+ ['attributes'] = {
+ { ['name'] = 'type', ['value'] = 'data' },
+ { ['name'] = 'uri', ['value'] = datauri },
+ },
+ }
+ send_message{to=tojid, body="Check out this data!", payloads={reference}}
+ disconnect()
+end)