apk_package.h 5.76 KB
Newer Older
1 2 3
/* apk_database.h - Alpine Package Keeper (APK)
 *
 * 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 19 20

struct apk_database;
struct apk_name;
21
struct apk_provider;
22

Timo Teräs's avatar
Timo Teräs committed
23
#define APK_SCRIPT_INVALID		-1
24 25 26 27 28 29 30 31
#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
32

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

Timo Teräs's avatar
Timo Teräs committed
39
struct apk_sign_ctx {
40
	int keys_fd;
Timo Teräs's avatar
Timo Teräs committed
41 42 43 44 45 46 47 48 49 50
	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;
51
	EVP_MD_CTX mdctx;
Timo Teräs's avatar
Timo Teräs committed
52 53 54 55 56 57 58 59

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

60 61
struct apk_dependency {
	struct apk_name *name;
62
	apk_blob_t *version;
Timo Teräs's avatar
Timo Teräs committed
63 64
	unsigned solver_state : 22;
	unsigned repository_tag : 6;
65
	unsigned conflict : 1;
66
	unsigned result_mask : 3;
67 68 69
};
APK_ARRAY(apk_dependency_array, struct apk_dependency);

70 71
struct apk_installed_package {
	struct apk_package *pkg;
72
	unsigned int run_all_triggers : 1;
73
	unsigned int repository_tag : 6;
74
	unsigned short replaces_priority;
75 76 77 78 79
	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;
80
	struct apk_string_array *pending_triggers;
81
	struct apk_dependency_array *replaces;
82 83
};

84 85
#define APK_PKG_UNINSTALLABLE		((char*) -1)

86 87
struct apk_package {
	apk_hash_node hash_node;
88 89 90 91
	union {
		int state_int;
		void *state_ptr;
	};
92
	struct apk_name *name;
93 94
	struct apk_installed_package *ipkg;
	apk_blob_t *version, *arch, *license;
95 96
	apk_blob_t *origin, *maintainer;
	char *url, *description, *commit;
97
	char *filename;
98
	struct apk_dependency_array *depends, *install_if, *provides;
Timo Teräs's avatar
Timo Teräs committed
99
	size_t installed_size, size;
100
	time_t build_time;
101
	unsigned int topology_hard;
102
	unsigned repos : APK_MAX_REPOS;
Timo Teräs's avatar
Timo Teräs committed
103
	struct apk_checksum csum;
104 105 106
};
APK_ARRAY(apk_package_array, struct apk_package *);

107 108 109
#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}

110 111 112
#define PKG_VER_FMT		"%s-" BLOB_FMT
#define PKG_VER_PRINTF(pkg)	pkg->name->name, BLOB_PRINTF(*pkg->version)

Timo Teräs's avatar
Timo Teräs committed
113 114
extern const char *apk_script_types[];

115
void apk_sign_ctx_init(struct apk_sign_ctx *ctx, int action,
116
		       struct apk_checksum *identity, int keys_fd);
Timo Teräs's avatar
Timo Teräs committed
117 118 119 120
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);
121
int apk_sign_ctx_parse_pkginfo_line(void *ctx, apk_blob_t line);
122 123
int apk_sign_ctx_verify_tar(void *ctx, const struct apk_file_info *fi,
			    struct apk_istream *is);
124
int apk_sign_ctx_mpart_cb(void *ctx, int part, apk_blob_t blob);
Timo Teräs's avatar
Timo Teräs committed
125

Timo Teräs's avatar
Timo Teräs committed
126 127
void apk_dep_from_pkg(struct apk_dependency *dep, struct apk_database *db,
		      struct apk_package *pkg);
128 129 130
int apk_dep_is_materialized(struct apk_dependency *dep, struct apk_package *pkg);
int apk_dep_is_materialized_or_provided(struct apk_dependency *dep, struct apk_package *pkg);
int apk_dep_is_provided(struct apk_dependency *dep, struct apk_provider *p);
131

132 133
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);
134 135 136
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 **);

137
int apk_deps_write(struct apk_database *db, struct apk_dependency_array *deps,
138
		   struct apk_ostream *os, apk_blob_t separator);
139

140 141
int apk_deps_add(struct apk_dependency_array **depends,
		 struct apk_dependency *dep);
142 143
void apk_deps_del(struct apk_dependency_array **deps,
		  struct apk_name *name);
144 145
int apk_script_type(const char *name);

146 147
struct apk_package *apk_pkg_get_installed(struct apk_name *name);

148 149
void apk_pkg_format_plain(struct apk_package *pkg, apk_blob_t to);
void apk_pkg_format_cache(struct apk_package *pkg, apk_blob_t to);
150
struct apk_package *apk_pkg_new(void);
151 152
int apk_pkg_read(struct apk_database *db, const char *name,
		 struct apk_sign_ctx *ctx, struct apk_package **pkg);
153 154
void apk_pkg_free(struct apk_package *pkg);

155 156
int apk_pkg_parse_name(apk_blob_t apkname, apk_blob_t *name, apk_blob_t *version);

157 158
int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg,
		     char field, apk_blob_t value);
159 160 161 162 163 164 165

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);
166 167 168
int apk_ipkg_run_script(struct apk_installed_package *ipkg,
			struct apk_database *db,
			unsigned int type, char **argv);
169 170

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

173 174
int apk_pkg_version_compare(struct apk_package *a, struct apk_package *b);

175
#endif