2016-05-13 06:42:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Class to validate and to work with IPv6 addresses
|
|
|
|
*
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-25 02:12:02 +01:00
|
|
|
* @package Requests\Utilities
|
2016-05-13 06:42:28 +02:00
|
|
|
*/
|
|
|
|
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-25 02:12:02 +01:00
|
|
|
namespace WpOrg\Requests;
|
|
|
|
|
|
|
|
use WpOrg\Requests\Exception\InvalidArgument;
|
|
|
|
use WpOrg\Requests\Utility\InputValidator;
|
|
|
|
|
2016-05-13 06:42:28 +02:00
|
|
|
/**
|
|
|
|
* Class to validate and to work with IPv6 addresses
|
|
|
|
*
|
|
|
|
* This was originally based on the PEAR class of the same name, but has been
|
|
|
|
* entirely rewritten.
|
|
|
|
*
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-25 02:12:02 +01:00
|
|
|
* @package Requests\Utilities
|
2016-05-13 06:42:28 +02:00
|
|
|
*/
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-25 02:12:02 +01:00
|
|
|
final class Ipv6 {
|
2016-05-13 06:42:28 +02:00
|
|
|
/**
|
|
|
|
* Uncompresses an IPv6 address
|
|
|
|
*
|
|
|
|
* RFC 4291 allows you to compress consecutive zero pieces in an address to
|
|
|
|
* '::'. This method expects a valid IPv6 address and expands the '::' to
|
|
|
|
* the required number of zero pieces.
|
|
|
|
*
|
|
|
|
* Example: FF01::101 -> FF01:0:0:0:0:0:0:101
|
|
|
|
* ::1 -> 0:0:0:0:0:0:0:1
|
|
|
|
*
|
|
|
|
* @author Alexander Merz <alexander.merz@web.de>
|
|
|
|
* @author elfrink at introweb dot nl
|
|
|
|
* @author Josh Peck <jmp at joshpeck dot org>
|
|
|
|
* @copyright 2003-2005 The PHP Group
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-25 02:12:02 +01:00
|
|
|
* @license https://opensource.org/licenses/bsd-license.php
|
|
|
|
*
|
|
|
|
* @param string|Stringable $ip An IPv6 address
|
2016-05-13 06:42:28 +02:00
|
|
|
* @return string The uncompressed IPv6 address
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-25 02:12:02 +01:00
|
|
|
*
|
|
|
|
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not a string or a stringable object.
|
2016-05-13 06:42:28 +02:00
|
|
|
*/
|
|
|
|
public static function uncompress($ip) {
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-25 02:12:02 +01:00
|
|
|
if (InputValidator::is_string_or_stringable($ip) === false) {
|
|
|
|
throw InvalidArgument::create(1, '$ip', 'string|Stringable', gettype($ip));
|
|
|
|
}
|
|
|
|
|
|
|
|
$ip = (string) $ip;
|
|
|
|
|
2016-05-13 06:42:28 +02:00
|
|
|
if (substr_count($ip, '::') !== 1) {
|
|
|
|
return $ip;
|
|
|
|
}
|
|
|
|
|
|
|
|
list($ip1, $ip2) = explode('::', $ip);
|
External Libraries: Update the Requests library to version `1.8.0`.
While some of the changes in the `1.8.0` release have already been copied to WordPress Core in earlier releases (see [38727], [46258], [47902] and [49382]), this release contains additional improvements, including:
- A significant performance fix when using cURL.
- Improved compliance with RFC2616.
The library has also been moved under the WordPress project’s GitHub organization and can now be found at https://github.com/WordPress/Requests.
Props jrf, dd32, rmccue, justinahinon, netweb, schlessera, TimothyBJacobs, soulseekah, ozh, skithund, carlalexander, travisnorthcutt, desrosj.
Fixes #53101.
Built from https://develop.svn.wordpress.org/trunk@50842
git-svn-id: http://core.svn.wordpress.org/trunk@50451 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-11 21:42:02 +02:00
|
|
|
$c1 = ($ip1 === '') ? -1 : substr_count($ip1, ':');
|
|
|
|
$c2 = ($ip2 === '') ? -1 : substr_count($ip2, ':');
|
2016-05-13 06:42:28 +02:00
|
|
|
|
|
|
|
if (strpos($ip2, '.') !== false) {
|
|
|
|
$c2++;
|
|
|
|
}
|
|
|
|
// ::
|
|
|
|
if ($c1 === -1 && $c2 === -1) {
|
|
|
|
$ip = '0:0:0:0:0:0:0:0';
|
|
|
|
}
|
|
|
|
// ::xxx
|
External Libraries: Update the Requests library to version `1.8.0`.
While some of the changes in the `1.8.0` release have already been copied to WordPress Core in earlier releases (see [38727], [46258], [47902] and [49382]), this release contains additional improvements, including:
- A significant performance fix when using cURL.
- Improved compliance with RFC2616.
The library has also been moved under the WordPress project’s GitHub organization and can now be found at https://github.com/WordPress/Requests.
Props jrf, dd32, rmccue, justinahinon, netweb, schlessera, TimothyBJacobs, soulseekah, ozh, skithund, carlalexander, travisnorthcutt, desrosj.
Fixes #53101.
Built from https://develop.svn.wordpress.org/trunk@50842
git-svn-id: http://core.svn.wordpress.org/trunk@50451 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-11 21:42:02 +02:00
|
|
|
elseif ($c1 === -1) {
|
2016-05-13 06:42:28 +02:00
|
|
|
$fill = str_repeat('0:', 7 - $c2);
|
External Libraries: Update the Requests library to version `1.8.0`.
While some of the changes in the `1.8.0` release have already been copied to WordPress Core in earlier releases (see [38727], [46258], [47902] and [49382]), this release contains additional improvements, including:
- A significant performance fix when using cURL.
- Improved compliance with RFC2616.
The library has also been moved under the WordPress project’s GitHub organization and can now be found at https://github.com/WordPress/Requests.
Props jrf, dd32, rmccue, justinahinon, netweb, schlessera, TimothyBJacobs, soulseekah, ozh, skithund, carlalexander, travisnorthcutt, desrosj.
Fixes #53101.
Built from https://develop.svn.wordpress.org/trunk@50842
git-svn-id: http://core.svn.wordpress.org/trunk@50451 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-11 21:42:02 +02:00
|
|
|
$ip = str_replace('::', $fill, $ip);
|
2016-05-13 06:42:28 +02:00
|
|
|
}
|
|
|
|
// xxx::
|
External Libraries: Update the Requests library to version `1.8.0`.
While some of the changes in the `1.8.0` release have already been copied to WordPress Core in earlier releases (see [38727], [46258], [47902] and [49382]), this release contains additional improvements, including:
- A significant performance fix when using cURL.
- Improved compliance with RFC2616.
The library has also been moved under the WordPress project’s GitHub organization and can now be found at https://github.com/WordPress/Requests.
Props jrf, dd32, rmccue, justinahinon, netweb, schlessera, TimothyBJacobs, soulseekah, ozh, skithund, carlalexander, travisnorthcutt, desrosj.
Fixes #53101.
Built from https://develop.svn.wordpress.org/trunk@50842
git-svn-id: http://core.svn.wordpress.org/trunk@50451 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-11 21:42:02 +02:00
|
|
|
elseif ($c2 === -1) {
|
2016-05-13 06:42:28 +02:00
|
|
|
$fill = str_repeat(':0', 7 - $c1);
|
External Libraries: Update the Requests library to version `1.8.0`.
While some of the changes in the `1.8.0` release have already been copied to WordPress Core in earlier releases (see [38727], [46258], [47902] and [49382]), this release contains additional improvements, including:
- A significant performance fix when using cURL.
- Improved compliance with RFC2616.
The library has also been moved under the WordPress project’s GitHub organization and can now be found at https://github.com/WordPress/Requests.
Props jrf, dd32, rmccue, justinahinon, netweb, schlessera, TimothyBJacobs, soulseekah, ozh, skithund, carlalexander, travisnorthcutt, desrosj.
Fixes #53101.
Built from https://develop.svn.wordpress.org/trunk@50842
git-svn-id: http://core.svn.wordpress.org/trunk@50451 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-11 21:42:02 +02:00
|
|
|
$ip = str_replace('::', $fill, $ip);
|
2016-05-13 06:42:28 +02:00
|
|
|
}
|
|
|
|
// xxx::xxx
|
|
|
|
else {
|
|
|
|
$fill = ':' . str_repeat('0:', 6 - $c2 - $c1);
|
External Libraries: Update the Requests library to version `1.8.0`.
While some of the changes in the `1.8.0` release have already been copied to WordPress Core in earlier releases (see [38727], [46258], [47902] and [49382]), this release contains additional improvements, including:
- A significant performance fix when using cURL.
- Improved compliance with RFC2616.
The library has also been moved under the WordPress project’s GitHub organization and can now be found at https://github.com/WordPress/Requests.
Props jrf, dd32, rmccue, justinahinon, netweb, schlessera, TimothyBJacobs, soulseekah, ozh, skithund, carlalexander, travisnorthcutt, desrosj.
Fixes #53101.
Built from https://develop.svn.wordpress.org/trunk@50842
git-svn-id: http://core.svn.wordpress.org/trunk@50451 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-11 21:42:02 +02:00
|
|
|
$ip = str_replace('::', $fill, $ip);
|
2016-05-13 06:42:28 +02:00
|
|
|
}
|
|
|
|
return $ip;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compresses an IPv6 address
|
|
|
|
*
|
|
|
|
* RFC 4291 allows you to compress consecutive zero pieces in an address to
|
|
|
|
* '::'. This method expects a valid IPv6 address and compresses consecutive
|
|
|
|
* zero pieces to '::'.
|
|
|
|
*
|
|
|
|
* Example: FF01:0:0:0:0:0:0:101 -> FF01::101
|
|
|
|
* 0:0:0:0:0:0:0:1 -> ::1
|
|
|
|
*
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-25 02:12:02 +01:00
|
|
|
* @see \WpOrg\Requests\IPv6::uncompress()
|
|
|
|
*
|
2016-05-13 06:42:28 +02:00
|
|
|
* @param string $ip An IPv6 address
|
|
|
|
* @return string The compressed IPv6 address
|
|
|
|
*/
|
|
|
|
public static function compress($ip) {
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-25 02:12:02 +01:00
|
|
|
// Prepare the IP to be compressed.
|
|
|
|
// Note: Input validation is handled in the `uncompress()` method, which is the first call made in this method.
|
External Libraries: Update the Requests library to version `1.8.0`.
While some of the changes in the `1.8.0` release have already been copied to WordPress Core in earlier releases (see [38727], [46258], [47902] and [49382]), this release contains additional improvements, including:
- A significant performance fix when using cURL.
- Improved compliance with RFC2616.
The library has also been moved under the WordPress project’s GitHub organization and can now be found at https://github.com/WordPress/Requests.
Props jrf, dd32, rmccue, justinahinon, netweb, schlessera, TimothyBJacobs, soulseekah, ozh, skithund, carlalexander, travisnorthcutt, desrosj.
Fixes #53101.
Built from https://develop.svn.wordpress.org/trunk@50842
git-svn-id: http://core.svn.wordpress.org/trunk@50451 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-11 21:42:02 +02:00
|
|
|
$ip = self::uncompress($ip);
|
2016-05-13 06:42:28 +02:00
|
|
|
$ip_parts = self::split_v6_v4($ip);
|
|
|
|
|
|
|
|
// Replace all leading zeros
|
|
|
|
$ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]);
|
|
|
|
|
|
|
|
// Find bunches of zeros
|
|
|
|
if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE)) {
|
|
|
|
$max = 0;
|
|
|
|
$pos = null;
|
|
|
|
foreach ($matches[0] as $match) {
|
|
|
|
if (strlen($match[0]) > $max) {
|
|
|
|
$max = strlen($match[0]);
|
|
|
|
$pos = $match[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($ip_parts[1] !== '') {
|
|
|
|
return implode(':', $ip_parts);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $ip_parts[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Splits an IPv6 address into the IPv6 and IPv4 representation parts
|
|
|
|
*
|
|
|
|
* RFC 4291 allows you to represent the last two parts of an IPv6 address
|
|
|
|
* using the standard IPv4 representation
|
|
|
|
*
|
|
|
|
* Example: 0:0:0:0:0:0:13.1.68.3
|
|
|
|
* 0:0:0:0:0:FFFF:129.144.52.38
|
|
|
|
*
|
|
|
|
* @param string $ip An IPv6 address
|
|
|
|
* @return string[] [0] contains the IPv6 represented part, and [1] the IPv4 represented part
|
|
|
|
*/
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-25 02:12:02 +01:00
|
|
|
private static function split_v6_v4($ip) {
|
2016-05-13 06:42:28 +02:00
|
|
|
if (strpos($ip, '.') !== false) {
|
External Libraries: Update the Requests library to version `1.8.0`.
While some of the changes in the `1.8.0` release have already been copied to WordPress Core in earlier releases (see [38727], [46258], [47902] and [49382]), this release contains additional improvements, including:
- A significant performance fix when using cURL.
- Improved compliance with RFC2616.
The library has also been moved under the WordPress project’s GitHub organization and can now be found at https://github.com/WordPress/Requests.
Props jrf, dd32, rmccue, justinahinon, netweb, schlessera, TimothyBJacobs, soulseekah, ozh, skithund, carlalexander, travisnorthcutt, desrosj.
Fixes #53101.
Built from https://develop.svn.wordpress.org/trunk@50842
git-svn-id: http://core.svn.wordpress.org/trunk@50451 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-11 21:42:02 +02:00
|
|
|
$pos = strrpos($ip, ':');
|
2016-05-13 06:42:28 +02:00
|
|
|
$ipv6_part = substr($ip, 0, $pos);
|
|
|
|
$ipv4_part = substr($ip, $pos + 1);
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-25 02:12:02 +01:00
|
|
|
return [$ipv6_part, $ipv4_part];
|
2016-05-13 06:42:28 +02:00
|
|
|
}
|
|
|
|
else {
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-25 02:12:02 +01:00
|
|
|
return [$ip, ''];
|
2016-05-13 06:42:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks an IPv6 address
|
|
|
|
*
|
|
|
|
* Checks if the given IP is a valid IPv6 address
|
|
|
|
*
|
|
|
|
* @param string $ip An IPv6 address
|
|
|
|
* @return bool true if $ip is a valid IPv6 address
|
|
|
|
*/
|
|
|
|
public static function check_ipv6($ip) {
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-25 02:12:02 +01:00
|
|
|
// Note: Input validation is handled in the `uncompress()` method, which is the first call made in this method.
|
External Libraries: Update the Requests library to version `1.8.0`.
While some of the changes in the `1.8.0` release have already been copied to WordPress Core in earlier releases (see [38727], [46258], [47902] and [49382]), this release contains additional improvements, including:
- A significant performance fix when using cURL.
- Improved compliance with RFC2616.
The library has also been moved under the WordPress project’s GitHub organization and can now be found at https://github.com/WordPress/Requests.
Props jrf, dd32, rmccue, justinahinon, netweb, schlessera, TimothyBJacobs, soulseekah, ozh, skithund, carlalexander, travisnorthcutt, desrosj.
Fixes #53101.
Built from https://develop.svn.wordpress.org/trunk@50842
git-svn-id: http://core.svn.wordpress.org/trunk@50451 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-11 21:42:02 +02:00
|
|
|
$ip = self::uncompress($ip);
|
2016-05-13 06:42:28 +02:00
|
|
|
list($ipv6, $ipv4) = self::split_v6_v4($ip);
|
External Libraries: Update the Requests library to version `1.8.0`.
While some of the changes in the `1.8.0` release have already been copied to WordPress Core in earlier releases (see [38727], [46258], [47902] and [49382]), this release contains additional improvements, including:
- A significant performance fix when using cURL.
- Improved compliance with RFC2616.
The library has also been moved under the WordPress project’s GitHub organization and can now be found at https://github.com/WordPress/Requests.
Props jrf, dd32, rmccue, justinahinon, netweb, schlessera, TimothyBJacobs, soulseekah, ozh, skithund, carlalexander, travisnorthcutt, desrosj.
Fixes #53101.
Built from https://develop.svn.wordpress.org/trunk@50842
git-svn-id: http://core.svn.wordpress.org/trunk@50451 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-11 21:42:02 +02:00
|
|
|
$ipv6 = explode(':', $ipv6);
|
|
|
|
$ipv4 = explode('.', $ipv4);
|
2016-05-13 06:42:28 +02:00
|
|
|
if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) {
|
|
|
|
foreach ($ipv6 as $ipv6_part) {
|
|
|
|
// The section can't be empty
|
|
|
|
if ($ipv6_part === '') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nor can it be over four characters
|
|
|
|
if (strlen($ipv6_part) > 4) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove leading zeros (this is safe because of the above)
|
|
|
|
$ipv6_part = ltrim($ipv6_part, '0');
|
|
|
|
if ($ipv6_part === '') {
|
|
|
|
$ipv6_part = '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the value is valid
|
|
|
|
$value = hexdec($ipv6_part);
|
|
|
|
if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count($ipv4) === 4) {
|
|
|
|
foreach ($ipv4 as $ipv4_part) {
|
|
|
|
$value = (int) $ipv4_part;
|
|
|
|
if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|