Mercurial > prosody-hg
comparison util/jid.lua @ 11200:bf8f2da84007
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 05 Nov 2020 22:31:25 +0100 |
| parents | 0b0a42542456 |
| children | 3616128cd2e3 |
comparison
equal
deleted
inserted
replaced
| 11199:6c7c50a4de32 | 11200:bf8f2da84007 |
|---|---|
| 20 ["/"] = "\\2f"; [":"] = "\\3a"; | 20 ["/"] = "\\2f"; [":"] = "\\3a"; |
| 21 ["<"] = "\\3c"; [">"] = "\\3e"; | 21 ["<"] = "\\3c"; [">"] = "\\3e"; |
| 22 ["@"] = "\\40"; ["\\"] = "\\5c"; | 22 ["@"] = "\\40"; ["\\"] = "\\5c"; |
| 23 }; | 23 }; |
| 24 local unescapes = {}; | 24 local unescapes = {}; |
| 25 for k,v in pairs(escapes) do unescapes[v] = k; end | 25 local backslash_escapes = {}; |
| 26 for k,v in pairs(escapes) do | |
| 27 unescapes[v] = k; | |
| 28 backslash_escapes[v] = v:gsub("\\", escapes) | |
| 29 end | |
| 26 | 30 |
| 27 local _ENV = nil; | 31 local _ENV = nil; |
| 28 -- luacheck: std none | 32 -- luacheck: std none |
| 29 | 33 |
| 30 local function split(jid) | 34 local function split(jid) |
| 43 return node.."@"..host; | 47 return node.."@"..host; |
| 44 end | 48 end |
| 45 return host; | 49 return host; |
| 46 end | 50 end |
| 47 | 51 |
| 48 local function prepped_split(jid) | 52 local function prepped_split(jid, strict) |
| 49 local node, host, resource = split(jid); | 53 local node, host, resource = split(jid); |
| 50 if host and host ~= "." then | 54 if host and host ~= "." then |
| 51 if sub(host, -1, -1) == "." then -- Strip empty root label | 55 if sub(host, -1, -1) == "." then -- Strip empty root label |
| 52 host = sub(host, 1, -2); | 56 host = sub(host, 1, -2); |
| 53 end | 57 end |
| 54 host = nameprep(host); | 58 host = nameprep(host, strict); |
| 55 if not host then return; end | 59 if not host then return; end |
| 56 if node then | 60 if node then |
| 57 node = nodeprep(node); | 61 node = nodeprep(node, strict); |
| 58 if not node then return; end | 62 if not node then return; end |
| 59 end | 63 end |
| 60 if resource then | 64 if resource then |
| 61 resource = resourceprep(resource); | 65 resource = resourceprep(resource, strict); |
| 62 if not resource then return; end | 66 if not resource then return; end |
| 63 end | 67 end |
| 64 return node, host, resource; | 68 return node, host, resource; |
| 65 end | 69 end |
| 66 end | 70 end |
| 75 return host.."/"..resource; | 79 return host.."/"..resource; |
| 76 end | 80 end |
| 77 return host; | 81 return host; |
| 78 end | 82 end |
| 79 | 83 |
| 80 local function prep(jid) | 84 local function prep(jid, strict) |
| 81 local node, host, resource = prepped_split(jid); | 85 local node, host, resource = prepped_split(jid, strict); |
| 82 return join(node, host, resource); | 86 return join(node, host, resource); |
| 83 end | 87 end |
| 84 | 88 |
| 85 local function compare(jid, acl) | 89 local function compare(jid, acl) |
| 86 -- compare jid to single acl rule | 90 -- compare jid to single acl rule |
| 105 | 109 |
| 106 local function resource(jid) | 110 local function resource(jid) |
| 107 return (select(3, split(jid))); | 111 return (select(3, split(jid))); |
| 108 end | 112 end |
| 109 | 113 |
| 110 local function escape(s) return s and (s:gsub(".", escapes)); end | 114 local function escape(s) return s and (s:gsub("\\%x%x", backslash_escapes):gsub("[\"&'/:<>@ ]", escapes)); end |
| 111 local function unescape(s) return s and (s:gsub("\\%x%x", unescapes)); end | 115 local function unescape(s) return s and (s:gsub("\\%x%x", unescapes)); end |
| 112 | 116 |
| 113 return { | 117 return { |
| 114 split = split; | 118 split = split; |
| 115 bare = bare; | 119 bare = bare; |
