From bfbf37ce80786f3a0d6c904509cc27d53698dd52 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 10 Jul 2009 15:51:40 -0600 Subject: [PATCH] PHP 5 conversions for Horde_Registry Move some session code from Horde:: to Horde_Registry::. --- framework/Auth/lib/Horde/Auth.php | 7 +- framework/Auth/lib/Horde/Auth/Application.php | 12 +- framework/Core/lib/Horde.php | 75 ---------- framework/Core/lib/Horde/Config.php | 24 ++-- framework/Core/lib/Horde/Menu.php | 7 +- framework/Core/lib/Horde/Registry.php | 160 +++++++++++++++------ framework/Core/lib/Horde/Registry/Caller.php | 2 + framework/Mime/lib/Horde/Mime/Viewer/Vcard.php | 16 +-- framework/Rpc/lib/Horde/Rpc/Jsonrpc.php | 7 +- framework/Rpc/lib/Horde/Rpc/Webdav.php | 136 ++++++++++-------- framework/Rpc/lib/Horde/Rpc/Xmlrpc.php | 9 +- .../Text_Filter/lib/Horde/Text/Filter/Emails.php | 9 +- 12 files changed, 236 insertions(+), 228 deletions(-) diff --git a/framework/Auth/lib/Horde/Auth.php b/framework/Auth/lib/Horde/Auth.php index 8a5695a14..b1dfea29c 100644 --- a/framework/Auth/lib/Horde/Auth.php +++ b/framework/Auth/lib/Horde/Auth.php @@ -331,9 +331,10 @@ class Horde_Auth $errApps = array(); foreach ($GLOBALS['registry']->listApps(array('notoolbar', 'hidden', 'active', 'admin')) as $app) { - if ($GLOBALS['registry']->hasMethod('removeUserData', $app) && - is_a($result = $GLOBALS['registry']->callByPackage($app, 'removeUserData', array($userId)), 'PEAR_Error')) { - Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); + try { + $GLOBALS['registry']->callByPackage($app, 'removeUserData', array($userId)); + } catch (Horde_Exception $e) { + Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); $errApps[] = $app; } } diff --git a/framework/Auth/lib/Horde/Auth/Application.php b/framework/Auth/lib/Horde/Auth/Application.php index 392426274..c3d161871 100644 --- a/framework/Auth/lib/Horde/Auth/Application.php +++ b/framework/Auth/lib/Horde/Auth/Application.php @@ -81,7 +81,11 @@ class Horde_Auth_Application extends Horde_Auth_Driver throw new Horde_Exception($this->_params['app'] . ' does not provide an authenticate() method.'); } - if (!$GLOBALS['registry']->callByPackage($this->_params['app'], 'authenticate', array('userId' => $userId, 'credentials' => $credentials, 'params' => $this->_params))) { + try { + if (!$GLOBALS['registry']->callByPackage($this->_params['app'], 'authenticate', array('userId' => $userId, 'credentials' => $credentials, 'params' => $this->_params))) { + throw new Horde_Exception('', Horde_Auth::REASON_BADLOGIN); + } + } catch (Horde_Exception $e) { throw new Horde_Exception('', Horde_Auth::REASON_BADLOGIN); } @@ -185,11 +189,7 @@ class Horde_Auth_Application extends Horde_Auth_Driver public function removeUser($userId) { if ($this->hasCapability('remove')) { - $res = $GLOBALS['registry']->callByPackage($this->_params['app'], 'removeUser', array($userId)); - if (is_a($res, 'PEAR_Error')) { - throw new Horde_Exception($result); - } - + $GLOBALS['registry']->callByPackage($this->_params['app'], 'removeUser', array($userId)); Horde_Auth::removeUserData($userId); } else { parent::removeUser($userId); diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index c0f17c7f8..6f758e0e1 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -162,28 +162,6 @@ class Horde } /** - * Destroys any existing session on login and make sure to use a new - * session ID, to avoid session fixation issues. Should be called before - * checking a login. - */ - static public function getCleanSession() - { - // Make sure to force a completely new session ID and clear all - // session data. - session_regenerate_id(true); - session_unset(); - - /* Reset cookie timeouts, if necessary. */ - if (!empty($GLOBALS['conf']['session']['timeout'])) { - $app = $GLOBALS['registry']->getApp(); - if (Horde_Secret::clearKey($app)) { - Horde_Secret::setKey($app); - } - Horde_Secret::setKey('auth'); - } - } - - /** * Aborts with a fatal error, displaying debug information to the user. * * @param mixed $error Either a string or an object with a getMessage() @@ -1634,59 +1612,6 @@ HTML; } /** - * Sets a custom session handler up, if there is one. - * If the global variable 'session_cache_limiter' is defined, its value - * will override the cache limiter setting found in the configuration - * file. - * - * The custom session handler object will be contained in the global - * 'horde_sessionhandler' variable. - */ - static public function setupSessionHandler() - { - global $conf; - - ini_set('url_rewriter.tags', 0); - if (!empty($conf['session']['use_only_cookies'])) { - ini_set('session.use_only_cookies', 1); - if (!empty($conf['cookie']['domain']) && - strpos($conf['server']['name'], '.') === false) { - self::fatal('Session cookies will not work without a FQDN and with a non-empty cookie domain. Either use a fully qualified domain name like "http://www.example.com" instead of "http://example" only, or set the cookie domain in the Horde configuration to an empty value, or enable non-cookie (url-based) sessions in the Horde configuration.', __FILE__, __LINE__); - } - } - - session_set_cookie_params($conf['session']['timeout'], - $conf['cookie']['path'], $conf['cookie']['domain'], $conf['use_ssl'] == 1 ? 1 : 0); - session_cache_limiter(Horde_Util::nonInputVar('session_cache_limiter', $conf['session']['cache_limiter'])); - session_name(urlencode($conf['session']['name'])); - - $type = !empty($conf['sessionhandler']['type']) ? $conf['sessionhandler']['type'] : 'none'; - if ($type == 'external') { - $calls = $conf['sessionhandler']['params']; - session_set_save_handler($calls['open'], - $calls['close'], - $calls['read'], - $calls['write'], - $calls['destroy'], - $calls['gc']); - } elseif ($type != 'none') { - try { - $sh = &Horde_SessionHandler::singleton($conf['sessionhandler']['type'], array_merge(self::getDriverConfig('sessionhandler', $conf['sessionhandler']['type']), array('memcache' => !empty($conf['sessionhandler']['memcache'])))); - ini_set('session.save_handler', 'user'); - session_set_save_handler(array(&$sh, 'open'), - array(&$sh, 'close'), - array(&$sh, 'read'), - array(&$sh, 'write'), - array(&$sh, 'destroy'), - array(&$sh, 'gc')); - $GLOBALS['horde_sessionhandler'] = $sh; - } catch (Horde_Exception $e) { - self::fatal(new Horde_Exception('Horde is unable to correctly start the custom session handler.'), __FILE__, __LINE__, false); - } - } - } - - /** * Returns an un-used access key from the label given. * * @param string $label The label to choose an access key from. diff --git a/framework/Core/lib/Horde/Config.php b/framework/Core/lib/Horde/Config.php index d35b819eb..2961fc8a3 100644 --- a/framework/Core/lib/Horde/Config.php +++ b/framework/Core/lib/Horde/Config.php @@ -1367,21 +1367,27 @@ class Horde_Config $f = array(); if ($GLOBALS['registry']->hasMethod('clients/getClientSource')) { $addressbook = $GLOBALS['registry']->call('clients/getClientSource'); - $fields = $GLOBALS['registry']->call('clients/clientFields', array($addressbook)); - if ($fields instanceof PEAR_Error) { - $fields = $GLOBALS['registry']->call('clients/fields', array($addressbook)); - } - if (!$fields instanceof PEAR_Error) { - foreach ($fields as $field) { - $f[$field['name']] = $field['label']; + try { + $fields = $GLOBALS['registry']->call('clients/clientFields', array($addressbook)); + } catch (Horde_Exception $e) { + try { + $fields = $GLOBALS['registry']->call('clients/fields', array($addressbook)); + } catch (Horde_Exception $e) { + $fields = array(); } } + + foreach ($fields as $field) { + $f[$field['name']] = $field['label']; + } } return $f; case 'list-contact-sources': - $res = $GLOBALS['registry']->call('contacts/sources'); - return $res; + try { + return $GLOBALS['registry']->call('contacts/sources'); + } catch (Horde_Exception $e) {} + break; } return array(); diff --git a/framework/Core/lib/Horde/Menu.php b/framework/Core/lib/Horde/Menu.php index 5a66ce835..5e54896a2 100644 --- a/framework/Core/lib/Horde/Menu.php +++ b/framework/Core/lib/Horde/Menu.php @@ -263,10 +263,9 @@ class Horde_Menu if (isset($conf['menu']['apps']) && is_array($conf['menu']['apps'])) { foreach ($conf['menu']['apps'] as $app) { if ($registry->get('status', $app) != 'inactive' && $registry->hasPermission($app, PERMS_SHOW)) { - $url = $registry->getInitialPage($app); - if (!is_a($url, 'PEAR_Error')) { - $this->add(Horde::url($url), $registry->get('name', $app), $registry->get('icon', $app), ''); - } + try { + $this->add(Horde::url($registry->getInitialPage($app)), $registry->get('name', $app), $registry->get('icon', $app), ''); + } catch (Horde_Exception $e) {} } } } diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 29695cdf8..35c1a92cf 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -87,6 +87,7 @@ class Horde_Registry * @param integer $session_flags Any session flags. * * @return Horde_Registry The Horde_Registry instance. + * @thros Horde_Exception */ static public function singleton($session_flags = 0) { @@ -133,7 +134,7 @@ class Horde_Registry SESSION_NONE. */ $_SESSION = array(); } else { - Horde::setupSessionHandler(); + $this->setupSessionHandler(); $old_error = error_reporting(0); session_start(); if ($session_flags & self::SESSION_READONLY) { @@ -142,10 +143,6 @@ class Horde_Registry session_write_close(); } error_reporting($old_error); - - if (!isset($_SESSION['_registry'])) { - $_SESSION['_registry'] = array(); - } } /* Initialize the localization routines and variables. We can't use @@ -187,11 +184,8 @@ class Horde_Registry } /* Create the global Perms object. */ + // TODO: Remove(?) $GLOBALS['perms'] = Perms::singleton(); - - /* Attach javascript notification listener. */ - $notification = Horde_Notification::singleton(); - $notification->attach('javascript'); } /** @@ -259,10 +253,8 @@ class Horde_Registry /* Read the registry configuration files. */ require HORDE_BASE . '/config/registry.php'; $files = glob(HORDE_BASE . '/config/registry.d/*.php'); - if ($files) { - foreach ($files as $r) { - include $r; - } + foreach ($files as $r) { + include $r; } if ($vhost) { @@ -544,8 +536,8 @@ class Horde_Registry * @param string $method The method to call. * @param array $args Arguments to the method. * - * @return TODO - * Returns PEAR_Error on error. + * @return mixed TODO + * @throws Horde_Exception */ public function call($method, $args = array()) { @@ -556,7 +548,7 @@ class Horde_Registry } elseif (!empty($this->_cache['interfaces'][$interface])) { $app = $this->_cache['interfaces'][$interface]; } else { - return PEAR::raiseError('The method "' . $method . '" is not defined in the Horde Registry.'); + throw new Horde_Exception('The method "' . $method . '" is not defined in the Horde Registry.'); } return $this->callByPackage($app, $call, $args); @@ -569,8 +561,8 @@ class Horde_Registry * @param string $call The method to call. * @param array $args Arguments to the method. * - * @return TODO - * Returns PEAR_Error on error. + * @return mixed TODO + * @throws Horde_Exception */ public function callByPackage($app, $call, $args = array()) { @@ -578,7 +570,7 @@ class Horde_Registry * $app's services and included the API file, so we don't try * to do it again explicitly in this method. */ if (!$this->hasMethod($call, $app)) { - return PEAR::raiseError(sprintf('The method "%s" is not defined in the API for %s.', $call, $app)); + throw new Horde_Exception(sprintf('The method "%s" is not defined in the API for %s.', $call, $app)); } /* Load the API now. */ @@ -590,7 +582,7 @@ class Horde_Registry /* Make sure that the function actually exists. */ $function = '_' . $app . '_' . str_replace('/', '_', $call); if (!function_exists($function)) { - return PEAR::raiseError('The function implementing ' . $call . ' (' . $function . ') is not defined in ' . $app . '\'s API.'); + throw new Horde_Exception('The function implementing ' . $call . ' (' . $function . ') is not defined in ' . $app . '\'s API.'); } $checkPerms = isset($this->_cache['api'][$app][$call]['checkperms']) @@ -601,9 +593,6 @@ class Horde_Registry * including any files which might do it for us. Return an * error immediately if pushApp() fails. */ $pushed = $this->pushApp($app, $checkPerms); - if (is_a($pushed, 'PEAR_Error')) { - return $pushed; - } $res = call_user_func_array($function, $args); @@ -626,8 +615,8 @@ class Horde_Registry * @param array $args Arguments to the method. * @param mixed $extra Extra, non-standard arguments to the method. * - * @return TODO - * Returns PEAR_Error on error. + * @return mixed TODO + * @throws Horde_Exception */ public function link($method, $args = array(), $extra = '') { @@ -638,7 +627,7 @@ class Horde_Registry } elseif (!empty($this->_cache['interfaces'][$interface])) { $app = $this->_cache['interfaces'][$interface]; } else { - return PEAR::raiseError('The method "' . $method . '" is not defined in the Horde Registry.'); + throw new Horde_Exception('The method "' . $method . '" is not defined in the Horde Registry.'); } return $this->linkByPackage($app, $call, $args, $extra); @@ -652,8 +641,8 @@ class Horde_Registry * @param array $args Arguments to the method. * @param mixed $extra Extra, non-standard arguments to the method. * - * @return TODO - * Returns PEAR_Error on error. + * @return mixed TODO + * @throws Horde_Exception */ public function linkByPackage($app, $call, $args = array(), $extra = '') { @@ -661,13 +650,13 @@ class Horde_Registry * services and included the API file, so we don't try to do * it it again explicitly in this method. */ if (!$this->hasMethod($call, $app)) { - return PEAR::raiseError('The method "' . $call . '" is not defined in ' . $app . '\'s API.'); + throw new Horde_Exception('The method "' . $call . '" is not defined in ' . $app . '\'s API.'); } /* Make sure the link is defined. */ $this->_loadApiCache(); if (empty($this->_cache['api'][$app][$call]['link'])) { - return PEAR::raiseError('The link ' . $call . ' is not defined in ' . $app . '\'s API.'); + throw new Horde_Exception('The link ' . $call . ' is not defined in ' . $app . '\'s API.'); } /* Initial link value. */ @@ -717,8 +706,8 @@ class Horde_Registry * @param string $path The application string. * @param string $app The application being called. * - * @return TODO - * Returns PEAR_Error on error. + * @return string The application file path. + * @throws Horde_Exception */ public function applicationFilePath($path, $app = null) { @@ -727,7 +716,7 @@ class Horde_Registry } if (!isset($this->applications[$app])) { - return PEAR::raiseError(sprintf(_("\"%s\" is not configured in the Horde Registry."), $app)); + throw new Horde_Exception(sprintf(_("\"%s\" is not configured in the Horde Registry."), $app)); } return str_replace('%application%', $this->applications[$app]['fileroot'], $path); @@ -739,8 +728,7 @@ class Horde_Registry * @param string $path The application string. * @param string $app The application being called. * - * @return TODO - * Returns PEAR_Error on error. + * @return string The application web path. */ public function applicationWebPath($path, $app = null) { @@ -791,7 +779,7 @@ class Horde_Registry * - To anyone who is allowed by an explicit ACL on $app. */ if ($checkPerms && !$this->hasPermission($app)) { Horde::logMessage(sprintf('%s does not have READ permission for %s', Horde_Auth::getAuth() ? 'User ' . Horde_Auth::getAuth() : 'Guest user', $app), __FILE__, __LINE__, PEAR_LOG_DEBUG); - return PEAR::raiseError(sprintf(_('%s is not authorised for %s.'), Horde_Auth::getAuth() ? 'User ' . Horde_Auth::getAuth() : 'Guest user', $this->applications[$app]['name']), 'permission_denied'); + throw new Horde_Exception(sprintf(_('%s is not authorised for %s.'), Horde_Auth::getAuth() ? 'User ' . Horde_Auth::getAuth() : 'Guest user', $this->applications[$app]['name']), 'permission_denied'); } /* Set up autoload paths for the current application. This needs to @@ -893,8 +881,6 @@ class Horde_Registry * them into the global $conf variable. * * @param string $app The name of the application. - * - * @throws Horde_Exception */ public function importConfig($app) { @@ -926,9 +912,9 @@ class Horde_Registry if (!Horde_Auth::getAuth()) { $GLOBALS['prefs'] = Prefs::factory('session', $app, '', '', null, false); } else { - if (!isset($GLOBALS['prefs']) || $GLOBALS['prefs']->getUser() != Horde_Auth::getAuth()) { - $GLOBALS['prefs'] = Prefs::factory($GLOBALS['conf']['prefs']['driver'], $app, - Horde_Auth::getAuth(), Horde_Auth::getCredential('password')); + if (!isset($GLOBALS['prefs']) || + ($GLOBALS['prefs']->getUser() != Horde_Auth::getAuth())) { + $GLOBALS['prefs'] = Prefs::factory($GLOBALS['conf']['prefs']['driver'], $app, Horde_Auth::getAuth(), Horde_Auth::getCredential('password')); } else { $GLOBALS['prefs']->retrieve($app); } @@ -1041,7 +1027,7 @@ class Horde_Registry * @param string $app The name of the application. * * @return string URL pointing to the inital page of the application. - * Returns PEAR_Error on error. + * @throws Horde_Exception */ public function getInitialPage($app = null) { @@ -1049,9 +1035,11 @@ class Horde_Registry $app = $this->getApp(); } - return isset($this->applications[$app]) - ? $this->applications[$app]['webroot'] . '/' . (isset($this->applications[$app]['initial_page']) ? $this->applications[$app]['initial_page'] : '') - : PEAR::raiseError(sprintf(_("\"%s\" is not configured in the Horde Registry."), $app)); + if (isset($this->applications[$app])) { + return $this->applications[$app]['webroot'] . '/' . (isset($this->applications[$app]['initial_page']) ? $this->applications[$app]['initial_page'] : ''); + } + + throw new Horde_Exception(sprintf(_("\"%s\" is not configured in the Horde Registry."), $app)); } /** @@ -1120,8 +1108,86 @@ class Horde_Registry return $id; } elseif (isset($_SESSION['_registry']['md5'][$name])) { return $id . '|' . $_SESSION['_registry']['md5'][$name]; - } else { - return false; + } + + return false; + } + + /** + * Sets a custom session handler up, if there is one. + * If the global variable 'session_cache_limiter' is defined, its value + * will override the cache limiter setting found in the configuration + * file. + * + * The custom session handler object will be contained in the global + * 'horde_sessionhandler' variable. + */ + public function setupSessionHandler() + { + global $conf; + + ini_set('url_rewriter.tags', 0); + if (!empty($conf['session']['use_only_cookies'])) { + ini_set('session.use_only_cookies', 1); + if (!empty($conf['cookie']['domain']) && + strpos($conf['server']['name'], '.') === false) { + Horde::fatal('Session cookies will not work without a FQDN and with a non-empty cookie domain. Either use a fully qualified domain name like "http://www.example.com" instead of "http://example" only, or set the cookie domain in the Horde configuration to an empty value, or enable non-cookie (url-based) sessions in the Horde configuration.', __FILE__, __LINE__); + } + } + + session_set_cookie_params($conf['session']['timeout'], + $conf['cookie']['path'], $conf['cookie']['domain'], $conf['use_ssl'] == 1 ? 1 : 0); + session_cache_limiter(Horde_Util::nonInputVar('session_cache_limiter', $conf['session']['cache_limiter'])); + session_name(urlencode($conf['session']['name'])); + + $type = empty($conf['sessionhandler']['type']) + ? 'none' + : $conf['sessionhandler']['type']; + + if ($type == 'external') { + $calls = $conf['sessionhandler']['params']; + session_set_save_handler($calls['open'], + $calls['close'], + $calls['read'], + $calls['write'], + $calls['destroy'], + $calls['gc']); + } elseif ($type != 'none') { + try { + $sh = Horde_SessionHandler::singleton($conf['sessionhandler']['type'], array_merge(Horde::getDriverConfig('sessionhandler', $conf['sessionhandler']['type']), array('memcache' => !empty($conf['sessionhandler']['memcache'])))); + ini_set('session.save_handler', 'user'); + session_set_save_handler(array(&$sh, 'open'), + array(&$sh, 'close'), + array(&$sh, 'read'), + array(&$sh, 'write'), + array(&$sh, 'destroy'), + array(&$sh, 'gc')); + $GLOBALS['horde_sessionhandler'] = $sh; + } catch (Horde_Exception $e) { + Horde::fatal(new Horde_Exception('Horde is unable to correctly start the custom session handler.'), __FILE__, __LINE__, false); + } + } + } + + /** + * Destroys any existing session on login and make sure to use a new + * session ID, to avoid session fixation issues. Should be called before + * checking a login. + */ + public function getCleanSession() + { + // Make sure to force a completely new session ID and clear all + // session data. + session_regenerate_id(true); + session_unset(); + + /* Reset cookie timeouts, if necessary. */ + if (!empty($GLOBALS['conf']['session']['timeout'])) { + $app = $this->getApp(); + if (Horde_Secret::clearKey($app)) { + Horde_Secret::setKey($app); + } + Horde_Secret::setKey('auth'); } } diff --git a/framework/Core/lib/Horde/Registry/Caller.php b/framework/Core/lib/Horde/Registry/Caller.php index 1189a7710..c7a460a74 100644 --- a/framework/Core/lib/Horde/Registry/Caller.php +++ b/framework/Core/lib/Horde/Registry/Caller.php @@ -32,6 +32,8 @@ class Horde_Registry_Caller /** * TODO + * + * @throws Horde_Exception */ public function __call($method, $args) { diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Vcard.php b/framework/Mime/lib/Horde/Mime/Viewer/Vcard.php index 1881b0aec..17f548a86 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/Vcard.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/Vcard.php @@ -68,17 +68,13 @@ class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Driver $source = Horde_Util::getFormData('source'); $count = 0; foreach ($iCal->getComponents() as $c) { - if (is_a($c, 'Horde_iCalendar_vcard')) { - $contacts = $registry->call('contacts/import', - array($c, null, $source)); - if (is_a($contacts, 'PEAR_Error')) { - $notification->push( - _("There was an error importing the contact data:") . ' ' - . $contacts->getMessage(), - 'horde.error'); - continue; + if ($c instanceof Horde_iCalendar_vcard) { + try { + $contacts = $registry->call('contacts/import', array($c, null, $source)); + ++$count; + } catch (Horde_Exception $e) { + $notification->push(_("There was an error importing the contact data:") . ' ' . $e->getMessage(), 'horde.error'); } - $count++; } } $notification->push(sprintf(ngettext( diff --git a/framework/Rpc/lib/Horde/Rpc/Jsonrpc.php b/framework/Rpc/lib/Horde/Rpc/Jsonrpc.php index 026a19a9d..e1f5005e9 100644 --- a/framework/Rpc/lib/Horde/Rpc/Jsonrpc.php +++ b/framework/Rpc/lib/Horde/Rpc/Jsonrpc.php @@ -74,9 +74,10 @@ class Horde_Rpc_Jsonrpc extends Horde_Rpc } // Call the method. - $result = $GLOBALS['registry']->call($method, $params); - if (is_a($result, 'PEAR_Error')) { - return $this->_raiseError($result, $request); + try { + $result = $GLOBALS['registry']->call($method, $params); + } catch (Horde_Exception $e) { + return $this->_raiseError($e, $request); } // Return result. diff --git a/framework/Rpc/lib/Horde/Rpc/Webdav.php b/framework/Rpc/lib/Horde/Rpc/Webdav.php index 3eb7fa495..5787ffa23 100644 --- a/framework/Rpc/lib/Horde/Rpc/Webdav.php +++ b/framework/Rpc/lib/Horde/Rpc/Webdav.php @@ -319,15 +319,15 @@ class Horde_Rpc_Webdav extends Horde_Rpc $content .= fgets($options['stream']); } - $result = $GLOBALS['registry']->callByPackage($pieces[0], 'put', array('path' => $path, 'content' => $content, 'type' => $options['content_type'])); - if (is_a($result, 'PEAR_Error')) { - Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - if ($result->getCode()) { - return $this->_checkHTTPCode($result->getCode()) - . ' ' . $result->getMessage(); - } else { - return '500 Internal Server Error. Check server logs'; + try { + $GLOBALS['registry']->callByPackage($pieces[0], 'put', array('path' => $path, 'content' => $content, 'type' => $options['content_type'])); + } catch (Horde_Exception $e) { + Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); + if ($e->getCode()) { + return $this->_checkHTTPCode($e->getCode()) . ' ' . $result->getMessage(); } + + return '500 Internal Server Error. Check server logs'; } return true; @@ -351,28 +351,29 @@ class Horde_Rpc_Webdav extends Horde_Rpc $path = $options['path']; $pieces = explode('/', trim($this->path, '/'), 2); - if (count($pieces) == 2) { - $app = $pieces[0]; - $path = $pieces[1]; + if (count($pieces) != 2) { + Horde::logMessage(sprintf(_("Error deleting from path %s; must be [app]/[path]", $options['path'])), __FILE__, __LINE__, PEAR_LOG_INFO); + return '403 Must supply a resource within the application to delete.'; + } - // TODO: Support HTTP/1.1 If-Match on ETag here + $app = $pieces[0]; + $path = $pieces[1]; - // Delete access is checked in each app. - $result = $GLOBALS['registry']->callByPackage($app, 'path_delete', array($path)); - if (is_a($result, 'PEAR_Error')) { - Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_INFO); - if ($result->getCode()) { - return $this->_checkHTTPCode($result->getCode()) - . ' ' . $result->getMessage(); - } else { - return '500 Internal Server Error. Check server logs'; - } + // TODO: Support HTTP/1.1 If-Match on ETag here + + // Delete access is checked in each app. + try { + $GLOBALS['registry']->callByPackage($app, 'path_delete', array($path)); + } catch (Horde_Exception $e) { + Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_INFO); + if ($e->getCode()) { + return $this->_checkHTTPCode($e->getCode()) . ' ' . $e->getMessage(); } - return '204 No Content'; - } else { - Horde::logMessage(sprintf(_("Error deleting from path %s; must be [app]/[path]", $options['path'])), __FILE__, __LINE__, PEAR_LOG_INFO); - return '403 Must supply a resource within the application to delete.'; + + return '500 Internal Server Error. Check server logs'; } + + return '204 No Content'; } /** @@ -411,23 +412,23 @@ class Horde_Rpc_Webdav extends Horde_Rpc // Take the module name from the path $pieces = explode('/', $path, 2); - if (count($pieces) == 2) { - // Send the request to the application - $result = $GLOBALS['registry']->callByPackage($pieces[0], 'mkcol', array('path' => $path)); - if (is_a($result, 'PEAR_Error')) { - Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - if ($result->getCode()) { - return $this->_checkHTTPCode($result->getCode()) - . ' ' . $result->getMessage(); - } else { - return '500 Internal Server Error. Check server logs'; - } - } - } else { + if (count($pieces) != 2) { Horde::logMessage(sprintf(_("Unable to create directory %s; must be [app]/[path]"), $path), __FILE__, __LINE__, PEAR_LOG_INFO); return '403 Must specify a resource within an application. MKCOL disallowed at top level.'; } + // Send the request to the application + try { + $GLOBALS['registry']->callByPackage($pieces[0], 'mkcol', array('path' => $path)); + } catch (Horde_Exception $e) { + Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); + if ($e->getCode()) { + return $this->_checkHTTPCode($e->getCode()) . ' ' . $e->getMessage(); + } + + return '500 Internal Server Error. Check server logs'; + } + return '200 OK'; } @@ -446,27 +447,28 @@ class Horde_Rpc_Webdav extends Horde_Rpc // Take the module name from the path $sourcePieces = explode('/', $path, 2); - if (count($sourcePieces) == 2) { - $destPieces = explode('/', $options['dest'], 2); - if (!(count($destPieces) == 2) || $sourcesPieces[0] != $destPieces[0]) { - return '400 Can not move across applications.'; - } - // Send the request to the module - $result = $GLOBALS['registry']->callByPackage($sourcePieces[0], 'move', array('path' => $path, 'dest' => $options['dest'])); - if (is_a($result, 'PEAR_Error')) { - Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - if ($result->getCode()) { - return $this->_checkHTTPCode($result->getCode()) - . ' ' . $result->getMessage(); - } else { - return '500 Internal Server Error. Check server logs'; - } - } - } else { + if (count($sourcePieces) != 2) { Horde::logMessage(sprintf(_("Unable to rename %s; must be [app]/[path] and within the same application."), $path), __FILE__, __LINE__, PEAR_LOG_INFO); return '403 Must specify a resource within an application. MOVE disallowed at top level.'; } + $destPieces = explode('/', $options['dest'], 2); + if (!(count($destPieces) == 2) || $sourcesPieces[0] != $destPieces[0]) { + return '400 Can not move across applications.'; + } + + // Send the request to the module + try { + $GLOBALS['registry']->callByPackage($sourcePieces[0], 'move', array('path' => $path, 'dest' => $options['dest'])); + } catch (Horde_Exception $e) { + Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); + if ($e->getCode()) { + return $this->_checkHTTPCode($e->getCode()) . ' ' . $e->getMessage(); + } + + return '500 Internal Server Error. Check server logs'; + } + return '200 OK'; } @@ -539,7 +541,13 @@ class Horde_Rpc_Webdav extends Horde_Rpc // Make sure the applications each only return one level $options['depth'] = 0; } - $results = $registry->callByPackage($app, 'browse', array('path' => '/', 'depth' => $options['depth'])); + + try { + $results = $registry->callByPackage($app, 'browse', array('path' => '/', 'depth' => $options['depth'])); + } catch (Horde_Exception $e) { + continue; + } + $options['depth'] = $origdepth; foreach ($results as $itemPath => $item) { @@ -555,20 +563,22 @@ class Horde_Rpc_Webdav extends Horde_Rpc } } } -Horde::logMessage(print_r($list, true), __FILE__, __LINE__, PEAR_LOG_ERR); return $list; } else { $path = trim($path, '/'); $pieces = explode('/', $path); - $items = $registry->callByPackage($pieces[0], 'browse', array('path' => $path, 'depth' => $options['depth'])); + + try { + $items = $registry->callByPackage($pieces[0], 'browse', array('path' => $path, 'depth' => $options['depth'])); + } catch (Horde_Exception $e) { + Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); + return $e; + } + if ($items === false) { // File not found return $items; } - if (is_a($items, 'PEAR_Error')) { - Horde::logMessage($items, __FILE__, __LINE__, PEAR_LOG_ERR); - return $items; - } if (empty($items)) { // No content exists at this level. return array(); diff --git a/framework/Rpc/lib/Horde/Rpc/Xmlrpc.php b/framework/Rpc/lib/Horde/Rpc/Xmlrpc.php index e95021580..660e3ffcc 100644 --- a/framework/Rpc/lib/Horde/Rpc/Xmlrpc.php +++ b/framework/Rpc/lib/Horde/Rpc/Xmlrpc.php @@ -71,10 +71,11 @@ class Horde_Rpc_Xmlrpc extends Horde_Rpc return 'Method "' . $method . '" is not defined'; } - $result = $registry->call($method, $params); - if (is_a($result, 'PEAR_Error')) { - $result = array('faultCode' => (int)$result->getCode(), - 'faultString' => $result->getMessage()); + try { + $result = $registry->call($method, $params); + } catch (Horde_Exception $e) { + $result = array('faultCode' => (int)$e->getCode(), + 'faultString' => $e->getMessage()); } return $result; diff --git a/framework/Text_Filter/lib/Horde/Text/Filter/Emails.php b/framework/Text_Filter/lib/Horde/Text/Filter/Emails.php index dd14fc165..956266f57 100644 --- a/framework/Text_Filter/lib/Horde/Text/Filter/Emails.php +++ b/framework/Text_Filter/lib/Horde/Text/Filter/Emails.php @@ -132,10 +132,11 @@ EOP; } parse_str($args, $extra); - $url = $GLOBALS['registry']->call('mail/compose', - array(array('to' => $email), - $extra)); - if (is_a($url, 'PEAR_Error')) { + try { + $url = $GLOBALS['registry']->call('mail/compose', + array(array('to' => $email), + $extra)); + } catch (Horde_Exception $e) { $url = 'mailto:' . urlencode($email); } -- 2.11.0