librazor/razor.h
author Richard Hughes <richard@hughsie.com>
Mon Jun 30 10:46:20 2008 +0100 (2008-06-30)
changeset 304 bf23ba00db03
parent 302 9b71b537d175
child 306 cd3954499086
permissions -rw-r--r--
the vararg list must be terminated with zero else 64bit machines may crash

On 64 bit systems, the integer 0 is 32 bits and the pointer 0 is 64 bits.
The upper 32 bits will not be cleared and the loop will never terminate.
Also add the RAZOR_SENTINEL __attribute__ ((__sentinel__(0))) on GCC4
so we catch where we get this wrong automatically.

This also fixes the new search functionality from James which was missed
in the merge.
     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, const char *name);
   185 
   186 enum razor_diff_action {
   187 	RAZOR_DIFF_ACTION_ADD,
   188 	RAZOR_DIFF_ACTION_REMOVE,
   189 };
   190 
   191 typedef void (*razor_diff_callback_t)(enum razor_diff_action action,
   192 				      struct razor_package *package,
   193 				      const char *name,
   194 				      const char *version,
   195 				      const char *arch,
   196 				      void *data);
   197 
   198 void
   199 razor_set_diff(struct razor_set *set, struct razor_set *upstream,
   200 	       razor_diff_callback_t callback, void *data);
   201 struct razor_package_iterator *
   202 razor_set_create_remove_iterator(struct razor_set *set,
   203 				 struct razor_set *next);
   204 struct razor_package_iterator *
   205 razor_set_create_install_iterator(struct razor_set *set,
   206 				  struct razor_set *next);
   207 
   208 /**
   209  * SECTION:transaction
   210  * @title: Transaction
   211  * @short_description: Create a new package set by merging two or more sets.
   212  *
   213  * The razor transaction object provides a way to create a new package set
   214  * from packages from one or more other package sets.
   215  **/
   216 
   217 struct razor_transaction *
   218 razor_transaction_create(struct razor_set *system, struct razor_set *upstream);
   219 void razor_transaction_install_package(struct razor_transaction *transaction,
   220 				       struct razor_package *package);
   221 void razor_transaction_remove_package(struct razor_transaction *transaction,
   222 				      struct razor_package *package);
   223 void razor_transaction_update_package(struct razor_transaction *trans,
   224 				      struct razor_package *package);
   225 void razor_transaction_update_all(struct razor_transaction *transaction);
   226 int razor_transaction_resolve(struct razor_transaction *trans);
   227 int razor_transaction_describe(struct razor_transaction *trans);
   228 struct razor_set *razor_transaction_finish(struct razor_transaction *trans);
   229 void razor_transaction_destroy(struct razor_transaction *trans);
   230 
   231 /* Temporary helper for test suite. */
   232 int razor_transaction_unsatisfied_property(struct razor_transaction *trans,
   233 					   const char *name,
   234 					   uint32_t flags,
   235 					   const char *version);
   236 
   237 /**
   238  * SECTION:rpm
   239  * @title: Razor RPM
   240  * @short_description: Operating on RPM files.
   241  *
   242  * Functions for open RPM files and extracting information and
   243  * installing or removing RPM files.
   244  **/
   245 
   246 struct razor_rpm;
   247 
   248 struct razor_rpm *razor_rpm_open(const char *filename);
   249 int razor_rpm_install(struct razor_rpm *rpm, const char *root);
   250 int razor_rpm_close(struct razor_rpm *rpm);
   251 
   252 /**
   253  * SECTION:importer
   254  * @title: Importer
   255  * @short_description: A mechanism for building #razor_set objects
   256  *
   257  * For building a razor set from external sources, like yum, rpmdb or
   258  * RPM files.
   259  **/
   260 struct razor_importer;
   261 
   262 struct razor_importer *razor_importer_create(void);
   263 void razor_importer_destroy(struct razor_importer *importer);
   264 void razor_importer_begin_package(struct razor_importer *importer,
   265 				  const char *name,
   266 				  const char *version,
   267 				  const char *arch);
   268 void razor_importer_add_details(struct razor_importer *importer,
   269 				const char *summary,
   270 				const char *description,
   271 				const char *url,
   272 				const char *license);
   273 void razor_importer_add_property(struct razor_importer *importer,
   274 				 const char *name,
   275 				 uint32_t flags,
   276 				 const char *version);
   277 void razor_importer_add_file(struct razor_importer *importer,
   278 			     const char *name);
   279 void razor_importer_finish_package(struct razor_importer *importer);
   280 
   281 int razor_importer_add_rpm(struct razor_importer *importer,
   282 			   struct razor_rpm *rpm);
   283 
   284 struct razor_set *razor_importer_finish(struct razor_importer *importer);
   285 
   286 struct razor_set *razor_set_create_from_yum(void);
   287 struct razor_set *razor_set_create_from_rpmdb(void);
   288 
   289 /**
   290  * SECTION:root
   291  * @title: Root
   292  * @short_description: Functions for accessing an install root.
   293  *
   294  * The #razor_root object encapsulate access to and locking of a razor
   295  * install root.
   296  **/
   297 struct razor_root;
   298 
   299 int razor_root_create(const char *root);
   300 struct razor_root *razor_root_open(const char *root);
   301 struct razor_set *razor_root_open_read_only(const char *root);
   302 struct razor_set *razor_root_get_system_set(struct razor_root *root);
   303 int razor_root_close(struct razor_root *root);
   304 void razor_root_update(struct razor_root *root, struct razor_set *next);
   305 int razor_root_commit(struct razor_root *root);
   306 
   307 
   308 /**
   309  * SECTION:misc
   310  * @title: Miscellaneous Functions
   311  * @short_description: Various helper functions
   312  *
   313  * Functions that doesn't fit anywhere else.
   314  **/
   315 
   316 const char *
   317 razor_property_relation_to_string(struct razor_property *p);
   318 const char *
   319 razor_property_type_to_string(struct razor_property *p);
   320 
   321 void razor_build_evr(char *evr_buf, int size, const char *epoch,
   322 		     const char *version, const char *release);
   323 int razor_versioncmp(const char *s1, const char *s2);
   324 
   325 
   326 #endif /* _RAZOR_H_ */