summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-10-21 09:02:31 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2014-10-21 09:02:31 (GMT)
commit9742abf6c84fad608c40b9be6d2a9bfa00364687 (patch)
tree91d70b70d520d4be54811bcc4343ea13a4b8ba7c
parente86778c8b65f7d61a437e2d17f41bc031c63b58c (diff)
downloadiRony-9742abf6c84fad608c40b9be6d2a9bfa00364687.tar.gz
Support Chwala API with multi-folder capabilities (#3809)
-rw-r--r--lib/Kolab/DAV/Backend.php57
-rw-r--r--lib/Kolab/DAV/Collection.php1
-rw-r--r--lib/Kolab/DAV/Locks/Chwala.php8
-rw-r--r--lib/Kolab/DAV/Node.php14
4 files changed, 28 insertions, 52 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/Locks/Chwala.php b/lib/Kolab/DAV/Locks/Chwala.php
index f5eb8d8..d85ad3a 100644
--- a/lib/Kolab/DAV/Locks/Chwala.php
+++ b/lib/Kolab/DAV/Locks/Chwala.php
@@ -45,7 +45,7 @@ class Chwala extends AbstractBackend
/**
* The file API backend class
*
- * @var file_api_storage
+ * @var Kolab\DAV\Backend
*/
protected $backend;
@@ -57,7 +57,7 @@ class Chwala extends AbstractBackend
*/
public function __construct($path = null)
{
- $this->backend = Backend::get_instance()->get_backend();
+ $this->backend = Backend::get_instance();
$this->basePath = $path;
}
@@ -106,7 +106,7 @@ class Chwala extends AbstractBackend
console(__METHOD__, $uri, $lockInfo);
try {
- $this->backend->lock($this->uri2path($uri), $this->from_lockinfo($lockInfo));
+ $this->backend->lock_create($this->uri2path($uri), $this->from_lockinfo($lockInfo));
}
catch (Exception $e) {
return false;
@@ -127,7 +127,7 @@ class Chwala extends AbstractBackend
console(__METHOD__, $uri, $lockInfo);
try {
- $this->backend->unlock($this->uri2path($uri), $this->from_lockinfo($lockInfo));
+ $this->backend->lock_delete($this->uri2path($uri), $this->from_lockinfo($lockInfo));
}
catch (Exception $e) {
return false;
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;