]> granicus.if.org Git - ejabberd/commitdiff
New command get_room_options (#567)
authorBadlop <badlop@process-one.net>
Fri, 15 May 2015 15:47:10 +0000 (17:47 +0200)
committerBadlop <badlop@process-one.net>
Fri, 15 May 2015 15:47:10 +0000 (17:47 +0200)
src/ejabberd_ctl.erl
src/ejabberd_xmlrpc.erl
src/mod_muc_admin.erl

index 6ab383b1238d6150bb2ce555242051d46559ebe7..1eae7f758ed00911b8c4894cdedba3373af42735 100644 (file)
@@ -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);
 
index 904604fc9bcb134c7daaa98608f023ed1694a024..7e437104993e6b9c09c0e2692f314720e8ab7157 100644 (file)
@@ -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) ->
index 1d77d3ebe563f5ea0d40d1eacd5fa6b9da5bf648..1a6d8a865c8f09f4604e40d6757d517e257dfe60 100644 (file)
@@ -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