summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Collet <remi@remirepo.net>2020-04-06 16:25:35 +0200
committerRemi Collet <remi@remirepo.net>2020-04-06 16:25:35 +0200
commit1e01976460c4e6b10de9a26e486ab2b2871cbff4 (patch)
tree4e8130f1fb41d92b544b7799bb7a7404676ccc42
parent3e69ef1a847841608eacdd8683ff549562be55c4 (diff)
add rpmaddtag() function
-rw-r--r--package.xml6
-rw-r--r--php_rpminfo.h9
-rw-r--r--rpminfo.c83
-rw-r--r--tests/007-rpmdbinfo.phpt26
4 files changed, 106 insertions, 18 deletions
diff --git a/package.xml b/package.xml
index b66dbf5..81ab508 100644
--- a/package.xml
+++ b/package.xml
@@ -18,8 +18,8 @@ Available functions:
</lead>
<date>2020-03-25</date>
<version>
- <release>0.4.3dev</release>
- <api>0.4.0</api>
+ <release>0.5.0dev</release>
+ <api>0.5.0</api>
</version>
<stability>
<release>stable</release>
@@ -27,7 +27,7 @@ Available functions:
</stability>
<license>PHP 3.01</license>
<notes>
--
+- add rpmaddtag() function
</notes>
<contents>
<dir name="/">
diff --git a/php_rpminfo.h b/php_rpminfo.h
index 85adeef..87db8e9 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 "0.4.3-dev"
+#define PHP_RPMINFO_VERSION "0.5.0-dev"
#ifdef PHP_WIN32
# define PHP_RPMINFO_API __declspec(dllexport)
@@ -37,8 +37,11 @@ extern zend_module_entry rpminfo_module_entry;
#endif
ZEND_BEGIN_MODULE_GLOBALS(rpminfo)
- rpmts ts;
- rpmdb db;
+ rpmts ts; /* transaction set */
+ rpmdb db; /* database */
+ int nb_tags; /* stored tags */
+ int max_tags; /* allocated tags */
+ rpmTagVal *tags; /* tags storage */
ZEND_END_MODULE_GLOBALS(rpminfo)
#define RPMINFO_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(rpminfo, v)
diff --git a/rpminfo.c b/rpminfo.c
index 03053d8..a076cf9 100644
--- a/rpminfo.c
+++ b/rpminfo.c
@@ -61,22 +61,32 @@ static void rpm_header_to_zval(zval *return_value, Header h, zend_bool full)
rpmTagVal tag;
rpmTagType type;
const char *val;
+ int i;
array_init(return_value);
hi = headerInitIterator(h);
while ((tag=headerNextTag(hi)) != RPMTAG_NOT_FOUND) {
- switch (tag) {
- case RPMTAG_NAME:
- case RPMTAG_VERSION:
- case RPMTAG_RELEASE:
- case RPMTAG_EPOCH:
- case RPMTAG_ARCH:
- case RPMTAG_SUMMARY:
- break;
- default:
- if (!full) {
- continue;
- }
+ if (!full) {
+ switch (tag) {
+ case RPMTAG_NAME:
+ case RPMTAG_VERSION:
+ case RPMTAG_RELEASE:
+ case RPMTAG_EPOCH:
+ case RPMTAG_ARCH:
+ case RPMTAG_SUMMARY:
+ /* Always present tags */
+ break;
+ default:
+ /* Additional tags */
+ for (i=0 ; i<RPMINFO_G(nb_tags) ; i++) {
+ if (tag == RPMINFO_G(tags)[i]) {
+ break;
+ }
+ }
+ if (i==RPMINFO_G(nb_tags)) {
+ continue;
+ }
+ }
}
type = rpmTagGetTagType(tag);
@@ -516,6 +526,43 @@ PHP_FUNCTION(rpmvercmp)
}
/* }}} */
+#if PHP_VERSION_ID < 70200
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rpmaddtag, 0, 2, _IS_BOOL, NULL, 0)
+#else
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rpmaddtag, 0, 2, _IS_BOOL, 0)
+#endif
+ ZEND_ARG_TYPE_INFO(0, rpmtag, IS_LONG, 0)
+ZEND_END_ARG_INFO()
+
+/* {{{ proto int rpmaddtag(int tag)
+ add a tag in the default set */
+PHP_FUNCTION(rpmaddtag)
+{
+ int i;
+ zend_long tag;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &tag) == FAILURE) {
+ return;
+ }
+
+ if (RPMINFO_G(tags)) {
+ for (i=0 ; i<RPMINFO_G(nb_tags) ; i++) {
+ if (RPMINFO_G(tags)[i] == tag) {
+ RETURN_BOOL(0);
+ }
+ }
+ RPMINFO_G(max_tags) += 16;
+ RPMINFO_G(tags) = erealloc(RPMINFO_G(tags), RPMINFO_G(max_tags) * sizeof(rpmTagVal));
+ } else {
+ RPMINFO_G(max_tags) = 16;
+ RPMINFO_G(tags) = emalloc(RPMINFO_G(max_tags) * sizeof(rpmTagVal));
+ }
+ RPMINFO_G(tags)[RPMINFO_G(nb_tags)++] = tag;
+
+ RETURN_BOOL(1);
+}
+/* }}} */
+
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(rpminfo)
@@ -573,6 +620,10 @@ PHP_RINIT_FUNCTION(rpminfo)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
+ RPMINFO_G(nb_tags) = 0;
+ RPMINFO_G(max_tags) = 0;
+ RPMINFO_G(tags) = NULL;
+
return SUCCESS;
}
/* }}} */
@@ -590,6 +641,13 @@ PHP_RSHUTDOWN_FUNCTION(rpminfo)
RPMINFO_G(ts) = NULL;
}
+ if (RPMINFO_G(tags)) {
+ efree(RPMINFO_G(tags));
+ RPMINFO_G(nb_tags) = 0;
+ RPMINFO_G(max_tags) = 0;
+ RPMINFO_G(tags) = NULL;
+ }
+
return SUCCESS;
}
/* }}} */
@@ -627,6 +685,7 @@ static PHP_GINIT_FUNCTION(rpminfo) /* {{{ */
* Every user visible function must have an entry in rpminfo_functions[].
*/
const zend_function_entry rpminfo_functions[] = {
+ PHP_FE(rpmaddtag, arginfo_rpmaddtag)
PHP_FE(rpmdbinfo, arginfo_rpmdbinfo)
PHP_FE(rpmdbsearch, arginfo_rpmdbsearch)
PHP_FE(rpminfo, arginfo_rpminfo)
diff --git a/tests/007-rpmdbinfo.phpt b/tests/007-rpmdbinfo.phpt
index 4d142c7..4a977d1 100644
--- a/tests/007-rpmdbinfo.phpt
+++ b/tests/007-rpmdbinfo.phpt
@@ -6,6 +6,10 @@ Check for rpmdbinfo function on Name
<?php
var_dump(rpmdbinfo('doesntexistsinrpmdb'));
var_dump(rpmdbinfo('bash'));
+var_dump(rpmaddtag(RPMTAG_INSTALLTIME));
+var_dump(rpmaddtag(RPMTAG_BUILDTIME));
+var_dump(rpmaddtag(RPMTAG_INSTALLTIME));
+var_dump(rpmdbinfo('bash'));
?>
Done
--EXPECTF--
@@ -25,4 +29,26 @@ array(1) {
string(%d) "%s"
}
}
+bool(true)
+bool(true)
+bool(false)
+array(1) {
+ [0]=>
+ array(7) {
+ ["Name"]=>
+ string(4) "bash"
+ ["Version"]=>
+ string(%d) "%s"
+ ["Release"]=>
+ string(%d) "%s"
+ ["Summary"]=>
+ string(26) "The GNU Bourne Again shell"
+ ["Buildtime"]=>
+ int(%d)
+ ["Installtime"]=>
+ int(%d)
+ ["Arch"]=>
+ string(%d) "%s"
+ }
+}
Done