From 1017f6f159386699a10d2529c50fb5e28b5c1889 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sat, 19 Nov 2011 14:40:29 +0100 Subject: begin with remote api --- inc/remote.php | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 inc/remote.php (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php new file mode 100644 index 000000000..ea5e23af3 --- /dev/null +++ b/inc/remote.php @@ -0,0 +1,120 @@ + array( + * 'args' => array( + * 'type' => 'string|int|...', + * ) + * ) + * ) + * + * plugin names are formed the following: + * core methods begin by a 'dokuwiki' or 'wiki' followed by a . and the method name itself. + * i.e.: dokuwiki.version or wiki.getPage + * + * plugin methods are formed like 'plugin..'. + * i.e.: plugin.clock.getTime or plugin.clock_gmt.getTime + * + * + * + * @throws RemoteException + */ +class RemoteAPI { + + /** + * @var array remote methods provided by dokuwiki. + */ + private $coreMethods = array(); + + /** + * @var array remote methods provided by dokuwiki plugins - will be filled lazy via + * {@see RemoteAPI#getPluginMethods} + */ + private $pluginMethods = null; + + /** + * Get all available methods with remote access. + * + * @return array with information to all available methods + */ + public function getMethods() { + $this->forceAccess(); + return array_merge($this->getCoreMethods(), $this->getPluginMethods()); + } + + /** + * call a method via remote api. + * + * @param string $method name of the method to call. + * @param array $args arguments to pass to the given method + * @return mixed result of method call, must be a primitive type. + */ + public function call($method, $args) { + $this->forceAccess(); + $method = explode('.', $method); + if ($method[0] === 'plugin') { + $plugin = plugin_load('remote', $method[1]); + if (!$plugin) { + throw new RemoteException('Method unavailable'); + } + return call_user_func_array(array($plugin, $method[2]), $args); + } else { + // TODO call core method + } + + } + + /** + * @return bool true if the current user has access to remote api. + */ + public function hasAccess() { + global $conf; + if (!isset($conf['remote'])) { + return false; + } + return $conf['remote']; + } + + /** + * @throws RemoteException On denied access. + * @return void + */ + private function forceAccess() { + if (!$this->hasAccess()) { + throw new RemoteException('Access denied'); + } + } + + /** + * @return array all plugin methods. + */ + public function getPluginMethods() { + if ($this->pluginMethods === null) { + // TODO: find plugin methods + $this->pluginMethods = array(); + } + return $this->pluginMethods; + } + + /** + * @return array all core methods. + */ + public function getCoreMethods() { + return $this->coreMethods; + } +} + + +class RemoteException extends Exception {} \ No newline at end of file -- cgit v1.2.3 From 457ad80ad7c53870fc033997bfbf36e3904f9c4e Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 23 Nov 2011 20:25:58 +0100 Subject: introduced remote api class --- inc/remote.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index ea5e23af3..13a38aa17 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -17,6 +17,7 @@ if (!defined('DOKU_INC')) die(); * 'args' => array( * 'type' => 'string|int|...', * ) + * 'return' => 'type' * ) * ) * @@ -102,8 +103,20 @@ class RemoteAPI { */ public function getPluginMethods() { if ($this->pluginMethods === null) { - // TODO: find plugin methods $this->pluginMethods = array(); + $plugins = plugin_list('remote'); + + foreach ($plugins as $pluginName) { + $plugin = plugin_load('remote', $pluginName); + if (!is_subclass_of($plugin, 'DokuWiki_Remote_Plugin')) { + throw new RemoteException("Plugin $pluginName dose not implement DokuWiki_Remote_Plugin"); + } + + $methods = $plugin->_getMethods(); + foreach ($methods as $method => $meta) { + $this->pluginMethods["plugin.$pluginName.$method"] = $meta; + } + } } return $this->pluginMethods; } -- cgit v1.2.3 From f61380cb67f8216ae4c75922511ff5a07fd21ca0 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Mon, 28 Nov 2011 19:06:16 +0100 Subject: introduced first remote test cases --- inc/remote.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index 13a38aa17..6f48d2015 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -92,7 +92,7 @@ class RemoteAPI { * @throws RemoteException On denied access. * @return void */ - private function forceAccess() { + public function forceAccess() { if (!$this->hasAccess()) { throw new RemoteException('Access denied'); } -- cgit v1.2.3 From 3f3bb97fcdd30282632d96a5bb19d2ea61c01504 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Mon, 28 Nov 2011 20:59:49 +0100 Subject: removed dublicated content --- inc/remote.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index 6f48d2015..14f6614f1 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -130,4 +130,5 @@ class RemoteAPI { } -class RemoteException extends Exception {} \ No newline at end of file +class RemoteException extends Exception {} +class RemoteAccessDenied extends RemoteException {} \ No newline at end of file -- cgit v1.2.3 From 4815d222f25c9a31949297223c98cfca7151ae8d Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Thu, 8 Dec 2011 19:57:18 +0100 Subject: RemoteAPI can now handle remote calls. --- inc/remote.php | 68 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 19 deletions(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index 14f6614f1..5f136a43d 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -2,6 +2,9 @@ if (!defined('DOKU_INC')) die(); +class RemoteException extends Exception {} +class RemoteAccessDenied extends RemoteException {} + /** * This class provides information about remote access to the wiki. * @@ -13,11 +16,16 @@ if (!defined('DOKU_INC')) die(); * == Information structure == * The information about methods will be given in an array with the following structure: * array( - * 'method.name' => array( + * 'method.remoteName' => array( * 'args' => array( - * 'type' => 'string|int|...', + * 'name' => array( + * 'type' => 'string|int|...|date|file', + * ['doc' = 'argument documentation'], + * ), * ) - * 'return' => 'type' + * 'name' => 'method name in class', + * 'return' => 'type', +* ['doc' = 'method documentation'], * ) * ) * @@ -35,9 +43,9 @@ if (!defined('DOKU_INC')) die(); class RemoteAPI { /** - * @var array remote methods provided by dokuwiki. + * @var RemoteAPICore */ - private $coreMethods = array(); + private $coreMethods = null; /** * @var array remote methods provided by dokuwiki plugins - will be filled lazy via @@ -62,19 +70,36 @@ class RemoteAPI { * @param array $args arguments to pass to the given method * @return mixed result of method call, must be a primitive type. */ - public function call($method, $args) { + public function call($method, $args = array()) { $this->forceAccess(); - $method = explode('.', $method); - if ($method[0] === 'plugin') { - $plugin = plugin_load('remote', $method[1]); + list($type, $pluginName, $call) = explode('.', $method, 3); + if ($type === 'plugin') { + $plugin = plugin_load('remote', $pluginName); if (!$plugin) { - throw new RemoteException('Method unavailable'); + throw new RemoteException('Method dose not exists'); } - return call_user_func_array(array($plugin, $method[2]), $args); + return call_user_func_array(array($plugin, $call), $args); } else { - // TODO call core method + $coreMethods = $this->getCoreMethods(); + if (!isset($coreMethods[$method])) { + throw new RemoteException('Method dose not exists'); + } + $this->checkArgumentLength($coreMethods[$method], $args); + return call_user_func_array(array($this->coreMethods, $this->getMethodName($coreMethods, $method)), $args); } + } + private function checkArgumentLength($method, $args) { + if (count($method['args']) < count($args)) { + throw new RemoteException('Method dose not exists - wrong parameter count.'); + } + } + + private function getMethodName($methodMeta, $method) { + if (isset($methodMeta[$method]['name'])) { + return $methodMeta[$method]['name']; + } + return $method; } /** @@ -122,13 +147,18 @@ class RemoteAPI { } /** + * @param RemoteAPICore $apiCore this parameter is used for testing. Here you can pass a non-default RemoteAPICore + * instance. (for mocking) * @return array all core methods. */ - public function getCoreMethods() { - return $this->coreMethods; + public function getCoreMethods($apiCore = null) { + if ($this->coreMethods === null) { + if ($apiCore === null) { + $this->coreMethods = new RemoteAPICore(); + } else { + $this->coreMethods = $apiCore; + } + } + return $this->coreMethods->__getRemoteInfo(); } -} - - -class RemoteException extends Exception {} -class RemoteAccessDenied extends RemoteException {} \ No newline at end of file +} \ No newline at end of file -- cgit v1.2.3 From 647919c9a61d928502b0b45063cc60702d0d310e Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Thu, 8 Dec 2011 20:33:30 +0100 Subject: added remote plugin calls. --- inc/remote.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index 5f136a43d..bc35d525e 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -75,10 +75,12 @@ class RemoteAPI { list($type, $pluginName, $call) = explode('.', $method, 3); if ($type === 'plugin') { $plugin = plugin_load('remote', $pluginName); + $methods = $this->getPluginMethods(); if (!$plugin) { throw new RemoteException('Method dose not exists'); } - return call_user_func_array(array($plugin, $call), $args); + $name = $this->getMethodName($methods, $method); + return call_user_func_array(array($plugin, $name), $args); } else { $coreMethods = $this->getCoreMethods(); if (!isset($coreMethods[$method])) { @@ -99,7 +101,8 @@ class RemoteAPI { if (isset($methodMeta[$method]['name'])) { return $methodMeta[$method]['name']; } - return $method; + $method = explode('.', $method); + return $method[count($method)-1]; } /** -- cgit v1.2.3 From 795114e73f18f06c2b32b433e150cad81da6581f Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sat, 10 Dec 2011 14:05:33 +0100 Subject: changed return types --- inc/remote.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index bc35d525e..7e82b6845 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -5,6 +5,21 @@ if (!defined('DOKU_INC')) die(); class RemoteException extends Exception {} class RemoteAccessDenied extends RemoteException {} +abstract class RemoteDataType { + private $value; + + function __construct($value) { + $this->value = $value; + } + + function getValue() { + return $this->value; + } +} + +class RemoteDate extends RemoteDataType {} +class RemoteFile extends RemoteDataType {} + /** * This class provides information about remote access to the wiki. * -- cgit v1.2.3 From 37fa8abdcb4ed0634f9c21c8e6f2d727d1ffd600 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 21 Dec 2011 14:35:48 +0100 Subject: added methods from xmlrpc.php to RemoteAPICore --- inc/remote.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index 7e82b6845..e18c71092 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -33,10 +33,7 @@ class RemoteFile extends RemoteDataType {} * array( * 'method.remoteName' => array( * 'args' => array( - * 'name' => array( - * 'type' => 'string|int|...|date|file', - * ['doc' = 'argument documentation'], - * ), + * 'name' => 'type eg. string|int|...|date|file', * ) * 'name' => 'method name in class', * 'return' => 'type', -- cgit v1.2.3 From a317247b19c498f4292480110cf0e0a1ce9780e8 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 8 Jan 2012 14:54:53 +0100 Subject: updated remote hasAccess function --- inc/remote.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index e18c71092..94d428e8c 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -71,7 +71,6 @@ class RemoteAPI { * @return array with information to all available methods */ public function getMethods() { - $this->forceAccess(); return array_merge($this->getCoreMethods(), $this->getPluginMethods()); } @@ -122,10 +121,18 @@ class RemoteAPI { */ public function hasAccess() { global $conf; - if (!isset($conf['remote'])) { + global $USERINFO; + if (!$conf['remote']) { return false; } - return $conf['remote']; + if(!$conf['useacl']) { + return true; + } + if(trim($conf['remoteuser']) == '') { + return true; + } + + return auth_isMember($conf['remoteuser'], $_SERVER['REMOTE_USER'], (array) $USERINFO['grps']); } /** -- cgit v1.2.3 From 4beb39ea51a46409ab3abd4a1b880bf5d3d5dc4a Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 8 Jan 2012 15:31:46 +0100 Subject: enforce acl on remote method call --- inc/remote.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index 94d428e8c..15d2308f8 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -82,7 +82,6 @@ class RemoteAPI { * @return mixed result of method call, must be a primitive type. */ public function call($method, $args = array()) { - $this->forceAccess(); list($type, $pluginName, $call) = explode('.', $method, 3); if ($type === 'plugin') { $plugin = plugin_load('remote', $pluginName); @@ -90,10 +89,12 @@ class RemoteAPI { if (!$plugin) { throw new RemoteException('Method dose not exists'); } + $this->checkAccess($methods[$method]); $name = $this->getMethodName($methods, $method); return call_user_func_array(array($plugin, $name), $args); } else { $coreMethods = $this->getCoreMethods(); + $this->checkAccess($coreMethods[$method]); if (!isset($coreMethods[$method])) { throw new RemoteException('Method dose not exists'); } @@ -102,6 +103,16 @@ class RemoteAPI { } } + private function checkAccess($methodMeta) { + if (!isset($methodMeta['public'])) { + $this->forceAccess(); + } else{ + if ($methodMeta['public'] == '0') { + $this->forceAccess(); + } + } + } + private function checkArgumentLength($method, $args) { if (count($method['args']) < count($args)) { throw new RemoteException('Method dose not exists - wrong parameter count.'); @@ -141,7 +152,7 @@ class RemoteAPI { */ public function forceAccess() { if (!$this->hasAccess()) { - throw new RemoteException('Access denied'); + throw new RemoteAccessDenied(); } } -- cgit v1.2.3 From 3a13cfe7e12afabb47139702b7f118d63ccf42c2 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 8 Jan 2012 18:10:38 +0100 Subject: set login as public method --- inc/remote.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index 15d2308f8..76d07b344 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -1,6 +1,7 @@ Date: Sun, 8 Jan 2012 18:27:27 +0100 Subject: treat null as empty array --- inc/remote.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index 76d07b344..c18cb3713 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -83,6 +83,9 @@ class RemoteAPI { * @return mixed result of method call, must be a primitive type. */ public function call($method, $args = array()) { + if ($args === null) { + $args = array(); + } list($type, $pluginName, $call) = explode('.', $method, 3); if ($type === 'plugin') { $plugin = plugin_load('remote', $pluginName); -- cgit v1.2.3 From f95017850a515969190f54df3d57a00449245bb9 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 8 Jan 2012 18:37:59 +0100 Subject: delegate file and date transformation to remote library --- inc/remote.php | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index c18cb3713..71ceb97b5 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -18,9 +18,6 @@ abstract class RemoteDataType { } } -class RemoteDate extends RemoteDataType {} -class RemoteFile extends RemoteDataType {} - /** * This class provides information about remote access to the wiki. * @@ -66,6 +63,14 @@ class RemoteAPI { */ private $pluginMethods = null; + private $dateTransformation; + private $fileTransformation; + + public function __construct() { + $this->dateTransformation = array($this, 'dummyTransformation'); + $this->fileTransformation = array($this, 'dummyTransformation'); + } + /** * Get all available methods with remote access. * @@ -191,11 +196,31 @@ class RemoteAPI { public function getCoreMethods($apiCore = null) { if ($this->coreMethods === null) { if ($apiCore === null) { - $this->coreMethods = new RemoteAPICore(); + $this->coreMethods = new RemoteAPICore($this); } else { $this->coreMethods = $apiCore; } } return $this->coreMethods->__getRemoteInfo(); } + + public function toFile($data) { + return call_user_func($this->fileTransformation, $data); + } + + public function toDate($data) { + return call_user_func($this->dateTransformation, $data); + } + + public function dummyTransformation($data) { + return $data; + } + + public function setDateTransformation($dateTransformation) { + $this->dateTransformation = $dateTransformation; + } + + public function setFileTransformation($fileTransformation) { + $this->fileTransformation = $fileTransformation; + } } \ No newline at end of file -- cgit v1.2.3 From e61127e4af913a252fbe5c8f427501268501895c Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 8 Jan 2012 19:31:10 +0100 Subject: refactored RemoteAccessDenied to RemoteAccessDeniedException --- inc/remote.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index 71ceb97b5..8c505911c 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -4,7 +4,7 @@ if (!defined('DOKU_INC')) die(); require_once(DOKU_INC.'inc/RemoteAPICore.php'); class RemoteException extends Exception {} -class RemoteAccessDenied extends RemoteException {} +class RemoteAccessDeniedException extends RemoteException {} abstract class RemoteDataType { private $value; @@ -161,7 +161,7 @@ class RemoteAPI { */ public function forceAccess() { if (!$this->hasAccess()) { - throw new RemoteAccessDenied(); + throw new RemoteAccessDeniedException(); } } -- cgit v1.2.3 From 200ff6b799de7ba300488ec4cb4833c0092761e5 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 22 Jan 2012 11:58:39 +0100 Subject: removed unused class --- inc/remote.php | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index 8c505911c..0a507e95d 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -6,18 +6,6 @@ require_once(DOKU_INC.'inc/RemoteAPICore.php'); class RemoteException extends Exception {} class RemoteAccessDeniedException extends RemoteException {} -abstract class RemoteDataType { - private $value; - - function __construct($value) { - $this->value = $value; - } - - function getValue() { - return $this->value; - } -} - /** * This class provides information about remote access to the wiki. * -- cgit v1.2.3 From 750a55de568a82aaa40ca384a17a64804e94f2b9 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 5 Feb 2012 12:33:35 +0100 Subject: corrected comment --- inc/remote.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index 0a507e95d..82a0d3c08 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -23,7 +23,8 @@ class RemoteAccessDeniedException extends RemoteException {} * ) * 'name' => 'method name in class', * 'return' => 'type', -* ['doc' = 'method documentation'], + * 'public' => 1/0 - method bypass default group check (used by login) + * ['doc' = 'method documentation'], * ) * ) * -- cgit v1.2.3 From 03d7247e047c21d2733f837148a1499f56784ae3 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 5 Feb 2012 12:36:19 +0100 Subject: moved plugin and core method calls to seperate function --- inc/remote.php | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index 82a0d3c08..105969f8b 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -82,23 +82,31 @@ class RemoteAPI { } list($type, $pluginName, $call) = explode('.', $method, 3); if ($type === 'plugin') { - $plugin = plugin_load('remote', $pluginName); - $methods = $this->getPluginMethods(); - if (!$plugin) { - throw new RemoteException('Method dose not exists'); - } - $this->checkAccess($methods[$method]); - $name = $this->getMethodName($methods, $method); - return call_user_func_array(array($plugin, $name), $args); + return $this->callPlugin($pluginName, $method, $args); } else { - $coreMethods = $this->getCoreMethods(); - $this->checkAccess($coreMethods[$method]); - if (!isset($coreMethods[$method])) { - throw new RemoteException('Method dose not exists'); - } - $this->checkArgumentLength($coreMethods[$method], $args); - return call_user_func_array(array($this->coreMethods, $this->getMethodName($coreMethods, $method)), $args); + return $this->callCoreMethod($method, $args); + } + } + + private function callPlugin($pluginName, $method, $args) { + $plugin = plugin_load('remote', $pluginName); + $methods = $this->getPluginMethods(); + if (!$plugin) { + throw new RemoteException('Method dose not exists'); + } + $this->checkAccess($methods[$method]); + $name = $this->getMethodName($methods, $method); + return call_user_func_array(array($plugin, $name), $args); + } + + private function callCoreMethod($method, $args) { + $coreMethods = $this->getCoreMethods(); + $this->checkAccess($coreMethods[$method]); + if (!isset($coreMethods[$method])) { + throw new RemoteException('Method dose not exists'); } + $this->checkArgumentLength($coreMethods[$method], $args); + return call_user_func_array(array($this->coreMethods, $this->getMethodName($coreMethods, $method)), $args); } private function checkAccess($methodMeta) { -- cgit v1.2.3 From 4ea1d54936a1d1e9b919e06639632bc2ac65f6d3 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 21 Mar 2012 11:01:38 +0100 Subject: typo fixes --- inc/remote.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index c8af76420..fb095f517 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -92,7 +92,7 @@ class RemoteAPI { $plugin = plugin_load('remote', $pluginName); $methods = $this->getPluginMethods(); if (!$plugin) { - throw new RemoteException('Method dose not exists', -32603); + throw new RemoteException('Method does not exist', -32603); } $this->checkAccess($methods[$method]); $name = $this->getMethodName($methods, $method); @@ -103,7 +103,7 @@ class RemoteAPI { $coreMethods = $this->getCoreMethods(); $this->checkAccess($coreMethods[$method]); if (!isset($coreMethods[$method])) { - throw new RemoteException('Method dose not exists', -32603); + throw new RemoteException('Method does not exist', -32603); } $this->checkArgumentLength($coreMethods[$method], $args); return call_user_func_array(array($this->coreMethods, $this->getMethodName($coreMethods, $method)), $args); @@ -121,7 +121,7 @@ class RemoteAPI { private function checkArgumentLength($method, $args) { if (count($method['args']) < count($args)) { - throw new RemoteException('Method dose not exists - wrong parameter count.', -32603); + throw new RemoteException('Method does not exist - wrong parameter count.', -32603); } } @@ -173,7 +173,7 @@ class RemoteAPI { foreach ($plugins as $pluginName) { $plugin = plugin_load('remote', $pluginName); if (!is_subclass_of($plugin, 'DokuWiki_Remote_Plugin')) { - throw new RemoteException("Plugin $pluginName dose not implement DokuWiki_Remote_Plugin"); + throw new RemoteException("Plugin $pluginName does not implement DokuWiki_Remote_Plugin"); } $methods = $plugin->_getMethods(); -- cgit v1.2.3 From c2eb026d070a5ba9ba1ee8754c3a862a026a7ea8 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 21 Mar 2012 11:04:12 +0100 Subject: changed error code for unauthorized method calls. --- inc/remote.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index fb095f517..b4cc8e6cc 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -158,7 +158,7 @@ class RemoteAPI { */ public function forceAccess() { if (!$this->hasAccess()) { - throw new RemoteAccessDeniedException('server error. not authorized to call method', -32603); + throw new RemoteAccessDeniedException('server error. not authorized to call method', -32604); } } -- cgit v1.2.3 From 7c35ac36c1dea2d6f26d8184dcbf1fe5afae59ac Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 21 Mar 2012 13:15:18 +0100 Subject: added RPC_CALL_ADD event. This event enables plugins to register custom method names. --- inc/remote.php | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index b4cc8e6cc..089a5f7d4 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -35,8 +35,6 @@ class RemoteAccessDeniedException extends RemoteException {} * plugin methods are formed like 'plugin..'. * i.e.: plugin.clock.getTime or plugin.clock_gmt.getTime * - * - * * @throws RemoteException */ class RemoteAPI { @@ -52,6 +50,14 @@ class RemoteAPI { */ private $pluginMethods = null; + /** + * @var array contains custom calls to the api. Plugins can use the XML_CALL_REGISTER event. + * The data inside is 'custom.call.something' => array('plugin name', 'remote method name') + * + * The remote method name is the same as in the remote name returned by _getMethods(). + */ + private $pluginCustomCalls = null; + private $dateTransformation; private $fileTransformation; @@ -83,9 +89,34 @@ class RemoteAPI { list($type, $pluginName, $call) = explode('.', $method, 3); if ($type === 'plugin') { return $this->callPlugin($pluginName, $method, $args); - } else { + } + if ($this->coreMethodExist($method)) { return $this->callCoreMethod($method, $args); } + return $this->callCustomCallPlugin($method, $args); + } + + private function coreMethodExist($name) { + $coreMethods = $this->getCoreMethods(); + return array_key_exists($name, $coreMethods); + } + + private function callCustomCallPlugin($method, $args) { + $customCalls = $this->getCustomCallPlugins(); + if (!array_key_exists($method, $customCalls)) { + throw new RemoteException('Method does not exist', -32603); + } + $customCall = $customCalls[$method]; + return $this->callPlugin($customCall[0], $customCall[1], $args); + } + + private function getCustomCallPlugins() { + if ($this->pluginCustomCalls === null) { + $data = array(); + trigger_event('RPC_CALL_ADD', $data); + $this->pluginCustomCalls = $data; + } + return $this->pluginCustomCalls; } private function callPlugin($pluginName, $method, $args) { -- cgit v1.2.3 From 418431a22a4a8f9d62e60e1d8eaa9bcf321377ce Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 21 Mar 2012 13:34:19 +0100 Subject: updated comment --- inc/remote.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index 089a5f7d4..0347bd900 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -19,7 +19,7 @@ class RemoteAccessDeniedException extends RemoteException {} * array( * 'method.remoteName' => array( * 'args' => array( - * 'name' => 'type eg. string|int|...|date|file', + * 'type eg. string|int|...|date|file', * ) * 'name' => 'method name in class', * 'return' => 'type', -- cgit v1.2.3 From b967e5fc8fd93226eba7926c13b73b93878f182b Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Thu, 22 Mar 2012 12:11:31 +0100 Subject: removed requires, changed conf check in xmlrpc.php --- inc/remote.php | 1 - 1 file changed, 1 deletion(-) (limited to 'inc/remote.php') diff --git a/inc/remote.php b/inc/remote.php index 0347bd900..2ef28afd2 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -1,7 +1,6 @@