Hi,

I originally subscribed to wget-patches but it looks pretty dead.

I've come up with this patch so that I could mirror my employer's
site, running Oracle Portal (yuk) down to regular old static html.

http://wlazlo.net/blog/file_download/3

Oracle portal make a big mess redirecting links such as /pls/home to
/portal/page?_pageid=33,1&_dad=portal&_schema=OSRPTLT

This patch does 2 things:

   * Saves the document using the original filename, before the redirect
   * If the page being saved does not have a dot in it's basename, it
will append "/index.html", thus allowing the original URL naming
scheme without further configuration of the target web server.

If someone thinks this patch is useful, let me know I'll clean it up,
test it, add appropriate command line options, documentation etc etc.

I know the code as it stands probably doesn't meet guidelines but I
was just scratching an itch here.

Cheers,
Matt.

--
Reclaim your digital rights, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d-- s: a- C++++ UL+++ P++ L+++++ E--- W+++ N o-- K w--
O M V- PS+++ PE Y PGP t+ 5 X++ R+ !tv b+++ DI- D++
G-- e* h-- r+ y+++++
------END GEEK CODE BLOCK------

http://wlazlo.net
diff -ru wget-1.10.2/src/retr.c wget-1.10.2.orig/src/retr.c
--- wget-1.10.2/src/retr.c	2005-06-26 01:07:11.000000000 +1000
+++ wget-1.10.2.orig/src/retr.c	2006-10-05 16:38:59.000000000 +1000
@@ -32,6 +32,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
+#include <libgen.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif /* HAVE_UNISTD_H */
@@ -582,6 +583,41 @@
 
 static char *getproxy PARAMS ((struct url *));
 
+/**
+ * Anything that doesn't have a dot in it's basename is translated thus:
+ * 	www.domain/pls/orhome => www.domain/pls/orhome/index.html
+ *
+ * Anything with a dot in the basename is unmolested:
+ * 	www.domain/pls/portal/stuff_about_crap.pdf => www.domain/pls/portal/stuff_about_crap.pdf
+ */
+
+static char* 
+apply_ora_logic (char *local_file)
+{
+  char* ret;
+  char* tmp;
+  static const char* pagename = "/index.html";
+  unsigned int len;
+  int mangle = 1;
+  
+  tmp = xstrdup(local_file); 
+  const char *bname = basename (tmp);
+  if (index (bname, '.'))
+    mangle = 0;
+  xfree (tmp);
+
+  if (!mangle)
+    ret = xstrdup(local_file);
+  else {
+    len = strlen (local_file) + strlen (pagename) + 1;
+    ret = xmalloc0 (len);
+    strcat (ret, local_file);
+    strcat (ret, pagename);
+  }
+
+  return ret;
+}
+
 /* Retrieve the given URL.  Decides which loop to call -- HTTP, FTP,
    FTP, proxy, etc.  */
 
@@ -600,6 +636,7 @@
   int up_error_code;		/* url parse error code */
   char *local_file;
   int redirection_count = 0;
+  char *ora_saveloc = 0;
 
   int post_data_suspended = 0;
   char *saved_post_data = NULL;
@@ -664,7 +701,11 @@
 #endif
       || (proxy_url && proxy_url->scheme == SCHEME_HTTP))
     {
-      result = http_loop (u, &mynewloc, &local_file, refurl, dt, proxy_url);
+      result = http_loop (u, &mynewloc, (ora_saveloc ? &ora_saveloc : &local_file), refurl, dt, proxy_url);
+      if (ora_saveloc == 0) 
+        {
+          ora_saveloc = apply_ora_logic(local_file);
+        }
     }
   else if (u->scheme == SCHEME_FTP)
     {
@@ -763,6 +804,13 @@
       goto redirected;
     }
 
+  if (ora_saveloc)
+    {
+      if (local_file)
+        xfree (local_file);
+      local_file = ora_saveloc;
+    }
+
   if (local_file)
     {
       if (*dt & RETROKF)

Reply via email to