From 8997cc9cfca46c31d20a8e91372d63536f19ef0c Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 19 Dec 2024 09:08:31 +0100 Subject: add rpmexpand, rpmexpandnumeric to retrieve rpm macro value add rpmdefine to set rpm macro value --- package.xml | 7 +++--- php_rpminfo.h | 2 +- rpminfo.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ rpminfo.stub.php | 7 ++++++ rpminfo_arginfo.h | 20 ++++++++++++++++- tests/015-rpmmacro.phpt | 25 +++++++++++++++++++++ 6 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 tests/015-rpmmacro.phpt diff --git a/package.xml b/package.xml index 9f29bbe..172eba6 100644 --- a/package.xml +++ b/package.xml @@ -15,8 +15,8 @@ Documentation: https://www.php.net/rpminfo 2024-09-03 - 1.1.2dev - 1.1.0 + 1.2.0dev + 1.2.0 stable @@ -24,7 +24,8 @@ Documentation: https://www.php.net/rpminfo PHP-3.01 diff --git a/php_rpminfo.h b/php_rpminfo.h index 6f54208..44f5955 100644 --- a/php_rpminfo.h +++ b/php_rpminfo.h @@ -22,7 +22,7 @@ extern zend_module_entry rpminfo_module_entry; #define phpext_rpminfo_ptr &rpminfo_module_entry -#define PHP_RPMINFO_VERSION "1.1.2-dev" +#define PHP_RPMINFO_VERSION "1.2.0-dev" #define PHP_RPMINFO_AUTHOR "Remi Collet" #define PHP_RPMINFO_LICENSE "PHP-3.01" diff --git a/rpminfo.c b/rpminfo.c index 55a5351..17d08b4 100644 --- a/rpminfo.c +++ b/rpminfo.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "php_rpminfo.h" @@ -867,6 +868,64 @@ PHP_FUNCTION(rpmgetsymlink) } /* }}} */ +/* {{{ proto array rpmexpand(string $text): string + Expand macro in text */ +PHP_FUNCTION(rpmexpand) +{ + char *text, *result; + size_t len; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &text, &len) == FAILURE) { + RETURN_THROWS(); + } + + (void)rpminfo_getts(); // read config files + + result = rpmExpand(text, NULL); + RETVAL_STRING(result); + free(result); +} +/* }}} */ + +/* {{{ proto array rpmexpandnumeric(string $text): int + Expand macro in text */ +PHP_FUNCTION(rpmexpandnumeric) +{ + char *text; + size_t len; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &text, &len) == FAILURE) { + RETURN_THROWS(); + } + + (void)rpminfo_getts(); // read config files + + result = rpmExpandNumeric(text); + + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto array rpmdefine(string $macro): bool + Define a new macro */ +PHP_FUNCTION(rpmdefine) +{ + char *macro; + size_t len; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", ¯o, &len) == FAILURE) { + RETURN_THROWS(); + } + + (void)rpminfo_getts(); // read config files + + result = rpmDefineMacro(NULL, macro, RMIL_GLOBAL); + + RETURN_BOOL(result == 0); +} +/* }}} */ /* {{{ PHP_MINIT_FUNCTION */ diff --git a/rpminfo.stub.php b/rpminfo.stub.php index aa87215..026df4b 100644 --- a/rpminfo.stub.php +++ b/rpminfo.stub.php @@ -13,3 +13,10 @@ function rpminfo(string $path, bool $full = false, ?string &$error = null): Arra function rpmvercmp(string $evr1, string $evr2, ?string $operator = null): int|bool {} function rpmgetsymlink(string $path, string $name): string|null {} + +function rpmexpand(string $text): string {} + +function rpmexpandnumeric(string $text): int {} + +function rpmdefine(string $macro): bool {} + diff --git a/rpminfo_arginfo.h b/rpminfo_arginfo.h index 0764f6f..6db4fed 100644 --- a/rpminfo_arginfo.h +++ b/rpminfo_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 6b129e53b21eb21027683874775c2cdb7d1d485d */ + * Stub hash: dc980a56084190700162f5a8c70b54fcdbc30ced */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rpmaddtag, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, rpmtag, IS_LONG, 0) @@ -34,6 +34,18 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rpmgetsymlink, 0, 2, IS_STRING, ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rpmexpand, 0, 1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rpmexpandnumeric, 0, 1, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rpmdefine, 0, 1, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, macro, IS_STRING, 0) +ZEND_END_ARG_INFO() + ZEND_FUNCTION(rpmaddtag); ZEND_FUNCTION(rpmdbinfo); @@ -41,6 +53,9 @@ ZEND_FUNCTION(rpmdbsearch); ZEND_FUNCTION(rpminfo); ZEND_FUNCTION(rpmvercmp); ZEND_FUNCTION(rpmgetsymlink); +ZEND_FUNCTION(rpmexpand); +ZEND_FUNCTION(rpmexpandnumeric); +ZEND_FUNCTION(rpmdefine); static const zend_function_entry ext_functions[] = { @@ -50,5 +65,8 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(rpminfo, arginfo_rpminfo) ZEND_FE(rpmvercmp, arginfo_rpmvercmp) ZEND_FE(rpmgetsymlink, arginfo_rpmgetsymlink) + ZEND_FE(rpmexpand, arginfo_rpmexpand) + ZEND_FE(rpmexpandnumeric, arginfo_rpmexpandnumeric) + ZEND_FE(rpmdefine, arginfo_rpmdefine) ZEND_FE_END }; diff --git a/tests/015-rpmmacro.phpt b/tests/015-rpmmacro.phpt new file mode 100644 index 0000000..13a92e1 --- /dev/null +++ b/tests/015-rpmmacro.phpt @@ -0,0 +1,25 @@ +--TEST-- +Check for rpmdefine, rpmexpand, rpmexpandnumeric +--SKIPIF-- + +--FILE-- + 0); + +$name = "_my_test_macro_for_rpminfo_"; +$val = __FILE__; +var_dump(rpmexpand("%$name") === "%$name" ); +var_dump(rpmdefine("$name $val")); +var_dump(rpmexpand("%$name") === __FILE__); +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + -- cgit