/usr/share/php/Horde/Dav/Client.php is in php-horde-dav 1.0.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | <?php
/**
* Copyright 2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (BSD). If you
* did not receive this file, see http://www.horde.org/licenses/bsd.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/bsd BSD
* @package Dav
*/
/**
* A wrapper around Sabre\DAV\Client that uses Horde's HTTP library.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/bsd BSD
* @package Dav
*/
class Horde_Dav_Client extends Sabre\DAV\Client
{
/**
* A HTTP client.
*
* @var Horde_Http_Client
*/
protected $_http;
/**
* Constructor
*
* Settings are provided through the 'settings' argument. The following
* settings are supported:
*
* * client
* * baseUri
* * userName (optional)
* * password (optional)
* * proxy (optional)
*
* @param array $settings
*/
public function __construct(array $settings)
{
if (!isset($settings['client'])) {
throw new InvalidArgumentException('A client must be provided');
}
$this->_http = $settings['client'];
$this->propertyMap['{DAV:}current-user-privilege-set'] = 'Sabre\\DAVACL\\Property\\CurrentUserPrivilegeSet';
parent::__construct($settings);
}
/**
* Performs an actual HTTP request, and returns the result.
*
* If the specified url is relative, it will be expanded based on the base
* url.
*
* The returned array contains 3 keys:
* * body - the response body
* * httpCode - a HTTP code (200, 404, etc)
* * headers - a list of response http headers. The header names have
* been lowercased.
*
* @param string $method
* @param string $url
* @param string $body
* @param array $headers
*
* @return array
* @throws Horde_Dav_Exception
*/
public function request($method, $url = '', $body = null, $headers = array())
{
$url = $this->getAbsoluteUrl($url);
$this->_http->{'request.redirects'} = 5;
$this->_http->{'request.verifyPeer'} = $this->verifyPeer;
if ($this->proxy) {
$this->_http->{'request.proxyServer'} = $this->proxy;
}
if ($this->userName && $this->authType) {
if ($this->authType & self::AUTH_BASIC) {
$this->_http->{'request.authenticationScheme'} = Horde_Http::AUTH_BASIC;
}
if ($this->authType & self::AUTH_DIGEST) {
$this->_http->{'request.authenticationScheme'} = Horde_Http::AUTH_DIGEST;
}
$this->_http->{'request.username'} = $this->userName;
$this->_http->{'request.password'} = $this->password;
}
// Not supported by Horde_Http_Client yet:
// $this->trustedCertificates;
if ($method == 'HEAD') {
$body = null;
}
try {
$result = $this->_http->request($method, $url, $body, $headers);
} catch (Horde_Http_Exception $e) {
throw new Horde_Dav_Exception($e);
}
if (isset($result->headers['dav']) &&
is_array($result->headers['dav'])) {
$result->headers['dav'] = implode(', ', $result->headers['dav']);
}
$response = array(
'body' => $result->getBody(),
'statusCode' => $result->code,
'headers' => $result->headers,
'url' => $result->uri,
);
if ($response['statusCode'] >= 400) {
switch ($response['statusCode']) {
case 400:
throw new Horde_Dav_Exception('Bad request', $response['statusCode']);
case 401:
throw new Horde_Dav_Exception('Not authenticated', $response['statusCode']);
case 402:
throw new Horde_Dav_Exception('Payment required', $response['statusCode']);
case 403:
throw new Horde_Dav_Exception('Forbidden', $response['statusCode']);
case 404:
throw new Horde_Dav_Exception('Resource not found.', $response['statusCode']);
case 405:
throw new Horde_Dav_Exception('Method not allowed', $response['statusCode']);
case 409:
throw new Horde_Dav_Exception('Conflict', $response['statusCode']);
case 412:
throw new Horde_Dav_Exception('Precondition failed', $response['statusCode']);
case 416:
throw new Horde_Dav_Exception('Requested Range Not Satisfiable', $response['statusCode']);
case 500:
throw new Horde_Dav_Exception('Internal server error', $response['statusCode']);
case 501:
throw new Horde_Dav_Exception('Not Implemented', $response['statusCode']);
case 507:
throw new Horde_Dav_Exception('Insufficient storage', $response['statusCode']);
default:
throw new Horde_Dav_Exception('HTTP error response. (errorcode ' . $response['statusCode'] . ')', $response['statusCode']);
}
}
return $response;
}
}
|