Software /
code /
prosody
Comparison
util/jid.lua @ 12802:4a8740e01813
Merge 0.12->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 12 Dec 2022 07:10:54 +0100 |
parent | 12769:27e1d4354274 |
child | 12975:d10957394a3c |
comparison
equal
deleted
inserted
replaced
12801:ebd6b4d8bf04 | 12802:4a8740e01813 |
---|---|
33 | 33 |
34 local function split(jid) | 34 local function split(jid) |
35 if jid == nil then return; end | 35 if jid == nil then return; end |
36 local node, nodepos = match(jid, "^([^@/]+)@()"); | 36 local node, nodepos = match(jid, "^([^@/]+)@()"); |
37 local host, hostpos = match(jid, "^([^@/]+)()", nodepos); | 37 local host, hostpos = match(jid, "^([^@/]+)()", nodepos); |
38 if node ~= nil and host == nil then return nil, nil, nil; end | 38 local resource = host and match(jid, "^/(.+)$", hostpos); |
39 local resource = match(jid, "^/(.+)$", hostpos); | |
40 if (host == nil) or ((resource == nil) and #jid >= hostpos) then return nil, nil, nil; end | 39 if (host == nil) or ((resource == nil) and #jid >= hostpos) then return nil, nil, nil; end |
41 return node, host, resource; | 40 return node, host, resource; |
42 end | 41 end |
43 | 42 |
44 local function bare(jid) | 43 local function bare(jid) |
89 local function compare(jid, acl) | 88 local function compare(jid, acl) |
90 -- compare jid to single acl rule | 89 -- compare jid to single acl rule |
91 -- TODO compare to table of rules? | 90 -- TODO compare to table of rules? |
92 local jid_node, jid_host, jid_resource = split(jid); | 91 local jid_node, jid_host, jid_resource = split(jid); |
93 local acl_node, acl_host, acl_resource = split(acl); | 92 local acl_node, acl_host, acl_resource = split(acl); |
94 if ((acl_node ~= nil and acl_node == jid_node) or acl_node == nil) and | 93 if (acl_node == nil or acl_node == jid_node) and |
95 ((acl_host ~= nil and acl_host == jid_host) or acl_host == nil) and | 94 (acl_host == nil or acl_host == jid_host) and |
96 ((acl_resource ~= nil and acl_resource == jid_resource) or acl_resource == nil) then | 95 (acl_resource == nil or acl_resource == jid_resource) then |
97 return true | 96 return true |
98 end | 97 end |
99 return false | 98 return false |
100 end | 99 end |
101 | 100 |
109 | 108 |
110 local function resource(jid) | 109 local function resource(jid) |
111 return (select(3, split(jid))); | 110 return (select(3, split(jid))); |
112 end | 111 end |
113 | 112 |
113 -- TODO Forbid \20 at start and end of escaped output per XEP-0106 v1.1 | |
114 local function escape(s) return s and (s:gsub("\\%x%x", backslash_escapes):gsub("[\"&'/:<>@ ]", escapes)); end | 114 local function escape(s) return s and (s:gsub("\\%x%x", backslash_escapes):gsub("[\"&'/:<>@ ]", escapes)); end |
115 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 |
116 | 116 |
117 return { | 117 return { |
118 split = split; | 118 split = split; |