bittorrent: no_mangle, pub and naming cleanups

- Remove rs_prefix
- Remove no_mangle and pub when not needed

Related to ticket: #7498
pull/12693/head
Jason Ish 2 years ago committed by Victor Julien
parent 05dd607f34
commit f0116c3a6b

@ -142,11 +142,10 @@ impl BitTorrentDHTState {
// C exports. // C exports.
export_tx_data_get!(bittorrent_dht_get_tx_data, BitTorrentDHTTransaction); export_tx_data_get!(get_tx_data, BitTorrentDHTTransaction);
export_state_data_get!(bittorrent_dht_get_state_data, BitTorrentDHTState); export_state_data_get!(get_state_data, BitTorrentDHTState);
#[no_mangle] extern "C" fn state_new(
pub extern "C" fn rs_bittorrent_dht_state_new(
_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto, _orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto,
) -> *mut std::os::raw::c_void { ) -> *mut std::os::raw::c_void {
let state = BitTorrentDHTState::new(); let state = BitTorrentDHTState::new();
@ -154,41 +153,36 @@ pub extern "C" fn rs_bittorrent_dht_state_new(
return Box::into_raw(boxed) as *mut std::os::raw::c_void; return Box::into_raw(boxed) as *mut std::os::raw::c_void;
} }
#[no_mangle] unsafe extern "C" fn state_free(state: *mut std::os::raw::c_void) {
pub unsafe extern "C" fn rs_bittorrent_dht_state_free(state: *mut std::os::raw::c_void) {
std::mem::drop(Box::from_raw(state as *mut BitTorrentDHTState)); std::mem::drop(Box::from_raw(state as *mut BitTorrentDHTState));
} }
#[no_mangle] unsafe extern "C" fn state_tx_free(
pub unsafe extern "C" fn rs_bittorrent_dht_state_tx_free(
state: *mut std::os::raw::c_void, tx_id: u64, state: *mut std::os::raw::c_void, tx_id: u64,
) { ) {
let state = cast_pointer!(state, BitTorrentDHTState); let state = cast_pointer!(state, BitTorrentDHTState);
state.free_tx(tx_id); state.free_tx(tx_id);
} }
#[no_mangle] unsafe extern "C" fn parse_ts(
pub unsafe extern "C" fn rs_bittorrent_dht_parse_ts(
_flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void, _flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void,
stream_slice: StreamSlice, _data: *const std::os::raw::c_void, stream_slice: StreamSlice, _data: *const std::os::raw::c_void,
) -> AppLayerResult { ) -> AppLayerResult {
return rs_bittorrent_dht_parse( return parse(
_flow, state, _pstate, stream_slice, _flow, state, _pstate, stream_slice,
_data, Direction::ToServer); _data, Direction::ToServer);
} }
#[no_mangle] unsafe extern "C" fn parse_tc(
pub unsafe extern "C" fn rs_bittorrent_dht_parse_tc(
_flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void, _flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void,
stream_slice: StreamSlice, _data: *const std::os::raw::c_void, stream_slice: StreamSlice, _data: *const std::os::raw::c_void,
) -> AppLayerResult { ) -> AppLayerResult {
return rs_bittorrent_dht_parse( return parse(
_flow, state, _pstate, stream_slice, _flow, state, _pstate, stream_slice,
_data, Direction::ToClient); _data, Direction::ToClient);
} }
#[no_mangle] unsafe extern "C" fn parse(
pub unsafe extern "C" fn rs_bittorrent_dht_parse(
_flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void, _flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void,
stream_slice: StreamSlice, _data: *const std::os::raw::c_void, stream_slice: StreamSlice, _data: *const std::os::raw::c_void,
direction: Direction, direction: Direction,
@ -198,8 +192,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_parse(
state.parse(buf, direction).into() state.parse(buf, direction).into()
} }
#[no_mangle] unsafe extern "C" fn state_get_tx(
pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx(
state: *mut std::os::raw::c_void, tx_id: u64, state: *mut std::os::raw::c_void, tx_id: u64,
) -> *mut std::os::raw::c_void { ) -> *mut std::os::raw::c_void {
let state = cast_pointer!(state, BitTorrentDHTState); let state = cast_pointer!(state, BitTorrentDHTState);
@ -213,16 +206,14 @@ pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx(
} }
} }
#[no_mangle] unsafe extern "C" fn state_get_tx_count(
pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx_count(
state: *mut std::os::raw::c_void, state: *mut std::os::raw::c_void,
) -> u64 { ) -> u64 {
let state = cast_pointer!(state, BitTorrentDHTState); let state = cast_pointer!(state, BitTorrentDHTState);
return state.tx_id; return state.tx_id;
} }
#[no_mangle] unsafe extern "C" fn tx_get_alstate_progress(
pub unsafe extern "C" fn rs_bittorrent_dht_tx_get_alstate_progress(
tx: *mut std::os::raw::c_void, _direction: u8, tx: *mut std::os::raw::c_void, _direction: u8,
) -> std::os::raw::c_int { ) -> std::os::raw::c_int {
let tx = cast_pointer!(tx, BitTorrentDHTTransaction); let tx = cast_pointer!(tx, BitTorrentDHTTransaction);
@ -235,8 +226,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_tx_get_alstate_progress(
return 0; return 0;
} }
#[no_mangle] unsafe extern "C" fn state_get_tx_iterator(
pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx_iterator(
_ipproto: u8, _alproto: AppProto, state: *mut std::os::raw::c_void, min_tx_id: u64, _ipproto: u8, _alproto: AppProto, state: *mut std::os::raw::c_void, min_tx_id: u64,
_max_tx_id: u64, istate: &mut u64, _max_tx_id: u64, istate: &mut u64,
) -> applayer::AppLayerGetTxIterTuple { ) -> applayer::AppLayerGetTxIterTuple {
@ -257,7 +247,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx_iterator(
const PARSER_NAME: &[u8] = b"bittorrent-dht\0"; const PARSER_NAME: &[u8] = b"bittorrent-dht\0";
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn rs_bittorrent_dht_udp_register_parser() { pub unsafe extern "C" fn SCRegisterBittorrentDhtUdpParser() {
let parser = RustParser { let parser = RustParser {
name: PARSER_NAME.as_ptr() as *const std::os::raw::c_char, name: PARSER_NAME.as_ptr() as *const std::os::raw::c_char,
default_port: std::ptr::null(), default_port: std::ptr::null(),
@ -266,24 +256,24 @@ pub unsafe extern "C" fn rs_bittorrent_dht_udp_register_parser() {
probe_tc: None, probe_tc: None,
min_depth: 0, min_depth: 0,
max_depth: 16, max_depth: 16,
state_new: rs_bittorrent_dht_state_new, state_new,
state_free: rs_bittorrent_dht_state_free, state_free,
tx_free: rs_bittorrent_dht_state_tx_free, tx_free: state_tx_free,
parse_ts: rs_bittorrent_dht_parse_ts, parse_ts,
parse_tc: rs_bittorrent_dht_parse_tc, parse_tc,
get_tx_count: rs_bittorrent_dht_state_get_tx_count, get_tx_count: state_get_tx_count,
get_tx: rs_bittorrent_dht_state_get_tx, get_tx: state_get_tx,
tx_comp_st_ts: 1, tx_comp_st_ts: 1,
tx_comp_st_tc: 1, tx_comp_st_tc: 1,
tx_get_progress: rs_bittorrent_dht_tx_get_alstate_progress, tx_get_progress: tx_get_alstate_progress,
get_eventinfo: Some(BitTorrentDHTEvent::get_event_info), get_eventinfo: Some(BitTorrentDHTEvent::get_event_info),
get_eventinfo_byid: Some(BitTorrentDHTEvent::get_event_info_by_id), get_eventinfo_byid: Some(BitTorrentDHTEvent::get_event_info_by_id),
localstorage_new: None, localstorage_new: None,
localstorage_free: None, localstorage_free: None,
get_tx_files: None, get_tx_files: None,
get_tx_iterator: Some(rs_bittorrent_dht_state_get_tx_iterator), get_tx_iterator: Some(state_get_tx_iterator),
get_tx_data: bittorrent_dht_get_tx_data, get_tx_data,
get_state_data: bittorrent_dht_get_state_data, get_state_data,
apply_tx_config: None, apply_tx_config: None,
flags: 0, flags: 0,
get_frame_id_by_name: None, get_frame_id_by_name: None,

@ -131,7 +131,7 @@ fn log_bittorrent_dht(
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn rs_bittorrent_dht_logger_log( pub unsafe extern "C" fn SCBittorrentDhtLogger(
tx: *mut std::os::raw::c_void, js: &mut JsonBuilder, tx: *mut std::os::raw::c_void, js: &mut JsonBuilder,
) -> bool { ) -> bool {
let tx = cast_pointer!(tx, BitTorrentDHTTransaction); let tx = cast_pointer!(tx, BitTorrentDHTTransaction);

@ -1738,7 +1738,7 @@ void AppLayerParserRegisterProtocolParsers(void)
RegisterSMTPParsers(); RegisterSMTPParsers();
SCRegisterDnsUdpParser(); SCRegisterDnsUdpParser();
SCRegisterDnsTcpParser(); SCRegisterDnsTcpParser();
rs_bittorrent_dht_udp_register_parser(); SCRegisterBittorrentDhtUdpParser();
RegisterModbusParsers(); RegisterModbusParsers();
SCEnipRegisterParsers(); SCEnipRegisterParsers();
RegisterDNP3Parsers(); RegisterDNP3Parsers();

@ -918,7 +918,7 @@ void OutputRegisterRootLoggers(void)
RegisterSimpleJsonApplayerLogger(ALPROTO_HTTP2, rs_http2_log_json, "http"); RegisterSimpleJsonApplayerLogger(ALPROTO_HTTP2, rs_http2_log_json, "http");
// underscore instead of dash for bittorrent_dht // underscore instead of dash for bittorrent_dht
RegisterSimpleJsonApplayerLogger( RegisterSimpleJsonApplayerLogger(
ALPROTO_BITTORRENT_DHT, rs_bittorrent_dht_logger_log, "bittorrent_dht"); ALPROTO_BITTORRENT_DHT, SCBittorrentDhtLogger, "bittorrent_dht");
OutputPacketLoggerRegister(); OutputPacketLoggerRegister();
OutputFiledataLoggerRegister(); OutputFiledataLoggerRegister();

Loading…
Cancel
Save