Browse code

Improve layout of libclamav_rust directory

Add a top-level Cargo.toml.

Remove the vestigial libclamav_rust/Makefile.am.

Place Rust source under a libclamav_rust/src directory as is canonical
for Rust projects.

Scott Hutton authored on 2021/11/18 07:45:25
Showing 8 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,5 @@
0
+[workspace]
1
+
2
+members = [
3
+    "libclamav_rust",
4
+]
... ...
@@ -9,4 +9,5 @@ add_rust_library(TARGET clamav_rust WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DI
9 9
 if (WIN32)
10 10
     target_link_libraries(clamav_rust PUBLIC INTERFACE Userenv)
11 11
 endif()
12
+
12 13
 add_library(ClamAV::libclamav_rust ALIAS clamav_rust)
... ...
@@ -12,4 +12,3 @@ log = {version = "*", features = ["std"]}
12 12
 [lib]
13 13
 crate-type = ["staticlib"]
14 14
 name = "clamav_rust"
15
-path = "lib.rs"
16 15
deleted file mode 100644
... ...
@@ -1,18 +0,0 @@
1
-#
2
-# Rust common libs for ClamAV apps
3
-#
4
-
5
-rdiff_SOURCES = \
6
-    rdiff/Cargo.toml \
7
-    rdiff/rdiff.rs
8
-
9
-EXTRA_DIST = $(rdiff_SOURCES)
10
-
11
-$(top_builddir)/common_rust/rdiff/$(RUST_TARGET_SUBDIR)/librdiff.a: $(rdiff_SOURCES)
12
-	cd $(top_srcdir)/common_rust/rdiff && \
13
-	mkdir -p $(top_builddir)/common_rust/rdiff && \
14
-	CARGO_TARGET_DIR=$(top_builddir)/common_rust/rdiff cargo build --target-dir $(abs_top_builddir)/common_rust/rdiff $(CARGO_RELEASE_ARGS)
15
-
16
-rdiff_LIB=$(top_builddir)/common_rust/rdiff/$(RUST_TARGET_SUBDIR)/librdiff.a
17
-
18
-all: $(rdiff_LIB)
19 1
deleted file mode 100644
... ...
@@ -1,23 +0,0 @@
1
-/*
2
- *  libclamav features written in Rust
3
- *
4
- *  Copyright (C) 2021 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
5
- *
6
- *  Authors: Micah Snyder, Mickey Sola
7
- *
8
- *  This program is free software; you can redistribute it and/or modify
9
- *  it under the terms of the GNU General Public License version 2 as
10
- *  published by the Free Software Foundation.
11
- *
12
- *  This program is distributed in the hope that it will be useful,
13
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
- *  GNU General Public License for more details.
16
- *
17
- *  You should have received a copy of the GNU General Public License
18
- *  along with this program; if not, write to the Free Software
19
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
- *  MA 02110-1301, USA.
21
- */
22
-
23
-pub mod logging;
24 1
\ No newline at end of file
25 2
deleted file mode 100644
... ...
@@ -1,77 +0,0 @@
1
-/*
2
- *  Rust logging module
3
- *
4
- *  Copyright (C) 2021 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
5
- *
6
- *  Authors: Mickey Sola
7
- *
8
- *  This program is free software; you can redistribute it and/or modify
9
- *  it under the terms of the GNU General Public License version 2 as
10
- *  published by the Free Software Foundation.
11
- *
12
- *  This program is distributed in the hope that it will be useful,
13
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
- *  GNU General Public License for more details.
16
- *
17
- *  You should have received a copy of the GNU General Public License
18
- *  along with this program; if not, write to the Free Software
19
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
- *  MA 02110-1301, USA.
21
- */
22
-
23
-use std::ffi::c_void;
24
-use std::ffi::CString;
25
-use std::os::raw::c_char;
26
-
27
-extern crate log;
28
-
29
-use self::log::LevelFilter;
30
-use self::log::{Level, Metadata, Record};
31
-
32
-extern "C" {
33
-    fn cli_warnmsg(str: *const c_char, ...) -> c_void;
34
-    fn cli_dbgmsg(str: *const c_char, ...) -> c_void;
35
-    fn cli_infomsg_simple(str: *const c_char, ...) -> c_void;
36
-    fn cli_errmsg(str: *const c_char, ...) -> c_void;
37
-}
38
-
39
-pub struct ClamLogger;
40
-
41
-impl log::Log for ClamLogger {
42
-    fn enabled(&self, metadata: &Metadata) -> bool {
43
-        metadata.level() <= Level::Debug
44
-    }
45
-
46
-    fn log(&self, record: &Record) {
47
-        if self.enabled(record.metadata()) {
48
-            let msg = CString::new(format!("{}\n", record.args())).unwrap();
49
-            let ptr = msg.as_ptr();
50
-
51
-            match record.level() {
52
-                Level::Debug => unsafe {
53
-                    cli_dbgmsg(ptr);
54
-                },
55
-                Level::Error => unsafe {
56
-                    cli_errmsg(ptr);
57
-                },
58
-                Level::Info => unsafe {
59
-                    cli_infomsg_simple(ptr);
60
-                },
61
-                Level::Warn => unsafe {
62
-                    cli_warnmsg(ptr);
63
-                },
64
-                _ => {}
65
-            }
66
-        }
67
-    }
68
-
69
-    fn flush(&self) {}
70
-}
71
-
72
-#[no_mangle]
73
-pub extern "C" fn clrs_log_init() -> bool {
74
-    log::set_boxed_logger(Box::new(ClamLogger))
75
-        .map(|()| log::set_max_level(LevelFilter::Debug))
76
-        .is_ok()
77
-}
78 1
new file mode 100644
... ...
@@ -0,0 +1,23 @@
0
+/*
1
+ *  libclamav features written in Rust
2
+ *
3
+ *  Copyright (C) 2021 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
4
+ *
5
+ *  Authors: Micah Snyder, Mickey Sola
6
+ *
7
+ *  This program is free software; you can redistribute it and/or modify
8
+ *  it under the terms of the GNU General Public License version 2 as
9
+ *  published by the Free Software Foundation.
10
+ *
11
+ *  This program is distributed in the hope that it will be useful,
12
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ *  GNU General Public License for more details.
15
+ *
16
+ *  You should have received a copy of the GNU General Public License
17
+ *  along with this program; if not, write to the Free Software
18
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
+ *  MA 02110-1301, USA.
20
+ */
21
+
22
+pub mod logging;
0 23
\ No newline at end of file
1 24
new file mode 100644
... ...
@@ -0,0 +1,77 @@
0
+/*
1
+ *  Rust logging module
2
+ *
3
+ *  Copyright (C) 2021 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
4
+ *
5
+ *  Authors: Mickey Sola
6
+ *
7
+ *  This program is free software; you can redistribute it and/or modify
8
+ *  it under the terms of the GNU General Public License version 2 as
9
+ *  published by the Free Software Foundation.
10
+ *
11
+ *  This program is distributed in the hope that it will be useful,
12
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ *  GNU General Public License for more details.
15
+ *
16
+ *  You should have received a copy of the GNU General Public License
17
+ *  along with this program; if not, write to the Free Software
18
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
+ *  MA 02110-1301, USA.
20
+ */
21
+
22
+use std::ffi::c_void;
23
+use std::ffi::CString;
24
+use std::os::raw::c_char;
25
+
26
+extern crate log;
27
+
28
+use self::log::LevelFilter;
29
+use self::log::{Level, Metadata, Record};
30
+
31
+extern "C" {
32
+    fn cli_warnmsg(str: *const c_char, ...) -> c_void;
33
+    fn cli_dbgmsg(str: *const c_char, ...) -> c_void;
34
+    fn cli_infomsg_simple(str: *const c_char, ...) -> c_void;
35
+    fn cli_errmsg(str: *const c_char, ...) -> c_void;
36
+}
37
+
38
+pub struct ClamLogger;
39
+
40
+impl log::Log for ClamLogger {
41
+    fn enabled(&self, metadata: &Metadata) -> bool {
42
+        metadata.level() <= Level::Debug
43
+    }
44
+
45
+    fn log(&self, record: &Record) {
46
+        if self.enabled(record.metadata()) {
47
+            let msg = CString::new(format!("{}\n", record.args())).unwrap();
48
+            let ptr = msg.as_ptr();
49
+
50
+            match record.level() {
51
+                Level::Debug => unsafe {
52
+                    cli_dbgmsg(ptr);
53
+                },
54
+                Level::Error => unsafe {
55
+                    cli_errmsg(ptr);
56
+                },
57
+                Level::Info => unsafe {
58
+                    cli_infomsg_simple(ptr);
59
+                },
60
+                Level::Warn => unsafe {
61
+                    cli_warnmsg(ptr);
62
+                },
63
+                _ => {}
64
+            }
65
+        }
66
+    }
67
+
68
+    fn flush(&self) {}
69
+}
70
+
71
+#[no_mangle]
72
+pub extern "C" fn clrs_log_init() -> bool {
73
+    log::set_boxed_logger(Box::new(ClamLogger))
74
+        .map(|()| log::set_max_level(LevelFilter::Debug))
75
+        .is_ok()
76
+}