From dcc00bca6daf0c7fb31767c2d2b01b8a4a533cb6 Mon Sep 17 00:00:00 2001 From: Badlop Date: Mon, 31 Mar 2008 19:48:35 +0000 Subject: [PATCH] * src/ejabberd_listener.erl: Remove code of the unused listening socket option 'ssl' (EJAB-159) * src/ejabberd_app.erl: Likewise SVN Revision: 1263 --- ChangeLog | 4 ++ src/ejabberd_app.erl | 1 - src/ejabberd_listener.erl | 85 +++++++++------------------------------ 3 files changed, 22 insertions(+), 68 deletions(-) diff --git a/ChangeLog b/ChangeLog index 472653fcd..e9f4dc1d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2008-03-31 Badlop + * src/ejabberd_listener.erl: Remove code of the unused listening + socket option 'ssl' (EJAB-159) + * src/ejabberd_app.erl: Likewise + * doc/webadmmain.png: Updated to ejabberd 2.0.0 * doc/webadmmainru.png: Likewise diff --git a/src/ejabberd_app.erl b/src/ejabberd_app.erl index 4c12069d1..8f335ad5b 100644 --- a/src/ejabberd_app.erl +++ b/src/ejabberd_app.erl @@ -44,7 +44,6 @@ start(normal, _Args) -> randoms:start(), db_init(), sha:start(), - catch ssl:start(), stringprep_sup:start_link(), translate:start(), acl:start(), diff --git a/src/ejabberd_listener.erl b/src/ejabberd_listener.erl index f16cfb0d8..98b90861c 100644 --- a/src/ejabberd_listener.erl +++ b/src/ejabberd_listener.erl @@ -29,7 +29,6 @@ -export([start_link/0, init/1, start/3, init/3, - init_ssl/4, start_listener/3, stop_listener/1, add_listener/3, @@ -61,24 +60,27 @@ init(_) -> start(Port, Module, Opts) -> - SSLError = "There is a problem with your ejabberd configuration file: the option 'ssl' for listening sockets is no longer available. To get SSL encryption use the option 'tls'.", + case includes_deprecated_ssl_option(Opts) of + false -> + {ok, proc_lib:spawn_link(?MODULE, init, + [Port, Module, Opts])}; + true -> + SSLErr="There is a problem with your ejabberd configuration file: " + "the option 'ssl' for listening sockets is no longer available." + "To get SSL encryption use the option 'tls'.", + ?ERROR_MSG(SSLErr, []), + {error, SSLErr} + end. + +%% Parse the options of the socket, +%% and return if the deprecated option 'ssl' is included +%% @spec(Opts::[opt()]) -> true | false +includes_deprecated_ssl_option(Opts) -> case lists:keysearch(ssl, 1, Opts) of {value, {ssl, _SSLOpts}} -> - %%{ok, proc_lib:spawn_link(?MODULE, init_ssl, - %% [Port, Module, Opts, SSLOpts])}; - ?ERROR_MSG(SSLError, []), - {error, SSLError}; + true; _ -> - case lists:member(ssl, Opts) of - true -> - %%{ok, proc_lib:spawn_link(?MODULE, init_ssl, - %% [Port, Module, Opts, []])}; - ?ERROR_MSG(SSLError, []), - {error, SSLError}; - false -> - {ok, proc_lib:spawn_link(?MODULE, init, - [Port, Module, Opts])} - end + lists:member(ssl, Opts) end. init(Port, Module, Opts) -> @@ -127,57 +129,6 @@ accept(ListenSocket, Module, Opts) -> accept(ListenSocket, Module, Opts) end. - -init_ssl(Port, Module, Opts, SSLOpts) -> - SockOpts = lists:filter(fun({ip, _}) -> true; - (inet6) -> true; - (inet) -> true; - ({verify, _}) -> true; - ({depth, _}) -> true; - ({certfile, _}) -> true; - ({keyfile, _}) -> true; - ({password, _}) -> true; - ({cacertfile, _}) -> true; - ({ciphers, _}) -> true; - (_) -> false - end, Opts), - Res = ssl:listen(Port, [binary, - {packet, 0}, - {active, false}, - {nodelay, true} | - SockOpts ++ SSLOpts]), - case Res of - {ok, ListenSocket} -> - accept_ssl(ListenSocket, Module, Opts); - {error, Reason} -> - ?ERROR_MSG("Failed to open socket for ~p: ~p", - [{Port, Module, Opts}, Reason]), - error - end. - -accept_ssl(ListenSocket, Module, Opts) -> - case ssl:accept(ListenSocket, 200) of - {ok, Socket} -> - case {ssl:sockname(Socket), ssl:peername(Socket)} of - {{ok, Addr}, {ok, PAddr}} -> - ?INFO_MSG("(~w) Accepted SSL connection ~w -> ~w", - [Socket, PAddr, Addr]); - _ -> - ok - end, - {ok, Pid} = Module:start({ssl, Socket}, Opts), - catch ssl:controlling_process(Socket, Pid), - Module:become_controller(Pid), - accept_ssl(ListenSocket, Module, Opts); - {error, timeout} -> - accept_ssl(ListenSocket, Module, Opts); - {error, Reason} -> - ?INFO_MSG("(~w) Failed SSL handshake: ~w", - [ListenSocket, Reason]), - accept_ssl(ListenSocket, Module, Opts) - end. - - start_listener(Port, Module, Opts) -> start_module_sup(Module), start_listener_sup(Port, Module, Opts).