librazor/razor.h
author Kristian H?gsberg <krh@redhat.com>
Wed Jul 02 14:37:38 2008 -0400 (2008-07-02)
changeset 311 cd292c2de0b6
parent 307 95b6bcadd6c4
child 316 5ebed314390c
permissions -rw-r--r--
Move DEPSOLVE.txt and REPO.txt into docbook.

A little messy, but it's a first step towards pulling all the docs into
a nice self-contained document.
     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 struct razor_package_iterator *
   195 razor_set_create_remove_iterator(struct razor_set *set,
   196 				 struct razor_set *next);
   197 struct razor_package_iterator *
   198 razor_set_create_install_iterator(struct razor_set *set,
   199 				  struct razor_set *next);
   200 
   201 /**
   202  * SECTION:transaction
   203  * @title: Transaction
   204  * @short_description: Create a new package set by merging two or more sets.
   205  *
   206  * The razor transaction object provides a way to create a new package set
   207  * from packages from one or more other package sets.
   208  **/
   209 
   210 struct razor_transaction *
   211 razor_transaction_create(struct razor_set *system, struct razor_set *upstream);
   212 void razor_transaction_install_package(struct razor_transaction *transaction,
   213 				       struct razor_package *package);
   214 void razor_transaction_remove_package(struct razor_transaction *transaction,
   215 				      struct razor_package *package);
   216 void razor_transaction_update_package(struct razor_transaction *trans,
   217 				      struct razor_package *package);
   218 void razor_transaction_update_all(struct razor_transaction *transaction);
   219 int razor_transaction_resolve(struct razor_transaction *trans);
   220 int razor_transaction_describe(struct razor_transaction *trans);
   221 struct razor_set *razor_transaction_finish(struct razor_transaction *trans);
   222 void razor_transaction_destroy(struct razor_transaction *trans);
   223 
   224 /* Temporary helper for test suite. */
   225 int razor_transaction_unsatisfied_property(struct razor_transaction *trans,
   226 					   const char *name,
   227 					   uint32_t flags,
   228 					   const char *version);
   229 
   230 /**
   231  * SECTION:rpm
   232  * @title: Razor RPM
   233  * @short_description: Operating on RPM files.
   234  *
   235  * Functions for open RPM files and extracting information and
   236  * installing or removing RPM files.
   237  **/
   238 
   239 struct razor_rpm;
   240 
   241 struct razor_rpm *razor_rpm_open(const char *filename);
   242 int razor_rpm_install(struct razor_rpm *rpm, const char *root);
   243 int razor_rpm_close(struct razor_rpm *rpm);
   244 
   245 /**
   246  * SECTION:importer
   247  * @title: Importer
   248  * @short_description: A mechanism for building #razor_set objects
   249  *
   250  * The %razor_importer is a helper object for building a razor set
   251  * from external sources, like yum metadata, the RPM database or RPM
   252  * files.
   253  *
   254  * The importer is a stateful object; it has the notion of a current
   255  * package, and the caller can provide meta data such as properties,
   256  * files and similiar for the package as it becomes available.  Once a
   257  * package is fully described, the next pacakge can begin.  When all
   258  * packages have been described to the importer, the importer will
   259  * create a new %razor_set with the specified packages.
   260  *
   261  * A typical use
   262  * of the importer will follow this template:
   263  * |[
   264  * importer = razor_importer_create();
   265  *
   266  * while ( /<!-- -->* more packages to import *<!-- -->/; ) {
   267  *   /<!-- -->* get name, version and arch of next package *<!-- -->/
   268  *   razor_importer_begin_package(importer, name, version, arch);
   269  *   razor_importer_add_details(importer, summary, description, url, license);
   270  *
   271  *   while ( /<!-- -->* more properties to add *<!-- -->/ )
   272  *     razor_importer_add_property(importer, name, flags, version);
   273  *
   274  *   while ( /<!-- -->* [more files to add *<!-- -->/ )
   275  *     razor_importer_add_file(importer, name);
   276  *
   277  *   razor_importer_finish_package(importer);
   278  * }
   279  *
   280  * return razor_importer_finish(importer);
   281  * ]|
   282  **/
   283 struct razor_importer;
   284 
   285 struct razor_importer *razor_importer_create(void);
   286 void razor_importer_destroy(struct razor_importer *importer);
   287 void razor_importer_begin_package(struct razor_importer *importer,
   288 				  const char *name,
   289 				  const char *version,
   290 				  const char *arch);
   291 void razor_importer_add_details(struct razor_importer *importer,
   292 				const char *summary,
   293 				const char *description,
   294 				const char *url,
   295 				const char *license);
   296 void razor_importer_add_property(struct razor_importer *importer,
   297 				 const char *name,
   298 				 uint32_t flags,
   299 				 const char *version);
   300 void razor_importer_add_file(struct razor_importer *importer,
   301 			     const char *name);
   302 void razor_importer_finish_package(struct razor_importer *importer);
   303 
   304 int razor_importer_add_rpm(struct razor_importer *importer,
   305 			   struct razor_rpm *rpm);
   306 
   307 struct razor_set *razor_importer_finish(struct razor_importer *importer);
   308 
   309 struct razor_set *razor_set_create_from_yum(void);
   310 struct razor_set *razor_set_create_from_rpmdb(void);
   311 
   312 /**
   313  * SECTION:root
   314  * @title: Root
   315  * @short_description: Functions for accessing an install root.
   316  *
   317  * The #razor_root object encapsulate access to and locking of a razor
   318  * install root.
   319  **/
   320 struct razor_root;
   321 
   322 int razor_root_create(const char *root);
   323 struct razor_root *razor_root_open(const char *root);
   324 struct razor_set *razor_root_open_read_only(const char *root);
   325 struct razor_set *razor_root_get_system_set(struct razor_root *root);
   326 int razor_root_close(struct razor_root *root);
   327 void razor_root_update(struct razor_root *root, struct razor_set *next);
   328 int razor_root_commit(struct razor_root *root);
   329 
   330 
   331 /**
   332  * SECTION:misc
   333  * @title: Miscellaneous Functions
   334  * @short_description: Various helper functions
   335  *
   336  * Functions that doesn't fit anywhere else.
   337  **/
   338 
   339 const char *
   340 razor_property_relation_to_string(struct razor_property *p);
   341 const char *
   342 razor_property_type_to_string(struct razor_property *p);
   343 
   344 void razor_build_evr(char *evr_buf, int size, const char *epoch,
   345 		     const char *version, const char *release);
   346 int razor_versioncmp(const char *s1, const char *s2);
   347 
   348 
   349 #endif /* _RAZOR_H_ */