[aur-dev] [PATCH/RFC] Add pkglist command to the RPC interface

Lukas Fleischer archlinux at cryptocrack.de
Wed Apr 30 07:58:32 EDT 2014


This returns a list of all package names from the database.

Signed-off-by: Lukas Fleischer <archlinux at cryptocrack.de>
---
What do you think about this? Does this sound like a useful feature? Do
we need to cache the results?

 web/html/rpc.php          |  2 ++
 web/lib/aurjson.class.php | 33 +++++++++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/web/html/rpc.php b/web/html/rpc.php
index 415dcb8..f43792a 100644
--- a/web/html/rpc.php
+++ b/web/html/rpc.php
@@ -24,6 +24,7 @@ else {
   <li><tt>info</tt></li>
   <li><tt>multiinfo</tt></li>
   <li><tt>msearch</tt></li>
+  <li><tt>pkglist</tt></li>
 </ul>
 <p>Each method requires the following HTTP GET syntax:</p>
 <pre>type=<em>methodname</em>&arg=<em>data</em></pre>
@@ -35,6 +36,7 @@ else {
   <dt><tt>info</tt></dt><dd><tt>http://aur-url/rpc.php?type=info&arg=foobar</tt></dd>
   <dt><tt>multiinfo</tt></dt><dd><tt>http://aur-url/rpc.php?type=multiinfo&arg[]=foo&arg[]=bar</tt></dd>
   <dt><tt>msearch</tt></dt><dd><tt>http://aur-url/rpc.php?type=msearch&arg=john</tt></li></dd>
+  <dt><tt>pkglist</tt></dt><dd><tt>http://aur-url/rpc.php?type=pkglist</tt></li></dd>
   <dt>Callback</dt><dd><tt>http://aur-url/rpc.php?type=search&arg=foobar&callback=jsonp1192244621103</tt></dd>
 </dl>
 </body></html>
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index 50d859c..bc42ac4 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -13,7 +13,7 @@ class AurJSON {
 	private $dbh = false;
 	private $version = 1;
 	private static $exposed_methods = array(
-		'search', 'info', 'multiinfo', 'msearch', 'suggest'
+		'search', 'info', 'multiinfo', 'msearch', 'suggest', 'pkglist'
 	);
 	private static $fields_v1 = array(
 		'Packages.ID', 'Packages.Name',
@@ -63,8 +63,11 @@ class AurJSON {
 			return $this->json_error('Invalid version specified.');
 		}
 
-		if (!isset($http_data['type']) || !isset($http_data['arg'])) {
-			return $this->json_error('No request type/data specified.');
+		if (!isset($http_data['type'])) {
+			return $this->json_error('No request type specified.');
+		}
+		if ($http_data['type'] != 'pkglist' && !isset($http_data['arg'])) {
+			return $this->json_error('No request argument specified.');
 		}
 		if (!in_array($http_data['type'], self::$exposed_methods)) {
 			return $this->json_error('Incorrect request type specified.');
@@ -72,7 +75,11 @@ class AurJSON {
 
 		$this->dbh = DB::connect();
 
-		$json = call_user_func(array(&$this, $http_data['type']), $http_data['arg']);
+		if (isset($http_data['arg'])) {
+			$json = call_user_func(array(&$this, $http_data['type']), $http_data['arg']);
+		} else {
+			$json = call_user_func(array(&$this, $http_data['type']));
+		}
 
 		$etag = md5($json);
 		header("Etag: \"$etag\"");
@@ -387,5 +394,23 @@ class AurJSON {
 
 		return json_encode($result_array);
 	}
+
+	/*
+	 * Get the names of all packages.
+	 *
+	 * @return string The JSON formatted response data.
+	 */
+	private function pkglist() {
+		$query = 'SELECT Name FROM Packages';
+
+		$result = $this->dbh->query($query);
+		$result_array = array();
+
+		if ($result) {
+			$result_array = $result->fetchAll(PDO::FETCH_COLUMN, 0);
+		}
+
+		return $this->json_results('pkglist', count($result_array), $result_array);
+	}
 }
 
-- 
1.9.2



More information about the aur-dev mailing list