From 277523f830ca3a5455092f582d7bdc89b2f0cc07 Mon Sep 17 00:00:00 2001
From: Jaime Perez Crespo <jaime.perez@uninett.no>
Date: Tue, 21 Apr 2015 12:47:52 +0200
Subject: [PATCH] Move SimpleSAML_Utilities::getSelfHost() to
 SimpleSAML\Utils\HTTP::getSelfHost() and deprecate the former.

---
 .../Metadata/MetaDataStorageHandler.php       |  2 +-
 .../MetaDataStorageHandlerFlatFile.php        |  4 ++--
 .../Metadata/MetaDataStorageSource.php        |  2 +-
 lib/SimpleSAML/Utilities.php                  | 13 +++----------
 lib/SimpleSAML/Utils/HTTP.php                 | 19 +++++++++++++++++++
 www/admin/hostnames.php                       |  2 +-
 6 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
index 70aba6d1d..7ec37a88e 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
@@ -198,7 +198,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandler {
 
 	
 		/* Then we look for the hostname. */
-		$currenthost = SimpleSAML_Utilities::getSelfHost(); // sp.example.org
+		$currenthost = \SimpleSAML\Utils\HTTP::getSelfHost(); // sp.example.org
 		if(strpos($currenthost, ":") !== FALSE) {
 			$currenthostdecomposed = explode(":", $currenthost);
 			$currenthost = $currenthostdecomposed[0];
diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
index b028bb4f8..656426b17 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
@@ -123,9 +123,9 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerFlatFile extends SimpleSAML_Meta
 		} elseif($set === 'shib13-idp-hosted') {
 			return $baseurl . 'shib13/idp/metadata.php';
 		} elseif($set === 'wsfed-sp-hosted') {
-			return 'urn:federation:' . SimpleSAML_Utilities::getSelfHost();
+			return 'urn:federation:' . \SimpleSAML\Utils\HTTP::getSelfHost();
 		} elseif($set === 'adfs-idp-hosted') {
-			return 'urn:federation:' . SimpleSAML_Utilities::getSelfHost() . ':idp';
+			return 'urn:federation:' . \SimpleSAML\Utils\HTTP::getSelfHost() . ':idp';
 		} else {
 			throw new Exception('Can not generate dynamic EntityID for metadata of this type: [' . $set . ']');
 		}
diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageSource.php b/lib/SimpleSAML/Metadata/MetaDataStorageSource.php
index 0ce412165..1fc1160b3 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageSource.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageSource.php
@@ -178,7 +178,7 @@ abstract class SimpleSAML_Metadata_MetaDataStorageSource {
 		$metadataSet = $this->getMetadataSet($set);
 
 		/* Check for hostname. */
-		$currenthost = SimpleSAML_Utilities::getSelfHost(); // sp.example.org
+		$currenthost = \SimpleSAML\Utils\HTTP::getSelfHost(); // sp.example.org
 		if(strpos($currenthost, ":") !== FALSE) {
 			$currenthostdecomposed = explode(":", $currenthost);
 			$currenthost = $currenthostdecomposed[0];
diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 38e6bc71c..303956dd3 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -29,19 +29,12 @@ class SimpleSAML_Utilities {
 
 
 	/**
-	 * Will return sp.example.org
+	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfHost() instead.
 	 */
 	public static function getSelfHost() {
-
-		$url = self::getBaseURL();
-
-		$start = strpos($url,'://') + 3;
-		$length = strcspn($url,'/:',$start);
-
-		return substr($url, $start, $length);
-
+		return \SimpleSAML\Utils\HTTP::getSelfHost();
 	}
-	
+
 	/**
 	 * Retrieve Host value from $_SERVER environment variables
 	 */
diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php
index e754b17bb..38840c5a2 100644
--- a/lib/SimpleSAML/Utils/HTTP.php
+++ b/lib/SimpleSAML/Utils/HTTP.php
@@ -316,6 +316,25 @@ class HTTP
     }
 
 
+    /**
+     * Retrieve our own host.
+     *
+     * @return string The current host.
+     *
+     * @author Andreas Solberg, UNINETT AS <andreas.solberg@uninett.no>
+     * @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
+     */
+    public static function getSelfHost()
+    {
+        $url = self::getBaseURL();
+
+        $start = strpos($url, '://') + 3;
+        $length = strcspn($url, '/:', $start);
+
+        return substr($url, $start, $length);
+    }
+
+
     /**
      * Parse a query string into an array.
      *
diff --git a/www/admin/hostnames.php b/www/admin/hostnames.php
index 0a520a93a..90792209d 100644
--- a/www/admin/hostnames.php
+++ b/www/admin/hostnames.php
@@ -17,7 +17,7 @@ $attributes['SERVER_PROTOCOL'] = array($_SERVER['SERVER_PROTOCOL']);
 $attributes['SERVER_PORT'] = array($_SERVER['SERVER_PORT']);
 
 $attributes['Utilities_getBaseURL()'] = array(\SimpleSAML\Utils\HTTP::getBaseURL());
-$attributes['Utilities_getSelfHost()'] = array(SimpleSAML_Utilities::getSelfHost());
+$attributes['Utilities_getSelfHost()'] = array(\SimpleSAML\Utils\HTTP::getSelfHost());
 $attributes['Utilities_selfURLhost()'] = array(SimpleSAML_Utilities::selfURLhost());
 $attributes['Utilities_selfURLNoQuery()'] = array(SimpleSAML_Utilities::selfURLNoQuery());
 $attributes['Utilities_getSelfHostWithPath()'] = array(SimpleSAML_Utilities::getSelfHostWithPath());
-- 
GitLab