Move the send DB updates out of the protocol and into Send::class

This commit is contained in:
2023-07-19 12:32:41 +10:00
parent 7584e3e44e
commit f4fc6c24a4
6 changed files with 67 additions and 58 deletions

View File

@@ -573,7 +573,7 @@ final class Binkp extends BaseProtocol
$buf = $this->send->read(self::BLOCKSIZE);
} catch (UnreadableFileEncountered) {
$this->send->close(FALSE);
$this->send->close(FALSE,$this->node);
$this->sessionClear(self::SE_SENDFILE);
} catch (\Exception $e) {
@@ -863,7 +863,7 @@ final class Binkp extends BaseProtocol
$this->msgs(self::BPM_ERR,sprintf('M_FILE: unparsable file info: "%s", what are you on?',$buf));
if ($this->sessionGet(self::SE_SENDFILE))
$this->send->close(FALSE);
$this->send->close(FALSE,$this->node);
$this->rc = self::S_FAILURE;
@@ -957,7 +957,7 @@ final class Binkp extends BaseProtocol
Log::error(sprintf('%s:! Cannot send file from requested offset [%d]',self::LOGKEY,$file['offs']));
$this->msgs(self::BPM_ERR,'Can\'t send file from requested offset');
$this->send->close(FALSE);
$this->send->close(FALSE,$this->node);
$this->sessionClear(self::SE_SENDFILE);
} else {
@@ -998,45 +998,10 @@ final class Binkp extends BaseProtocol
Log::error(sprintf('%s:! M_got[skip] for unknown file [%s]',self::LOGKEY,$buf));
} else {
Log::info(sprintf('%s:= Packet/File [%s], type [%d] sent with [%d] items.',self::LOGKEY,$this->send->nameas,$this->send->type,$this->send->dbids->count()));
Log::info(sprintf('%s:= Packet/File [%s], type [%d] sent.',self::LOGKEY,$this->send->nameas,$this->send->type));
$this->sessionClear(self::SE_WAITGOT|self::SE_SENDFILE);
// Update netmail table
if (($this->send->type === Send::T_NETMAIL)
&& ($x=$this->send->dbids)->count())
DB::table('netmails')
->whereIn('id',$x)
->update([
'sent_at'=>Carbon::now(),
'sent_pkt'=>$this->send->name,
'sent_id'=>$this->node->address->id,
'flags'=>DB::raw('flags | '.Message::FLAG_SENT),
]);
// Update echomails table
elseif (($this->send->type === Send::T_ECHOMAIL)
&& ($x=$this->send->dbids)->count()
&& $this->node->aka_remote_authed->count())
DB::table('echomail_seenby')
->whereIn('echomail_id',$x)
->whereIn('address_id',$this->node->aka_remote_authed->pluck('id'))
->update([
'sent_at'=>Carbon::now(),
'sent_pkt'=>$this->send->name,
]);
// Update the file seenby
elseif (($this->send->type === Send::T_FILE)
&& ($x=$this->send->dbids)->count()
&& $this->node->aka_remote_authed->count())
DB::table('file_seenby')
->whereIn('file_id',$x)
->whereIn('address_id',$this->node->aka_remote_authed->pluck('id'))
->update([
'sent_at'=>Carbon::now(),
]);
$this->send->close(TRUE);
$this->send->close(TRUE,$this->node);
}
}

View File

@@ -1211,7 +1211,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
$z = new Zmodem;
if (! $z->zmodem_sendinit($this->client,$zap) && $this->send->togo_count)
$z->zmodem_sendfile($this->send);
$z->zmodem_sendfile($this->send,$this->node);
}
// Send files
@@ -1219,7 +1219,7 @@ final class EMSI extends BaseProtocol implements CRCInterface,ZmodemInterface
$z = new Zmodem;
if (! $z->zmodem_sendinit($this->client,$zap) && $this->send->togo_count)
$z->zmodem_sendfile($this->send);
$z->zmodem_sendfile($this->send,$this->node);
}
}

View File

@@ -4,7 +4,7 @@ namespace App\Classes\Protocol;
use Illuminate\Support\Facades\Log;
use App\Classes\Protocol;
use App\Classes\{Node,Protocol};
use App\Classes\Protocol\Zmodem as ZmodemClass;
use App\Classes\File\{Receive,Send};
use App\Classes\Sock\{SocketClient,SocketException};
@@ -509,7 +509,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
* @param Send $send
* @return int
*/
public function zmodem_sendfile(Send $send): int
public function zmodem_sendfile(Send $send,Node $node): int
{
Log::debug(sprintf('%s:+ zmodem_sendfile',self::LOGKEY));
@@ -519,16 +519,16 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
switch ($rc) {
case self::OK:
$send->close(TRUE);
case self::ZSKIP:
$send->close(TRUE,$node);
break;
case self::ZSKIP:
case self::ZFERR:
$send->close(FALSE);
$send->close(FALSE,$node);
break;
default:
$send->close(FALSE);
$send->close(FALSE,$node);
$this->ls_zabort();
break;
}
@@ -2143,7 +2143,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$trys = 0;
$needack = 0;
switch (($rc = $this->ls_zsendfinfo($send,$sernum,$send->pos,$fileleft,$bytesleft))) {
switch (($rc=$this->ls_zsendfinfo($send,$sernum,$send->pos,$fileleft,$bytesleft))) {
/* Ok, It's OK! */
case self::ZRPOS:
Log::debug(sprintf('%s: - ls_zsendfile ZRPOS to [%d]',self::LOGKEY,$send->pos));
@@ -2152,6 +2152,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
/* Skip it */
case self::ZSKIP:
/* Suspend it */
// @todo Should ZFERR be next to ZABORT?
case self::ZFERR:
// @todo Mark the file as skipped
Log::debug(sprintf('%s: - ls_zsendfile ZSKIP/ZFERR',self::LOGKEY));