summaryrefslogtreecommitdiffstats
path: root/rpminfo.c
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 /rpminfo.c
parentdeb0dd428220509aa74242a230586065c3df53ff (diff)
add rpmexpand, rpmexpandnumeric to retrieve rpm macro value
add rpmdefine to set rpm macro value
Diffstat (limited to 'rpminfo.c')
-rw-r--r--rpminfo.c59
1 files changed, 59 insertions, 0 deletions
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
*/