<commit_before>#--
##   Riassence Framework
 #   Copyright 2008 Riassence Inc.
 #   http://riassence.com/
 #
 #   You should have received a copy of the GNU General Public License along
 #   with this software package. If not, contact <EMAIL>
 ##
 #++
class SessionTimeout < ServletPlugin
  def match( uri, request_type )
    if request_type == :post and uri == File.join($config[:broker_urls][:hello],'goodbye')
      return true
    end
    return false
  end
  def post( req, res, ses )
    msg = $SESSION.init_msg( req, res, true )
    msg.expire_session()
    msg.response_done
  end
end
SessionTimeout.new

class Main < Plugin
  
  # url_responder gets called whenever the
  # page location.href changes, enabled virtual uris
  # to enable back/forward/bookmarking in browsers,
  # when software is coded to support it.
  #
  # Client-side support is included in js/url_responder.js
  #
  # Also allows virtual-host -like behavior, if software
  # is coded to support it.
  def url_responder(msg,location_href)
    
    mses = msg.session[:main]
    
    # Virtual locations:
    if location_href.data.include?('#')
      
      # split 'http://localhost:8001/#/some_uri'
      #   -> ['http://localhost:8001/','/some_uri']
      mses[:url] = location_href.data.split('#')
      
      virtual_uri = mses[:url][1]
      
      # built-in support for signing out, deletes the
      # server-side session and reloads the page
      if virtual_uri == '/sign_out'
        msg.reply( %{
          COMM.Transporter.stop=true;
          location.href=#{$config[:indexhtml_conf][:respond_address].to_json};
        } )
        msg.expire_session()
      end
      
    else
      
      # assigns only a virtual url
      mses[:url] = [location_href.data]
      
    end
    
    # url_responder always accepts locations
    return true
    
  end
  
  
  # new session initialization,
  # called just once per session.
  def init_ses(msg)
    
    ses = msg.session
    
    ## Creates :main hash in msg.session, common stuff
    ## that removes unneccessary duplicates in other plugins.
    ses[:main] = {
      
      # 'boot' state, gets incremented on each request.
      :boot => 0,
      
      # [real,virtual] url
      :url  => [nil,nil],
      
      # the date/time of the client
      :client_time => HValue.new( msg, 0 ),
      
      # the location.href value of the client
      :location_href => HValue.new(msg,'#'),
      
      ## array for segmented transfers
      :delayed_calls => [],
      
      :poll_mode => true,
      :title_loading => true
      
    }
    
    ## binds the location_href HValue to self::url_responder
    ses[:main][:location_href].bind( 'main', 'url_responder')
  end
  
  # called once when a session is 
  # restored using the cookie's ses_key
  def restore_ses(msg)
    ## Resets session data to defaults
    ses = msg.session
    init_ses(msg) unless ses.has_key?(:main)
    ses[:main][:boot] = 0
    ses[:main][:delayed_calls] = []
    ses[:main][:poll_mode] = true
    ses[:main][:title_loading] = true
  end
  
  def delayed_call(msg,args)
    msg.session[:main][:delayed_calls].push( args )
  end
  
  # called on every request of an
  # active, valid session
  def idle(msg)
    
    init_ses(msg) unless msg.session.has_key?(:main)
    
    mses = msg.session[:main]
    
    ## Prioritizes segmented execution to prevent
    ## the client from choking on itself
    if mses[:boot] == 0
      
      msg.reply("ELEM.setStyle(0,'background-color','#{$config[:main_plugin][:bg_color]}');")
      
      ## url_responder is bound in the client-space
      ## to tell the server its status by updating its value
      # msg.reply require_js('main')
      msg.reply "COMM.Values['#{mses[:location_href].val_id}'].bind(COMM.urlResponder);"
      msg.reply "urlResponder = COMM.URLResponder;" # backwards compatibility
      ## This enables SesWatcher that changes :client_time every 60 seconds.
      ## It makes the client to poll the server on regular intervals, when polling mode
      ## is disabled.
      # 5000ms = 5secs
      msg.reply "sesWatcher = COMM.SessionWatcher.nu(#{$config[:main_plugin][:server_poll_interval]},'#{mses[:client_time].val_id}');"
      
    elsif mses[:boot] == 1<commit_msg>moved the urlResponder assignment to autosync.js<commit_after>#--
##   Riassence Framework
 #   Copyright 2008 Riassence Inc.
 #   http://riassence.com/
 #
 #   You should have received a copy of the GNU General Public License along
 #   with this software package. If not, contact <EMAIL>
 ##
 #++
class SessionTimeout < ServletPlugin
  def match( uri, request_type )
    if request_type == :post and uri == File.join($config[:broker_urls][:hello],'goodbye')
      return true
    end
    return false
  end
  def post( req, res, ses )
    msg = $SESSION.init_msg( req, res, true )
    msg.expire_session()
    msg.response_done
  end
end
SessionTimeout.new

class Main < Plugin
  
  # url_responder gets called whenever the
  # page location.href changes, enabled virtual uris
  # to enable back/forward/bookmarking in browsers,
  # when software is coded to support it.
  #
  # Client-side support is included in js/url_responder.js
  #
  # Also allows virtual-host -like behavior, if software
  # is coded to support it.
  def url_responder(msg,location_href)
    
    mses = msg.session[:main]
    
    # Virtual locations:
    if location_href.data.include?('#')
      
      # split 'http://localhost:8001/#/some_uri'
      #   -> ['http://localhost:8001/','/some_uri']
      mses[:url] = location_href.data.split('#')
      
      virtual_uri = mses[:url][1]
      
      # built-in support for signing out, deletes the
      # server-side session and reloads the page
      if virtual_uri == '/sign_out'
        msg.reply( %{
          COMM.Transporter.stop=true;
          location.href=#{$config[:indexhtml_conf][:respond_address].to_json};
        } )
        msg.expire_session()
      end
      
    else
      
      # assigns only a virtual url
      mses[:url] = [location_href.data]
      
    end
    
    # url_responder always accepts locations
    return true
    
  end
  
  
  # new session initialization,
  # called just once per session.
  def init_ses(msg)
    
    ses = msg.session
    
    ## Creates :main hash in msg.session, common stuff
    ## that removes unneccessary duplicates in other plugins.
    ses[:main] = {
      
      # 'boot' state, gets incremented on each request.
      :boot => 0,
      
      # [real,virtual] url
      :url  => [nil,nil],
      
      # the date/time of the client
      :client_time => HValue.new( msg, 0 ),
      
      # the location.href value of the client
      :location_href => HValue.new(msg,''),
      
      ## array for segmented transfers
      :delayed_calls => [],
      
      :poll_mode => true,
      :title_loading => true
      
    }
    
    ## binds the location_href HValue to self::url_responder
    ses[:main][:location_href].bind( 'main', 'url_responder')
  end
  
  # called once when a session is 
  # restored using the cookie's ses_key
  def restore_ses(msg)
    ## Resets session data to defaults
    ses = msg.session
    init_ses(msg) unless ses.has_key?(:main)
    ses[:main][:boot] = 0
    ses[:main][:delayed_calls] = []
    ses[:main][:poll_mode] = true
    ses[:main][:title_loading] = true
  end
  
  def delayed_call(msg,args)
    msg.session[:main][:delayed_calls].push( args )
  end
  
  # called on every request of an
  # active, valid session
  def idle(msg)
    
    init_ses(msg) unless msg.session.has_key?(:main)
    
    mses = msg.session[:main]
    
    ## Prioritizes segmented execution to prevent
    ## the client from choking on itself
    if mses[:boot] == 0
      
      msg.reply("ELEM.setStyle(0,'background-color','#{$config[:main_plugin][:bg_color]}');")
      
      ## url_responder is bound in the client-space
      ## to tell the server its status by updating its value
      location_href_id = mses[:location_href].val_id.to_json
      msg.reply "COMM.Values.values[#{location_href_id}].bind(COMM.urlResponder);"
      ## This enables SesWatcher that changes :client_time every 60 seconds.
      ## It makes the client to poll the server on regular intervals, when polling mode
      ## is disabled.
      # 5000ms = 5secs
      client_time_id = mses[:client_time].val_id.to_json
      poll_interval = $config[:main_plugin][:server_poll_interval]
      msg.reply "sesWatcher = COMM.SessionWatcher.nu(#{poll_interval},#{client_time_id});"
      
    elsif mses[:boot] == 1
{'fraction_non_alphanumeric': 0.11304246383574429, 'fraction_numerical': 0.006066262249183388, 'mean_word_length': 2.6295512277730735, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2967388', 'n_tokens_mistral': 2758, 'n_tokens_neox': 2676, 'n_words': 723}