# HG changeset patch # User Matthew Wild # Date 1368052250 -3600 # Node ID 767999c39f0a51f69ddf172066fe3aefec1a9e9b # Parent 225d3ba1eb7bb7cdd31beaaecbabda7699d85b2a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago... diff -r 225d3ba1eb7b -r 767999c39f0a mod_jid_prep/mod_jid_prep.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_jid_prep/mod_jid_prep.lua Wed May 08 23:30:50 2013 +0100 @@ -0,0 +1,28 @@ +-- Run JIDs through stringprep processing on behalf of clients +-- http://xmpp.org/extensions/inbox/jidprep.html + +local jid_prep = require "util.jid".prep; +local st = require "util.stanza"; + +local xmlns_prep = "urn:xmpp:jidprep:tmp"; + +function prep_jid(event) + local stanza = event.stanza; + local jid = jid_prep(stanza:get_child_text("jid", xmlns_prep)); + if not jid then + return event.origin.send(st.error_reply(stanza, "modify", "jid-malformed")); + end + return event.origin.send(st.reply(stanza):tag("jid", { xmlns = xmlns_prep }):text(jid)); +end + + +module:hook("iq/host/"..xmlns_prep..":jid", prep_jid); + +module:depends("http"); +module:provides("http", { + route = { + ["GET /*"] = function (event, jid) + return jid_prep(jid) or 400; + end; + } +});