diff options
Diffstat (limited to 'apps/files_external/3rdparty/icewind/smb/src/Native')
7 files changed, 0 insertions, 1274 deletions
diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeFileInfo.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeFileInfo.php deleted file mode 100644 index d8be57c7311..00000000000 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeFileInfo.php +++ /dev/null @@ -1,196 +0,0 @@ -<?php -/** - * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Licensed under the MIT license: - * http://opensource.org/licenses/MIT - */ - -namespace Icewind\SMB\Native; - -use Icewind\SMB\ACL; -use Icewind\SMB\IFileInfo; - -class NativeFileInfo implements IFileInfo { - /** - * @var string - */ - protected $path; - - /** - * @var string - */ - protected $name; - - /** - * @var NativeShare - */ - protected $share; - - /** - * @var array|null - */ - protected $attributeCache = null; - - /** - * @param NativeShare $share - * @param string $path - * @param string $name - */ - public function __construct($share, $path, $name) { - $this->share = $share; - $this->path = $path; - $this->name = $name; - } - - /** - * @return string - */ - public function getPath() { - return $this->path; - } - - /** - * @return string - */ - public function getName() { - return $this->name; - } - - /** - * @return array - */ - protected function stat() { - if (is_null($this->attributeCache)) { - $rawAttributes = explode(',', $this->share->getAttribute($this->path, 'system.dos_attr.*')); - $this->attributeCache = []; - foreach ($rawAttributes as $rawAttribute) { - list($name, $value) = explode(':', $rawAttribute); - $name = strtolower($name); - if ($name == 'mode') { - $this->attributeCache[$name] = (int)hexdec(substr($value, 2)); - } else { - $this->attributeCache[$name] = (int)$value; - } - } - } - return $this->attributeCache; - } - - /** - * @return int - */ - public function getSize() { - $stat = $this->stat(); - return $stat['size']; - } - - /** - * @return int - */ - public function getMTime() { - $stat = $this->stat(); - return $stat['change_time']; - } - - /** - * On "mode": - * - * different smbclient versions seem to return different mode values for 'system.dos_attr.mode' - * - * older versions return the dos permissions mask as defined in `IFileInfo::MODE_*` while - * newer versions return the equivalent unix permission mask. - * - * Since the unix mask doesn't contain the proper hidden/archive/system flags we have to assume them - * as false (except for `hidden` where we use the unix dotfile convention) - */ - - /** - * @return int - */ - protected function getMode() { - $mode = $this->stat()['mode']; - - // Let us ignore the ATTR_NOT_CONTENT_INDEXED for now - $mode &= ~0x00002000; - - return $mode; - } - - /** - * @return bool - */ - public function isDirectory() { - $mode = $this->getMode(); - if ($mode > 0x1000) { - return (bool)($mode & 0x4000); // 0x4000: unix directory flag - } else { - return (bool)($mode & IFileInfo::MODE_DIRECTORY); - } - } - - /** - * @return bool - */ - public function isReadOnly() { - $mode = $this->getMode(); - if ($mode > 0x1000) { - return !(bool)($mode & 0x80); // 0x80: owner write permissions - } else { - return (bool)($mode & IFileInfo::MODE_READONLY); - } - } - - /** - * @return bool - */ - public function isHidden() { - $mode = $this->getMode(); - if ($mode > 0x1000) { - return strlen($this->name) > 0 && $this->name[0] === '.'; - } else { - return (bool)($mode & IFileInfo::MODE_HIDDEN); - } - } - - /** - * @return bool - */ - public function isSystem() { - $mode = $this->getMode(); - if ($mode > 0x1000) { - return false; - } else { - return (bool)($mode & IFileInfo::MODE_SYSTEM); - } - } - - /** - * @return bool - */ - public function isArchived() { - $mode = $this->getMode(); - if ($mode > 0x1000) { - return false; - } else { - return (bool)($mode & IFileInfo::MODE_ARCHIVE); - } - } - - /** - * @return ACL[] - */ - public function getAcls(): array { - $acls = []; - $attribute = $this->share->getAttribute($this->path, 'system.nt_sec_desc.acl.*+'); - - foreach (explode(',', $attribute) as $acl) { - list($user, $permissions) = explode(':', $acl, 2); - list($type, $flags, $mask) = explode('/', $permissions); - $mask = hexdec($mask); - - $acls[$user] = new ACL($type, $flags, $mask); - } - - return $acls; - } -} diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeReadStream.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeReadStream.php deleted file mode 100644 index fe0af760d3f..00000000000 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeReadStream.php +++ /dev/null @@ -1,100 +0,0 @@ -<?php -/** - * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Licensed under the MIT license: - * http://opensource.org/licenses/MIT - */ - -namespace Icewind\SMB\Native; - -/** - * Stream optimized for read only usage - */ -class NativeReadStream extends NativeStream { - const CHUNK_SIZE = 1048576; // 1MB chunks - /** - * @var resource - */ - private $readBuffer = null; - - private $bufferSize = 0; - - private $pos = 0; - - public function stream_open($path, $mode, $options, &$opened_path) { - $this->readBuffer = fopen('php://memory', 'r+'); - - return parent::stream_open($path, $mode, $options, $opened_path); - } - - /** - * Wrap a stream from libsmbclient-php into a regular php stream - * - * @param \Icewind\SMB\NativeState $state - * @param resource $smbStream - * @param string $mode - * @param string $url - * @return resource - */ - public static function wrap($state, $smbStream, $mode, $url) { - stream_wrapper_register('nativesmb', NativeReadStream::class); - $context = stream_context_create([ - 'nativesmb' => [ - 'state' => $state, - 'handle' => $smbStream, - 'url' => $url - ] - ]); - $fh = fopen('nativesmb://', $mode, false, $context); - stream_wrapper_unregister('nativesmb'); - return $fh; - } - - public function stream_read($count) { - // php reads 8192 bytes at once - // however due to network latency etc, it's faster to read in larger chunks - // and buffer the result - if (!parent::stream_eof() && $this->bufferSize < $count) { - $remaining = $this->readBuffer; - $this->readBuffer = fopen('php://memory', 'r+'); - $this->bufferSize = 0; - stream_copy_to_stream($remaining, $this->readBuffer); - $this->bufferSize += fwrite($this->readBuffer, parent::stream_read(self::CHUNK_SIZE)); - fseek($this->readBuffer, 0); - } - - $result = fread($this->readBuffer, $count); - $this->bufferSize -= $count; - - $read = strlen($result); - $this->pos += $read; - - return $result; - } - - public function stream_seek($offset, $whence = SEEK_SET) { - $result = parent::stream_seek($offset, $whence); - if ($result) { - $this->readBuffer = fopen('php://memory', 'r+'); - $this->bufferSize = 0; - $this->pos = parent::stream_tell(); - } - return $result; - } - - public function stream_eof() { - return $this->bufferSize <= 0 && parent::stream_eof(); - } - - public function stream_tell() { - return $this->pos; - } - - public function stream_write($data) { - return false; - } - - public function stream_truncate($size) { - return false; - } -} diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeServer.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeServer.php deleted file mode 100644 index aadb05d0fea..00000000000 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeServer.php +++ /dev/null @@ -1,66 +0,0 @@ -<?php -/** - * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Licensed under the MIT license: - * http://opensource.org/licenses/MIT - */ - -namespace Icewind\SMB\Native; - -use Icewind\SMB\AbstractServer; -use Icewind\SMB\IAuth; -use Icewind\SMB\IOptions; -use Icewind\SMB\ISystem; -use Icewind\SMB\TimeZoneProvider; - -class NativeServer extends AbstractServer { - /** - * @var NativeState - */ - protected $state; - - public function __construct($host, IAuth $auth, ISystem $system, TimeZoneProvider $timeZoneProvider, IOptions $options) { - parent::__construct($host, $auth, $system, $timeZoneProvider, $options); - $this->state = new NativeState(); - } - - protected function connect() { - $this->state->init($this->getAuth(), $this->getOptions()); - } - - /** - * @return \Icewind\SMB\IShare[] - * @throws \Icewind\SMB\Exception\AuthenticationException - * @throws \Icewind\SMB\Exception\InvalidHostException - */ - public function listShares() { - $this->connect(); - $shares = []; - $dh = $this->state->opendir('smb://' . $this->getHost()); - while ($share = $this->state->readdir($dh)) { - if ($share['type'] === 'file share') { - $shares[] = $this->getShare($share['name']); - } - } - $this->state->closedir($dh); - return $shares; - } - - /** - * @param string $name - * @return \Icewind\SMB\IShare - */ - public function getShare($name) { - return new NativeShare($this, $name); - } - - /** - * Check if the smbclient php extension is available - * - * @param ISystem $system - * @return bool - */ - public static function available(ISystem $system) { - return $system->libSmbclientAvailable(); - } -} diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeShare.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeShare.php deleted file mode 100644 index 5368538edca..00000000000 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeShare.php +++ /dev/null @@ -1,360 +0,0 @@ -<?php -/** - * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Licensed under the MIT license: - * http://opensource.org/licenses/MIT - */ - -namespace Icewind\SMB\Native; - -use Icewind\SMB\AbstractShare; -use Icewind\SMB\Exception\DependencyException; -use Icewind\SMB\Exception\InvalidPathException; -use Icewind\SMB\Exception\InvalidResourceException; -use Icewind\SMB\INotifyHandler; -use Icewind\SMB\IServer; -use Icewind\SMB\Wrapped\Server; -use Icewind\SMB\Wrapped\Share; - -class NativeShare extends AbstractShare { - /** - * @var IServer $server - */ - private $server; - - /** - * @var string $name - */ - private $name; - - /** - * @var NativeState $state - */ - private $state; - - /** - * @param IServer $server - * @param string $name - */ - public function __construct($server, $name) { - parent::__construct(); - $this->server = $server; - $this->name = $name; - } - - /** - * @throws \Icewind\SMB\Exception\ConnectionException - * @throws \Icewind\SMB\Exception\AuthenticationException - * @throws \Icewind\SMB\Exception\InvalidHostException - */ - protected function getState() { - if ($this->state and $this->state instanceof NativeState) { - return $this->state; - } - - $this->state = new NativeState(); - $this->state->init($this->server->getAuth(), $this->server->getOptions()); - return $this->state; - } - - /** - * Get the name of the share - * - * @return string - */ - public function getName() { - return $this->name; - } - - private function buildUrl($path) { - $this->verifyPath($path); - $url = sprintf('smb://%s/%s', $this->server->getHost(), $this->name); - if ($path) { - $path = trim($path, '/'); - $url .= '/'; - $url .= implode('/', array_map('rawurlencode', explode('/', $path))); - } - return $url; - } - - /** - * List the content of a remote folder - * - * @param string $path - * @return \Icewind\SMB\IFileInfo[] - * - * @throws \Icewind\SMB\Exception\NotFoundException - * @throws \Icewind\SMB\Exception\InvalidTypeException - */ - public function dir($path) { - $files = []; - - $dh = $this->getState()->opendir($this->buildUrl($path)); - while ($file = $this->getState()->readdir($dh)) { - $name = $file['name']; - if ($name !== '.' and $name !== '..') { - $fullPath = $path . '/' . $name; - $files [] = new NativeFileInfo($this, $fullPath, $name); - } - } - - $this->getState()->closedir($dh); - return $files; - } - - /** - * @param string $path - * @return \Icewind\SMB\IFileInfo - */ - public function stat($path) { - $info = new NativeFileInfo($this, $path, self::mb_basename($path)); - - // trigger attribute loading - $info->getSize(); - - return $info; - } - - /** - * Multibyte unicode safe version of basename() - * - * @param string $path - * @link https://www.php.net/manual/en/function.basename.php#121405 - * @return string - */ - protected static function mb_basename($path) { - if (preg_match('@^.*[\\\\/]([^\\\\/]+)$@s', $path, $matches)) { - return $matches[1]; - } elseif (preg_match('@^([^\\\\/]+)$@s', $path, $matches)) { - return $matches[1]; - } - - return ''; - } - - /** - * Create a folder on the share - * - * @param string $path - * @return bool - * - * @throws \Icewind\SMB\Exception\NotFoundException - * @throws \Icewind\SMB\Exception\AlreadyExistsException - */ - public function mkdir($path) { - return $this->getState()->mkdir($this->buildUrl($path)); - } - - /** - * Remove a folder on the share - * - * @param string $path - * @return bool - * - * @throws \Icewind\SMB\Exception\NotFoundException - * @throws \Icewind\SMB\Exception\InvalidTypeException - */ - public function rmdir($path) { - return $this->getState()->rmdir($this->buildUrl($path)); - } - - /** - * Delete a file on the share - * - * @param string $path - * @return bool - * - * @throws \Icewind\SMB\Exception\NotFoundException - * @throws \Icewind\SMB\Exception\InvalidTypeException - */ - public function del($path) { - return $this->getState()->unlink($this->buildUrl($path)); - } - - /** - * Rename a remote file - * - * @param string $from - * @param string $to - * @return bool - * - * @throws \Icewind\SMB\Exception\NotFoundException - * @throws \Icewind\SMB\Exception\AlreadyExistsException - */ - public function rename($from, $to) { - return $this->getState()->rename($this->buildUrl($from), $this->buildUrl($to)); - } - - /** - * Upload a local file - * - * @param string $source local file - * @param string $target remove file - * @return bool - * - * @throws \Icewind\SMB\Exception\NotFoundException - * @throws \Icewind\SMB\Exception\InvalidTypeException - */ - public function put($source, $target) { - $sourceHandle = fopen($source, 'rb'); - $targetUrl = $this->buildUrl($target); - - $targetHandle = $this->getState()->create($targetUrl); - - while ($data = fread($sourceHandle, NativeReadStream::CHUNK_SIZE)) { - $this->getState()->write($targetHandle, $data, $targetUrl); - } - $this->getState()->close($targetHandle, $targetUrl); - return true; - } - - /** - * Download a remote file - * - * @param string $source remove file - * @param string $target local file - * @return bool - * - * @throws \Icewind\SMB\Exception\NotFoundException - * @throws \Icewind\SMB\Exception\InvalidTypeException - * @throws \Icewind\SMB\Exception\InvalidPathException - * @throws \Icewind\SMB\Exception\InvalidResourceException - */ - public function get($source, $target) { - if (!$target) { - throw new InvalidPathException('Invalid target path: Filename cannot be empty'); - } - - $sourceHandle = $this->getState()->open($this->buildUrl($source), 'r'); - if (!$sourceHandle) { - throw new InvalidResourceException('Failed opening remote file "' . $source . '" for reading'); - } - - $targetHandle = @fopen($target, 'wb'); - if (!$targetHandle) { - $error = error_get_last(); - if (is_array($error)) { - $reason = $error['message']; - } else { - $reason = 'Unknown error'; - } - $this->getState()->close($sourceHandle, $this->buildUrl($source)); - throw new InvalidResourceException('Failed opening local file "' . $target . '" for writing: ' . $reason); - } - - while ($data = $this->getState()->read($sourceHandle, NativeReadStream::CHUNK_SIZE)) { - fwrite($targetHandle, $data); - } - $this->getState()->close($sourceHandle, $this->buildUrl($source)); - return true; - } - - /** - * Open a readable stream to a remote file - * - * @param string $source - * @return resource a read only stream with the contents of the remote file - * - * @throws \Icewind\SMB\Exception\NotFoundException - * @throws \Icewind\SMB\Exception\InvalidTypeException - */ - public function read($source) { - $url = $this->buildUrl($source); - $handle = $this->getState()->open($url, 'r'); - return NativeReadStream::wrap($this->getState(), $handle, 'r', $url); - } - - /** - * Open a writeable stream to a remote file - * Note: This method will truncate the file to 0bytes first - * - * @param string $source - * @return resource a writeable stream - * - * @throws \Icewind\SMB\Exception\NotFoundException - * @throws \Icewind\SMB\Exception\InvalidTypeException - */ - public function write($source) { - $url = $this->buildUrl($source); - $handle = $this->getState()->create($url); - return NativeWriteStream::wrap($this->getState(), $handle, 'w', $url); - } - - /** - * Open a writeable stream and set the cursor to the end of the stream - * - * @param string $source - * @return resource a writeable stream - * - * @throws \Icewind\SMB\Exception\NotFoundException - * @throws \Icewind\SMB\Exception\InvalidTypeException - */ - public function append($source) { - $url = $this->buildUrl($source); - $handle = $this->getState()->open($url, "a+"); - return NativeWriteStream::wrap($this->getState(), $handle, "a", $url); - } - - /** - * Get extended attributes for the path - * - * @param string $path - * @param string $attribute attribute to get the info - * @return string the attribute value - */ - public function getAttribute($path, $attribute) { - return $this->getState()->getxattr($this->buildUrl($path), $attribute); - } - - /** - * Set extended attributes for the given path - * - * @param string $path - * @param string $attribute attribute to get the info - * @param string|int $value - * @return mixed the attribute value - */ - public function setAttribute($path, $attribute, $value) { - if ($attribute === 'system.dos_attr.mode' and is_int($value)) { - $value = '0x' . dechex($value); - } - - return $this->getState()->setxattr($this->buildUrl($path), $attribute, $value); - } - - /** - * Set DOS comaptible node mode - * - * @param string $path - * @param int $mode a combination of FileInfo::MODE_READONLY, FileInfo::MODE_ARCHIVE, FileInfo::MODE_SYSTEM and FileInfo::MODE_HIDDEN, FileInfo::NORMAL - * @return mixed - */ - public function setMode($path, $mode) { - return $this->setAttribute($path, 'system.dos_attr.mode', $mode); - } - - /** - * Start smb notify listener - * Note: This is a blocking call - * - * @param string $path - * @return INotifyHandler - */ - public function notify($path) { - // php-smbclient does not support notify (https://github.com/eduardok/libsmbclient-php/issues/29) - // so we use the smbclient based backend for this - if (!Server::available($this->server->getSystem())) { - throw new DependencyException('smbclient not found in path for notify command'); - } - $share = new Share($this->server, $this->getName(), $this->server->getSystem()); - return $share->notify($path); - } - - public function getServer(): IServer { - return $this->server; - } - - public function __destruct() { - unset($this->state); - } -} diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeState.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeState.php deleted file mode 100644 index 3bfb1c3da24..00000000000 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeState.php +++ /dev/null @@ -1,317 +0,0 @@ -<?php -/** - * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Licensed under the MIT license: - * http://opensource.org/licenses/MIT - */ - -namespace Icewind\SMB\Native; - -use Icewind\SMB\Exception\AlreadyExistsException; -use Icewind\SMB\Exception\ConnectionRefusedException; -use Icewind\SMB\Exception\ConnectionResetException; -use Icewind\SMB\Exception\Exception; -use Icewind\SMB\Exception\FileInUseException; -use Icewind\SMB\Exception\ForbiddenException; -use Icewind\SMB\Exception\HostDownException; -use Icewind\SMB\Exception\InvalidArgumentException; -use Icewind\SMB\Exception\InvalidTypeException; -use Icewind\SMB\Exception\ConnectionAbortedException; -use Icewind\SMB\Exception\NoRouteToHostException; -use Icewind\SMB\Exception\NotEmptyException; -use Icewind\SMB\Exception\NotFoundException; -use Icewind\SMB\Exception\OutOfSpaceException; -use Icewind\SMB\Exception\TimedOutException; -use Icewind\SMB\IAuth; -use Icewind\SMB\IOptions; - -/** - * Low level wrapper for libsmbclient-php with error handling - */ -class NativeState { - /** - * @var resource - */ - protected $state; - - protected $handlerSet = false; - - protected $connected = false; - - // see error.h - const EXCEPTION_MAP = [ - 1 => ForbiddenException::class, - 2 => NotFoundException::class, - 13 => ForbiddenException::class, - 16 => FileInUseException::class, - 17 => AlreadyExistsException::class, - 20 => InvalidTypeException::class, - 21 => InvalidTypeException::class, - 22 => InvalidArgumentException::class, - 28 => OutOfSpaceException::class, - 39 => NotEmptyException::class, - 103 => ConnectionAbortedException::class, - 104 => ConnectionResetException::class, - 110 => TimedOutException::class, - 111 => ConnectionRefusedException::class, - 112 => HostDownException::class, - 113 => NoRouteToHostException::class - ]; - - protected function handleError($path) { - $error = smbclient_state_errno($this->state); - if ($error === 0) { - return; - } - throw Exception::fromMap(self::EXCEPTION_MAP, $error, $path); - } - - protected function testResult($result, $uri) { - if ($result === false or $result === null) { - // smb://host/share/path - if (is_string($uri) && count(explode('/', $uri, 5)) > 4) { - list(, , , , $path) = explode('/', $uri, 5); - $path = '/' . $path; - } else { - $path = null; - } - $this->handleError($path); - } - } - - /** - * @param IAuth $auth - * @param IOptions $options - * @return bool - */ - public function init(IAuth $auth, IOptions $options) { - if ($this->connected) { - return true; - } - $this->state = smbclient_state_new(); - smbclient_option_set($this->state, SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN, false); - smbclient_option_set($this->state, SMBCLIENT_OPT_TIMEOUT, $options->getTimeout() * 1000); - $auth->setExtraSmbClientOptions($this->state); - $result = @smbclient_state_init($this->state, $auth->getWorkgroup(), $auth->getUsername(), $auth->getPassword()); - - $this->testResult($result, ''); - $this->connected = true; - return $result; - } - - /** - * @param string $uri - * @return resource - */ - public function opendir($uri) { - $result = @smbclient_opendir($this->state, $uri); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param resource $dir - * @return array - */ - public function readdir($dir) { - $result = @smbclient_readdir($this->state, $dir); - - $this->testResult($result, $dir); - return $result; - } - - /** - * @param $dir - * @return bool - */ - public function closedir($dir) { - $result = smbclient_closedir($this->state, $dir); - - $this->testResult($result, $dir); - return $result; - } - - /** - * @param string $old - * @param string $new - * @return bool - */ - public function rename($old, $new) { - $result = @smbclient_rename($this->state, $old, $this->state, $new); - - $this->testResult($result, $new); - return $result; - } - - /** - * @param string $uri - * @return bool - */ - public function unlink($uri) { - $result = @smbclient_unlink($this->state, $uri); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param string $uri - * @param int $mask - * @return bool - */ - public function mkdir($uri, $mask = 0777) { - $result = @smbclient_mkdir($this->state, $uri, $mask); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param string $uri - * @return bool - */ - public function rmdir($uri) { - $result = @smbclient_rmdir($this->state, $uri); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param string $uri - * @return array - */ - public function stat($uri) { - $result = @smbclient_stat($this->state, $uri); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param resource $file - * @return array - */ - public function fstat($file) { - $result = @smbclient_fstat($this->state, $file); - - $this->testResult($result, $file); - return $result; - } - - /** - * @param string $uri - * @param string $mode - * @param int $mask - * @return resource - */ - public function open($uri, $mode, $mask = 0666) { - $result = @smbclient_open($this->state, $uri, $mode, $mask); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param string $uri - * @param int $mask - * @return resource - */ - public function create($uri, $mask = 0666) { - $result = @smbclient_creat($this->state, $uri, $mask); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param resource $file - * @param int $bytes - * @return string - */ - public function read($file, $bytes) { - $result = @smbclient_read($this->state, $file, $bytes); - - $this->testResult($result, $file); - return $result; - } - - /** - * @param resource $file - * @param string $data - * @param string $path - * @param int $length - * @return int - */ - public function write($file, $data, $path, $length = null) { - $result = @smbclient_write($this->state, $file, $data, $length); - - $this->testResult($result, $path); - return $result; - } - - /** - * @param resource $file - * @param int $offset - * @param int $whence SEEK_SET | SEEK_CUR | SEEK_END - * @return int|bool new file offset as measured from the start of the file on success, false on failure. - */ - public function lseek($file, $offset, $whence = SEEK_SET) { - $result = @smbclient_lseek($this->state, $file, $offset, $whence); - - $this->testResult($result, $file); - return $result; - } - - /** - * @param resource $file - * @param int $size - * @return bool - */ - public function ftruncate($file, $size) { - $result = @smbclient_ftruncate($this->state, $file, $size); - - $this->testResult($result, $file); - return $result; - } - - public function close($file, $path) { - $result = @smbclient_close($this->state, $file); - - $this->testResult($result, $path); - return $result; - } - - /** - * @param string $uri - * @param string $key - * @return string - */ - public function getxattr($uri, $key) { - $result = @smbclient_getxattr($this->state, $uri, $key); - - $this->testResult($result, $uri); - return $result; - } - - /** - * @param string $uri - * @param string $key - * @param string $value - * @param int $flags - * @return mixed - */ - public function setxattr($uri, $key, $value, $flags = 0) { - $result = @smbclient_setxattr($this->state, $uri, $key, $value, $flags); - - $this->testResult($result, $uri); - return $result; - } - - public function __destruct() { - if ($this->connected) { - smbclient_state_free($this->state); - } - } -} diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeStream.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeStream.php deleted file mode 100644 index c75afaa5f1d..00000000000 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeStream.php +++ /dev/null @@ -1,131 +0,0 @@ -<?php -/** - * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Licensed under the MIT license: - * http://opensource.org/licenses/MIT - */ - -namespace Icewind\SMB\Native; - -use Icewind\SMB\Exception\Exception; -use Icewind\SMB\Exception\InvalidRequestException; -use Icewind\Streams\File; - -class NativeStream implements File { - /** - * @var resource - */ - public $context; - - /** - * @var NativeState - */ - protected $state; - - /** - * @var resource - */ - protected $handle; - - /** - * @var bool - */ - protected $eof = false; - - /** - * @var string - */ - protected $url; - - /** - * Wrap a stream from libsmbclient-php into a regular php stream - * - * @param \Icewind\SMB\NativeState $state - * @param resource $smbStream - * @param string $mode - * @param string $url - * @return resource - */ - public static function wrap($state, $smbStream, $mode, $url) { - stream_wrapper_register('nativesmb', NativeStream::class); - $context = stream_context_create([ - 'nativesmb' => [ - 'state' => $state, - 'handle' => $smbStream, - 'url' => $url - ] - ]); - $fh = fopen('nativesmb://', $mode, false, $context); - stream_wrapper_unregister('nativesmb'); - return $fh; - } - - public function stream_close() { - try { - return $this->state->close($this->handle, $this->url); - } catch (\Exception $e) { - return false; - } - } - - public function stream_eof() { - return $this->eof; - } - - public function stream_flush() { - } - - - public function stream_open($path, $mode, $options, &$opened_path) { - $context = stream_context_get_options($this->context); - $this->state = $context['nativesmb']['state']; - $this->handle = $context['nativesmb']['handle']; - $this->url = $context['nativesmb']['url']; - return true; - } - - public function stream_read($count) { - $result = $this->state->read($this->handle, $count); - if (strlen($result) < $count) { - $this->eof = true; - } - return $result; - } - - public function stream_seek($offset, $whence = SEEK_SET) { - $this->eof = false; - try { - return $this->state->lseek($this->handle, $offset, $whence) !== false; - } catch (InvalidRequestException $e) { - return false; - } - } - - public function stream_stat() { - try { - return $this->state->stat($this->url); - } catch (Exception $e) { - return false; - } - } - - public function stream_tell() { - return $this->state->lseek($this->handle, 0, SEEK_CUR); - } - - public function stream_write($data) { - return $this->state->write($this->handle, $data, $this->url); - } - - public function stream_truncate($size) { - return $this->state->ftruncate($this->handle, $size); - } - - public function stream_set_option($option, $arg1, $arg2) { - return false; - } - - public function stream_lock($operation) { - return false; - } -} diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeWriteStream.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeWriteStream.php deleted file mode 100644 index 4e90e5a655d..00000000000 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeWriteStream.php +++ /dev/null @@ -1,104 +0,0 @@ -<?php -/** - * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Licensed under the MIT license: - * http://opensource.org/licenses/MIT - */ - -namespace Icewind\SMB\Native; - -/** - * Stream optimized for write only usage - */ -class NativeWriteStream extends NativeStream { - const CHUNK_SIZE = 1048576; // 1MB chunks - /** - * @var resource - */ - private $writeBuffer = null; - - private $bufferSize = 0; - - private $pos = 0; - - public function stream_open($path, $mode, $options, &$opened_path) { - $this->writeBuffer = fopen('php://memory', 'r+'); - - return parent::stream_open($path, $mode, $options, $opened_path); - } - - /** - * Wrap a stream from libsmbclient-php into a regular php stream - * - * @param \Icewind\SMB\NativeState $state - * @param resource $smbStream - * @param string $mode - * @param string $url - * @return resource - */ - public static function wrap($state, $smbStream, $mode, $url) { - stream_wrapper_register('nativesmb', NativeWriteStream::class); - $context = stream_context_create([ - 'nativesmb' => [ - 'state' => $state, - 'handle' => $smbStream, - 'url' => $url - ] - ]); - $fh = fopen('nativesmb://', $mode, false, $context); - stream_wrapper_unregister('nativesmb'); - return $fh; - } - - public function stream_seek($offset, $whence = SEEK_SET) { - $this->flushWrite(); - $result = parent::stream_seek($offset, $whence); - if ($result) { - $this->pos = parent::stream_tell(); - } - return $result; - } - - private function flushWrite() { - rewind($this->writeBuffer); - $this->state->write($this->handle, stream_get_contents($this->writeBuffer), $this->url); - $this->writeBuffer = fopen('php://memory', 'r+'); - $this->bufferSize = 0; - } - - public function stream_write($data) { - $written = fwrite($this->writeBuffer, $data); - $this->bufferSize += $written; - $this->pos += $written; - - if ($this->bufferSize >= self::CHUNK_SIZE) { - $this->flushWrite(); - } - - return $written; - } - - public function stream_close() { - try { - $this->flushWrite(); - $flushResult = true; - } catch (\Exception $e) { - $flushResult = false; - } - return parent::stream_close() && $flushResult; - } - - public function stream_tell() { - return $this->pos; - } - - public function stream_read($count) { - return false; - } - - public function stream_truncate($size) { - $this->flushWrite(); - $this->pos = $size; - return parent::stream_truncate($size); - } -} |