2 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
3 * Copyright (C) 2008 Red Hat, Inc
4 * Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #ifndef _RAZOR_INTERNAL_H_
22 #define _RAZOR_INTERNAL_H_
30 #include "types/types.h"
33 #if defined(__GNUC__) && __GNUC__ >= 4
34 #define RAZOR_EXPORT __attribute__ ((visibility("default")))
39 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
40 #define PADDING(value, base) (-(value) & (base - 1))
41 #define ALIGN(value, base) ((value) + PADDING(value, base))
42 void *zalloc(size_t size);
44 struct razor_set_section {
50 struct razor_set_header {
53 uint32_t num_sections;
56 #define RAZOR_MAGIC 0x525a4442
57 #define RAZOR_VERSION 1
59 #define RAZOR_STRING_POOL "string_pool"
60 #define RAZOR_PACKAGES "packages"
61 #define RAZOR_PROPERTIES "properties"
62 #define RAZOR_PACKAGE_POOL "package_pool"
63 #define RAZOR_PROPERTY_POOL "property_pool"
64 #define RAZOR_PREFIX_POOL "prefix_pool"
66 #define RAZOR_DETAILS_STRING_POOL "details_string_pool"
68 #define RAZOR_FILES "files"
69 #define RAZOR_FILE_POOL "file_pool"
70 #define RAZOR_FILE_STRING_POOL "file_string_pool"
77 struct razor_package {
78 unsigned int name : 24;
79 unsigned int flags : 8;
86 struct list_head properties;
87 struct list_head files;
88 struct list_head install_prefixes;
89 struct razor_script preun;
90 struct razor_script postun;
94 struct razor_property {
98 struct list_head packages;
105 struct list_head packages;
108 #define RAZOR_ENTRY_LAST 0x80
111 struct array string_pool;
112 struct array packages;
113 struct array properties;
115 struct array package_pool;
116 struct array property_pool;
117 struct array file_pool;
118 struct array prefix_pool;
119 struct array file_string_pool;
120 struct array details_string_pool;
121 struct razor_mapped_file *mapped_files;
125 struct import_entry {
130 struct import_directory {
131 uint32_t name, count;
133 struct array packages;
134 struct import_directory *last;
137 struct razor_importer {
138 struct razor_set *set;
139 struct hashtable table;
140 struct hashtable file_table;
141 struct hashtable details_table;
142 struct razor_package *package;
143 struct array properties;
145 struct array file_requires;
146 struct array install_prefixes;
149 struct razor_package_iterator {
150 struct razor_set *set;
151 struct razor_package *package, *end;
157 razor_package_iterator_init_for_property(struct razor_package_iterator *pi,
158 struct razor_set *set,
159 struct razor_property *property);
161 struct razor_property_iterator {
162 struct razor_set *set;
163 struct razor_property *property, *end;
167 struct razor_file_iterator {
168 struct razor_set *set;
175 razor_set_aquire_lock(struct razor_set *set, const char *path, int exclusive);
178 razor_set_find_entry(struct razor_set *set,
179 struct razor_entry *dir, const char *pattern);
181 struct razor_merger *
182 razor_merger_create(struct razor_set *set1, struct razor_set *set2);
184 razor_merger_add_package(struct razor_merger *merger,
185 struct razor_package *package);
187 razor_merger_commit(struct razor_merger *merger);
189 razor_merger_package_add_script(struct razor_merger *merger,
190 struct razor_package *package,
191 enum razor_property_flags script,
192 const char *program, const char *body);
194 razor_merger_destroy(struct razor_merger *merger);
196 int run_lua_script(const char *root, const char *name, const char *body,
197 ssize_t len, int arg1);
199 int razor_run_script(const char *root, enum razor_property_flags script,
200 const char *program, const char *body, int arg1);
202 /* Utility functions */
205 razor_package_get_details_varg(struct razor_set *set,
206 struct razor_package *package,
208 void razor_rpm_get_details_varg(struct razor_rpm *rpm, va_list args);
210 int razor_create_dir(const char *root, const char *path);
211 int razor_remove(const char *path);
212 int razor_write(int fd, const void *data, size_t size);
214 void *razor_file_get_contents(const char *filename, size_t *length);
215 int razor_file_free_contents(void *addr, size_t length);
218 typedef int (*razor_compare_with_data_func_t)(const void *p1,
222 razor_qsort_with_data(void *base, size_t nelem, size_t size,
223 razor_compare_with_data_func_t compare, void *data);
227 struct array vars, string_pool;
230 void environment_init(struct environment *env);
231 void environment_add_variable(struct environment *env,
232 const char *variable, const char *value);
233 void environment_set(struct environment *env);
234 void environment_unset(struct environment *env);
235 void environment_release(struct environment *env);
237 #endif /* _RAZOR_INTERNAL_H_ */