API: ignore charset when checking content types
[dokuwiki.git] / inc / Remote / XmlRpcServer.php
bloba1566b3d208af9ac586c2685309eb7af5d1a4093
1 <?php
3 namespace dokuwiki\Remote;
5 use IXR\DataType\Base64;
6 use IXR\DataType\Date;
7 use IXR\Exception\ServerException;
8 use IXR\Message\Error;
9 use IXR\Server\Server;
11 /**
12 * Contains needed wrapper functions and registers all available XMLRPC functions.
14 class XmlRpcServer extends Server
16 protected $remote;
18 /**
19 * Constructor. Register methods and run Server
21 public function __construct($wait = false)
23 $this->remote = new Api();
24 parent::__construct(false, false, $wait);
27 /** @inheritdoc */
28 public function serve($data = false)
30 global $conf;
31 global $INPUT;
32 if (!$conf['remote']) {
33 throw new ServerException("XML-RPC server not enabled.", -32605);
35 if (!empty($conf['remotecors'])) {
36 header('Access-Control-Allow-Origin: ' . $conf['remotecors']);
38 [$contentType] = explode(';', $INPUT->server->str('CONTENT_TYPE'), 2); // ignore charset
39 $contentType = strtolower($contentType); // mime types are case-insensitive
40 if ($contentType !== 'text/xml' && $contentType !== 'application/xml') {
41 throw new ServerException('XML-RPC server accepts XML requests only.', -32606);
44 parent::serve($data);
47 /**
48 * @inheritdoc
50 protected function call($methodname, $args)
52 try {
53 $result = $this->remote->call($methodname, $args);
54 return $result;
55 } catch (AccessDeniedException $e) {
56 if (!isset($_SERVER['REMOTE_USER'])) {
57 http_status(401);
58 return new Error(-32603, "server error. not authorized to call method $methodname");
59 } else {
60 http_status(403);
61 return new Error(-32604, "server error. forbidden to call the method $methodname");
63 } catch (RemoteException $e) {
64 return new Error($e->getCode(), $e->getMessage());