/** * As long as the oidList() function is implemented correctly, there is no need * to reimplement this in subclasses. * Take care: the logic in here comes from reverse engineerring of the snmpwalk * command and takes into account all corner cases. * @return an array with an oid value, null or true */ public function getnext($oid) { $array = $this->oidList(); // if it is not a scalar value, look first to see if the object exists // if it does, return its scalar value if (!preg_match('/\\.0$/', $oid)) { if (($pos = array_search($oid, $array)) !== false) { //return array( $array[$pos], $oid . '.0' ); return $this->get($oid . '.0'); } } else { // looking for next of a scalar val: remove the .0 suffix $oid = eZSNMPd::removeSuffix($oid); } // now search for an exact match with a known oid // if found, return the next oid in the list if (($pos = array_search($oid, $array)) !== false) { if ($pos + 1 < count($array)) { return $this->get($array[$pos + 1] . '.0'); } else { // last oid in the tree: no more next return true; } } // last chance: maybe the searched oid is a node in the tree, not a leaf // a little bit of regexp magic here: if an oid begins with the searched // one, then it is its first ancestor $match = "/^" . str_replace('.', '\\.', $oid) . "/"; foreach ($array as $anOid) { if (preg_match($match, $anOid)) { return $this->get($anOid . '.0'); } } // but what about snmp walking the complete mib? if ('.' . $this->oidRoot() == $oid . '.' && count($array)) { return $this->get($array[0] . '.0'); } return null; }