diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | lib/net/http.rb | 96 | ||||
-rw-r--r-- | lib/net/pop.rb | 25 | ||||
-rw-r--r-- | lib/net/protocol.rb | 145 | ||||
-rw-r--r-- | lib/net/smtp.rb | 12 |
5 files changed, 158 insertions, 129 deletions
@@ -1,3 +1,12 @@ +Wed Jul 12 15:04:11 2000 Minero Aoki <aamine@dp.u-netsurf.ne.jp> + + * lib/net/protocol.rb, smtp.rb, pop.rb, http.rb: 1.1.26. + + * lib/net/protocol.rb, smtp.rb, pop.rb, http.rb: + add module Net::NetPrivate and its inner classes + {Read,Write}Adapter, Command, Socket, + SMTPCommand, POP3Command, APOPCommand, HTTPCommand + Tue Jul 11 16:54:17 2000 Yukihiro Matsumoto <matz@netlab.co.jp> * parse.y (yylex): `@<digit>' is no longer a valid instance diff --git a/lib/net/http.rb b/lib/net/http.rb index 5e66f9dde..5a5917baa 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -1,6 +1,6 @@ =begin -= net/http.rb += net/http.rb version 1.1.27 maintained by Minero Aoki <aamine@dp.u-netsurf.ne.jp> This file is derived from "http-access.rb". @@ -25,8 +25,6 @@ You can freely distribute/modify this library. : port HTTP default port, 80 -: command_type - Command class for Net::HTTP, HTTPCommand == Methods @@ -116,9 +114,9 @@ You can freely distribute/modify this library. ex. - http.post2( '/index.html', 'data data data...' ) do |f| - f.header - f.body + http.post2( '/index.html', 'data data data...' ) do |adapter| + adapter.header + adapter.body end @@ -214,13 +212,13 @@ module Net class HTTP < Protocol protocol_param :port, '80' - protocol_param :command_type, '::Net::HTTPCommand' + protocol_param :command_type, '::Net::NetPrivate::HTTPCommand' class << self def procdest( dest, block ) if block then - return ReadAdapter.new( block ), nil + return NetPrivate::ReadAdapter.new( block ), nil else dest ||= '' return dest, dest @@ -420,43 +418,6 @@ module Net HTTPSession = HTTP - class HTTPReadAdapter - - def initialize( command ) - @command = command - @header = @body = nil - end - - def inspect - "#<#{type}>" - end - - def header - unless @header then - @header = @command.get_response - end - @header - end - alias response header - - def body( dest = nil, &block ) - dest, ret = HTTP.procdest( dest, block ) - unless @body then - @body = @command.get_body( response, dest ) - end - @body - end - alias entity body - - def off - body - @command = nil - @header - end - - end - - class HTTPResponse < Response def initialize( code_type, bexist, code, msg ) @@ -470,7 +431,7 @@ module Net attr_accessor :body def inspect - "#<Net::HTTPResponse #{code}>" + "#<#{type.name} #{code}>" end def []( key ) @@ -559,6 +520,47 @@ module Net HTTPVersionNotSupported = HTTPFatalErrorCode.mkchild + class HTTPReadAdapter + + def initialize( command ) + @command = command + @header = @body = nil + end + + def inspect + "#<#{type}>" + end + + def header + unless @header then + @header = @command.get_response + end + @header + end + alias response header + + def body( dest = nil, &block ) + dest, ret = HTTP.procdest( dest, block ) + unless @body then + @body = @command.get_body( response, dest ) + end + @body + end + alias entity body + + def off + body + @command = nil + @header + end + + end + + + + module NetPrivate + + class HTTPCommand < Command HTTPVersion = '1.1' @@ -819,4 +821,6 @@ module Net end + end # module Net::NetPrivate + end # module Net diff --git a/lib/net/pop.rb b/lib/net/pop.rb index df95bc0c3..01b2deaa8 100644 --- a/lib/net/pop.rb +++ b/lib/net/pop.rb @@ -1,6 +1,6 @@ =begin -= net/pop.rb += net/pop.rb version 1.1.27 written by Minero Aoki <aamine@dp.u-netsurf.ne.jp> @@ -117,7 +117,7 @@ module Net class POP3 < Protocol protocol_param :port, '110' - protocol_param :command_type, '::Net::POP3Command' + protocol_param :command_type, '::Net::NetPrivate::POP3Command' protocol_param :mail_type, '::Net::POPMail' @@ -155,6 +155,12 @@ module Net POP3Session = POP3 + class APOP < POP3 + protocol_param :command_type, 'Net::NetPrivate::APOPCommand' + end + + APOPSession = APOP + class POPMail @@ -174,7 +180,7 @@ module Net def all( dest = '' ) if iterator? then - dest = ReadAdapter.new( Proc.new ) + dest = NetPrivate::ReadAdapter.new( Proc.new ) end @command.retr( @num, dest ) end @@ -207,12 +213,7 @@ module Net - class APOP < POP3 - protocol_param :command_type, 'Net::APOPCommand' - end - - APOPSession = APOP - + module NetPrivate class POP3Command < Command @@ -311,7 +312,6 @@ module Net end - class APOPCommand < POP3Command def initialize( sock ) @@ -334,4 +334,7 @@ module Net end -end + + end # module Net::NetPrivate + +end # module Net diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb index 10bc8b0a1..b351c268b 100644 --- a/lib/net/protocol.rb +++ b/lib/net/protocol.rb @@ -1,6 +1,6 @@ =begin -= net/protocol.rb += net/protocol.rb version 1.1.27 written by Minero Aoki <aamine@dp.u-netsurf.ne.jp> @@ -64,7 +64,7 @@ module Net class Protocol - Version = '1.1.26' + Version = '1.1.27' class << self @@ -137,7 +137,7 @@ module Net protocol_param :port, 'nil' protocol_param :command_type, 'nil' - protocol_param :socket_type, '::Net::Socket' + protocol_param :socket_type, '::Net::NetPrivate::Socket' def initialize( addr = nil, port = nil ) @@ -220,72 +220,6 @@ module Net - class Command - - def initialize( sock ) - @socket = sock - @last_reply = nil - @critical = false - end - - attr_accessor :socket - attr_reader :last_reply - - def inspect - "#<#{type}>" - end - - # abstract quit - - - private - - # abstract get_reply() - - def check_reply( *oks ) - @last_reply = get_reply - reply_must( @last_reply, *oks ) - end - - def reply_must( rep, *oks ) - oks.each do |i| - if i === rep then - return rep - end - end - rep.error! - end - - def getok( line, ok = SuccessCode ) - @socket.writeline line - check_reply ok - end - - - def critical - return if @critical - @critical = true - r = yield - @critical = false - r - end - - def critical? - @critical - end - - def begin_critical - ret = @critical - @critical = true - not ret - end - - def end_critical - @critical = false - end - - end - class Response @@ -379,6 +313,9 @@ module Net + module NetPrivate + + class WriteAdapter def initialize( sock, mid ) @@ -414,6 +351,73 @@ module Net end + class Command + + def initialize( sock ) + @socket = sock + @last_reply = nil + @critical = false + end + + attr_accessor :socket + attr_reader :last_reply + + def inspect + "#<#{type}>" + end + + # abstract quit + + + private + + # abstract get_reply() + + def check_reply( *oks ) + @last_reply = get_reply + reply_must( @last_reply, *oks ) + end + + def reply_must( rep, *oks ) + oks.each do |i| + if i === rep then + return rep + end + end + rep.error! + end + + def getok( line, ok = SuccessCode ) + @socket.writeline line + check_reply ok + end + + + def critical + return if @critical + @critical = true + r = yield + @critical = false + r + end + + def critical? + @critical + end + + def begin_critical + ret = @critical + @critical = true + not ret + end + + def end_critical + @critical = false + end + + end + + class Socket def initialize( addr, port, pipe = nil ) @@ -756,6 +760,9 @@ module Net end + end # module Net::NetPrivate + + def Net.quote( str ) str = str.gsub( "\n", '\\n' ) str.gsub!( "\r", '\\r' ) diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb index 57e4116f2..0b4313c52 100644 --- a/lib/net/smtp.rb +++ b/lib/net/smtp.rb @@ -1,6 +1,6 @@ =begin -= net/smtp.rb += net/smtp.rb version 1.1.27 written by Minero Aoki <aamine@dp.u-netsurf.ne.jp> @@ -84,7 +84,7 @@ module Net class SMTP < Protocol protocol_param :port, '25' - protocol_param :command_type, '::Net::SMTPCommand' + protocol_param :command_type, '::Net::NetPrivate::SMTPCommand' def initialize( addr = nil, port = nil ) @@ -157,6 +157,9 @@ module Net + module NetPrivate + + class SMTPCommand < Command def initialize( sock ) @@ -286,4 +289,7 @@ module Net end -end + + end # module Net::NetPrivate + +end # module Net |