0cb9ba11c168fa5e5ef76f71ee5ff69eb98a3bb1
[project/opkg-lede.git] / libopkg / pkg.h
1 /* pkg.h - the itsy package management system
2
3 Carl D. Worth
4
5 Copyright (C) 2001 University of Southern California
6
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.
11
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.
16 */
17
18 #ifndef PKG_H
19 #define PKG_H
20
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <unistd.h>
24
25 #include "pkg_vec.h"
26 #include "str_list.h"
27 #include "pkg_src.h"
28 #include "pkg_dest.h"
29 #include "opkg_conf.h"
30 #include "conffile_list.h"
31
32 struct opkg_conf;
33
34
35 #define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0])
36
37 /* I think "Size" is currently the shortest field name */
38 #define PKG_MINIMUM_FIELD_NAME_LEN 4
39
40 enum pkg_state_want
41 {
42 SW_UNKNOWN = 1,
43 SW_INSTALL,
44 SW_DEINSTALL,
45 SW_PURGE,
46 SW_LAST_STATE_WANT
47 };
48 typedef enum pkg_state_want pkg_state_want_t;
49
50 enum pkg_state_flag
51 {
52 SF_OK = 0,
53 SF_REINSTREQ = 1,
54 SF_HOLD = 2, /* do not upgrade version */
55 SF_REPLACE = 4, /* replace this package */
56 SF_NOPRUNE = 8, /* do not remove obsolete files */
57 SF_PREFER = 16, /* prefer this version */
58 SF_OBSOLETE = 32, /* old package in upgrade pair */
59 SF_MARKED = 64, /* temporary mark */
60 SF_FILELIST_CHANGED = 128, /* needs filelist written */
61 SF_USER = 256,
62 SF_LAST_STATE_FLAG
63 };
64 typedef enum pkg_state_flag pkg_state_flag_t;
65 #define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
66
67 enum pkg_state_status
68 {
69 SS_NOT_INSTALLED = 1,
70 SS_UNPACKED,
71 SS_HALF_CONFIGURED,
72 SS_INSTALLED,
73 SS_HALF_INSTALLED,
74 SS_CONFIG_FILES,
75 SS_POST_INST_FAILED,
76 SS_REMOVAL_FAILED,
77 SS_LAST_STATE_STATUS
78 };
79 typedef enum pkg_state_status pkg_state_status_t;
80
81 struct abstract_pkg{
82 char * name;
83 int dependencies_checked;
84 pkg_vec_t * pkgs;
85 pkg_state_status_t state_status;
86 pkg_state_flag_t state_flag;
87 struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
88 abstract_pkg_vec_t * provided_by;
89 abstract_pkg_vec_t * replaced_by;
90 };
91
92 #include "pkg_depends.h"
93
94 /* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
95
96 The 3 version fields should go into a single version struct. (This
97 is especially important since, currently, pkg->version can easily
98 be mistaken for pkg_verson_str_alloc(pkg) although they are very
99 distinct. This has been the source of multiple bugs.
100
101 The 3 state fields could possibly also go into their own struct.
102
103 All fields which deal with lists of packages, (Depends,
104 Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
105 be handled by a single struct in pkg_t
106
107 All string fields for which there is a small set of possible
108 values, (section, maintainer, architecture, maybe version?), that
109 are reused among different packages -- for all such packages we
110 should move from "char *"s to some atom datatype to share data
111 storage and use less memory. We might even do reference counting,
112 but probably not since most often we only create new pkg_t structs,
113 we don't often free them. */
114 struct pkg
115 {
116 char *name;
117 unsigned long epoch;
118 char *version;
119 char *revision;
120 char *familiar_revision;
121 pkg_src_t *src;
122 pkg_dest_t *dest;
123 char *architecture;
124 char *section;
125 char *maintainer;
126 char *description;
127 char *tags;
128 pkg_state_want_t state_want;
129 pkg_state_flag_t state_flag;
130 pkg_state_status_t state_status;
131 char **depends_str;
132 int depends_count;
133 char **pre_depends_str;
134 int pre_depends_count;
135 char **recommends_str;
136 int recommends_count;
137 char **suggests_str;
138 int suggests_count;
139 compound_depend_t * depends;
140
141 /* Abhaya: new conflicts */
142 char **conflicts_str;
143 compound_depend_t * conflicts;
144 int conflicts_count;
145
146 char **replaces_str;
147 int replaces_count;
148 abstract_pkg_t ** replaces;
149
150 char **provides_str;
151 int provides_count;
152 abstract_pkg_t ** provides;
153
154 abstract_pkg_t *parent;
155
156 pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
157
158 char *filename;
159 char *local_filename;
160 char *url;
161 char *tmp_unpack_dir;
162 char *md5sum;
163 char *size;
164 char *installed_size;
165 char *priority;
166 char *source;
167 conffile_list_t conffiles;
168 time_t installed_time;
169 /* As pointer for lazy evaluation */
170 str_list_t *installed_files;
171 /* XXX: CLEANUP: I'd like to perhaps come up with a better
172 mechanism to avoid the problem here, (which is that the
173 installed_files list was being freed from an inner loop while
174 still being used within an outer loop. */
175 int installed_files_ref_cnt;
176 int essential;
177 int arch_priority;
178 /* Adding this flag, to "force" opkg to choose a "provided_by_hand" package, if there are multiple choice */
179 int provided_by_hand;
180
181 /* this flag specifies whether the package was installed to satisfy another
182 * package's dependancies */
183 int auto_installed;
184 };
185
186 pkg_t *pkg_new(void);
187 int pkg_init(pkg_t *pkg);
188 void pkg_deinit(pkg_t *pkg);
189 int pkg_init_from_file(pkg_t *pkg, const char *filename);
190 abstract_pkg_t *abstract_pkg_new(void);
191 int abstract_pkg_init(abstract_pkg_t *ab_pkg);
192
193 /*
194 * merges fields from newpkg into oldpkg.
195 * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
196 */
197 int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
198
199 char *pkg_version_str_alloc(pkg_t *pkg);
200
201 int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
202 int pkg_name_version_and_architecture_compare(void *a, void *b);
203 int abstract_pkg_name_compare(void *a, void *b);
204
205 char * pkg_formatted_info(pkg_t *pkg );
206 char * pkg_formatted_field(pkg_t *pkg, const char *field );
207
208 void set_flags_from_control(opkg_conf_t *conf, pkg_t *pkg);
209
210 void pkg_print_info(pkg_t *pkg, FILE *file);
211 void pkg_print_status(pkg_t * pkg, FILE * file);
212 void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
213 str_list_t *pkg_get_installed_files(pkg_t *pkg);
214 int pkg_free_installed_files(pkg_t *pkg);
215 int pkg_remove_installed_files_list(opkg_conf_t *conf, pkg_t *pkg);
216 conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
217 int pkg_run_script(struct opkg_conf *conf, pkg_t *pkg,
218 const char *script, const char *args);
219
220 /* enum mappings */
221 char *pkg_state_want_to_str(pkg_state_want_t sw);
222 pkg_state_want_t pkg_state_want_from_str(char *str);
223 char *pkg_state_flag_to_str(pkg_state_flag_t sf);
224 pkg_state_flag_t pkg_state_flag_from_str(const char *str);
225 char *pkg_state_status_to_str(pkg_state_status_t ss);
226 pkg_state_status_t pkg_state_status_from_str(const char *str);
227
228 int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
229
230 int pkg_arch_supported(opkg_conf_t *conf, pkg_t *pkg);
231 int pkg_info_preinstall_check(opkg_conf_t *conf);
232 int pkg_free_installed_files(pkg_t *pkg);
233
234 int pkg_write_filelist(opkg_conf_t *conf, pkg_t *pkg);
235 int pkg_write_changed_filelists(opkg_conf_t *conf);
236
237 #endif