rpm.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. rpm.h
  3. Copyright (C) 2012 Red Hat, Inc.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef SATYR_RPM_H
  17. #define SATYR_RPM_H
  18. /**
  19. * @file
  20. * @brief RPM-related structures and utilities.
  21. */
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #include <stdbool.h>
  26. #include <inttypes.h>
  27. struct sr_json_value;
  28. /* XXX: Should be moved to separated header once we support more package types.
  29. */
  30. enum sr_package_role
  31. {
  32. /* The role the package has in the problem is either unknown or
  33. * irrelevant.
  34. */
  35. SR_ROLE_UNKNOWN = 0,
  36. /* The packages contains the executable or script the execution of which
  37. * caused the problem to manifest.
  38. */
  39. SR_ROLE_AFFECTED
  40. };
  41. struct sr_rpm_consistency
  42. {
  43. char *path;
  44. bool owner_changed;
  45. bool group_changed;
  46. bool mode_changed;
  47. bool md5_mismatch;
  48. bool size_changed;
  49. bool major_number_changed;
  50. bool minor_number_changed;
  51. bool symlink_changed;
  52. bool modification_time_changed;
  53. struct sr_rpm_consistency *next;
  54. };
  55. struct sr_rpm_package
  56. {
  57. char *name;
  58. uint32_t epoch;
  59. char *version;
  60. char *release;
  61. char *architecture;
  62. uint64_t install_time;
  63. enum sr_package_role role;
  64. struct sr_rpm_consistency *consistency;
  65. struct sr_rpm_package *next;
  66. };
  67. struct sr_rpm_package *
  68. sr_rpm_package_new();
  69. void
  70. sr_rpm_package_init(struct sr_rpm_package *package);
  71. void
  72. sr_rpm_package_free(struct sr_rpm_package *package,
  73. bool recursive);
  74. /**
  75. * Compares two packages.
  76. * @param package1
  77. * It must be non-NULL pointer. It's not modified by calling this
  78. * function.
  79. * @param package2
  80. * It must be non-NULL pointer. It's not modified by calling this
  81. * function.
  82. * @returns
  83. * Returns 0 if the packages are same. Returns negative number if
  84. * package1 is found to be 'less' than package2. Returns positive
  85. * number if package1 is found to be 'greater' than package2.
  86. */
  87. int
  88. sr_rpm_package_cmp(struct sr_rpm_package *package1,
  89. struct sr_rpm_package *package2);
  90. /**
  91. * Compares two packages by their name, version and release.
  92. * @param package1
  93. * It must be non-NULL pointer. It's not modified by calling this
  94. * function.
  95. * @param package2
  96. * It must be non-NULL pointer. It's not modified by calling this
  97. * function.
  98. * @returns
  99. * Returns 0 if the packages are same. Returns negative number if
  100. * package1 is found to be 'less' than package2. Returns positive
  101. * number if package1 is found to be 'greater' than package2.
  102. */
  103. int
  104. sr_rpm_package_cmp_nvr(struct sr_rpm_package *package1,
  105. struct sr_rpm_package *package2);
  106. /**
  107. * Compares two packages by their name, epoch, version, release and
  108. * architecture.
  109. * @param package1
  110. * It must be non-NULL pointer. It's not modified by calling this
  111. * function.
  112. * @param package2
  113. * It must be non-NULL pointer. It's not modified by calling this
  114. * function.
  115. * @returns
  116. * Returns 0 if the packages are same. Returns negative number if
  117. * package1 is found to be 'less' than package2. Returns positive
  118. * number if package1 is found to be 'greater' than package2.
  119. */
  120. int
  121. sr_rpm_package_cmp_nevra(struct sr_rpm_package *package1,
  122. struct sr_rpm_package *package2);
  123. /**
  124. * Appends 'item' at the end of the list 'dest'.
  125. * @returns
  126. * This function returns the 'dest' package. If 'dest' is NULL, it
  127. * returns the 'item' package.
  128. */
  129. struct sr_rpm_package *
  130. sr_rpm_package_append(struct sr_rpm_package *dest,
  131. struct sr_rpm_package *item);
  132. /**
  133. * Returns the number of packages in the list.
  134. */
  135. int
  136. sr_rpm_package_count(struct sr_rpm_package *packages);
  137. struct sr_rpm_package *
  138. sr_rpm_package_sort(struct sr_rpm_package *packages);
  139. struct sr_rpm_package *
  140. sr_rpm_package_uniq(struct sr_rpm_package *packages);
  141. struct sr_rpm_package *
  142. sr_rpm_package_get_by_name(const char *name,
  143. char **error_message);
  144. struct sr_rpm_package *
  145. sr_rpm_package_get_by_path(const char *path,
  146. char **error_message);
  147. char *
  148. sr_rpm_package_to_json(struct sr_rpm_package *package,
  149. bool recursive);
  150. struct sr_rpm_package *
  151. sr_rpm_package_from_json(struct sr_json_value *list, bool recursive,
  152. char **error_message);
  153. bool
  154. sr_rpm_package_parse_nvr(const char *text,
  155. char **name,
  156. char **version,
  157. char **release);
  158. bool
  159. sr_rpm_package_parse_nevra(const char *text,
  160. char **name,
  161. uint32_t *epoch,
  162. char **version,
  163. char **release,
  164. char **architecture);
  165. struct sr_rpm_consistency *
  166. sr_rpm_consistency_new();
  167. void
  168. sr_rpm_consistency_init(struct sr_rpm_consistency *consistency);
  169. void
  170. sr_rpm_consistency_free(struct sr_rpm_consistency *consistency,
  171. bool recursive);
  172. int
  173. sr_rpm_consistency_cmp(struct sr_rpm_consistency *consistency1,
  174. struct sr_rpm_consistency *consistency2);
  175. int
  176. sr_rpm_consistency_cmp_recursive(struct sr_rpm_consistency *consistency1,
  177. struct sr_rpm_consistency *consistency2);
  178. /**
  179. * Appends 'item' at the end of the list 'dest'.
  180. * @returns
  181. * This function returns the 'dest' consistency info. If 'dest' is
  182. * NULL, it returns the 'item' consistency info.
  183. */
  184. struct sr_rpm_consistency *
  185. sr_rpm_consistency_append(struct sr_rpm_consistency *dest,
  186. struct sr_rpm_consistency *item);
  187. #ifdef __cplusplus
  188. }
  189. #endif
  190. #endif