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