From: Jason Ish Date: Mon, 8 Jun 2020 17:11:28 +0000 (-0600) Subject: jsonbuilder: export {set,append}_string_from_bytes to C X-Git-Tag: suricata-6.0.0-beta1~335 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3b7c582189a056be4d2e08dc1358535e8759803;p=thirdparty%2Fsuricata.git jsonbuilder: export {set,append}_string_from_bytes to C --- diff --git a/rust/src/jsonbuilder.rs b/rust/src/jsonbuilder.rs index 3394383ce6..0cd9ed6b05 100644 --- a/rust/src/jsonbuilder.rs +++ b/rust/src/jsonbuilder.rs @@ -605,6 +605,20 @@ pub unsafe extern "C" fn jb_set_string( return false; } +#[no_mangle] +pub unsafe extern "C" fn jb_set_string_from_bytes( + js: &mut JsonBuilder, key: *const c_char, bytes: *const u8, len: u32, +) -> bool { + if bytes == std::ptr::null() || len == 0 { + return false; + } + if let Ok(key) = CStr::from_ptr(key).to_str() { + let val = std::slice::from_raw_parts(bytes, len as usize); + return js.set_string_from_bytes(key, val).is_ok(); + } + return false; +} + #[no_mangle] pub unsafe extern "C" fn jb_set_jsont( jb: &mut JsonBuilder, key: *const c_char, jsont: &mut json::JsonT, @@ -641,6 +655,17 @@ pub unsafe extern "C" fn jb_append_string(js: &mut JsonBuilder, val: *const c_ch return false; } +#[no_mangle] +pub unsafe extern "C" fn jb_append_string_from_bytes( + js: &mut JsonBuilder, bytes: *const u8, len: u32, +) -> bool { + if bytes == std::ptr::null() || len == 0 { + return false; + } + let val = std::slice::from_raw_parts(bytes, len as usize); + return js.append_string_from_bytes(val).is_ok(); +} + #[no_mangle] pub unsafe extern "C" fn jb_append_uint(js: &mut JsonBuilder, val: u64) -> bool { return js.append_uint(val).is_ok();