New mod_adhoc_api and related improvements #4357
Merged
+1,266
−130
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update 2025-03-10
,
separatorejabberd includes mod_configure, which allows to execute 20 commands using a XMPP client with ad-hoc command support. Some of those ad-hoc commands are described in XEP-0133 and others are specifically designed for ejabberd.
On the other hand, we have around 200 API commands that are perfectly documented and accessible from multiple methods (HTTP, XMLRPC, command line and WebAdmin) thanks to the different frontends... so it makes sense to write another frontend that allows to execute all those API commands using a XMPP client with ad-hoc command support.
This PR adds mod_adhoc_api, a new ejabberd module that allows to execute API commands using XEP-0050 (Ad-Hoc Commands). It includes documentation and some test cases.
This PR also includes several improvements in ejabberd required for that feature.
This is a draft text that could be included in the ejabberd release notes:
New option
access
inmod_configure
mod_configure
always had support to configure what accounts can access its features: using theconfigure
access rule. The name of that access rule was hard-coded, beingconfigure
. Now, thanks to the new optionaccess
, that can be configured.mod_http_api
returns sorted list elementsWhen
mod_http_api
returns a list of elements, now those elements are sorted alphabetically. If it is a list of tuples, the tuples are sorted alphabetically by the first element in that tuple.Notice that the new module
mod_adhoc_api
uses internallymod_http_api
to format the API command arguments and result, this means thatmod_adhoc_api
benefits from this feature too.New API commands to change mnesia table storage
There are two new API commands:
mnesia_list_tables
andmnesia_table_change_storage
.In fact those commands were already implemented since ejabberd 24.06, but they were tagged as
internal
as they were only used by WebAdmin. Now they are available for any API frontend, includingmod_adhoc_api
.New
mod_adhoc_api
moduleYou may remember this paragraph from the ejabberd 24.06 release notes:
Almost a year ago, ejabberd WebAdmin got support to execute all those 200 API commands... and now your XMPP client can execute them too!
The new mod_adhoc_api ejabberd module allows to execute all the ejabberd API commands using a XMPP client that supports XEP-0050 Ad-Hoc Commands and XEP-0030 Service Discovery.
Simply add this module to
modules
, setupapi_permissions
to grant some account permission to execute some command, or tags of commands, or all commands. Reload the ejabberd configuration and login with your client to that account.Now you can execute the same commands in the command line, using ReST, in the WebAdmin, and in your XMPP client!
This feature has been tested with Gajim, Psi, Psi+ and Tkabber. Conversejs allows to list and execute the commands, but doesn't show the result to the user.
create_room_with_opts
API command separatorsOne of the arguments accepted by the
create_room_with_opts
API command is a list of room options, expressed as tuples of option name and option value. And some room option values are also list of tuples! This is the case of affiliations and subscribers.That is not a problem for API frontends that accept structured arguments like
mod_http_api
andejabberd_xmlrpc
. But this is a problem in ejabberdctl, WebAdmin andmod_adhoc_api
, because they don't use structured arguments, and instead separate list elements with,
and tuple elements with:
. In that case, a list of tuples of list of tuples cannot be parsed correctly if all them use the same separators.Solution: when using the
create_room_with_opts
command to setaffiliations
andsubscribers
options:,
and now should be with;
:
and now should be with=
All the previous separators are still supported for backwards compatibility, but please use the new recommended separators, specially if using ejabberdctl, WebAdmin, and
mod_adhoc_api
.Let's see side by side the old and the new recommended syntax:
In a practical example, instead of this (which didn't work at all):
ejabberdctl \ create_room_with_opts \ room_old_separators \ conference.localhost \ localhost \ "persistent:true,affiliations:owner:user1@localhost,member:user2@localhost"
please use:
ejabberdctl \ create_room_with_opts \ room_new_separators \ conference.localhost \ localhost \ "persistent:true,affiliations:owner=user1@localhost;member=user2@localhost"
Notice that both the old and new separators are supported by
create_room_with_opts
. For example, let's usecurl
to query mod_http_api: