diff options
author | ubq323 <ubq323@ubq323.website> | 2024-08-26 14:24:25 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-08-26 14:24:25 +0100 |
commit | 82a68e3d97f88454ed0ca1b639aa61c0f59e352f (patch) | |
tree | b0b25fc4fcdecce35185e520e838301226aac12d /xmpp.lua |
init
Diffstat (limited to 'xmpp.lua')
-rw-r--r-- | xmpp.lua | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/xmpp.lua b/xmpp.lua new file mode 100644 index 0000000..a2ea6cb --- /dev/null +++ b/xmpp.lua @@ -0,0 +1,87 @@ +local jid = 'wilson@ubq323.website' +local server = 'ubq323.website' +local auth = 'AHdpbHNvbgBncmVnb3J5PDM=' +local resource = 'cheese' + + +local cqueues = require'cqueues' +local socket = require'cqueues.socket' + + +local function connect(...) + local sock = assert(socket.connect(... or server, 5222)) + sock:setmode('bn','bn') + + local start = ([[ +<?xml version='1.0'?><stream:stream from='%s' to='%s' version='1.0' xml:lang='en' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>]]):format(jid, server) + + local function check_and_send(test, text) + local x = sock:read('-2048') + print(x) + assert(x:find(test)) + if text then sock:write(text) end + end + + sock:write(start) + check_and_send('starttls', [[<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>]]) + check_and_send('proceed', nil) + sock:starttls() + sock:write(start) + check_and_send('PLAIN', + ([[<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>%s</auth>]]):format(auth)) + check_and_send('success',start) + check_and_send('bind', ([[<iq type='set' id='aaa'> + <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>%s</resource></bind></iq> + ]]):format(resource)) + check_and_send('jid','<presence/>') + + return sock +end + +-- sock:write[[ +-- <iq type='set' id='1234'> +-- <pubsub xmlns='http://jabber.org/protocol/pubsub'> +-- <publish node='urn:xmpp:avatar:metadata'> +-- <item id='89229147c33129fd8d1ab177b6cbea725e72a8b4'> +-- <metadata xmlns='urn:xmpp:avatar:metadata'> +-- <info bytes='54660' +-- height='213' +-- width='203' +-- id='89229147c33129fd8d1ab177b6cbea725e72a8b4' +-- type='image/png' +-- url='https://ubq323.website/files/itAE9dXL.png'/> +-- </metadata> +-- </item> +-- </publish> +-- </pubsub> +-- </iq>]] + +local sock = connect(...) + +local mucs = { + 'ja@conference.ubq323.website' +} + +for _, muc in ipairs(mucs) do + sock:write(([[ + <presence to='%s'> + <x xmlns='http://jabber.org/protocol/muc'/> + </presence>]]):format(muc .. '/wilson')) +end + + +-- sock:write[[<iq type='get' +-- to='ja@conference.ubq323.website/viba' +-- id='retrieve1'> +-- <pubsub xmlns='http://jabber.org/protocol/pubsub'> +-- <items node='urn:xmpp:avatar:data'> +-- <item id='9c78e85250ef6f74f44f3142f559cc4f4465298c'/> +-- </items> +-- </pubsub> +-- </iq>]] + +local xml=require'xml' +for x in xml.stanzae(function() return sock:read('-2048') end) do + print(x) +end + |