diff options
Diffstat (limited to 'rust/src/sip/log.rs')
-rw-r--r-- | rust/src/sip/log.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/rust/src/sip/log.rs b/rust/src/sip/log.rs new file mode 100644 index 0000000..792acfa --- /dev/null +++ b/rust/src/sip/log.rs @@ -0,0 +1,54 @@ +/* Copyright (C) 2019 Open Information Security Foundation + * + * You can copy, redistribute or modify this Program under the terms of + * the GNU General Public License version 2 as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +// written by Giuseppe Longo <giuseppe@glongo.it> + +use crate::jsonbuilder::{JsonBuilder, JsonError}; +use crate::sip::sip::SIPTransaction; + +fn log(tx: &SIPTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> { + js.open_object("sip")?; + + if let Some(req) = &tx.request { + js.set_string("method", &req.method)? + .set_string("uri", &req.path)? + .set_string("version", &req.version)?; + } + + if let Some(req_line) = &tx.request_line { + js.set_string("request_line", req_line)?; + } + + if let Some(resp) = &tx.response { + js.set_string("version", &resp.version)? + .set_string("code", &resp.code)? + .set_string("reason", &resp.reason)?; + } + + if let Some(resp_line) = &tx.response_line { + js.set_string("response_line", resp_line)?; + } + + js.close()?; + + Ok(()) +} + +#[no_mangle] +pub extern "C" fn rs_sip_log_json(tx: &mut SIPTransaction, js: &mut JsonBuilder) -> bool { + log(tx, js).is_ok() +}
\ No newline at end of file |