summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--REFLECTION27
-rw-r--r--examples/librpm.php47
-rw-r--r--package.xml3
-rw-r--r--rpminfo.c87
-rw-r--r--tests/003-rpminfo.phpt2
-rw-r--r--tests/bidon-src.rpmbin6257 -> 6336 bytes
-rw-r--r--tests/bidon.rpmbin6808 -> 6972 bytes
7 files changed, 161 insertions, 5 deletions
diff --git a/REFLECTION b/REFLECTION
index bc1a151..f31edc4 100644
--- a/REFLECTION
+++ b/REFLECTION
@@ -1,7 +1,30 @@
-Extension [ <persistent> extension #15 rpminfo version 0.2.0 ] {
+Extension [ <persistent> extension #15 rpminfo version 0.2.1-dev ] {
- - Constants [1] {
+ - Constants [24] {
Constant [ string RPMVERSION ] { 4.14.1 }
+ Constant [ integer RPMSENSE_ANY ] { 0 }
+ Constant [ integer RPMSENSE_LESS ] { 2 }
+ Constant [ integer RPMSENSE_GREATER ] { 4 }
+ Constant [ integer RPMSENSE_EQUAL ] { 8 }
+ Constant [ integer RPMSENSE_POSTTRANS ] { 32 }
+ Constant [ integer RPMSENSE_PREREQ ] { 64 }
+ Constant [ integer RPMSENSE_PRETRANS ] { 128 }
+ Constant [ integer RPMSENSE_INTERP ] { 256 }
+ Constant [ integer RPMSENSE_SCRIPT_PRE ] { 512 }
+ Constant [ integer RPMSENSE_SCRIPT_POST ] { 1024 }
+ Constant [ integer RPMSENSE_SCRIPT_PREUN ] { 2048 }
+ Constant [ integer RPMSENSE_SCRIPT_POSTUN ] { 4096 }
+ Constant [ integer RPMSENSE_SCRIPT_VERIFY ] { 8192 }
+ Constant [ integer RPMSENSE_FIND_REQUIRES ] { 16384 }
+ Constant [ integer RPMSENSE_FIND_PROVIDES ] { 32768 }
+ Constant [ integer RPMSENSE_TRIGGERIN ] { 65536 }
+ Constant [ integer RPMSENSE_TRIGGERUN ] { 131072 }
+ Constant [ integer RPMSENSE_TRIGGERPOSTUN ] { 262144 }
+ Constant [ integer RPMSENSE_MISSINGOK ] { 524288 }
+ Constant [ integer RPMSENSE_RPMLIB ] { 16777216 }
+ Constant [ integer RPMSENSE_TRIGGERPREIN ] { 33554432 }
+ Constant [ integer RPMSENSE_KEYRING ] { 67108864 }
+ Constant [ integer RPMSENSE_CONFIG ] { 268435456 }
}
- Functions {
diff --git a/examples/librpm.php b/examples/librpm.php
index 90082e0..b012e54 100644
--- a/examples/librpm.php
+++ b/examples/librpm.php
@@ -7,6 +7,28 @@ namespace Remi\RPM;
abstract class Common {
protected $info = NULL;
+ protected function _dep(Array $names, Array $flags, Array $vers) {
+ $ret = [];
+ $signs = [
+ RPMSENSE_EQUAL => ' = ',
+ RPMSENSE_LESS => ' < ',
+ RPMSENSE_GREATER => ' > ',
+ RPMSENSE_LESS | RPMSENSE_EQUAL => ' <= ',
+ RPMSENSE_GREATER | RPMSENSE_EQUAL => ' >= ',
+ ];
+
+ if (count($names) == count($vers) && count($vers) == count($flags)) {
+ for ($i=0 ; $i<count($names) ; $i++) {
+ if (isset($signs[$flags[$i] & 15])) {
+ $ret[] = $names[$i] . $signs[$flags[$i] & 15] . $vers[$i];
+ } else {
+ $ret[] = $names[$i] . '('. ($flags[$i] & 15) .')' . $vers[$i];
+ }
+ }
+ }
+ return $ret;
+ }
+
public function __get($name) {
switch ($name) {
case 'EVR':
@@ -25,6 +47,22 @@ abstract class Common {
$ret .= '.' . $this->info['Arch'];
}
return $ret;
+ case 'Requires':
+ if (isset($this->info['Requirename'])) {
+ return $this->_dep($this->info['Requirename'], $this->info['Requireflags'], $this->info['Requireversion']);
+ }
+ case 'Conflicts':
+ if (isset($this->info['Conflictname'])) {
+ return $this->_dep($this->info['Conflictname'], $this->info['Conflictflags'], $this->info['Conflictversion']);
+ }
+ case 'Obsoletes':
+ if (isset($this->info['Obsoletename'])) {
+ return $this->_dep($this->info['Obsoletename'], $this->info['Obsoleteflags'], $this->info['Obsoleteversion']);
+ }
+ case 'Provides':
+ if (isset($this->info['Providename'])) {
+ return $this->_dep($this->info['Providename'], $this->info['Provideflags'], $this->info['Provideversion']);
+ }
default:
if (isset($this->info[$name])) {
return $this->info[$name];
@@ -76,3 +114,12 @@ class Package extends Common {
}
}
+
+/*
+$a = new File(dirname(__DIR__).'/tests/bidon.rpm');
+echo "Requires: "; print_r($a->Requires);
+echo "Provides: "; print_r($a->Provides);
+echo "Conflicts: "; print_r($a->Conflicts);
+echo "Obsoletes: "; print_r($a->Obsoletes);
+*/
+
diff --git a/package.xml b/package.xml
index ab41d56..dbba8ae 100644
--- a/package.xml
+++ b/package.xml
@@ -27,7 +27,8 @@ Available functions:
<license>PHP 3.01</license>
<notes>
- add summary in minimal information set
-- retrieve array of strings from metadata
+- retrieve array from metadata
+- add RPMSENSE_* macros
</notes>
<contents>
<dir name="/">
diff --git a/rpminfo.c b/rpminfo.c
index f594771..263270a 100644
--- a/rpminfo.c
+++ b/rpminfo.c
@@ -69,6 +69,7 @@ static void rpm_header_to_zval(zval *return_value, Header h, zend_bool full)
}
}
+ //printf("Tag: %-30s Type: %8lx - %8lx - %8lx\n", rpmTagGetName(tag), (long)rpmTagGetTagType(tag), (long)rpmTagGetType(tag), (long)rpmTagGetReturnType(tag));
type = rpmTagGetTagType(tag);
switch (type) {
case RPM_STRING_TYPE:
@@ -82,10 +83,70 @@ static void rpm_header_to_zval(zval *return_value, Header h, zend_bool full)
break;
case RPM_CHAR_TYPE:
case RPM_INT8_TYPE:
+ add_assoc_long(return_value, rpmTagGetName(tag), (zend_long)headerGetNumber(h, tag));
+ break;
case RPM_INT16_TYPE:
+ if (rpmTagGetReturnType(tag) == RPM_ARRAY_RETURN_TYPE) {
+ struct rpmtd_s keys;
+ if (headerGet(h, tag, &keys, HEADERGET_MINMEM)) {
+ uint16_t *key;
+ zval tmp;
+
+ array_init(&tmp);
+ rpmtdInit(&keys);
+ while (rpmtdNext(&keys)>=0) {
+ key = rpmtdGetUint16(&keys);
+ add_next_index_long(&tmp, (zend_long)*key);
+ }
+ add_assoc_zval(return_value, rpmTagGetName(tag), &tmp);
+ } else {
+ add_assoc_null(return_value, rpmTagGetName(tag));
+ }
+ } else {
+ add_assoc_long(return_value, rpmTagGetName(tag), (zend_long)headerGetNumber(h, tag));
+ }
+ break;
case RPM_INT32_TYPE:
+ if (rpmTagGetReturnType(tag) == RPM_ARRAY_RETURN_TYPE) {
+ struct rpmtd_s keys;
+ if (headerGet(h, tag, &keys, HEADERGET_MINMEM)) {
+ uint32_t *key;
+ zval tmp;
+
+ array_init(&tmp);
+ rpmtdInit(&keys);
+ while (rpmtdNext(&keys)>=0) {
+ key = rpmtdGetUint32(&keys);
+ add_next_index_long(&tmp, (zend_long)*key);
+ }
+ add_assoc_zval(return_value, rpmTagGetName(tag), &tmp);
+ } else {
+ add_assoc_null(return_value, rpmTagGetName(tag));
+ }
+ } else {
+ add_assoc_long(return_value, rpmTagGetName(tag), (zend_long)headerGetNumber(h, tag));
+ }
+ break;
case RPM_INT64_TYPE:
- add_assoc_long(return_value, rpmTagGetName(tag), (zend_long)headerGetNumber(h, tag));
+ if (rpmTagGetReturnType(tag) == RPM_ARRAY_RETURN_TYPE) {
+ struct rpmtd_s keys;
+ if (headerGet(h, tag, &keys, HEADERGET_MINMEM)) {
+ uint64_t *key;
+ zval tmp;
+
+ array_init(&tmp);
+ rpmtdInit(&keys);
+ while (rpmtdNext(&keys)>=0) {
+ key = rpmtdGetUint64(&keys);
+ add_next_index_long(&tmp, (zend_long)*key);
+ }
+ add_assoc_zval(return_value, rpmTagGetName(tag), &tmp);
+ } else {
+ add_assoc_null(return_value, rpmTagGetName(tag));
+ }
+ } else {
+ add_assoc_long(return_value, rpmTagGetName(tag), (zend_long)headerGetNumber(h, tag));
+ }
break;
case RPM_STRING_ARRAY_TYPE:
{
@@ -245,6 +306,30 @@ PHP_MINIT_FUNCTION(rpminfo)
{
REGISTER_STRING_CONSTANT("RPMVERSION", (char *)RPMVERSION, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_ANY", RPMSENSE_ANY, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_LESS", RPMSENSE_LESS, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_GREATER", RPMSENSE_GREATER, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_EQUAL", RPMSENSE_EQUAL, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_POSTTRANS", RPMSENSE_POSTTRANS, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_PREREQ", RPMSENSE_PREREQ, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_PRETRANS", RPMSENSE_PRETRANS, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_INTERP", RPMSENSE_INTERP, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_SCRIPT_PRE", RPMSENSE_SCRIPT_PRE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_SCRIPT_POST", RPMSENSE_SCRIPT_POST, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_SCRIPT_PREUN", RPMSENSE_SCRIPT_PREUN, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_SCRIPT_POSTUN", RPMSENSE_SCRIPT_POSTUN, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_SCRIPT_VERIFY", RPMSENSE_SCRIPT_VERIFY, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_FIND_REQUIRES", RPMSENSE_FIND_REQUIRES, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_FIND_PROVIDES", RPMSENSE_FIND_PROVIDES, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_TRIGGERIN", RPMSENSE_TRIGGERIN, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_TRIGGERUN", RPMSENSE_TRIGGERUN, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_TRIGGERPOSTUN", RPMSENSE_TRIGGERPOSTUN, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_MISSINGOK", RPMSENSE_MISSINGOK, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_RPMLIB", RPMSENSE_RPMLIB, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_TRIGGERPREIN", RPMSENSE_TRIGGERPREIN, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_KEYRING", RPMSENSE_KEYRING, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("RPMSENSE_CONFIG", RPMSENSE_CONFIG, CONST_CS | CONST_PERSISTENT);
+
return SUCCESS;
}
/* }}} */
diff --git a/tests/003-rpminfo.phpt b/tests/003-rpminfo.phpt
index e5e01ab..beb7b47 100644
--- a/tests/003-rpminfo.phpt
+++ b/tests/003-rpminfo.phpt
@@ -14,7 +14,7 @@ array(5) {
["Version"]=>
string(1) "1"
["Release"]=>
- string(11) "1.fc25.remi"
+ string(11) "1.fc27.remi"
["Summary"]=>
string(5) "Bidon"
["Arch"]=>
diff --git a/tests/bidon-src.rpm b/tests/bidon-src.rpm
index c1c05cf..7943ac6 100644
--- a/tests/bidon-src.rpm
+++ b/tests/bidon-src.rpm
Binary files differ
diff --git a/tests/bidon.rpm b/tests/bidon.rpm
index 259ddf6..6cbfa04 100644
--- a/tests/bidon.rpm
+++ b/tests/bidon.rpm
Binary files differ