Server.php 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Hartmut Holzgraefe <hholzgra@php.net> |
  17. // | Christian Stocker <chregu@bitflux.ch> |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: Server.php,v 1.13 2003/11/18 21:09:35 hholzgra Exp $
  21. //
  22. // WebDAV server base class, needs to be extended to do useful work
  23. //
  24. // require_once "HTTP/HTTP.php";
  25. require_once "HTTP/WebDAV/Tools/_parse_propfind.php";
  26. require_once "HTTP/WebDAV/Tools/_parse_proppatch.php";
  27. require_once "HTTP/WebDAV/Tools/_parse_lockinfo.php";
  28. /**
  29. * Virtual base class for implementing WebDAV servers
  30. *
  31. * this is it
  32. * bla bla
  33. *
  34. * @package HTTP_WebDAV_Server
  35. * @author Hartmut Holzgraefe <hholzgra@php.net>
  36. * @version 0.95dev
  37. */
  38. class HTTP_WebDAV_Server {
  39. // {{{ Member Variables
  40. /**
  41. * URI path for this request
  42. *
  43. * @var string
  44. */
  45. var $path;
  46. /**
  47. * Realm string to be used in authentification popups
  48. *
  49. * @var string
  50. */
  51. var $http_auth_realm = "PHP WebDAV";
  52. /**
  53. * Remember parsed If: (RFC2518/9.4) header conditions
  54. *
  55. * @var array
  56. */
  57. var $_if_header_uris = array();
  58. var $_http_status = "200 OK";
  59. var $_prop_encoding = "utf-8";
  60. // }}}
  61. // {{{ Constructor
  62. /**
  63. * Constructor
  64. *
  65. * @param void
  66. */
  67. function HTTP_WebDAV_Server() {
  68. // PHP messages destroy XML output -> switch them off
  69. ini_set("display_errors", 0);
  70. }
  71. // }}}
  72. // {{{ ServeRequest()
  73. /**
  74. * Serve WebDAV HTTP request
  75. *
  76. * dispatch WebDAV HTTP request to the apropriate method handler
  77. *
  78. * @param void
  79. * @return void
  80. */
  81. function ServeRequest() {
  82. // identify ourselves
  83. header("X-Dav-Powered-By: PHP class: ".get_class($this));
  84. if (!$this->_check_auth()) {
  85. // RFC2518 says we must use Digest instead of Basic
  86. // but Microsoft Clients do not support Digest
  87. // and we don't support NTLM and M$-Kerberos
  88. // so we are stuck with Basic here
  89. header('WWW-Authenticate: Basic realm="'.($this->http_auth_realm).'"');
  90. header('HTTP/1.0 401 Unauthorized');
  91. exit;
  92. }
  93. if(! $this->_check_if_header_conditions()) {
  94. header("HTTP/1.0 412 Precondition failed");
  95. exit;
  96. }
  97. // set path
  98. $this->path =
  99. $this->_urldecode(!empty($_SERVER["PATH_INFO"]) ? $_SERVER["PATH_INFO"] : "/");
  100. if(ini_get("magic_quotes_gpc")) {
  101. $this->path = stripslashes($this->path);
  102. }
  103. // detect requested method names
  104. $method = strtolower($_SERVER["REQUEST_METHOD"]);
  105. $wrapper = "http_".$method;
  106. // activate HEAD emulation by GET if no HEAD method found
  107. if ($method == "head" && !method_exists($this, "head")) {
  108. $method = "get";
  109. }
  110. if (method_exists($this, $wrapper) &&
  111. ($method == "options" || method_exists($this, $method))) {
  112. $this->$wrapper(); // call method by name
  113. } else {
  114. if ($_SERVER["REQUEST_METHOD"] == "LOCK") {
  115. $this->http_status("412 Precondition failed");
  116. } else {
  117. $this->http_status("405 Method not allowed");
  118. header("Allow: ".join(", ", $this->_allow())); // tell client what's allowed
  119. }
  120. }
  121. }
  122. // }}}
  123. // {{{ abstract WebDAV methods
  124. // {{{ GET()
  125. /**
  126. * GET implementation
  127. *
  128. * overload this method to retrieve resources from your server
  129. * <br>
  130. *
  131. *
  132. * @abstract
  133. * @param array &$params Array of input and output parameters
  134. * <br><b>input</b><ul>
  135. * <li> path -
  136. * </ul>
  137. * <br><b>output</b><ul>
  138. * <li> size -
  139. * </ul>
  140. * @returns int HTTP-Statuscode
  141. */
  142. /* abstract
  143. function GET(&$params) {
  144. // dummy entry for PHPDoc
  145. }
  146. */
  147. // }}}
  148. // {{{ PUT()
  149. /**
  150. * PUT implementation
  151. *
  152. * PUT implementation
  153. *
  154. * @abstract
  155. * @param array &$params
  156. * @returns int HTTP-Statuscode
  157. */
  158. /* abstract
  159. function PUT() {
  160. // dummy entry for PHPDoc
  161. }
  162. */
  163. // }}}
  164. // {{{ COPY()
  165. /**
  166. * COPY implementation
  167. *
  168. * COPY implementation
  169. *
  170. * @abstract
  171. * @param array &$params
  172. * @returns int HTTP-Statuscode
  173. */
  174. /* abstract
  175. function COPY() {
  176. // dummy entry for PHPDoc
  177. }
  178. */
  179. // }}}
  180. // {{{ MOVE()
  181. /**
  182. * MOVE implementation
  183. *
  184. * MOVE implementation
  185. *
  186. * @abstract
  187. * @param array &$params
  188. * @returns int HTTP-Statuscode
  189. */
  190. /* abstract
  191. function MOVE() {
  192. // dummy entry for PHPDoc
  193. }
  194. */
  195. // }}}
  196. // {{{ DELETE()
  197. /**
  198. * DELETE implementation
  199. *
  200. * DELETE implementation
  201. *
  202. * @abstract
  203. * @param array &$params
  204. * @returns int HTTP-Statuscode
  205. */
  206. /* abstract
  207. function DELETE() {
  208. // dummy entry for PHPDoc
  209. }
  210. */
  211. // }}}
  212. // {{{ PROPFIND()
  213. /**
  214. * PROPFIND implementation
  215. *
  216. * PROPFIND implementation
  217. *
  218. * @abstract
  219. * @param array &$params
  220. * @returns int HTTP-Statuscode
  221. */
  222. /* abstract
  223. function PROPFIND() {
  224. // dummy entry for PHPDoc
  225. }
  226. */
  227. // }}}
  228. // {{{ PROPPATCH()
  229. /**
  230. * PROPPATCH implementation
  231. *
  232. * PROPPATCH implementation
  233. *
  234. * @abstract
  235. * @param array &$params
  236. * @returns int HTTP-Statuscode
  237. */
  238. /* abstract
  239. function PROPPATCH() {
  240. // dummy entry for PHPDoc
  241. }
  242. */
  243. // }}}
  244. // {{{ LOCK()
  245. /**
  246. * LOCK implementation
  247. *
  248. * LOCK implementation
  249. *
  250. * @abstract
  251. * @param array &$params
  252. * @returns int HTTP-Statuscode
  253. */
  254. /* abstract
  255. function LOCK() {
  256. // dummy entry for PHPDoc
  257. }
  258. */
  259. // }}}
  260. // {{{ UNLOCK()
  261. /**
  262. * UNLOCK implementation
  263. *
  264. * UNLOCK implementation
  265. *
  266. * @abstract
  267. * @param array &$params
  268. * @returns int HTTP-Statuscode
  269. */
  270. /* abstract
  271. function UNLOCK() {
  272. // dummy entry for PHPDoc
  273. }
  274. */
  275. // }}}
  276. // }}}
  277. // {{{ other abstract methods
  278. // {{{ check_auth()
  279. /**
  280. * check authentication
  281. *
  282. * overload this method to retrieve and confirm authentication information
  283. *
  284. * @abstract
  285. * @param string type Authentication type, e.g. "basic" or "digest"
  286. * @param string username Transmitted username
  287. * @param string passwort Transmitted password
  288. * @returns bool Authentication status
  289. */
  290. /* abstract
  291. function check_auth($type, $username, $password) {
  292. // dummy entry for PHPDoc
  293. }
  294. */
  295. // }}}
  296. // {{{ checklock()
  297. /**
  298. * check lock status for a resource
  299. *
  300. * overload this method to return shared and exclusive locks
  301. * active for this resource
  302. *
  303. * @abstract
  304. * @param string resource Resource path to check
  305. * @returns array An array of lock entries each consisting
  306. * of 'type' ('shared'/'exclusive'), 'token' and 'timeout'
  307. */
  308. /* abstract
  309. function checklock($resource) {
  310. // dummy entry for PHPDoc
  311. }
  312. */
  313. // }}}
  314. // }}}
  315. // {{{ WebDAV HTTP method wrappers
  316. // {{{ http_OPTIONS()
  317. /**
  318. * OPTIONS method handler
  319. *
  320. * The OPTIONS method handler creates a valid OPTIONS reply
  321. * including Dav: and Allowed: heaers
  322. * based on the implemented methods found in the actual instance
  323. *
  324. * @param void
  325. * @returns void
  326. */
  327. function http_OPTIONS() {
  328. $this->http_status("200 OK");
  329. // be nice to M$ clients
  330. header("MS-Author-Via: DAV");
  331. // get allowed methods
  332. $allow = $this->_allow();
  333. // dav header
  334. $dav = array(1); // assume we are always dav class 1 compliant
  335. if (isset($allow['lock']))
  336. $dav[] = 2; // dav class 2 requires locking
  337. header("DAV: ".join(",", $dav));
  338. header("Allow: ".join(", ", $allow));
  339. }
  340. // }}}
  341. // {{{ http_PROPFIND()
  342. function http_PROPFIND() {
  343. $options = Array();
  344. $options["path"] = $this->path;
  345. if (isset($_SERVER['HTTP_DEPTH'])) {
  346. $options["depth"] = $_SERVER["HTTP_DEPTH"];
  347. } else {
  348. $options["depth"] = "infinity";
  349. }
  350. $propinfo = new _parse_propfind("php://input");
  351. if (!$propinfo->success) {
  352. $this->http_status("400 Error");
  353. return;
  354. }
  355. $options['props'] = $propinfo->props;
  356. if ($this->propfind($options, $files)) {
  357. // collect namespaces
  358. $ns_hash = array();
  359. $ns_defs = "xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\""; // M$ needs this for time values
  360. foreach($files["files"] as $filekey => $file) {
  361. if (@is_array($file["props"])) {
  362. foreach($file["props"] as $key => $prop) {
  363. // clean up returned properties, leave only requested entries
  364. switch($options['props']) {
  365. case "all":
  366. break;
  367. case "names":
  368. unset($files["files"][$filekey]["props"][$key]["val"]);
  369. break;
  370. default:
  371. $found = false;
  372. if (is_array($options["props"])) {
  373. foreach($options["props"] as $reqprop) {
  374. if ($reqprop["name"] == $prop["name"]) {
  375. // todo NameSpaces
  376. $found = true;
  377. break;
  378. }
  379. }
  380. }
  381. if (!$found) {
  382. $files["files"][$filekey]["props"][$key]="";
  383. continue(2);
  384. }
  385. break;
  386. }
  387. if (empty($prop["ns"]))
  388. continue;
  389. $ns = $prop["ns"];
  390. if ($ns == "DAV:")
  391. continue;
  392. if (isset($ns_hash[$ns]))
  393. continue;
  394. $ns_name = "ns".(count($ns_hash) + 1);
  395. $ns_hash[$ns] = $ns_name;
  396. $ns_defs .= " xmlns:$ns_name=\"$ns\"";
  397. }
  398. }
  399. // add entries requested but not found
  400. if (is_array($options['props'])) {
  401. foreach($options["props"] as $reqprop) {
  402. if($reqprop['name']=="") continue;
  403. $found = false;
  404. foreach($file["props"] as $prop) {
  405. if ($reqprop["name"] == $prop["name"]) {
  406. // todo NameSpaces
  407. $found = true;
  408. break;
  409. }
  410. }
  411. if (!$found) {
  412. if($reqprop["xmlns"]==="DAV:" && $reqprop["name"]==="lockdiscovery") {
  413. $files["files"][$filekey]["props"][]
  414. = $this->mkprop("DAV:", "lockdiscovery" , $this->lockdiscovery($files["files"][$filekey]['path']));
  415. } else {
  416. $files["files"][$filekey]["noprops"][] =
  417. $this->mkprop($reqprop["xmlns"], $reqprop["name"], "");
  418. if ($reqprop["xmlns"] != "DAV:" &&
  419. !isset($ns_hash[$reqprop["xmlns"]])) {
  420. $ns_name = "ns".(count($ns_hash) + 1);
  421. $ns_hash[$reqprop["xmlns"]] = $ns_name;
  422. $ns_defs .= " xmlns:$ns_name=\"$reqprop[xmlns]\"";
  423. }
  424. }
  425. }
  426. }
  427. }
  428. }
  429. $this->http_status("207 Multi-Status");
  430. header('Content-Type: text/xml; charset="utf-8"');
  431. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  432. echo "<D:multistatus xmlns:D=\"DAV:\">\n";
  433. foreach($files["files"] as $file) {
  434. if(!is_array($file) || empty($file) || !isset($file["path"])) continue;
  435. echo " <D:response $ns_defs>\n";
  436. $path = $file['path'];
  437. if(!is_string($path) || $path==="") continue;
  438. // todo: make sure collection hrefs end in '/'
  439. // http://$_SERVER[HTTP_HOST]
  440. echo " <D:href>".$this->_urlencode($_SERVER["SCRIPT_NAME"].$path)."</D:href>\n";
  441. echo " <D:propstat>\n";
  442. echo " <D:prop>\n";
  443. if (@is_array($file["props"])) {
  444. foreach($file["props"] as $key => $prop) {
  445. if (!is_array($prop)) continue;
  446. if (!isset($prop["name"])) continue;
  447. if (!isset($prop["val"]) || $prop["val"] === "" || $prop["val"] === false) {
  448. if($prop["ns"]=="DAV:") {
  449. echo " <D:$prop[name]/>\n";
  450. } else if($prop["ns"]) {
  451. echo " <".$ns_hash[$prop["ns"]].":$prop[name]/>\n";
  452. } else {
  453. echo " <$prop[name] xmlns=\"\"/>";
  454. }
  455. } else if ($prop["ns"] == "DAV:") {
  456. switch ($prop["name"]) {
  457. case "creationdate":
  458. echo " <D:creationdate ns0:dt=\"dateTime.tz\">".
  459. date("Y-m-d\\TH:i:s\\Z",$prop['val']).
  460. "</D:creationdate>\n";
  461. break;
  462. case "getlastmodified":
  463. echo " <D:getlastmodified ns0:dt=\"dateTime.rfc1123\">".
  464. date("D, j M Y H:m:s ",
  465. $prop['val']).
  466. "GMT</D:getlastmodified>\n";
  467. break;
  468. case "resourcetype":
  469. echo " <D:resourcetype><D:$prop[val]/></D:resourcetype>\n";
  470. break;
  471. case "supportedlock":
  472. echo " <D:supportedlock>$prop[val]</D:supportedlock>\n";
  473. break;
  474. case "lockdiscovery":
  475. echo " <D:lockdiscovery>\n";
  476. echo $prop["val"];
  477. echo " </D:lockdiscovery>\n";
  478. break;
  479. default:
  480. echo " <D:$prop[name]>".
  481. $this->prop_encode(htmlspecialchars
  482. ($prop['val'])).
  483. "</D:$prop[name]>\n";
  484. break;
  485. }
  486. } else {
  487. if ($prop["ns"]) {
  488. echo " <".$ns_hash[$prop["ns"]].
  489. ":$prop[name]>".
  490. $this->prop_encode(htmlspecialchars
  491. ($prop['val']))."</".
  492. $ns_hash[$prop["ns"]].
  493. ":$prop[name]>\n";
  494. } else {
  495. echo " <$prop[name] xmlns=\"\">".
  496. $this->prop_encode(htmlspecialchars
  497. ($prop['val'])).
  498. "</$prop[name]>\n";
  499. }
  500. }
  501. }
  502. }
  503. echo " </D:prop>\n";
  504. echo " <D:status>HTTP/1.1 200 OK</D:status>\n";
  505. echo " </D:propstat>\n";
  506. if (@is_array($file["noprops"])) {
  507. echo " <D:propstat>\n";
  508. echo " <D:prop>\n";
  509. foreach($file["noprops"] as $key => $prop) {
  510. if (!is_array($prop))
  511. $prop = array("val" => $prop);
  512. if ($prop["ns"] == "DAV:") {
  513. echo " <D:$prop[name]/>\n";
  514. } else if ($prop["ns"] == "") {
  515. echo " <$prop[name] xmlns=\"\"/>\n";
  516. } else {
  517. echo " <".$ns_hash[$prop["ns"]].
  518. ":$prop[name]/>\n";
  519. }
  520. }
  521. echo " </D:prop>\n";
  522. echo " <D:status>HTTP/1.1 404 Not Found</D:status>\n";
  523. echo " </D:propstat>\n";
  524. }
  525. echo " </D:response>\n";
  526. }
  527. echo "</D:multistatus>\n";
  528. } else {
  529. $this->http_status("404 Not Found");
  530. }
  531. }
  532. // }}}
  533. // {{{ http_PROPPATCH()
  534. function http_PROPPATCH() {
  535. if($this->_check_lock_status($this->path)) {
  536. $options = Array();
  537. $options["path"] = $this->path;
  538. $propinfo = new _parse_proppatch("php://input");
  539. if (!$propinfo->success) {
  540. $this->http_status("400 Error");
  541. return;
  542. }
  543. $options['props'] = $propinfo->props;
  544. $responsedescr = $this->proppatch($options);
  545. $this->http_status("207 Multi-Status");
  546. header('Content-Type: text/xml; charset="utf-8"');
  547. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  548. echo "<D:multistatus xmlns:D=\"DAV:\">\n";
  549. echo " <D:response>\n";
  550. echo " <D:href>".$this->_urlencode($_SERVER["SCRIPT_NAME"].$this->path)."</D:href>\n";
  551. foreach($options["props"] as $prop) {
  552. echo " <D:propstat>\n";
  553. echo " <D:prop><$prop[name] xmlns=\"$prop[ns]\"/></D:prop>\n";
  554. echo " <D:status>HTTP/1.1 $prop[status]</D:status>\n";
  555. echo " </D:propstat>\n";
  556. }
  557. if ($responsedescr) {
  558. echo " <D:responsedescription>".
  559. $this->prop_encode(htmlspecialchars($responsedescr)).
  560. "</D:responsedescription>\n";
  561. }
  562. echo " </D:response>\n";
  563. echo "</D:multistatus>\n";
  564. } else {
  565. $this->http_status("423 Locked");
  566. }
  567. }
  568. // }}}
  569. // {{{ http_MKCOL()
  570. function http_MKCOL() {
  571. $options = Array();
  572. $options["path"] = $this->path;
  573. $stat = $this->mkcol($options);
  574. $this->http_status($stat);
  575. }
  576. // }}}
  577. // {{{ http_GET()
  578. /**
  579. * GET wrapper
  580. *
  581. * GET wrapper
  582. *
  583. * @param void
  584. * @returns void
  585. */
  586. function http_GET() {
  587. $options = Array();
  588. $options["path"] = $this->path;
  589. $this->_get_ranges($options);
  590. if (true == ($status = $this->get($options))) {
  591. if (!headers_sent()) {
  592. $status = "200 OK";
  593. if (!isset($options['mimetype'])) {
  594. $options['mimetype'] = "application/octet-stream";
  595. }
  596. header("Content-type: $options[mimetype]");
  597. if (isset($options['mtime'])) {
  598. header("Last-modified:".date("D, j M Y H:m:s ", $options['mtime'])."GMT");
  599. }
  600. if (isset($options['stream'])) {
  601. // GET handler returned a stream
  602. if (!empty($options['ranges']) && (0===fseek($options['stream'], 0, SEEK_SET))) {
  603. // partial request and stream is seekable
  604. if (count($options['ranges']) === 1) {
  605. $range = $options['ranges'][0];
  606. if (isset($range['start'])) {
  607. fseek($options['stream'], $range['start'], SEEK_SET);
  608. if (feof($options['stream'])) {
  609. http_status("416 Requested range not satisfiable");
  610. exit;
  611. }
  612. if (isset($range['end'])) {
  613. $size = $range['end']-$range['start']+1;
  614. http_status("206 partial");
  615. header("Content-length: $size");
  616. header("Content-range: $range[start]-$range[end]/". (isset($options['size']) ? $options['size'] : "*"));
  617. while ($size && !feof($options['stream'])) {
  618. $buffer = fread($options['stream'], 4096);
  619. $size -= strlen($buffer);
  620. echo $buffer;
  621. }
  622. } else {
  623. http_status("206 partial");
  624. if (isset($options['size'])) {
  625. header("Content-length: ".($options['size'] - $range['start']));
  626. header("Content-range: $start-$end/". (isset($options['size']) ? $options['size'] : "*"));
  627. }
  628. fpassthru($options['stream']);
  629. }
  630. } else {
  631. header("Content-length: ".$range['last']);
  632. fseek($options['stream'], -$range['last'], SEEK_END);
  633. fpassthru($options['stream']);
  634. }
  635. } else {
  636. $this->_multipart_byterange_header(); // init multipart
  637. foreach ($options['ranges'] as $range) {
  638. // TODO what if size unknown? 500?
  639. if (isset($range['start'])) {
  640. $from = $range['start'];
  641. $to = !empty($range['end']) ? $range['end'] : $options['size']-1;
  642. } else {
  643. $from = $options['size'] - $range['last']-1;
  644. $to = $options['size'] -1;
  645. }
  646. $total = isset($options['size']) ? $options['size'] : "*";
  647. $size = $to - $from + 1;
  648. $this->_multipart_byterange_header($options['mimetype'], $from, $to, $total);
  649. fseek($options['stream'], $start, SEEK_SET);
  650. while ($size && !feof($options['stream'])) {
  651. $buffer = fread($options['stream'], 4096);
  652. $size -= strlen($buffer);
  653. echo $buffer;
  654. }
  655. }
  656. $this->_multipart_byterange_header(); // end multipart
  657. }
  658. } else {
  659. // normal request or stream isn't seekable, return full content
  660. if (isset($options['size'])) {
  661. header("Content-length: ".$options['size']);
  662. }
  663. fpassthru($options['stream']);
  664. return; // no more headers
  665. }
  666. } elseif (isset($options['data'])) {
  667. if (is_array($options['data'])) {
  668. // reply to partial request
  669. } else {
  670. header("Content-length: ".strlen($options['data']));
  671. echo $data;
  672. }
  673. }
  674. }
  675. }
  676. if (false === $status) {
  677. $this->http_status("404 not found");
  678. }
  679. $this->http_status("$status");
  680. }
  681. function _get_ranges(&$options) {
  682. if (isset($_SERVER['HTTP_RANGE'])) {
  683. if (ereg("bytes[[:space:]]*=[[:space:]]*(.*)", $_SERVER['HTTP_RANGE'], $matches)) {
  684. $options["ranges"] = array();
  685. foreach (explode(",", $matches[1]) as $range) {
  686. list($start, $end) = explode("-", $range);
  687. $options["ranges"][] = ($start==="") ? array("last"=>$end) : array("start"=>$start, "end"=>$end);
  688. }
  689. }
  690. }
  691. }
  692. function _multipart_byterange_header($mimetype = false, $from = false, $to=false, $total=false) {
  693. if ($mimetype == false) {
  694. if (!isset($this->multipart_separator)) {
  695. // initial
  696. $this->multipart_separator = "SEPPARATOR_".md5(microtime());
  697. header("Content-type: multipart/byteranges; boundary=".$this->multipart_separator);
  698. } else {
  699. // final
  700. echo "\n--{$this->multipart_separator}--";
  701. }
  702. } else {
  703. echo "\n--{$this->multipart_separator}\n";
  704. echo "Content-type: $mimetype\n";
  705. echo "Content-range: $from-$to/". ($total === false ? "*" : $total);
  706. echo "\n\n";
  707. }
  708. }
  709. // }}}
  710. // {{{ http_HEAD()
  711. function http_HEAD() {
  712. $status = false;
  713. $options = Array();
  714. $options["path"] = $this->path;
  715. if (method_exists($this, "HEAD")) {
  716. $status = $this->head($options);
  717. } else if (method_exists($this, "GET")) {
  718. ob_start();
  719. $status = $this->GET($options);
  720. ob_end_clean();
  721. }
  722. if($status===true) $status = "200 OK";
  723. if($status===false) $status = "404 Not found";
  724. $this->http_status($status);
  725. }
  726. // }}}
  727. // {{{ http_PUT()
  728. function http_PUT() {
  729. if ($this->_check_lock_status($this->path)) {
  730. $options = Array();
  731. $options["path"] = $this->path;
  732. $options["content_length"] = $_SERVER["CONTENT_LENGTH"];
  733. // get the Content-type
  734. if (isset($_SERVER["CONTENT_TYPE"])) {
  735. // for now we do not support any sort of multipart requests
  736. if (!strncmp($_SERVER["CONTENT_TYPE"], "multipart/", 10)) {
  737. $this->http_status(501);
  738. return;
  739. }
  740. $options["content_type"] = $_SERVER["CONTENT_TYPE"];
  741. } else {
  742. // default content type if none given
  743. $options["content_type"] = "application/octet-stream";
  744. }
  745. /* RFC 2616 2.6 says "The recipient of the entity MUST NOT
  746. ignore any Content-* (e.g. Content-Range) headers that it
  747. does not understand or implement and MUST return a 501
  748. (Not Implemented) response in such cases.
  749. */
  750. foreach ($_SERVER as $key => $val) {
  751. if (strncmp($key, "HTTP_CONTENT", 11)) continue;
  752. switch ($key) {
  753. case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
  754. // TODO support this if ext/zlib filters are available
  755. $this->http_status(501);
  756. return;
  757. case 'HTTP_CONTENT_LANGUAGE': // RFC 2616 14.12
  758. // we assume it is not critical if this one is ignored
  759. // in the actual PUT implementation ...
  760. $options["content_language"] = $value;
  761. break;
  762. case 'HTTP_CONTENT_LOCATION': // RFC 2616 14.14
  763. /* The meaning of the Content-Location header in PUT
  764. or POST requests is undefined; servers are free
  765. to ignore it in those cases. */
  766. break;
  767. case 'HTTP_CONTENT_RANGE': // RFC 2616 14.16
  768. // single byte range requests are supported
  769. // the header format is also specified in RFC 2616 14.16
  770. // TODO we have to ensure that implementations support this or send 501 instead
  771. if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $value, $matches)) {
  772. $this->http_status(400);
  773. return;
  774. }
  775. $range = array("start"=>$matches[1], "end"=>$matches[2]);
  776. if (is_numeric($matches[3])) {
  777. $range["total_length"] = $matches[3];
  778. }
  779. $option["ranges"][] = $range;
  780. // TODO make sure the implementation supports partial PUT
  781. // this has to be done in advance to avoid data being overwritten
  782. // on implementations that do not support this ...
  783. break;
  784. case 'HTTP_CONTENT_MD5': // RFC 2616 14.15
  785. // TODO: maybe we can just pretend here?
  786. $this->http_status(501);
  787. return;
  788. default:
  789. // any other unknown Content-* headers
  790. $this->http_status(501);
  791. return;
  792. }
  793. }
  794. $options["stream"] = fopen("php://input", "r");
  795. $stat = $this->PUT($options);
  796. if (is_resource($stat) && get_resource_type($stat) == "stream") {
  797. $stream = $stat;
  798. if (!empty($options["ranges"])) {
  799. // TODO multipart support is missing (see also above)
  800. // TODO error checking
  801. $stat = fseek($stream, $range[0]["start"], SEEK_SET);
  802. fwrite($stream, fread($options["stream"], $range[0]["end"]-$range[0]["start"]+1));
  803. } else {
  804. while (!feof($options["stream"])) {
  805. fwrite($stream, fread($options["stream"], 4096));
  806. }
  807. }
  808. fclose($stream);
  809. $stat = $options["new"] ? "201 Created" : "204 No Content";
  810. }
  811. $this->http_status($stat);
  812. } else {
  813. $this->http_status("423 Locked");
  814. }
  815. }
  816. // }}}
  817. // {{{ http_DELETE()
  818. function http_DELETE() {
  819. // RFC 2518 Section 9.2, last paragraph
  820. if (isset($_SERVER["HTTP_DEPTH"])) {
  821. if ($_SERVER["HTTP_DEPTH"] != "infinity") {
  822. $this->http_status("400 Bad Request");
  823. return;
  824. }
  825. }
  826. if ($this->_check_lock_status($this->path)) {
  827. $options = Array();
  828. $options["path"] = $this->path;
  829. $stat = $this->delete($options);
  830. $this->http_status($stat);
  831. } else {
  832. $this->http_status("423 Locked");
  833. }
  834. }
  835. // }}}
  836. // {{{ http_COPY()
  837. function http_COPY() {
  838. $this->_copymove("copy");
  839. }
  840. // }}}
  841. // {{{ http_MOVE()
  842. function http_MOVE() {
  843. if ($this->_check_lock_status($this->path)) {
  844. $this->_copymove("move");
  845. } else {
  846. $this->http_status("423 Locked");
  847. }
  848. }
  849. // }}}
  850. // {{{ http_LOCK()
  851. function http_LOCK() {
  852. $lockinfo = new _parse_lockinfo("php://input");
  853. if($this->_check_lock_status($this->path, $lockinfo->lockscope === "shared")) {
  854. $options = Array();
  855. $options["path"] = $this->path;
  856. if (isset($_SERVER['HTTP_DEPTH'])) {
  857. $options["depth"] = $_SERVER["HTTP_DEPTH"];
  858. } else {
  859. $options["depth"] = "infinity";
  860. }
  861. if (isset($_SERVER["HTTP_TIMEOUT"])) {
  862. $options["timeout"] = explode(",", $_SERVER["HTTP_TIMEOUT"]);
  863. }
  864. if(empty($_SERVER['CONTENT_LENGTH']) && !empty($_SERVER['HTTP_IF'])) {
  865. $options["update"] = substr($_SERVER['HTTP_IF'],2,-2);
  866. $stat = $this->lock($options);
  867. } else {
  868. // new lock
  869. if ($lockinfo->success) {
  870. $options["scope"] = $lockinfo->lockscope;
  871. $options["type"] = $lockinfo->locktype;
  872. $options["owner"] = $lockinfo->owner;
  873. }
  874. $options["locktoken"] = $this->_new_locktoken();
  875. $stat = $this->lock($options);
  876. }
  877. if(is_bool($stat)) {
  878. $http_stat = $stat ? "200 OK" : "423 Locked";
  879. } else {
  880. $http_stat = $stat;
  881. }
  882. $this->http_status($http_stat);
  883. if($options["timeout"]) {
  884. // more than a million is considered an absolute timestamp
  885. // less is more likely a relative value
  886. if($options["timeout"]>1000000) {
  887. $timeout = "Second-".($options['timeout']-time());
  888. } else {
  889. $timeout = "Second-$options[timeout]";
  890. }
  891. } else {
  892. $timeout = "Infinite";
  893. }
  894. if ($stat == true) { // ok
  895. header('Content-Type: text/xml; charset="utf-8"');
  896. header("Lock-Token: <$options[locktoken]>");
  897. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  898. echo "<D:prop xmlns:D=\"DAV:\">\n";
  899. echo " <D:lockdiscovery>\n";
  900. echo " <D:activelock>\n";
  901. echo " <D:lockscope><D:$options[scope]/></D:lockscope>\n";
  902. echo " <D:locktype><D:$options[type]/></D:locktype>\n";
  903. echo " <D:depth>$options[depth]</D:depth>\n";
  904. echo " <D:owner>$options[owner]</D:owner>\n";
  905. echo " <D:timeout>$timeout</D:timeout>\n";
  906. echo " <D:locktoken><D:href>$options[locktoken]</D:href></D:locktoken>\n";
  907. echo " </D:activelock>\n";
  908. echo " </D:lockdiscovery>\n";
  909. echo "</D:prop>\n\n";
  910. } else { // fail
  911. // TODO!!!
  912. }
  913. } else {
  914. $this->http_status("423 Locked");
  915. }
  916. }
  917. // }}}
  918. // {{{ http_UNLOCK()
  919. function http_UNLOCK() {
  920. $options = Array();
  921. $options["path"] = $this->path;
  922. if (isset($_SERVER['HTTP_DEPTH'])) {
  923. $options["depth"] = $_SERVER["HTTP_DEPTH"];
  924. } else {
  925. $options["depth"] = "infinity";
  926. }
  927. $options["token"] = substr($_SERVER["HTTP_LOCK_TOKEN"], 1, -1); // strip <>
  928. $stat = $this->unlock($options);
  929. $this->http_status($stat);
  930. }
  931. // }}}
  932. // }}}
  933. // {{{ _copymove()
  934. function _copymove($what) {
  935. $options = Array();
  936. $options["path"] = $this->path;
  937. if (isset($_SERVER["HTTP_DEPTH"])) {
  938. $options["depth"] = $_SERVER["HTTP_DEPTH"];
  939. } else {
  940. $options["depth"] = "infinity";
  941. }
  942. extract(parse_url($_SERVER["HTTP_DESTINATION"]));
  943. $http_host = $host;
  944. if (isset($port))
  945. $http_host.= ":$port";
  946. if ($http_host == $_SERVER["HTTP_HOST"] &&
  947. !strncmp($_SERVER["SCRIPT_NAME"], $path,
  948. strlen($_SERVER["SCRIPT_NAME"]))) {
  949. $options["dest"] = substr($path, strlen($_SERVER["SCRIPT_NAME"]));
  950. if (!$this->_check_lock_status($options["dest"])) {
  951. $this->http_status("423 Locked");
  952. return;
  953. }
  954. } else {
  955. $options["dest_url"] = $_SERVER["HTTP_DESTINATION"];
  956. }
  957. // see RFC 2518 Sections 9.6, 8.8.4 and 8.9.3
  958. if (isset($_SERVER["HTTP_OVERWRITE"])) {
  959. $options["overwrite"] = $_SERVER["HTTP_OVERWRITE"] == "T";
  960. } else {
  961. $options["overwrite"] = true;
  962. }
  963. $stat = $this->$what($options);
  964. $this->http_status($stat);
  965. }
  966. // }}}
  967. // {{{ _allow()
  968. /**
  969. * check for implemented HTTP methods
  970. *
  971. * check for implemented HTTP methods
  972. *
  973. * @param void
  974. * @returns array something
  975. */
  976. function _allow() {
  977. // OPTIONS is always there
  978. $allow = array("options" =>"OPTIONS");
  979. // all other METHODS need both a http_method() wrapper
  980. // and a method() implementation
  981. // the base class supplies wrappers only
  982. foreach(get_class_methods($this) as $method) {
  983. if (!strncmp("http_", $method, 5)) {
  984. $method = substr($method, 5);
  985. if (method_exists($this, $method)) {
  986. $allow[$method] = strtoupper($method);
  987. }
  988. }
  989. }
  990. // we can emulate a missing HEAD implemetation using GET
  991. if (isset($allow["get"]))
  992. $allow["head"] = "HEAD";
  993. // no LOCK without checklok()
  994. if (!method_exists($this, "checklock")) {
  995. unset($allow["lock"]);
  996. unset($allow["unlock"]);
  997. }
  998. return $allow;
  999. }
  1000. // }}}
  1001. function mkprop() {
  1002. $args = func_get_args();
  1003. if (count($args) == 3) {
  1004. return array("name" =>$args[1],
  1005. "ns" =>$args[0], "val" =>$args[2]);
  1006. } else {
  1007. return array("name" =>$args[0],
  1008. "ns" =>"DAV:", "val" =>$args[1]);
  1009. }
  1010. }
  1011. // {{{ _check_auth
  1012. function _check_auth() {
  1013. if (method_exists($this, "check_auth")) {
  1014. return $this->check_auth(@$_SERVER["AUTH_TYPE"],
  1015. @$_SERVER["PHP_AUTH_USER"],
  1016. @$_SERVER["PHP_AUTH_PW"]);
  1017. } else {
  1018. return true;
  1019. }
  1020. }
  1021. // }}}
  1022. // {{{ UUID stuff
  1023. function _new_uuid() {
  1024. if (function_exists("uuid_create")) {
  1025. return uuid_create();
  1026. }
  1027. // fallback
  1028. $uuid = md5(microtime().getmypid()); // this should be random enough for now
  1029. // set variant and version fields for 'true' random uuid
  1030. $uuid {
  1031. 12}
  1032. = "4";
  1033. $n = 8 + (ord($uuid {
  1034. 16}
  1035. ) & 3);
  1036. $hex = "0123456789abcdef";
  1037. $uuid {
  1038. 16}
  1039. = $hex {
  1040. $n};
  1041. // return formated uuid
  1042. return substr($uuid, 0, 8)."-".substr($uuid, 8, 4)."-".substr($uuid,
  1043. 12,
  1044. 4)."-".
  1045. substr($uuid, 16, 4)."-".substr($uuid, 20);
  1046. }
  1047. function _new_locktoken() {
  1048. return "opaquelocktoken:".$this->_new_uuid();
  1049. }
  1050. // }}}
  1051. // {{{ WebDAV If: header parsing
  1052. function _if_header_lexer($string,
  1053. &$pos) {
  1054. while (ctype_space($string{$pos}))
  1055. ++$pos; // skip whitespace
  1056. if (strlen($string) <= $pos)
  1057. return false;
  1058. $c = $string{$pos++};
  1059. switch ($c) {
  1060. case "<":
  1061. $pos2 = strpos($string, ">", $pos);
  1062. $uri = substr($string, $pos, $pos2 - $pos);
  1063. $pos = $pos2 + 1;
  1064. return array("URI", $uri);
  1065. case "[":
  1066. if ($string {
  1067. $pos}
  1068. == "W") {
  1069. $type = "ETAG_WEAK";
  1070. $pos += 2;
  1071. } else {
  1072. $type = "ETAG_STRONG";
  1073. }
  1074. $pos2 = strpos($string, "]", $pos);
  1075. $etag = substr($string, $pos + 1, $pos2 - $pos - 2);
  1076. $pos = $pos2 + 1;
  1077. return array($type, $etag);
  1078. case "N":
  1079. $pos += 2;
  1080. return array("NOT", "Not");
  1081. default:
  1082. return array("CHAR", $c);
  1083. }
  1084. }
  1085. /**
  1086. * parse If: header
  1087. *
  1088. * dispatch WebDAV HTTP request to the apropriate method handler
  1089. *
  1090. * @param $str
  1091. * @return void
  1092. */
  1093. function _if_header_parser($str) {
  1094. $pos = 0;
  1095. $len = strlen($str);
  1096. $uris = array();
  1097. while ($pos < $len) {
  1098. $token = $this->_if_header_lexer($str, $pos);
  1099. if ($token[0] == "URI") {
  1100. $uri = $token[1];
  1101. $token = $this->_if_header_lexer($str, $pos);
  1102. } else {
  1103. $uri = "";
  1104. }
  1105. if ($token[0] != "CHAR" || $token[1] != "(")
  1106. return false;
  1107. $list = array();
  1108. $level = 1;
  1109. $not = "";
  1110. while ($level) {
  1111. $token = $this->_if_header_lexer($str, $pos);
  1112. if ($token[0] == "NOT") {
  1113. $not = "!";
  1114. continue;
  1115. }
  1116. switch ($token[0]) {
  1117. case "CHAR":
  1118. switch ($token[1]) {
  1119. case "(":
  1120. $level++;
  1121. break;
  1122. case ")":
  1123. $level--;
  1124. break;
  1125. default:
  1126. return false;
  1127. }
  1128. break;
  1129. case "URI":
  1130. $list[] = $not."<$token[1]>";
  1131. break;
  1132. case "ETAG_WEAK":
  1133. $list[] = $not."[W/'$token[1]']>";
  1134. break;
  1135. case "ETAG_STRONG":
  1136. $list[] = $not."['$token[1]']>";
  1137. break;
  1138. default:
  1139. return false;
  1140. }
  1141. $not = "";
  1142. }
  1143. if (@is_array($uris[$uri]))
  1144. $uris[$uri] = array_merge($uris[$uri],$list);
  1145. else
  1146. $uris[$uri] = $list;
  1147. }
  1148. return $uris;
  1149. }
  1150. function _check_if_header_conditions() {
  1151. // see rfc 2518 sec. 9.4
  1152. if (isset($_SERVER["HTTP_IF"])) {
  1153. $this->_if_header_uris =
  1154. $this->_if_header_parser($_SERVER["HTTP_IF"]);
  1155. foreach($this->_if_header_uris as $uri => $conditions) {
  1156. if ($uri == "") {
  1157. // default uri is the complete request uri
  1158. $uri = (@$_SERVER["HTTPS"] === "on" ? "https:" : "http:");
  1159. $uri.=
  1160. "//$_SERVER[HTTP_HOST]$_SERVER[SCRIPT_NAME]$_SERVER[PATH_INFO]";
  1161. }
  1162. // all must match
  1163. $state = true;
  1164. foreach($conditions as $condition) {
  1165. // lock tokens may be free form (RFC2518 6.3)
  1166. // but if opatuelocktokens are used (RFC2518 6.4)
  1167. // we have to check the format (litmus tests this)
  1168. if (!strncmp($condition, "<opaquelocktoken:", strlen("<opaquelocktoken"))) {
  1169. if (!ereg("^<opaquelocktoken:[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}>$", $condition)) {
  1170. return false;
  1171. }
  1172. }
  1173. if (!$this->_check_uri_condition($uri, $condition)) {
  1174. $state = false;
  1175. break;
  1176. }
  1177. }
  1178. // any match is ok
  1179. if ($state == true)
  1180. return true;
  1181. }
  1182. return false;
  1183. }
  1184. return true;
  1185. }
  1186. /**
  1187. * Check a single URI condition parsed from an if-header
  1188. *
  1189. * Check a single URI condition parsed from an if-header
  1190. *
  1191. * @abstract
  1192. * @param string $uri URI to check
  1193. * @param string $condition Condition to check for this URI
  1194. * @returns bool Condition check result
  1195. */
  1196. function _check_uri_condition($uri, $condition) {
  1197. // not really implemented here,
  1198. // implementations must override
  1199. return true;
  1200. }
  1201. function _check_lock_status($path, $exclusive_only = false) {
  1202. // FIXME depth -> ignored for now
  1203. if (method_exists($this, "checklock")) {
  1204. // is locked?
  1205. $lock = $this->checklock($path);
  1206. // ... and lock is not owned?
  1207. if (is_array($lock) && count($lock)) {
  1208. // FIXME doesn't check uri restrictions yet
  1209. if (!strstr($_SERVER["HTTP_IF"], $lock["token"])) {
  1210. if (!$exclusive_only || ($lock["scope"] !== "shared"))
  1211. return false;
  1212. }
  1213. }
  1214. }
  1215. return true;
  1216. }
  1217. // }}}
  1218. function lockdiscovery($path) {
  1219. if (!method_exists($this, "checklock")) {
  1220. return "";
  1221. }
  1222. $lock = $this->checklock($path);
  1223. $activelocks = "";
  1224. if (is_array($lock) && count($lock)) {
  1225. if (!empty($lock["expires"])) {
  1226. $timeout = "Second-".($lock["expires"] - time());
  1227. } else if (!empty($lock["timeout"])) {
  1228. $timeout = "Second-$lock[timeout]";
  1229. } else {
  1230. $timeout = "Infinite";
  1231. }
  1232. $activelocks.= "
  1233. <D:activelock>
  1234. <D:lockscope><D:$lock[scope]/></D:lockscope>
  1235. <D:locktype><D:$lock[type]/></D:locktype>
  1236. <D:depth>$lock[depth]</D:depth>
  1237. <D:owner>$lock[owner]</D:owner>
  1238. <D:timeout>$timeout</D:timeout>
  1239. <D:locktoken><D:href>$lock[token]</D:href></D:locktoken>
  1240. </D:activelock>
  1241. ";
  1242. }
  1243. return $activelocks;
  1244. }
  1245. function http_status($status) {
  1246. if($status === true) $status = "200 OK";
  1247. $this->_http_status = $status;
  1248. header("HTTP/1.1 $status");
  1249. header("X-WebDAV-Status: $status");
  1250. }
  1251. function _urlencode($path, $for_html=false) {
  1252. $return = strtr($path,array(" "=>"%20",
  1253. "&"=>"%26",
  1254. "<"=>"%3C",
  1255. ">"=>"%3E",
  1256. ));
  1257. if ($for_html) {
  1258. $return = str_replace("'", "%27", $return);
  1259. }
  1260. return $return;
  1261. }
  1262. function _urldecode($path) {
  1263. return urldecode($path);
  1264. }
  1265. function prop_encode($text) {
  1266. switch ($this->_prop_encoding) {
  1267. case "utf-8":
  1268. return $text;
  1269. default:
  1270. return utf8_encode($text);
  1271. }
  1272. }
  1273. }
  1274. /*
  1275. * Local variables:
  1276. * tab-width: 4
  1277. * c-basic-offset: 4
  1278. * End:
  1279. */
  1280. ?>