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