Permalink
Browse files

Create callback-based response stream, gather all DL actions in a sep…

…arate function.
  • Loading branch information...
1 parent c19e2a4 commit 4e7874720428302220baaa90733e5dff9dd1137c @cdujeu cdujeu committed May 9, 2016
@@ -0,0 +1,18 @@
+{
+ "name" : "pydio/core",
+ "autoload": {
+ "psr-4": {
+ "Pydio\\Core\\": "./src/pydio/Core",
+ "Pydio\\Tests\\": "./src/pydio/Tests"
+ }
+ },
+ "require": {
+ "zendframework/zend-diactoros": "~1.0",
+ "guzzlehttp/guzzle": "~5",
+ "guzzlehttp/command": "~0.7",
+ "guzzlehttp/guzzle-services": "~0.5",
+ "gimler/guzzle-description-loader" : "*",
+ "commerceguys/guzzle-oauth2-plugin": "~2.0"
+ }
+
+}
@@ -0,0 +1,242 @@
+<?php
+/*
+ * Copyright 2007-2015 Abstrium <contact (at) pydio.com>
+ * This file is part of Pydio.
+ *
+ * Pydio is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pydio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Pydio. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The latest code can be found at <http://pyd.io/>.
+ */
+namespace Pydio\Core\Http;
+
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\StreamInterface;
+use Zend\Diactoros\Response;
+
+defined('AJXP_EXEC') or die('Access not allowed');
+
+
+class AsyncResponseStream implements StreamInterface
+{
+ /**
+ * @var callable
+ */
+ private $callback;
+
+ /**
+ * @var bool
+ */
+ private $callbackExecuted = false;
+
+ /**
+ * AsyncResponseStream constructor.
+ * @param callable $callable
+ */
+ public function __construct($callable){
+ $this->callback = $callable;
+ }
+
+ /**
+ * Reads all data from the stream into a string, from the beginning to end.
+ *
+ * This method MUST attempt to seek to the beginning of the stream before
+ * reading data and read the stream until the end is reached.
+ *
+ * Warning: This could attempt to load a large amount of data into memory.
+ *
+ * This method MUST NOT raise an exception in order to conform with PHP's
+ * string casting operations.
+ *
+ * @see http://php.net/manual/en/language.oop5.magic.php#object.tostring
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->getContents();
+ }
+
+ /**
+ * Closes the stream and any underlying resources.
+ *
+ * @return void
+ */
+ public function close()
+ {
+ $this->callback = null;
+ $this->callbackExecuted = false;
+ }
+
+ /**
+ * Separates any underlying resources from the stream.
+ *
+ * After the stream has been detached, the stream is in an unusable state.
+ *
+ * @return resource|null Underlying PHP stream, if any
+ */
+ public function detach()
+ {
+ return null;
+ }
+
+ /**
+ * Get the size of the stream if known.
+ *
+ * @return int|null Returns the size in bytes if known, or null if unknown.
+ */
+ public function getSize()
+ {
+ // Return a non-null size if there's a pending callback.
+ return (isSet($this->callback) && !$this->callbackExecuted ? 1 : null);
+ }
+
+ /**
+ * Returns the current position of the file read/write pointer
+ *
+ * @return int Position of the file pointer
+ * @throws \RuntimeException on error.
+ */
+ public function tell()
+ {
+ throw new \RuntimeException();
+ }
+
+ /**
+ * Returns true if the stream is at the end of the stream.
+ *
+ * @return bool
+ */
+ public function eof()
+ {
+ return $this->callbackExecuted;
+ }
+
+ /**
+ * Returns whether or not the stream is seekable.
+ *
+ * @return bool
+ */
+ public function isSeekable()
+ {
+ return false;
+ }
+
+ /**
+ * Seek to a position in the stream.
+ *
+ * @link http://www.php.net/manual/en/function.fseek.php
+ * @param int $offset Stream offset
+ * @param int $whence Specifies how the cursor position will be calculated
+ * based on the seek offset. Valid values are identical to the built-in
+ * PHP $whence values for `fseek()`. SEEK_SET: Set position equal to
+ * offset bytes SEEK_CUR: Set position to current location plus offset
+ * SEEK_END: Set position to end-of-stream plus offset.
+ * @throws \RuntimeException on failure.
+ */
+ public function seek($offset, $whence = SEEK_SET)
+ {
+ throw new \RuntimeException();
+ }
+
+ /**
+ * Seek to the beginning of the stream.
+ *
+ * If the stream is not seekable, this method will raise an exception;
+ * otherwise, it will perform a seek(0).
+ *
+ * @see seek()
+ * @link http://www.php.net/manual/en/function.fseek.php
+ * @throws \RuntimeException on failure.
+ */
+ public function rewind()
+ {
+ throw new \RuntimeException();
+ }
+
+ /**
+ * Returns whether or not the stream is writable.
+ *
+ * @return bool
+ */
+ public function isWritable()
+ {
+ return false;
+ }
+
+ /**
+ * Write data to the stream.
+ *
+ * @param string $string The string that is to be written.
+ * @return int Returns the number of bytes written to the stream.
+ * @throws \RuntimeException on failure.
+ */
+ public function write($string)
+ {
+ throw new \RuntimeException();
+ }
+
+ /**
+ * Returns whether or not the stream is readable.
+ *
+ * @return bool
+ */
+ public function isReadable()
+ {
+ return true;
+ }
+
+ /**
+ * Read data from the stream.
+ *
+ * @param int $length Read up to $length bytes from the object and return
+ * them. Fewer than $length bytes may be returned if underlying stream
+ * call returns fewer bytes.
+ * @return string Returns the data read from the stream, or an empty string
+ * if no bytes are available.
+ * @throws \RuntimeException if an error occurs.
+ */
+ public function read($length)
+ {
+ call_user_func($this->callback);
+ $this->callbackExecuted = true;
+ }
+
+ /**
+ * Returns the remaining contents in a string
+ *
+ * @return string
+ * @throws \RuntimeException if unable to read or an error occurs while
+ * reading.
+ */
+ public function getContents()
+ {
+ $this->read(0);
+ }
+
+ /**
+ * Get stream metadata as an associative array or retrieve a specific key.
+ *
+ * The keys returned are identical to the keys returned from PHP's
+ * stream_get_meta_data() function.
+ *
+ * @link http://php.net/manual/en/function.stream-get-meta-data.php
+ * @param string $key Specific metadata to retrieve.
+ * @return array|mixed|null Returns an associative array if no key is
+ * provided. Returns a specific key value if a key is provided and the
+ * value is found, or null if the key is not found.
+ */
+ public function getMetadata($key = null)
+ {
+ return [];
+ }
+}
@@ -0,0 +1,69 @@
+<?php
+/*
+ * Copyright 2007-2015 Abstrium <contact (at) pydio.com>
+ * This file is part of Pydio.
+ *
+ * Pydio is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pydio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Pydio. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The latest code can be found at <http://pyd.io/>.
+ */
+namespace Pydio\Core\Services;
+
+use Psr\Http\Message\ServerRequestInterface;
+
+defined('AJXP_EXEC') or die('Access not allowed');
+
+define('PYDIO_SESSION_NAME', 'AjaXplorer');
+define('PYDIO_SESSION_QUERY_PARAM', 'ajxp_sessid');
+
+class SessionService
+{
+ private static $sessionName = PYDIO_SESSION_NAME;
+
+ public static function setSessionName($sessionName){
+ self::$sessionName = $sessionName;
+ }
+
+ public static function getSessionName(){
+ return self::$sessionName;
+ }
+
+ public static function start(ServerRequestInterface &$request){
+
+ $getParams = $request->getQueryParams();
+ if (isSet($getParams[PYDIO_SESSION_QUERY_PARAM])) {
+ $cookies = $request->getCookieParams();
+ if (!isSet($cookies[self::$sessionName])) {
+ $cookies[self::$sessionName] = $getParams[PYDIO_SESSION_QUERY_PARAM];
+ $request = $request->withCookieParams($cookies);
+ }
+ }
+
+ if(defined("AJXP_SESSION_HANDLER_PATH") && defined("AJXP_SESSION_HANDLER_CLASSNAME") && file_exists(AJXP_SESSION_HANDLER_PATH)){
+ require_once(AJXP_SESSION_HANDLER_PATH);
+ if(class_exists(AJXP_SESSION_HANDLER_CLASSNAME, false)){
+ $sessionHandlerClass = AJXP_SESSION_HANDLER_CLASSNAME;
+ $sessionHandler = new $sessionHandlerClass();
+ session_set_save_handler($sessionHandler, false);
+ }
+ }
+ session_name(self::$sessionName);
+ session_start();
+
+ }
+
+ public static function close(){
+ session_write_close();
+ }
+}
@@ -22,6 +22,8 @@
namespace Pydio\Access\Driver\DataProvider;
use DOMXPath;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
use Pydio\Access\Core\AbstractAccessDriver;
use Pydio\Access\Core\Filter\AJXP_PermissionMask;
use Pydio\Access\Core\Repository;
@@ -334,14 +336,15 @@ public function parseSpecificContributions(&$contribNode)
}
}
- public function preProcessBookmarkAction($action, &$httpVars, $fileVars)
- {
+ public function preProcessBookmarkAction(ServerRequestInterface &$request, ResponseInterface $response){
+ $httpVars = $request->getParsedBody();
if (isSet($httpVars["bm_action"]) && $httpVars["bm_action"] == "add_bookmark" && AuthService::usersEnabled()) {
$bmUser = AuthService::getLoggedUser();
$bookmarks = $bmUser->getBookmarks();
foreach ($bookmarks as $bm) {
if ($bm["PATH"] == $httpVars["bm_path"]) {
$httpVars["bm_action"] = "delete_bookmark";
+ $request = $request->withParsedBody($httpVars);
break;
}
}
Oops, something went wrong.

0 comments on commit 4e78747

Please sign in to comment.