Graphical package manager for pacman based on pamac 5.x.x
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

aur3.vala 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * pamac-vala
  3. *
  4. * Copyright (C) 2014 Guillaume Benoit <guillaume@manjaro.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a get of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. //~ const string srcpkgdir = "/tmp/pamac";
  20. namespace AUR {
  21. // AUR urls
  22. const string aur_url = "http://aur3.org/";
  23. public string[] search (string needle) {
  24. string[] results = {};
  25. try {
  26. // Resolve hostname to IP address
  27. var resolver = Resolver.get_default ();
  28. var addresses = resolver.lookup_by_name (host, null);
  29. var address = addresses.nth_data (0);
  30. // Connect
  31. var client = new SocketClient ();
  32. var conn = client.connect (new InetSocketAddress (address, 1819));
  33. // Send HTTP GET request
  34. var message = @"nd $query";
  35. conn.output_stream.write (message.data);
  36. // Receive response
  37. var response = new DataInputStream (conn.input_stream);
  38. string line;
  39. while ((line = response.read_line (null)) != null) {
  40. results += line;
  41. }
  42. } catch (Error e) {
  43. stderr.printf ("%s\n", e.message);
  44. }
  45. return results;
  46. }
  47. public void info (string pkgname) {
  48. string uri = rpc_url + rpc_info + pkgname;
  49. var session = new Soup.Session ();
  50. var message = new Soup.Message ("GET", uri);
  51. session.send_message (message);
  52. try {
  53. var parser = new Json.Parser ();
  54. parser.load_from_data ((string) message.response_body.flatten ().data, -1);
  55. var root_object = parser.get_root ().get_object ();
  56. var pkg_info = root_object.get_object_member ("results");
  57. AUR.Pkg aur_pkg = new AUR.Pkg (pkg_info);
  58. stdout.printf ("got %s (%s)\n", aur_pkg.name, aur_pkg.license);
  59. } catch (Error e) {
  60. stderr.printf ("Failed to get infos about %s from AUR\n", pkgname);
  61. print (e.message);
  62. }
  63. }
  64. }