• Модуль: webdav
  • Путь к файлу: ~/bitrix/modules/webdav/classes/general.php
  • Класс: CWebDavBase
  • Вызов: CWebDavBase::base_LOCK
function base_LOCK()
{
	$options = array(
		'path' => $this->_path,
		'depth' => (isset($_SERVER['HTTP_DEPTH']) ? $_SERVER['HTTP_DEPTH'] : 'infinity'));

	if (isset($_SERVER['HTTP_TIMEOUT']))
	{
		$options['timeout'] = explode(',', $_SERVER['HTTP_TIMEOUT']);
	}

	if (empty($_SERVER['CONTENT_LENGTH']) && !empty($_SERVER['HTTP_IF']))
	{
		if (!$this->_check_lock_status($this->_path))
		{
			$this->ThrowError("423 Locked", "WEBDAV_LOCK_LOCKED", '', __FILE__.' '.__LINE__);
			return;
		}

		$options["locktoken"] = mb_substr($_SERVER['HTTP_IF'], 2, -2);
		$options["update"]	  = $options["locktoken"];

		$options['owner']	  = "unknown";
		$options['scope']	  = "exclusive";
		$options['type']	  = "write";

		$stat = $this->LOCK($options);
	}
	else
	{
		$lockinfo = new __CParseLockinfo();
		$lockinfo->LoadFromPhpInput();

		if (!$lockinfo->success)
		{
			$this->ThrowError("400 bad request", "WEBDAV_LOCK_PARSE", '', __FILE__.' '.__LINE__);
		}

		if (!$this->_check_lock_status($this->_path, $lockinfo->lockscope !== "shared"))
		{
			$this->ThrowError("423 Locked", "WEBDAV_LOCK_LOCKED", '', __FILE__.' '.__LINE__);
			return;
		}

		$options["scope"]	  = $lockinfo->lockscope;
		$options["type"]	  = $lockinfo->locktype;
		$options["owner"]	  = $lockinfo->owner;
		$options["locktoken"] = $this->_new_locktoken();

		$stat = $this->LOCK($options);
	}

	if (is_bool($stat))
	{
		$http_stat = ($stat ? '200 OK' : '423 Locked');
	}
	else
	{
		$http_stat = $stat;
	}
	$this->SetStatus($http_stat);

	if (mb_substr($http_stat, 0, 1) == '2')
	{
		if ($options['timeout'])
		{
			if ($options['timeout'] > 1000000)
			{
				$timeout = 'Second-' . ($options['timeout'][0] - time());
			}
			else
			{
				$timeout = 'Second-' . $options['timeout'][0];
			}
		}
		else
		{
			$timeout = 'Infinite';
		}

		self::set_header('Content-Type: text/xml; charset="utf-8"');
		self::set_header("Lock-Token: <".$options['locktoken'].">");
		$strOutput = "n" .
			"n" .
			" n" .
			"  n" .
			"	n" .
			"	n" .
			"	" . htmlspecialcharsEx($options['depth']) . "n" .
			"	" . htmlspecialcharsEx($options['owner']) . "n" .
			"	" . htmlspecialcharsEx($timeout) . "n" .
			"	" . $options['locktoken'] . "n" .
			"  n" .
			" n".
			"nn";
		self::set_header('Content-Length: ' . $this->strlen($strOutput));
		echo $strOutput;
	}
}