librazor/razor-internal.h
author J. Ali Harlow <ali@juiblex.co.uk>
Thu Jul 02 11:31:45 2009 +0100 (2009-07-02)
changeset 371 d7eea3164151
parent 364 66ec30bde5e5
child 372 6e93e5485947
permissions -rw-r--r--
Test uninstall scripts survive merge
     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 ALIGN(value, base) (((value) + (base - 1)) & ~((base) - 1))
    41 
    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 
    65 #define RAZOR_DETAILS_STRING_POOL	"details_string_pool"
    66 
    67 #define RAZOR_FILES			"files"
    68 #define RAZOR_FILE_POOL			"file_pool"
    69 #define RAZOR_FILE_STRING_POOL		"file_string_pool"
    70 
    71 struct razor_script {
    72 	uint32_t program;
    73 	uint32_t body;
    74 };
    75 
    76 struct razor_package {
    77 	unsigned int name  : 24;
    78 	unsigned int flags : 8;
    79 	uint32_t version;
    80 	uint32_t arch;
    81 	uint32_t summary;
    82 	uint32_t description;
    83 	uint32_t url;
    84 	uint32_t license;
    85 	struct list_head properties;
    86 	struct list_head files;
    87 	struct razor_script preun;
    88 	struct razor_script postun;
    89 };
    90 
    91 
    92 struct razor_property {
    93 	uint32_t name;
    94 	uint32_t flags;
    95 	uint32_t version;
    96 	struct list_head packages;
    97 };
    98 
    99 struct razor_entry {
   100 	uint32_t name  : 24;
   101 	uint32_t flags : 8;
   102 	uint32_t start;
   103 	struct list_head packages;
   104 };
   105 
   106 #define RAZOR_ENTRY_LAST	0x80
   107 
   108 struct razor_set {
   109 	struct array string_pool;
   110  	struct array packages;
   111  	struct array properties;
   112  	struct array files;
   113 	struct array package_pool;
   114  	struct array property_pool;
   115  	struct array file_pool;
   116 	struct array file_string_pool;
   117 	struct array details_string_pool;
   118 
   119 	struct razor_set_header *header;
   120 	size_t header_size;
   121 
   122 	struct razor_set_header *details_header;
   123 	size_t details_header_size;
   124 
   125 	struct razor_set_header *files_header;
   126 	size_t files_header_size;
   127 };
   128 
   129 struct import_entry {
   130 	uint32_t package;
   131 	char *name;
   132 };
   133 
   134 struct import_directory {
   135 	uint32_t name, count;
   136 	struct array files;
   137 	struct array packages;
   138 	struct import_directory *last;
   139 };
   140 
   141 struct razor_importer {
   142 	struct razor_set *set;
   143 	struct hashtable table;
   144 	struct hashtable file_table;
   145 	struct hashtable details_table;
   146 	struct razor_package *package;
   147 	struct array properties;
   148 	struct array files;
   149 	struct array file_requires;
   150 };
   151 
   152 struct razor_package_iterator {
   153 	struct razor_set *set;
   154 	struct razor_package *package, *end;
   155 	struct list *index;
   156 	int free_index;
   157 };
   158 
   159 void
   160 razor_package_iterator_init_for_property(struct razor_package_iterator *pi,
   161 					 struct razor_set *set,
   162 					 struct razor_property *property);
   163 
   164 struct razor_property_iterator {
   165 	struct razor_set *set;
   166 	struct razor_property *property, *end;
   167 	struct list *index;
   168 };
   169 
   170 struct razor_file_iterator {
   171 	struct razor_set *set;
   172 	struct array path;
   173 	struct list *index;
   174 };
   175 
   176 struct razor_entry *
   177 razor_set_find_entry(struct razor_set *set,
   178 		     struct razor_entry *dir, const char *pattern);
   179 
   180 struct razor_merger *
   181 razor_merger_create(struct razor_set *set1, struct razor_set *set2);
   182 void
   183 razor_merger_add_package(struct razor_merger *merger,
   184 			 struct razor_package *package);
   185 struct razor_set *
   186 razor_merger_commit(struct razor_merger *merger);
   187 void
   188 razor_merger_package_add_script(struct razor_merger *merger,
   189 				struct razor_package *package,
   190 				enum razor_property_flags script,
   191 				const char *program, const char *body);
   192 void
   193 razor_merger_destroy(struct razor_merger *merger);
   194 
   195 int run_lua_script(const char *root, const char *name, const char *body,
   196 		   ssize_t len);
   197 
   198 int razor_run_script(const char *root, enum razor_property_flags script,
   199 		     const char *program, const char *body);
   200 
   201 /* Utility functions */
   202 
   203 void
   204 razor_package_get_details_varg(struct razor_set *set,
   205 			       struct razor_package *package,
   206 			       va_list args);
   207 void razor_rpm_get_details_varg(struct razor_rpm *rpm, va_list args);
   208 
   209 int razor_create_dir(const char *root, const char *path);
   210 int razor_write(int fd, const void *data, size_t size);
   211 
   212 void *razor_file_get_contents(const char *filename, size_t *length);
   213 int razor_file_free_contents(void *addr, size_t length);
   214 
   215 
   216 typedef int (*razor_compare_with_data_func_t)(const void *p1,
   217 					      const void *p,
   218 					      void *data);
   219 uint32_t *
   220 razor_qsort_with_data(void *base, size_t nelem, size_t size,
   221 		      razor_compare_with_data_func_t compare, void *data);
   222 
   223 #endif /* _RAZOR_INTERNAL_H_ */