diff options
author | Robin Appelman <icewind@owncloud.com> | 2014-08-26 18:46:07 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-02-16 13:52:11 +0100 |
commit | d2255a1d304aa5e537e8aa097add2a51aa0e5d89 (patch) | |
tree | 79801d54149e6c8037e717a1d5d6ac43327eb6db /apps/files_external/3rdparty/icewind/smb/src/Connection.php | |
parent | 78febb2ee594bac5d483f7c8534ed5eb33c2c528 (diff) | |
download | nextcloud-server-d2255a1d304aa5e537e8aa097add2a51aa0e5d89.tar.gz nextcloud-server-d2255a1d304aa5e537e8aa097add2a51aa0e5d89.zip |
New SMB storage backend
Diffstat (limited to 'apps/files_external/3rdparty/icewind/smb/src/Connection.php')
-rw-r--r-- | apps/files_external/3rdparty/icewind/smb/src/Connection.php | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/apps/files_external/3rdparty/icewind/smb/src/Connection.php b/apps/files_external/3rdparty/icewind/smb/src/Connection.php new file mode 100644 index 00000000000..6191b11ac8e --- /dev/null +++ b/apps/files_external/3rdparty/icewind/smb/src/Connection.php @@ -0,0 +1,78 @@ +<?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; + +use Icewind\SMB\Exception\AuthenticationException; +use Icewind\SMB\Exception\ConnectionException; +use Icewind\SMB\Exception\InvalidHostException; + +class Connection extends RawConnection { + const DELIMITER = 'smb:'; + + /** + * send input to smbclient + * + * @param string $input + */ + public function write($input) { + parent::write($input . PHP_EOL); + } + + /** + * get all unprocessed output from smbclient until the next prompt + * + * @throws ConnectionException + * @return string + */ + public function read() { + if (!$this->isValid()) { + throw new ConnectionException(); + } + $line = $this->readLine(); //first line is prompt + $this->checkConnectionError($line); + + $output = array(); + $line = $this->readLine(); + $length = mb_strlen(self::DELIMITER); + while (mb_substr($line, 0, $length) !== self::DELIMITER) { //next prompt functions as delimiter + $output[] .= $line; + $line = $this->readLine(); + } + return $output; + } + + /** + * check if the first line holds a connection failure + * + * @param $line + * @throws AuthenticationException + * @throws InvalidHostException + */ + private function checkConnectionError($line) { + $line = rtrim($line, ')'); + if (substr($line, -23) === ErrorCodes::LogonFailure) { + throw new AuthenticationException(); + } + if (substr($line, -26) === ErrorCodes::BadHostName) { + throw new InvalidHostException(); + } + if (substr($line, -22) === ErrorCodes::Unsuccessful) { + throw new InvalidHostException(); + } + if (substr($line, -28) === ErrorCodes::ConnectionRefused) { + throw new InvalidHostException(); + } + } + + public function close($terminate = true) { + if (is_resource($this->getInputStream())) { + $this->write('close' . PHP_EOL); + } + parent::close($terminate); + } +} |