Add new method of multiple by[] search in API v6.
The 'provides' by field is also supported in the new
multiple by[] method included with this patch.
'provides' may not be used in legacy (v5) singular by search.
A helpful json error message is returned to the user to indicate so.
This patch is a follow-up implementation to
https://patchwork.archlinux.org/patch/479/
Signed-off-by: Kevin Morris
---
doc/rpc.txt | 24 ++---
web/lib/aurjson.class.php | 105 --
2 files changed, 116 insertions(+), 13 deletions(-)
diff --git a/doc/rpc.txt b/doc/rpc.txt
index 3148ebe..486a49d 100644
--- a/doc/rpc.txt
+++ b/doc/rpc.txt
@@ -5,7 +5,7 @@ Package Search
--
Package searches can be performed by issuing HTTP GET requests of the form
-+/rpc/?v=5&type=search&by=_field_&arg=_keywords_+ where _keywords_ is the
++/rpc/?v=6&type=search&by[]=_field_&arg[]=_keywords_+ where _keywords_ is the
search argument and _field_ is one of the following values:
* `name` (search by package name only)
@@ -15,31 +15,39 @@ search argument and _field_ is one of the following values:
* `makedepends` (search for packages that makedepend on _keywords_)
* `optdepends` (search for packages that optdepend on _keywords_)
* `checkdepends` (search for packages that checkdepend on _keywords_)
+* `provides` (search by package provides; v6 multiple by[] only)
The _by_ parameter can be skipped and defaults to `name-desc`.
If a maintainer search is performed and the search argument is left empty, a
list of orphan packages is returned.
+Note: Legacy v5 support is still enabled for singular _by_ searches.
+
Package Details
---
Package information can be obtained by issuing HTTP GET requests of the form
-+/rpc/?v=5&type=info&arg[]=_pkg1_&arg[]=_pkg2_&...+ where _pkg1_, _pkg2_, ...
++/rpc/?v=6&type=info&arg[]=_pkg1_&arg[]=_pkg2_&...+ where _pkg1_, _pkg2_, ...
are the names of packages to retrieve package details for.
Examples
`search`::
- `/rpc/?v=5&type=search&arg=foobar`
+ `/rpc/?v=6&type=search&arg=foobar`
`search` by maintainer::
- `/rpc/?v=5&type=search&by=maintainer&arg=john`
+ `/rpc/?v=6&type=search&by[]=maintainer&arg=john`
`search` packages that have _boost_ as `makedepends`::
- `/rpc/?v=5&type=search&by=makedepends&arg=boost`
+ `/rpc/?v=6&type=search&by[]=makedepends&arg=boost`
`search` with callback::
- `/rpc/?v=5&type=search&arg=foobar&callback=jsonp1192244621103`
+ `/rpc/?v=6&type=search&arg=foobar&callback=jsonp1192244621103`
+`search` by provides::
+ `/rpc/?v=6&type=search&by[]=provides&arg[]=gcc`
+`search` by provides and name::
+ `/rpc/?v=6&type=search&by[]=name&by[]=provides&arg[]=gcc`
`info`::
- `/rpc/?v=5&type=info&arg[]=foobar`
+ `/rpc/?v=6&type=info&arg[]=foobar`
`info` with multiple packages::
- `/rpc/?v=5&type=info&arg[]=foo&arg[]=bar`
+ `/rpc/?v=6&type=info&arg[]=foo&arg[]=bar`
+
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index c275d21..ab4eb19 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -80,7 +80,8 @@ class AurJSON {
if (isset($http_data['v'])) {
$this->version = intval($http_data['v']);
}
- if ($this->version < 1 || $this->version > 5) {
+
+ if ($this->version < 1 || $this->version > 6) {
return $this->json_error('Invalid version specified.');
}
@@ -94,8 +95,14 @@ class AurJSON {
if (isset($http_data['search_by']) && !isset($http_data['by']))
{
$http_data['by'] = $http_data['search_by'];
}
- if (isset($http_data['by']) && !in_array($http_data['by'],
self::$exposed_fields)) {
- return $this->json_error('Incorrect by field
specified.');
+
+ if (isset($http_data['by']) && !is_array($http_data['by'])) {
+ if ($http_data['by'] === 'provides') {
+ return $this->json_error("The 'provides' by
field " .
+ "may only be used via multiple by[]
search.");
+ } elseif (!in_array($http_data['by'],
self::$exposed_fields)) {
+ return $this->json_error('Incorrect by field
specified.');
+ }
}
$this->dbh = DB::connect();
@@ -360,7 +367,7 @@ class AurJSON {
} elseif ($this->version >= 2) {
if ($this->version == 2 || $this->version == 3) {
$fields = implode(',', self::$fields_v2);
- } else if ($this->version == 4 || $this->version == 5) {
+ } else if ($this->version == 4 || $this->version == 5
|| $this->version == 6) {
$fields = implode(',', self::$fields_v4);
}