apk_package.h 6.69 KB
Newer Older
1
/* apk_package.h - Alpine Package Keeper (APK)
2 3
 *
 * Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
4
 * Copyright (C) 2008-2011 Timo Teräs <timo.teras@iki.fi>
5 6
 * All rights reserved.
 *
Timo Teräs's avatar
Timo Teräs committed
7
 * This program is free software; you can redistribute it and/or modify it
8 9 10 11 12 13 14 15 16
 * under the terms of the GNU General Public License version 2 as published
 * by the Free Software Foundation. See http://www.gnu.org/ for details.
 */

#ifndef APK_PKG_H
#define APK_PKG_H

#include "apk_version.h"
#include "apk_hash.h"
17
#include "apk_io.h"
18
#include "apk_solver_data.h"
19 20 21

struct apk_database;
struct apk_name;
22
struct apk_provider;
23

Timo Teräs's avatar
Timo Teräs committed
24
#define APK_SCRIPT_INVALID		-1
25 26 27 28 29 30 31 32
#define APK_SCRIPT_PRE_INSTALL		0
#define APK_SCRIPT_POST_INSTALL		1
#define APK_SCRIPT_PRE_DEINSTALL	2
#define APK_SCRIPT_POST_DEINSTALL	3
#define APK_SCRIPT_PRE_UPGRADE		4
#define APK_SCRIPT_POST_UPGRADE		5
#define APK_SCRIPT_TRIGGER		6
#define APK_SCRIPT_MAX			7
33

34 35 36 37
#define APK_SIGN_NONE			0
#define APK_SIGN_VERIFY			1
#define APK_SIGN_VERIFY_IDENTITY	2
#define APK_SIGN_GENERATE		4
38
#define APK_SIGN_VERIFY_AND_GENERATE	5
39

40 41 42 43 44
#define APK_DEP_IRRELEVANT		0x01
#define APK_DEP_SATISFIES		0x02
#define APK_DEP_CONFLICTS		0x04
#define APK_FOREACH_INSTALLED		0x10
#define APK_FOREACH_MARKED		0x20
45
#define APK_FOREACH_NULL_MATCHES_ALL	0x40
46
#define APK_FOREACH_GENID_MASK		0xffffff00
47

Timo Teräs's avatar
Timo Teräs committed
48
struct apk_sign_ctx {
49
	int keys_fd;
Timo Teräs's avatar
Timo Teräs committed
50 51 52 53 54 55 56 57 58 59
	int action;
	const EVP_MD *md;
	int num_signatures;
	int control_started : 1;
	int data_started : 1;
	int has_data_checksum : 1;
	int control_verified : 1;
	int data_verified : 1;
	char data_checksum[EVP_MAX_MD_SIZE];
	struct apk_checksum identity;
60
	EVP_MD_CTX mdctx;
Timo Teräs's avatar
Timo Teräs committed
61 62 63 64 65 66 67 68

	struct {
		apk_blob_t data;
		EVP_PKEY *pkey;
		char *identity;
	} signature;
};

69 70
struct apk_dependency {
	struct apk_name *name;
71
	apk_blob_t *version;
72
	unsigned broken : 1;
Timo Teräs's avatar
Timo Teräs committed
73
	unsigned repository_tag : 6;
74
	unsigned conflict : 1;
75
	unsigned result_mask : 3;
76 77 78
};
APK_ARRAY(apk_dependency_array, struct apk_dependency);

79 80 81 82 83 84 85
struct apk_installed_package {
	struct apk_package *pkg;
	struct list_head installed_pkgs_list;
	struct list_head trigger_pkgs_list;
	struct hlist_head owned_dirs;
	apk_blob_t script[APK_SCRIPT_MAX];
	struct apk_string_array *triggers;
86
	struct apk_string_array *pending_triggers;
87
	struct apk_dependency_array *replaces;
88 89 90 91 92 93

	unsigned short replaces_priority;
	unsigned repository_tag : 6;
	unsigned run_all_triggers : 1;
	unsigned broken_files : 1;
	unsigned broken_script : 1;
94 95
};

96 97
struct apk_package {
	apk_hash_node hash_node;
98
	union {
99
		struct apk_solver_package_state ss;
100
		struct {
101
			unsigned int foreach_genid;
102 103 104 105 106
			union {
				int state_int;
				void *state_ptr;
			};
		};
107
	};
108
	struct apk_name *name;
109 110
	struct apk_installed_package *ipkg;
	apk_blob_t *version, *arch, *license;
111 112
	apk_blob_t *origin, *maintainer;
	char *url, *description, *commit;
113
	char *filename;
114
	struct apk_dependency_array *depends, *install_if, *provides;
Timo Teräs's avatar
Timo Teräs committed
115
	size_t installed_size, size;
116
	time_t build_time;
117
	unsigned repos : APK_MAX_REPOS;
118
	unsigned marked : 1;
119
	unsigned uninstallable : 1;
120
	unsigned cached_non_repository : 1;
Timo Teräs's avatar
Timo Teräs committed
121
	struct apk_checksum csum;
122 123 124
};
APK_ARRAY(apk_package_array, struct apk_package *);

125 126 127
#define APK_PROVIDER_FROM_PACKAGE(pkg)	  (struct apk_provider){(pkg),(pkg)->version}
#define APK_PROVIDER_FROM_PROVIDES(pkg,p) (struct apk_provider){(pkg),(p)->version}

128 129
#define PKG_VER_FMT		"%s-" BLOB_FMT
#define PKG_VER_PRINTF(pkg)	pkg->name->name, BLOB_PRINTF(*pkg->version)
130 131
#define PKG_FILE_FMT		PKG_VER_FMT ".apk"
#define PKG_FILE_PRINTF(pkg)	PKG_VER_PRINTF(pkg)
132

Timo Teräs's avatar
Timo Teräs committed
133 134
extern const char *apk_script_types[];

135
void apk_sign_ctx_init(struct apk_sign_ctx *ctx, int action,
136
		       struct apk_checksum *identity, int keys_fd);
Timo Teräs's avatar
Timo Teräs committed
137 138 139 140
void apk_sign_ctx_free(struct apk_sign_ctx *ctx);
int apk_sign_ctx_process_file(struct apk_sign_ctx *ctx,
			      const struct apk_file_info *fi,
			      struct apk_istream *is);
141
int apk_sign_ctx_parse_pkginfo_line(void *ctx, apk_blob_t line);
142 143
int apk_sign_ctx_verify_tar(void *ctx, const struct apk_file_info *fi,
			    struct apk_istream *is);
144
int apk_sign_ctx_mpart_cb(void *ctx, int part, apk_blob_t blob);
Timo Teräs's avatar
Timo Teräs committed
145

Timo Teräs's avatar
Timo Teräs committed
146 147
void apk_dep_from_pkg(struct apk_dependency *dep, struct apk_database *db,
		      struct apk_package *pkg);
148 149
int apk_dep_is_materialized(struct apk_dependency *dep, struct apk_package *pkg);
int apk_dep_is_provided(struct apk_dependency *dep, struct apk_provider *p);
150 151
int apk_dep_analyze(struct apk_dependency *dep, struct apk_package *pkg);
char *apk_dep_snprintf(char *buf, size_t n, struct apk_dependency *dep);
152

153 154
void apk_blob_push_dep(apk_blob_t *to, struct apk_database *, struct apk_dependency *dep);
void apk_blob_push_deps(apk_blob_t *to, struct apk_database *, struct apk_dependency_array *deps);
155 156 157
void apk_blob_pull_dep(apk_blob_t *from, struct apk_database *, struct apk_dependency *);
void apk_blob_pull_deps(apk_blob_t *from, struct apk_database *, struct apk_dependency_array **);

158
int apk_deps_write(struct apk_database *db, struct apk_dependency_array *deps,
159
		   struct apk_ostream *os, apk_blob_t separator);
160

161 162
void apk_deps_add(struct apk_dependency_array **depends, struct apk_dependency *dep);
void apk_deps_del(struct apk_dependency_array **deps, struct apk_name *name);
163 164
int apk_script_type(const char *name);

165 166
struct apk_package *apk_pkg_get_installed(struct apk_name *name);

167
struct apk_package *apk_pkg_new(void);
168 169
int apk_pkg_read(struct apk_database *db, const char *name,
		 struct apk_sign_ctx *ctx, struct apk_package **pkg);
170 171
void apk_pkg_free(struct apk_package *pkg);

172 173
int apk_pkg_parse_name(apk_blob_t apkname, apk_blob_t *name, apk_blob_t *version);

174 175
int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg,
		     char field, apk_blob_t value);
176 177 178 179 180 181 182

struct apk_installed_package *apk_pkg_install(struct apk_database *db, struct apk_package *pkg);
void apk_pkg_uninstall(struct apk_database *db, struct apk_package *pkg);

int apk_ipkg_add_script(struct apk_installed_package *ipkg,
			struct apk_istream *is,
			unsigned int type, unsigned int size);
183 184
void apk_ipkg_run_script(struct apk_installed_package *ipkg, struct apk_database *db,
			 unsigned int type, char **argv);
185 186

struct apk_package *apk_pkg_parse_index_entry(struct apk_database *db, apk_blob_t entry);
187
int apk_pkg_write_index_entry(struct apk_package *pkg, struct apk_ostream *os);
188

189 190
int apk_pkg_version_compare(struct apk_package *a, struct apk_package *b);

191
unsigned int apk_foreach_genid(void);
192
void apk_pkg_foreach_matching_dependency(
193 194
		struct apk_package *pkg, struct apk_dependency_array *deps,
		unsigned int match, struct apk_package *mpkg,
195 196 197
		void cb(struct apk_package *pkg0, struct apk_dependency *dep0, struct apk_package *pkg, void *ctx),
		void *ctx);
void apk_pkg_foreach_reverse_dependency(
198
		struct apk_package *pkg, unsigned int match,
199 200 201
		void cb(struct apk_package *pkg0, struct apk_dependency *dep0, struct apk_package *pkg, void *ctx),
		void *ctx);

202
#endif