]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust: stub out configuration access functions
authorJason Ish <ish@unx.ca>
Mon, 3 Apr 2017 21:31:49 +0000 (15:31 -0600)
committerJason Ish <ish@unx.ca>
Mon, 5 Jun 2017 20:57:20 +0000 (14:57 -0600)
rust/src/conf.rs [new file with mode: 0644]
rust/src/lib.rs

diff --git a/rust/src/conf.rs b/rust/src/conf.rs
new file mode 100644 (file)
index 0000000..080396a
--- /dev/null
@@ -0,0 +1,67 @@
+/* Copyright (C) 2017 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.
+ */
+
+use std::os::raw::c_char;
+use std::ffi::{CString, CStr};
+use std::ptr;
+use std::str;
+
+use log::*;
+
+extern {
+    fn ConfGet(key: *const c_char, res: *mut *const c_char) -> i8;
+}
+
+// Return the string value of a configuration value.
+pub fn conf_get(key: &str) -> Option<&str> {
+    let mut vptr: *const c_char = ptr::null_mut();
+
+    unsafe {
+        if ConfGet(CString::new(key).unwrap().as_ptr(), &mut vptr) != 1 {
+            SCLogInfo!("Failed to find value for key {}", key);
+            return None;
+        }
+    }
+
+    if vptr == ptr::null() {
+        return None;
+    }
+
+    let value = str::from_utf8(unsafe{
+        CStr::from_ptr(vptr).to_bytes()
+    }).unwrap();
+
+    return Some(value);
+}
+
+// Return the value of key as a boolean. A value that is not set is
+// the same as having it set to false.
+pub fn conf_get_bool(key: &str) -> bool {
+    match conf_get(key) {
+        Some(val) => {
+            match val {
+                "1" | "yes" | "true" | "on" => {
+                    return true;
+                },
+                _ => {},
+            }
+        },
+        None => {},
+    }
+
+    return false;
+}
index 4b25340d4299c15437b6b3cc1865ded0d748452a..fb257128b2ac6edecbb03d1198f04111c19fcb1c 100644 (file)
@@ -1,2 +1,4 @@
 #[macro_use]
 pub mod log;
+
+pub mod conf;