From 7ecb46bf083a9cd1b8bfe56785b6b91bc81174a3 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Wed, 4 Aug 2010 18:13:58 +0200 Subject: [PATCH] Catch Icalendar exceptions. --- kronolith/lib/Ajax/Application.php | 12 ++++++------ kronolith/lib/Api.php | 6 +++--- kronolith/lib/Driver/Ical.php | 29 ++++++++++++++++++----------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/kronolith/lib/Ajax/Application.php b/kronolith/lib/Ajax/Application.php index ca42a1610..68885da94 100644 --- a/kronolith/lib/Ajax/Application.php +++ b/kronolith/lib/Ajax/Application.php @@ -826,14 +826,14 @@ class Kronolith_Ajax_Application extends Horde_Core_Ajax_Application $driver->open($this->_vars->url); $ical = $driver->getRemoteCalendar(false); $result->success = true; - $name = $ical->getAttribute('X-WR-CALNAME'); - if (!($name instanceof PEAR_Error)) { + try { + $name = $ical->getAttribute('X-WR-CALNAME'); $result->name = $name; - } - $desc = $ical->getAttribute('X-WR-CALDESC'); - if (!($desc instanceof PEAR_Error)) { + } catch (Horde_Icalendar_Exception $e) {} + try { + $desc = $ical->getAttribute('X-WR-CALDESC'); $result->desc = $desc; - } + } catch (Horde_Icalendar_Exception $e) {} } catch (Exception $e) { if ($e->getCode() == 401) { $result->auth = true; diff --git a/kronolith/lib/Api.php b/kronolith/lib/Api.php index 9e945a7da..661e8c269 100644 --- a/kronolith/lib/Api.php +++ b/kronolith/lib/Api.php @@ -648,10 +648,10 @@ class Kronolith_Api extends Horde_Registry_Api // Need to ensure that the original recurring event is // added before any of the instance exceptions. Easiest way // to do that is just add all the recurrence-id entries last - $recurrenceId = $content->getAttribute('RECURRENCE-ID'); - if (!($recurrenceId instanceof PEAR_Error)) { + try { + $recurrenceId = $content->getAttribute('RECURRENCE-ID'); $recurrences[] = $content; - } else { + } catch (Horde_Icalendar_Exception $e) { $ids[] = $this->_addiCalEvent($content, $kronolith_driver); } } diff --git a/kronolith/lib/Driver/Ical.php b/kronolith/lib/Driver/Ical.php index 28a437228..680f6bc5e 100644 --- a/kronolith/lib/Driver/Ical.php +++ b/kronolith/lib/Driver/Ical.php @@ -127,12 +127,14 @@ class Kronolith_Driver_Ical extends Kronolith_Driver /* Catch RECURRENCE-ID attributes which mark single recurrence * instances. */ - $recurrence_id = $component->getAttribute('RECURRENCE-ID'); - if (is_int($recurrence_id) && - is_string($uid = $component->getAttribute('UID')) && - is_int($seq = $component->getAttribute('SEQUENCE'))) { - $exceptions[$uid][$seq] = $recurrence_id; - } + try { + $recurrence_id = $component->getAttribute('RECURRENCE-ID'); + if (is_int($recurrence_id) && + is_string($uid = $component->getAttribute('UID')) && + is_int($seq = $component->getAttribute('SEQUENCE'))) { + $exceptions[$uid][$seq] = $recurrence_id; + } + } catch (Horde_Icalendar_Exception $e) {} /* Ignore events out of the period. */ if ( @@ -199,7 +201,7 @@ class Kronolith_Driver_Ical extends Kronolith_Driver * * @param boolean $cache Whether to return data from the session cache. * - * @return Horde_Icalendar The calendar data, or an error on failure. + * @return Horde_Icalendar The calendar data. * @throws Kronolith_Exception */ public function getRemoteCalendar($cache = true) @@ -253,13 +255,18 @@ class Kronolith_Driver_Ical extends Kronolith_Driver $data = $response->getBody(); $ical = new Horde_Icalendar(); - $result = $ical->parsevCalendar($data); + try { + $result = $ical->parsevCalendar($data); + } catch (Horde_Icalendar_Exception $e) { + if ($cache) { + $cacheOb->set($signature, serialize($e->getMessage())); + } + throw new Kronolith_Exception($e); + } + if ($cache) { $cacheOb->set($signature, serialize($ical)); } - if ($result instanceof PEAR_Error) { - throw new Kronolith_Exception($result); - } return $ical; } -- 2.11.0