Changeset 6490

Show
Ignore:
Timestamp:
02/10/08 15:18:03 (5 years ago)
Author:
drry
Message:

lang/ruby/chokan/trunk/plugins/uri_information.rb
lang/ruby/chokan/trunk/config.yaml.sample: citrus ブランチとだいたい同じ。

Location:
lang/ruby/chokan/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/chokan/trunk/config.yaml.sample

    r1533 r6490  
    1919 
    2020  UriInformation: 
    21     accept_scheme: 
     21    accept_schemes: 
    2222      - http 
    2323      - https 
  • lang/ruby/chokan/trunk/plugins/uri_information.rb

    r5866 r6490  
    1010class UriInformation < Chokan::PluginBase 
    1111        MAX_REDIRECT = 10 
    12         HEADER       = { 
    13                 "User-Agent" => "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11", 
     12        HEADERS      = { 
     13                "User-Agent" => "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12", 
    1414                "Accept"     => "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", 
    1515        } 
    1616 
    17         def initialize(config, chokan) 
    18                 super 
    19                 @uri = /(#{URI.regexp(@config['accept_scheme']).to_s})/ 
    20         end 
    21  
    2217        def on_privmsg(prefix, channel, message) 
    2318                @channel = channel 
    24                 message.scan(@uri) do |uri| 
     19                URI.extract(messages, @config['accept_schemes'] || 
     20                                      @config['accept_scheme']) do |uri| 
    2521                        begin 
    26                                 uri = uri[0] 
    2722                                uri = URI(uri) 
    2823                                mes = nil 
     
    9590                        } 
    9691                        data = data.collect {|k,v| "#{k}=#{URI.escape(v, /[^-.!~*'()\w]/n)}" }.join("&") 
    97                         res = http.post(login_uri.request_uri, data, HEADER) 
     92                        res = http.post(login_uri.request_uri, data, HEADERS) 
    9893                        if res.key?("set-cookie") 
    9994                                res["set-cookie"].split(/\s*,\s*/).each do |c| 
     
    146141        end 
    147142 
    148         def http(uri, header=HEADER, limit=MAX_REDIRECT) 
     143        def http(uri, headers=HEADERS, limit=MAX_REDIRECT) 
    149144                return "Redirect loop?: last:#{uri}" if limit <= 0 
    150145 
     
    154149                http.use_ssl = (uri.scheme == "https") 
    155150                http.start do |http| 
    156                         r = http.head(uri.request_uri, header) 
     151                        r = http.head(uri.request_uri, headers) 
    157152                        log r.code.inspect 
    158153                        case r.code 
     
    160155                                case r["Content-Type"] 
    161156                                when /html/ 
    162                                         ret = html(http.get(uri.request_uri, header.merge({ 
     157                                        ret = html(http.get(uri.request_uri, headers.merge({ 
    163158                                                "Range" => "0-5000" 
    164159                                        }))) 
    165160                                when /image/ 
    166                                         ret = image(http.get(uri.request_uri, header)) 
     161                                        ret = image(http.get(uri.request_uri, headers)) 
    167162                                else 
    168163                                        if r["Content-Length"] 
     
    178173                                if auth 
    179174                                        auth = "Basic " + ["#{auth["user"]}:#{auth["pass"]}"].pack("m") 
    180                                         ret = http(uri, header.update({'Authorization' => auth}), limit-1) 
     175                                        ret = http(uri, headers.update({'Authorization' => auth}), limit-1) 
    181176                                else 
    182177                                        ret = realm 
     
    185180                                loc = URI(r["Location"]) 
    186181                                loc = uri + loc if loc.relative? 
    187                                 ret = http(loc, header, limit-1) 
     182                                ret = http(loc, headers, limit-1) 
    188183                        else 
    189184                                ret = "[#{r.code} #{r.message}]"