ejabberdctl srg_create with optional name, description and display arguments

Is it possible to modify the srg_create command (provided by mod_admin_extra module) to make the name, description and display optional? So for ex.

# ejabberdctl srg_create 'group1' 'example.net' 'Group1' '' ''

should create a shared roster 'group1' on virtual host 'example.net' with name 'Group1' and an empty description and no displayed groups.

I have observed that the arguments are being passed to "srg_create(Group, Host, Name, Description, Display)" function in mod_admin_extra.erl. Is it possible to modify this function so that it checks if any of the given parameters are empty and if so does not add them to the Opts variable (I am assuming that mod_shared_roster:create_group function ignores those parameters which are not passed).

Try to apply this patch to

Try to apply this patch to ejabberd:

--- src/ejabberd_ctl.erl
+++ src/ejabberd_ctl.erl
@@ -318,18 +318,19 @@ format_args(Args, ArgsFormat) ->
       [],
       lists:zip(ArgsFormat, Args)).

-format_arg(Arg, Format) ->
-    Parse = case Format of
-               integer ->
-                   "~d";
-               string ->
-                   NumChars = integer_to_list(string:len(Arg)),
-                   "~" ++ NumChars ++ "c"
-           end,
+format_arg(Arg, integer) ->
+    format_arg2(Arg, "~d");
+format_arg("", string) ->
+    "";
+format_arg(Arg, string) ->
+    NumChars = integer_to_list(string:len(Arg)),
+    Parse = "~" ++ NumChars ++ "c",
+    format_arg2(Arg, Parse).
+
+format_arg2(Arg, Parse)->
     {ok, [Arg2], _RemainingArguments} = io_lib:fread(Parse, Arg),
     Arg2.

-
 %%-----------------------------
 %% Format result
 %%-----------------------------

Now you can do things like:

$ ejabberdctl srg_create noname localhost \"\" mydesc mydisp
$ ejabberdctl srg_create nodisplay localhost myname mydesc \"\"                              

If you don't find any problem with that patch, it will be applied to ejabberd.

Though the patch did not

Though the patch did not apply perfectly, the code seems to be working flawlessly. Also I have observed that trailing backslashes should not be used to leave the fields empty. So the correct commands would be:

$ ejabberdctl srg_create noname localhost "" mydesc mydisp
$ ejabberdctl srg_create nodisplay localhost myname mydesc ""

Using single quotes as below also worked:

$ ejabberdctl srg_create noname localhost '' mydesc mydisp
$ ejabberdctl srg_create nodisplay localhost myname mydesc ''

My apologies. The patch

My apologies. The patch actually doesn't do what is required. It seems to create empty lists. The below output should make this clear:

$ ejabberdctl srg_create group1 example.net "" "" ""
$ ejabberdctl srg_get_info group1 example.net
name []
displayed_groups [[]]
description []

where as the expected output should be:
$ ejabberdctl srg_get_info group1 example.net
name ""
displayed_groups []
description ""

I think this is only a minor problem. Could it be fixed?

In Erlang, "" is another way

In Erlang, "" is another way to represent the same that []. So that isn't a problem.

The real problem is [[]]. This patch solves it, please verify before I commit them:

--- src/mod_admin_extra.erl     (revisión: 1041)
+++ src/mod_admin_extra.erl     (copia de trabajo)
@@ -1017,7 +1017,10 @@
 %%%

 srg_create(Group, Host, Name, Description, Display) ->
-    {ok, DisplayList} = regexp:split(Display, "\\\\n"),
+    {ok, DisplayList} = case Display of
+       [] -> {ok, []};
+       _ -> regexp:split(Display, "\\\\n")
+    end,
     Opts = [{name, Name},
            {displayed_groups, DisplayList},
            {description, Description}],

Committed

Quote:

This patch solves it, please verify before I commit them

I've committed the patch to SVN.

Patch committed

Quote:

If you don't find any problem with that patch, it will be applied to ejabberd.

I've committed the patch to ejabberd SVN 2.1.x branch and trunk.

Syndicate content