opkg: Fix #ifdef
[oweals/opkg-lede.git] / opkg_download.c
index a73406d2d5c61a9dcabe5db8830c60b6976d8fb7..c0a66fe3229555f083ce4365da863eee1b650995 100644 (file)
 #include "file_util.h"
 #include "str_util.h"
 
+#ifdef OPKG_LIB
+#include "libopkg.h"
+opkg_download_progress_callback opkg_cb_download_progress = NULL;
+#endif
 
 int
 curl_progress_func (void* data,
@@ -38,6 +42,15 @@ curl_progress_func (void* data,
 {
     int i;
     int p = d*100/t;
+
+#ifdef OPKG_LIB
+    if (opkg_cb_download_progress)
+    {
+       opkg_cb_download_progress (p);
+       return 0;
+    }
+#endif
+
     printf ("\r%3d%% |", p);
     for (i = 1; i < 73; i++)
     {
@@ -131,6 +144,14 @@ int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name
        curl_easy_setopt (curl, CURLOPT_WRITEDATA, file);
        curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
        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);