apk_package.h 3.97 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 23 24 25 26 27 28
#define APK_SCRIPT_INVALID		-1
#define APK_SCRIPT_PRE_INSTALL		1
#define APK_SCRIPT_POST_INSTALL		2
#define APK_SCRIPT_PRE_DEINSTALL	3
#define APK_SCRIPT_POST_DEINSTALL	4
#define APK_SCRIPT_PRE_UPGRADE		5
#define APK_SCRIPT_POST_UPGRADE		6
29

30 31 32
#define APK_PKG_NOT_INSTALLED		0
#define APK_PKG_INSTALLED		1

33 34 35 36
#define APK_SIGN_VERIFY			0
#define APK_SIGN_GENERATE_V1		1
#define APK_SIGN_GENERATE		2

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

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

57 58 59 60 61 62 63
struct apk_script {
	struct hlist_node script_list;
	unsigned int type;
	unsigned int size;
	char script[];
};

64 65 66 67
#define APK_DEPMASK_REQUIRE	(APK_VERSION_EQUAL|APK_VERSION_LESS|\
				 APK_VERSION_GREATER)
#define APK_DEPMASK_CONFLICT	(0)

68 69
struct apk_dependency {
	struct apk_name *name;
70 71
	int result_mask;
	char *version;
72 73 74 75 76 77
};
APK_ARRAY(apk_dependency_array, struct apk_dependency);

struct apk_package {
	apk_hash_node hash_node;

78
	unsigned repos;
79 80 81 82
	struct apk_name *name;
	char *version;
	char *url, *description, *license;
	struct apk_dependency_array *depends;
Timo Teräs's avatar
Timo Teräs committed
83
	size_t installed_size, size;
84
	char *filename;
Timo Teräs's avatar
Timo Teräs committed
85
	struct apk_checksum csum;
86 87

	/* for installed packages only */
88
	struct list_head installed_pkgs_list;
89
	struct hlist_head owned_dirs;
90 91 92 93
	struct hlist_head scripts;
};
APK_ARRAY(apk_package_array, struct apk_package *);

Timo Teräs's avatar
Timo Teräs committed
94 95
extern const char *apk_script_types[];

Timo Teräs's avatar
Timo Teräs committed
96 97 98 99 100
void apk_sign_ctx_init(struct apk_sign_ctx *ctx, int action);
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);
101
int apk_sign_ctx_mpart_cb(void *ctx, int part, apk_blob_t blob);
Timo Teräs's avatar
Timo Teräs committed
102

103 104
int apk_deps_add(struct apk_dependency_array **depends,
		 struct apk_dependency *dep);
105 106
void apk_deps_del(struct apk_dependency_array **deps,
		  struct apk_name *name);
107 108 109
void apk_deps_parse(struct apk_database *db,
		    struct apk_dependency_array **depends,
		    apk_blob_t blob);
110
int apk_deps_write(struct apk_dependency_array *deps, struct apk_ostream *os);
111 112
int apk_script_type(const char *name);

113
struct apk_package *apk_pkg_new(void);
Timo Teräs's avatar
Timo Teräs committed
114 115
struct apk_package *apk_pkg_read(struct apk_database *db, const char *name,
				 struct apk_sign_ctx *ctx);
116 117
void apk_pkg_free(struct apk_package *pkg);

118 119
int apk_pkg_parse_name(apk_blob_t apkname, apk_blob_t *name, apk_blob_t *version);

120 121
int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg,
		     char field, apk_blob_t value);
122
int apk_pkg_get_state(struct apk_package *pkg);
123
void apk_pkg_set_state(struct apk_database *db, struct apk_package *pkg, int state);
124
int apk_pkg_add_script(struct apk_package *pkg, struct apk_istream *is,
125
		       unsigned int type, unsigned int size);
126
int apk_pkg_run_script(struct apk_package *pkg, int root_fd,
127 128 129
		       unsigned int type);

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

132 133
int apk_pkg_version_compare(struct apk_package *a, struct apk_package *b);

Timo Teräs's avatar
Timo Teräs committed
134
struct apk_dependency apk_dep_from_str(struct apk_database *db, char *str);
135 136
struct apk_dependency apk_dep_from_pkg(struct apk_database *db,
				       struct apk_package *pkg);
137
#endif