ruby-session-devel-cvs Mailing List for ruby-session: Got persistance?
Status: Alpha
Brought to you by:
thetitan
You can subscribe to this list here.
| 2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(14) |
Sep
(2) |
Oct
|
Nov
(5) |
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(13) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Sean C. <the...@us...> - 2002-06-25 01:53:48
|
Update of /cvsroot/ruby-session/ruby-session/src/apache
In directory usw-pr-cvs1:/tmp/cvs-serv5376
Modified Files:
session.rb
Log Message:
*) I'm not even going to venture to guess what it was that I didn't change,
but suffice it to say that a lot changed and this is only a snapshot for
backup purposes only.
Index: session.rb
===================================================================
RCS file: /cvsroot/ruby-session/ruby-session/src/apache/session.rb,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- session.rb 20 Jun 2002 13:46:50 -0000 1.4
+++ session.rb 25 Jun 2002 01:53:45 -0000 1.5
@@ -5,42 +5,281 @@
# $Id$
require 'session'
+require 'apache/cookie'
+
+class Session
+ public
+
+ # Ugly hack-ish method for extending Session to include various
+ # routines not included in the base class and are special to
+ # Apache::Session
+
+ def apache_session_setup()
+ # Boolean values for where we fetched our session data from
+ @uri_session = nil
+ @cookie_session = nil
+ end # def apache_session_setup
+end # module Session
+
+
module Apache
+ class Request
+ attr_accessor(:cookie_session, :uri_session, :uri_session_place)
+ def setup_session_state()
+ @cookie_session ||= nil
+ @uri_session ||= nil
+ @uri_session_place ||= nil
+ end # def setup_session_state()
+ end # class Request
+
class Session
+ NONE = 1
+ OPTIONAL = 2
+ REQUIRED = 3
+ URI_ARG = 4
+ URI_END = 5
+ URI_SESSION = 6
+ URI_START = 7
+
@@html_session_re_a = nil
@@html_session_re_form = nil
@@html_session_re_img = nil
- @@uri_session_ri = nil
+ @@uri_session_re = nil
+
+
+ def Session.check_access(r)
+ return_code = Apache::DECLINED
+
+ # This is likely going to bite people who have their apache
+ # config screwed up, but, we're going to check/refresh that
+ # people ar visiting the vhost that the server is setup to
+ # handle. It's done for security reasons... sorry.
+ r.headers_in.each_key do |header|
+ if header.downcase == 'host' and
+ r.headers_in['Host'].downcase != r.server_name.downcase
+ r.headers_out['Location'] = r.construct_url(r.unparsed_uri)
+ return(Apache::HTTP_MOVED_TEMPORARILY)
+ end # if header.downcase
+ end # r.headers_in...
+
+
+ # Setup the session environment now that the request has a URI
+ if ENV.has_key?('COOKIE_SESSION')
+ case ENV['COOKIE_SESSION']
+ when 'required'
+ r.cookie_session = REQUIRED
+ when 'optional'
+ r.cookie_session = OPTIONAL
+ when 'none'
+ r.cookie_sessoin = NONE
+ else
+ r.cookie_session = OPTIONAL
+ end # case ENV['COOKIE_SESSION']
+ end # if ENV.has_key?('COOKIE_SESSION')
+
+ if ENV.has_key?('URI_SESSION')
+ case ENV['URI_SESSION']
+ when 'required'
+ r.uri_session = REQUIRED
+ when 'optional'
+ r.uri_session = OPTIONAL
+ when 'none'
+ r.uri_session = NONE
+ else
+ r.uri_session = OPTIONAL
+ end # case ENV['URI_SESSION']
+ end # if ENV.has_key?('URI_SESSION')
+
+ if ENV.has_key?('URI_SESSION_PLACE')
+ case ENV['URI_SESSION_PLACE']
+ when 'arg'
+ r.uri_session_place = URI_ARG
+ when 'end'
+ r.uri_session_place = URI_END
+ when 'start'
+ r.uri_session_place = URI_START
+ else
+ r.uri_session_place = URI_START
+ end # case ENV['URI_SESSION_PLACE']
+ end # if ENV.has_key?('URI_SESSION_PLACE')
+
+ case r.uri_session
+ when REQUIRED
+ # Send user a 302 with session in URI
+ if $session.session_id.nil?
+ $session.generate()
+
+ args = r.args || ''
+ path_info = r.path_info || ''
+
+ case r.uri_session_place
+ when URI_ARG
+ if r.args.nil?
+ r.headers_out['Location'] = "#{r.uri}#{path_info}?sess=#{$session.session_id}"
+ else
+ r.headers_out['Location'] = "#{r.uri}#{path_info}#{args}&sess=#{$session.session_id}"
+ end
+ when URI_END
+ r.headers_out['Location'] = "#{File.dirname(r.uri)}/sess=#{$session.session_id}/#{File.basename(r.uri)}#{path_info}#{args}"
+ when URI_START
+ r.headers_out['Location'] = "/sess=#{$session.session_id}#{r.uri}#{path_info}#{args}"
+ end # case r.uri_session_place
+ return(Apache::HTTP_MOVED_TEMPORARILY)
+ end
+ return_code = Apache::OK
+ when OPTIONAL
+ # If session exists, don't destroy it
+ # Pass user along regardless of whether they have one or not
+ return_code = Apache::OK
+ when NONE
+ # Remove any session data found in the env
+ # Pass the user along with an empty session id/data
+ $session = nil
+ return_code = Apache::DECLINED
+ end # case r.uri_session
+
+
+ # XXXX
+ case r.cookie_session
+ when REQUIRED
+
+ # If required and we don't have any cookies, 302 the user to
+ # our URL again, but send out a test cookie in the 302. If we
+ # catch a cookie in the response, then let the user through.
+ # If the user doesn't allow cookies, and r.uri_session is set
+ # to OPTIONAL, then bounce the user a URI session. This
+ # allows for cookied sessions by default, but if the user is
+ # smart and has turned off cookies, then we still let them
+ # through the site.
+
+ if $session.session_id.nil?
+ $session.generate()
+
+ args = r.args || ''
+ path_info = r.path_info || ''
+
+ case r.uri_session_place
+ when URI_ARG
+ if r.args.nil?
+ r.headers_out['Location'] = "#{r.uri}#{path_info}?sess=#{$session.session_id}"
+ else
+ r.headers_out['Location'] = "#{r.uri}#{path_info}#{args}&sess=#{$session.session_id}"
+ end
+ when URI_END
+ r.headers_out['Location'] = "#{File.dirname(r.uri)}/sess=#{$session.session_id}/#{File.basename(r.uri)}#{path_info}#{args}"
+ when URI_START
+ r.headers_out['Location'] = "/sess=#{$session.session_id}#{r.uri}#{path_info}#{args}"
+ end # case r.uri_session_place
+ return(Apache::HTTP_MOVED_TEMPORARILY)
+ end
+ return_code = Apache::OK
+ when OPTIONAL
+ # If session exists, don't destroy it
+ # Pass user along regardless of whether they have one or not
+ return_code = Apache::OK
+ when NONE
+ # Remove any session data found in the env
+ # Pass the user along with an empty session id/data
+ $session = nil
+ return_code = Apache::DECLINED
+ end # case r.uri_session
+
+ $session.load() unless $session.session_id.nil?
+
+ return(return_code)
+ end # def Session.check_access()
+
def Session.cleanup(r)
- s = nil
+ $session = nil
+ return(Apache::OK)
end # def Session.cleanup()
def Session.init(r)
- s = Session.new()
+ r.setup_session_state()
+ s = Kernel.const_get('Session').new()
+ s.apache_session_setup()
- # One time init junk
+ # One time init foo
@@html_session_re_a ||= Regexp.new('(<\s*[Aa].*?[Hh][Rr][Ee][Ff]\s*=\s*)(([\'\"])((?:[^#]|[Mm][Aa][Ii][Ll][Tt][Oo]).*?[^\?]*?){0,1}(\?.*?){0,1}\3)(.*?>)')
@@html_session_re_form ||= Regexp.new('(<\s*[Ff][Oo][Rr][Mm].*?[Aa][Cc][Tt][Ii][Oo][Nn]\s*=\s*)(([\'"])([^\?]*?){0,1}(\?.*?){0,1}\3)(.*?>)')
@@html_session_re_img ||= Regexp.new('(<\s*[Ii][Mm][Gg].*?[Ss][Rr][Cc]\s*=\s*)(([\'"])([^\?]*?){0,1}(\?.*?){0,1}\3)(.*?>)')
- @@uri_session_re ||= Regexp.new('/sess=([A-Fa-f0-9]{32})/')
+ @@uri_session_re ||= Regexp.new('([\/\?\&])sess=([A-Fa-f0-9]{32})([\&\/]?)')
+
+ return(Apache::DECLINED)
end # def Session.init()
+ def Session.rewrite_output(r)
+ if !$session.session_id.nil? and r.uri_session != NONE
+ # Rewrite the HTML
+ #
+ # Need to make sure that we only rewrite URLs for the current
+ # VHOST (ie: relative and fully qualified)
+
+ return(Apache::OK)
+ else
+ return(Apache::DECLINED)
+ end
+ end # def Session.rewrite_output()
+
+
+ def html_sessionize_str(str, re)
+ str_orig = str.dup
+
+ while (md = re.match(str_orig)) do
+ tag = md.to_a[1] + md.to_a[3] + md.to_a[4]
+
+ if md.to_a[4].index('mailto') == 0
+ tag = md.to_a[0]
+ elsif md.to_a[5]
+ if md.to_a[5].index(Regexp.new('[\/\?\+]sess='))
+ tag <<= md.to_a[5] + md.to_a[3] + md.to_a[6]
+ else
+ tag <<= md.to_a[5] + '+sess=' + @session_id + md.to_a[3] + md.to_a[6]
+ end
+ else
+ tag <<= '?sess=' + @session_id + md.to_a[3] + md.to_a[6]
+ end
+
+ str.gsub!(Regexp.escape(md.to_a[0]), tag)
+ str_orig = md.post_match
+ end # while loop
+
+ return(tmpl)
+ end # def sessionize_str()
+
+
+ # Translate URI is responsible for nabbing the session out of the URI
+ # or out of the cookie.
def Session.translate_uri(r)
- md = @@uri_session_re.match(r.uri)
+ md = @@uri_session_re.match(r.unparsed_uri)
if !md.nil?
- $session.session_id = md[1]
- r.uri = uri.sub(md[0], '/')
+ $session.uri_session = true
+ $session.session_id = md[2]
+ case md[1]
+ when '/'
+ r.uri = r.uri.sub(Regexp.escape(md[0]), md[1])
+ when '?'
+ if md[3].nil?
+ r.args = r.args.sub(Regexp.escape(md[0]), '')
+ else
+ r.args = r.args.sub(Regexp.escape(md[0]), md[1])
+ end
+ when '&'
+ if md[3].nil?
+ r.args = r.args.sub(Regexp.escape(md[0]), '')
+ else
+ r.args = r.args.sub(Regexp.escape(md[0]), md[1])
+ end
+ end # case md[1]
- $session.generate() unless $session.load()
- r.notes['session_id'] = $session.session_id
+ # $session.generate() unless $session.load()
else
# No Session or invalid session found in the URI
- #
- # XXX Need to incorporate checking for cookies here
+ $session.uri_session = false
end # if md.nil?
# Let another handler map this request to a file
|
|
From: Sean C. <the...@us...> - 2002-06-20 13:52:42
|
Update of /cvsroot/ruby-session/ruby-session/src/session
In directory usw-pr-cvs1:/tmp/cvs-serv15872
Modified Files:
dbi.rb
Log Message:
*) Removing a few debugging routines that I shouldn't have committed
Index: dbi.rb
===================================================================
RCS file: /cvsroot/ruby-session/ruby-session/src/session/dbi.rb,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- dbi.rb 13 Jun 2002 12:28:27 -0000 1.1
+++ dbi.rb 20 Jun 2002 13:52:39 -0000 1.2
@@ -1,7 +1,4 @@
-$:.unshift('/usr/home/sean/open_source/ruby-dbi/src/lib/dbi')
-$:.unshift('/usr/home/sean/open_source/ruby-dbi/src/lib/dbd_pg')
require 'dbi'
-#require 'Pg'
class Session
@@commit.push('dbi_commit')
|
|
From: Sean C. <the...@us...> - 2002-06-20 13:50:39
|
Update of /cvsroot/ruby-session/ruby-session/src/apache In directory usw-pr-cvs1:/tmp/cvs-serv15392 Removed Files: cookie.rb Log Message: *) Killing off a bad attempt at cookies --- cookie.rb DELETED --- |
|
From: Sean C. <the...@us...> - 2002-06-20 13:49:13
|
Update of /cvsroot/ruby-session/ruby-session/src/apache/session In directory usw-pr-cvs1:/tmp/cvs-serv14994 Removed Files: file.rb Log Message: *) Killing off old work that lead me to dive into the guts of mod_ruby --- file.rb DELETED --- |
|
From: Sean C. <the...@us...> - 2002-06-20 13:46:54
|
Update of /cvsroot/ruby-session/ruby-session/src/apache
In directory usw-pr-cvs1:/tmp/cvs-serv14258
Modified Files:
session.rb
Log Message:
*) Updated apache/session.rb to become actually usable as a sessioning
module. Currently it only strips session data from the URI but
will quickly snab data out of cookies and rewrite pages.
Index: session.rb
===================================================================
RCS file: /cvsroot/ruby-session/ruby-session/src/apache/session.rb,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- session.rb 19 Nov 2001 00:16:15 -0000 1.3
+++ session.rb 20 Jun 2002 13:46:50 -0000 1.4
@@ -1,179 +1,52 @@
#!/usr/local/bin/ruby -w
-# ruby-session: Got persistence?
-
-# Copyright 2001
-# Sean Chittenden <se...@ch...>. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgment:
-#
-# This product includes software developed by Sean Chittenden
-# <se...@ch...> and ruby-session's contributors.
-#
-# 4. Neither the name of the software nor the names of its contributors
-# may be used to endorse or promote products derived from this software
-# without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-# Please see the LICENSE file for more information regarding the use
-# and distribution of this software.
+# See the LICENSE file for copyright and distribution information.
#
# $Id$
+require 'session'
+
module Apache
class Session
- attr_accessor :cookies, :data, :expired, :session_dir, :session_id
- attr_reader :session_id_length, :start_time, :type
-
- #
- # Class methods
- #
-
- # RubyAccessHandler Apache::Session
- def Session.check_access (r)
- if ENV.has_key?('SESSION')
- if ENV['SESSION'] == 'require'
- # Test to see if the request has a session
-
- # if the request doesn't have a session, then generate a
- # session using Session.generate(), append it to the URL,
- # and send a 302 response
+ @@html_session_re_a = nil
+ @@html_session_re_form = nil
+ @@html_session_re_img = nil
+ @@uri_session_ri = nil
+
+ def Session.cleanup(r)
+ s = nil
+ end # def Session.cleanup()
+
+
+ def Session.init(r)
+ s = Session.new()
+
+ # One time init junk
+ @@html_session_re_a ||= Regexp.new('(<\s*[Aa].*?[Hh][Rr][Ee][Ff]\s*=\s*)(([\'\"])((?:[^#]|[Mm][Aa][Ii][Ll][Tt][Oo]).*?[^\?]*?){0,1}(\?.*?){0,1}\3)(.*?>)')
+ @@html_session_re_form ||= Regexp.new('(<\s*[Ff][Oo][Rr][Mm].*?[Aa][Cc][Tt][Ii][Oo][Nn]\s*=\s*)(([\'"])([^\?]*?){0,1}(\?.*?){0,1}\3)(.*?>)')
+ @@html_session_re_img ||= Regexp.new('(<\s*[Ii][Mm][Gg].*?[Ss][Rr][Cc]\s*=\s*)(([\'"])([^\?]*?){0,1}(\?.*?){0,1}\3)(.*?>)')
+ @@uri_session_re ||= Regexp.new('/sess=([A-Fa-f0-9]{32})/')
+ end # def Session.init()
+
+
+ def Session.translate_uri(r)
+ md = @@uri_session_re.match(r.uri)
+ if !md.nil?
+ $session.session_id = md[1]
+ r.uri = uri.sub(md[0], '/')
- end
+ $session.generate() unless $session.load()
+ r.notes['session_id'] = $session.session_id
else
+ # No Session or invalid session found in the URI
+ #
+ # XXX Need to incorporate checking for cookies here
+ end # if md.nil?
+
+ # Let another handler map this request to a file
+ return(Apache::DECLINED)
+ end # def Session.translate_uri()
- # if ruby-session can't handle this request, then pass the
- # request to the next access handler
-
- return(Apache::DECLINED)
- end # if ENV.has_key?()
- end # def Session.check_access
-
-
- def Session.exist? (location)
- return(Session._exist?(location))
- end # def Session.exist?
-
-
- def Session.generate ()
- require 'digest/md5'
- md5digest = Digest::MD5.new
- md5digest.update(Time.now.to_f.to_s + rand.to_s + $$.to_s)
- return(md5digest.hexdigest)
- end # def Session.generate
-
-
- def Session.make_location (*args)
- begin
- return(Session._make_location(args))
- rescue NameError
- raise RuntimeError, "No Session persistence layers available"
- end
- end # def Session.make_location
-
-
- public # methods
-
-
- def [] (key)
- return(@data[key])
- end # def []
-
-
- def []= (key, value)
- return(@data[key] = value)
- end # def []=
-
-
- def delete ()
- self._delete
- end # def delete
-
-
- def exist? (session_id)
- return(self._exist?)
- end # def exist?
-
-
- def location ()
- @location = self.make_location unless (@location)
- return(@location)
- end # def location
-
-
- def persist ()
- @data['__ruby_session_expired__'] = (@expired ? 'y' : 'n')
- @data['__ruby_session_start_time__'] = @start_time
-
- self._persist
-
- @data.delete('__ruby_session_expired__')
- @data.delete('__ruby_session_start_time__')
- end # def persist
-
-
- def restore ()
- self._restore
-
- @start_time = @data.delete('__ruby_session_start_time__')
- @expired = (@data.delete('__ruby_session_expired__') == 'y' ? true : false)
- end # def restore
-
-
- def type= (type)
- @type = type.downcase
- begin
- require File.join('apache', 'session', @type)
- rescue LoadError
- raise LoadError, "Invalid Session Type '#{type}'"
- end
-
- return(@type)
- end # def type=
-
-
- private
-
-
- def initialize (opts = {})
- @cookies = (opts.has_key?('cookies') ? opts['cookies'] : false)
- @data = (opts.has_key?('session_data') ? opts['session_data'] : {})
- @expired = false
- @location = nil
- @session_dir = (opts.has_key?('session_dir') ? opts['session_dir'] : '/tmp')
- @session_id = nil
- @start_time = Time.now
- @type = self.type = (opts.has_key?('type') ? opts['type'] : 'file')
-
- if opts.has_key?('session_id')
- @session_id = opts['session_id']
- self.restore
- else
- @session_id = Session.generate
- end # if opts.has_key?('session_id')
-
- end # def initialize ()
end # class Session
-
end # module Apache
|
|
From: Sean C. <the...@us...> - 2002-06-20 13:45:38
|
Update of /cvsroot/ruby-session/ruby-session/src/session
In directory usw-pr-cvs1:/tmp/cvs-serv14029
Added Files:
pstore.rb
Log Message:
*) Added a pstore routine for quick and dirty sessioning
--- NEW FILE: pstore.rb ---
# See the LICENSE file for copyright and distribution information.
#
# $Id: pstore.rb,v 1.1 2002/06/20 13:45:34 thetitan Exp $
require 'pstore'
class Session
@@commit.push('pstore_commit')
@@init.push('pstore_init')
@@load.push('pstore_load')
@@tmp = nil
attr_accessor(:pstore_file)
public
def pstore_roots()
@pstore_db = PStore.new(@pstore_file) if @pstore_db.nil?
@pstore_db.transaction do |db|
return(@pstore_db.roots)
end # @pstore_db.transaction
end # def pstore_roots()
private
def pstore_commit()
@pstore_db = PStore.new(@pstore_file) if @pstore_db.nil?
@pstore_db.transaction do
@pstore_db[@session_id] = @@data
end # @pstore_db.transaction
end # def pstore_commit()
def pstore_init()
@pstore_db = nil
@pstore_file = nil
end # def pstore_init()
def pstore_load()
@pstore_db = PStore.new(@pstore_file) if @pstore_db.nil?
begin
@pstore_db.transaction do |db|
@@data = db[@session_id]
end # @pstore_db.transaction
rescue PStore::Error
# Couldn't find the session
return(false)
rescue TypeError
# Empty pstore
return(false)
end # begin
return(true)
end # def pstore_load()
end # module Session
|
|
From: Sean C. <the...@us...> - 2002-06-20 13:41:48
|
Update of /cvsroot/ruby-session/ruby-session/src
In directory usw-pr-cvs1:/tmp/cvs-serv12953
Modified Files:
session.rb
Log Message:
*) Few bug fixes to get things working. Most work done in apache/session.rb
Index: session.rb
===================================================================
RCS file: /cvsroot/ruby-session/ruby-session/src/session.rb,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- session.rb 20 Jun 2002 00:50:44 -0000 1.2
+++ session.rb 20 Jun 2002 13:41:39 -0000 1.3
@@ -35,7 +35,7 @@
def commit(*args)
- @session_id = Session.generate() if @session_id.nil?
+ generate() if @session_id.nil?
@@data = Marshal.dump(self)
@@ -48,17 +48,25 @@
end # def commit()
+ def generate()
+ reset()
+ return(@session_id = Session.generate())
+ end # def generate()
+
+
def load(*args)
raise "Need a Session ID" if @session_id.nil?
for load_meth in @@load
m = self.method(load_meth)
- m.call(*args)
+ if m.call(*args)
+ break
+ else
+ next
+ end
end # for load_meth
- if @@data.nil?
- return(false)
- else
+ if !@@data.nil?
obj = Marshal.load(@@data) if !@@data.nil?
@active = obj.active
@data = obj.data
@@ -71,6 +79,8 @@
@session_id = obj.session_id
@session_data = obj.session_data
return(true)
+ else
+ return(false)
end
end # def load()
@@ -90,7 +100,7 @@
def session_id()
- @session_id = Session.generate() if @session_id.nil?
+ generate() if @session_id.nil?
return(@session_id)
end # def session_id()
@@ -101,6 +111,11 @@
return(@session_id = session_id)
end # def session_id=()
+
+
+ def to_s()
+ return(@session_id)
+ end # def to_s
private
|
|
From: Sean C. <the...@us...> - 2002-06-20 00:50:47
|
Update of /cvsroot/ruby-session/ruby-session/src
In directory usw-pr-cvs1:/tmp/cvs-serv10525
Modified Files:
session.rb
Log Message:
*) Framework for sessions should be mostly done at this point
Index: session.rb
===================================================================
RCS file: /cvsroot/ruby-session/ruby-session/src/session.rb,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- session.rb 13 Jun 2002 12:28:25 -0000 1.1
+++ session.rb 20 Jun 2002 00:50:44 -0000 1.2
@@ -8,9 +8,11 @@
class Session
@@commit = []
+ @@data = nil
@@init = []
@@load = []
+ attr_reader(:active, :data, :expiration_time, :last_updated, :last_session_id, :rekey_time, :start_date, :last_session_id, :old_session_id, :secure, :session_data)
public
@@ -35,10 +37,14 @@
def commit(*args)
@session_id = Session.generate() if @session_id.nil?
+ @@data = Marshal.dump(self)
+
for commit_meth in @@commit
m = self.method(commit_meth)
m.call(*args)
end # for commit_meth
+
+ @@data = nil
end # def commit()
@@ -49,6 +55,23 @@
m = self.method(load_meth)
m.call(*args)
end # for load_meth
+
+ if @@data.nil?
+ return(false)
+ else
+ obj = Marshal.load(@@data) if !@@data.nil?
+ @active = obj.active
+ @data = obj.data
+ @expiration_time = obj.expiration_time
+ @last_updated = obj.last_updated
+ @old_session_id = obj.old_session_id
+ @rekey_time = obj.rekey_time
+ @start_date = obj.start_date
+ @secure = obj.secure
+ @session_id = obj.session_id
+ @session_data = obj.session_data
+ return(true)
+ end
end # def load()
@@ -77,7 +100,8 @@
raise "SessionID already set" if !@session_id.nil?
return(@session_id = session_id)
- end
+ end # def session_id=()
+
private
@@ -90,6 +114,6 @@
for init_meth in @@init
m = self.method(init_meth)
m.call(*args)
- end # for commit_meth
+ end # for init_meth in @@init
end # def initialize
end # class Session
|
|
From: Sean C. <the...@us...> - 2002-06-13 12:28:30
|
Update of /cvsroot/ruby-session/ruby-session/src/session
In directory usw-pr-cvs1:/tmp/cvs-serv28716/session
Added Files:
dbi.rb
Log Message:
*) Checking in work
*) Still an outstanding DBI bug with unescaping data on restore from the
database
*) Oustanding bug with converting to a Time object from data stored in
a 'timestamp without time zone' data type
--- NEW FILE: dbi.rb ---
$:.unshift('/usr/home/sean/open_source/ruby-dbi/src/lib/dbi')
$:.unshift('/usr/home/sean/open_source/ruby-dbi/src/lib/dbd_pg')
require 'dbi'
#require 'Pg'
class Session
@@commit.push('dbi_commit')
@@init.push('dbi_init')
@@load.push('dbi_load')
@@tmp = nil
attr_accessor(:db_host, :db_name, :db_table_name, :db_type, :db_user)
attr_reader(:dbh)
attr_writer(:db_pass)
private
def dbi_commit()
ins_sql() if @db_ins_sql.nil?
get_dbh() if @dbh.nil?
@@tmp = Marshal.dump(@data)
@dbh.do(@db_ins_sql, @session_id, Marshal.dump(@data))
end # def dbi_commit()
def dbi_init()
@dbh = nil
@db_dsn = nil
@db_host = nil
@db_name = nil
@db_pass = nil
@db_get_sql = nil
@db_ins_sql = nil
@db_table_name = 'session'
@db_type = 'Pg'
@db_user = nil
end # def dbi_init()
def dbi_load()
get_sql() if @db_get_sql.nil?
get_dbh() if @dbh.nil?
row = @dbh.select_one(@db_get_sql, @session_id)
if !row.nil?
p @@tmp
p row[1]
raise row[1].to_s
@data = Marshal.load(row[1].gsub(Regexp.new('\\\\\\\\'), '\\'))
@start_date = row[2]
@last_updated = row[3]
@secure = row[4]
@rekey_time = row[5]
@expiration_time = row[6]
$session = self
end
end # def dbi_commit()
def dsn()
if @db_dsn.nil?
dsn = "DBI:#{@db_type}:#{@db_name}"
dsn << ":#{@db_name}" if @db_host
@db_dsn = dsn
end
return(@db_dsn)
end # def dsn()
def get_dbh()
if @dbh.nil?
dsn() if @db_dsn.nil?
@dbh = DBI.connect(@db_dsn, @db_user, @db_pass)
end # if @dbh.nil?
return(@dbh)
end # def get_dbh()
def get_sql()
if @db_get_sql.nil?
#sql = "SELECT session_id, session_data, utc_start_time, utc_last_updated, secure, rekey_time, expiration_time FROM #{@db_table_name} WHERE session_id = ?"
sql = "SELECT session_id, session_data, utc_start_time FROM #{@db_table_name} WHERE session_id = ?"
@db_get_sql = sql
end
return(@db_get_sql)
end # def get_sql()
def ins_sql()
if @db_ins_sql.nil?
sql = "INSERT INTO session (session_id, session_data) VALUES (?,?)"
@db_ins_sql = sql
end
end # def ins_sql()
end # module Session
|
|
From: Sean C. <the...@us...> - 2002-06-13 12:28:29
|
Update of /cvsroot/ruby-session/ruby-session/src
In directory usw-pr-cvs1:/tmp/cvs-serv28716
Added Files:
session.rb
Log Message:
*) Checking in work
*) Still an outstanding DBI bug with unescaping data on restore from the
database
*) Oustanding bug with converting to a Time object from data stored in
a 'timestamp without time zone' data type
--- NEW FILE: session.rb ---
#!/usr/local/bin/ruby -w
#
# See the LICENSE file for copyright and distribution information.
#
# $Id: session.rb,v 1.1 2002/06/13 12:28:25 thetitan Exp $
require 'digest/md5'
class Session
@@commit = []
@@init = []
@@load = []
public
def Session.generate()
md5digest = Digest::MD5.new()
md5digest.update(Time.now.to_f.to_s + rand.to_s + $$.to_s)
return(md5digest.hexdigest)
end # def Session.generate
def [](key)
return(@data[key])
end # def []
def []=(key, value)
return(@data[key] = value)
end # def []=
def commit(*args)
@session_id = Session.generate() if @session_id.nil?
for commit_meth in @@commit
m = self.method(commit_meth)
m.call(*args)
end # for commit_meth
end # def commit()
def load(*args)
raise "Need a Session ID" if @session_id.nil?
for load_meth in @@load
m = self.method(load_meth)
m.call(*args)
end # for load_meth
end # def load()
def reset()
@active = true
@data = {}
@expiration_time = nil
@last_updated = Time.now()
@old_session_id = nil
@rekey_time = nil
@start_date = Time.now()
@secure = false
@session_id = nil
@session_data = nil
end # def reset()
def session_id()
@session_id = Session.generate() if @session_id.nil?
return(@session_id)
end # def session_id()
def session_id=(session_id)
raise "SessionID already set" if !@session_id.nil?
return(@session_id = session_id)
end
private
def initialize(*args)
reset()
$session = self
for init_meth in @@init
m = self.method(init_meth)
m.call(*args)
end # for commit_meth
end # def initialize
end # class Session
|
|
From: Sean C. <the...@us...> - 2002-06-12 21:52:23
|
Update of /cvsroot/ruby-session/ruby-session/src/session In directory usw-pr-cvs1:/tmp/cvs-serv30067/session Log Message: Directory /cvsroot/ruby-session/ruby-session/src/session added to the repository |
|
From: Sean C. <the...@us...> - 2002-06-12 20:25:39
|
Update of /cvsroot/ruby-session/ruby-session/src/sql In directory usw-pr-cvs1:/tmp/cvs-serv22003 Added Files: postgresql.sql Log Message: *) Added schema and stored procedures for PostgreSQL support for ruby-session. Session ID generation must be done on the client. It could be done in the database, but isn't being done there now. --- NEW FILE: postgresql.sql --- /* $Id: postgresql.sql,v 1.1 2002/06/12 20:25:36 thetitan Exp $ * * See the LICENSE file for copyright and distribution information */ /* * Please install Pl/PgSQL. Can be installed via: * * createlang --dbname=template1 plgsql * * where template1 can be substituted for any other existing database. * * * Load this file into your database via: * * psql -f postgresql.sql db_name username */ DROP TABLE session; CREATE TABLE session ( session_id VARCHAR(64) NOT NULL, utc_start_time TIMESTAMP WITHOUT TIME ZONE NOT NULL, utc_last_updated TIMESTAMP WITHOUT TIME ZONE NOT NULL, active CHAR(1) DEFAULT 'y' NOT NULL, secure BOOL DEFAULT FALSE NOT NULL, rekey_time INTERVAL DEFAULT '5 min'::INTERVAL NOT NULL, expiration_time INTERVAL DEFAULT '60 min'::INTERVAL NOT NULL, session_data BYTEA NOT NULL ); CREATE UNIQUE INDEX session_id_udx ON session (session_id); DROP FUNCTION session_ins_opq(); CREATE FUNCTION session_ins_opq() RETURNS opaque AS ' BEGIN NEW.utc_start_time := (SELECT NOW()); NEW.utc_last_updated := (SELECT NOW()); RETURN NEW; END; ' LANGUAGE 'plpgsql'; DROP FUNCTION session_upd_opq(); CREATE FUNCTION session_upd_opq() RETURNS opaque AS ' BEGIN NEW.utc_start_time := OLD.utc_start_time; NEW.utc_last_updated := (SELECT NOW()); RETURN NEW; END; ' LANGUAGE 'plpgsql'; DROP FUNCTION session_cleanup(); CREATE FUNCTION session_cleanup() RETURNS BOOL AS ' BEGIN EXECUTE ''DELETE FROM session WHERE (utc_last_updated + expiration_time) < NOW()''; RETURN TRUE; END ' LANGUAGE 'plpgsql'; CREATE TRIGGER session_ins_opq BEFORE INSERT ON session FOR EACH ROW EXECUTE PROCEDURE session_ins_opq(); CREATE TRIGGER session_upd_opq BEFORE UPDATE ON session FOR EACH ROW EXECUTE PROCEDURE session_upd_opq(); /* SELECT session_cleanup(); */ |
|
From: Sean C. <the...@us...> - 2002-06-12 09:48:55
|
Update of /cvsroot/ruby-session/ruby-session/src/sql In directory usw-pr-cvs1:/tmp/cvs-serv24676/sql Log Message: Directory /cvsroot/ruby-session/ruby-session/src/sql added to the repository |
|
From: Sean C. <the...@us...> - 2001-11-19 08:42:27
|
Update of /cvsroot/ruby-session/ruby-session/src/apache
In directory usw-pr-cvs1:/tmp/cvs-serv29304
Added Files:
cookie.rb
Log Message:
* Adding Apache::Cookie. Module isn't fully functional, but it does
go a long way towards providing a consistent mod_ruby interface for
cookies.
* Can create cookies, add cookies to CookieDough and bake the
CookieDough to get a valid Cookie.
* Need to add ability to set more meta-data about cookie values
* Need to add ability to read cookies from incoming HTTP headers
--- NEW FILE: cookie.rb ---
# ruby-session: Got persistence?
# Copyright 2001
# Sean Chittenden <se...@ch...>. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgment:
#
# This product includes software developed by Sean Chittenden
# <se...@ch...> and ruby-session's contributors.
#
# 4. Neither the name of the software nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# Please see the LICENSE file for more information regarding the use
# and distribution of this software.
#
# $Id: cookie.rb,v 1.1 2001/11/19 08:42:24 thetitan Exp $
module Apache
class Cookie
attr_accessor :secure
attr_reader
public
def Cookie.uri_escape (str_arg)
str = str_arg.dup
str.gsub!(/#{Regexp.escape('%')}/o, '%25')
str.gsub!(/#{Regexp.escape('$')}/o, '%24')
str.gsub!(/#{Regexp.escape('&')}/o, '%26')
str.gsub!(/#{Regexp.escape('"')}/o, '%22')
str.gsub!(/#{Regexp.escape('\'')}/o, '%27')
str.gsub!(/#{Regexp.escape(',')}/o, '%2C')
str.gsub!(/#{Regexp.escape('=')}/o, '%3D')
str.gsub!(/#{Regexp.escape(';')}/o, '%3B')
str.gsub!(/#{Regexp.escape(':')}/o, '%3A')
str.gsub!(/#{Regexp.escape(" ")}/o, '%20')
str.gsub!(/#{Regexp.escape("\n")}/o, '%0A')
str.gsub!(/#{Regexp.escape("\t")}/o, '%09')
str.gsub!(/#{Regexp.escape("\r")}/o, '%0D')
str.gsub(/([^a-zA-Z0-9._-]+)/o) do
'%' + $1.unpack('H2' * $1.size).join('%').upcase
end.tr(' ', '+')
return(str)
end # def uri_escape
def name
return(Apache.unescape_url(@name))
end # def name
# Sets the cookie name. Cookie name's can't start with a dollar sign ($)
# as specified by RFC 2109. All $'s are being escaped by uri_escape().
def name= (name_arg)
name = name_arg.dup
@name = Cookie.uri_escape(name)
end # def name=
def to_s
return(self.to_str)
end # def to_s
def to_str
return(@name.to_s + '=' + @value.to_s)
end # def to_str
def value
return(Apache.unescape_url(@value))
end # def value
# Sets the value of the cookie. This must be ASCII printable, but
# I'm not checking for that now. Instead I'm just going to borrow
# some code from cgi.rb and will URI encode the value. XXX
def value= (value_arg)
value = value_arg.dup
@value = Cookie.uri_escape(value)
end # def value=
private
def initialize
@name = '' # Cookie name
@value = '' # Cookie value (must be ASCII printable)
@secure = false
end # def initialize
end # class Cookie
class CookieDough
public
def add (*args)
args.each do |arg|
@jar[arg.name] = arg
end # args.each
end # def add
def bake
cookies = []
@jar.keys.sort.each do |cookie_name|
cookies.push(@jar.fetch(cookie_name).to_str)
end # @jar.keys.sort.each
return('Set-Cookie: ' + cookies.join(','))
end # def bake
private
def initialize ( *args )
@jar = {}
if args.length == 0
@r = Apache.request
else
if args[0].type.to_s == "Apache::Request"
@r = args[0]
else
raise TypeError, "Need a request handler to operate on"
end # if args[0]
end # def initialize
end # def initialize
end # class CookieDough
end # module Apache
|
|
From: Sean C. <the...@us...> - 2001-11-19 00:16:17
|
Update of /cvsroot/ruby-session/ruby-session/src/apache
In directory usw-pr-cvs1:/tmp/cvs-serv16034
Modified Files:
session.rb
Log Message:
Added write-thru cache for the location instance data
Added prelim-stubs for cookies (default to off)
Added initial code for a session Access handler for mod_ruby
generate() is now the class method Session.generate()
Cleaned up end block styles (reduces LoC)
Alphabatized methods/functions
Sessions now leave it up to the native persistence layer to worry about
maintaining session start times (file stores a raw Time object instance)
Variable renaming in the initialize method: gsub!(/options/, 'opts')
Index: session.rb
===================================================================
RCS file: /cvsroot/ruby-session/ruby-session/src/apache/session.rb,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- session.rb 2001/08/25 19:57:31 1.2
+++ session.rb 2001/11/19 00:16:15 1.3
@@ -42,52 +42,45 @@
module Apache
class Session
- attr_accessor :data, :expired, :session_dir, :session_id
- attr_reader :location, :session_id_length, :start_time, :type
+ attr_accessor :cookies, :data, :expired, :session_dir, :session_id
+ attr_reader :session_id_length, :start_time, :type
+ #
+ # Class methods
+ #
+
+ # RubyAccessHandler Apache::Session
+ def Session.check_access (r)
+ if ENV.has_key?('SESSION')
+ if ENV['SESSION'] == 'require'
+ # Test to see if the request has a session
+
+ # if the request doesn't have a session, then generate a
+ # session using Session.generate(), append it to the URL,
+ # and send a 302 response
- public
-
- def [] (key)
- return(@data[key])
- end
- # End: def [] ()
-
-
- def []= (key, value)
- return(@data[key] = value)
- end
- # End: def []= ()
+ end
+ else
+ # if ruby-session can't handle this request, then pass the
+ # request to the next access handler
- def delete ()
- @location = self.make_location unless(@location)
- self._delete
- end
- # End: def delete ()
+ return(Apache::DECLINED)
+ end # if ENV.has_key?()
+ end # def Session.check_access
def Session.exist? (location)
return(Session._exist?(location))
- end
- # End: def Session.exist? ()
+ end # def Session.exist?
- def exist? (session_id)
- @location = self.make_location unless (@location)
- return(self._exist?)
- end
- # End: def exist? ()
-
-
- def generate ()
+ def Session.generate ()
require 'digest/md5'
md5digest = Digest::MD5.new
md5digest.update(Time.now.to_f.to_s + rand.to_s + $$.to_s)
- @session_id = md5digest.hexdigest
- return(@session_id)
- end
- # End: def generate ()
+ return(md5digest.hexdigest)
+ end # def Session.generate
def Session.make_location (*args)
@@ -96,33 +89,55 @@
rescue NameError
raise RuntimeError, "No Session persistence layers available"
end
- end
- # End: def Session.make_location ()
+ end # def Session.make_location
- def persist ()
- @location = self.make_location unless(@location)
+ public # methods
+
+
+ def [] (key)
+ return(@data[key])
+ end # def []
+
+ def []= (key, value)
+ return(@data[key] = value)
+ end # def []=
+
+
+ def delete ()
+ self._delete
+ end # def delete
+
+
+ def exist? (session_id)
+ return(self._exist?)
+ end # def exist?
+
+
+ def location ()
+ @location = self.make_location unless (@location)
+ return(@location)
+ end # def location
+
+
+ def persist ()
@data['__ruby_session_expired__'] = (@expired ? 'y' : 'n')
- @data['__ruby_session_start_time__'] = @start_time.to_f.to_s
+ @data['__ruby_session_start_time__'] = @start_time
self._persist
@data.delete('__ruby_session_expired__')
@data.delete('__ruby_session_start_time__')
- end
- # End: def persist ()
+ end # def persist
def restore ()
- @location = self.make_location unless(@location)
-
self._restore
+ @start_time = @data.delete('__ruby_session_start_time__')
@expired = (@data.delete('__ruby_session_expired__') == 'y' ? true : false)
- @start_time = Time.at(@data.delete('__ruby_session_start_time__').to_f)
- end
- # End: def restore ()
+ end # def restore
def type= (type)
@@ -132,37 +147,33 @@
rescue LoadError
raise LoadError, "Invalid Session Type '#{type}'"
end
- end
- # End: def type= ()
+
+ return(@type)
+ end # def type=
private
- def initialize (options = {})
- @data = (options.has_key?('session_data') ? options['session_data'] : {})
+ def initialize (opts = {})
+ @cookies = (opts.has_key?('cookies') ? opts['cookies'] : false)
+ @data = (opts.has_key?('session_data') ? opts['session_data'] : {})
@expired = false
@location = nil
- @session_dir = (options.has_key?('session_dir') ? options['session_dir'] : '/tmp')
+ @session_dir = (opts.has_key?('session_dir') ? opts['session_dir'] : '/tmp')
@session_id = nil
@start_time = Time.now
- @type = nil
+ @type = self.type = (opts.has_key?('type') ? opts['type'] : 'file')
- self.type = (options.has_key?('type') ? options['type'] : 'file')
-
- if options.has_key?('session_id')
- @session_id = options['session_id']
+ if opts.has_key?('session_id')
+ @session_id = opts['session_id']
self.restore
else
- @session_id = self.generate
- end
- # End: if options.has_key?('session_id')
+ @session_id = Session.generate
+ end # if opts.has_key?('session_id')
- end
- # End: def initialize ()
+ end # def initialize ()
- end
- # End: class Session
+ end # class Session
-end
-# End: module Apache
+end # module Apache
|
|
From: Sean C. <the...@us...> - 2001-11-19 00:10:49
|
Update of /cvsroot/ruby-session/ruby-session/src/apache/session
In directory usw-pr-cvs1:/tmp/cvs-serv15515
Modified Files:
file.rb
Log Message:
Fixed a NASTY NASTY bug that resulted in the loss of meta-data for a session.
This commit removes merging data that has changed on disk (same session opened
twice). Last write wins.
Index: file.rb
===================================================================
RCS file: /cvsroot/ruby-session/ruby-session/src/apache/session/file.rb,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- file.rb 2001/11/18 23:53:49 1.4
+++ file.rb 2001/11/19 00:10:46 1.5
@@ -83,7 +83,6 @@
Marshal.dump(@data, f)
f.close()
rescue Errno::EEXIST
- self.restore
f = File.new(self.location, File::TRUNC|File::WRONLY, 0600)
Marshal.dump(@data, f)
f.close()
|
|
From: Sean C. <the...@us...> - 2001-11-18 23:53:52
|
Update of /cvsroot/ruby-session/ruby-session/src/apache/session
In directory usw-pr-cvs1:/tmp/cvs-serv11942
Modified Files:
file.rb
Log Message:
Location isn't always specified: use a write-through accessor method that'll
create the location if it hasn't been already.
Removed duplicate make_location function that was older than the maintained
version in session.rb
Index: file.rb
===================================================================
RCS file: /cvsroot/ruby-session/ruby-session/src/apache/session/file.rb,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- file.rb 2001/11/18 21:35:08 1.3
+++ file.rb 2001/11/18 23:53:49 1.4
@@ -49,7 +49,7 @@
def _delete ()
begin
- File.delete(@location)
+ File.delete(self.location)
rescue Errno::ENOENT
raise RuntimeError, "Unable to delete session #{@session_id}"
end
@@ -67,7 +67,7 @@
def _exist? ()
- return(Session._exist?(@location))
+ return(Session._exist?(self.location))
end # def _exist?
@@ -77,21 +77,14 @@
end # def Session._make_location
- def make_location (session_id = @session_id, session_dir = @session_dir)
- return(Session._make_location(session_id, session_dir))
- end # def make_location
-
-
def _persist ()
- self.make_location() unless(@location)
-
begin
- f = File.new(@location, File::CREAT|File::TRUNC|File::WRONLY|File::EXCL, 0600)
+ f = File.new(self.location, File::CREAT|File::TRUNC|File::WRONLY|File::EXCL, 0600)
Marshal.dump(@data, f)
f.close()
rescue Errno::EEXIST
self.restore
- f = File.new(@location, File::TRUNC|File::WRONLY, 0600)
+ f = File.new(self.location, File::TRUNC|File::WRONLY, 0600)
Marshal.dump(@data, f)
f.close()
end
@@ -100,7 +93,7 @@
def _restore ()
begin
- f = File.new(@location, File::RDONLY)
+ f = File.new(self.location, File::RDONLY)
@data.update(Marshal.load(f))
f.close
rescue Errno::ENOENT
|
|
From: Sean C. <the...@us...> - 2001-11-18 21:35:12
|
Update of /cvsroot/ruby-session/ruby-session/src/apache/session
In directory usw-pr-cvs1:/tmp/cvs-serv15032
Modified Files:
file.rb
Log Message:
Updated End blocks to a more concise style
Index: file.rb
===================================================================
RCS file: /cvsroot/ruby-session/ruby-session/src/apache/session/file.rb,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- file.rb 2001/08/25 19:54:56 1.2
+++ file.rb 2001/11/18 21:35:08 1.3
@@ -53,8 +53,7 @@
rescue Errno::ENOENT
raise RuntimeError, "Unable to delete session #{@session_id}"
end
- end
- # End: def _delete ()
+ end # def _delete
def Session._exist? (location)
@@ -63,29 +62,24 @@
return(true)
rescue Errno::ENOENT
return(false)
- end
- # End: begin
- end
- # End: def Session._exist? ()
+ end # begin
+ end # def Session._exist?
def _exist? ()
return(Session._exist?(@location))
- end
- # End: def _exist? ()
+ end # def _exist?
def Session._make_location (*args)
session_id, session_dir = args.flatten
return(File.join(session_dir, ".ruby-session-#{session_id}"))
- end
- # End: def Session._make_location ()
+ end # def Session._make_location
def make_location (session_id = @session_id, session_dir = @session_dir)
return(Session._make_location(session_id, session_dir))
- end
- # End: def make_location ()
+ end # def make_location
def _persist ()
@@ -101,8 +95,7 @@
Marshal.dump(@data, f)
f.close()
end
- end
- # End: def _persist ()
+ end # def _persist
def _restore ()
@@ -113,14 +106,11 @@
rescue Errno::ENOENT
raise RuntimeError, "Can not restore session '#{@session_id}': session does not valid"
end
- end
- # End: def _restore ()
+ end # def _restore
private
- end
- # End: module Session
+ end # module Session
-end
-# End: module Apache
+end # module Apache
|
|
From: Sean C. <the...@us...> - 2001-09-04 00:14:20
|
Update of /cvsroot/ruby-session/www/doc In directory usw-pr-cvs1:/tmp/cvs-serv1224/doc Log Message: Directory /cvsroot/ruby-session/www/doc added to the repository |
|
From: Sean C. <the...@us...> - 2001-09-03 04:19:22
|
Update of /cvsroot/ruby-session/ruby-session
In directory usw-pr-cvs1:/tmp/cvs-serv32287
Modified Files:
Makefile
Log Message:
Added distclean target
Index: Makefile
===================================================================
RCS file: /cvsroot/ruby-session/ruby-session/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Makefile 2001/08/25 21:44:39 1.1
+++ Makefile 2001/09/03 04:19:17 1.2
@@ -5,3 +5,6 @@
uninstall:
@ruby uninstall.rb
+
+distclean:
+ find . -name '*~' -o -name '*.bak' -exec rm -f {} \;
|
|
From: Sean C. <the...@us...> - 2001-08-25 22:01:50
|
Update of /cvsroot/ruby-session/ruby-session/doc In directory usw-pr-cvs1:/tmp/cvs-serv25825/doc Added Files: INSTALL Log Message: Added README and INSTALL (install in diff directory because windows has numb-nuts developers that thought that case-insensitivity was a good idea) --- NEW FILE: INSTALL --- To install, type: make install To uninstall, type: make uninstall |
|
From: Sean C. <the...@us...> - 2001-08-25 22:01:50
|
Update of /cvsroot/ruby-session/ruby-session In directory usw-pr-cvs1:/tmp/cvs-serv25825 Added Files: README Log Message: Added README and INSTALL (install in diff directory because windows has numb-nuts developers that thought that case-insensitivity was a good idea) --- NEW FILE: README --- For information on installation, please see doc/INSTALL |
|
From: Sean C. <the...@us...> - 2001-08-25 22:00:00
|
Update of /cvsroot/ruby-session/ruby-session/doc In directory usw-pr-cvs1:/tmp/cvs-serv25492/doc Log Message: Directory /cvsroot/ruby-session/ruby-session/doc added to the repository |
|
From: Sean C. <the...@us...> - 2001-08-25 21:44:42
|
Update of /cvsroot/ruby-session/ruby-session
In directory usw-pr-cvs1:/tmp/cvs-serv22294
Added Files:
Makefile install.rb uninstall.rb
Log Message:
Added installation/uninstallation targests and scripts
--- NEW FILE: Makefile ---
# $Id: Makefile,v 1.1 2001/08/25 21:44:39 thetitan Exp $
install:
@ruby install.rb
uninstall:
@ruby uninstall.rb
--- NEW FILE: install.rb ---
#! /usr/bin/env ruby
#
# Copyright (c) 2001 by Sean Chittenden <se...@ch...>
# Adapted from an install script originally by Jim Menard <ji...@io...>
#
=begin
= Introduction
This script installs ruby-session into the Ruby site-local library directory.
= Usage
install.rb
=end
require 'getoptlong'
require 'ftools'
require 'find'
SRCDIR = 'src'
def instdir
g = GetoptLong.new(['--install-dir', '-i', GetoptLong::REQUIRED_ARGUMENT])
g.each { | name, arg |
if name == '--install-dir'
return arg
else
$stderr.puts "usage: $0 [--install-dir dir]"
end
}
begin
require 'rbconfig'
libdir = Config::CONFIG['sitedir'] + "/" +
Config::CONFIG['MAJOR'] + "." +
Config::CONFIG['MINOR']
rescue ScriptError
$LOAD_PATH.each do |l|
if l =~ /site_ruby/ && l =~ /\d$/ && l !~ /#{PLATFORM}/
libdir = l
break
end
end
STDERR.puts "Can't find required file `rbconfig.rb'."
STDERR.puts "The `ruby-tmpl' files need to be installed manually in" +
" #{libdir}"
end
return libdir
end
INSTALL_DIR = instdir()
File.makedirs(File.join(INSTALL_DIR, 'apache','session'))
Find.find(SRCDIR) { |f|
File.install(f, File.join(INSTALL_DIR, f).gsub!(/#{SRCDIR}/, ''), 0644, true) if f =~ /.rb$/
}
--- NEW FILE: uninstall.rb ---
#! /usr/bin/env ruby
#
# Copyright (c) 2001 by Sean Chittenden <se...@ch...>
# Adapted from an install script originally by Jim Menard <ji...@io...>
#
=begin
= Introduction
This script uninstalls ruby-session from the Ruby site-local library directory.
= Usage
uninstall.rb
=end
require 'getoptlong'
require 'ftools'
require 'find'
SRCDIR = 'src'
def instdir
g = GetoptLong.new(['--install-dir', '-i', GetoptLong::REQUIRED_ARGUMENT])
g.each { | name, arg |
if name == '--install-dir'
return arg
else
$stderr.puts "usage: $0 [--install-dir dir]"
end
}
begin
require 'rbconfig'
libdir = Config::CONFIG['sitedir'] + "/" +
Config::CONFIG['MAJOR'] + "." +
Config::CONFIG['MINOR']
rescue ScriptError
$LOAD_PATH.each do |l|
if l =~ /site_ruby/ && l =~ /\d$/ && l !~ /#{PLATFORM}/
libdir = l
break
end
end
STDERR.puts "Can't find required file `rbconfig.rb'."
STDERR.puts "The `ruby-tmpl' files need to be installed manually in" +
" #{libdir}"
end
return libdir
end
INSTALL_DIR = instdir()
dirs = []
Find.find(SRCDIR) { |f|
fm = File.join(INSTALL_DIR, f).gsub(/#{Regexp.escape(SRCDIR)}/, '')
begin
File.delete(fm) if fm =~ /.rb$/
rescue Errno::ENOENT
$stderr.puts "#{fm} does not exist"
end
begin
if File.stat(fm).directory?
dirs.push(String.new(fm))
end
rescue Errno::ENOENT
# NO OP
end
}
dirs.each {|d|
begin
Dir.delete(d)
rescue Errno::ENOTEMPTY
# NO OP
end
}
|
|
From: Sean C. <the...@us...> - 2001-08-25 19:57:34
|
Update of /cvsroot/ruby-session/ruby-session/src/apache
In directory usw-pr-cvs1:/tmp/cvs-serv29654/src/apache
Modified Files:
session.rb
Log Message:
Added more functionality... created an abstract front end to various persistence layers
Fixd speling erors
Index: session.rb
===================================================================
RCS file: /cvsroot/ruby-session/ruby-session/src/apache/session.rb,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- session.rb 2001/08/25 10:31:52 1.1
+++ session.rb 2001/08/25 19:57:31 1.2
@@ -1,6 +1,6 @@
#!/usr/local/bin/ruby -w
-# ruby-session: Got persistance?
+# ruby-session: Got persistence?
# Copyright 2001
# Sean Chittenden <se...@ch...>. All rights reserved.
@@ -14,10 +14,10 @@
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
+# must display the following acknowledgment:
#
# This product includes software developed by Sean Chittenden
-# <se...@ch...> and ruby-tmpl's contributors.
+# <se...@ch...> and ruby-session's contributors.
#
# 4. Neither the name of the software nor the names of its contributors
# may be used to endorse or promote products derived from this software
@@ -51,18 +51,35 @@
def [] (key)
return(@data[key])
end
+ # End: def [] ()
def []= (key, value)
return(@data[key] = value)
end
+ # End: def []= ()
def delete ()
- self.make_location unless(@location)
- self._delete()
+ @location = self.make_location unless(@location)
+ self._delete
end
+ # End: def delete ()
+
+ def Session.exist? (location)
+ return(Session._exist?(location))
+ end
+ # End: def Session.exist? ()
+
+
+ def exist? (session_id)
+ @location = self.make_location unless (@location)
+ return(self._exist?)
+ end
+ # End: def exist? ()
+
+
def generate ()
require 'digest/md5'
md5digest = Digest::MD5.new
@@ -70,25 +87,37 @@
@session_id = md5digest.hexdigest
return(@session_id)
end
+ # End: def generate ()
+ def Session.make_location (*args)
+ begin
+ return(Session._make_location(args))
+ rescue NameError
+ raise RuntimeError, "No Session persistence layers available"
+ end
+ end
+ # End: def Session.make_location ()
+
+
def persist ()
- self.make_location() unless(@location)
+ @location = self.make_location unless(@location)
@data['__ruby_session_expired__'] = (@expired ? 'y' : 'n')
@data['__ruby_session_start_time__'] = @start_time.to_f.to_s
- self._persist()
+ self._persist
@data.delete('__ruby_session_expired__')
@data.delete('__ruby_session_start_time__')
end
+ # End: def persist ()
def restore ()
- self.make_location() unless(@location)
+ @location = self.make_location unless(@location)
- self._restore()
+ self._restore
@expired = (@data.delete('__ruby_session_expired__') == 'y' ? true : false)
@start_time = Time.at(@data.delete('__ruby_session_start_time__').to_f)
@@ -104,10 +133,12 @@
raise LoadError, "Invalid Session Type '#{type}'"
end
end
+ # End: def type= ()
private
+
def initialize (options = {})
@data = (options.has_key?('session_data') ? options['session_data'] : {})
@expired = false
@@ -121,7 +152,7 @@
if options.has_key?('session_id')
@session_id = options['session_id']
- self.restore()
+ self.restore
else
@session_id = self.generate
end
|