portdb: reimplemented XML output format support

This commit is contained in:
Matt Housh 2024-03-22 16:20:49 -05:00
parent 70e3eab922
commit 84208a533c
Signed by: jaeger
GPG Key ID: F9DE89ED1BFADFD7
4 changed files with 205 additions and 60 deletions

View File

@ -20,6 +20,17 @@
EOD; EOD;
return $this->out; return $this->out;
} }
public function rowToXML() {
$this->out = <<<EOD
<duplicate>
<name>$this->name</name>
<count>$this->count</count>
</duplicate>\n
EOD;
return $this->out;
}
} }
?> ?>

View File

@ -56,6 +56,48 @@
EOD; EOD;
return $this->out; return $this->out;
} }
public function filesToXML() {
$xml = "";
if ($this->type == "httpup") {
$base_url = "{$this->url}";
} else {
$base_url = localrepo($this->repo);
}
if ($base_url != "") {
$base_url = chop($base_url, "/");
$xml .= "<pkgfile>{$base_url}/{$this->name}/Pkgfile</pkgfile>\n";
$xml .= " <footprint>{$base_url}/{$this->name}/.footprint</footprint>\n";
$xml .= " <signature>{$base_url}/{$this->name}/.signature</signature>";
}
return $xml;
}
public function rowToXML() {
$downloadcmd = $this->downloadCmd();
$this->out = <<<EOD
<port>
<name>$this->name</name>
<repo>$this->repo</repo>\n
EOD;
if ($this->type == "httpup") {
$files = $this->filesToXML();
$this->out .= <<<EOD
<files>
$files
</files>\n
EOD;
}
$this->out .= <<<EOD
<command>$downloadcmd</command>
</port>\n
EOD;
return $this->out;
}
} }
?> ?>

View File

@ -63,6 +63,21 @@ EOD;
return $this->out; return $this->out;
} }
public function rowToXML() {
$maintainer = $this->obfuscate($this->maintainer);
$this->out = <<<EOD
<repo>
<name>$this->name</name>
<maintainer>$maintainer</maintainer>
<type>$this->type</type>
<url>$this->url</url>
<ports>$this->numports</ports>
<publickey>$this->pubkey</publickey>
</repo>\n
EOD;
return $this->out;
}
public function getSyncFile() { public function getSyncFile() {
$maintainer = $this->obfuscate($this->maintainer); $maintainer = $this->obfuscate($this->maintainer);
$content = ''; $content = '';

View File

@ -20,6 +20,10 @@
print file_get_contents('footer.html'); print file_get_contents('footer.html');
} }
function xmlDocType() {
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
}
function localrepo($name) { function localrepo($name) {
global $cruxver; global $cruxver;
@ -40,6 +44,10 @@
if (isset($_GET['f'])) { $format = sanitize($_GET['f']); } else $format = null; if (isset($_GET['f'])) { $format = sanitize($_GET['f']); } else $format = null;
if (isset($_GET['s'])) { $strict = sanitize($_GET['s']); } else $strict = null; if (isset($_GET['s'])) { $strict = sanitize($_GET['s']); } else $strict = null;
if ($format == "xml") {
header('Content-Type: application/xml');
}
switch ($action) { switch ($action) {
case "repo": case "repo":
# individual repo index # individual repo index
@ -63,6 +71,22 @@
array_push($ports, $port); array_push($ports, $port);
} }
if ($format == "xml") {
# doctype
xmlDocType();
$out = "<ports>\n";
# add ports
foreach ($ports as $port) {
$out .= $port->rowToXML();
}
# end
$out .= "</ports>\n";
print($out);
} else {
# header # header
printHeader(); printHeader();
@ -96,6 +120,8 @@ EOD;
# footer # footer
printFooter(); printFooter();
}
break; break;
case "search": case "search":
@ -125,6 +151,22 @@ EOD;
} }
} }
if ($format == "xml") {
# doctype
xmlDocType();
$out = "<ports>\n";
# add ports
foreach ($ports as $port) {
$out .= $port->rowToXML();
}
# end
$out .= "</ports>\n";
print($out);
} else {
# header # header
printHeader(); printHeader();
@ -173,6 +215,8 @@ EOD;
# footer # footer
printFooter(); printFooter();
}
break; break;
case "dups": case "dups":
@ -190,6 +234,21 @@ EOD;
array_push($dups, $dup); array_push($dups, $dup);
} }
if ($format == "xml") {
# doctype
xmlDocType();
$out = "<duplicates>\n";
# add duplicates
foreach ($dups as $dup) {
$out .= $dup->rowToXML();
}
# end
$out .= "</duplicates>\n";
print($out);
} else {
# header # header
printHeader(); printHeader();
@ -221,6 +280,7 @@ EOD;
# footer # footer
printFooter(); printFooter();
}
break; break;
@ -271,6 +331,22 @@ EOD;
$rows = $db->doQuery($sql); $rows = $db->doQuery($sql);
$uniquecount = $rows[0]['uniquecount']; $uniquecount = $rows[0]['uniquecount'];
if ($format == "xml") {
# doctype
xmlDocType();
$out = "<repos>\n";
# add repos
foreach ($repos as $repo) {
$out .= $repo->rowToXML();
}
# end
$out .= "</repos>\n";
print($out);
} else {
# header # header
printHeader(); printHeader();
@ -316,5 +392,6 @@ EOD;
# footer # footer
printFooter(); printFooter();
} }
}
?> ?>