* @copyright Catalyst .Net Ltd * @license http://gnu.org/copyleft/gpl.html GNU GPL v2 */ require_once("XMLElement.php"); require_once("CalDAVPrincipal.php"); define('DEPTH_INFINITY', 9999); /** * A class for collecting things to do with this request. * * @package davical */ class CalDAVRequest { var $options; /** * The raw data sent along with the request */ var $raw_post; /** * The HTTP request method: PROPFIND, LOCK, REPORT, OPTIONS, etc... */ var $method; /** * The depth parameter from the request headers, coerced into a valid integer: 0, 1 * or DEPTH_INFINITY which is defined above. The default is set per various RFCs. */ var $depth; /** * The 'principal' (user/resource/...) which this request seeks to access * @var CalDAVPrincipal */ var $principal; /** * The 'current_user_principal_xml' the DAV:current-user-principal answer. An * XMLElement object with an or fragment. */ var $current_user_principal_xml; /** * The user agent making the request. */ var $user_agent; /** * The ID of the collection containing this path, or of this path if it is a collection */ var $collection_id; /** * The path corresponding to the collection_id */ var $collection_path; /** * The type of collection being requested: * calendar, schedule-inbox, schedule-outbox */ var $collection_type; /** * Create a new CalDAVRequest object. */ function CalDAVRequest( $options = array() ) { global $session, $c, $debugging; $this->options = $options; if ( !isset($this->options['allow_by_email']) ) $this->options['allow_by_email'] = false; $this->principal = (object) array( 'username' => $session->username, 'user_no' => $session->user_no ); $this->raw_post = file_get_contents ( 'php://input'); if ( (isset($c->dbg['ALL']) && $c->dbg['ALL']) || (isset($c->dbg['request']) && $c->dbg['request']) ) { /** Log the request headers */ $lines = apache_request_headers(); dbg_error_log( "LOG ", "***************** Request Header ****************" ); dbg_error_log( "LOG ", "%s %s", $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'] ); foreach( $lines AS $k => $v ) { dbg_error_log( "LOG headers", "-->%s: %s", $k, $v ); } dbg_error_log( "LOG ", "******************** Request ********************" ); // Log the request in all it's gory detail. $lines = preg_split( '#[\r\n]+#', $this->raw_post); foreach( $lines AS $v ) { dbg_error_log( "LOG request", "-->%s", $v ); } } if ( isset($debugging) && isset($_GET['method']) ) { $_SERVER['REQUEST_METHOD'] = $_GET['method']; } $this->method = $_SERVER['REQUEST_METHOD']; $this->user_agent = ((isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "Probably Mulberry")); /** * A variety of requests may set the "Depth" header to control recursion */ if ( isset($_SERVER['HTTP_DEPTH']) ) { $this->depth = $_SERVER['HTTP_DEPTH']; } else { /** * Per rfc2518, section 9.2, 'Depth' might not always be present, and if it * is not present then a reasonable request-type-dependent default should be * chosen. */ switch( $this->method ) { case 'PROPFIND': case 'DELETE': case 'MOVE': case 'COPY': case 'LOCK': $this->depth = 'infinity'; break; case 'REPORT': default: $this->depth = 0; } } if ( $this->depth == 'infinity' ) $this->depth = DEPTH_INFINITY; $this->depth = intval($this->depth); /** * MOVE/COPY use a "Destination" header and (optionally) an "Overwrite" one. */ if ( isset($_SERVER['HTTP_DESTINATION']) ) $this->destination = $_SERVER['HTTP_DESTINATION']; $this->overwrite = ( isset($_SERVER['HTTP_OVERWRITE']) ? $_SERVER['HTTP_OVERWRITE'] : 'T' ); // RFC2518, 9.6 says default True. /** * LOCK things use an "If" header to hold the lock in some cases, and "Lock-token" in others */ if ( isset($_SERVER['HTTP_IF']) ) $this->if_clause = $_SERVER['HTTP_IF']; if ( isset($_SERVER['HTTP_LOCK_TOKEN']) && preg_match( '#[<]opaquelocktoken:(.*)[>]#', $_SERVER['HTTP_LOCK_TOKEN'], $matches ) ) { $this->lock_token = $matches[1]; } /** * LOCK things use a "Timeout" header to set a series of reducing alternative values */ if ( isset($_SERVER['HTTP_TIMEOUT']) ) { $timeouts = split( ',', $_SERVER['HTTP_TIMEOUT'] ); foreach( $timeouts AS $k => $v ) { if ( strtolower($v) == 'infinite' ) { $this->timeout = (isset($c->maximum_lock_timeout) ? $c->maximum_lock_timeout : 86400 * 100); break; } elseif ( strtolower(substr($v,0,7)) == 'second-' ) { $this->timeout = min( intval(substr($v,7)), (isset($c->maximum_lock_timeout) ? $c->maximum_lock_timeout : 86400 * 100) ); break; } } if ( ! isset($this->timeout) || $this->timeout == 0 ) $this->timeout = (isset($c->default_lock_timeout) ? $c->default_lock_timeout : 900); } /** * Our path is /