Simplified logging and fix BINKP issue when receiving less than the blksize

This commit is contained in:
Deon George
2021-08-17 23:49:39 +10:00
parent 5bf612e5b4
commit 978843b5e3
7 changed files with 285 additions and 253 deletions

View File

@@ -19,10 +19,10 @@ use App\Traits\CRC as CRCTrait;
final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
{
use CRCTrait;
private const LOGKEY = 'PE-';
use CRCTrait;
private const EMSI_BEG = '**EMSI_';
private const EMSI_ARGUS1 = '-PZT8AF6-';
private const EMSI_DAT = self::EMSI_BEG.'DAT';
@@ -82,9 +82,12 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
{
// If our parent returns a PID, we've forked
if (! parent::onConnect($client)) {
Log::withContext(['pid'=>getmypid()]);
$this->session(self::SESSION_AUTO,$client,(new Address));
$this->client->close();
Log::info(sprintf('%s: = End - Connection closed [%s]',__METHOD__,$client->address_remote));
Log::info(sprintf('%s:= onConnect - Connection closed [%s]',self::LOGKEY,$client->address_remote));
exit(0);
}
@@ -98,7 +101,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
*/
private function emsi_banner(): void
{
Log::debug(sprintf('%s: + Start',__METHOD__));
Log::debug(sprintf('%s:+ emsi_banner',self::LOGKEY));
$banner = 'This is a mail only system - unless you are a mailer, you should disconnect :)';
$this->client->buffer_add(self::EMSI_REQ.str_repeat(self::DEL,strlen(self::EMSI_REQ)).$banner.self::CR);
@@ -254,12 +257,13 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
*/
private function emsi_parsedat(string $str): int
{
Log::debug(sprintf('%s: + Start',__METHOD__));
if ($this->DEBUG)
Log::debug(sprintf('%s:+ emsi_parsedat',self::LOGKEY));
$l = 0;
if (! ($str=strstr($str,self::EMSI_DAT))) {
Log::error(sprintf('%s: ! No EMSI_DAT signature found?',__METHOD__));
Log::error(sprintf('%s:! No EMSI_DAT signature found?',self::LOGKEY));
return 0;
}
@@ -269,7 +273,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
/* Bad EMSI length */
if ($l != ($x=strlen($str)-18)) {
Log::error(sprintf('%s: ! Bad EMSI_DAT length: [%u], should be: [%u]!',__METHOD__,$l,$x));
Log::error(sprintf('%s:! Bad EMSI_DAT length: [%u], should be: [%u]!',self::LOGKEY,$l,$x));
return 0;
}
@@ -279,14 +283,14 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
/* Bad EMSI CRC */
if ($l != ($x = crc16(substr($str,2,strlen($str)-6)))) {
Log::error(sprintf('%s: ! Bad EMSI_DAT CRC: [%04X], should be: [%04X]!',__METHOD__,$l,$x));
Log::error(sprintf('%s:! Bad EMSI_DAT CRC: [%04X], should be: [%04X]!',self::LOGKEY,$l,$x));
return 0;
}
/* No EMSI ident */
if (strncmp(substr($str,14),"{EMSI}",6)) {
Log::error(sprintf('%s: ! No EMSI fingerprint?',__METHOD__));
Log::error(sprintf('%s:! No EMSI fingerprint?',self::LOGKEY));
return 0;
}
@@ -294,34 +298,34 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
/* {AKAs} */
$x = 21;
foreach (explode(' ',$this->emsi_dat_parse($str,$x)) as $rem_aka) {
Log::debug(sprintf('%s: - Parsing AKA [%s]',__METHOD__,$rem_aka));
Log::debug(sprintf('%s: - Parsing AKA [%s]',self::LOGKEY,$rem_aka));
try {
if (! ($o = Address::findFTN($rem_aka))) {
Log::debug(sprintf('%s: ? AKA is UNKNOWN [%s]',__METHOD__,$rem_aka));
Log::debug(sprintf('%s: ? AKA is UNKNOWN [%s]',self::LOGKEY,$rem_aka));
continue;
}
} catch (Exception) {
Log::error(sprintf('%s: ! AKA is INVALID [%s]',__METHOD__,$rem_aka));
Log::error(sprintf('%s: ! AKA is INVALID [%s]',self::LOGKEY,$rem_aka));
continue;
}
// Check if the remote has our AKA
if ($this->setup->system->addresses->pluck('ftn')->search($o->ftn) !== FALSE) {
Log::error(sprintf('%s: ! AKA is OURS [%s]',__METHOD__,$o->ftn));
Log::error(sprintf('%s: ! AKA is OURS [%s]',self::LOGKEY,$o->ftn));
continue;
}
// @todo lock nodes
Log::info(sprintf('%s: - Remote AKA [%s]',__METHOD__,$o->ftn));
Log::info(sprintf('%s: - Remote AKA [%s]',self::LOGKEY,$o->ftn));
$this->node->ftn = $o;
}
if ($this->originate AND ! $this->node->originate_check()) {
Log::error(sprintf('%s: ! We didnt get who we called?',__METHOD__));
Log::error(sprintf('%s: ! We didnt get who we called?',self::LOGKEY));
return self::S_FAILURE|self::S_ADDTRY;
}
@@ -340,18 +344,18 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
}
if (! $c) {
Log::info(sprintf('%s: - Remote has password [%s] on us, and we expect [%s]',__METHOD__,$p,$this->node->password));
Log::info(sprintf('%s: - Remote has password [%s] on us, and we expect [%s]',self::LOGKEY,$p,$this->node->password));
if ($p || $this->node->password)
$this->node->optionSet(self::O_BAD);
} else {
$this->node->optionSet(self::O_PWD);
Log::info(sprintf('%s: - Remote Authed [%d] AKAs',__METHOD__,$c));
Log::info(sprintf('%s: - Remote Authed [%d] AKAs',self::LOGKEY,$c));
}
/* Link codes */
Log::notice(sprintf('%s: - Remote Link Codes [%s]',__METHOD__,$this->emsi_dat_parse($str,$x)));
Log::notice(sprintf('%s: - Remote Link Codes [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x)));
/* Compatibility codes */
$codes = $this->emsi_dat_parse($str,$x);
@@ -359,44 +363,44 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
foreach (explode(',',$codes) as $code) {
switch ($code) {
case 'ARC':
Log::debug(sprintf('%s: = Node accepts ARC mail bundle (ARC)',__METHOD__));
Log::debug(sprintf('%s: = Node accepts ARC mail bundle (ARC)',self::LOGKEY));
break;
case 'NRQ':
Log::debug(sprintf('%s: = No file requests accepted by this system (NRQ)',__METHOD__));
Log::debug(sprintf('%s: = No file requests accepted by this system (NRQ)',self::LOGKEY));
$this->node->optionSet(self::O_NRQ);
break;
case 'XMA':
Log::debug(sprintf('%s: = Node supports other forms of compressed mail (XMA)',__METHOD__));
Log::debug(sprintf('%s: = Node supports other forms of compressed mail (XMA)',self::LOGKEY));
break;
case 'ZAP':
Log::debug(sprintf('%s: = Remote wants ZEDZAP',__METHOD__));
Log::debug(sprintf('%s: = Remote wants ZEDZAP',self::LOGKEY));
$this->node->optionSet(self::P_ZEDZAP);
break;
case 'ZMO':
Log::debug(sprintf('%s: = Remote wants ZMODEM',__METHOD__));
Log::debug(sprintf('%s: = Remote wants ZMODEM',self::LOGKEY));
$this->node->optionSet(self::P_ZMODEM);
break;
default:
Log::info(sprintf('%s: = Ignoring unknown option: [%s] ',__METHOD__,$code));
Log::info(sprintf('%s: = Ignoring unknown option: [%s] ',self::LOGKEY,$code));
}
}
/* Mailer code */
Log::notice(sprintf('%s: - Remote Mailer Code [%s]',__METHOD__,$this->emsi_dat_parse($str,$x))); // hex
Log::notice(sprintf('%s: - Remote Mailer Code [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x))); // hex
/* Mailer name */
Log::notice(sprintf('%s: - Remote Mailer [%s]',__METHOD__,$this->emsi_dat_parse($str,$x)));
Log::notice(sprintf('%s: - Remote Mailer [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x)));
/* Mailer version */
Log::notice(sprintf('%s: - Remote Mailer Version [%s]',__METHOD__,$this->emsi_dat_parse($str,$x)));
Log::notice(sprintf('%s: - Remote Mailer Version [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x)));
/* Mailer serial number */
Log::notice(sprintf('%s: - Remote Mailer Serial Number [%s]',__METHOD__,$this->emsi_dat_parse($str,$x)));
Log::notice(sprintf('%s: - Remote Mailer Serial Number [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x)));
while ($t=strpos($str,'}',$x)) {
$p = substr($str,$x,$t-$x);
@@ -407,22 +411,22 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
case 'IDENT':
/* System name */
$x = $t+2;
Log::notice(sprintf('%s: - Remote System [%s]',__METHOD__,$this->emsi_dat_parse($str,$x,']')));
Log::notice(sprintf('%s: - Remote System [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x,']')));
/* System location */
Log::notice(sprintf('%s: - Remote Location [%s]',__METHOD__,$this->emsi_dat_parse($str,$x,']')));
Log::notice(sprintf('%s: - Remote Location [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x,']')));
/* Operator name */
Log::notice(sprintf('%s: - Remote Operator [%s]',__METHOD__,$this->emsi_dat_parse($str,$x,']')));
Log::notice(sprintf('%s: - Remote Operator [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x,']')));
/* Phone */
Log::notice(sprintf('%s: - Remote Phone Number [%s]',__METHOD__,$this->emsi_dat_parse($str,$x,']')));
Log::notice(sprintf('%s: - Remote Phone Number [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x,']')));
/* Baud rate */
$this->client->speed = $this->emsi_dat_parse($str,$x,']');
/* Flags */
Log::notice(sprintf('%s: - Remote Flags [%s]',__METHOD__,$this->emsi_dat_parse($str,$x,']')));
Log::notice(sprintf('%s: - Remote Flags [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x,']')));
$x++;
break;
@@ -430,21 +434,21 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
// {TRAF}{}
case 'TRAF':
$x = $t+1;
Log::notice(sprintf('%s: - Remote TRAF [%s]',__METHOD__,$this->emsi_dat_parse($str,$x)));
Log::notice(sprintf('%s: - Remote TRAF [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x)));
break;
// {OHFR}{}
case 'OHFR':
$x = $t+1;
Log::notice(sprintf('%s: - Remote OHFR [%s]',__METHOD__,$this->emsi_dat_parse($str,$x)));
Log::notice(sprintf('%s: - Remote OHFR [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x)));
break;
// {MOH#}{[]}
case 'MOH#':
$x = $t+2;
Log::notice(sprintf('%s: - Remote MOH# [%s]',__METHOD__,$this->emsi_dat_parse($str,$x,']')));
Log::notice(sprintf('%s: - Remote MOH# [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x,']')));
$x++;
break;
@@ -452,7 +456,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
// {TRX#}{[]}
case 'TRX#':
$x = $t+2;
Log::notice(sprintf('%s: - Remote TRX [%s]',__METHOD__,$this->emsi_dat_parse($str,$x,']')));
Log::notice(sprintf('%s: - Remote TRX [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x,']')));
$x++;
break;
@@ -460,14 +464,14 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
// {TZUTC}{[]}
case 'TZUTC':
$x = $t+2;
Log::notice(sprintf('%s: - Remote TZUTC [%s]',__METHOD__,$this->emsi_dat_parse($str,$x,']')));
Log::notice(sprintf('%s: - Remote TZUTC [%s]',self::LOGKEY,$this->emsi_dat_parse($str,$x,']')));
$x++;
break;
default:
$x = $t+1;
Log::notice(sprintf('%s: - Remote UNKNOWN [%s] (%s)',__METHOD__,$this->emsi_dat_parse($str,$x),$p));
Log::notice(sprintf('%s: - Remote UNKNOWN [%s] (%s)',self::LOGKEY,$this->emsi_dat_parse($str,$x),$p));
}
}
@@ -482,9 +486,9 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
*/
private function emsi_recv(int $mode): int
{
Log::debug(sprintf('%s: + Start',__METHOD__));
Log::debug(sprintf('%s:+ emsi_recv',self::LOGKEY));
Log::debug(sprintf('%s: - STEP 1',__METHOD__));
Log::debug(sprintf('%s: - STEP 1',self::LOGKEY));
/*
* Step 1
* +-+------------------------------------------------------------------+
@@ -499,7 +503,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
do {
step2:
Log::debug(sprintf('%s: - STEP 2',__METHOD__));
Log::debug(sprintf('%s: - STEP 2',self::LOGKEY));
/* Step 2
+-+------------------------------------------------------------------+
:2: Increment Tries :
@@ -530,7 +534,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
$this->client->buffer_flush(5);
step3:
Log::debug(sprintf('%s: - STEP 3',__METHOD__));
Log::debug(sprintf('%s: - STEP 3',self::LOGKEY));
/* Step 3
* +-+------------------------------------------------------------------+
* :3: T1=20 seconds :
@@ -540,7 +544,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
$t1 = $this->client->timer_set(20);
step4:
Log::debug(sprintf('%s: - STEP 4',__METHOD__));
Log::debug(sprintf('%s: - STEP 4',self::LOGKEY));
/* Step 4
+-+------------------------------------------------------------------+
:4: Wait for EMSI sequence until EMSI_HBT or EMSI_DAT or any of the :
@@ -586,15 +590,15 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
if (($ch == ord(self::CR)) || ($ch == ord(self::NL))) {
if (! strncmp($p,self::EMSI_HBT,self::EMSI_SEQ_LEN)) {
Log::debug(sprintf('%s: - Received EMSI_HBT',__METHOD__));
Log::debug(sprintf('%s: - Received EMSI_HBT',self::LOGKEY));
goto step3;
}
if (! strncmp($p,self::EMSI_DAT,10)) {
Log::debug(sprintf('%s: - Received EMSI_DAT',__METHOD__));
Log::debug(sprintf('%s:- Received EMSI_DAT',self::LOGKEY));
Log::debug(sprintf('%s: - STEP 5',__METHOD__));
Log::debug(sprintf('%s: - STEP 5',self::LOGKEY));
/* Step 5
+-+------------------------------------------------------------------+
:5: Receive EMSI_DAT packet :
@@ -612,7 +616,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
$this->client->buffer_add(self::EMSI_ACK.self::CR);
$this->client->buffer_flush(5);
Log::debug(sprintf('%s: - STEP 6',__METHOD__));
Log::debug(sprintf('%s: - STEP 6',self::LOGKEY));
/* Step 6
+-+------------------------------------------------------------------+
:6: Received EMSI_DAT packet OK, exit. :
@@ -622,7 +626,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
return self::OK;
} else {
Log::debug(sprintf('%s: - EMSI_DAT didnt parse',__METHOD__));
Log::debug(sprintf('%s: - EMSI_DAT didnt parse',self::LOGKEY));
goto step2;
}
@@ -633,11 +637,11 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
} else {
if (strlen($p) >= self::EMSI_BUF) {
Log::warning(sprintf('%s: ! EMSI_DAT packet too long.',__METHOD__));
Log::warning(sprintf('%s: ! EMSI_DAT packet too long.',self::LOGKEY));
$rew = strstr($p,self::EMSI_BEG,TRUE);
if ($rew && $rew != $p) {
Log::notice(sprintf('%s: - Got EMSI_DAT at offset [%d].',__METHOD__,strlen($rew)));
Log::notice(sprintf('%s: - Got EMSI_DAT at offset [%d].',self::LOGKEY,strlen($rew)));
$p = substr($p,strlen($rew));
}
@@ -661,9 +665,9 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
*/
private function emsi_send(): int
{
Log::debug(sprintf('%s: + Start',__METHOD__));
Log::debug(sprintf('%s:+ emsi_send',self::LOGKEY));
Log::debug(sprintf('%s: - STEP 1',__METHOD__));
Log::debug(sprintf('%s: - STEP 1',self::LOGKEY));
/* Step 1
+-+------------------------------------------------------------------+
:1: Tries=0, T1=60 seconds :
@@ -675,7 +679,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
$t1 = $this->client->timer_set(self::EMSI_HSTIMEOUT);
step2:
Log::debug(sprintf('%s: - STEP 2',__METHOD__));
Log::debug(sprintf('%s: - STEP 2',self::LOGKEY));
/* Step 2
+-+------------------------------------------------------------------+
:2: Transmit EMSI_DAT packet and increment Tries :
@@ -697,7 +701,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
:3: T2=20 seconds :
+-+------------------------------------------------------------------+
*/
Log::debug(sprintf('%s: - STEP 3',__METHOD__));
Log::debug(sprintf('%s: - STEP 3',self::LOGKEY));
$t2 = $this->client->timer_set(20);
/* Step 4
@@ -715,7 +719,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
: : If any other sequence received, go to step 2. :
+-+------------------------------------------------------------------+
*/
Log::debug(sprintf('%s: - STEP 4',__METHOD__));
Log::debug(sprintf('%s: - STEP 4',self::LOGKEY));
while(! $this->client->timer_expired($t1)) {
$ch = $this->client->read_ch(max( 1,min($this->client->timer_rest($t1),$this->client->timer_rest($t2))));
// Log::debug(sprintf('%s: - Got (%x) {%03d} (%c)',__METHOD__,$ch,$ch,$ch));
@@ -739,7 +743,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
continue;
if (! strncmp($p,self::EMSI_DAT,10)) {
Log::warning(sprintf('%s: - Got unexpected EMSI_DAT - Argus?',__METHOD__));
Log::warning(sprintf('%s: - Got unexpected EMSI_DAT - Argus?',self::LOGKEY));
$this->client->buffer_add(self::EMSI_ACK);
$this->client->buffer_add(self::EMSI_ACK);
$this->client->buffer_flush(1);
@@ -747,12 +751,12 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
$t2 = $this->client->timer_set($this->client->timer_rest($t2) >> 2);
} else if (! strncmp($p,self::EMSI_REQ,self::EMSI_SEQ_LEN)) {
Log::notice(sprintf('%s: - Got EMSI_REQ - skipping...',__METHOD__));
Log::notice(sprintf('%s: - Got EMSI_REQ - skipping...',self::LOGKEY));
} else if (! strncmp($p,self::EMSI_ACK,self::EMSI_SEQ_LEN)) {
Log::debug(sprintf('%s: - Got EMSI_ACK',__METHOD__));
Log::debug(sprintf('%s: - Got EMSI_ACK',self::LOGKEY));
Log::debug(sprintf('%s: - STEP 5',__METHOD__));
Log::debug(sprintf('%s: - STEP 5',self::LOGKEY));
/* Step 5
+-+------------------------------------------------------------------+
:5: Received EMSI_ACK, exit. :
@@ -772,7 +776,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
$p .= chr($ch);
} else {
Log::warning(sprintf('%s: ! EMSI packet too long',__METHOD__));
Log::warning(sprintf('%s: ! EMSI packet too long',self::LOGKEY));
}
}
} /* goto step4; */
@@ -801,7 +805,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
protected function protocol_init(): int
{
if ($this->DEBUG)
Log::debug(sprintf('%s: + Start',__METHOD__));
Log::debug(sprintf('%s:+ protocol_init',self::LOGKEY));
$got = 0;
$tries = 0;
@@ -824,7 +828,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
while (TRUE) {
$ch = $this->client->read_ch(max( 1,min($this->client->timer_rest($t1),$this->client->timer_rest($t2))));
if ($this->DEBUG)
Log::debug(sprintf('%s: - Got [%x] (%c)',__METHOD__,$ch,$ch));
Log::debug(sprintf('%s: - Got [%x] (%c)',self::LOGKEY,$ch,$ch));
if (($ch != self::TIMEOUT) && ($ch < 0))
return $ch;
@@ -843,7 +847,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
if (++$tries > 10)
return self::TIMEOUT;
Log::debug(sprintf('%s: - Sending EMSI_INQ (Try %d of 10)...',__METHOD__,$tries));
Log::debug(sprintf('%s: - Sending EMSI_INQ (Try %d of 10)...',self::LOGKEY,$tries));
$this->client->buffer_add(self::EMSI_INQ.self::CR);
}
@@ -858,7 +862,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
if (($ch == ord(self::CR)) || ($ch == ord(self::NL))) {
if (strstr($p,self::EMSI_REQ)) {
Log::info(sprintf('%s: - Got EMSI_REQ',__METHOD__));
Log::info(sprintf('%s: - Got EMSI_REQ',self::LOGKEY));
if ($gotreq++)
return self::OK;
@@ -866,7 +870,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
$this->client->buffer_flush(5);
} elseif ($p && strstr($p,self::EMSI_BEG) && strstr($p,self::EMSI_ARGUS1)) {
Log::info(sprintf('%s: - Got Intro [%s]',__METHOD__,$p));
Log::info(sprintf('%s: - Got Intro [%s]',self::LOGKEY,$p));
}
continue;
@@ -890,7 +894,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
while (! $this->client->timer_expired($t1)) {
$ch = $this->client->read_ch(max( 1,min($this->client->timer_rest($t1),$this->client->timer_rest($t2))));
if ($this->DEBUG)
Log::debug(sprintf('%s: - Got [%x] (%c)',__METHOD__,$ch,$ch));
Log::debug(sprintf('%s: - Got [%x] (%c)',self::LOGKEY,$ch,$ch));
if (($ch != self::TIMEOUT) && ($ch < 0))
return $ch;
@@ -919,7 +923,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
$got = 0;
if (strstr($p, self::EMSI_INQ)) {
Log::info(sprintf('%s: - Got EMSI_REQ',__METHOD__));
Log::info(sprintf('%s: - Got EMSI_REQ',self::LOGKEY));
return self::OK;
}
@@ -944,7 +948,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
*/
protected function protocol_session(): int
{
Log::debug(sprintf('%s: + Start',__METHOD__));
Log::debug(sprintf('%s:+ protocol_session',self::LOGKEY));
$was_req = 0;
$got_req = 0;
@@ -962,19 +966,19 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
if ($rc < 0)
return (self::S_REDIAL|self::S_ADDTRY);
Log::info(sprintf('%s: - Starting outbound EMSI session to [%s]',__METHOD__,$this->client->address_remote));
Log::info(sprintf('%s: - Starting outbound EMSI session to [%s]',self::LOGKEY,$this->client->address_remote));
// Inbound session
} else {
$rc = $this->emsi_recv(self::SM_INBOUND);
if ($rc < 0) {
Log::error(sprintf('%s: ! Unable to establish EMSI session',__METHOD__));
Log::error(sprintf('%s:! Unable to establish EMSI session',self::LOGKEY));
return (self::S_REDIAL|self::S_ADDTRY);
}
Log::info(sprintf('%s: - Starting inbound EMSI session from [%s]',__METHOD__,$this->client->address_remote));
Log::info(sprintf('%s: - Starting inbound EMSI session from [%s]',self::LOGKEY,$this->client->address_remote));
if ($this->node->aka_authed) {
$xproto = $this->is_freq_available();
@@ -985,7 +989,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
foreach ($this->protocols as $p => $key) {
if ($this->node->optionGet($key)) {
Log::debug(sprintf('%s: - Remote supports [%s] (%x)',__METHOD__,$p,$key));
Log::debug(sprintf('%s: - Remote supports [%s] (%x)',self::LOGKEY,$p,$key));
$this->optionSet($key);
}
}
@@ -1002,14 +1006,14 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
// @todo Lock Node AKAs
Log::info(sprintf('%s: - We have %lu%s mail, %lu%s files',__METHOD__,$this->send->mail_size,'b',$this->send->file_size,'b'));
Log::info(sprintf('%s: - We have %lu%s mail, %lu%s files',self::LOGKEY,$this->send->mail_size,'b',$this->send->file_size,'b'));
$proto = $this->originate ? $this->node->optionGet(self::P_MASK) : $this->optionGet(self::P_MASK);
switch ($proto) {
case self::P_NONE:
case self::P_NCP:
Log::error(sprintf('%s: ! No compatible protocols',__METHOD__));
Log::error(sprintf('%s:! No compatible protocols',self::LOGKEY));
return self::S_FAILURE;
@@ -1046,17 +1050,17 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
break;
default:
Log::error(sprintf('%s: ? Unknown Protocol [%s]',__METHOD__,$proto));
Log::error(sprintf('%s: ? Unknown Protocol [%s]',self::LOGKEY,$proto));
$t = 'Unknown';
}
$xproto = ($this->optionGet(self::O_RH1) && ($this->node->optionGet(self::O_RH1)));
$x = (substr($t,1,1) == 'H' && $xproto ) ? 'x' : '';
Log::info(sprintf('%s: = Using [%s]',__METHOD__,$t));
Log::info(sprintf('%s: = Using [%s]',self::LOGKEY,$t));
Log::debug(sprintf('%s: = Options: %s%s%s%s%s%s%s%s%s%s%s',
__METHOD__,$x,$t,
Log::debug(sprintf('%s: = Options: %s%s%s%s%s%s%s%s%s%s%s',
self::LOGKEY,$x,$t,
($this->node->optionGet(self::O_LST)) ? '/LST' : '',
($this->node->optionGet(self::O_PWD)) ? '/PWD' : '',
($this->node->optionGet(self::O_HXT)) ? '/MO': '',
@@ -1148,7 +1152,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
*/
private function wazoorecv(int $zap): bool
{
Log::debug(sprintf('%s: + Start',__METHOD__));
Log::debug(sprintf('%s:+ wazoorecv',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);
@@ -1165,7 +1169,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
*/
private function wazoosend(int $zap): bool
{
Log::debug(sprintf('%s: + Start [%d]',__METHOD__,$zap));
Log::debug(sprintf('%s:+ wazoosend [%d]',self::LOGKEY,$zap));
// See if there is anything to add to the outbound
// Add our mail to the queue if we have authenticated
@@ -1179,7 +1183,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
if (! $z->zmodem_sendinit($this->client,$zap) && $this->send->total_count)
$z->zmodem_sendfile($this->send);
Log::debug(sprintf('%s: - Finished sending',__METHOD__));
Log::debug(sprintf('%s:- Finished sending',self::LOGKEY));
return ($z->zmodem_senddone()<0);
}
}
}