librazor/razor.h
author J. Ali Harlow <ali@juiblex.co.uk>
Wed Jun 03 08:26:09 2009 +0100 (2009-06-03)
changeset 368 ea743486ba6f
parent 363 c75a2d5caae9
child 369 f8c27fe9fe63
permissions -rw-r--r--
Add automatic provides for lua pre-loaded modules
     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 	RAZOR_PROPERTY_SCRIPT_MASK	=
    62 		RAZOR_PROPERTY_PRE |
    63 		RAZOR_PROPERTY_POST |
    64 		RAZOR_PROPERTY_PREUN |
    65 		RAZOR_PROPERTY_POSTUN
    66 };
    67 
    68 /**
    69  * SECTION:set
    70  * @title: Package Set
    71  * @short_description: Represents a set of packages and their metadata.
    72  *
    73  * This object represents a set of packages, their dependency
    74  * information, the file lists and a number of other details.
    75  **/
    76 
    77 struct razor_set;
    78 struct razor_package;
    79 struct razor_property;
    80 
    81 /**
    82  * razor_set_create:
    83  * 
    84  * Create a new #razor_set object.
    85  * 
    86  * Returns: the new #razor_set object.
    87  **/
    88 struct razor_set *razor_set_create_without_root(void);
    89 struct razor_set *razor_set_create(void);
    90 struct razor_set *razor_set_open(const char *filename);
    91 void razor_set_destroy(struct razor_set *set);
    92 int razor_set_write_to_fd(struct razor_set *set, int fd,
    93 			  enum razor_repo_file_type type);
    94 int razor_set_write(struct razor_set *set, const char *filename,
    95 		    enum razor_repo_file_type type);
    96 
    97 int razor_set_open_details(struct razor_set *set, const char *filename);
    98 int razor_set_open_files(struct razor_set *set, const char *filename);
    99 
   100 struct razor_package *
   101 razor_set_get_package(struct razor_set *set, const char *package);
   102 
   103 void
   104 razor_package_get_details(struct razor_set *set,
   105 			  struct razor_package *package, ...);
   106 
   107 
   108 /**
   109  * SECTION:iterator
   110  * @title: Iterators
   111  * @short_description: Objects for traversing packages or properties.
   112  *
   113  * The razor iterator objects provides a way to iterate through a set
   114  * of packages or properties.
   115  **/
   116 
   117 struct razor_package_iterator;
   118 
   119 /**
   120  * razor_package_iterator_create:
   121  * 
   122  * Create a new #razor_package_iterator object.
   123  * 
   124  * Returns: the new #razor_package_iterator object.
   125  **/
   126 
   127 struct razor_package_iterator *
   128 razor_package_iterator_create(struct razor_set *set);
   129 
   130 /**
   131  * razor_package_iterator_create_for_property:
   132  * 
   133  * Create a new #razor_package_iterator object for the packages that
   134  * own the given property.
   135  * 
   136  * Returns: the new #razor_package_iterator object.
   137  **/
   138 struct razor_package_iterator *
   139 razor_package_iterator_create_for_property(struct razor_set *set,
   140 					   struct razor_property *property);
   141 
   142 /**
   143  * razor_package_iterator_create_for_file:
   144  *
   145  * Create a new #razor_package_iterator object for the packages that
   146  * contain the given file name.
   147  *
   148  * Returns: the new #razor_package_iterator object.
   149  **/
   150 struct razor_package_iterator *
   151 razor_package_iterator_create_for_file(struct razor_set *set,
   152 				       const char *filename);
   153 
   154 int razor_package_iterator_next(struct razor_package_iterator *pi,
   155 				struct razor_package **package, ...);
   156 void razor_package_iterator_destroy(struct razor_package_iterator *pi);
   157 
   158 struct razor_package_query *
   159 razor_package_query_create(struct razor_set *set);
   160 void
   161 razor_package_query_add_package(struct razor_package_query *pq,
   162 				struct razor_package *p);
   163 void
   164 razor_package_query_add_iterator(struct razor_package_query *pq,
   165 				 struct razor_package_iterator *pi);
   166 struct razor_package_iterator *
   167 razor_package_query_finish(struct razor_package_query *pq);
   168 
   169 struct razor_property_iterator;
   170 struct razor_property_iterator *
   171 razor_property_iterator_create(struct razor_set *set,
   172 			       struct razor_package *package);
   173 int razor_property_iterator_next(struct razor_property_iterator *pi,
   174 				 struct razor_property **property,
   175 				 const char **name,
   176 				 uint32_t *flags,
   177 				 const char **version);
   178 void
   179 razor_property_iterator_destroy(struct razor_property_iterator *pi);
   180 
   181 struct razor_file_iterator;
   182 struct razor_file_iterator *
   183 razor_file_iterator_create(struct razor_set *set,
   184 			   struct razor_package *package);
   185 int razor_file_iterator_next(struct razor_file_iterator *fi,
   186 			     const char **name);
   187 void razor_file_iterator_destroy(struct razor_file_iterator *fi);
   188 
   189 void razor_set_list_files(struct razor_set *set, const char *prefix);
   190 void razor_set_list_package_files(struct razor_set *set,
   191 				  struct razor_package *package);
   192 
   193 enum razor_diff_action {
   194 	RAZOR_DIFF_ACTION_ADD,
   195 	RAZOR_DIFF_ACTION_REMOVE,
   196 };
   197 
   198 typedef void (*razor_diff_callback_t)(enum razor_diff_action action,
   199 				      struct razor_package *package,
   200 				      const char *name,
   201 				      const char *version,
   202 				      const char *arch,
   203 				      void *data);
   204 
   205 void
   206 razor_set_diff(struct razor_set *set, struct razor_set *upstream,
   207 	       razor_diff_callback_t callback, void *data);
   208 
   209 struct razor_install_iterator;
   210 
   211 enum razor_install_action {
   212 	RAZOR_INSTALL_ACTION_ADD,
   213 	RAZOR_INSTALL_ACTION_REMOVE
   214 };
   215 
   216 struct razor_install_iterator *
   217 razor_set_create_install_iterator(struct razor_set *set,
   218 				  struct razor_set *next);
   219 
   220 int razor_install_iterator_next(struct razor_install_iterator *ii,
   221 				struct razor_set **set,
   222 				struct razor_package **package,
   223 				enum razor_install_action *action,
   224 				int *count);
   225 
   226 void razor_install_iterator_destroy(struct razor_install_iterator *ii);
   227 
   228 /**
   229  * SECTION:transaction
   230  * @title: Transaction
   231  * @short_description: Create a new package set by merging two or more sets.
   232  *
   233  * The razor transaction object provides a way to create a new package set
   234  * from packages from one or more other package sets.
   235  **/
   236 
   237 struct razor_transaction *
   238 razor_transaction_create(struct razor_set *system, struct razor_set *upstream);
   239 void razor_transaction_install_package(struct razor_transaction *transaction,
   240 				       struct razor_package *package);
   241 void razor_transaction_remove_package(struct razor_transaction *transaction,
   242 				      struct razor_package *package);
   243 void razor_transaction_update_package(struct razor_transaction *trans,
   244 				      struct razor_package *package);
   245 void razor_transaction_update_all(struct razor_transaction *transaction);
   246 int razor_transaction_resolve(struct razor_transaction *trans);
   247 int razor_transaction_describe(struct razor_transaction *trans);
   248 struct razor_set *razor_transaction_finish(struct razor_transaction *trans);
   249 void razor_transaction_destroy(struct razor_transaction *trans);
   250 
   251 /* Temporary helper for test suite. */
   252 int razor_transaction_unsatisfied_property(struct razor_transaction *trans,
   253 					   const char *name,
   254 					   uint32_t flags,
   255 					   const char *version);
   256 
   257 /**
   258  * SECTION:rpm
   259  * @title: Razor RPM
   260  * @short_description: Operating on RPM files.
   261  *
   262  * Functions for open RPM files and extracting information and
   263  * installing or removing RPM files.
   264  **/
   265 
   266 struct razor_relocations;
   267 struct razor_rpm;
   268 
   269 struct razor_relocations *razor_relocations_create(void);
   270 void razor_relocations_add(struct razor_relocations *relocations,
   271 			   const char *oldpath, const char *newpath);
   272 void razor_relocations_set_rpm(struct razor_relocations *relocations,
   273 			       struct razor_rpm *rpm);
   274 const char *razor_relocations_apply(struct razor_relocations *relocations,
   275 				    const char *path);
   276 void razor_relocations_destroy(struct razor_relocations *relocations);
   277 
   278 struct razor_rpm *razor_rpm_open(const char *filename);
   279 void razor_rpm_set_relocations(struct razor_rpm *rpm,
   280 			       struct razor_relocations *relocations);
   281 int razor_rpm_install(struct razor_rpm *rpm, const char *root);
   282 int razor_rpm_close(struct razor_rpm *rpm);
   283 
   284 /**
   285  * SECTION:importer
   286  * @title: Importer
   287  * @short_description: A mechanism for building #razor_set objects
   288  *
   289  * The %razor_importer is a helper object for building a razor set
   290  * from external sources, like yum metadata, the RPM database or RPM
   291  * files.
   292  *
   293  * The importer is a stateful object; it has the notion of a current
   294  * package, and the caller can provide meta data such as properties,
   295  * files and similiar for the package as it becomes available.  Once a
   296  * package is fully described, the next pacakge can begin.  When all
   297  * packages have been described to the importer, the importer will
   298  * create a new %razor_set with the specified packages.
   299  *
   300  * A typical use
   301  * of the importer will follow this template:
   302  * |[
   303  * importer = razor_importer_create();
   304  *
   305  * while ( /<!-- -->* more packages to import *<!-- -->/; ) {
   306  *   /<!-- -->* get name, version and arch of next package *<!-- -->/
   307  *   razor_importer_begin_package(importer, name, version, arch);
   308  *   razor_importer_add_details(importer, summary, description, url, license);
   309  *
   310  *   while ( /<!-- -->* more properties to add *<!-- -->/ )
   311  *     razor_importer_add_property(importer, name, flags, version);
   312  *
   313  *   while ( /<!-- -->* [more files to add *<!-- -->/ )
   314  *     razor_importer_add_file(importer, name);
   315  *
   316  *   razor_importer_finish_package(importer);
   317  * }
   318  *
   319  * return razor_importer_finish(importer);
   320  * ]|
   321  **/
   322 struct razor_importer;
   323 
   324 struct razor_importer *razor_importer_create(void);
   325 void razor_importer_destroy(struct razor_importer *importer);
   326 void razor_importer_begin_package(struct razor_importer *importer,
   327 				  const char *name,
   328 				  const char *version,
   329 				  const char *arch);
   330 void razor_importer_add_details(struct razor_importer *importer,
   331 				const char *summary,
   332 				const char *description,
   333 				const char *url,
   334 				const char *license);
   335 void razor_importer_add_property(struct razor_importer *importer,
   336 				 const char *name,
   337 				 uint32_t flags,
   338 				 const char *version);
   339 void razor_importer_add_file(struct razor_importer *importer,
   340 			     const char *name);
   341 void razor_importer_finish_package(struct razor_importer *importer);
   342 
   343 int razor_importer_add_rpm(struct razor_importer *importer,
   344 			   struct razor_rpm *rpm);
   345 
   346 struct razor_set *razor_importer_finish(struct razor_importer *importer);
   347 
   348 struct razor_set *razor_set_create_from_yum(void);
   349 struct razor_set *razor_set_create_from_rpmdb(void);
   350 
   351 /**
   352  * SECTION:root
   353  * @title: Root
   354  * @short_description: Functions for accessing an install root.
   355  *
   356  * The #razor_root object encapsulate access to and locking of a razor
   357  * install root.
   358  **/
   359 struct razor_root;
   360 
   361 int razor_root_create(const char *root);
   362 struct razor_root *razor_root_open(const char *root);
   363 struct razor_set *razor_root_open_read_only(const char *root);
   364 struct razor_set *razor_root_get_system_set(struct razor_root *root);
   365 int razor_root_close(struct razor_root *root);
   366 void razor_root_update(struct razor_root *root, struct razor_set *next);
   367 int razor_root_commit(struct razor_root *root);
   368 
   369 
   370 /**
   371  * SECTION:misc
   372  * @title: Miscellaneous Functions
   373  * @short_description: Various helper functions
   374  *
   375  * Functions that doesn't fit anywhere else.
   376  **/
   377 
   378 const char *
   379 razor_property_relation_to_string(struct razor_property *p);
   380 const char *
   381 razor_property_type_to_string(struct razor_property *p);
   382 
   383 void razor_build_evr(char *evr_buf, int size, const char *epoch,
   384 		     const char *version, const char *release);
   385 int razor_versioncmp(const char *s1, const char *s2);
   386 
   387 void razor_disable_root_name_checks(int disable);
   388 
   389 void razor_set_lua_loader(const char *modname, void (*loader)());
   390 void (*razor_get_lua_loader(const char *modname))();
   391 
   392 
   393 #endif /* _RAZOR_H_ */