25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

Use pattern matching in check_voice_request_fields/2 and check_voice_approvement_fields/2

This commit is contained in:
Maxim Ignatenko 2011-09-20 16:52:53 +03:00
parent eb8347f92b
commit faed7698c2

View File

@ -3752,23 +3752,18 @@ is_voice_request(Els) ->
end end
end, false, Els). end, false, Els).
check_voice_request_fields({Field, Value}, Acc) -> check_voice_request_fields(_, false) ->
if Acc -> false;
case Field of check_voice_request_fields({"FORM_TYPE", "http://jabber.org/protocol/muc#request"}, true) ->
"FORM_TYPE" -> true;
case Value of check_voice_request_fields({"FORM_TYPE", _}, _) ->
"http://jabber.org/protocol/muc#request" -> false;
true check_voice_request_fields({"muc#role", "participant"}, true) ->
end; true;
"muc#role" -> check_voice_request_fields({"muc#role", _}, _) ->
case Value of false;
"participant" -> check_voice_request_fields(_, true) ->
true true. % silently ignore any extra fields
end;
_ ->
true % silently ignore any extra fields
end
end.
prepare_request_form(Requester, Nick, Lang) -> prepare_request_form(Requester, Nick, Lang) ->
{xmlelement, "message", [{"type", "normal"}], [ {xmlelement, "message", [{"type", "normal"}], [
@ -3830,35 +3825,24 @@ is_voice_approvement(Els) ->
end end
end, false, Els). end, false, Els).
check_voice_approvement_fields({Field, Value}, Acc) -> check_voice_approvement_fields(_, false) ->
if Acc -> false;
case Field of check_voice_approvement_fields({"FORM_TYPE", "http://jabber.org/protocol/muc#request"}, true) ->
"FORM_TYPE" ->
case Value of
"http://jabber.org/protocol/muc#request" ->
true
end;
"muc#role" ->
case Value of
"participant" ->
true
end;
"muc#jid" ->
true; % TODO: make some validation here
"muc#roomnick" ->
true; true;
"muc#request_allow" -> check_voice_approvement_fields({"FORM_TYPE", _}, _) ->
% XXX: submitted forms with request_allow unchecked ignored here false;
case Value of check_voice_approvement_fields({"muc#role", "participant"}, true) ->
"true" ->
true; true;
"1" -> check_voice_approvement_fields({"muc#role", _}, _) ->
true false;
end; check_voice_approvement_fields({"muc#request_allow", "true"}, true) ->
_ -> true;
true % ignore unknown fields check_voice_approvement_fields({"muc#request_allow", "1"}, true) ->
end true;
end. check_voice_approvement_fields({"muc#request_allow", _}, _) ->
false;
check_voice_approvement_fields(_, true) ->
true; % do not check any other fields
extract_jid_from_voice_approvement(Els) -> extract_jid_from_voice_approvement(Els) ->
lists:foldl( lists:foldl(