* @copyright Catalyst .Net Ltd * @license http://gnu.org/copyleft/gpl.html GNU GPL v2 */ require_once("XMLElement.php"); define('DEPTH_INFINITY', 9999); /** * A class for collecting things to do with this request. * * @package rscds */ class CalDAVRequest { var $options; /** * 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 $principal; /** * Create a new CalDAVRequest object. */ function CalDAVRequest( $options = array() ) { global $session, $c, $debugging; $this->options = $options; $this->principal = (object) array( 'username' => $session->username, 'user_no' => $session->user_no ); $this->raw_post = file_get_contents ( 'php://input'); if ( isset($debugging) && isset($_GET['method']) ) { $_SERVER['REQUEST_METHOD'] = $_GET['method']; } $this->method = $_SERVER['REQUEST_METHOD']; /** * 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 = max( intval(substr($v,7)), (isset($c->maximum_lock_timeout) ? $c->maximum_lock_timeout : 86400 * 100) ); break; } } if ( ! isset($this->timeout) ) $this->timeout = (isset($c->default_lock_timeout) ? $c->default_lock_timeout : 900); } /** * Our path is /