$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);