From 0e1086c99fc4b5a90cb3ecc63bc4cb4df607f96f Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 27 Nov 2024 22:19:30 +1100 Subject: [PATCH] Fixes for Zmodem missed in bf3fce --- app/Classes/Protocol.php | 2 ++ app/Classes/Protocol/EMSI.php | 16 ++++++++++++---- app/Classes/Protocol/Zmodem.php | 4 +++- app/Classes/Sock/SocketServer.php | 2 ++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/Classes/Protocol.php b/app/Classes/Protocol.php index 88896c1..01735ce 100644 --- a/app/Classes/Protocol.php +++ b/app/Classes/Protocol.php @@ -288,6 +288,8 @@ abstract class Protocol else { Log::withContext(['pid'=>getmypid()]); + Log::debug(sprintf('%s:* Client session starting',self::LOGKEY)); + $this->session($client,(new Address)); } diff --git a/app/Classes/Protocol/EMSI.php b/app/Classes/Protocol/EMSI.php index 6b1e729..bbc7743 100644 --- a/app/Classes/Protocol/EMSI.php +++ b/app/Classes/Protocol/EMSI.php @@ -921,8 +921,16 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface $t1 = $this->client->timer_set(self::EMSI_HSTIMEOUT); $t2 = $this->client->timer_set(self::EMSI_RESEND_TO); + $c = 0; while (! $this->client->timer_expired($t1)) { - $ch = $this->client->read_ch(max( 1,min($this->client->timer_rest($t1),$this->client->timer_rest($t2)))); + try { + $ch = $this->client->read_ch(max( 1,min($this->client->timer_rest($t1),$this->client->timer_rest($t2)))); + + } catch (SocketException $e) { + if ($c++ > 2) + return self::TIMEOUT; + } + if (static::DEBUG) Log::debug(sprintf('%s:- Got [%x] (%c)',self::LOGKEY,$ch,$ch)); @@ -1193,7 +1201,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface Log::debug(sprintf('%s:+ Start WAZOO Receive',self::LOGKEY)); // @todo If the node is not defined in the DB node->address is NULL. Need to figure out how to handle those nodes. - $rc = (new Zmodem)->zmodem_receive($this->client,$zap,$this->recv,$this->node->address,$this->force_queue); + $rc = (new Zmodem($this->setup))->zmodem_receive($this->client,$zap,$this->recv,$this->node->address,$this->force_queue); return ($rc === self::RCDO || $rc === self::ERROR); } @@ -1217,7 +1225,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface foreach ($this->node->aka_remote_authed as $ao) { // Send mail while ($this->send->mail($ao)) { - $z = new Zmodem; + $z = new Zmodem($this->setup); if (! $z->zmodem_sendinit($this->client,$zap) && $this->send->togo_count) $z->zmodem_sendfile($this->send,$this->node); @@ -1225,7 +1233,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface // Send files while ($this->send->files($ao)) { - $z = new Zmodem; + $z = new Zmodem($this->setup); if (! $z->zmodem_sendinit($this->client,$zap) && $this->send->togo_count) $z->zmodem_sendfile($this->send,$this->node); diff --git a/app/Classes/Protocol/Zmodem.php b/app/Classes/Protocol/Zmodem.php index 3fb7322..13774e1 100644 --- a/app/Classes/Protocol/Zmodem.php +++ b/app/Classes/Protocol/Zmodem.php @@ -516,7 +516,9 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface return $rc; } catch (\Exception $e) { - Log::error(sprintf('%s:! Error [%s]',self::LOGKEY,$e->getMessage())); + Log::error(sprintf('%s:! Error [%s]',self::LOGKEY,$e->getMessage()),['rc'=>$rc]); + + return $rc; } } diff --git a/app/Classes/Sock/SocketServer.php b/app/Classes/Sock/SocketServer.php index c0642a6..cfab49d 100644 --- a/app/Classes/Sock/SocketServer.php +++ b/app/Classes/Sock/SocketServer.php @@ -127,6 +127,8 @@ final class SocketServer { if (($accept = socket_accept($this->server)) === FALSE) throw new SocketException(SocketException::CANT_ACCEPT,socket_strerror(socket_last_error($this->server))); + Log::debug(sprintf('%s:* TCP Loop Start',self::LOGKEY)); + try { $r = new SocketClient($accept);