|
@@ -114,22 +114,10 @@ local services_mt = {
|
114
|
114
|
end;
|
115
|
115
|
}
|
116
|
116
|
|
117
|
|
-local function handle_services(event)
|
118
|
|
- local origin, stanza = event.origin, event.stanza;
|
119
|
|
- local action = stanza.tags[1];
|
120
|
|
-
|
121
|
|
- local user_bare = jid.bare(stanza.attr.from);
|
122
|
|
- local user_host = jid.host(user_bare);
|
123
|
|
- if not ((access:empty() and origin.type == "c2s") or access:contains(user_bare) or access:contains(user_host)) then
|
124
|
|
- origin.send(st.error_reply(stanza, "auth", "forbidden"));
|
125
|
|
- return true;
|
126
|
|
- end
|
127
|
|
-
|
128
|
|
- local reply = st.reply(stanza):tag("services", { xmlns = action.attr.xmlns });
|
|
117
|
+function get_services(requested_type, origin, stanza, reply)
|
129
|
118
|
local extras = module:get_host_items("external_service");
|
130
|
119
|
local services = ( configured_services + extras ) / prepare;
|
131
|
120
|
|
132
|
|
- local requested_type = action.attr.type;
|
133
|
121
|
if requested_type then
|
134
|
122
|
services:filter(function(item)
|
135
|
123
|
return item.type == requested_type;
|
|
@@ -138,25 +126,48 @@ local function handle_services(event)
|
138
|
126
|
|
139
|
127
|
setmetatable(services, services_mt);
|
140
|
128
|
|
141
|
|
- module:fire_event("external_service/services", {
|
|
129
|
+ if origin and stanza and reply then
|
|
130
|
+ module:fire_event("external_service/services", {
|
142
|
131
|
origin = origin;
|
143
|
132
|
stanza = stanza;
|
144
|
133
|
reply = reply;
|
145
|
134
|
requested_type = requested_type;
|
146
|
135
|
services = services;
|
147
|
136
|
});
|
|
137
|
+ end
|
148
|
138
|
|
|
139
|
+ local res_services = {};
|
149
|
140
|
for _, srv in ipairs(services) do
|
150
|
|
- reply:tag("service", {
|
151
|
|
- type = srv.type;
|
152
|
|
- transport = srv.transport;
|
153
|
|
- host = srv.host;
|
154
|
|
- port = srv.port and string.format("%d", srv.port) or nil;
|
155
|
|
- username = srv.username;
|
156
|
|
- password = srv.password;
|
157
|
|
- expires = srv.expires and dt.datetime(srv.expires) or nil;
|
158
|
|
- restricted = srv.restricted and "1" or nil;
|
159
|
|
- }):up();
|
|
141
|
+ table.insert(res_services, {
|
|
142
|
+ type = srv.type;
|
|
143
|
+ transport = srv.transport;
|
|
144
|
+ host = srv.host;
|
|
145
|
+ port = srv.port and string.format("%d", srv.port) or nil;
|
|
146
|
+ username = srv.username;
|
|
147
|
+ password = srv.password;
|
|
148
|
+ expires = srv.expires and dt.datetime(srv.expires) or nil;
|
|
149
|
+ restricted = srv.restricted and "1" or nil;
|
|
150
|
+ })
|
|
151
|
+ end
|
|
152
|
+
|
|
153
|
+ return res_services;
|
|
154
|
+end
|
|
155
|
+
|
|
156
|
+local function handle_services(event)
|
|
157
|
+ local origin, stanza = event.origin, event.stanza;
|
|
158
|
+ local action = stanza.tags[1];
|
|
159
|
+
|
|
160
|
+ local user_bare = jid.bare(stanza.attr.from);
|
|
161
|
+ local user_host = jid.host(user_bare);
|
|
162
|
+ if not ((access:empty() and origin.type == "c2s") or access:contains(user_bare) or access:contains(user_host)) then
|
|
163
|
+ origin.send(st.error_reply(stanza, "auth", "forbidden"));
|
|
164
|
+ return true;
|
|
165
|
+ end
|
|
166
|
+
|
|
167
|
+ local reply = st.reply(stanza):tag("services", { xmlns = action.attr.xmlns });
|
|
168
|
+
|
|
169
|
+ for _, srv in ipairs(get_services(action.attr.type, origin, stanza, reply)) do
|
|
170
|
+ reply:tag("service", srv):up();
|
160
|
171
|
end
|
161
|
172
|
|
162
|
173
|
origin.send(reply);
|