package.xml 0000644 0001750 0001750 00000025374 14040307736 013050 0 ustar kubelik kubelik
rrd
pecl.php.net
PHP bindings to rrd tool system
Procedural and simple OO wrapper for rrdtool - data logging and graphing system for time series data.
Miroslav Kubelik
koubel
koubel@php.net
yes
2021-04-22
2.0.3
1.1
stable
stable
BSD
- fix windows build - thanks Christoph <cmb@php.net>
7.0.0
1.4.0
rrd
2.0.3
1.1
stable
stable
BSD
- fix windows build - thanks Christoph <cmb@php.net>
2021-04-22
2.0.2
1.1
stable
stable
- compatibility with PHP 8 - thanks Remi
2021-04-18
2.0.1
1.1
stable
stable
- config.m4 - cleanup, pkg-config usage
- check for rrdtool 1.5, 1.6 - works without code changes
2016-05-10
2.0.0
1.1
stable
stable
- utilize ZSTR macros for zend_string
2015-12-28
2.0.0beta2
1.1
beta
stable
- package.xml release info fix
2015-06-16
2.0.0beta1
1.1
beta
stable
- first release for PHP 7 - 2.x series isn't BC compatible with PHP 5
2015-06-16
1.1.3
1.1.3
stable
stable
- rrdc_disconnect is available in rrd 1.4.0+ (Remi)
2014-01-15
1.1.2
1.1.2
stable
stable
- closing connection to rrd caching daemon #66088
- better documentation for RRDGraph::setOptions #65756
2014-01-14
1.1.1
1.1.1
stable
stable
- possible segfault in rrd_fetch
2013-09-03
1.1.0
1.1.0
stable
stable
- bug with multiple data sources in rrd_lastupdate - BC break #61316
2012-06-04
1.0.5
1.0.5
stable
stable
- license changed to the BSD license
2011-11-16
1.0.5RC2
1.0.5
beta
stable
- zts build fixed #59992
2011-10-17
1.0.5RC1
1.0.5
beta
stable
- config.m4 - lib searching rewritten, better support across architectures #22683
- RRDUpdater - multiple DS don't work #23579
- better support for compiling under 5.2.x #22719
- small manual fixes
2011-09-27
1.0.4
1.0.4
stable
stable
- can be used with 5.4/trunk #22836
2011-08-12
1.0.3
1.0.3
stable
stable
- fixed installation for libs outside LDFLAGS #22666
2011-04-29
1.0.2
1.0.2
stable
stable
- fixed broken installation on FreeBSD #22651
2011-04-19
1.0.1
1.0.1
stable
stable
- fixed broken pecl installation #22644
2011-04-16
1.0.0
1.0.0
stable
stable
- fixed all reported bugs, mostly in tests
- rrd_version() added
- better tests
2011-04-12
0.10.0
0.10.0
stable
beta
- fixed all reported bugs
- fixed major bug in rrd_fetch #21402
- BC break : returned array format from rrd_fetch changed, these items doesn't
exist anymore - "ds_cnt", "ds_namv"
2011-03-03
0.9.0
0.9.0
beta
beta
first official pecl release
2011-01-03
rrd-2.0.3/tests/data/definition.inc 0000644 0001750 0001750 00000000730 14040307736 017043 0 ustar kubelik kubelik rrd_updater_fetch.txt
speed-dump.xml: speed.rrd
$(rrd_binary) dump speed.rrd >speed-dump.xml
moreDS-empty.rrd:
$(rrd_binary) create moreDS-empty.rrd --start 920804400 \
DS:speed1:COUNTER:600:U:U \
DS:speed2:COUNTER:600:U:U \
RRA:AVERAGE:0.5:1:24 \
RRA:AVERAGE:0.5:6:10
cp moreDS-empty.rrd moreDS-updater.rrd
$(rrd_binary) update moreDS-updater.rrd \
920804700:12345:11340 920805000:12357:11357 920805300:12363:11363
$(rrd_binary) fetch moreDS-updater.rrd AVERAGE \
--start 920804400 --end 920808000 >moreDS_updater_fetch.txt
rm moreDS-updater.rrd
moreDS.rrd:
$(rrd_binary) create moreDS.rrd --start 920804400 \
DS:speed1:COUNTER:600:U:U \
DS:speed2:COUNTER:600:U:U \
RRA:AVERAGE:0.5:1:24 \
RRA:AVERAGE:0.5:6:10
$(rrd_binary) update moreDS.rrd \
920804700:12345:11340 920805000:12357:11357 920805300:12363:11363 \
920805600:12363:11364 920805900:12363:11364 920806200:12373:11373 \
920806500:12383:11373 920806800:12393:11393 920807100:12399:11399 \
920807400:12405:11405 920807700:12411:11411 920808000:12415:11415 \
920808300:12420:11420 920808600:12422:11422 920808900:12423:11423
moreDS_fetch.txt: moreDS.rrd
$(rrd_binary) fetch moreDS.rrd AVERAGE \
--start 920804400 --end 920808000 >moreDS_fetch.txt
rrd-2.0.3/tests/rrd_001.phpt 0000644 0001750 0001750 00000000235 14040307736 015353 0 ustar kubelik kubelik --TEST--
rrd module presence test
--SKIPIF--
--FILE--
--EXPECTF--
rrd extension loaded
rrd-2.0.3/tests/rrd_002.phpt 0000644 0001750 0001750 00000001327 14040307736 015357 0 ustar kubelik kubelik --TEST--
RRDGraph test
--SKIPIF--
--FILE--
setOptions(array(
"--start" => "920804400",
"--end" => 920808000,
"--vertical-label" => "m/s",
"DEF:myspeed=$data_updatedDb:speed:AVERAGE",
"CDEF:realspeed=myspeed,1000,*",
"LINE2:realspeed#FF0000"
));
var_dump($graphObj->save());
var_dump(file_exists($outputPngFile));
?>
--EXPECTF--
array(3) {
["xsize"]=>
int(497)
["ysize"]=>
int(%d)
["calcpr"]=>
NULL
}
bool(true)
rrd-2.0.3/tests/rrd_003.phpt 0000644 0001750 0001750 00000000620 14040307736 015353 0 ustar kubelik kubelik --TEST--
RRDCreator test
--SKIPIF--
--FILE--
addDataSource("speed:COUNTER:600:U:U");
$creator->addArchive("AVERAGE:0.5:1:24");
$creator->addArchive("AVERAGE:0.5:6:10");
$creator->save();
var_dump(file_exists($rrdFile));
?>
--EXPECTF--
bool(true)
rrd-2.0.3/tests/rrd_004.phpt 0000644 0001750 0001750 00000004146 14040307736 015363 0 ustar kubelik kubelik --TEST--
RRDUpdater test
--SKIPIF--
--FILE--
update(array("speed" => "12345"), "920804700");
$updator->update(array("speed" => "12357"), "920805000");
$updator->update(array("speed" => "12363"), "920805300");
$updator->update(array("speed" => "12363"), "920805600");
$updator->update(array("speed" => "12363"), "920805900");
$updator->update(array("speed" => "12373"), "920806200");
$updator->update(array("speed" => "12383"), "920806500");
$updator->update(array("speed" => "12393"), "920806800");
$updator->update(array("speed" => "12399"), "920807100");
$updator->update(array("speed" => "12405"), "920807400");
$updator->update(array("speed" => "12411"), "920807700");
$updator->update(array("speed" => "12415"), "920808000");
$updator->update(array("speed" => "12420"), "920808300");
$updator->update(array("speed" => "12422"), "920808600");
$updator->update(array("speed" => "12423"), "920808900");
//graph just for "visual test" if test fails
$command = "$rrdtool_bin graph "
. dirname(__FILE__) . "/rrd_updater_test.png "
. "--start 920804400 --end 920808000 "
. "--vertical-label m/s "
. "DEF:myspeed=$rrdFile:speed:AVERAGE "
. "CDEF:realspeed=myspeed,1000,* "
. "LINE2:realspeed#FF0000";
echo "exporting rrd_updater_test.png via exec\n";
exec($command);
$command = "$rrdtool_bin fetch $rrdFile AVERAGE --start 920804400 --end 920809200";
exec($command, $output);
// maybe bug in exec output catching
if ($output[1] === "\n") {
$output[1] = "";
}
$originalFetch = file($data_updaterTxt, FILE_IGNORE_NEW_LINES);
echo "comparing original and current fetch\n";
var_dump(array_diff($output, $originalFetch));
?>
--EXPECTF--
exporting rrd_updater_test.png via exec
comparing original and current fetch
array(0) {
}
rrd-2.0.3/tests/rrd_005.phpt 0000644 0001750 0001750 00000002061 14040307736 015356 0 ustar kubelik kubelik --TEST--
RRDUpdater default timestamp test
--SKIPIF--
--FILE--
update(array("speed" => "12345"));
sleep(1);
$updator->update(array("speed" => "12357"));
sleep(1);
$updator->update(array("speed" => "12363"));
sleep(1);
$updator->update(array("speed" => "12363"));
sleep(1);
$updator->update(array("speed" => "12363"));
sleep(1);
//mostly for "visual test"
$command = "$rrdtool_bin graph "
. dirname(__FILE__) . "/rrd_updater_default_val.png "
. "--start -5s --end now "
. "--vertical-label m/s "
. "DEF:myspeed=$rrdFile:speed:AVERAGE "
. "CDEF:realspeed=myspeed,1000,* "
. "LINE2:realspeed#FF0000";
echo "exporting graph via exec\n";
exec($command);
?>
--EXPECTF--
exporting %s via exec
rrd-2.0.3/tests/rrd_006.phpt 0000644 0001750 0001750 00000002172 14040307736 015362 0 ustar kubelik kubelik --TEST--
rrd_update test
--SKIPIF--
--FILE--
--EXPECTF--
exporting rrd_update_1.png via exec
bool(true)
rrd-2.0.3/tests/rrd_007.phpt 0000644 0001750 0001750 00000000504 14040307736 015360 0 ustar kubelik kubelik --TEST--
rrd_create test
--SKIPIF--
--FILE--
--EXPECTF--
bool(true)
rrd-2.0.3/tests/rrd_008.phpt 0000644 0001750 0001750 00000001764 14040307736 015372 0 ustar kubelik kubelik --TEST--
rrd_graph test
--SKIPIF--
--FILE--
--EXPECTF--
exporting image via exec
array(3) {
["xsize"]=>
int(497)
["ysize"]=>
int(%d)
["calcpr"]=>
NULL
}
rrd-2.0.3/tests/rrd_009.phpt 0000644 0001750 0001750 00000000422 14040307736 015361 0 ustar kubelik kubelik --TEST--
rrd_error test
--SKIPIF--
--FILE--
--EXPECTF--
string(31) "can't parse argument 'badParam'"
bool(false) rrd-2.0.3/tests/rrd_010.phpt 0000644 0001750 0001750 00000003145 14040307736 015356 0 ustar kubelik kubelik --TEST--
rrd_fetch test
--SKIPIF--
--FILE--
--EXPECTF--
array(4) {
["start"]=>
int(920804400)
["end"]=>
int(920808300)
["step"]=>
int(300)
["data"]=>
array(2) {
["speed1"]=>
array(13) {
[920804700]=>
float(NAN)
[920805000]=>
float(0.04)
[920805300]=>
float(0.02)
[920805600]=>
float(0)
[920805900]=>
float(0)
[920806200]=>
float(0.03333333333%s)
[920806500]=>
float(0.03333333333%s)
[920806800]=>
float(0.03333333333%s)
[920807100]=>
float(0.02)
[920807400]=>
float(0.02)
[920807700]=>
float(0.02)
[920808000]=>
float(0.01333333333%s)
[920808300]=>
float(0.01666666666%s)
}
["speed2"]=>
array(13) {
[920804700]=>
float(NAN)
[920805000]=>
float(0.05666666666%s)
[920805300]=>
float(0.02)
[920805600]=>
float(0.00333333333%s)
[920805900]=>
float(0)
[920806200]=>
float(0.03)
[920806500]=>
float(0)
[920806800]=>
float(0.06666666666%s)
[920807100]=>
float(0.02)
[920807400]=>
float(0.02)
[920807700]=>
float(0.02)
[920808000]=>
float(0.01333333333%s)
[920808300]=>
float(0.01666666666%s)
}
}
}
rrd-2.0.3/tests/rrd_011.phpt 0000644 0001750 0001750 00000000714 14040307736 015356 0 ustar kubelik kubelik --TEST--
rrd_first test
--SKIPIF--
--FILE--
--EXPECTF--
int(920802000)
int(920791800)
bool(false)
bool(false)
rrd-2.0.3/tests/rrd_012.phpt 0000644 0001750 0001750 00000002631 14040307736 015357 0 ustar kubelik kubelik --TEST--
rrd_info test
--SKIPIF--
--FILE--
--EXPECTF--
array(27) {
["filename"]=>
string(%d) %s
["rrd_version"]=>
string(4) %s
["step"]=>
int(300)
["last_update"]=>
int(920808900)
["header_size"]=>
int(%d)
["ds[speed].index"]=>
int(0)
["ds[speed].type"]=>
string(7) "COUNTER"
["ds[speed].minimal_heartbeat"]=>
int(600)
["ds[speed].min"]=>
float(NAN)
["ds[speed].max"]=>
float(NAN)
["ds[speed].last_ds"]=>
string(5) "12423"
["ds[speed].value"]=>
float(0)
["ds[speed].unknown_sec"]=>
int(0)
["rra[0].cf"]=>
string(7) "AVERAGE"
["rra[0].rows"]=>
int(24)
["rra[0].cur_row"]=>
int(%d)
["rra[0].pdp_per_row"]=>
int(1)
["rra[0].xff"]=>
float(0.5)
["rra[0].cdp_prep[0].value"]=>
float(NAN)
["rra[0].cdp_prep[0].unknown_datapoints"]=>
int(0)
["rra[1].cf"]=>
string(7) "AVERAGE"
["rra[1].rows"]=>
int(10)
["rra[1].cur_row"]=>
int(%d)
["rra[1].pdp_per_row"]=>
int(6)
["rra[1].xff"]=>
float(0.5)
["rra[1].cdp_prep[0].value"]=>
float(0.02666666666%s)
["rra[1].cdp_prep[0].unknown_datapoints"]=>
int(0)
}
bool(true)
rrd-2.0.3/tests/rrd_013.phpt 0000644 0001750 0001750 00000000446 14040307736 015362 0 ustar kubelik kubelik --TEST--
rrd_last test
--SKIPIF--
--FILE--
--EXPECTF--
int(920808900) rrd-2.0.3/tests/rrd_014.phpt 0000644 0001750 0001750 00000001515 14040307736 015361 0 ustar kubelik kubelik --TEST--
rrd_lastupdate test
--SKIPIF--
--FILE--
--EXPECTF--
array(4) {
["last_update"]=>
int(920808900)
["ds_cnt"]=>
int(1)
["ds_navm"]=>
array(1) {
[0]=>
string(5) "speed"
}
["data"]=>
array(1) {
[0]=>
string(5) "12423"
}
}
array(4) {
["last_update"]=>
int(920808900)
["ds_cnt"]=>
int(2)
["ds_navm"]=>
array(2) {
[0]=>
string(6) "speed1"
[1]=>
string(6) "speed2"
}
["data"]=>
array(2) {
[0]=>
string(5) "12423"
[1]=>
string(5) "11423"
}
} rrd-2.0.3/tests/rrd_015.phpt 0000644 0001750 0001750 00000001200 14040307736 015351 0 ustar kubelik kubelik --TEST--
rrd_restore test
--SKIPIF--
--FILE--
--EXPECTF--
bool(true)
bool(true)
bool(true)
rrd-2.0.3/tests/rrd_016.phpt 0000644 0001750 0001750 00000001060 14040307736 015356 0 ustar kubelik kubelik --TEST--
rrd_tune test
--SKIPIF--
--FILE--
--EXPECTF--
bool(true)
bool(false)
bool(true)
%s rrd-2.0.3/tests/rrd_017.phpt 0000644 0001750 0001750 00000003703 14040307736 015365 0 ustar kubelik kubelik --TEST--
rrd_xport test
--SKIPIF--
--FILE--
--EXPECTF--
array(4) {
["start"]=>
int(920804700)
["end"]=>
int(920808300)
["step"]=>
int(300)
["data"]=>
array(2) {
[0]=>
array(2) {
["legend"]=>
string(7) "myspeed"
["data"]=>
array(13) {
[920804700]=>
float(NAN)
[920805000]=>
float(0.04)
[920805300]=>
float(0.02)
[920805600]=>
float(0)
[920805900]=>
float(0)
[920806200]=>
float(0.0333333333%s)
[920806500]=>
float(0.0333333333%s)
[920806800]=>
float(0.0333333333%s)
[920807100]=>
float(0.02)
[920807400]=>
float(0.02)
[920807700]=>
float(0.02)
[920808000]=>
float(0.0133333333%s)
[920808300]=>
float(0.0166666666%s)
}
}
[1]=>
array(2) {
["legend"]=>
string(9) "realspeed"
["data"]=>
array(13) {
[920804700]=>
float(NAN)
[920805000]=>
float(40)
[920805300]=>
float(20)
[920805600]=>
float(0)
[920805900]=>
float(0)
[920806200]=>
float(33.333333333%s)
[920806500]=>
float(33.333333333%s)
[920806800]=>
float(33.333333333%s)
[920807100]=>
float(20)
[920807400]=>
float(20)
[920807700]=>
float(20)
[920808000]=>
float(13.333333333%s)
[920808300]=>
float(16.666666666%s)
}
}
}
}
rrd-2.0.3/tests/rrd_018.phpt 0000644 0001750 0001750 00000001706 14040307736 015367 0 ustar kubelik kubelik --TEST--
RRDGraph saveVerbose test
--SKIPIF--
--FILE--
setOptions(array(
"--start" => "920804400",
"--end" => 920808000,
"--vertical-label" => "m/s",
"DEF:myspeed=$rrdFile:speed:AVERAGE",
"CDEF:realspeed=myspeed,1000,*",
"LINE2:realspeed#FF0000"
));
var_dump($graphObj->saveVerbose());
?>
--EXPECTF--
array(10) {
["graph_left"]=>
int(67)
["graph_top"]=>
int(%d)
["graph_width"]=>
int(400)
["graph_height"]=>
int(100)
["image_width"]=>
int(497)
["image_height"]=>
int(%d)
["graph_start"]=>
int(920804400)
["graph_end"]=>
int(920808000)
["value_min"]=>
float(0)
["value_max"]=>
float(40)
}
rrd-2.0.3/tests/rrd_019.phpt 0000644 0001750 0001750 00000002165 14040307736 015370 0 ustar kubelik kubelik --TEST--
RRDGraph saveVerbose full export test
--SKIPIF--
--FILE--
setOptions(array(
"--start" => "920804400",
"--end" => 920808000,
"--vertical-label" => "m/s",
"DEF:myspeed=$rrdFile:speed:AVERAGE",
"CDEF:realspeed=myspeed,1000,*",
"LINE2:realspeed#FF0000"
));
$output = $graphObj->saveVerbose();
$imgData = $output["image"]; unset($output["image"]);
//output without img data
var_dump($output);
//detection of correct PNG header
var_dump(substr($imgData, 0, 8) == "\x89PNG\x0d\x0a\x1a\x0a");
?>
--EXPECTF--
array(10) {
["graph_left"]=>
int(67)
["graph_top"]=>
int(%d)
["graph_width"]=>
int(400)
["graph_height"]=>
int(100)
["image_width"]=>
int(497)
["image_height"]=>
int(%d)
["graph_start"]=>
int(920804400)
["graph_end"]=>
int(920808000)
["value_min"]=>
float(0)
["value_max"]=>
float(40)
}
bool(true)
rrd-2.0.3/tests/rrd_020.phpt 0000644 0001750 0001750 00000000377 14040307736 015363 0 ustar kubelik kubelik --TEST--
rrd_version test
--SKIPIF--
--FILE--
= 2);
?>
--EXPECTF--
string(%i) "%s"
bool(true)
bool(true)
rrd-2.0.3/tests/rrd_021.phpt 0000644 0001750 0001750 00000002227 14040307736 015360 0 ustar kubelik kubelik --TEST--
RRDUpdater more data source test
--SKIPIF--
--FILE--
update(array("speed1" => 12345, "speed2" => 11340), 920804700);
$updator->update(array("speed1" => 12357, "speed2" => 11357), 920805000);
$updator->update(array("speed1" => 12363, "speed2" => 11363), 920805300);
//mostly for "visual test"
$command = "$rrdtool_bin fetch $rrdFile AVERAGE "
. "--start 920804400 --end 920808000 "
. ">" . dirname(__FILE__) . "/rrd_updater_moreDS_fetch.txt";
$output = array();
exec($command, $output);
$originalFetch = file($data_moreDSUpdaterTxt, FILE_IGNORE_NEW_LINES);
echo "comparing original and current fetch\n";
var_dump(array_diff($output, $originalFetch));
?>
--EXPECTF--
comparing original and current fetch
array(0) {
}
rrd-2.0.3/tests/rrd_022.phpt 0000644 0001750 0001750 00000000354 14040307736 015360 0 ustar kubelik kubelik --TEST--
rrdc_disconnect test
--SKIPIF--
= 1.4");
}
?>
--FILE--
--EXPECTF--
NULL
rrd-2.0.3/tests/rrdtool-bin.inc.in 0000644 0001750 0001750 00000000162 14040307736 016641 0 ustar kubelik kubelik
rrd-2.0.3/tests/skipif.inc 0000644 0001750 0001750 00000000124 14040307736 015264 0 ustar kubelik kubelik
rrd-2.0.3/rrd_info.c 0000644 0001750 0001750 00000004264 14040307736 014121 0 ustar kubelik kubelik /**
* PHP bindings to the rrdtool
*
* This source file is subject to the BSD license that is bundled
* with this package in the file LICENSE.
* ---------------------------------------------------------------
* Author: Miroslav Kubelik
* ---------------------------------------------------------------
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include
#include "php_rrd.h"
#include "rrd_info.h"
/* {{{ proto array rrd_info(string file)
Gets the header information from an RRD.
*/
PHP_FUNCTION(rrd_info)
{
char *filename;
size_t filename_length;
/* list of arguments for rrd_info call, it's more efficient then u
* usage of rrd_args, because there isn't array of arguments in parameters
*/
char *argv[3];
/* return value from rrd_info_r() */
rrd_info_t *rrd_info_data;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename,
&filename_length) == FAILURE) {
return;
}
if (php_check_open_basedir(filename)) RETURN_FALSE;
argv[0] = "dummy";
argv[1] = estrdup("info");
argv[2] = estrndup(filename, filename_length);
rrd_info_data = rrd_info(2, &argv[1]);
efree(argv[2]); efree(argv[1]);
if (!rrd_info_data) RETURN_FALSE;
/* making return array*/
array_init(return_value);
rrd_info_toarray(rrd_info_data, return_value);
rrd_info_free(rrd_info_data);
}
/* }}} */
/* {{{ converts rrd_info_t struct into php array
@return int 1 OK, 0 conversion failed
*/
unsigned rrd_info_toarray(const rrd_info_t *rrd_info_data, zval *array)
{
const rrd_info_t *data_p;
if (!rrd_info_data || Z_TYPE_P(array) != IS_ARRAY) return 0;
data_p = rrd_info_data;
while (data_p) {
switch (data_p->type) {
case RD_I_VAL:
add_assoc_double(array, data_p->key, data_p->value.u_val);
break;
case RD_I_CNT:
add_assoc_long(array, data_p->key, data_p->value.u_cnt);
break;
case RD_I_INT:
add_assoc_long(array, data_p->key, data_p->value.u_int);
break;
case RD_I_STR:
add_assoc_string(array, data_p->key, data_p->value.u_str);
break;
case RD_I_BLO:
add_assoc_stringl(array, data_p->key, (char *)data_p->value.u_blo.ptr,
data_p->value.u_blo.size);
break;
}
data_p = data_p->next;
}
return 1;
}
/* }}} */
rrd-2.0.3/rrd_info.h 0000644 0001750 0001750 00000001136 14040307736 014121 0 ustar kubelik kubelik /**
* PHP bindings to the rrdtool
*
* This source file is subject to the BSD license that is bundled
* with this package in the file LICENSE.
* ---------------------------------------------------------------
* Author: Miroslav Kubelik
* ---------------------------------------------------------------
*/
#ifndef RRD_INFO_H
#define RRD_INFO_H
extern PHP_FUNCTION(rrd_info);
/* necessary, because rrd_info_t definition is needed for function definition */
#include
extern unsigned rrd_info_toarray(const rrd_info_t *rrd_info_data, zval *array);
#endif /* RRD_INFO_H */
rrd-2.0.3/rrd_graph.c 0000644 0001750 0001750 00000023767 14040307736 014300 0 ustar kubelik kubelik /**
* PHP bindings to the rrdtool
*
* This source file is subject to the BSD license that is bundled
* with this package in the file LICENSE.
* ---------------------------------------------------------------
* Author: Miroslav Kubelik
* ---------------------------------------------------------------
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "zend_exceptions.h"
#include "ext/standard/php_smart_string.h"
#include
#include "php_rrd.h"
#include "rrd_info.h"
#include "rrd_graph.h"
/* declare class entry */
static zend_class_entry *ce_rrd_graph;
/* declare class handlers */
static zend_object_handlers rrd_graph_handlers;
/**
* overloading the standard zend object structure (std property) in the need
* of having dedicated creating/cloning/destruction functions
*/
typedef struct _rrd_graph_object {
char *file_path;
zval zv_arr_options;
zend_object std;
} rrd_graph_object;
/**
* fetch our custom object from user space object
*/
static inline rrd_graph_object *php_rrd_graph_fetch_object(zend_object *obj) {
return (rrd_graph_object *)((char*)(obj) - XtOffsetOf(rrd_graph_object, std));
}
/* {{{ rrd_graph_object_dtor
close all resources and the memory allocated for our internal object
*/
static void rrd_graph_object_dtor(zend_object *object)
{
rrd_graph_object *intern_obj = php_rrd_graph_fetch_object(object);
if (!intern_obj) return;
if (intern_obj->file_path){
efree(intern_obj->file_path);
}
if (!Z_ISUNDEF(intern_obj->zv_arr_options)) {
zval_dtor(&intern_obj->zv_arr_options);
}
zend_object_std_dtor(&intern_obj->std);
}
/* }}} */
/* {{{ rrd_graph_object_new
creates new rrd graph object
*/
static zend_object *rrd_graph_object_new(zend_class_entry *ce)
{
rrd_graph_object *intern_obj = ecalloc(1, sizeof(rrd_graph_object) +
zend_object_properties_size(ce));
intern_obj->file_path = NULL;
ZVAL_UNDEF(&intern_obj->zv_arr_options);
zend_object_std_init(&intern_obj->std, ce);
object_properties_init(&intern_obj->std, ce);
intern_obj->std.handlers = &rrd_graph_handlers;
return &intern_obj->std;
}
/* }}} */
/* {{{ proto void RRDGraph::__construct(string path)
creates new object for rrd graph function
*/
PHP_METHOD(RRDGraph, __construct)
{
rrd_graph_object *intern_obj;
char *path;
size_t path_length;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &path, &path_length) == FAILURE) {
return;
}
intern_obj = php_rrd_graph_fetch_object(Z_OBJ_P(getThis()));
intern_obj->file_path = estrdup(path);
}
/* }}} */
/* {{{ proto void RRDGraph::setOptions(array options)
set command options for rrd graph call
*/
PHP_METHOD(RRDGraph, setOptions)
{
rrd_graph_object *intern_obj;
zval *zv_arr_options;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zv_arr_options) == FAILURE) {
return;
}
intern_obj = php_rrd_graph_fetch_object(Z_OBJ_P(getThis()));
/* if our array is initialized, so delete it first */
if (!Z_ISUNDEF(intern_obj->zv_arr_options)) {
zval_dtor(&intern_obj->zv_arr_options);
}
/* copy array from parameter */
ZVAL_DUP(&intern_obj->zv_arr_options, zv_arr_options);
}
/* }}} */
/* {{{
creates arguments for rrd_graph call for RRDGraph instance options
*/
static rrd_args *rrd_graph_obj_create_argv(const char *command_name, const rrd_graph_object *obj)
{
/* iterated item and keys*/
zval *zv_option_val;
zend_ulong num_key;
zend_string *zs_key;
/* arguments for rrd_graph call as php array - temporary storage */
zval zv_argv;
rrd_args *result;
array_init(&zv_argv);
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(obj->zv_arr_options), num_key, zs_key, zv_option_val) {
(void)num_key; /* to avoid -Wunused-but-set-variable */
smart_string option = {0}; /* one argument option */
/* option with string key means long option, hence they are used as
* "key=value" e.g. "--start=920804400"
*/
if (zs_key) {
smart_string_appends(&option, ZSTR_VAL(zs_key));
smart_string_appendc(&option, '=');
}
/* use always string for option value */
if (Z_TYPE_P(zv_option_val) != IS_STRING) {
convert_to_string(zv_option_val);
}
smart_string_appendl(&option, Z_STRVAL_P(zv_option_val), Z_STRLEN_P(zv_option_val));
smart_string_0(&option);
add_next_index_string(&zv_argv, option.c);
smart_string_free(&option);
} ZEND_HASH_FOREACH_END();
result = rrd_args_init_by_phparray(command_name, obj->file_path, &zv_argv);
zval_dtor(&zv_argv);
return result;
}
/* }}} */
/* {{{ proto array RRDGraph::save()
Saves graph according to current option
*/
PHP_METHOD(RRDGraph, save)
{
rrd_graph_object *intern_obj = php_rrd_graph_fetch_object(Z_OBJ_P(getThis()));
/* returned values if rrd_graph doesn't fail */
int xsize, ysize;
double ymin,ymax;
char **calcpr;
/* arguments for rrd_graph call */
rrd_args *graph_argv;
if (Z_TYPE(intern_obj->zv_arr_options) != IS_ARRAY) {
zend_throw_exception(NULL, "options aren't correctly set", 0);
return;
}
if (php_check_open_basedir(intern_obj->file_path)) {
RETURN_FALSE;
}
graph_argv = rrd_graph_obj_create_argv("graph", intern_obj);
if (!graph_argv) {
zend_error(E_WARNING, "cannot allocate arguments options");
RETURN_FALSE;
}
if (rrd_test_error()) rrd_clear_error();
/* call rrd graph and test if fails */
if (rrd_graph(graph_argv->count - 1, &graph_argv->args[1], &calcpr, &xsize,
&ysize, NULL, &ymin, &ymax) == -1) {
/* throw exception with rrd error string */
zend_throw_exception(NULL, rrd_get_error(), 0);
rrd_clear_error();
rrd_args_free(graph_argv);
return;
}
/* making return array */
array_init(return_value);
add_assoc_long(return_value, "xsize", xsize);
add_assoc_long(return_value, "ysize", ysize);
/* add calcpr return values under "calcpr" key
*
* if calcpr isn't presented add PHP NULL value
*/
if (!calcpr) {
add_assoc_null(return_value, "calcpr");
} else {
/* calcpr is presented, hence create array for it, and add it to return array */
zval zv_calcpr_array;
array_init(&zv_calcpr_array);
if (calcpr) {
unsigned i;
for (i = 0; calcpr[i]; i++) {
add_next_index_string(&zv_calcpr_array, calcpr[i]);
free(calcpr[i]);
}
free(calcpr);
}
add_assoc_zval(return_value, "calcpr", &zv_calcpr_array);
}
rrd_args_free(graph_argv);
}
/* }}} */
/* {{{ proto array RRDGraph::saveVerbose()
Saves graph according to current option with return an extra information about
saved image.
*/
PHP_METHOD(RRDGraph, saveVerbose)
{
rrd_graph_object *intern_obj = php_rrd_graph_fetch_object(Z_OBJ_P(getThis()));
/* return value from rrd_graphv */
rrd_info_t *rrd_info_data;
/* arguments for rrd_graph call */
rrd_args *graph_argv;
if (Z_TYPE(intern_obj->zv_arr_options) != IS_ARRAY) {
zend_throw_exception(NULL, "options aren't correctly set", 0);
return;
}
graph_argv = rrd_graph_obj_create_argv("graphv", intern_obj);
if (!graph_argv) {
zend_error(E_WARNING, "cannot allocate arguments options");
RETURN_FALSE;
}
if (rrd_test_error()) rrd_clear_error();
/* call rrd graphv and test if fails */
rrd_info_data = rrd_graph_v(graph_argv->count - 1, &graph_argv->args[1]);
if (!rrd_info_data) {
/* throw exception with rrd error string */
zend_throw_exception(NULL, rrd_get_error(), 0);
rrd_clear_error();
rrd_args_free(graph_argv);
return;
}
/* making return array */
array_init(return_value);
rrd_info_toarray(rrd_info_data, return_value);
rrd_info_free(rrd_info_data);
rrd_args_free(graph_argv);
}
/* }}} */
/* {{{ proto array rrd_graph(string file, array options)
Ceates a graph based on options passed via an array.
*/
PHP_FUNCTION(rrd_graph)
{
char *filename;
size_t filename_length;
zval *zv_arr_options;
rrd_args *argv;
/* returned values if rrd_graph doesn't fail */
int xsize, ysize;
double ymin,ymax;
char **calcpr;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "pa", &filename,
&filename_length, &zv_arr_options) == FAILURE) {
return;
}
if (php_check_open_basedir(filename)) RETURN_FALSE;
argv = rrd_args_init_by_phparray("graph", filename, zv_arr_options);
if (!argv) {
zend_error(E_WARNING, "cannot allocate arguments options");
RETURN_FALSE;
}
if (rrd_test_error()) rrd_clear_error();
/* call rrd graph and test if fails */
if (rrd_graph(argv->count - 1, &argv->args[1], &calcpr, &xsize, &ysize,
NULL, &ymin, &ymax) == -1) {
rrd_args_free(argv);
RETURN_FALSE;
}
/* making return array*/
array_init(return_value);
add_assoc_long(return_value, "xsize", xsize);
add_assoc_long(return_value, "ysize", ysize);
/* add calcpr return values under "calcpr" key
*
* if calcpr isn't presented add PHP NULL value
*/
if (!calcpr) {
add_assoc_null(return_value, "calcpr");
} else {
/* calcpr is presented, hence create array for it, and add it to return array */
zval zv_calcpr_array;
array_init(&zv_calcpr_array);
if (calcpr) {
unsigned i;
for (i = 0; calcpr[i]; i++) {
add_next_index_string(&zv_calcpr_array, calcpr[i]);
free(calcpr[i]);
}
free(calcpr);
}
add_assoc_zval(return_value, "calcpr", &zv_calcpr_array);
}
rrd_args_free(argv);
}
/* }}} */
/* arguments */
ZEND_BEGIN_ARG_INFO_EX(arginfo_rrd_void, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_rrd_path, 0, 0, 1)
ZEND_ARG_INFO(0, path)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_rrd_options, 0, 0, 1)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
/* class method table */
static zend_function_entry rrd_graph_methods[] = {
PHP_ME(RRDGraph, __construct, arginfo_rrd_path, ZEND_ACC_PUBLIC)
PHP_ME(RRDGraph, save, arginfo_rrd_void, ZEND_ACC_PUBLIC)
PHP_ME(RRDGraph, saveVerbose, arginfo_rrd_void, ZEND_ACC_PUBLIC)
PHP_ME(RRDGraph, setOptions, arginfo_rrd_options, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* minit hook, called from main module minit */
void rrd_graph_minit()
{
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "RRDGraph", rrd_graph_methods);
ce.create_object = rrd_graph_object_new;
ce_rrd_graph = zend_register_internal_class(&ce);
memcpy(&rrd_graph_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
rrd_graph_handlers.clone_obj = NULL;
rrd_graph_handlers.offset = XtOffsetOf(rrd_graph_object, std);
rrd_graph_handlers.free_obj = rrd_graph_object_dtor;
}
rrd-2.0.3/rrd_graph.h 0000644 0001750 0001750 00000000716 14040307736 014272 0 ustar kubelik kubelik /**
* PHP bindings to the rrdtool
*
* This source file is subject to the BSD license that is bundled
* with this package in the file LICENSE.
* ---------------------------------------------------------------
* Author: Miroslav Kubelik
* ---------------------------------------------------------------
*/
#ifndef RRD_GRAPH_H
#define RRD_GRAPH_H
extern void rrd_graph_minit();
extern PHP_FUNCTION(rrd_graph);
#endif /* RRD_GRAPH_H */
rrd-2.0.3/rrd.c 0000644 0001750 0001750 00000042142 14040307736 013103 0 ustar kubelik kubelik /**
* PHP bindings to the rrdtool
*
* This source file is subject to the BSD license that is bundled
* with this package in the file LICENSE.
* ---------------------------------------------------------------
* Author: Miroslav Kubelik
* ---------------------------------------------------------------
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "ext/standard/php_smart_string.h"
#include "ext/standard/php_array.h"
#include "ext/standard/info.h"
#include
#ifdef HAVE_RRDC_DISCONNECT
#include
#endif
#include "php_rrd.h"
#include "rrd_graph.h"
#include "rrd_create.h"
#include "rrd_update.h"
#include "rrd_info.h"
/* {{{ proto string rrd_error()
Get the error message set by the last rrd tool function call, this function
clear error buffer also.
*/
PHP_FUNCTION(rrd_error)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (!rrd_test_error()) RETURN_FALSE;
RETVAL_STRING(rrd_get_error());
rrd_clear_error();
}
/* }}} */
/* {{{ proto array rrd_fetch(string file, array options)
Fetch data from RRD in requested resolution.
*/
PHP_FUNCTION(rrd_fetch)
{
char *filename;
size_t filename_length;
zval *zv_arr_options;
rrd_args *argv;
/* returned values if rrd_fetch doesn't fail */
time_t start, end;
zend_ulong step,
ds_cnt; /* count of data sources */
char **ds_namv; /* list of data source names */
rrd_value_t *ds_data; /* all data from all sources */
if (zend_parse_parameters(ZEND_NUM_ARGS(), "pa", &filename,
&filename_length, &zv_arr_options) == FAILURE) {
return;
}
if (php_check_open_basedir(filename)) RETURN_FALSE;
argv = rrd_args_init_by_phparray("fetch", filename, zv_arr_options);
if (!argv) {
zend_error(E_WARNING, "cannot allocate arguments options");
RETURN_FALSE;
}
if (rrd_test_error()) rrd_clear_error();
/* call rrd_fetch and test if fails */
if (rrd_fetch(argv->count - 1, &argv->args[1], &start, &end, &step, &ds_cnt,
&ds_namv, &ds_data) == -1 ) {
rrd_args_free(argv);
RETURN_FALSE;
}
/* making return array */
array_init(return_value);
add_assoc_long(return_value, "start", start);
add_assoc_long(return_value, "end", end);
add_assoc_long(return_value, "step", step);
/* add "ds_namv" and "data" array into return values if there is any
* result data
*/
if (!ds_data || !ds_namv || !ds_cnt) {
add_assoc_null(return_value, "data");
} else {
rrd_value_t *datap = ds_data;
unsigned timestamp, ds_counter;
/* final array for all data from all data sources */
zval zv_data_array;
array_init(&zv_data_array);
/* add arrays for each data source, each array will be filled with
* retrieved data for a particular data source
*/
for (ds_counter = 0; ds_counter < ds_cnt; ds_counter++) {
zval zv_ds_data_array;
array_init(&zv_ds_data_array);
add_assoc_zval(&zv_data_array, ds_namv[ds_counter], &zv_ds_data_array);
}
for (timestamp = start + step; timestamp <= end; timestamp += step) {
/* try to find current data source result array in the
* zv_data_array
*/
zend_hash_internal_pointer_reset(Z_ARRVAL(zv_data_array));
for (ds_counter = 0; ds_counter < ds_cnt; ds_counter++) {
/* pointer for one data source retrieved data */
zval *ds_data_array;
/* value for key (timestamp) in data array */
char str_timestamp[11];
ZEND_LTOA((zend_ulong)timestamp, str_timestamp, sizeof(str_timestamp));
/* gets pointer for data source result array */
ds_data_array = zend_hash_get_current_data(Z_ARRVAL(zv_data_array));
add_assoc_double(ds_data_array, str_timestamp, *(datap++));
zend_hash_move_forward(Z_ARRVAL(zv_data_array));
}
}
add_assoc_zval(return_value, "data", &zv_data_array);
/* free data from rrd_fetch */
free(ds_data);
for (ds_counter = 0; ds_counter < ds_cnt; ds_counter++) {
free(ds_namv[ds_counter]);
}
free(ds_namv);
}
rrd_args_free(argv);
}
/* }}} */
/* {{{ proto int rrd_first(string file [, int rraindex = 0])
Gets first update time of an RRD file
*/
PHP_FUNCTION(rrd_first)
{
char *filename;
size_t filename_length;
long rraindex = 0;
/* return value from rrd_first_r call */
time_t rrd_first_return_val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|l", &filename,
&filename_length, &rraindex) == FAILURE) {
return;
}
if (rraindex < 0) {
rrd_set_error("invalid rraindex number, rraindex must be >= 0");
RETURN_FALSE;
}
if (php_check_open_basedir(filename)) {
RETURN_FALSE;
}
if (rrd_test_error()) rrd_clear_error();
/* call rrd_first and test if fails */
rrd_first_return_val = rrd_first_r(filename, rraindex);
if (rrd_first_return_val == -1) {
RETURN_FALSE;
}
RETURN_LONG(rrd_first_return_val);
}
/* }}} */
/* {{{ proto int rrd_last(string file)
Gets last update time of an RRD file
*/
PHP_FUNCTION(rrd_last)
{
char *filename;
size_t filename_length;
/* return value from rrd_first_r call */
time_t rrd_last_return_val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename,
&filename_length) == FAILURE) {
return;
}
if (php_check_open_basedir(filename)) {
RETURN_FALSE;
}
if (rrd_test_error()) rrd_clear_error();
/* call rrd_last and test if fails */
rrd_last_return_val = rrd_last_r(filename);
if (rrd_last_return_val == -1) {
RETURN_FALSE;
}
RETURN_LONG(rrd_last_return_val);
}
/* }}} */
/* {{{ proto int rrd_lastupdate(string file)
Gets last update details of an RRD file */
PHP_FUNCTION(rrd_lastupdate)
{
char *filename;
size_t filename_length;
/* list of arguments for rrd_lastupdate call, it's more efficient then
* usage of rrd_args, because there isn't array of arguments in parameters
*/
char *argv[3];
/* return values from rrd_lastupdate_r function */
time_t last_update;
unsigned long ds_cnt;
char **ds_namv;
char **last_ds;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename,
&filename_length) == FAILURE) {
return;
}
if (php_check_open_basedir(filename)) {
RETURN_FALSE;
}
argv[0] = "dummy";
argv[1] = estrdup("lastupdate");
argv[2] = estrndup(filename, filename_length);
if (rrd_test_error()) rrd_clear_error();
#ifdef HAVE_RRD_LASTUPDATE_R
if (rrd_lastupdate_r(argv[2], &last_update, &ds_cnt, &ds_namv,
&last_ds) == -1) {
#else
if (rrd_lastupdate(2, &argv[1], &last_update, &ds_cnt, &ds_namv,
&last_ds) == -1) {
#endif
efree(argv[2]); efree(argv[1]);
RETURN_FALSE;
}
efree(argv[2]); efree(argv[1]);
/* making return array*/
array_init(return_value);
add_assoc_long(return_value, "last_update", last_update);
add_assoc_long(return_value, "ds_cnt", ds_cnt);
/* "ds_navm" return array or null, if no available */
if (!ds_namv || !ds_cnt) {
add_assoc_null(return_value, "ds_namv");
} else {
unsigned i;
zval zv_ds_namv_array;
array_init(&zv_ds_namv_array);
for (i = 0; i < ds_cnt; i++) {
add_next_index_string(&zv_ds_namv_array, ds_namv[i]);
free(ds_namv[i]);
}
free(ds_namv);
add_assoc_zval(return_value, "ds_navm", &zv_ds_namv_array);
}
/* "data" return array or null, if no available */
if (!last_ds || !ds_cnt) {
add_assoc_null(return_value, "data");
} else {
unsigned i;
zval zv_data_array;
array_init(&zv_data_array);
/* simple array for "data" is enough, data source names and timestamps are
* available under other return value keys
*/
for (i = 0; i < ds_cnt; i++) {
add_next_index_string(&zv_data_array, last_ds[i]);
free(last_ds[i]);
}
free(last_ds);
add_assoc_zval(return_value, "data", &zv_data_array);
}
}
/* {{{ proto array rrd_restore(string xmlFile, string rrdFile [, array options])
Restores an RRD file from a XML dump */
PHP_FUNCTION(rrd_restore)
{
char *xml_filename, *rrd_filename;
size_t xml_filename_length, rrd_filename_length;
zval *zv_arr_options = NULL;
/* this is merge of options and rrd_filename. This is needed because
* rrd_args_init_by_phparray allows only one filename as argument, so
* rrd_filename mugst be part of array of arguments
*/
zval zv_options;
rrd_args *argv;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "pp|a", &xml_filename,
&xml_filename_length, &rrd_filename, &rrd_filename_length,
&zv_arr_options) == FAILURE) {
return;
}
if (php_check_open_basedir(xml_filename) ||
php_check_open_basedir(rrd_filename)) {
RETURN_FALSE;
}
/* zv_options = merge rrd_filename and zv_arr_options content */
array_init(&zv_options);
add_next_index_string(&zv_options, rrd_filename);
if (zv_arr_options && Z_TYPE_P(zv_arr_options) == IS_ARRAY) {
php_array_merge(Z_ARRVAL(zv_options), Z_ARRVAL_P(zv_arr_options));
}
argv = rrd_args_init_by_phparray("restore", xml_filename, &zv_options);
if (!argv) {
zend_error(E_WARNING, "cannot allocate arguments options");
zval_dtor(&zv_options);
RETURN_FALSE;
}
if (rrd_test_error()) rrd_clear_error();
/* call rrd_ restore and test if fails */
if (rrd_restore(argv->count-1, &argv->args[1]) == -1) {
RETVAL_FALSE;
} else {
RETVAL_TRUE;
}
zval_dtor(&zv_options);
rrd_args_free(argv);
}
/* }}} */
/* {{{ proto bool rrd_tune(string file, array options)
Tune an RRD file with the options passed (passed via array) */
PHP_FUNCTION(rrd_tune)
{
char *filename;
size_t filename_length;
zval *zv_arr_options;
rrd_args *argv;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "pa", &filename,
&filename_length, &zv_arr_options) == FAILURE) {
return;
}
if (!zend_hash_num_elements(Z_ARRVAL_P(zv_arr_options))) {
zend_error(E_WARNING, "options array mustn't be empty");
RETURN_FALSE;
}
if (php_check_open_basedir(filename)) RETURN_FALSE;
argv = rrd_args_init_by_phparray("tune", filename, zv_arr_options);
if (!argv) {
zend_error(E_WARNING, "cannot allocate arguments options");
RETURN_FALSE;
}
if (rrd_test_error()) rrd_clear_error();
/* call rrd_tune and test if fails */
if (rrd_tune(argv->count-1, &argv->args[1]) == -1 ) {
RETVAL_FALSE;
} else {
RETVAL_TRUE;
}
rrd_args_free(argv);
}
/* }}} */
/* {{{ proto array rrd_xport(array options)
* Creates a graph based on options passed via an array
*/
PHP_FUNCTION(rrd_xport)
{
zval *zv_arr_options;
rrd_args *argv;
/* return values from rrd_xport */
int xxsize;
time_t start, end, time_index;
zend_ulong step, outvar_count;
char **legend_v;
rrd_value_t *data, *data_ptr;
zval zv_data;
zend_ulong outvar_index;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zv_arr_options) == FAILURE) {
return;
}
argv = rrd_args_init_by_phparray("xport", "", zv_arr_options);
if (!argv) {
zend_error(E_WARNING, "cannot allocate arguments options");
RETURN_FALSE;
}
if (rrd_test_error()) rrd_clear_error();
/* call rrd_xport and test if fails */
if (rrd_xport(argv->count-1, &argv->args[1], &xxsize, &start, &end, &step,
&outvar_count, &legend_v, &data) == -1) {
php_printf("rrd_xport failed");
rrd_args_free(argv);
RETURN_FALSE;
}
rrd_args_free(argv);
/* fill rrd_xport return values into array */
array_init(return_value);
add_assoc_long(return_value, "start", start + step);
add_assoc_long(return_value, "end", end);
add_assoc_long(return_value, "step", step);
/* no data available */
if (!data) {
add_assoc_null(return_value, "data");
return;
}
array_init(&zv_data);
for (outvar_index = 0; outvar_index < outvar_count; outvar_index++) {
/* array for a whole one output variable data, it contains indexes
* array(
* "legend" => "variable legend",
* "data" => array(
* 920807400 => 0.14,
* 920807800 => 21,
* ...
* ))
*/
zval zv_var_data, time_data;
array_init(&zv_var_data);
array_init(&time_data);
add_assoc_string(&zv_var_data, "legend", legend_v[outvar_index]);
free(legend_v[outvar_index]);
data_ptr = data + outvar_index;
for (time_index = start + step; time_index <= end; time_index += step) {
/* value for key (timestamp) in data array */
char str_timestamp[11];
ZEND_LTOA((zend_ulong)time_index, str_timestamp, sizeof(str_timestamp));
add_assoc_double(&time_data, str_timestamp, *data_ptr);
data_ptr += outvar_count;
}
add_assoc_zval(&zv_var_data, "data", &time_data);
add_next_index_zval(&zv_data, &zv_var_data);
}
add_assoc_zval(return_value, "data", &zv_data);
free(legend_v);
free(data);
}
/* }}} */
#ifdef HAVE_RRDC_DISCONNECT
/* {{{ proto void rrdc_disconnect()
* Close any outstanding connection to rrd cache daemon.
*/
PHP_FUNCTION(rrdc_disconnect)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}
rrdc_disconnect();
}
#endif
/* {{{ proto string rrd_version()
* Gets version of underlying librrd.
*/
PHP_FUNCTION(rrd_version)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETVAL_STRING(rrd_strversion());
}
/* {{{ arguments */
ZEND_BEGIN_ARG_INFO(arginfo_rrd_fetch, 0)
ZEND_ARG_INFO(0, file)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_rrd_first, 0, 0, 1)
ZEND_ARG_INFO(0, file)
ZEND_ARG_INFO(0, raaindex)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_rrd_last, 0)
ZEND_ARG_INFO(0, file)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_rrd_lastupdate, 0)
ZEND_ARG_INFO(0, file)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_rrd_restore, 0, 0, 2)
ZEND_ARG_INFO(0, xml_file)
ZEND_ARG_INFO(0, rrd_file)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_rrd_tune, 0)
ZEND_ARG_INFO(0, file)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_rrd_xport, 0)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_rrd_info, 0)
ZEND_ARG_INFO(0, file)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_rrd_graph, 0)
ZEND_ARG_INFO(0, file)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_rrd_create, 0)
ZEND_ARG_INFO(0, filename)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_rrd_update, 0)
ZEND_ARG_INFO(0, file)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_rrd_void, 0)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ */
static zend_function_entry rrd_functions[] = {
PHP_FE(rrd_update, arginfo_rrd_update)
PHP_FE(rrd_create, arginfo_rrd_create)
PHP_FE(rrd_graph, arginfo_rrd_graph)
PHP_FE(rrd_error, arginfo_rrd_void)
PHP_FE(rrd_fetch, arginfo_rrd_fetch)
PHP_FE(rrd_first, arginfo_rrd_first)
PHP_FE(rrd_info, arginfo_rrd_info)
PHP_FE(rrd_last, arginfo_rrd_last)
PHP_FE(rrd_lastupdate, arginfo_rrd_lastupdate)
PHP_FE(rrd_restore, arginfo_rrd_restore)
PHP_FE(rrd_tune, arginfo_rrd_tune)
PHP_FE(rrd_xport, arginfo_rrd_xport)
#ifdef HAVE_RRDC_DISCONNECT
PHP_FE(rrdc_disconnect, arginfo_rrd_void)
#endif
PHP_FE(rrd_version, arginfo_rrd_void)
PHP_FE_END
};
/* }}} */
#ifdef COMPILE_DL_RRD
ZEND_GET_MODULE(rrd)
#endif
/* {{{ PHP_MINIT_FUNCTION */
static PHP_MINIT_FUNCTION(rrd)
{
rrd_graph_minit();
rrd_create_minit();
rrd_update_minit();
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION */
static PHP_MINFO_FUNCTION(rrd)
{
php_info_print_table_start();
php_info_print_table_header(2, "rrd tool module", "enabled");
php_info_print_table_row(2, "rrd tool module version", PHP_RRD_VERSION);
php_info_print_table_row(2, "rrdtool library version", rrd_strversion());
php_info_print_table_end();
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION */
static PHP_MSHUTDOWN_FUNCTION(rrd)
{
#ifdef HAVE_RRDC_DISCONNECT
/* ensure that any connection to rrd cache deamon will be closed */
rrdc_disconnect();
#endif
return SUCCESS;
}
/* }}} */
/* {{{ rrd module_entry */
zend_module_entry rrd_module_entry = {
STANDARD_MODULE_HEADER,
"rrd",
rrd_functions,
PHP_MINIT(rrd),
PHP_MSHUTDOWN(rrd),
NULL, /* PHP_RINIT(rrd) */
NULL, /* PHP_RSHUTDOWN(rrd) */
PHP_MINFO(rrd),
PHP_RRD_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* }}} */
/* {{{ Inits rrd arguments object for a particular rrd command by php array
* filename paremeter is optional.
*/
rrd_args *rrd_args_init_by_phparray(const char *command_name, const char *filename,
const zval *options)
{
unsigned i, option_count, args_counter = 2;
rrd_args *result;
if (Z_TYPE_P(options) != IS_ARRAY) return NULL;
option_count = zend_hash_num_elements(Z_ARRVAL_P(options));
if (!option_count) return NULL;
if (!strlen(command_name)) return NULL;
result = (rrd_args *)emalloc(sizeof(rrd_args));
/* "dummy" + command_name + filename if presented */
result->count = option_count + (strlen(filename) ? 3 : 2);
result->args = (char **)safe_emalloc(result->count, sizeof(char *), 0);
/* "dummy" and command_name are always needed */
result->args[0] = "dummy";
result->args[1] = estrdup(command_name);
/* append filename if it's presented */
if (strlen(filename)) result->args[args_counter++] = estrdup(filename);
zend_hash_internal_pointer_reset(Z_ARRVAL_P(options));
for (i=0; i < option_count; i++) {
zval *item;
smart_string option = {0}; /* one argument option */
/* force using strings as array items */
item = zend_hash_get_current_data(Z_ARRVAL_P(options));
if (Z_TYPE_P(item) != IS_STRING) convert_to_string(item);
smart_string_appendl(&option, Z_STRVAL_P(item), Z_STRLEN_P(item));
smart_string_0(&option);
result->args[args_counter++] = estrdup(option.c);
smart_string_free(&option);
zend_hash_move_forward(Z_ARRVAL_P(options));
}
return result;
}
/* }}} */
/* {{{ Frees all memory for arguments object
*/
void rrd_args_free(rrd_args *args)
{
int i;
if (!args || !args->args) return;
for (i = 1; i < args->count; i++) {
efree(args->args[i]);
}
efree(args->args);
efree(args);
}
/* }}} */
rrd-2.0.3/php_rrd.h 0000644 0001750 0001750 00000001600 14040307736 013751 0 ustar kubelik kubelik /**
* PHP bindings to the rrdtool
*
* This source file is subject to the BSD license that is bundled
* with this package in the file LICENSE.
* ---------------------------------------------------------------
* Author: Miroslav Kubelik
* ---------------------------------------------------------------
*/
#ifndef PHP_RRD_H
#define PHP_RRD_H
extern zend_module_entry rrd_module_entry;
#define phpext_rrd_ptr &rrd_module_entry
#define PHP_RRD_VERSION "2.0.3"
#ifdef ZTS
#include "TSRM.h"
#endif
#ifndef zend_parse_parameters_none
# define zend_parse_parameters_none() zend_parse_parameters(ZEND_NUM_ARGS(), "")
#endif
typedef struct _rrd_args {
int count;
char **args;
} rrd_args;
extern rrd_args *rrd_args_init_by_phparray(const char *command_name, const char *filename,
const zval *options);
extern void rrd_args_free(rrd_args *args);
#endif /* PHP_RRD_H */
rrd-2.0.3/config.m4 0000644 0001750 0001750 00000003100 14040307736 013646 0 ustar kubelik kubelik dnl config.m4 for extension php_rrd
dnl Comments in this file start with the string 'dnl'.
PHP_ARG_WITH(rrd, for rrdtool support,
[ --with-rrd Include rrdtool support (requires rrdtool >= 1.3.0)], yes)
AC_ARG_WITH(rrd-binary,
[AC_HELP_STRING([--with-rrd-binary][=PATH], [rrd binary dir path, mostly for testing (default=$PATH)])],
[AC_PATH_PROG(RRDTOOL_BIN, rrdtool, no, $withval)],
[AC_PATH_PROG(RRDTOOL_BIN, rrdtool, no, $PATH)])
AC_SUBST(RRDTOOL_BIN)
if test -f $srcdir/tests/rrdtool-bin.inc.in; then
AC_OUTPUT(tests/rrdtool-bin.inc)
AC_OUTPUT(tests/data/Makefile)
fi
if test "$PHP_RRD" != "no"; then
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
AC_MSG_CHECKING(for librdd)
if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists librrd && $PKG_CONFIG librrd --atleast-version 1.3.0; then
AC_MSG_RESULT(found)
LIBRRD_CFLAGS=`$PKG_CONFIG librrd --cflags`
LIBRRD_LDFLAGS=`$PKG_CONFIG librrd --libs`
PHP_EVAL_LIBLINE($LIBRRD_LDFLAGS, RRD_SHARED_LIBADD)
PHP_EVAL_INCLINE($LIBRRD_CFLAGS)
AC_DEFINE(HAVE_RRDTOOL, 1, [ ])
else
AC_MSG_ERROR(pkgconfig and librrd in version >= 1.3.0 must be installed)
fi
dnl rrd_lastupdate_r available in 1.4.0+
AC_CHECK_LIB([rrd], [rrd_lastupdate_r],
[
AC_DEFINE(HAVE_RRD_LASTUPDATE_R, 1, [ ])
], , [$LIBRRD_LDFLAGS])
dnl rrdc_disconnect available in 1.4.0+
AC_CHECK_LIB([rrd], [rrdc_disconnect],
[
AC_DEFINE(HAVE_RRDC_DISCONNECT, 1, [ ])
], , [$LIBRRD_LDFLAGS])
PHP_NEW_EXTENSION(rrd, rrd.c rrd_graph.c rrd_create.c rrd_update.c rrd_info.c, $ext_shared)
PHP_SUBST(RRD_SHARED_LIBADD)
fi
rrd-2.0.3/config.w32 0000644 0001750 0001750 00000001220 14040307736 013742 0 ustar kubelik kubelik // vim: ft=javascript:
ARG_WITH("rrd", "whether to enable RRD support", "no");
if ("no" != PHP_RRD) {
if (CHECK_LIB("rrdlib.lib;librrd*.lib", "rrd", PHP_RRD) &&
CHECK_HEADER_ADD_INCLUDE("rrd.h", "CFLAGS_RRD")) {
/* This leads to mode_t redefinition, but actually it's strange as it
seems to be dedicated to perl. */
ADD_FLAG("CFLAGS_RRD", "/D PERLPATCHLEVEL=0");
ADD_FLAG("CFLAGS_RRD", "/D HAVE_RRD_LASTUPDATE_R=1");
EXTENSION("rrd", "rrd.c rrd_graph.c rrd_create.c rrd_update.c rrd_info.c");
AC_DEFINE('HAVE_RRD', 1, 'Have RRD library');
} else {
WARNING("rrd not enabled, libs or headers not found");
}
}
rrd-2.0.3/rrd_update.c 0000644 0001750 0001750 00000015533 14040307736 014451 0 ustar kubelik kubelik /**
* PHP bindings to the rrdtool
*
* This source file is subject to the BSD license that is bundled
* with this package in the file LICENSE.
* ---------------------------------------------------------------
* Author: Miroslav Kubelik
* ---------------------------------------------------------------
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "zend_exceptions.h"
#include "ext/standard/php_smart_string.h"
#include
#include "php_rrd.h"
#include "rrd_update.h"
/* declare class entry */
static zend_class_entry *ce_rrd_update;
/* declare class handlers */
static zend_object_handlers rrd_update_handlers;
/**
* overloading the standard zend object structure (std property) in the need
* of having dedicated creating/cloning/destruction functions
*/
typedef struct _rrd_update_object {
/** path to newly created rrd file */
char *file_path;
zend_object std;
} rrd_update_object;
/**
* fetch our custom object from user space object
*/
static inline rrd_update_object *php_rrd_update_fetch_object(zend_object *obj) {
return (rrd_update_object *)((char*)(obj) - XtOffsetOf(rrd_update_object, std));
}
/* {{{ rrd_update_object_dtor
close all resources and the memory allocated for our internal object
*/
static void rrd_update_object_dtor(zend_object *object)
{
rrd_update_object *intern_obj = php_rrd_update_fetch_object(object);
if (!intern_obj) return;
if (intern_obj->file_path)
efree(intern_obj->file_path);
zend_object_std_dtor(&intern_obj->std);
}
/* }}} */
/* {{{ rrd_update_object_new
creates new rrd update object
*/
static zend_object *rrd_update_object_new(zend_class_entry *ce)
{
rrd_update_object *intern_obj = ecalloc(1, sizeof(rrd_update_object) +
zend_object_properties_size(ce));
intern_obj->file_path = NULL;
zend_object_std_init(&intern_obj->std, ce);
object_properties_init(&intern_obj->std, ce);
intern_obj->std.handlers = &rrd_update_handlers;
return &intern_obj->std;
}
/* }}} */
/* {{{ proto void RRDUpdater::__construct(string path)
creates new object for rrd update function
*/
PHP_METHOD(RRDUpdater, __construct)
{
rrd_update_object *intern_obj;
char *path;
size_t path_length;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &path, &path_length) == FAILURE) {
return;
}
intern_obj = php_rrd_update_fetch_object(Z_OBJ_P(getThis()));
intern_obj->file_path = estrdup(path);
}
/* }}} */
/* {{{ proto array RRDUpdater::update(array $values, [string time=time()])
Updates data sources in RRD database
*/
PHP_METHOD(RRDUpdater, update)
{
rrd_update_object *intern_obj;
zval *zv_values_array;
/* help structures for preparing arguments for rrd_update call */
zval zv_update_argv;
rrd_args *update_argv;
/* 'N' means default time string for rrd update,
* see rrdtool update man page
*/
char *time = "N";
size_t time_str_length = 1;
int argc = ZEND_NUM_ARGS();
zend_string *zs_ds_name;
zval *zv_ds_val;
/* string for all data source names formated for rrd_update call */
smart_string ds_names = {0};
/* string for all data source values for rrd_update call */
smart_string ds_vals = {0};
if (zend_parse_parameters(argc, "a|s", &zv_values_array, &time,
&time_str_length) == FAILURE) {
return;
}
if (zend_hash_num_elements(Z_ARRVAL_P(zv_values_array)) <= 0) {
RETURN_TRUE;
}
intern_obj = php_rrd_update_fetch_object(Z_OBJ_P(getThis()));
if (php_check_open_basedir(intern_obj->file_path)) {
RETURN_FALSE;
}
if (argc > 1 && time_str_length == 0) {
zend_throw_exception(NULL, "time cannot be empty string", 0);
return;
}
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zv_values_array), zs_ds_name, zv_ds_val) {
if (ds_names.len) {
smart_string_appendc(&ds_names, ':');
} else {
smart_string_appends(&ds_names, "--template=");
}
smart_string_appends(&ds_names, ZSTR_VAL(zs_ds_name));
/* "timestamp:ds1Value:ds2Value" string */
if (!ds_vals.len) {
smart_string_appends(&ds_vals, time);
}
smart_string_appendc(&ds_vals, ':');
if (Z_TYPE_P(zv_ds_val) != IS_STRING) {
convert_to_string(zv_ds_val);
}
smart_string_appendl(&ds_vals, Z_STRVAL_P(zv_ds_val), Z_STRLEN_P(zv_ds_val));
} ZEND_HASH_FOREACH_END();
smart_string_0(&ds_names);
smart_string_0(&ds_vals);
/* add copy of names and values strings into arguments array and free
* original strings
*/
array_init(&zv_update_argv);
add_next_index_string(&zv_update_argv, ds_names.c);
add_next_index_string(&zv_update_argv, ds_vals.c);
smart_string_free(&ds_names);
smart_string_free(&ds_vals);
update_argv = rrd_args_init_by_phparray("update", intern_obj->file_path, &zv_update_argv);
if (!update_argv) {
zend_error(E_WARNING, "cannot allocate arguments options");
zval_dtor(&zv_update_argv);
if (time_str_length == 0) efree(time);
RETURN_FALSE;
}
if (rrd_test_error()) rrd_clear_error();
/* call rrd_update and test if fails */
if (rrd_update(update_argv->count - 1, &update_argv->args[1]) == -1) {
zval_dtor(&zv_update_argv);
rrd_args_free(update_argv);
/* throw exception with rrd error string */
zend_throw_exception(NULL, rrd_get_error(), 0);
rrd_clear_error();
return;
}
zval_dtor(&zv_update_argv);
rrd_args_free(update_argv);
RETURN_TRUE;
}
/* }}} */
/* {{{ proto int rrd_update(string file, array options)
Updates the RRD file with a particular options and values.
*/
PHP_FUNCTION(rrd_update)
{
char *filename;
size_t filename_length;
zval *zv_arr_options;
rrd_args *argv;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "pa", &filename,
&filename_length, &zv_arr_options) == FAILURE) {
return;
}
if (php_check_open_basedir(filename)) RETURN_FALSE;
argv = rrd_args_init_by_phparray("update", filename, zv_arr_options);
if (!argv) {
zend_error(E_WARNING, "cannot allocate arguments options");
RETURN_FALSE;
}
if (rrd_test_error()) rrd_clear_error();
if (rrd_update(argv->count - 1, &argv->args[1]) == -1 ) {
RETVAL_FALSE;
} else {
RETVAL_TRUE;
}
rrd_args_free(argv);
}
/* }}} */
ZEND_BEGIN_ARG_INFO(arginfo_rrdupdater_construct, 0)
ZEND_ARG_INFO(0, path)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_rrdupdater_update, 0, 0, 1)
ZEND_ARG_INFO(0, values)
ZEND_ARG_INFO(0, time)
ZEND_END_ARG_INFO()
/* class method table */
static zend_function_entry rrd_update_methods[] = {
PHP_ME(RRDUpdater, __construct, arginfo_rrdupdater_construct, ZEND_ACC_PUBLIC)
PHP_ME(RRDUpdater, update, arginfo_rrdupdater_update, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* minit hook, called from main module minit */
void rrd_update_minit()
{
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "RRDUpdater", rrd_update_methods);
ce.create_object = rrd_update_object_new;
ce_rrd_update = zend_register_internal_class(&ce);
memcpy(&rrd_update_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
rrd_update_handlers.clone_obj = NULL;
rrd_update_handlers.offset = XtOffsetOf(rrd_update_object, std);
rrd_update_handlers.free_obj = rrd_update_object_dtor;
}
rrd-2.0.3/rrd_update.h 0000644 0001750 0001750 00000000705 14040307736 014451 0 ustar kubelik kubelik /**
* PHP bindings to the rrdtool
*
* This source file is subject to the BSD license that is bundled
* with this package in the file LICENSE.
* ---------------------------------------------------------------
* Author: Miroslav Kubelik
* ---------------------------------------------------------------
*/
#ifndef RRD_UPDATE_H
#define RRD_UPDATE_H
void rrd_update_minit();
PHP_FUNCTION(rrd_update);
#endif /* RRD_UPDATE_H */
rrd-2.0.3/rrd_create.h 0000644 0001750 0001750 00000000705 14040307736 014432 0 ustar kubelik kubelik /**
* PHP bindings to the rrdtool
*
* This source file is subject to the BSD license that is bundled
* with this package in the file LICENSE.
* ---------------------------------------------------------------
* Author: Miroslav Kubelik
* ---------------------------------------------------------------
*/
#ifndef RRD_CREATE_H
#define RRD_CREATE_H
void rrd_create_minit();
PHP_FUNCTION(rrd_create);
#endif /* RRD_CREATE_H */
rrd-2.0.3/rrd_create.c 0000644 0001750 0001750 00000022644 14040307736 014433 0 ustar kubelik kubelik /**
* PHP bindings to the rrdtool
*
* This source file is subject to the BSD license that is bundled
* with this package in the file LICENSE.
* ---------------------------------------------------------------
* Author: Miroslav Kubelik
* ---------------------------------------------------------------
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "zend_exceptions.h"
#include "ext/standard/php_array.h"
#include
#include "php_rrd.h"
#include "rrd_create.h"
/* declare class entry */
static zend_class_entry *ce_rrd_create;
/* declare class handlers */
static zend_object_handlers rrd_create_handlers;
/* overloading the standard zend object structure (std property) in the need
of having dedicated creating/cloning/destruction functions
*/
typedef struct _rrd_create_object {
/** path to newly created rrd file */
char *file_path;
/* "--start" parameters in rrd create */
char *start_time;
/* "--step" parameters in rrd create */
zval zv_step;
/* "DS" parameters in rrd create */
zval zv_arr_data_sources;
/* "RRA" parameters in rrd create */
zval zv_arr_archives;
zend_object std;
} rrd_create_object;
/**
* fetch our custom object from user space object
*/
static inline rrd_create_object *php_rrd_create_fetch_object(zend_object *obj) {
return (rrd_create_object *)((char*)(obj) - XtOffsetOf(rrd_create_object, std));
}
/* {{{ rrd_create_object_dtor
close all resources and the memory allocated for our internal object
*/
static void rrd_create_object_dtor(zend_object *object)
{
rrd_create_object *intern_obj = php_rrd_create_fetch_object(object);
if (!intern_obj) return;
if (intern_obj->file_path)
efree(intern_obj->file_path);
if (intern_obj->start_time)
efree(intern_obj->start_time);
if (!Z_ISUNDEF(intern_obj->zv_step))
zval_dtor(&intern_obj->zv_step);
if (!Z_ISUNDEF(intern_obj->zv_arr_data_sources))
zval_dtor(&intern_obj->zv_arr_data_sources);
if (!Z_ISUNDEF(intern_obj->zv_arr_archives))
zval_dtor(&intern_obj->zv_arr_archives);
zend_object_std_dtor(&intern_obj->std);
}
/* }}} */
/* {{{ rrd_create_object_new
creates new rrd create object
*/
static zend_object *rrd_create_object_new(zend_class_entry *ce)
{
rrd_create_object *intern_obj = ecalloc(1, sizeof(rrd_create_object) +
zend_object_properties_size(ce));
intern_obj->file_path = NULL;
intern_obj->start_time = NULL;
ZVAL_UNDEF(&intern_obj->zv_step);
ZVAL_UNDEF(&intern_obj->zv_arr_data_sources);
ZVAL_UNDEF(&intern_obj->zv_arr_archives);
zend_object_std_init(&intern_obj->std, ce);
object_properties_init(&intern_obj->std, ce);
intern_obj->std.handlers = &rrd_create_handlers;
return &intern_obj->std;
}
/* }}} */
/* {{{ proto void RRDCreator::__construct(string path [,string startTime]
[,int step])
creates new object for creating rrd database
*/
PHP_METHOD(RRDCreator, __construct)
{
rrd_create_object *intern_obj;
char *path; size_t path_length;
/* better to set defaults for optional parameters */
zend_string *start_time;
long step = 0;
int argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc, "p|Sl", &path, &path_length,
&start_time, &step) == FAILURE) {
return;
}
if (path_length == 0) {
zend_throw_exception(NULL,
"path for rrd file cannot be empty string", 0);
return;
}
if (argc > 1 && ZSTR_LEN(start_time) == 0) {
zend_throw_exception(NULL,
"startTime cannot be empty string", 0);
return;
}
if (argc > 2 && step <= 0) {
zend_throw_exception(NULL,
"step parameter must be greater then 0", 0);
return;
}
intern_obj = php_rrd_create_fetch_object(Z_OBJ_P(getThis()));
intern_obj->file_path = estrdup(path);
if (start_time) intern_obj->start_time = estrdup(ZSTR_VAL(start_time));
if (step) {
ZVAL_LONG(&intern_obj->zv_step, step);
}
}
/* }}} */
/* {{{ proto RRDCreator::addDataSource(string description)
Add information about data source
*/
PHP_METHOD(RRDCreator, addDataSource)
{
rrd_create_object *intern_obj;
zend_string *description;
char *rrd_source_desc;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &description) == FAILURE) {
return;
}
if (ZSTR_LEN(description) == 0) {
zend_throw_exception(NULL,
"description parameter cannot be empty string", 0);
return;
}
intern_obj = php_rrd_create_fetch_object(Z_OBJ_P(getThis()));
if (Z_ISUNDEF(intern_obj->zv_arr_data_sources)) {
array_init(&intern_obj->zv_arr_data_sources);
}
rrd_source_desc = emalloc(ZSTR_LEN(description) + 4);
strcpy(rrd_source_desc, "DS:");
strcat(rrd_source_desc, ZSTR_VAL(description));
add_next_index_string(&intern_obj->zv_arr_data_sources, rrd_source_desc);
efree(rrd_source_desc);
}
/* }}} */
/* {{{ proto RRDCreator::addArchive(string description)
Add information about new round robin archive
*/
PHP_METHOD(RRDCreator, addArchive)
{
rrd_create_object *intern_obj;
zend_string *description;
char *rrd_archive_desc;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &description) == FAILURE) {
return;
}
if (ZSTR_LEN(description) == 0) {
zend_throw_exception(NULL,
"description parameter cannot be empty string", 0);
return;
}
intern_obj = php_rrd_create_fetch_object(Z_OBJ_P(getThis()));
if (Z_ISUNDEF(intern_obj->zv_arr_archives)) {
array_init(&intern_obj->zv_arr_archives);
}
rrd_archive_desc = emalloc(ZSTR_LEN(description) + 5);
strcpy(rrd_archive_desc, "RRA:");
strcat(rrd_archive_desc, ZSTR_VAL(description));
add_next_index_string(&intern_obj->zv_arr_archives, rrd_archive_desc);
efree(rrd_archive_desc);
}
/* }}} */
/* {{{ proto bool RRDCreator::save()
Saves new rrd database according to current properties.
*/
PHP_METHOD(RRDCreator, save)
{
rrd_create_object *intern_obj = php_rrd_create_fetch_object(Z_OBJ_P(getThis()));
/* help structures for preparing arguments for rrd_create call */
zval zv_create_argv;
rrd_args *create_argv;
array_init(&zv_create_argv);
if (intern_obj->start_time) {
const char *prefix = "--start=";
char *start_time_str = emalloc(strlen(intern_obj->start_time)
+ strlen(prefix) + 1);
strcpy(start_time_str, prefix);
strcat(start_time_str, intern_obj->start_time);
add_next_index_string(&zv_create_argv, start_time_str);
efree(start_time_str);
}
if (!Z_ISUNDEF(intern_obj->zv_step)) {
const char *prefix = "--step=";
char *start_time_str;
convert_to_string(&intern_obj->zv_step);
start_time_str = emalloc(strlen(prefix) + Z_STRLEN(intern_obj->zv_step) + 1);
strcpy(start_time_str, prefix);
strcat(start_time_str, Z_STRVAL(intern_obj->zv_step));
add_next_index_string(&zv_create_argv, start_time_str);
/* back to long, doesn't needed, but we are consistent */
convert_to_long(&intern_obj->zv_step);
efree(start_time_str);
}
/* add array of archive and data source strings into argument list */
php_array_merge(Z_ARRVAL(zv_create_argv), Z_ARRVAL(intern_obj->zv_arr_data_sources));
php_array_merge(Z_ARRVAL(zv_create_argv), Z_ARRVAL(intern_obj->zv_arr_archives));
create_argv = rrd_args_init_by_phparray("create", intern_obj->file_path, &zv_create_argv);
if (!create_argv) {
zend_error(E_WARNING, "cannot allocate arguments options");
zval_dtor(&zv_create_argv);
RETURN_FALSE;
}
if (rrd_test_error()) rrd_clear_error();
/* call rrd_create and test if fails */
if (rrd_create(create_argv->count - 1, &create_argv->args[1]) == -1) {
zval_dtor(&zv_create_argv);
rrd_args_free(create_argv);
/* throw exception with rrd error string */
zend_throw_exception(NULL, rrd_get_error(), 0);
rrd_clear_error();
return;
}
zval_dtor(&zv_create_argv);
rrd_args_free(create_argv);
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool rrd_create(string file, array options)
Create an RRD file with the options passed
*/
PHP_FUNCTION(rrd_create)
{
char *filename;
size_t filename_length;
zval *zv_arr_options;
rrd_args *argv;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "pa", &filename,
&filename_length, &zv_arr_options) == FAILURE) {
return;
}
if (php_check_open_basedir(filename)) RETURN_FALSE;
argv = rrd_args_init_by_phparray("create", filename, zv_arr_options);
if (!argv) {
zend_error(E_WARNING, "cannot allocate arguments options");
RETURN_FALSE;
}
if (rrd_test_error()) rrd_clear_error();
if (rrd_create(argv->count - 1, &argv->args[1]) == -1 ) {
RETVAL_FALSE;
} else {
RETVAL_TRUE;
}
rrd_args_free(argv);
}
/* }}} */
ZEND_BEGIN_ARG_INFO_EX(arginfo_rrdcreator_construct, 0, 0, 1)
ZEND_ARG_INFO(0, path)
ZEND_ARG_INFO(0, startTime)
ZEND_ARG_INFO(0, step)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_rrdcreator_description, 0, 0, 1)
ZEND_ARG_INFO(0, description)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_rrdcreator_void, 0, 0, 0)
ZEND_END_ARG_INFO()
/* class method table */
static zend_function_entry rrd_create_methods[] = {
PHP_ME(RRDCreator, __construct, arginfo_rrdcreator_construct, ZEND_ACC_PUBLIC)
PHP_ME(RRDCreator, save, arginfo_rrdcreator_void, ZEND_ACC_PUBLIC)
PHP_ME(RRDCreator, addDataSource, arginfo_rrdcreator_description, ZEND_ACC_PUBLIC)
PHP_ME(RRDCreator, addArchive, arginfo_rrdcreator_description, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* minit hook, called from main module minit */
void rrd_create_minit()
{
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "RRDCreator", rrd_create_methods);
ce.create_object = rrd_create_object_new;
ce_rrd_create = zend_register_internal_class(&ce);
memcpy(&rrd_create_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
rrd_create_handlers.clone_obj = NULL;
rrd_create_handlers.offset = XtOffsetOf(rrd_create_object, std);
rrd_create_handlers.free_obj = rrd_create_object_dtor;
}
rrd-2.0.3/CREDITS 0000644 0001750 0001750 00000000327 14040307736 013167 0 ustar kubelik kubelik RRD
Miroslav Kubelik (koubel@php.net)
Big Thanks:
Joe Miller - author of first rrdtool extension
Jeffrey Wheat, Dan Cech, Benny Baumann - patches and improvements
Remi Collet - for relentless bug fixing and support
rrd-2.0.3/LICENSE 0000644 0001750 0001750 00000002451 14040307736 013154 0 ustar kubelik kubelik Copyright (c) 2010 - 2015, Miroslav KubelĂk
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.