From edd80c571dc3cda01cc1248a9d053841488bdf97 Mon Sep 17 00:00:00 2001 From: Boris Lytochkin Date: Sun, 12 Jun 2011 11:58:49 +0000 Subject: [PATCH] move SNMP VERSION constants into SNMP class itself --- ext/snmp/snmp.c | 8 +++--- ext/snmp/tests/snmp-object-errno-errstr.phpt | 8 +++--- ext/snmp/tests/snmp-object-error.phpt | 10 +++---- ext/snmp/tests/snmp-object-properties.phpt | 2 +- .../tests/snmp-object-setSecurity_error.phpt | 2 +- ext/snmp/tests/snmp-object.phpt | 26 +++++++++---------- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index f25fbd62eb5..af4d80b8082 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -2385,10 +2385,10 @@ PHP_MINIT_FUNCTION(snmp) REGISTER_LONG_CONSTANT("SNMP_INTEGER", ASN_INTEGER, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SNMP_COUNTER64", ASN_COUNTER64, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SNMP_VERSION_1", SNMP_VERSION_1, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SNMP_VERSION_2c", SNMP_VERSION_2c, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SNMP_VERSION_2C", SNMP_VERSION_2c, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SNMP_VERSION_3", SNMP_VERSION_3, CONST_CS | CONST_PERSISTENT); + REGISTER_SNMP_CLASS_CONST_LONG("VERSION_1", (long)SNMP_VERSION_1); + REGISTER_SNMP_CLASS_CONST_LONG("VERSION_2c", (long)SNMP_VERSION_2c); + REGISTER_SNMP_CLASS_CONST_LONG("VERSION_2C", (long)SNMP_VERSION_2c); + REGISTER_SNMP_CLASS_CONST_LONG("VERSION_3", (long)SNMP_VERSION_3); REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_NOERROR", (long)PHP_SNMP_ERRNO_NOERROR); REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_GENERIC", (long)PHP_SNMP_ERRNO_GENERIC); diff --git a/ext/snmp/tests/snmp-object-errno-errstr.phpt b/ext/snmp/tests/snmp-object-errno-errstr.phpt index f46254ed344..923fb856e07 100644 --- a/ext/snmp/tests/snmp-object-errno-errstr.phpt +++ b/ext/snmp/tests/snmp-object-errno-errstr.phpt @@ -17,27 +17,27 @@ snmp_set_valueretrieval(SNMP_VALUE_PLAIN); snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL); echo "SNMP::ERRNO_NOERROR\n"; -$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); var_dump(@$session->get('.1.3.6.1.2.1.1.1.0')); var_dump($session->getErrno() == SNMP::ERRNO_NOERROR); var_dump($session->getError()); $session->close(); echo "SNMP::ERRNO_TIMEOUT\n"; -$session = new SNMP(SNMP_VERSION_2c, $hostname, 'timeout_community_432', $timeout, $retries); +$session = new SNMP(SNMP::VERSION_2c, $hostname, 'timeout_community_432', $timeout, $retries); $session->valueretrieval = SNMP_VALUE_LIBRARY; var_dump(@$session->get('.1.3.6.1.2.1.1.1.0')); var_dump($session->getErrno() == SNMP::ERRNO_TIMEOUT); var_dump($session->getError()); $session->close(); echo "SNMP::ERRNO_ERROR_IN_REPLY\n"; -$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); var_dump(@$session->get('.1.3.6.1.2.1.1.1.110')); var_dump($session->getErrno() == SNMP::ERRNO_ERROR_IN_REPLY); var_dump($session->getError()); $session->close(); echo "SNMP::ERRNO_GENERIC\n"; -$session = new SNMP(SNMP_VERSION_3, $hostname, 'somebogususer', $timeout, $retries); +$session = new SNMP(SNMP::VERSION_3, $hostname, 'somebogususer', $timeout, $retries); $session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass); var_dump(@$session->get('.1.3.6.1.2.1.1.1.0')); var_dump($session->getErrno() == SNMP::ERRNO_GENERIC); diff --git a/ext/snmp/tests/snmp-object-error.phpt b/ext/snmp/tests/snmp-object-error.phpt index e4fb526d3ee..00db3a318c5 100644 --- a/ext/snmp/tests/snmp-object-error.phpt +++ b/ext/snmp/tests/snmp-object-error.phpt @@ -15,17 +15,17 @@ snmp_set_quick_print(false); snmp_set_valueretrieval(SNMP_VALUE_PLAIN); try { -var_dump(new SNMP(SNMP_VERSION_1, $hostname)); +var_dump(new SNMP(SNMP::VERSION_1, $hostname)); } catch (Exception $e) { print $e->getMessage() . "\n"; } try { -var_dump(new SNMP(SNMP_VERSION_1, $hostname, $community, '')); +var_dump(new SNMP(SNMP::VERSION_1, $hostname, $community, '')); } catch (Exception $e) { print $e->getMessage() . "\n"; } try { -var_dump(new SNMP(SNMP_VERSION_1, $hostname, $community, $timeout, '')); +var_dump(new SNMP(SNMP::VERSION_1, $hostname, $community, $timeout, '')); } catch (Exception $e) { print $e->getMessage() . "\n"; } @@ -36,7 +36,7 @@ var_dump(new SNMP(7, $hostname, $community)); } echo "Open normal session\n"; -$session = new SNMP(SNMP_VERSION_3, $hostname, $user_noauth, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries); $session->valueretrieval = 67; var_dump($session->valueretrieval); echo "Closing session\n"; @@ -45,7 +45,7 @@ var_dump($session->close()); var_dump($session->get('.1.3.6.1.2.1.1.1.0')); var_dump($session->close()); -$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); var_dump($session->walk('.1.3.6.1.2.1.1', FALSE, '')); var_dump($session->walk('.1.3.6.1.2.1.1', FALSE, 0, '')); var_dump($session->get()); diff --git a/ext/snmp/tests/snmp-object-properties.phpt b/ext/snmp/tests/snmp-object-properties.phpt index 0bdf51b46e9..98423670c1a 100644 --- a/ext/snmp/tests/snmp-object-properties.phpt +++ b/ext/snmp/tests/snmp-object-properties.phpt @@ -18,7 +18,7 @@ snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL); echo "Check working\n"; -$session = new SNMP(SNMP_VERSION_1, $hostname, $community, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_1, $hostname, $community, $timeout, $retries); var_dump($session); $session->max_oids = 40; diff --git a/ext/snmp/tests/snmp-object-setSecurity_error.phpt b/ext/snmp/tests/snmp-object-setSecurity_error.phpt index b5327649c07..fc3a1b2269e 100644 --- a/ext/snmp/tests/snmp-object-setSecurity_error.phpt +++ b/ext/snmp/tests/snmp-object-setSecurity_error.phpt @@ -14,7 +14,7 @@ require_once(dirname(__FILE__).'/snmp_include.inc'); snmp_set_quick_print(false); snmp_set_valueretrieval(SNMP_VALUE_PLAIN); -$session = new SNMP(SNMP_VERSION_3, $hostname, $user_noauth, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries); $session->setSecurity('noAuthNoPriv'); #echo "Checking error handling\n"; diff --git a/ext/snmp/tests/snmp-object.phpt b/ext/snmp/tests/snmp-object.phpt index 64db8b870dc..684391b461e 100644 --- a/ext/snmp/tests/snmp-object.phpt +++ b/ext/snmp/tests/snmp-object.phpt @@ -17,7 +17,7 @@ snmp_set_valueretrieval(SNMP_VALUE_PLAIN); snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL); echo "SNMPv1\n"; -$session = new SNMP(SNMP_VERSION_1, $hostname, $community, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_1, $hostname, $community, $timeout, $retries); $session->valueretrieval = SNMP_VALUE_LIBRARY; var_dump($session->get('.1.3.6.1.2.1.1.1.0')); var_dump($session->get(array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.3.0'))); @@ -25,13 +25,13 @@ var_dump($session->getnext('.1.3.6.1.2.1.1.1.0')); var_dump($session->close()); echo "SNMPv2\n"; -$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); var_dump($session->get('.1.3.6.1.2.1.1.1.0')); var_dump($session->getnext('.1.3.6.1.2.1.1.1.0')); var_dump($session->close()); echo "GET with preserving original OID names\n"; -$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); $orig = array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.5.0'); $result = $session->get($orig, TRUE); foreach($orig as $oid){ @@ -40,7 +40,7 @@ foreach($orig as $oid){ var_dump($session->close()); echo "WALK multiple on single OID\n"; -$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); $z = $session->walk('.1.3.6.1.2.1.1'); var_dump(gettype($z)); var_dump(count($z)); @@ -49,7 +49,7 @@ var_dump(array_shift($z)); var_dump($session->close()); echo "WALK multiple on single OID, non_repeaters set to 0\n"; -$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); $z = $session->walk('.1.3.6.1.2.1.1', 0); var_dump(gettype($z)); var_dump(count($z)); @@ -58,7 +58,7 @@ var_dump(array_shift($z)); var_dump($session->close()); echo "WALK multiple on single OID, non_repeaters set to 0, max_repetitions set to 30\n"; -$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); $z = $session->walk('.1.3.6.1.2.1.1', 0, 30); var_dump(gettype($z)); var_dump(count($z)); @@ -67,7 +67,7 @@ var_dump(array_shift($z)); var_dump($session->close()); echo "WALK multiple on single OID, max_oids set to 30\n"; -$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); $session->max_oids = 30; $z = $session->walk('.1.3.6.1.2.1.1'); var_dump(gettype($z)); @@ -77,7 +77,7 @@ var_dump(array_shift($z)); var_dump($session->close()); echo "WALK multiple on single OID with OID suffix as keys\n"; -$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); $z = $session->walk('.1.3.6.1.2.1.1', TRUE); var_dump(gettype($z)); var_dump(count($z)); @@ -86,21 +86,21 @@ var_dump(array_shift($z)); var_dump($session->close()); echo "SNMPv3 (default security settings)\n"; -$session = new SNMP(SNMP_VERSION_3, $hostname, $user_noauth, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries); #$session->setSecurity($user_noauth, 'noAuthNoPriv', '', '', '', '', '', ''); var_dump($session->get('.1.3.6.1.2.1.1.1.0')); var_dump($session->getnext('.1.3.6.1.2.1.1.1.0')); var_dump($session->close()); echo "SNMPv3 (noAuthNoPriv)\n"; -$session = new SNMP(SNMP_VERSION_3, $hostname, $user_noauth, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries); $session->setSecurity('noAuthNoPriv'); var_dump($session->get('.1.3.6.1.2.1.1.1.0')); var_dump($session->getnext('.1.3.6.1.2.1.1.1.0')); var_dump($session->close()); echo "SNMPv3 (authPriv)\n"; -$session = new SNMP(SNMP_VERSION_3, $hostname, $rwuser, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries); $session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass); var_dump($session->get('.1.3.6.1.2.1.1.1.0')); var_dump($session->getnext('.1.3.6.1.2.1.1.1.0')); @@ -108,7 +108,7 @@ var_dump($session->walk('.1.3.6.1.2.1.1.1.0')); var_dump($session->close()); echo "SET single OID\n"; -$session = new SNMP(SNMP_VERSION_3, $hostname, $rwuser, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries); $session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass); $oid1 = 'SNMPv2-MIB::sysContact.0'; $oldvalue1 = $session->get($oid1); @@ -123,7 +123,7 @@ var_dump(($session->get($oid1) === $oldvalue1)); var_dump($session->close()); echo "SNMPv3, setting contextEngineID (authPriv)\n"; -$session = new SNMP(SNMP_VERSION_3, $hostname, $rwuser, $timeout, $retries); +$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries); $session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '', 'aeeeff'); var_dump($session->get('.1.3.6.1.2.1.1.1.0')); var_dump($session->close());