From e3056c880364f5cb79eb9280b4d34b34c3eb4f93 Mon Sep 17 00:00:00 2001 From: aamine Date: Fri, 2 May 2003 14:35:01 +0000 Subject: * lib/net/protocol.rb: remove Protocol class. * lib/net/smtp.rb (SMTP): ditto. * lib/net/pop.rb (POP3): ditto. * lib/net/http.rb (HTTP): ditto. * lib/net/protocol.rb: remove Command class. * lib/net/smtp.rb (SMTPCommand): ditto. * lib/net/pop.rb (POP3Command): ditto. * lib/net/pop.rb: remove APOPCommand class. * lib/net/protocol.rb: remove Code class and its all subclasses. * lib/net/protocol.rb: remove Response class and its all subclasses. * lib/net/pop.rb (POPMail): new method unique_id (alias uidl). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/net/protocol.rb | 343 +--------------------------------------------------- 1 file changed, 2 insertions(+), 341 deletions(-) (limited to 'lib/net/protocol.rb') diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb index 9da1ad8909..fd85771dd5 100644 --- a/lib/net/protocol.rb +++ b/lib/net/protocol.rb @@ -2,7 +2,8 @@ = net/protocol.rb -Copyright (c) 1999-2002 Yukihiro Matsumoto +Copyright (c) 1999-2003 Yukihiro Matsumoto +Copyright (c) 1999-2003 Minero Aoki written & maintained by Minero Aoki @@ -23,211 +24,6 @@ require 'timeout' module Net - class Protocol - - Version = '1.2.3' - Revision = '$Revision$'.slice(/[\d\.]+/) - - - class << self - - def port - default_port - end - - private - - def protocol_param( name, val ) - module_eval <<-EOS, __FILE__, __LINE__ + 1 - def self.#{name.id2name} - #{val} - end - EOS - end - - end - - - # - # --- Configuration Staffs for Sub Classes --- - # - # class method default_port - # class method command_type - # class method socket_type - # - # private method do_start - # private method do_finish - # - # private method conn_address - # private method conn_port - # - - - def Protocol.start( address, port = nil, *args ) - instance = new(address, port) - if block_given? - instance.start(*args) { - return yield(instance) - } - else - instance.start(*args) - instance - end - end - - def initialize( addr, port = nil ) - @address = addr - @port = port || self.class.default_port - - @command = nil - @socket = nil - - @started = false - - @open_timeout = 30 - @read_timeout = 60 - - @debug_output = nil - end - - attr_reader :address - attr_reader :port - - attr_reader :command - attr_reader :socket - - attr_accessor :open_timeout - - attr_reader :read_timeout - - def read_timeout=( sec ) - @socket.read_timeout = sec if @socket - @read_timeout = sec - end - - def started? - @started - end - - alias active? started? - - def set_debug_output( arg ) # un-documented - @debug_output = arg - end - - def inspect - "#<#{self.class} #{@address}:#{@port} open=#{active?}>" - end - - # - # open - # - - def start( *args ) - @started and raise IOError, 'protocol has been opened already' - - if block_given? - begin - do_start(*args) - @started = true - return yield(self) - ensure - finish if @started - end - end - - do_start(*args) - @started = true - self - end - - private - - # abstract do_start() - - def conn_socket - @socket = self.class.socket_type.open( - conn_address(), conn_port(), - @open_timeout, @read_timeout, @debug_output ) - on_connect - end - - alias conn_address address - alias conn_port port - - def reconn_socket - @socket.reopen @open_timeout - on_connect - end - - def conn_command - @command = self.class.command_type.new(@socket) - end - - def on_connect - end - - # - # close - # - - public - - def finish - raise IOError, 'closing already closed protocol' unless @started - do_finish - @started = false - nil - end - - private - - # abstract do_finish() - - def disconn_command - @command.quit if @command and not @command.critical? - @command = nil - end - - def disconn_socket - @socket.close if @socket and not @socket.closed? - @socket = nil - end - - end - - Session = Protocol - - - class Response - - def initialize( ctype, code, msg ) - @code_type = ctype - @code = code - @message = msg - super() - end - - attr_reader :code_type - attr_reader :code - attr_reader :message - alias msg message - - def inspect - "#<#{self.class} #{@code}>" - end - - def error! - raise error_type().new(code + ' ' + @message.dump, self) - end - - def error_type - @code_type.error_type - end - - end - - class ProtocolError < StandardError; end class ProtoSyntaxError < ProtocolError; end class ProtoFatalError < ProtocolError; end @@ -238,129 +34,6 @@ module Net class ProtoRetriableError < ProtocolError; end ProtocRetryError = ProtoRetriableError - class ProtocolError - - def initialize( msg, resp ) - super msg - @response = resp - end - - attr_reader :response - alias data response - - def inspect - "#<#{self.class} #{self.message}>" - end - - end - - - class Code - - def initialize( paren, err ) - @parents = [self] + paren - @error_type = err - end - - def parents - @parents.dup - end - - attr_reader :error_type - - def inspect - "#<#{self.class} #{sprintf '0x%x', __id__}>" - end - - def ===( response ) - response.code_type.parents.each do |c| - return true if c == self - end - false - end - - def mkchild( err = nil ) - self.class.new(@parents, err || @error_type) - end - - end - - ReplyCode = Code.new([], ProtoUnknownError) - InformationCode = ReplyCode.mkchild(ProtoUnknownError) - SuccessCode = ReplyCode.mkchild(ProtoUnknownError) - ContinueCode = ReplyCode.mkchild(ProtoUnknownError) - ErrorCode = ReplyCode.mkchild(ProtocolError) - SyntaxErrorCode = ErrorCode.mkchild(ProtoSyntaxError) - FatalErrorCode = ErrorCode.mkchild(ProtoFatalError) - ServerErrorCode = ErrorCode.mkchild(ProtoServerError) - AuthErrorCode = ErrorCode.mkchild(ProtoAuthError) - RetriableCode = ReplyCode.mkchild(ProtoRetriableError) - UnknownCode = ReplyCode.mkchild(ProtoUnknownError) - - - class Command - - def initialize( sock ) - @socket = sock - @last_reply = nil - @atomic = false - end - - attr_accessor :socket - attr_reader :last_reply - - def inspect - "#<#{self.class} socket=#{@socket.inspect} critical=#{@atomic}>" - end - - # abstract quit() - - private - - def check_reply( *oks ) - @last_reply = get_reply() - reply_must @last_reply, *oks - end - - # abstract get_reply() - - def reply_must( rep, *oks ) - oks.each do |i| - return rep if i === rep - end - rep.error! - end - - def getok( line, expect = SuccessCode ) - @socket.writeline line - check_reply expect - end - - # - # critical session - # - - public - - def critical? - @atomic - end - - def error_ok - @atomic = false - end - - private - - def atomic - @atomic = true - ret = yield - @atomic = false - ret - end - - end - class InternetMessageIO @@ -765,16 +438,4 @@ module Net end - - # for backward compatibility - module NetPrivate - Response = ::Net::Response - Command = ::Net::Command - Socket = ::Net::InternetMessageIO - BufferedSocket = ::Net::InternetMessageIO - WriteAdapter = ::Net::WriteAdapter - ReadAdapter = ::Net::ReadAdapter - end - BufferedSocket = ::Net::InternetMessageIO - end # module Net -- cgit v1.2.3