Land #14772, Extract module data store to its own file

This commit is contained in:
dwelch-r7 2021-02-19 17:35:28 +00:00 committed by GitHub
commit 3817ab9345
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 64 deletions

View File

@ -339,69 +339,5 @@ class DataStore < Hash
end
###
#
# DataStore wrapper for modules that will attempt to back values against the
# framework's datastore if they aren't found in the module's datastore. This
# is done to simulate global data store values.
#
###
class ModuleDataStore < DataStore
def initialize(m)
super()
@_module = m
end
#
# Fetch the key from the local hash first, or from the framework datastore
# if we can't directly find it
#
def fetch(key)
key = find_key_case(key)
val = nil
val = super if(@imported_by[key] != 'self')
if (val.nil? and @_module and @_module.framework)
val = @_module.framework.datastore[key]
end
val = super if val.nil?
val
end
#
# Same as fetch
#
def [](key)
key = find_key_case(key)
val = nil
val = super if(@imported_by[key] != 'self')
if (val.nil? and @_module and @_module.framework)
val = @_module.framework.datastore[key]
end
val = super if val.nil?
val
end
#
# Was this entry actually set or just using its default
#
def default?(key)
(@imported_by[key] == 'self')
end
#
# Return a deep copy of this datastore.
#
def copy
ds = self.class.new(@_module)
self.keys.each do |k|
ds.import_option(k, self[k].kind_of?(String) ? self[k].dup : self[k], @imported[k], @imported_by[k])
end
ds.aliases = self.aliases.dup
ds
end
end
end

View File

@ -0,0 +1,67 @@
# -*- coding: binary -*-
module Msf
###
#
# DataStore wrapper for modules that will attempt to back values against the
# framework's datastore if they aren't found in the module's datastore. This
# is done to simulate global data store values.
#
###
class ModuleDataStore < DataStore
def initialize(m)
super()
@_module = m
end
#
# Fetch the key from the local hash first, or from the framework datastore
# if we can't directly find it
#
def fetch(key)
key = find_key_case(key)
val = nil
val = super if(@imported_by[key] != 'self')
if (val.nil? and @_module and @_module.framework)
val = @_module.framework.datastore[key]
end
val = super if val.nil?
val
end
#
# Same as fetch
#
def [](key)
key = find_key_case(key)
val = nil
val = super if(@imported_by[key] != 'self')
if (val.nil? and @_module and @_module.framework)
val = @_module.framework.datastore[key]
end
val = super if val.nil?
val
end
#
# Was this entry actually set or just using its default
#
def default?(key)
(@imported_by[key] == 'self')
end
#
# Return a deep copy of this datastore.
#
def copy
ds = self.class.new(@_module)
self.keys.each do |k|
ds.import_option(k, self[k].kind_of?(String) ? self[k].dup : self[k], @imported[k], @imported_by[k])
end
ds.aliases = self.aliases.dup
ds
end
end
end