Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/cgi
File: session.rb
# frozen_string_literal: true
[0] Fix | Delete
#
[1] Fix | Delete
# cgi/session.rb - session support for cgi scripts
[2] Fix | Delete
#
[3] Fix | Delete
# Copyright (C) 2001 Yukihiro "Matz" Matsumoto
[4] Fix | Delete
# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
[5] Fix | Delete
# Copyright (C) 2000 Information-technology Promotion Agency, Japan
[6] Fix | Delete
#
[7] Fix | Delete
# Author: Yukihiro "Matz" Matsumoto
[8] Fix | Delete
#
[9] Fix | Delete
# Documentation: William Webber (william@williamwebber.com)
[10] Fix | Delete
[11] Fix | Delete
require 'cgi'
[12] Fix | Delete
require 'tmpdir'
[13] Fix | Delete
[14] Fix | Delete
class CGI
[15] Fix | Delete
[16] Fix | Delete
# == Overview
[17] Fix | Delete
#
[18] Fix | Delete
# This file provides the CGI::Session class, which provides session
[19] Fix | Delete
# support for CGI scripts. A session is a sequence of HTTP requests
[20] Fix | Delete
# and responses linked together and associated with a single client.
[21] Fix | Delete
# Information associated with the session is stored
[22] Fix | Delete
# on the server between requests. A session id is passed between client
[23] Fix | Delete
# and server with every request and response, transparently
[24] Fix | Delete
# to the user. This adds state information to the otherwise stateless
[25] Fix | Delete
# HTTP request/response protocol.
[26] Fix | Delete
#
[27] Fix | Delete
# == Lifecycle
[28] Fix | Delete
#
[29] Fix | Delete
# A CGI::Session instance is created from a CGI object. By default,
[30] Fix | Delete
# this CGI::Session instance will start a new session if none currently
[31] Fix | Delete
# exists, or continue the current session for this client if one does
[32] Fix | Delete
# exist. The +new_session+ option can be used to either always or
[33] Fix | Delete
# never create a new session. See #new() for more details.
[34] Fix | Delete
#
[35] Fix | Delete
# #delete() deletes a session from session storage. It
[36] Fix | Delete
# does not however remove the session id from the client. If the client
[37] Fix | Delete
# makes another request with the same id, the effect will be to start
[38] Fix | Delete
# a new session with the old session's id.
[39] Fix | Delete
#
[40] Fix | Delete
# == Setting and retrieving session data.
[41] Fix | Delete
#
[42] Fix | Delete
# The Session class associates data with a session as key-value pairs.
[43] Fix | Delete
# This data can be set and retrieved by indexing the Session instance
[44] Fix | Delete
# using '[]', much the same as hashes (although other hash methods
[45] Fix | Delete
# are not supported).
[46] Fix | Delete
#
[47] Fix | Delete
# When session processing has been completed for a request, the
[48] Fix | Delete
# session should be closed using the close() method. This will
[49] Fix | Delete
# store the session's state to persistent storage. If you want
[50] Fix | Delete
# to store the session's state to persistent storage without
[51] Fix | Delete
# finishing session processing for this request, call the update()
[52] Fix | Delete
# method.
[53] Fix | Delete
#
[54] Fix | Delete
# == Storing session state
[55] Fix | Delete
#
[56] Fix | Delete
# The caller can specify what form of storage to use for the session's
[57] Fix | Delete
# data with the +database_manager+ option to CGI::Session::new. The
[58] Fix | Delete
# following storage classes are provided as part of the standard library:
[59] Fix | Delete
#
[60] Fix | Delete
# CGI::Session::FileStore:: stores data as plain text in a flat file. Only
[61] Fix | Delete
# works with String data. This is the default
[62] Fix | Delete
# storage type.
[63] Fix | Delete
# CGI::Session::MemoryStore:: stores data in an in-memory hash. The data
[64] Fix | Delete
# only persists for as long as the current Ruby
[65] Fix | Delete
# interpreter instance does.
[66] Fix | Delete
# CGI::Session::PStore:: stores data in Marshalled format. Provided by
[67] Fix | Delete
# cgi/session/pstore.rb. Supports data of any type,
[68] Fix | Delete
# and provides file-locking and transaction support.
[69] Fix | Delete
#
[70] Fix | Delete
# Custom storage types can also be created by defining a class with
[71] Fix | Delete
# the following methods:
[72] Fix | Delete
#
[73] Fix | Delete
# new(session, options)
[74] Fix | Delete
# restore # returns hash of session data.
[75] Fix | Delete
# update
[76] Fix | Delete
# close
[77] Fix | Delete
# delete
[78] Fix | Delete
#
[79] Fix | Delete
# Changing storage type mid-session does not work. Note in particular
[80] Fix | Delete
# that by default the FileStore and PStore session data files have the
[81] Fix | Delete
# same name. If your application switches from one to the other without
[82] Fix | Delete
# making sure that filenames will be different
[83] Fix | Delete
# and clients still have old sessions lying around in cookies, then
[84] Fix | Delete
# things will break nastily!
[85] Fix | Delete
#
[86] Fix | Delete
# == Maintaining the session id.
[87] Fix | Delete
#
[88] Fix | Delete
# Most session state is maintained on the server. However, a session
[89] Fix | Delete
# id must be passed backwards and forwards between client and server
[90] Fix | Delete
# to maintain a reference to this session state.
[91] Fix | Delete
#
[92] Fix | Delete
# The simplest way to do this is via cookies. The CGI::Session class
[93] Fix | Delete
# provides transparent support for session id communication via cookies
[94] Fix | Delete
# if the client has cookies enabled.
[95] Fix | Delete
#
[96] Fix | Delete
# If the client has cookies disabled, the session id must be included
[97] Fix | Delete
# as a parameter of all requests sent by the client to the server. The
[98] Fix | Delete
# CGI::Session class in conjunction with the CGI class will transparently
[99] Fix | Delete
# add the session id as a hidden input field to all forms generated
[100] Fix | Delete
# using the CGI#form() HTML generation method. No built-in support is
[101] Fix | Delete
# provided for other mechanisms, such as URL re-writing. The caller is
[102] Fix | Delete
# responsible for extracting the session id from the session_id
[103] Fix | Delete
# attribute and manually encoding it in URLs and adding it as a hidden
[104] Fix | Delete
# input to HTML forms created by other mechanisms. Also, session expiry
[105] Fix | Delete
# is not automatically handled.
[106] Fix | Delete
#
[107] Fix | Delete
# == Examples of use
[108] Fix | Delete
#
[109] Fix | Delete
# === Setting the user's name
[110] Fix | Delete
#
[111] Fix | Delete
# require 'cgi'
[112] Fix | Delete
# require 'cgi/session'
[113] Fix | Delete
# require 'cgi/session/pstore' # provides CGI::Session::PStore
[114] Fix | Delete
#
[115] Fix | Delete
# cgi = CGI.new("html4")
[116] Fix | Delete
#
[117] Fix | Delete
# session = CGI::Session.new(cgi,
[118] Fix | Delete
# 'database_manager' => CGI::Session::PStore, # use PStore
[119] Fix | Delete
# 'session_key' => '_rb_sess_id', # custom session key
[120] Fix | Delete
# 'session_expires' => Time.now + 30 * 60, # 30 minute timeout
[121] Fix | Delete
# 'prefix' => 'pstore_sid_') # PStore option
[122] Fix | Delete
# if cgi.has_key?('user_name') and cgi['user_name'] != ''
[123] Fix | Delete
# # coerce to String: cgi[] returns the
[124] Fix | Delete
# # string-like CGI::QueryExtension::Value
[125] Fix | Delete
# session['user_name'] = cgi['user_name'].to_s
[126] Fix | Delete
# elsif !session['user_name']
[127] Fix | Delete
# session['user_name'] = "guest"
[128] Fix | Delete
# end
[129] Fix | Delete
# session.close
[130] Fix | Delete
#
[131] Fix | Delete
# === Creating a new session safely
[132] Fix | Delete
#
[133] Fix | Delete
# require 'cgi'
[134] Fix | Delete
# require 'cgi/session'
[135] Fix | Delete
#
[136] Fix | Delete
# cgi = CGI.new("html4")
[137] Fix | Delete
#
[138] Fix | Delete
# # We make sure to delete an old session if one exists,
[139] Fix | Delete
# # not just to free resources, but to prevent the session
[140] Fix | Delete
# # from being maliciously hijacked later on.
[141] Fix | Delete
# begin
[142] Fix | Delete
# session = CGI::Session.new(cgi, 'new_session' => false)
[143] Fix | Delete
# session.delete
[144] Fix | Delete
# rescue ArgumentError # if no old session
[145] Fix | Delete
# end
[146] Fix | Delete
# session = CGI::Session.new(cgi, 'new_session' => true)
[147] Fix | Delete
# session.close
[148] Fix | Delete
#
[149] Fix | Delete
class Session
[150] Fix | Delete
[151] Fix | Delete
class NoSession < RuntimeError #:nodoc:
[152] Fix | Delete
end
[153] Fix | Delete
[154] Fix | Delete
# The id of this session.
[155] Fix | Delete
attr_reader :session_id, :new_session
[156] Fix | Delete
[157] Fix | Delete
def Session::callback(dbman) #:nodoc:
[158] Fix | Delete
Proc.new{
[159] Fix | Delete
dbman[0].close unless dbman.empty?
[160] Fix | Delete
}
[161] Fix | Delete
end
[162] Fix | Delete
[163] Fix | Delete
# Create a new session id.
[164] Fix | Delete
#
[165] Fix | Delete
# The session id is a secure random number by SecureRandom
[166] Fix | Delete
# if possible, otherwise an SHA512 hash based upon the time,
[167] Fix | Delete
# a random number, and a constant string. This routine is
[168] Fix | Delete
# used internally for automatically generated session ids.
[169] Fix | Delete
def create_new_id
[170] Fix | Delete
require 'securerandom'
[171] Fix | Delete
begin
[172] Fix | Delete
# by OpenSSL, or system provided entropy pool
[173] Fix | Delete
session_id = SecureRandom.hex(16)
[174] Fix | Delete
rescue NotImplementedError
[175] Fix | Delete
# never happens on modern systems
[176] Fix | Delete
require 'digest'
[177] Fix | Delete
d = Digest('SHA512').new
[178] Fix | Delete
now = Time::now
[179] Fix | Delete
d.update(now.to_s)
[180] Fix | Delete
d.update(String(now.usec))
[181] Fix | Delete
d.update(String(rand(0)))
[182] Fix | Delete
d.update(String($$))
[183] Fix | Delete
d.update('foobar')
[184] Fix | Delete
session_id = d.hexdigest[0, 32]
[185] Fix | Delete
end
[186] Fix | Delete
session_id
[187] Fix | Delete
end
[188] Fix | Delete
private :create_new_id
[189] Fix | Delete
[190] Fix | Delete
# Create a new CGI::Session object for +request+.
[191] Fix | Delete
#
[192] Fix | Delete
# +request+ is an instance of the +CGI+ class (see cgi.rb).
[193] Fix | Delete
# +option+ is a hash of options for initialising this
[194] Fix | Delete
# CGI::Session instance. The following options are
[195] Fix | Delete
# recognised:
[196] Fix | Delete
#
[197] Fix | Delete
# session_key:: the parameter name used for the session id.
[198] Fix | Delete
# Defaults to '_session_id'.
[199] Fix | Delete
# session_id:: the session id to use. If not provided, then
[200] Fix | Delete
# it is retrieved from the +session_key+ parameter
[201] Fix | Delete
# of the request, or automatically generated for
[202] Fix | Delete
# a new session.
[203] Fix | Delete
# new_session:: if true, force creation of a new session. If not set,
[204] Fix | Delete
# a new session is only created if none currently
[205] Fix | Delete
# exists. If false, a new session is never created,
[206] Fix | Delete
# and if none currently exists and the +session_id+
[207] Fix | Delete
# option is not set, an ArgumentError is raised.
[208] Fix | Delete
# database_manager:: the name of the class providing storage facilities
[209] Fix | Delete
# for session state persistence. Built-in support
[210] Fix | Delete
# is provided for +FileStore+ (the default),
[211] Fix | Delete
# +MemoryStore+, and +PStore+ (from
[212] Fix | Delete
# cgi/session/pstore.rb). See the documentation for
[213] Fix | Delete
# these classes for more details.
[214] Fix | Delete
#
[215] Fix | Delete
# The following options are also recognised, but only apply if the
[216] Fix | Delete
# session id is stored in a cookie.
[217] Fix | Delete
#
[218] Fix | Delete
# session_expires:: the time the current session expires, as a
[219] Fix | Delete
# +Time+ object. If not set, the session will terminate
[220] Fix | Delete
# when the user's browser is closed.
[221] Fix | Delete
# session_domain:: the hostname domain for which this session is valid.
[222] Fix | Delete
# If not set, defaults to the hostname of the server.
[223] Fix | Delete
# session_secure:: if +true+, this session will only work over HTTPS.
[224] Fix | Delete
# session_path:: the path for which this session applies. Defaults
[225] Fix | Delete
# to the directory of the CGI script.
[226] Fix | Delete
#
[227] Fix | Delete
# +option+ is also passed on to the session storage class initializer; see
[228] Fix | Delete
# the documentation for each session storage class for the options
[229] Fix | Delete
# they support.
[230] Fix | Delete
#
[231] Fix | Delete
# The retrieved or created session is automatically added to +request+
[232] Fix | Delete
# as a cookie, and also to its +output_hidden+ table, which is used
[233] Fix | Delete
# to add hidden input elements to forms.
[234] Fix | Delete
#
[235] Fix | Delete
# *WARNING* the +output_hidden+
[236] Fix | Delete
# fields are surrounded by a <fieldset> tag in HTML 4 generation, which
[237] Fix | Delete
# is _not_ invisible on many browsers; you may wish to disable the
[238] Fix | Delete
# use of fieldsets with code similar to the following
[239] Fix | Delete
# (see http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/37805)
[240] Fix | Delete
#
[241] Fix | Delete
# cgi = CGI.new("html4")
[242] Fix | Delete
# class << cgi
[243] Fix | Delete
# undef_method :fieldset
[244] Fix | Delete
# end
[245] Fix | Delete
#
[246] Fix | Delete
def initialize(request, option={})
[247] Fix | Delete
@new_session = false
[248] Fix | Delete
session_key = option['session_key'] || '_session_id'
[249] Fix | Delete
session_id = option['session_id']
[250] Fix | Delete
unless session_id
[251] Fix | Delete
if option['new_session']
[252] Fix | Delete
session_id = create_new_id
[253] Fix | Delete
@new_session = true
[254] Fix | Delete
end
[255] Fix | Delete
end
[256] Fix | Delete
unless session_id
[257] Fix | Delete
if request.key?(session_key)
[258] Fix | Delete
session_id = request[session_key]
[259] Fix | Delete
session_id = session_id.read if session_id.respond_to?(:read)
[260] Fix | Delete
end
[261] Fix | Delete
unless session_id
[262] Fix | Delete
session_id, = request.cookies[session_key]
[263] Fix | Delete
end
[264] Fix | Delete
unless session_id
[265] Fix | Delete
unless option.fetch('new_session', true)
[266] Fix | Delete
raise ArgumentError, "session_key `%s' should be supplied"%session_key
[267] Fix | Delete
end
[268] Fix | Delete
session_id = create_new_id
[269] Fix | Delete
@new_session = true
[270] Fix | Delete
end
[271] Fix | Delete
end
[272] Fix | Delete
@session_id = session_id
[273] Fix | Delete
dbman = option['database_manager'] || FileStore
[274] Fix | Delete
begin
[275] Fix | Delete
@dbman = dbman::new(self, option)
[276] Fix | Delete
rescue NoSession
[277] Fix | Delete
unless option.fetch('new_session', true)
[278] Fix | Delete
raise ArgumentError, "invalid session_id `%s'"%session_id
[279] Fix | Delete
end
[280] Fix | Delete
session_id = @session_id = create_new_id unless session_id
[281] Fix | Delete
@new_session=true
[282] Fix | Delete
retry
[283] Fix | Delete
end
[284] Fix | Delete
request.instance_eval do
[285] Fix | Delete
@output_hidden = {session_key => session_id} unless option['no_hidden']
[286] Fix | Delete
@output_cookies = [
[287] Fix | Delete
Cookie::new("name" => session_key,
[288] Fix | Delete
"value" => session_id,
[289] Fix | Delete
"expires" => option['session_expires'],
[290] Fix | Delete
"domain" => option['session_domain'],
[291] Fix | Delete
"secure" => option['session_secure'],
[292] Fix | Delete
"path" =>
[293] Fix | Delete
if option['session_path']
[294] Fix | Delete
option['session_path']
[295] Fix | Delete
elsif ENV["SCRIPT_NAME"]
[296] Fix | Delete
File::dirname(ENV["SCRIPT_NAME"])
[297] Fix | Delete
else
[298] Fix | Delete
""
[299] Fix | Delete
end)
[300] Fix | Delete
] unless option['no_cookies']
[301] Fix | Delete
end
[302] Fix | Delete
@dbprot = [@dbman]
[303] Fix | Delete
ObjectSpace::define_finalizer(self, Session::callback(@dbprot))
[304] Fix | Delete
end
[305] Fix | Delete
[306] Fix | Delete
# Retrieve the session data for key +key+.
[307] Fix | Delete
def [](key)
[308] Fix | Delete
@data ||= @dbman.restore
[309] Fix | Delete
@data[key]
[310] Fix | Delete
end
[311] Fix | Delete
[312] Fix | Delete
# Set the session data for key +key+.
[313] Fix | Delete
def []=(key, val)
[314] Fix | Delete
@write_lock ||= true
[315] Fix | Delete
@data ||= @dbman.restore
[316] Fix | Delete
@data[key] = val
[317] Fix | Delete
end
[318] Fix | Delete
[319] Fix | Delete
# Store session data on the server. For some session storage types,
[320] Fix | Delete
# this is a no-op.
[321] Fix | Delete
def update
[322] Fix | Delete
@dbman.update
[323] Fix | Delete
end
[324] Fix | Delete
[325] Fix | Delete
# Store session data on the server and close the session storage.
[326] Fix | Delete
# For some session storage types, this is a no-op.
[327] Fix | Delete
def close
[328] Fix | Delete
@dbman.close
[329] Fix | Delete
@dbprot.clear
[330] Fix | Delete
end
[331] Fix | Delete
[332] Fix | Delete
# Delete the session from storage. Also closes the storage.
[333] Fix | Delete
#
[334] Fix | Delete
# Note that the session's data is _not_ automatically deleted
[335] Fix | Delete
# upon the session expiring.
[336] Fix | Delete
def delete
[337] Fix | Delete
@dbman.delete
[338] Fix | Delete
@dbprot.clear
[339] Fix | Delete
end
[340] Fix | Delete
[341] Fix | Delete
# File-based session storage class.
[342] Fix | Delete
#
[343] Fix | Delete
# Implements session storage as a flat file of 'key=value' values.
[344] Fix | Delete
# This storage type only works directly with String values; the
[345] Fix | Delete
# user is responsible for converting other types to Strings when
[346] Fix | Delete
# storing and from Strings when retrieving.
[347] Fix | Delete
class FileStore
[348] Fix | Delete
# Create a new FileStore instance.
[349] Fix | Delete
#
[350] Fix | Delete
# This constructor is used internally by CGI::Session. The
[351] Fix | Delete
# user does not generally need to call it directly.
[352] Fix | Delete
#
[353] Fix | Delete
# +session+ is the session for which this instance is being
[354] Fix | Delete
# created. The session id must only contain alphanumeric
[355] Fix | Delete
# characters; automatically generated session ids observe
[356] Fix | Delete
# this requirement.
[357] Fix | Delete
#
[358] Fix | Delete
# +option+ is a hash of options for the initializer. The
[359] Fix | Delete
# following options are recognised:
[360] Fix | Delete
#
[361] Fix | Delete
# tmpdir:: the directory to use for storing the FileStore
[362] Fix | Delete
# file. Defaults to Dir::tmpdir (generally "/tmp"
[363] Fix | Delete
# on Unix systems).
[364] Fix | Delete
# prefix:: the prefix to add to the session id when generating
[365] Fix | Delete
# the filename for this session's FileStore file.
[366] Fix | Delete
# Defaults to "cgi_sid_".
[367] Fix | Delete
# suffix:: the prefix to add to the session id when generating
[368] Fix | Delete
# the filename for this session's FileStore file.
[369] Fix | Delete
# Defaults to the empty string.
[370] Fix | Delete
#
[371] Fix | Delete
# This session's FileStore file will be created if it does
[372] Fix | Delete
# not exist, or opened if it does.
[373] Fix | Delete
def initialize(session, option={})
[374] Fix | Delete
dir = option['tmpdir'] || Dir::tmpdir
[375] Fix | Delete
prefix = option['prefix'] || 'cgi_sid_'
[376] Fix | Delete
suffix = option['suffix'] || ''
[377] Fix | Delete
id = session.session_id
[378] Fix | Delete
require 'digest/md5'
[379] Fix | Delete
md5 = Digest::MD5.hexdigest(id)[0,16]
[380] Fix | Delete
@path = dir+"/"+prefix+md5+suffix
[381] Fix | Delete
if File::exist? @path
[382] Fix | Delete
@hash = nil
[383] Fix | Delete
else
[384] Fix | Delete
unless session.new_session
[385] Fix | Delete
raise CGI::Session::NoSession, "uninitialized session"
[386] Fix | Delete
end
[387] Fix | Delete
@hash = {}
[388] Fix | Delete
end
[389] Fix | Delete
end
[390] Fix | Delete
[391] Fix | Delete
# Restore session state from the session's FileStore file.
[392] Fix | Delete
#
[393] Fix | Delete
# Returns the session state as a hash.
[394] Fix | Delete
def restore
[395] Fix | Delete
unless @hash
[396] Fix | Delete
@hash = {}
[397] Fix | Delete
begin
[398] Fix | Delete
lockf = File.open(@path+".lock", "r")
[399] Fix | Delete
lockf.flock File::LOCK_SH
[400] Fix | Delete
f = File.open(@path, 'r')
[401] Fix | Delete
for line in f
[402] Fix | Delete
line.chomp!
[403] Fix | Delete
k, v = line.split('=',2)
[404] Fix | Delete
@hash[CGI.unescape(k)] = Marshal.restore(CGI.unescape(v))
[405] Fix | Delete
end
[406] Fix | Delete
ensure
[407] Fix | Delete
f&.close
[408] Fix | Delete
lockf&.close
[409] Fix | Delete
end
[410] Fix | Delete
end
[411] Fix | Delete
@hash
[412] Fix | Delete
end
[413] Fix | Delete
[414] Fix | Delete
# Save session state to the session's FileStore file.
[415] Fix | Delete
def update
[416] Fix | Delete
return unless @hash
[417] Fix | Delete
begin
[418] Fix | Delete
lockf = File.open(@path+".lock", File::CREAT|File::RDWR, 0600)
[419] Fix | Delete
lockf.flock File::LOCK_EX
[420] Fix | Delete
f = File.open(@path+".new", File::CREAT|File::TRUNC|File::WRONLY, 0600)
[421] Fix | Delete
for k,v in @hash
[422] Fix | Delete
f.printf "%s=%s\n", CGI.escape(k), CGI.escape(String(Marshal.dump(v)))
[423] Fix | Delete
end
[424] Fix | Delete
f.close
[425] Fix | Delete
File.rename @path+".new", @path
[426] Fix | Delete
ensure
[427] Fix | Delete
f&.close
[428] Fix | Delete
lockf&.close
[429] Fix | Delete
end
[430] Fix | Delete
end
[431] Fix | Delete
[432] Fix | Delete
# Update and close the session's FileStore file.
[433] Fix | Delete
def close
[434] Fix | Delete
update
[435] Fix | Delete
end
[436] Fix | Delete
[437] Fix | Delete
# Close and delete the session's FileStore file.
[438] Fix | Delete
def delete
[439] Fix | Delete
File::unlink @path+".lock" rescue nil
[440] Fix | Delete
File::unlink @path+".new" rescue nil
[441] Fix | Delete
File::unlink @path rescue nil
[442] Fix | Delete
end
[443] Fix | Delete
end
[444] Fix | Delete
[445] Fix | Delete
# In-memory session storage class.
[446] Fix | Delete
#
[447] Fix | Delete
# Implements session storage as a global in-memory hash. Session
[448] Fix | Delete
# data will only persist for as long as the Ruby interpreter
[449] Fix | Delete
# instance does.
[450] Fix | Delete
class MemoryStore
[451] Fix | Delete
GLOBAL_HASH_TABLE = {} #:nodoc:
[452] Fix | Delete
[453] Fix | Delete
# Create a new MemoryStore instance.
[454] Fix | Delete
#
[455] Fix | Delete
# +session+ is the session this instance is associated with.
[456] Fix | Delete
# +option+ is a list of initialisation options. None are
[457] Fix | Delete
# currently recognized.
[458] Fix | Delete
def initialize(session, option=nil)
[459] Fix | Delete
@session_id = session.session_id
[460] Fix | Delete
unless GLOBAL_HASH_TABLE.key?(@session_id)
[461] Fix | Delete
unless session.new_session
[462] Fix | Delete
raise CGI::Session::NoSession, "uninitialized session"
[463] Fix | Delete
end
[464] Fix | Delete
GLOBAL_HASH_TABLE[@session_id] = {}
[465] Fix | Delete
end
[466] Fix | Delete
end
[467] Fix | Delete
[468] Fix | Delete
# Restore session state.
[469] Fix | Delete
#
[470] Fix | Delete
# Returns session data as a hash.
[471] Fix | Delete
def restore
[472] Fix | Delete
GLOBAL_HASH_TABLE[@session_id]
[473] Fix | Delete
end
[474] Fix | Delete
[475] Fix | Delete
# Update session state.
[476] Fix | Delete
#
[477] Fix | Delete
# A no-op.
[478] Fix | Delete
def update
[479] Fix | Delete
# don't need to update; hash is shared
[480] Fix | Delete
end
[481] Fix | Delete
[482] Fix | Delete
# Close session storage.
[483] Fix | Delete
#
[484] Fix | Delete
# A no-op.
[485] Fix | Delete
def close
[486] Fix | Delete
# don't need to close
[487] Fix | Delete
end
[488] Fix | Delete
[489] Fix | Delete
# Delete the session state.
[490] Fix | Delete
def delete
[491] Fix | Delete
GLOBAL_HASH_TABLE.delete(@session_id)
[492] Fix | Delete
end
[493] Fix | Delete
end
[494] Fix | Delete
[495] Fix | Delete
# Dummy session storage class.
[496] Fix | Delete
#
[497] Fix | Delete
# Implements session storage place holder. No actual storage
[498] Fix | Delete
# will be done.
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function