"MDL-21170, fixed form conflict"
[moodle.git] / webservice / lib.php
CommitLineData
06e7fadc 1<?php
cc93c7da 2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
06e7fadc 18/**
cc93c7da 19 * Web services utility functions and classes
06e7fadc 20 *
06e7fadc 21 * @package webservice
551f4420 22 * @copyright 2009 Moodle Pty Ltd (http://moodle.com)
cc93c7da 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
06e7fadc 24 */
25
cc93c7da 26require_once($CFG->libdir.'/externallib.php');
893d7f0f 27
5593d2dc 28/**
29 * Exception indicating access control problem in web service call
01482a4a 30 * @author Petr Skoda (skodak)
5593d2dc 31 */
32class webservice_access_exception extends moodle_exception {
33 /**
34 * Constructor
35 */
36 function __construct($debuginfo) {
e8b21670 37 parent::__construct('accessexception', 'webservice', '', null, $debuginfo);
5593d2dc 38 }
39}
40
f0dafb3c 41/**
42 * Is protocol enabled?
43 * @param string $protocol name of WS protocol
44 * @return bool
45 */
cc93c7da 46function webservice_protocol_is_enabled($protocol) {
47 global $CFG;
893d7f0f 48
cc93c7da 49 if (empty($CFG->enablewebservices)) {
50 return false;
893d7f0f 51 }
52
cc93c7da 53 $active = explode(',', $CFG->webserviceprotocols);
893d7f0f 54
cc93c7da 55 return(in_array($protocol, $active));
56}
893d7f0f 57
01482a4a 58//=== WS classes ===
893d7f0f 59
f0dafb3c 60/**
3f599588 61 * Mandatory interface for all test client classes.
01482a4a 62 * @author Petr Skoda (skodak)
f0dafb3c 63 */
64interface webservice_test_client_interface {
65 /**
66 * Execute test client WS request
67 * @param string $serverurl
68 * @param string $function
69 * @param array $params
70 * @return mixed
71 */
72 public function simpletest($serverurl, $function, $params);
73}
74
06e7fadc 75/**
3f599588 76 * Mandatory interface for all web service protocol classes
01482a4a 77 * @author Petr Skoda (skodak)
06e7fadc 78 */
01482a4a
PS
79interface webservice_server_interface {
80 /**
81 * Process request from client.
82 * @return void
83 */
84 public function run();
85}
88098133 86
01482a4a
PS
87/**
88 * Abstract web service base class.
89 * @author Petr Skoda (skodak)
90 */
91abstract class webservice_server implements webservice_server_interface {
88098133 92
93 /** @property string $wsname name of the web server plugin */
94 protected $wsname = null;
95
c187722c
PS
96 /** @property string $username name of local user */
97 protected $username = null;
98
99 /** @property string $password password of the local user */
100 protected $password = null;
b107e647 101
88098133 102 /** @property bool $simple true if simple auth used */
103 protected $simple;
104
01482a4a
PS
105 /** @property string $token authentication token*/
106 protected $token = null;
88098133 107
108 /** @property object restricted context */
109 protected $restricted_context;
110
01482a4a
PS
111 /** @property int restrict call to one service id*/
112 protected $restricted_serviceid = null;
113
114 /**
115 * Authenticate user using username+password or token.
116 * This function sets up $USER global.
117 * It is safe to use has_capability() after this.
118 * This method also verifies user is allowed to use this
119 * server.
120 * @return void
121 */
122 protected function authenticate_user() {
123 global $CFG, $DB;
124
125 if (!NO_MOODLE_COOKIES) {
126 throw new coding_exception('Cookies must be disabled in WS servers!');
127 }
128
129 if (!is_enabled_auth('webservice')) {
130 throw new webservice_access_exception('WS auth not enabled');
131 }
132
133 if (!$auth = get_auth_plugin('webservice')) {
134 throw new webservice_access_exception('WS auth missing');
135 }
136
137 // NOTE: the exception details are here for debugging only, it is controlled via the $CFG->degug
138
139 if ($this->simple) {
140 $this->restricted_context = get_context_instance(CONTEXT_SYSTEM);
141
142 if (!$this->username) {
143 throw new webservice_access_exception('Missing username');
144 }
145
146 if (!$this->password) {
147 throw new webservice_access_exception('Missing password');
148 }
149
150 if (!$auth->user_login_webservice($this->username, $this->password)) {
fd8ad938 151 // TODO: MDL-12886 log failed login attempts
01482a4a
PS
152 throw new webservice_access_exception('Wrong username or password');
153 }
154
155 $user = $DB->get_record('user', array('username'=>$this->username, 'mnethostid'=>$CFG->mnet_localhost_id, 'deleted'=>0), '*', MUST_EXIST);
156
157 } else {
158 if (!$token = $DB->get_record('external_tokens', array('token'=>$this->token, 'tokentype'=>EXTERNAL_TOKEN_PERMANENT))) {
fd8ad938 159 // TODO: MDL-12886 log failed login attempts
3785c9e2 160 throw new webservice_access_exception(get_string('invalidtoken', 'webservice'));
01482a4a
PS
161 }
162
4ba8df5c 163 if ($token->validuntil and $token->validuntil < time()) {
3785c9e2 164 throw new webservice_access_exception(get_string('invalidtimedtoken', 'webservice'));
01482a4a
PS
165 }
166
167 if ($token->iprestriction and !address_in_subnet(getremoteaddr(), $token->iprestriction)) {
3785c9e2 168 throw new webservice_access_exception(get_string('invalidiptoken', 'webservice'));
01482a4a
PS
169 }
170
171 $this->restricted_context = get_context_instance_by_id($token->contextid);
4a355d18 172 $this->restricted_serviceid = $token->externalserviceid;
01482a4a
PS
173
174 $user = $DB->get_record('user', array('id'=>$token->userid, 'deleted'=>0), '*', MUST_EXIST);
175
176 // log token access
177 $DB->set_field('external_tokens', 'lastaccess', time(), array('id'=>$token->id));
178 }
179
180 // now fake user login, the session is completely empty too
181 session_set_user($user);
182
183 if (!has_capability("webservice/$this->wsname:use", $this->restricted_context)) {
184 throw new webservice_access_exception('Access to web service not allowed');
185 }
186
187 external_api::set_context_restriction($this->restricted_context);
188 }
189}
190
191/**
192 * Special abstraction of our srvices that allows
193 * interaction with stock Zend ws servers.
194 * @author Petr Skoda (skodak)
195 */
196abstract class webservice_zend_server extends webservice_server {
197
abf7dc44 198 /** @property string name of the zend server class : Zend_XmlRpc_Server, Zend_Soap_Server, Zend_Soap_AutoDiscover, ...*/
01482a4a
PS
199 protected $zend_class;
200
201 /** @property object Zend server instance */
202 protected $zend_server;
203
204 /** @property string $service_class virtual web service class with all functions user name execute, created on the fly */
205 protected $service_class;
206
88098133 207 /**
208 * Contructor
2458e30a 209 * @param bool $simple use simple authentication
88098133 210 */
2458e30a
PS
211 public function __construct($simple, $zend_class) {
212 $this->simple = $simple;
88098133 213 $this->zend_class = $zend_class;
214 }
215
216 /**
217 * Process request from client.
218 * @param bool $simple use simple authentication
219 * @return void
220 */
2458e30a 221 public function run() {
88098133 222 // we will probably need a lot of memory in some functions
223 @raise_memory_limit('128M');
224
225 // set some longer timeout, this script is not sending any output,
226 // this means we need to manually extend the timeout operations
227 // that need longer time to finish
228 external_api::set_timeout();
229
e8b21670 230 // now create the instance of zend server
231 $this->init_zend_server();
232
88098133 233 // set up exception handler first, we want to sent them back in correct format that
234 // the other system understands
235 // we do not need to call the original default handler because this ws handler does everything
236 set_exception_handler(array($this, 'exception_handler'));
237
c187722c
PS
238 // init all properties from the request data
239 $this->parse_request();
240
88098133 241 // this sets up $USER and $SESSION and context restrictions
242 $this->authenticate_user();
243
244 // make a list of all functions user is allowed to excecute
245 $this->init_service_class();
246
2458e30a 247 // tell server what functions are available
88098133 248 $this->zend_server->setClass($this->service_class);
2458e30a
PS
249
250 // execute and return response, this sends some headers too
88098133 251 $response = $this->zend_server->handle();
2458e30a 252
5593d2dc 253/*
b107e647 254 error_log(ob_get_clean());
5593d2dc 255 error_log($response);
256*/
88098133 257 // session cleanup
258 $this->session_cleanup();
259
ca6340bf 260 //finally send the result
261 $this->send_headers();
88098133 262 echo $response;
263 die;
264 }
265
266 /**
267 * Load virtual class needed for Zend api
268 * @return void
269 */
270 protected function init_service_class() {
271 global $USER, $DB;
272
273 // first ofall get a complete list of services user is allowed to access
88098133 274
01482a4a
PS
275 if ($this->restricted_serviceid) {
276 $params = array('sid1'=>$this->restricted_serviceid, 'sid2'=>$this->restricted_serviceid);
277 $wscond1 = 'AND s.id = :sid1';
278 $wscond2 = 'AND s.id = :sid2';
279 } else {
280 $params = array();
281 $wscond1 = '';
282 $wscond2 = '';
283 }
88098133 284
01482a4a
PS
285 // now make sure the function is listed in at least one service user is allowed to use
286 // allow access only if:
287 // 1/ entry in the external_services_users table if required
288 // 2/ validuntil not reached
289 // 3/ has capability if specified in service desc
290 // 4/ iprestriction
88098133 291
01482a4a
PS
292 $sql = "SELECT s.*, NULL AS iprestriction
293 FROM {external_services} s
294 JOIN {external_services_functions} sf ON (sf.externalserviceid = s.id AND s.restrictedusers = 0)
295 WHERE s.enabled = 1 $wscond1
88098133 296
01482a4a
PS
297 UNION
298
299 SELECT s.*, su.iprestriction
300 FROM {external_services} s
301 JOIN {external_services_functions} sf ON (sf.externalserviceid = s.id AND s.restrictedusers = 1)
302 JOIN {external_services_users} su ON (su.externalserviceid = s.id AND su.userid = :userid)
303 WHERE s.enabled = 1 AND su.validuntil IS NULL OR su.validuntil < :now $wscond2";
304
305 $params = array_merge($params, array('userid'=>$USER->id, 'now'=>time()));
88098133 306
307 $serviceids = array();
308 $rs = $DB->get_recordset_sql($sql, $params);
309
310 // now make sure user may access at least one service
311 $remoteaddr = getremoteaddr();
312 $allowed = false;
313 foreach ($rs as $service) {
314 if (isset($serviceids[$service->id])) {
315 continue;
316 }
317 if ($service->requiredcapability and !has_capability($service->requiredcapability, $this->restricted_context)) {
318 continue; // cap required, sorry
319 }
320 if ($service->iprestriction and !address_in_subnet($remoteaddr, $service->iprestriction)) {
321 continue; // wrong request source ip, sorry
322 }
323 $serviceids[$service->id] = $service->id;
324 }
325 $rs->close();
326
327 // now get the list of all functions
328 if ($serviceids) {
329 list($serviceids, $params) = $DB->get_in_or_equal($serviceids);
330 $sql = "SELECT f.*
331 FROM {external_functions} f
332 WHERE f.name IN (SELECT sf.functionname
333 FROM {external_services_functions} sf
334 WHERE sf.externalserviceid $serviceids)";
335 $functions = $DB->get_records_sql($sql, $params);
336 } else {
337 $functions = array();
338 }
339
340 // now make the virtual WS class with all the fuctions for this particular user
341 $methods = '';
342 foreach ($functions as $function) {
343 $methods .= $this->get_virtual_method_code($function);
344 }
345
5593d2dc 346 // let's use unique class name, there might be problem in unit tests
88098133 347 $classname = 'webservices_virtual_class_000000';
348 while(class_exists($classname)) {
349 $classname++;
350 }
351
352 $code = '
353/**
354 * Virtual class web services for user id '.$USER->id.' in context '.$this->restricted_context->id.'.
355 */
356class '.$classname.' {
357'.$methods.'
358}
359';
f0dafb3c 360
88098133 361 // load the virtual class definition into memory
362 eval($code);
88098133 363 $this->service_class = $classname;
364 }
365
366 /**
367 * returns virtual method code
368 * @param object $function
369 * @return string PHP code
370 */
371 protected function get_virtual_method_code($function) {
372 global $CFG;
373
5593d2dc 374 $function = external_function_info($function);
88098133 375
376 $params = array();
377 $params_desc = array();
453a7a85 378 foreach ($function->parameters_desc->keys as $name=>$keydesc) {
88098133 379 $params[] = '$'.$name;
453a7a85 380 $type = 'string';
381 if ($keydesc instanceof external_value) {
382 switch($keydesc->type) {
383 case PARAM_BOOL: // 0 or 1 only for now
384 case PARAM_INT:
385 $type = 'int'; break;
386 case PARAM_FLOAT;
387 $type = 'double'; break;
388 default:
389 $type = 'string';
390 }
391 } else if ($keydesc instanceof external_single_structure) {
392 $type = 'struct';
393 } else if ($keydesc instanceof external_multiple_structure) {
394 $type = 'array';
395 }
396 $params_desc[] = ' * @param '.$type.' $'.$name.' '.$keydesc->desc;
88098133 397 }
398 $params = implode(', ', $params);
399 $params_desc = implode("\n", $params_desc);
400
453a7a85 401 if (is_null($function->returns_desc)) {
402 $return = ' * @return void';
403 } else {
404 $type = 'string';
405 if ($function->returns_desc instanceof external_value) {
406 switch($function->returns_desc->type) {
407 case PARAM_BOOL: // 0 or 1 only for now
408 case PARAM_INT:
409 $type = 'int'; break;
410 case PARAM_FLOAT;
411 $type = 'double'; break;
412 default:
413 $type = 'string';
414 }
415 } else if ($function->returns_desc instanceof external_single_structure) {
416 $type = 'struct';
417 } else if ($function->returns_desc instanceof external_multiple_structure) {
418 $type = 'array';
419 }
420 $return = ' * @return '.$type.' '.$function->returns_desc->desc;
421 }
d4e764ab 422
01482a4a 423 // now crate the virtual method that calls the ext implementation
88098133 424
425 $code = '
426 /**
5593d2dc 427 * '.$function->description.'
428 *
88098133 429'.$params_desc.'
453a7a85 430'.$return.'
88098133 431 */
432 public function '.$function->name.'('.$params.') {
433 return '.$function->classname.'::'.$function->methodname.'('.$params.');
434 }
435';
436 return $code;
437 }
438
439 /**
b107e647 440 * Set up zend service class
88098133 441 * @return void
442 */
443 protected function init_zend_server() {
88098133 444 $this->zend_server = new $this->zend_class();
88098133 445 }
446
c187722c
PS
447 /**
448 * This method parses the $_REQUEST superglobal and looks for
449 * the following information:
450 * 1/ user authentication - username+password or token (wsusername, wspassword and wstoken parameters)
451 *
452 * @return void
453 */
454 protected function parse_request() {
455 if ($this->simple) {
01482a4a 456 //note: some clients have problems with entity encoding :-(
c187722c
PS
457 if (isset($_REQUEST['wsusername'])) {
458 $this->username = $_REQUEST['wsusername'];
c187722c
PS
459 }
460 if (isset($_REQUEST['wspassword'])) {
461 $this->password = $_REQUEST['wspassword'];
c187722c
PS
462 }
463 } else {
01482a4a
PS
464 if (isset($_REQUEST['wstoken'])) {
465 $this->token = $_REQUEST['wstoken'];
88098133 466 }
88098133 467 }
88098133 468 }
469
ca6340bf 470 /**
471 * Internal implementation - sending of page headers.
472 * @return void
473 */
474 protected function send_headers() {
475 header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
476 header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
477 header('Pragma: no-cache');
478 header('Accept-Ranges: none');
479 }
480
88098133 481 /**
482 * Specialised exception handler, we can not use the standard one because
483 * it can not just print html to output.
484 *
485 * @param exception $ex
486 * @return void does not return
487 */
488 public function exception_handler($ex) {
88098133 489 // detect active db transactions, rollback and log as error
3086dd59 490 abort_all_db_transactions();
88098133 491
88098133 492 // some hacks might need a cleanup hook
493 $this->session_cleanup($ex);
494
ca6340bf 495 // now let the plugin send the exception to client
b107e647 496 $this->send_error($ex);
ca6340bf 497
88098133 498 // not much else we can do now, add some logging later
499 exit(1);
500 }
501
b107e647
PS
502 /**
503 * Send the error information to the WS client
504 * formatted as XML document.
505 * @param exception $ex
506 * @return void
507 */
508 protected function send_error($ex=null) {
509 $this->send_headers();
510 echo $this->zend_server->fault($ex);
511 }
01482a4a 512
88098133 513 /**
514 * Future hook needed for emulated sessions.
515 * @param exception $exception null means normal termination, $exception received when WS call failed
516 * @return void
517 */
518 protected function session_cleanup($exception=null) {
519 if ($this->simple) {
520 // nothing needs to be done, there is no persistent session
521 } else {
522 // close emulated session if used
523 }
524 }
525
cc93c7da 526}
527
886d7556 528/**
cc93c7da 529 * Web Service server base class, this class handles both
530 * simple and token authentication.
531 * @author Petr Skoda (skodak)
886d7556 532 */
01482a4a 533abstract class webservice_base_server extends webservice_server {
88098133 534
cc93c7da 535 /** @property array $parameters the function parameters - the real values submitted in the request */
536 protected $parameters = null;
537
538 /** @property string $functionname the name of the function that is executed */
539 protected $functionname = null;
540
541 /** @property object $function full function description */
542 protected $function = null;
543
544 /** @property mixed $returns function return value */
545 protected $returns = null;
06e7fadc 546
547 /**
cc93c7da 548 * Contructor
2458e30a 549 * @param bool $simple use simple authentication
06e7fadc 550 */
2458e30a
PS
551 public function __construct($simple) {
552 $this->simple = $simple;
06e7fadc 553 }
554
24350e06 555 /**
cc93c7da 556 * This method parses the request input, it needs to get:
557 * 1/ user authentication - username+password or token
558 * 2/ function name
559 * 3/ function parameters
560 *
561 * @return void
24350e06 562 */
cc93c7da 563 abstract protected function parse_request();
24350e06 564
cc93c7da 565 /**
566 * Send the result of function call to the WS client.
567 * @return void
568 */
569 abstract protected function send_response();
24350e06 570
fa0797ec 571 /**
cc93c7da 572 * Send the error information to the WS client.
573 * @param exception $ex
574 * @return void
fa0797ec 575 */
cc93c7da 576 abstract protected function send_error($ex=null);
fa0797ec 577
cc93c7da 578 /**
579 * Process request from client.
cc93c7da 580 * @return void
581 */
2458e30a 582 public function run() {
cc93c7da 583 // we will probably need a lot of memory in some functions
584 @raise_memory_limit('128M');
fa0797ec 585
cc93c7da 586 // set some longer timeout, this script is not sending any output,
587 // this means we need to manually extend the timeout operations
588 // that need longer time to finish
589 external_api::set_timeout();
fa0797ec 590
cc93c7da 591 // set up exception handler first, we want to sent them back in correct format that
592 // the other system understands
593 // we do not need to call the original default handler because this ws handler does everything
594 set_exception_handler(array($this, 'exception_handler'));
06e7fadc 595
cc93c7da 596 // init all properties from the request data
597 $this->parse_request();
06e7fadc 598
cc93c7da 599 // authenticate user, this has to be done after the request parsing
600 // this also sets up $USER and $SESSION
601 $this->authenticate_user();
06e7fadc 602
cc93c7da 603 // find all needed function info and make sure user may actually execute the function
604 $this->load_function_info();
f7631e73 605
cc93c7da 606 // finally, execute the function - any errors are catched by the default exception handler
607 $this->execute();
06e7fadc 608
cc93c7da 609 // send the results back in correct format
610 $this->send_response();
06e7fadc 611
cc93c7da 612 // session cleanup
613 $this->session_cleanup();
06e7fadc 614
cc93c7da 615 die;
f7631e73 616 }
617
cc93c7da 618 /**
619 * Specialised exception handler, we can not use the standard one because
620 * it can not just print html to output.
621 *
622 * @param exception $ex
623 * @return void does not return
624 */
625 public function exception_handler($ex) {
cc93c7da 626 // detect active db transactions, rollback and log as error
3086dd59 627 abort_all_db_transactions();
06e7fadc 628
cc93c7da 629 // some hacks might need a cleanup hook
630 $this->session_cleanup($ex);
06e7fadc 631
ca6340bf 632 // now let the plugin send the exception to client
633 $this->send_error($ex);
634
cc93c7da 635 // not much else we can do now, add some logging later
636 exit(1);
f7631e73 637 }
638
639 /**
cc93c7da 640 * Future hook needed for emulated sessions.
641 * @param exception $exception null means normal termination, $exception received when WS call failed
642 * @return void
f7631e73 643 */
cc93c7da 644 protected function session_cleanup($exception=null) {
645 if ($this->simple) {
646 // nothing needs to be done, there is no persistent session
647 } else {
648 // close emulated session if used
649 }
f7631e73 650 }
651
24350e06 652 /**
cc93c7da 653 * Fetches the function description from database,
654 * verifies user is allowed to use this function and
655 * loads all paremeters and return descriptions.
656 * @return void
24350e06 657 */
cc93c7da 658 protected function load_function_info() {
659 global $DB, $USER, $CFG;
40f024c9 660
cc93c7da 661 if (empty($this->functionname)) {
662 throw new invalid_parameter_exception('Missing function name');
663 }
24350e06 664
cc93c7da 665 // function must exist
5593d2dc 666 $function = external_function_info($this->functionname);
cc93c7da 667
01482a4a
PS
668 if ($this->restricted_serviceid) {
669 $params = array('sid1'=>$this->restricted_serviceid, 'sid2'=>$this->restricted_serviceid);
670 $wscond1 = 'AND s.id = :sid1';
671 $wscond2 = 'AND s.id = :sid2';
672 } else {
673 $params = array();
674 $wscond1 = '';
675 $wscond2 = '';
676 }
677
cc93c7da 678 // now let's verify access control
b8c5309e 679
680 // now make sure the function is listed in at least one service user is allowed to use
681 // allow access only if:
682 // 1/ entry in the external_services_users table if required
683 // 2/ validuntil not reached
684 // 3/ has capability if specified in service desc
685 // 4/ iprestriction
686
687 $sql = "SELECT s.*, NULL AS iprestriction
688 FROM {external_services} s
689 JOIN {external_services_functions} sf ON (sf.externalserviceid = s.id AND s.restrictedusers = 0 AND sf.functionname = :name1)
690 WHERE s.enabled = 1 $wscond1
691
692 UNION
693
694 SELECT s.*, su.iprestriction
695 FROM {external_services} s
696 JOIN {external_services_functions} sf ON (sf.externalserviceid = s.id AND s.restrictedusers = 1 AND sf.functionname = :name2)
697 JOIN {external_services_users} su ON (su.externalserviceid = s.id AND su.userid = :userid)
698 WHERE s.enabled = 1 AND su.validuntil IS NULL OR su.validuntil < :now $wscond2";
699 $params = array_merge($params, array('userid'=>$USER->id, 'name1'=>$function->name, 'name2'=>$function->name, 'now'=>time()));
88098133 700
701 $rs = $DB->get_recordset_sql($sql, $params);
702 // now make sure user may access at least one service
703 $remoteaddr = getremoteaddr();
704 $allowed = false;
705 foreach ($rs as $service) {
706 if ($service->requiredcapability and !has_capability($service->requiredcapability, $this->restricted_context)) {
707 continue; // cap required, sorry
cc93c7da 708 }
88098133 709 if ($service->iprestriction and !address_in_subnet($remoteaddr, $service->iprestriction)) {
710 continue; // wrong request source ip, sorry
cc93c7da 711 }
88098133 712 $allowed = true;
713 break; // one service is enough, no need to continue
714 }
715 $rs->close();
716 if (!$allowed) {
c91cc5ef 717 throw new webservice_access_exception('Access to external function not allowed');
cc93c7da 718 }
9baf6825 719
cc93c7da 720 // we have all we need now
721 $this->function = $function;
722 }
723
724 /**
725 * Execute previously loaded function using parameters parsed from the request data.
726 * @return void
727 */
728 protected function execute() {
729 // validate params, this also sorts the params properly, we need the correct order in the next part
730 $params = call_user_func(array($this->function->classname, 'validate_parameters'), $this->function->parameters_desc, $this->parameters);
9baf6825 731
cc93c7da 732 // execute - yay!
733 $this->returns = call_user_func_array(array($this->function->classname, $this->function->methodname), array_values($params));
9baf6825 734 }
735}
736
737