librazor/razor-internal.h
author J. Ali Harlow <ali@juiblex.co.uk>
Wed Jul 08 22:14:16 2009 +0100 (2009-07-08)
changeset 377 5549419824b4
parent 376 d15a16347c77
child 388 6a6462ce8a08
permissions -rw-r--r--
Fix bugs when removing files and directories
     1 /*
     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>
     5  *
     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.
    10  *
    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.
    15  *
    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.
    19  */
    20 
    21 #ifndef _RAZOR_INTERNAL_H_
    22 #define _RAZOR_INTERNAL_H_
    23 
    24 #include <stdlib.h>
    25 #include <stdint.h>
    26 #include <stdarg.h>
    27 #include <unistd.h>
    28 
    29 #include "razor.h"
    30 #include "types/types.h"
    31 
    32 /* GCC visibility */
    33 #if defined(__GNUC__) && __GNUC__ >= 4
    34 #define RAZOR_EXPORT __attribute__ ((visibility("default")))
    35 #else
    36 #define RAZOR_EXPORT
    37 #endif
    38 
    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);
    43 
    44 struct razor_set_section {
    45 	uint32_t name;
    46 	uint32_t offset;
    47 	uint32_t size;
    48 };
    49 
    50 struct razor_set_header {
    51 	uint32_t magic;
    52 	uint32_t version;
    53 	uint32_t num_sections;
    54 };
    55 
    56 #define RAZOR_MAGIC 	0x525a4442
    57 #define RAZOR_VERSION	1
    58 
    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"
    65 
    66 #define RAZOR_DETAILS_STRING_POOL	"details_string_pool"
    67 
    68 #define RAZOR_FILES			"files"
    69 #define RAZOR_FILE_POOL			"file_pool"
    70 #define RAZOR_FILE_STRING_POOL		"file_string_pool"
    71 
    72 struct razor_script {
    73 	uint32_t program;
    74 	uint32_t body;
    75 };
    76 
    77 struct razor_package {
    78 	unsigned int name  : 24;
    79 	unsigned int flags : 8;
    80 	uint32_t version;
    81 	uint32_t arch;
    82 	uint32_t summary;
    83 	uint32_t description;
    84 	uint32_t url;
    85 	uint32_t license;
    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;
    91 };
    92 
    93 
    94 struct razor_property {
    95 	uint32_t name;
    96 	uint32_t flags;
    97 	uint32_t version;
    98 	struct list_head packages;
    99 };
   100 
   101 struct razor_entry {
   102 	uint32_t name  : 24;
   103 	uint32_t flags : 8;
   104 	uint32_t start;
   105 	struct list_head packages;
   106 };
   107 
   108 #define RAZOR_ENTRY_LAST	0x80
   109 
   110 struct razor_set {
   111 	struct array string_pool;
   112  	struct array packages;
   113  	struct array properties;
   114  	struct array files;
   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;
   122 };
   123 
   124 struct import_entry {
   125 	uint32_t package;
   126 	char *name;
   127 };
   128 
   129 struct import_directory {
   130 	uint32_t name, count;
   131 	struct array files;
   132 	struct array packages;
   133 	struct import_directory *last;
   134 };
   135 
   136 struct razor_importer {
   137 	struct razor_set *set;
   138 	struct hashtable table;
   139 	struct hashtable file_table;
   140 	struct hashtable details_table;
   141 	struct razor_package *package;
   142 	struct array properties;
   143 	struct array files;
   144 	struct array file_requires;
   145 	struct array install_prefixes;
   146 };
   147 
   148 struct razor_package_iterator {
   149 	struct razor_set *set;
   150 	struct razor_package *package, *end;
   151 	struct list *index;
   152 	int free_index;
   153 };
   154 
   155 void
   156 razor_package_iterator_init_for_property(struct razor_package_iterator *pi,
   157 					 struct razor_set *set,
   158 					 struct razor_property *property);
   159 
   160 struct razor_property_iterator {
   161 	struct razor_set *set;
   162 	struct razor_property *property, *end;
   163 	struct list *index;
   164 };
   165 
   166 struct razor_file_iterator {
   167 	struct razor_set *set;
   168 	struct array path;
   169 	struct list *index;
   170 	int post_order;
   171 };
   172 
   173 struct razor_entry *
   174 razor_set_find_entry(struct razor_set *set,
   175 		     struct razor_entry *dir, const char *pattern);
   176 
   177 struct razor_merger *
   178 razor_merger_create(struct razor_set *set1, struct razor_set *set2);
   179 void
   180 razor_merger_add_package(struct razor_merger *merger,
   181 			 struct razor_package *package);
   182 struct razor_set *
   183 razor_merger_commit(struct razor_merger *merger);
   184 void
   185 razor_merger_package_add_script(struct razor_merger *merger,
   186 				struct razor_package *package,
   187 				enum razor_property_flags script,
   188 				const char *program, const char *body);
   189 void
   190 razor_merger_destroy(struct razor_merger *merger);
   191 
   192 int run_lua_script(const char *root, const char *name, const char *body,
   193 		   ssize_t len, int arg1);
   194 
   195 int razor_run_script(const char *root, enum razor_property_flags script,
   196 		     const char *program, const char *body, int arg1);
   197 
   198 /* Utility functions */
   199 
   200 void
   201 razor_package_get_details_varg(struct razor_set *set,
   202 			       struct razor_package *package,
   203 			       va_list args);
   204 void razor_rpm_get_details_varg(struct razor_rpm *rpm, va_list args);
   205 
   206 int razor_create_dir(const char *root, const char *path);
   207 int razor_remove(const char *path);
   208 int razor_write(int fd, const void *data, size_t size);
   209 
   210 void *razor_file_get_contents(const char *filename, size_t *length);
   211 int razor_file_free_contents(void *addr, size_t length);
   212 
   213 
   214 typedef int (*razor_compare_with_data_func_t)(const void *p1,
   215 					      const void *p,
   216 					      void *data);
   217 uint32_t *
   218 razor_qsort_with_data(void *base, size_t nelem, size_t size,
   219 		      razor_compare_with_data_func_t compare, void *data);
   220 
   221 struct environment {
   222 	int is_set;
   223 	struct array vars, string_pool;
   224 };
   225 
   226 void environment_init(struct environment *env);
   227 void environment_add_variable(struct environment *env,
   228 			      const char *variable, const char *value);
   229 void environment_set(struct environment *env);
   230 void environment_unset(struct environment *env);
   231 void environment_release(struct environment *env);
   232 
   233 #endif /* _RAZOR_INTERNAL_H_ */