davclient.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Vincent Petry
  6. * @copyright 2013 Vincent Petry <pvince81@owncloud.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * This class extends the SabreDAV client with additional functionality
  24. * like request timeout.
  25. */
  26. class OC_DAVClient extends \Sabre\DAV\Client {
  27. protected $requestTimeout;
  28. protected $verifyHost;
  29. /**
  30. * Sets the request timeout or 0 to disable timeout.
  31. * @param integer $timeout in seconds or 0 to disable
  32. */
  33. public function setRequestTimeout($timeout) {
  34. $this->requestTimeout = (int)$timeout;
  35. }
  36. /**
  37. * Sets the CURLOPT_SSL_VERIFYHOST setting
  38. * @param integer $value value to set CURLOPT_SSL_VERIFYHOST to
  39. */
  40. public function setVerifyHost($value) {
  41. $this->verifyHost = $value;
  42. }
  43. protected function curlRequest($url, $settings) {
  44. if ($this->requestTimeout > 0) {
  45. $settings[CURLOPT_TIMEOUT] = $this->requestTimeout;
  46. }
  47. if (!is_null($this->verifyHost)) {
  48. $settings[CURLOPT_SSL_VERIFYHOST] = $this->verifyHost;
  49. }
  50. return parent::curlRequest($url, $settings);
  51. }
  52. }