/* * Copyright (C) 2008 Kristian Høgsberg * Copyright (C) 2008 Red Hat, Inc * Copyright (C) 2009, 2011 J. Ali Harlow * * 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 #include #include #include #include "razor.h" #include "types/types.h" /* GCC extensions */ #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 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_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_PREFIX_POOL "prefix_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_script { uint32_t program; uint32_t body; }; struct razor_package { unsigned int name : 24; unsigned int 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 list_head install_prefixes; struct razor_script preun; struct razor_script postun; }; 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 { uint32_t header_version; 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 prefix_pool; struct array file_string_pool; struct array details_string_pool; struct razor_mapped_file *mapped_files; int lock_fd, ref_count; }; 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 array install_prefixes; }; 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_file_iterator { struct razor_set *set; struct array path; struct list *index; int post_order; }; int razor_set_aquire_lock(struct razor_set *set, const char *path, int exclusive); 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_commit(struct razor_merger *merger); void razor_merger_package_add_script(struct razor_merger *merger, struct razor_package *package, enum razor_property_flags script, const char *program, const char *body); void razor_merger_destroy(struct razor_merger *merger); int run_lua_script(const char *root, const char *name, const char *body, ssize_t len, int arg1); int razor_run_script(const char *root, enum razor_property_flags script, const char *program, const char *body, int arg1); /* Utility functions */ void razor_package_get_details_varg(struct razor_set *set, struct razor_package *package, va_list args); void razor_rpm_get_details_varg(struct razor_rpm *rpm, va_list args); int razor_create_dir(const char *root, const char *path); int razor_remove(const char *path); int razor_write(int fd, const void *data, size_t size); void *razor_file_get_contents(const char *filename, size_t *length); int razor_file_free_contents(void *addr, size_t length); 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); struct environment { int is_set; struct array vars, string_pool; }; void environment_init(struct environment *env); void environment_add_variable(struct environment *env, const char *variable, const char *value); void environment_set(struct environment *env); void environment_unset(struct environment *env); void environment_release(struct environment *env); #endif /* _RAZOR_INTERNAL_H_ */