# Copyright (C) 2003, 2004 Gregoire Lejeune <gregoire.lejeune@free.fr>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA

module Asp
  class GlobalASA
    require 'asp/common'
    
    public
    def getAsaCode
      
      begin
        lcode = IO::readlines( @xGAsaFile.untaint ).untaint
        code = lcode.join( " " )
      
#      filename = @xGAsaFile
#        @oAspHandler.load_code( code ), filename.untaint )
        @oAspHandler.load_code( code )
      rescue => e
        if Asp::Common::debug == 1 
          result = @oApacheRequest.escape_html(e.message)
          @oApacheRequest.server.log_error( "[Ruby/ASP] [%d] : (%s #%d) : %s", $$, __FILE__, __LINE__, result )
        end
        return false
      end

      return true 
  
    end
    
    private 
    def initialize( xFile, r, aspHandler )
      @oApacheRequest = r
      @xGAsaFile = mapPath( xFile + "/global.asa" )
      @xGAsaFile.untaint
      @oAspHandler = aspHandler
    end
  
    def mapPath( path )
      result = ( @oApacheRequest.lookup_file( path ).filename || path )
      return result
    end

  end
end
