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