Resorting methods, no functional changes
This commit is contained in:
parent
731fdb0a44
commit
0457b3df25
app/Classes
@ -37,20 +37,6 @@ abstract class FTN
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if a line is a kludge line.
|
|
||||||
*
|
|
||||||
* @param string $kludge
|
|
||||||
* @param string $string
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function kludge(string $kludge,string $string)
|
|
||||||
{
|
|
||||||
return (preg_match("/^{$kludge}/",$string))
|
|
||||||
? chop(preg_replace("/^{$kludge}/",'',$string),"\r")
|
|
||||||
: FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function creates our unpack header
|
* This function creates our unpack header
|
||||||
*
|
*
|
||||||
|
@ -141,6 +141,7 @@ class Message extends FTNBase
|
|||||||
private Collection $via; // The path the message has gone using Via lines (Netmail)
|
private Collection $via; // The path the message has gone using Via lines (Netmail)
|
||||||
private Collection $unknown; // Temporarily hold attributes we have no logic for.
|
private Collection $unknown; // Temporarily hold attributes we have no logic for.
|
||||||
|
|
||||||
|
/** @deprecated Not sure why this is needed? */
|
||||||
public bool $packed = FALSE; // Has the message been packed successfully
|
public bool $packed = FALSE; // Has the message been packed successfully
|
||||||
|
|
||||||
// Convert characters into printable chars
|
// Convert characters into printable chars
|
||||||
@ -189,6 +190,94 @@ class Message extends FTNBase
|
|||||||
0xfc => 0x207f, 0xfd => 0x00b2, 0xfe => 0x25a0, 0xff => 0x00a0,
|
0xfc => 0x207f, 0xfd => 0x00b2, 0xfe => 0x25a0, 0xff => 0x00a0,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a message from a packet
|
||||||
|
*
|
||||||
|
* @param string $msg
|
||||||
|
* @param Zone|null $zone
|
||||||
|
* @return Message
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public static function parseMessage(string $msg,Zone $zone=NULL): self
|
||||||
|
{
|
||||||
|
Log::info(sprintf('%s:= Processing message [%d] bytes from zone [%d]',self::LOGKEY,strlen($msg),$zone?->zone_id));
|
||||||
|
|
||||||
|
$o = new self($zone);
|
||||||
|
$o->dump = $msg;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$o->header = unpack(self::unpackheader(self::header),substr($msg,0,self::HEADER_LEN));
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error(sprintf('%s:! Error bad packet header',self::LOGKEY),['e'=>$e->getMessage(),'header'=>substr($msg,0,self::HEADER_LEN)]);
|
||||||
|
$validator = Validator::make([
|
||||||
|
'header' => substr($msg,0,self::HEADER_LEN),
|
||||||
|
],[
|
||||||
|
'header' => [function ($attribute,$value,$fail) use ($e) { return $fail($e->getMessage()); }]
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($validator->fails())
|
||||||
|
$o->errors = $validator;
|
||||||
|
|
||||||
|
return $o;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ptr = 0;
|
||||||
|
|
||||||
|
// To User
|
||||||
|
$o->user_to = strstr(substr($msg,self::HEADER_LEN+$ptr),"\x00",TRUE);
|
||||||
|
$ptr += strlen($o->user_to)+1;
|
||||||
|
|
||||||
|
// From User
|
||||||
|
$o->user_from = strstr(substr($msg,self::HEADER_LEN+$ptr),"\x00",TRUE);
|
||||||
|
$ptr += strlen($o->user_from)+1;
|
||||||
|
|
||||||
|
// Subject
|
||||||
|
$o->subject = strstr(substr($msg,self::HEADER_LEN+$ptr),"\x00",TRUE);
|
||||||
|
$ptr += strlen($o->subject)+1;
|
||||||
|
|
||||||
|
// Check if this is an Echomail
|
||||||
|
if (! strncmp(substr($msg,self::HEADER_LEN+$ptr),'AREA:',5)) {
|
||||||
|
$o->echoarea = strtoupper(substr($msg,self::HEADER_LEN+$ptr+5,strpos($msg,"\r",self::HEADER_LEN+$ptr+5)-(self::HEADER_LEN+$ptr+5)));
|
||||||
|
$ptr += strlen($o->echoarea)+5+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$o->unpackMessage(substr($msg,self::HEADER_LEN+$ptr));
|
||||||
|
|
||||||
|
if (($x=$o->validate())->fails()) {
|
||||||
|
Log::debug(sprintf('%s:! Message fails validation (%s@%s->%s@%s)',self::LOGKEY,$o->user_from,$o->fftn,$o->user_to,$o->tftn),['result'=>$x->errors()]);
|
||||||
|
//throw new \Exception('Message validation fails:'.join(' ',$x->errors()->all()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $o;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translate the string into something printable via the web
|
||||||
|
*
|
||||||
|
* @param string $string
|
||||||
|
* @param array $skip
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function tr(string $string,array $skip=[0x0a,0x0d]): string
|
||||||
|
{
|
||||||
|
$tr = [];
|
||||||
|
|
||||||
|
foreach (self::CP437 as $k=>$v) {
|
||||||
|
if (in_array($k,$skip))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$tr[chr($k)] = '&#'.$v;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strtr($string,$tr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Packets have no concept of a zone, so we add it for any calculations that could use it
|
||||||
|
*
|
||||||
|
* @param Zone|NULL $zone
|
||||||
|
*/
|
||||||
public function __construct(Zone $zone=NULL)
|
public function __construct(Zone $zone=NULL)
|
||||||
{
|
{
|
||||||
$this->zone = $zone;
|
$this->zone = $zone;
|
||||||
@ -508,6 +597,20 @@ class Message extends FTNBase
|
|||||||
$this->decode($values);
|
$this->decode($values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a line is a kludge line.
|
||||||
|
*
|
||||||
|
* @param string $kludge
|
||||||
|
* @param string $string
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function kludge(string $kludge,string $string)
|
||||||
|
{
|
||||||
|
return (preg_match("/^{$kludge}/",$string))
|
||||||
|
? chop(preg_replace("/^{$kludge}/",'',$string),"\r")
|
||||||
|
: FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reduce our PATH/SEEN-BY for messages as per FSC-0068
|
* Reduce our PATH/SEEN-BY for messages as per FSC-0068
|
||||||
*
|
*
|
||||||
@ -517,7 +620,7 @@ class Message extends FTNBase
|
|||||||
* @param string $delim
|
* @param string $delim
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function optimise_path(Collection $path,string $prefix,int $len=79,string $delim="\r"): string
|
private function optimise_path(Collection $path,string $prefix,int $len=79,string $delim="\r"): string
|
||||||
{
|
{
|
||||||
$cur = NULL;
|
$cur = NULL;
|
||||||
$result = $prefix;
|
$result = $prefix;
|
||||||
@ -546,89 +649,6 @@ class Message extends FTNBase
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse a message from a packet
|
|
||||||
*
|
|
||||||
* @param string $msg
|
|
||||||
* @param Zone|null $zone
|
|
||||||
* @return Message
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public static function parseMessage(string $msg,Zone $zone=NULL): self
|
|
||||||
{
|
|
||||||
Log::info(sprintf('%s:= Processing message [%d] bytes from zone [%d]',self::LOGKEY,strlen($msg),$zone?->zone_id));
|
|
||||||
|
|
||||||
$o = new self($zone);
|
|
||||||
$o->dump = $msg;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$o->header = unpack(self::unpackheader(self::header),substr($msg,0,self::HEADER_LEN));
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Log::error(sprintf('%s:! Error bad packet header',self::LOGKEY),['e'=>$e->getMessage(),'header'=>substr($msg,0,self::HEADER_LEN)]);
|
|
||||||
$validator = Validator::make([
|
|
||||||
'header' => substr($msg,0,self::HEADER_LEN),
|
|
||||||
],[
|
|
||||||
'header' => [function ($attribute,$value,$fail) use ($e) { return $fail($e->getMessage()); }]
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($validator->fails())
|
|
||||||
$o->errors = $validator;
|
|
||||||
|
|
||||||
return $o;
|
|
||||||
}
|
|
||||||
|
|
||||||
$ptr = 0;
|
|
||||||
|
|
||||||
// To User
|
|
||||||
$o->user_to = strstr(substr($msg,self::HEADER_LEN+$ptr),"\x00",TRUE);
|
|
||||||
$ptr += strlen($o->user_to)+1;
|
|
||||||
|
|
||||||
// From User
|
|
||||||
$o->user_from = strstr(substr($msg,self::HEADER_LEN+$ptr),"\x00",TRUE);
|
|
||||||
$ptr += strlen($o->user_from)+1;
|
|
||||||
|
|
||||||
// Subject
|
|
||||||
$o->subject = strstr(substr($msg,self::HEADER_LEN+$ptr),"\x00",TRUE);
|
|
||||||
$ptr += strlen($o->subject)+1;
|
|
||||||
|
|
||||||
// Check if this is an Echomail
|
|
||||||
if (! strncmp(substr($msg,self::HEADER_LEN+$ptr),'AREA:',5)) {
|
|
||||||
$o->echoarea = strtoupper(substr($msg,self::HEADER_LEN+$ptr+5,strpos($msg,"\r",self::HEADER_LEN+$ptr+5)-(self::HEADER_LEN+$ptr+5)));
|
|
||||||
$ptr += strlen($o->echoarea)+5+1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$o->unpackMessage(substr($msg,self::HEADER_LEN+$ptr));
|
|
||||||
|
|
||||||
if (($x=$o->validate())->fails()) {
|
|
||||||
Log::debug(sprintf('%s:! Message fails validation (%s@%s->%s@%s)',self::LOGKEY,$o->user_from,$o->fftn,$o->user_to,$o->tftn),['result'=>$x->errors()]);
|
|
||||||
//throw new \Exception('Message validation fails:'.join(' ',$x->errors()->all()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $o;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Translate the string into something printable via the web
|
|
||||||
*
|
|
||||||
* @param string $string
|
|
||||||
* @param array $skip
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function tr(string $string,array $skip=[0x0a,0x0d]): string
|
|
||||||
{
|
|
||||||
$tr = [];
|
|
||||||
|
|
||||||
foreach (self::CP437 as $k=>$v) {
|
|
||||||
if (in_array($k,$skip))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
$tr[chr($k)] = '&#'.$v;
|
|
||||||
}
|
|
||||||
|
|
||||||
return strtr($string,$tr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this message doesnt have an AREATAG, then its a netmail.
|
* If this message doesnt have an AREATAG, then its a netmail.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user