summaryrefslogtreecommitdiff
path: root/src/apk_extract.h
blob: 94fc401bd6bcf0537a104922b6a4e9e1c582b34a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* apk_extract.c - Alpine Package Keeper (APK)
 *
 * Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
 * Copyright (C) 2008-2021 Timo Teräs <timo.teras@iki.fi>
 * All rights reserved.
 *
 * SPDX-License-Identifier: GPL-2.0-only
 */

#ifndef APK_EXTRACT
#define APK_EXTRACT

#include "apk_crypto.h"
#include "apk_print.h"
#include "apk_io.h"

struct adb;
struct apk_ctx;
struct apk_extract_ctx;

#define APK_EXTRACTF_NO_CHOWN		0x0001
#define APK_EXTRACTF_NO_OVERWRITE	0x0002

int apk_extract_file(int atfd, const struct apk_file_info *ae,
		const char *extract_name, const char *hardlink_name,
		struct apk_istream *is,
		apk_progress_cb cb, void *cb_ctx, struct apk_digest_ctx *dctx,
		unsigned int extract_flags, struct apk_out *out);

struct apk_extract_ops {
	int (*v2index)(struct apk_extract_ctx *, apk_blob_t *desc, struct apk_istream *is);
	int (*v2meta)(struct apk_extract_ctx *, struct apk_istream *is);
	int (*v3index)(struct apk_extract_ctx *, struct adb *);
	int (*v3meta)(struct apk_extract_ctx *, struct adb *);
	int (*script)(struct apk_extract_ctx *, unsigned int script, size_t size, struct apk_istream *is);
	int (*file)(struct apk_extract_ctx *, const struct apk_file_info *fi, struct apk_istream *is);
};

struct apk_extract_ctx {
	struct apk_ctx *ac;
	const struct apk_extract_ops *ops;
	struct apk_checksum *identity;
	apk_blob_t desc;
	void *pctx;
	unsigned generate_identity : 1;
	unsigned is_package : 1;
	unsigned is_index : 1;
};

static inline void apk_extract_init(struct apk_extract_ctx *ectx, struct apk_ctx *ac, const struct apk_extract_ops *ops) {
	*ectx = (struct apk_extract_ctx){.ac = ac, .ops = ops};
}
static inline void apk_extract_reset(struct apk_extract_ctx *ectx) {
	apk_extract_init(ectx, ectx->ac, ectx->ops);
}
static inline void apk_extract_generate_identity(struct apk_extract_ctx *ctx, struct apk_checksum *id) {
	ctx->identity = id;
	ctx->generate_identity = 1;
}
static inline void apk_extract_verify_identity(struct apk_extract_ctx *ctx, struct apk_checksum *id) {
	ctx->identity = id;
}
int apk_extract(struct apk_extract_ctx *, struct apk_istream *is);

int apk_extract_v2(struct apk_extract_ctx *, struct apk_istream *is);
void apk_extract_v2_control(struct apk_extract_ctx *, apk_blob_t, apk_blob_t);
int apk_extract_v2_meta(struct apk_extract_ctx *ectx, struct apk_istream *is);

int apk_extract_v3(struct apk_extract_ctx *, struct apk_istream *is);

#endif