]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust app layer template: functions to get buffers
authorJason Ish <ish@unx.ca>
Wed, 19 Sep 2018 04:35:20 +0000 (22:35 -0600)
committerVictor Julien <victor@inliniac.net>
Wed, 19 Sep 2018 19:00:51 +0000 (21:00 +0200)
Example functions for getting the request and response buffers.
Useful for running detection on the decoded buffers.

rust/src/applayertemplate/template.rs

index 865034b8b2ad3ad37ec63c201710f2f55823cb93..3eb746587e84e80d8f07713038262f3e2182b590 100644 (file)
@@ -459,6 +459,51 @@ pub extern "C" fn rs_template_state_get_tx_iterator(
     }
 }
 
+/// Get the request buffer for a transaction from C.
+///
+/// No required for parsing, but an example function for retrieving a
+/// pointer to the request buffer from C for detection.
+#[no_mangle]
+pub extern "C" fn rs_template_get_request_buffer(
+    tx: *mut libc::c_void,
+    buf: *mut *const libc::uint8_t,
+    len: *mut libc::uint32_t,
+) -> libc::uint8_t
+{
+    let tx = cast_pointer!(tx, TemplateTransaction);
+    if let Some(ref request) = tx.request {
+        if request.len() > 0 {
+            unsafe {
+                *len = request.len() as libc::uint32_t;
+                *buf = request.as_ptr();
+            }
+            return 1;
+        }
+    }
+    return 0;
+}
+
+/// Get the response buffer for a transaction from C.
+#[no_mangle]
+pub extern "C" fn rs_template_get_response_buffer(
+    tx: *mut libc::c_void,
+    buf: *mut *const libc::uint8_t,
+    len: *mut libc::uint32_t,
+) -> libc::uint8_t
+{
+    let tx = cast_pointer!(tx, TemplateTransaction);
+    if let Some(ref response) = tx.response {
+        if response.len() > 0 {
+            unsafe {
+                *len = response.len() as libc::uint32_t;
+                *buf = response.as_ptr();
+            }
+            return 1;
+        }
+    }
+    return 0;
+}
+
 // Parser name as a C style string.
 const PARSER_NAME: &'static [u8] = b"template-rust\0";