Changeset View
Changeset View
Standalone View
Standalone View
apps/kolab_guam/src/kolab_guam_session.erl
Show First 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | |||||
full_rule_name(Module) when is_atom(Module) -> list_to_atom("kolab_guam_rule_" ++ atom_to_list(Module)). | full_rule_name(Module) when is_atom(Module) -> list_to_atom("kolab_guam_rule_" ++ atom_to_list(Module)). | ||||
apply_ruleset_serverside(ImapSession, ServerData, CurrentlyActiveRules) -> | apply_ruleset_serverside(ImapSession, ServerData, CurrentlyActiveRules) -> | ||||
%TODO: allow undecided rules to opt-in here as well | %TODO: allow undecided rules to opt-in here as well | ||||
apply_next_rule_serverside(ImapSession, ServerData, [], CurrentlyActiveRules). | apply_next_rule_serverside(ImapSession, ServerData, [], CurrentlyActiveRules). | ||||
apply_next_rule_serverside(_ImapSession, ServerData, ActiveRulesAcc, []) -> { ServerData, lists:reverse(ActiveRulesAcc) }; | apply_next_rule_serverside(_ImapSession, ServerData, ActiveRulesAcc, []) -> { ServerData, lists:reverse(ActiveRulesAcc) }; | ||||
apply_next_rule_serverside(_ImapSession, ServerData, [], undefined) -> | |||||
{ ServerData, [] }; | |||||
apply_next_rule_serverside(ImapSession, ServerData, ActiveRulesAcc, [{ Module, RuleState } | ActiveRules]) -> | apply_next_rule_serverside(ImapSession, ServerData, ActiveRulesAcc, [{ Module, RuleState } | ActiveRules]) -> | ||||
%TODO: allow rules to remove themselves from the action during serverside processing? | %TODO: allow rules to remove themselves from the action during serverside processing? | ||||
{ ModifiedData, ModifiedRuleState } = Module:apply_to_server_message(ImapSession, ServerData, RuleState), | { ModifiedData, ModifiedRuleState } = Module:apply_to_server_message(ImapSession, ServerData, RuleState), | ||||
apply_next_rule_serverside(ImapSession, ModifiedData, [{ Module, ModifiedRuleState } | ActiveRulesAcc], ActiveRules). | apply_next_rule_serverside(ImapSession, ModifiedData, [{ Module, ModifiedRuleState } | ActiveRulesAcc], ActiveRules). | ||||
apply_ruleset_clientside(_ImapSession, _Socket, ClientData, _CurrentCommandSplit, [], []) -> | apply_ruleset_clientside(_ImapSession, _Socket, ClientData, _CurrentCommandSplit, [], []) -> | ||||
{ ClientData, [], [], perform_passthrough, undefined }; | { ClientData, [], [], undefined, undefined, perform_passthrough }; | ||||
apply_ruleset_clientside(ImapSession, Socket, ClientData, CurrentCommandSplit, UndecidedRules, CurrentlyActiveRules) -> | apply_ruleset_clientside(ImapSession, Socket, ClientData, CurrentCommandSplit, UndecidedRules, CurrentlyActiveRules) -> | ||||
{ PostAction, SplitCommand, SplitResetTrigger } = | { PostAction, SplitCommand, SplitResetTrigger } = | ||||
case CurrentCommandSplit of | case CurrentCommandSplit of | ||||
undefined -> | undefined -> | ||||
case eimap_utils:split_command_into_components(ClientData) of | case eimap_utils:split_command_into_components(ClientData) of | ||||
{ _Tag, <<>>, <<>> } -> { buffer_data, undefined, reset_for_next_client_command }; | { _Tag, <<>>, <<>> } -> { buffer_data, undefined, reset_for_next_client_command }; | ||||
{ _Tag, Command, _Data } = Split -> { perform_passthrough, Split, when_to_reset_split(Command) } | { _Tag, Command, _Data } = Split -> { perform_passthrough, Split, when_to_reset_split(Command) } | ||||
end; | end; | ||||
Show All 9 Lines | |||||
when_to_reset_split(<<"authenticate">>) -> reset_on_server_response; | when_to_reset_split(<<"authenticate">>) -> reset_on_server_response; | ||||
when_to_reset_split(_) -> reset_for_next_client_command. | when_to_reset_split(_) -> reset_for_next_client_command. | ||||
check_undecided(_Socket, _ClientData, undefined, Rules) -> | check_undecided(_Socket, _ClientData, undefined, Rules) -> | ||||
%% if we do not have a properly split command ... do nothing! | %% if we do not have a properly split command ... do nothing! | ||||
{ Rules, [] }; | { Rules, [] }; | ||||
check_undecided(Socket, ClientData, SplitCommand, Rules) -> check_next_undecided_rule(Socket, ClientData, SplitCommand, Rules, { [], [] }). | check_undecided(Socket, ClientData, SplitCommand, Rules) -> check_next_undecided_rule(Socket, ClientData, SplitCommand, Rules, { [], [] }). | ||||
check_next_undecided_rule(_Socket, _ClientData, _SplitCommand, [], Accs) -> Accs; | check_next_undecided_rule(_Socket, _ClientData, _SplitCommand, [], Accs) -> Accs; | ||||
check_next_undecided_rule(_Socket, _ClientData, _SplitCommand, undefined, Accs) -> Accs; | |||||
check_next_undecided_rule(Socket, ClientData, SplitCommand, [Rule|Rules], { UndecidedAcc, NewActiveAcc }) -> | check_next_undecided_rule(Socket, ClientData, SplitCommand, [Rule|Rules], { UndecidedAcc, NewActiveAcc }) -> | ||||
{ Module, RuleState } = Rule, | { Module, RuleState } = Rule, | ||||
%%lager:debug("Does ~p apply with state ~p? let's find out!", [Module, RuleState]), | %%lager:debug("Does ~p apply with state ~p? let's find out!", [Module, RuleState]), | ||||
Application = Module:applies(Socket, ClientData, SplitCommand, RuleState), | Application = Module:applies(Socket, ClientData, SplitCommand, RuleState), | ||||
check_next_undecided_rule(Socket, ClientData, SplitCommand, Rules, applies(Module, Application, UndecidedAcc, NewActiveAcc)). | check_next_undecided_rule(Socket, ClientData, SplitCommand, Rules, applies(Module, Application, UndecidedAcc, NewActiveAcc)). | ||||
applies(Module, { true, RuleState }, UndecidedAcc, NewActiveAcc) -> { UndecidedAcc, [{ Module, RuleState }|NewActiveAcc] }; | applies(Module, { true, RuleState }, UndecidedAcc, NewActiveAcc) -> { UndecidedAcc, [{ Module, RuleState }|NewActiveAcc] }; | ||||
applies(_Module, { false, _RuleState }, UndecidedAcc, NewActiveAcc) -> { UndecidedAcc, NewActiveAcc }; | applies(_Module, { false, _RuleState }, UndecidedAcc, NewActiveAcc) -> { UndecidedAcc, NewActiveAcc }; | ||||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |