php-5.6/0000755000175100017510000000000012644400410011474 5ustar ondrejondrejphp-5.6/package.xml0000644000175100017510000002166312265443701013632 0ustar ondrejondrej 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 2014-01-15 1.1.3 1.1.3 stable stable BSD - rrdc_disconnect is available in rrd 1.4.0+ (Remi) 5.3.2 1.4.0 rrd 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 doesnt' 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 test - 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 : rdd_fetch returned array format 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 php-5.6/rrd-1.1.3/0000755000175100017510000000000012644400410012721 5ustar ondrejondrejphp-5.6/rrd-1.1.3/tests/0000755000175100017510000000000012644400410014063 5ustar ondrejondrejphp-5.6/rrd-1.1.3/tests/data/0000755000175100017510000000000012644400410014774 5ustar ondrejondrejphp-5.6/rrd-1.1.3/tests/data/definition.inc0000644000175100017510000000073012265443701017630 0ustar ondrejondrejrrd_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 php-5.6/rrd-1.1.3/tests/rrd_001.phpt0000644000175100017510000000023512265443701016140 0ustar ondrejondrej--TEST-- rrd module presence test --SKIPIF-- --FILE-- --EXPECTF-- rrd extension loaded php-5.6/rrd-1.1.3/tests/rrd_002.phpt0000644000175100017510000000132712265443701016144 0ustar ondrejondrej--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) php-5.6/rrd-1.1.3/tests/rrd_003.phpt0000644000175100017510000000062012265443701016140 0ustar ondrejondrej--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) php-5.6/rrd-1.1.3/tests/rrd_004.phpt0000644000175100017510000000404412265443701016145 0ustar ondrejondrej--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"; $output = array(); exec($command, $output); $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) { } php-5.6/rrd-1.1.3/tests/rrd_005.phpt0000644000175100017510000000206112265443701016143 0ustar ondrejondrej--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 php-5.6/rrd-1.1.3/tests/rrd_006.phpt0000644000175100017510000000217212265443701016147 0ustar ondrejondrej--TEST-- rrd_update test --SKIPIF-- --FILE-- --EXPECTF-- exporting rrd_update_1.png via exec bool(true) php-5.6/rrd-1.1.3/tests/rrd_007.phpt0000644000175100017510000000050412265443701016145 0ustar ondrejondrej--TEST-- rrd_create test --SKIPIF-- --FILE-- --EXPECTF-- bool(true) php-5.6/rrd-1.1.3/tests/rrd_008.phpt0000644000175100017510000000175612265443701016160 0ustar ondrejondrej--TEST-- rrd_graph test --SKIPIF-- include('skipif.inc'); include('rrdtool-bin.inc'); include('data/definition.inc'); if (!file_exists($data_updatedDb)) { die("skip $data_updatedDb doesnt' exist"); } ?> --FILE-- --EXPECTF-- exporting image via exec array(3) { ["xsize"]=> int(497) ["ysize"]=> int(%d) ["calcpr"]=> NULL } php-5.6/rrd-1.1.3/tests/rrd_009.phpt0000644000175100017510000000042212265443701016146 0ustar ondrejondrej--TEST-- rrd_error test --SKIPIF-- --FILE-- --EXPECTF-- string(31) "can't parse argument 'badParam'" bool(false)php-5.6/rrd-1.1.3/tests/rrd_010.phpt0000644000175100017510000000316012265443701016140 0ustar ondrejondrej--TEST-- rrd_fetch test --SKIPIF-- include('skipif.inc'); include('data/definition.inc'); if (!file_exists($data_moreDSDb)) { die("skip $data_moreDSDb doesnt' exist"); } --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.033333333333333) [920806500]=> float(0.033333333333333) [920806800]=> float(0.033333333333333) [920807100]=> float(0.02) [920807400]=> float(0.02) [920807700]=> float(0.02) [920808000]=> float(0.013333333333333) [920808300]=> float(0.016666666666667) } ["speed2"]=> array(13) { [920804700]=> float(NAN) [920805000]=> float(0.056666666666667) [920805300]=> float(0.02) [920805600]=> float(0.0033333333333333) [920805900]=> float(0) [920806200]=> float(0.03) [920806500]=> float(0) [920806800]=> float(0.066666666666667) [920807100]=> float(0.02) [920807400]=> float(0.02) [920807700]=> float(0.02) [920808000]=> float(0.013333333333333) [920808300]=> float(0.016666666666667) } } }php-5.6/rrd-1.1.3/tests/rrd_011.phpt0000644000175100017510000000071412265443701016143 0ustar ondrejondrej--TEST-- rrd_first test --SKIPIF-- --FILE-- --EXPECTF-- int(920802000) int(920791800) bool(false) bool(false) php-5.6/rrd-1.1.3/tests/rrd_012.phpt0000644000175100017510000000263312265443701016146 0ustar ondrejondrej--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.026666666666667) ["rra[1].cdp_prep[0].unknown_datapoints"]=> int(0) } bool(true) php-5.6/rrd-1.1.3/tests/rrd_013.phpt0000644000175100017510000000043512265443701016145 0ustar ondrejondrej--TEST-- rrd_last test --SKIPIF-- include('skipif.inc'); include('data/definition.inc'); if (!file_exists($data_updatedDb)) { die("skip $data_updatedDb doesn't exist"); } --FILE-- --EXPECTF-- int(920808900)php-5.6/rrd-1.1.3/tests/rrd_014.phpt0000644000175100017510000000151512265443701016146 0ustar ondrejondrej--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" } }php-5.6/rrd-1.1.3/tests/rrd_015.phpt0000644000175100017510000000120012265443701016136 0ustar ondrejondrej--TEST-- rrd_restore test --SKIPIF-- --FILE-- --EXPECTF-- bool(true) bool(true) bool(true) php-5.6/rrd-1.1.3/tests/rrd_016.phpt0000644000175100017510000000106012265443701016143 0ustar ondrejondrej--TEST-- rrd_tune test --SKIPIF-- --FILE-- --EXPECTF-- bool(true) bool(false) bool(true) %sphp-5.6/rrd-1.1.3/tests/rrd_017.phpt0000644000175100017510000000372712265443701016160 0ustar ondrejondrej--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.033333333333333) [920806500]=> float(0.033333333333333) [920806800]=> float(0.033333333333333) [920807100]=> float(0.02) [920807400]=> float(0.02) [920807700]=> float(0.02) [920808000]=> float(0.013333333333333) [920808300]=> float(0.016666666666667) } } [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.333333333333) [920806500]=> float(33.333333333333) [920806800]=> float(33.333333333333) [920807100]=> float(20) [920807400]=> float(20) [920807700]=> float(20) [920808000]=> float(13.333333333333) [920808300]=> float(16.666666666667) } } } } php-5.6/rrd-1.1.3/tests/rrd_018.phpt0000644000175100017510000000170612265443701016154 0ustar ondrejondrej--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) } php-5.6/rrd-1.1.3/tests/rrd_019.phpt0000644000175100017510000000216512265443701016155 0ustar ondrejondrej--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) php-5.6/rrd-1.1.3/tests/rrd_020.phpt0000644000175100017510000000037712265443701016150 0ustar ondrejondrej--TEST-- rrd_version test --SKIPIF-- --FILE-- = 2); ?> --EXPECTF-- string(%i) "%s" bool(true) bool(true) php-5.6/rrd-1.1.3/tests/rrd_021.phpt0000644000175100017510000000222712265443701016145 0ustar ondrejondrej--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) { } php-5.6/rrd-1.1.3/tests/rrd_022.phpt0000644000175100017510000000035412265443701016145 0ustar ondrejondrej--TEST-- rrdc_disconnect test --SKIPIF-- = 1.4"); } ?> --FILE-- --EXPECTF-- NULL php-5.6/rrd-1.1.3/tests/rrdtool-bin.inc.in0000644000175100017510000000016212265443701017426 0ustar ondrejondrej php-5.6/rrd-1.1.3/tests/skipif.inc0000644000175100017510000000012412265443701016051 0ustar ondrejondrej php-5.6/rrd-1.1.3/rrd_info.c0000644000175100017510000000433312265443701014703 0ustar ondrejondrej/** * 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; int 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() TSRMLS_CC, "s", &filename, &filename_length) == FAILURE) { return; } if (php_check_open_basedir(filename TSRMLS_CC)) 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 TSRMLS_CC); rrd_info_free(rrd_info_data); } /* }}} */ /* {{{ converts rrd_info_t struct into php array @return int 1 OK, 0 conversion failed */ uint rrd_info_toarray(const rrd_info_t *rrd_info_data, zval *array TSRMLS_DC) { 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, 1); 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, 1); break; } data_p = data_p->next; } return 1; } /* }}} */ php-5.6/rrd-1.1.3/rrd_info.h0000644000175100017510000000114412265443701014705 0ustar ondrejondrej/** * 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 uint rrd_info_toarray(const rrd_info_t *rrd_info_data, zval *array TSRMLS_DC); #endif /* RRD_INFO_H */ php-5.6/rrd-1.1.3/rrd_graph.c0000644000175100017510000002626312265443701015057 0ustar ondrejondrej/** * 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_str.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 { zend_object std; char *file_path; zval *zv_arr_options; } rrd_graph_object; /* {{{ rrd_graph_object_dtor close all resources and the memory allocated for our internal object */ static void rrd_graph_object_dtor(void *object TSRMLS_DC) { rrd_graph_object *intern_obj = (rrd_graph_object *)object; if (intern_obj->file_path) efree(intern_obj->file_path); if (intern_obj->zv_arr_options) { zval_dtor(intern_obj->zv_arr_options); } zend_object_std_dtor(&intern_obj->std TSRMLS_CC); efree(intern_obj); } /* }}} */ /* {{{ rrd_graph_object_new creates new rrd graph object */ static zend_object_value rrd_graph_object_new(zend_class_entry *ce TSRMLS_DC) { rrd_graph_object *intern_obj; zend_object_value retval; #if ZEND_MODULE_API_NO < 20100409 zval *tmp; #endif intern_obj = ecalloc(1, sizeof(*intern_obj)); zend_object_std_init(&intern_obj->std, ce TSRMLS_CC); intern_obj->file_path = NULL; intern_obj->zv_arr_options = NULL; #if ZEND_MODULE_API_NO >= 20100409 object_properties_init(&intern_obj->std, ce); #else zend_hash_copy(intern_obj->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval*) ); #endif retval.handle = zend_objects_store_put(intern_obj, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)rrd_graph_object_dtor, NULL TSRMLS_CC ); retval.handlers = &rrd_graph_handlers; return retval; } /* }}} */ /* {{{ proto void RRDGraph::__construct(string path) creates new object for rrd graph function */ PHP_METHOD(RRDGraph, __construct) { rrd_graph_object *intern_obj; char *path; int path_length; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_length) == FAILURE) { return; } intern_obj = (rrd_graph_object*)zend_object_store_get_object(getThis() TSRMLS_CC); 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() TSRMLS_CC, "a", &zv_arr_options) == FAILURE) { return; } intern_obj = (rrd_graph_object*)zend_object_store_get_object(getThis() TSRMLS_CC); /* if our array is initialized, so delete it first */ if (intern_obj->zv_arr_options) { zval_dtor(intern_obj->zv_arr_options); } /* copy array from parameter */ MAKE_STD_ZVAL(intern_obj->zv_arr_options); *intern_obj->zv_arr_options = *zv_arr_options; zval_copy_ctor(intern_obj->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 TSRMLS_DC) { /* iterated item */ zval **zv_option_val; /* arguments for rrd_graph call as php array - temporary storage */ zval *zv_argv; rrd_args *result; MAKE_STD_ZVAL(zv_argv); array_init(zv_argv); zend_hash_internal_pointer_reset(Z_ARRVAL_P(obj->zv_arr_options)); while (zend_hash_get_current_data(Z_ARRVAL_P(obj->zv_arr_options), (void**)&zv_option_val) == SUCCESS) { /* copy for converted non-string value, because we don't want to modify * original array item */ zval option_str_copy; /* pointer for current value, either on zv_option_val (current array item) * or on option_str_copy (string converted item) */ zval *option_ptr = *zv_option_val; char *str_key; ulong num_key; smart_str option = {0}; /* one argument option */ /* option with string key means long option, hence they are used as * "key=value" e.g. "--start=920804400" */ if (zend_hash_get_current_key(Z_ARRVAL_P(obj->zv_arr_options), &str_key, &num_key, 0) == HASH_KEY_IS_STRING) { smart_str_appends(&option, str_key); smart_str_appendc(&option, '='); }; /* if option isn't string, use new value as old one casted to string */ if (Z_TYPE_PP(zv_option_val) != IS_STRING) { option_str_copy = **zv_option_val; zval_copy_ctor(&option_str_copy); convert_to_string(&option_str_copy); option_ptr = &option_str_copy; } smart_str_appendl(&option, Z_STRVAL_P(option_ptr), Z_STRLEN_P(option_ptr)); smart_str_0(&option); add_next_index_string(zv_argv, option.c, 1); smart_str_free(&option); if (option_ptr != *zv_option_val) { zval_dtor(&option_str_copy); } zend_hash_move_forward(Z_ARRVAL_P(obj->zv_arr_options)); } result = rrd_args_init_by_phparray(command_name, obj->file_path, zv_argv TSRMLS_CC); 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 = (rrd_graph_object *)zend_object_store_get_object(getThis() TSRMLS_CC); /* 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 (!intern_obj->zv_arr_options || Z_TYPE_P(intern_obj->zv_arr_options) != IS_ARRAY) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "options aren't correctly set", 0 TSRMLS_CC); return; } if (php_check_open_basedir(intern_obj->file_path TSRMLS_CC)) { RETURN_FALSE; } graph_argv = rrd_graph_obj_create_argv("graph", intern_obj TSRMLS_CC); 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(zend_exception_get_default(TSRMLS_C), rrd_get_error(), 0 TSRMLS_CC); 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; MAKE_STD_ZVAL(zv_calcpr_array) array_init(zv_calcpr_array); if (calcpr) { uint i; for (i = 0; calcpr[i]; i++) { add_next_index_string(zv_calcpr_array, calcpr[i], 1); 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 = (rrd_graph_object *)zend_object_store_get_object(getThis() TSRMLS_CC); /* return value from rrd_graphv */ rrd_info_t *rrd_info_data; /* arguments for rrd_graph call */ rrd_args *graph_argv; if (!intern_obj->zv_arr_options || Z_TYPE_P(intern_obj->zv_arr_options) != IS_ARRAY) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "options aren't correctly set", 0 TSRMLS_CC); return; } graph_argv = rrd_graph_obj_create_argv("graphv", intern_obj TSRMLS_CC); 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(zend_exception_get_default(TSRMLS_C), rrd_get_error(), 0 TSRMLS_CC); rrd_clear_error(); rrd_args_free(graph_argv); return; } /* making return array */ array_init(return_value); rrd_info_toarray(rrd_info_data, return_value TSRMLS_CC); 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; int 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() TSRMLS_CC, "sa", &filename, &filename_length, &zv_arr_options) == FAILURE) { return; } if (php_check_open_basedir(filename TSRMLS_CC)) RETURN_FALSE; argv = rrd_args_init_by_phparray("graph", filename, zv_arr_options TSRMLS_CC); 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; MAKE_STD_ZVAL(zv_calcpr_array) array_init(zv_calcpr_array); if (calcpr) { uint i; for (i=0; calcpr[i]; i++) { add_next_index_string(zv_calcpr_array, calcpr[i], 1); 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_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, NULL, ZEND_ACC_PUBLIC) PHP_ME(RRDGraph, saveVerbose, NULL, ZEND_ACC_PUBLIC) PHP_ME(RRDGraph, setOptions, arginfo_rrd_options, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* minit hook, called from main module minit */ void rrd_graph_minit(TSRMLS_D) { 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 TSRMLS_CC); memcpy(&rrd_graph_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); rrd_graph_handlers.clone_obj = NULL; } php-5.6/rrd-1.1.3/rrd_graph.h0000644000175100017510000000072612265443701015060 0ustar ondrejondrej/** * 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(TSRMLS_D); extern PHP_FUNCTION(rrd_graph); #endif /* RRD_GRAPH_H */ php-5.6/rrd-1.1.3/rrd.c0000644000175100017510000004275412265443701013701 0ustar ondrejondrej/** * 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_str.h" #include "ext/standard/php_array.h" #include "ext/standard/info.h" #include #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(), 1); rrd_clear_error(); } /* }}} */ /* {{{ proto array rrd_fetch(string file, array options) Fetch data from RRD in requested resolution. */ PHP_FUNCTION(rrd_fetch) { char *filename; int filename_length; zval *zv_arr_options; rrd_args *argv; /* returned values if rrd_fetch doesn't fail */ time_t start, end; 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() TSRMLS_CC, "sa", &filename, &filename_length, &zv_arr_options) == FAILURE) { return; } if (php_check_open_basedir(filename TSRMLS_CC)) RETURN_FALSE; argv = rrd_args_init_by_phparray("fetch", filename, zv_arr_options TSRMLS_CC); 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; uint timestamp, ds_counter; /* final array for all data from all data sources */ zval *zv_data_array; MAKE_STD_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; MAKE_STD_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_P(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 */ zval *zv_timestamp; MAKE_STD_ZVAL(zv_timestamp); ZVAL_LONG(zv_timestamp, timestamp); convert_to_string(zv_timestamp); /* gets pointer for data source result array */ zend_hash_get_current_data(Z_ARRVAL_P(zv_data_array), (void**) &ds_data_array); add_assoc_double(*ds_data_array, Z_STRVAL_P(zv_timestamp), *(datap++)); zend_hash_move_forward(Z_ARRVAL_P(zv_data_array)); zval_dtor(zv_timestamp); efree(zv_timestamp); } } 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; int 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() TSRMLS_CC, "s|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 TSRMLS_CC)) 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; int filename_length; /* return value from rrd_first_r call */ time_t rrd_last_return_val; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_length) == FAILURE) { return; } if (php_check_open_basedir(filename TSRMLS_CC)) 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; int 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() TSRMLS_CC, "s", &filename, &filename_length) == FAILURE) { return; } if (php_check_open_basedir(filename TSRMLS_CC)) 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 { uint i; zval *zv_ds_namv_array; MAKE_STD_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], 1); 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 { uint i; zval *zv_data_array; MAKE_STD_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], 1); 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; int 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() TSRMLS_CC, "ss|a", &xml_filename, &xml_filename_length, &rrd_filename, &rrd_filename_length, &zv_arr_options) == FAILURE) { return; } if (php_check_open_basedir(xml_filename TSRMLS_CC)) RETURN_FALSE; if (php_check_open_basedir(rrd_filename TSRMLS_CC)) RETURN_FALSE; /* zv_options = merge rrd_filename and zv_arr_options content */ MAKE_STD_ZVAL(zv_options); array_init(zv_options); add_next_index_string(zv_options, rrd_filename, 1); if (zv_arr_options && Z_TYPE_P(zv_arr_options) == IS_ARRAY) { php_array_merge(Z_ARRVAL_P(zv_options), Z_ARRVAL_P(zv_arr_options), 0 TSRMLS_CC); } argv = rrd_args_init_by_phparray("restore", xml_filename, zv_options TSRMLS_CC); if (!argv) { zend_error(E_WARNING, "cannot allocate arguments 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; int filename_length; zval *zv_arr_options; rrd_args *argv; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &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 TSRMLS_CC)) RETURN_FALSE; argv = rrd_args_init_by_phparray("tune", filename, zv_arr_options TSRMLS_CC); 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; ulong step, outvar_count; char **legend_v; rrd_value_t *data, *data_ptr; zval *zv_data; ulong outvar_index; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zv_arr_options) == FAILURE) { return; } argv = rrd_args_init_by_phparray("xport", "", zv_arr_options TSRMLS_CC); 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; } MAKE_STD_ZVAL(zv_data); 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; MAKE_STD_ZVAL(zv_var_data); array_init(zv_var_data); MAKE_STD_ZVAL(time_data); array_init(time_data); add_assoc_string(zv_var_data, "legend", legend_v[outvar_index], 1); 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 */ zval *zv_timestamp; MAKE_STD_ZVAL(zv_timestamp); ZVAL_LONG(zv_timestamp, time_index); convert_to_string(zv_timestamp); add_assoc_double(time_data, Z_STRVAL_P(zv_timestamp), *data_ptr); data_ptr += outvar_count; zval_dtor(zv_timestamp); } 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(), 1); } /* {{{ 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() /* }}} */ /* {{{ */ 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, NULL) 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, NULL) #endif PHP_FE(rrd_version, NULL) {NULL, NULL, NULL} }; /* }}} */ #ifdef COMPILE_DL_RRD ZEND_GET_MODULE(rrd) #endif /* {{{ PHP_MINIT_FUNCTION */ static PHP_MINIT_FUNCTION(rrd) { rrd_graph_minit(TSRMLS_C); rrd_create_minit(TSRMLS_C); rrd_update_minit(TSRMLS_C); 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 TSRMLS_DC) { uint i, option_count, args_counter = 2; 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; rrd_args *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; iargs[args_counter++] = estrdup(option.c); smart_str_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; icount; i++) efree(args->args[i]); efree(args->args); efree(args); } /* }}} */ php-5.6/rrd-1.1.3/php_rrd.h0000644000175100017510000000162412265443701014544 0ustar ondrejondrej/** * 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 "1.1.3" #ifdef ZTS #include "TSRM.h" #endif #ifndef zend_parse_parameters_none # define zend_parse_parameters_none() zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") #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 TSRMLS_DC); extern void rrd_args_free(rrd_args *args); #endif /* PHP_RRD_H */ php-5.6/rrd-1.1.3/config.m40000644000175100017510000000464412265443701014451 0ustar ondrejondrejdnl 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[=DIR] Include rrdtool support (requires rrdtool >= 1.3.x)]) 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 if test "$PHP_RRD" != "yes"; then AC_MSG_CHECKING(if rrdtool specified path is valid) if test -r "$PHP_RRD/include/rrd.h"; then RRDTOOL_INCDIR=$PHP_RRD/include RRDTOOL_LIBDIR=$PHP_RRD/$PHP_LIBDIR AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) AC_MSG_ERROR([The specified RRDTool path is invalid or the installation is incomplete Please specify another path or reinstall the rrdtool distribution]) fi else AC_MSG_CHECKING([for rrdtool header files in default paths]) for i in /usr /usr/local /usr/local/rrdtool /opt; do test -r $i/include/rrd.h && RRDTOOL_LIBDIR=$i/$PHP_LIBDIR && RRDTOOL_INCDIR=$i/include done if test -z "$RRDTOOL_INCDIR"; then AC_MSG_RESULT([not found]) AC_MSG_ERROR([Please reinstall the rrdtool distribution]) else AC_MSG_RESULT(found in $RRDTOOL_INCDIR) fi fi dnl Finish the setup PHP_ADD_INCLUDE($RRDTOOL_INCDIR) PHP_CHECK_LIBRARY(rrd, rrd_create, [ PHP_ADD_LIBRARY_WITH_PATH(rrd, $RRDTOOL_LIBDIR, RRD_SHARED_LIBADD) AC_DEFINE(HAVE_RRDTOOL, 1, [ ]) ], [ AC_MSG_ERROR([wrong rrd lib version or lib not found]) ], [ -L$RRDTOOL_LIBDIR ]) dnl save temporary LDFLAGS, necessary for PHP_CHECK_FUNC old_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -L$RRDTOOL_LIBDIR" dnl rrd_graph_v is available in 1.3.0+ PHP_CHECK_FUNC(rrd_graph_v, rrd) if test "$ac_cv_func_rrd_graph_v" != yes; then AC_MSG_ERROR([rrd lib version seems older than 1.3.0, update to 1.3.0+]) fi dnl rrd_lastupdate_r available in 1.4.0+ PHP_CHECK_FUNC(rrd_lastupdate_r, rrd) dnl rrdc_disconnect available in 1.4.0+ PHP_CHECK_FUNC(rrdc_disconnect, rrd) LDFLAGS=$old_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 php-5.6/rrd-1.1.3/rrd_update.c0000644000175100017510000001731712265443701015240 0ustar ondrejondrej/** * 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 #include "php.h" #include "php_rrd.h" #include "rrd_update.h" #include "zend_exceptions.h" #include "ext/standard/php_smart_str.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 { zend_object std; /** path to newly created rrd file */ char *file_path; } rrd_update_object; /* {{{ rrd_update_object_dtor close all resources and the memory allocated for our internal object */ static void rrd_update_object_dtor(void *object TSRMLS_DC) { rrd_update_object *intern_obj = (rrd_update_object *)object; if (intern_obj->file_path) efree(intern_obj->file_path); zend_object_std_dtor(&intern_obj->std TSRMLS_CC); efree(intern_obj); } /* }}} */ /* {{{ rrd_update_object_new creates new rrd update object */ static zend_object_value rrd_update_object_new(zend_class_entry *ce TSRMLS_DC) { rrd_update_object *intern_obj; zend_object_value retval; #if ZEND_MODULE_API_NO < 20100409 zval *tmp; #endif intern_obj = ecalloc(1, sizeof(*intern_obj)); zend_object_std_init(&intern_obj->std, ce TSRMLS_CC); intern_obj->file_path = NULL; #if ZEND_MODULE_API_NO >= 20100409 object_properties_init(&intern_obj->std, ce); #else zend_hash_copy(intern_obj->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval*) ); #endif retval.handle = zend_objects_store_put(intern_obj, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)rrd_update_object_dtor, NULL TSRMLS_CC ); retval.handlers = &rrd_update_handlers; return retval; } /* }}} */ /* {{{ proto void RRDUpdater::__construct(string path) creates new object for rrd update function */ PHP_METHOD(RRDUpdater, __construct) { rrd_update_object *intern_obj; char *path; int path_length; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_length) == FAILURE) { return; } intern_obj = (rrd_update_object*)zend_object_store_get_object(getThis() TSRMLS_CC); 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; char *time = NULL; int time_str_length = 0; int argc = ZEND_NUM_ARGS(); uint ds_count,i; /* string for all data source names formated for rrd_update call */ smart_str ds_names = {0}; /* string for all data source values for rrd_update call */ smart_str ds_vals = {0}; if (zend_parse_parameters(argc TSRMLS_CC, "a|s", &zv_values_array, &time, &time_str_length) == FAILURE) { return; } ds_count = zend_hash_num_elements(Z_ARRVAL_P(zv_values_array)); if (ds_count<=0) { RETURN_TRUE; } intern_obj = (rrd_update_object *)zend_object_store_get_object(getThis() TSRMLS_CC); if (php_check_open_basedir(intern_obj->file_path TSRMLS_CC)) { RETURN_FALSE; } if (time_str_length == 0) { if (argc > 1) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "time cannot be empty string", 0 TSRMLS_CC); return; } /* default time string, see rrdtool update man page, it's need to be freed */ time = estrdup("N"); } zend_hash_internal_pointer_reset(Z_ARRVAL_P(zv_values_array)); for (i=0; ifile_path, zv_update_argv TSRMLS_CC); 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); if (time_str_length == 0) efree(time); /* throw exception with rrd error string */ zend_throw_exception(zend_exception_get_default(TSRMLS_C), rrd_get_error(), 0 TSRMLS_CC); rrd_clear_error(); return; } /* parameter isn't presented and we alloced default one, so we need to * free this one */ if (time_str_length == 0) efree(time); 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; int filename_length; zval *zv_arr_options; rrd_args *argv; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &filename, &filename_length, &zv_arr_options) == FAILURE) { return; } if (php_check_open_basedir(filename TSRMLS_CC)) RETURN_FALSE; argv = rrd_args_init_by_phparray("update", filename, zv_arr_options TSRMLS_CC); 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); } /* }}} */ /* Arguments * it's necessary to use unique name e.g. arginfo_rrdcreator_construct because * in PHP < 5.3 ZEND_BEGIN_ARG_INFO_EX doesn't declare arginfo structure as * static */ 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) {NULL, NULL, NULL} }; /* minit hook, called from main module minit */ void rrd_update_minit(TSRMLS_D) { 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 TSRMLS_CC); memcpy(&rrd_update_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); rrd_update_handlers.clone_obj = NULL; } php-5.6/rrd-1.1.3/rrd_update.h0000644000175100017510000000071512265443701015237 0ustar ondrejondrej/** * 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(TSRMLS_D); PHP_FUNCTION(rrd_update); #endif /* RRD_UPDATE_H */ php-5.6/rrd-1.1.3/rrd_create.h0000644000175100017510000000071512265443701015220 0ustar ondrejondrej/** * 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(TSRMLS_D); PHP_FUNCTION(rrd_create); #endif /* RRD_CREATE_H */ php-5.6/rrd-1.1.3/rrd_create.c0000644000175100017510000002413312265443701015213 0ustar ondrejondrej/** * 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 #include "php.h" #include "rrd_create.h" #include "php_rrd.h" #include "zend_exceptions.h" #include "ext/standard/php_array.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 { zend_object std; /** 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; } rrd_create_object; /* {{{ rrd_create_object_dtor close all resources and the memory allocated for our internal object */ static void rrd_create_object_dtor(void *object TSRMLS_DC) { rrd_create_object *intern_obj = (rrd_create_object *)object; if (intern_obj->file_path) efree(intern_obj->file_path); if (intern_obj->start_time) efree(intern_obj->start_time); if (intern_obj->zv_step) zval_dtor(intern_obj->zv_step); if (intern_obj->zv_arr_data_sources) zval_dtor(intern_obj->zv_arr_data_sources); if (intern_obj->zv_arr_archives) zval_dtor(intern_obj->zv_arr_archives); zend_object_std_dtor(&intern_obj->std TSRMLS_CC); efree(intern_obj); } /* }}} */ /* {{{ rrd_create_object_new creates new rrd create object */ static zend_object_value rrd_create_object_new(zend_class_entry *ce TSRMLS_DC) { rrd_create_object *intern_obj; zend_object_value retval; #if ZEND_MODULE_API_NO < 20100409 zval *tmp; #endif intern_obj = ecalloc(1, sizeof(*intern_obj)); zend_object_std_init(&intern_obj->std, ce TSRMLS_CC); intern_obj->file_path = NULL; intern_obj->start_time = NULL; intern_obj->zv_step = NULL; intern_obj->zv_arr_data_sources = NULL; intern_obj->zv_arr_archives = NULL; #if ZEND_MODULE_API_NO >= 20100409 object_properties_init(&intern_obj->std, ce); #else zend_hash_copy(intern_obj->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval*) ); #endif retval.handle = zend_objects_store_put(intern_obj, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)rrd_create_object_dtor, NULL TSRMLS_CC ); retval.handlers = &rrd_create_handlers; return retval; } /* }}} */ /* {{{ 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; int path_length; /* better to set defaults for optional parameters */ char *start_time = NULL; int start_time_length = 0; long step = 0; int argc = ZEND_NUM_ARGS(); if (zend_parse_parameters(argc TSRMLS_CC, "s|sl", &path, &path_length, &start_time, &start_time_length, &step) == FAILURE) { return; } if (path_length == 0) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "path for rrd file cannot be empty string", 0 TSRMLS_CC); return; } if (argc > 1 && start_time_length == 0) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "startTime cannot be empty string", 0 TSRMLS_CC); return; } if (argc > 2 && step <= 0) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "step parameter must be greater then 0", 0 TSRMLS_CC); return; } intern_obj = (rrd_create_object*)zend_object_store_get_object(getThis() TSRMLS_CC); intern_obj->file_path = estrdup(path); if (start_time) intern_obj->start_time = estrdup(start_time); if (step) { MAKE_STD_ZVAL(intern_obj->zv_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; char *desc, *rrd_source_desc; int desc_length; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &desc, &desc_length) == FAILURE) { return; } if (desc_length == 0) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "description parameter cannot be empty string", 0 TSRMLS_CC); return; } intern_obj = (rrd_create_object*)zend_object_store_get_object(getThis() TSRMLS_CC); if (!intern_obj->zv_arr_data_sources) { MAKE_STD_ZVAL(intern_obj->zv_arr_data_sources); array_init(intern_obj->zv_arr_data_sources); } rrd_source_desc = emalloc(desc_length + 4); strcpy(rrd_source_desc, "DS:"); strcat(rrd_source_desc, desc); add_next_index_string(intern_obj->zv_arr_data_sources, rrd_source_desc, 1); 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; char *desc, *rrd_archive_desc; int desc_length; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &desc, &desc_length) == FAILURE) { return; } if (desc_length == 0) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "description parameter cannot be empty string", 0 TSRMLS_CC); return; } intern_obj = (rrd_create_object*)zend_object_store_get_object(getThis() TSRMLS_CC); if (!intern_obj->zv_arr_archives) { MAKE_STD_ZVAL(intern_obj->zv_arr_archives); array_init(intern_obj->zv_arr_archives); } rrd_archive_desc = emalloc(desc_length + 5); strcpy(rrd_archive_desc, "RRA:"); strcat(rrd_archive_desc, desc); add_next_index_string(intern_obj->zv_arr_archives, rrd_archive_desc, 1); 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 = (rrd_create_object *)zend_object_store_get_object(getThis() TSRMLS_CC); /* help structures for preparing arguments for rrd_create call */ zval *zv_create_argv; rrd_args *create_argv; MAKE_STD_ZVAL(zv_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, 1); efree(start_time_str); } if (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_P(intern_obj->zv_step) + 1); strcpy(start_time_str, prefix); strcat(start_time_str, Z_STRVAL_P(intern_obj->zv_step)); add_next_index_string(zv_create_argv, start_time_str, 1); /* 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_P(zv_create_argv), Z_ARRVAL_P(intern_obj->zv_arr_data_sources), 0 TSRMLS_CC); php_array_merge(Z_ARRVAL_P(zv_create_argv), Z_ARRVAL_P(intern_obj->zv_arr_archives), 0 TSRMLS_CC); create_argv = rrd_args_init_by_phparray("create", intern_obj->file_path, zv_create_argv TSRMLS_CC); 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(zend_exception_get_default(TSRMLS_C), rrd_get_error(), 0 TSRMLS_CC); 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; int filename_length; zval *zv_arr_options; rrd_args *argv; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &filename, &filename_length, &zv_arr_options) == FAILURE) { return; } if (php_check_open_basedir(filename TSRMLS_CC)) RETURN_FALSE; argv = rrd_args_init_by_phparray("create", filename, zv_arr_options TSRMLS_CC); 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); } /* }}} */ /* Arguments * it's necessary to use unique name e.g. arginfo_rrdcreator_construct because * in PHP < 5.3 ZEND_BEGIN_ARG_INFO_EX doesn't declare arginfo structure as * static */ 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() /* class method table */ static zend_function_entry rrd_create_methods[] = { PHP_ME(RRDCreator, __construct, arginfo_rrdcreator_construct, ZEND_ACC_PUBLIC) PHP_ME(RRDCreator, save, NULL, ZEND_ACC_PUBLIC) PHP_ME(RRDCreator, addDataSource, arginfo_rrdcreator_description, ZEND_ACC_PUBLIC) PHP_ME(RRDCreator, addArchive, arginfo_rrdcreator_description, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* minit hook, called from main module minit */ void rrd_create_minit(TSRMLS_D) { 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 TSRMLS_CC); memcpy(&rrd_create_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); rrd_create_handlers.clone_obj = NULL; } php-5.6/rrd-1.1.3/CREDITS0000644000175100017510000000024312265443701013751 0ustar ondrejondrejRRD Miroslav Kubelik Big Thanks: Joe Miller - author of first rrdtool extension Jeffrey Wheat, Dan Cech, Benny Baumann - patches and improvements php-5.6/rrd-1.1.3/LICENSE0000644000175100017510000000245112265443701013741 0ustar ondrejondrejCopyright (c) 2010 - 2011, 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. php-7.0/0000755000175100017510000000000012644400426011477 5ustar ondrejondrejphp-7.0/package.xml0000644000175100017510000002351412640215517013622 0ustar ondrejondrej 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 2015-12-28 2.0.0 1.1 stable stable BSD - utilize ZSTR macros for zend_string 7.0.0 1.4.0 rrd 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 php-7.0/rrd-2.0.0/0000755000175100017510000000000012644400426012721 5ustar ondrejondrejphp-7.0/rrd-2.0.0/tests/0000755000175100017510000000000012644400426014063 5ustar ondrejondrejphp-7.0/rrd-2.0.0/tests/data/0000755000175100017510000000000012644400426014774 5ustar ondrejondrejphp-7.0/rrd-2.0.0/tests/data/definition.inc0000644000175100017510000000073012640215517017620 0ustar ondrejondrejrrd_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 php-7.0/rrd-2.0.0/tests/rrd_001.phpt0000644000175100017510000000023512640215517016130 0ustar ondrejondrej--TEST-- rrd module presence test --SKIPIF-- --FILE-- --EXPECTF-- rrd extension loaded php-7.0/rrd-2.0.0/tests/rrd_002.phpt0000644000175100017510000000132712640215517016134 0ustar ondrejondrej--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) php-7.0/rrd-2.0.0/tests/rrd_003.phpt0000644000175100017510000000062012640215517016130 0ustar ondrejondrej--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) php-7.0/rrd-2.0.0/tests/rrd_004.phpt0000644000175100017510000000414612640215517016140 0ustar ondrejondrej--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) { } php-7.0/rrd-2.0.0/tests/rrd_005.phpt0000644000175100017510000000206112640215517016133 0ustar ondrejondrej--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 php-7.0/rrd-2.0.0/tests/rrd_006.phpt0000644000175100017510000000217212640215517016137 0ustar ondrejondrej--TEST-- rrd_update test --SKIPIF-- --FILE-- --EXPECTF-- exporting rrd_update_1.png via exec bool(true) php-7.0/rrd-2.0.0/tests/rrd_007.phpt0000644000175100017510000000050412640215517016135 0ustar ondrejondrej--TEST-- rrd_create test --SKIPIF-- --FILE-- --EXPECTF-- bool(true) php-7.0/rrd-2.0.0/tests/rrd_008.phpt0000644000175100017510000000176412640215517016147 0ustar ondrejondrej--TEST-- rrd_graph test --SKIPIF-- --FILE-- --EXPECTF-- exporting image via exec array(3) { ["xsize"]=> int(497) ["ysize"]=> int(%d) ["calcpr"]=> NULL } php-7.0/rrd-2.0.0/tests/rrd_009.phpt0000644000175100017510000000042212640215517016136 0ustar ondrejondrej--TEST-- rrd_error test --SKIPIF-- --FILE-- --EXPECTF-- string(31) "can't parse argument 'badParam'" bool(false)php-7.0/rrd-2.0.0/tests/rrd_010.phpt0000644000175100017510000000317112640215517016132 0ustar ondrejondrej--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.033333333333333) [920806500]=> float(0.033333333333333) [920806800]=> float(0.033333333333333) [920807100]=> float(0.02) [920807400]=> float(0.02) [920807700]=> float(0.02) [920808000]=> float(0.013333333333333) [920808300]=> float(0.016666666666667) } ["speed2"]=> array(13) { [920804700]=> float(NAN) [920805000]=> float(0.056666666666667) [920805300]=> float(0.02) [920805600]=> float(0.0033333333333333) [920805900]=> float(0) [920806200]=> float(0.03) [920806500]=> float(0) [920806800]=> float(0.066666666666667) [920807100]=> float(0.02) [920807400]=> float(0.02) [920807700]=> float(0.02) [920808000]=> float(0.013333333333333) [920808300]=> float(0.016666666666667) } } }php-7.0/rrd-2.0.0/tests/rrd_011.phpt0000644000175100017510000000071412640215517016133 0ustar ondrejondrej--TEST-- rrd_first test --SKIPIF-- --FILE-- --EXPECTF-- int(920802000) int(920791800) bool(false) bool(false) php-7.0/rrd-2.0.0/tests/rrd_012.phpt0000644000175100017510000000263312640215517016136 0ustar ondrejondrej--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.026666666666667) ["rra[1].cdp_prep[0].unknown_datapoints"]=> int(0) } bool(true) php-7.0/rrd-2.0.0/tests/rrd_013.phpt0000644000175100017510000000044612640215517016137 0ustar ondrejondrej--TEST-- rrd_last test --SKIPIF-- --FILE-- --EXPECTF-- int(920808900)php-7.0/rrd-2.0.0/tests/rrd_014.phpt0000644000175100017510000000151512640215517016136 0ustar ondrejondrej--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" } }php-7.0/rrd-2.0.0/tests/rrd_015.phpt0000644000175100017510000000120012640215517016126 0ustar ondrejondrej--TEST-- rrd_restore test --SKIPIF-- --FILE-- --EXPECTF-- bool(true) bool(true) bool(true) php-7.0/rrd-2.0.0/tests/rrd_016.phpt0000644000175100017510000000106012640215517016133 0ustar ondrejondrej--TEST-- rrd_tune test --SKIPIF-- --FILE-- --EXPECTF-- bool(true) bool(false) bool(true) %sphp-7.0/rrd-2.0.0/tests/rrd_017.phpt0000644000175100017510000000372712640215517016150 0ustar ondrejondrej--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.033333333333333) [920806500]=> float(0.033333333333333) [920806800]=> float(0.033333333333333) [920807100]=> float(0.02) [920807400]=> float(0.02) [920807700]=> float(0.02) [920808000]=> float(0.013333333333333) [920808300]=> float(0.016666666666667) } } [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.333333333333) [920806500]=> float(33.333333333333) [920806800]=> float(33.333333333333) [920807100]=> float(20) [920807400]=> float(20) [920807700]=> float(20) [920808000]=> float(13.333333333333) [920808300]=> float(16.666666666667) } } } } php-7.0/rrd-2.0.0/tests/rrd_018.phpt0000644000175100017510000000170612640215517016144 0ustar ondrejondrej--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) } php-7.0/rrd-2.0.0/tests/rrd_019.phpt0000644000175100017510000000216512640215517016145 0ustar ondrejondrej--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) php-7.0/rrd-2.0.0/tests/rrd_020.phpt0000644000175100017510000000037712640215517016140 0ustar ondrejondrej--TEST-- rrd_version test --SKIPIF-- --FILE-- = 2); ?> --EXPECTF-- string(%i) "%s" bool(true) bool(true) php-7.0/rrd-2.0.0/tests/rrd_021.phpt0000644000175100017510000000222712640215517016135 0ustar ondrejondrej--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) { } php-7.0/rrd-2.0.0/tests/rrd_022.phpt0000644000175100017510000000035412640215517016135 0ustar ondrejondrej--TEST-- rrdc_disconnect test --SKIPIF-- = 1.4"); } ?> --FILE-- --EXPECTF-- NULL php-7.0/rrd-2.0.0/tests/rrdtool-bin.inc.in0000644000175100017510000000016212640215517017416 0ustar ondrejondrej php-7.0/rrd-2.0.0/tests/skipif.inc0000644000175100017510000000012412640215517016041 0ustar ondrejondrej php-7.0/rrd-2.0.0/rrd_info.c0000644000175100017510000000426012640215517014672 0ustar ondrejondrej/** * 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 */ uint 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; } /* }}} */ php-7.0/rrd-2.0.0/rrd_info.h0000644000175100017510000000113212640215517014672 0ustar ondrejondrej/** * 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 uint rrd_info_toarray(const rrd_info_t *rrd_info_data, zval *array); #endif /* RRD_INFO_H */ php-7.0/rrd-2.0.0/rrd_graph.c0000644000175100017510000002352612640215517015046 0ustar ondrejondrej/** * 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) { 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) { uint 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) { uint 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_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, NULL, ZEND_ACC_PUBLIC) PHP_ME(RRDGraph, saveVerbose, NULL, 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; } php-7.0/rrd-2.0.0/rrd_graph.h0000644000175100017510000000071612640215517015047 0ustar ondrejondrej/** * 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 */ php-7.0/rrd-2.0.0/rrd.c0000644000175100017510000004174112640215517013664 0ustar ondrejondrej/** * 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; 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; uint 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 { uint 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 { uint 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; ulong step, outvar_count; char **legend_v; rrd_value_t *data, *data_ptr; zval zv_data; 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() /* }}} */ /* {{{ */ 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, NULL) 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, NULL) #endif PHP_FE(rrd_version, NULL) 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) { uint 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); } /* }}} */ php-7.0/rrd-2.0.0/php_rrd.h0000644000175100017510000000160012640215517014526 0ustar ondrejondrej/** * 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.0" #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 */ php-7.0/rrd-2.0.0/config.m40000644000175100017510000000464412640215517014441 0ustar ondrejondrejdnl 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[=DIR] Include rrdtool support (requires rrdtool >= 1.3.x)]) 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 if test "$PHP_RRD" != "yes"; then AC_MSG_CHECKING(if rrdtool specified path is valid) if test -r "$PHP_RRD/include/rrd.h"; then RRDTOOL_INCDIR=$PHP_RRD/include RRDTOOL_LIBDIR=$PHP_RRD/$PHP_LIBDIR AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) AC_MSG_ERROR([The specified RRDTool path is invalid or the installation is incomplete Please specify another path or reinstall the rrdtool distribution]) fi else AC_MSG_CHECKING([for rrdtool header files in default paths]) for i in /usr /usr/local /usr/local/rrdtool /opt; do test -r $i/include/rrd.h && RRDTOOL_LIBDIR=$i/$PHP_LIBDIR && RRDTOOL_INCDIR=$i/include done if test -z "$RRDTOOL_INCDIR"; then AC_MSG_RESULT([not found]) AC_MSG_ERROR([Please reinstall the rrdtool distribution]) else AC_MSG_RESULT(found in $RRDTOOL_INCDIR) fi fi dnl Finish the setup PHP_ADD_INCLUDE($RRDTOOL_INCDIR) PHP_CHECK_LIBRARY(rrd, rrd_create, [ PHP_ADD_LIBRARY_WITH_PATH(rrd, $RRDTOOL_LIBDIR, RRD_SHARED_LIBADD) AC_DEFINE(HAVE_RRDTOOL, 1, [ ]) ], [ AC_MSG_ERROR([wrong rrd lib version or lib not found]) ], [ -L$RRDTOOL_LIBDIR ]) dnl save temporary LDFLAGS, necessary for PHP_CHECK_FUNC old_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -L$RRDTOOL_LIBDIR" dnl rrd_graph_v is available in 1.3.0+ PHP_CHECK_FUNC(rrd_graph_v, rrd) if test "$ac_cv_func_rrd_graph_v" != yes; then AC_MSG_ERROR([rrd lib version seems older than 1.3.0, update to 1.3.0+]) fi dnl rrd_lastupdate_r available in 1.4.0+ PHP_CHECK_FUNC(rrd_lastupdate_r, rrd) dnl rrdc_disconnect available in 1.4.0+ PHP_CHECK_FUNC(rrdc_disconnect, rrd) LDFLAGS=$old_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 php-7.0/rrd-2.0.0/config.w320000644000175100017510000000120512640215517014522 0ustar ondrejondrej// vim: ft=javascript: ARG_WITH("rrd", "whether to enable RRD support", "no"); if ("no" != PHP_RRD) { if (CHECK_LIB("rrdlib.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"); } } php-7.0/rrd-2.0.0/rrd_update.c0000644000175100017510000001553312640215517015226 0ustar ondrejondrej/** * 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; } php-7.0/rrd-2.0.0/rrd_update.h0000644000175100017510000000070512640215517015226 0ustar ondrejondrej/** * 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 */ php-7.0/rrd-2.0.0/rrd_create.h0000644000175100017510000000070512640215517015207 0ustar ondrejondrej/** * 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 */ php-7.0/rrd-2.0.0/rrd_create.c0000644000175100017510000002250312640215517015202 0ustar ondrejondrej/** * 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() /* class method table */ static zend_function_entry rrd_create_methods[] = { PHP_ME(RRDCreator, __construct, arginfo_rrdcreator_construct, ZEND_ACC_PUBLIC) PHP_ME(RRDCreator, save, NULL, 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; } php-7.0/rrd-2.0.0/CREDITS0000644000175100017510000000032712640215517013744 0ustar ondrejondrejRRD 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 php-7.0/rrd-2.0.0/LICENSE0000644000175100017510000000245112640215517013731 0ustar ondrejondrejCopyright (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.