Class: Datadog::AppSec::WAF::Handle

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/appsec/waf/handle.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(handle_ptr) ⇒ Handle

Returns a new instance of Handle.



9
10
11
# File 'lib/datadog/appsec/waf/handle.rb', line 9

def initialize(handle_ptr)
  @handle_ptr = handle_ptr
end

Instance Method Details

#build_contextHandle

Builds a WAF context.

Returns:

Raises:



27
28
29
30
31
32
33
34
# File 'lib/datadog/appsec/waf/handle.rb', line 27

def build_context
  ensure_pointer_presence!

  context_obj = LibDDWAF.ddwaf_context_init(@handle_ptr)
  raise LibDDWAFError, "Could not create context" if context_obj.null?

  Context.new(context_obj)
end

#finalize!Object

Destroys the WAF handle and sets the pointer to nil.

The instance becomes unusable after this method is called.



16
17
18
19
20
21
# File 'lib/datadog/appsec/waf/handle.rb', line 16

def finalize!
  handle_ptr_to_destroy = @handle_ptr
  @handle_ptr = nil

  LibDDWAF.ddwaf_destroy(handle_ptr_to_destroy)
end

#known_addressesArray<String>

Returns the list of known addresses in the WAF handle.

Returns:

  • (Array<String>)

    the list of known addresses



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/datadog/appsec/waf/handle.rb', line 39

def known_addresses
  return @known_addresses if defined?(@known_addresses)

  ensure_pointer_presence!

  count = LibDDWAF::UInt32Ptr.new
  list = LibDDWAF.ddwaf_known_addresses(@handle_ptr, count)

  return [] if count == 0 # list is null

  @known_addresses = list.get_array_of_string(0, count[:value]).compact
end