Skip to content

Commit

Permalink
fix: refactor of ss_plugin_byte_buffer
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Scolaro <[email protected]>
  • Loading branch information
therealbobo committed Apr 6, 2023
1 parent bf82cf0 commit ea065f4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
15 changes: 2 additions & 13 deletions userspace/libsinsp/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,19 +328,8 @@ bool sinsp_plugin::resolve_dylib_symbols(std::string &errstr)
strlcpy(tf.m_display, fdisplay.c_str(), sizeof(tf.m_display));
strlcpy(tf.m_description, fdesc.c_str(), sizeof(tf.m_description));
tf.m_print_format = PF_DEC;
std::map<std::string, ppm_param_type> pt_lut = {
{"string", PT_CHARBUF},
{"uint64", PT_UINT64},
{"reltime", PT_RELTIME},
{"abstime", PT_ABSTIME},
{"bool", PT_BOOL},
{"ipv4addr", PT_IPV4ADDR},
{"ipv4net", PT_IPV4NET},
{"ipv6addr", PT_IPV6ADDR},
{"ipv6net", PT_IPV6NET},
};
if(pt_lut.find(ftype) != pt_lut.end()) {
tf.m_type = pt_lut[ftype];
if(m_pt_lut.find(ftype) != m_pt_lut.end()) {
tf.m_type = m_pt_lut.at(ftype);
} else {
throw sinsp_exception(
string("error in plugin ") + name() + ": invalid field type " + ftype);
Expand Down
14 changes: 14 additions & 0 deletions userspace/libsinsp/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ class sinsp_plugin: public sinsp_plugin_cap_sourcing, public sinsp_plugin_cap_ex
ss_plugin_t* m_state;
plugin_caps_t m_caps;
plugin_handle_t* m_handle;
//
// Plugin Type Look Up Table
//
const std::unordered_map<std::string, ppm_param_type> m_pt_lut = {
{"string", PT_CHARBUF},
{"uint64", PT_UINT64},
{"reltime", PT_RELTIME},
{"abstime", PT_ABSTIME},
{"bool", PT_BOOL},
{"ipv4addr", PT_IPV4ADDR},
{"ipv4net", PT_IPV4NET},
{"ipv6addr", PT_IPV6ADDR},
{"ipv6net", PT_IPV6NET},
};

/** Event Sourcing **/
uint32_t m_id;
Expand Down
4 changes: 2 additions & 2 deletions userspace/libsinsp/plugin_filtercheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ bool sinsp_filter_check_plugin::extract(sinsp_evt *evt, OUT vector<extract_value
case PT_IPV6ADDR:
case PT_IPV6NET:
{
res.len = (uint32_t) efield.res.buf[i]->len;
res.ptr = (uint8_t*) efield.res.buf[i]->ptr;
res.len = (uint32_t) efield.res.buf[i].len;
res.ptr = (uint8_t*) efield.res.buf[i].ptr;
break;
}
case PT_CHARBUF:
Expand Down
4 changes: 2 additions & 2 deletions userspace/plugin/plugin_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C" {
// API versions of this plugin framework
//
#define PLUGIN_API_VERSION_MAJOR 2
#define PLUGIN_API_VERSION_MINOR 0
#define PLUGIN_API_VERSION_MINOR 1
#define PLUGIN_API_VERSION_PATCH 0

//
Expand Down Expand Up @@ -387,4 +387,4 @@ typedef struct

#ifdef __cplusplus
}
#endif
#endif
7 changes: 3 additions & 4 deletions userspace/plugin/plugin_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ typedef struct ss_plugin_event
uint64_t ts;
} ss_plugin_event;

struct const_sized_buffer {
typedef struct ss_plugin_byte_buffer{
uint32_t len;
const void* ptr;
};
typedef struct const_sized_buffer const_sized_buffer;
} ss_plugin_byte_buffer;

// Used in extract_fields functions below to receive a field/arg
// pair and return an extracted value.
Expand Down Expand Up @@ -134,7 +133,7 @@ typedef struct ss_plugin_extract_field
uint64_t* u64;
uint32_t* u32;
bool* boolean;
const_sized_buffer** buf;
ss_plugin_byte_buffer* buf;
} res;
uint64_t res_len;

Expand Down

0 comments on commit ea065f4

Please sign in to comment.