From 0800c48928ec1b7adc572e4373b3612185701dd7 Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 23 Nov 2023 23:17:13 +1100 Subject: [PATCH] Use regex for received file evaluation. Fixes recording received packet names --- app/Classes/FTN/Packet.php | 2 ++ app/Classes/FTN/Tic.php | 8 ++++---- app/Classes/File.php | 6 ++++-- app/Console/Commands/PacketInfo.php | 4 ++-- app/Console/Commands/PacketProcess.php | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/Classes/FTN/Packet.php b/app/Classes/FTN/Packet.php index 31f6df9..b674148 100644 --- a/app/Classes/FTN/Packet.php +++ b/app/Classes/FTN/Packet.php @@ -25,6 +25,8 @@ class Packet extends FTNBase implements \Iterator, \Countable private const BLOCKSIZE = 1024; protected const PACKED_MSG_LEAD = "\02\00"; + public const regex = '([[:xdigit:]]{4})(?:-(\d{4,10}))?-(.+)'; + public const PACKET_TYPES = [ '2.2' => FTNBase\Packet\FSC45::class, '2+' => FTNBase\Packet\FSC48::class, diff --git a/app/Classes/FTN/Tic.php b/app/Classes/FTN/Tic.php index 5cc628e..b976cb3 100644 --- a/app/Classes/FTN/Tic.php +++ b/app/Classes/FTN/Tic.php @@ -182,10 +182,10 @@ class Tic extends FTNBase $this->file->recv_tic = preg_replace('/\.[Tt][Ii][Cc]$/','',$filename); $m = []; - if (preg_match('/^(([0-9A-F]{4})-)?(([0-9]{4,10})-)?(.*).[Tt][Ii][Cc]$/',$filename,$m)) { - $aid = $m[2]; - $mtime = $m[4]; - $this->file->recv_tic = $m[5]; + if (preg_match(sprintf('/^%s\.[Tt][Ii][Cc]$/',Packet::regex),$filename,$m)) { + $aid = $m[1]; + $mtime = $m[2]; + $this->file->recv_tic = $m[3]; } $ldesc = ''; diff --git a/app/Classes/File.php b/app/Classes/File.php index 1279c4f..9c53284 100644 --- a/app/Classes/File.php +++ b/app/Classes/File.php @@ -7,6 +7,8 @@ use Illuminate\Support\Arr; use Illuminate\Support\Facades\Log; use Symfony\Component\HttpFoundation\File\File as FileBase; +use App\Classes\FTN\Packet; + class File extends FileBase implements \Iterator { private const LOGKEY = 'F--'; @@ -108,7 +110,7 @@ class File extends FileBase implements \Iterator */ public function rawName(): string { - return preg_replace('/^[0-9A-F]{4}-([0-9]+)-]/','',$this->getFilename()); + return preg_replace(sprintf('/^%s\.pkt$/i',Packet::regex),'\3\4',$this->getFilename()); } /** @@ -129,7 +131,7 @@ class File extends FileBase implements \Iterator return preg_replace('/.pkt$/i','',Arr::get(stream_get_meta_data($f),'uri')); } else { - return $this->isPacket() ? preg_replace('/.pkt$/i','',$this->rawName()) : NULL; + return $this->isPacket() ? $this->rawName() : NULL; } } } \ No newline at end of file diff --git a/app/Console/Commands/PacketInfo.php b/app/Console/Commands/PacketInfo.php index 42fa630..988b457 100644 --- a/app/Console/Commands/PacketInfo.php +++ b/app/Console/Commands/PacketInfo.php @@ -45,8 +45,8 @@ class PacketInfo extends Command if ($this->argument('ftn')) { $a = Address::findFTN($this->argument('ftn')); - } elseif (preg_match('/^(([0-9A-F]+)-)+/',$this->argument('file'),$m)) { - $a = Address::findOrFail(hexdec($m[2])); + } elseif (preg_match(sprintf('/^%s\.pkt$/',Packet::regex),$this->argument('file'),$m)) { + $a = Address::findOrFail(hexdec($m[1])); } foreach ($f as $packet) { diff --git a/app/Console/Commands/PacketProcess.php b/app/Console/Commands/PacketProcess.php index a19f285..b28030c 100644 --- a/app/Console/Commands/PacketProcess.php +++ b/app/Console/Commands/PacketProcess.php @@ -48,8 +48,8 @@ class PacketProcess extends Command if ($this->argument('ftn')) { $a = Address::findFTN($this->argument('ftn')); - } elseif (preg_match('/^(([0-9A-F]+)-([0-9]+))+/',$this->argument('file'),$m)) { - $a = Address::findOrFail(hexdec($m[2])); + } elseif (preg_match(sprintf('/^%s\.pkt$/',Packet::regex),$this->argument('file'),$m)) { + $a = Address::findOrFail(hexdec($m[1])); } else { $this->error('Unable to determine sender FTN address');