summaryrefslogtreecommitdiff
path: root/xmpp
diff options
context:
space:
mode:
authorrebecca <ubq323@ubq323.website>2026-09-12 18:30:08 +0100
committerrebecca <ubq323@ubq323.website>2026-09-12 18:33:50 +0100
commit085040f49cc1386b294857aa68651329b0044420 (patch)
tree5d9a5e7d011e384ae1ca36a64be4f4eaca9f8ca0 /xmpp
parentfa9da79c39f62439ece735ed0e7dfe4c4c9692b2 (diff)
refactor classes and inheritance
Diffstat (limited to 'xmpp')
-rw-r--r--xmpp/pylon.lua82
1 files changed, 9 insertions, 73 deletions
diff --git a/xmpp/pylon.lua b/xmpp/pylon.lua
index 2476fc9..b3b6bc7 100644
--- a/xmpp/pylon.lua
+++ b/xmpp/pylon.lua
@@ -1,60 +1,22 @@
local socket = require'cqueues.socket'
+local class = require'r.class'
+
+local Channel = require'channel'
+local BasePylon = require 'pylon'
local xml = require'xmpp.xml'
-local X = xml.X
-local xmlify = xml.xmlify
+local X,xmlify = xml.X, xml.xmlify
local base64 = require'xmpp.base64'
local sha1 = require'xmpp.sha1'
-local Channel = require'channel'
-local pylon = require 'pylon'
-local Xmpp = pylon.subclass "xmpp"
-
-local function make_auth(authz, authn, password)
- -- sasl plain (RFC4616)
- return base64.encode(authz..'\0'..authn..'\0'..password)
-end
+local Xmpp = class.extend(BasePylon)
function Xmpp.init(self)
- self:check_config "server component component_secret"
-
- self.cq = self.wilson.cq -- todo
- self.nicks_inuse = {} -- todo
-end
-
-function Xmpp._connect_c2s(self)
- local sock = assert(socket.connect(self.server, 5222))
- self.sock = sock
- 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(self.jid, self.server)
-
- -- state of the art xml parser
- local function check_and_send(test, text)
- local x = sock:read('-2048')
- assert(x:find(test))
- if text then sock:write(text) end
- end
- local function ietf_urn(v) return 'urn:ietf:params:xml:ns:xmpp-'..v end
-
- sock:write(start)
- check_and_send('starttls', xmlify(X.starttls{xmlns=ietf_urn"tls"}))
- check_and_send('proceed', nil)
- sock:starttls()
- sock:write(start)
- local auth = make_auth('', self.jid:match"(.*)@", self.password)
- check_and_send('PLAIN',
- xmlify(X.auth{xmlns=ietf_urn"sasl", mechanism='PLAIN', auth}))
- check_and_send('success',start)
- check_and_send('bind',
- xmlify(X.iq{type='set', id='aaaa',
- X.bind{xmlns=ietf_urn"bind", X.resource{self.resource}}}))
- check_and_send('jid',X.presence{X.show{'chat'}})
+ self:_check_fields"server component component_secret"
- return sock
+ self.nicks_inuse = {}
end
--- this sucks! no tls! no security! only use on local connections!
+-- only use on local connections!
function Xmpp._connect_component(self)
local sock = assert(socket.connect(self.server, 5347))
self.sock = sock
@@ -62,8 +24,6 @@ function Xmpp._connect_component(self)
-- yes, our component name goes in the 'to' field. don't ask me why
local start = ([[<stream:stream to='%s' xmlns='jabber:component:accept' xmlns:stream='http://etherx.jabber.org/streams'>]]):format(self.component)
- -- print(start)
-
-- state of the art xml parser
local function check_and_send(test, text)
local x = sock:read('-2048')
@@ -73,7 +33,6 @@ function Xmpp._connect_component(self)
sock:write(start)
local streamhead = sock:read('-2048')
- -- print('streamhead', streamhead)
assert(streamhead:find'accept')
local streamid = streamhead:match"id='(.-)'"
sock:write(xmlify(X.handshake{sha1.sha1(streamid..self.component_secret)}))
@@ -81,7 +40,6 @@ function Xmpp._connect_component(self)
return sock
end
-Xmpp._connect = Xmpp._connect_component
local THE_MUC = 'd@conference.ubq323.website'
@@ -139,26 +97,4 @@ function Xmpp.sending(self)
end
end
-function Xmpp.post(self, dest_channel, message)
- self.inbox:enqueue(dest_channel, message)
-end
-
return Xmpp
-
--- local cq = cqueues.new()
--- local conf = {
--- jid='wilson@ubq323.website',
--- server='ubq323.website',
--- password='gregory<3',
--- resource='cheese',
--- }
--- local dummy_network = {
--- post = function(self, pylonname, channel, message)
--- pprint(pylonname, channel, message)
--- end
--- }
--- local pylon = Xmpp.makepylon('xmpptest',conf, cq, dummy_network)
--- pylon:run()
-
--- pprint('peas', cq:loop())
-