XMPP/Jabber echo bot (written in sed)
Do you know that situation, you really really need an XMPP echo bot, but you don’t have access to high-level tools like Python <https://github.com/horazont/aioxmpp>
_ to write one? All you have is openssl
, bash
, dig
, stdbuf
and sed
? Then this tool is for you.
This is an XMPP echo bot written in (mostly) sed. Bash is used to do the pre-authentication setup (look up DNS records, establish TLS via openssl s_client
). sed processes the XML stream and handles all interaction with the server on the XMPP level. Yes, this kinda parses XML in sed.
Tested to work against Prosody 0.9.
::
./echoz.sh user@domain password
XEP-0092 (Software Version) <https://xmpp.org/extensions/xep-0092.html>
_XEP-0199 (XMPP Ping) <https://xmpp.org/extensions/xep-0199.html>
_Matthew Wild <https://github.com/mwild1>
_Georg Lukas <https://op-co.de/>
_Lance <https://github.com/legastero>
_Wikipedia <https://en.wikipedia.org/wiki/Sed>
_Test <xmpp:[email protected]>
_tr
to convert >
to \n
-- since sed is line (or NUL) based, there’s not really another way to parse XMPP XML (which generally never contains newlines) with sed.Design Considerations
xml2
to convert the XML stream into events; however, it turns out that 2xm[
doesn’t like stream resets. Also, using the tr
approach also allows us to detect the end of elements, which is useful for various purposes.