+ url = "http://code.google.com/p/" url "/downloads/list"
+ d("googlecode url, mungled url to: " url)
+
+ } else if (url ~ /^http:\/\/pecl.php.net\/get\//) {
+ gsub("-.*", "", filename)
+ url = "http://pecl.php.net/package/" filename
+ d("pecl.php.net url, mungled url to: " url)
+
+ } else if (url ~/http:\/\/cdn.mysql.com\//) {
+ gsub("http:\/\/cdn.mysql.com\/", "", url)
+ url = "http://vesta.informatik.rwth-aachen.de/mysql/" url
+ d("mysql CDN, mungled url to: " url)
+
+ } else if (url ~ /^(http|https):\/\/launchpad\.net\/(.*)\//) {
+ gsub("^(http|https):\/\/launchpad\.net\/", "", url)
+ gsub("\/.*/", "", url)
+ url = "https://code.launchpad.net/" url "/+download"
+ d("main launchpad url, mungled url to: " url)
+
+ } else if (url ~ /^(http|https):\/\/edge\.launchpad\.net\/(.*)\//) {
+ gsub("^(http|https):\/\/edge\.launchpad\.net\/", "", url)
+ gsub("\/.*/", "", url)
+ url = "https://edge.launchpad.net/" url "/+download"
+ d("edge launchpad url, mungled url to: " url)
+
+ } else if (url ~ /^(http|https):\/\/github.com\/.*\/(.*)\/tarball\//) {
+ gsub("\/tarball\/.*", "/downloads", url)
+ d("github tarball url, mungled url to: " url)
+
+ } else if (url ~ /^(http|https):\/\/github.com\/.*\/(.*)\/archive\//) {
+ gsub("\/archive\/.*", "/tags", url)
+ d("github archive url, mungled url to: " url)
+
+ } else if (url ~ /^(http|https):\/\/bitbucket.org\/.*\/get\/.*/) {
+ # https://bitbucket.org/logilab/pylint/get/tip.tar.bz2 -> https://bitbucket.org/logilab/pylint/downloads
+ gsub("\/get\/.*", "/downloads", url)
+ d("github bitbucket url, mungled url to: " url)
+
+ } else if (url ~ /^(http|https):\/\/cgit\..*\/(.*)\/snapshot\//) {
+ gsub("\/snapshot\/.*", "/", url)
+ d("cgit snapshot tarball url, mungled url to: " url)
+
+ } else if (url ~ /^(http|https):\/\/www2\.aquamaniac\.de\/sites\/download\//) {
+ url = "http://www2.aquamaniac.de/sites/download/packages.php"
+ d("aquamaniac.de tarball url, mungled url to: " url)
+
+ } else if (url ~ /^(http|https):\/\/www.process-one.net\/downloads\/ejabberd\//) {
+ url = "http://www.process-one.net/en/ejabberd/archive/"
+ d("ejabberd tarball url, mungled url to: " url)
+
+ } else if (url ~ /^(http|https):\/\/llvm.org\/releases\//) {
+ url = "http://llvm.org/releases/download.html"
+ d("llvm tarball url, mungled url to: " url)
+
+ } else if (url ~ /^(http|https):\/\/download\.owncloud\.org\/community\//) {
+ url = "http://owncloud.org/changelog/"
+ d("owncloud tarball url, mungled url to: " url)
+
+ } else if (url ~ /^(http|https):\/\/hackage\.haskell\.org\/packages\/archive\//) {
+ gsub("\/packages\/archive","/package",url)
+ d("hackage haskell tarball url, mungled url to: " url)
+
+ } else if (url ~ /^http:\/\/www.taskwarrior.org\/download\//) {
+ url = "http://taskwarrior.org/projects/taskwarrior/wiki/Download"
+ d("taskwarrior tarball url, mungled url to: " url)
+ } else if (url ~/^http:\/\/www.rarlab.com\/rar\// && filename ~ /^unrarsrc/) {
+ url = "http://www.rarlab.com/rar_add.htm"
+ d("unrar tarball url, mungled url to: " url)
+ } else if (url ~/^http:\/\/www.rarlab.com\/rar\//) {
+ url = "http://www.rarlab.com/download.htm"
+ d("rar tarball url, mungled url to: " url)
+ }
+
+ d("Retrieving: " url)
+ user_agent = "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2) Gecko/20100129 PLD/3.0 (Th) Iceweasel/3.6"
+ cmd = "wget -t 2 -T 45 --user-agent \"" user_agent "\" -nv -O - \"" url "\" --passive-ftp --no-check-certificate > " tmpfile " 2> " tmpfileerr
+ d("Execute: " cmd)
+ errno = system(cmd)
+ d("Execute done")
+
+ if (errno != 0) {
+ d("Reading failure response...")
+ wholeerr = ""
+ while (getline oneline < tmpfileerr)
+ wholeerr = (wholeerr " " oneline)
+ d("Error Response: " wholeerr)
+
+ system("rm -f " tmpfile)
+ system("rm -f " tmpfileerr)
+ retval = ("WGET ERROR: " errno ": " wholeerr)
+ return retval