From ab149755b62aaf7959a97e4a425e20aebf4c92cc Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 13 Jul 2010 10:42:06 -0400 Subject: handle notices without profiles better in RSS output --- lib/apiaction.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/apiaction.php b/lib/apiaction.php index 8de13a62d..16dd87814 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -461,6 +461,11 @@ class ApiAction extends Action function twitterRssEntryArray($notice) { $profile = $notice->getProfile(); + + if (empty($profile)) { + throw new ServerException(sprintf(_('No such profile: %d'), $notice->profile_id)); + } + $entry = array(); // We trim() to avoid extraneous whitespace in the output @@ -789,13 +794,23 @@ class ApiAction extends Action if (is_array($notice)) { foreach ($notice as $n) { - $entry = $this->twitterRssEntryArray($n); - $this->showTwitterRssItem($entry); + try { + $entry = $this->twitterRssEntryArray($n); + $this->showTwitterRssItem($entry); + } catch (Exception $e) { + common_log(LOG_ERR, "Error with notice {$n->id}: " . $e->getMessage()); + // continue on exceptions + } } } else { while ($notice->fetch()) { - $entry = $this->twitterRssEntryArray($notice); - $this->showTwitterRssItem($entry); + try { + $entry = $this->twitterRssEntryArray($notice); + $this->showTwitterRssItem($entry); + } catch (Exception $e) { + common_log(LOG_ERR, "Error with notice {$n->id}: " . $e->getMessage()); + // continue on exceptions + } } } -- cgit v1.2.3-54-g00ecf From dfd65a4290c7c2f6137d5508597189c4202bfaee Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 13 Jul 2010 10:51:25 -0400 Subject: push exception on missing profile down to Notice::getProfile() --- classes/Notice.php | 8 +++++++- lib/apiaction.php | 8 ++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/classes/Notice.php b/classes/Notice.php index 482bc550b..ae7e2e540 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -90,7 +90,13 @@ class Notice extends Memcached_DataObject function getProfile() { - return Profile::staticGet('id', $this->profile_id); + $profile = Profile::staticGet('id', $this->profile_id); + + if (empty($profile)) { + throw new ServerException(sprintf(_('No such profile (%d) for notice (%d)'), $this->profile_id, $this->id)); + } + + return $profile; } function delete() diff --git a/lib/apiaction.php b/lib/apiaction.php index 16dd87814..01985f0db 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -462,10 +462,6 @@ class ApiAction extends Action { $profile = $notice->getProfile(); - if (empty($profile)) { - throw new ServerException(sprintf(_('No such profile: %d'), $notice->profile_id)); - } - $entry = array(); // We trim() to avoid extraneous whitespace in the output @@ -798,7 +794,7 @@ class ApiAction extends Action $entry = $this->twitterRssEntryArray($n); $this->showTwitterRssItem($entry); } catch (Exception $e) { - common_log(LOG_ERR, "Error with notice {$n->id}: " . $e->getMessage()); + common_log(LOG_ERR, $e->getMessage()); // continue on exceptions } } @@ -808,7 +804,7 @@ class ApiAction extends Action $entry = $this->twitterRssEntryArray($notice); $this->showTwitterRssItem($entry); } catch (Exception $e) { - common_log(LOG_ERR, "Error with notice {$n->id}: " . $e->getMessage()); + common_log(LOG_ERR, $e->getMessage()); // continue on exceptions } } -- cgit v1.2.3-54-g00ecf From 6968c96b44d17295ceb229af2385449400f4976a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 13 Jul 2010 10:53:47 -0400 Subject: log exceptions in atom feeds, but don't let them kill the output --- lib/atomnoticefeed.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/atomnoticefeed.php b/lib/atomnoticefeed.php index 6ed803ce4..b88217291 100644 --- a/lib/atomnoticefeed.php +++ b/lib/atomnoticefeed.php @@ -125,12 +125,17 @@ class AtomNoticeFeed extends Atom10Feed */ function addEntryFromNotice($notice) { - $source = $this->showSource(); - $author = $this->showAuthor(); + try { + $source = $this->showSource(); + $author = $this->showAuthor(); - $cur = empty($this->cur) ? common_current_user() : $this->cur; + $cur = empty($this->cur) ? common_current_user() : $this->cur; - $this->addEntryRaw($notice->asAtomEntry(false, $source, $author, $cur)); + $this->addEntryRaw($notice->asAtomEntry(false, $source, $author, $cur)); + } catch (Exception $e) { + common_log(LOG_ERR, $e->getMessage()); + // we continue on exceptions + } } function showSource() -- cgit v1.2.3-54-g00ecf From d706a3e21ba88afc9e7a19652aa19eb4e8c54cd2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 13 Jul 2010 10:59:01 -0400 Subject: handle missing profile for notices better in NoticeList --- lib/noticelist.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/noticelist.php b/lib/noticelist.php index e23cf3b6d..17adf3a49 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -96,8 +96,14 @@ class NoticeList extends Widget break; } - $item = $this->newListItem($this->notice); - $item->show(); + try { + $item = $this->newListItem($this->notice); + $item->show(); + } catch (Exception $e) { + // we log exceptions and continue + common_log(LOG_ERR, $e->getMessage()); + continue; + } } $this->out->elementEnd('ol'); -- cgit v1.2.3-54-g00ecf From 1044f27e47faf89400c8a8734cdb9db21fad84bd Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 13 Jul 2010 10:59:15 -0400 Subject: handle missing profile for notices better in Rss10Action --- lib/rssaction.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/rssaction.php b/lib/rssaction.php index 62e3f21b6..f366db972 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -178,7 +178,13 @@ class Rss10Action extends Action if (count($this->notices)) { foreach ($this->notices as $n) { - $this->showItem($n); + try { + $this->showItem($n); + } catch (Exception $e) { + // log exceptions and continue + common_log(LOG_ERR, $e->getMessage()); + continue; + } } } @@ -232,7 +238,7 @@ class Rss10Action extends Action function showItem($notice) { - $profile = Profile::staticGet($notice->profile_id); + $profile = $notice->getProfile(); $nurl = common_local_url('shownotice', array('notice' => $notice->id)); $creator_uri = common_profile_uri($profile); $this->elementStart('item', array('rdf:about' => $notice->uri, -- cgit v1.2.3-54-g00ecf From 453a06fff4f92a9fd34db2899c012d828c69202e Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 13 Jul 2010 11:11:29 -0400 Subject: Exceptions are caught and continued on JSON, XML, Atom and RSS output in API --- lib/apiaction.php | 69 +++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 35 deletions(-) (limited to 'lib') diff --git a/lib/apiaction.php b/lib/apiaction.php index 01985f0db..297dcedec 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -734,14 +734,16 @@ class ApiAction extends Action 'xmlns:statusnet' => 'http://status.net/schema/api/1/')); if (is_array($notice)) { - foreach ($notice as $n) { - $twitter_status = $this->twitterStatusArray($n); - $this->showTwitterXmlStatus($twitter_status); - } - } else { - while ($notice->fetch()) { + $notice = new ArrayWrapper($notice); + } + + while ($notice->fetch()) { + try { $twitter_status = $this->twitterStatusArray($notice); $this->showTwitterXmlStatus($twitter_status); + } catch (Exception $e) { + common_log(LOG_ERR, $e->getMessage()); + continue; } } @@ -789,24 +791,16 @@ class ApiAction extends Action $this->element('ttl', null, '40'); if (is_array($notice)) { - foreach ($notice as $n) { - try { - $entry = $this->twitterRssEntryArray($n); - $this->showTwitterRssItem($entry); - } catch (Exception $e) { - common_log(LOG_ERR, $e->getMessage()); - // continue on exceptions - } - } - } else { - while ($notice->fetch()) { - try { - $entry = $this->twitterRssEntryArray($notice); - $this->showTwitterRssItem($entry); - } catch (Exception $e) { - common_log(LOG_ERR, $e->getMessage()); - // continue on exceptions - } + $notice = new ArrayWrapper($notice); + } + + while ($notice->fetch()) { + try { + $entry = $this->twitterRssEntryArray($notice); + $this->showTwitterRssItem($entry); + } catch (Exception $e) { + common_log(LOG_ERR, $e->getMessage()); + // continue on exceptions } } @@ -842,12 +836,15 @@ class ApiAction extends Action $this->element('subtitle', null, $subtitle); if (is_array($notice)) { - foreach ($notice as $n) { - $this->raw($n->asAtomEntry()); - } - } else { - while ($notice->fetch()) { + $notice = new ArrayWrapper($notice); + } + + while ($notice->fetch()) { + try { $this->raw($notice->asAtomEntry()); + } catch (Exception $e) { + common_log(LOG_ERR, $e->getMessage()); + continue; } } @@ -1042,14 +1039,16 @@ class ApiAction extends Action $statuses = array(); if (is_array($notice)) { - foreach ($notice as $n) { - $twitter_status = $this->twitterStatusArray($n); - array_push($statuses, $twitter_status); - } - } else { - while ($notice->fetch()) { + $notice = new ArrayWrapper($notice); + } + + while ($notice->fetch()) { + try { $twitter_status = $this->twitterStatusArray($notice); array_push($statuses, $twitter_status); + } catch (Exception $e) { + common_log(LOG_ERR, $e->getMessage()); + continue; } } -- cgit v1.2.3-54-g00ecf From 65862d8f7f45d487d4714137af96d3a24e4ca386 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 16 Jul 2010 14:40:22 -0700 Subject: Suppress HTTP error headers for JSONP API output --- lib/apiaction.php | 20 +++++++++++++------- lib/apiauth.php | 38 +++----------------------------------- 2 files changed, 16 insertions(+), 42 deletions(-) (limited to 'lib') diff --git a/lib/apiaction.php b/lib/apiaction.php index 297dcedec..7868ecab1 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -126,6 +126,7 @@ class ApiAction extends Action var $max_id = null; var $since_id = null; var $source = null; + var $callback = null; var $access = self::READ_ONLY; // read (default) or read-write @@ -145,6 +146,7 @@ class ApiAction extends Action parent::prepare($args); $this->format = $this->arg('format'); + $this->callback = $this->arg('callback'); $this->page = (int)$this->arg('page', 1); $this->count = (int)$this->arg('count', 20); $this->max_id = (int)$this->arg('max_id', 0); @@ -1185,9 +1187,8 @@ class ApiAction extends Action header('Content-Type: application/json; charset=utf-8'); // Check for JSONP callback - $callback = $this->arg('callback'); - if ($callback) { - print $callback . '('; + if (isset($this->callback)) { + print $this->callback . '('; } break; case 'rss': @@ -1216,8 +1217,7 @@ class ApiAction extends Action case 'json': // Check for JSONP callback - $callback = $this->arg('callback'); - if ($callback) { + if (isset($this->callback)) { print ')'; } break; @@ -1247,7 +1247,10 @@ class ApiAction extends Action $status_string = ClientErrorAction::$status[$code]; - header('HTTP/1.1 '.$code.' '.$status_string); + // Do not emit error header for JSONP + if (!isset($this->callback)) { + header('HTTP/1.1 '.$code.' '.$status_string); + } if ($format == 'xml') { $this->initDocument('xml'); @@ -1280,7 +1283,10 @@ class ApiAction extends Action $status_string = ServerErrorAction::$status[$code]; - header('HTTP/1.1 '.$code.' '.$status_string); + // Do not emit error header for JSONP + if (!isset($this->callback)) { + header('HTTP/1.1 '.$code.' '.$status_string); + } if ($content_type == 'xml') { $this->initDocument('xml'); diff --git a/lib/apiauth.php b/lib/apiauth.php index 91cb64262..cf7a2692c 100644 --- a/lib/apiauth.php +++ b/lib/apiauth.php @@ -227,7 +227,7 @@ class ApiAuthAction extends ApiAction } catch (OAuthException $e) { common_log(LOG_WARNING, 'API OAuthException - ' . $e->getMessage()); - $this->showAuthError(); + $this->clientError($e->getMessage(), 401, $this->format); exit; } } @@ -265,7 +265,7 @@ class ApiAuthAction extends ApiAction // show error if the user clicks 'cancel' - $this->showAuthError(); + $this->clientError("Could not authenticate you.", 401, $this->format); exit; } else { @@ -298,7 +298,7 @@ class ApiAuthAction extends ApiAction $proxy, $ip); common_log(LOG_WARNING, $msg); - $this->showAuthError(); + $this->clientError("Could not authenticate you.", 401, $this->format); exit; } } @@ -345,36 +345,4 @@ class ApiAuthAction extends ApiAction } } } - - /** - * Output an authentication error message. Use XML or JSON if one - * of those formats is specified, otherwise output plain text - * - * @return void - */ - - function showAuthError() - { - header('HTTP/1.1 401 Unauthorized'); - $msg = 'Could not authenticate you.'; - - if ($this->format == 'xml') { - header('Content-Type: application/xml; charset=utf-8'); - $this->startXML(); - $this->elementStart('hash'); - $this->element('error', null, $msg); - $this->element('request', null, $_SERVER['REQUEST_URI']); - $this->elementEnd('hash'); - $this->endXML(); - } elseif ($this->format == 'json') { - header('Content-Type: application/json; charset=utf-8'); - $error_array = array('error' => $msg, - 'request' => $_SERVER['REQUEST_URI']); - print(json_encode($error_array)); - } else { - header('Content-type: text/plain'); - print "$msg\n"; - } - } - } -- cgit v1.2.3-54-g00ecf From dbb5e9e1914c9dc67019a4abb1948d40171df0d4 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 22 Jul 2010 16:00:26 -0700 Subject: accept mailto: URIs as OStatus identifiers --- lib/activityutils.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/activityutils.php b/lib/activityutils.php index 401fd7fc2..dd38d4e14 100644 --- a/lib/activityutils.php +++ b/lib/activityutils.php @@ -257,6 +257,12 @@ class ActivityUtils */ static function validateUri($uri) { + // Check mailto: URIs first + + if (preg_match('/^mailto:(.*)$/', $uri, $match)) { + return Validate::email($match[1], common_config('email', 'check_domain')); + } + if (Validate::uri($uri)) { return true; } -- cgit v1.2.3-54-g00ecf