cvs: pear(MAINT_0_10) /Net_NNTP/NNTP Protocol.php
| From: | Heino H. Gehlsen | Date: | Fri, 14 Nov 2003 08:44:19 +0000 |
| Subject: | cvs: pear(MAINT_0_10) /Net_NNTP/NNTP Protocol.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-14267@lists.php.net to get a copy of this message | ||
heino Fri Nov 14 03:44:19 2003 EDT
Modified files: (Branch: MAINT_0_10)
/pear/Net_NNTP/NNTP Protocol.php
Log:
Fix bug #7 (+ some whitespace)
Index: pear/Net_NNTP/NNTP/Protocol.php
diff -u pear/Net_NNTP/NNTP/Protocol.php:1.6 pear/Net_NNTP/NNTP/Protocol.php:1.6.2.1
--- pear/Net_NNTP/NNTP/Protocol.php:1.6 Fri Oct 10 11:39:21 2003
+++ pear/Net_NNTP/NNTP/Protocol.php Fri Nov 14 03:44:19 2003
@@ -57,7 +57,7 @@
// | been changes or removed. |
// | |
// +-----------------------------------------------------------------------+
-// $Id: Protocol.php,v 1.6 2003/10/10 15:39:21 heino Exp $
+// $Id: Protocol.php,v 1.6.2.1 2003/11/14 08:44:19 heino Exp $
require_once 'PEAR.php';
require_once 'Net/Socket.php';
@@ -1045,41 +1045,54 @@
function _getTextResponse()
{
$data = array();
+ $line = '';
+ // Continue until connection is lost
while(!$this->_socket->eof()) {
- // Retrieve a line (terminated by "\r\n") from the server.
- $line = $this->_socket->gets(1024); // Lines may not be longer than 988+2 chars
(RFC2822 2.3)
- if (PEAR::isError($line) ) {
- return PEAR::throwError( 'Failed to read from socket!', null,
$line->getMessage());
+ // Retrieve and append up to 1024 characters from the server.
+ $line .= $this->_socket->gets(1024);
+ if (PEAR::isError($line) ) {
+ return PEAR::throwError( 'Failed to read from socket!', null,
$line->getMessage());
}
- // Verify recieved line
- if (strlen($line) < 2 || substr($line, -2) != "\r\n") {
- return PEAR::throwError('Invalid line recieved!', null);
- }
+ // Continue if the line is not terminated by CRLF
+ if (substr($line, -2) != "\r\n" || strlen($line) < 2) {
+ continue;
+ }
- // Check if line terminates the textresponse
- if ($line == ".\r\n") {
- // return all previous lines
- return $data;
- break;
+ // Validate recieved line
+ if (false) {
+ // Lines should/may not be longer than 998+2 chars (RFC2822 2.3)
+ if (strlen($line) > 1000) {
+ return PEAR::throwError('Invalid line recieved!', null);
+ }
}
- // Remove "\r\n" from the end of the line
- $line = substr($line, 0, -2);
+ // Remove CRLF from the end of the line
+ $line = substr($line, 0, -2);
+
+ // Check if the line terminates the textresponse
+ if ($line == '.') {
+ // return all previous lines
+ return $data;
+ break;
+ }
// If 1st char is '.' it's doubled (NNTP/RFC977 2.4.1)
if (substr($line, 0, 2) == '..') {
$line = substr($line, 1);
- }
+ }
// Add the line to the array of lines
$data[] = $line;
+
+ // Reset/empty $line
+ $line = '';
}
return PEAR::throwError('Data stream not terminated with period', null);
- }
+ }
// }}}
// {{{ _sendCommand()
@@ -1095,7 +1108,8 @@
*/
function _sendCommand($cmd)
{
- if (!strlen($cmd) > 510) { // NNTP/RFC977 only allows command up to 512 (-2) chars.
+ // NNTP/RFC977 only allows command up to 512 (-2) chars.
+ if (!strlen($cmd) > 510) {
return PEAR::throwError('Failed to write to socket! (Command to long - max 510
chars)');
}