propagate base_uri and debug level to handlers

This commit is contained in:
Ralf Becker 2008-05-17 12:54:26 +00:00
parent 9008414fff
commit a659e4eb6b
4 changed files with 72 additions and 46 deletions

View File

@ -78,7 +78,7 @@ class groupdav extends HTTP_WebDAV_Server
function __construct()
{
if ($this->debug > 2) foreach($_SERVER as $name => $val) error_log("groupdav: \$_SERVER[$name]='$val'");
if ($this->debug > 2) error_log('groupdav: $_SERVER='.array2string($_SERVER));
parent::HTTP_WebDAV_Server();
@ -86,9 +86,15 @@ class groupdav extends HTTP_WebDAV_Server
$this->egw_charset = $this->translation->charset();
}
function _instancicate_handler($app)
/**
* get the handler for $app
*
* @param string $app
* @return groupdav_handler
*/
function app_handler($app)
{
$this->handler = groupdav_handler::app_handler($app);
return groupdav_handler::app_handler($app,$this->debug,$this->base_uri);
}
/**
@ -123,7 +129,7 @@ class groupdav extends HTTP_WebDAV_Server
*/
function PROPFIND(&$options, &$files,$method='PROPFIND')
{
if ($this->debug) error_log(__CLASS__."::$method(".str_replace(array("\n",' ',"\t"),'',print_r($options,true)).')');
if ($this->debug) error_log(__CLASS__."::$method(".array2string($options,true).')');
// parse path in form [/account_lid]/app[/more]
if (!self::_parse_path($options['path'],$id,$app,$user) && $app && !$user)
@ -185,10 +191,10 @@ class groupdav extends HTTP_WebDAV_Server
}
if (!in_array($app,array('principals','groups')) && !$GLOBALS['egw_info']['user']['apps'][$app])
{
error_log(__CLASS__."::$method(path=$options[path]) 403 Forbidden: no app rights for '$app'");
return '403 Forbidden'; // no rights for the given app
if ($this->debug) error_log(__CLASS__."::$method(path=$options[path]) 403 Forbidden: no app rights for '$app'");
return "403 Forbidden: no app rights for '$app'"; // no rights for the given app
}
if (($handler = groupdav_handler::app_handler($app,$this->debug)))
if (($handler = self::app_handler($app)))
{
if ($method != 'REPORT' && !$id) // no self URL for REPORT requests (only PROPFIND) or propfinds on an id
{
@ -243,7 +249,7 @@ class groupdav extends HTTP_WebDAV_Server
*/
function REPORT(&$options, &$files)
{
if ($this->debug > 1) error_log(__METHOD__.'('.str_replace(array("\n",' '),'',print_r($options,true)).')');
if ($this->debug > 1) error_log(__METHOD__.'('.array2string($options).')');
return $this->PROPFIND($options,$files,'REPORT');
}
@ -266,13 +272,13 @@ class groupdav extends HTTP_WebDAV_Server
*/
function GET(&$options)
{
if ($this->debug) error_log(__METHOD__.'('.print_r($options,true).')');
if ($this->debug) error_log(__METHOD__.'('.array2string($options).')');
if (!$this->_parse_path($options['path'],$id,$app,$user))
{
return '404 Not Found';
}
if (($handler = groupdav_handler::app_handler($app,$this->debug)))
if (($handler = self::app_handler($app)))
{
return $handler->get($options,$id);
}
@ -296,13 +302,13 @@ class groupdav extends HTTP_WebDAV_Server
$options['content'] .= fread($options['stream'],8192);
}
}
if ($this->debug) error_log(__METHOD__.'('.print_r($options,true).')');
if ($this->debug) error_log(__METHOD__.'('.array2string($options).')');
if (!$this->_parse_path($options['path'],$id,$app,$user))
{
return '404 Not Found';
}
if (($handler = groupdav_handler::app_handler($app,$this->debug)))
if (($handler = self::app_handler($app)))
{
$status = $handler->put($options,$id,$user);
// set default stati: true --> 204 No Content, false --> should be already handled
@ -320,13 +326,13 @@ class groupdav extends HTTP_WebDAV_Server
*/
function DELETE($options)
{
if ($this->debug) error_log(__METHOD__.'('.print_r($options,true).')');
if ($this->debug) error_log(__METHOD__.'('.array2string($options).')');
if (!$this->_parse_path($options['path'],$id,$app,$user))
{
return '404 Not Found';
}
if (($handler = groupdav_handler::app_handler($app,$this->debug)))
if (($handler = self::app_handler($app)))
{
$status = $handler->delete($options,$id);
// set default stati: true --> 204 No Content, false --> should be already handled
@ -344,7 +350,7 @@ class groupdav extends HTTP_WebDAV_Server
*/
function MKCOL($options)
{
if ($this->debug) error_log(__METHOD__.'('.print_r($options,true).')');
if ($this->debug) error_log(__METHOD__.'('.array2string($options).')');
return '501 Not Implemented';
}
@ -357,7 +363,7 @@ class groupdav extends HTTP_WebDAV_Server
*/
function MOVE($options)
{
if ($this->debug) error_log(__METHOD__.'('.print_r($options,true).')');
if ($this->debug) error_log(__METHOD__.'('.array2string($options).')');
return '501 Not Implemented';
}
@ -370,7 +376,7 @@ class groupdav extends HTTP_WebDAV_Server
*/
function COPY($options, $del=false)
{
if ($this->debug) error_log('groupdav::'.($del ? 'MOVE' : 'COPY').'('.print_r($options,true).')');
if ($this->debug) error_log('groupdav::'.($del ? 'MOVE' : 'COPY').'('.array2string($options).')');
return '501 Not Implemented';
}
@ -383,13 +389,13 @@ class groupdav extends HTTP_WebDAV_Server
*/
function LOCK(&$options)
{
error_log(__METHOD__.'('.str_replace(array("\n",' '),'',print_r($options,true)).')');
self::_parse_path($options['path'],$id,$app,$user);
$path = egw_vfs::app_entry_lock_path($app,$id);
if ($this->debug) error_log(__METHOD__.'('.array2string($options).") path=$path");
// get the app handler, to check if the user has edit access to the entry (required to make locks)
$handler = groupdav_handler::app_handler($app);
$handler = self::app_handler($app);
// TODO recursive locks on directories not supported yet
if (!$id || !empty($options['depth']) || !$handler->check_access(EGW_ACL_EDIT,$id))
@ -419,7 +425,7 @@ class groupdav extends HTTP_WebDAV_Server
self::_parse_path($options['path'],$id,$app,$user);
$path = egw_vfs::app_entry_lock_path($app,$id);
error_log(__METHOD__.'('.str_replace(array("\n",' '),'',print_r($options,true)).") path=$path");
if ($this->debug) error_log(__METHOD__.'('.array2string($options).") path=$path");
return egw_vfs::unlock($path,$options['token']) ? '204 No Content' : '409 Conflict';
}
@ -471,7 +477,7 @@ class groupdav extends HTTP_WebDAV_Server
}
if (!($ok = $id && in_array($app,array('addressbook','calendar','infolog','principals','groups')) && $user))
{
error_log(__METHOD__."('$path') returning false: id=$id, app='$app', user=$user");
if ($this->debug) error_log(__METHOD__."('$path') returning false: id=$id, app='$app', user=$user");
}
return $ok;
}

View File

@ -26,12 +26,13 @@ class groupdav_groups extends groupdav_handler
/**
* Constructor
*
* @param string $app
* @param int $debug=null
* @param string $app 'calendar', 'addressbook' or 'infolog'
* @param int $debug=null debug-level to set
* @param string $base_uri=null base url of handler
*/
function __construct($app,$debug=null)
function __construct($app,$debug=null,$base_uri=null)
{
parent::__construct($app,$debug);
parent::__construct($app,$debug,$base_uri);
$this->accounts = $GLOBALS['egw']->accounts;
}
@ -55,19 +56,19 @@ class groupdav_groups extends groupdav_handler
HTTP_WebDAV_Server::mkprop('getetag',$this->get_etag($account)),
HTTP_WebDAV_Server::mkprop('resourcetype','principal'),
HTTP_WebDAV_Server::mkprop('alternate-URI-set',''),
HTTP_WebDAV_Server::mkprop('principal-URL',$_SERVER['SCRIPT_NAME'].'/groups/'.$account['account_lid']),
HTTP_WebDAV_Server::mkprop(groupdav::CALDAV,'calendar-home-set',$_SERVER['SCRIPT_NAME'].'/calendar/'),
HTTP_WebDAV_Server::mkprop('principal-URL',$this->base_uri.'/groups/'.$account['account_lid']),
HTTP_WebDAV_Server::mkprop(groupdav::CALDAV,'calendar-home-set',$this->base_uri.'/calendar/'),
);
foreach($this->accounts->members($account['account_id']) as $uid => $user)
{
$props[] = HTTP_WebDAV_Server::mkprop('group-membership',$_SERVER['SCRIPT_NAME'].'/principals/'.$user);
$props[] = HTTP_WebDAV_Server::mkprop('group-membership',$this->base_uri.'/principals/'.$user);
}
$files['files'][] = array(
'path' => '/groups/'.$account['account_lid'],
'props' => $props,
);
if ($this->debug > 1) error_log(__METHOD__."($path) path=/principals/".$account['account_lid'].', props='.array2string($props));
}
//error_log(__METHOD__."($path,,,$user) files=".array2string($files['files']));
return true;
}
@ -85,7 +86,7 @@ class groupdav_groups extends groupdav_handler
return $account;
}
$options['data'] = 'Principal: '.$account['account_lid'].
"\nURL: ".$_SERVER['SCRIPT_NAME'].$options['path'].
"\nURL: ".$this->base_uri.$options['path'].
"\nName: ".lang('Group').' '.$account['account_lid'].
($account['account_email'] ? "\nEmail: ".$account['account_email'] : '').
"\nMembers: ".implode(', ',$this->accounts->members($id))."\n";

View File

@ -23,7 +23,7 @@ abstract class groupdav_handler
*
* @var integer
*/
var $debug = 1;
var $debug = 0;
/**
* eGW's charset
@ -53,6 +53,12 @@ abstract class groupdav_handler
* @var string
*/
var $app;
/**
* Base url of handler, need to prefix all pathes not automatic handled by HTTP_WebDAV_Server
*
* @var string
*/
var $base_uri;
/**
* HTTP_IF_MATCH / etag of current request / last call to _common_get_put_delete() method
*
@ -63,13 +69,15 @@ abstract class groupdav_handler
/**
* Constructor
*
* @param string $app
* @param int $debug=null
* @param string $app 'calendar', 'addressbook' or 'infolog'
* @param int $debug=null debug-level to set
* @param string $base_uri=null base url of handler
*/
function __construct($app,$debug=null)
function __construct($app,$debug=null,$base_uri=null)
{
$this->app = $app;
if (!is_null($debug)) $this->debug = $debug;
$this->base_uri = is_null($base_uri) ? $base_uri : $_SERVER['SCRIPT_NAME'];
$this->translation =& $GLOBALS['egw']->translation;
$this->egw_charset = $this->translation->charset();
@ -156,6 +164,7 @@ abstract class groupdav_handler
}
if (!is_array($entry) || !isset($entry['id']) || !(isset($entry['modified']) || isset($entry['etag'])))
{
error_log(__METHOD__."(".array2string($entry).") Cant create etag!");
return false;
}
return '"'.$entry['id'].':'.(isset($entry['etag']) ? $entry['etag'] : $entry['modified']).'"';
@ -183,9 +192,10 @@ abstract class groupdav_handler
* @param string $method GET, PUT, DELETE
* @param array &$options
* @param int $id
* @param boolean &$return_no_access=false if set to true on call, instead of '403 Forbidden' the entry is returned and $return_no_access===false
* @return array/string entry on success, string with http-error-code on failure, null for PUT on an unknown id
*/
function _common_get_put_delete($method,&$options,$id)
function _common_get_put_delete($method,&$options,$id,&$return_no_access=false)
{
if (!in_array($this->app,array('principals','groups')) && !$GLOBALS['egw_info']['user']['apps'][$this->app])
{
@ -196,8 +206,16 @@ abstract class groupdav_handler
if (!($entry = $this->read($id)) && ($method != 'PUT' || $event === false) ||
($extra_acl != EGW_ACL_READ && $this->check_access($extra_acl,$entry) === false))
{
if ($this->debug) error_log(__METHOD__."($method,,$id) 403 Forbidden/404 Not Found: read($id)==".($entry===false?'false':'null'));
return !is_null($entry) ? '403 Forbidden' : '404 Not Found';
if ($return_no_access && !is_null($entry))
{
if ($this->debug) error_log(__METHOD__."($method,,$id,$return_no_access) is_null(\$entry)=".(int)is_null($entry).", set to false");
$return_no_access = false;
}
else
{
if ($this->debug) error_log(__METHOD__."($method,,$id) 403 Forbidden/404 Not Found: read($id)==".($entry===false?'false':'null'));
return !is_null($entry) ? '403 Forbidden' : '404 Not Found';
}
}
if ($entry)
{
@ -225,9 +243,10 @@ abstract class groupdav_handler
* @static
* @param string $app 'calendar', 'addressbook' or 'infolog'
* @param int $debug=null debug-level to set
* @param string $base_uri=null base url of handler
* @return groupdav_handler
*/
static function &app_handler($app,$debug=null)
static function &app_handler($app,$debug=null,$base_uri=null)
{
static $handler_cache = array();
@ -236,7 +255,7 @@ abstract class groupdav_handler
$class = $app.'_groupdav';
if (!class_exists($class) && !class_exists($class = 'groupdav_'.$app)) return null;
$handler_cache[$app] = new $class($app);
$handler_cache[$app] = new $class($app,$debug,$base_uri);
}
return $handler_cache[$app];
}

View File

@ -26,12 +26,13 @@ class groupdav_principals extends groupdav_handler
/**
* Constructor
*
* @param string $app
* @param int $debug=null
* @param string $app 'calendar', 'addressbook' or 'infolog'
* @param int $debug=null debug-level to set
* @param string $base_uri=null base url of handler
*/
function __construct($app,$debug=null)
function __construct($app,$debug=null,$base_uri=null)
{
parent::__construct($app,$debug);
parent::__construct($app,$debug,$base_uri);
$this->accounts = $GLOBALS['egw']->accounts;
}
@ -71,9 +72,8 @@ class groupdav_principals extends groupdav_handler
'path' => '/principals/'.$account['account_lid'],
'props' => $props,
);
error_log(__METHOD__."($path) path=/principals/".$account['account_lid'].', props='.array2string($props));
if ($this->debug > 1) error_log(__METHOD__."($path) path=/principals/".$account['account_lid'].', props='.array2string($props));
}
//error_log(__METHOD__."($path,,,$user) files=".array2string($files['files']));
return true;
}