Optimise BINKP msg processing by using ltrim instead of skip_blanks. Should also address taurus mailers that add a NULL to the end of ADR messages
This commit is contained in:
parent
76dc90ceb3
commit
b3dfca5b89
@ -436,12 +436,17 @@ final class Binkp extends BaseProtocol
|
||||
switch ($msg) {
|
||||
case self::BPM_ADR:
|
||||
Log::debug(sprintf('%s:- ADR:Address [%s]',self::LOGKEY,$data));
|
||||
$rc = $this->M_adr($data);
|
||||
// @note It seems taurus may pad data with nulls at the end (esp BPM_ADR), so we should trim that.
|
||||
$rc = $this->M_adr(trim($data));
|
||||
break;
|
||||
|
||||
case self::BPM_EOB:
|
||||
Log::debug(sprintf('%s:- EOB:We got an EOB message with [%d] chars in the buffer',self::LOGKEY,strlen($data)));
|
||||
$rc = $this->M_eob($data);
|
||||
|
||||
if (strlen($data))
|
||||
Log::critical(sprintf('%s:! EOB but we have data?',self::LOGKEY),['data'=>$data]);
|
||||
|
||||
$rc = $this->M_eob();
|
||||
break;
|
||||
|
||||
case self::BPM_NUL:
|
||||
@ -451,7 +456,7 @@ final class Binkp extends BaseProtocol
|
||||
|
||||
case self::BPM_PWD:
|
||||
Log::debug(sprintf('%s:- PWD:We got a password [%s]',self::LOGKEY,$data));
|
||||
$rc = $this->M_pwd($data);
|
||||
$rc = $this->M_pwd(ltrim($data));
|
||||
break;
|
||||
|
||||
case self::BPM_ERR:
|
||||
@ -476,7 +481,7 @@ final class Binkp extends BaseProtocol
|
||||
|
||||
case self::BPM_OK:
|
||||
Log::debug(sprintf('%s:- OK:Got an OK [%s]',self::LOGKEY,$data));
|
||||
$rc = $this->M_ok($data);
|
||||
$rc = $this->M_ok(ltrim($data));
|
||||
break;
|
||||
|
||||
case self::BPM_CHAT:
|
||||
@ -680,7 +685,6 @@ final class Binkp extends BaseProtocol
|
||||
*/
|
||||
private function M_adr(string $buf): bool
|
||||
{
|
||||
$buf = $this->skip_blanks($buf);
|
||||
$rc = 0;
|
||||
|
||||
while ($rem_aka=$this->strsep($buf,' ')) {
|
||||
@ -810,7 +814,7 @@ final class Binkp extends BaseProtocol
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function M_eob(string $buf): bool
|
||||
private function M_eob(): bool
|
||||
{
|
||||
if ($this->recv->fd) {
|
||||
Log::info(sprintf('%s:= Closing receiving file.',self::LOGKEY));
|
||||
@ -1034,16 +1038,16 @@ final class Binkp extends BaseProtocol
|
||||
Log::info(sprintf('%s:+ M_NUL [%s]',self::LOGKEY,$buf));
|
||||
|
||||
if (! strncmp($buf,'SYS ',4)) {
|
||||
$this->node->system = $this->skip_blanks(substr($buf,4));
|
||||
$this->node->system = ltrim(substr($buf,4));
|
||||
|
||||
} elseif (! strncmp($buf, 'ZYZ ',4)) {
|
||||
$this->node->sysop = $this->skip_blanks(substr($buf,4));
|
||||
$this->node->sysop = ltrim(substr($buf,4));
|
||||
|
||||
} elseif (! strncmp($buf,'LOC ',4)) {
|
||||
$this->node->location = $this->skip_blanks(substr($buf,4));
|
||||
$this->node->location = ltrim(substr($buf,4));
|
||||
|
||||
} elseif (! strncmp($buf,'NDL ',4)) {
|
||||
$data = $this->skip_blanks(substr($buf,4));
|
||||
$data = ltrim(substr($buf,4));
|
||||
$comma = strpos($data,',');
|
||||
$spd = substr($data,0,$comma);
|
||||
|
||||
@ -1054,7 +1058,7 @@ final class Binkp extends BaseProtocol
|
||||
$this->client->speed = $spd;
|
||||
|
||||
} else {
|
||||
$comma = $this->skip_blanks(substr($buf,4));
|
||||
$comma = ltrim(substr($buf,4));
|
||||
$c = 0;
|
||||
while (($x=substr($comma,$c,1)) && is_numeric($x))
|
||||
$c++;
|
||||
@ -1076,10 +1080,10 @@ final class Binkp extends BaseProtocol
|
||||
}
|
||||
|
||||
} elseif (! strncmp($buf,'TIME ',5)) {
|
||||
$this->node->node_time = $this->skip_blanks(substr($buf,5));
|
||||
$this->node->node_time = ltrim(substr($buf,5));
|
||||
|
||||
} elseif (! strncmp($buf,'VER ',4)) {
|
||||
$data = $this->skip_blanks(substr($buf,4));
|
||||
$data = ltrim(substr($buf,4));
|
||||
$matches = [];
|
||||
preg_match('#^(.+)\s+\(?binkp/([0-9]+)\.([0-9]+)\)?$#',$data,$matches);
|
||||
|
||||
@ -1094,7 +1098,7 @@ final class Binkp extends BaseProtocol
|
||||
}
|
||||
|
||||
} elseif (! strncmp($buf,'TRF ',4)) {
|
||||
$data = $this->skip_blanks(substr($buf,4));
|
||||
$data = ltrim(substr($buf,4));
|
||||
$matches = [];
|
||||
preg_match('/^([0-9]+)\s+([0-9]+)$/',$data,$matches);
|
||||
|
||||
@ -1108,13 +1112,13 @@ final class Binkp extends BaseProtocol
|
||||
$this->sessionSet(self::SE_DELAYEOB);
|
||||
|
||||
} elseif (! strncmp($buf,'PHN ',4)) {
|
||||
$this->node->phone = $this->skip_blanks(substr($buf,4));
|
||||
$this->node->phone = ltrim(substr($buf,4));
|
||||
|
||||
} elseif (! strncmp($buf,'OPM ',4)) {
|
||||
$this->node->message = $this->skip_blanks(substr($buf,4));
|
||||
$this->node->message = ltrim(substr($buf,4));
|
||||
|
||||
} elseif (! strncmp($buf,'OPT ',4)) {
|
||||
$data = $this->skip_blanks(substr($buf,4));
|
||||
$data = ltrim(substr($buf,4));
|
||||
|
||||
while ($data && ($p = $this->strsep($data,' '))) {
|
||||
if (! strcmp($p,'MB')) {
|
||||
@ -1198,8 +1202,6 @@ final class Binkp extends BaseProtocol
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$buf = $this->skip_blanks($buf);
|
||||
|
||||
if ($this->optionGet(self::O_PWD) && $buf) {
|
||||
while (($t=$this->strsep($buf," \t")))
|
||||
if (strcmp($t,'non-secure') === 0) {
|
||||
@ -1226,7 +1228,6 @@ final class Binkp extends BaseProtocol
|
||||
*/
|
||||
private function M_pwd(string $buf): bool
|
||||
{
|
||||
$buf = $this->skip_blanks($buf);
|
||||
$have_CRAM = !strncasecmp($buf,'CRAM-MD5-',9);
|
||||
$have_pwd = $this->optionGet(self::O_PWD);
|
||||
|
||||
@ -1502,7 +1503,7 @@ final class Binkp extends BaseProtocol
|
||||
* @param string $str
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
* @todo Can this be replaced with ltrim?
|
||||
* @deprecated - use ltrim instead
|
||||
*/
|
||||
private function skip_blanks(string $str): string
|
||||
{
|
||||
@ -1542,6 +1543,7 @@ final class Binkp extends BaseProtocol
|
||||
* @param string $str
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
* @deprecated No longer required since we are using ltrim
|
||||
*/
|
||||
private function isSpace(string $str):bool
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user