rhughes@241: /* rhughes@241: * Copyright (C) 2008 Kristian Høgsberg rhughes@241: * Copyright (C) 2008 Red Hat, Inc ali@403: * Copyright (C) 2009, 2011 J. Ali Harlow rhughes@241: * rhughes@241: * This program is free software; you can redistribute it and/or modify rhughes@241: * it under the terms of the GNU General Public License as published by rhughes@241: * the Free Software Foundation; either version 2 of the License, or rhughes@241: * (at your option) any later version. rhughes@241: * rhughes@241: * This program is distributed in the hope that it will be useful, rhughes@241: * but WITHOUT ANY WARRANTY; without even the implied warranty of rhughes@241: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the rhughes@241: * GNU General Public License for more details. rhughes@241: * rhughes@241: * You should have received a copy of the GNU General Public License along rhughes@241: * with this program; if not, write to the Free Software Foundation, Inc., rhughes@241: * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. rhughes@241: */ rhughes@241: rhughes@241: #ifndef _RAZOR_H_ rhughes@241: #define _RAZOR_H_ rhughes@241: jbowes@284: #include ali@403: #include ali@403: ali@403: /* GCC extensions */ ali@403: #if defined(__GNUC__) ali@403: #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) ali@403: #define RAZOR_MALLOC __attribute__((__malloc__)) ali@403: #else ali@403: #define RAZOR_MALLOC ali@403: #endif ali@403: #if __GNUC__ >= 4 ali@403: #define RAZOR_NULL_TERMINATED __attribute__ ((__sentinel__)) ali@403: #else ali@403: #define RAZOR_NULL_TERMINATED ali@403: #endif ali@403: #endif /* __GNUC__ */ jbowes@284: krh@373: enum razor_section_type { krh@373: RAZOR_SECTION_MAIN = 0x01, krh@373: RAZOR_SECTION_DETAILS = 0x02, krh@373: RAZOR_SECTION_FILES = 0x04, krh@373: RAZOR_SECTION_ALL = 0x07 jbowes@258: }; jbowes@258: ali@403: enum razor_stage_type { ali@403: RAZOR_STAGE_SCRIPTS_PRE = 0x1, ali@403: RAZOR_STAGE_FILES = 0x2, ali@403: RAZOR_STAGE_SCRIPTS_POST = 0x4, ali@403: RAZOR_STAGE_SCRIPTS = 0x5, ali@403: RAZOR_STAGE_ALL = 0x7 ali@403: }; ali@403: richard@302: enum razor_detail_type { richard@307: RAZOR_DETAIL_LAST = 0, /* the sentinel */ richard@307: RAZOR_DETAIL_NAME, richard@302: RAZOR_DETAIL_VERSION, richard@302: RAZOR_DETAIL_ARCH, richard@302: RAZOR_DETAIL_SUMMARY, richard@302: RAZOR_DETAIL_DESCRIPTION, richard@302: RAZOR_DETAIL_URL, ali@369: RAZOR_DETAIL_LICENSE, ali@369: RAZOR_DETAIL_PREUNPROG, ali@369: RAZOR_DETAIL_PREUN, ali@369: RAZOR_DETAIL_POSTUNPROG, ali@372: RAZOR_DETAIL_POSTUN, ali@372: RAZOR_DETAIL_PREFIXES richard@302: }; richard@302: krh@247: enum razor_property_flags { krh@247: RAZOR_PROPERTY_LESS = 1 << 0, krh@247: RAZOR_PROPERTY_GREATER = 1 << 1, krh@247: RAZOR_PROPERTY_EQUAL = 1 << 2, krh@247: RAZOR_PROPERTY_RELATION_MASK = krh@247: RAZOR_PROPERTY_LESS | krh@247: RAZOR_PROPERTY_GREATER | krh@247: RAZOR_PROPERTY_EQUAL, krh@247: krh@247: RAZOR_PROPERTY_REQUIRES = 0 << 3, krh@247: RAZOR_PROPERTY_PROVIDES = 1 << 3, krh@247: RAZOR_PROPERTY_CONFLICTS = 2 << 3, krh@247: RAZOR_PROPERTY_OBSOLETES = 3 << 3, krh@247: RAZOR_PROPERTY_TYPE_MASK = 3 << 3, krh@247: krh@247: RAZOR_PROPERTY_PRE = 1 << 5, krh@247: RAZOR_PROPERTY_POST = 1 << 6, krh@247: RAZOR_PROPERTY_PREUN = 1 << 7, ali@368: RAZOR_PROPERTY_POSTUN = 1 << 8, ali@368: RAZOR_PROPERTY_SCRIPT_MASK = ali@368: RAZOR_PROPERTY_PRE | ali@368: RAZOR_PROPERTY_POST | ali@368: RAZOR_PROPERTY_PREUN | ali@368: RAZOR_PROPERTY_POSTUN rhughes@241: }; rhughes@241: krh@262: /** ali@403: * SECTION:atomic ali@403: * @title: Atomic transactions ali@403: * @short_description: File-based transactions that shouldn't half-succeed ali@403: * ali@403: * This is a helper object for issuing a sequence of file-based actions ali@403: * that should either all succeed or all fail. ali@403: * ali@403: * Note that currently only Windows 7 has a native implementation and that ali@403: * the fallback implementation will not rollback even if an error does occur. ali@403: * This could (and should) be improved. ali@403: **/ ali@403: struct razor_atomic; ali@403: ali@403: struct razor_atomic *razor_atomic_open(const char *description); ali@403: int razor_atomic_commit(struct razor_atomic *atomic); ali@403: const char *razor_atomic_get_error_msg(struct razor_atomic *atomic); ali@403: void razor_atomic_destroy(struct razor_atomic *atomic); ali@403: ali@403: /** ali@403: * razor_atomic_make_dirs ali@403: * ali@403: * Create all sub-directories leading up to path. We know root exists ali@403: * and is a dir, root does not end in a '/', and path either has a ali@403: * leading '/' or (on MS-Windows only) root is the empty string ali@403: * and path starts with drive (eg., "c:/windows"). ali@403: * Note: path itself is not created, only the directory in which it ali@403: * (would) exist. ali@403: * ali@403: * Returns: non-zero on error. ali@403: **/ ali@403: int razor_atomic_make_dirs(struct razor_atomic *atomic, const char *root, ali@403: const char *path); ali@403: int razor_atomic_remove(struct razor_atomic *atomic, const char *path); ali@403: int razor_atomic_rename_file(struct razor_atomic *atomic, const char *oldpath, ali@403: const char *newpath); ali@403: ali@403: /** ali@403: * razor_atomic_create_dir ali@403: * ali@403: * Create a directory, replacing any existing object at this path except ali@403: * an existing directory (which is not counted as a error). ali@403: * ali@403: * Returns: non-zero on error. ali@403: */ ali@403: int razor_atomic_create_dir(struct razor_atomic *atomic, const char *dirname, ali@403: mode_t mode); ali@403: ali@403: /** ali@403: * razor_atomic_create_symlink ali@403: * ali@403: * Create a symbolic link, replacing any existing object at this path except ali@403: * a non-empty directory. ali@403: * ali@403: * Note: This function will always fail on platforms that don't support ali@403: * symbolic links. ali@403: * ali@403: * Returns: non-zero on error. ali@403: */ ali@403: int razor_atomic_create_symlink(struct razor_atomic *atomic, const char *target, ali@403: const char *path); ali@403: /** ali@403: * razor_atomic_create_file ali@403: * ali@403: * Create a file, replacing any existing object at this path except ali@403: * a non-empty directory. ali@403: * ali@403: * Returns: A handle to be passed to razor_atomic_write() and ali@403: * razor_atomic_close() or a negative value on error. ali@403: */ ali@403: int razor_atomic_create_file(struct razor_atomic *atomic, const char *filename, ali@403: mode_t mode); ali@403: int razor_atomic_write(struct razor_atomic *atomic, int handle, ali@403: const void *data, size_t size); ali@403: int razor_atomic_close(struct razor_atomic *atomic, int handle); ali@403: int razor_atomic_sync(struct razor_atomic *atomic, int handle); ali@403: void razor_atomic_abort(struct razor_atomic *atomic, const char *error_msg); ali@403: int razor_atomic_in_error_state(struct razor_atomic *atomic); ali@403: ali@403: /** krh@262: * SECTION:set krh@262: * @title: Package Set krh@262: * @short_description: Represents a set of packages and their metadata. krh@262: * krh@262: * This object represents a set of packages, their dependency krh@262: * information, the file lists and a number of other details. krh@262: **/ rhughes@241: krh@262: struct razor_set; krh@262: struct razor_package; krh@262: struct razor_property; krh@262: ali@403: #define RAZOR_HEADER_VERSION 2 /* Current version */ ali@403: #define RAZOR_HEADER_VERSION_MIN 1 /* Minimum version we support */ ali@403: krh@262: /** krh@262: * razor_set_create: krh@262: * krh@262: * Create a new #razor_set object. krh@262: * krh@262: * Returns: the new #razor_set object. krh@262: **/ ali@363: struct razor_set *razor_set_create_without_root(void); rhughes@241: struct razor_set *razor_set_create(void); ali@403: struct razor_set *razor_set_open(const char *filename, ali@403: struct razor_atomic *atomic); ali@403: uint32_t razor_set_get_header_version(struct razor_set *set); ali@403: int razor_set_set_header_version(struct razor_set *set, ali@403: uint32_t header_version); ali@403: void razor_set_unref(struct razor_set *set); ali@403: struct razor_set *razor_set_ref(struct razor_set *set); ali@403: void razor_set_write_to_handle(struct razor_set *set, ali@403: struct razor_atomic *atomic, int handle, ali@403: uint32_t section_mask); ali@403: int razor_set_write(struct razor_set *set, struct razor_atomic *atomic, krh@373: const char *filename, uint32_t setions); ali@403: int razor_set_bind_sections(struct razor_set *set, struct razor_atomic *atomic, ali@403: const char *filename); rhughes@241: rhughes@241: struct razor_package * rhughes@241: razor_set_get_package(struct razor_set *set, const char *package); rhughes@241: jbowes@258: void richard@304: razor_package_get_details(struct razor_set *set, richard@307: struct razor_package *package, ...); ali@369: int ali@382: razor_package_remove(struct razor_set *prev, struct razor_set *next, ali@403: struct razor_atomic *atomic, struct razor_package *package, ali@403: const char *root, int install_count, ali@403: enum razor_stage_type stage); krh@262: krh@262: /** krh@262: * SECTION:iterator krh@262: * @title: Iterators krh@262: * @short_description: Objects for traversing packages or properties. krh@262: * krh@262: * The razor iterator objects provides a way to iterate through a set krh@262: * of packages or properties. krh@262: **/ krh@262: rhughes@241: struct razor_package_iterator; krh@262: krh@262: /** krh@262: * razor_package_iterator_create: krh@262: * krh@262: * Create a new #razor_package_iterator object. krh@262: * krh@262: * Returns: the new #razor_package_iterator object. krh@262: **/ krh@262: rhughes@241: struct razor_package_iterator * rhughes@241: razor_package_iterator_create(struct razor_set *set); krh@262: krh@262: /** krh@262: * razor_package_iterator_create_for_property: krh@262: * krh@262: * Create a new #razor_package_iterator object for the packages that krh@262: * own the given property. krh@262: * krh@262: * Returns: the new #razor_package_iterator object. krh@262: **/ rhughes@241: struct razor_package_iterator * rhughes@241: razor_package_iterator_create_for_property(struct razor_set *set, rhughes@241: struct razor_property *property); jbowes@277: jbowes@277: /** jbowes@277: * razor_package_iterator_create_for_file: jbowes@277: * jbowes@277: * Create a new #razor_package_iterator object for the packages that jbowes@277: * contain the given file name. jbowes@277: * jbowes@277: * Returns: the new #razor_package_iterator object. jbowes@277: **/ rhughes@241: struct razor_package_iterator * rhughes@241: razor_package_iterator_create_for_file(struct razor_set *set, rhughes@241: const char *filename); rhughes@241: rhughes@241: int razor_package_iterator_next(struct razor_package_iterator *pi, richard@307: struct razor_package **package, ...); rhughes@241: void razor_package_iterator_destroy(struct razor_package_iterator *pi); rhughes@241: rhughes@241: struct razor_package_query * rhughes@241: razor_package_query_create(struct razor_set *set); rhughes@241: void rhughes@241: razor_package_query_add_package(struct razor_package_query *pq, rhughes@241: struct razor_package *p); rhughes@241: void rhughes@241: razor_package_query_add_iterator(struct razor_package_query *pq, rhughes@241: struct razor_package_iterator *pi); rhughes@241: struct razor_package_iterator * rhughes@241: razor_package_query_finish(struct razor_package_query *pq); rhughes@241: rhughes@241: struct razor_property_iterator; rhughes@241: struct razor_property_iterator * rhughes@241: razor_property_iterator_create(struct razor_set *set, rhughes@241: struct razor_package *package); rhughes@241: int razor_property_iterator_next(struct razor_property_iterator *pi, rhughes@241: struct razor_property **property, rhughes@241: const char **name, krh@247: uint32_t *flags, krh@247: const char **version); rhughes@241: void rhughes@241: razor_property_iterator_destroy(struct razor_property_iterator *pi); rhughes@241: ali@351: struct razor_file_iterator; ali@351: struct razor_file_iterator * ali@351: razor_file_iterator_create(struct razor_set *set, ali@377: struct razor_package *package, int post_order); ali@351: int razor_file_iterator_next(struct razor_file_iterator *fi, ali@351: const char **name); ali@351: void razor_file_iterator_destroy(struct razor_file_iterator *fi); ali@351: rhughes@241: void razor_set_list_files(struct razor_set *set, const char *prefix); krh@306: void razor_set_list_package_files(struct razor_set *set, krh@306: struct razor_package *package); rhughes@241: krh@253: enum razor_diff_action { krh@253: RAZOR_DIFF_ACTION_ADD, krh@253: RAZOR_DIFF_ACTION_REMOVE, krh@253: }; krh@253: krh@253: typedef void (*razor_diff_callback_t)(enum razor_diff_action action, krh@253: struct razor_package *package, krh@253: const char *name, krh@253: const char *version, krh@253: const char *arch, krh@253: void *data); krh@253: rhughes@241: void rhughes@241: razor_set_diff(struct razor_set *set, struct razor_set *upstream, krh@253: razor_diff_callback_t callback, void *data); krh@316: krh@316: struct razor_install_iterator; krh@316: krh@316: enum razor_install_action { krh@316: RAZOR_INSTALL_ACTION_ADD, krh@316: RAZOR_INSTALL_ACTION_REMOVE krh@316: }; krh@316: krh@316: struct razor_install_iterator * krh@254: razor_set_create_install_iterator(struct razor_set *set, krh@254: struct razor_set *next); rhughes@241: krh@316: int razor_install_iterator_next(struct razor_install_iterator *ii, krh@316: struct razor_package **package, krh@316: enum razor_install_action *action, krh@316: int *count); krh@316: ali@403: void razor_install_iterator_rewind(struct razor_install_iterator *ii); krh@316: void razor_install_iterator_destroy(struct razor_install_iterator *ii); krh@316: krh@262: /** krh@262: * SECTION:transaction krh@262: * @title: Transaction krh@262: * @short_description: Create a new package set by merging two or more sets. krh@262: * krh@262: * The razor transaction object provides a way to create a new package set krh@262: * from packages from one or more other package sets. krh@262: **/ rhughes@241: ali@369: struct razor_rpm; ali@369: rhughes@241: struct razor_transaction * rhughes@241: razor_transaction_create(struct razor_set *system, struct razor_set *upstream); rhughes@241: void razor_transaction_install_package(struct razor_transaction *transaction, rhughes@241: struct razor_package *package); rhughes@241: void razor_transaction_remove_package(struct razor_transaction *transaction, rhughes@241: struct razor_package *package); rhughes@241: void razor_transaction_update_package(struct razor_transaction *trans, rhughes@241: struct razor_package *package); ali@369: void razor_transaction_fixup_package(struct razor_transaction *trans, ali@369: struct razor_package *package, ali@369: struct razor_rpm *rpm); rhughes@241: void razor_transaction_update_all(struct razor_transaction *transaction); rhughes@241: int razor_transaction_resolve(struct razor_transaction *trans); rhughes@241: int razor_transaction_describe(struct razor_transaction *trans); ali@369: struct razor_set *razor_transaction_commit(struct razor_transaction *trans); rhughes@241: void razor_transaction_destroy(struct razor_transaction *trans); rhughes@241: rhughes@241: /* Temporary helper for test suite. */ rhughes@241: int razor_transaction_unsatisfied_property(struct razor_transaction *trans, rhughes@241: const char *name, krh@247: uint32_t flags, krh@247: const char *version); rhughes@241: krh@262: /** krh@262: * SECTION:rpm krh@262: * @title: Razor RPM krh@262: * @short_description: Operating on RPM files. krh@262: * krh@262: * Functions for open RPM files and extracting information and krh@262: * installing or removing RPM files. krh@262: **/ rhughes@241: ali@351: struct razor_relocations; krh@262: ali@351: struct razor_relocations *razor_relocations_create(void); ali@351: void razor_relocations_add(struct razor_relocations *relocations, ali@351: const char *oldpath, const char *newpath); ali@351: void razor_relocations_set_rpm(struct razor_relocations *relocations, ali@351: struct razor_rpm *rpm); ali@351: const char *razor_relocations_apply(struct razor_relocations *relocations, ali@351: const char *path); ali@351: void razor_relocations_destroy(struct razor_relocations *relocations); ali@351: ali@403: struct razor_rpm *razor_rpm_open(const char *filename, ali@403: struct razor_atomic *atomic); ali@369: void razor_rpm_get_details(struct razor_rpm *rpm, ...); ali@351: void razor_rpm_set_relocations(struct razor_rpm *rpm, ali@351: struct razor_relocations *relocations); ali@403: int razor_rpm_install(struct razor_rpm *rpm, struct razor_atomic *atomic, ali@403: const char *root, int install_count, ali@403: enum razor_stage_type stage); krh@262: int razor_rpm_close(struct razor_rpm *rpm); krh@262: krh@262: /** krh@262: * SECTION:importer krh@262: * @title: Importer krh@262: * @short_description: A mechanism for building #razor_set objects krh@262: * krh@309: * The %razor_importer is a helper object for building a razor set krh@309: * from external sources, like yum metadata, the RPM database or RPM krh@309: * files. krh@309: * krh@309: * The importer is a stateful object; it has the notion of a current krh@309: * package, and the caller can provide meta data such as properties, krh@309: * files and similiar for the package as it becomes available. Once a krh@309: * package is fully described, the next pacakge can begin. When all krh@309: * packages have been described to the importer, the importer will krh@309: * create a new %razor_set with the specified packages. krh@309: * krh@309: * A typical use krh@309: * of the importer will follow this template: krh@309: * |[ krh@309: * importer = razor_importer_create(); krh@309: * krh@309: * while ( /* more packages to import */; ) { krh@309: * /* get name, version and arch of next package */ krh@309: * razor_importer_begin_package(importer, name, version, arch); krh@309: * razor_importer_add_details(importer, summary, description, url, license); krh@309: * krh@309: * while ( /* more properties to add */ ) krh@309: * razor_importer_add_property(importer, name, flags, version); krh@309: * krh@309: * while ( /* [more files to add */ ) krh@309: * razor_importer_add_file(importer, name); krh@309: * krh@309: * razor_importer_finish_package(importer); krh@309: * } krh@309: * krh@309: * return razor_importer_finish(importer); krh@309: * ]| krh@262: **/ rhughes@241: struct razor_importer; rhughes@241: krh@249: struct razor_importer *razor_importer_create(void); rhughes@241: void razor_importer_destroy(struct razor_importer *importer); rhughes@241: void razor_importer_begin_package(struct razor_importer *importer, rhughes@241: const char *name, rhughes@241: const char *version, rhughes@241: const char *arch); jbowes@258: void razor_importer_add_details(struct razor_importer *importer, jbowes@258: const char *summary, jbowes@258: const char *description, jbowes@258: const char *url, jbowes@258: const char *license); ali@369: void razor_importer_add_script(struct razor_importer *importer, ali@369: enum razor_property_flags script, ali@369: const char *program, ali@369: const char *body); ali@372: void razor_importer_add_install_prefix(struct razor_importer *importer, ali@372: const char *install_prefix); rhughes@241: void razor_importer_add_property(struct razor_importer *importer, rhughes@241: const char *name, krh@247: uint32_t flags, krh@247: const char *version); rhughes@241: void razor_importer_add_file(struct razor_importer *importer, rhughes@241: const char *name); rhughes@241: void razor_importer_finish_package(struct razor_importer *importer); rhughes@241: rhughes@241: int razor_importer_add_rpm(struct razor_importer *importer, rhughes@241: struct razor_rpm *rpm); rhughes@241: rhughes@241: struct razor_set *razor_importer_finish(struct razor_importer *importer); rhughes@241: rhughes@241: struct razor_set *razor_set_create_from_yum(void); rhughes@241: struct razor_set *razor_set_create_from_rpmdb(void); rhughes@241: krh@262: /** krh@262: * SECTION:root krh@262: * @title: Root krh@262: * @short_description: Functions for accessing an install root. krh@262: * krh@262: * The #razor_root object encapsulate access to and locking of a razor krh@262: * install root. krh@262: **/ rhughes@241: struct razor_root; rhughes@241: rhughes@241: int razor_root_create(const char *root); ali@403: struct razor_root * ali@403: razor_root_open(const char *root, struct razor_atomic *atomic); ali@403: struct razor_set *razor_root_open_read_only(const char *root, ali@403: struct razor_atomic *atomic); krh@250: struct razor_set *razor_root_get_system_set(struct razor_root *root); krh@250: int razor_root_close(struct razor_root *root); krh@250: void razor_root_update(struct razor_root *root, struct razor_set *next); krh@250: int razor_root_commit(struct razor_root *root); rhughes@241: krh@262: /** krh@262: * SECTION:misc krh@262: * @title: Miscellaneous Functions krh@262: * @short_description: Various helper functions krh@262: * krh@262: * Functions that doesn't fit anywhere else. krh@262: **/ krh@262: krh@262: const char * krh@262: razor_property_relation_to_string(struct razor_property *p); krh@262: const char * krh@262: razor_property_type_to_string(struct razor_property *p); krh@262: krh@262: void razor_build_evr(char *evr_buf, int size, const char *epoch, krh@262: const char *version, const char *release); krh@262: int razor_versioncmp(const char *s1, const char *s2); krh@262: ali@359: void razor_disable_root_name_checks(int disable); ali@359: ali@361: void razor_set_lua_loader(const char *modname, void (*loader)()); ali@368: void (*razor_get_lua_loader(const char *modname))(); ali@361: ali@403: char *razor_concat(const char *s, ...) RAZOR_MALLOC RAZOR_NULL_TERMINATED; ali@403: ali@403: const char *razor_system_arch(void); krh@262: rhughes@241: #endif /* _RAZOR_H_ */