summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Collet <remi@remirepo.net>2024-12-19 09:08:31 +0100
committerRemi Collet <remi@php.net>2024-12-19 09:08:31 +0100
commit8997cc9cfca46c31d20a8e91372d63536f19ef0c (patch)
tree405dfdb8633845faa8ca151b77885fa15d2493af
parentdeb0dd428220509aa74242a230586065c3df53ff (diff)
add rpmexpand, rpmexpandnumeric to retrieve rpm macro value
add rpmdefine to set rpm macro value
-rw-r--r--package.xml7
-rw-r--r--php_rpminfo.h2
-rw-r--r--rpminfo.c59
-rw-r--r--rpminfo.stub.php7
-rw-r--r--rpminfo_arginfo.h20
-rw-r--r--tests/015-rpmmacro.phpt25
6 files changed, 115 insertions, 5 deletions
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
</lead>
<date>2024-09-03</date>
<version>
- <release>1.1.2dev</release>
- <api>1.1.0</api>
+ <release>1.2.0dev</release>
+ <api>1.2.0</api>
</version>
<stability>
<release>stable</release>
@@ -24,7 +24,8 @@ Documentation: https://www.php.net/rpminfo
</stability>
<license uri="https://www.php.net/license/3_01.txt" filesource="LICENSE">PHP-3.01</license>
<notes><![CDATA[
--
+- add rpmexpand, rpmexpandnumeric to retrieve rpm macro value
+- add rpmdefine to set rpm macro value
]]></notes>
<contents>
<dir name="/">
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 <rpm/rpmio.h>
#include <rpm/rpmlib.h>
#include <rpm/rpmts.h>
+#include <rpm/rpmmacro.h>
#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", &macro, &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--
+<?php if (!extension_loaded("rpminfo")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(is_dir(rpmexpand("%{_dbpath}")));
+
+var_dump(rpmexpandnumeric("%__isa_bits") === PHP_INT_SIZE * 8);
+var_dump(rpmexpandnumeric("0%{?fedora}%{?rhel}") > 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)
+