aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2018-10-05 13:13:04 +0200
committersteckbrief <steckbrief@chefmail.de>2018-10-05 13:13:04 +0200
commit82c3719e0dbad12c5d26f346ec8ef41b48d48ee0 (patch)
treee38692465fa1a6d135e0bc725fd29208494adbe8
parentabe4d4646217e04827cbcef6e012524bbaa0b33c (diff)
moves upload functionality into its own function
-rw-r--r--prosody-module/mod_http_upload_external/mod_http_upload_external.lua52
1 files changed, 28 insertions, 24 deletions
diff --git a/prosody-module/mod_http_upload_external/mod_http_upload_external.lua b/prosody-module/mod_http_upload_external/mod_http_upload_external.lua
index a026da0..50c0bfa 100644
--- a/prosody-module/mod_http_upload_external/mod_http_upload_external.lua
+++ b/prosody-module/mod_http_upload_external/mod_http_upload_external.lua
@@ -188,30 +188,7 @@ local function deletefile(origin, orig_from, stanza, request)
end
end
--- hooks
-module:hook("iq/host/"..xmlns_http_upload..":request", function (event)
- local stanza, origin = event.stanza, event.origin;
- local orig_from = stanza.attr.from;
- local request = stanza.tags[1];
- -- local clients only
- if origin.type ~= "c2s" then
- origin.send(st.error_reply(stanza, "cancel", "not-authorized"));
- return true;
- end
- -- check configuration
- if not external_url or not xmpp_server_key then
- module:log("debug", "missing configuration options: http_upload_external_url and/or http_upload_external_server_key");
- origin.send(st.error_reply(stanza, "cancel", "internal-server-error"));
- return true;
- end
- local slot_type = request.attr.type;
- if slot_type then
- module:log("debug", "incoming request is of type " .. slot_type);
- else
- module:log("debug", "incoming request has no type - using default type 'upload'");
- end
-
- if not slot_type or slot_type == "upload" then
+local function create_upload_slot(origin, orig_from, stanza, request)
-- validate
local filename = request:get_child_text("filename");
if not filename then
@@ -318,6 +295,33 @@ module:hook("iq/host/"..xmlns_http_upload..":request", function (event)
reply:tag("put"):text(put_url):up();
origin.send(reply);
return true;
+end
+
+-- hooks
+module:hook("iq/host/"..xmlns_http_upload..":request", function (event)
+ local stanza, origin = event.stanza, event.origin;
+ local orig_from = stanza.attr.from;
+ local request = stanza.tags[1];
+ -- local clients only
+ if origin.type ~= "c2s" then
+ origin.send(st.error_reply(stanza, "cancel", "not-authorized"));
+ return true;
+ end
+ -- check configuration
+ if not external_url or not xmpp_server_key then
+ module:log("debug", "missing configuration options: http_upload_external_url and/or http_upload_external_server_key");
+ origin.send(st.error_reply(stanza, "cancel", "internal-server-error"));
+ return true;
+ end
+ local slot_type = request.attr.type;
+ if slot_type then
+ module:log("debug", "incoming request is of type " .. slot_type);
+ else
+ module:log("debug", "incoming request has no type - using default type 'upload'");
+ end
+
+ if not slot_type or slot_type == "upload" then
+ return create_upload_slot(origin, orig_from, stanza, request);
elseif slot_type == "delete" then
return deletefile(origin, orig_from, stanza, request);
elseif slot_type == "list" then