From 7c111d8d564aa37efe0b364081fabc03c9f42357 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Wed, 7 Jun 2006 13:44:44 +0000 Subject: [PATCH] Improve error handling. git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@54 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- banana/NetNNTP.inc.php | 3 +++ banana/banana.inc.php.in | 53 +++++++++++++++++++++++++++++++++++++----------- banana/post.inc.php | 4 ++++ banana/spool.inc.php | 7 ++++++- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/banana/NetNNTP.inc.php b/banana/NetNNTP.inc.php index 3cebaed..45af23f 100644 --- a/banana/NetNNTP.inc.php +++ b/banana/NetNNTP.inc.php @@ -20,6 +20,8 @@ class nntp var $lasterrorcode; /** last NNTP error text */ var $lasterrortext; + /** test validity */ + var $valid = true; /** constructor * @param $_host STRING NNTP host @@ -33,6 +35,7 @@ class nntp $url = parse_url($_url); $this->ns = fsockopen($url['host'], $url['port'], $errno, $errstr, $_timeout); if (!$this->ns) { + $this->valid = false; return null; } diff --git a/banana/banana.inc.php.in b/banana/banana.inc.php.in index 0ca84e0..fa0f94f 100644 --- a/banana/banana.inc.php.in +++ b/banana/banana.inc.php.in @@ -87,6 +87,9 @@ class Banana $this->_require('NetNNTP'); setlocale(LC_ALL, $this->profile['locale']); $this->nntp = new nntp($this->host); + if (!$this->nntp || !$this->nntp->valid) { + $this->nntp = null; + } } function run($class = 'Banana') @@ -202,7 +205,9 @@ class Banana function action_showThread($group, $first) { - $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); + if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { + return '

'._b_('Impossible charger la liste des messages').'

'; + } if ($first > count($this->spool->overview)) { $first = count($this->spool->overview); @@ -222,9 +227,11 @@ class Banana function action_showArticle($group, $id, $part) { - $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); - $this->_newPost($id); - if (!$this->post) { + if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { + return '

'._b_('Impossible charger la liste des messages').'

'; + } + + if (!$this->_newPost($id)) { if ($this->nntp->lasterrorcode == "423") { $this->spool->delid($id); } @@ -243,9 +250,11 @@ class Banana function action_getAttachment($group, $id, $pjid, $action) { - $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); - $this->_newPost($id); - if (!$this->post) { + if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { + return '

'._b_('Impossible charger la liste des messages').'

'; + } + + if (!$this->_newPost($id)) { if ($this->nntp->lasterrorcode == "423") { $this->spool->delid($id); } @@ -263,8 +272,13 @@ class Banana function action_cancelArticle($group, $id) { - $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); - $this->_newPost($id); + if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { + return '

'._b_('Impossible charger la liste des messages').'

'; + } + + if (!$this->_newPost($id)) { + return '

'._b_('Impossible de trouver le message à annuler').'

'; + } $mid = array_search($id, $this->spool->ids); if (!$this->post->checkcancel()) { @@ -293,8 +307,7 @@ class Banana if ($id > 0) { $this->nntp->group($group); - $this->_newPost($id); - if ($this->post) { + if ($this->_newPost($id)) { $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post->headers['subject']); $body = utf8_encode($this->post->name." "._b_("a écrit"))." :\n".wrap($this->post->get_body(), "> "); $target = isset($this->post->headers['followup-to']) ? $this->post->headers['followup-to'] : $this->post->headers['newsgroups']; @@ -343,7 +356,10 @@ class Banana } $to = preg_replace('/\s*(,|;)\s*/', ',', $_POST['newsgroups']); - $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); + if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) { + return '

'._b_('Impossible charger la liste des messages').'

'; + } + $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']); $msg = 'From: '.$this->profile['name']."\n" . "Newsgroups: ". $to . "\n" @@ -354,6 +370,9 @@ class Banana if ($artid != -1) { $this->_require('post'); $post = new BananaPost($artid); + if (!$post || !$post->valid) { + return '

'._b_('Impossible charger le message d\'origine').'

'; + } $refs = ( isset($post->headers['references']) ? $post->headers['references']." " : "" ); $msg .= "References: $refs{$post->headers['message-id']}\n"; } @@ -412,13 +431,23 @@ class Banana $this->_require('spool'); if (!$this->spool || $this->spool->group != $group) { $this->spool = new BananaSpool($group, $disp, $since); + if (!$this->spool || !$this->spool->valid) { + $this->spool = null; + return false; + } } + return true; } function _newPost($id) { $this->_require('post'); $this->post = new BananaPost($id); + if (!$this->post || !$this->post->valid) { + $this->post = null; + return false; + } + return true; } function _newGroup() diff --git a/banana/post.inc.php b/banana/post.inc.php index daea089..b240ca2 100644 --- a/banana/post.inc.php +++ b/banana/post.inc.php @@ -23,6 +23,8 @@ class BananaPost var $pj; /** poster name */ var $name; + /** test validity */ + var $valid = true; /** constructor * @param $_id STRING MSGNUM or MSGID (a group should be selected in this case) @@ -34,6 +36,7 @@ class BananaPost $this->pj = array(); $this->messages = array(); if (!$this->_header()) { + $this->valid = false; return null; } @@ -41,6 +44,7 @@ class BananaPost if ($body = $banana->nntp->body($_id)) { $this->body = join("\n", $body); } else { + $this->valid = false; return null; } diff --git a/banana/spool.inc.php b/banana/spool.inc.php index afe1a5a..17296b1 100644 --- a/banana/spool.inc.php +++ b/banana/spool.inc.php @@ -83,6 +83,8 @@ class BananaSpool var $ids; /** thread starts */ var $roots; + /** test validity */ + var $valid = true; /** constructor * @param $_group STRING group name @@ -94,7 +96,10 @@ class BananaSpool global $banana; $this->group = $_group; $groupinfo = $banana->nntp->group($_group); - if (!$groupinfo) { return null; } + if (!$groupinfo) { + $this->valid = false; + return null; + } $this->_readFromFile(); -- 2.1.4