diff --git a/rust/src/json.rs b/rust/src/json.rs index 28dbb6bfcb..0ac4d04bad 100644 --- a/rust/src/json.rs +++ b/rust/src/json.rs @@ -35,6 +35,7 @@ extern { fn json_string(value: *const c_char) -> *mut JsonT; fn json_integer(val: u64) -> *mut JsonT; + fn SCJsonBool(val: bool) -> *mut JsonT; } pub struct Json { @@ -83,6 +84,14 @@ impl Json { } } + pub fn set_boolean(&self, key: &str, val: bool) { + unsafe { + json_object_set_new(self.js, + CString::new(key).unwrap().as_ptr(), + SCJsonBool(val)); + } + } + pub fn array_append(&self, val: Json) { unsafe { json_array_append_new(self.js, val.js); diff --git a/src/output-json.c b/src/output-json.c index 071b3f233f..32495d416c 100644 --- a/src/output-json.c +++ b/src/output-json.c @@ -92,6 +92,11 @@ void OutputJsonRegister (void) OutputRegisterModule(MODULE_NAME, "eve-log", OutputJsonInitCtx); } +json_t *SCJsonBool(int val) +{ + return (val ? json_true() : json_false()); +} + /* Default Sensor ID value */ static int64_t sensor_id = -1; /* -1 = not defined */ diff --git a/src/output-json.h b/src/output-json.h index 5f42e7657a..2386224e5a 100644 --- a/src/output-json.h +++ b/src/output-json.h @@ -64,6 +64,8 @@ typedef struct AlertJsonThread_ { LogFileCtx *file_ctx; } AlertJsonThread; +json_t *SCJsonBool(int val); + #endif /* HAVE_LIBJANSSON */ #endif /* __OUTPUT_JSON_H__ */ diff --git a/src/suricata-common.h b/src/suricata-common.h index 940e3e06f9..0af2078d64 100644 --- a/src/suricata-common.h +++ b/src/suricata-common.h @@ -229,7 +229,8 @@ #endif /* Appears not all current distros have jansson that defines this. */ #ifndef json_boolean -#define json_boolean(val) ((val) ? json_true() : json_false()) +#define json_boolean(val) SCJsonBool((val)) +//#define json_boolean(val) ((val) ? json_true() : json_false()) #endif #endif