Introduce struct xbps_handle and use it for xbps_init().
This structure sets up function callbacks for fetching files and unpacking binary packages, as well as setting the debug boolean. This way the affected functions (xbps_fetch_file() and xbps_unpack_binary_pkg()) do not need to accept the fn cb pointers and data as arguments. Bump XBPS_RELVER.
This commit is contained in:
@@ -53,7 +53,7 @@
|
||||
* @def XBPS_RELVER
|
||||
* Current library release date.
|
||||
*/
|
||||
#define XBPS_RELVER "20110218"
|
||||
#define XBPS_RELVER "20110221"
|
||||
|
||||
/**
|
||||
* @def XBPS_META_PATH
|
||||
@@ -128,16 +128,61 @@ void xbps_warn_printf(const char *, ...);
|
||||
/** @addtogroup initend */
|
||||
/*@{*/
|
||||
|
||||
/**
|
||||
* @struct xbps_handle xbps_api.h "xbps_api.h"
|
||||
* @brief Structure to be passed to xbps_init() and xbps_end() functions.
|
||||
*
|
||||
* This structure sets some global properties for libxbps, to set some
|
||||
* function callbacks and data to the fetch and unpack functions.
|
||||
*/
|
||||
struct xbps_handle {
|
||||
/**
|
||||
* @var xbps_unpack_cb
|
||||
*
|
||||
* Pointer to the supplied function callback to be used in
|
||||
* xbps_unpack_binary_pkg().
|
||||
*/
|
||||
void (*xbps_unpack_cb)(void *);
|
||||
/**
|
||||
* @var xupd
|
||||
*
|
||||
* Pointer to a xbps_unpack_progress_data structure to be passed
|
||||
* as argument to the \a xbps_unpack_cb function callback.
|
||||
*/
|
||||
struct xbps_unpack_progress_data *xupd;
|
||||
/**
|
||||
* @var xbps_fetch_cb
|
||||
*
|
||||
* Pointer to the supplied function callback to be used in
|
||||
* xbps_fetch_file().
|
||||
*/
|
||||
void (*xbps_fetch_cb)(void *);
|
||||
/**
|
||||
* @var xfpd
|
||||
*
|
||||
* Pointer to a xbps_fetch_progress_data structure to be passed
|
||||
* as argument to the \a xbps_fetch_cb function callback.
|
||||
*/
|
||||
struct xbps_fetch_progress_data *xfpd;
|
||||
/**
|
||||
* @var with_debug
|
||||
*
|
||||
* Set to true to enable debugging messages to stderr.
|
||||
*/
|
||||
bool with_debug;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize the XBPS library with the following steps:
|
||||
*
|
||||
* - Sets the function callbacks for fetching and unpacking.
|
||||
* - Sets default cache connections for libfetch.
|
||||
*
|
||||
* - Initializes the debug printfs.
|
||||
*
|
||||
* @param[in] debug If true, debugging output will be shown to stderr.
|
||||
* @param[in] xh Pointer to an xbps_handle structure. It's
|
||||
* assumed that this pointer is not NULL.
|
||||
*/
|
||||
void xbps_init(bool debug);
|
||||
void xbps_init(struct xbps_handle *xh);
|
||||
|
||||
/**
|
||||
* Releases all resources used by the XBPS library.
|
||||
@@ -295,10 +340,6 @@ struct xbps_fetch_progress_data {
|
||||
* @param[in] refetch If true and local/remote size/mtime do not match,
|
||||
* fetch the file from scratch.
|
||||
* @param[in] flags Flags passed to libfetch's fetchXget().
|
||||
* @param[in] progress_cb Pointer to a function callback to update the
|
||||
* the fetch progress.
|
||||
* @param[in] xfpd Pointer to a xbps_fetch_progress_data struct to be
|
||||
* passed to the \a progress_cb callback as its argument.
|
||||
*
|
||||
* @return -1 on error, 0 if not downloaded (because local/remote size/mtime
|
||||
* do not match) and 1 if downloaded successfully.
|
||||
@@ -306,9 +347,7 @@ struct xbps_fetch_progress_data {
|
||||
int xbps_fetch_file(const char *uri,
|
||||
const char *outputdir,
|
||||
bool refetch,
|
||||
const char *flags,
|
||||
void (*progress_cb)(void *),
|
||||
struct xbps_fetch_progress_data *xfpd);
|
||||
const char *flags);
|
||||
|
||||
/**
|
||||
* Returns last error string reported by xbps_fetch_file().
|
||||
@@ -995,18 +1034,12 @@ prop_dictionary_t
|
||||
* by the \a uri argument (if necessary).
|
||||
*
|
||||
* @param[in] uri URI to a remote repository.
|
||||
* @param[in] progress_cb Pointer to a function callback to update the
|
||||
* the fetch progress.
|
||||
* @param[in] xfpd Pointer to a xbps_fetch_progress_data struct to be
|
||||
* passed to the \a progress_cb callback as its argument.
|
||||
*
|
||||
* @return -1 on error (errno is set appropiately), 0 if transfer was
|
||||
* not necessary (local/remote size/mtime matched) or 1 if
|
||||
* downloaded successfully.
|
||||
*/
|
||||
int xbps_repository_sync_pkg_index(const char *uri,
|
||||
void (*progress_cb)(void *),
|
||||
struct xbps_fetch_progress_data *xfpd);
|
||||
int xbps_repository_sync_pkg_index(const char *uri);
|
||||
|
||||
/*@}*/
|
||||
|
||||
@@ -1142,16 +1175,10 @@ struct xbps_unpack_progress_data {
|
||||
*
|
||||
* @param[in] trans_pkg_dict Package proplib dictionary as stored in the
|
||||
* \a packages array returned by the transaction dictionary.
|
||||
* @param[in] progress_cb Pointer to a function callback to update progress data
|
||||
* while extracting files in package (optional).
|
||||
* @param[in] xupd Pointer to a struct xbps_unpack_progress_data to be passed to
|
||||
* the function callback \a progress_cb.
|
||||
*
|
||||
* @return 0 on success, otherwise an errno value.
|
||||
*/
|
||||
int xbps_unpack_binary_pkg(prop_dictionary_t trans_pkg_dict,
|
||||
void (*progress_cb)(void *),
|
||||
struct xbps_unpack_progress_data *xupd);
|
||||
int xbps_unpack_binary_pkg(prop_dictionary_t trans_pkg_dict);
|
||||
|
||||
/*@}*/
|
||||
|
||||
|
||||
@@ -76,18 +76,15 @@ __BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Sets the libfetch's cache connection limits.
|
||||
*
|
||||
* @param[in] global Number of global cached connections, if set to 0
|
||||
* by default it's set to XBPS_FETCH_CACHECONN.
|
||||
* @param[in] per_host Number of per host cached connections, if set to 0
|
||||
* by default it's set to XBPS_FETCH_CACHECONN_HOST.
|
||||
* From lib/initend.c
|
||||
*/
|
||||
void HIDDEN xbps_fetch_set_cache_connection(int global, int per_host);
|
||||
struct xbps_handle HIDDEN *xbps_handle_get(void);
|
||||
|
||||
/**
|
||||
* Destroys the libfetch's cache connection established.
|
||||
* @private
|
||||
* From lib/download.c
|
||||
*/
|
||||
void HIDDEN xbps_fetch_set_cache_connection(int global, int per_host);
|
||||
void HIDDEN xbps_fetch_unset_cache_connection(void);
|
||||
|
||||
/**
|
||||
@@ -102,16 +99,7 @@ int HIDDEN xbps_entry_install_conf_file(prop_dictionary_t,
|
||||
const char *);
|
||||
/**
|
||||
* @private
|
||||
* From lib/plist_archive_entry.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.
|
||||
* From lib/plist_entry.c
|
||||
*/
|
||||
prop_dictionary_t HIDDEN
|
||||
xbps_read_dict_from_archive_entry(struct archive *ar,
|
||||
@@ -152,44 +140,16 @@ prop_dictionary_t HIDDEN xbps_transaction_dictionary_get(void);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* From lib/repository_sync_index.c
|
||||
*/
|
||||
char HIDDEN *xbps_get_remote_repo_string(const char *);
|
||||
|
||||
/**
|
||||
* Forks and executes a command in the current working directory
|
||||
* with an arbitrary number of arguments.
|
||||
*
|
||||
* @param[in] arg Arguments passed to execvp(3) when forked, the last
|
||||
* argument must be NULL.
|
||||
*
|
||||
* @return 0 on success, -1 on error and errno set appropiately.
|
||||
* @private
|
||||
* From lib/fexec.c
|
||||
*/
|
||||
int HIDDEN xbps_file_exec(const char *arg, ...);
|
||||
|
||||
/**
|
||||
* Forks and executes a command in the current working directory
|
||||
* with an arbitrary number of arguments.
|
||||
*
|
||||
* @param[in] arg Arguments passed to execvp(3) when forked, does not need
|
||||
* to be terminated with a NULL argument.
|
||||
*
|
||||
* @return 0 on success, -1 on error and errno set appropiately.
|
||||
*/
|
||||
int HIDDEN xbps_file_exec_skipempty(const char *arg, ...);
|
||||
|
||||
/**
|
||||
* Forks and executes a command with an arbitrary number of arguments
|
||||
* in a specified path.
|
||||
*
|
||||
* If uid==0 and /bin/sh (relative to path) exists, a chroot(2) call
|
||||
* will be done, otherwise chdir(2) to path.
|
||||
*
|
||||
* @param[in] path Destination path to chroot(2) or chdir(2).
|
||||
* @param[in] arg Arguments passed to execvp(3) when forked, the last
|
||||
* argument must be NULL.
|
||||
*
|
||||
* @return 0 on success, -1 on error and errno set appropiately.
|
||||
*/
|
||||
int HIDDEN xbps_file_chdir_exec(const char *path, const char *arg, ...);
|
||||
|
||||
/**
|
||||
@@ -201,7 +161,7 @@ int HIDDEN xbps_repository_pkg_replaces(prop_dictionary_t,
|
||||
|
||||
/**
|
||||
* @private
|
||||
* From lib/plist.c
|
||||
* From lib/plist_find.c
|
||||
*/
|
||||
prop_dictionary_t HIDDEN
|
||||
xbps_find_virtualpkg_user_in_dict_by_name(prop_dictionary_t,
|
||||
|
||||
Reference in New Issue
Block a user