Only export symbols starting with razor_ in dynamic library.
Apart from being good practice to avoid clashes with higher-level
libraries and the application, this also fixes an obscure bug: The
gnulib library is used both by librazor (the dynamic library) and
by razor (the executable). In doing so, we want to have two separate
copies of the library despite the code duplication this involves.
Without the explicit limit to export only razor_ symbols, the razor
executable under mingw64 was picking up the getopt_long function
from librazor and the optind variable from libgnu which meant that
it did not see optind changing. Hiding librazor's copy of getopt
causes the linker to find libgnu's copy and everything works.
Note that under mingw librazor-#.dll still contains undocumented
(private) razor_ symbols but these will do no harm as long as nobody
tries to use them.
2 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
3 * Copyright (C) 2008 Red Hat, Inc
4 * Copyright (C) 2009, 2011, 2012, 2014 J. Ali Harlow <ali@juiblex.co.uk>
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.
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.
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.
25 #include <sys/types.h>
29 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
30 #define RAZOR_MALLOC __attribute__((__malloc__))
35 #define RAZOR_NULL_TERMINATED __attribute__ ((__sentinel__))
37 #define RAZOR_NULL_TERMINATED
41 enum razor_section_type {
42 RAZOR_SECTION_MAIN = 0x01,
43 RAZOR_SECTION_DETAILS = 0x02,
44 RAZOR_SECTION_FILES = 0x04,
45 RAZOR_SECTION_ALL = 0x07
48 enum razor_stage_type {
49 RAZOR_STAGE_SCRIPTS_PRE = 0x1,
50 RAZOR_STAGE_FILES = 0x2,
51 RAZOR_STAGE_SCRIPTS_POST = 0x4,
52 RAZOR_STAGE_SCRIPTS = 0x5,
56 enum razor_detail_type {
57 RAZOR_DETAIL_LAST = 0, /* the sentinel */
62 RAZOR_DETAIL_DESCRIPTION,
65 RAZOR_DETAIL_PREUNPROG,
67 RAZOR_DETAIL_POSTUNPROG,
72 enum razor_property_flags {
73 RAZOR_PROPERTY_LESS = 1 << 0,
74 RAZOR_PROPERTY_GREATER = 1 << 1,
75 RAZOR_PROPERTY_EQUAL = 1 << 2,
76 RAZOR_PROPERTY_RELATION_MASK =
78 RAZOR_PROPERTY_GREATER |
81 RAZOR_PROPERTY_REQUIRES = 0 << 3,
82 RAZOR_PROPERTY_PROVIDES = 1 << 3,
83 RAZOR_PROPERTY_CONFLICTS = 2 << 3,
84 RAZOR_PROPERTY_OBSOLETES = 3 << 3,
85 RAZOR_PROPERTY_TYPE_MASK = 3 << 3,
87 RAZOR_PROPERTY_PRE = 1 << 5,
88 RAZOR_PROPERTY_POST = 1 << 6,
89 RAZOR_PROPERTY_PREUN = 1 << 7,
90 RAZOR_PROPERTY_POSTUN = 1 << 8,
91 RAZOR_PROPERTY_SCRIPT_MASK =
94 RAZOR_PROPERTY_PREUN |
98 enum razor_set_flags {
100 * Create a private copy of the razor set such that changes made
101 * to the underlying file are not visible in the razor set.
102 * If this flag is not set then the caller must ensure that the
103 * underlying file (if any) is not changed.
105 RAZOR_SET_PRIVATE = 1 << 0,
110 * @title: Error reporting
111 * @short_description: A system for reporting errors.
113 * This object represents an error condition.
117 struct razor_error *razor_error_new_str(int domain, int code,
118 const char *object, const char *str);
119 struct razor_error *razor_error_dup(struct razor_error *src,
120 const char *summary);
122 #define razor_set_error(error, domain, code, object, str) \
124 *(error) = razor_error_new_str(domain, code, object, str); \
127 #define razor_propagate_error(dest, src, summary) \
129 *(dest) = razor_error_dup(src, summary); \
132 #define RAZOR_ERROR_DOMAIN(i1,i2,i3,c) \
133 (((i1)&0xff)<<24|((i2)&0xff)<<16|((i3)&0xff)<<8|(c)&0xff)
135 #define RAZOR_GENERAL_ERROR RAZOR_ERROR_DOMAIN('R','z','r',0)
136 #define RAZOR_POSIX_ERROR RAZOR_ERROR_DOMAIN('R','z','r',1)
137 #define RAZOR_MSWIN_ERROR RAZOR_ERROR_DOMAIN('R','z','r',2)
138 #define RAZOR_ZLIB_ERROR RAZOR_ERROR_DOMAIN('R','z','r',3)
140 enum razor_general_error {
141 RAZOR_GENERAL_ERROR_FAILED,
142 RAZOR_GENERAL_ERROR_DATABASE_CORRUPTED,
143 RAZOR_GENERAL_ERROR_DATABASE_INCOMPATIBLE,
144 RAZOR_GENERAL_ERROR_DATABASE_EXISTS,
145 RAZOR_GENERAL_ERROR_DATABASE_LOCKED,
146 RAZOR_GENERAL_ERROR_RPM_UNSUPPORTED,
149 int razor_error_get_domain(struct razor_error *error);
150 int razor_error_get_code(struct razor_error *error);
151 const char *razor_error_get_object(struct razor_error *error);
152 const char *razor_error_get_primary_text(struct razor_error *error);
153 const char *razor_error_get_secondary_text(struct razor_error *error);
154 const char *razor_error_get_msg(struct razor_error *error);
155 void razor_error_free(struct razor_error *error);
159 * @title: Atomic transactions
160 * @short_description: File-based transactions that shouldn't half-succeed
162 * This is a helper object for issuing a sequence of file-based actions
163 * that should either all succeed or all fail.
165 * Note that currently only Windows 7 has a native implementation and that
166 * while the emulated fallback implementation attempts to rollback the
167 * transaction if it fails, this is not guaranteed to succeed and that
168 * the transaction is held in core (and thus vulnernable to program crashes,
169 * power loss, etc.). This could (and should) be improved.
171 * Atomic transactions can be disabled via configure, in which case all
175 @RAZOR_HAVE_ATOMIC_ROLLBACK@
179 struct razor_atomic *razor_atomic_open(const char *description);
180 int razor_atomic_commit(struct razor_atomic *atomic);
181 struct razor_error *razor_atomic_get_error(struct razor_atomic *atomic);
182 const char *razor_atomic_get_error_msg(struct razor_atomic *atomic);
183 void razor_atomic_destroy(struct razor_atomic *atomic);
186 * razor_atomic_make_dirs
188 * Create all sub-directories leading up to path. We know root exists
189 * and is a dir, root does not end in a '/', and path either has a
190 * leading '/' or (on MS-Windows only) root is the empty string
191 * and path starts with drive (eg., "c:/windows").
192 * Note: path itself is not created, only the directory in which it
195 * Returns: non-zero on error.
197 int razor_atomic_make_dirs(struct razor_atomic *atomic, const char *root,
199 int razor_atomic_remove(struct razor_atomic *atomic, const char *path);
200 int razor_atomic_rename_file(struct razor_atomic *atomic, const char *oldpath,
201 const char *newpath);
204 * razor_atomic_create_dir
206 * Create a directory, replacing any existing object at this path except
207 * an existing directory (which is not counted as a error).
209 * Returns: non-zero on error.
211 int razor_atomic_create_dir(struct razor_atomic *atomic, const char *dirname,
215 * razor_atomic_create_symlink
217 * Create a symbolic link, replacing any existing object at this path except
218 * a non-empty directory.
220 * Note: This function will always fail on platforms that don't support
223 * Returns: non-zero on error.
225 int razor_atomic_create_symlink(struct razor_atomic *atomic, const char *target,
228 * razor_atomic_create_file
230 * Create a file, replacing any existing object at this path except
231 * a non-empty directory.
233 * Returns: A handle to be passed to razor_atomic_write() and
234 * razor_atomic_close() or a negative value on error.
236 int razor_atomic_create_file(struct razor_atomic *atomic, const char *filename,
238 int razor_atomic_write(struct razor_atomic *atomic, int handle,
239 const void *data, size_t size);
240 int razor_atomic_close(struct razor_atomic *atomic, int handle);
241 int razor_atomic_sync(struct razor_atomic *atomic, int handle);
242 void razor_atomic_abort(struct razor_atomic *atomic, int domain, int code,
243 const char *error_msg);
244 void razor_atomic_propagate_error(struct razor_atomic *atomic,
245 struct razor_error *error, const char *summary);
246 int razor_atomic_in_error_state(struct razor_atomic *atomic);
250 * @title: Package Set
251 * @short_description: Represents a set of packages and their metadata.
253 * This object represents a set of packages, their dependency
254 * information, the file lists and a number of other details.
258 struct razor_package;
259 struct razor_property;
261 #define RAZOR_HEADER_VERSION 2 /* Current version */
262 #define RAZOR_HEADER_VERSION_MIN 1 /* Minimum version we support */
267 * Create a new #razor_set object.
269 * Returns: the new #razor_set object.
271 struct razor_set *razor_set_create_without_root(void);
272 struct razor_set *razor_set_create(void);
274 razor_set_open(const char *filename, enum razor_set_flags flags,
275 struct razor_error **error);
276 uint32_t razor_set_get_header_version(struct razor_set *set);
277 int razor_set_set_header_version(struct razor_set *set,
278 uint32_t header_version);
279 void razor_set_unref(struct razor_set *set);
280 struct razor_set *razor_set_ref(struct razor_set *set);
281 void razor_set_write_to_handle(struct razor_set *set,
282 struct razor_atomic *atomic, int handle,
283 uint32_t section_mask);
284 int razor_set_write(struct razor_set *set, struct razor_atomic *atomic,
285 const char *filename, uint32_t setions);
287 razor_set_bind_sections(struct razor_set *set, const char *filename,
288 enum razor_set_flags flags, struct razor_error **error);
291 razor_package_get_details(struct razor_set *set,
292 struct razor_package *package, ...);
294 razor_package_remove(struct razor_set *prev, struct razor_set *next,
295 struct razor_atomic *atomic, struct razor_package *package,
296 const char *root, int install_count,
297 enum razor_stage_type stage);
302 * @short_description: Objects for traversing packages or properties.
304 * The razor iterator objects provides a way to iterate through a set
305 * of packages or properties.
308 struct razor_package_iterator;
311 * razor_package_iterator_create:
313 * Create a new #razor_package_iterator object.
315 * Returns: the new #razor_package_iterator object.
318 struct razor_package_iterator *
319 razor_package_iterator_create(struct razor_set *set);
322 * razor_package_iterator_create_for_property:
324 * Create a new #razor_package_iterator object for the packages that
325 * own the given property.
327 * Returns: the new #razor_package_iterator object.
329 struct razor_package_iterator *
330 razor_package_iterator_create_for_property(struct razor_set *set,
331 struct razor_property *property);
334 * razor_package_iterator_create_for_file:
336 * Create a new #razor_package_iterator object for the packages that
337 * contain the given file name.
339 * Returns: the new #razor_package_iterator object.
341 struct razor_package_iterator *
342 razor_package_iterator_create_for_file(struct razor_set *set,
343 const char *filename);
345 int razor_package_iterator_next(struct razor_package_iterator *pi,
346 struct razor_package **package, ...);
347 void razor_package_iterator_destroy(struct razor_package_iterator *pi);
349 struct razor_package_query *
350 razor_package_query_create(struct razor_set *set);
352 razor_package_query_add_package(struct razor_package_query *pq,
353 struct razor_package *p);
355 razor_package_query_add_iterator(struct razor_package_query *pq,
356 struct razor_package_iterator *pi);
357 struct razor_package_iterator *
358 razor_package_query_finish(struct razor_package_query *pq);
360 struct razor_property_iterator;
361 struct razor_property_iterator *
362 razor_property_iterator_create(struct razor_set *set,
363 struct razor_package *package);
364 int razor_property_iterator_next(struct razor_property_iterator *pi,
365 struct razor_property **property,
368 const char **version);
370 razor_property_iterator_destroy(struct razor_property_iterator *pi);
372 struct razor_file_iterator;
373 struct razor_file_iterator *
374 razor_file_iterator_create(struct razor_set *set,
375 struct razor_package *package, int post_order);
376 int razor_file_iterator_next(struct razor_file_iterator *fi,
378 void razor_file_iterator_destroy(struct razor_file_iterator *fi);
380 void razor_set_list_files(struct razor_set *set, const char *prefix);
381 void razor_set_list_package_files(struct razor_set *set,
382 struct razor_package *package);
384 enum razor_diff_action {
385 RAZOR_DIFF_ACTION_ADD,
386 RAZOR_DIFF_ACTION_REMOVE,
389 typedef void (*razor_diff_callback_t)(enum razor_diff_action action,
390 struct razor_package *package,
397 razor_set_diff(struct razor_set *set, struct razor_set *upstream,
398 razor_diff_callback_t callback, void *data);
400 struct razor_install_iterator;
402 enum razor_install_action {
403 RAZOR_INSTALL_ACTION_ADD,
404 RAZOR_INSTALL_ACTION_REMOVE,
405 RAZOR_INSTALL_ACTION_COMMIT
408 struct razor_install_iterator *
409 razor_set_create_install_iterator(struct razor_set *set,
410 struct razor_set *next);
412 int razor_install_iterator_next(struct razor_install_iterator *ii,
413 struct razor_package **package,
414 enum razor_install_action *action,
418 * razor_install_iterator_commit_set
420 * Immediately after razor_install_iterator_next() returns
421 * RAZOR_INSTALL_ACTION_COMMIT, this function will return the razor_set
422 * which should be committed.
424 * Returns: a new #razor_set object.
427 razor_install_iterator_commit_set(struct razor_install_iterator *ii);
429 void razor_install_iterator_rewind(struct razor_install_iterator *ii);
430 size_t razor_install_iterator_tell(struct razor_install_iterator *ii);
431 size_t razor_install_iterator_seek(struct razor_install_iterator *ii,
433 void razor_install_iterator_destroy(struct razor_install_iterator *ii);
436 * SECTION:transaction
437 * @title: Transaction
438 * @short_description: Create a new package set by merging two or more sets.
440 * The razor transaction object provides a way to create a new package set
441 * from packages from one or more other package sets.
446 struct razor_transaction *
447 razor_transaction_create(struct razor_set *system, struct razor_set *upstream);
448 void razor_transaction_install_package(struct razor_transaction *transaction,
449 struct razor_package *package);
450 void razor_transaction_remove_package(struct razor_transaction *transaction,
451 struct razor_package *package);
452 void razor_transaction_update_package(struct razor_transaction *trans,
453 struct razor_package *package);
454 void razor_transaction_fixup_package(struct razor_transaction *trans,
455 struct razor_package *package,
456 struct razor_rpm *rpm);
457 void razor_transaction_update_all(struct razor_transaction *transaction);
458 int razor_transaction_resolve(struct razor_transaction *trans);
460 typedef void (*razor_unsatisfied_callback_t)(const char *requirement,
461 struct razor_package *package,
467 int razor_transaction_unsatisfied(struct razor_transaction *trans,
468 razor_unsatisfied_callback_t callback,
470 int razor_transaction_describe(struct razor_transaction *trans);
471 struct razor_set *razor_transaction_commit(struct razor_transaction *trans);
472 void razor_transaction_destroy(struct razor_transaction *trans);
474 /* Temporary helper for test suite. */
475 int razor_transaction_unsatisfied_property(struct razor_transaction *trans,
478 const char *version);
483 * @short_description: Operating on RPM files.
485 * Functions for open RPM files and extracting information and
486 * installing or removing RPM files.
489 struct razor_relocations;
491 struct razor_relocations *razor_relocations_create(void);
492 void razor_relocations_add(struct razor_relocations *relocations,
493 const char *oldpath, const char *newpath);
494 void razor_relocations_set_rpm(struct razor_relocations *relocations,
495 struct razor_rpm *rpm);
496 const char *razor_relocations_apply(struct razor_relocations *relocations,
498 void razor_relocations_destroy(struct razor_relocations *relocations);
500 struct razor_rpm *razor_rpm_open(const char *filename,
501 struct razor_error **error);
502 void razor_rpm_get_details(struct razor_rpm *rpm, ...);
503 void razor_rpm_set_relocations(struct razor_rpm *rpm,
504 struct razor_relocations *relocations);
505 int razor_rpm_install(struct razor_rpm *rpm, struct razor_atomic *atomic,
506 const char *root, int install_count,
507 enum razor_stage_type stage);
508 int razor_rpm_close(struct razor_rpm *rpm);
513 * @short_description: A mechanism for building #razor_set objects
515 * The %razor_importer is a helper object for building a razor set
516 * from external sources, like yum metadata, the RPM database or RPM
519 * The importer is a stateful object; it has the notion of a current
520 * package, and the caller can provide meta data such as properties,
521 * files and similiar for the package as it becomes available. Once a
522 * package is fully described, the next pacakge can begin. When all
523 * packages have been described to the importer, the importer will
524 * create a new %razor_set with the specified packages.
527 * of the importer will follow this template:
529 * importer = razor_importer_create();
531 * while ( /<!-- -->* more packages to import *<!-- -->/; ) {
532 * /<!-- -->* get name, version and arch of next package *<!-- -->/
533 * razor_importer_begin_package(importer, name, version, arch);
534 * razor_importer_add_details(importer, summary, description, url, license);
536 * while ( /<!-- -->* more properties to add *<!-- -->/ )
537 * razor_importer_add_property(importer, name, flags, version);
539 * while ( /<!-- -->* [more files to add *<!-- -->/ )
540 * razor_importer_add_file(importer, name);
542 * razor_importer_finish_package(importer);
545 * return razor_importer_finish(importer);
548 struct razor_importer;
550 struct razor_importer *razor_importer_create(void);
551 void razor_importer_destroy(struct razor_importer *importer);
552 void razor_importer_begin_package(struct razor_importer *importer,
556 void razor_importer_add_details(struct razor_importer *importer,
558 const char *description,
560 const char *license);
561 void razor_importer_add_script(struct razor_importer *importer,
562 enum razor_property_flags script,
565 void razor_importer_add_install_prefix(struct razor_importer *importer,
566 const char *install_prefix);
567 void razor_importer_add_property(struct razor_importer *importer,
570 const char *version);
571 void razor_importer_add_file(struct razor_importer *importer,
573 void razor_importer_finish_package(struct razor_importer *importer);
575 int razor_importer_add_rpm(struct razor_importer *importer,
576 struct razor_rpm *rpm);
578 struct razor_set *razor_importer_finish(struct razor_importer *importer);
580 struct razor_set *razor_set_create_from_yum(void);
581 struct razor_set *razor_set_create_from_rpmdb(void);
586 * @short_description: Functions for accessing an install root.
588 * The #razor_root object encapsulate access to and locking of a razor
593 const char *razor_get_database_path();
594 void razor_set_database_path(const char *database_path);
595 int razor_root_create(const char *root, struct razor_error **error);
597 razor_root_open(const char *root, struct razor_error **error);
599 razor_root_open_read_only(const char *root, struct razor_error **error);
600 struct razor_set *razor_root_get_system_set(struct razor_root *root);
601 int razor_root_close(struct razor_root *root);
603 razor_root_update(struct razor_root *root, struct razor_set *next,
604 struct razor_atomic *atomic);
608 * @title: Miscellaneous Functions
609 * @short_description: Various helper functions
611 * Functions that doesn't fit anywhere else.
615 razor_property_relation_to_string(struct razor_property *p);
617 razor_property_type_to_string(struct razor_property *p);
619 void razor_build_evr(char *evr_buf, int size, const char *epoch,
620 const char *version, const char *release);
621 int razor_versioncmp(const char *s1, const char *s2);
623 void razor_disable_root_name_checks(int disable);
625 void razor_set_lua_loader(const char *modname, void (*loader)());
626 void (*razor_get_lua_loader(const char *modname))();
628 char *razor_concat(const char *s, ...) RAZOR_MALLOC RAZOR_NULL_TERMINATED;
630 char *razor_path_add_root(const char *path, const char *root) RAZOR_MALLOC;
632 const char *razor_system_arch(void);
634 #endif /* _RAZOR_H_ */