From 084d0c4efe9e22c0dcfaf8a9132ee6bda21c8e99 Mon Sep 17 00:00:00 2001 From: Badlop Date: Fri, 15 May 2015 17:47:10 +0200 Subject: [PATCH] New command get_room_options (#567) --- src/ejabberd_ctl.erl | 9 +++++++++ src/ejabberd_xmlrpc.erl | 6 ++++++ src/mod_muc_admin.erl | 27 +++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/ejabberd_ctl.erl b/src/ejabberd_ctl.erl index 6ab383b12..1eae7f758 100644 --- a/src/ejabberd_ctl.erl +++ b/src/ejabberd_ctl.erl @@ -353,6 +353,15 @@ format_result(String, {_Name, string}) when is_list(String) -> format_result(Binary, {_Name, string}) when is_binary(Binary) -> io_lib:format("~s", [binary_to_list(Binary)]); +format_result(Atom, {_Name, string}) when is_atom(Atom) -> + io_lib:format("~s", [atom_to_list(Atom)]); + +format_result(Integer, {_Name, string}) when is_integer(Integer) -> + io_lib:format("~s", [integer_to_list(Integer)]); + +format_result(Other, {_Name, string}) -> + io_lib:format("~p", [Other]); + format_result(Code, {_Name, rescode}) -> make_status(Code); diff --git a/src/ejabberd_xmlrpc.erl b/src/ejabberd_xmlrpc.erl index 904604fc9..7e4371049 100644 --- a/src/ejabberd_xmlrpc.erl +++ b/src/ejabberd_xmlrpc.erl @@ -466,6 +466,12 @@ format_result(String, {Name, string}) when is_list(String) -> {struct, [{Name, lists:flatten(String)}]}; format_result(Binary, {Name, string}) when is_binary(Binary) -> {struct, [{Name, binary_to_list(Binary)}]}; +format_result(Atom, {Name, string}) when is_atom(Atom) -> + {struct, [{Name, atom_to_list(Atom)}]}; +format_result(Integer, {Name, string}) when is_integer(Integer) -> + {struct, [{Name, integer_to_list(Integer)}]}; +format_result(Other, {Name, string}) -> + {struct, [{Name, io_lib:format("~p", [Other])}]}; format_result(String, {Name, binary}) when is_list(String) -> {struct, [{Name, lists:flatten(String)}]}; format_result(Binary, {Name, binary}) when is_binary(Binary) -> diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl index 1d77d3ebe..1a6d8a865 100644 --- a/src/mod_muc_admin.erl +++ b/src/mod_muc_admin.erl @@ -23,6 +23,7 @@ get_room_occupants_number/2, send_direct_invitation/4, change_room_option/4, + get_room_options/2, set_room_affiliation/4, get_room_affiliations/2, web_menu_main/2, web_page_main/2, % Web Admin API @@ -145,6 +146,16 @@ commands() -> args = [{name, binary}, {service, binary}, {option, binary}, {value, binary}], result = {res, rescode}}, + #ejabberd_commands{name = get_room_options, tags = [muc_room], + desc = "Get options from a MUC room", + module = ?MODULE, function = get_room_options, + args = [{name, binary}, {service, binary}], + result = {options, {list, + {option, {tuple, + [{name, string}, + {value, string} + ]}} + }}}, #ejabberd_commands{name = set_room_affiliation, tags = [muc_room], desc = "Change an affiliation in a MUC room", @@ -799,6 +810,22 @@ change_option(Option, Value, Config) -> title -> Config#config{title = Value} end. +%%---------------------------- +%% Get Room Options +%%---------------------------- + +get_room_options(Name, Service) -> + Pid = get_room_pid(Name, Service), + get_room_options(Pid). + +get_room_options(Pid) -> + Config = get_room_config(Pid), + get_options(Config). + +get_options(Config) -> + Fields = record_info(fields, config), + [config | Values] = tuple_to_list(Config), + lists:zip(Fields, Values). %%---------------------------- %% Get Room Affiliations