X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libopkg%2Fopkg_download.c;h=1d882a14e1852d9492fcb30aafbb23a2b65a2f80;hp=27b9d2e389fab47ecb1d680caa6e78b4af23401f;hb=968549573f2146ef6efa8abef722533b82716b2b;hpb=e107c4253aba1620f80caa375dbe0d405fcdde83 diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c index 27b9d2e..1d882a1 100644 --- a/libopkg/opkg_download.c +++ b/libopkg/opkg_download.c @@ -1,5 +1,5 @@ /* vi: set noexpandtab sw=4 sts=4: */ -/* opkg_download.c - the itsy package management system +/* opkg_download.c - the opkg package management system Carl D. Worth @@ -22,7 +22,7 @@ #include #endif -#include "opkg.h" +#include "includes.h" #include "opkg_download.h" #include "opkg_message.h" #include "opkg_state.h" @@ -31,54 +31,9 @@ #include "xsystem.h" #include "file_util.h" #include "str_util.h" +#include "opkg_defines.h" -#include "libopkg.h" -opkg_download_progress_callback opkg_cb_download_progress = NULL; - -int -curl_progress_func (char* url, - double t, /* dltotal */ - double d, /* dlnow */ - double ultotal, - double ulnow) -{ - int i; - int p = (t) ? d*100/t : 0; - - if (opkg_cb_download_progress) - { - static int prev = -1; - - /* don't report the same percentage multiple times - * (this can occur due to rounding) */ - if (prev == p) - return 0; - prev = p; - - opkg_cb_download_progress (p, url); - return 0; - } - - /* skip progress bar if we haven't done started yet - * this prevents drawing the progress bar if we receive an error such as - * file not found */ - if (t == 0) - return 0; - - printf ("\r%3d%% |", p); - for (i = 1; i < 73; i++) - { - if (i <= p * 0.73) - printf ("="); - else - printf ("-"); - } - printf ("|"); - fflush(stdout); - return 0; -} - -int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name) +int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name, curl_progress_func cb, void *data) { int err = 0; @@ -88,8 +43,6 @@ int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name opkg_message(conf,OPKG_NOTICE,"Downloading %s\n", src); - fflush(stdout); - if (str_starts_with(src, "file:")) { int ret; const char *file_src = src + 5; @@ -121,31 +74,6 @@ int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name setenv("no_proxy", conf->no_proxy, 1); } - /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */ -#if 0 - sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s", - (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "", - conf->proxy_user ? "--proxy-user=" : "", - conf->proxy_user ? conf->proxy_user : "", - conf->proxy_passwd ? "--proxy-passwd=" : "", - conf->proxy_passwd ? conf->proxy_passwd : "", - conf->verbose_wget ? "" : "-q", - conf->tmp_dir, - src); - err = xsystem(cmd); - if (err) { - if (err != -1) { - opkg_message(conf,OPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n", - __FUNCTION__, err, cmd); - } - unlink(tmp_file_location); - free(tmp_file_location); - free(src_basec); - free(cmd); - return EINVAL; - } - free(cmd); -#endif CURL *curl; CURLcode res; FILE * file = fopen (tmp_file_location, "w"); @@ -155,9 +83,12 @@ int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name { curl_easy_setopt (curl, CURLOPT_URL, src); curl_easy_setopt (curl, CURLOPT_WRITEDATA, file); - curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, src); - curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, curl_progress_func); + curl_easy_setopt (curl, CURLOPT_NOPROGRESS, (cb == NULL)); + if (cb) + { + curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, data); + curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, cb); + } curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); if (conf->http_proxy || conf->ftp_proxy) { @@ -182,10 +113,6 @@ int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name else return -1; - /* if no custom progress handler was set, we need to clear the default progress bar */ - if (!opkg_cb_download_progress) - printf ("\n"); - err = file_move(tmp_file_location, dest_file_name); free(tmp_file_location); @@ -203,6 +130,7 @@ int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir) int err; char *url; char *pkgid; + 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", @@ -220,9 +148,14 @@ int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir) "../../foo.ipk". While this is correct, and exactly what we want to use to construct url above, here we actually need to use just the filename part, without any directory. */ - sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename); - err = opkg_download(conf, url, pkg->local_filename); + stripped_filename = strrchr(pkg->filename, '/'); + if ( ! stripped_filename ) + stripped_filename = pkg->filename; + + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, stripped_filename); + + err = opkg_download(conf, url, pkg->local_filename, NULL, NULL); free(url); opkg_set_current_state (conf, OPKG_STATE_NONE, NULL); @@ -247,7 +180,7 @@ 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); + err = opkg_download(conf, url, tmp_file, NULL, NULL); if (err) return err; @@ -300,27 +233,52 @@ opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file) #ifdef HAVE_GPGME int status = -1; gpgme_ctx_t ctx; - gpgme_data_t sig, text; + gpgme_data_t sig, text, key; gpgme_error_t err = -1; gpgme_verify_result_t result; gpgme_signature_t s; + char *trusted_path = NULL; err = gpgme_new (&ctx); if (err) return -1; + sprintf_alloc(&trusted_path, "%s/%s", conf->offline_root, "/etc/opkg/trusted.gpg"); + err = gpgme_data_new_from_file (&key, trusted_path, 1); + free (trusted_path); + if (err) + { + return -1; + } + err = gpgme_op_import (ctx, key); + if (err) + { + gpgme_data_release (key); + return -1; + } + gpgme_data_release (key); + err = gpgme_data_new_from_file (&sig, sig_file, 1); if (err) + { + gpgme_release (ctx); return -1; + } err = gpgme_data_new_from_file (&text, text_file, 1); if (err) + { + gpgme_data_release (sig); + gpgme_release (ctx); return -1; + } err = gpgme_op_verify (ctx, sig, text, NULL); result = gpgme_op_verify_result (ctx); + if (!result) + return -1; /* see if any of the signitures matched */ s = result->signatures; @@ -332,6 +290,7 @@ opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file) s = s->next; } + gpgme_data_release (sig); gpgme_data_release (text); gpgme_release (ctx);