pkg.h 7.4 KB

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