opkg: include the current url being downloaded in the progress callback
[oweals/opkg-lede.git] / opkg_download.c
index 6859e92ee9d7c043781ed72cdd270b5bb092dd91..3370b1f60a9253b5e17cc9a9a1793f48c209dad4 100644 (file)
@@ -34,19 +34,19 @@ opkg_download_progress_callback opkg_cb_download_progress = NULL;
 #endif
 
 int
-curl_progress_func (void* data,
-                         double t, /* dltotal */
-                         double d, /* dlnow */
-                         double ultotal,
-                         double ulnow)
+curl_progress_func (char* url,
+                   double t, /* dltotal */
+                   double d, /* dlnow */
+                   double ultotal,
+                   double ulnow)
 {
     int i;
     int p = d*100/t;
 
-#ifdef LIBOPKG
+#ifdef OPKG_LIB
     if (opkg_cb_download_progress)
     {
-       opkg_cb_download_progress (p);
+       opkg_cb_download_progress (p, url);
        return 0;
     }
 #endif
@@ -142,8 +142,17 @@ 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_NOPROGRESS, 0);
+       curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, src);
        curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, curl_progress_func);
+       if (conf->http_proxy || conf->ftp_proxy)
+       {
+           char *userpwd;
+           sprintf_alloc (&userpwd, "%s:%s", conf->proxy_user,
+                   conf->proxy_passwd);
+           curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, userpwd);
+           free (userpwd);
+       }
        res = curl_easy_perform (curl);
        curl_easy_cleanup (curl);
        fclose (file);