/** * Compares two respones. * * Compares two respones, based on criteria defined in * {@link static::$compareBy}. * * @param Response $itemA The response to compare. * @param Response $itemB The response to compare $a against. * * @return int Returns 0 if the two respones are equal according to every * criteria specified, -1 if $a should be placed before $b, and 1 if $b * should be placed before $a. */ protected function compare(Response $itemA, Response $itemB) { foreach ($this->compareBy as $name => $spec) { if (!is_string($name)) { $name = $spec; $spec = null; } $members = array(0 => $itemA->getProperty($name), 1 => $itemB->getProperty($name)); if (is_callable($spec)) { uasort($members, $spec); } elseif ($members[0] === $members[1]) { continue; } else { $flags = SORT_REGULAR; $order = SORT_ASC; if (is_array($spec)) { list($order, $flags) = $spec; } elseif (null !== $spec) { $order = $spec; } if (SORT_ASC === $order) { asort($members, $flags); } else { arsort($members, $flags); } } return key($members) === 0 ? -1 : 1; } return 0; }
/** * Checks whether the queue item's target is the HOSTNAME_INVALID constant. * * @param Response $item The item to check. * * @return bool TRUE on success, FALSE on failure. */ function isHostnameInvalid(Response $item) { return $item->getProperty('target') === Test\HOSTNAME_INVALID . '/32'; }
/** * Login to a RouterOS connection. * * This is the actual login procedure, applied regardless of persistence and * charset settings. * * @param Communicator $com The communicator to attempt to login to. * @param string $username The RouterOS username. * @param string $password The RouterOS password. Potentially parsed * already by iconv. * @param int|null $timeout The time to wait for each response. NULL * waits indefinetly. * * @return bool TRUE on success, FALSE on failure. */ private static function _login(Communicator $com, $username, $password = '', $timeout = null) { $request = new Request('/login'); $request->send($com); $response = new Response($com, false, $timeout); $request->setArgument('name', $username); $request->setArgument('response', '00' . md5(chr(0) . $password . pack('H*', $response->getProperty('ret')))); $request->send($com); $response = new Response($com, false, $timeout); return $response->getType() === Response::TYPE_FINAL && null === $response->getProperty('ret'); }