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.

aur.vala 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. namespace AUR {
  20. // AUR urls
  21. const string aur_url = "http://aur.archlinux.org";
  22. const string rpc_url = aur_url + "/rpc.php";
  23. const string rpc_search = "?type=search&arg=";
  24. const string rpc_info = "?type=info&arg=";
  25. const string rpc_multiinfo = "?type=multiinfo";
  26. const string rpc_multiinfo_arg = "&arg[]=";
  27. const string aur_url_id = "/packages.php?setlang=en&ID=";
  28. public Json.Array search (string[] needles) {
  29. Json.Array prev_inter = new Json.Array ();
  30. string uri = rpc_url + rpc_search + Uri.escape_string (needles[0]);
  31. var session = new Soup.Session ();
  32. var message = new Soup.Message ("GET", uri);
  33. var parser = new Json.Parser ();
  34. unowned Json.Object root_object;
  35. session.send_message (message);
  36. try {
  37. parser.load_from_data ((string) message.response_body.flatten ().data, -1);
  38. root_object = parser.get_root ().get_object ();
  39. prev_inter = root_object.get_array_member ("results");
  40. } catch (Error e) {
  41. print (e.message);
  42. }
  43. int length = needles.length;
  44. if (length == 1)
  45. return prev_inter;
  46. int i = 1;
  47. Json.Array inter = new Json.Array ();
  48. Json.Array found = new Json.Array ();
  49. while (i < length) {
  50. inter = new Json.Array ();
  51. uri = rpc_url + rpc_search + Uri.escape_string (needles[i]);
  52. message = new Soup.Message ("GET", uri);
  53. session.send_message (message);
  54. try {
  55. parser.load_from_data ((string) message.response_body.flatten ().data, -1);
  56. root_object = parser.get_root ().get_object ();
  57. found = root_object.get_array_member ("results");
  58. } catch (Error e) {
  59. print (e.message);
  60. }
  61. foreach (Json.Node prev_inter_node in prev_inter.get_elements ()) {
  62. foreach (Json.Node found_node in found.get_elements ()) {
  63. if (strcmp (prev_inter_node.get_object ().get_string_member ("Name"),
  64. found_node.get_object ().get_string_member ("Name")) == 0) {
  65. inter.add_element (prev_inter_node);
  66. }
  67. }
  68. }
  69. if (i != (length -1))
  70. prev_inter = inter;
  71. i += 1;
  72. }
  73. return inter;
  74. }
  75. public Json.Object? info (string pkgname) {
  76. unowned Json.Object? pkg_info = null;
  77. string uri = rpc_url + rpc_info + pkgname;
  78. var session = new Soup.Session ();
  79. var message = new Soup.Message ("GET", uri);
  80. session.send_message (message);
  81. try {
  82. var parser = new Json.Parser ();
  83. parser.load_from_data ((string) message.response_body.flatten ().data, -1);
  84. pkg_info = parser.get_root ().get_object ().get_object_member ("results");
  85. } catch (Error e) {
  86. stderr.printf ("Failed to get infos about %s from AUR\n", pkgname);
  87. print (e.message);
  88. }
  89. return pkg_info;
  90. }
  91. public Json.Array multiinfo (string[] pkgnames) {
  92. Json.Array results = new Json.Array ();
  93. var builder = new StringBuilder ();
  94. builder.append (rpc_url);
  95. builder.append (rpc_multiinfo);
  96. foreach (string pkgname in pkgnames) {
  97. builder.append (rpc_multiinfo_arg);
  98. builder.append (pkgname);
  99. }
  100. var session = new Soup.Session ();
  101. var message = new Soup.Message ("GET", builder.str);
  102. session.send_message (message);
  103. try {
  104. var parser = new Json.Parser ();
  105. parser.load_from_data ((string) message.response_body.flatten ().data, -1);
  106. unowned Json.Object root_object = parser.get_root ().get_object ();
  107. results = root_object.get_array_member ("results");
  108. } catch (Error e) {
  109. print (e.message);
  110. }
  111. return results;
  112. }
  113. }