Implemented support for working with remote repositories.
libfetch from NetBSD's pkgsrc has been imported into lib/fetch, but the objects are embedded into libxbps. Only a public function to fetch files has been implemented: xbps_fetch_file(). The library now is built with -fvisibility=hidden by default, and exported symbols are the ones that use the SYMEXPORT macro. The code works well enough, but will need many more cleanups. --HG-- extra : convert_revision : xtraeme%40gmail.com-20091027004600-0lq9aao67lisbzxv
This commit is contained in:
183
include/fetch.h
Normal file
183
include/fetch.h
Normal file
@@ -0,0 +1,183 @@
|
||||
/* $NetBSD: fetch.h,v 1.15 2009/10/15 12:36:57 joerg Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1998-2004 Dag-Erling Coïdn Smorgrav
|
||||
* 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
|
||||
* in this position and unchanged.
|
||||
* 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD: fetch.h,v 1.26 2004/09/21 18:35:20 des Exp $
|
||||
*/
|
||||
|
||||
#ifndef _FETCH_H_INCLUDED
|
||||
#define _FETCH_H_INCLUDED
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define _LIBFETCH_VER "libfetch/2.0"
|
||||
|
||||
#define URL_HOSTLEN 255
|
||||
#define URL_SCHEMELEN 16
|
||||
#define URL_USERLEN 256
|
||||
#define URL_PWDLEN 256
|
||||
|
||||
typedef struct fetchIO fetchIO;
|
||||
|
||||
struct url {
|
||||
char scheme[URL_SCHEMELEN + 1];
|
||||
char user[URL_USERLEN + 1];
|
||||
char pwd[URL_PWDLEN + 1];
|
||||
char host[URL_HOSTLEN + 1];
|
||||
int port;
|
||||
char *doc;
|
||||
off_t offset;
|
||||
size_t length;
|
||||
time_t last_modified;
|
||||
};
|
||||
|
||||
struct url_stat {
|
||||
off_t size;
|
||||
time_t atime;
|
||||
time_t mtime;
|
||||
};
|
||||
|
||||
struct url_list {
|
||||
size_t length;
|
||||
size_t alloc_size;
|
||||
struct url *urls;
|
||||
};
|
||||
|
||||
/* Recognized schemes */
|
||||
#define SCHEME_FTP "ftp"
|
||||
#define SCHEME_HTTP "http"
|
||||
#define SCHEME_HTTPS "https"
|
||||
#define SCHEME_FILE "file"
|
||||
|
||||
/* Error codes */
|
||||
#define FETCH_ABORT 1
|
||||
#define FETCH_AUTH 2
|
||||
#define FETCH_DOWN 3
|
||||
#define FETCH_EXISTS 4
|
||||
#define FETCH_FULL 5
|
||||
#define FETCH_INFO 6
|
||||
#define FETCH_MEMORY 7
|
||||
#define FETCH_MOVED 8
|
||||
#define FETCH_NETWORK 9
|
||||
#define FETCH_OK 10
|
||||
#define FETCH_PROTO 11
|
||||
#define FETCH_RESOLV 12
|
||||
#define FETCH_SERVER 13
|
||||
#define FETCH_TEMP 14
|
||||
#define FETCH_TIMEOUT 15
|
||||
#define FETCH_UNAVAIL 16
|
||||
#define FETCH_UNKNOWN 17
|
||||
#define FETCH_URL 18
|
||||
#define FETCH_VERBOSE 19
|
||||
#define FETCH_UNCHANGED 20
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void fetchIO_close(fetchIO *);
|
||||
ssize_t fetchIO_read(fetchIO *, void *, size_t);
|
||||
ssize_t fetchIO_write(fetchIO *, const void *, size_t);
|
||||
|
||||
/* fetchIO-specific functions */
|
||||
fetchIO *fetchXGetFile(struct url *, struct url_stat *, const char *);
|
||||
fetchIO *fetchGetFile(struct url *, const char *);
|
||||
fetchIO *fetchPutFile(struct url *, const char *);
|
||||
int fetchStatFile(struct url *, struct url_stat *, const char *);
|
||||
int fetchListFile(struct url_list *, struct url *, const char *,
|
||||
const char *);
|
||||
|
||||
/* HTTP-specific functions */
|
||||
fetchIO *fetchXGetHTTP(struct url *, struct url_stat *, const char *);
|
||||
fetchIO *fetchGetHTTP(struct url *, const char *);
|
||||
fetchIO *fetchPutHTTP(struct url *, const char *);
|
||||
int fetchStatHTTP(struct url *, struct url_stat *, const char *);
|
||||
int fetchListHTTP(struct url_list *, struct url *, const char *,
|
||||
const char *);
|
||||
|
||||
/* FTP-specific functions */
|
||||
fetchIO *fetchXGetFTP(struct url *, struct url_stat *, const char *);
|
||||
fetchIO *fetchGetFTP(struct url *, const char *);
|
||||
fetchIO *fetchPutFTP(struct url *, const char *);
|
||||
int fetchStatFTP(struct url *, struct url_stat *, const char *);
|
||||
int fetchListFTP(struct url_list *, struct url *, const char *,
|
||||
const char *);
|
||||
|
||||
/* Generic functions */
|
||||
fetchIO *fetchXGetURL(const char *, struct url_stat *, const char *);
|
||||
fetchIO *fetchGetURL(const char *, const char *);
|
||||
fetchIO *fetchPutURL(const char *, const char *);
|
||||
int fetchStatURL(const char *, struct url_stat *, const char *);
|
||||
int fetchListURL(struct url_list *, const char *, const char *,
|
||||
const char *);
|
||||
fetchIO *fetchXGet(struct url *, struct url_stat *, const char *);
|
||||
fetchIO *fetchGet(struct url *, const char *);
|
||||
fetchIO *fetchPut(struct url *, const char *);
|
||||
int fetchStat(struct url *, struct url_stat *, const char *);
|
||||
int fetchList(struct url_list *, struct url *, const char *,
|
||||
const char *);
|
||||
|
||||
/* URL parsing */
|
||||
struct url *fetchMakeURL(const char *, const char *, int,
|
||||
const char *, const char *, const char *);
|
||||
struct url *fetchParseURL(const char *);
|
||||
struct url *fetchCopyURL(const struct url *);
|
||||
char *fetchStringifyURL(const struct url *);
|
||||
void fetchFreeURL(struct url *);
|
||||
|
||||
/* URL listening */
|
||||
void fetchInitURLList(struct url_list *);
|
||||
int fetchAppendURLList(struct url_list *, const struct url_list *);
|
||||
void fetchFreeURLList(struct url_list *);
|
||||
char *fetchUnquotePath(struct url *);
|
||||
char *fetchUnquoteFilename(struct url *);
|
||||
|
||||
/* Authentication */
|
||||
typedef int (*auth_t)(struct url *);
|
||||
extern auth_t fetchAuthMethod;
|
||||
|
||||
/* Last error code */
|
||||
extern int fetchLastErrCode;
|
||||
#define MAXERRSTRING 256
|
||||
extern char fetchLastErrString[MAXERRSTRING];
|
||||
|
||||
/* I/O timeout */
|
||||
extern int fetchTimeout;
|
||||
|
||||
/* Restart interrupted syscalls */
|
||||
extern volatile int fetchRestartCalls;
|
||||
|
||||
/* Extra verbosity */
|
||||
extern int fetchDebug;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -68,17 +68,29 @@
|
||||
#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
|
||||
#endif
|
||||
|
||||
#if __GNUC__ >= 4
|
||||
#define SYMEXPORT __attribute__ ((visibility("default")))
|
||||
#else
|
||||
#define SYMEXPORT
|
||||
#endif
|
||||
|
||||
/* From lib/configure.c */
|
||||
int xbps_configure_pkg(const char *, const char *, bool);
|
||||
int xbps_configure_all_pkgs(void);
|
||||
int SYMEXPORT xbps_configure_pkg(const char *, const char *, bool);
|
||||
int SYMEXPORT xbps_configure_all_pkgs(void);
|
||||
|
||||
/* from lib/cmpver.c */
|
||||
int xbps_cmpver(const char *, const char *);
|
||||
int SYMEXPORT xbps_cmpver(const char *, const char *);
|
||||
|
||||
/* From lib/download.c */
|
||||
int SYMEXPORT xbps_fetch_file(const char *, const char *);
|
||||
void SYMEXPORT (*xbps_fetch_start_cb)(const char *, off_t *, off_t *);
|
||||
void SYMEXPORT (*xbps_fetch_update_cb)(off_t *);
|
||||
void SYMEXPORT (*xbps_fetch_end_cb)(void);
|
||||
|
||||
/* From lib/fexec.c */
|
||||
int xbps_file_exec(const char *, ...);
|
||||
int xbps_file_exec_skipempty(const char *, ...);
|
||||
int xbps_file_chdir_exec(const char *, const char *, ...);
|
||||
int SYMEXPORT xbps_file_exec(const char *, ...);
|
||||
int SYMEXPORT xbps_file_exec_skipempty(const char *, ...);
|
||||
int SYMEXPORT xbps_file_chdir_exec(const char *, const char *, ...);
|
||||
|
||||
/* From lib/humanize_number.c */
|
||||
#define HN_DECIMAL 0x01
|
||||
@@ -88,85 +100,89 @@ int xbps_file_chdir_exec(const char *, const char *, ...);
|
||||
#define HN_GETSCALE 0x10
|
||||
#define HN_AUTOSCALE 0x20
|
||||
|
||||
int xbps_humanize_number(char *, size_t, int64_t, const char *,
|
||||
int SYMEXPORT xbps_humanize_number(char *, size_t, int64_t, const char *,
|
||||
int, int);
|
||||
|
||||
/* From lib/findpkg.c */
|
||||
struct repository_data {
|
||||
SIMPLEQ_ENTRY(repository_data) chain;
|
||||
prop_dictionary_t rd_repod;
|
||||
char *rd_uri;
|
||||
};
|
||||
SIMPLEQ_HEAD(, repository_data) repodata_queue;
|
||||
SYMEXPORT SIMPLEQ_HEAD(, repository_data) repodata_queue;
|
||||
|
||||
int xbps_prepare_pkg(const char *);
|
||||
int xbps_find_new_pkg(const char *, prop_dictionary_t);
|
||||
int xbps_find_new_packages(void);
|
||||
int xbps_prepare_repolist_data(void);
|
||||
void xbps_release_repolist_data(void);
|
||||
prop_dictionary_t xbps_get_pkg_props(void);
|
||||
int SYMEXPORT xbps_prepare_pkg(const char *);
|
||||
int SYMEXPORT xbps_find_new_pkg(const char *, prop_dictionary_t);
|
||||
int SYMEXPORT xbps_find_new_packages(void);
|
||||
int SYMEXPORT xbps_prepare_repolist_data(void);
|
||||
void SYMEXPORT xbps_release_repolist_data(void);
|
||||
prop_dictionary_t SYMEXPORT xbps_get_pkg_props(void);
|
||||
|
||||
/* From lib/depends.c */
|
||||
int xbps_find_deps_in_pkg(prop_dictionary_t, prop_dictionary_t);
|
||||
int SYMEXPORT xbps_find_deps_in_pkg(prop_dictionary_t, prop_dictionary_t);
|
||||
|
||||
/* From lib/orphans.c */
|
||||
prop_array_t xbps_find_orphan_packages(void);
|
||||
prop_array_t SYMEXPORT xbps_find_orphan_packages(void);
|
||||
|
||||
/* From lib/plist.c */
|
||||
bool xbps_add_obj_to_dict(prop_dictionary_t, prop_object_t,
|
||||
bool SYMEXPORT xbps_add_obj_to_dict(prop_dictionary_t, prop_object_t,
|
||||
const char *);
|
||||
bool xbps_add_obj_to_array(prop_array_t, prop_object_t);
|
||||
bool SYMEXPORT xbps_add_obj_to_array(prop_array_t, prop_object_t);
|
||||
|
||||
int xbps_callback_array_iter_in_dict(prop_dictionary_t,
|
||||
int SYMEXPORT xbps_callback_array_iter_in_dict(prop_dictionary_t,
|
||||
const char *,
|
||||
int (*fn)(prop_object_t, void *, bool *),
|
||||
void *);
|
||||
int xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t,
|
||||
int SYMEXPORT xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t,
|
||||
const char *,
|
||||
int (*fn)(prop_object_t, void *, bool *),
|
||||
void *);
|
||||
int xbps_callback_array_iter_in_repolist(int (*fn)(prop_object_t,
|
||||
int SYMEXPORT xbps_callback_array_iter_in_repolist(int (*fn)(prop_object_t,
|
||||
void *, bool *), void *);
|
||||
|
||||
prop_dictionary_t xbps_find_pkg_in_dict(prop_dictionary_t,
|
||||
prop_dictionary_t SYMEXPORT xbps_find_pkg_in_dict(prop_dictionary_t,
|
||||
const char *, const char *);
|
||||
prop_dictionary_t xbps_find_pkg_from_plist(const char *, const char *);
|
||||
prop_dictionary_t xbps_find_pkg_installed_from_plist(const char *);
|
||||
bool xbps_find_string_in_array(prop_array_t, const char *);
|
||||
prop_dictionary_t SYMEXPORT xbps_find_pkg_from_plist(const char *,
|
||||
const char *);
|
||||
prop_dictionary_t SYMEXPORT xbps_find_pkg_installed_from_plist(const char *);
|
||||
bool SYMEXPORT xbps_find_string_in_array(prop_array_t, const char *);
|
||||
|
||||
prop_dictionary_t xbps_prepare_regpkgdb_dict(void);
|
||||
void xbps_release_regpkgdb_dict(void);
|
||||
prop_object_iterator_t xbps_get_array_iter_from_dict(prop_dictionary_t,
|
||||
const char *);
|
||||
prop_dictionary_t SYMEXPORT xbps_prepare_regpkgdb_dict(void);
|
||||
void SYMEXPORT xbps_release_regpkgdb_dict(void);
|
||||
prop_object_iterator_t SYMEXPORT
|
||||
xbps_get_array_iter_from_dict(prop_dictionary_t, const char *);
|
||||
|
||||
prop_dictionary_t xbps_read_dict_from_archive_entry(struct archive *,
|
||||
struct archive_entry *);
|
||||
prop_dictionary_t SYMEXPORT xbps_read_dict_from_archive_entry(struct archive *,
|
||||
struct archive_entry *);
|
||||
|
||||
int xbps_remove_pkg_dict_from_file(const char *, const char *);
|
||||
int xbps_remove_pkg_from_dict(prop_dictionary_t, const char *,
|
||||
int SYMEXPORT xbps_remove_pkg_dict_from_file(const char *, const char *);
|
||||
int SYMEXPORT xbps_remove_pkg_from_dict(prop_dictionary_t, const char *,
|
||||
const char *);
|
||||
int xbps_remove_string_from_array(prop_array_t, const char *);
|
||||
int SYMEXPORT xbps_remove_string_from_array(prop_array_t, const char *);
|
||||
|
||||
/* From lib/purge.c */
|
||||
int xbps_purge_pkg(const char *, bool);
|
||||
int xbps_purge_all_pkgs(void);
|
||||
int SYMEXPORT xbps_purge_pkg(const char *, bool);
|
||||
int SYMEXPORT xbps_purge_all_pkgs(void);
|
||||
|
||||
/* From lib/register.c */
|
||||
int xbps_register_pkg(prop_dictionary_t, bool);
|
||||
int xbps_unregister_pkg(const char *);
|
||||
int SYMEXPORT xbps_register_pkg(prop_dictionary_t, bool);
|
||||
int SYMEXPORT xbps_unregister_pkg(const char *);
|
||||
|
||||
/* From lib/remove.c */
|
||||
int xbps_remove_pkg(const char *, const char *, bool);
|
||||
int SYMEXPORT xbps_remove_pkg(const char *, const char *, bool);
|
||||
|
||||
/* From lib/repository.c */
|
||||
int xbps_register_repository(const char *);
|
||||
int xbps_unregister_repository(const char *);
|
||||
int SYMEXPORT xbps_register_repository(const char *);
|
||||
int SYMEXPORT xbps_unregister_repository(const char *);
|
||||
int SYMEXPORT xbps_sync_repository_pkg_index(const char *);
|
||||
char SYMEXPORT *xbps_get_remote_repo_string(const char *);
|
||||
|
||||
/* From lib/requiredby.c */
|
||||
int xbps_requiredby_pkg_add(prop_array_t, prop_dictionary_t);
|
||||
int xbps_requiredby_pkg_remove(const char *);
|
||||
int SYMEXPORT xbps_requiredby_pkg_add(prop_array_t, prop_dictionary_t);
|
||||
int SYMEXPORT xbps_requiredby_pkg_remove(const char *);
|
||||
|
||||
/* From lib/sortdeps.c */
|
||||
int xbps_sort_pkg_deps(prop_dictionary_t);
|
||||
int SYMEXPORT xbps_sort_pkg_deps(prop_dictionary_t);
|
||||
|
||||
/* From lib/state.c */
|
||||
typedef enum pkg_state {
|
||||
@@ -176,31 +192,31 @@ typedef enum pkg_state {
|
||||
XBPS_PKG_STATE_CONFIG_FILES,
|
||||
XBPS_PKG_STATE_NOT_INSTALLED
|
||||
} pkg_state_t;
|
||||
int xbps_get_pkg_state_installed(const char *, pkg_state_t *);
|
||||
int xbps_get_pkg_state_dictionary(prop_dictionary_t, pkg_state_t *);
|
||||
int xbps_set_pkg_state_installed(const char *, pkg_state_t);
|
||||
int xbps_set_pkg_state_dictionary(prop_dictionary_t, pkg_state_t);
|
||||
int SYMEXPORT xbps_get_pkg_state_installed(const char *, pkg_state_t *);
|
||||
int SYMEXPORT xbps_get_pkg_state_dictionary(prop_dictionary_t, pkg_state_t *);
|
||||
int SYMEXPORT xbps_set_pkg_state_installed(const char *, pkg_state_t);
|
||||
int SYMEXPORT xbps_set_pkg_state_dictionary(prop_dictionary_t, pkg_state_t);
|
||||
|
||||
/* From lib/unpack.c */
|
||||
int xbps_unpack_binary_pkg(prop_dictionary_t, bool);
|
||||
int SYMEXPORT xbps_unpack_binary_pkg(prop_dictionary_t, bool);
|
||||
|
||||
/* From lib/util.c */
|
||||
char * xbps_xasprintf(const char *, ...);
|
||||
char * xbps_get_file_hash(const char *);
|
||||
int xbps_check_file_hash(const char *, const char *);
|
||||
int xbps_check_pkg_file_hash(prop_dictionary_t, const char *);
|
||||
int xbps_check_is_installed_pkg(const char *);
|
||||
bool xbps_check_is_installed_pkgname(const char *);
|
||||
char * xbps_get_pkg_index_plist(const char *);
|
||||
char * xbps_get_pkg_name(const char *);
|
||||
const char * xbps_get_pkg_version(const char *);
|
||||
const char * xbps_get_pkg_revision(const char *);
|
||||
bool xbps_pkg_has_rundeps(prop_dictionary_t);
|
||||
void xbps_set_rootdir(const char *);
|
||||
const char * xbps_get_rootdir(void);
|
||||
void xbps_set_flags(int);
|
||||
int xbps_get_flags(void);
|
||||
bool xbps_yesno(const char *, ...);
|
||||
bool xbps_noyes(const char *, ...);
|
||||
char SYMEXPORT *xbps_xasprintf(const char *, ...);
|
||||
char SYMEXPORT *xbps_get_file_hash(const char *);
|
||||
int SYMEXPORT xbps_check_file_hash(const char *, const char *);
|
||||
int SYMEXPORT xbps_check_pkg_file_hash(prop_dictionary_t, const char *);
|
||||
int SYMEXPORT xbps_check_is_installed_pkg(const char *);
|
||||
bool SYMEXPORT xbps_check_is_installed_pkgname(const char *);
|
||||
char SYMEXPORT *xbps_get_pkg_index_plist(const char *);
|
||||
char SYMEXPORT *xbps_get_pkg_name(const char *);
|
||||
const char SYMEXPORT *xbps_get_pkg_version(const char *);
|
||||
const char SYMEXPORT *xbps_get_pkg_revision(const char *);
|
||||
bool SYMEXPORT xbps_pkg_has_rundeps(prop_dictionary_t);
|
||||
void SYMEXPORT xbps_set_rootdir(const char *);
|
||||
const char SYMEXPORT *xbps_get_rootdir(void);
|
||||
void SYMEXPORT xbps_set_flags(int);
|
||||
int SYMEXPORT xbps_get_flags(void);
|
||||
bool SYMEXPORT xbps_yesno(const char *, ...);
|
||||
bool SYMEXPORT xbps_noyes(const char *, ...);
|
||||
|
||||
#endif /* !_XBPS_API_H_ */
|
||||
|
||||
Reference in New Issue
Block a user