diff options
Diffstat (limited to 'prosody-module/mod_http_upload_external')
-rw-r--r-- | prosody-module/mod_http_upload_external/mod_http_upload_external.lua | 64 |
1 files changed, 39 insertions, 25 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 001894c..4f4e83b 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 @@ -28,6 +28,10 @@ module:depends("disco"); -- namespace local xmlns_http_upload = "urn:xmpp:filetransfer:http"; +-- versions +spec_version = "v0.3"; +impl_version = "v0.3-dev"; + module:add_feature(xmlns_http_upload); if filetransfer_manager_ui_url then @@ -185,31 +189,8 @@ 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 - -- validate +local function create_upload_slot(origin, orig_from, stanza, request) + -- validate local filename = request:get_child_text("filename"); if not filename then origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid filename")); @@ -315,10 +296,43 @@ 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 return listfiles(origin, orig_from, stanza, request); + elseif slot_type == "version" then + local reply = st.reply(stanza); + reply:tag("version", { xmlns = xmlns_http_upload }); + reply:tag("xmpp-fileservice-module", { spec = spec_version, implementation = impl_version }):up(); + origin.send(reply); + return true; else origin.send(st.error_reply(stanza, "cancel", "undefined-condition", "status code: " .. statuscode .. " response: " ..respbody)); return true; |