package.h 3.03 KB
Newer Older
1 2 3
#ifndef REPREPRO_PACKAGE_H
#define REPREPRO_PACKAGE_H

4 5
#include "atoms.h"

6 7 8 9 10
struct package {
	/*@temp@*/ struct target *target;
	const char *name;
	const char *control;
	size_t controllen;
11 12 13 14
	/* for the following NULL means not yet extracted: */
	const char *version;
	const char *source;
	const char *sourceversion;
15
	architecture_t architecture;
16 17 18

	/* used to keep the memory that might be needed for the above,
	 * only to be used to free once this struct is abandoned */
19
	char *pkgchunk, *pkgname, *pkgversion, *pkgsource, *pkgsrcversion;
20
};
21
struct distribution;
22
struct target;
23
struct atomlist;
24 25
struct logger;
struct trackingdata;
26

27 28 29 30 31 32 33 34 35 36 37
typedef retvalue action_each_target(struct target *, void *);
typedef retvalue action_each_package(struct package *, void *);

/* call <action> for each package of <distribution> */
retvalue package_foreach(struct distribution *, /*@null@*/const struct atomlist *, /*@null@*/const struct atomlist *, /*@null@*/const struct atomlist *, action_each_package, /*@null@*/action_each_target, void *);
/* same but different ways to restrict it */
retvalue package_foreach_c(struct distribution *, /*@null@*/const struct atomlist *, architecture_t, packagetype_t, action_each_package, void *);

/* delete every package decider returns RET_OK for */
retvalue package_remove_each(struct distribution *, const struct atomlist *, const struct atomlist *, const struct atomlist *, action_each_package /*decider*/, struct trackingdata *, void *);

38 39 40 41 42 43

retvalue package_get(struct target *, const char * /*name*/, /*@null@*/ const char */*version*/, /*@out@*/ struct package *);

static inline void package_done(struct package *pkg) {
	free(pkg->pkgname);
	free(pkg->pkgchunk);
44 45 46
	free(pkg->pkgversion);
	free(pkg->pkgsource);
	free(pkg->pkgsrcversion);
47 48 49
	memset(pkg, 0, sizeof(*pkg));
}

50 51
retvalue package_getversion(struct package *);
retvalue package_getsource(struct package *);
52
retvalue package_getarchitecture(struct package *);
53 54 55 56 57 58 59 60 61 62 63 64 65

static inline char *package_dupversion(struct package *package) {
	assert (package->version != NULL);
	if (package->pkgversion == NULL)
		return strdup(package->version);
	else {
		// steal version from package
		// (caller must ensure it is not freed while still needed)
		char *v = package->pkgversion;
		package->pkgversion = NULL;
		return v;
	}
}
66 67 68 69 70 71 72 73 74 75 76

struct package_cursor {
	/*@temp@*/struct target *target;
	struct cursor *cursor;
	struct package current;
};

retvalue package_openiterator(struct target *, bool /*readonly*/, /*@out@*/struct package_cursor *);
bool package_next(struct package_cursor *);
retvalue package_closeiterator(struct package_cursor *);

77
retvalue package_remove(struct package *, /*@null@*/struct logger *, /*@null@*/struct trackingdata *);
78 79 80
retvalue package_remove_by_cursor(struct package_cursor *, /*@null@*/struct logger *, /*@null@*/struct trackingdata *);
retvalue package_newcontrol_by_cursor(struct package_cursor *, const char *, size_t);

81 82 83 84
retvalue package_check(struct package *, void *);
retvalue package_referenceforsnapshot(struct package *, void *);
retvalue package_rerunnotifiers(struct package *, void *);

85
#endif