]> git.mxchange.org Git - hub.git/commitdiff
Rewritten session id solver to lesser negation
authorRoland Häder <roland@mxchange.org>
Thu, 31 Mar 2011 01:49:19 +0000 (01:49 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 31 Mar 2011 01:49:19 +0000 (01:49 +0000)
application/hub/main/tools/class_HubTools.php

index 5426c0b7c6066a51b3309f89d7cfc45a9a0d354d..60fd33ca75a2ae72458fb9b2e0610c1333a555a8 100644 (file)
@@ -112,38 +112,38 @@ class HubTools extends BaseFrameworkSystem {
                $recipient = $sessionId;
 
                // Does it match a direct ip:port? (hint: see www.regexlib.com for the regular expression)
-               if (!preg_match('/((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])):([0-9]{3,5})/', $sessionId)) {
-                       // Is it in cache?
-                       if (isset($selfInstance->sessionIdCache[$sessionId])) {
-                               // Debug message
-                               $selfInstance->debugOutput('HUB-TOOLS: Using entry from sessionIdCache[] array.');
-
-                               // Then use it
-                               $recipient = $selfInstance->sessionIdCache[$sessionId];
-                       } elseif (preg_match('/([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}/', $sessionId)) {
-                               // Hostname:port found
-                               $hostnameArray = explode(':', $sessionId);
-
-                               // Try to resolve it and add port again
-                               // @TODO We may want to encapsulate this PHP call into an own class
-                               $recipient = gethostbyname($hostnameArray[0]) . ':' . $hostnameArray[1];
-
-                               // Is it valid?
-                               if ($recipient == $sessionId) {
-                                       // Resolving hostname->IP failed!
-                                       throw new NoValidHostnameException($hostnameArray, self::EXCEPTION_HOSTNAME_NOT_FOUND);
-                               } // END - if
-                       } elseif (!preg_match('/([a-f0-9]{' . $selfInstance->getSessionIdLength() . '})/', $sessionId)) {
-                               // Invalid session id
-                               throw new InvalidSessionIdException($sessionId, self::EXCEPTION_SESSION_ID_IS_INVALID);
-                       } else {
-                               // Debug message
-                               $selfInstance->debugOutput('HUB-TOOLS: Using internal resolver.');
-
-                               // Resolve it here
-                               $recipient = $selfInstance->resolveIpPortBySessionId($sessionId);
-                       }
-               } // END - if
+               if (preg_match('/((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])):([0-9]{3,5})/', $sessionId)) {
+                       // Direct ip:port found
+                       $selfInstance->debugOutput('HUB-TOOLS: Direct ip:port ' . $sessionId . ' detected.');
+               } elseif (isset($selfInstance->sessionIdCache[$sessionId])) {
+                       // Debug message
+                       $selfInstance->debugOutput('HUB-TOOLS: Using entry from sessionIdCache[] array.');
+
+                       // Found in cache!
+                       $recipient = $selfInstance->sessionIdCache[$sessionId];
+               } elseif (preg_match('/([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}/', $sessionId)) {
+                       // Hostname:port found
+                       $hostnameArray = explode(':', $sessionId);
+
+                       // Try to resolve it and add port again
+                       // @TODO We may want to encapsulate this PHP call into an own class
+                       $recipient = gethostbyname($hostnameArray[0]) . ':' . $hostnameArray[1];
+
+                       // Is it valid?
+                       if ($recipient == $sessionId) {
+                               // Resolving hostname->IP failed!
+                               throw new NoValidHostnameException($hostnameArray, self::EXCEPTION_HOSTNAME_NOT_FOUND);
+                       } // END - if
+               } elseif (preg_match('/([a-f0-9]{' . $selfInstance->getSessionIdLength() . '})/', $sessionId)) {
+                       // Debug message
+                       $selfInstance->debugOutput('HUB-TOOLS: Using internal resolver.');
+
+                       // Resolve session id into a ip:port combination
+                       $recipient = $selfInstance->resolveIpPortBySessionId($sessionId);
+               } else {
+                       // Invalid session id
+                       throw new InvalidSessionIdException($sessionId, self::EXCEPTION_SESSION_ID_IS_INVALID);
+               }
 
                // Output message
                $selfInstance->debugOutput('HUB-TOOLS: Session id ' . $sessionId . ' resolved to ' . $recipient);