diff options
author | Aleksander Machniak <machniak@kolabsys.com> | 2014-10-21 09:08:00 (GMT) |
---|---|---|
committer | Aleksander Machniak <machniak@kolabsys.com> | 2014-10-21 09:08:00 (GMT) |
commit | 2446e622016b425d7a05332452199b2c5854d01f (patch) | |
tree | 7cb33a010fda0d590aba37bd0c740b7166130052 /lib | |
parent | 46a1580a7b7f71b65c008a428ae8d3d7ef9560ae (diff) | |
download | iRony-2446e622016b425d7a05332452199b2c5854d01f.tar.gz |
Support Chwala API with multi-folder capabilities (#3809)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kolab/DAV/Backend.php | 57 | ||||
-rw-r--r-- | lib/Kolab/DAV/Collection.php | 1 | ||||
-rw-r--r-- | lib/Kolab/DAV/Node.php | 14 |
3 files changed, 24 insertions, 48 deletions
diff --git a/lib/Kolab/DAV/Backend.php b/lib/Kolab/DAV/Backend.php index 816d8e1..555ee56 100644 --- a/lib/Kolab/DAV/Backend.php +++ b/lib/Kolab/DAV/Backend.php @@ -23,19 +23,12 @@ namespace Kolab\DAV; -use \rcube; +use Kolab\DAV\Auth\HTTPBasic; -class Backend +class Backend extends \file_api_lib { + protected $configured = false; protected static $instance; - protected $api; - protected $conf; - protected $app_name = 'Kolab File API'; - protected $config = array( - 'date_format' => 'Y-m-d H:i', - 'language' => 'en_US', - ); - /** * This implements the 'singleton' design pattern @@ -46,7 +39,6 @@ class Backend { if (!self::$instance) { self::$instance = new Backend(); - self::$instance->init(); } return self::$instance; @@ -57,42 +49,29 @@ class Backend */ protected function __construct() { - $rcube = rcube::get_instance(); - $this->conf = $rcube->config; - } - - /** - * Returns file API backend - */ - public function get_backend() - { - return $this->api; } /** - * Initialise backend class + * Configure main (authentication) driver */ protected function init() { - $driver = $this->conf->get('fileapi_backend', 'kolab'); - $class = $driver . '_file_storage'; + // We currently support only one auth driver which is Kolab driver. + // Because of that we don't need to authenticate in Kolab again, + // we need only to configure it to use current username/password. + // This is required if we want to use external storage drivers. - $this->api = new $class; - $this->api->configure($this->config); - } + if (!$this->configured && !empty(HTTPBasic::$current_user)) { + // configure authentication driver + $config = array( + 'username' => HTTPBasic::$current_user, + 'password' => HTTPBasic::$current_pass, + ); - /* - * Returns API capabilities - */ - protected function capabilities() - { - foreach ($this->api->capabilities() as $name => $value) { - // skip disabled capabilities - if ($value !== false) { - $caps[$name] = $value; - } - } + $backend = $this->get_backend(); + $backend->configure($config, ''); - return $caps; + $this->configured = true; + } } } diff --git a/lib/Kolab/DAV/Collection.php b/lib/Kolab/DAV/Collection.php index d8d39b7..b148ece 100644 --- a/lib/Kolab/DAV/Collection.php +++ b/lib/Kolab/DAV/Collection.php @@ -48,6 +48,7 @@ class Collection extends \Kolab\DAV\Node implements \Sabre\DAV\ICollection try { // @TODO: This should be cached too (out of this class) $folders = $this->backend->folder_list(); + $folders = $folders['list']; } catch (Exception $e) { } diff --git a/lib/Kolab/DAV/Node.php b/lib/Kolab/DAV/Node.php index b8d3542..beba2a9 100644 --- a/lib/Kolab/DAV/Node.php +++ b/lib/Kolab/DAV/Node.php @@ -42,7 +42,7 @@ class Node implements \Sabre\DAV\INode /** * The file API backend class * - * @var file_api_storage + * @var Kolab\DAV\Backend */ protected $backend; @@ -74,7 +74,7 @@ class Node implements \Sabre\DAV\INode $this->data = $data; $this->path = $path; $this->parent = $parent; - $this->backend = Backend::get_instance()->get_backend(); + $this->backend = Backend::get_instance(); if ($this->path == Collection::ROOT_DIRECTORY) { $this->path = ''; @@ -172,6 +172,8 @@ class Node implements \Sabre\DAV\INode // $data can be a resource or a string if (is_resource($data)) { + rewind($data); + // $data can be php://input or php://temp // php://input is not seekable, we need to "convert" // it to seekable resource, fstat/rewind later will work @@ -182,17 +184,11 @@ class Node implements \Sabre\DAV\INode rewind($new_data); $data = $new_data; } - - $content = stream_get_contents($data, 1024000, 0); - rewind($data); - } - else { - $content = &$data; } $filedata = array( 'content' => $data, - 'type' => rcube_mime::file_content_type($content, $name, $type, true), + 'type' => $type, ); return $filedata; |