summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md69
-rw-r--r--package.xml3
-rw-r--r--rpminfo.c22
3 files changed, 89 insertions, 5 deletions
diff --git a/README.md b/README.md
index 9461c22..8d42ae9 100644
--- a/README.md
+++ b/README.md
@@ -97,12 +97,77 @@ The return value is an array of hash tables, or false if it fails.
[0] => Array
(
[Name] => php
- [Version] => 7.2.2
- [Release] => 1.fc27.remi
+ [Version] => 7.3.5
+ [Release] => 1.fc31.remi
+ [Summary] => PHP scripting language for creating dynamic web sites
[Arch] => x86_64
)
)
+Retrieve information from rpm database about installed packages using glob or regex.
+The return value is an array of hash tables, or false if it fails.
+
+ $ php -a
+ php > print_r(rpmdbinfo("php-pecl-r*", false, RPM_MATCH_GLOB));
+ Array
+ (
+ [0] => Array
+ (
+ [Name] => php-pecl-radius
+ [Version] => 1.4.0
+ [Release] => 0.10.b1.fc31
+ [Summary] => Radius client library
+ [Arch] => x86_64
+ )
+ [1] => Array
+ (
+ [Name] => php-pecl-request
+ [Version] => 1.0.0
+ [Release] => 0.11.b2.fc31.remi.7.3
+ [Summary] => Server-side request and response objects
+ [Arch] => x86_64
+ )
+ [2] => Array
+ (
+ [Name] => php-pecl-rpminfo
+ [Version] => 0.2.3
+ [Release] => 1.fc31.remi.7.3
+ [Summary] => RPM information
+ [Arch] => x86_64
+ )
+ )
+
+ $ php -a
+ php > print_r(rpmdbinfo("^php-pecl-r", false, RPM_MATCH_REGEX));
+ Array
+ (
+ [0] => Array
+ (
+ [Name] => php-pecl-radius
+ [Version] => 1.4.0
+ [Release] => 0.10.b1.fc31
+ [Summary] => Radius client library
+ [Arch] => x86_64
+ )
+ [1] => Array
+ (
+ [Name] => php-pecl-request
+ [Version] => 1.0.0
+ [Release] => 0.11.b2.fc31.remi.7.3
+ [Summary] => Server-side request and response objects
+ [Arch] => x86_64
+ )
+ [2] => Array
+ (
+ [Name] => php-pecl-rpminfo
+ [Version] => 0.2.3
+ [Release] => 1.fc31.remi.7.3
+ [Summary] => RPM information
+ [Arch] => x86_64
+ )
+ )
+
+
----
# LICENSE
diff --git a/package.xml b/package.xml
index 01360d6..b5c6e65 100644
--- a/package.xml
+++ b/package.xml
@@ -26,7 +26,8 @@ Available functions:
</stability>
<license>PHP 3.01</license>
<notes>
--
+- add match_mode parameters to rpmdbinfo function allowing
+ to search packages with name matching a glob or a regex.
</notes>
<contents>
<dir name="/">
diff --git a/rpminfo.c b/rpminfo.c
index 4a6abea..fdf9d93 100644
--- a/rpminfo.c
+++ b/rpminfo.c
@@ -247,6 +247,7 @@ PHP_FUNCTION(rpminfo)
ZEND_BEGIN_ARG_INFO_EX(arginfo_rpmdbinfo, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_ARG_INFO(0, full)
+ ZEND_ARG_INFO(0, match_mode)
ZEND_END_ARG_INFO()
/* {{{ proto array rpmdbinfo(string name [, bool full [, string &$error])
@@ -256,22 +257,35 @@ PHP_FUNCTION(rpmdbinfo)
char *name;
size_t len;
zend_bool full = 0;
+ zend_long mode = 0;
Header h;
rpmdb db;
rpmdbMatchIterator di;
rpmts ts = rpminfo_getts(_RPMVSF_NODIGESTS | _RPMVSF_NOSIGNATURES | RPMVSF_NOHDRCHK);
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|b", &name, &len, &full) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|bl", &name, &len, &full, &mode) == FAILURE) {
return;
}
rpmtsOpenDB(ts, O_RDONLY);
db = rpmtsGetRdb(ts);
- di = rpmdbInitIterator(db, RPMTAG_NAME, name, len);
+ if (mode) {
+ di = rpmdbInitIterator(db, RPMTAG_NAME, NULL, 0);
+ } else {
+ di = rpmdbInitIterator(db, RPMTAG_NAME, name, len);
+ }
if (!di) {
+ php_error_docref(NULL, E_WARNING, "Can't open rpmdb");
rpmtsCloseDB(ts);
RETURN_FALSE;
}
+ if (mode) {
+ if (rpmdbSetIteratorRE(di, RPMTAG_NAME, mode, name)) {
+ php_error_docref(NULL, E_WARNING, "Can't set filter");
+ rpmtsCloseDB(ts);
+ RETURN_FALSE;
+ }
+ }
array_init(return_value);
while ((h = rpmdbNextIterator(di)) != NULL) {
@@ -389,6 +403,10 @@ PHP_MINIT_FUNCTION(rpminfo)
REGISTER_LONG_CONSTANT("RPMSENSE_KEYRING", RPMSENSE_KEYRING, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("RPMSENSE_CONFIG", RPMSENSE_CONFIG, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPM_MATCH_EQUAL", 0, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPM_MATCH_REGEX", RPMMIRE_REGEX, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPM_MATCH_GLOB", RPMMIRE_GLOB, CONST_CS | CONST_PERSISTENT);
+
return SUCCESS;
}
/* }}} */