// written by Pierre Chifflier <chifflier@wzdftpd.net>
-use crate::json::*;
+use crate::jsonbuilder::{JsonBuilder, JsonError};
use crate::krb::krb5::{KRB5State,KRB5Transaction,test_weak_encryption};
-#[no_mangle]
-pub extern "C" fn rs_krb5_log_json_response(_state: &mut KRB5State, tx: &mut KRB5Transaction) -> *mut JsonT
+fn krb5_log_response(jsb: &mut JsonBuilder, tx: &mut KRB5Transaction) -> Result<(), JsonError>
{
- let js = Json::object();
match tx.error_code {
Some(c) => {
- js.set_string("msg_type", "KRB_ERROR");
- js.set_string("failed_request", &format!("{:?}", tx.msg_type));
- js.set_string("error_code", &format!("{:?}", c));
+ jsb.set_string("msg_type", "KRB_ERROR")?;
+ jsb.set_string("failed_request", &format!("{:?}", tx.msg_type))?;
+ jsb.set_string("error_code", &format!("{:?}", c))?;
},
- None => { js.set_string("msg_type", &format!("{:?}", tx.msg_type)); },
+ None => { jsb.set_string("msg_type", &format!("{:?}", tx.msg_type))?; },
}
let cname = match tx.cname {
Some(ref x) => format!("{}", x),
Some(ref x) => format!("{:?}", x),
None => "<none>".to_owned(),
};
- js.set_string("cname", &cname);
- js.set_string("realm", &realm);
- js.set_string("sname", &sname);
- js.set_string("encryption", &encryption);
- js.set_boolean("weak_encryption", tx.etype.map_or(false,test_weak_encryption));
- return js.unwrap();
+ jsb.set_string("cname", &cname)?;
+ jsb.set_string("realm", &realm)?;
+ jsb.set_string("sname", &sname)?;
+ jsb.set_string("encryption", &encryption)?;
+ jsb.set_bool("weak_encryption", tx.etype.map_or(false,test_weak_encryption))?;
+
+ return Ok(());
}
+#[no_mangle]
+pub extern "C" fn rs_krb5_log_json_response(jsb: &mut JsonBuilder, _state: &mut KRB5State, tx: &mut KRB5Transaction) -> bool
+{
+ krb5_log_response(jsb, tx).is_ok()
+}
{
KRB5Transaction *krb5tx = tx;
LogKRB5LogThread *thread = thread_data;
- json_t *js, *krb5js;
- js = CreateJSONHeader(p, LOG_DIR_PACKET, "krb5", NULL);
- if (unlikely(js == NULL)) {
+ JsonBuilder *jb = CreateEveHeader(p, LOG_DIR_PACKET, "krb5", NULL);
+ if (unlikely(jb == NULL)) {
return TM_ECODE_FAILED;
}
- JsonAddCommonOptions(&thread->krb5log_ctx->cfg, p, f, js);
+ EveAddCommonOptions(&thread->krb5log_ctx->cfg, p, f, jb);
- krb5js = rs_krb5_log_json_response(state, krb5tx);
- if (unlikely(krb5js == NULL)) {
+ jb_open_object(jb, "krb5");
+ if (!rs_krb5_log_json_response(jb, state, krb5tx)) {
goto error;
}
- json_object_set_new(js, "krb5", krb5js);
+ jb_close(jb);
MemBufferReset(thread->buffer);
- OutputJSONBuffer(js, thread->krb5log_ctx->file_ctx, &thread->buffer);
+ OutputJsonBuilderBuffer(jb, thread->krb5log_ctx->file_ctx, &thread->buffer);
- json_decref(js);
+ jb_free(jb);
return TM_ECODE_OK;
error:
- json_decref(js);
+ jb_free(jb);
return TM_ECODE_FAILED;
}