From b91b274b9259d349f90c4636c36b76e1b05343ea Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Sat, 30 Aug 2008 11:25:29 +0000 Subject: [PATCH] MDL-16180 - add portfolio support to mnet --- admin/mnet/adminlib.php | 12 +++++++++ admin/mnet/mnet_services.html | 5 +++- lib/adminlib.php | 6 +++++ mnet/lib.php | 46 ++++++++++++++++++++++++++--------- mnet/remote_client.php | 7 +++++- mnet/xmlrpc/server.php | 23 +++++++++++++++--- 6 files changed, 82 insertions(+), 17 deletions(-) diff --git a/admin/mnet/adminlib.php b/admin/mnet/adminlib.php index 8c5455499f..2e91159e6c 100644 --- a/admin/mnet/adminlib.php +++ b/admin/mnet/adminlib.php @@ -35,6 +35,12 @@ function mnet_get_functions($type, $parentname) { if (function_exists($mnet_publishes)) { (array)$publishes = $mnet_publishes(); } + } else if ('portfolio' == $type) { + $docname = 'lib.php'; + $relname = '/portfolio/type/' . $parentname . '/'. $docname; + $filename = $CFG->dirroot . $relname; + require_once($CFG->libdir . '/portfoliolib.php'); + $publishes = (array)portfolio_static_function($parentname, 'mnet_publishes'); } else { // auth or enrol $relname = '/'.$type.'/'.$parentname.'/'.$docname; @@ -179,5 +185,11 @@ function upgrade_RPC_functions($returnurl) { mnet_get_functions('enrol', $dir); } } + + if ($plugins = get_list_of_plugins('portfolio/type')) { + foreach ($plugins as $p) { + mnet_get_functions('portfolio', $p); + } + } } ?> diff --git a/admin/mnet/mnet_services.html b/admin/mnet/mnet_services.html index ae83cb7ea8..dcfa80d7ab 100644 --- a/admin/mnet/mnet_services.html +++ b/admin/mnet/mnet_services.html @@ -44,6 +44,9 @@ print_simple_box_start("center", ""); echo $breakstring; ?> + + + /> '; -?> +} ?> /> dirroot . '/portfolio/type/' . $plugin . '/db'; + } + } + /// Local database changes, if the local folder exists. if (file_exists($CFG->dirroot . '/local')) { $dbdirs[] = $CFG->dirroot.'/local/db'; diff --git a/mnet/lib.php b/mnet/lib.php index 958695f5c7..f6cc6ce5cd 100644 --- a/mnet/lib.php +++ b/mnet/lib.php @@ -494,22 +494,42 @@ function mnet_permit_rpc_call($includefile, $functionname, $class=false) { return RPC_NOSUCHCLASS; } - $object = new $class(); + $object = false; + $static = false; + + try { + // @todo set here whatever we can to ensure that errors cause exceptions :( + // see MDL-16175 - long term solution is teaching the dispatcher about: + // a: the difference between static and class methods + // b: object constructor arguments + $object = @new $class(); + if (!method_exists($object, $functionname)) { + // Generate error response - unable to locate method + return RPC_NOSUCHMETHOD; + } - if (!method_exists($object, $functionname)) { - // Generate error response - unable to locate method - return RPC_NOSUCHMETHOD; - } + if (!method_exists($object, 'mnet_publishes')) { + // Generate error response - the class doesn't publish + // *any* methods, because it doesn't have an mnet_publishes + // method + return RPC_FORBIDDENMETHOD; + } - if (!method_exists($object, 'mnet_publishes')) { - // Generate error response - the class doesn't publish - // *any* methods, because it doesn't have an mnet_publishes - // method - return RPC_FORBIDDENMETHOD; + // Get the list of published services - initialise method array + $servicelist = $object->mnet_publishes(); + } + catch (Exception $e) { + if (method_exists($class, $functionname)) { + // static... don't try to instantiate it. + if (!method_exists($class, 'mnet_publishes')) { + return RPC_FORBIDDENMETHOD; + } else { + $servicelist = call_user_func(array($class, 'mnet_publishes')); + } + $static = $class; + } } - // Get the list of published services - initialise method array - $servicelist = $object->mnet_publishes(); $methodapproved = false; // If the method is in the list of approved methods, set the @@ -527,6 +547,8 @@ function mnet_permit_rpc_call($includefile, $functionname, $class=false) { // Stash the object so we can call the method on it later $MNET_REMOTE_CLIENT->object_to_call($object); + $MNET_REMOTE_CLIENT->static_location($static); + // WE'RE LOOKING AT A FUNCTION } else { if (!function_exists($functionname)) { diff --git a/mnet/remote_client.php b/mnet/remote_client.php index 0cfd06df70..d618bf93e6 100644 --- a/mnet/remote_client.php +++ b/mnet/remote_client.php @@ -12,8 +12,9 @@ class mnet_remote_client extends mnet_peer { // If the remote client is trying to execute a method on an object instead // of just a function, we'll instantiate the proper class and store it in - // this 'object_to_call' property. + // this 'object_to_call' property, or 'static_location' if it wants to be called statically var $object_to_call = false; + var $static_location = false; var $request_was_encrypted = false; var $request_was_signed = false; @@ -29,6 +30,10 @@ class mnet_remote_client extends mnet_peer { $this->object_to_call = $object; } + function static_location($location) { + $this->static_location = $location; + } + function plaintext_is_ok() { global $CFG; diff --git a/mnet/xmlrpc/server.php b/mnet/xmlrpc/server.php index c937003d61..f8f26fd13b 100644 --- a/mnet/xmlrpc/server.php +++ b/mnet/xmlrpc/server.php @@ -314,10 +314,12 @@ function mnet_server_fault_xml($code, $text, $privatekey = null) { function mnet_server_dummy_method($methodname, $argsarray, $functionname) { global $MNET_REMOTE_CLIENT; - if (!is_object($MNET_REMOTE_CLIENT->object_to_call)) { - return @call_user_func_array($functionname, $argsarray); - } else { + if (is_object($MNET_REMOTE_CLIENT->object_to_call)) { return @call_user_method_array($functionname, $MNET_REMOTE_CLIENT->object_to_call, $argsarray); + } else if (!empty($MNET_REMOTE_CLIENT->static_location)) { + return @call_user_func_array(array($MNET_REMOTE_CLIENT->static_location, $functionname), $argsarray); + } else { + return @call_user_func_array($functionname, $argsarray); } } @@ -471,6 +473,21 @@ function mnet_server_dispatch($payload) { exit(mnet_server_fault(703, 'nosuchfunction')); } + } else if ($callstack[0] == 'portfolio') { + // Break out the callstack into its elements + list($base, $plugin, $filename, $methodname) = $callstack; + + if ($filename == 'lib.php') { + $pluginclass = 'portfolio_plugin_' . $plugin; + $includefile = '/portfolio/type/'.$plugin.'/lib.php'; + $response = mnet_server_invoke_method($includefile, $methodname, $method, $payload, $pluginclass); + $response = mnet_server_prepare_response($response); + echo $response; + } else { + // Generate error response - unable to locate function + exit(mnet_server_fault(7012, 'nosuchfunction')); + } + ////////////////////////////////////// STRICT MOD/* } elseif ($callstack[0] == 'mod' || 'dangerous' == $CFG->mnet_dispatcher_mode) { list($base, $module, $filename, $functionname) = $callstack; -- 2.39.5