From 0aa211eefb4fd8d007f07d720825b9aa86e3c6ea Mon Sep 17 00:00:00 2001
From: Robin Appelman <robin@icewind.nl>
Date: Fri, 6 Jan 2017 15:10:50 +0100
Subject: [PATCH] Add missing smb files

Signed-off-by: Robin Appelman <robin@icewind.nl>
---
 3rdparty                                      |  2 +-
 .../3rdparty/icewind/smb/src/Change.php       | 40 +++++++++
 .../smb/src/Exception/DependencyException.php | 11 +++
 .../icewind/smb/src/INotifyHandler.php        | 46 ++++++++++
 .../icewind/smb/src/NotifyHandler.php         | 88 +++++++++++++++++++
 5 files changed, 186 insertions(+), 1 deletion(-)
 create mode 100644 apps/files_external/3rdparty/icewind/smb/src/Change.php
 create mode 100644 apps/files_external/3rdparty/icewind/smb/src/Exception/DependencyException.php
 create mode 100644 apps/files_external/3rdparty/icewind/smb/src/INotifyHandler.php
 create mode 100644 apps/files_external/3rdparty/icewind/smb/src/NotifyHandler.php

diff --git a/3rdparty b/3rdparty
index f2d8ba7bfeb..204e4842df5 160000
--- a/3rdparty
+++ b/3rdparty
@@ -1 +1 @@
-Subproject commit f2d8ba7bfebb769835b637f01eaa602e36cdcca0
+Subproject commit 204e4842df5d63c759f9c2d110c1a14036900e24
diff --git a/apps/files_external/3rdparty/icewind/smb/src/Change.php b/apps/files_external/3rdparty/icewind/smb/src/Change.php
new file mode 100644
index 00000000000..9dfd57b3973
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/smb/src/Change.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
+ * This file is licensed under the Licensed under the MIT license:
+ * http://opensource.org/licenses/MIT
+ *
+ */
+
+namespace Icewind\SMB;
+
+class Change {
+	private $code;
+
+	private $path;
+
+	/**
+	 * Change constructor.
+	 *
+	 * @param $code
+	 * @param $path
+	 */
+	public function __construct($code, $path) {
+		$this->code = $code;
+		$this->path = $path;
+	}
+
+	/**
+	 * @return integer
+	 */
+	public function getCode() {
+		return $this->code;
+	}
+
+	/**
+	 * @return string
+	 */
+	public function getPath() {
+		return $this->path;
+	}
+}
diff --git a/apps/files_external/3rdparty/icewind/smb/src/Exception/DependencyException.php b/apps/files_external/3rdparty/icewind/smb/src/Exception/DependencyException.php
new file mode 100644
index 00000000000..39735578798
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/smb/src/Exception/DependencyException.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Copyright (c) 2016 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Licensed under the MIT license:
+ * http://opensource.org/licenses/MIT
+ */
+
+namespace Icewind\SMB\Exception;
+
+class DependencyException extends Exception {
+}
diff --git a/apps/files_external/3rdparty/icewind/smb/src/INotifyHandler.php b/apps/files_external/3rdparty/icewind/smb/src/INotifyHandler.php
new file mode 100644
index 00000000000..1ee59b26ddd
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/smb/src/INotifyHandler.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
+ * This file is licensed under the Licensed under the MIT license:
+ * http://opensource.org/licenses/MIT
+ *
+ */
+
+namespace Icewind\SMB;
+
+
+interface INotifyHandler {
+	// https://msdn.microsoft.com/en-us/library/dn392331.aspx
+	const NOTIFY_ADDED = 1;
+	const NOTIFY_REMOVED = 2;
+	const NOTIFY_MODIFIED = 3;
+	const NOTIFY_RENAMED_OLD = 4;
+	const NOTIFY_RENAMED_NEW = 5;
+	const NOTIFY_ADDED_STREAM = 6;
+	const NOTIFY_REMOVED_STREAM = 7;
+	const NOTIFY_MODIFIED_STREAM = 8;
+	const NOTIFY_REMOVED_BY_DELETE = 9;
+
+	/**
+	 * Get all changes detected since the start of the notify process or the last call to getChanges
+	 *
+	 * @return Change[]
+	 */
+	public function getChanges();
+
+	/**
+	 * Listen actively to all incoming changes
+	 *
+	 * Note that this is a blocking process and will cause the process to block forever if not explicitly terminated
+	 *
+	 * @param callable $callback
+	 */
+	public function listen($callback);
+
+	/**
+	 * Stop listening for changes
+	 *
+	 * Note that any pending changes will be discarded
+	 */
+	public function stop();
+}
diff --git a/apps/files_external/3rdparty/icewind/smb/src/NotifyHandler.php b/apps/files_external/3rdparty/icewind/smb/src/NotifyHandler.php
new file mode 100644
index 00000000000..194e848502b
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/smb/src/NotifyHandler.php
@@ -0,0 +1,88 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
+ * This file is licensed under the Licensed under the MIT license:
+ * http://opensource.org/licenses/MIT
+ *
+ */
+
+namespace Icewind\SMB;
+
+
+class NotifyHandler implements INotifyHandler {
+	/**
+	 * @var Connection
+	 */
+	private $connection;
+
+	/**
+	 * @var string
+	 */
+	private $path;
+
+	private $listening = true;
+
+	/**
+	 * @param Connection $connection
+	 * @param string $path
+	 */
+	public function __construct(Connection $connection, $path) {
+		$this->connection = $connection;
+		$this->path = $path;
+	}
+
+	/**
+	 * Get all changes detected since the start of the notify process or the last call to getChanges
+	 *
+	 * @return Change[]
+	 */
+	public function getChanges() {
+		if (!$this->listening) {
+			return [];
+		}
+		stream_set_blocking($this->connection->getOutputStream(), 0);
+		$lines = [];
+		while (($line = $this->connection->readLine())) {
+			$lines[] = $line;
+		}
+		stream_set_blocking($this->connection->getOutputStream(), 1);
+		return array_values(array_filter(array_map([$this, 'parseChangeLine'], $lines)));
+	}
+
+	/**
+	 * Listen actively to all incoming changes
+	 *
+	 * Note that this is a blocking process and will cause the process to block forever if not explicitly terminated
+	 *
+	 * @param callable $callback
+	 */
+	public function listen($callback) {
+		if ($this->listening) {
+			$this->connection->read(function ($line) use ($callback) {
+				return $callback($this->parseChangeLine($line));
+			});
+		}
+	}
+
+	private function parseChangeLine($line) {
+		$code = (int)substr($line, 0, 4);
+		if ($code === 0) {
+			return null;
+		}
+		$subPath = str_replace('\\', '/', substr($line, 5));
+		if ($this->path === '') {
+			return new Change($code, $subPath);
+		} else {
+			return new Change($code, $this->path . '/' . $subPath);
+		}
+	}
+
+	public function stop() {
+		$this->listening = false;
+		$this->connection->close();
+	}
+
+	public function __destruct() {
+		$this->stop();
+	}
+}
-- 
GitLab