1 /* pkg.h - the opkg package management system
5 Copyright (C) 2001 University of Southern California
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
21 #include <sys/types.h>
22 #include <libubox/blob.h>
26 #include "active_list.h"
29 #include "opkg_conf.h"
30 #include "conffile_list.h"
35 #define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
38 /* I think "Size" is currently the shortest field name */
39 #define PKG_MINIMUM_FIELD_NAME_LEN 4
48 typedef enum pkg_state_want pkg_state_want_t;
53 SF_HOLD = 2, /* do not upgrade version */
54 SF_REPLACE = 4, /* replace this package */
55 SF_NOPRUNE = 8, /* do not remove obsolete files */
56 SF_PREFER = 16, /* prefer this version */
57 SF_OBSOLETE = 32, /* old package in upgrade pair */
58 SF_MARKED = 64, /* temporary mark */
59 SF_FILELIST_CHANGED = 128, /* needs filelist written */
62 SF_IGNORE = 1024, /* ignore this package in dependency checks */
65 typedef enum pkg_state_flag pkg_state_flag_t;
66 #define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
68 enum pkg_state_status {
79 typedef enum pkg_state_status pkg_state_status_t;
107 struct abstract_pkg {
109 int dependencies_checked;
111 pkg_state_status_t state_status;
112 pkg_state_flag_t state_flag;
114 /* XXX: This should be abstract_pkg_vec_t for consistency. */
115 struct abstract_pkg **depended_upon_by;
117 abstract_pkg_vec_t *provided_by;
118 abstract_pkg_vec_t *replaced_by;
121 #include "pkg_depends.h"
123 enum pkg_alternative_field {
130 struct pkg_alternative {
136 struct pkg_alternatives {
138 struct pkg_alternative **alts;
141 /* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
143 The 3 version fields should go into a single version struct. (This
144 is especially important since, currently, pkg->version can easily
145 be mistaken for pkg_verson_str_alloc(pkg) although they are very
146 distinct. This has been the source of multiple bugs.
148 The 3 state fields could possibly also go into their own struct.
150 All fields which deal with lists of packages, (Depends,
151 Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
152 be handled by a single struct in pkg_t
154 All string fields for which there is a small set of possible
155 values, (section, maintainer, architecture, maybe version?), that
156 are reused among different packages -- for all such packages we
157 should move from "char *"s to some atom datatype to share data
158 storage and use less memory. We might even do reference counting,
159 but probably not since most often we only create new pkg_t structs,
160 we don't often free them. */
165 pkg_state_want_t state_want:3;
166 pkg_state_flag_t state_flag:11;
167 pkg_state_status_t state_status:4;
169 abstract_pkg_t *parent;
171 /* As pointer for lazy evaluation */
172 str_list_t *installed_files;
173 /* XXX: CLEANUP: I'd like to perhaps come up with a better
174 mechanism to avoid the problem here, (which is that the
175 installed_files list was being freed from an inner loop while
176 still being used within an outer loop. */
177 int installed_files_ref_cnt;
179 unsigned int essential:1;
180 /* Adding this flag, to "force" opkg to choose a "provided_by_hand" package, if there are multiple choice */
181 unsigned int provided_by_hand:1;
183 /* this flag specifies whether the package was installed to satisfy another
184 * package's dependancies */
185 unsigned int auto_installed:1;
186 unsigned int is_upgrade:1;
188 unsigned int arch_index:3;
190 struct blob_buf blob;
193 pkg_t *pkg_new(void);
194 void pkg_deinit(pkg_t * pkg);
195 int pkg_init_from_file(pkg_t * pkg, const char *filename);
197 void *pkg_set_raw(pkg_t *pkg, int id, const void *val, size_t len);
198 void *pkg_get_raw(const pkg_t *pkg, int id);
200 static inline int pkg_set_int(pkg_t *pkg, int id, int val)
202 int *res = pkg_set_raw(pkg, id, &val, sizeof(val));
203 return res ? *res : 0;
206 static inline int pkg_get_int(const pkg_t *pkg, int id)
208 int *ptr = pkg_get_raw(pkg, id);
209 return ptr ? *ptr : 0;
212 char *pkg_set_string(pkg_t *pkg, int id, const char *s);
214 static inline char *pkg_get_string(const pkg_t *pkg, int id)
216 return (char *) pkg_get_raw(pkg, id);
219 static inline void * pkg_set_ptr(pkg_t *pkg, int id, void *ptr)
221 void **res = pkg_set_raw(pkg, id, &ptr, sizeof(ptr));
222 return res ? *res : NULL;
225 static inline void * pkg_get_ptr(const pkg_t *pkg, int id)
227 void **ptr = pkg_get_raw(pkg, id);
228 return ptr ? *ptr : NULL;
231 char *pkg_set_architecture(pkg_t *pkg, const char *architecture, ssize_t len);
232 char *pkg_get_architecture(const pkg_t *pkg);
233 int pkg_get_arch_priority(const pkg_t *pkg);
235 char *pkg_get_md5(const pkg_t *pkg);
236 char *pkg_set_md5(pkg_t *pkg, const char *cksum);
238 char *pkg_get_sha256(const pkg_t *pkg);
239 char *pkg_set_sha256(pkg_t *pkg, const char *cksum);
241 abstract_pkg_t *abstract_pkg_new(void);
244 * merges fields from newpkg into oldpkg.
245 * Forcibly sets oldpkg state_status, state_want and state_flags
247 int pkg_merge(pkg_t * oldpkg, pkg_t * newpkg);
249 char *pkg_version_str_alloc(pkg_t * pkg);
251 int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
252 int pkg_name_version_and_architecture_compare(const void *a, const void *b);
253 int abstract_pkg_name_compare(const void *a, const void *b);
255 void pkg_formatted_info(FILE * fp, pkg_t * pkg);
256 void pkg_formatted_field(FILE * fp, pkg_t * pkg, const char *field);
258 void pkg_print_status(pkg_t * pkg, FILE * file);
259 str_list_t *pkg_get_installed_files(pkg_t * pkg);
260 void pkg_free_installed_files(pkg_t * pkg);
261 void pkg_remove_installed_files_list(pkg_t * pkg);
262 conffile_t *pkg_get_conffile(pkg_t * pkg, const char *file_name);
263 int pkg_run_script(pkg_t * pkg, const char *script, const char *args);
266 pkg_state_want_t pkg_state_want_from_str(char *str);
267 pkg_state_flag_t pkg_state_flag_from_str(const char *str);
268 pkg_state_status_t pkg_state_status_from_str(const char *str);
270 int pkg_version_satisfied(pkg_t * it, pkg_t * ref, const char *op);
272 int pkg_arch_supported(pkg_t * pkg);
273 void pkg_info_preinstall_check(void);
275 int pkg_write_filelist(pkg_t * pkg);
276 int pkg_write_changed_filelists(void);