summaryrefslogtreecommitdiffstats
path: root/libopkg/opkg_download.c
diff options
context:
space:
mode:
authorgraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2009-12-08 20:20:03 (EST)
committer graham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2009-12-08 20:20:03 (EST)
commit2fdb3fc0b67757afd6fe7a244b6e14d2a546af0e (patch)
treea5e28a26a07e429a753f29945cc8ba9c4f6c9884 /libopkg/opkg_download.c
parente4a49209222ea7385f64e9336425df115a3ea1a3 (diff)
Merge commit 'grg' into HEAD
git-svn-id: http://opkg.googlecode.com/svn/trunk@471 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
Diffstat (limited to 'libopkg/opkg_download.c')
-rw-r--r--libopkg/opkg_download.c139
1 files changed, 69 insertions, 70 deletions
diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c
index c4b2f0c..7062766 100644
--- a/libopkg/opkg_download.c
+++ b/libopkg/opkg_download.c
@@ -58,7 +58,7 @@ static void openssl_init(void);
#endif
#ifdef HAVE_OPENSSL
-static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath);
+static X509_STORE *setup_verify(char *CAfile, char *CApath);
#endif
#ifdef HAVE_CURL
@@ -67,7 +67,7 @@ static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath);
* each time
*/
static CURL *curl = NULL;
-static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data);
+static CURL *opkg_curl_init(curl_progress_func cb, void *data);
#endif
static int
@@ -76,8 +76,9 @@ str_starts_with(const char *str, const char *prefix)
return (strncmp(str, prefix, strlen(prefix)) == 0);
}
-int opkg_download(opkg_conf_t *conf, const char *src,
- const char *dest_file_name, curl_progress_func cb, void *data)
+int
+opkg_download(const char *src, const char *dest_file_name,
+ curl_progress_func cb, void *data)
{
int err = 0;
@@ -85,37 +86,39 @@ int opkg_download(opkg_conf_t *conf, const char *src,
char *src_base = basename(src_basec);
char *tmp_file_location;
- opkg_message(conf,OPKG_NOTICE,"Downloading %s\n", src);
+ free(src_basec);
+
+ opkg_msg(NOTICE,"Downloading %s.\n", src);
if (str_starts_with(src, "file:")) {
const char *file_src = src + 5;
- opkg_message(conf,OPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
+ opkg_msg(INFO, "Copying %s to %s...", file_src, dest_file_name);
err = file_copy(file_src, dest_file_name);
- opkg_message(conf,OPKG_INFO,"Done\n");
- free(src_basec);
+ opkg_msg(INFO, "Done.\n");
return err;
}
sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
err = unlink(tmp_file_location);
if (err && errno != ENOENT) {
- opkg_message(conf,OPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
- __FUNCTION__, tmp_file_location, strerror(errno));
+ opkg_perror(ERROR, "Failed to unlink %s\n", tmp_file_location);
free(tmp_file_location);
- free(src_basec);
return -1;
}
if (conf->http_proxy) {
- opkg_message(conf,OPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
+ opkg_msg(DEBUG, "Setting environment variable: http_proxy = %s.\n",
+ conf->http_proxy);
setenv("http_proxy", conf->http_proxy, 1);
}
if (conf->ftp_proxy) {
- opkg_message(conf,OPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
+ opkg_msg(DEBUG, "Setting environment variable: ftp_proxy = %s.\n",
+ conf->ftp_proxy);
setenv("ftp_proxy", conf->ftp_proxy, 1);
}
if (conf->no_proxy) {
- opkg_message(conf,OPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
+ opkg_msg(DEBUG,"Setting environment variable: no_proxy = %s.\n",
+ conf->no_proxy);
setenv("no_proxy", conf->no_proxy, 1);
}
@@ -123,7 +126,7 @@ int opkg_download(opkg_conf_t *conf, const char *src,
CURLcode res;
FILE * file = fopen (tmp_file_location, "w");
- curl = opkg_curl_init (conf, cb, data);
+ curl = opkg_curl_init (cb, data);
if (curl)
{
curl_easy_setopt (curl, CURLOPT_URL, src);
@@ -135,9 +138,9 @@ int opkg_download(opkg_conf_t *conf, const char *src,
{
long error_code;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &error_code);
- opkg_message(conf, OPKG_ERROR, "Failed to download %s. \nerror detail: %s\n", src, curl_easy_strerror(res));
+ opkg_msg(ERROR, "Failed to download %s: %s.\n",
+ src, curl_easy_strerror(res));
free(tmp_file_location);
- free(src_basec);
return res;
}
@@ -145,7 +148,6 @@ int opkg_download(opkg_conf_t *conf, const char *src,
else
{
free(tmp_file_location);
- free(src_basec);
return -1;
}
#else
@@ -167,9 +169,8 @@ int opkg_download(opkg_conf_t *conf, const char *src,
res = xsystem(argv);
if (res) {
- opkg_message(conf, OPKG_ERROR, "Failed to download %s, error %d\n", src, res);
+ opkg_msg(ERROR, "Failed to download %s, wget returned %d.\n", src, res);
free(tmp_file_location);
- free(src_basec);
return res;
}
}
@@ -178,20 +179,20 @@ int opkg_download(opkg_conf_t *conf, const char *src,
err = file_move(tmp_file_location, dest_file_name);
free(tmp_file_location);
- free(src_basec);
return err;
}
-static int opkg_download_cache(opkg_conf_t *conf, const char *src,
- const char *dest_file_name, curl_progress_func cb, void *data)
+static int
+opkg_download_cache(const char *src, const char *dest_file_name,
+ curl_progress_func cb, void *data)
{
char *cache_name = xstrdup(src);
char *cache_location, *p;
int err = 0;
if (!conf->cache || str_starts_with(src, "file:")) {
- err = opkg_download(conf, src, dest_file_name, cb, data);
+ err = opkg_download(src, dest_file_name, cb, data);
goto out1;
}
@@ -201,9 +202,9 @@ static int opkg_download_cache(opkg_conf_t *conf, const char *src,
sprintf_alloc(&cache_location, "%s/%s", conf->cache, cache_name);
if (file_exists(cache_location))
- opkg_message(conf, OPKG_NOTICE, "Copying %s\n", cache_location);
+ opkg_msg(NOTICE, "Copying %s.\n", cache_location);
else {
- err = opkg_download(conf, src, cache_location, cb, data);
+ err = opkg_download(src, cache_location, cb, data);
if (err) {
(void) unlink(cache_location);
goto out2;
@@ -220,19 +221,21 @@ out1:
return err;
}
-int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir)
+int
+opkg_download_pkg(pkg_t *pkg, const char *dir)
{
int err;
char *url;
char *stripped_filename;
if (pkg->src == NULL) {
- opkg_message(conf,OPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
- pkg->name, pkg->parent->name);
+ opkg_msg(ERROR, "Package %s is not available from any configured src.\n",
+ pkg->name);
return -1;
}
if (pkg->filename == NULL) {
- opkg_message(conf,OPKG_ERROR, "ERROR: Package %s (parent %s) does not have a valid filename field.\n",pkg->name, pkg->parent->name);
+ opkg_msg(ERROR, "Package %s does not have a valid filename field.\n",
+ pkg->name);
return -1;
}
@@ -249,7 +252,7 @@ int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir)
sprintf_alloc(&pkg->local_filename, "%s/%s", dir, stripped_filename);
- err = opkg_download_cache(conf, url, pkg->local_filename, NULL, NULL);
+ err = opkg_download_cache(url, pkg->local_filename, NULL, NULL);
free(url);
return err;
@@ -258,7 +261,8 @@ int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir)
/*
* Downloads file from url, installs in package database, return package name.
*/
-int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **namep)
+int
+opkg_prepare_url_for_install(const char *url, char **namep)
{
int err = 0;
pkg_t *pkg;
@@ -272,11 +276,11 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name
char *file_base = basename(file_basec);
sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
- err = opkg_download(conf, url, tmp_file, NULL, NULL);
+ err = opkg_download(url, tmp_file, NULL, NULL);
if (err)
return err;
- err = pkg_init_from_file(conf, pkg, tmp_file);
+ err = pkg_init_from_file(pkg, tmp_file);
if (err)
return err;
@@ -287,10 +291,11 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name
|| strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
|| strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
- err = pkg_init_from_file(conf, pkg, url);
+ err = pkg_init_from_file(pkg, url);
if (err)
return err;
- opkg_message(conf, OPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
+ opkg_msg(DEBUG2, "Package %s provided by hand (%s).\n",
+ pkg->name, pkg->local_filename);
pkg->provided_by_hand = 1;
} else {
@@ -299,15 +304,10 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name
return 0;
}
- if (!pkg->architecture) {
- opkg_message(conf, OPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
- return -1;
- }
-
pkg->dest = conf->default_dest;
pkg->state_want = SW_INSTALL;
pkg->state_flag |= SF_PREFER;
- pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
+ hash_insert_pkg(pkg, 1);
if (namep) {
*namep = pkg->name;
@@ -316,7 +316,7 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name
}
int
-opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file)
+opkg_verify_file (char *text_file, char *sig_file)
{
#if defined HAVE_GPGME
if (conf->check_signature == 0 )
@@ -324,7 +324,7 @@ opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file)
int status = -1;
gpgme_ctx_t ctx;
gpgme_data_t sig, text, key;
- gpgme_error_t err = -1;
+ gpgme_error_t err;
gpgme_verify_result_t result;
gpgme_signature_t s;
char *trusted_path = NULL;
@@ -397,31 +397,29 @@ opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file)
openssl_init();
// Set-up the key store
- if(!(store = setup_verify(conf, conf->signature_ca_file, conf->signature_ca_path))){
- opkg_message(conf, OPKG_ERROR,
- "Can't open CA certificates\n");
+ if(!(store = setup_verify(conf->signature_ca_file, conf->signature_ca_path))){
+ opkg_msg(ERROR, "Can't open CA certificates.\n");
goto verify_file_end;
}
// Open a BIO to read the sig file
if (!(in = BIO_new_file(sig_file, "rb"))){
- opkg_message(conf, OPKG_ERROR,
- "Can't open signature file %s\n", sig_file);
+ opkg_msg(ERROR, "Can't open signature file %s.\n", sig_file);
goto verify_file_end;
}
// Read the PKCS7 block contained in the sig file
p7 = PEM_read_bio_PKCS7(in, NULL, NULL, NULL);
if(!p7){
- opkg_message(conf, OPKG_ERROR,
- "Can't read signature file (Corrupted ?)\n");
+ opkg_msg(ERROR, "Can't read signature file %s (Corrupted ?).\n",
+ sig_file);
goto verify_file_end;
}
#if defined(HAVE_PATHFINDER)
if(conf->check_x509_path){
if(!pkcs7_pathfinder_verify_signers(p7)){
- opkg_message(conf, OPKG_ERROR, "pkcs7_pathfinder_verify_signers: "
- "Path verification failed\n");
+ opkg_msg(ERROR, "pkcs7_pathfinder_verify_signers: "
+ "Path verification failed.\n");
goto verify_file_end;
}
}
@@ -429,16 +427,14 @@ opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file)
// Open the Package file to authenticate
if (!(indata = BIO_new_file(text_file, "rb"))){
- opkg_message(conf, OPKG_ERROR,
- "Can't open file %s\n", text_file);
+ opkg_msg(ERROR, "Can't open file %s.\n", text_file);
goto verify_file_end;
}
// Let's verify the autenticity !
if (PKCS7_verify(p7, NULL, store, indata, NULL, PKCS7_BINARY) != 1){
// Get Off My Lawn!
- opkg_message(conf, OPKG_ERROR,
- "Verification failure\n");
+ opkg_msg(ERROR, "Verification failure.\n");
}else{
// Victory !
status = 0;
@@ -477,7 +473,9 @@ static void openssl_init(void){
#if defined HAVE_OPENSSL
-static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath){
+static X509_STORE *
+setup_verify(char *CAfile, char *CApath)
+{
X509_STORE *store = NULL;
X509_LOOKUP *lookup = NULL;
@@ -496,8 +494,7 @@ static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath){
if (CAfile) {
if(!X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM)) {
// Invalid CA => Bye bye
- opkg_message(conf, OPKG_ERROR,
- "Error loading file %s\n", CAfile);
+ opkg_msg(ERROR, "Error loading file %s.\n", CAfile);
goto end;
}
} else {
@@ -512,8 +509,7 @@ static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath){
if (CApath) {
if(!X509_LOOKUP_add_dir(lookup,CApath,X509_FILETYPE_PEM)) {
- opkg_message(conf, OPKG_ERROR,
- "Error loading directory %s\n", CApath);
+ opkg_msg(ERROR, "Error loading directory %s.\n", CApath);
goto end;
}
} else {
@@ -541,7 +537,9 @@ void opkg_curl_cleanup(void){
}
}
-static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data){
+static CURL *
+opkg_curl_init(curl_progress_func cb, void *data)
+{
if(curl == NULL){
curl = curl_easy_init();
@@ -553,7 +551,7 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data
/* use crypto engine */
if (curl_easy_setopt(curl, CURLOPT_SSLENGINE, conf->ssl_engine) != CURLE_OK){
- opkg_message(conf, OPKG_ERROR, "can't set crypto engine: '%s'\n",
+ opkg_msg(ERROR, "Can't set crypto engine '%s'.\n",
conf->ssl_engine);
opkg_curl_cleanup();
@@ -561,7 +559,8 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data
}
/* set the crypto engine as default */
if (curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L) != CURLE_OK){
- opkg_message(conf, OPKG_ERROR, "can't set crypto engine as default\n");
+ opkg_msg(ERROR, "Can't set crypto engine '%s' as default.\n",
+ conf->ssl_engine);
opkg_curl_cleanup();
return NULL;
@@ -572,7 +571,7 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data
if(conf->ssl_key_passwd){
if (curl_easy_setopt(curl, CURLOPT_SSLKEYPASSWD, conf->ssl_key_passwd) != CURLE_OK)
{
- opkg_message(conf, OPKG_DEBUG, "Failed to set key password\n");
+ opkg_msg(DEBUG, "Failed to set key password.\n");
}
}
@@ -580,7 +579,7 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data
if(conf->ssl_cert_type){
if (curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, conf->ssl_cert_type) != CURLE_OK)
{
- opkg_message(conf, OPKG_DEBUG, "Failed to set certificate format\n");
+ opkg_msg(DEBUG, "Failed to set certificate format.\n");
}
}
/* SSL cert name isn't mandatory */
@@ -592,13 +591,13 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data
if(conf->ssl_key_type){
if (curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, conf->ssl_key_type) != CURLE_OK)
{
- opkg_message(conf, OPKG_DEBUG, "Failed to set key format\n");
+ opkg_msg(DEBUG, "Failed to set key format.\n");
}
}
if(conf->ssl_key){
if (curl_easy_setopt(curl, CURLOPT_SSLKEY, conf->ssl_key) != CURLE_OK)
{
- opkg_message(conf, OPKG_DEBUG, "Failed to set key\n");
+ opkg_msg(DEBUG, "Failed to set key.\n");
}
}
@@ -612,7 +611,7 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data
#ifdef HAVE_PATHFINDER
if(conf->check_x509_path){
if (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, curl_ssl_ctx_function) != CURLE_OK){
- opkg_message(conf, OPKG_DEBUG, "Failed to set ssl path verification callback\n");
+ opkg_msg(DEBUG, "Failed to set ssl path verification callback.\n");
}else{
curl_easy_setopt(curl, CURLOPT_SSL_CTX_DATA, NULL);
}