diff options
Diffstat (limited to 'lib/connector/sabre/client.php')
-rw-r--r-- | lib/connector/sabre/client.php | 83 |
1 files changed, 44 insertions, 39 deletions
diff --git a/lib/connector/sabre/client.php b/lib/connector/sabre/client.php index b799b541a05..7e8f21264f9 100644 --- a/lib/connector/sabre/client.php +++ b/lib/connector/sabre/client.php @@ -23,29 +23,18 @@ class OC_Connector_Sabre_Client extends Sabre_DAV_Client {
- protected $curlSettings;
-
- public function __construct(array $settings) {
- //set default curl settings
- $this->curlSettings = array(
- CURLOPT_RETURNTRANSFER => true,
- // Return headers as part of the response
- CURLOPT_HEADER => true,
- // Automatically follow redirects
- CURLOPT_FOLLOWLOCATION => true,
- CURLOPT_MAXREDIRS => 5,
- CURLOPT_SSL_VERIFYPEER => true,
- //CURLOPT_SSL_VERIFYPEER => false,
- );
- parent::__construct($settings);
- }
-
- public function setCurlSettings($settings) {
- if (is_array($settings)) {
- foreach ($settings as $k => $v) {
- $this->curlSettings[$k] = $v;
- }
- }
+ protected $trustedCertificates;
+
+ /**
+ * Add trusted root certificates to the webdav client.
+ *
+ * The parameter certificates should be a absulute path to a file which contains
+ * all trusted certificates
+ *
+ * @param string $certificates
+ */
+ public function addTrustedCertificates($certificates) {
+ $this->trustedCertificates = $certificates;
}
/**
@@ -68,14 +57,24 @@ class OC_Connector_Sabre_Client extends Sabre_DAV_Client { * @return array
*/
public function request($method, $url = '', $body = null, $headers = array()) {
-
- $this->curlSettings[CURLOPT_POSTFIELDS] = $body;
+
$url = $this->getAbsoluteUrl($url);
+ $curlSettings = array(
+ CURLOPT_RETURNTRANSFER => true,
+ // Return headers as part of the response
+ CURLOPT_HEADER => true,
+ CURLOPT_POSTFIELDS => $body,
+ // Automatically follow redirects
+ CURLOPT_FOLLOWLOCATION => true,
+ CURLOPT_MAXREDIRS => 5,
+ );
+
+ if($this->trustedCertificates) {
+ $curlSettings[CURLOPT_CAINFO] = $this->trustedCertificates;
+ }
+
switch ($method) {
- case 'PUT':
- $this->curlSettings[CURLOPT_PUT] = true;
- break;
case 'HEAD' :
// do not read body with HEAD requests (this is neccessary because cURL does not ignore the body with HEAD
@@ -83,12 +82,12 @@ class OC_Connector_Sabre_Client extends Sabre_DAV_Client { // specs...) cURL does unfortunately return an error in this case ("transfer closed transfer closed with
// ... bytes remaining to read") this can be circumvented by explicitly telling cURL to ignore the
// response body
- $this->curlSettings[CURLOPT_NOBODY] = true;
- $this->curlSettings[CURLOPT_CUSTOMREQUEST] = 'HEAD';
+ $curlSettings[CURLOPT_NOBODY] = true;
+ $curlSettings[CURLOPT_CUSTOMREQUEST] = 'HEAD';
break;
default:
- $this->curlSettings[CURLOPT_CUSTOMREQUEST] = $method;
+ $curlSettings[CURLOPT_CUSTOMREQUEST] = $method;
break;
}
@@ -100,15 +99,22 @@ class OC_Connector_Sabre_Client extends Sabre_DAV_Client { $nHeaders[] = $key . ': ' . $value;
}
- $this->curlSettings[CURLOPT_HTTPHEADER] = $nHeaders;
+ $curlSettings[CURLOPT_HTTPHEADER] = $nHeaders;
if ($this->proxy) {
- $this->curlSettings[CURLOPT_PROXY] = $this->proxy;
+ $curlSettings[CURLOPT_PROXY] = $this->proxy;
}
- if ($this->userName) {
- $this->curlSettings[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC | CURLAUTH_DIGEST;
- $this->curlSettings[CURLOPT_USERPWD] = $this->userName . ':' . $this->password;
+ if ($this->userName && $this->authType) {
+ $curlType = 0;
+ if ($this->authType & self::AUTH_BASIC) {
+ $curlType |= CURLAUTH_BASIC;
+ }
+ if ($this->authType & self::AUTH_DIGEST) {
+ $curlType |= CURLAUTH_DIGEST;
+ }
+ $curlSettings[CURLOPT_HTTPAUTH] = $curlType;
+ $curlSettings[CURLOPT_USERPWD] = $this->userName . ':' . $this->password;
}
list(
@@ -116,7 +122,7 @@ class OC_Connector_Sabre_Client extends Sabre_DAV_Client { $curlInfo,
$curlErrNo,
$curlError
- ) = $this->curlRequest($url, $this->curlSettings);
+ ) = $this->curlRequest($url, $curlSettings);
$headerBlob = substr($response, 0, $curlInfo['header_size']);
$response = substr($response, $curlInfo['header_size']);
@@ -163,6 +169,5 @@ class OC_Connector_Sabre_Client extends Sabre_DAV_Client { return $response;
- }
-
+ }
}
\ No newline at end of file |