From dc3f5ffa12c35832ac3457f60643e3f43415513c Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Mon, 26 Oct 2009 19:30:12 +0000 Subject: [PATCH] MDL-12886 untested amf server --- lang/en_utf8/webservice_amf.php | 1 - webservice/amf/db/access.php | 12 ++++ webservice/amf/lib.php | 87 ----------------------------- webservice/amf/locallib.php | 53 ++++++++++++++++++ webservice/amf/server.php | 53 +++++++++--------- webservice/amf/simpleserver.php | 46 +++++++++++++++ webservice/amf/testclient/index.php | 1 + webservice/amf/version.php | 3 + webservice/testclient.php | 5 ++ 9 files changed, 146 insertions(+), 115 deletions(-) create mode 100644 webservice/amf/db/access.php delete mode 100644 webservice/amf/lib.php create mode 100644 webservice/amf/locallib.php create mode 100644 webservice/amf/simpleserver.php create mode 100644 webservice/amf/version.php diff --git a/lang/en_utf8/webservice_amf.php b/lang/en_utf8/webservice_amf.php index f51fe76cb8..e3cf1d66d7 100644 --- a/lang/en_utf8/webservice_amf.php +++ b/lang/en_utf8/webservice_amf.php @@ -1,4 +1,3 @@ array( + 'captype' => 'read', // in fact this may be considered read and write at the same time + 'contextlevel' => CONTEXT_COURSE, // the context level should be probably CONTEXT_MODULE + 'legacy' => array( + ), + ), + +); diff --git a/webservice/amf/lib.php b/webservice/amf/lib.php deleted file mode 100644 index 4e5fb0da4a..0000000000 --- a/webservice/amf/lib.php +++ /dev/null @@ -1,87 +0,0 @@ -dirroot.'/webservice/lib.php'); - -/* - * AMF server class - */ -final class amf_server extends webservice_server { - - - public function __construct() { - //set web service proctol name - $this->set_protocolname("Amf"); - $this->set_protocolid("amf"); - } - - /** - * Run the AMF server - */ - public function run() { - $enable = $this->get_enable(); - if (empty($enable)) { - die; - } - include "Zend/Loader.php"; - Zend_Loader::registerAutoload(); - - //retrieve the api name - $classpath = optional_param('classpath','user',PARAM_ALPHA); - require_once(dirname(__FILE__) . '/../../'.$classpath.'/external.php'); - - /// run the Zend AMF server - $server = new Zend_Amf_Server(); - $debugmode = get_config($this->get_protocolid(),'debug'); - if (!empty($debugmode)) { - $server->setProduction(false); - } else { - $server->setProduction(true); - } - $server->setClass($classpath."_external"); - $response = $server->handle(); - echo $response; - } - - /** - * Names of the server settings - * @return array - */ - public static function get_setting_names() { - return array('debug'); - } - - public function settings_form(&$mform) { - $debug = get_config($this->get_protocolid(), 'debug'); - $debug = true; - if (empty($debug)) { - $debug = false; - } - $mform->addElement('checkbox', 'debug', get_string('amfdebug', 'webservice')); - } -} - -?> diff --git a/webservice/amf/locallib.php b/webservice/amf/locallib.php new file mode 100644 index 0000000000..1a86ca65bb --- /dev/null +++ b/webservice/amf/locallib.php @@ -0,0 +1,53 @@ +. + +/** + * AMF web service implementation classes and methods. + * + * @package webservice + * @copyright 2009 Moodle Pty Ltd (http://moodle.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once("$CFG->dirroot/webservice/lib.php"); + +/** + * AMF service server implementation. + * @author Petr Skoda (skodak) + */ +class webservice_amf_server extends webservice_zend_server { + /** + * Contructor + * @param bool $simple use simple authentication + */ + public function __construct($simple) { + require_once 'Zend/Amf/Server.php'; + parent::__construct($simple, 'Zend_Amf_Server'); + $this->wsname = 'amf'; + } + + /** + * Set up zend service class + * @return void + */ + protected function init_zend_server() { + parent::init_zend_server(); + // TODO: add some exception handling + } +} + +// TODO: implement AMF test client somehow, maybe we could use moodle form to feed the data to the flash app somehow diff --git a/webservice/amf/server.php b/webservice/amf/server.php index eeb9cf9f97..e25f11e767 100644 --- a/webservice/amf/server.php +++ b/webservice/amf/server.php @@ -1,39 +1,38 @@ . + /** - * Moodle - Modular Object-Oriented Dynamic Learning Environment - * http://moodle.com - * - * LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details: + * AMF web service entry point. The authentication is done via tokens. * - * http://www.gnu.org/copyleft/gpl.html - * - * @category Moodle * @package webservice - * @copyright Copyright (c) 1999 onwards Martin Dougiamas http://dougiamas.com - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL License + * @copyright 2009 Moodle Pty Ltd (http://moodle.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -/** - * Moodle AMF server - */ -require_once(dirname(__FILE__) . '/../../config.php'); -require_once('lib.php'); +define('NO_MOODLE_COOKIES', true); + +require('../../config.php'); +require_once("$CFG->dirroot/webservice/amf/locallib.php"); -if (empty($CFG->enablewebservices)) { +if (!webservice_protocol_is_enabled('amf')) { die; } -$server = new amf_server(); +$server = new webservice_amf_server(true); $server->run(); +die; -?> \ No newline at end of file diff --git a/webservice/amf/simpleserver.php b/webservice/amf/simpleserver.php new file mode 100644 index 0000000000..2e89df7feb --- /dev/null +++ b/webservice/amf/simpleserver.php @@ -0,0 +1,46 @@ +. + +/** + * AMF web service entry point. The authentication is done via tokens. + * + * @package webservice + * @copyright 2009 Moodle Pty Ltd (http://moodle.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +define('NO_MOODLE_COOKIES', true); + +require('../../config.php'); +require_once("$CFG->dirroot/webservice/amf/locallib.php"); + +//ob_start(); + +//TODO: for now disable all mess in xml +ini_set('display_errors', '0'); +ini_set('log_errors', '1'); +$CFG->debugdisplay = false; + +if (!webservice_protocol_is_enabled('amf')) { + die; +} + +$server = new webservice_amf_server(true); +$server->run(); +die; + + diff --git a/webservice/amf/testclient/index.php b/webservice/amf/testclient/index.php index c14d0fdd9a..6097e64904 100644 --- a/webservice/amf/testclient/index.php +++ b/webservice/amf/testclient/index.php @@ -1,6 +1,7 @@ wwwroot.'/webservice/amf/testclient/moodleclient.swf'; $args['width'] = '100%'; diff --git a/webservice/amf/version.php b/webservice/amf/version.php new file mode 100644 index 0000000000..f15e31b9c5 --- /dev/null +++ b/webservice/amf/version.php @@ -0,0 +1,3 @@ +version = 2009101900; diff --git a/webservice/testclient.php b/webservice/testclient.php index 6035ce43ee..22126378ab 100644 --- a/webservice/testclient.php +++ b/webservice/testclient.php @@ -52,6 +52,11 @@ foreach ($active_protocols as $p) { if (empty($available_protocols[$p])) { continue; } + include_once($available_protocols[$p].'/locallib.php'); + if (!class_exists('webservice_'.$p.'_test_client')) { + // test client support not implemented + continue; + } $protocols[$p] = get_string('pluginname', 'webservice_'.$p); } if (!isset($protocols[$protocol])) { // whitelisting security -- 2.39.5