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