librazor/razor.h
author James Bowes <jbowes@redhat.com>
Wed Jul 09 10:11:13 2008 -0400 (2008-07-09)
changeset 318 829d6711b316
parent 309 a69289c9080c
child 351 48b0adfe3059
permissions -rw-r--r--
Use strings to identify section types in the on-disk repo format.

Previously, a given razor file type had a fixed number of sections in a
fixed order, identified by an integer type. Now, sections are identified
by a named string (stored in a string pool after the section lists).

This will allow for razor files to contain arbitrary sections.

For bonus points, also drop the 4k section alignment and change the
magic byte string to "RZDB".

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