diff options
Diffstat (limited to 'rpminfo.c')
-rw-r--r-- | rpminfo.c | 74 |
1 files changed, 70 insertions, 4 deletions
@@ -30,6 +30,7 @@ #include <rpm/rpmio.h> #include <rpm/rpmlib.h> #include <rpm/rpmts.h> +#include <rpm/rpmmacro.h> #include "php_rpminfo.h" @@ -69,6 +70,13 @@ static rpmdb rpminfo_getdb(void) { return RPMINFO_G(db); } +static void rpminfo_closedb(void) { + if (RPMINFO_G(db)) { + rpmtsCloseDB(RPMINFO_G(ts)); + RPMINFO_G(db) = NULL; + } +} + static void rpm_header_to_zval(zval *return_value, Header h, zend_bool full) { HeaderIterator hi; @@ -867,6 +875,66 @@ 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 */ + + rpminfo_closedb(); /* Close the DB to allow path change */ + + result = rpmDefineMacro(NULL, macro, RMIL_GLOBAL); + + RETURN_BOOL(result == 0); +} +/* }}} */ /* {{{ PHP_MINIT_FUNCTION */ @@ -940,10 +1008,8 @@ PHP_RINIT_FUNCTION(rpminfo) PHP_RSHUTDOWN_FUNCTION(rpminfo) { if (RPMINFO_G(ts)) { - if (RPMINFO_G(db)) { - rpmtsCloseDB(RPMINFO_G(ts)); - RPMINFO_G(db) = NULL; - } + rpminfo_closedb(); + rpmtsFree(RPMINFO_G(ts)); RPMINFO_G(ts) = NULL; } |