Class: Rodsec::Modsec

Inherits:
Object
  • Object
show all
Includes:
StringPointers
Defined in:
lib/rodsec/modsec.rb

Constant Summary

Constants included from StringPointers

StringPointers::EMPTY_STRING

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StringPointers

#strptr

Constructor Details

#initialize(&log_blk) ⇒ Modsec

Returns a new instance of Modsec.



7
8
9
10
11
12
13
14
# File 'lib/rodsec/modsec.rb', line 7

def initialize &log_blk
  @msc_ptr = Wrapper.msc_init
  @msc_ptr.free = Wrapper['msc_cleanup']

  Wrapper.msc_set_connector_info @msc_ptr, (strptr info_string)

  logger_fn &log_blk
end

Instance Attribute Details

#msc_ptrObject (readonly)

Returns the value of attribute msc_ptr.



18
19
20
# File 'lib/rodsec/modsec.rb', line 18

def msc_ptr
  @msc_ptr
end

Instance Method Details

#info_stringObject

given to ModSecurity. should be in the form ConnectorName vX.Y.Z-tag (something else)



51
52
53
# File 'lib/rodsec/modsec.rb', line 51

def info_string
  "Rodsec v#{VERSION}"
end

#logger_fn(&log_blk) ⇒ Object

Given a block, this will set the logger callback. With no block, it will return the current logger callback, which may be nil. ‘ModSecLogCb’, ‘void (*) (void *, const void *)’ msc_set_log_cb(ModSecurity *msc, ModSecLogCb cb)



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rodsec/modsec.rb', line 24

def logger_fn &log_blk
  if block_given?
    # set the logger callback
    #
    # NOTENOTE logger_fn and logger_closure must NOT be garbage-collected,
    # otherwise callbacks from C to logger_fn will segfault. Also,
    # Fiddle::Function seems to not keep a reference its closure argument,
    # so hang on to that too.

    return_type = Fiddle::TYPE_VOID
    arg_types = Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP

    # txn_log_tag is set in the contructor of Transaction.
    @logger_closure = Fiddle::Closure::BlockCaller.new return_type, arg_types do |txn_log_tag, log_str_ptr|
      log_blk.call txn_log_tag.to_s, log_str_ptr.to_s
    end

    @logger_fn = Fiddle::Function.new @logger_closure, arg_types, return_type
    Wrapper.msc_set_log_cb @msc_ptr, @logger_fn
  else
    # return the logger callback, might be nil
    @logger_fn
  end
end

#version_infoObject

information about the version of libmodsecurity



56
57
58
# File 'lib/rodsec/modsec.rb', line 56

def version_info
  (Wrapper.msc_who_am_i @msc_ptr).to_s
end