Permalink
Browse files

Fixed thrift calls

  • Loading branch information...
hkerem committed Aug 7, 2012
1 parent c6ea4fc commit dc1fa6b0c4c89d3a49eadcc0538e5c217f92d0bb
Showing with 22 additions and 12 deletions.
  1. +1 −1 src/mydlp/mydlp_acl.erl
  2. +1 −1 src/mydlp/mydlp_api.erl
  3. +1 −1 src/mydlp/mydlp_incident.erl
  4. +19 −9 src/mydlp/mydlp_tc.erl
View
@@ -286,7 +286,7 @@ execute_itypes(ITypes, Addr, Files) ->
execute_itypes_pf(ITypes, Addr, File) ->
File1 = case File#file.mime_type of
- undefined -> MT = mydlp_tc:get_mime(File#file.data),
+ undefined -> MT = mydlp_tc:get_mime(File#file.filename, File#file.data),
File#file{mime_type=MT};
_Else -> File end,
View
@@ -1114,7 +1114,7 @@ reconstruct_cr(#file{} = File) ->
get_mimes(Files) -> get_mimes(Files, []).
get_mimes([#file{mime_type=undefined} = File|Files], Returns) ->
- MT = mydlp_tc:get_mime(File#file.data),
+ MT = mydlp_tc:get_mime(File#file.filename, File#file.data),
get_mimes(Files, [File#file{mime_type=MT}|Returns]);
get_mimes([File|Files], Returns) ->
get_mimes(Files, [File|Returns]);
@@ -162,7 +162,7 @@ process_log_files(LogId, true = IsLogData, [File|Files]) ->
Size = mydlp_api:binary_size(File1#file.data),
MimeType = case File1#file.mime_type of
- undefined -> mydlp_tc:get_mime(File1#file.data);
+ undefined -> mydlp_tc:get_mime(File1#file.filename, File1#file.data);
Else -> Else end,
Filename = mydlp_api:file_to_str(File1),
{ok, Path} = mydlp_api:quarantine(File1),
View
@@ -35,7 +35,7 @@
%% API
-export([start_link/0,
pre_init/1,
- get_mime/1,
+ get_mime/2,
get_text/3,
stop/0]).
@@ -55,35 +55,45 @@
-define(MMLEN, 4096).
-get_mime(Data) when is_list(Data) ->
+get_mime(undefined, Data) -> get_mime("noname", Data);
+get_mime("", Data) -> get_mime("noname", Data);
+get_mime(<<>>, Data) -> get_mime("noname", Data);
+
+get_mime(Filename, Data) when is_list(Data) ->
L = length(Data),
Data1 = case L > ?MMLEN of
true -> lists:sublist(Data, ?MMLEN);
false -> Data
end,
- get_mime(list_to_binary(Data1));
+ get_mime(Filename,list_to_binary(Data1));
-get_mime(<<>>) -> <<"application/x-empty">>;
-get_mime(<<"Rar!", _Rest/binary>>) -> <<"application/x-rar">>; % WinRAR
+get_mime(_Filename, <<>>) -> <<"application/x-empty">>;
+get_mime(_Filename, <<"Rar!", _Rest/binary>>) -> <<"application/x-rar">>; % WinRAR
%get_mime(<<202,254,186,190, _Rest/binary>>) -> <<"application/java-vm">>; % CAFE BABE -> java class
-get_mime(<< 16#00,16#01,16#00,16#00,
+get_mime(_Filename,
+ << 16#00,16#01,16#00,16#00,
16#53,16#74,15#61,15#6E,
16#64,16#61,16#72,16#64,
16#20,16#4A,16#65,16#74,
16#20,16#44,16#42, _Rest/binary>>) -> <<"application/msaccess">>;
-get_mime(<< 16#00,16#01,16#00,16#00,
+get_mime(_Filename,
+ << 16#00,16#01,16#00,16#00,
16#53,16#74,16#61,16#6E,
16#64,16#61,16#72,16#64,
16#20,16#41,16#43,16#45,
16#20,16#44,16#42, _Rest/binary>>) -> <<"application/msaccess">>;
-get_mime(Data) when is_binary(Data) ->
+get_mime(Filename, Data) when is_binary(Data) ->
S = size(Data),
Data1 = case S > ?MMLEN of
true -> <<D:?MMLEN/binary, _/binary>> = Data, D;
false -> Data
end,
+ Filename1 = case Filename of
+ F when is_list(F) -> unicode:characters_to_binary(Filename);
+ F when is_binary(F) -> F;
+ _Else -> unicode:characters_to_binary("noname") end,
TRet = try
- call_pool({thrift, java, getMime, [Data1]})
+ call_pool({thrift, java, getMime, [Filename1, Data1]})
catch _:_Exception ->
unknown_type end,

0 comments on commit dc1fa6b

Please sign in to comment.