diff options
Diffstat (limited to 'src/mod_version.erl')
-rw-r--r-- | src/mod_version.erl | 90 |
1 files changed, 47 insertions, 43 deletions
diff --git a/src/mod_version.erl b/src/mod_version.erl index 7cda907cc..088961a6b 100644 --- a/src/mod_version.erl +++ b/src/mod_version.erl @@ -25,66 +25,70 @@ %%%---------------------------------------------------------------------- -module(mod_version). + -author('alexey@process-one.net'). -behaviour(gen_mod). --export([start/2, - stop/1, - process_local_iq/3]). +-export([start/2, stop/1, process_local_iq/3]). -include("ejabberd.hrl"). --include("jlib.hrl"). - +-include("jlib.hrl"). start(Host, Opts) -> - IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue), - gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_VERSION, - ?MODULE, process_local_iq, IQDisc). + IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1, + one_queue), + gen_iq_handler:add_iq_handler(ejabberd_local, Host, + ?NS_VERSION, ?MODULE, process_local_iq, + IQDisc). stop(Host) -> - gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_VERSION). - + gen_iq_handler:remove_iq_handler(ejabberd_local, Host, + ?NS_VERSION). -process_local_iq(_From, To, #iq{id = _ID, type = Type, - xmlns = _XMLNS, sub_el = SubEl} = IQ) -> +process_local_iq(_From, To, + #iq{id = _ID, type = Type, xmlns = _XMLNS, + sub_el = SubEl} = + IQ) -> case Type of - set -> - IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}; - get -> - Host = To#jid.lserver, - OS = case gen_mod:get_module_opt(Host, ?MODULE, show_os, true) of - true -> [get_os()]; - false -> [] - end, - IQ#iq{type = result, - sub_el = [{xmlelement, "query", - [{"xmlns", ?NS_VERSION}], - [{xmlelement, "name", [], - [{xmlcdata, "ejabberd"}]}, - {xmlelement, "version", [], - [{xmlcdata, ?VERSION}]} - ] ++ OS - }]} + set -> + IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}; + get -> + Host = To#jid.lserver, + OS = case gen_mod:get_module_opt(Host, ?MODULE, show_os, + fun(B) when is_boolean(B) -> B end, + true) + of + true -> [get_os()]; + false -> [] + end, + IQ#iq{type = result, + sub_el = + [#xmlel{name = <<"query">>, + attrs = [{<<"xmlns">>, ?NS_VERSION}], + children = + [#xmlel{name = <<"name">>, attrs = [], + children = + [{xmlcdata, <<"ejabberd">>}]}, + #xmlel{name = <<"version">>, attrs = [], + children = [{xmlcdata, ?VERSION}]}] + ++ OS}]} end. - get_os() -> OSType = case os:type() of - {Osfamily, Osname} -> - atom_to_list(Osfamily) ++ "/" ++ - atom_to_list(Osname); - Osfamily -> - atom_to_list(Osfamily) + {Osfamily, Osname} -> + <<(iolist_to_binary(atom_to_list(Osfamily)))/binary, + "/", (iolist_to_binary(atom_to_list(Osname)))/binary>>; + Osfamily -> iolist_to_binary(atom_to_list(Osfamily)) end, OSVersion = case os:version() of - {Major, Minor, Release} -> - lists:flatten( - io_lib:format("~w.~w.~w", - [Major, Minor, Release])); - VersionString -> - VersionString + {Major, Minor, Release} -> + iolist_to_binary(io_lib:format("~w.~w.~w", + [Major, Minor, Release])); + VersionString -> VersionString end, - OS = OSType ++ " " ++ OSVersion, - {xmlelement, "os", [], [{xmlcdata, OS}]}. + OS = <<OSType/binary, " ", OSVersion/binary>>, + #xmlel{name = <<"os">>, attrs = [], + children = [{xmlcdata, OS}]}. |