/** debug mode */
private $debug = false;
+ private $bt = array();
/** constructor
* @param $host STRING NNTP host
}
$this->checkState();
- $this->posting = ($this->lastresultcode == '200');
+ $this->posting = ($this->lastresultcode == '200');
if ($reader && $this->posting) {
$this->execLine('MODE READER');
$this->posting = ($this->lastresultcode == '200');
public function lastError()
{
- return $this->lasterrortext;
+ if (!is_utf8($this->lasterrortext)) {
+ return utf8_encode($this->lasterrortext);
+ } else {
+ return $this->lasterrortext;
+ }
+ }
+
+ public function backtrace()
+ {
+ if ($this->debug) {
+ return $this->bt;
+ } else {
+ return null;
+ }
}
# Socket functions
/** get a line from server
* @return STRING
*/
- private function getLine()
+ private function &getLine()
{
- return rtrim(fgets($this->ns, 1200));
+ $data = rtrim(@fgets($this->ns, 1200), "\r\n");
+ return $data;
}
/** fetch data (and on delimitor)
* @param STRING $delim string indicating and of transmission
*/
- private function fetchResult($callback = null)
+ private function &fetchResult()
{
$array = Array();
- while (($result = $this->getLine()) != '.') {
- if (!is_null($callback)) {
- list($key, $result) = call_user_func($callback, $result);
- if (is_null($result)) {
- continue;
- }
- if (is_null($key)) {
- $array[] = $result;
- } else {
- $array[$key] = $result;
- }
- } else {
- $array[] = $result;
- }
+ while (($result =& $this->getLine()) != '.') {
+ $array[] =& $result;
+ }
+ if ($this->debug && $this->bt) {
+ $trace =& $this->bt[count($this->bt) - 1];
+ $trace['response'] = count($array);
+ $trace['time'] = microtime(true) - $trace['start'];
}
return $array;
}
}
if ($this->debug) {
$db_line = preg_replace('/PASS .*/', 'PASS *******', $line);
- echo $db_line;
+ $this->bt[] = array('action' => $db_line, 'start' => microtime(true));
}
- return fputs($this->ns, $line, strlen($line));
+ return @fputs($this->ns, $line, strlen($line));
}
/** put a message (multiline)
$message = join("\n", $_message);
}
if ($message) {
+ $message = preg_replace("/(^|\n)\./", '\1..', $message);
$this->putLine("$message\r\n", false);
}
return $this->execLine('.');
private function checkState($strict = true)
{
$result = $this->getLine();
- if ($this->debug) {
- echo "$result\n";
- }
$this->lastresultcode = substr($result, 0, 3);
$this->lastresulttext = substr($result, 4);
+ if ($this->debug && $this->bt) {
+ $trace =& $this->bt[count($this->bt) - 1];
+ $trace['time'] = microtime(true) - $trace['start'];
+ $trace['code'] = $this->lastresultcode;
+ $trace['message'] = $this->lastresulttext;
+ $trace['response'] = 0;
+ }
$c = $this->lastresultcode{0};
if ($c == '2' || (($c == '1' || $c == '3') && !$strict)) {
return true;
$groups = array();
foreach ($list as $result) {
list($group, $last, $first, $p) = explode(' ', $result, 4);
- if (!is_null(Banana::$boxpattern) || preg_match('@' . Banana::$boxpattern . '@i', $group)) {
+ if (!Banana::$boxpattern || preg_match('@' . Banana::$boxpattern . '@i', $group)) {
$groups[$group] = array(intval($last), intval($first), $p);
}
}
if (!$this->execLine("XGTITLE $pattern ")) {
return false;
}
- $array = $this->fetchResult();
+ $array =& $this->fetchResult();
$groups = array();
- foreach ($array as $result) {
- list($group, $desc) = split("[ \t]", $result, 2);
+ foreach ($array as &$result) {
+ @list($group, $desc) = preg_split("[ \t]", $result, 2);
$groups[$group] = $desc;
}
return $groups;
if (!$this->execLine("XHDR $hdr $range ")) {
return false;
}
- $array = $this->fetchResult();
+ $array =& $this->fetchResult();
$headers = array();
foreach ($array as &$result) {
@list($head, $value) = explode(' ', $result, 2);
if (!$this->execLine("XPAT $hdr $range $pat")) {
return false;
}
- $array = $this->fetchResult();
+ $array =& $this->fetchResult();
$headers = array();
foreach ($array as &$result) {
list($head, $value) = explode(' ', $result, 2);
}
}
-// vim:set et sw=4 sts=4 ts=4
+// vim:set et sw=4 sts=4 ts=4 enc=utf-8:
?>