|
@@ -1,6 +1,45 @@
|
1
|
1
|
local jid = require "util.jid";
|
2
|
2
|
local runner, waiter = require "util.async".runner, require "util.async".waiter;
|
3
|
3
|
|
|
4
|
+local muc_domain_prefix
|
|
5
|
+ = module:get_option_string("muc_mapper_domain_prefix", "conference");
|
|
6
|
+
|
|
7
|
+-- defaults to module.host, the module that uses the utility
|
|
8
|
+local muc_domain_base
|
|
9
|
+ = module:get_option_string("muc_mapper_domain_base", module.host);
|
|
10
|
+
|
|
11
|
+-- The "real" MUC domain that we are proxying to
|
|
12
|
+local muc_domain = module:get_option_string(
|
|
13
|
+ "muc_mapper_domain", muc_domain_prefix.."."..muc_domain_base);
|
|
14
|
+
|
|
15
|
+local escaped_muc_domain_base = muc_domain_base:gsub("%p", "%%%1");
|
|
16
|
+local escaped_muc_domain_prefix = muc_domain_prefix:gsub("%p", "%%%1");
|
|
17
|
+-- The pattern used to extract the target subdomain
|
|
18
|
+-- (e.g. extract 'foo' from 'foo.muc.example.com')
|
|
19
|
+local target_subdomain_pattern
|
|
20
|
+ = "^"..escaped_muc_domain_prefix..".([^%.]+)%."..escaped_muc_domain_base;
|
|
21
|
+
|
|
22
|
+--- Utility function to check and convert a room JID from
|
|
23
|
+-- virtual room1@muc.foo.example.com to real [foo]room1@muc.example.com
|
|
24
|
+-- @param room_jid the room jid to match and rewrite if needed
|
|
25
|
+-- @return returns room jid [foo]room1@muc.example.com when it has subdomain
|
|
26
|
+-- otherwise room1@muc.example.com(the room_jid value untouched)
|
|
27
|
+local function room_jid_match_rewrite(room_jid)
|
|
28
|
+ local node, host, resource = jid.split(room_jid);
|
|
29
|
+ local target_subdomain = host and host:match(target_subdomain_pattern);
|
|
30
|
+ if not target_subdomain then
|
|
31
|
+ module:log("debug", "No need to rewrite out 'to' %s", room_jid);
|
|
32
|
+ return room_jid;
|
|
33
|
+ end
|
|
34
|
+ -- Ok, rewrite room_jid address to new format
|
|
35
|
+ local new_node, new_host, new_resource
|
|
36
|
+ = "["..target_subdomain.."]"..node, muc_domain, resource;
|
|
37
|
+ room_jid = jid.join(new_node, new_host, new_resource);
|
|
38
|
+ module:log("debug", "Rewrote to %s", room_jid);
|
|
39
|
+ return room_jid
|
|
40
|
+end
|
|
41
|
+
|
|
42
|
+
|
4
|
43
|
--- Finds and returns room by its jid
|
5
|
44
|
-- @param room_jid the room jid to search in the muc component
|
6
|
45
|
-- @return returns room if found or nil
|
|
@@ -37,4 +76,5 @@ end
|
37
|
76
|
return {
|
38
|
77
|
get_room_from_jid = get_room_from_jid;
|
39
|
78
|
wrap_async_run = wrap_async_run;
|
|
79
|
+ room_jid_match_rewrite= room_jid_match_rewrite;
|
40
|
80
|
};
|