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