update(userspace/falco): use mutable proto fields where applicable

Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
This commit is contained in:
Leonardo Di Donato 2020-02-06 22:22:40 +00:00 committed by poiana
parent 738d757b08
commit b3171dbae1

View File

@ -35,15 +35,14 @@ const static struct luaL_reg ll_falco_outputs [] =
{NULL, NULL}
};
falco_outputs::falco_outputs(falco_engine *engine)
: m_falco_engine(engine),
falco_outputs::falco_outputs(falco_engine *engine):
m_falco_engine(engine),
m_initialized(false),
m_buffered(true),
m_json_output(false),
m_time_format_iso_8601(false),
m_hostname("")
{
}
falco_outputs::~falco_outputs()
@ -135,7 +134,6 @@ void falco_outputs::add_output(output_config oc)
const char *lerr = lua_tostring(m_ls, -1);
throw falco_exception(string(lerr));
}
}
void falco_outputs::handle_event(gen_event *ev, string &rule, string &source,
@ -245,7 +243,6 @@ void falco_outputs::handle_msg(uint64_t now,
{
throw falco_exception("No function " + m_lua_output_msg + " found in lua compiler module");
}
}
void falco_outputs::reopen_outputs()
@ -291,7 +288,8 @@ int falco_outputs::handle_http(lua_State *ls)
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
if(res != CURLE_OK)
{
falco_logger::log(LOG_ERR, "libcurl error: " + string(curl_easy_strerror(res)));
}
curl_easy_cleanup(curl);
@ -322,11 +320,12 @@ int falco_outputs::handle_grpc(lua_State *ls)
// time
gen_event *evt = (gen_event *)lua_topointer(ls, 1);
auto& timestamp = *grpc_res.mutable_time();
timestamp = google::protobuf::util::TimeUtil::NanosecondsToTimestamp(evt->get_ts());
auto timestamp = grpc_res.mutable_time();
*timestamp = google::protobuf::util::TimeUtil::NanosecondsToTimestamp(evt->get_ts());
// rule
grpc_res.set_rule((char *)lua_tostring(ls, 2));
auto rule = grpc_res.mutable_rule();
*rule = (char *)lua_tostring(ls, 2);
// source
falco::schema::source s = falco::schema::source::SYSCALL;
@ -349,20 +348,23 @@ int falco_outputs::handle_grpc(lua_State *ls)
grpc_res.set_priority(p);
// output
grpc_res.set_output((char *)lua_tostring(ls, 5));
auto output = grpc_res.mutable_output();
*output = (char *)lua_tostring(ls, 5);
// output fields
auto &fields = *grpc_res.mutable_output_fields();
lua_pushnil(ls); // so that lua_next removes it from stack and puts (k, v) on it
while (lua_next(ls, 6) != 0) {
while(lua_next(ls, 6) != 0)
{
fields[lua_tostring(ls, -2)] = lua_tostring(ls, -1);
lua_pop(ls, 1); // remove value, keep key for lua_next
}
lua_pop(ls, 1); // pop table
// hostname
grpc_res.set_hostname((char* )lua_tostring(ls, 7));
auto host = grpc_res.mutable_hostname();
*host = (char *)lua_tostring(ls, 7);
falco::output::queue::get().push(grpc_res);