diff options
Diffstat (limited to 'apps/files_external/3rdparty/icewind/smb/src/NativeServer.php')
-rw-r--r-- | apps/files_external/3rdparty/icewind/smb/src/NativeServer.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/apps/files_external/3rdparty/icewind/smb/src/NativeServer.php b/apps/files_external/3rdparty/icewind/smb/src/NativeServer.php new file mode 100644 index 00000000000..4628e3ec108 --- /dev/null +++ b/apps/files_external/3rdparty/icewind/smb/src/NativeServer.php @@ -0,0 +1,60 @@ +<?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; + +class NativeServer extends Server { + /** + * @var \Icewind\SMB\NativeState + */ + protected $state; + + /** + * @param string $host + * @param string $user + * @param string $password + */ + public function __construct($host, $user, $password) { + parent::__construct($host, $user, $password); + $this->state = new NativeState(); + } + + protected function connect() { + $user = $this->getUser(); + $workgroup = null; + if (strpos($user, '/')) { + list($workgroup, $user) = explode($user, '/'); + } + $this->state->init($workgroup, $user, $this->getPassword()); + } + + /** + * @return \Icewind\SMB\IShare[] + * @throws \Icewind\SMB\Exception\AuthenticationException + * @throws \Icewind\SMB\Exception\InvalidHostException + */ + public function listShares() { + $this->connect(); + $shares = array(); + $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); + } +} |