librazor/razor.h
author J. Ali Harlow <ali@juiblex.co.uk>
Wed Apr 29 17:00:01 2009 +0100 (2009-04-29)
changeset 361 2523d03a840e
parent 359 c9c90315ea24
child 363 c75a2d5caae9
permissions -rw-r--r--
Add support for preloading lua modules. This is useful both when
providing lua bindings to applications based on librazor and when
producing static binaries using librazor (where otherwise the lua
POSIX library would need to be included as an additional dynamic
object).
rhughes@241
     1
/*
rhughes@241
     2
 * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
rhughes@241
     3
 * Copyright (C) 2008  Red Hat, Inc
rhughes@241
     4
 *
rhughes@241
     5
 * This program is free software; you can redistribute it and/or modify
rhughes@241
     6
 * it under the terms of the GNU General Public License as published by
rhughes@241
     7
 * the Free Software Foundation; either version 2 of the License, or
rhughes@241
     8
 * (at your option) any later version.
rhughes@241
     9
 *
rhughes@241
    10
 * This program is distributed in the hope that it will be useful,
rhughes@241
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rhughes@241
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
rhughes@241
    13
 * GNU General Public License for more details.
rhughes@241
    14
 *
rhughes@241
    15
 * You should have received a copy of the GNU General Public License along
rhughes@241
    16
 * with this program; if not, write to the Free Software Foundation, Inc.,
rhughes@241
    17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
rhughes@241
    18
 */
rhughes@241
    19
rhughes@241
    20
#ifndef _RAZOR_H_
rhughes@241
    21
#define _RAZOR_H_
rhughes@241
    22
jbowes@284
    23
#include <stdint.h>
jbowes@284
    24
jbowes@258
    25
enum razor_repo_file_type {
jbowes@258
    26
	RAZOR_REPO_FILE_MAIN,
jbowes@258
    27
	RAZOR_REPO_FILE_DETAILS,
jbowes@258
    28
	RAZOR_REPO_FILE_FILES
jbowes@258
    29
};
jbowes@258
    30
richard@302
    31
enum razor_detail_type {
richard@307
    32
	RAZOR_DETAIL_LAST = 0,	/* the sentinel */
richard@307
    33
	RAZOR_DETAIL_NAME,
richard@302
    34
	RAZOR_DETAIL_VERSION,
richard@302
    35
	RAZOR_DETAIL_ARCH,
richard@302
    36
	RAZOR_DETAIL_SUMMARY,
richard@302
    37
	RAZOR_DETAIL_DESCRIPTION,
richard@302
    38
	RAZOR_DETAIL_URL,
richard@302
    39
	RAZOR_DETAIL_LICENSE
richard@302
    40
};
richard@302
    41
krh@247
    42
enum razor_property_flags {
krh@247
    43
	RAZOR_PROPERTY_LESS		= 1 << 0,
krh@247
    44
	RAZOR_PROPERTY_GREATER		= 1 << 1,
krh@247
    45
	RAZOR_PROPERTY_EQUAL		= 1 << 2,
krh@247
    46
	RAZOR_PROPERTY_RELATION_MASK	=
krh@247
    47
		RAZOR_PROPERTY_LESS |
krh@247
    48
		RAZOR_PROPERTY_GREATER |
krh@247
    49
		RAZOR_PROPERTY_EQUAL,
krh@247
    50
krh@247
    51
	RAZOR_PROPERTY_REQUIRES		= 0 << 3,
krh@247
    52
	RAZOR_PROPERTY_PROVIDES		= 1 << 3,
krh@247
    53
	RAZOR_PROPERTY_CONFLICTS	= 2 << 3,
krh@247
    54
	RAZOR_PROPERTY_OBSOLETES	= 3 << 3,
krh@247
    55
	RAZOR_PROPERTY_TYPE_MASK	= 3 << 3,
krh@247
    56
		
krh@247
    57
	RAZOR_PROPERTY_PRE		= 1 << 5,
krh@247
    58
	RAZOR_PROPERTY_POST		= 1 << 6,
krh@247
    59
	RAZOR_PROPERTY_PREUN		= 1 << 7,
krh@247
    60
	RAZOR_PROPERTY_POSTUN		= 1 << 8
rhughes@241
    61
};
rhughes@241
    62
krh@262
    63
/**
krh@262
    64
 * SECTION:set
krh@262
    65
 * @title: Package Set
krh@262
    66
 * @short_description: Represents a set of packages and their metadata.
krh@262
    67
 *
krh@262
    68
 * This object represents a set of packages, their dependency
krh@262
    69
 * information, the file lists and a number of other details.
krh@262
    70
 **/
rhughes@241
    71
krh@262
    72
struct razor_set;
krh@262
    73
struct razor_package;
krh@262
    74
struct razor_property;
krh@262
    75
krh@262
    76
/**
krh@262
    77
 * razor_set_create:
krh@262
    78
 * 
krh@262
    79
 * Create a new #razor_set object.
krh@262
    80
 * 
krh@262
    81
 * Returns: the new #razor_set object.
krh@262
    82
 **/
rhughes@241
    83
struct razor_set *razor_set_create(void);
rhughes@241
    84
struct razor_set *razor_set_open(const char *filename);
rhughes@241
    85
void razor_set_destroy(struct razor_set *set);
jbowes@258
    86
int razor_set_write_to_fd(struct razor_set *set, int fd,
jbowes@258
    87
			  enum razor_repo_file_type type);
jbowes@258
    88
int razor_set_write(struct razor_set *set, const char *filename,
jbowes@258
    89
		    enum razor_repo_file_type type);
jbowes@258
    90
jbowes@288
    91
int razor_set_open_details(struct razor_set *set, const char *filename);
jbowes@288
    92
int razor_set_open_files(struct razor_set *set, const char *filename);
rhughes@241
    93
rhughes@241
    94
struct razor_package *
rhughes@241
    95
razor_set_get_package(struct razor_set *set, const char *package);
rhughes@241
    96
jbowes@258
    97
void
richard@304
    98
razor_package_get_details(struct razor_set *set,
richard@307
    99
			  struct razor_package *package, ...);
jbowes@258
   100
krh@262
   101
krh@262
   102
/**
krh@262
   103
 * SECTION:iterator
krh@262
   104
 * @title: Iterators
krh@262
   105
 * @short_description: Objects for traversing packages or properties.
krh@262
   106
 *
krh@262
   107
 * The razor iterator objects provides a way to iterate through a set
krh@262
   108
 * of packages or properties.
krh@262
   109
 **/
krh@262
   110
rhughes@241
   111
struct razor_package_iterator;
krh@262
   112
krh@262
   113
/**
krh@262
   114
 * razor_package_iterator_create:
krh@262
   115
 * 
krh@262
   116
 * Create a new #razor_package_iterator object.
krh@262
   117
 * 
krh@262
   118
 * Returns: the new #razor_package_iterator object.
krh@262
   119
 **/
krh@262
   120
rhughes@241
   121
struct razor_package_iterator *
rhughes@241
   122
razor_package_iterator_create(struct razor_set *set);
krh@262
   123
krh@262
   124
/**
krh@262
   125
 * razor_package_iterator_create_for_property:
krh@262
   126
 * 
krh@262
   127
 * Create a new #razor_package_iterator object for the packages that
krh@262
   128
 * own the given property.
krh@262
   129
 * 
krh@262
   130
 * Returns: the new #razor_package_iterator object.
krh@262
   131
 **/
rhughes@241
   132
struct razor_package_iterator *
rhughes@241
   133
razor_package_iterator_create_for_property(struct razor_set *set,
rhughes@241
   134
					   struct razor_property *property);
jbowes@277
   135
jbowes@277
   136
/**
jbowes@277
   137
 * razor_package_iterator_create_for_file:
jbowes@277
   138
 *
jbowes@277
   139
 * Create a new #razor_package_iterator object for the packages that
jbowes@277
   140
 * contain the given file name.
jbowes@277
   141
 *
jbowes@277
   142
 * Returns: the new #razor_package_iterator object.
jbowes@277
   143
 **/
rhughes@241
   144
struct razor_package_iterator *
rhughes@241
   145
razor_package_iterator_create_for_file(struct razor_set *set,
rhughes@241
   146
				       const char *filename);
rhughes@241
   147
rhughes@241
   148
int razor_package_iterator_next(struct razor_package_iterator *pi,
richard@307
   149
				struct razor_package **package, ...);
rhughes@241
   150
void razor_package_iterator_destroy(struct razor_package_iterator *pi);
rhughes@241
   151
rhughes@241
   152
struct razor_package_query *
rhughes@241
   153
razor_package_query_create(struct razor_set *set);
rhughes@241
   154
void
rhughes@241
   155
razor_package_query_add_package(struct razor_package_query *pq,
rhughes@241
   156
				struct razor_package *p);
rhughes@241
   157
void
rhughes@241
   158
razor_package_query_add_iterator(struct razor_package_query *pq,
rhughes@241
   159
				 struct razor_package_iterator *pi);
rhughes@241
   160
struct razor_package_iterator *
rhughes@241
   161
razor_package_query_finish(struct razor_package_query *pq);
rhughes@241
   162
rhughes@241
   163
struct razor_property_iterator;
rhughes@241
   164
struct razor_property_iterator *
rhughes@241
   165
razor_property_iterator_create(struct razor_set *set,
rhughes@241
   166
			       struct razor_package *package);
rhughes@241
   167
int razor_property_iterator_next(struct razor_property_iterator *pi,
rhughes@241
   168
				 struct razor_property **property,
rhughes@241
   169
				 const char **name,
krh@247
   170
				 uint32_t *flags,
krh@247
   171
				 const char **version);
rhughes@241
   172
void
rhughes@241
   173
razor_property_iterator_destroy(struct razor_property_iterator *pi);
rhughes@241
   174
ali@351
   175
struct razor_file_iterator;
ali@351
   176
struct razor_file_iterator *
ali@351
   177
razor_file_iterator_create(struct razor_set *set,
ali@351
   178
			   struct razor_package *package);
ali@351
   179
int razor_file_iterator_next(struct razor_file_iterator *fi,
ali@351
   180
			     const char **name);
ali@351
   181
void razor_file_iterator_destroy(struct razor_file_iterator *fi);
ali@351
   182
rhughes@241
   183
void razor_set_list_files(struct razor_set *set, const char *prefix);
krh@306
   184
void razor_set_list_package_files(struct razor_set *set,
krh@306
   185
				  struct razor_package *package);
rhughes@241
   186
krh@253
   187
enum razor_diff_action {
krh@253
   188
	RAZOR_DIFF_ACTION_ADD,
krh@253
   189
	RAZOR_DIFF_ACTION_REMOVE,
krh@253
   190
};
krh@253
   191
krh@253
   192
typedef void (*razor_diff_callback_t)(enum razor_diff_action action,
krh@253
   193
				      struct razor_package *package,
krh@253
   194
				      const char *name,
krh@253
   195
				      const char *version,
krh@253
   196
				      const char *arch,
krh@253
   197
				      void *data);
krh@253
   198
rhughes@241
   199
void
rhughes@241
   200
razor_set_diff(struct razor_set *set, struct razor_set *upstream,
krh@253
   201
	       razor_diff_callback_t callback, void *data);
krh@316
   202
krh@316
   203
struct razor_install_iterator;
krh@316
   204
krh@316
   205
enum razor_install_action {
krh@316
   206
	RAZOR_INSTALL_ACTION_ADD,
krh@316
   207
	RAZOR_INSTALL_ACTION_REMOVE
krh@316
   208
};
krh@316
   209
krh@316
   210
struct razor_install_iterator *
krh@254
   211
razor_set_create_install_iterator(struct razor_set *set,
krh@254
   212
				  struct razor_set *next);
rhughes@241
   213
krh@316
   214
int razor_install_iterator_next(struct razor_install_iterator *ii,
krh@316
   215
				struct razor_set **set,
krh@316
   216
				struct razor_package **package,
krh@316
   217
				enum razor_install_action *action,
krh@316
   218
				int *count);
krh@316
   219
krh@316
   220
void razor_install_iterator_destroy(struct razor_install_iterator *ii);
krh@316
   221
krh@262
   222
/**
krh@262
   223
 * SECTION:transaction
krh@262
   224
 * @title: Transaction
krh@262
   225
 * @short_description: Create a new package set by merging two or more sets.
krh@262
   226
 *
krh@262
   227
 * The razor transaction object provides a way to create a new package set
krh@262
   228
 * from packages from one or more other package sets.
krh@262
   229
 **/
rhughes@241
   230
rhughes@241
   231
struct razor_transaction *
rhughes@241
   232
razor_transaction_create(struct razor_set *system, struct razor_set *upstream);
rhughes@241
   233
void razor_transaction_install_package(struct razor_transaction *transaction,
rhughes@241
   234
				       struct razor_package *package);
rhughes@241
   235
void razor_transaction_remove_package(struct razor_transaction *transaction,
rhughes@241
   236
				      struct razor_package *package);
rhughes@241
   237
void razor_transaction_update_package(struct razor_transaction *trans,
rhughes@241
   238
				      struct razor_package *package);
rhughes@241
   239
void razor_transaction_update_all(struct razor_transaction *transaction);
rhughes@241
   240
int razor_transaction_resolve(struct razor_transaction *trans);
rhughes@241
   241
int razor_transaction_describe(struct razor_transaction *trans);
rhughes@241
   242
struct razor_set *razor_transaction_finish(struct razor_transaction *trans);
rhughes@241
   243
void razor_transaction_destroy(struct razor_transaction *trans);
rhughes@241
   244
rhughes@241
   245
/* Temporary helper for test suite. */
rhughes@241
   246
int razor_transaction_unsatisfied_property(struct razor_transaction *trans,
rhughes@241
   247
					   const char *name,
krh@247
   248
					   uint32_t flags,
krh@247
   249
					   const char *version);
rhughes@241
   250
krh@262
   251
/**
krh@262
   252
 * SECTION:rpm
krh@262
   253
 * @title: Razor RPM
krh@262
   254
 * @short_description: Operating on RPM files.
krh@262
   255
 *
krh@262
   256
 * Functions for open RPM files and extracting information and
krh@262
   257
 * installing or removing RPM files.
krh@262
   258
 **/
rhughes@241
   259
ali@351
   260
struct razor_relocations;
krh@262
   261
struct razor_rpm;
krh@262
   262
ali@351
   263
struct razor_relocations *razor_relocations_create(void);
ali@351
   264
void razor_relocations_add(struct razor_relocations *relocations,
ali@351
   265
			   const char *oldpath, const char *newpath);
ali@351
   266
void razor_relocations_set_rpm(struct razor_relocations *relocations,
ali@351
   267
			       struct razor_rpm *rpm);
ali@351
   268
const char *razor_relocations_apply(struct razor_relocations *relocations,
ali@351
   269
				    const char *path);
ali@351
   270
void razor_relocations_destroy(struct razor_relocations *relocations);
ali@351
   271
krh@262
   272
struct razor_rpm *razor_rpm_open(const char *filename);
ali@351
   273
void razor_rpm_set_relocations(struct razor_rpm *rpm,
ali@351
   274
			       struct razor_relocations *relocations);
krh@262
   275
int razor_rpm_install(struct razor_rpm *rpm, const char *root);
krh@262
   276
int razor_rpm_close(struct razor_rpm *rpm);
krh@262
   277
krh@262
   278
/**
krh@262
   279
 * SECTION:importer
krh@262
   280
 * @title: Importer
krh@262
   281
 * @short_description: A mechanism for building #razor_set objects
krh@262
   282
 *
krh@309
   283
 * The %razor_importer is a helper object for building a razor set
krh@309
   284
 * from external sources, like yum metadata, the RPM database or RPM
krh@309
   285
 * files.
krh@309
   286
 *
krh@309
   287
 * The importer is a stateful object; it has the notion of a current
krh@309
   288
 * package, and the caller can provide meta data such as properties,
krh@309
   289
 * files and similiar for the package as it becomes available.  Once a
krh@309
   290
 * package is fully described, the next pacakge can begin.  When all
krh@309
   291
 * packages have been described to the importer, the importer will
krh@309
   292
 * create a new %razor_set with the specified packages.
krh@309
   293
 *
krh@309
   294
 * A typical use
krh@309
   295
 * of the importer will follow this template:
krh@309
   296
 * |[
krh@309
   297
 * importer = razor_importer_create();
krh@309
   298
 *
krh@309
   299
 * while ( /<!-- -->* more packages to import *<!-- -->/; ) {
krh@309
   300
 *   /<!-- -->* get name, version and arch of next package *<!-- -->/
krh@309
   301
 *   razor_importer_begin_package(importer, name, version, arch);
krh@309
   302
 *   razor_importer_add_details(importer, summary, description, url, license);
krh@309
   303
 *
krh@309
   304
 *   while ( /<!-- -->* more properties to add *<!-- -->/ )
krh@309
   305
 *     razor_importer_add_property(importer, name, flags, version);
krh@309
   306
 *
krh@309
   307
 *   while ( /<!-- -->* [more files to add *<!-- -->/ )
krh@309
   308
 *     razor_importer_add_file(importer, name);
krh@309
   309
 *
krh@309
   310
 *   razor_importer_finish_package(importer);
krh@309
   311
 * }
krh@309
   312
 *
krh@309
   313
 * return razor_importer_finish(importer);
krh@309
   314
 * ]|
krh@262
   315
 **/
rhughes@241
   316
struct razor_importer;
rhughes@241
   317
krh@249
   318
struct razor_importer *razor_importer_create(void);
rhughes@241
   319
void razor_importer_destroy(struct razor_importer *importer);
rhughes@241
   320
void razor_importer_begin_package(struct razor_importer *importer,
rhughes@241
   321
				  const char *name,
rhughes@241
   322
				  const char *version,
rhughes@241
   323
				  const char *arch);
jbowes@258
   324
void razor_importer_add_details(struct razor_importer *importer,
jbowes@258
   325
				const char *summary,
jbowes@258
   326
				const char *description,
jbowes@258
   327
				const char *url,
jbowes@258
   328
				const char *license);
rhughes@241
   329
void razor_importer_add_property(struct razor_importer *importer,
rhughes@241
   330
				 const char *name,
krh@247
   331
				 uint32_t flags,
krh@247
   332
				 const char *version);
rhughes@241
   333
void razor_importer_add_file(struct razor_importer *importer,
rhughes@241
   334
			     const char *name);
rhughes@241
   335
void razor_importer_finish_package(struct razor_importer *importer);
rhughes@241
   336
rhughes@241
   337
int razor_importer_add_rpm(struct razor_importer *importer,
rhughes@241
   338
			   struct razor_rpm *rpm);
rhughes@241
   339
rhughes@241
   340
struct razor_set *razor_importer_finish(struct razor_importer *importer);
rhughes@241
   341
rhughes@241
   342
struct razor_set *razor_set_create_from_yum(void);
rhughes@241
   343
struct razor_set *razor_set_create_from_rpmdb(void);
rhughes@241
   344
krh@262
   345
/**
krh@262
   346
 * SECTION:root
krh@262
   347
 * @title: Root
krh@262
   348
 * @short_description: Functions for accessing an install root.
krh@262
   349
 *
krh@262
   350
 * The #razor_root object encapsulate access to and locking of a razor
krh@262
   351
 * install root.
krh@262
   352
 **/
rhughes@241
   353
struct razor_root;
rhughes@241
   354
rhughes@241
   355
int razor_root_create(const char *root);
krh@250
   356
struct razor_root *razor_root_open(const char *root);
rhughes@241
   357
struct razor_set *razor_root_open_read_only(const char *root);
krh@250
   358
struct razor_set *razor_root_get_system_set(struct razor_root *root);
krh@250
   359
int razor_root_close(struct razor_root *root);
krh@250
   360
void razor_root_update(struct razor_root *root, struct razor_set *next);
krh@250
   361
int razor_root_commit(struct razor_root *root);
rhughes@241
   362
krh@262
   363
krh@262
   364
/**
krh@262
   365
 * SECTION:misc
krh@262
   366
 * @title: Miscellaneous Functions
krh@262
   367
 * @short_description: Various helper functions
krh@262
   368
 *
krh@262
   369
 * Functions that doesn't fit anywhere else.
krh@262
   370
 **/
krh@262
   371
krh@262
   372
const char *
krh@262
   373
razor_property_relation_to_string(struct razor_property *p);
krh@262
   374
const char *
krh@262
   375
razor_property_type_to_string(struct razor_property *p);
krh@262
   376
krh@262
   377
void razor_build_evr(char *evr_buf, int size, const char *epoch,
krh@262
   378
		     const char *version, const char *release);
krh@262
   379
int razor_versioncmp(const char *s1, const char *s2);
krh@262
   380
ali@359
   381
void razor_disable_root_name_checks(int disable);
ali@359
   382
ali@361
   383
void razor_set_lua_loader(const char *modname, void (*loader)());
ali@361
   384
krh@262
   385
rhughes@241
   386
#endif /* _RAZOR_H_ */