librazor/razor-internal.h
author Richard Hughes <richard@hughsie.com>
Sun Jun 29 10:55:17 2008 +0100 (2008-06-29)
changeset 300 455eaa569767
parent 271 3980d1d9148e
child 302 9b71b537d175
permissions -rw-r--r--
add missing licencing information at the top of each source file

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