librazor/razor.h
author Richard Hughes <richard@hughsie.com>
Mon Jun 30 10:46:20 2008 +0100 (2008-06-30)
changeset 304 bf23ba00db03
parent 302 9b71b537d175
child 306 cd3954499086
permissions -rw-r--r--
the vararg list must be terminated with zero else 64bit machines may crash

On 64 bit systems, the integer 0 is 32 bits and the pointer 0 is 64 bits.
The upper 32 bits will not be cleared and the loop will never terminate.
Also add the RAZOR_SENTINEL __attribute__ ((__sentinel__(0))) on GCC4
so we catch where we get this wrong automatically.

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