From 6befdb098a16e22a8b6bb69a1c9c49988771577f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Mon, 28 Jan 2008 12:50:31 +0000
Subject: [PATCH] Adding a session->getsize class to measure the size of the
 session. I also removed the reference to the configuration class which saved
 12% size of the session size... will be further reduced... hold on.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@202 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Session.php           | 18 ++++++++++++------
 templates/default/en/status.php      |  2 ++
 www/example-simple/saml2-example.php |  5 +----
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/lib/SimpleSAML/Session.php b/lib/SimpleSAML/Session.php
index 3bf9ff8c1..02d4426dd 100644
--- a/lib/SimpleSAML/Session.php
+++ b/lib/SimpleSAML/Session.php
@@ -41,9 +41,6 @@ class SimpleSAML_Session {
 	 * about what went wrong.
 	 */
 	private $trackid = 0;
-
-	
-	private $configuration = null;
 	
 	private $authnrequests = array();
 	private $shibauthreq = null;
@@ -76,7 +73,7 @@ class SimpleSAML_Session {
 	 */
 	private function __construct($protocol, SimpleSAML_XML_AuthnResponse $message = null, $authenticated = true) {
 
-		$this->configuration = SimpleSAML_Configuration::getInstance();
+
 
 		$this->protocol = $protocol;
 		$this->authnresponse = $message;
@@ -87,7 +84,8 @@ class SimpleSAML_Session {
 			$this->sessionstarted = time();
 		}
 		
-		$this->sessionduration = $this->configuration->getValue('session.duration');
+		$configuration = SimpleSAML_Configuration::getInstance();
+		$this->sessionduration = $configuration->getValue('session.duration');
 		
 		$this->trackid = SimpleSAML_Utilities::generateTrackID();
 	}
@@ -206,6 +204,8 @@ class SimpleSAML_Session {
 	 * authentication request.
 	 */
 	public function getAuthnRequest($protocol, $requestid) {
+
+		$configuration = SimpleSAML_Configuration::getInstance();
 		if (isset($this->authnrequests[$protocol])) {
 			/*
 			 * Traverse all cached authentication requests in this session for this user using this protocol
@@ -215,7 +215,7 @@ class SimpleSAML_Session {
 				 * If any of the cached requests is elder than the session.requestcache duration, then just
 				 * simply delete it :)
 				 */
-				if ($cache['date'] < $this->configuration->getValue('session.requestcache', time() - (4*60*60) ))
+				if ($cache['date'] < $configuration->getValue('session.requestcache', time() - (4*60*60) ))
 					unset($this->authnrequests[$protocol][$id]);
 			}
 		}
@@ -355,6 +355,12 @@ class SimpleSAML_Session {
 	public function isModified() {
 		return $this->dirty;
 	}
+	
+	
+	public function getSize() {
+		$s = serialize($this);
+		return strlen($s);
+	}
 }
 
 ?>
\ No newline at end of file
diff --git a/templates/default/en/status.php b/templates/default/en/status.php
index e38885d7a..0929302f1 100644
--- a/templates/default/en/status.php
+++ b/templates/default/en/status.php
@@ -13,6 +13,8 @@
 		
 		<p><?php echo $data['valid']; ?>. Your session is valid for <?php echo $data['remaining']; ?> seconds from now.</p>
 		
+		<p>Session size: <?php echo isset($data['sessionsize']) ? $data['sessionsize'] : 'na'; ?>
+		
 		<h2>Your attributes</h2>
 		
 			<table>
diff --git a/www/example-simple/saml2-example.php b/www/example-simple/saml2-example.php
index 30705a345..be04257fb 100644
--- a/www/example-simple/saml2-example.php
+++ b/www/example-simple/saml2-example.php
@@ -5,10 +5,6 @@ require_once('../_include.php');
 require_once('SimpleSAML/Utilities.php');
 require_once('SimpleSAML/Session.php');
 require_once('SimpleSAML/Metadata/MetaDataStorageHandler.php');
-require_once('SimpleSAML/XML/SAML20/AuthnRequest.php');
-require_once('SimpleSAML/XML/SAML20/AuthnResponse.php');
-require_once('SimpleSAML/Bindings/SAML20/HTTPRedirect.php');
-require_once('SimpleSAML/Bindings/SAML20/HTTPPost.php');
 require_once('SimpleSAML/XHTML/Template.php');
 
 
@@ -42,6 +38,7 @@ $et = new SimpleSAML_XHTML_Template($config, 'status.php');
 
 $et->data['header'] = 'SAML 2.0 SP Demo Example';
 $et->data['remaining'] = $session->remainingTime();
+$et->data['sessionsize'] = $session->getSize();
 $et->data['attributes'] = $attributes;
 $et->data['valid'] = $session->isValid() ? 'Session is valid' : 'Session is invalid';
 
-- 
GitLab