librazor/razor-internal.h
author J. Ali Harlow <ali@juiblex.co.uk>
Wed Jun 03 08:26:09 2009 +0100 (2009-06-03)
changeset 368 ea743486ba6f
parent 360 c798d6db076b
child 369 f8c27fe9fe63
permissions -rw-r--r--
Add automatic provides for lua pre-loaded modules
     1 /*
     2  * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
     3  * Copyright (C) 2008  Red Hat, Inc
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; either version 2 of the License, or
     8  * (at your option) any later version.
     9  *
    10  * This program is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  * GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License along
    16  * with this program; if not, write to the Free Software Foundation, Inc.,
    17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    18  */
    19 
    20 #ifndef _RAZOR_INTERNAL_H_
    21 #define _RAZOR_INTERNAL_H_
    22 
    23 #include <stdlib.h>
    24 #include <stdint.h>
    25 #include <stdarg.h>
    26 #include <unistd.h>
    27 
    28 #include "razor.h"
    29 #include "types/types.h"
    30 
    31 /* GCC visibility */
    32 #if defined(__GNUC__) && __GNUC__ >= 4
    33 #define RAZOR_EXPORT __attribute__ ((visibility("default")))
    34 #else
    35 #define RAZOR_EXPORT
    36 #endif
    37 
    38 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
    39 #define ALIGN(value, base) (((value) + (base - 1)) & ~((base) - 1))
    40 
    41 void *zalloc(size_t size);
    42 
    43 struct razor_set_section {
    44 	uint32_t name;
    45 	uint32_t offset;
    46 	uint32_t size;
    47 };
    48 
    49 struct razor_set_header {
    50 	uint32_t magic;
    51 	uint32_t version;
    52 	uint32_t num_sections;
    53 };
    54 
    55 #define RAZOR_MAGIC 	0x525a4442
    56 #define RAZOR_VERSION	1
    57 
    58 #define RAZOR_STRING_POOL		"string_pool"
    59 #define RAZOR_PACKAGES			"packages"
    60 #define RAZOR_PROPERTIES		"properties"
    61 #define RAZOR_PACKAGE_POOL		"package_pool"
    62 #define RAZOR_PROPERTY_POOL		"property_pool"
    63 
    64 #define RAZOR_DETAILS_STRING_POOL	"details_string_pool"
    65 
    66 #define RAZOR_FILES			"files"
    67 #define RAZOR_FILE_POOL			"file_pool"
    68 #define RAZOR_FILE_STRING_POOL		"file_string_pool"
    69 
    70 struct razor_package {
    71 	unsigned int name  : 24;
    72 	unsigned int flags : 8;
    73 	uint32_t version;
    74 	uint32_t arch;
    75 	uint32_t summary;
    76 	uint32_t description;
    77 	uint32_t url;
    78 	uint32_t license;
    79 	struct list_head properties;
    80 	struct list_head files;
    81 };
    82 
    83 
    84 struct razor_property {
    85 	uint32_t name;
    86 	uint32_t flags;
    87 	uint32_t version;
    88 	struct list_head packages;
    89 };
    90 
    91 struct razor_entry {
    92 	uint32_t name  : 24;
    93 	uint32_t flags : 8;
    94 	uint32_t start;
    95 	struct list_head packages;
    96 };
    97 
    98 #define RAZOR_ENTRY_LAST	0x80
    99 
   100 struct razor_set {
   101 	struct array string_pool;
   102  	struct array packages;
   103  	struct array properties;
   104  	struct array files;
   105 	struct array package_pool;
   106  	struct array property_pool;
   107  	struct array file_pool;
   108 	struct array file_string_pool;
   109 	struct array details_string_pool;
   110 
   111 	struct razor_set_header *header;
   112 	size_t header_size;
   113 
   114 	struct razor_set_header *details_header;
   115 	size_t details_header_size;
   116 
   117 	struct razor_set_header *files_header;
   118 	size_t files_header_size;
   119 };
   120 
   121 struct import_entry {
   122 	uint32_t package;
   123 	char *name;
   124 };
   125 
   126 struct import_directory {
   127 	uint32_t name, count;
   128 	struct array files;
   129 	struct array packages;
   130 	struct import_directory *last;
   131 };
   132 
   133 struct razor_importer {
   134 	struct razor_set *set;
   135 	struct hashtable table;
   136 	struct hashtable file_table;
   137 	struct hashtable details_table;
   138 	struct razor_package *package;
   139 	struct array properties;
   140 	struct array files;
   141 	struct array file_requires;
   142 };
   143 
   144 struct razor_package_iterator {
   145 	struct razor_set *set;
   146 	struct razor_package *package, *end;
   147 	struct list *index;
   148 	int free_index;
   149 };
   150 
   151 void
   152 razor_package_iterator_init_for_property(struct razor_package_iterator *pi,
   153 					 struct razor_set *set,
   154 					 struct razor_property *property);
   155 
   156 struct razor_property_iterator {
   157 	struct razor_set *set;
   158 	struct razor_property *property, *end;
   159 	struct list *index;
   160 };
   161 
   162 struct razor_file_iterator {
   163 	struct razor_set *set;
   164 	struct array path;
   165 	struct list *index;
   166 };
   167 
   168 struct razor_entry *
   169 razor_set_find_entry(struct razor_set *set,
   170 		     struct razor_entry *dir, const char *pattern);
   171 
   172 struct razor_merger *
   173 razor_merger_create(struct razor_set *set1, struct razor_set *set2);
   174 void
   175 razor_merger_add_package(struct razor_merger *merger,
   176 			 struct razor_package *package);
   177 struct razor_set *
   178 razor_merger_finish(struct razor_merger *merger);
   179 
   180 int run_lua_script(const char *root, const char *name, const char *body,
   181 		   ssize_t len);
   182 
   183 /* Utility functions */
   184 
   185 void
   186 razor_package_get_details_varg(struct razor_set *set,
   187 			       struct razor_package *package,
   188 			       va_list args);
   189 
   190 int razor_create_dir(const char *root, const char *path);
   191 int razor_write(int fd, const void *data, size_t size);
   192 
   193 void *razor_file_get_contents(const char *filename, size_t *length);
   194 int razor_file_free_contents(void *addr, size_t length);
   195 
   196 
   197 typedef int (*razor_compare_with_data_func_t)(const void *p1,
   198 					      const void *p,
   199 					      void *data);
   200 uint32_t *
   201 razor_qsort_with_data(void *base, size_t nelem, size_t size,
   202 		      razor_compare_with_data_func_t compare, void *data);
   203 
   204 #endif /* _RAZOR_INTERNAL_H_ */