librazor/razor.h
author James Bowes <jbowes@redhat.com>
Mon Jun 23 21:20:16 2008 -0400 (2008-06-23)
changeset 278 97c12ddedfb3
parent 271 3980d1d9148e
child 284 6e19775d8930
permissions -rw-r--r--
Create an empty package iterator when we don't know about the given file.

This is an easy way to stop segfaults when trying to destroy iterators for
unknown files.
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@258
    23
enum razor_repo_file_type {
jbowes@258
    24
	RAZOR_REPO_FILE_MAIN,
jbowes@258
    25
	RAZOR_REPO_FILE_DETAILS,
jbowes@258
    26
	RAZOR_REPO_FILE_FILES
jbowes@258
    27
};
jbowes@258
    28
krh@247
    29
enum razor_property_flags {
krh@247
    30
	RAZOR_PROPERTY_LESS		= 1 << 0,
krh@247
    31
	RAZOR_PROPERTY_GREATER		= 1 << 1,
krh@247
    32
	RAZOR_PROPERTY_EQUAL		= 1 << 2,
krh@247
    33
	RAZOR_PROPERTY_RELATION_MASK	=
krh@247
    34
		RAZOR_PROPERTY_LESS |
krh@247
    35
		RAZOR_PROPERTY_GREATER |
krh@247
    36
		RAZOR_PROPERTY_EQUAL,
krh@247
    37
krh@247
    38
	RAZOR_PROPERTY_REQUIRES		= 0 << 3,
krh@247
    39
	RAZOR_PROPERTY_PROVIDES		= 1 << 3,
krh@247
    40
	RAZOR_PROPERTY_CONFLICTS	= 2 << 3,
krh@247
    41
	RAZOR_PROPERTY_OBSOLETES	= 3 << 3,
krh@247
    42
	RAZOR_PROPERTY_TYPE_MASK	= 3 << 3,
krh@247
    43
		
krh@247
    44
	RAZOR_PROPERTY_PRE		= 1 << 5,
krh@247
    45
	RAZOR_PROPERTY_POST		= 1 << 6,
krh@247
    46
	RAZOR_PROPERTY_PREUN		= 1 << 7,
krh@247
    47
	RAZOR_PROPERTY_POSTUN		= 1 << 8
rhughes@241
    48
};
rhughes@241
    49
krh@262
    50
/**
krh@262
    51
 * SECTION:set
krh@262
    52
 * @title: Package Set
krh@262
    53
 * @short_description: Represents a set of packages and their metadata.
krh@262
    54
 *
krh@262
    55
 * This object represents a set of packages, their dependency
krh@262
    56
 * information, the file lists and a number of other details.
krh@262
    57
 **/
rhughes@241
    58
krh@262
    59
struct razor_set;
krh@262
    60
struct razor_package;
krh@262
    61
struct razor_property;
krh@262
    62
krh@262
    63
/**
krh@262
    64
 * razor_set_create:
krh@262
    65
 * 
krh@262
    66
 * Create a new #razor_set object.
krh@262
    67
 * 
krh@262
    68
 * Returns: the new #razor_set object.
krh@262
    69
 **/
rhughes@241
    70
struct razor_set *razor_set_create(void);
rhughes@241
    71
struct razor_set *razor_set_open(const char *filename);
rhughes@241
    72
void razor_set_destroy(struct razor_set *set);
jbowes@258
    73
int razor_set_write_to_fd(struct razor_set *set, int fd,
jbowes@258
    74
			  enum razor_repo_file_type type);
jbowes@258
    75
int razor_set_write(struct razor_set *set, const char *filename,
jbowes@258
    76
		    enum razor_repo_file_type type);
jbowes@258
    77
jbowes@258
    78
void razor_set_open_details(struct razor_set *set, const char *filename);
jbowes@258
    79
void razor_set_open_files(struct razor_set *set, const char *filename);
rhughes@241
    80
rhughes@241
    81
struct razor_package *
rhughes@241
    82
razor_set_get_package(struct razor_set *set, const char *package);
rhughes@241
    83
jbowes@258
    84
void
jbowes@258
    85
razor_package_get_details(struct razor_set *set, struct razor_package *package,
jbowes@258
    86
			  const char **summary, const char **description,
jbowes@258
    87
			  const char **url, const char **license);
jbowes@258
    88
krh@262
    89
krh@262
    90
/**
krh@262
    91
 * SECTION:iterator
krh@262
    92
 * @title: Iterators
krh@262
    93
 * @short_description: Objects for traversing packages or properties.
krh@262
    94
 *
krh@262
    95
 * The razor iterator objects provides a way to iterate through a set
krh@262
    96
 * of packages or properties.
krh@262
    97
 **/
krh@262
    98
rhughes@241
    99
struct razor_package_iterator;
krh@262
   100
krh@262
   101
/**
krh@262
   102
 * razor_package_iterator_create:
krh@262
   103
 * 
krh@262
   104
 * Create a new #razor_package_iterator object.
krh@262
   105
 * 
krh@262
   106
 * Returns: the new #razor_package_iterator object.
krh@262
   107
 **/
krh@262
   108
rhughes@241
   109
struct razor_package_iterator *
rhughes@241
   110
razor_package_iterator_create(struct razor_set *set);
krh@262
   111
krh@262
   112
/**
krh@262
   113
 * razor_package_iterator_create_for_property:
krh@262
   114
 * 
krh@262
   115
 * Create a new #razor_package_iterator object for the packages that
krh@262
   116
 * own the given property.
krh@262
   117
 * 
krh@262
   118
 * Returns: the new #razor_package_iterator object.
krh@262
   119
 **/
rhughes@241
   120
struct razor_package_iterator *
rhughes@241
   121
razor_package_iterator_create_for_property(struct razor_set *set,
rhughes@241
   122
					   struct razor_property *property);
jbowes@277
   123
jbowes@277
   124
/**
jbowes@277
   125
 * razor_package_iterator_create_for_file:
jbowes@277
   126
 *
jbowes@277
   127
 * Create a new #razor_package_iterator object for the packages that
jbowes@277
   128
 * contain the given file name.
jbowes@277
   129
 *
jbowes@277
   130
 * Returns: the new #razor_package_iterator object.
jbowes@277
   131
 **/
rhughes@241
   132
struct razor_package_iterator *
rhughes@241
   133
razor_package_iterator_create_for_file(struct razor_set *set,
rhughes@241
   134
				       const char *filename);
rhughes@241
   135
rhughes@241
   136
int razor_package_iterator_next(struct razor_package_iterator *pi,
rhughes@241
   137
				struct razor_package **package,
rhughes@241
   138
				const char **name,
rhughes@241
   139
				const char **version,
rhughes@241
   140
				const char **arch);
rhughes@241
   141
void razor_package_iterator_destroy(struct razor_package_iterator *pi);
rhughes@241
   142
rhughes@241
   143
struct razor_package_query *
rhughes@241
   144
razor_package_query_create(struct razor_set *set);
rhughes@241
   145
void
rhughes@241
   146
razor_package_query_add_package(struct razor_package_query *pq,
rhughes@241
   147
				struct razor_package *p);
rhughes@241
   148
void
rhughes@241
   149
razor_package_query_add_iterator(struct razor_package_query *pq,
rhughes@241
   150
				 struct razor_package_iterator *pi);
rhughes@241
   151
struct razor_package_iterator *
rhughes@241
   152
razor_package_query_finish(struct razor_package_query *pq);
rhughes@241
   153
rhughes@241
   154
struct razor_property_iterator;
rhughes@241
   155
struct razor_property_iterator *
rhughes@241
   156
razor_property_iterator_create(struct razor_set *set,
rhughes@241
   157
			       struct razor_package *package);
rhughes@241
   158
int razor_property_iterator_next(struct razor_property_iterator *pi,
rhughes@241
   159
				 struct razor_property **property,
rhughes@241
   160
				 const char **name,
krh@247
   161
				 uint32_t *flags,
krh@247
   162
				 const char **version);
rhughes@241
   163
void
rhughes@241
   164
razor_property_iterator_destroy(struct razor_property_iterator *pi);
rhughes@241
   165
rhughes@241
   166
void razor_set_list_files(struct razor_set *set, const char *prefix);
rhughes@241
   167
void razor_set_list_package_files(struct razor_set *set, const char *name);
rhughes@241
   168
krh@253
   169
enum razor_diff_action {
krh@253
   170
	RAZOR_DIFF_ACTION_ADD,
krh@253
   171
	RAZOR_DIFF_ACTION_REMOVE,
krh@253
   172
};
krh@253
   173
krh@253
   174
typedef void (*razor_diff_callback_t)(enum razor_diff_action action,
krh@253
   175
				      struct razor_package *package,
krh@253
   176
				      const char *name,
krh@253
   177
				      const char *version,
krh@253
   178
				      const char *arch,
krh@253
   179
				      void *data);
krh@253
   180
rhughes@241
   181
void
rhughes@241
   182
razor_set_diff(struct razor_set *set, struct razor_set *upstream,
krh@253
   183
	       razor_diff_callback_t callback, void *data);
krh@254
   184
struct razor_package_iterator *
krh@254
   185
razor_set_create_remove_iterator(struct razor_set *set,
krh@254
   186
				 struct razor_set *next);
krh@254
   187
struct razor_package_iterator *
krh@254
   188
razor_set_create_install_iterator(struct razor_set *set,
krh@254
   189
				  struct razor_set *next);
rhughes@241
   190
krh@262
   191
/**
krh@262
   192
 * SECTION:transaction
krh@262
   193
 * @title: Transaction
krh@262
   194
 * @short_description: Create a new package set by merging two or more sets.
krh@262
   195
 *
krh@262
   196
 * The razor transaction object provides a way to create a new package set
krh@262
   197
 * from packages from one or more other package sets.
krh@262
   198
 **/
rhughes@241
   199
rhughes@241
   200
struct razor_transaction *
rhughes@241
   201
razor_transaction_create(struct razor_set *system, struct razor_set *upstream);
rhughes@241
   202
void razor_transaction_install_package(struct razor_transaction *transaction,
rhughes@241
   203
				       struct razor_package *package);
rhughes@241
   204
void razor_transaction_remove_package(struct razor_transaction *transaction,
rhughes@241
   205
				      struct razor_package *package);
rhughes@241
   206
void razor_transaction_update_package(struct razor_transaction *trans,
rhughes@241
   207
				      struct razor_package *package);
rhughes@241
   208
void razor_transaction_update_all(struct razor_transaction *transaction);
rhughes@241
   209
int razor_transaction_resolve(struct razor_transaction *trans);
rhughes@241
   210
int razor_transaction_describe(struct razor_transaction *trans);
rhughes@241
   211
struct razor_set *razor_transaction_finish(struct razor_transaction *trans);
rhughes@241
   212
void razor_transaction_destroy(struct razor_transaction *trans);
rhughes@241
   213
rhughes@241
   214
/* Temporary helper for test suite. */
rhughes@241
   215
int razor_transaction_unsatisfied_property(struct razor_transaction *trans,
rhughes@241
   216
					   const char *name,
krh@247
   217
					   uint32_t flags,
krh@247
   218
					   const char *version);
rhughes@241
   219
krh@262
   220
/**
krh@262
   221
 * SECTION:rpm
krh@262
   222
 * @title: Razor RPM
krh@262
   223
 * @short_description: Operating on RPM files.
krh@262
   224
 *
krh@262
   225
 * Functions for open RPM files and extracting information and
krh@262
   226
 * installing or removing RPM files.
krh@262
   227
 **/
rhughes@241
   228
krh@262
   229
struct razor_rpm;
krh@262
   230
krh@262
   231
struct razor_rpm *razor_rpm_open(const char *filename);
krh@262
   232
int razor_rpm_install(struct razor_rpm *rpm, const char *root);
krh@262
   233
int razor_rpm_close(struct razor_rpm *rpm);
krh@262
   234
krh@262
   235
/**
krh@262
   236
 * SECTION:importer
krh@262
   237
 * @title: Importer
krh@262
   238
 * @short_description: A mechanism for building #razor_set objects
krh@262
   239
 *
krh@262
   240
 * For building a razor set from external sources, like yum, rpmdb or
krh@262
   241
 * RPM files.
krh@262
   242
 **/
rhughes@241
   243
struct razor_importer;
rhughes@241
   244
krh@249
   245
struct razor_importer *razor_importer_create(void);
rhughes@241
   246
void razor_importer_destroy(struct razor_importer *importer);
rhughes@241
   247
void razor_importer_begin_package(struct razor_importer *importer,
rhughes@241
   248
				  const char *name,
rhughes@241
   249
				  const char *version,
rhughes@241
   250
				  const char *arch);
jbowes@258
   251
void razor_importer_add_details(struct razor_importer *importer,
jbowes@258
   252
				const char *summary,
jbowes@258
   253
				const char *description,
jbowes@258
   254
				const char *url,
jbowes@258
   255
				const char *license);
rhughes@241
   256
void razor_importer_add_property(struct razor_importer *importer,
rhughes@241
   257
				 const char *name,
krh@247
   258
				 uint32_t flags,
krh@247
   259
				 const char *version);
rhughes@241
   260
void razor_importer_add_file(struct razor_importer *importer,
rhughes@241
   261
			     const char *name);
rhughes@241
   262
void razor_importer_finish_package(struct razor_importer *importer);
rhughes@241
   263
rhughes@241
   264
int razor_importer_add_rpm(struct razor_importer *importer,
rhughes@241
   265
			   struct razor_rpm *rpm);
rhughes@241
   266
rhughes@241
   267
struct razor_set *razor_importer_finish(struct razor_importer *importer);
rhughes@241
   268
rhughes@241
   269
struct razor_set *razor_set_create_from_yum(void);
rhughes@241
   270
struct razor_set *razor_set_create_from_rpmdb(void);
rhughes@241
   271
krh@262
   272
/**
krh@262
   273
 * SECTION:root
krh@262
   274
 * @title: Root
krh@262
   275
 * @short_description: Functions for accessing an install root.
krh@262
   276
 *
krh@262
   277
 * The #razor_root object encapsulate access to and locking of a razor
krh@262
   278
 * install root.
krh@262
   279
 **/
rhughes@241
   280
struct razor_root;
rhughes@241
   281
rhughes@241
   282
int razor_root_create(const char *root);
krh@250
   283
struct razor_root *razor_root_open(const char *root);
rhughes@241
   284
struct razor_set *razor_root_open_read_only(const char *root);
krh@250
   285
struct razor_set *razor_root_get_system_set(struct razor_root *root);
krh@250
   286
int razor_root_close(struct razor_root *root);
krh@250
   287
void razor_root_update(struct razor_root *root, struct razor_set *next);
krh@250
   288
int razor_root_commit(struct razor_root *root);
rhughes@241
   289
krh@262
   290
krh@262
   291
/**
krh@262
   292
 * SECTION:misc
krh@262
   293
 * @title: Miscellaneous Functions
krh@262
   294
 * @short_description: Various helper functions
krh@262
   295
 *
krh@262
   296
 * Functions that doesn't fit anywhere else.
krh@262
   297
 **/
krh@262
   298
krh@262
   299
const char *
krh@262
   300
razor_property_relation_to_string(struct razor_property *p);
krh@262
   301
const char *
krh@262
   302
razor_property_type_to_string(struct razor_property *p);
krh@262
   303
krh@262
   304
void razor_build_evr(char *evr_buf, int size, const char *epoch,
krh@262
   305
		     const char *version, const char *release);
krh@262
   306
int razor_versioncmp(const char *s1, const char *s2);
krh@262
   307
krh@262
   308
rhughes@241
   309
#endif /* _RAZOR_H_ */