*/
#include "config.h"
+#include "includes.h"
+#include "opkg_download.h"
+#include "opkg_message.h"
+
+#include "sprintf_alloc.h"
+#include "xsystem.h"
+#include "file_util.h"
+#include "opkg_defines.h"
+#include "libbb/libbb.h"
+
#ifdef HAVE_CURL
#include <curl/curl.h>
#endif
#include <openssl/hmac.h>
#endif
-#include "includes.h"
-#include "opkg_download.h"
-#include "opkg_message.h"
-
-#include "sprintf_alloc.h"
-#include "xsystem.h"
-#include "file_util.h"
-#include "str_util.h"
-#include "opkg_defines.h"
-#include "libbb/libbb.h"
-
#ifdef HAVE_PATHFINDER
#include "opkg_pathfinder.h"
#endif
* each time
*/
static CURL *curl = NULL;
-static void opkg_curl_cleanup(void);
static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data);
#endif
+static int
+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)
{
opkg_message(conf,OPKG_NOTICE,"Downloading %s\n", src);
if (str_starts_with(src, "file:")) {
- int ret;
const char *file_src = src + 5;
opkg_message(conf,OPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
- ret = file_copy(src + 5, dest_file_name);
+ err = file_copy(file_src, dest_file_name);
opkg_message(conf,OPKG_INFO,"Done\n");
free(src_basec);
- return ret;
+ return err;
}
sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
__FUNCTION__, tmp_file_location, strerror(errno));
free(tmp_file_location);
free(src_basec);
- return errno;
+ return -1;
}
if (conf->http_proxy) {
}
#ifdef HAVE_CURL
- CURL *curl;
CURLcode res;
FILE * file = fopen (tmp_file_location, "w");
#else
{
int res;
- char *wgetcmd;
- char *wgetopts;
- wgetopts = getenv("OPKG_WGETOPTS");
- sprintf_alloc(&wgetcmd, "wget -q %s%s -O \"%s\" \"%s\"",
- (conf->http_proxy || conf->ftp_proxy) ? "-Y on " : "",
- (wgetopts!=NULL) ? wgetopts : "",
- tmp_file_location, src);
- opkg_message(conf, OPKG_INFO, "Executing: %s\n", wgetcmd);
- res = xsystem(wgetcmd);
- free(wgetcmd);
+ const char *argv[8];
+ int i = 0;
+
+ argv[i++] = "wget";
+ argv[i++] = "-q";
+ if (conf->http_proxy || conf->ftp_proxy) {
+ argv[i++] = "-Y";
+ argv[i++] = "on";
+ }
+ argv[i++] = "-O";
+ argv[i++] = tmp_file_location;
+ argv[i++] = src;
+ argv[i++] = NULL;
+ res = xsystem(argv);
+
if (res) {
opkg_message(conf, OPKG_ERROR, "Failed to download %s, error %d\n", src, res);
free(tmp_file_location);
free(tmp_file_location);
free(src_basec);
- if (err) {
- return err;
- }
-
- return 0;
+ return err;
}
static int opkg_download_cache(opkg_conf_t *conf, const char *src,
if (err)
return err;
- err = pkg_init_from_file(pkg, tmp_file);
+ err = pkg_init_from_file(conf, pkg, tmp_file);
if (err)
return err;
|| strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
|| strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
- err = pkg_init_from_file(pkg, url);
+ err = pkg_init_from_file(conf, pkg, url);
if (err)
return err;
opkg_message(conf, OPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
if (!pkg->architecture) {
opkg_message(conf, OPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
- return -EINVAL;
+ return -1;
}
pkg->dest = conf->default_dest;
pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
if (namep) {
- *namep = xstrdup(pkg->name);
+ *namep = pkg->name;
}
return 0;
}
#endif
#ifdef HAVE_CURL
-static void opkg_curl_cleanup(void){
+void opkg_curl_cleanup(void){
if(curl != NULL){
curl_easy_cleanup (curl);
curl = NULL;
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, userpwd);
free (userpwd);
}
-
- /* add curl cleanup callback */
- if(!atexit(opkg_curl_cleanup)){
- opkg_message(conf,OPKG_DEBUG, "Failed to register atexit curl cleanup function\n");
- }
-
}
curl_easy_setopt (curl, CURLOPT_NOPROGRESS, (cb == NULL));