librazor/razor-internal.h
author Kristian H?gsberg <krh@redhat.com>
Wed Jun 25 15:29:49 2008 -0400 (2008-06-25)
changeset 295 c56b39adbfe4
parent 269 03fc85294bc9
child 300 455eaa569767
permissions -rw-r--r--
Fix pkg-config file problems.

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