librazor/razor.h.in
author J. Ali Harlow <ali@juiblex.co.uk>
Fri Jun 08 18:02:49 2018 +0100 (2018-06-08)
changeset 501 850be6a6885c
parent 483 8087224f30c4
permissions -rw-r--r--
Added tag 0.7 for changeset f98d77376544
     1 /*
     2  * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
     3  * Copyright (C) 2008  Red Hat, Inc
     4  * Copyright (C) 2009, 2011, 2012, 2014, 2016, 2018
     5  *		 J. Ali Harlow <ali@juiblex.co.uk>
     6  *
     7  * This program is free software; you can redistribute it and/or modify
     8  * it under the terms of the GNU General Public License as published by
     9  * the Free Software Foundation; either version 2 of the License, or
    10  * (at your option) any later version.
    11  *
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License along
    18  * with this program; if not, write to the Free Software Foundation, Inc.,
    19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    20  */
    21 
    22 #ifndef _RAZOR_H_
    23 #define _RAZOR_H_
    24 
    25 #include <stdio.h>
    26 #include <stdint.h>
    27 #include <sys/stat.h>
    28 
    29 /* GCC extensions */
    30 #if defined(__GNUC__)
    31 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
    32 #define RAZOR_MALLOC __attribute__((__malloc__))
    33 #else
    34 #define RAZOR_MALLOC
    35 #endif
    36 #if __GNUC__ >= 4
    37 #define RAZOR_NULL_TERMINATED __attribute__ ((__sentinel__))
    38 #else
    39 #define RAZOR_NULL_TERMINATED
    40 #endif
    41 #endif	/* __GNUC__ */
    42 
    43 enum razor_section_type {
    44 	RAZOR_SECTION_MAIN = 0x01,
    45 	RAZOR_SECTION_DETAILS = 0x02,
    46 	RAZOR_SECTION_FILES = 0x04,
    47 	RAZOR_SECTION_ALL = 0x07
    48 };
    49 
    50 enum razor_stage_type {
    51 	RAZOR_STAGE_SCRIPTS_PRE = 0x1,
    52 	RAZOR_STAGE_FILES = 0x2,
    53 	RAZOR_STAGE_SCRIPTS_POST = 0x4,
    54 	RAZOR_STAGE_SCRIPTS = 0x5,
    55 	RAZOR_STAGE_ALL = 0x7
    56 };
    57 
    58 enum razor_detail_type {
    59 	RAZOR_DETAIL_LAST = 0,	/* the sentinel */
    60 	RAZOR_DETAIL_NAME,
    61 	RAZOR_DETAIL_VERSION,
    62 	RAZOR_DETAIL_ARCH,
    63 	RAZOR_DETAIL_SUMMARY,
    64 	RAZOR_DETAIL_DESCRIPTION,
    65 	RAZOR_DETAIL_URL,
    66 	RAZOR_DETAIL_LICENSE,
    67 	RAZOR_DETAIL_PREUNPROG,
    68 	RAZOR_DETAIL_PREUN,
    69 	RAZOR_DETAIL_POSTUNPROG,
    70 	RAZOR_DETAIL_POSTUN,
    71 	RAZOR_DETAIL_PREFIXES
    72 };
    73 
    74 enum razor_property_flags {
    75 	RAZOR_PROPERTY_LESS		= 1 << 0,
    76 	RAZOR_PROPERTY_GREATER		= 1 << 1,
    77 	RAZOR_PROPERTY_EQUAL		= 1 << 2,
    78 	RAZOR_PROPERTY_RELATION_MASK	=
    79 		RAZOR_PROPERTY_LESS |
    80 		RAZOR_PROPERTY_GREATER |
    81 		RAZOR_PROPERTY_EQUAL,
    82 
    83 	RAZOR_PROPERTY_REQUIRES		= 0 << 3,
    84 	RAZOR_PROPERTY_PROVIDES		= 1 << 3,
    85 	RAZOR_PROPERTY_CONFLICTS	= 2 << 3,
    86 	RAZOR_PROPERTY_OBSOLETES	= 3 << 3,
    87 	RAZOR_PROPERTY_TYPE_MASK	= 3 << 3,
    88 		
    89 	RAZOR_PROPERTY_PRE		= 1 << 5,
    90 	RAZOR_PROPERTY_POST		= 1 << 6,
    91 	RAZOR_PROPERTY_PREUN		= 1 << 7,
    92 	RAZOR_PROPERTY_POSTUN		= 1 << 8,
    93 	RAZOR_PROPERTY_SCRIPT_MASK	=
    94 		RAZOR_PROPERTY_PRE |
    95 		RAZOR_PROPERTY_POST |
    96 		RAZOR_PROPERTY_PREUN |
    97 		RAZOR_PROPERTY_POSTUN
    98 };
    99 
   100 enum razor_set_flags {
   101 	/*
   102 	 * Create a private copy of the razor set such that changes made
   103 	 * to the underlying file are not visible in the razor set.
   104 	 * If this flag is not set then the caller must ensure that the
   105 	 * underlying file (if any) is not changed.
   106 	 */
   107 	RAZOR_SET_PRIVATE		= 1 << 0,
   108 };
   109 
   110 /**
   111  * SECTION:error
   112  * @title: Error reporting
   113  * @short_description: A system for reporting errors.
   114  *
   115  * This object represents an error condition.
   116  */
   117 struct razor_error;
   118 
   119 struct razor_error *razor_error_new_str(int domain, int code,
   120 					const char *object, const char *str);
   121 struct razor_error *razor_error_dup(struct razor_error *src,
   122 				    const char *summary);
   123 
   124 #define razor_set_error(error, domain, code, object, str) \
   125 	if (error) \
   126 		*(error) = razor_error_new_str(domain, code, object, str); \
   127 	else
   128 
   129 #define razor_propagate_error(dest, src, summary) \
   130 	if (dest) \
   131 		*(dest) = razor_error_dup(src, summary); \
   132 	else
   133 
   134 #define razor_error_matches(error, domain, code) \
   135 	((error) && razor_error_get_domain(error) == (domain) && \
   136 	 razor_error_get_code(error) == (code))
   137 
   138 #define RAZOR_ERROR_DOMAIN(i1,i2,i3,c) \
   139 	(((i1)&0xff)<<24|((i2)&0xff)<<16|((i3)&0xff)<<8|(c)&0xff)
   140 
   141 #define RAZOR_GENERAL_ERROR	RAZOR_ERROR_DOMAIN('R','z','r',0)
   142 #define RAZOR_POSIX_ERROR	RAZOR_ERROR_DOMAIN('R','z','r',1)
   143 #define RAZOR_MSWIN_ERROR	RAZOR_ERROR_DOMAIN('R','z','r',2)
   144 #define RAZOR_ZLIB_ERROR	RAZOR_ERROR_DOMAIN('R','z','r',3)
   145 
   146 enum razor_general_error {
   147 	RAZOR_GENERAL_ERROR_FAILED,
   148 	RAZOR_GENERAL_ERROR_DATABASE_CORRUPTED,
   149 	RAZOR_GENERAL_ERROR_DATABASE_INCOMPATIBLE,
   150 	RAZOR_GENERAL_ERROR_DATABASE_EXISTS,
   151 	RAZOR_GENERAL_ERROR_DATABASE_LOCKED,
   152 	RAZOR_GENERAL_ERROR_RPM_UNSUPPORTED,
   153 	RAZOR_GENERAL_ERROR_UNSUPPORTED_URI,
   154 	RAZOR_GENERAL_ERROR_BAD_URI,
   155 	RAZOR_GENERAL_ERROR_UNSUPPORTED_ARCHIVE,
   156 	RAZOR_GENERAL_ERROR_ALREADY_LOCKED,
   157 	RAZOR_GENERAL_ERROR_EXTERNALLY_LOCKED,
   158 };
   159 
   160 int razor_error_get_domain(struct razor_error *error);
   161 int razor_error_get_code(struct razor_error *error);
   162 const char *razor_error_get_object(struct razor_error *error);
   163 const char *razor_error_get_primary_text(struct razor_error *error);
   164 const char *razor_error_get_secondary_text(struct razor_error *error);
   165 const char *razor_error_get_msg(struct razor_error *error);
   166 void razor_error_free(struct razor_error *error);
   167 
   168 /**
   169  * SECTION:atomic
   170  * @title: Atomic transactions
   171  * @short_description: File-based transactions that shouldn't half-succeed
   172  *
   173  * This is a helper object for issuing a sequence of file-based actions
   174  * that should either all succeed or all fail.
   175  *
   176  * Note that currently only Windows 7 has a native implementation and that
   177  * while the emulated fallback implementation attempts to rollback the
   178  * transaction if it fails, this is not guaranteed to succeed and that
   179  * the transaction is held in core (and thus vulnernable to program crashes,
   180  * power loss, etc.). This could (and should) be improved.
   181  *
   182  * Atomic transactions can be disabled via configure, in which case all
   183  * bets are off.
   184  **/
   185 
   186 @RAZOR_HAVE_ATOMIC_ROLLBACK@
   187 
   188 struct razor_atomic;
   189 
   190 struct razor_atomic *razor_atomic_open(const char *description);
   191 int razor_atomic_commit(struct razor_atomic *atomic);
   192 struct razor_error *razor_atomic_get_error(struct razor_atomic *atomic);
   193 const char *razor_atomic_get_error_msg(struct razor_atomic *atomic);
   194 void razor_atomic_destroy(struct razor_atomic *atomic);
   195 
   196 /**
   197  * razor_atomic_make_dirs
   198  * 
   199  * Create all sub-directories leading up to uri. We know root_uri exists
   200  * and is a dir, root_uri does not end in a '/', and uri either has a
   201  * leading '/' or (on MS-Windows only) root_uri is the empty string
   202  * and uri starts with drive (eg., "c:/windows").
   203  * Note: uri itself is not created, only the directory in which it
   204  * (would) exist.
   205  *
   206  * Returns: non-zero on error.
   207  **/
   208 int razor_atomic_make_dirs(struct razor_atomic *atomic, const char *root_uri,
   209   const char *uri);
   210 int razor_atomic_remove(struct razor_atomic *atomic, const char *path);
   211 int razor_atomic_rename_file(struct razor_atomic *atomic, const char *old_uri,
   212 			     const char *new_uri);
   213 
   214 /**
   215  * razor_atomic_create_dir
   216  * 
   217  * Create a directory, replacing any existing object at this path except
   218  * an existing directory (which is not counted as a error).
   219  *
   220  * Returns: non-zero on error.
   221  */
   222 int razor_atomic_create_dir(struct razor_atomic *atomic, const char *uri,
   223 			    mode_t mode);
   224 
   225 /**
   226  * razor_atomic_create_symlink
   227  * 
   228  * Create a symbolic link, replacing any existing object at this path except
   229  * a non-empty directory.
   230  *
   231  * Note: This function will always fail on platforms that don't support
   232  * symbolic links.
   233  *
   234  * Returns: non-zero on error.
   235  */
   236 int razor_atomic_create_symlink(struct razor_atomic *atomic, const char *target,
   237 				const char *uri);
   238 /**
   239  * razor_atomic_create_file
   240  * 
   241  * Create a file, replacing any existing object at this path except
   242  * a non-empty directory.
   243  *
   244  * Returns: A handle to be passed to razor_atomic_write() and
   245  * razor_atomic_close() or a negative value on error.
   246  */
   247 int razor_atomic_create_file(struct razor_atomic *atomic, const char *uri,
   248 			     mode_t mode);
   249 int razor_atomic_write(struct razor_atomic *atomic, int handle,
   250 		       const void *data, size_t size);
   251 int razor_atomic_close(struct razor_atomic *atomic, int handle);
   252 int razor_atomic_sync(struct razor_atomic *atomic, int handle);
   253 void razor_atomic_abort(struct razor_atomic *atomic, int domain, int code,
   254 			const char *error_msg);
   255 void
   256 razor_atomic_propagate_error(struct razor_atomic *atomic,
   257 			     struct razor_error *error, const char *summary);
   258 int razor_atomic_in_error_state(struct razor_atomic *atomic);
   259 
   260 /**
   261  * SECTION:set
   262  * @title: Package Set
   263  * @short_description: Represents a set of packages and their metadata.
   264  *
   265  * This object represents a set of packages, their dependency
   266  * information, the file lists and a number of other details.
   267  **/
   268 
   269 struct razor_set;
   270 struct razor_package;
   271 struct razor_property;
   272 
   273 #define RAZOR_HEADER_VERSION		2	/* Current version */
   274 #define RAZOR_HEADER_VERSION_MIN	1	/* Minimum version we support */
   275 
   276 /**
   277  * razor_set_create:
   278  * 
   279  * Create a new #razor_set object.
   280  * 
   281  * Returns: the new #razor_set object.
   282  **/
   283 struct razor_set *razor_set_create_without_root(void);
   284 struct razor_set *razor_set_create(void);
   285 struct razor_set *
   286 razor_set_open(const char *uri, enum razor_set_flags flags,
   287 	       struct razor_error **error);
   288 uint32_t razor_set_get_header_version(struct razor_set *set);
   289 int razor_set_set_header_version(struct razor_set *set,
   290 				 uint32_t header_version);
   291 void razor_set_unref(struct razor_set *set);
   292 struct razor_set *razor_set_ref(struct razor_set *set);
   293 void razor_set_write_to_handle(struct razor_set *set,
   294 			       struct razor_atomic *atomic, int handle,
   295 			       uint32_t section_mask);
   296 int razor_set_write(struct razor_set *set, struct razor_atomic *atomic,
   297 		    const char *uri, uint32_t setions);
   298 int
   299 razor_set_bind_sections(struct razor_set *set, const char *uri,
   300 			enum razor_set_flags flags, struct razor_error **error);
   301 
   302 void
   303 razor_package_get_details(struct razor_set *set,
   304 			  struct razor_package *package, ...);
   305 int
   306 razor_package_remove(struct razor_set *prev, struct razor_set *next,
   307 		     struct razor_atomic *atomic, struct razor_package *package,
   308 		     const char *root_uri, int install_count,
   309 		     enum razor_stage_type stage);
   310 
   311 /**
   312  * SECTION:iterator
   313  * @title: Iterators
   314  * @short_description: Objects for traversing packages or properties.
   315  *
   316  * The razor iterator objects provides a way to iterate through a set
   317  * of packages or properties.
   318  **/
   319 
   320 struct razor_package_iterator;
   321 
   322 /**
   323  * razor_package_iterator_create:
   324  * 
   325  * Create a new #razor_package_iterator object.
   326  * 
   327  * Returns: the new #razor_package_iterator object.
   328  **/
   329 
   330 struct razor_package_iterator *
   331 razor_package_iterator_create(struct razor_set *set);
   332 
   333 /**
   334  * razor_package_iterator_create_for_property:
   335  * 
   336  * Create a new #razor_package_iterator object for the packages that
   337  * own the given property.
   338  * 
   339  * Returns: the new #razor_package_iterator object.
   340  **/
   341 struct razor_package_iterator *
   342 razor_package_iterator_create_for_property(struct razor_set *set,
   343 					   struct razor_property *property);
   344 
   345 /**
   346  * razor_package_iterator_create_for_file:
   347  *
   348  * Create a new #razor_package_iterator object for the packages that
   349  * contain the given file name.
   350  *
   351  * Returns: the new #razor_package_iterator object.
   352  **/
   353 struct razor_package_iterator *
   354 razor_package_iterator_create_for_file(struct razor_set *set,
   355 				       const char *filename);
   356 
   357 int razor_package_iterator_next(struct razor_package_iterator *pi,
   358 				struct razor_package **package, ...);
   359 void razor_package_iterator_destroy(struct razor_package_iterator *pi);
   360 
   361 struct razor_package_query *
   362 razor_package_query_create(struct razor_set *set);
   363 void
   364 razor_package_query_add_package(struct razor_package_query *pq,
   365 				struct razor_package *p);
   366 void
   367 razor_package_query_add_iterator(struct razor_package_query *pq,
   368 				 struct razor_package_iterator *pi);
   369 struct razor_package_iterator *
   370 razor_package_query_finish(struct razor_package_query *pq);
   371 
   372 struct razor_property_iterator;
   373 struct razor_property_iterator *
   374 razor_property_iterator_create(struct razor_set *set,
   375 			       struct razor_package *package);
   376 int razor_property_iterator_next(struct razor_property_iterator *pi,
   377 				 struct razor_property **property,
   378 				 const char **name,
   379 				 uint32_t *flags,
   380 				 const char **version);
   381 void
   382 razor_property_iterator_destroy(struct razor_property_iterator *pi);
   383 
   384 struct razor_file_iterator;
   385 struct razor_file_iterator *
   386 razor_file_iterator_create(struct razor_set *set,
   387 			   struct razor_package *package, int post_order);
   388 int razor_file_iterator_next(struct razor_file_iterator *fi,
   389 			     const char **name);
   390 void razor_file_iterator_destroy(struct razor_file_iterator *fi);
   391 
   392 void razor_set_list_files(struct razor_set *set, const char *prefix);
   393 void razor_set_list_package_files(struct razor_set *set,
   394 				  struct razor_package *package);
   395 
   396 struct razor_string_iterator;
   397 struct razor_string_iterator *
   398 razor_install_prefix_iterator_create(struct razor_set *set,
   399 				     struct razor_package *package);
   400 int razor_string_iterator_next(struct razor_string_iterator *si,
   401 			       const char **string);
   402 void razor_string_iterator_destroy(struct razor_string_iterator *si);
   403 
   404 enum razor_diff_action {
   405 	RAZOR_DIFF_ACTION_ADD,
   406 	RAZOR_DIFF_ACTION_REMOVE,
   407 };
   408 
   409 typedef void (*razor_diff_callback_t)(enum razor_diff_action action,
   410 				      struct razor_package *package,
   411 				      const char *name,
   412 				      const char *version,
   413 				      const char *arch,
   414 				      void *data);
   415 
   416 void
   417 razor_set_diff(struct razor_set *set, struct razor_set *upstream,
   418 	       razor_diff_callback_t callback, void *data);
   419 
   420 struct razor_install_iterator;
   421 
   422 enum razor_install_action {
   423 	RAZOR_INSTALL_ACTION_ADD,
   424 	RAZOR_INSTALL_ACTION_REMOVE,
   425 	RAZOR_INSTALL_ACTION_COMMIT
   426 };
   427 
   428 struct razor_install_iterator *
   429 razor_set_create_install_iterator(struct razor_set *set,
   430 				  struct razor_set *next);
   431 
   432 int razor_install_iterator_next(struct razor_install_iterator *ii,
   433 				struct razor_package **package,
   434 				enum razor_install_action *action,
   435 				int *count);
   436 
   437 /**
   438  * razor_install_iterator_commit_set
   439  *
   440  * Immediately after razor_install_iterator_next() returns
   441  * RAZOR_INSTALL_ACTION_COMMIT, this function will return the razor_set
   442  * which should be committed.
   443  *
   444  * Returns: a new #razor_set object.
   445  **/
   446 struct razor_set *
   447 razor_install_iterator_commit_set(struct razor_install_iterator *ii);
   448 
   449 void razor_install_iterator_rewind(struct razor_install_iterator *ii);
   450 size_t razor_install_iterator_tell(struct razor_install_iterator *ii);
   451 size_t razor_install_iterator_seek(struct razor_install_iterator *ii,
   452 				   size_t pos);
   453 void razor_install_iterator_destroy(struct razor_install_iterator *ii);
   454 
   455 /**
   456  * SECTION:transaction
   457  * @title: Transaction
   458  * @short_description: Create a new package set by merging two or more sets.
   459  *
   460  * The razor transaction object provides a way to create a new package set
   461  * from packages from one or more other package sets.
   462  **/
   463 
   464 struct razor_rpm;
   465 
   466 struct razor_transaction *
   467 razor_transaction_create(struct razor_set *system, struct razor_set *upstream);
   468 void razor_transaction_install_package(struct razor_transaction *transaction,
   469 				       struct razor_package *package);
   470 void razor_transaction_remove_package(struct razor_transaction *transaction,
   471 				      struct razor_package *package);
   472 void razor_transaction_update_package(struct razor_transaction *trans,
   473 				      struct razor_package *package);
   474 void razor_transaction_fixup_package(struct razor_transaction *trans,
   475 				     struct razor_package *package,
   476 				     struct razor_rpm *rpm);
   477 void razor_transaction_update_all(struct razor_transaction *transaction);
   478 int razor_transaction_resolve(struct razor_transaction *trans);
   479 
   480 typedef void (*razor_unsatisfied_callback_t)(const char *requirement,
   481 					     struct razor_package *package,
   482 					     const char *name,
   483 					     const char *version,
   484 					     const char *arch,
   485 					     void *data);
   486 
   487 int razor_transaction_unsatisfied(struct razor_transaction *trans,
   488 				  razor_unsatisfied_callback_t callback,
   489 				  void *data);
   490 int razor_transaction_describe(struct razor_transaction *trans);
   491 struct razor_set *razor_transaction_commit(struct razor_transaction *trans);
   492 void razor_transaction_destroy(struct razor_transaction *trans);
   493 
   494 /* Temporary helper for test suite. */
   495 int razor_transaction_unsatisfied_property(struct razor_transaction *trans,
   496 					   const char *name,
   497 					   uint32_t flags,
   498 					   const char *version);
   499 
   500 /**
   501  * SECTION:rpm
   502  * @title: Razor RPM
   503  * @short_description: Operating on RPM files.
   504  *
   505  * Functions for open RPM files and extracting information and
   506  * installing or removing RPM files.
   507  **/
   508 
   509 struct razor_relocations;
   510 
   511 struct razor_relocations *razor_relocations_create(void);
   512 void razor_relocations_add(struct razor_relocations *relocations,
   513 			   const char *oldpath, const char *newpath);
   514 void razor_relocations_set_rpm(struct razor_relocations *relocations,
   515 			       struct razor_rpm *rpm);
   516 const char *razor_relocations_apply(struct razor_relocations *relocations,
   517 				    const char *path);
   518 void razor_relocations_destroy(struct razor_relocations *relocations);
   519 
   520 struct razor_rpm *razor_rpm_open(const char *uri, struct razor_error **error);
   521 void razor_rpm_get_details(struct razor_rpm *rpm, ...);
   522 void razor_rpm_set_relocations(struct razor_rpm *rpm,
   523 			       struct razor_relocations *relocations);
   524 int razor_rpm_install(struct razor_rpm *rpm, struct razor_atomic *atomic,
   525 		      const char *root_uri, int install_count,
   526 		      enum razor_stage_type stage);
   527 int razor_rpm_close(struct razor_rpm *rpm);
   528 
   529 /**
   530  * SECTION:importer
   531  * @title: Importer
   532  * @short_description: A mechanism for building #razor_set objects
   533  *
   534  * The %razor_importer is a helper object for building a razor set
   535  * from external sources, like yum metadata, the RPM database or RPM
   536  * files.
   537  *
   538  * The importer is a stateful object; it has the notion of a current
   539  * package, and the caller can provide meta data such as properties,
   540  * files and similiar for the package as it becomes available.  Once a
   541  * package is fully described, the next pacakge can begin.  When all
   542  * packages have been described to the importer, the importer will
   543  * create a new %razor_set with the specified packages.
   544  *
   545  * A typical use
   546  * of the importer will follow this template:
   547  * |[
   548  * importer = razor_importer_create();
   549  *
   550  * while ( /<!-- -->* more packages to import *<!-- -->/; ) {
   551  *   /<!-- -->* get name, version and arch of next package *<!-- -->/
   552  *   razor_importer_begin_package(importer, name, version, arch);
   553  *   razor_importer_add_details(importer, summary, description, url, license);
   554  *
   555  *   while ( /<!-- -->* more properties to add *<!-- -->/ )
   556  *     razor_importer_add_property(importer, name, flags, version);
   557  *
   558  *   while ( /<!-- -->* [more files to add *<!-- -->/ )
   559  *     razor_importer_add_file(importer, name);
   560  *
   561  *   razor_importer_finish_package(importer);
   562  * }
   563  *
   564  * return razor_importer_finish(importer);
   565  * ]|
   566  **/
   567 struct razor_importer;
   568 
   569 struct razor_importer *razor_importer_create(void);
   570 void razor_importer_destroy(struct razor_importer *importer);
   571 void razor_importer_begin_package(struct razor_importer *importer,
   572 				  const char *name,
   573 				  const char *version,
   574 				  const char *arch);
   575 void razor_importer_add_details(struct razor_importer *importer,
   576 				const char *summary,
   577 				const char *description,
   578 				const char *url,
   579 				const char *license);
   580 void razor_importer_add_script(struct razor_importer *importer,
   581 			       enum razor_property_flags script,
   582 			       const char *program,
   583 			       const char *body);
   584 void razor_importer_add_install_prefix(struct razor_importer *importer,
   585 				       const char *install_prefix);
   586 void razor_importer_add_property(struct razor_importer *importer,
   587 				 const char *name,
   588 				 uint32_t flags,
   589 				 const char *version);
   590 void razor_importer_add_file(struct razor_importer *importer,
   591 			     const char *name);
   592 void razor_importer_finish_package(struct razor_importer *importer);
   593 
   594 int razor_importer_add_rpm(struct razor_importer *importer,
   595 			   struct razor_rpm *rpm);
   596 
   597 struct razor_set *razor_importer_finish(struct razor_importer *importer);
   598 
   599 /**
   600  * SECTION:root
   601  * @title: Root
   602  * @short_description: Functions for accessing an install root.
   603  *
   604  * The #razor_root object encapsulate access to and locking of a razor
   605  * install root.
   606  **/
   607 struct razor_root;
   608 
   609 const char *razor_get_database_uri(void);
   610 void razor_set_database_uri(const char *database_uri);
   611 int razor_root_create(const char *root_uri, struct razor_error **error);
   612 struct razor_root *
   613 razor_root_open(const char *root_uri, struct razor_error **error);
   614 struct razor_set *
   615 razor_root_open_read_only(const char *root_uri, struct razor_error **error);
   616 struct razor_set *razor_root_get_system_set(struct razor_root *root);
   617 int razor_root_close(struct razor_root *root);
   618 int
   619 razor_root_update(struct razor_root *root, struct razor_set *next,
   620 		  struct razor_atomic *atomic);
   621 
   622 /**
   623  * SECTION:uri-io
   624  * @title: URI Input/Output
   625  * @short_description: Functions to support non-file URI handlers
   626  *
   627  * Libraries that want to support URIs other than file URIs (which razor
   628  * handles internally), can install their own URI handlers. Unsupported
   629  * virtual functions should be set to %NULL. A fallback URI handler (which
   630  * will be used if no scheme-specific handler is found) can be installed
   631  * by passing scheme as %NULL. Finally, URI handlers can be removed by
   632  * passing vtable as %NULL.
   633  **/
   634 
   635 struct razor_uri_vtable {
   636 	unsigned structure_size;
   637 	int (*mkdir)(const char *path, mode_t mode, struct razor_error **error);
   638 	int (*unlink)(const char *path, struct razor_error **error);
   639 	int (*open)(const char *path, int flags, mode_t mode,
   640 		    struct razor_error **error);
   641 	int (*move)(const char *path, const char *dest,
   642 		    struct razor_error **error);
   643 	void *(*get_contents)(const char *path, size_t *length, int _private,
   644 			      struct razor_error **error);
   645 	int (*free_contents)(void *addr, size_t length);
   646 	int (*is_directory)(const char *path, struct razor_error **error);
   647 	char *(*mkdtemp_near)(const char *path, const char *_template,
   648 			      struct razor_error **error);
   649 	void *(*opendir)(const char *path, struct razor_error **error);
   650 	char *(*readdir)(void *dir, struct razor_error **error);
   651 	int (*closedir)(void *dir, struct razor_error **error);
   652 };
   653 
   654 int razor_uri_mkdir(const char *uri, mode_t mode, struct razor_error **error);
   655 int razor_uri_unlink(const char *uri, struct razor_error **error);
   656 int razor_uri_open(const char *uri, int flags, mode_t mode,
   657 		   struct razor_error **error);
   658 int razor_uri_move(const char *uri, const char *dest,
   659 		   struct razor_error **error);
   660 int razor_uri_is_directory(const char *uri, struct razor_error **error);
   661 char *razor_uri_mkdtemp_near(const char *uri, const char *_template,
   662 			     struct razor_error **error) RAZOR_MALLOC;
   663 void *razor_uri_opendir(const char *uri, struct razor_error **error);
   664 char *razor_uri_readdir(void *dir, struct razor_error **error) RAZOR_MALLOC;
   665 int razor_uri_closedir(void *dir, struct razor_error **error);
   666 void *razor_uri_get_contents(const char *uri, size_t *length, int _private,
   667 			     struct razor_error **error);
   668 int razor_uri_free_contents(void *addr, size_t length);
   669 
   670 int razor_uri_set_vtable(const char *scheme, struct razor_uri_vtable *vtable,
   671 			 struct razor_error **error);
   672 
   673 /**
   674  * SECTION:misc
   675  * @title: Miscellaneous Functions
   676  * @short_description: Various helper functions
   677  *
   678  * Functions that doesn't fit anywhere else.
   679  **/
   680 
   681 const char *
   682 razor_property_relation_to_string(struct razor_property *p);
   683 const char *
   684 razor_property_type_to_string(struct razor_property *p);
   685 
   686 void razor_build_evr(char *evr_buf, int size, const char *epoch,
   687 		     const char *version, const char *release);
   688 int razor_versioncmp(const char *s1, const char *s2);
   689 
   690 void razor_disable_root_name_checks(int disable);
   691 
   692 void razor_set_lua_loader(const char *modname, void (*loader)());
   693 void (*razor_get_lua_loader(const char *modname))();
   694 
   695 char *razor_concat(const char *s, ...) RAZOR_MALLOC RAZOR_NULL_TERMINATED;
   696 
   697 char *razor_path_from_uri(const char *uri, struct razor_error **error)
   698       RAZOR_MALLOC;
   699 char *razor_path_to_uri(const char *path) RAZOR_MALLOC;
   700 char *razor_path_relative_to_uri(const char *uri, const char *path,
   701 				 struct razor_error **error) RAZOR_MALLOC;
   702 
   703 /* According to RFC 3986 § 5.2 */
   704 char *razor_resolve_relative_uri(const char *base_uri, const char *relative_uri,
   705 				 struct razor_error **error);
   706 
   707 const char *razor_system_arch(void);
   708 
   709 int razor_dump_database(FILE *fp, const char *root_uri, const char *filename,
   710 			struct razor_error **error);
   711 
   712 #endif /* _RAZOR_H_ */