librazor/razor.h
author J. Ali Harlow <ali@juiblex.co.uk>
Wed Apr 29 17:00:01 2009 +0100 (2009-04-29)
changeset 361 2523d03a840e
parent 359 c9c90315ea24
child 363 c75a2d5caae9
permissions -rw-r--r--
Add support for preloading lua modules. This is useful both when
providing lua bindings to applications based on librazor and when
producing static binaries using librazor (where otherwise the lua
POSIX library would need to be included as an additional dynamic
object).
     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 struct razor_file_iterator;
   176 struct razor_file_iterator *
   177 razor_file_iterator_create(struct razor_set *set,
   178 			   struct razor_package *package);
   179 int razor_file_iterator_next(struct razor_file_iterator *fi,
   180 			     const char **name);
   181 void razor_file_iterator_destroy(struct razor_file_iterator *fi);
   182 
   183 void razor_set_list_files(struct razor_set *set, const char *prefix);
   184 void razor_set_list_package_files(struct razor_set *set,
   185 				  struct razor_package *package);
   186 
   187 enum razor_diff_action {
   188 	RAZOR_DIFF_ACTION_ADD,
   189 	RAZOR_DIFF_ACTION_REMOVE,
   190 };
   191 
   192 typedef void (*razor_diff_callback_t)(enum razor_diff_action action,
   193 				      struct razor_package *package,
   194 				      const char *name,
   195 				      const char *version,
   196 				      const char *arch,
   197 				      void *data);
   198 
   199 void
   200 razor_set_diff(struct razor_set *set, struct razor_set *upstream,
   201 	       razor_diff_callback_t callback, void *data);
   202 
   203 struct razor_install_iterator;
   204 
   205 enum razor_install_action {
   206 	RAZOR_INSTALL_ACTION_ADD,
   207 	RAZOR_INSTALL_ACTION_REMOVE
   208 };
   209 
   210 struct razor_install_iterator *
   211 razor_set_create_install_iterator(struct razor_set *set,
   212 				  struct razor_set *next);
   213 
   214 int razor_install_iterator_next(struct razor_install_iterator *ii,
   215 				struct razor_set **set,
   216 				struct razor_package **package,
   217 				enum razor_install_action *action,
   218 				int *count);
   219 
   220 void razor_install_iterator_destroy(struct razor_install_iterator *ii);
   221 
   222 /**
   223  * SECTION:transaction
   224  * @title: Transaction
   225  * @short_description: Create a new package set by merging two or more sets.
   226  *
   227  * The razor transaction object provides a way to create a new package set
   228  * from packages from one or more other package sets.
   229  **/
   230 
   231 struct razor_transaction *
   232 razor_transaction_create(struct razor_set *system, struct razor_set *upstream);
   233 void razor_transaction_install_package(struct razor_transaction *transaction,
   234 				       struct razor_package *package);
   235 void razor_transaction_remove_package(struct razor_transaction *transaction,
   236 				      struct razor_package *package);
   237 void razor_transaction_update_package(struct razor_transaction *trans,
   238 				      struct razor_package *package);
   239 void razor_transaction_update_all(struct razor_transaction *transaction);
   240 int razor_transaction_resolve(struct razor_transaction *trans);
   241 int razor_transaction_describe(struct razor_transaction *trans);
   242 struct razor_set *razor_transaction_finish(struct razor_transaction *trans);
   243 void razor_transaction_destroy(struct razor_transaction *trans);
   244 
   245 /* Temporary helper for test suite. */
   246 int razor_transaction_unsatisfied_property(struct razor_transaction *trans,
   247 					   const char *name,
   248 					   uint32_t flags,
   249 					   const char *version);
   250 
   251 /**
   252  * SECTION:rpm
   253  * @title: Razor RPM
   254  * @short_description: Operating on RPM files.
   255  *
   256  * Functions for open RPM files and extracting information and
   257  * installing or removing RPM files.
   258  **/
   259 
   260 struct razor_relocations;
   261 struct razor_rpm;
   262 
   263 struct razor_relocations *razor_relocations_create(void);
   264 void razor_relocations_add(struct razor_relocations *relocations,
   265 			   const char *oldpath, const char *newpath);
   266 void razor_relocations_set_rpm(struct razor_relocations *relocations,
   267 			       struct razor_rpm *rpm);
   268 const char *razor_relocations_apply(struct razor_relocations *relocations,
   269 				    const char *path);
   270 void razor_relocations_destroy(struct razor_relocations *relocations);
   271 
   272 struct razor_rpm *razor_rpm_open(const char *filename);
   273 void razor_rpm_set_relocations(struct razor_rpm *rpm,
   274 			       struct razor_relocations *relocations);
   275 int razor_rpm_install(struct razor_rpm *rpm, const char *root);
   276 int razor_rpm_close(struct razor_rpm *rpm);
   277 
   278 /**
   279  * SECTION:importer
   280  * @title: Importer
   281  * @short_description: A mechanism for building #razor_set objects
   282  *
   283  * The %razor_importer is a helper object for building a razor set
   284  * from external sources, like yum metadata, the RPM database or RPM
   285  * files.
   286  *
   287  * The importer is a stateful object; it has the notion of a current
   288  * package, and the caller can provide meta data such as properties,
   289  * files and similiar for the package as it becomes available.  Once a
   290  * package is fully described, the next pacakge can begin.  When all
   291  * packages have been described to the importer, the importer will
   292  * create a new %razor_set with the specified packages.
   293  *
   294  * A typical use
   295  * of the importer will follow this template:
   296  * |[
   297  * importer = razor_importer_create();
   298  *
   299  * while ( /<!-- -->* more packages to import *<!-- -->/; ) {
   300  *   /<!-- -->* get name, version and arch of next package *<!-- -->/
   301  *   razor_importer_begin_package(importer, name, version, arch);
   302  *   razor_importer_add_details(importer, summary, description, url, license);
   303  *
   304  *   while ( /<!-- -->* more properties to add *<!-- -->/ )
   305  *     razor_importer_add_property(importer, name, flags, version);
   306  *
   307  *   while ( /<!-- -->* [more files to add *<!-- -->/ )
   308  *     razor_importer_add_file(importer, name);
   309  *
   310  *   razor_importer_finish_package(importer);
   311  * }
   312  *
   313  * return razor_importer_finish(importer);
   314  * ]|
   315  **/
   316 struct razor_importer;
   317 
   318 struct razor_importer *razor_importer_create(void);
   319 void razor_importer_destroy(struct razor_importer *importer);
   320 void razor_importer_begin_package(struct razor_importer *importer,
   321 				  const char *name,
   322 				  const char *version,
   323 				  const char *arch);
   324 void razor_importer_add_details(struct razor_importer *importer,
   325 				const char *summary,
   326 				const char *description,
   327 				const char *url,
   328 				const char *license);
   329 void razor_importer_add_property(struct razor_importer *importer,
   330 				 const char *name,
   331 				 uint32_t flags,
   332 				 const char *version);
   333 void razor_importer_add_file(struct razor_importer *importer,
   334 			     const char *name);
   335 void razor_importer_finish_package(struct razor_importer *importer);
   336 
   337 int razor_importer_add_rpm(struct razor_importer *importer,
   338 			   struct razor_rpm *rpm);
   339 
   340 struct razor_set *razor_importer_finish(struct razor_importer *importer);
   341 
   342 struct razor_set *razor_set_create_from_yum(void);
   343 struct razor_set *razor_set_create_from_rpmdb(void);
   344 
   345 /**
   346  * SECTION:root
   347  * @title: Root
   348  * @short_description: Functions for accessing an install root.
   349  *
   350  * The #razor_root object encapsulate access to and locking of a razor
   351  * install root.
   352  **/
   353 struct razor_root;
   354 
   355 int razor_root_create(const char *root);
   356 struct razor_root *razor_root_open(const char *root);
   357 struct razor_set *razor_root_open_read_only(const char *root);
   358 struct razor_set *razor_root_get_system_set(struct razor_root *root);
   359 int razor_root_close(struct razor_root *root);
   360 void razor_root_update(struct razor_root *root, struct razor_set *next);
   361 int razor_root_commit(struct razor_root *root);
   362 
   363 
   364 /**
   365  * SECTION:misc
   366  * @title: Miscellaneous Functions
   367  * @short_description: Various helper functions
   368  *
   369  * Functions that doesn't fit anywhere else.
   370  **/
   371 
   372 const char *
   373 razor_property_relation_to_string(struct razor_property *p);
   374 const char *
   375 razor_property_type_to_string(struct razor_property *p);
   376 
   377 void razor_build_evr(char *evr_buf, int size, const char *epoch,
   378 		     const char *version, const char *release);
   379 int razor_versioncmp(const char *s1, const char *s2);
   380 
   381 void razor_disable_root_name_checks(int disable);
   382 
   383 void razor_set_lua_loader(const char *modname, void (*loader)());
   384 
   385 
   386 #endif /* _RAZOR_H_ */