librazor/razor-internal.h
author Richard Hughes <richard@hughsie.com>
Mon Jun 30 09:47:32 2008 +0100 (2008-06-30)
changeset 303 2d450078e46e
parent 300 455eaa569767
child 318 829d6711b316
permissions -rw-r--r--
trivial: razor_property_iterator_create() can have package NULL and be valid
     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 
    27 #include "razor.h"
    28 
    29 /* GCC visibility */
    30 #if defined(__GNUC__) && __GNUC__ >= 4
    31 #define RAZOR_EXPORT __attribute__ ((visibility("default")))
    32 #else
    33 #define RAZOR_EXPORT
    34 #endif
    35 
    36 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
    37 #define ALIGN(value, base) (((value) + (base - 1)) & ~((base) - 1))
    38 
    39 void *zalloc(size_t size);
    40 
    41 struct array {
    42 	void *data;
    43 	int size, alloc;
    44 };
    45 
    46 void array_init(struct array *array);
    47 void array_release(struct array *array);
    48 void *array_add(struct array *array, int size);
    49 
    50 
    51 struct list_head {
    52 	uint32_t list_ptr : 24;
    53 	uint32_t flags    : 8;
    54 };
    55 
    56 struct list {
    57 	uint32_t data  : 24;
    58 	uint32_t flags : 8;
    59 };
    60 
    61 void list_set_empty(struct list_head *head);
    62 void list_set_ptr(struct list_head *head, uint32_t ptr);
    63 void list_set_array(struct list_head *head, struct array *pool, struct array *items, int force_indirect);
    64 
    65 struct list *list_first(struct list_head *head, struct array *pool);
    66 struct list *list_next(struct list *list);
    67 
    68 void list_remap_pool(struct array *pool, uint32_t *map);
    69 void list_remap_head(struct list_head *list, uint32_t *map);
    70 
    71 
    72 struct hashtable {
    73 	struct array buckets;
    74 	struct array *pool;
    75 };
    76 
    77 void hashtable_init(struct hashtable *table, struct array *pool);
    78 void hashtable_release(struct hashtable *table);
    79 uint32_t hashtable_insert(struct hashtable *table, const char *key);
    80 uint32_t hashtable_lookup(struct hashtable *table, const char *key);
    81 uint32_t hashtable_tokenize(struct hashtable *table, const char *string);
    82 
    83 
    84 struct razor_set_section {
    85 	uint32_t type;
    86 	uint32_t offset;
    87 	uint32_t size;
    88 };
    89 
    90 struct razor_set_header {
    91 	uint32_t magic;
    92 	uint32_t version;
    93 	struct razor_set_section sections[0];
    94 };
    95 
    96 #define RAZOR_MAGIC 		0x7a7a7a7a
    97 #define RAZOR_DETAILS_MAGIC 	0x7a7a7a7b
    98 #define RAZOR_FILES_MAGIC 	0x7a7a7a7c
    99 #define RAZOR_VERSION 1
   100 
   101 #define RAZOR_STRING_POOL		0
   102 #define RAZOR_PACKAGES			1
   103 #define RAZOR_PROPERTIES		2
   104 #define RAZOR_PACKAGE_POOL		3
   105 #define RAZOR_PROPERTY_POOL		4
   106 
   107 #define RAZOR_DETAILS_STRING_POOL	0
   108 
   109 #define RAZOR_FILES			0
   110 #define RAZOR_FILE_POOL			1
   111 #define RAZOR_FILE_STRING_POOL		2
   112 
   113 struct razor_package {
   114 	uint name  : 24;
   115 	uint flags : 8;
   116 	uint32_t version;
   117 	uint32_t arch;
   118 	uint32_t summary;
   119 	uint32_t description;
   120 	uint32_t url;
   121 	uint32_t license;
   122 	struct list_head properties;
   123 	struct list_head files;
   124 };
   125 
   126 
   127 struct razor_property {
   128 	uint32_t name;
   129 	uint32_t flags;
   130 	uint32_t version;
   131 	struct list_head packages;
   132 };
   133 
   134 struct razor_entry {
   135 	uint32_t name  : 24;
   136 	uint32_t flags : 8;
   137 	uint32_t start;
   138 	struct list_head packages;
   139 };
   140 
   141 #define RAZOR_ENTRY_LAST	0x80
   142 
   143 struct razor_set {
   144 	struct array string_pool;
   145  	struct array packages;
   146  	struct array properties;
   147  	struct array files;
   148 	struct array package_pool;
   149  	struct array property_pool;
   150  	struct array file_pool;
   151 	struct array file_string_pool;
   152 	struct array details_string_pool;
   153 	struct razor_set_header *header;
   154 	struct razor_set_header *details_header;
   155 	struct razor_set_header *files_header;
   156 };
   157 
   158 struct import_entry {
   159 	uint32_t package;
   160 	char *name;
   161 };
   162 
   163 struct import_directory {
   164 	uint32_t name, count;
   165 	struct array files;
   166 	struct array packages;
   167 	struct import_directory *last;
   168 };
   169 
   170 struct razor_importer {
   171 	struct razor_set *set;
   172 	struct hashtable table;
   173 	struct hashtable file_table;
   174 	struct hashtable details_table;
   175 	struct razor_package *package;
   176 	struct array properties;
   177 	struct array files;
   178 	struct array file_requires;
   179 };
   180 
   181 struct razor_package_iterator {
   182 	struct razor_set *set;
   183 	struct razor_package *package, *end;
   184 	struct list *index;
   185 	int free_index;
   186 };
   187 
   188 void
   189 razor_package_iterator_init_for_property(struct razor_package_iterator *pi,
   190 					 struct razor_set *set,
   191 					 struct razor_property *property);
   192 
   193 struct razor_property_iterator {
   194 	struct razor_set *set;
   195 	struct razor_property *property, *end;
   196 	struct list *index;
   197 };
   198 
   199 struct razor_entry *
   200 razor_set_find_entry(struct razor_set *set,
   201 		     struct razor_entry *dir, const char *pattern);
   202 
   203 struct razor_merger *
   204 razor_merger_create(struct razor_set *set1, struct razor_set *set2);
   205 void
   206 razor_merger_add_package(struct razor_merger *merger,
   207 			 struct razor_package *package);
   208 struct razor_set *
   209 razor_merger_finish(struct razor_merger *merger);
   210 
   211 /* Utility functions */
   212 
   213 void
   214 razor_package_get_details_varg(struct razor_set *set,
   215 			       struct razor_package *package,
   216 			       va_list args);
   217 
   218 int razor_create_dir(const char *root, const char *path);
   219 int razor_write(int fd, const void *data, size_t size);
   220 
   221 
   222 typedef int (*razor_compare_with_data_func_t)(const void *p1,
   223 					      const void *p,
   224 					      void *data);
   225 uint32_t *
   226 razor_qsort_with_data(void *base, size_t nelem, size_t size,
   227 		      razor_compare_with_data_func_t compare, void *data);
   228 
   229 #endif /* _RAZOR_INTERNAL_H_ */