diff options
author | Remi Collet <remi@remirepo.net> | 2020-03-11 15:31:48 +0100 |
---|---|---|
committer | Remi Collet <remi@remirepo.net> | 2020-03-11 15:31:48 +0100 |
commit | db270c6c4667957045127ad04af206ce48e9a5c8 (patch) | |
tree | d11a4957179e9c969fc5eab53183d55e83950889 /rpminfo.c | |
parent | 2e3e6f8220d68a5e62197d51aed16a3e08da223b (diff) |
add match_mode parameters to rpmdbinfo function
allowing to search packages with name matching a glob or a regex
Diffstat (limited to 'rpminfo.c')
-rw-r--r-- | rpminfo.c | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -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; } /* }}} */ |