From ffc255b71561e59214e26e05331935983330abd5 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 13 Nov 2010 03:18:58 +0100 Subject: [PATCH] Starting to clean up the public API, move private stuff into xbps_api_impl.h. --- bin/xbps-bin/check.c | 1 + bin/xbps-bin/defs.h | 11 +++ bin/xbps-bin/install.c | 1 + bin/xbps-bin/main.c | 1 + bin/xbps-bin/show-deps.c | 1 + bin/xbps-repo/repository.c | 1 + bin/xbps-repo/util.c | 5 ++ bin/xbps-uhelper/main.c | 1 + include/xbps_api.h | 118 +++---------------------------- include/xbps_api_impl.h | 124 +++++++++++++++++++++++++++++++++ lib/cmpver.c | 2 + lib/fexec.c | 1 + lib/package_config_files.c | 1 + lib/package_configure.c | 4 +- lib/package_purge.c | 1 + lib/package_register.c | 1 + lib/package_remove.c | 1 + lib/package_remove_obsoletes.c | 1 + lib/package_requiredby.c | 1 + lib/package_state.c | 1 + lib/package_unpack.c | 1 + lib/plist.c | 3 +- lib/regpkgs_dictionary.c | 1 + lib/repository.c | 1 + lib/repository_finddeps.c | 1 + lib/repository_findpkg.c | 1 + lib/repository_plist.c | 1 + lib/repository_pool.c | 1 + lib/repository_sync_index.c | 1 + lib/sortdeps.c | 1 + lib/util.c | 5 +- 31 files changed, 184 insertions(+), 111 deletions(-) create mode 100644 include/xbps_api_impl.h diff --git a/bin/xbps-bin/check.c b/bin/xbps-bin/check.c index 84ed0a75..5824d669 100644 --- a/bin/xbps-bin/check.c +++ b/bin/xbps-bin/check.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "defs.h" diff --git a/bin/xbps-bin/defs.h b/bin/xbps-bin/defs.h index e2944248..30bcd123 100644 --- a/bin/xbps-bin/defs.h +++ b/bin/xbps-bin/defs.h @@ -26,6 +26,16 @@ #ifndef _XBPS_BIN_DEFS_H_ #define _XBPS_BIN_DEFS_H_ +#ifdef DEBUG +#define DPRINTF(x) printf x +#else +#define DPRINTF(x) +#endif + +#ifndef __UNCONST +#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) +#endif + int xbps_install_new_pkg(const char *); int xbps_update_pkg(const char *); int xbps_autoupdate_pkgs(bool); @@ -40,4 +50,5 @@ int show_pkg_info_from_metadir(const char *); int show_pkg_files_from_metadir(const char *); int find_files_in_packages(const char *); + #endif /* !_XBPS_BIN_DEFS_H_ */ diff --git a/bin/xbps-bin/install.c b/bin/xbps-bin/install.c index e4e4ff38..c92a444e 100644 --- a/bin/xbps-bin/install.c +++ b/bin/xbps-bin/install.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include "defs.h" diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index 4ae86ad9..982191d0 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include "defs.h" diff --git a/bin/xbps-bin/show-deps.c b/bin/xbps-bin/show-deps.c index cf3f7b69..eac3ce09 100644 --- a/bin/xbps-bin/show-deps.c +++ b/bin/xbps-bin/show-deps.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "defs.h" diff --git a/bin/xbps-repo/repository.c b/bin/xbps-repo/repository.c index ef7fb454..51c6a580 100644 --- a/bin/xbps-repo/repository.c +++ b/bin/xbps-repo/repository.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include "defs.h" diff --git a/bin/xbps-repo/util.c b/bin/xbps-repo/util.c index c21cd4eb..30d61dbb 100644 --- a/bin/xbps-repo/util.c +++ b/bin/xbps-repo/util.c @@ -29,10 +29,15 @@ #include #include #include +#include #include #include "defs.h" +#ifndef __UNCONST +#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) +#endif + void show_pkg_info_only_repo(prop_dictionary_t dict) { diff --git a/bin/xbps-uhelper/main.c b/bin/xbps-uhelper/main.c index 11871a3d..1b4790d6 100644 --- a/bin/xbps-uhelper/main.c +++ b/bin/xbps-uhelper/main.c @@ -29,6 +29,7 @@ #include #include #include +#include #include diff --git a/include/xbps_api.h b/include/xbps_api.h index beabb59d..ab4b3ca2 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -30,26 +30,21 @@ #include #include -/** - * @cond - */ -#ifndef DEBUG -# define NDEBUG -#endif -#include -/** - * @endcond - */ #include #include #include #include -#if defined(__cplusplus) -extern "C" { +#ifdef __cplusplus +# define __BEGIN_DECLS extern "C" { +# define __END_DECLS } +#else +# define __BEGIN_DECLS +# define __END_DECLS #endif + /** * @file include/xbps_api.h * @brief XBPS Library API header @@ -125,49 +120,7 @@ extern "C" { */ #define XBPS_FLAG_FORCE 0x00000002 - -/** - * @cond - */ -#define ARCHIVE_READ_BLOCKSIZE 10240 - -#define EXTRACT_FLAGS ARCHIVE_EXTRACT_SECURE_NODOTDOT | \ - ARCHIVE_EXTRACT_SECURE_SYMLINKS -#define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | \ - ARCHIVE_EXTRACT_TIME | EXTRACT_FLAGS - -#ifndef __UNCONST -#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) -#endif - -#ifdef DEBUG -#define DPRINTF(x) printf x -#else -#define DPRINTF(x) -#endif - -/* - * By default all public functions have default visibility, unless - * gcc >= 4.x and the HIDDEN definition is used. - */ -#if __GNUC__ >= 4 -#define HIDDEN __attribute__ ((visibility("hidden"))) -#else -#define HIDDEN -#endif -/** - * @endcond - */ - -/** - * @private - * From lib/package_config_files.c - */ -int HIDDEN xbps_config_file_from_archive_entry(prop_dictionary_t, - struct archive_entry *, - const char *, - int *, - bool *); +__BEGIN_DECLS /** @addtogroup configure */ /*@{*/ @@ -525,20 +478,6 @@ prop_object_iterator_t xbps_get_array_iter_from_dict(prop_dictionary_t dict, prop_dictionary_t xbps_get_pkg_dict_from_metadata_plist(const char *pkgn, const char *plist); -/** - * @private - * Finds a proplib dictionary in an archive, matching a specific - * entry on it. - * - * @param[in] ar Pointer to an archive object, as returned by libarchive. - * @param[in] entry Pointer to an archive entry object, as returned by libarchive. - * - * @return The proplib dictionary associated with entry, NULL otherwise - * and errno is set appropiately. - */ -prop_dictionary_t HIDDEN xbps_read_dict_from_archive_entry(struct archive *ar, - struct archive_entry *entry); - /** * Removes the package's proplib dictionary matching \a pkgname * in a plist file. @@ -685,12 +624,6 @@ int xbps_remove_pkg_files(prop_dictionary_t dict, const char *key); /*@}*/ -/** - * @private - * From lib/package_remove_obsoletes.c - */ -int HIDDEN xbps_remove_obsoletes(prop_dictionary_t, prop_dictionary_t); - /** @addtogroup repo_register */ /*@{*/ @@ -714,13 +647,6 @@ int xbps_repository_unregister(const char *uri); /*@}*/ -/** - * @private - * From lib/repository_finddeps.c - */ -int HIDDEN xbps_repository_find_pkg_deps(prop_dictionary_t, - prop_dictionary_t); - /** @addtogroup repo_pkgs */ /*@{*/ @@ -747,7 +673,7 @@ int xbps_repository_install_pkg(const char *pkg, bool bypattern); * * @param pkgname The package name to update. * @param instpkg Installed package dictionary, as returned by - * xbps_find_pkg_installed_from_plist(). + * xbps_find_pkg_dict_installed(). * * @return 0 on success, or an errno value otherwise. */ @@ -776,7 +702,7 @@ int xbps_repository_update_allpkgs(void); * xbps_repository_update_pkg() functions are not called previously. * * @return The transaction dictionary to install/update/replace - * a package list. + * a package list. NULL on failure and errno set appropiately. */ prop_dictionary_t xbps_repository_get_transaction_dict(void); @@ -923,26 +849,6 @@ void xbps_repository_pool_release(void); */ int xbps_repository_sync_pkg_index(const char *uri); -/** - * @private - */ -char HIDDEN *xbps_get_remote_repo_string(const char *uri); - -/*@}*/ - -/** - * @private - * From lib/package_requiredby.c - */ -int HIDDEN xbps_requiredby_pkg_add(prop_array_t, prop_dictionary_t); -int HIDDEN xbps_requiredby_pkg_remove(const char *); - -/** - * @private - * From lib/sortdeps.c - */ -int HIDDEN xbps_sort_pkg_deps(prop_dictionary_t); - /** @addtogroup pkgstates */ /*@{*/ @@ -1251,8 +1157,6 @@ bool xbps_noyes(const char *, ...); /*@}*/ -#if defined(__cplusplus) -} -#endif +__END_DECLS #endif /* !_XBPS_API_H_ */ diff --git a/include/xbps_api_impl.h b/include/xbps_api_impl.h new file mode 100644 index 00000000..b8bc3cef --- /dev/null +++ b/include/xbps_api_impl.h @@ -0,0 +1,124 @@ +/*- + * Copyright (c) 2010 Juan Romero Pardines. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *- + */ + +#ifndef _XBPS_API_IMPL_H_ +#define _XBPS_API_IMPL_H_ + +#ifndef DEBUG +# define NDEBUG +#endif +#include +#include + +#define ARCHIVE_READ_BLOCKSIZE 10240 + +#define EXTRACT_FLAGS ARCHIVE_EXTRACT_SECURE_NODOTDOT | \ + ARCHIVE_EXTRACT_SECURE_SYMLINKS +#define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | \ + ARCHIVE_EXTRACT_TIME | EXTRACT_FLAGS + +#ifndef __UNCONST +#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) +#endif + +#ifdef DEBUG +#define DPRINTF(x) printf x +#else +#define DPRINTF(x) +#endif + +/* + * By default all public functions have default visibility, unless + * gcc >= 4.x and the HIDDEN definition is used. + */ +#if __GNUC__ >= 4 +#define HIDDEN __attribute__ ((visibility("hidden"))) +#else +#define HIDDEN +#endif + +__BEGIN_DECLS +/** + * @private + * From lib/package_config_files.c + */ +int HIDDEN xbps_config_file_from_archive_entry(prop_dictionary_t, + struct archive_entry *, + const char *, + int *, + bool *); + +/** + * @private + * From lib/plist.c + * + * Finds a proplib dictionary in an archive, matching a specific + * entry on it. + * + * @param[in] ar Pointer to an archive object, as returned by libarchive. + * @param[in] entry Pointer to an archive entry object, as returned by libarchive. + * + * @return The proplib dictionary associated with entry, NULL otherwise + * and errno is set appropiately. + */ +prop_dictionary_t HIDDEN + xbps_read_dict_from_archive_entry(struct archive *ar, + struct archive_entry *entry); + +/** + * @private + * From lib/package_remove_obsoletes.c + */ +int HIDDEN xbps_remove_obsoletes(prop_dictionary_t, prop_dictionary_t); + +/** + * @private + * From lib/repository_finddeps.c + */ +int HIDDEN xbps_repository_find_pkg_deps(prop_dictionary_t, + prop_dictionary_t); + +/** + * @private + * From lib/package_requiredby.c + */ +int HIDDEN xbps_requiredby_pkg_add(prop_array_t, prop_dictionary_t); +int HIDDEN xbps_requiredby_pkg_remove(const char *); + +/** + * @private + * From lib/sortdeps.c + */ +int HIDDEN xbps_sort_pkg_deps(prop_dictionary_t); + +/** + * @private + */ +char HIDDEN *xbps_get_remote_repo_string(const char *); + +__END_DECLS + +#endif /* !_XBPS_API_IMPL_H_ */ diff --git a/lib/cmpver.c b/lib/cmpver.c index 08db6817..abd89319 100644 --- a/lib/cmpver.c +++ b/lib/cmpver.c @@ -23,7 +23,9 @@ #include #include #include + #include +#include "xbps_api_impl.h" /* * split_version(pkgname, endname, epoch, revision) returns a pointer to diff --git a/lib/fexec.c b/lib/fexec.c index a220f241..64695adb 100644 --- a/lib/fexec.c +++ b/lib/fexec.c @@ -35,6 +35,7 @@ #include #include +#include "xbps_api_impl.h" /** * @file lib/fexec.c diff --git a/lib/package_config_files.c b/lib/package_config_files.c index 2334f08d..6cb5952d 100644 --- a/lib/package_config_files.c +++ b/lib/package_config_files.c @@ -31,6 +31,7 @@ #include #include +#include "xbps_api_impl.h" int HIDDEN xbps_config_file_from_archive_entry(prop_dictionary_t d, diff --git a/lib/package_configure.c b/lib/package_configure.c index 88b11acc..101bf3fc 100644 --- a/lib/package_configure.c +++ b/lib/package_configure.c @@ -28,6 +28,9 @@ #include #include +#include +#include "xbps_api_impl.h" + /** * @file lib/configure.c * @brief Package configuration routines @@ -44,7 +47,6 @@ * (or packages) will be reconfigured even if its state is * XBPS_PKG_STATE_INSTALLED. */ -#include int xbps_configure_all_pkgs(void) diff --git a/lib/package_purge.c b/lib/package_purge.c index 4c6b28dc..f22daa09 100644 --- a/lib/package_purge.c +++ b/lib/package_purge.c @@ -30,6 +30,7 @@ #include #include +#include "xbps_api_impl.h" /** * @file lib/purge.c diff --git a/lib/package_register.c b/lib/package_register.c index 1622cca9..b506a2a3 100644 --- a/lib/package_register.c +++ b/lib/package_register.c @@ -29,6 +29,7 @@ #include #include +#include "xbps_api_impl.h" /** * @file lib/register.c diff --git a/lib/package_remove.c b/lib/package_remove.c index 050879ed..c8174d58 100644 --- a/lib/package_remove.c +++ b/lib/package_remove.c @@ -32,6 +32,7 @@ #include #include +#include "xbps_api_impl.h" /** * @file lib/remove.c diff --git a/lib/package_remove_obsoletes.c b/lib/package_remove_obsoletes.c index 60a538c2..262da476 100644 --- a/lib/package_remove_obsoletes.c +++ b/lib/package_remove_obsoletes.c @@ -34,6 +34,7 @@ #include #include +#include "xbps_api_impl.h" int HIDDEN xbps_remove_obsoletes(prop_dictionary_t oldd, prop_dictionary_t newd) diff --git a/lib/package_requiredby.c b/lib/package_requiredby.c index decc4e52..73065d2d 100644 --- a/lib/package_requiredby.c +++ b/lib/package_requiredby.c @@ -30,6 +30,7 @@ #include #include +#include "xbps_api_impl.h" static int add_pkg_into_reqby(prop_dictionary_t pkgd, const char *reqname) diff --git a/lib/package_state.c b/lib/package_state.c index a980147c..e8c210dc 100644 --- a/lib/package_state.c +++ b/lib/package_state.c @@ -30,6 +30,7 @@ #include #include +#include "xbps_api_impl.h" /** * @file lib/state.c diff --git a/lib/package_unpack.c b/lib/package_unpack.c index 88c942c9..af272eee 100644 --- a/lib/package_unpack.c +++ b/lib/package_unpack.c @@ -31,6 +31,7 @@ #include #include +#include "xbps_api_impl.h" /** * @file lib/unpack.c diff --git a/lib/plist.c b/lib/plist.c index 21a3c42e..f9e2da23 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -29,8 +29,9 @@ #include #include -#include #include +#include +#include "xbps_api_impl.h" /** * @file lib/plist.c diff --git a/lib/regpkgs_dictionary.c b/lib/regpkgs_dictionary.c index 6c75797a..08b587e0 100644 --- a/lib/regpkgs_dictionary.c +++ b/lib/regpkgs_dictionary.c @@ -30,6 +30,7 @@ #include #include +#include "xbps_api_impl.h" /** * @file lib/regpkgs_dictionary.c diff --git a/lib/repository.c b/lib/repository.c index 5dca13b5..4b86ffac 100644 --- a/lib/repository.c +++ b/lib/repository.c @@ -30,6 +30,7 @@ #include #include +#include "xbps_api_impl.h" /** * @file lib/repository.c diff --git a/lib/repository_finddeps.c b/lib/repository_finddeps.c index 5f0a28c4..06dd241a 100644 --- a/lib/repository_finddeps.c +++ b/lib/repository_finddeps.c @@ -29,6 +29,7 @@ #include #include +#include "xbps_api_impl.h" static int store_dependency(prop_dictionary_t trans_dict, prop_dictionary_t repo_pkg_dict, diff --git a/lib/repository_findpkg.c b/lib/repository_findpkg.c index 904e95e5..50545d52 100644 --- a/lib/repository_findpkg.c +++ b/lib/repository_findpkg.c @@ -30,6 +30,7 @@ #include #include +#include "xbps_api_impl.h" /** * @file lib/repository_findpkg.c diff --git a/lib/repository_plist.c b/lib/repository_plist.c index 685b46c7..356a7a84 100644 --- a/lib/repository_plist.c +++ b/lib/repository_plist.c @@ -32,6 +32,7 @@ #include #include +#include "xbps_api_impl.h" #include "fetch.h" /** diff --git a/lib/repository_pool.c b/lib/repository_pool.c index 5ff4d104..f6b25a66 100644 --- a/lib/repository_pool.c +++ b/lib/repository_pool.c @@ -30,6 +30,7 @@ #include #include +#include "xbps_api_impl.h" /** * @file lib/repository_pool.c diff --git a/lib/repository_sync_index.c b/lib/repository_sync_index.c index e9e05d06..20f1d43e 100644 --- a/lib/repository_sync_index.c +++ b/lib/repository_sync_index.c @@ -31,6 +31,7 @@ #include #include +#include "xbps_api_impl.h" #include "fetch.h" /** diff --git a/lib/sortdeps.c b/lib/sortdeps.c index 89893118..917de07f 100644 --- a/lib/sortdeps.c +++ b/lib/sortdeps.c @@ -29,6 +29,7 @@ #include #include +#include "xbps_api_impl.h" struct sorted_dependency { SIMPLEQ_ENTRY(sorted_dependency) chain; diff --git a/lib/util.c b/lib/util.c index 8d03f264..38df7c13 100644 --- a/lib/util.c +++ b/lib/util.c @@ -35,9 +35,10 @@ #include #include -#include -#include #include "config.h" +#include +#include +#include "xbps_api_impl.h" /** * @file lib/util.c