<commit_before>=begin
                  Arachni
  Copyright (c) 2010-2011 Tasos "Zapotek" Laskos <<EMAIL>>

  This is free software; you can copy and distribute and modify
  this program under the term of the GPL v2.0 License
  (See LICENSE file for details)

=end

module Arachni

#
# The following are pretty much rip offs of Metasploit's
# /lib/msf/core/option_container.rb
#
#

###
#
# The base class for all options.
#
###
class OptBase

    #
    # The name of the option.
    #
    attr_reader   :name

    #
    # Whether or not the option is required.
    #
    attr_reader   :required

    #
    # The description of the option.
    #
    attr_reader   :desc

    #
    # The default value of the option.
    #
    attr_reader   :default

    #
    # Storing the name of the option.
    #
    attr_writer   :name

    #
    # The component that owns this option.
    #
    attr_accessor :owner

    #
    # The list of potential valid values
    #
    attr_accessor :enums


    #
    # Initializes a named option with the supplied attribute array.
    # The array is composed of three values.
    #
    # attrs[0] = required (boolean type)
    # attrs[1] = description (string)
    # attrs[2] = default value
    # attrs[3] = possible enum values
    #
    # @param    [String]    name    the name of the options
    # @param    [Array]     attrs   option attributes
    #
    def initialize( name, attrs = [] )
        @name     = name
        @required = attrs[0] || false
        @desc     = attrs[1]
        @default  = attrs[2]
        @enums    = [ *(attrs[3]) ].map { |x| x.to_s }
    end

    #
    # Returns true if this is a required option.
    #
    def required?
        return required
    end

    #
    # Returns true if the supplied type is equivalent to this option's type.
    #
    def type?( in_type )
        return (type == in_type)
    end

    #
    # If it's required and the value is nil or empty, then it's not valid.
    #
    def valid?( value )
        return ( required? && ( value == nil || value.to_s.empty? ) ) ? false : true
    end

    #
    # Returns true if the value supplied is nil and it's required to be
    # a valid value
    #
    def empty_required_value?( value )
        return ( required? && value.nil? )
    end

    #
    # Normalizes the supplied value to conform with the type that the option is
    # conveying.
    #
    def normalize( value )
        value
    end

    #
    # Converts the Options object to hash
    #
    # @return    [Hash]
    #
    def to_h
        hash = Hash.new
        self.instance_variables.each {
            |var|
            hash[var.to_s.gsub( /@/, '' )] = self.instance_variable_get( var )
        }
        return hash
    end


protected

    attr_writer   :required, :desc, :default # :nodoc:
end

###
#
# Core option types.  The core supported option types are:
#
# OptString  - Multi-byte character string<commit_msg>to_h(): added 'type' in the hash<commit_after>=begin
                  Arachni
  Copyright (c) 2010-2011 Tasos "Zapotek" Laskos <<EMAIL>>

  This is free software; you can copy and distribute and modify
  this program under the term of the GPL v2.0 License
  (See LICENSE file for details)

=end

module Arachni

#
# The following are pretty much rip offs of Metasploit's
# /lib/msf/core/option_container.rb
#
#

###
#
# The base class for all options.
#
###
class OptBase

    #
    # The name of the option.
    #
    attr_reader   :name

    #
    # Whether or not the option is required.
    #
    attr_reader   :required

    #
    # The description of the option.
    #
    attr_reader   :desc

    #
    # The default value of the option.
    #
    attr_reader   :default

    #
    # Storing the name of the option.
    #
    attr_writer   :name

    #
    # The component that owns this option.
    #
    attr_accessor :owner

    #
    # The list of potential valid values
    #
    attr_accessor :enums


    #
    # Initializes a named option with the supplied attribute array.
    # The array is composed of three values.
    #
    # attrs[0] = required (boolean type)
    # attrs[1] = description (string)
    # attrs[2] = default value
    # attrs[3] = possible enum values
    #
    # @param    [String]    name    the name of the options
    # @param    [Array]     attrs   option attributes
    #
    def initialize( name, attrs = [] )
        @name     = name
        @required = attrs[0] || false
        @desc     = attrs[1]
        @default  = attrs[2]
        @enums    = [ *(attrs[3]) ].map { |x| x.to_s }
    end

    #
    # Returns true if this is a required option.
    #
    def required?
        return required
    end

    #
    # Returns true if the supplied type is equivalent to this option's type.
    #
    def type?( in_type )
        return (type == in_type)
    end

    #
    # If it's required and the value is nil or empty, then it's not valid.
    #
    def valid?( value )
        return ( required? && ( value == nil || value.to_s.empty? ) ) ? false : true
    end

    #
    # Returns true if the value supplied is nil and it's required to be
    # a valid value
    #
    def empty_required_value?( value )
        return ( required? && value.nil? )
    end

    #
    # Normalizes the supplied value to conform with the type that the option is
    # conveying.
    #
    def normalize( value )
        value
    end

    #
    # Converts the Options object to hash
    #
    # @return    [Hash]
    #
    def to_h
        hash = Hash.new
        self.instance_variables.each {
            |var|
            hash[var.to_s.gsub( /@/, '' )] = self.instance_variable_get( var )
        }
        return hash.merge( 'type' => type )
    end


protected

    attr_writer   :required, :desc, :default # :nodoc:
end

###
#
# Core option types.  The core supported option types are:
#
# OptString  - Multi-byte character string
{'fraction_non_alphanumeric': 0.09098625021218808, 'fraction_numerical': 0.006111016805296215, 'mean_word_length': 1.9269746646795827, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '4519481', 'n_tokens_mistral': 1874, 'n_tokens_neox': 1825, 'n_words': 630}