X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libopkg%2Fpkg.h;h=d9cab552826b3d3f2328f91cffab0d3bca676f6e;hp=229594d92cf2b0b4cacd7e4090f3c1abb5de9221;hb=2b3d362edbedf3ebbbeb4d50e3653c1702fd61ce;hpb=a854b2c2b08ca1fd9740f714b7a68e0f47e0cb53 diff --git a/libopkg/pkg.h b/libopkg/pkg.h index 229594d..d9cab55 100644 --- a/libopkg/pkg.h +++ b/libopkg/pkg.h @@ -18,9 +18,10 @@ #ifndef PKG_H #define PKG_H +#include "config.h" + #include -#include -#include +#include #include "pkg_vec.h" #include "str_list.h" @@ -32,62 +33,89 @@ struct opkg_conf; - +#ifndef ARRAY_SIZE #define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0]) +#endif /* I think "Size" is currently the shortest field name */ #define PKG_MINIMUM_FIELD_NAME_LEN 4 -enum pkg_state_want -{ - SW_UNKNOWN = 1, - SW_INSTALL, - SW_DEINSTALL, - SW_PURGE, - SW_LAST_STATE_WANT +enum pkg_state_want { + SW_UNKNOWN = 1, + SW_INSTALL, + SW_DEINSTALL, + SW_PURGE, + SW_LAST_STATE_WANT }; typedef enum pkg_state_want pkg_state_want_t; -enum pkg_state_flag -{ - SF_OK = 0, - SF_REINSTREQ = 1, - SF_HOLD = 2, /* do not upgrade version */ - SF_REPLACE = 4, /* replace this package */ - SF_NOPRUNE = 8, /* do not remove obsolete files */ - SF_PREFER = 16, /* prefer this version */ - SF_OBSOLETE = 32, /* old package in upgrade pair */ - SF_MARKED = 64, /* temporary mark */ - SF_FILELIST_CHANGED = 128, /* needs filelist written */ - SF_USER = 256, - SF_LAST_STATE_FLAG +enum pkg_state_flag { + SF_OK = 0, + SF_REINSTREQ = 1, + SF_HOLD = 2, /* do not upgrade version */ + SF_REPLACE = 4, /* replace this package */ + SF_NOPRUNE = 8, /* do not remove obsolete files */ + SF_PREFER = 16, /* prefer this version */ + SF_OBSOLETE = 32, /* old package in upgrade pair */ + SF_MARKED = 64, /* temporary mark */ + SF_FILELIST_CHANGED = 128, /* needs filelist written */ + SF_USER = 256, + SF_NEED_DETAIL = 512, + SF_LAST_STATE_FLAG }; typedef enum pkg_state_flag pkg_state_flag_t; #define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER) -enum pkg_state_status -{ - SS_NOT_INSTALLED = 1, - SS_UNPACKED, - SS_HALF_CONFIGURED, - SS_INSTALLED, - SS_HALF_INSTALLED, - SS_CONFIG_FILES, - SS_POST_INST_FAILED, - SS_REMOVAL_FAILED, - SS_LAST_STATE_STATUS +enum pkg_state_status { + SS_NOT_INSTALLED = 1, + SS_UNPACKED, + SS_HALF_CONFIGURED, + SS_INSTALLED, + SS_HALF_INSTALLED, + SS_CONFIG_FILES, + SS_POST_INST_FAILED, + SS_REMOVAL_FAILED, + SS_LAST_STATE_STATUS }; typedef enum pkg_state_status pkg_state_status_t; -struct abstract_pkg{ - char * name; - int dependencies_checked; - pkg_vec_t * pkgs; - pkg_state_status_t state_status; - pkg_state_flag_t state_flag; - struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */ - abstract_pkg_vec_t * provided_by; - abstract_pkg_vec_t * replaced_by; +enum pkg_fields { + PKG_MAINTAINER, + PKG_PRIORITY, + PKG_SOURCE, + PKG_TAGS, + PKG_SECTION, + PKG_EPOCH, + PKG_FILENAME, + PKG_LOCAL_FILENAME, + PKG_VERSION, + PKG_REVISION, + PKG_DESCRIPTION, + PKG_MD5SUM, + PKG_SHA256SUM, + PKG_SIZE, + PKG_INSTALLED_SIZE, + PKG_INSTALLED_TIME, + PKG_TMP_UNPACK_DIR, + PKG_REPLACES, + PKG_PROVIDES, + PKG_DEPENDS, + PKG_CONFLICTS, + PKG_CONFFILES, +}; + +struct abstract_pkg { + char *name; + int dependencies_checked; + pkg_vec_t *pkgs; + pkg_state_status_t state_status; + pkg_state_flag_t state_flag; + + /* XXX: This should be abstract_pkg_vec_t for consistency. */ + struct abstract_pkg **depended_upon_by; + + abstract_pkg_vec_t *provided_by; + abstract_pkg_vec_t *replaced_by; }; #include "pkg_depends.h" @@ -112,122 +140,121 @@ struct abstract_pkg{ storage and use less memory. We might even do reference counting, but probably not since most often we only create new pkg_t structs, we don't often free them. */ -struct pkg -{ - char *name; - unsigned long epoch; - char *version; - char *revision; - pkg_src_t *src; - pkg_dest_t *dest; - char *architecture; - char *section; - char *maintainer; - char *description; - char *tags; - pkg_state_want_t state_want; - pkg_state_flag_t state_flag; - pkg_state_status_t state_status; - char **depends_str; - int depends_count; - char **pre_depends_str; - int pre_depends_count; - char **recommends_str; - int recommends_count; - char **suggests_str; - int suggests_count; - struct active_list list; /* Used for installing|upgrading */ - compound_depend_t * depends; - - /* Abhaya: new conflicts */ - char **conflicts_str; - compound_depend_t * conflicts; - int conflicts_count; - - char **replaces_str; - int replaces_count; - abstract_pkg_t ** replaces; - - char **provides_str; - int provides_count; - abstract_pkg_t ** provides; - - abstract_pkg_t *parent; - - pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */ - - char *filename; - char *local_filename; - char *url; - char *tmp_unpack_dir; - char *md5sum; -#if defined HAVE_SHA256 - char *sha256sum; -#endif - char *size; - char *installed_size; - char *priority; - char *source; - conffile_list_t conffiles; - time_t installed_time; - /* As pointer for lazy evaluation */ - str_list_t *installed_files; - /* XXX: CLEANUP: I'd like to perhaps come up with a better - mechanism to avoid the problem here, (which is that the - installed_files list was being freed from an inner loop while - still being used within an outer loop. */ - int installed_files_ref_cnt; - int essential; - int arch_priority; +struct pkg { + char *name; + pkg_src_t *src; + pkg_dest_t *dest; + pkg_state_want_t state_want:3; + pkg_state_flag_t state_flag:11; + pkg_state_status_t state_status:4; + + abstract_pkg_t *parent; + + /* As pointer for lazy evaluation */ + str_list_t *installed_files; + /* XXX: CLEANUP: I'd like to perhaps come up with a better + mechanism to avoid the problem here, (which is that the + installed_files list was being freed from an inner loop while + still being used within an outer loop. */ + int installed_files_ref_cnt; + + int essential:1; /* Adding this flag, to "force" opkg to choose a "provided_by_hand" package, if there are multiple choice */ - int provided_by_hand; + int provided_by_hand:1; - /* this flag specifies whether the package was installed to satisfy another - * package's dependancies */ - int auto_installed; + /* this flag specifies whether the package was installed to satisfy another + * package's dependancies */ + int auto_installed:1; + int is_upgrade:1; + + int arch_index:3; + + struct blob_buf blob; }; pkg_t *pkg_new(void); -void pkg_deinit(pkg_t *pkg); -int pkg_init_from_file(opkg_conf_t *conf, pkg_t *pkg, const char *filename); +void pkg_deinit(pkg_t * pkg); +int pkg_init_from_file(pkg_t * pkg, const char *filename); + +void *pkg_set_raw(pkg_t *pkg, int id, const void *val, size_t len); +void *pkg_get_raw(const pkg_t *pkg, int id); + +static inline int pkg_set_int(pkg_t *pkg, int id, int val) +{ + return (intptr_t) pkg_set_raw(pkg, id, &val, sizeof(val)); +} + +static inline int pkg_get_int(const pkg_t *pkg, int id) +{ + return (intptr_t) pkg_get_raw(pkg, id); +} + +char *pkg_set_string(pkg_t *pkg, int id, const char *s); + +static inline char *pkg_get_string(const pkg_t *pkg, int id) +{ + return (char *) pkg_get_raw(pkg, id); +} + +static inline void * pkg_set_ptr(pkg_t *pkg, int id, void *ptr) +{ + void **res = pkg_set_raw(pkg, id, &ptr, sizeof(ptr)); + return res ? *res : NULL; +} + +static inline void * pkg_get_ptr(const pkg_t *pkg, int id) +{ + void **ptr = pkg_get_raw(pkg, id); + return ptr ? *ptr : NULL; +} + +char *pkg_set_architecture(pkg_t *pkg, const char *architecture, ssize_t len); +char *pkg_get_architecture(const pkg_t *pkg); +int pkg_get_arch_priority(const pkg_t *pkg); + +char *pkg_get_md5(const pkg_t *pkg); +char *pkg_set_md5(pkg_t *pkg, const char *cksum); + +char *pkg_get_sha256(const pkg_t *pkg); +char *pkg_set_sha256(pkg_t *pkg, const char *cksum); + abstract_pkg_t *abstract_pkg_new(void); -/* +/* * merges fields from newpkg into oldpkg. - * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero + * Forcibly sets oldpkg state_status, state_want and state_flags */ -int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status); +int pkg_merge(pkg_t * oldpkg, pkg_t * newpkg); -char *pkg_version_str_alloc(pkg_t *pkg); +char *pkg_version_str_alloc(pkg_t * pkg); int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg); int pkg_name_version_and_architecture_compare(const void *a, const void *b); int abstract_pkg_name_compare(const void *a, const void *b); -void pkg_formatted_info(FILE *fp, pkg_t *pkg); -void pkg_formatted_field(FILE *fp, pkg_t *pkg, const char *field); +void pkg_formatted_info(FILE * fp, pkg_t * pkg); +void pkg_formatted_field(FILE * fp, pkg_t * pkg, const char *field); -void set_flags_from_control(opkg_conf_t *conf, pkg_t *pkg); +void set_flags_from_control(pkg_t * pkg); void pkg_print_status(pkg_t * pkg, FILE * file); -str_list_t *pkg_get_installed_files(opkg_conf_t *conf, pkg_t *pkg); -void pkg_free_installed_files(pkg_t *pkg); -void pkg_remove_installed_files_list(opkg_conf_t *conf, pkg_t *pkg); -conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name); -int pkg_run_script(struct opkg_conf *conf, pkg_t *pkg, - const char *script, const char *args); +str_list_t *pkg_get_installed_files(pkg_t * pkg); +void pkg_free_installed_files(pkg_t * pkg); +void pkg_remove_installed_files_list(pkg_t * pkg); +conffile_t *pkg_get_conffile(pkg_t * pkg, const char *file_name); +int pkg_run_script(pkg_t * pkg, const char *script, const char *args); /* enum mappings */ pkg_state_want_t pkg_state_want_from_str(char *str); pkg_state_flag_t pkg_state_flag_from_str(const char *str); pkg_state_status_t pkg_state_status_from_str(const char *str); -int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op); +int pkg_version_satisfied(pkg_t * it, pkg_t * ref, const char *op); -int pkg_arch_supported(opkg_conf_t *conf, pkg_t *pkg); -void pkg_info_preinstall_check(opkg_conf_t *conf); +int pkg_arch_supported(pkg_t * pkg); +void pkg_info_preinstall_check(void); -int pkg_write_filelist(opkg_conf_t *conf, pkg_t *pkg); -int pkg_write_changed_filelists(opkg_conf_t *conf); +int pkg_write_filelist(pkg_t * pkg); +int pkg_write_changed_filelists(void); #endif