ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLPurifier_AttrDef_URI_IPv6 Class Reference

Validates an IPv6 address. More...

+ Inheritance diagram for HTMLPurifier_AttrDef_URI_IPv6:
+ Collaboration diagram for HTMLPurifier_AttrDef_URI_IPv6:

Public Member Functions

 validate ($aIP, $config, $context)
 Validates and cleans passed string according to a definition.

Additional Inherited Members

- Data Fields inherited from HTMLPurifier_AttrDef
 $minimized = false
 Tells us whether or not an HTML attribute is minimized.
 $required = false
 Tells us whether or not an HTML attribute is required.
- Protected Member Functions inherited from HTMLPurifier_AttrDef_URI_IPv4
 _loadRegex ()
 Lazy load function to prevent regex from being stuffed in cache.
- Protected Attributes inherited from HTMLPurifier_AttrDef_URI_IPv4
 $ip4
 IPv4 regex, protected so that IPv6 can reuse it.

Detailed Description

Validates an IPv6 address.

Author
Feyd @ forums.devnetwork.net (public domain)
Note
This function requires brackets to have been removed from address in URI.

Definition at line 9 of file IPv6.php.

Member Function Documentation

HTMLPurifier_AttrDef_URI_IPv6::validate (   $string,
  $config,
  $context 
)

Validates and cleans passed string according to a definition.

Parameters
$stringString to be validated and cleaned.
$configMandatory HTMLPurifier_Config object.
$contextMandatory HTMLPurifier_AttrContext object.

Reimplemented from HTMLPurifier_AttrDef_URI_IPv4.

Definition at line 12 of file IPv6.php.

References HTMLPurifier_AttrDef_URI_IPv4\_loadRegex().

{
if (!$this->ip4) $this->_loadRegex();
$original = $aIP;
$hex = '[0-9a-fA-F]';
$blk = '(?:' . $hex . '{1,4})';
$pre = '(?:/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))'; // /0 - /128
// prefix check
if (strpos($aIP, '/') !== false)
{
if (preg_match('#' . $pre . '$#s', $aIP, $find))
{
$aIP = substr($aIP, 0, 0-strlen($find[0]));
unset($find);
}
else
{
return false;
}
}
// IPv4-compatiblity check
if (preg_match('#(?<=:'.')' . $this->ip4 . '$#s', $aIP, $find))
{
$aIP = substr($aIP, 0, 0-strlen($find[0]));
$ip = explode('.', $find[0]);
$ip = array_map('dechex', $ip);
$aIP .= $ip[0] . $ip[1] . ':' . $ip[2] . $ip[3];
unset($find, $ip);
}
// compression check
$aIP = explode('::', $aIP);
$c = count($aIP);
if ($c > 2)
{
return false;
}
elseif ($c == 2)
{
list($first, $second) = $aIP;
$first = explode(':', $first);
$second = explode(':', $second);
if (count($first) + count($second) > 8)
{
return false;
}
while(count($first) < 8)
{
array_push($first, '0');
}
array_splice($first, 8 - count($second), 8, $second);
$aIP = $first;
unset($first,$second);
}
else
{
$aIP = explode(':', $aIP[0]);
}
$c = count($aIP);
if ($c != 8)
{
return false;
}
// All the pieces should be 16-bit hex strings. Are they?
foreach ($aIP as $piece)
{
if (!preg_match('#^[0-9a-fA-F]{4}$#s', sprintf('%04s', $piece)))
{
return false;
}
}
return $original;
}

+ Here is the call graph for this function:


The documentation for this class was generated from the following file: