<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3AMNet_API</id>
	<title>Development:MNet API - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3AMNet_API"/>
	<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:MNet_API&amp;action=history"/>
	<updated>2026-05-06T20:44:30Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:MNet_API&amp;diff=11328&amp;oldid=prev</id>
		<title>Олег Давидович: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:MNet_API&amp;diff=11328&amp;oldid=prev"/>
		<updated>2024-10-21T08:51:25Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 08:51, 21 октября 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Олег Давидович</name></author>
	</entry>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:MNet_API&amp;diff=11327&amp;oldid=prev</id>
		<title>1&gt;Tsala: category edit</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:MNet_API&amp;diff=11327&amp;oldid=prev"/>
		<updated>2010-02-18T20:17:15Z</updated>

		<summary type="html">&lt;p&gt;category edit&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
This page aims to serve as the location for documenting the Moodle NETwork API (MNET API), both the XMLRPC functions and the associated code.  &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;#039;&amp;#039;It is a work in progress, please add to it as you discover undocumented code.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== How to use MNET ==&lt;br /&gt;
This paragraph will explain you how to setup a connection between a client and a server with mnet. It will also explain where to write the functions you want to call in the server.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Note: The following code is just here to give you a better idea of how the API works. Do not expect them to work as provided.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=== Basic Client/Server code===&lt;br /&gt;
In this example  we&amp;#039;ll ask the server which methods we can access. The system server methods &amp;#039;ListMethods&amp;#039; is already implemented, so we will only write client code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Code php&amp;gt;&lt;br /&gt;
    require_once($CFG-&amp;gt;dirroot . &amp;#039;/mnet/xmlrpc/client.php&amp;#039;); //mnet client library&lt;br /&gt;
&lt;br /&gt;
    /// Setup MNET environment&lt;br /&gt;
        global $MNET;&lt;br /&gt;
        if (empty($MNET)) {&lt;br /&gt;
            $MNET = new mnet_environment();&lt;br /&gt;
            $MNET-&amp;gt;init();&lt;br /&gt;
        }             &lt;br /&gt;
   &lt;br /&gt;
    /// Setup the server&lt;br /&gt;
        $host = $DB-&amp;gt;get_record(&amp;#039;mnet_host&amp;#039;,array(&amp;#039;id&amp;#039; =&amp;gt; 4)); //we retrieve the server(host) from the &amp;#039;mnet_host&amp;#039; table&lt;br /&gt;
        $mnet_peer = new mnet_peer();                          //we create a new mnet_peer (server/host)&lt;br /&gt;
        $mnet_peer-&amp;gt;set_wwwroot($host-&amp;gt;wwwroot);               //we set this mnet_peer with the host http address&lt;br /&gt;
&lt;br /&gt;
    /// Connect to the remote moodle and retrieve the list of methods (synchronous transmission)&lt;br /&gt;
        $client = new mnet_xmlrpc_client();        //create a new client&lt;br /&gt;
        $client-&amp;gt;set_method(&amp;#039;system/listMethods&amp;#039;); //tell it which method we&amp;#039;re going to call       &lt;br /&gt;
        $client-&amp;gt;send($mnet_peer);                 //Call the server&lt;br /&gt;
        $response = $client-&amp;gt;response;             //Receive the server response &lt;br /&gt;
&lt;br /&gt;
        var_dump($response);&lt;br /&gt;
&amp;lt;/Code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== System methods ===&lt;br /&gt;
System methods are declared as available into /mnet/xmlrpc/client.php::permission_to_call(). If you add a new system method you will have to add its name to the system_methods array into this function.&lt;br /&gt;
&lt;br /&gt;
A mnet server comes with few system methods which have been implemented into /mnet/xmlrpc/server.php::mnet_system()&amp;lt;br&amp;gt;&lt;br /&gt;
Parameters are saved into the $params array. Your first $client-&amp;gt;add_param($param1) we&amp;#039;ll be in $params[0] etc.&lt;br /&gt;
&lt;br /&gt;
=== Specific methods ===&lt;br /&gt;
Most of the time you don&amp;#039;t want to add a system method but a method for a module/service. You also want it to be displayed by the &amp;quot;ListMethods&amp;quot; system method.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s implement a function returning &amp;quot;Hello World&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
1. We create this function into servicefolder/services.php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
class services {&lt;br /&gt;
&lt;br /&gt;
    function static helloWorld($firstname, $surname) {&lt;br /&gt;
        return &amp;quot;Hello World&amp;quot; . $firstname . $surname; //note that we could return an array, &lt;br /&gt;
                                                      //it would still be managed by mnet without a change anywhere else&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We register this function as a mnet function into the database:&amp;lt;br&amp;gt;&lt;br /&gt;
Into admin/mnet/adminlib.php, we add this code:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
function mnet_get_functions($type, $parentname) {&lt;br /&gt;
...&lt;br /&gt;
else if (&amp;#039;service&amp;#039; == $type) {&lt;br /&gt;
/// we&amp;#039;re going to load the service object (after having checked it exists) &lt;br /&gt;
/// and call mnet_publishes function&lt;br /&gt;
$docname = &amp;#039;services.php&amp;#039;;&lt;br /&gt;
$relname = &amp;#039;/servicefolder/&amp;#039;. $docname;&lt;br /&gt;
$filename = $CFG-&amp;gt;dirroot.$relname;&lt;br /&gt;
if (file_exists($filename)) include_once $filename;&lt;br /&gt;
$class = &amp;quot;services&amp;quot;;&lt;br /&gt;
if (class_exists($class)) {&lt;br /&gt;
    $object = new $class(); &lt;br /&gt;
    if (method_exists($object, &amp;#039;mnet_publishes&amp;#039;)) {&lt;br /&gt;
        (array)$publishes = $object-&amp;gt;mnet_publishes(); //retrieve the service information&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
... &lt;br /&gt;
///below, the retrieved information are saved into the database&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
function upgrade_RPC_functions($returnurl) {&lt;br /&gt;
    ...&lt;br /&gt;
    /// check other mnet_get_functions calls into the same file&lt;br /&gt;
    mnet_get_functions(&amp;#039;service&amp;#039;, null);&lt;br /&gt;
}&lt;br /&gt;
*/&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Into the &amp;#039;&amp;#039;Service&amp;#039;&amp;#039; class of servicefolder/services.php, add&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
public static function mnet_publishes() {&lt;br /&gt;
    $service= array();&lt;br /&gt;
    $service[&amp;#039;name&amp;#039;]        = &amp;#039;service&amp;#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
    $service[&amp;#039;apiversion&amp;#039;]  = 1;&lt;br /&gt;
    $service[&amp;#039;methods&amp;#039;]     = array(&amp;#039;helloWorld&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
    return array($service);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. The server needs to dispatch&lt;br /&gt;
in mnet/xmlrpc/server.php::mnet_server_dispatch(), we need to add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
else if ($callstack[0] == &amp;#039;servicefolder&amp;#039;) {    &lt;br /&gt;
        list($base, $filename, $methodname) = $callstack;  // Break out the callstack into its elements&lt;br /&gt;
        if ($filename == &amp;#039;services.php&amp;#039;) {   &lt;br /&gt;
            $response = mnet_server_invoke_method(&amp;#039;/servicefolder/services.php&amp;#039;, $methodname, $method, $payload, &amp;#039;services&amp;#039;);&lt;br /&gt;
            $response = mnet_server_prepare_response($response);&lt;br /&gt;
            echo $response;&lt;br /&gt;
        } else {&lt;br /&gt;
        /// Generate error response - unable to locate function&lt;br /&gt;
            exit(mnet_server_fault(7012, &amp;#039;nosuchfunction&amp;#039;));&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
4. We add the method to the &amp;quot;ListMethods&amp;quot; system method&amp;lt;br&amp;gt;&lt;br /&gt;
No code is needed. Just go into the Moodle Administration &amp;gt; Networking &amp;gt; Peers. Select the &amp;#039;&amp;#039;Services&amp;#039;&amp;#039; tab from the host server. There, activate your service.&lt;br /&gt;
&lt;br /&gt;
5. We write some client code&amp;lt;br&amp;gt;&lt;br /&gt;
First of all test the code from the section &amp;quot;Client/Server&amp;quot; above. You should see &amp;quot;&amp;#039;&amp;#039;servicefolder/services.php/helloworld&amp;#039;&amp;#039;&amp;quot; function into the response.&lt;br /&gt;
&lt;br /&gt;
We can now call this method. Change:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$client-&amp;gt;set_method(&amp;#039;system/listMethods&amp;#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
For:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$client-&amp;gt;set_method(&amp;#039;servicefolder/services.php/helloworld&amp;#039;);&lt;br /&gt;
$client-&amp;gt;add_param(&amp;#039;Thierry&amp;#039;); &lt;br /&gt;
$client-&amp;gt;add_param(&amp;#039;Henry&amp;#039;); &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Entry points/XMLRPC documentation==&lt;br /&gt;
&lt;br /&gt;
The entry point is wwwroot/xmlrpc/server.php, which at some point calls mnet_permit_rpc_call, which sets some member variables in the MNET_REMOTE_CLIENT object (mnet/remote_client.php) so that later when mnet_server_dummy_method is called, it can dispatch the call accordingly.  I &amp;#039;&amp;#039;&amp;#039;think&amp;#039;&amp;#039;&amp;#039; mnet_server_dummy_method is the only way functions get called.&lt;br /&gt;
&lt;br /&gt;
Currently you can call class methods, static methods and functions.  However, for a class method, there is currently only support to construct the object with no constructor arguments.&lt;br /&gt;
&lt;br /&gt;
==Authentication Functions==&lt;br /&gt;
&lt;br /&gt;
Documentation TODO&lt;br /&gt;
&lt;br /&gt;
==Enrolment Functions==&lt;br /&gt;
&lt;br /&gt;
Documentation TODO&lt;br /&gt;
&lt;br /&gt;
== Repository Functions ==&lt;br /&gt;
&lt;br /&gt;
Documentation TODO&lt;br /&gt;
&lt;br /&gt;
==Portfolio Functions==&lt;br /&gt;
&lt;br /&gt;
===send_content_intent===&lt;br /&gt;
&lt;br /&gt;
* Defined in: portfolio/type/mahara/lib.php&lt;br /&gt;
* Implemented in: Mahara.  Moodle has this function but it is not an xmlrpc function, only a helper function to call the xmlrpc function in Mahara.  (See MDL-16269)&lt;br /&gt;
* Parameters: &lt;br /&gt;
** username: username of user to find or create&lt;br /&gt;
* Returns: Stdclass object with keys:&lt;br /&gt;
** sendtype: string - either &amp;#039;queue&amp;#039; or &amp;#039;immediate&amp;#039; depending on what the remote system has decided&lt;br /&gt;
** token: string - to use for all further communication&lt;br /&gt;
&lt;br /&gt;
===send_content_ready===&lt;br /&gt;
&lt;br /&gt;
* Defined in: portfolio/type/mahara/lib.php&lt;br /&gt;
* Implemented in: Mahara.  Moodle has this function but it is not an xmlrpc function, only a helper function to call the xmlrpc function in Mahara.  (See MDL-16269)&lt;br /&gt;
* Parameters:&lt;br /&gt;
** token: string, previously return from from send_content_intent&lt;br /&gt;
** username: string, username of user to find&lt;br /&gt;
** format: string: currently just &amp;#039;file&amp;#039;, could be more later &lt;br /&gt;
** data: keyed array, information &amp;#039;&amp;#039;&amp;#039;per format&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
*** shared keys, expected by all formats:&lt;br /&gt;
****  totalsize: total filesize of included files (in bytes) - used for quota checks&lt;br /&gt;
*** &amp;#039;file&amp;#039; format keys:&lt;br /&gt;
**** filesmanifest: keyed array of file information (keyed by filename):&lt;br /&gt;
***** filename: desired name of file&lt;br /&gt;
***** sha1: sha1 of file&lt;br /&gt;
***** size: size of file (in bytes)&lt;br /&gt;
**** zipfilesha1: sha1 of the zipfile containing the file(s)&lt;br /&gt;
**** zipfilesize: size of the zipfile containing the file(s)&lt;br /&gt;
** wait: boolean. whether the remote system is expected to immediately launch a request to fetch file or queue it for cron.&lt;br /&gt;
* Returns: Stdclass object with keys:&lt;br /&gt;
** status: boolean, success or failure&lt;br /&gt;
** type: string, &amp;#039;queued&amp;#039; or &amp;#039;complete&amp;#039;&lt;br /&gt;
** querystring: string, used for the final &amp;#039;continue to portfolio&amp;#039; link (eg ?folder=6&amp;amp;file=6 to highlight new files that were added)&lt;br /&gt;
&lt;br /&gt;
===fetch_file===&lt;br /&gt;
&lt;br /&gt;
* Defined in: portfolio/type/mahara/lib.php&lt;br /&gt;
* Implemented in: Moodle.&lt;br /&gt;
* Parameters:&lt;br /&gt;
** token: string, same that was returned in send_content_intent and used subsequently in send_content_ready&lt;br /&gt;
* Returns: base64 encoded file (currently a zipfile, as can include multiple files)&lt;br /&gt;
&lt;br /&gt;
[[Category:MNet]]&lt;/div&gt;</summary>
		<author><name>1&gt;Tsala</name></author>
	</entry>
</feed>