librazor/razor-internal.h
author Richard Hughes <richard@hughsie.com>
Wed Jul 02 18:46:47 2008 +0100 (2008-07-02)
changeset 310 9a7691262ce6
parent 300 455eaa569767
child 318 829d6711b316
permissions -rw-r--r--
rename the .repo files to .rzdb files
richard@300
     1
/*
richard@300
     2
 * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
richard@300
     3
 * Copyright (C) 2008  Red Hat, Inc
richard@300
     4
 *
richard@300
     5
 * This program is free software; you can redistribute it and/or modify
richard@300
     6
 * it under the terms of the GNU General Public License as published by
richard@300
     7
 * the Free Software Foundation; either version 2 of the License, or
richard@300
     8
 * (at your option) any later version.
richard@300
     9
 *
richard@300
    10
 * This program is distributed in the hope that it will be useful,
richard@300
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
richard@300
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
richard@300
    13
 * GNU General Public License for more details.
richard@300
    14
 *
richard@300
    15
 * You should have received a copy of the GNU General Public License along
richard@300
    16
 * with this program; if not, write to the Free Software Foundation, Inc.,
richard@300
    17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
richard@300
    18
 */
richard@300
    19
rhughes@241
    20
#ifndef _RAZOR_INTERNAL_H_
rhughes@241
    21
#define _RAZOR_INTERNAL_H_
rhughes@241
    22
krh@248
    23
#include <stdlib.h>
krh@248
    24
#include <stdint.h>
richard@302
    25
#include <stdarg.h>
richard@302
    26
richard@302
    27
#include "razor.h"
krh@248
    28
krh@269
    29
/* GCC visibility */
krh@269
    30
#if defined(__GNUC__) && __GNUC__ >= 4
krh@269
    31
#define RAZOR_EXPORT __attribute__ ((visibility("default")))
krh@269
    32
#else
krh@269
    33
#define RAZOR_EXPORT
krh@269
    34
#endif
krh@269
    35
krh@271
    36
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
krh@271
    37
#define ALIGN(value, base) (((value) + (base - 1)) & ~((base) - 1))
krh@269
    38
krh@248
    39
void *zalloc(size_t size);
krh@248
    40
krh@248
    41
struct array {
krh@248
    42
	void *data;
krh@248
    43
	int size, alloc;
krh@248
    44
};
krh@248
    45
krh@248
    46
void array_init(struct array *array);
krh@248
    47
void array_release(struct array *array);
krh@248
    48
void *array_add(struct array *array, int size);
krh@248
    49
krh@248
    50
krh@248
    51
struct list_head {
krh@248
    52
	uint32_t list_ptr : 24;
krh@248
    53
	uint32_t flags    : 8;
krh@248
    54
};
krh@248
    55
krh@248
    56
struct list {
krh@248
    57
	uint32_t data  : 24;
krh@248
    58
	uint32_t flags : 8;
krh@248
    59
};
krh@248
    60
krh@248
    61
void list_set_empty(struct list_head *head);
krh@248
    62
void list_set_ptr(struct list_head *head, uint32_t ptr);
krh@248
    63
void list_set_array(struct list_head *head, struct array *pool, struct array *items, int force_indirect);
krh@248
    64
krh@248
    65
struct list *list_first(struct list_head *head, struct array *pool);
krh@248
    66
struct list *list_next(struct list *list);
krh@248
    67
krh@248
    68
void list_remap_pool(struct array *pool, uint32_t *map);
krh@248
    69
void list_remap_head(struct list_head *list, uint32_t *map);
krh@248
    70
krh@248
    71
krh@248
    72
struct hashtable {
krh@248
    73
	struct array buckets;
krh@248
    74
	struct array *pool;
krh@248
    75
};
krh@248
    76
krh@248
    77
void hashtable_init(struct hashtable *table, struct array *pool);
krh@248
    78
void hashtable_release(struct hashtable *table);
krh@248
    79
uint32_t hashtable_insert(struct hashtable *table, const char *key);
krh@248
    80
uint32_t hashtable_lookup(struct hashtable *table, const char *key);
krh@248
    81
uint32_t hashtable_tokenize(struct hashtable *table, const char *string);
krh@248
    82
krh@248
    83
krh@248
    84
struct razor_set_section {
krh@248
    85
	uint32_t type;
krh@248
    86
	uint32_t offset;
krh@248
    87
	uint32_t size;
krh@248
    88
};
krh@248
    89
krh@248
    90
struct razor_set_header {
krh@248
    91
	uint32_t magic;
krh@248
    92
	uint32_t version;
krh@248
    93
	struct razor_set_section sections[0];
krh@248
    94
};
krh@248
    95
jbowes@258
    96
#define RAZOR_MAGIC 		0x7a7a7a7a
jbowes@258
    97
#define RAZOR_DETAILS_MAGIC 	0x7a7a7a7b
jbowes@258
    98
#define RAZOR_FILES_MAGIC 	0x7a7a7a7c
krh@248
    99
#define RAZOR_VERSION 1
krh@248
   100
jbowes@258
   101
#define RAZOR_STRING_POOL		0
jbowes@258
   102
#define RAZOR_PACKAGES			1
jbowes@258
   103
#define RAZOR_PROPERTIES		2
jbowes@258
   104
#define RAZOR_PACKAGE_POOL		3
jbowes@258
   105
#define RAZOR_PROPERTY_POOL		4
jbowes@258
   106
jbowes@258
   107
#define RAZOR_DETAILS_STRING_POOL	0
jbowes@258
   108
jbowes@258
   109
#define RAZOR_FILES			0
jbowes@258
   110
#define RAZOR_FILE_POOL			1
jbowes@258
   111
#define RAZOR_FILE_STRING_POOL		2
krh@248
   112
krh@248
   113
struct razor_package {
jbowes@258
   114
	uint name  : 24;
jbowes@258
   115
	uint flags : 8;
krh@248
   116
	uint32_t version;
krh@248
   117
	uint32_t arch;
jbowes@258
   118
	uint32_t summary;
jbowes@258
   119
	uint32_t description;
jbowes@258
   120
	uint32_t url;
jbowes@258
   121
	uint32_t license;
krh@248
   122
	struct list_head properties;
krh@248
   123
	struct list_head files;
krh@248
   124
};
krh@248
   125
jbowes@258
   126
krh@248
   127
struct razor_property {
krh@248
   128
	uint32_t name;
krh@248
   129
	uint32_t flags;
krh@248
   130
	uint32_t version;
krh@248
   131
	struct list_head packages;
krh@248
   132
};
krh@248
   133
krh@248
   134
struct razor_entry {
krh@248
   135
	uint32_t name  : 24;
krh@248
   136
	uint32_t flags : 8;
krh@248
   137
	uint32_t start;
krh@248
   138
	struct list_head packages;
krh@248
   139
};
krh@248
   140
krh@248
   141
#define RAZOR_ENTRY_LAST	0x80
krh@248
   142
krh@248
   143
struct razor_set {
krh@248
   144
	struct array string_pool;
krh@248
   145
 	struct array packages;
krh@248
   146
 	struct array properties;
krh@248
   147
 	struct array files;
krh@248
   148
	struct array package_pool;
krh@248
   149
 	struct array property_pool;
krh@248
   150
 	struct array file_pool;
jbowes@258
   151
	struct array file_string_pool;
jbowes@258
   152
	struct array details_string_pool;
krh@248
   153
	struct razor_set_header *header;
jbowes@258
   154
	struct razor_set_header *details_header;
jbowes@258
   155
	struct razor_set_header *files_header;
krh@248
   156
};
krh@248
   157
krh@248
   158
struct import_entry {
krh@248
   159
	uint32_t package;
krh@248
   160
	char *name;
krh@248
   161
};
krh@248
   162
krh@248
   163
struct import_directory {
krh@248
   164
	uint32_t name, count;
krh@248
   165
	struct array files;
krh@248
   166
	struct array packages;
krh@248
   167
	struct import_directory *last;
krh@248
   168
};
krh@248
   169
krh@248
   170
struct razor_importer {
krh@248
   171
	struct razor_set *set;
krh@248
   172
	struct hashtable table;
jbowes@258
   173
	struct hashtable file_table;
jbowes@258
   174
	struct hashtable details_table;
krh@248
   175
	struct razor_package *package;
krh@248
   176
	struct array properties;
krh@248
   177
	struct array files;
krh@248
   178
	struct array file_requires;
krh@248
   179
};
krh@248
   180
krh@248
   181
struct razor_package_iterator {
krh@248
   182
	struct razor_set *set;
krh@248
   183
	struct razor_package *package, *end;
krh@248
   184
	struct list *index;
krh@248
   185
	int free_index;
krh@248
   186
};
krh@248
   187
krh@248
   188
void
krh@248
   189
razor_package_iterator_init_for_property(struct razor_package_iterator *pi,
krh@248
   190
					 struct razor_set *set,
krh@248
   191
					 struct razor_property *property);
krh@248
   192
krh@248
   193
struct razor_property_iterator {
krh@248
   194
	struct razor_set *set;
krh@248
   195
	struct razor_property *property, *end;
krh@248
   196
	struct list *index;
krh@248
   197
};
krh@248
   198
krh@248
   199
struct razor_entry *
krh@248
   200
razor_set_find_entry(struct razor_set *set,
krh@248
   201
		     struct razor_entry *dir, const char *pattern);
krh@248
   202
krh@248
   203
struct razor_merger *
krh@248
   204
razor_merger_create(struct razor_set *set1, struct razor_set *set2);
krh@248
   205
void
krh@248
   206
razor_merger_add_package(struct razor_merger *merger,
krh@248
   207
			 struct razor_package *package);
krh@248
   208
struct razor_set *
krh@248
   209
razor_merger_finish(struct razor_merger *merger);
krh@248
   210
rhughes@241
   211
/* Utility functions */
rhughes@241
   212
richard@302
   213
void
richard@302
   214
razor_package_get_details_varg(struct razor_set *set,
richard@302
   215
			       struct razor_package *package,
richard@302
   216
			       va_list args);
richard@302
   217
rhughes@241
   218
int razor_create_dir(const char *root, const char *path);
rhughes@241
   219
int razor_write(int fd, const void *data, size_t size);
rhughes@241
   220
rhughes@241
   221
rhughes@241
   222
typedef int (*razor_compare_with_data_func_t)(const void *p1,
rhughes@241
   223
					      const void *p,
rhughes@241
   224
					      void *data);
rhughes@241
   225
uint32_t *
rhughes@241
   226
razor_qsort_with_data(void *base, size_t nelem, size_t size,
rhughes@241
   227
		      razor_compare_with_data_func_t compare, void *data);
rhughes@241
   228
rhughes@241
   229
#endif /* _RAZOR_INTERNAL_H_ */