mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
Use jlib:parse_xdata_submit/1 in is_voice_request/1 and is_voice_approvement/1
This commit is contained in:
parent
b1d8168dd3
commit
7c8eab4f43
@ -337,7 +337,7 @@ normal_state({route, From, "",
|
|||||||
NewStateData = case is_moderator(From, StateData) of
|
NewStateData = case is_moderator(From, StateData) of
|
||||||
true ->
|
true ->
|
||||||
case extract_jid_from_voice_approvement(Els) of
|
case extract_jid_from_voice_approvement(Els) of
|
||||||
{error, X} ->
|
{error, _} ->
|
||||||
ErrText = "Failed to extract JID from your voice request approvement",
|
ErrText = "Failed to extract JID from your voice request approvement",
|
||||||
Err = jlib:make_error_reply(
|
Err = jlib:make_error_reply(
|
||||||
Packet, ?ERRT_BAD_REQUEST(Lang, ErrText)),
|
Packet, ?ERRT_BAD_REQUEST(Lang, ErrText)),
|
||||||
@ -3721,46 +3721,53 @@ get_mucroom_disco_items(StateData) ->
|
|||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
% Voice request support
|
% Voice request support
|
||||||
|
|
||||||
|
is_voice_request({xmlelement, "x", _, _} = Elem) ->
|
||||||
|
try
|
||||||
|
case xml:get_tag_attr_s("xmlns", Elem) of
|
||||||
|
?NS_XDATA ->
|
||||||
|
Fields = jlib:parse_xdata_submit(Elem),
|
||||||
|
lists:foldl(
|
||||||
|
fun(X,Y) ->
|
||||||
|
check_voice_request_fields(X,Y)
|
||||||
|
end,
|
||||||
|
true, Fields)
|
||||||
|
end
|
||||||
|
catch
|
||||||
|
error: _ ->
|
||||||
|
false
|
||||||
|
end;
|
||||||
is_voice_request(Els) ->
|
is_voice_request(Els) ->
|
||||||
try
|
lists:foldl(
|
||||||
case xml:remove_cdata(Els) of
|
fun(X, Acc) ->
|
||||||
[{xmlelement, "x", _, Els1} = XEl] ->
|
case Acc of
|
||||||
case xml:get_tag_attr_s("xmlns", XEl) of
|
false ->
|
||||||
?NS_XDATA ->
|
case X of
|
||||||
lists:foldl(
|
{xmlelement, "x", _, _} ->
|
||||||
fun(X,Y) ->
|
is_voice_request(X);
|
||||||
check_voice_request_fields(X,Y)
|
_ ->
|
||||||
end,
|
false
|
||||||
true, xml:remove_cdata(Els1))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
catch
|
|
||||||
error: _ ->
|
|
||||||
false
|
|
||||||
end.
|
|
||||||
|
|
||||||
check_voice_request_fields({xmlelement, "field", _, Els} = Elem, Acc) ->
|
|
||||||
try
|
|
||||||
case Acc of
|
|
||||||
true ->
|
|
||||||
case xml:get_tag_attr_s("var", Elem) of
|
|
||||||
"FORM_TYPE" ->
|
|
||||||
[{xmlelement, "value", _, Value}] = xml:remove_cdata(Els),
|
|
||||||
case xml:get_cdata(Value) of
|
|
||||||
"http://jabber.org/protocol/muc#request" ->
|
|
||||||
true
|
|
||||||
end;
|
end;
|
||||||
"muc#role" ->
|
true ->
|
||||||
[{xmlelement, "value", _, Value}] = xml:remove_cdata(Els),
|
true
|
||||||
case xml:get_cdata(Value) of
|
|
||||||
"participant" ->
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end, false, Els).
|
||||||
|
|
||||||
|
check_voice_request_fields({Field, Value}, Acc) ->
|
||||||
|
if Acc ->
|
||||||
|
case Field of
|
||||||
|
"FORM_TYPE" ->
|
||||||
|
case Value of
|
||||||
|
"http://jabber.org/protocol/muc#request" ->
|
||||||
|
true
|
||||||
|
end;
|
||||||
|
"muc#role" ->
|
||||||
|
case Value of
|
||||||
|
"participant" ->
|
||||||
|
true
|
||||||
|
end;
|
||||||
|
_ ->
|
||||||
|
true % silently ignore any extra fields
|
||||||
end
|
end
|
||||||
catch
|
|
||||||
error: _ ->
|
|
||||||
false
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
prepare_request_form(Requester, Nick, Lang) ->
|
prepare_request_form(Requester, Nick, Lang) ->
|
||||||
@ -3792,39 +3799,47 @@ send_voice_request(From, StateData) ->
|
|||||||
prepare_request_form(From, FromNick, ""))
|
prepare_request_form(From, FromNick, ""))
|
||||||
end, Moderators).
|
end, Moderators).
|
||||||
|
|
||||||
is_voice_approvement(Els) ->
|
is_voice_approvement({xmlelement, "x", _, _} = Elem) ->
|
||||||
try
|
try
|
||||||
case xml:remove_cdata(Els) of
|
case xml:get_tag_attr_s("xmlns", Elem) of
|
||||||
[{xmlelement, "x", Attrs, Els1}] ->
|
?NS_XDATA ->
|
||||||
case xml:get_attr_s("xmlns", Attrs) of
|
Fields = jlib:parse_xdata_submit(Elem),
|
||||||
?NS_XDATA ->
|
lists:foldl(
|
||||||
case xml:get_attr_s("type", Attrs) of
|
fun(X,Y) ->
|
||||||
"submit" ->
|
check_voice_approvement_fields(X,Y)
|
||||||
lists:foldl(
|
end,
|
||||||
fun(X,Y) ->
|
true, Fields)
|
||||||
check_voice_approvement_fields(X,Y)
|
|
||||||
end,
|
|
||||||
true, xml:remove_cdata(Els1))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
catch
|
catch
|
||||||
error: _ ->
|
error: _ ->
|
||||||
false
|
false
|
||||||
end.
|
end;
|
||||||
|
is_voice_approvement(Els) ->
|
||||||
|
lists:foldl(
|
||||||
|
fun(X, Acc) ->
|
||||||
|
case Acc of
|
||||||
|
false ->
|
||||||
|
case X of
|
||||||
|
{xmlelement, "x", _, _} ->
|
||||||
|
is_voice_approvement(X);
|
||||||
|
_ ->
|
||||||
|
false
|
||||||
|
end;
|
||||||
|
true ->
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end, false, Els).
|
||||||
|
|
||||||
check_voice_approvement_fields({xmlelement, "field", Attrs, Els}, Acc) ->
|
check_voice_approvement_fields({Field, Value}, Acc) ->
|
||||||
if Acc ->
|
if Acc ->
|
||||||
case xml:get_attr_s("var", Attrs) of
|
case Field of
|
||||||
"FORM_TYPE" ->
|
"FORM_TYPE" ->
|
||||||
[{xmlelement, "value", _, Value}] = xml:remove_cdata(Els),
|
case Value of
|
||||||
case xml:get_cdata(Value) of
|
|
||||||
"http://jabber.org/protocol/muc#request" ->
|
"http://jabber.org/protocol/muc#request" ->
|
||||||
true
|
true
|
||||||
end;
|
end;
|
||||||
"muc#role" ->
|
"muc#role" ->
|
||||||
[{xmlelement, "value", _, Value}] = xml:remove_cdata(Els),
|
case Value of
|
||||||
case xml:get_cdata(Value) of
|
|
||||||
"participant" ->
|
"participant" ->
|
||||||
true
|
true
|
||||||
end;
|
end;
|
||||||
@ -3834,8 +3849,7 @@ check_voice_approvement_fields({xmlelement, "field", Attrs, Els}, Acc) ->
|
|||||||
true;
|
true;
|
||||||
"muc#request_allow" ->
|
"muc#request_allow" ->
|
||||||
% XXX: submitted forms with request_allow unchecked ignored here
|
% XXX: submitted forms with request_allow unchecked ignored here
|
||||||
[{xmlelement, "value", _, Value}] = xml:remove_cdata(Els),
|
case Value of
|
||||||
case xml:get_cdata(Value) of
|
|
||||||
"true" ->
|
"true" ->
|
||||||
true;
|
true;
|
||||||
"1" ->
|
"1" ->
|
||||||
@ -3844,34 +3858,38 @@ check_voice_approvement_fields({xmlelement, "field", Attrs, Els}, Acc) ->
|
|||||||
_ ->
|
_ ->
|
||||||
true % ignore unknown fields
|
true % ignore unknown fields
|
||||||
end
|
end
|
||||||
end;
|
end.
|
||||||
check_voice_approvement_fields({xmlelement, _, _, _}, _) ->
|
|
||||||
true.
|
|
||||||
|
|
||||||
extract_jid_from_voice_approvement(Els) ->
|
extract_jid_from_voice_approvement(Els) ->
|
||||||
try
|
lists:foldl(
|
||||||
[{xmlelement, "x", _, Els1}] = xml:remove_cdata(Els),
|
fun(X, Acc) ->
|
||||||
Jid = lists:foldl(
|
case Acc of
|
||||||
fun(El, Acc) ->
|
{error, _} ->
|
||||||
case xml:get_tag_attr_s("var", El) of
|
case X of
|
||||||
"muc#jid" ->
|
{xmlelement, "x", _, _} ->
|
||||||
{xmlelement, "field", _, Els2} = El,
|
Fields = jlib:parse_xdata_submit(X),
|
||||||
[{xmlelement, "value", _, Value}] = xml:remove_cdata(Els2),
|
Jid = lists:foldl(
|
||||||
xml:get_cdata(Value);
|
fun(T, Acc2) ->
|
||||||
|
case Acc2 of
|
||||||
|
{error, _} ->
|
||||||
|
case T of
|
||||||
|
{"muc#jid", Jid} ->
|
||||||
|
Jid;
|
||||||
|
_ ->
|
||||||
|
Acc2
|
||||||
|
end;
|
||||||
|
_ ->
|
||||||
|
Acc2
|
||||||
|
end
|
||||||
|
end, {error, jid_not_found}, Fields),
|
||||||
|
jlib:string_to_jid(Jid);
|
||||||
_ ->
|
_ ->
|
||||||
Acc
|
Acc
|
||||||
end
|
end;
|
||||||
end, {error, jid_not_found}, xml:remove_cdata(Els1)),
|
_ ->
|
||||||
case Jid of
|
Acc
|
||||||
{error, _} = Err ->
|
end
|
||||||
Err;
|
end, {error, jid_not_found}, Els).
|
||||||
_ ->
|
|
||||||
jlib:string_to_jid(Jid)
|
|
||||||
end
|
|
||||||
catch
|
|
||||||
error: X ->
|
|
||||||
{error, X}
|
|
||||||
end.
|
|
||||||
|
|
||||||
last_voice_request_time(BareJID, StateData) ->
|
last_voice_request_time(BareJID, StateData) ->
|
||||||
case ?DICT:find(BareJID, StateData#state.last_voice_request_time) of
|
case ?DICT:find(BareJID, StateData#state.last_voice_request_time) of
|
||||||
|
Loading…
Reference in New Issue
Block a user