librazor/razor.h
author Kristian H?gsberg <krh@redhat.com>
Mon Jun 30 13:28:59 2008 -0400 (2008-06-30)
changeset 306 cd3954499086
parent 304 bf23ba00db03
child 307 95b6bcadd6c4
permissions -rw-r--r--
Get rid of razor_set_get_package().

This was always a silly little helper function, not general enough for
real world applications. Use an iterator to search through the set to
find the package of interest.
     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 /* GCC sentinel */
    26 #if defined(__GNUC__) && __GNUC__ >= 4
    27 #define RAZOR_SENTINEL __attribute__ ((__sentinel__(0)));
    28 #else
    29 #define RAZOR_SENTINEL
    30 #endif
    31 
    32 enum razor_repo_file_type {
    33 	RAZOR_REPO_FILE_MAIN,
    34 	RAZOR_REPO_FILE_DETAILS,
    35 	RAZOR_REPO_FILE_FILES
    36 };
    37 
    38 enum razor_detail_type {
    39 	RAZOR_DETAIL_NAME = 1, /* NULL (0 on 32 bit) is the sentinel */
    40 	RAZOR_DETAIL_VERSION,
    41 	RAZOR_DETAIL_ARCH,
    42 	RAZOR_DETAIL_SUMMARY,
    43 	RAZOR_DETAIL_DESCRIPTION,
    44 	RAZOR_DETAIL_URL,
    45 	RAZOR_DETAIL_LICENSE
    46 };
    47 
    48 enum razor_property_flags {
    49 	RAZOR_PROPERTY_LESS		= 1 << 0,
    50 	RAZOR_PROPERTY_GREATER		= 1 << 1,
    51 	RAZOR_PROPERTY_EQUAL		= 1 << 2,
    52 	RAZOR_PROPERTY_RELATION_MASK	=
    53 		RAZOR_PROPERTY_LESS |
    54 		RAZOR_PROPERTY_GREATER |
    55 		RAZOR_PROPERTY_EQUAL,
    56 
    57 	RAZOR_PROPERTY_REQUIRES		= 0 << 3,
    58 	RAZOR_PROPERTY_PROVIDES		= 1 << 3,
    59 	RAZOR_PROPERTY_CONFLICTS	= 2 << 3,
    60 	RAZOR_PROPERTY_OBSOLETES	= 3 << 3,
    61 	RAZOR_PROPERTY_TYPE_MASK	= 3 << 3,
    62 		
    63 	RAZOR_PROPERTY_PRE		= 1 << 5,
    64 	RAZOR_PROPERTY_POST		= 1 << 6,
    65 	RAZOR_PROPERTY_PREUN		= 1 << 7,
    66 	RAZOR_PROPERTY_POSTUN		= 1 << 8
    67 };
    68 
    69 /**
    70  * SECTION:set
    71  * @title: Package Set
    72  * @short_description: Represents a set of packages and their metadata.
    73  *
    74  * This object represents a set of packages, their dependency
    75  * information, the file lists and a number of other details.
    76  **/
    77 
    78 struct razor_set;
    79 struct razor_package;
    80 struct razor_property;
    81 
    82 /**
    83  * razor_set_create:
    84  * 
    85  * Create a new #razor_set object.
    86  * 
    87  * Returns: the new #razor_set object.
    88  **/
    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 			  RAZOR_SENTINEL;
   107 
   108 
   109 /**
   110  * SECTION:iterator
   111  * @title: Iterators
   112  * @short_description: Objects for traversing packages or properties.
   113  *
   114  * The razor iterator objects provides a way to iterate through a set
   115  * of packages or properties.
   116  **/
   117 
   118 struct razor_package_iterator;
   119 
   120 /**
   121  * razor_package_iterator_create:
   122  * 
   123  * Create a new #razor_package_iterator object.
   124  * 
   125  * Returns: the new #razor_package_iterator object.
   126  **/
   127 
   128 struct razor_package_iterator *
   129 razor_package_iterator_create(struct razor_set *set);
   130 
   131 /**
   132  * razor_package_iterator_create_for_property:
   133  * 
   134  * Create a new #razor_package_iterator object for the packages that
   135  * own the given property.
   136  * 
   137  * Returns: the new #razor_package_iterator object.
   138  **/
   139 struct razor_package_iterator *
   140 razor_package_iterator_create_for_property(struct razor_set *set,
   141 					   struct razor_property *property);
   142 
   143 /**
   144  * razor_package_iterator_create_for_file:
   145  *
   146  * Create a new #razor_package_iterator object for the packages that
   147  * contain the given file name.
   148  *
   149  * Returns: the new #razor_package_iterator object.
   150  **/
   151 struct razor_package_iterator *
   152 razor_package_iterator_create_for_file(struct razor_set *set,
   153 				       const char *filename);
   154 
   155 int razor_package_iterator_next(struct razor_package_iterator *pi,
   156 				struct razor_package **package, ...)
   157 				RAZOR_SENTINEL;
   158 void razor_package_iterator_destroy(struct razor_package_iterator *pi);
   159 
   160 struct razor_package_query *
   161 razor_package_query_create(struct razor_set *set);
   162 void
   163 razor_package_query_add_package(struct razor_package_query *pq,
   164 				struct razor_package *p);
   165 void
   166 razor_package_query_add_iterator(struct razor_package_query *pq,
   167 				 struct razor_package_iterator *pi);
   168 struct razor_package_iterator *
   169 razor_package_query_finish(struct razor_package_query *pq);
   170 
   171 struct razor_property_iterator;
   172 struct razor_property_iterator *
   173 razor_property_iterator_create(struct razor_set *set,
   174 			       struct razor_package *package);
   175 int razor_property_iterator_next(struct razor_property_iterator *pi,
   176 				 struct razor_property **property,
   177 				 const char **name,
   178 				 uint32_t *flags,
   179 				 const char **version);
   180 void
   181 razor_property_iterator_destroy(struct razor_property_iterator *pi);
   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 struct razor_package_iterator *
   203 razor_set_create_remove_iterator(struct razor_set *set,
   204 				 struct razor_set *next);
   205 struct razor_package_iterator *
   206 razor_set_create_install_iterator(struct razor_set *set,
   207 				  struct razor_set *next);
   208 
   209 /**
   210  * SECTION:transaction
   211  * @title: Transaction
   212  * @short_description: Create a new package set by merging two or more sets.
   213  *
   214  * The razor transaction object provides a way to create a new package set
   215  * from packages from one or more other package sets.
   216  **/
   217 
   218 struct razor_transaction *
   219 razor_transaction_create(struct razor_set *system, struct razor_set *upstream);
   220 void razor_transaction_install_package(struct razor_transaction *transaction,
   221 				       struct razor_package *package);
   222 void razor_transaction_remove_package(struct razor_transaction *transaction,
   223 				      struct razor_package *package);
   224 void razor_transaction_update_package(struct razor_transaction *trans,
   225 				      struct razor_package *package);
   226 void razor_transaction_update_all(struct razor_transaction *transaction);
   227 int razor_transaction_resolve(struct razor_transaction *trans);
   228 int razor_transaction_describe(struct razor_transaction *trans);
   229 struct razor_set *razor_transaction_finish(struct razor_transaction *trans);
   230 void razor_transaction_destroy(struct razor_transaction *trans);
   231 
   232 /* Temporary helper for test suite. */
   233 int razor_transaction_unsatisfied_property(struct razor_transaction *trans,
   234 					   const char *name,
   235 					   uint32_t flags,
   236 					   const char *version);
   237 
   238 /**
   239  * SECTION:rpm
   240  * @title: Razor RPM
   241  * @short_description: Operating on RPM files.
   242  *
   243  * Functions for open RPM files and extracting information and
   244  * installing or removing RPM files.
   245  **/
   246 
   247 struct razor_rpm;
   248 
   249 struct razor_rpm *razor_rpm_open(const char *filename);
   250 int razor_rpm_install(struct razor_rpm *rpm, const char *root);
   251 int razor_rpm_close(struct razor_rpm *rpm);
   252 
   253 /**
   254  * SECTION:importer
   255  * @title: Importer
   256  * @short_description: A mechanism for building #razor_set objects
   257  *
   258  * For building a razor set from external sources, like yum, rpmdb or
   259  * RPM files.
   260  **/
   261 struct razor_importer;
   262 
   263 struct razor_importer *razor_importer_create(void);
   264 void razor_importer_destroy(struct razor_importer *importer);
   265 void razor_importer_begin_package(struct razor_importer *importer,
   266 				  const char *name,
   267 				  const char *version,
   268 				  const char *arch);
   269 void razor_importer_add_details(struct razor_importer *importer,
   270 				const char *summary,
   271 				const char *description,
   272 				const char *url,
   273 				const char *license);
   274 void razor_importer_add_property(struct razor_importer *importer,
   275 				 const char *name,
   276 				 uint32_t flags,
   277 				 const char *version);
   278 void razor_importer_add_file(struct razor_importer *importer,
   279 			     const char *name);
   280 void razor_importer_finish_package(struct razor_importer *importer);
   281 
   282 int razor_importer_add_rpm(struct razor_importer *importer,
   283 			   struct razor_rpm *rpm);
   284 
   285 struct razor_set *razor_importer_finish(struct razor_importer *importer);
   286 
   287 struct razor_set *razor_set_create_from_yum(void);
   288 struct razor_set *razor_set_create_from_rpmdb(void);
   289 
   290 /**
   291  * SECTION:root
   292  * @title: Root
   293  * @short_description: Functions for accessing an install root.
   294  *
   295  * The #razor_root object encapsulate access to and locking of a razor
   296  * install root.
   297  **/
   298 struct razor_root;
   299 
   300 int razor_root_create(const char *root);
   301 struct razor_root *razor_root_open(const char *root);
   302 struct razor_set *razor_root_open_read_only(const char *root);
   303 struct razor_set *razor_root_get_system_set(struct razor_root *root);
   304 int razor_root_close(struct razor_root *root);
   305 void razor_root_update(struct razor_root *root, struct razor_set *next);
   306 int razor_root_commit(struct razor_root *root);
   307 
   308 
   309 /**
   310  * SECTION:misc
   311  * @title: Miscellaneous Functions
   312  * @short_description: Various helper functions
   313  *
   314  * Functions that doesn't fit anywhere else.
   315  **/
   316 
   317 const char *
   318 razor_property_relation_to_string(struct razor_property *p);
   319 const char *
   320 razor_property_type_to_string(struct razor_property *p);
   321 
   322 void razor_build_evr(char *evr_buf, int size, const char *epoch,
   323 		     const char *version, const char *release);
   324 int razor_versioncmp(const char *s1, const char *s2);
   325 
   326 
   327 #endif /* _RAZOR_H_ */