<commit_before><?php

/**
 * Misc static functions that is used several places.in example parsing and id generation.
 *
 * @author <NAME>, UNINETT AS. <<EMAIL>>
 * @package simpleSAMLphp
 */
class SimpleSAML_Utilities {

	/**
	 * List of log levels.
	 *
	 * This list is used to restore the log levels after some log levels are disabled.
	 *
	 * @var array
	 */
	private static $logLevelStack = array();


	/**
	 * The current mask of disabled log levels.
	 *
	 * Note: This mask is not directly related to the PHP error reporting level.
	 *
	 * @var int
	 */
	public static $logMask = 0;


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfHost() instead.
	 */
	public static function getSelfHost() {
		return \SimpleSAML\Utils\HTTP::getSelfHost();
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfURLHost() instead.
	 */
	public static function selfURLhost() {
		return \SimpleSAML\Utils\HTTP::getSelfURLHost();
	}

	
	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::isHTTPS() instead.
	 */
	public static function isHTTPS() {
		return \SimpleSAML\Utils\HTTP::isHTTPS();
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfURLNoQuery() instead.
	 */
	public static function selfURLNoQuery() {
		return \SimpleSAML\Utils\HTTP::getSelfURLNoQuery();
	
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfHostWithPath() instead.
	 */
	public static function getSelfHostWithPath() {
		return \SimpleSAML\Utils\HTTP::getSelfHostWithPath();
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getFirstPathElement() instead.
	 */
	public static function getFirstPathElement($trailingslash = true) {
		return \SimpleSAML\Utils\HTTP::getFirstPathElement($trailingslash);
	}


    /**
     * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfURL() instead.
     */
	public static function selfURL() {
		return \SimpleSAML\Utils\HTTP::getSelfURL();
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getBaseURL() instead.
	 */
	public static function getBaseURL() {
		return \SimpleSAML\Utils\HTTP::getBaseURL();
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::addURLParameters() instead.
	 */
	public static function addURLparameter($url, $parameters) {
		return \SimpleSAML\Utils\HTTP::addURLParameters($url, $parameters);
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use \SimpleSAML\Utils\HTTP::checkURLAllowed() instead.
	 */
	public static function checkURLAllowed($url, array $trustedSites = NULL) {
		return \SimpleSAML\Utils\HTTP::checkURLAllowed($url, $trustedSites);
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML_Auth_State::parseStateID() instead.
	 */
	public static function parseStateID($stateId) {
		return SimpleSAML_Auth_State::parseStateID($stateId);
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0.
	 */
	public static function checkDateConditions($start=NULL, $end=NULL) {
		$currentTime = time();

		if (!empty($start)) {
			$startTime = SAML2_Utils::xsDateTimeToTimestamp($start);
			/* Allow for a 10 minute difference in Time */
			if (($startTime < 0) || (($startTime - 600) > $currentTime)) {
				return FALSE;
			}
		}
		if (!empty($end)) {
			$endTime = SAML2_Utils::xsDateTimeToTimestamp($end);
			if (($endTime < 0) || ($endTime <= $currentTime)) {
				return FALSE;
			}
		}
		return TRUE;
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\Random::generateID() instead.
	 */
	public static function generateID() {
		return SimpleSAML\Utils\Random::generateID();
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use \SimpleSAML\Utils\Time::generateTimestamp() instead.
	 */
	public static function generateTimestamp($instant = NULL) {
		return SimpleSAML\Utils\Time::generateTimestamp($instant);
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use \SimpleSAML\Utils\Time::parseDuration() instead.
	 */
	public static function parseDuration($duration, $timestamp = NULL) {
		return SimpleSAML\Utils\Time::parseDuration($duration, $timestamp);
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please raise a SimpleSAML_Error_Error exception instead.
	 */
	public static function fatalError($trackId = 'na', $errorCode = null, Exception $e = null) {
		throw new SimpleSAML_Error_Error($errorCode, $e);
	}


	/**
	 * @deprecated This method will be removed in version 2.0. Use SimpleSAML\Utils\Net::ipCIDRcheck() instead.
	 */
	static function ipCIDRcheck($cidr, $ip = null) {
		return SimpleSAML\Utils\Net::ipCIDRcheck($cidr, $ip);
	}

	private static function _doRedirect($url, $parameters = array()) {
		assert('is_string($url)');
		assert('!empty($url)');
		assert('is_array($parameters)');

		if (!empty($parameters)) {
			$url = self::addURLparameter($url, $parameters);
		}

		/* Set the HTTP result code. This is either 303 See Other or
		 * 302 Found. HTTP 303 See Other is sent if the HTTP version
		 * is HTTP/1.1 and the request type was a POST request.
		 */
		if ($_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1' &&
			$_SERVER['REQUEST_METHOD'] === 'POST') {
			$code = 303;
		} else {
			$code = 302;
		}<commit_msg>Declare visibility of SimpleSAML_Utilities::ipCIDRcheck().<commit_after><?php

/**
 * Misc static functions that is used several places.in example parsing and id generation.
 *
 * @author <NAME>, UNINETT AS. <<EMAIL>>
 * @package simpleSAMLphp
 */
class SimpleSAML_Utilities {

	/**
	 * List of log levels.
	 *
	 * This list is used to restore the log levels after some log levels are disabled.
	 *
	 * @var array
	 */
	private static $logLevelStack = array();


	/**
	 * The current mask of disabled log levels.
	 *
	 * Note: This mask is not directly related to the PHP error reporting level.
	 *
	 * @var int
	 */
	public static $logMask = 0;


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfHost() instead.
	 */
	public static function getSelfHost() {
		return \SimpleSAML\Utils\HTTP::getSelfHost();
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfURLHost() instead.
	 */
	public static function selfURLhost() {
		return \SimpleSAML\Utils\HTTP::getSelfURLHost();
	}

	
	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::isHTTPS() instead.
	 */
	public static function isHTTPS() {
		return \SimpleSAML\Utils\HTTP::isHTTPS();
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfURLNoQuery() instead.
	 */
	public static function selfURLNoQuery() {
		return \SimpleSAML\Utils\HTTP::getSelfURLNoQuery();
	
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfHostWithPath() instead.
	 */
	public static function getSelfHostWithPath() {
		return \SimpleSAML\Utils\HTTP::getSelfHostWithPath();
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getFirstPathElement() instead.
	 */
	public static function getFirstPathElement($trailingslash = true) {
		return \SimpleSAML\Utils\HTTP::getFirstPathElement($trailingslash);
	}


    /**
     * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfURL() instead.
     */
	public static function selfURL() {
		return \SimpleSAML\Utils\HTTP::getSelfURL();
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getBaseURL() instead.
	 */
	public static function getBaseURL() {
		return \SimpleSAML\Utils\HTTP::getBaseURL();
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::addURLParameters() instead.
	 */
	public static function addURLparameter($url, $parameters) {
		return \SimpleSAML\Utils\HTTP::addURLParameters($url, $parameters);
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use \SimpleSAML\Utils\HTTP::checkURLAllowed() instead.
	 */
	public static function checkURLAllowed($url, array $trustedSites = NULL) {
		return \SimpleSAML\Utils\HTTP::checkURLAllowed($url, $trustedSites);
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML_Auth_State::parseStateID() instead.
	 */
	public static function parseStateID($stateId) {
		return SimpleSAML_Auth_State::parseStateID($stateId);
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0.
	 */
	public static function checkDateConditions($start=NULL, $end=NULL) {
		$currentTime = time();

		if (!empty($start)) {
			$startTime = SAML2_Utils::xsDateTimeToTimestamp($start);
			/* Allow for a 10 minute difference in Time */
			if (($startTime < 0) || (($startTime - 600) > $currentTime)) {
				return FALSE;
			}
		}
		if (!empty($end)) {
			$endTime = SAML2_Utils::xsDateTimeToTimestamp($end);
			if (($endTime < 0) || ($endTime <= $currentTime)) {
				return FALSE;
			}
		}
		return TRUE;
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\Random::generateID() instead.
	 */
	public static function generateID() {
		return SimpleSAML\Utils\Random::generateID();
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use \SimpleSAML\Utils\Time::generateTimestamp() instead.
	 */
	public static function generateTimestamp($instant = NULL) {
		return SimpleSAML\Utils\Time::generateTimestamp($instant);
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please use \SimpleSAML\Utils\Time::parseDuration() instead.
	 */
	public static function parseDuration($duration, $timestamp = NULL) {
		return SimpleSAML\Utils\Time::parseDuration($duration, $timestamp);
	}


	/**
	 * @deprecated This method will be removed in SSP 2.0. Please raise a SimpleSAML_Error_Error exception instead.
	 */
	public static function fatalError($trackId = 'na', $errorCode = null, Exception $e = null) {
		throw new SimpleSAML_Error_Error($errorCode, $e);
	}


	/**
	 * @deprecated This method will be removed in version 2.0. Use SimpleSAML\Utils\Net::ipCIDRcheck() instead.
	 */
	public static function ipCIDRcheck($cidr, $ip = null) {
		return SimpleSAML\Utils\Net::ipCIDRcheck($cidr, $ip);
	}

	private static function _doRedirect($url, $parameters = array()) {
		assert('is_string($url)');
		assert('!empty($url)');
		assert('is_array($parameters)');

		if (!empty($parameters)) {
			$url = self::addURLparameter($url, $parameters);
		}

		/* Set the HTTP result code. This is either 303 See Other or
		 * 302 Found. HTTP 303 See Other is sent if the HTTP version
		 * is HTTP/1.1 and the request type was a POST request.
		 */
		if ($_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1' &&
			$_SERVER['REQUEST_METHOD'] === 'POST') {
			$code = 303;
		} else {
			$code = 302;
		}
{'fraction_non_alphanumeric': 0.1313355859861284, 'fraction_numerical': 0.011203983638627067, 'mean_word_length': 3.847844827586207, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4983716', 'n_tokens_mistral': 3896, 'n_tokens_neox': 3476, 'n_words': 1018}