comparison mod_client_proxy/mod_client_proxy.lua @ 3101:a14a573d43ff

mod_client_proxy: fix warnings
author Jonas Wielicki <jonas@wielicki.name>
date Sun, 03 Jun 2018 16:26:25 +0200
parents a81456a13797
children
comparison
equal deleted inserted replaced
3100:0422fb55cc37 3101:a14a573d43ff
1 if module:get_host_type() ~= "component" then 1 if module:get_host_type() ~= "component" then
2 error("proxy_component should be loaded as component", 0); 2 error("proxy_component should be loaded as component", 0);
3 end 3 end
4
5 local comp_host = module:get_host();
6 local comp_name = module:get_option_string("name", "Proxy Component");
7 4
8 local jid_split = require "util.jid".split; 5 local jid_split = require "util.jid".split;
9 local jid_bare = require "util.jid".bare; 6 local jid_bare = require "util.jid".bare;
10 local jid_prep = require "util.jid".prep; 7 local jid_prep = require "util.jid".prep;
11 local st = require "util.stanza"; 8 local st = require "util.stanza";
12 local array = require "util.array"; 9 local array = require "util.array";
13 10
14 local target_address = module:get_option_string("target_address"); 11 local target_address = module:get_option_string("target_address");
15 12
16 local hosts = prosody.hosts;
17
18 sessions = array{}; 13 sessions = array{};
19 local sessions = sessions; 14 local sessions = sessions;
20 15
21 local function handle_target_presence(origin, stanza) 16 local function handle_target_presence(stanza)
22 local type = stanza.attr.type; 17 local type = stanza.attr.type;
23 module:log("debug", "received presence from destination: %s", type) 18 module:log("debug", "received presence from destination: %s", type)
24 local _, _, resource = jid_split(stanza.attr.from); 19 local _, _, resource = jid_split(stanza.attr.from);
25 if type == "error" then 20 if type == "error" then
26 -- drop all known sessions 21 -- drop all known sessions
62 sessions:push(resource) 57 sessions:push(resource)
63 end 58 end
64 end 59 end
65 end 60 end
66 61
67 local function handle_from_target(origin, stanza) 62 local function handle_from_target(stanza)
68 local type = stanza.attr.type 63 local type = stanza.attr.type
69 module:log( 64 module:log(
70 "debug", 65 "debug",
71 "non-presence stanza from target: name = %s, type = %s", 66 "non-presence stanza from target: name = %s, type = %s",
72 stanza.name, 67 stanza.name,
109 -- break 104 -- break
110 module:send(st.error_reply(stanza, "cancel", "feature-not-implemented")) 105 module:send(st.error_reply(stanza, "cancel", "feature-not-implemented"))
111 end 106 end
112 end 107 end
113 108
114 local function handle_to_target(origin, stanza) 109 local function handle_to_target(stanza)
115 local type = stanza.attr.type; 110 local type = stanza.attr.type;
116 module:log( 111 module:log(
117 "debug", 112 "debug",
118 "stanza to target: name = %s, type = %s", 113 "stanza to target: name = %s, type = %s",
119 stanza.name, type 114 stanza.name, type
150 145
151 stanza.attr.from = natted_from 146 stanza.attr.from = natted_from
152 stanza.attr.to = target 147 stanza.attr.to = target
153 148
154 module:send(stanza) 149 module:send(stanza)
155 else 150 end
156 -- FIXME: handle and forward result/error correctly 151 -- FIXME: handle and forward result/error correctly
157 end
158 elseif stanza.name == "message" then 152 elseif stanza.name == "message" then
159 -- not implemented yet, we need a way to ensure that routing doesn’t 153 -- not implemented yet, we need a way to ensure that routing doesn’t
160 -- break 154 -- break
161 module:send(st.error_reply(stanza, "cancel", "feature-not-implemented")) 155 module:send(st.error_reply(stanza, "cancel", "feature-not-implemented"))
162 end 156 end
171 if bare_from == target_address then 165 if bare_from == target_address then
172 -- from our target, to whom? 166 -- from our target, to whom?
173 if not to then 167 if not to then
174 -- directly to component 168 -- directly to component
175 if stanza.name == "presence" then 169 if stanza.name == "presence" then
176 handle_target_presence(origin, stanza) 170 handle_target_presence(stanza)
177 else 171 else
178 module:send(st.error_reply(stanza, "cancel", "bad-request")) 172 module:send(st.error_reply(stanza, "cancel", "bad-request"))
179 return true 173 return true
180 end 174 end
181 else 175 else
182 -- to someone else 176 -- to someone else
183 handle_from_target(origin, stanza) 177 handle_from_target(stanza)
184 end 178 end
185 else 179 else
186 handle_to_target(origin, stanza) 180 handle_to_target(stanza)
187 end 181 end
188 return true 182 return true
189 end 183 end
190 184
191 module:hook("iq/bare", stanza_handler, -1); 185 module:hook("iq/bare", stanza_handler, -1);