summaryrefslogtreecommitdiff
path: root/xmpp.lua
blob: a2ea6cb92de9218da350d50eb7a1646f5dbea991 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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