summaryrefslogtreecommitdiff
path: root/librazor/razor-internal.h
blob: fbedd77eea36bb32575c0ab0eed9d7d1b47e962d (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
 * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
 * Copyright (C) 2008  Red Hat, Inc
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef _RAZOR_INTERNAL_H_
#define _RAZOR_INTERNAL_H_

#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>

#include "razor.h"

/* GCC visibility */
#if defined(__GNUC__) && __GNUC__ >= 4
#define RAZOR_EXPORT __attribute__ ((visibility("default")))
#else
#define RAZOR_EXPORT
#endif

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#define PADDING(value, base) (-(value) & (base - 1))
#define ALIGN(value, base) ((value) + PADDING(value, base))
void *zalloc(size_t size);

struct array {
	void *data;
	int size, alloc;
};

void array_init(struct array *array);
void array_release(struct array *array);
void *array_add(struct array *array, int size);


struct list_head {
	uint32_t list_ptr : 24;
	uint32_t flags    : 8;
};

struct list {
	uint32_t data  : 24;
	uint32_t flags : 8;
};

void list_set_empty(struct list_head *head);
void list_set_ptr(struct list_head *head, uint32_t ptr);
void list_set_array(struct list_head *head, struct array *pool, struct array *items, int force_indirect);

struct list *list_first(struct list_head *head, struct array *pool);
struct list *list_next(struct list *list);

void list_remap_pool(struct array *pool, uint32_t *map);
void list_remap_head(struct list_head *list, uint32_t *map);


struct hashtable {
	struct array buckets;
	struct array *pool;
};

void hashtable_init(struct hashtable *table, struct array *pool);
void hashtable_release(struct hashtable *table);
uint32_t hashtable_insert(struct hashtable *table, const char *key);
uint32_t hashtable_lookup(struct hashtable *table, const char *key);
uint32_t hashtable_tokenize(struct hashtable *table, const char *string);


struct razor_set_section {
	uint32_t name;
	uint32_t offset;
	uint32_t size;
};

struct razor_set_header {
	uint32_t magic;
	uint32_t version;
	uint32_t num_sections;
};

#define RAZOR_MAGIC 	0x525a4442
#define RAZOR_VERSION	1

#define RAZOR_STRING_POOL		"string_pool"
#define RAZOR_PACKAGES			"packages"
#define RAZOR_PROPERTIES		"properties"
#define RAZOR_PACKAGE_POOL		"package_pool"
#define RAZOR_PROPERTY_POOL		"property_pool"

#define RAZOR_DETAILS_STRING_POOL	"details_string_pool"

#define RAZOR_FILES			"files"
#define RAZOR_FILE_POOL			"file_pool"
#define RAZOR_FILE_STRING_POOL		"file_string_pool"

struct razor_package {
	uint name  : 24;
	uint flags : 8;
	uint32_t version;
	uint32_t arch;
	uint32_t summary;
	uint32_t description;
	uint32_t url;
	uint32_t license;
	struct list_head properties;
	struct list_head files;
};


struct razor_property {
	uint32_t name;
	uint32_t flags;
	uint32_t version;
	struct list_head packages;
};

struct razor_entry {
	uint32_t name  : 24;
	uint32_t flags : 8;
	uint32_t start;
	struct list_head packages;
};

#define RAZOR_ENTRY_LAST	0x80

struct razor_set {
	struct array string_pool;
 	struct array packages;
 	struct array properties;
 	struct array files;
	struct array package_pool;
 	struct array property_pool;
 	struct array file_pool;
	struct array file_string_pool;
	struct array details_string_pool;
	struct razor_mapped_file *mapped_files;
};

struct import_entry {
	uint32_t package;
	char *name;
};

struct import_directory {
	uint32_t name, count;
	struct array files;
	struct array packages;
	struct import_directory *last;
};

struct razor_importer {
	struct razor_set *set;
	struct hashtable table;
	struct hashtable file_table;
	struct hashtable details_table;
	struct razor_package *package;
	struct array properties;
	struct array files;
	struct array file_requires;
};

struct razor_package_iterator {
	struct razor_set *set;
	struct razor_package *package, *end;
	struct list *index;
	int free_index;
};

void
razor_package_iterator_init_for_property(struct razor_package_iterator *pi,
					 struct razor_set *set,
					 struct razor_property *property);

struct razor_property_iterator {
	struct razor_set *set;
	struct razor_property *property, *end;
	struct list *index;
};

struct razor_entry *
razor_set_find_entry(struct razor_set *set,
		     struct razor_entry *dir, const char *pattern);

struct razor_merger *
razor_merger_create(struct razor_set *set1, struct razor_set *set2);
void
razor_merger_add_package(struct razor_merger *merger,
			 struct razor_package *package);
struct razor_set *
razor_merger_finish(struct razor_merger *merger);

/* Utility functions */

void
razor_package_get_details_varg(struct razor_set *set,
			       struct razor_package *package,
			       va_list args);

int razor_create_dir(const char *root, const char *path);
int razor_write(int fd, const void *data, size_t size);


typedef int (*razor_compare_with_data_func_t)(const void *p1,
					      const void *p,
					      void *data);
uint32_t *
razor_qsort_with_data(void *base, size_t nelem, size_t size,
		      razor_compare_with_data_func_t compare, void *data);

#endif /* _RAZOR_INTERNAL_H_ */