lytboris                                 Sat, 05 Feb 2011 00:29:31 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=308037

Log:
added r/o info property with basic session info,
fix crash in _get_properties in trunk

Changed paths:
    U   php/php-src/trunk/ext/snmp/snmp.c
    U   php/php-src/trunk/ext/snmp/tests/snmp-object-properties.phpt

Modified: php/php-src/trunk/ext/snmp/snmp.c
===================================================================
--- php/php-src/trunk/ext/snmp/snmp.c   2011-02-04 21:49:51 UTC (rev 308036)
+++ php/php-src/trunk/ext/snmp/snmp.c   2011-02-05 00:29:31 UTC (rev 308037)
@@ -1193,7 +1193,7 @@
 static int netsnmp_session_set_contextEngineID(struct snmp_session *s, u_char 
* contextEngineID TSRMLS_DC)
 {
        size_t  ebuf_len = 32, eout_len = 0;
-       u_char  *ebuf = (u_char *) malloc(ebuf_len); /* memory freed by SNMP 
library, strdup NOT estrdup */
+       u_char  *ebuf = (u_char *) malloc(ebuf_len); /* memory freed by SNMP 
library, malloc NOT emalloc */

        if (ebuf == NULL) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "malloc failure 
setting contextEngineID");
@@ -1204,6 +1204,11 @@
                free(ebuf);
                return (-1);
        }
+
+       if (s->contextEngineID) {
+               free(s->contextEngineID);
+       }
+
        s->contextEngineID = ebuf;
        s->contextEngineIDLen = eout_len;
        return (0);
@@ -1971,7 +1976,11 @@
        ulong num_key;

        obj = (php_snmp_object *)zend_objects_get_address(object TSRMLS_CC);
+#if PHP_VERSION_ID < 50399
        props = obj->zo.properties;
+#else
+       props = zend_std_get_properties(object TSRMLS_CC);
+#endif

        zend_hash_internal_pointer_reset_ex(&php_snmp_properties, &pos);

@@ -1989,6 +1998,34 @@
 /* }}} */

 /* {{{ */
+static int php_snmp_read_info(php_snmp_object *snmp_object, zval **retval 
TSRMLS_DC)
+{
+       zval *val;
+
+       MAKE_STD_ZVAL(*retval);
+       array_init(*retval);
+
+       MAKE_STD_ZVAL(val);
+       ZVAL_STRINGL(val, snmp_object->session->peername, 
strlen(snmp_object->session->peername), 1);
+       add_assoc_zval(*retval, "hostname", val);
+
+       MAKE_STD_ZVAL(val);
+       ZVAL_LONG(val, snmp_object->session->remote_port);
+       add_assoc_zval(*retval, "port", val);
+
+       MAKE_STD_ZVAL(val);
+       ZVAL_LONG(val, snmp_object->session->timeout);
+       add_assoc_zval(*retval, "timeout", val);
+
+       MAKE_STD_ZVAL(val);
+       ZVAL_LONG(val, snmp_object->session->retries);
+       add_assoc_zval(*retval, "retries", val);
+
+       return SUCCESS;
+}
+/* }}} */
+
+/* {{{ */
 static int php_snmp_read_max_oids(php_snmp_object *snmp_object, zval **retval 
TSRMLS_DC)
 {
        MAKE_STD_ZVAL(*retval);
@@ -2036,6 +2073,14 @@
 #endif

 /* {{{ */
+static int php_snmp_write_info(php_snmp_object *snmp_object, zval *newval 
TSRMLS_DC)
+{
+       php_error_docref(NULL TSRMLS_CC, E_WARNING, "info property is 
read-only");
+       return FAILURE;
+}
+/* }}} */
+
+/* {{{ */
 static int php_snmp_write_max_oids(php_snmp_object *snmp_object, zval *newval 
TSRMLS_DC)
 {
        zval ztmp;
@@ -2184,6 +2229,7 @@
        { "" #name "",          sizeof("" #name "") - 1,        
php_snmp_read_##name,   php_snmp_write_##name }

 const php_snmp_prop_handler php_snmp_property_entries[] = {
+       PHP_SNMP_PROPERTY_ENTRY_RECORD(info),
        PHP_SNMP_PROPERTY_ENTRY_RECORD(max_oids),
        PHP_SNMP_PROPERTY_ENTRY_RECORD(valueretrieval),
        PHP_SNMP_PROPERTY_ENTRY_RECORD(quick_print),

Modified: php/php-src/trunk/ext/snmp/tests/snmp-object-properties.phpt
===================================================================
--- php/php-src/trunk/ext/snmp/tests/snmp-object-properties.phpt        
2011-02-04 21:49:51 UTC (rev 308036)
+++ php/php-src/trunk/ext/snmp/tests/snmp-object-properties.phpt        
2011-02-05 00:29:31 UTC (rev 308037)
@@ -21,6 +21,7 @@
 $session = new SNMP(SNMP_VERSION_1, $hostname, $community, $timeout, $retries);
 var_dump($session);

+$session->max_oids = 40;
 $session->enum_print = TRUE;
 $session->quick_print = TRUE;
 $session->valueretrieval = SNMP_VALUE_LIBRARY;
@@ -28,6 +29,7 @@

 var_dump($session);

+$session->max_oids = "40";
 $session->enum_print = "1";
 $session->quick_print = "1";
 $session->valueretrieval = "1";
@@ -55,10 +57,25 @@
 $session->oid_output_format = 78;
 var_dump($session->oid_output_format);

+$session->info = array("blah" => 2);
+var_dump($session->info);
 ?>
 --EXPECTF--
 Check working
 object(SNMP)#%d (%d) {
+  ["info"]=>
+  array(4) {
+    ["hostname"]=>
+    %string|unicode%(%d) "%s"
+    ["port"]=>
+    int(%d)
+    ["timeout"]=>
+    int(%i)
+    ["retries"]=>
+    int(%d)
+  }
+  ["max_oids"]=>
+  int(0)
   ["valueretrieval"]=>
   int(1)
   ["quick_print"]=>
@@ -69,6 +86,19 @@
   int(3)
 }
 object(SNMP)#%d (%d) {
+  ["info"]=>
+  array(4) {
+    ["hostname"]=>
+    %string|unicode%(%d) "%s"
+    ["port"]=>
+    int(%d)
+    ["timeout"]=>
+    int(%i)
+    ["retries"]=>
+    int(%d)
+  }
+  ["max_oids"]=>
+  int(40)
   ["valueretrieval"]=>
   int(0)
   ["quick_print"]=>
@@ -79,6 +109,19 @@
   int(4)
 }
 object(SNMP)#%d (%d) {
+  ["info"]=>
+  array(4) {
+    ["hostname"]=>
+    %string|unicode%(%d) "%s"
+    ["port"]=>
+    int(%d)
+    ["timeout"]=>
+    int(%i)
+    ["retries"]=>
+    int(%d)
+  }
+  ["max_oids"]=>
+  int(40)
   ["valueretrieval"]=>
   int(1)
   ["quick_print"]=>
@@ -92,6 +135,19 @@
 bool(true)
 bool(false)
 object(SNMP)#%d (%d) {
+  ["info"]=>
+  array(4) {
+    ["hostname"]=>
+    %string|unicode%(%d) "%s"
+    ["port"]=>
+    int(%d)
+    ["timeout"]=>
+    int(%i)
+    ["retries"]=>
+    int(%d)
+  }
+  ["max_oids"]=>
+  int(40)
   ["valueretrieval"]=>
   int(1)
   ["quick_print"]=>
@@ -115,4 +171,16 @@
 int(1)

 Warning: main(): Unknown SNMP output print format '78' in %s on line %d
-int(3)
\ No newline at end of file
+int(3)
+
+Warning: main(): info property is read-only in %s on line %d
+array(4) {
+  ["hostname"]=>
+  %string|unicode%(%d) "%s"
+  ["port"]=>
+  int(%d)
+  ["timeout"]=>
+  int(%i)
+  ["retries"]=>
+  int(%d)
+}
\ No newline at end of file

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to