diff options
author | Mickaël Rémond <mickael.remond@process-one.net> | 2008-05-09 19:53:06 +0000 |
---|---|---|
committer | Mickaël Rémond <mickael.remond@process-one.net> | 2008-05-09 19:53:06 +0000 |
commit | 977a20700a50f35449e384d668b4dc68eb904fd4 (patch) | |
tree | d42fcfd7902f738e459baa6228da3a27bef81e98 /src | |
parent | * src/mod_ip_blacklist.erl: ignore when we do not have the IP. (diff) |
* src/mod_ip_blacklist.erl: Better error handling (EJAB-625).
SVN Revision: 1321
Diffstat (limited to 'src')
-rw-r--r-- | src/mod_ip_blacklist.erl | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/mod_ip_blacklist.erl b/src/mod_ip_blacklist.erl index 495faa5fb..6a0cc3947 100644 --- a/src/mod_ip_blacklist.erl +++ b/src/mod_ip_blacklist.erl @@ -85,20 +85,25 @@ loop(_State) -> %% TODO: Support comment lines starting by % update_bl_c2s() -> ?INFO_MSG("Updating C2S Blacklist", []), - {ok, {{_Version, 200, _Reason}, _Headers, Body}} = http:request(?BLC2S), - IPs = string:tokens(Body,"\n"), - ets:delete_all_objects(bl_c2s), - lists:foreach( - fun(IP) -> - ets:insert(bl_c2s, #bl_c2s{ip=list_to_binary(IP)}) - end, IPs). + case http:request(?BLC2S) of + {ok, {{_Version, 200, _Reason}, _Headers, Body}} -> + IPs = string:tokens(Body,"\n"), + ets:delete_all_objects(bl_c2s), + lists:foreach( + fun(IP) -> + ets:insert(bl_c2s, #bl_c2s{ip=list_to_binary(IP)}) + end, IPs); + {error, Reason} -> + ?ERROR_MSG("Cannot download C2S blacklist file. Reason: ~p", + [Reason]) + end. %% Hook is run with: %% ejabberd_hooks:run_fold(check_bl_c2s, false, [IP]), %% Return: false: IP not blacklisted %% true: IP is blacklisted %% IPV4 IP tuple: -is_ip_in_c2s_blacklist(_Val, IP) -> +is_ip_in_c2s_blacklist(_Val, IP) when is_tuple(IP) -> BinaryIP = list_to_binary(jlib:ip_to_list(IP)), case ets:lookup(bl_c2s, BinaryIP) of [] -> %% Not in blacklist |