diff options
author | wew <wew@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-29 03:52:24 +0000 |
---|---|---|
committer | wew <wew@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-29 03:52:24 +0000 |
commit | 22a5aec4b322c1be9eced78967e5cfd0ae54b6cb () | |
tree | 6605cba04fac7043d2764b1ab917a1c3dab0fa02 /lib/cgi/session.rb | |
parent | 11f521b98e276262e140f1a40469c910267a7021 (diff) |
Add documentation in RDoc format.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | lib/cgi/session.rb | 282 |
1 files changed, 278 insertions, 4 deletions
@@ -1,21 +1,175 @@ # Copyright (C) 2001 Yukihiro "Matz" Matsumoto # Copyright (C) 2000 Network Applied Communication Laboratory, Inc. # Copyright (C) 2000 Information-technology Promotion Agency, Japan require 'cgi' require 'tmpdir' class CGI class Session attr_reader :session_id - def Session::callback(dbman) lambda{ dbman[0].close unless dbman.empty? } end def Session::create_new_id require 'digest/md5' md5 = Digest::MD5::new @@ -26,6 +180,62 @@ class CGI md5.hexdigest[0,16] end def initialize(request, option={}) session_key = option['session_key'] || '_session_id' id = option['session_id'] @@ -73,6 +283,7 @@ class CGI ObjectSpace::define_finalizer(self, Session::callback(@dbprot)) end def [](key) unless @data @data = @dbman.restore @@ -80,6 +291,7 @@ class CGI @data[key] end def []=(key, val) unless @write_lock @write_lock = true @@ -90,25 +302,61 @@ class CGI @data[key] = val end - def update @dbman.update end def close @dbman.close @dbprot.clear end def delete @dbman.delete @dbprot.clear end class FileStore - def check_id(id) /[^0-9a-zA-Z]/ =~ id.to_s ? false : true end def initialize(session, option={}) dir = option['tmpdir'] || Dir::tmpdir prefix = option['prefix'] || '' @@ -128,6 +376,9 @@ class CGI end end def restore unless @hash @hash = {} @@ -142,6 +393,7 @@ class CGI @hash end def update return unless @hash @f.rewind @@ -151,12 +403,14 @@ class CGI @f.truncate @f.tell end def close return if @f.closed? update @f.close end def delete path = @f.path @f.close @@ -164,26 +418,46 @@ class CGI end end class MemoryStore - GLOBAL_HASH_TABLE = {} def initialize(session, option=nil) @session_id = session.session_id GLOBAL_HASH_TABLE[@session_id] ||= {} end def restore GLOBAL_HASH_TABLE[@session_id] end def update # don't need to update; hash is shared end def close # don't need to close end def delete GLOBAL_HASH_TABLE.delete(@session_id) end |