cvs: pecl /statgrab config.m4 php_statgrab.h statgrab.c
| From: | Ilia Alshanetsky | Date: | Wed, 10 Mar 2004 19:43:48 +0000 |
| Subject: | cvs: pecl /statgrab config.m4 php_statgrab.h statgrab.c | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-1045@lists.php.net to get a copy of this message | ||
iliaa Wed Mar 10 14:43:48 2004 EDT
Modified files:
/pecl/statgrab config.m4 php_statgrab.h statgrab.c
Log:
Updated interface with new functionality avaliable in libstatgrab 0.9
(old versions of libstatgrab are still supported).
Added statg_network_iface_stats() function to get interface information.
Added additional information to network functions.
http://cvs.php.net/diff.php/pecl/statgrab/config.m4?r1=1.1&r2=1.2&ty=u
Index: pecl/statgrab/config.m4
diff -u pecl/statgrab/config.m4:1.1 pecl/statgrab/config.m4:1.2
--- pecl/statgrab/config.m4:1.1 Tue Jan 27 22:24:44 2004
+++ pecl/statgrab/config.m4 Wed Mar 10 14:43:46 2004
@@ -1,9 +1,13 @@
-dnl $Id: config.m4,v 1.1 2004/01/28 03:24:44 iliaa Exp $
+dnl $Id: config.m4,v 1.2 2004/03/10 19:43:46 iliaa Exp $
dnl config.m4 for extension statgrab
PHP_ARG_WITH(statgrab, for libstatgrab support,
[ --with-statgrab Include libstatgrab support])
+AC_DEFUN(PHP_STATGRAB_CHECK_VERSION,[
+ PHP_CHECK_LIBRARY(statgrab, get_network_iface_stats, [AC_DEFINE(HAVE_STATGRAB_09,
1, [ ])], [], [ -L$STATGRAB_DIR/lib $STATGRAB_SHARED_LIBADD ])
+])
+
if test "$PHP_STATGRAB" != "no"; then
SEARCH_PATH="/usr/local /usr"
SEARCH_FOR="/include/statgrab.h"
@@ -31,6 +35,7 @@
[
PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $STATGRAB_DIR/lib, STATGRAB_SHARED_LIBADD)
AC_DEFINE(HAVE_STATGRABLIB,1,[ ])
+ PHP_STATGRAB_CHECK_VERSION
],[
AC_MSG_ERROR([wrong libstatgrab version or lib not found])
],[
@@ -41,3 +46,4 @@
PHP_NEW_EXTENSION(statgrab, statgrab.c, $ext_shared)
fi
+
http://cvs.php.net/diff.php/pecl/statgrab/php_statgrab.h?r1=1.1&r2=1.2&ty=u
Index: pecl/statgrab/php_statgrab.h
diff -u pecl/statgrab/php_statgrab.h:1.1 pecl/statgrab/php_statgrab.h:1.2
--- pecl/statgrab/php_statgrab.h:1.1 Tue Jan 27 22:24:44 2004
+++ pecl/statgrab/php_statgrab.h Wed Mar 10 14:43:46 2004
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_statgrab.h,v 1.1 2004/01/28 03:24:44 iliaa Exp $ */
+/* $Id: php_statgrab.h,v 1.2 2004/03/10 19:43:46 iliaa Exp $ */
#ifndef PHP_STATGRAB_H
#define PHP_STATGRAB_H
@@ -52,6 +52,9 @@
PHP_FUNCTION(statg_page_stats_diff);
PHP_FUNCTION(statg_process_stats);
PHP_FUNCTION(statg_user_stats);
+#ifdef HAVE_STATGRAB_09
+PHP_FUNCTION(statg_network_iface_stats);
+#endif
#endif /* PHP_STATGRAB_H */
http://cvs.php.net/diff.php/pecl/statgrab/statgrab.c?r1=1.1&r2=1.2&ty=u
Index: pecl/statgrab/statgrab.c
diff -u pecl/statgrab/statgrab.c:1.1 pecl/statgrab/statgrab.c:1.2
--- pecl/statgrab/statgrab.c:1.1 Tue Jan 27 22:24:44 2004
+++ pecl/statgrab/statgrab.c Wed Mar 10 14:43:46 2004
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: statgrab.c,v 1.1 2004/01/28 03:24:44 iliaa Exp $ */
+/* $Id: statgrab.c,v 1.2 2004/03/10 19:43:46 iliaa Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -30,7 +30,7 @@
#include "ext/standard/php_string.h" /* needed for php_explode */
#include "php_statgrab.h"
-#define PHP_STATGRAB_VERSION "0.1"
+#define PHP_STATGRAB_VERSION "0.2"
#define PHP_STATG_ADD_FVAL(rtz, key, val) add_assoc_double_ex(rtz, key, sizeof(key), val);
#define PHP_STATG_ADD_LVAL(rtz, key, val) add_assoc_long_ex(rtz, key, sizeof(key), val);
@@ -40,7 +40,6 @@
add_assoc_stringl_ex(rtz, key, sizeof(key), tmp, tmp_len, 1); \
}
-
/* True global resources - no need for thread safety here
static int le_statgrab;
*/
@@ -65,6 +64,9 @@
PHP_FE(statg_page_stats_diff, NULL)
PHP_FE(statg_process_stats, NULL)
PHP_FE(statg_user_stats, NULL)
+#ifdef HAVE_STATGRAB_09
+ PHP_FE(statg_network_iface_stats, NULL)
+#endif
{NULL, NULL, NULL} /* Must be the last line in statgrab_functions[] */
};
/* }}} */
@@ -105,6 +107,12 @@
zend_error(E_ERROR, "libstatgrab: Failed to drop privileges");
}
+#ifdef HAVE_STATGRAB_09
+ REGISTER_LONG_CONSTANT("STATG_FULL_DUPLEX", FULL_DUPLEX, CONST_CS|CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("STATG_HALF_DUPLEX", HALF_DUPLEX, CONST_CS|CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("STATG_UNKNOWN_DUPLEX", UNKNOWN_DUPLEX,
CONST_CS|CONST_PERSISTENT);
+#endif
+
return SUCCESS;
}
/* }}} */
@@ -364,6 +372,13 @@
PHP_STATG_ADD_LLVAL(tmpz, "sent", ns->tx)
PHP_STATG_ADD_LLVAL(tmpz, "recieved", ns->rx)
+#ifdef HAVE_STATGRAB_09
+ PHP_STATG_ADD_LLVAL(tmpz, "packets_received", ns->ipackets)
+ PHP_STATG_ADD_LLVAL(tmpz, "packets_transmitted", ns->opackets)
+ PHP_STATG_ADD_LLVAL(tmpz, "recieve_errors", ns->ierrors)
+ PHP_STATG_ADD_LLVAL(tmpz, "transmit_errors", ns->oerrors)
+ PHP_STATG_ADD_LLVAL(tmpz, "collisions", ns->collisions)
+#endif
PHP_STATG_ADD_LVAL(tmpz, "time_frame", ns->systime)
add_assoc_zval(return_value, ns->interface_name, tmpz);
@@ -479,6 +494,44 @@
}
/* }}} */
+#ifdef HAVE_STATGRAB_09
+/* {{{ proto array statg_network_iface_stats()
+ Returns an array containing statistics about the network interfaces in the machine. */
+PHP_FUNCTION(statg_network_iface_stats)
+{
+ network_iface_stat_t *ifs;
+ int ent, i;
+
+ if (ZEND_NUM_ARGS()) {
+ WRONG_PARAM_COUNT;
+ }
+
+ ifs = get_network_iface_stats(&ent);
+
+ if (ifs == NULL) {
+ RETURN_FALSE;
+ }
+
+ array_init(return_value);
+
+ for (i = 0; i < ent; i++) {
+ zval *tmpz;
+
+ MAKE_STD_ZVAL(tmpz);
+ array_init(tmpz);
+
+ PHP_STATG_ADD_LVAL(tmpz, "speed", ifs->speed)
+ PHP_STATG_ADD_LVAL(tmpz, "duplex", ifs->dup)
+ add_assoc_bool(tmpz, "active", ifs->up);
+
+ add_assoc_zval(return_value, ifs->interface_name, tmpz);
+
+ ifs++;
+ }
+}
+/* }}} */
+#endif
+
/*
* Local variables:
* tab-width: 4