MNET 1.0 RPC: Difference between revisions
David Mudrak (talk | contribs) m (Text replacement - "<code>" to "<syntaxhighlight lang="php">") |
David Mudrak (talk | contribs) m (Text replacement - "</code>" to "</syntaxhighlight>") |
||
Line 25: | Line 25: | ||
Instead, the rpc layer expects one of several prefixes in the method name | Instead, the rpc layer expects one of several prefixes in the method name | ||
* <syntaxhighlight lang="php">mod_</ | * <syntaxhighlight lang="php">mod_</syntaxhighlight> | ||
* <syntaxhighlight lang="php">auth_</ | * <syntaxhighlight lang="php">auth_</syntaxhighlight> | ||
* <syntaxhighlight lang="php">enrol_</ | * <syntaxhighlight lang="php">enrol_</syntaxhighlight> | ||
==== For modules ==== | ==== For modules ==== | ||
An RPC call to <syntaxhighlight lang="php">mod_forum_dofoobar()</ | An RPC call to <syntaxhighlight lang="php">mod_forum_dofoobar()</syntaxhighlight> rpc call triggers: | ||
* <syntaxhighlight lang="php">include_once(mod/forum/lib.php)</ | * <syntaxhighlight lang="php">include_once(mod/forum/lib.php)</syntaxhighlight> | ||
* check for <syntaxhighlight lang="php">function_exists("forum_rpc_dofoobar_enabled")</ | * check for <syntaxhighlight lang="php">function_exists("forum_rpc_dofoobar_enabled")</syntaxhighlight> | ||
* <syntaxhighlight lang="php">if (forum_rpc_dofoobar_enabled())</ | * <syntaxhighlight lang="php">if (forum_rpc_dofoobar_enabled())</syntaxhighlight> | ||
* then invoke <syntaxhighlight lang="php">forum_rpc_dofoobar()</ | * then invoke <syntaxhighlight lang="php">forum_rpc_dofoobar()</syntaxhighlight> with the parameters received... | ||
:'''Note:''' <syntaxhighlight lang="php">rpc_</ | :'''Note:''' <syntaxhighlight lang="php">rpc_</syntaxhighlight> is an arbitrary prefix that makes it clear that the function is for remote invocation. The <syntaxhighlight lang="php">_enabled()</syntaxhighlight> function must exist and return true for added security. make it really hard for a develper to expose something accidentally | ||
==== For auth and enrol plugins ==== | ==== For auth and enrol plugins ==== | ||
An RPC call to <syntaxhighlight lang="php">enrol_ldap_dofoobar()</ | An RPC call to <syntaxhighlight lang="php">enrol_ldap_dofoobar()</syntaxhighlight> rpc call triggers: | ||
* <syntaxhighlight lang="php">include_once(enrol/ldap/enrol.php)</ | * <syntaxhighlight lang="php">include_once(enrol/ldap/enrol.php)</syntaxhighlight> | ||
* instanciate the class | * instanciate the class | ||
* check for <syntaxhighlight lang="php">method_exists($obj, "rpc_dofoobar_enabled")</ | * check for <syntaxhighlight lang="php">method_exists($obj, "rpc_dofoobar_enabled")</syntaxhighlight> | ||
* <syntaxhighlight lang="php">if ($obj->rpc_dofoobar_enabled())</ | * <syntaxhighlight lang="php">if ($obj->rpc_dofoobar_enabled())</syntaxhighlight> | ||
* then invoke <syntaxhighlight lang="php">$obj->rpc_dofoobar()</ | * then invoke <syntaxhighlight lang="php">$obj->rpc_dofoobar()</syntaxhighlight> with the parameters received... |
Latest revision as of 13:04, 14 July 2021
Warning: This page is no longer in use. The information contained on the page should NOT be seen as relevant or reliable. |
As part of the Community hub infrastructure, we need to define RPC calling conventions...
Moodle's APIs follow several principles that make them scalable annd flexible.
- They are "Just In Time discoverable" rather than all registered at runtime. This is a good optimization for HTTP's statelesness.
- Once an entry point is hit (a webpage in moodle, for instance) the module code author is in control. The framework doesn't limit what kinds of interactions can happen.
So we want to preserve those capabilities... Additionally, we want to make sure the RPC calls are safe, and cannot be exposed by accident.
Outline of a new mnet API
Calls can be exposed via the mnet API by
- Moodle core
- Moodle auth plugins
- Moodle enrol plugins
- Moodle modules
How the RPC calls are dispatched
The dispatcher is slightly different from a conventional XML-RPC dispacher that gets the available methods registered at startup. (It is too costly to walk all the available modules and plugins on each invocation.)
Instead, the rpc layer expects one of several prefixes in the method name
mod_
auth_
enrol_
For modules
An RPC call to
mod_forum_dofoobar()
rpc call triggers:
include_once(mod/forum/lib.php)
- check for
function_exists("forum_rpc_dofoobar_enabled")
if (forum_rpc_dofoobar_enabled())
- then invoke with the parameters received...
forum_rpc_dofoobar()
- Note: is an arbitrary prefix that makes it clear that the function is for remote invocation. The
rpc_
function must exist and return true for added security. make it really hard for a develper to expose something accidentally_enabled()
For auth and enrol plugins
An RPC call to
enrol_ldap_dofoobar()
rpc call triggers:
include_once(enrol/ldap/enrol.php)
- instanciate the class
- check for
method_exists($obj, "rpc_dofoobar_enabled")
if ($obj->rpc_dofoobar_enabled())
- then invoke with the parameters received...
$obj->rpc_dofoobar()