diff options
Diffstat (limited to 'Sluift/Examples')
-rw-r--r-- | Sluift/Examples/MAMRSM.lua | 23 | ||||
-rw-r--r-- | Sluift/Examples/MAMRSMPage.lua | 36 | ||||
-rw-r--r-- | Sluift/Examples/MAMSimple.lua | 19 | ||||
-rw-r--r-- | Sluift/Examples/MAMSupportedFields.lua | 18 | ||||
-rw-r--r-- | Sluift/Examples/MAMUser.lua | 25 |
5 files changed, 121 insertions, 0 deletions
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() |