You are viewing a plain text version of this content. The canonical link for it is here.
Posted to site-cvs@tcl.apache.org by ro...@apache.org on 2002/07/29 23:24:26 UTC

cvs commit: tcl-site/websh/examples session_form.html session_form.ws3 session_form_ws3.txt

ronnie      2002/07/29 14:24:26

  Modified:    websh/examples session_form.html session_form.ws3
                        session_form_ws3.txt
  Log:
  - fixed saving the state
  - made sure that filecounter is initialized only once per thread
  - delete state after request (prevent session crosstalk
  
  Revision  Changes    Path
  1.2       +10 -5     tcl-site/websh/examples/session_form.html
  
  Index: session_form.html
  ===================================================================
  RCS file: /home/cvs/tcl-site/websh/examples/session_form.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- session_form.html	9 Jul 2002 06:54:53 -0000	1.1
  +++ session_form.html	29 Jul 2002 21:24:26 -0000	1.2
  @@ -27,8 +27,11 @@
   
   <I><FONT COLOR="#B22222"># Create a file counter that generates the session ids. We take
   </FONT></I><I><FONT COLOR="#B22222"># here an easy number generator, which produces sequential numbers
  -</FONT></I><I><FONT COLOR="#B22222"># and stores the actual counter value in a file
  -</FONT></I>web::filecounter idGenerator -<B><FONT COLOR="#A020F0">filename</FONT></B> [<B><FONT COLOR="#A020F0">file</FONT></B> <B><FONT COLOR="#A020F0">join</FONT></B> [config::cget stateDirectory] counter]
  +</FONT></I><I><FONT COLOR="#B22222"># and stores the actual counter value in a file (only create one if 
  +</FONT></I><I><FONT COLOR="#B22222"># the current interpreter does not already have one)
  +</FONT></I><B><FONT COLOR="#A020F0">if</FONT></B> {![<B><FONT COLOR="#A020F0">llength</FONT></B> [<B><FONT COLOR="#A020F0">info</FONT></B> commands idGenerator]]} {
  +    web::filecounter idGenerator -<B><FONT COLOR="#A020F0">filename</FONT></B> [<B><FONT COLOR="#A020F0">file</FONT></B> <B><FONT COLOR="#A020F0">join</FONT></B> [config::cget stateDirectory] counter]
  +}
   
   <I><FONT COLOR="#B22222"># Create a file context named 'state'. The option '-path' defines
   </FONT></I><I><FONT COLOR="#B22222"># where the session contexts are stored. '-attachto' defines an
  @@ -38,8 +41,7 @@
   </FONT></I>web::filecontext state -path [<B><FONT COLOR="#A020F0">file</FONT></B> <B><FONT COLOR="#A020F0">join</FONT></B> [config::cget stateDirectory] %s] -attachto sid -idgen <B><FONT COLOR="#BC8F8F">&quot;idGenerator nextval&quot;</FONT></B>
   
   <I><FONT COLOR="#B22222"># Make sure the session state directory exists
  -</FONT></I><B><FONT COLOR="#A020F0">file</FONT></B> mkdir [config::cget stateDirectory]
  -
  +</FONT></I><B><FONT COLOR="#A020F0">catch</FONT></B> {<B><FONT COLOR="#A020F0">file</FONT></B> mkdir [config::cget stateDirectory]}
   
   <B><FONT COLOR="#A020F0">proc</FONT></B> <B><FONT COLOR="#0000FF">form</FONT></B> {<FONT COLOR="#B8860B">page code</FONT>} {
       <I><FONT COLOR="#B22222"># Produces a HTML FORM tag. Nested form variables must be output
  @@ -97,7 +99,7 @@
   </FONT></I>    <I><FONT COLOR="#B22222"># name correctly here. If a HTML field is given twice or more
   </FONT></I>    <I><FONT COLOR="#B22222"># 'web::formvar -count &lt;fieldname&gt;' would give us the field count
   </FONT></I>    <I><FONT COLOR="#B22222"># 'web::formvar &lt;fieldname&gt;' returns then a list of n values.
  -</FONT></I>    <B><FONT COLOR="#A020F0">foreach</FONT></B> field [web::formvar names] {
  +</FONT></I>    <B><FONT COLOR="#A020F0">foreach</FONT></B> field [web::formvar -names] {
           state::cset $<FONT COLOR="#B8860B">field</FONT> [web::formvar $<FONT COLOR="#B8860B">field</FONT>]
       }
   }
  @@ -158,6 +160,9 @@
   </FONT></I><I><FONT COLOR="#B22222"># web::dispatch processes the URL - i.e. extracts parameters from the
   </FONT></I><I><FONT COLOR="#B22222"># URL - and handles HTML form input sent to this script.
   </FONT></I>web::dispatch -track sid
  +
  +<I><FONT COLOR="#B22222"># cleanup state (so we have no session crosstalk)
  +</FONT></I>state::delete
   </PRE>
   <HR>
   <ADDRESS>Generated by <A HREF="http://www.iki.fi/~mtr/genscript/">GNU enscript 1.6.3</A>.</ADDRESS>
  
  
  
  1.4       +10 -5     tcl-site/websh/examples/session_form.ws3
  
  Index: session_form.ws3
  ===================================================================
  RCS file: /home/cvs/tcl-site/websh/examples/session_form.ws3,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- session_form.ws3	9 Jul 2002 06:54:53 -0000	1.3
  +++ session_form.ws3	29 Jul 2002 21:24:26 -0000	1.4
  @@ -16,8 +16,11 @@
   
   # Create a file counter that generates the session ids. We take
   # here an easy number generator, which produces sequential numbers
  -# and stores the actual counter value in a file
  -web::filecounter idGenerator -filename [file join [config::cget stateDirectory] counter]
  +# and stores the actual counter value in a file (only create one if 
  +# the current interpreter does not already have one)
  +if {![llength [info commands idGenerator]]} {
  +    web::filecounter idGenerator -filename [file join [config::cget stateDirectory] counter]
  +}
   
   # Create a file context named 'state'. The option '-path' defines
   # where the session contexts are stored. '-attachto' defines an
  @@ -27,8 +30,7 @@
   web::filecontext state -path [file join [config::cget stateDirectory] %s] -attachto sid -idgen "idGenerator nextval"
   
   # Make sure the session state directory exists
  -file mkdir [config::cget stateDirectory]
  -
  +catch {file mkdir [config::cget stateDirectory]}
   
   proc form {page code} {
       # Produces a HTML FORM tag. Nested form variables must be output
  @@ -86,7 +88,7 @@
       # name correctly here. If a HTML field is given twice or more
       # 'web::formvar -count <fieldname>' would give us the field count
       # 'web::formvar <fieldname>' returns then a list of n values.
  -    foreach field [web::formvar names] {
  +    foreach field [web::formvar -names] {
           state::cset $field [web::formvar $field]
       }
   }
  @@ -147,3 +149,6 @@
   # web::dispatch processes the URL - i.e. extracts parameters from the
   # URL - and handles HTML form input sent to this script.
   web::dispatch -track sid
  +
  +# cleanup state (so we have no session crosstalk)
  +state::delete
  
  
  
  1.2       +10 -5     tcl-site/websh/examples/session_form_ws3.txt
  
  Index: session_form_ws3.txt
  ===================================================================
  RCS file: /home/cvs/tcl-site/websh/examples/session_form_ws3.txt,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- session_form_ws3.txt	9 Jul 2002 07:09:49 -0000	1.1
  +++ session_form_ws3.txt	29 Jul 2002 21:24:26 -0000	1.2
  @@ -16,8 +16,11 @@
   
   # Create a file counter that generates the session ids. We take
   # here an easy number generator, which produces sequential numbers
  -# and stores the actual counter value in a file
  -web::filecounter idGenerator -filename [file join [config::cget stateDirectory] counter]
  +# and stores the actual counter value in a file (only create one if 
  +# the current interpreter does not already have one)
  +if {![llength [info commands idGenerator]]} {
  +    web::filecounter idGenerator -filename [file join [config::cget stateDirectory] counter]
  +}
   
   # Create a file context named 'state'. The option '-path' defines
   # where the session contexts are stored. '-attachto' defines an
  @@ -27,8 +30,7 @@
   web::filecontext state -path [file join [config::cget stateDirectory] %s] -attachto sid -idgen "idGenerator nextval"
   
   # Make sure the session state directory exists
  -file mkdir [config::cget stateDirectory]
  -
  +catch {file mkdir [config::cget stateDirectory]}
   
   proc form {page code} {
       # Produces a HTML FORM tag. Nested form variables must be output
  @@ -86,7 +88,7 @@
       # name correctly here. If a HTML field is given twice or more
       # 'web::formvar -count <fieldname>' would give us the field count
       # 'web::formvar <fieldname>' returns then a list of n values.
  -    foreach field [web::formvar names] {
  +    foreach field [web::formvar -names] {
           state::cset $field [web::formvar $field]
       }
   }
  @@ -147,3 +149,6 @@
   # web::dispatch processes the URL - i.e. extracts parameters from the
   # URL - and handles HTML form input sent to this script.
   web::dispatch -track sid
  +
  +# cleanup state (so we have no session crosstalk)
  +state::delete
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tcl-site-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: tcl-site-cvs-help@tcl.apache.org