librazor/razor.h
author Richard Hughes <richard@hughsie.com>
Tue Jul 01 09:22:25 2008 +0100 (2008-07-01)
changeset 307 95b6bcadd6c4
parent 306 cd3954499086
child 309 a69289c9080c
permissions -rw-r--r--
convert the NULL sentinel to RAZOR_DETAIL_LAST
     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  * For building a razor set from external sources, like yum, rpmdb or
   251  * RPM files.
   252  **/
   253 struct razor_importer;
   254 
   255 struct razor_importer *razor_importer_create(void);
   256 void razor_importer_destroy(struct razor_importer *importer);
   257 void razor_importer_begin_package(struct razor_importer *importer,
   258 				  const char *name,
   259 				  const char *version,
   260 				  const char *arch);
   261 void razor_importer_add_details(struct razor_importer *importer,
   262 				const char *summary,
   263 				const char *description,
   264 				const char *url,
   265 				const char *license);
   266 void razor_importer_add_property(struct razor_importer *importer,
   267 				 const char *name,
   268 				 uint32_t flags,
   269 				 const char *version);
   270 void razor_importer_add_file(struct razor_importer *importer,
   271 			     const char *name);
   272 void razor_importer_finish_package(struct razor_importer *importer);
   273 
   274 int razor_importer_add_rpm(struct razor_importer *importer,
   275 			   struct razor_rpm *rpm);
   276 
   277 struct razor_set *razor_importer_finish(struct razor_importer *importer);
   278 
   279 struct razor_set *razor_set_create_from_yum(void);
   280 struct razor_set *razor_set_create_from_rpmdb(void);
   281 
   282 /**
   283  * SECTION:root
   284  * @title: Root
   285  * @short_description: Functions for accessing an install root.
   286  *
   287  * The #razor_root object encapsulate access to and locking of a razor
   288  * install root.
   289  **/
   290 struct razor_root;
   291 
   292 int razor_root_create(const char *root);
   293 struct razor_root *razor_root_open(const char *root);
   294 struct razor_set *razor_root_open_read_only(const char *root);
   295 struct razor_set *razor_root_get_system_set(struct razor_root *root);
   296 int razor_root_close(struct razor_root *root);
   297 void razor_root_update(struct razor_root *root, struct razor_set *next);
   298 int razor_root_commit(struct razor_root *root);
   299 
   300 
   301 /**
   302  * SECTION:misc
   303  * @title: Miscellaneous Functions
   304  * @short_description: Various helper functions
   305  *
   306  * Functions that doesn't fit anywhere else.
   307  **/
   308 
   309 const char *
   310 razor_property_relation_to_string(struct razor_property *p);
   311 const char *
   312 razor_property_type_to_string(struct razor_property *p);
   313 
   314 void razor_build_evr(char *evr_buf, int size, const char *epoch,
   315 		     const char *version, const char *release);
   316 int razor_versioncmp(const char *s1, const char *s2);
   317 
   318 
   319 #endif /* _RAZOR_H_ */