Changeset View
Changeset View
Standalone View
Standalone View
apps/kolab_guam/src/kolab_guam_session.erl
Show First 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | |||||
close_zlib_handle(Z) -> zlib:close(Z). | close_zlib_handle(Z) -> zlib:close(Z). | ||||
close_socket(_ImplicitTLS, _TLS, undefined) -> ok; | close_socket(_ImplicitTLS, _TLS, undefined) -> ok; | ||||
close_socket(_ImplicitTLS, true, Socket) -> ssl:close(Socket); | close_socket(_ImplicitTLS, true, Socket) -> ssl:close(Socket); | ||||
close_socket(true, _TLS, Socket) -> ssl:close(Socket); | close_socket(true, _TLS, Socket) -> ssl:close(Socket); | ||||
close_socket(_ImplicitTLS, _TLS, Socket) -> gen_tcp:close(Socket). | close_socket(_ImplicitTLS, _TLS, Socket) -> gen_tcp:close(Socket). | ||||
apply_rules(ImapSession, Socket, PreprocessData, CurrentCommandSplit, UndecidedRules, ActiveRules) -> | |||||
{ ModifiedData, NewSplitCommand, NewSplitResetTrigger, NewUndecidedRules, NewActiveRules, PostAction } = apply_ruleset_clientside(ImapSession, Socket, PreprocessData, CurrentCommandSplit, UndecidedRules, ActiveRules), | |||||
BufferThisData = | |||||
case PostAction of | |||||
perform_passthrough -> | |||||
eimap:passthrough_data(ImapSession, ModifiedData), | |||||
<<>>; | |||||
buffer_data -> | |||||
% Originally Aaron uses Data here, but later on this buffer is assumed to be | |||||
% already decoded, so we do have to use PreprocessData here, I think. | |||||
case binary:matches(PreprocessData, <<"\r\n">>) of | |||||
[] -> | |||||
lager:info("buffering: ~s", [PreprocessData]), | |||||
PreprocessData; | |||||
List -> | |||||
{FoundPos, _} = lists:last(List), | |||||
% I would like to have some binary:match for the last instead of the | |||||
% first occurrence; but I'm really inexperienced in erlang so I don't | |||||
% know how to solve this efficiently, so I'm using binary:matches with | |||||
% using the last element only | |||||
SplitPos = FoundPos + 2, | |||||
eimap:passthrough_data(ImapSession, binary:part(PreprocessData, 0, SplitPos)), | |||||
lager:info("sending first part: ~s", [binary:part(PreprocessData, 0, SplitPos)] ), | |||||
lager:info("buffering second part: ~s", [binary:part(PreprocessData, SplitPos, size(PreprocessData)-SplitPos)]), | |||||
binary:part(PreprocessData, SplitPos, size(PreprocessData)-SplitPos) | |||||
end | |||||
end, | |||||
{ NewUndecidedRules, NewActiveRules, BufferThisData, NewSplitCommand, NewSplitResetTrigger }. | |||||
read_line(Data) -> | read_line(Data) -> | ||||
case binary:match(Data, <<"\r\n">>) of | case binary:match(Data, <<"\r\n">>) of | ||||
nomatch -> | nomatch -> | ||||
{Data, <<>>}; | {Data, <<>>}; | ||||
{SplitPos, SplitSize} -> | {SplitPos, SplitSize} -> | ||||
{binary:part(Data, 0, SplitPos + SplitSize), binary:part(Data, SplitPos + SplitSize, size(Data)-(SplitPos + SplitSize))} | {binary:part(Data, 0, SplitPos + SplitSize), binary:part(Data, SplitPos + SplitSize, size(Data)-(SplitPos + SplitSize))} | ||||
end. | end. | ||||
Show All 32 Lines | case check_for_transmission_change_commands(TLS, TLSConfig, Data, Deflator, Socket) of | ||||
false -> eimap:starttls(ImapSession, undefined, undefined); | false -> eimap:starttls(ImapSession, undefined, undefined); | ||||
_ -> ok | _ -> ok | ||||
end, | end, | ||||
{ true, SSLSocket, Inflator, Deflator, UndecidedRules, ActiveRules, <<>>, undefined, undefined }; | { true, SSLSocket, Inflator, Deflator, UndecidedRules, ActiveRules, <<>>, undefined, undefined }; | ||||
{ compression, NewInflator, NewDeflator } -> | { compression, NewInflator, NewDeflator } -> | ||||
eimap:compress(ImapSession), % TODO: make optional | eimap:compress(ImapSession), % TODO: make optional | ||||
{ TLS, Socket, NewInflator, NewDeflator, UndecidedRules, ActiveRules, <<>>, undefined, undefined }; | { TLS, Socket, NewInflator, NewDeflator, UndecidedRules, ActiveRules, <<>>, undefined, undefined }; | ||||
nochange -> | nochange -> | ||||
{ NewUndecidedRules, NewActiveRules, BufferThisData, NewSplitCommand, NewSplitResetTrigger } = | { ModifiedData, NewSplitCommand, NewSplitResetTrigger, NewUndecidedRules, NewActiveRules, PostAction } = apply_ruleset_clientside(ImapSession, Socket, Data, CurrentCommandSplit, UndecidedRules, ActiveRules), | ||||
apply_rules(ImapSession, Socket, Data, CurrentCommandSplit, UndecidedRules, ActiveRules), | BufferThisData = | ||||
case PostAction of | |||||
perform_passthrough -> | |||||
eimap:passthrough_data(ImapSession, ModifiedData), | |||||
<<>>; | |||||
buffer_data -> | |||||
Data | |||||
end, | |||||
{ TLS, Socket, Inflator, Deflator, NewUndecidedRules, NewActiveRules, BufferThisData, NewSplitCommand, NewSplitResetTrigger } | { TLS, Socket, Inflator, Deflator, NewUndecidedRules, NewActiveRules, BufferThisData, NewSplitCommand, NewSplitResetTrigger } | ||||
end, | end, | ||||
set_socket_active(TLSActive, CurrentSocket), | set_socket_active(TLSActive, CurrentSocket), | ||||
State#state{ rules_deciding = CurrentUndecidedRules, rules_active = CurrentActiveRules, | State#state{ rules_deciding = CurrentUndecidedRules, rules_active = CurrentActiveRules, | ||||
socket = CurrentSocket, client_tls_active = TLSActive, | socket = CurrentSocket, client_tls_active = TLSActive, | ||||
inflator = CurrentInflator, deflator = CurrentDeflator, | inflator = CurrentInflator, deflator = CurrentDeflator, | ||||
buffered_client_data = DataToBuffer, | buffered_client_data = DataToBuffer, | ||||
current_command_split = SplitCommand, | current_command_split = SplitCommand, | ||||
▲ Show 20 Lines • Show All 203 Lines • Show Last 20 Lines |