apk_package.h 4.74 KB
Newer Older
1 2 3 4 5 6
/* apk_database.h - Alpine Package Keeper (APK)
 *
 * Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
 * Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
 * 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 21

struct apk_database;
struct apk_name;

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

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_V1		3
#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 62 63
#define APK_DEPMASK_REQUIRE	(APK_VERSION_EQUAL|APK_VERSION_LESS|\
				 APK_VERSION_GREATER)
#define APK_DEPMASK_CONFLICT	(0)

64 65
struct apk_dependency {
	struct apk_name *name;
66 67
	int result_mask;
	char *version;
68 69 70
};
APK_ARRAY(apk_dependency_array, struct apk_dependency);

71 72
#define APK_IPKGF_RUN_ALL_TRIGGERS	0x00000001

73 74
struct apk_installed_package {
	struct apk_package *pkg;
75
	unsigned int flags;
76 77 78 79 80
	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;
81
	struct apk_string_array *pending_triggers;
82 83
};

84 85
struct apk_package {
	apk_hash_node hash_node;
86
	unsigned repos;
87 88 89 90
	struct apk_name *name;
	char *version;
	char *url, *description, *license;
	struct apk_dependency_array *depends;
Timo Teräs's avatar
Timo Teräs committed
91
	size_t installed_size, size;
92
	char *filename;
Timo Teräs's avatar
Timo Teräs committed
93
	struct apk_checksum csum;
94
	struct apk_installed_package *ipkg;
95 96 97
};
APK_ARRAY(apk_package_array, struct apk_package *);

Timo Teräs's avatar
Timo Teräs committed
98 99
extern const char *apk_script_types[];

100
void apk_sign_ctx_init(struct apk_sign_ctx *ctx, int action,
101
		       struct apk_checksum *identity, int keys_fd);
Timo Teräs's avatar
Timo Teräs committed
102 103 104 105
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);
106
int apk_sign_ctx_parse_pkginfo_line(void *ctx, apk_blob_t line);
107 108
int apk_sign_ctx_verify_tar(void *ctx, const struct apk_file_info *fi,
			    struct apk_istream *is);
109
int apk_sign_ctx_mpart_cb(void *ctx, int part, apk_blob_t blob);
Timo Teräs's avatar
Timo Teräs committed
110

Timo Teräs's avatar
Timo Teräs committed
111 112 113 114
int apk_dep_from_blob(struct apk_dependency *dep, struct apk_database *db,
		      apk_blob_t blob);
void apk_dep_from_pkg(struct apk_dependency *dep, struct apk_database *db,
		      struct apk_package *pkg);
115 116
void apk_blob_push_dep(apk_blob_t *to, struct apk_dependency *dep);

117 118
int apk_deps_add(struct apk_dependency_array **depends,
		 struct apk_dependency *dep);
119 120
void apk_deps_del(struct apk_dependency_array **deps,
		  struct apk_name *name);
121 122 123
void apk_deps_parse(struct apk_database *db,
		    struct apk_dependency_array **depends,
		    apk_blob_t blob);
Timo Teräs's avatar
Timo Teräs committed
124

125
int apk_deps_write(struct apk_dependency_array *deps, struct apk_ostream *os);
126 127
int apk_script_type(const char *name);

128 129
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);
130
struct apk_package *apk_pkg_new(void);
131 132
int apk_pkg_read(struct apk_database *db, const char *name,
		 struct apk_sign_ctx *ctx, struct apk_package **pkg);
133 134
void apk_pkg_free(struct apk_package *pkg);

135 136
int apk_pkg_parse_name(apk_blob_t apkname, apk_blob_t *name, apk_blob_t *version);

137 138
int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg,
		     char field, apk_blob_t value);
139 140 141 142 143 144 145 146 147

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);
int apk_ipkg_run_script(struct apk_installed_package *ipkg, int root_fd,
		        unsigned int type, char **argv);
148 149

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

152 153
int apk_pkg_version_compare(struct apk_package *a, struct apk_package *b);

154
#endif