25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-26 17:38:45 +01:00

Merge remote-tracking branch 'processone/pr/1699'

* processone/pr/1699:
  Add support for HTTP File Upload, version 0.3.0
This commit is contained in:
Holger Weiss 2017-04-26 21:18:16 +02:00
commit 9b8364b6c8

View File

@ -512,12 +512,31 @@ process_iq(#iq{type = get, lang = Lang, sub_els = [#disco_info{}]} = IQ,
xmpp:make_iq_result(IQ, iq_disco_info(ServerHost, Lang, Name, AddInfo)); xmpp:make_iq_result(IQ, iq_disco_info(ServerHost, Lang, Name, AddInfo));
process_iq(#iq{type = get, sub_els = [#disco_items{}]} = IQ, _State) -> process_iq(#iq{type = get, sub_els = [#disco_items{}]} = IQ, _State) ->
xmpp:make_iq_result(IQ, #disco_items{}); xmpp:make_iq_result(IQ, #disco_items{});
process_iq(#iq{type = get, lang = Lang, from = From, process_iq(#iq{type = get, sub_els = [#upload_request{filename = File,
sub_els = [#upload_request{filename = File, size = Size,
size = Size, 'content-type' = CType,
'content-type' = CType, xmlns = XMLNS}]} = IQ,
xmlns = XMLNS}]} = IQ, State) ->
#state{server_host = ServerHost, access = Access} = State) -> process_slot_request(IQ, File, Size, CType, XMLNS, State);
process_iq(#iq{type = get, sub_els = [#upload_request_0{filename = File,
size = Size,
'content-type' = CType,
xmlns = XMLNS}]} = IQ,
State) ->
process_slot_request(IQ, File, Size, CType, XMLNS, State);
process_iq(#iq{type = T, lang = Lang} = IQ, _State) when T == get; T == set ->
Txt = <<"No module is handling this query">>,
xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang));
process_iq(#iq{}, _State) ->
not_request.
-spec process_slot_request(iq(), binary(), pos_integer(), binary(), binary(),
state()) -> {iq(), state()} | iq().
process_slot_request(#iq{lang = Lang, from = From} = IQ,
File, Size, CType, XMLNS,
#state{server_host = ServerHost,
access = Access} = State) ->
case acl:match_rule(ServerHost, Access, From) of case acl:match_rule(ServerHost, Access, From) of
allow -> allow ->
ContentType = yield_content_type(CType), ContentType = yield_content_type(CType),
@ -540,12 +559,7 @@ process_iq(#iq{type = get, lang = Lang, from = From,
[jid:encode(From)]), [jid:encode(From)]),
Txt = <<"Denied by ACL">>, Txt = <<"Denied by ACL">>,
xmpp:make_error(IQ, xmpp:err_forbidden(Txt, Lang)) xmpp:make_error(IQ, xmpp:err_forbidden(Txt, Lang))
end; end.
process_iq(#iq{type = T, lang = Lang} = IQ, _State) when T == get; T == set ->
Txt = <<"No module is handling this query">>,
xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang));
process_iq(#iq{}, _State) ->
not_request.
-spec create_slot(state(), jid(), binary(), pos_integer(), binary(), binary()) -spec create_slot(state(), jid(), binary(), pos_integer(), binary(), binary())
-> {ok, slot()} | {ok, binary(), binary()} | {error, xmlel()}. -> {ok, slot()} | {ok, binary(), binary()} | {error, xmlel()}.
@ -649,6 +663,8 @@ mk_slot(Slot, #state{put_url = PutPrefix, get_url = GetPrefix}, XMLNS) ->
PutURL = str:join([PutPrefix | Slot], <<$/>>), PutURL = str:join([PutPrefix | Slot], <<$/>>),
GetURL = str:join([GetPrefix | Slot], <<$/>>), GetURL = str:join([GetPrefix | Slot], <<$/>>),
mk_slot(PutURL, GetURL, XMLNS); mk_slot(PutURL, GetURL, XMLNS);
mk_slot(PutURL, GetURL, ?NS_HTTP_UPLOAD_0) ->
#upload_slot_0{get = GetURL, put = PutURL, xmlns = ?NS_HTTP_UPLOAD_0};
mk_slot(PutURL, GetURL, XMLNS) -> mk_slot(PutURL, GetURL, XMLNS) ->
#upload_slot{get = GetURL, put = PutURL, xmlns = XMLNS}. #upload_slot{get = GetURL, put = PutURL, xmlns = XMLNS}.
@ -702,18 +718,27 @@ iq_disco_info(Host, Lang, Name, AddInfo) ->
AddInfo; AddInfo;
MaxSize -> MaxSize ->
MaxSizeStr = integer_to_binary(MaxSize), MaxSizeStr = integer_to_binary(MaxSize),
Fields = [#xdata_field{type = hidden, XData = lists:map(
var = <<"FORM_TYPE">>, fun(NS) ->
values = [?NS_HTTP_UPLOAD]}, Fields = [#xdata_field{
#xdata_field{var = <<"max-file-size">>, type = hidden,
values = [MaxSizeStr]}], var = <<"FORM_TYPE">>,
[#xdata{type = result, fields = Fields}|AddInfo] values = [NS]},
#xdata_field{
var = <<"max-file-size">>,
values = [MaxSizeStr]}],
#xdata{type = result, fields = Fields}
end, [?NS_HTTP_UPLOAD, ?NS_HTTP_UPLOAD_0]),
XData ++ AddInfo
end, end,
#disco_info{identities = [#identity{category = <<"store">>, #disco_info{identities = [#identity{category = <<"store">>,
type = <<"file">>, type = <<"file">>,
name = translate:translate(Lang, Name)}], name = translate:translate(Lang, Name)}],
features = [?NS_HTTP_UPLOAD, ?NS_HTTP_UPLOAD_OLD, features = [?NS_HTTP_UPLOAD,
?NS_DISCO_INFO, ?NS_DISCO_ITEMS], ?NS_HTTP_UPLOAD_0,
?NS_HTTP_UPLOAD_OLD,
?NS_DISCO_INFO,
?NS_DISCO_ITEMS],
xdata = Form}. xdata = Form}.
%% HTTP request handling. %% HTTP request handling.