core/componentmanager.lua

changeset 3584
5d880c365dd4
parent 3561
579c087059fc
child 3586
78ed7ad330ab
equal deleted inserted replaced
3583:ef86ba720f00 3584:5d880c365dd4
14 local jid_split = require "util.jid".split; 14 local jid_split = require "util.jid".split;
15 local fire_event = prosody.events.fire_event; 15 local fire_event = prosody.events.fire_event;
16 local events_new = require "util.events".new; 16 local events_new = require "util.events".new;
17 local st = require "util.stanza"; 17 local st = require "util.stanza";
18 local prosody, hosts = prosody, prosody.hosts; 18 local prosody, hosts = prosody, prosody.hosts;
19 local ssl = ssl;
20 local uuid_gen = require "util.uuid".generate; 19 local uuid_gen = require "util.uuid".generate;
21 20
22 local pairs, setmetatable, type, tostring = pairs, setmetatable, type, tostring; 21 local pairs, setmetatable, type, tostring = pairs, setmetatable, type, tostring;
23 22
24 local components = {}; 23 local components = {};
74 end 73 end
75 end 74 end
76 75
77 function create_component(host, component, events) 76 function create_component(host, component, events)
78 -- TODO check for host well-formedness 77 -- TODO check for host well-formedness
79 local ssl_ctx, ssl_ctx_in;
80 if host and ssl then
81 -- We need to find SSL context to use...
82 -- Discussion in prosody@ concluded that
83 -- 1 level back is usually enough by default
84 local base_host = host:gsub("^[^%.]+%.", "");
85 if hosts[base_host] then
86 ssl_ctx = hosts[base_host].ssl_ctx;
87 ssl_ctx_in = hosts[base_host].ssl_ctx_in;
88 else
89 -- We have no cert, and no parent host to borrow a cert from
90 -- Use global/default cert if there is one
91 ssl_ctx = certmanager.create_context(host, "client");
92 ssl_ctx_in = certmanager.create_context(host, "server");
93 end
94 end
95 return { type = "component", host = host, connected = true, s2sout = {}, 78 return { type = "component", host = host, connected = true, s2sout = {},
96 ssl_ctx = ssl_ctx, ssl_ctx_in = ssl_ctx_in, events = events or events_new(), 79 events = events or events_new(),
97 dialback_secret = configmanager.get(host, "core", "dialback_secret") or uuid_gen(), 80 dialback_secret = configmanager.get(host, "core", "dialback_secret") or uuid_gen(),
98 disallow_s2s = configmanager.get(host, "core", "disallow_s2s"); }; 81 disallow_s2s = configmanager.get(host, "core", "disallow_s2s"); };
99 end 82 end
100 83
101 function register_component(host, component) 84 function register_component(host, component)

mercurial