Op verzoek van Tim ook file:// urls aankunnen

This commit is contained in:
Ward Wouts 2009-03-02 08:27:44 +00:00
parent d80217a5e9
commit 3305750de2

View file

@ -160,37 +160,48 @@ end
def fetch(uri_str, limit = 10) def fetch(uri_str, limit = 10)
# You should choose better exception. # You should choose better exception.
raise ArgumentError, 'HTTP redirect too deep' if limit == 0 raise ArgumentError, 'HTTP redirect too deep' if limit == 0
if URI.parse(uri_str).scheme.to_s == "file"
host = URI.parse(uri_str).host response = ""
port = URI.parse(uri_str).port if FileTest.exists?(URI.parse(uri_str).path)
path = URI.parse(uri_str).path File.open(URI.parse(uri_str).path).each_line{|line|
query = URI.parse(uri_str).query response += line
}
http = Net::HTTP.new(host, port) else
http.use_ssl = @use_ssl raise "Not found"
if query end
req = Net::HTTP::Get.new("#{URI.escape(path)}?#{URI.escape(query)}") response
else else
req = Net::HTTP::Get.new("#{URI.escape(path)}") host = URI.parse(uri_str).host
port = URI.parse(uri_str).port
path = URI.parse(uri_str).path
query = URI.parse(uri_str).query
http = Net::HTTP.new(host, port)
http.use_ssl = @use_ssl
if query
req = Net::HTTP::Get.new("#{URI.escape(path)}?#{URI.escape(query)}")
else
req = Net::HTTP::Get.new("#{URI.escape(path)}")
end
req.basic_auth @user, @pass
response = http.request(req)
case response
when Net::HTTPSuccess then response.body
when Net::HTTPRedirection then fetch(response['location'], limit - 1)
when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"
when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"
when Net::HTTPForbidden then puts "403 Forbidden #{uri_str}"
# when Net::HTTPNotFound then puts "404 Not Found #{uri_str}"
else
response.error!
end
end end
req.basic_auth @user, @pass end
response = http.request(req)
case response
when Net::HTTPSuccess then response
when Net::HTTPRedirection then fetch(response['location'], limit - 1)
when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"
when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"
when Net::HTTPForbidden then puts "403 Forbidden #{uri_str}"
i# when Net::HTTPNotFound then puts "404 Not Found #{uri_str}"
else
response.error!
end
end
def svnparse(url) def svnparse(url)
puts "\n#{url}" puts "\n#{url}"
begin begin
body = fetch("#{url}/.svn/entries").body body = fetch("#{url}/.svn/entries")
rescue rescue
end end
if body.nil? if body.nil?
@ -255,7 +266,7 @@ def cvsparse(url)
puts "\n#{url}" puts "\n#{url}"
body=[] body=[]
begin begin
body = fetch("#{url}/CVS/Entries").body body = fetch("#{url}/CVS/Entries")
rescue rescue
end end
if body.nil? if body.nil?
@ -281,7 +292,7 @@ def dsparse(url)
ds = DSParse.new ds = DSParse.new
dirs = Array.new dirs = Array.new
begin begin
body = fetch("#{url}/.DS_Store").body body = fetch("#{url}/.DS_Store")
rescue rescue
end end
if body.nil? if body.nil?
@ -298,7 +309,7 @@ def dsparse(url)
if entries[x] == '.' or entries[x] == '..' if entries[x] == '.' or entries[x] == '..'
next next
end end
body = fetch("#{url}/#{entries[x]}/.DS_Store").body body = fetch("#{url}/#{entries[x]}/.DS_Store")
dscheck = DSParse.new dscheck = DSParse.new
dscheck.readstring(body) dscheck.readstring(body)
if dscheck.isds? if dscheck.isds?
@ -317,7 +328,7 @@ end
def checksvn(url) def checksvn(url)
begin begin
puts "===================================================" puts "==================================================="
body = fetch("#{url}/.svn/entries").body body = fetch("#{url}/.svn/entries")
puts "Subversion info found:" puts "Subversion info found:"
svnparse(url) svnparse(url)
rescue rescue
@ -327,7 +338,7 @@ end
def checkcvs(url) def checkcvs(url)
begin begin
puts "===================================================" puts "==================================================="
body = fetch("#{url}/CVS/Entries").body body = fetch("#{url}/CVS/Entries")
puts "CVS info found:" puts "CVS info found:"
cvsparse(url) cvsparse(url)
rescue rescue
@ -337,7 +348,7 @@ end
def checkds(url) def checkds(url)
begin begin
puts "===================================================" puts "==================================================="
body = fetch("#{url}/.DS_Store").body body = fetch("#{url}/.DS_Store")
puts ".DS_Store file found:" puts ".DS_Store file found:"
dsparse(url) dsparse(url)
rescue rescue
@ -348,7 +359,7 @@ options = cmdline
if options["-u"].nil? if options["-u"].nil?
usage usage
else else
if ! options["-u"].match(/^http/) if ! options["-u"].match(/^(http|file)/)
options["-u"] = "http://#{options["-u"]}" options["-u"] = "http://#{options["-u"]}"
end end
end end