p4DAV.php #13

  • //
  • guest/
  • daniel_sabsay/
  • p4dav/
  • p4DAV.php
  • View
  • Commits
  • Open Download .zip Download (4 KB)
<?php
//=========================================================
// p4DAV.php  Implements a Perforce WebDAV server
//=========================================================
//
// +----------------------------------------------------------------+
// | PHP Version 4 and 5                                            |
// +----------------------------------------------------------------+
// | Author: Daniel Sabsay <danielsabsay@pacbell.net>  [Jan. 2005]  |
// | Derived from the open source HTTP_WebDAV_Server class (0.99.1) |
// | Original Name = davserver.php                                  |
// |      by: Hartmut Holzgraefe <hholzgra@php.net>                 |
// |          Christian Stocker <chregu@bitflux.ch>                 |
// +----------------------------------------------------------------+
//
// Runs as a helper for Apache HTTP requests of this pattern...
//       http://[thisdomain]/p4/[Perforce path without initial //]
// Requires a directory for temporary files (set below).
// Requires the service of the Perforce command-line client P4.
// Triggered by the following directive included in Apache's conf.ini file...
//       AliasMatch ^/p4.*  [mydir]/p4DAV.php
// Serves a single Perforce repository whose IP address is specified below
// Resides in a directory [mydir] with these companion files...
// 1) p4DAV.php [this file] (heavily modified from davserver.php)
// 2) DepotServer.php  (heavily modified from FileSystem.php)
// 3) DAVServer.php  (derived with slight mods from Server.php)
// 4) Tools  (a directory, unmodified from open-source distribution) containing...
//  4.1) _parse_lockinfo.php
//  4.2) _parse_propfind.php
//  4.3) _parse_proppatch.php
//**********************************************************
// You must edit the section below to your specifications
//**********************************************************
$prefix = '/p4';  //  Webserver DAV trigger prefix (Apache AliasMatch)
$base = $_SERVER['DOCUMENT_ROOT'].'/davroot/';// temporary file directory
$depot_host = 'localhost';              // Perforce repository
$depot_port = '1666';                   // Perforce contact port
$depot_agent = '/usr/local/bin/p4';     // Perforce command-line client
$admin_user = ' ';          // Perforce admin user
$admin_passwd = ' ';        // Perforce admin password
$logging = 1;    // Log level: 0=errors, 1=connections, 2=details, 3=debug
//***************************************************************************

require_once realpath('.').'/DepotServer.php';
$URI = $_SERVER['REQUEST_URI'];
$path = (strlen($URI)>strlen($prefix))? substr($URI,strlen($prefix)):'/';
$method = strtoupper($_SERVER['REQUEST_METHOD']);

// PHP messages destroy XML output, so switch them off
ini_set('display_errors', E_USER_NOTICE);

//*********************************
//   BASIC  CONNECTION  HEADER
//*********************************
if ($logging>0) {
  error_log('DAV REQ - repository='.$depot_host.':'.$depot_port.' log level = '.$logging);
  error_log($method.'=>'.$path.' '.strftime('%c',time()));
  $request_hdrs = apache_request_headers();
  unset($request_hdrs['Accept-Language']);  // suppress junk
  $log = ''; foreach ($request_hdrs as $k=>$v) { $log .= $k.'='.$v.'--'; }
  error_log($log);
}
//*********************************
//   CONFIGURE SERVER INSTANCE
//*********************************
$P = new Depot_Filesystem; // instantiate server class
$P->prefix = $prefix;
$P->base = $base;
$P->path = $path;
$P->logging = $logging;
$P->depot_host = $depot_host;
$P->depot_port = $depot_port;
$P->depot_agent = $depot_agent;
$P->admin_user = $admin_user; // used for deleting faux directory placeholders
$P->admin_passwd = $admin_passwd;

//******************
//   INVOKE SERVER
//******************
$P->ServeRequest($method);
flush();  // release any buffered output to client

//*********************************
//   BASIC  CONNECTION  TRAILER
//*********************************
if ($logging>0) {
  error_log('DAV RESPONSE');
  $response_hdrs = apache_response_headers();
  $log = ''; foreach ($response_hdrs as $k=>$v) { $log .= $k.'='.$v.'--'; }
  error_log($log);
}
?>
# Change User Description Committed
#13 4802 Daniel Sabsay Change default repository address to "localhost"
#12 4801 Daniel Sabsay Copyright and default user name cleaned up
#11 4800 Daniel Sabsay Final documentation update
GET method updated
Log now reports depot host & port being served
#10 4799 Daniel Sabsay Remove otiose debug logging code
#9 4796 Daniel Sabsay Cosmetic change to log mechanism
#8 4779 Daniel Sabsay A few bugs chased
#7 4778 Daniel Sabsay Improvements in logging (now shows response headers)
Change in directory searching mechanism
Now appropriately handles If-Modified-Since headers
#6 4774 Daniel Sabsay Repackaged functions all working
#5 4750 Daniel Sabsay Mac Finder can now mount the root (repository) level.
Directory last-modified dates are now retrieved.
Full log implementation now shows both sides of dialog.
#4 4749 Daniel Sabsay The code now uses no persistant workspaces or changelists.
Switched the faux directory mechanism to use deleted placeholder files.
Switched the logging mechanism to use the webserver logging methods.
#3 4725 Daniel Sabsay Changes to the DELETE and LIST logic
#2 4717 Daniel Sabsay Updated and clarified the Read Me section
#1 4711 Daniel Sabsay PUT works for first time