Pagina 1 di 1

slackyd & proxy

Inviato: lun 19 ott 2009, 17:17
da ZeroUno
slackyd può passare via proxy?

Ciao
01

Re: slackyd & proxy

Inviato: mar 20 ott 2009, 1:20
da Dani
No, non ancora.

Re: slackyd & proxy

Inviato: mar 20 ott 2009, 8:23
da ZeroUno
mi stavo vedendo il codice per vedere se riesco a sostituire il download con una chiamata a wget. Quel poco di C che so credo dovrebbe bastarmi, ma ho difficoltà ad individuare il punto esatto dove fa il download (sono arrivato ad individuare il name resolving quindi dovrebbe essere da quelle parti)

Ciao
01

Re: slackyd & proxy

Inviato: mar 20 ott 2009, 12:09
da ZeroUno
Ecco la patch corretta applicata al pacchetto slackyd del 13.0. Aggiunge lo switch -W che significa 'usa wget'

Codice: Seleziona tutto

diff --git slackyd-0.1.13beta/src/func.c b/Downloaded/slackyd-0.1.13beta/src/func.c
index 28172c0..0349f33 100644
--- slackyd-0.1.13beta/src/func.c
+++ slackyd-0.1.13beta/src/func.c
@@ -966,7 +966,7 @@ parse_options (int argc, char **argv)
         opt.cache = xstrdup (DATADIR);
     }

-       while ((c = getopt(argc, argv, "5" "B:D::IL::O::PRSU::VX::" "b:c:d::efg:hl::mnpqr::s::uvw:x")) != -1) {
+       while ((c = getopt(argc, argv, "5" "WB:D::IL::O::PRSU::VX::" "b:c:d::efg:hl::mnpqr::s::uvw:x")) != -1) {

        switch (c) {

@@ -1096,6 +1096,9 @@ parse_options (int argc, char **argv)
            p_fold.suggest  = (opt.check_dep) ? true : false;
            p_fold.conflict = true;
            break;
+       case 'W':
+           opt.wget        = true;
+           break;
        case 'h':
                usage (argv[0]);
                break;
diff --git slackyd-0.1.13beta/src/global.h b/Downloaded/slackyd-0.1.13beta/src/global.h
index f631ce0..c31a150 100644
--- slackyd-0.1.13beta/src/global.h
+++ slackyd-0.1.13beta/src/global.h
@@ -69,6 +69,7 @@ typedef struct options_t {
     bool skip_status;
     bool blacklist;
     bool show_blacklisted;
+    bool wget;

     u_short enabled;

diff --git slackyd-0.1.13beta/src/main.c b/Downloaded/slackyd-0.1.13beta/src/main.c
index eea22ce..dd04f80 100644
--- slackyd-0.1.13beta/src/main.c
+++ slackyd-0.1.13beta/src/main.c
@@ -54,6 +54,7 @@ usage(char *prgname)
     fprintf (stderr, " -v: Verbose mode.                                   \n");
     fprintf (stderr, " -V: Show slackyd info.                              \n");
     fprintf (stderr, " -w: View package info.                              \n");
+    fprintf (stderr, " -W: Using WGET to download files.                   \n");
     fprintf (stderr, " -x: Disable blacklist.                              \n");
     fprintf (stderr, " -X: Show packages available and blacklisted.        \n");

diff --git slackyd-0.1.13beta/src/net.c b/Downloaded/slackyd-0.1.13beta/src/net.c
index d9d4a90..51e219d 100644
--- slackyd-0.1.13beta/src/net.c
+++ slackyd-0.1.13beta/src/net.c
@@ -222,6 +222,24 @@ netstat (int init, time_t pause, unsigned long received, unsigned long filesz)

     return buffer;
 }
+
+int
+get_file_over_wget (net_t *netpolicy,bool is_http)
+{
+       char buffer[BUFFSIZE0];
+       int out;
+       if(is_http){
+               snprintf(buffer,BUFFSIZE, "/usr/bin/wget -O '%s' 'http://%s/%s'",netpolicy->destpath,netpolicy->hostname,netpolicy->srcpath);
+       }else{
+               snprintf(buffer,BUFFSIZE, "/usr/bin/wget -O '%s' 'ftp://%s/%s'",netpolicy->destpath,netpolicy->hostname,netpolicy->srcpath);
+       }
+       out=system(buffer);
+       if(out==0){
+               return shutdown_net_t(netpolicy, 0, NULL);
+       }else{
+               return shutdown_net_t(netpolicy, out, "Download Error!");
+       }
+}

 int
 get_file_over_http (net_t *netpolicy)
@@ -579,12 +597,21 @@ get_pkg (pkg_t *package)
     snprintf (netpolicy.srcpath,  BUFFSIZE, "%s/%s/%s", path, loc, name);
     snprintf (netpolicy.destpath, BUFFSIZE, "%s/%s", cache, name);

-    switch (REPOS[r].proto_t) {
-        case proto_http: return get_file_over_http (&netpolicy);  break;
-        case proto_ftp:  return get_file_over_ftp  (&netpolicy);  break;
-        case proto_file: return get_file_over_fs   (&netpolicy);  break;
-        default:   slassert (NULL);                               break;
-        }
+    if(opt.wget){
+           switch (REPOS[r].proto_t) {
+               case proto_http: return get_file_over_wget (&netpolicy,true);  break;
+               case proto_ftp:  return get_file_over_wget (&netpolicy,false);  break;
+               case proto_file: return get_file_over_fs   (&netpolicy);  break;
+               default:   slassert (NULL);                               break;
+           }
+    }else{
+           switch (REPOS[r].proto_t) {
+               case proto_http: return get_file_over_http (&netpolicy);  break;
+               case proto_ftp:  return get_file_over_ftp  (&netpolicy);  break;
+               case proto_file: return get_file_over_fs   (&netpolicy);  break;
+               default:   slassert (NULL);                               break;
+               }
+    }

     return -1;
 }
diff --git slackyd-0.1.13beta/src/packages.c b/Downloaded/slackyd-0.1.13beta/src/packages.c
index e796cf6..97d84ea 100644
--- slackyd-0.1.13beta/src/packages.c
+++ slackyd-0.1.13beta/src/packages.c
@@ -2499,13 +2499,21 @@ pkgsrc_get (pkg_t **packages[], unsigned *npackages)
                 currents[2]->s);

             filepath (netpolicy.destpath);
-
-            switch (proto) {
-                case proto_http: get_file_over_http (&netpolicy);  break;
-                case proto_ftp:  get_file_over_ftp  (&netpolicy);  break;
-                case proto_file: get_file_over_fs   (&netpolicy);  break;
+           if(opt.wget){
+               switch (proto) {
+                   case proto_http: get_file_over_wget (&netpolicy,true);  break;
+                   case proto_ftp:  get_file_over_wget (&netpolicy,false);  break;
+                   case proto_file: get_file_over_fs   (&netpolicy);  break;
+               default:   slassert (NULL);                               break;
+               }
+           }else{
+                switch (proto) {
+                    case proto_http: get_file_over_http (&netpolicy);  break;
+                    case proto_ftp:  get_file_over_ftp  (&netpolicy);  break;
+                    case proto_file: get_file_over_fs   (&netpolicy);  break;
                 default:   slassert (NULL);                        break;
-            }
+                }
+           }

             currents[0] = currents[0]->next;
             currents[1] = currents[1]->next;
diff --git slackyd-0.1.13beta/src/slackyd.h b/Downloaded/slackyd-0.1.13beta/src/slackyd.h
index 0ee747a..7161a9e 100644
--- slackyd-0.1.13beta/src/slackyd.h
+++ slackyd-0.1.13beta/src/slackyd.h
@@ -420,6 +420,8 @@ int check_elf_libs
         unsigned *n_missing_libs, char *tgz);

 /* net.c */
+int get_file_over_wget
+    (net_t *netpolicy, bool is_http);
 int get_file_over_http
     (net_t *netpolicy);
 int get_file_over_ftp
diff --git slackyd-0.1.13beta/src/update.c b/Downloaded/slackyd-0.1.13beta/src/update.c
index 2c73a94..208c9aa 100644
--- slackyd-0.1.13beta/src/update.c
+++ slackyd-0.1.13beta/src/update.c
@@ -280,13 +280,20 @@ update_get_file (unsigned index, branches branch, const char *file)
         break;

        }
-
-    switch (REPOS[index].proto_t)
-    {
-        case proto_http: return get_file_over_http (&netpolicy);  break;
-        case proto_ftp:  return get_file_over_ftp  (&netpolicy);  break;
-        case proto_file: return get_file_over_fs   (&netpolicy);  break;
-        default:   slassert (NULL);                               break;
+    if(opt.wget){
+            switch (REPOS[index].proto_t) {
+                case proto_http: return get_file_over_wget (&netpolicy,true);  break;
+                case proto_ftp:  return get_file_over_wget (&netpolicy,false);  break;
+                case proto_file: return get_file_over_fs   (&netpolicy);  break;
+                default:   slassert (NULL);                               break;
+            }
+    }else{
+            switch (REPOS[index].proto_t) {
+               case proto_http: return get_file_over_http (&netpolicy);  break;
+               case proto_ftp:  return get_file_over_ftp  (&netpolicy);  break;
+               case proto_file: return get_file_over_fs   (&netpolicy);  break;
+               default:   slassert (NULL);                               break;
+           }
     }

        return 0;

Al momento non gestisce il controllo per file già scaricati, ma almeno è possibile passare via proxy. Basta settare le variabili di ambiente http_proxy e ftp_proxy prima di lanciare slackyd -W

L'ho testata grossolanamente, quindi potrebbe contenere errori.


La metto in allegato perchè il copia/incolla non funge tanto bene.


Ciao,
01

Re: slackyd & proxy

Inviato: mer 21 ott 2009, 19:54
da Dani
Molto bene, ho dato una veloce lettura alla patch e sembra tutto corretto. E' un'ottima soluzione per aggirare l'attuale mancanza proxy.
Piu' tardi la applico al programma e faccio qualche test.
Grazie ;)

Re: slackyd & proxy

Inviato: mer 21 ott 2009, 21:44
da ZeroUno
pecca del fatto che slackyd -u -W non controlla se i file packages.txt&co sono più nuovi o gli stessi, per cui li scarica in ogni caso.

poi la soluzione con -W è stata un ripiego (che poi volevo usare -p che sta per proxy ma era già in uso). in verità la cosa corretta dovrebbe essere il mettere in slackyd.conf una direttiva ,ipo "usa proxy = on" e "usa il proxy = http://...:../" perchè altrimenti si rischia che wget non sappia quale usare. Anzi, la soluzione migliore (però non sò come si fa in C) è prelevare le variabili di ambiente http_proxy e ftp_proxy e usare wget se sono settate o usare il metodo interno se non settate.

Il vantaggio di -W a queste soluzioni è, però, il fatto di poter usarlo anche se non c'è proxy che da il vantaggio di avere la barra di scorrimento.

Oppure metterlo in slackyd.conf alla voce "usa wget = on/off" così tutti quelli che si sono fatti gli script basati su slackyd non devono modificarli. Si, secondo me questa potrebbe essere migliore come soluzione.

L'ultima alternativa è eliminare del tutto il downloader interno e lasciare solo wget :-D

Oppure lasci -W e buonanotte al secchio ;-)


Ah, oggi mi ha dato un errore non fatal con slackyd -W -b ... che non so da dove veniva; qualcosa tipo (in inglese) "non riesco a determinare il corrente cwd" in cui tale cwd dovrebbe essere /var/slacky/src/..., ma ha tranquillamente scaricato i file.

Ho verificato (cosa che non avevo fatto quando ho scritto la patch) che in caso di fallimento di wget dice correttamente "Download error" e va avanti con gli altri file.

Re: slackyd & proxy

Inviato: sab 24 ott 2009, 6:21
da Dani
ZeroUno ha scritto: Oppure metterlo in slackyd.conf alla voce "usa wget = on/off" così tutti quelli che si sono fatti gli script basati su slackyd non devono modificarli. Si, secondo me questa potrebbe essere migliore come soluzione.
viewtopic.php?f=20&t=22612&p=261023#p261023
Sistemato :thumbright: