]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/json: expose json_boolean
authorVictor Julien <victor@inliniac.net>
Mon, 15 May 2017 11:06:54 +0000 (13:06 +0200)
committerJason Ish <ish@unx.ca>
Mon, 5 Jun 2017 20:57:21 +0000 (14:57 -0600)
rust/src/json.rs
src/output-json.c
src/output-json.h
src/suricata-common.h

index 28dbb6bfcb6962ebc071544a0cd1ee6b93d65c55..0ac4d04bad582923777544722356f27f6a9d1c35 100644 (file)
@@ -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);
index 071b3f233fab7011d6fcd0fb8f65fc8363dca406..32495d416c252d2d4b4f73566c86effa0e1eaa39 100644 (file)
@@ -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 */
 
index 5f42e7657a49fcb291c091e9e3e1f6ec368041cd..2386224e5a46719fa2c828adf6e0b48b64dc2892 100644 (file)
@@ -64,6 +64,8 @@ typedef struct AlertJsonThread_ {
     LogFileCtx *file_ctx;
 } AlertJsonThread;
 
+json_t *SCJsonBool(int val);
+
 #endif /* HAVE_LIBJANSSON */
 
 #endif /* __OUTPUT_JSON_H__ */
index 940e3e06f93dacf6a493f35ef1f0bd8f875ce285..0af2078d64bd7c1caa0f898af5a6447edff8d6f9 100644 (file)
 #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