Revise CRC calls and use php's internal functions

This commit is contained in:
Deon George
2021-07-21 20:52:17 +10:00
parent 7cd3b814bb
commit 2fdc6eabad
5 changed files with 41 additions and 118 deletions

View File

@@ -54,56 +54,25 @@ if (! function_exists('hex_dump')) {
}
/**
* Split out an FTN address into its parts
*
* This function takes a fully qualified FTN address and splits it out into
* its components:
* Z:N/F.P@D
* Send a value has hex chars
*/
if (! function_exists('ftn_address_split')) {
function ftn_address_split(string $address,$key=NULL)
if (! function_exists('hexstr')) {
function hexstr(int $int)
{
if ($key AND ! in_array($key,['z','n','f','p','d']))
{
throw new \Exception('Unknown key :'.$key.' for '.$address);
if ($int > 0xffff)
throw new Exception('Int too large for hexstr');
$hexdigitslower = '0123456789abcdef';
$x = '';
if ($int > 0xff) {
$x .= substr($hexdigitslower,($int&0xf000)>>12,1);
$x .= substr($hexdigitslower,($int&0x0f00)>>8,1);
}
//$data = "10:12/909";
//$data = "10:12/909.5";
//$data = "10:12/909@foo";
//$data = "10:12/909.5@foo";
$z = substr($address,0,strpos($address,':'));
$x .= substr($hexdigitslower,($int&0x00f0)>>4,1);
$x .= substr($hexdigitslower,($int&0x000f),1);
if ($key == 'z')
return $z;
$x = strpos($address,':')+1;
$n = substr($address,$x,strpos($address,'/')-$x);
if ($key == 'n')
return $n;
$x = strpos($address,'/')+1;
$f = substr($address,$x,
(strpos($address,'.') ?:
(strpos($address,'@') ?: strlen($address)))-$x);
if ($key == 'f')
return $f;
$x = strpos($address,'.');
$p = $x ? substr($address,$x+1,(strpos($address,'@') ?: strlen($address))-$x-1) : 0;
if ($key == 'p')
return $p;
// @todo We dont handle domain yet.
$x = strpos($address,'@');
$d = $x ? substr($address,$x+1) : NULL;
if ($key == 'd')
return $d;
return ['z'=>$z,'n'=>$n,'f'=>$f,'p'=>$p,'d'=>$d];
return $x;
}
}