You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

87 lines
2.6 KiB

  1. <?php
  2. namespace dokuwiki\Remote\IXR;
  3. use dokuwiki\HTTP\HTTPClient;
  4. use IXR\Message\Message;
  5. use IXR\Request\Request;
  6. /**
  7. * This implements a XML-RPC client using our own HTTPClient
  8. *
  9. * Note: this now inherits from the IXR library's client and no longer from HTTPClient. Instead composition
  10. * is used to add the HTTP client.
  11. */
  12. class Client extends \IXR\Client\Client
  13. {
  14. /** @var HTTPClient */
  15. protected $httpClient;
  16. /** @var string */
  17. protected $posturl = '';
  18. /** @inheritdoc */
  19. public function __construct($server, $path = false, $port = 80, $timeout = 15, $timeout_io = null)
  20. {
  21. parent::__construct($server, $path, $port, $timeout, $timeout_io);
  22. if (!$path) {
  23. // Assume we have been given an URL instead
  24. $this->posturl = $server;
  25. } else {
  26. $this->posturl = 'http://' . $server . ':' . $port . $path;
  27. }
  28. $this->httpClient = new HTTPClient();
  29. $this->httpClient->timeout = $timeout;
  30. }
  31. /** @inheritdoc */
  32. public function query(...$args)
  33. {
  34. $method = array_shift($args);
  35. $request = new Request($method, $args);
  36. $length = $request->getLength();
  37. $xml = $request->getXml();
  38. $this->headers['Content-Type'] = 'text/xml';
  39. $this->headers['Content-Length'] = $length;
  40. $this->httpClient->headers = array_merge($this->httpClient->headers, $this->headers);
  41. if (!$this->httpClient->sendRequest($this->posturl, $xml, 'POST')) {
  42. $this->handleError(-32300, 'transport error - ' . $this->httpClient->error);
  43. return false;
  44. }
  45. // Check HTTP Response code
  46. if ($this->httpClient->status < 200 || $this->httpClient->status > 206) {
  47. $this->handleError(-32300, 'transport error - HTTP status ' . $this->httpClient->status);
  48. return false;
  49. }
  50. // Now parse what we've got back
  51. $this->message = new Message($this->httpClient->resp_body);
  52. if (!$this->message->parse()) {
  53. // XML error
  54. return $this->handleError(-32700, 'Parse error. Message not well formed');
  55. }
  56. // Is the message a fault?
  57. if ($this->message->messageType == 'fault') {
  58. return $this->handleError($this->message->faultCode, $this->message->faultString);
  59. }
  60. // Message must be OK
  61. return true;
  62. }
  63. /**
  64. * Direct access to the underlying HTTP client if needed
  65. *
  66. * @return HTTPClient
  67. */
  68. public function getHTTPClient()
  69. {
  70. return $this->httpClient;
  71. }
  72. }