rust: bindgen SCLogMessage

Ticket: 7667
pull/13884/head
Philippe Antoine 5 months ago committed by Victor Julien
parent cc845dccdb
commit 828a6bdbf8

@ -17,8 +17,7 @@
//! This module exposes items from the core "C" code to Rust.
use std;
use suricata_sys::sys::{AppProto, AppProtoEnum, SCLogLevel};
use suricata_sys::sys::{AppProto, AppProtoEnum};
#[cfg(not(test))]
use suricata_sys::sys::SCAppLayerParserTriggerRawStreamInspection;
@ -68,16 +67,6 @@ macro_rules!BIT_U64 {
//
// Function types for calls into C.
//
#[allow(non_snake_case)]
pub type SCLogMessageFunc =
extern "C" fn(level: SCLogLevel,
filename: *const std::os::raw::c_char,
line: std::os::raw::c_uint,
function: *const std::os::raw::c_char,
subsystem: *const std::os::raw::c_char,
message: *const std::os::raw::c_char) -> std::os::raw::c_int;
pub enum StreamingBufferConfig {}
// Opaque flow type (defined in C)
@ -129,8 +118,6 @@ pub type SCFileContainerRecycle = extern "C" fn (
#[allow(non_snake_case)]
#[repr(C)]
pub struct SuricataContext {
pub SCLogMessage: SCLogMessageFunc,
pub HttpRangeFreeBlock: SCHttpRangeFreeBlock,
pub HTPFileCloseHandleRange: SCHTPFileCloseHandleRange,

@ -19,9 +19,9 @@
use std::{ffi::CString, path::Path};
use crate::core::SC;
use suricata_sys::sys::{SCFatalErrorOnInitStatic, SCLogLevel};
#[cfg(not(test))]
use suricata_sys::sys::{SCError, SCLogMessage};
pub static mut LEVEL: SCLogLevel = SCLogLevel::SC_LOG_NOTSET;
@ -59,13 +59,13 @@ pub fn sclog(level: SCLogLevel, file: &str, line: u32, function: &str, message:
/// SCLogMessage wrapper. If the Suricata C context is not registered
/// a more basic log format will be used (for example, when running
/// Rust unit tests).
#[cfg(not(test))]
pub fn sc_log_message(
level: SCLogLevel, filename: &str, line: std::os::raw::c_uint, function: &str, module: &str,
message: &str,
) -> std::os::raw::c_int {
) -> SCError {
unsafe {
if let Some(c) = SC {
return (c.SCLogMessage)(
return SCLogMessage(
level,
to_safe_cstring(filename).as_ptr(),
line,
@ -76,6 +76,11 @@ pub fn sc_log_message(
}
}
#[cfg(test)]
pub fn sc_log_message(
level: SCLogLevel, filename: &str, line: std::os::raw::c_uint, _function: &str, _module: &str,
message: &str,
) -> i32 {
// Fall back if the Suricata C context is not registered which is
// the case when Rust unit tests are running.
//

@ -435,6 +435,17 @@ extern "C" {
s: *mut Signature, alproto: AppProto,
) -> ::std::os::raw::c_int;
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum SCError {
SC_OK = 0,
SC_ENOMEM = 1,
SC_EINVAL = 2,
SC_ELIMIT = 3,
SC_EEXIST = 4,
SC_ENOENT = 5,
SC_ERR_MAX = 6,
}
#[repr(i32)]
#[doc = " \\brief The various log levels\n NOTE: when adding new level, don't forget to update SCLogMapLogLevelToSyslogLevel()\n or it may result in logging to syslog with LOG_EMERG priority."]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
@ -450,6 +461,13 @@ pub enum SCLogLevel {
SC_LOG_DEBUG = 7,
SC_LOG_LEVEL_MAX = 8,
}
extern "C" {
pub fn SCLogMessage(
arg1: SCLogLevel, arg2: *const ::std::os::raw::c_char, arg3: ::std::os::raw::c_uint,
arg4: *const ::std::os::raw::c_char, arg5: *const ::std::os::raw::c_char,
message: *const ::std::os::raw::c_char,
) -> SCError;
}
extern "C" {
pub fn SCFatalErrorOnInitStatic(arg1: *const ::std::os::raw::c_char);
}

@ -25,8 +25,6 @@
#include "util-var.h"
const SuricataContext suricata_context = {
SCLogMessage,
HttpRangeFreeBlock,
HTPFileCloseHandleRange,

@ -25,9 +25,7 @@
#include "app-layer-ike.h" //IKEState, IKETransaction
#include "app-layer-tftp.h" //TFTPState, TFTPTransaction
#include "util-debug.h"
#include "util-file.h"
#include "util-var.h"
// hack for include orders cf SCSha256
typedef struct HttpRangeContainerBlock HttpRangeContainerBlock;
@ -35,9 +33,6 @@ typedef struct HttpRangeContainerBlock HttpRangeContainerBlock;
struct AppLayerParser;
typedef struct SuricataContext_ {
SCError (*SCLogMessage)(const SCLogLevel, const char *, const unsigned int, const char *,
const char *, const char *message);
void (*HttpRangeFreeBlock)(HttpRangeContainerBlock *);
bool (*HTPFileCloseHandleRange)(const StreamingBufferConfig *sbcfg, FileContainer *,
const uint16_t, HttpRangeContainerBlock *, const uint8_t *, uint32_t);

@ -24,6 +24,8 @@
#ifndef SURICATA_UTIL_DEBUG_H
#define SURICATA_UTIL_DEBUG_H
#include "util-error.h"
/**
* \brief The various log levels
* NOTE: when adding new level, don't forget to update SCLogMapLogLevelToSyslogLevel()
@ -42,11 +44,13 @@ typedef enum {
SC_LOG_LEVEL_MAX,
} SCLogLevel;
SCError SCLogMessage(const SCLogLevel, const char *, const unsigned int, const char *, const char *,
const char *message);
#ifndef SURICATA_BINDGEN_H
#include "suricata-common.h"
#include "threads.h"
#include "util-error.h"
#include "util-debug-filters.h"
/**
@ -542,9 +546,6 @@ void SCLogInitLogModule(SCLogInitData *);
void SCLogDeInitLogModule(void);
SCError SCLogMessage(const SCLogLevel, const char *, const unsigned int, const char *, const char *,
const char *message);
SCLogOPBuffer *SCLogAllocLogOPBuffer(void);
int SCLogDebugEnabled(void);

@ -23,7 +23,7 @@
#define SURICATA_UTIL_ERROR_H
/* different error types */
typedef enum {
typedef enum SCError {
SC_OK,
SC_ENOMEM,
@ -35,8 +35,10 @@ typedef enum {
SC_ERR_MAX
} SCError;
#ifndef SURICATA_BINDGEN_H
#include "threads.h"
extern thread_local SCError sc_errno;
#endif
#endif /* SURICATA_UTIL_ERROR_H */

Loading…
Cancel
Save