2
0

pkg.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /* pkg.h - the opkg package management system
  2. Carl D. Worth
  3. Copyright (C) 2001 University of Southern California
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License as
  6. published by the Free Software Foundation; either version 2, or (at
  7. your option) any later version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. */
  13. #ifndef PKG_H
  14. #define PKG_H
  15. #include "config.h"
  16. #include <sys/types.h>
  17. #include <libubox/blob.h>
  18. #include "pkg_vec.h"
  19. #include "str_list.h"
  20. #include "active_list.h"
  21. #include "pkg_src.h"
  22. #include "pkg_dest.h"
  23. #include "opkg_conf.h"
  24. #include "conffile_list.h"
  25. struct opkg_conf;
  26. #ifndef ARRAY_SIZE
  27. #define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
  28. #endif
  29. /* I think "Size" is currently the shortest field name */
  30. #define PKG_MINIMUM_FIELD_NAME_LEN 4
  31. enum pkg_state_want {
  32. SW_UNKNOWN = 1,
  33. SW_INSTALL,
  34. SW_DEINSTALL,
  35. SW_PURGE,
  36. SW_LAST_STATE_WANT
  37. };
  38. typedef enum pkg_state_want pkg_state_want_t;
  39. enum pkg_state_flag {
  40. SF_OK = 0,
  41. SF_REINSTREQ = 1,
  42. SF_HOLD = 2, /* do not upgrade version */
  43. SF_REPLACE = 4, /* replace this package */
  44. SF_NOPRUNE = 8, /* do not remove obsolete files */
  45. SF_PREFER = 16, /* prefer this version */
  46. SF_OBSOLETE = 32, /* old package in upgrade pair */
  47. SF_MARKED = 64, /* temporary mark */
  48. SF_FILELIST_CHANGED = 128, /* needs filelist written */
  49. SF_USER = 256,
  50. SF_NEED_DETAIL = 512,
  51. SF_LAST_STATE_FLAG
  52. };
  53. typedef enum pkg_state_flag pkg_state_flag_t;
  54. #define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  55. enum pkg_state_status {
  56. SS_NOT_INSTALLED = 1,
  57. SS_UNPACKED,
  58. SS_HALF_CONFIGURED,
  59. SS_INSTALLED,
  60. SS_HALF_INSTALLED,
  61. SS_CONFIG_FILES,
  62. SS_POST_INST_FAILED,
  63. SS_REMOVAL_FAILED,
  64. SS_LAST_STATE_STATUS
  65. };
  66. typedef enum pkg_state_status pkg_state_status_t;
  67. enum pkg_fields {
  68. PKG_MAINTAINER,
  69. PKG_PRIORITY,
  70. PKG_SOURCE,
  71. PKG_TAGS,
  72. PKG_SECTION,
  73. PKG_EPOCH,
  74. PKG_FILENAME,
  75. PKG_LOCAL_FILENAME,
  76. PKG_VERSION,
  77. PKG_REVISION,
  78. PKG_DESCRIPTION,
  79. PKG_MD5SUM,
  80. PKG_SHA256SUM,
  81. PKG_SIZE,
  82. PKG_INSTALLED_SIZE,
  83. PKG_INSTALLED_TIME,
  84. PKG_TMP_UNPACK_DIR,
  85. PKG_REPLACES,
  86. PKG_PROVIDES,
  87. PKG_DEPENDS,
  88. PKG_CONFLICTS,
  89. PKG_CONFFILES,
  90. };
  91. struct abstract_pkg {
  92. char *name;
  93. int dependencies_checked;
  94. pkg_vec_t *pkgs;
  95. pkg_state_status_t state_status;
  96. pkg_state_flag_t state_flag;
  97. /* XXX: This should be abstract_pkg_vec_t for consistency. */
  98. struct abstract_pkg **depended_upon_by;
  99. abstract_pkg_vec_t *provided_by;
  100. abstract_pkg_vec_t *replaced_by;
  101. };
  102. #include "pkg_depends.h"
  103. /* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  104. The 3 version fields should go into a single version struct. (This
  105. is especially important since, currently, pkg->version can easily
  106. be mistaken for pkg_verson_str_alloc(pkg) although they are very
  107. distinct. This has been the source of multiple bugs.
  108. The 3 state fields could possibly also go into their own struct.
  109. All fields which deal with lists of packages, (Depends,
  110. Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  111. be handled by a single struct in pkg_t
  112. All string fields for which there is a small set of possible
  113. values, (section, maintainer, architecture, maybe version?), that
  114. are reused among different packages -- for all such packages we
  115. should move from "char *"s to some atom datatype to share data
  116. storage and use less memory. We might even do reference counting,
  117. but probably not since most often we only create new pkg_t structs,
  118. we don't often free them. */
  119. struct pkg {
  120. char *name;
  121. pkg_src_t *src;
  122. pkg_dest_t *dest;
  123. pkg_state_want_t state_want:3;
  124. pkg_state_flag_t state_flag:11;
  125. pkg_state_status_t state_status:4;
  126. abstract_pkg_t *parent;
  127. /* As pointer for lazy evaluation */
  128. str_list_t *installed_files;
  129. /* XXX: CLEANUP: I'd like to perhaps come up with a better
  130. mechanism to avoid the problem here, (which is that the
  131. installed_files list was being freed from an inner loop while
  132. still being used within an outer loop. */
  133. int installed_files_ref_cnt;
  134. int essential:1;
  135. /* Adding this flag, to "force" opkg to choose a "provided_by_hand" package, if there are multiple choice */
  136. int provided_by_hand:1;
  137. /* this flag specifies whether the package was installed to satisfy another
  138. * package's dependancies */
  139. int auto_installed:1;
  140. int is_upgrade:1;
  141. int arch_index:3;
  142. struct blob_buf blob;
  143. };
  144. pkg_t *pkg_new(void);
  145. void pkg_deinit(pkg_t * pkg);
  146. int pkg_init_from_file(pkg_t * pkg, const char *filename);
  147. void *pkg_set_raw(pkg_t *pkg, int id, const void *val, size_t len);
  148. void *pkg_get_raw(const pkg_t *pkg, int id);
  149. static inline int pkg_set_int(pkg_t *pkg, int id, int val)
  150. {
  151. return (intptr_t) pkg_set_raw(pkg, id, &val, sizeof(val));
  152. }
  153. static inline int pkg_get_int(const pkg_t *pkg, int id)
  154. {
  155. return (intptr_t) pkg_get_raw(pkg, id);
  156. }
  157. char *pkg_set_string(pkg_t *pkg, int id, const char *s);
  158. static inline char *pkg_get_string(const pkg_t *pkg, int id)
  159. {
  160. return (char *) pkg_get_raw(pkg, id);
  161. }
  162. static inline void * pkg_set_ptr(pkg_t *pkg, int id, void *ptr)
  163. {
  164. void **res = pkg_set_raw(pkg, id, &ptr, sizeof(ptr));
  165. return res ? *res : NULL;
  166. }
  167. static inline void * pkg_get_ptr(const pkg_t *pkg, int id)
  168. {
  169. void **ptr = pkg_get_raw(pkg, id);
  170. return ptr ? *ptr : NULL;
  171. }
  172. char *pkg_set_architecture(pkg_t *pkg, const char *architecture, ssize_t len);
  173. char *pkg_get_architecture(const pkg_t *pkg);
  174. int pkg_get_arch_priority(const pkg_t *pkg);
  175. char *pkg_get_md5(const pkg_t *pkg);
  176. char *pkg_set_md5(pkg_t *pkg, const char *cksum);
  177. char *pkg_get_sha256(const pkg_t *pkg);
  178. char *pkg_set_sha256(pkg_t *pkg, const char *cksum);
  179. abstract_pkg_t *abstract_pkg_new(void);
  180. /*
  181. * merges fields from newpkg into oldpkg.
  182. * Forcibly sets oldpkg state_status, state_want and state_flags
  183. */
  184. int pkg_merge(pkg_t * oldpkg, pkg_t * newpkg);
  185. char *pkg_version_str_alloc(pkg_t * pkg);
  186. int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  187. int pkg_name_version_and_architecture_compare(const void *a, const void *b);
  188. int abstract_pkg_name_compare(const void *a, const void *b);
  189. void pkg_formatted_info(FILE * fp, pkg_t * pkg);
  190. void pkg_formatted_field(FILE * fp, pkg_t * pkg, const char *field);
  191. void set_flags_from_control(pkg_t * pkg);
  192. void pkg_print_status(pkg_t * pkg, FILE * file);
  193. str_list_t *pkg_get_installed_files(pkg_t * pkg);
  194. void pkg_free_installed_files(pkg_t * pkg);
  195. void pkg_remove_installed_files_list(pkg_t * pkg);
  196. conffile_t *pkg_get_conffile(pkg_t * pkg, const char *file_name);
  197. int pkg_run_script(pkg_t * pkg, const char *script, const char *args);
  198. /* enum mappings */
  199. pkg_state_want_t pkg_state_want_from_str(char *str);
  200. pkg_state_flag_t pkg_state_flag_from_str(const char *str);
  201. pkg_state_status_t pkg_state_status_from_str(const char *str);
  202. int pkg_version_satisfied(pkg_t * it, pkg_t * ref, const char *op);
  203. int pkg_arch_supported(pkg_t * pkg);
  204. void pkg_info_preinstall_check(void);
  205. int pkg_write_filelist(pkg_t * pkg);
  206. int pkg_write_changed_filelists(void);
  207. #endif